Skip to content

Commit

Permalink
Add printf and log functions to the grass layer
Browse files Browse the repository at this point in the history
  • Loading branch information
yhzhang0128 committed Jan 19, 2022
1 parent ceb7fba commit c88238e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
8 changes: 7 additions & 1 deletion earth/earth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
6 changes: 5 additions & 1 deletion grass/grass.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
* spawns some kernel processes, including file system and shell
*/

#include <stdlib.h>
#include "egos.h"
#include "grass.h"

struct earth *earth = (void*)EARTH_ADDR;

int global_var1;
int global_var2;
Expand All @@ -21,5 +24,6 @@ int main() {

char* buf = malloc(512);
free(buf);
SUCCESS("Within grass kernel with stack variable @0x%.8x", &buf);
return 0;
}
12 changes: 12 additions & 0 deletions grass/grass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <stdlib.h>

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
16 changes: 15 additions & 1 deletion shared/include/egos.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
#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);

int (*intr_enable)();
int (*intr_disable)();
int (*intr_register)(int id, handler_t handler);

struct dev_log log;
};

/* Interface between grass and apps */

0 comments on commit c88238e

Please sign in to comment.