/* kergen.c: Generates a memory image containing the Flight kernel */ /* Charles Eric LaForest, April 2008 */ /* laforest AT eecg.utoronto.ca */ #include "params.h" #include #include #include /*Initialize memory, compile code*/ int *kergen (int mem_size, int kernel_size) { int *mem; #define MEM_SIZE_CHAR (sizeof(int) * mem_size) mem = (int *) malloc (MEM_SIZE_CHAR); memset ((char *) mem, 0, MEM_SIZE_CHAR); /* These make up a simple assembler for the virtual machine. So far, this has been tested on x86 and Sparc. */ /*Literal*/ #define L(number) \ mem[here] = (number); here++; /*Instruction packing into an int*/ #define I(zero, one, two, three, four, five) \ (zero & OPCODE_MASK) | \ ((one & OPCODE_MASK) << OPCODE_WIDTH) | \ ((two & OPCODE_MASK) << (OPCODE_WIDTH * 2)) | \ ((three & OPCODE_MASK) << (OPCODE_WIDTH * 3)) | \ ((four & OPCODE_MASK) << (OPCODE_WIDTH * 4)) | \ ((five & OPCODE_MASK) << (OPCODE_WIDTH * 5)) /*Group of instructions*/ #define G(zero, one, two, three, four, five) \ L(I(zero,one,two,three,four,five)) /*Name the current location*/ #define N(name) \ int name = here-1; /*Resolve address of name (set named location to current compilation location)*/ #define R(name) \ mem[name] = here-1; /*Define a name (creates a dictionary entry)*/ #define D(name) \ N(name) \ char *name ## _string = #name; \ len = strlen(name ## _string); \ mem[there] = name; \ there -= len; \ mem[there-1] = len; \ for(i=0;i