static void log_output( int is_trace, int (*head_build)(char*,size_t,const void*,size_t), void* addr, size_t size) { char msg[MAX_MESSAGE_SIZE]; struct timeval tv; struct tm tm; gettimeofday(&tv, NULL); int msgsize = strftime(msg, sizeof(msg), "%Y-%m-%dT%H:%M:%S", localtime_r(&tv.tv_sec, &tm)); msgsize += sprintf(&msg[msgsize], ".%06d\t", (int)tv.tv_usec); msgsize += head_build(&msg[msgsize], sizeof(msg) - msgsize, addr, size); if (is_trace) { void* trace[MAX_BACKTRACE_SIZE]; memset(trace, 0, sizeof(trace)); const int num_bt = backtrace(trace, MAX_BACKTRACE_SIZE); char** const trace_str = backtrace_symbols(trace, MAX_BACKTRACE_SIZE); int i; for (i = 2/*remove this module*/; i < num_bt; ++i) { const size_t btstrsize = strlen(trace_str[i]); if (MAX_MESSAGE_SIZE < (btstrsize + msgsize)) { break; } strncat(msg, "\t", 1); strncat(msg, trace_str[i], btstrsize); msgsize += btstrsize + 1; } if (trace_str) { origin_free(trace_str); } } strncat(msg, "\n", 1); ++msgsize; write(malloc_wapper_logfd, msg, msgsize); }
int main(int argc, char **argv) { printf("\33[0;40;33m\n"); printf(" FemtoForth Copyright (C) 2014 Victor Yurkovsky\n"); printf(" This program comes with ABSOLUTELY NO WARRANTY'.\n"); printf(" This is free software, and you are welcome to redistribute it\n"); printf(" under certain conditions; type 'license' for details.\n\n"); color(COLOR_RESET);color(FORE_WHITE); //--------------------------------------------------------------------- // Data segment. Houses var at the bottom... // // memmap data segment U8* data_base = mmap((void*)0x04000000, CODE_SIZE, PROT_READ+PROT_WRITE+PROT_EXEC, MAP_ANONYMOUS|MAP_PRIVATE|MAP_FIXED, 0,0); //var structure is placed into bottom RESERVED (512) bytes of data! lay = (sMemLayout*)data_base; // HOST_RESERVED bytes var = (sVar*)(data_base+HOST_RESERVED); // SYS_RESERVED bytes // install system var structure at bottom lay->data_bottom = data_base; lay->data_top = data_base + CODE_SIZE; // var->data_ptr = lay->data_bottom + HOST_RESERVED + SYS_RESERVED; printf("data at %p->%p ",lay->data_bottom,lay->data_top); //--------------------------------------------------------------------- // Table - runtime // lay->table_bottom = mmap((U8**)(CODE_ADDRESS/4), sizeof(TINDEX)*TABLE_SIZE, PROT_READ+PROT_WRITE+PROT_EXEC, MAP_ANONYMOUS|MAP_SHARED|MAP_FIXED, 0,0); printf("TABLE at %p ",lay->table_bottom); lay->table_top = (U8*)lay->table_bottom + sizeof(TINDEX)*TABLE_SIZE; // var->table_ptr = (U8**)var->table_bottom; // *var->table_ptr++ = 0 ; //first table entry is always 0 ! //--------------------------------------------------------------------- // DSP // // lay->dsp_bottom = (U8*)malloc(DSP_SIZE); lay->dsp_top = lay->dsp_bottom + DSP_SIZE; printf("DSP at %p ",lay->dsp_top); //--------------------------------------------------------------------- // RSP lay->rsp_bottom = (U8*)malloc(RSP_SIZE); lay->rsp_top = lay->rsp_bottom + RSP_SIZE; var->sp_meow = (sRegsMM*)lay->rsp_top; printf("RSP at %p ",lay->rsp_top); //--------------------------------------------------------------------- // HEAD lay->head_bottom = (U8*)malloc(HEAD_SIZE); lay->head_top = lay->head_bottom + HEAD_SIZE; var->head_ptr = lay->head_bottom; printf("HEAD at %p \n",lay->head_bottom); //--------------------------------------------------------------------- // SRC lay->src_bottom = (char*)malloc(256); src_reset(); head_build(); // printf("data pointer is now at %p\n",var->data_ptr); kernel_load(); // printf("data pointer is now at %p\n",var->data_ptr); cmd_init(); lang_init(); // int i; //for(i=0;i<20;i++) // U32 qqq = xxx(0x3456,0x1234); // printf("bindings returns %x\n",1); interpret_init(); // src_error("ass"); // call_meow(); while(1) interpret_outer(); // line(); // int z = armFunction(99); // printf("assembly returnst %d\n",z); exit(0); }