mirror of
https://github.com/ringtailsoftware/uvm32.git
synced 2026-06-05 22:43:39 +00:00
Add commandline parsing to host. Add -e <size in bytes> option to configure extram.
This commit is contained in:
parent
93085f562c
commit
67e8fe13c0
3 changed files with 58 additions and 20 deletions
|
|
@ -110,7 +110,9 @@ Then, from inside the docker shell
|
||||||
|
|
||||||
make
|
make
|
||||||
|
|
||||||
./host/host apps/helloworld/helloworld.bin
|
./hosts/host/host apps/helloworld/helloworld.bin
|
||||||
|
|
||||||
|
`host` is the command line test VM for running samples. Run `host -h` for a full list of options.
|
||||||
|
|
||||||
## Native build
|
## Native build
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ disasm_common: all
|
||||||
$(PREFIX)objdump -S -d -f ${PROJECT}.elf
|
$(PREFIX)objdump -S -d -f ${PROJECT}.elf
|
||||||
|
|
||||||
test_common: all
|
test_common: all
|
||||||
${TOPDIR}/hosts/host/host ${PWD}/${PROJECT}.bin
|
${TOPDIR}/hosts/host/host ${HOST_EXTRA} ${PWD}/${PROJECT}.bin
|
||||||
|
|
||||||
clean_common:
|
clean_common:
|
||||||
rm -f ${PROJECT}.o ${PROJECT}.elf ${PROJECT}.bin
|
rm -f ${PROJECT}.o ${PROJECT}.elf ${PROJECT}.bin
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include "uvm32.h"
|
#include "uvm32.h"
|
||||||
|
|
||||||
#include "../common/uvm32_common_custom.h"
|
#include "../common/uvm32_common_custom.h"
|
||||||
|
|
@ -137,25 +138,53 @@ bool memdump(const char *filename, const uint8_t *buf, int len) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void usage(const char *name) {
|
||||||
|
printf("%s [options] filename.bin\n", name);
|
||||||
|
printf("Options:\n");
|
||||||
|
printf(" -h show help\n");
|
||||||
|
printf(" -i <num instructions> max instrs before requiring a syscall\n");
|
||||||
|
printf(" -e <extram size> numbers of bytes for extram\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
uvm32_state_t vmst;
|
uvm32_state_t vmst;
|
||||||
uint32_t max_instrs_per_run = 500000;
|
uint32_t max_instrs_per_run = 500000;
|
||||||
clock_t start_time = clock() / (CLOCKS_PER_SEC / 1000);
|
clock_t start_time = clock() / (CLOCKS_PER_SEC / 1000);
|
||||||
|
char c;
|
||||||
argc--;
|
const char *rom_filename = NULL;
|
||||||
argv++;
|
uint32_t extram_len = 0;
|
||||||
|
uint32_t *extram_buf = NULL;
|
||||||
if (argc < 1) {
|
uvm32_evt_t evt;
|
||||||
printf("<romfile> [max_instrs_per_run]\n");
|
bool isrunning = true;
|
||||||
return 1;
|
uint32_t total_instrs = 0;
|
||||||
}
|
uint32_t num_syscalls = 0;
|
||||||
|
|
||||||
if (argc > 1) {
|
|
||||||
max_instrs_per_run = strtoll(argv[1], NULL, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
int romlen = 0;
|
int romlen = 0;
|
||||||
uint8_t *rom = read_file(argv[0], &romlen);
|
|
||||||
|
// parse commandline args
|
||||||
|
while ((c = getopt(argc, argv, "hi:e:")) != -1) {
|
||||||
|
switch(c) {
|
||||||
|
case 'h':
|
||||||
|
usage(argv[0]);
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
max_instrs_per_run = strtoll(optarg, NULL, 10);
|
||||||
|
if (max_instrs_per_run < 1) {
|
||||||
|
usage(argv[0]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
extram_len = strtoll(optarg, NULL, 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (optind < argc) {
|
||||||
|
rom_filename = argv[optind];
|
||||||
|
} else {
|
||||||
|
usage(argv[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *rom = read_file(rom_filename, &romlen);
|
||||||
if (NULL == rom) {
|
if (NULL == rom) {
|
||||||
printf("file read failed!\n");
|
printf("file read failed!\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -168,10 +197,14 @@ int main(int argc, char *argv[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uvm32_evt_t evt;
|
if (extram_len > 0) {
|
||||||
bool isrunning = true;
|
extram_buf = (uint32_t *)malloc(extram_len);
|
||||||
uint32_t total_instrs = 0;
|
if (NULL == extram_buf) {
|
||||||
uint32_t num_syscalls = 0;
|
printf("Failed to allocate extram!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
uvm32_extram(&vmst, extram_buf, extram_len);
|
||||||
|
}
|
||||||
|
|
||||||
// setup terminal for getch()
|
// setup terminal for getch()
|
||||||
enableRawMode();
|
enableRawMode();
|
||||||
|
|
@ -254,6 +287,9 @@ int main(int argc, char *argv[]) {
|
||||||
printf("Executed total of %d instructions and %d syscalls\n", (int)total_instrs, (int)num_syscalls);
|
printf("Executed total of %d instructions and %d syscalls\n", (int)total_instrs, (int)num_syscalls);
|
||||||
|
|
||||||
free(rom);
|
free(rom);
|
||||||
|
if (extram_buf != NULL) {
|
||||||
|
free(extram_buf);
|
||||||
|
}
|
||||||
|
|
||||||
// put terminal back to how it was
|
// put terminal back to how it was
|
||||||
disableRawMode();
|
disableRawMode();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue