diff --git a/earth/earth.c b/earth/earth.c index 4e012a6c..b788c278 100644 --- a/earth/earth.c +++ b/earth/earth.c @@ -24,7 +24,7 @@ int main() { /* Put earth interface to a widely known address */ memcpy((void*)EARTH_ADDR, &earth, sizeof(earth)); - INFO("Put earth interface at 0x%.8x with size %d", EARTH_ADDR, sizeof(earth)); + INFO("Put earth interface at 0x%.8x with size 0x%x", EARTH_ADDR, sizeof(earth)); INFO("Start to load the grass layer"); return 0; @@ -59,5 +59,11 @@ int earth_init() { earth.intr_register = intr_register; SUCCESS("Finished initializing the CPU interrupts"); + earth.log.log_info = INFO; + earth.log.log_highlight = HIGHLIGHT; + earth.log.log_success = SUCCESS; + earth.log.log_error = ERROR; + earth.log.log_fatal = FATAL; + return 0; } diff --git a/grass/grass.c b/grass/grass.c index bc315132..3bfa586e 100644 --- a/grass/grass.c +++ b/grass/grass.c @@ -8,7 +8,10 @@ * spawns some kernel processes, including file system and shell */ -#include +#include "egos.h" +#include "grass.h" + +struct earth *earth = (void*)EARTH_ADDR; int global_var1; int global_var2; @@ -21,5 +24,6 @@ int main() { char* buf = malloc(512); free(buf); + SUCCESS("Within grass kernel with stack variable @0x%.8x", &buf); return 0; } diff --git a/grass/grass.h b/grass/grass.h new file mode 100644 index 00000000..bea60e14 --- /dev/null +++ b/grass/grass.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +extern struct earth *earth; +#define printf earth->tty_write + +#define INFO earth->log.log_info +#define HIGHLIGHT earth->log.log_highlight +#define SUCCESS earth->log.log_success +#define ERROR earth->log.log_error +#define FATAL earth->log.log_fatal diff --git a/shared/include/egos.h b/shared/include/egos.h index f2aedda2..11f99ef2 100644 --- a/shared/include/egos.h +++ b/shared/include/egos.h @@ -1,14 +1,24 @@ #pragma once +/* Interface between earth and grass */ + #define TIMER_INTR_ID 7 #define QUANTUM_NCYCLES 2000 #define EARTH_ADDR (0x8004000 - 0x40) typedef void (*handler_t)(int, void*); +struct dev_log { + int (*log_info)(const char *format, ...); + int (*log_highlight)(const char *format, ...); + int (*log_success)(const char *format, ...); + int (*log_error)(const char *format, ...); + int (*log_fatal)(const char *format, ...); +}; + struct earth { int (*tty_read)(char* buf, int len); - int (*tty_write)(const char *format, ...); + int (*tty_write)(const char *format, ...); int (*disk_read)(int block_no, int nblocks, char* dst); int (*disk_write)(int block_no, int nblocks, char* src); @@ -16,4 +26,8 @@ struct earth { int (*intr_enable)(); int (*intr_disable)(); int (*intr_register)(int id, handler_t handler); + + struct dev_log log; }; + +/* Interface between grass and apps */