From 953c02dfba25a021fd8e912db01e81ca34874931 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 8 Apr 2018 13:51:44 -0600 Subject: [PATCH] Update argument passing, add video resume --- fusee/fusee-primary/src/display/cfb_console.c | 80 +++++++++++++++++++ fusee/fusee-primary/src/display/video_fb.h | 4 + fusee/fusee-primary/src/main.c | 14 +++- fusee/fusee-primary/src/stage2.c | 18 +++-- fusee/fusee-primary/src/stage2.h | 19 +++-- .../fusee-secondary/src/display/cfb_console.c | 80 +++++++++++++++++++ fusee/fusee-secondary/src/display/video_fb.h | 4 + fusee/fusee-secondary/src/main.c | 8 +- fusee/fusee-secondary/src/stage2.h | 15 +++- fusee/fusee-secondary/src/utils.h | 6 +- .../fusee-tertiary/src/display/cfb_console.c | 80 +++++++++++++++++++ fusee/fusee-tertiary/src/display/video_fb.h | 4 + 12 files changed, 307 insertions(+), 25 deletions(-) diff --git a/fusee/fusee-primary/src/display/cfb_console.c b/fusee/fusee-primary/src/display/cfb_console.c index 906632748..65ef5462f 100644 --- a/fusee/fusee-primary/src/display/cfb_console.c +++ b/fusee/fusee-primary/src/display/cfb_console.c @@ -1462,6 +1462,86 @@ static void *video_logo (void) /*****************************************************************************/ +int video_resume(void *videobase, int row, int col) { + unsigned char color8; + + video_fb_address = videobase; +#ifdef CONFIG_VIDEO_HW_CURSOR + video_init_hw_cursor (VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT); +#endif + + /* Init drawing pats */ + switch (CONFIG_VIDEO_DATA_FORMAT) { + case GDF__8BIT_INDEX: + video_set_lut (0x01, CONSOLE_FG_COL, CONSOLE_FG_COL, CONSOLE_FG_COL); + video_set_lut (0x00, CONSOLE_BG_COL, CONSOLE_BG_COL, CONSOLE_BG_COL); + fgx = 0x01010101; + bgx = 0x00000000; + break; + case GDF__8BIT_332RGB: + color8 = ((CONSOLE_FG_COL & 0xe0) | + ((CONSOLE_FG_COL >> 3) & 0x1c) | CONSOLE_FG_COL >> 6); + fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8; + color8 = ((CONSOLE_BG_COL & 0xe0) | + ((CONSOLE_BG_COL >> 3) & 0x1c) | CONSOLE_BG_COL >> 6); + bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8; + break; + case GDF_15BIT_555RGB: + fgx = (((CONSOLE_FG_COL >> 3) << 26) | + ((CONSOLE_FG_COL >> 3) << 21) | ((CONSOLE_FG_COL >> 3) << 16) | + ((CONSOLE_FG_COL >> 3) << 10) | ((CONSOLE_FG_COL >> 3) << 5) | + (CONSOLE_FG_COL >> 3)); + bgx = (((CONSOLE_BG_COL >> 3) << 26) | + ((CONSOLE_BG_COL >> 3) << 21) | ((CONSOLE_BG_COL >> 3) << 16) | + ((CONSOLE_BG_COL >> 3) << 10) | ((CONSOLE_BG_COL >> 3) << 5) | + (CONSOLE_BG_COL >> 3)); + break; + case GDF_16BIT_565RGB: + fgx = (((CONSOLE_FG_COL >> 3) << 27) | + ((CONSOLE_FG_COL >> 2) << 21) | ((CONSOLE_FG_COL >> 3) << 16) | + ((CONSOLE_FG_COL >> 3) << 11) | ((CONSOLE_FG_COL >> 2) << 5) | + (CONSOLE_FG_COL >> 3)); + bgx = (((CONSOLE_BG_COL >> 3) << 27) | + ((CONSOLE_BG_COL >> 2) << 21) | ((CONSOLE_BG_COL >> 3) << 16) | + ((CONSOLE_BG_COL >> 3) << 11) | ((CONSOLE_BG_COL >> 2) << 5) | + (CONSOLE_BG_COL >> 3)); + break; + case GDF_32BIT_X888RGB: + fgx = (CONSOLE_FG_COL << 16) | (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL; + bgx = (CONSOLE_BG_COL << 16) | (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL; + break; + case GDF_24BIT_888RGB: + fgx = (CONSOLE_FG_COL << 24) | (CONSOLE_FG_COL << 16) | + (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL; + bgx = (CONSOLE_BG_COL << 24) | (CONSOLE_BG_COL << 16) | + (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL; + break; + } + eorx = fgx ^ bgx; + +#ifdef CONFIG_VIDEO_LOGO + /* Plot the logo and get start point of console */ + PRINTD ("Video: Drawing the logo ...\n"); + video_console_address = video_logo (); +#else + video_console_address = video_fb_address; +#endif + + /* Initialize the console */ + console_col = col; + console_row = row; + + return 0; +} + +int video_get_col(void) { + return console_col; +} + +int video_get_row(void) { + return console_row; +} + int video_init (void *videobase) { unsigned char color8; diff --git a/fusee/fusee-primary/src/display/video_fb.h b/fusee/fusee-primary/src/display/video_fb.h index 02ecee8dd..ebedc0626 100644 --- a/fusee/fusee-primary/src/display/video_fb.h +++ b/fusee/fusee-primary/src/display/video_fb.h @@ -47,7 +47,11 @@ #define CONFIG_VIDEO_PIXEL_SIZE 4 #define CONFIG_VIDEO_DATA_FORMAT GDF_32BIT_X888RGB /* BGR actually, but w/e */ +int video_get_col(void); +int video_get_row(void); + int video_init(void *fb); +int video_resume(void *fb, int row, int col); void video_puts(const char *s); #endif /*_VIDEO_FB_H_ */ diff --git a/fusee/fusee-primary/src/main.c b/fusee/fusee-primary/src/main.c index f8a12c5a8..95f376abc 100644 --- a/fusee/fusee-primary/src/main.c +++ b/fusee/fusee-primary/src/main.c @@ -89,10 +89,16 @@ int main(void) { /* Setup argv. */ memset(stage2_argv, 0, STAGE2_ARGC * sizeof(*stage2_argv)); - stage2_argv[STAGE2_ARGV_VERSION] = &stage2_argv[STAGE2_ARGC]; - *((u32 *)stage2_argv[STAGE2_ARGV_VERSION]) = 0; - stage2_argv[STAGE2_ARGV_CONFIG] = (void *)bct0; - stage2_argv[STAGE2_ARGV_LFB] = lfb_base; + stage2_argv[STAGE2_ARGV_PROGRAM_PATH] = (void *)stage2_get_program_path(); + stage2_argv[STAGE2_ARGV_ARGUMENT_STRUCT] = &stage2_argv[STAGE2_ARGC]; + stage2_args_t *args = (stage2_args_t *)stage2_argv[STAGE2_ARGV_ARGUMENT_STRUCT]; + + /* Setup arguments struct. */ + args->version = 0; + args->bct0 = bct0; + args->lfb = (uint32_t *)lfb_base; + args->console_col = video_get_col(); + args->console_row = video_get_row(); /* Jump to Stage 2. */ diff --git a/fusee/fusee-primary/src/stage2.c b/fusee/fusee-primary/src/stage2.c index 0eaa4b549..d6c02d241 100644 --- a/fusee/fusee-primary/src/stage2.c +++ b/fusee/fusee-primary/src/stage2.c @@ -6,12 +6,18 @@ #include "lib/vsprintf.h" #include "lib/ini.h" +char g_stage2_path[0x300] = {0}; + +const char *stage2_get_program_path(void) { + return g_stage2_path; +} + static int stage2_ini_handler(void *user, const char *section, const char *name, const char *value) { stage2_config_t *config = (stage2_config_t *)user; uintptr_t x = 0; if (strcmp(section, "stage1") == 0) { if (strcmp(name, STAGE2_NAME_KEY) == 0) { - strncpy(config->filename, value, sizeof(config->filename)); + strncpy(config->path, value, sizeof(config->path)); } else if (strcmp(name, STAGE2_ADDRESS_KEY) == 0) { /* Read in load address as a hex string. */ sscanf(value, "%x", &x); @@ -40,20 +46,22 @@ stage2_entrypoint_t load_stage2(const char *bct0) { generic_panic(); } - if (config.load_address == 0 || config.filename[0] == '\x00') { + if (config.load_address == 0 || config.path[0] == '\x00') { printk("Error: Failed to determine where to load stage2!\n"); generic_panic(); } printk("[DEBUG] Stage 2 Config:\n"); - printk(" Filename: %s\n", config.filename); + printk(" File Path: %s\n", config.path); printk(" Load Address: 0x%08x\n", config.load_address); printk(" Entrypoint: 0x%p\n", config.entrypoint); - if (!read_sd_file((void *)config.load_address, 0x100000, config.filename)) { - printk("Error: Failed to read stage2 (%s)!\n", config.filename); + if (!read_sd_file((void *)config.load_address, 0x100000, config.path)) { + printk("Error: Failed to read stage2 (%s)!\n", config.path); generic_panic(); } + strncpy(g_stage2_path, config.path, sizeof(g_stage2_path)); + return config.entrypoint; } diff --git a/fusee/fusee-primary/src/stage2.h b/fusee/fusee-primary/src/stage2.h index 536cd57f7..a243d53c5 100644 --- a/fusee/fusee-primary/src/stage2.h +++ b/fusee/fusee-primary/src/stage2.h @@ -4,11 +4,9 @@ #include "utils.h" /* TODO: Is there a more concise way to do this? */ -#define STAGE2_ARGV_VERSION 0 -#define STAGE2_ARGV_CONFIG 1 -#define STAGE2_ARGV_LFB 2 -#define STAGE2_ARGC 3 - +#define STAGE2_ARGV_PROGRAM_PATH 0 +#define STAGE2_ARGV_ARGUMENT_STRUCT 1 +#define STAGE2_ARGC 2 #define STAGE2_NAME_KEY "stage2_path" #define STAGE2_ADDRESS_KEY "stage2_addr" @@ -17,11 +15,20 @@ typedef void (*stage2_entrypoint_t)(int argc, void **argv); typedef struct { - char filename[0x300]; + char path[0x300]; uintptr_t load_address; stage2_entrypoint_t entrypoint; } stage2_config_t; +typedef struct { + uint32_t version; + const char *bct0; + uint32_t *lfb; + uint32_t console_row; + uint32_t console_col; +} stage2_args_t; + +const char *stage2_get_program_path(void); stage2_entrypoint_t load_stage2(const char *bct0); #endif \ No newline at end of file diff --git a/fusee/fusee-secondary/src/display/cfb_console.c b/fusee/fusee-secondary/src/display/cfb_console.c index 906632748..65ef5462f 100644 --- a/fusee/fusee-secondary/src/display/cfb_console.c +++ b/fusee/fusee-secondary/src/display/cfb_console.c @@ -1462,6 +1462,86 @@ static void *video_logo (void) /*****************************************************************************/ +int video_resume(void *videobase, int row, int col) { + unsigned char color8; + + video_fb_address = videobase; +#ifdef CONFIG_VIDEO_HW_CURSOR + video_init_hw_cursor (VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT); +#endif + + /* Init drawing pats */ + switch (CONFIG_VIDEO_DATA_FORMAT) { + case GDF__8BIT_INDEX: + video_set_lut (0x01, CONSOLE_FG_COL, CONSOLE_FG_COL, CONSOLE_FG_COL); + video_set_lut (0x00, CONSOLE_BG_COL, CONSOLE_BG_COL, CONSOLE_BG_COL); + fgx = 0x01010101; + bgx = 0x00000000; + break; + case GDF__8BIT_332RGB: + color8 = ((CONSOLE_FG_COL & 0xe0) | + ((CONSOLE_FG_COL >> 3) & 0x1c) | CONSOLE_FG_COL >> 6); + fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8; + color8 = ((CONSOLE_BG_COL & 0xe0) | + ((CONSOLE_BG_COL >> 3) & 0x1c) | CONSOLE_BG_COL >> 6); + bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8; + break; + case GDF_15BIT_555RGB: + fgx = (((CONSOLE_FG_COL >> 3) << 26) | + ((CONSOLE_FG_COL >> 3) << 21) | ((CONSOLE_FG_COL >> 3) << 16) | + ((CONSOLE_FG_COL >> 3) << 10) | ((CONSOLE_FG_COL >> 3) << 5) | + (CONSOLE_FG_COL >> 3)); + bgx = (((CONSOLE_BG_COL >> 3) << 26) | + ((CONSOLE_BG_COL >> 3) << 21) | ((CONSOLE_BG_COL >> 3) << 16) | + ((CONSOLE_BG_COL >> 3) << 10) | ((CONSOLE_BG_COL >> 3) << 5) | + (CONSOLE_BG_COL >> 3)); + break; + case GDF_16BIT_565RGB: + fgx = (((CONSOLE_FG_COL >> 3) << 27) | + ((CONSOLE_FG_COL >> 2) << 21) | ((CONSOLE_FG_COL >> 3) << 16) | + ((CONSOLE_FG_COL >> 3) << 11) | ((CONSOLE_FG_COL >> 2) << 5) | + (CONSOLE_FG_COL >> 3)); + bgx = (((CONSOLE_BG_COL >> 3) << 27) | + ((CONSOLE_BG_COL >> 2) << 21) | ((CONSOLE_BG_COL >> 3) << 16) | + ((CONSOLE_BG_COL >> 3) << 11) | ((CONSOLE_BG_COL >> 2) << 5) | + (CONSOLE_BG_COL >> 3)); + break; + case GDF_32BIT_X888RGB: + fgx = (CONSOLE_FG_COL << 16) | (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL; + bgx = (CONSOLE_BG_COL << 16) | (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL; + break; + case GDF_24BIT_888RGB: + fgx = (CONSOLE_FG_COL << 24) | (CONSOLE_FG_COL << 16) | + (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL; + bgx = (CONSOLE_BG_COL << 24) | (CONSOLE_BG_COL << 16) | + (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL; + break; + } + eorx = fgx ^ bgx; + +#ifdef CONFIG_VIDEO_LOGO + /* Plot the logo and get start point of console */ + PRINTD ("Video: Drawing the logo ...\n"); + video_console_address = video_logo (); +#else + video_console_address = video_fb_address; +#endif + + /* Initialize the console */ + console_col = col; + console_row = row; + + return 0; +} + +int video_get_col(void) { + return console_col; +} + +int video_get_row(void) { + return console_row; +} + int video_init (void *videobase) { unsigned char color8; diff --git a/fusee/fusee-secondary/src/display/video_fb.h b/fusee/fusee-secondary/src/display/video_fb.h index 02ecee8dd..ebedc0626 100644 --- a/fusee/fusee-secondary/src/display/video_fb.h +++ b/fusee/fusee-secondary/src/display/video_fb.h @@ -47,7 +47,11 @@ #define CONFIG_VIDEO_PIXEL_SIZE 4 #define CONFIG_VIDEO_DATA_FORMAT GDF_32BIT_X888RGB /* BGR actually, but w/e */ +int video_get_col(void); +int video_get_row(void); + int video_init(void *fb); +int video_resume(void *fb, int row, int col); void video_puts(const char *s); #endif /*_VIDEO_FB_H_ */ diff --git a/fusee/fusee-secondary/src/main.c b/fusee/fusee-secondary/src/main.c index 384edde7e..ddb735f5f 100644 --- a/fusee/fusee-secondary/src/main.c +++ b/fusee/fusee-secondary/src/main.c @@ -11,8 +11,9 @@ int main(int argc, void **argv) { entrypoint_t entrypoint; + stage2_args_t *args; - if (argc != STAGE2_ARGC || *((u32 *)argv[STAGE2_ARGV_VERSION]) != 0) { + if (argc != STAGE2_ARGC || ((args = (stage2_args_t *)argv[STAGE2_ARGV_ARGUMENT_STRUCT])->version != 0)) { generic_panic(); } @@ -20,12 +21,13 @@ int main(int argc, void **argv) { /* Setup LFB. */ /* TODO: How can we keep the console line/offset to resume printing? */ - video_init((u32 *)argv[STAGE2_ARGV_LFB]); + video_resume(args->lfb, args->console_row, args->console_col); printk("Welcome to Atmosph\xe8re Fus\xe9" "e Stage 2!\n"); + printk("Stage 2 executing from: %s\n", (const char *)argv[STAGE2_ARGV_PROGRAM_PATH]); /* This will load all remaining binaries off of the SD. */ - entrypoint = load_payload((const char *)argv[STAGE2_ARGV_CONFIG]); + entrypoint = load_payload(args->bct0); /* TODO: What do we want to do in terms of argc/argv? */ entrypoint(0, NULL); diff --git a/fusee/fusee-secondary/src/stage2.h b/fusee/fusee-secondary/src/stage2.h index e7ddb1a87..7ddce9c90 100644 --- a/fusee/fusee-secondary/src/stage2.h +++ b/fusee/fusee-secondary/src/stage2.h @@ -4,9 +4,16 @@ #include "utils.h" /* TODO: Is there a more concise way to do this? */ -#define STAGE2_ARGV_VERSION 0 -#define STAGE2_ARGV_CONFIG 1 -#define STAGE2_ARGV_LFB 2 -#define STAGE2_ARGC 3 +#define STAGE2_ARGV_PROGRAM_PATH 0 +#define STAGE2_ARGV_ARGUMENT_STRUCT 1 +#define STAGE2_ARGC 2 + +typedef struct { + uint32_t version; + const char *bct0; + uint32_t *lfb; + uint32_t console_row; + uint32_t console_col; +} stage2_args_t; #endif \ No newline at end of file diff --git a/fusee/fusee-secondary/src/utils.h b/fusee/fusee-secondary/src/utils.h index 5a288717d..535323795 100644 --- a/fusee/fusee-secondary/src/utils.h +++ b/fusee/fusee-secondary/src/utils.h @@ -69,9 +69,9 @@ static inline bool check_32bit_additive_overflow(uint32_t a, uint32_t b) { return __builtin_add_overflow_p(a, b, (uint32_t)0); } -void panic(uint32_t code); -void generic_panic(void); -void panic_predefined(uint32_t which); +__attribute__ ((noreturn)) void panic(uint32_t code); +__attribute__ ((noreturn)) void generic_panic(void); +__attribute__ ((noreturn)) void panic_predefined(uint32_t which); bool overlaps(uint64_t as, uint64_t ae, uint64_t bs, uint64_t be); #endif diff --git a/fusee/fusee-tertiary/src/display/cfb_console.c b/fusee/fusee-tertiary/src/display/cfb_console.c index 906632748..65ef5462f 100644 --- a/fusee/fusee-tertiary/src/display/cfb_console.c +++ b/fusee/fusee-tertiary/src/display/cfb_console.c @@ -1462,6 +1462,86 @@ static void *video_logo (void) /*****************************************************************************/ +int video_resume(void *videobase, int row, int col) { + unsigned char color8; + + video_fb_address = videobase; +#ifdef CONFIG_VIDEO_HW_CURSOR + video_init_hw_cursor (VIDEO_FONT_WIDTH, VIDEO_FONT_HEIGHT); +#endif + + /* Init drawing pats */ + switch (CONFIG_VIDEO_DATA_FORMAT) { + case GDF__8BIT_INDEX: + video_set_lut (0x01, CONSOLE_FG_COL, CONSOLE_FG_COL, CONSOLE_FG_COL); + video_set_lut (0x00, CONSOLE_BG_COL, CONSOLE_BG_COL, CONSOLE_BG_COL); + fgx = 0x01010101; + bgx = 0x00000000; + break; + case GDF__8BIT_332RGB: + color8 = ((CONSOLE_FG_COL & 0xe0) | + ((CONSOLE_FG_COL >> 3) & 0x1c) | CONSOLE_FG_COL >> 6); + fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8; + color8 = ((CONSOLE_BG_COL & 0xe0) | + ((CONSOLE_BG_COL >> 3) & 0x1c) | CONSOLE_BG_COL >> 6); + bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | color8; + break; + case GDF_15BIT_555RGB: + fgx = (((CONSOLE_FG_COL >> 3) << 26) | + ((CONSOLE_FG_COL >> 3) << 21) | ((CONSOLE_FG_COL >> 3) << 16) | + ((CONSOLE_FG_COL >> 3) << 10) | ((CONSOLE_FG_COL >> 3) << 5) | + (CONSOLE_FG_COL >> 3)); + bgx = (((CONSOLE_BG_COL >> 3) << 26) | + ((CONSOLE_BG_COL >> 3) << 21) | ((CONSOLE_BG_COL >> 3) << 16) | + ((CONSOLE_BG_COL >> 3) << 10) | ((CONSOLE_BG_COL >> 3) << 5) | + (CONSOLE_BG_COL >> 3)); + break; + case GDF_16BIT_565RGB: + fgx = (((CONSOLE_FG_COL >> 3) << 27) | + ((CONSOLE_FG_COL >> 2) << 21) | ((CONSOLE_FG_COL >> 3) << 16) | + ((CONSOLE_FG_COL >> 3) << 11) | ((CONSOLE_FG_COL >> 2) << 5) | + (CONSOLE_FG_COL >> 3)); + bgx = (((CONSOLE_BG_COL >> 3) << 27) | + ((CONSOLE_BG_COL >> 2) << 21) | ((CONSOLE_BG_COL >> 3) << 16) | + ((CONSOLE_BG_COL >> 3) << 11) | ((CONSOLE_BG_COL >> 2) << 5) | + (CONSOLE_BG_COL >> 3)); + break; + case GDF_32BIT_X888RGB: + fgx = (CONSOLE_FG_COL << 16) | (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL; + bgx = (CONSOLE_BG_COL << 16) | (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL; + break; + case GDF_24BIT_888RGB: + fgx = (CONSOLE_FG_COL << 24) | (CONSOLE_FG_COL << 16) | + (CONSOLE_FG_COL << 8) | CONSOLE_FG_COL; + bgx = (CONSOLE_BG_COL << 24) | (CONSOLE_BG_COL << 16) | + (CONSOLE_BG_COL << 8) | CONSOLE_BG_COL; + break; + } + eorx = fgx ^ bgx; + +#ifdef CONFIG_VIDEO_LOGO + /* Plot the logo and get start point of console */ + PRINTD ("Video: Drawing the logo ...\n"); + video_console_address = video_logo (); +#else + video_console_address = video_fb_address; +#endif + + /* Initialize the console */ + console_col = col; + console_row = row; + + return 0; +} + +int video_get_col(void) { + return console_col; +} + +int video_get_row(void) { + return console_row; +} + int video_init (void *videobase) { unsigned char color8; diff --git a/fusee/fusee-tertiary/src/display/video_fb.h b/fusee/fusee-tertiary/src/display/video_fb.h index 02ecee8dd..ebedc0626 100644 --- a/fusee/fusee-tertiary/src/display/video_fb.h +++ b/fusee/fusee-tertiary/src/display/video_fb.h @@ -47,7 +47,11 @@ #define CONFIG_VIDEO_PIXEL_SIZE 4 #define CONFIG_VIDEO_DATA_FORMAT GDF_32BIT_X888RGB /* BGR actually, but w/e */ +int video_get_col(void); +int video_get_row(void); + int video_init(void *fb); +int video_resume(void *fb, int row, int col); void video_puts(const char *s); #endif /*_VIDEO_FB_H_ */