📄 biosapi.c
字号:
#include "board.h"#include "utils.h"#include "bios.h"#include "bioscall.h"#include "flash.h"#include "console.h"static struct config_table_struct config_table;static unsigned long get_rom_size(struct system_table_struct *sys_tbl){ unsigned long rom_size = 0; int i; for (i = 0; i < 4; i++) rom_size += sys_tbl->rom_table[i].size; return rom_size;}static unsigned long get_dram_size(struct system_table_struct *sys_tbl){ unsigned long dram_size = 0; int i; for (i = 0; i < 4; i++) dram_size += sys_tbl->dram_table[i].size; return dram_size;}static int reboot(void){ void (*fp)(void); fp = (void (*)(void))(config_table.rom_base); (*fp)(); return 0;}static int bios_call_init(struct biosapi_init_struct *init_param){ struct system_table_struct *sys_tbl; sys_tbl = init_param->system_table; memset(&config_table, 0, sizeof(struct config_table_struct)); config_table.vendor_id = sys_tbl->vendor_id; config_table.device_id = sys_tbl->device_id; config_table.rev = sys_tbl->rev; config_table.system_table_offset = init_param->system_table_offset; config_table.system_table_size = sys_tbl->system_table_size; config_table.partition_table_offset = sys_tbl->partition_table_offset; config_table.partition_table_size = sys_tbl->partition_table_size; config_table.default_table_offset = sys_tbl->default_table_offset; config_table.bios_offset = 0; config_table.bios_size = sys_tbl->bios_size; config_table.rom_base = init_param->rom_base; config_table.rom_size = get_rom_size(sys_tbl); config_table.dram_base = init_param->dram_base; config_table.dram_size = get_dram_size(sys_tbl); config_table.startup_mode = sys_tbl->startup_mode; config_table.userflag = 0; flash_init(config_table.rom_base); return 0;}int bios_call_internal(unsigned long id, unsigned long arg){ switch (id) { case BIOSCALL_INIT: bios_call_init((struct biosapi_init_struct *)arg); break; case BIOSCALL_REBOOT: reboot(); break; case BIOSCALL_GET_VENDORID: *(unsigned short *)arg = config_table.vendor_id; break; case BIOSCALL_GET_DEVICEID: *(unsigned short *)arg = config_table.device_id; break; case BIOSCALL_GET_REV: *(unsigned long *)arg = config_table.rev; break; case BIOSCALL_GET_SYSTEMTABLEOFFSET: *(unsigned long *)arg = config_table.system_table_offset; break; case BIOSCALL_GET_SYSTEMTABLESIZE: *(unsigned long *)arg = config_table.system_table_size; break; case BIOSCALL_GET_PARTITIONTABLEOFFSET: *(unsigned long *)arg = config_table.partition_table_offset; break; case BIOSCALL_GET_PARTITIONTABLESIZE: *(unsigned long *)arg = config_table.partition_table_size; break; case BIOSCALL_GET_DEFAULTTABLEOFFSET: *(unsigned long *)arg = config_table.default_table_offset; break; case BIOSCALL_GET_BIOSOFFSET: *(unsigned long *)arg = config_table.bios_offset; break; case BIOSCALL_GET_BIOSSIZE: *(unsigned long *)arg = config_table.bios_size; break; case BIOSCALL_GET_ROMBASE: *(unsigned long *)arg = config_table.rom_base; break; case BIOSCALL_GET_ROMSIZE: *(unsigned long *)arg = config_table.rom_size; break; case BIOSCALL_GET_DRAMBASE: *(unsigned long *)arg = config_table.dram_base; break; case BIOSCALL_GET_DRAMSIZE: *(unsigned long *)arg = config_table.dram_size; break; case BIOSCALL_GET_STARTUPMODE: *(unsigned long *)arg = config_table.startup_mode; break; case BIOSCALL_GET_USERFLAG: *(unsigned long *)arg = config_table.userflag; break; case BIOSCALL_SET_USERFLAG: config_table.userflag = arg; break; case BIOSCALL_FLASH_ERASE: flash_erase(((struct flash_erase_struct *)arg)->addr, ((struct flash_erase_struct *)arg)->size); break; case BIOSCALL_FLASH_READ: flash_read(((struct flash_read_struct *)arg)->from, ((struct flash_read_struct *)arg)->len, &(((struct flash_read_struct *)arg)->retlen), ((struct flash_read_struct *)arg)->buf); break; case BIOSCALL_FLASH_WRITE: flash_write(((struct flash_write_struct *)arg)->to, ((struct flash_write_struct *)arg)->len, &(((struct flash_write_struct *)arg)->retlen), ((struct flash_write_struct *)arg)->buf); break; default: printf("BIOS error: invalid bios call!\r\n"); while (1); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -