#include #include #include #include #include #include #include #include #include #include "elf_loader.h" enum { MSGTYPE_KERNEL_FINISHED = 0x01, MSGTYPE_RPC_REQUEST = 0x02, }; 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 send_sync(void) { send_int(0x5a5a5a5a); } static int download_kernel(void *buffer, int maxlength) { int length; int i; unsigned char *_buffer = buffer; receive_sync(); length = receive_int(); if(length > maxlength) return -1; for(i=0;i 0) { if(load_elf(syscalls, kbuf, length, kcode, sizeof(kcode))) { flush_cpu_icache(); k(); send_sync(); send_char(MSGTYPE_KERNEL_FINISHED); } } } return 0; }