Update argument passing, add video resume

This commit is contained in:
Michael Scire 2018-04-08 13:51:44 -06:00
parent 82552b5a89
commit 953c02dfba
12 changed files with 307 additions and 25 deletions

View File

@ -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) int video_init (void *videobase)
{ {
unsigned char color8; unsigned char color8;

View File

@ -47,7 +47,11 @@
#define CONFIG_VIDEO_PIXEL_SIZE 4 #define CONFIG_VIDEO_PIXEL_SIZE 4
#define CONFIG_VIDEO_DATA_FORMAT GDF_32BIT_X888RGB /* BGR actually, but w/e */ #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_init(void *fb);
int video_resume(void *fb, int row, int col);
void video_puts(const char *s); void video_puts(const char *s);
#endif /*_VIDEO_FB_H_ */ #endif /*_VIDEO_FB_H_ */

View File

@ -89,10 +89,16 @@ int main(void) {
/* Setup argv. */ /* Setup argv. */
memset(stage2_argv, 0, STAGE2_ARGC * sizeof(*stage2_argv)); memset(stage2_argv, 0, STAGE2_ARGC * sizeof(*stage2_argv));
stage2_argv[STAGE2_ARGV_VERSION] = &stage2_argv[STAGE2_ARGC]; stage2_argv[STAGE2_ARGV_PROGRAM_PATH] = (void *)stage2_get_program_path();
*((u32 *)stage2_argv[STAGE2_ARGV_VERSION]) = 0; stage2_argv[STAGE2_ARGV_ARGUMENT_STRUCT] = &stage2_argv[STAGE2_ARGC];
stage2_argv[STAGE2_ARGV_CONFIG] = (void *)bct0; stage2_args_t *args = (stage2_args_t *)stage2_argv[STAGE2_ARGV_ARGUMENT_STRUCT];
stage2_argv[STAGE2_ARGV_LFB] = lfb_base;
/* 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. */ /* Jump to Stage 2. */

View File

@ -6,12 +6,18 @@
#include "lib/vsprintf.h" #include "lib/vsprintf.h"
#include "lib/ini.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) { static int stage2_ini_handler(void *user, const char *section, const char *name, const char *value) {
stage2_config_t *config = (stage2_config_t *)user; stage2_config_t *config = (stage2_config_t *)user;
uintptr_t x = 0; uintptr_t x = 0;
if (strcmp(section, "stage1") == 0) { if (strcmp(section, "stage1") == 0) {
if (strcmp(name, STAGE2_NAME_KEY) == 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) { } else if (strcmp(name, STAGE2_ADDRESS_KEY) == 0) {
/* Read in load address as a hex string. */ /* Read in load address as a hex string. */
sscanf(value, "%x", &x); sscanf(value, "%x", &x);
@ -40,20 +46,22 @@ stage2_entrypoint_t load_stage2(const char *bct0) {
generic_panic(); 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"); printk("Error: Failed to determine where to load stage2!\n");
generic_panic(); generic_panic();
} }
printk("[DEBUG] Stage 2 Config:\n"); 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(" Load Address: 0x%08x\n", config.load_address);
printk(" Entrypoint: 0x%p\n", config.entrypoint); printk(" Entrypoint: 0x%p\n", config.entrypoint);
if (!read_sd_file((void *)config.load_address, 0x100000, config.filename)) { if (!read_sd_file((void *)config.load_address, 0x100000, config.path)) {
printk("Error: Failed to read stage2 (%s)!\n", config.filename); printk("Error: Failed to read stage2 (%s)!\n", config.path);
generic_panic(); generic_panic();
} }
strncpy(g_stage2_path, config.path, sizeof(g_stage2_path));
return config.entrypoint; return config.entrypoint;
} }

View File

@ -4,11 +4,9 @@
#include "utils.h" #include "utils.h"
/* TODO: Is there a more concise way to do this? */ /* TODO: Is there a more concise way to do this? */
#define STAGE2_ARGV_VERSION 0 #define STAGE2_ARGV_PROGRAM_PATH 0
#define STAGE2_ARGV_CONFIG 1 #define STAGE2_ARGV_ARGUMENT_STRUCT 1
#define STAGE2_ARGV_LFB 2 #define STAGE2_ARGC 2
#define STAGE2_ARGC 3
#define STAGE2_NAME_KEY "stage2_path" #define STAGE2_NAME_KEY "stage2_path"
#define STAGE2_ADDRESS_KEY "stage2_addr" #define STAGE2_ADDRESS_KEY "stage2_addr"
@ -17,11 +15,20 @@
typedef void (*stage2_entrypoint_t)(int argc, void **argv); typedef void (*stage2_entrypoint_t)(int argc, void **argv);
typedef struct { typedef struct {
char filename[0x300]; char path[0x300];
uintptr_t load_address; uintptr_t load_address;
stage2_entrypoint_t entrypoint; stage2_entrypoint_t entrypoint;
} stage2_config_t; } 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); stage2_entrypoint_t load_stage2(const char *bct0);
#endif #endif

View File

@ -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) int video_init (void *videobase)
{ {
unsigned char color8; unsigned char color8;

View File

@ -47,7 +47,11 @@
#define CONFIG_VIDEO_PIXEL_SIZE 4 #define CONFIG_VIDEO_PIXEL_SIZE 4
#define CONFIG_VIDEO_DATA_FORMAT GDF_32BIT_X888RGB /* BGR actually, but w/e */ #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_init(void *fb);
int video_resume(void *fb, int row, int col);
void video_puts(const char *s); void video_puts(const char *s);
#endif /*_VIDEO_FB_H_ */ #endif /*_VIDEO_FB_H_ */

View File

@ -11,8 +11,9 @@
int main(int argc, void **argv) { int main(int argc, void **argv) {
entrypoint_t entrypoint; 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(); generic_panic();
} }
@ -20,12 +21,13 @@ int main(int argc, void **argv) {
/* Setup LFB. */ /* Setup LFB. */
/* TODO: How can we keep the console line/offset to resume printing? */ /* 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("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. */ /* 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? */ /* TODO: What do we want to do in terms of argc/argv? */
entrypoint(0, NULL); entrypoint(0, NULL);

View File

@ -4,9 +4,16 @@
#include "utils.h" #include "utils.h"
/* TODO: Is there a more concise way to do this? */ /* TODO: Is there a more concise way to do this? */
#define STAGE2_ARGV_VERSION 0 #define STAGE2_ARGV_PROGRAM_PATH 0
#define STAGE2_ARGV_CONFIG 1 #define STAGE2_ARGV_ARGUMENT_STRUCT 1
#define STAGE2_ARGV_LFB 2 #define STAGE2_ARGC 2
#define STAGE2_ARGC 3
typedef struct {
uint32_t version;
const char *bct0;
uint32_t *lfb;
uint32_t console_row;
uint32_t console_col;
} stage2_args_t;
#endif #endif

View File

@ -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); return __builtin_add_overflow_p(a, b, (uint32_t)0);
} }
void panic(uint32_t code); __attribute__ ((noreturn)) void panic(uint32_t code);
void generic_panic(void); __attribute__ ((noreturn)) void generic_panic(void);
void panic_predefined(uint32_t which); __attribute__ ((noreturn)) void panic_predefined(uint32_t which);
bool overlaps(uint64_t as, uint64_t ae, uint64_t bs, uint64_t be); bool overlaps(uint64_t as, uint64_t ae, uint64_t bs, uint64_t be);
#endif #endif

View File

@ -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) int video_init (void *videobase)
{ {
unsigned char color8; unsigned char color8;

View File

@ -47,7 +47,11 @@
#define CONFIG_VIDEO_PIXEL_SIZE 4 #define CONFIG_VIDEO_PIXEL_SIZE 4
#define CONFIG_VIDEO_DATA_FORMAT GDF_32BIT_X888RGB /* BGR actually, but w/e */ #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_init(void *fb);
int video_resume(void *fb, int row, int col);
void video_puts(const char *s); void video_puts(const char *s);
#endif /*_VIDEO_FB_H_ */ #endif /*_VIDEO_FB_H_ */