diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2020-05-15 18:41:36 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2020-05-15 18:41:36 +0200 |
commit | db0b5b08b866b914763017897ce8b095b37a75a9 (patch) | |
tree | c5c342e64067f854a7e2bceb67d0a89ca6050db6 | |
parent | ce9b01a0ec1f8ad127bcddb64ca2986e9b5c03fd (diff) | |
download | compilertests-db0b5b08b866b914763017897ce8b095b37a75a9.tar.gz compilertests-db0b5b08b866b914763017897ce8b095b37a75a9.tar.bz2 |
emul.c
- do not initialize memory (we have constants in the initialized data section!)
- use last 'hlt' instruction as a separator between code and data
-rw-r--r-- | ecomp-c/emul.c | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/ecomp-c/emul.c b/ecomp-c/emul.c index db63bc2..292002e 100644 --- a/ecomp-c/emul.c +++ b/ecomp-c/emul.c @@ -68,15 +68,15 @@ static void dump_stack( uc_engine *uc ) } } -static void initialize_memory( uc_engine *uc, uint64_t start_address, uint64_t end_address ) -{ - uint8_t mem[4]; +//~ static void initialize_memory( uc_engine *uc, uint64_t start_address, uint64_t end_address ) +//~ { + //~ uint8_t mem[4]; - memset( mem, 0, 4 ); - for( uint64_t a = start_address; a < end_address; a += 4 ) { - uc_mem_write( uc, a, &mem, 4 ); - } -} + //~ memset( mem, 0, 4 ); + //~ for( uint64_t a = start_address; a < end_address; a += 4 ) { + //~ uc_mem_write( uc, a, &mem, 4 ); + //~ } +//~ } static void dump_memory( uc_engine *uc, uint64_t start_address, uint64_t end_address ) { @@ -211,14 +211,32 @@ int main( int argc, char *argv[] ) for( int j = ( 16 - instrs[i].size ) * 2; j > 0; j-- ) { printf( " " ); } - if( instrs[i].size == 2 && instrs[i].bytes[0] == 0 && instrs[i].bytes[1] == 0 ) { - if( data_start == 0 ) { - data_start = instrs[i].address; - } - printf( "data\n" ); - } else { + + if( data_start == 0 ) { printf( "%s %s\n", instrs[i].mnemonic, instrs[i].op_str ); + } else { + printf( "data\n" ); } + + /* code and data segment are separated by a 'hlt' instruction, + * 'hlt' must not occur anywhere else and 'hlt' must be the + * last instruction in the code segment. + * Then we can calculate the beginning of the data segment + * (this is all needed as we have a flat binary format only) + */ + if( strcmp( instrs[i].mnemonic, "hlt" ) == 0 ) { + data_start = instrs[i].address + instrs[i].size; + } + + //~ } + //~ if( instrs[i].size == 2 && instrs[i].bytes[0] == 0 && instrs[i].bytes[1] == 0 ) { + //~ if( data_start == 0 ) { + //~ data_start = instrs[i].address; + //~ } + //~ exit( 1 ); + //~ printf( "data\n" ); + //~ } else { + //~ } } // remember address to instrs indexes so we can get the current @@ -263,10 +281,10 @@ int main( int argc, char *argv[] ) } // initialize memory (to make tests deterministic) - if( data_start == 0 ) { - data_start = CODE_START + code_size; - } - initialize_memory( uc, data_start, data_start + DATA_SIZE ); + //~ if( data_start == 0 ) { + //~ data_start = CODE_START + code_size; + //~ } + //~ initialize_memory( uc, data_start, data_start + DATA_SIZE ); // initialize stack pointer int addr = CODE_START; |