#include #include #include #include #include "corecom.h" /* host to device */ enum { MSGTYPE_REQUEST_IDENT = 1, MSGTYPE_LOAD_OBJECT, MSGTYPE_RUN_KERNEL, }; /* device to host */ enum { MSGTYPE_LOG = 1, MSGTYPE_MESSAGE_UNRECOGNIZED, MSGTYPE_IDENT, MSGTYPE_OBJECT_LOADED, MSGTYPE_INCORRECT_LENGTH, MSGTYPE_CRC_FAILED, MSGTYPE_OBJECT_UNRECOGNIZED, MSGTYPE_KERNEL_FINISHED, MSGTYPE_KERNEL_EXCEPTION, MSGTYPE_KERNEL_STARTUP_FAILED, MSGTYPE_RPC_REQUEST, }; static int receive_int(void) { unsigned int r; int i; r = 0; for(i=0;i<4;i++) { r <<= 8; r |= (unsigned char)uart_read(); } return r; } static char receive_char(void) { return uart_read(); } static void send_int(int x) { int i; for(i=0;i<4;i++) { uart_write((x & 0xff000000) >> 24); x <<= 8; } } static void send_sint(short int i) { uart_write((i >> 8) & 0xff); uart_write(i & 0xff); } static void send_char(char c) { uart_write(c); } static void receive_sync(void) { char c; int recognized; recognized = 0; while(recognized < 4) { c = uart_read(); if(c == 0x5a) recognized++; else recognized = 0; } } static void receive_and_load_object(object_loader load_object) { int length; int i; unsigned char buffer[256*1024]; unsigned int crc; length = receive_int(); if(length > sizeof(buffer)) { send_char(MSGTYPE_INCORRECT_LENGTH); return; } crc = receive_int(); for(i=0;i (sizeof(kernel_name)-1)) { send_char(MSGTYPE_INCORRECT_LENGTH); return; } for(i=0;i