From d15276557c65de2a1941632ec9024dea261cce26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20B=C3=B6hm?= Date: Tue, 7 Jul 2009 09:46:27 +0200 Subject: make instruction 64-bit wide to support more than 32 registers --- src/emu/risci.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/emu/risci.c') diff --git a/src/emu/risci.c b/src/emu/risci.c index 704ece8..1711089 100644 --- a/src/emu/risci.c +++ b/src/emu/risci.c @@ -17,8 +17,8 @@ #include "opc.h" bool is_debug = false; -size_t mem_size = 64 * 1024 * 1024; -size_t reg_size = 0; +uint64_t mem_size = 64 * 1024 * 1024; +uint64_t reg_size = 0; static void usage(int rc) @@ -42,17 +42,17 @@ void read_program(const char *program) if (lstat(program, &sb) == -1) pdie("cannot stat program"); - if (sb.st_size % 4) - die("program does not align to op-code size of 4 bytes"); + if (sb.st_size % sizeof(inst_t)) + die("program does not align to instruction size of %zu bytes", sizeof(inst_t)); int pfd; if ((pfd = open(program, O_RDONLY)) == -1) pdie("could not open program"); /* initialize register file */ - assert(read(pfd, ®_size, 4) == 4); + assert(read(pfd, ®_size, sizeof(inst_t)) == sizeof(inst_t)); reg_size += 4; - GPR = calloc(reg_size, 4); + GPR = calloc(reg_size, sizeof(uint32_t)); /* initialize pseudo registers */ BP = reg_size - 3; @@ -61,15 +61,15 @@ void read_program(const char *program) GPR[BP] = GPR[SP] = mem_size; GPR[RV] = 0; - assert(read(pfd, MEM, sb.st_size - 4) == sb.st_size - 4); - memset(MEM + sb.st_size + 4, 0xFF, 4); + assert(read(pfd, MEM, sb.st_size - sizeof(inst_t)) == (ssize_t)(sb.st_size - sizeof(inst_t))); + memset(MEM + sb.st_size, 0xFF, sizeof(inst_t)); } static -uint32_t next_instruction(void) +inst_t next_instruction(void) { - uint32_t tmp; - memcpy(&tmp, &MEM[IP], 4); + inst_t tmp; + memcpy(&tmp, &MEM[IP], sizeof(inst_t)); return tmp; } @@ -85,7 +85,7 @@ int main(int argc, char *argv[]) case 'h': usage(EXIT_SUCCESS); case 'm': - mem_size = atoi(optarg) * 4; + mem_size = atoi(optarg) * sizeof(uint32_t); break; case '?': default: @@ -97,7 +97,7 @@ int main(int argc, char *argv[]) argv += optind; /* reserve memory */ - MEM = calloc(mem_size, sizeof(char)); + MEM = calloc(mem_size, sizeof(uint8_t)); /* load program from file */ if (argc < 1) -- cgit v1.2.3