int main(int argc, char** argv){ if(argc != 2){ printf("Usage: sacs <source-file>\n"); return 0; } struct asm_binary* bin = asm_parse_file(argv[1]); mem_init(); mem_dynamic_alloc(0x400000,MEM_FAKE_ALLOC|MEM_USE_LOCKED); uint32_t loc = mem_dynamic_alloc(bin->size,MEM_USE_LOCKED); assert(loc == 0x400000); memcpy(mem_translate_addr(loc),bin->binary,bin->size); struct exec_stats_t* stats = exec_run(loc,loc,loc+bin->data_segment); mem_cleanup(); printf("C: %d\nIC: %d\nNOPs: %d\n",stats->c,stats->ic,stats->nopc); return 0; }
int main(void){ printf("Initializing\n"); mem_init(); printf("Allocating 1MB\n"); uint32_t loc = mem_dynamic_alloc(1<<20,0); printf("Got address 0x%X\n",loc); printf("Writing 192342\n"); mem_write32(loc,192343); printf("Reading...\n"); uint32_t result = mem_read32(loc); printf("Read %d\n",result); printf("Freeing\n"); mem_free(loc); printf("Cleaning up\n"); mem_cleanup(); return 0; }
void ctx_sample_task(void *argv) { UNUSED_PARAM(argv); uint32_t last_tick; uint32_t n = 0; uint32_t com = 0; uint32_t *ret_time = (uint32_t *)argv; MEM_TEST_NODE *mem; uint32_t mem_size; uint32_t total_allocated; uint32_t num_allocated, mem_num; MEM_TEST_LIST mem_test_list; ret_time[0] = 0; num_allocated = 0; total_allocated = 0; mem_test_list.head = mem_test_list.tail = NULL; /* Initialize random seed. */ srand(current_hardware_tick()); while(1) { n= n + 1; last_tick = current_hardware_tick(); task_yield(); if (com > 0x0FFFFFFF) { com = 0; n = 1; } last_tick = current_hardware_tick() - last_tick; if (last_tick < MAX_TIMER_TICKS) { com += last_tick; ret_time[0] = (com / n); } mem_size = (rand() % MAX_ALLOC) + sizeof(MEM_TEST_NODE); mem = (MEM_TEST_NODE *)mem_dynamic_alloc(mem_size); if (mem) { total_allocated += mem_size; mem->size = mem_size; sll_append(&mem_test_list, mem, OFFSETOF(MEM_TEST_NODE, next)); num_allocated++; } while ( (total_allocated > MEM_PER_TASK) || (mem == NULL) ) { mem_num = rand() % num_allocated; mem = sll_search_pop(&mem_test_list, pop_n, &mem_num, OFFSETOF(MEM_TEST_NODE, next)); if (mem) { total_allocated -= mem->size; num_allocated --; mem_dynamic_dealloc((uint8_t *)mem); } else { break; } } } }