#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* */ #define RAM_SIZE 0x20000 static uint8_t loc[RAM_SIZE]; void saveState(const char *fileName, void *buf, int size) { int ret, fd; assert(size > 0); fd = open(fileName, O_WRONLY | O_TRUNC | O_CREAT, 0644); assert(fd >= 0); cout << "size = " << size << endl; ret = write(fd, buf, size); cout << "ret = " << ret << endl; assert(ret == size); close(fd); } void store_inst(uint32_t inst, uint32_t offset) { uint32_t *addr = (uint32_t *)(loc + offset); *addr = inst; } int main(int argc, char *argv[]) { for(int idx = 0; idx < RAM_SIZE; idx++) { loc[idx] =0; } /* 10 10000 110000 00000 0 0000000000000 aa aabbb bccccd dddee e effffgggghhhh */ store_inst(0xa1800000, 0x0); /*wrasr r0 ; set asr16 to 0 */ /* 10 00001 101000 10000 0 0000000000000 aa aabbb bccccd dddee e effffgggghhhh */ store_inst(0x83440000, 0x4); /*rdasr r1 ; inc counter, put the current count in r1 */ /* 11 00001 000100 01000 1 0000000000000 aa aabbb bccccd dddee e effffgggghhhh*/ store_inst(0xc2222000, 0x8); /*st r1 [r8 + 0] ; Report a return value */ /* 10 00010 101000 10000 0 0000000000000 aa aabbb bccccd dddee e effffgggghhhh */ store_inst(0x85440000, 0xc); /*rdasr r2 ; inc counter, put the current count in r1 */ /* 11 00010 000100 01000 1 0000000000000 aa aabbb bccccd dddee e effffgggghhhh*/ store_inst(0xc4222000, 0x10); /*st r2 [r8 + 0] ; */ string memFileName = "asrMem.img"; saveState(memFileName.c_str(), loc, RAM_SIZE); }