soc/software/bios: Allow registering init functions.

This commit is contained in:
Vegard Storheil Eriksen 2021-06-13 14:03:43 +02:00
parent 61636f1248
commit 8d527a1f3f
5 changed files with 28 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include "readline.h"
#include "helpers.h"
#include "command.h"
#include "init.h"
extern unsigned int _ftext, _edata_rom;
@ -126,3 +127,10 @@ struct command_struct *command_dispatcher(char *command, int nb_params, char **p
return NULL;
}
void init_dispatcher(void)
{
for (const init_func* fp = __bios_init_start; fp != __bios_init_end; fp++) {
(*fp)();
}
}

View File

@ -5,5 +5,6 @@ void dump_bytes(unsigned int *ptr, int count, unsigned long addr);
void crcbios(void);
int get_param(char *buf, char **cmd, char **params);
struct command_struct *command_dispatcher(char *command, int nb_params, char **params);
void init_dispatcher(void);
#endif

View File

@ -0,0 +1,10 @@
#pragma once
typedef void (*init_func)(void);
extern init_func const __bios_init_start[];
extern init_func const __bios_init_end[];
#define define_init_func(f) \
const init_func __bios_init_##f __attribute__((__used__)) \
__attribute__((__section__(".bios_init"))) = f

View File

@ -41,6 +41,13 @@ SECTIONS
PROVIDE_HIDDEN (__bios_cmd_end = .);
} > rom
.init :
{
PROVIDE_HIDDEN (__bios_init_start = .);
KEEP(*(.bios_init))
PROVIDE_HIDDEN (__bios_init_end = .);
} > rom
.data :
{
. = ALIGN(8);

View File

@ -173,6 +173,8 @@ int main(int i, char **c)
video_framebuffer_dma_enable_write(1);
#endif
init_dispatcher();
if(sdr_ok) {
printf("--============== \e[1mBoot\e[0m ==================--\n");
boot_sequence();