Replace bios with bootloader, don't use bootsector
Instead of using the bootsector to load a bootloader, just put the bootloader in the ROM and call it a day. It looks for a file on the SD card in the root directory named `kernel.bin` and loads it into memory. This is not a perfect solution, as the kernel will grow larger and the kernel load address will have to change. At this point I could add back the bootloader, but that is for later. Also the bootloader is just a copy of the kernel, so that can be trimmed down a lot.
This commit is contained in:
@@ -1,11 +1,63 @@
|
||||
#include <stdint.h>
|
||||
#include <conio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "bios_calls.h"
|
||||
#include "uart.h"
|
||||
#include "devices/board_io.h"
|
||||
#include "devices/uart.h"
|
||||
#include "devices/mapper.h"
|
||||
#include "devices/sd_card.h"
|
||||
#include "filesystem/fat.h"
|
||||
#include "exec.h"
|
||||
|
||||
//Should probably do this in asm
|
||||
void load_bootsect() {
|
||||
uart_txb_block('A');
|
||||
for (;;);
|
||||
return;
|
||||
}
|
||||
#define KERNEL_LOAD_ADDR 0xD000
|
||||
|
||||
uint8_t buf[512];
|
||||
|
||||
int main() {
|
||||
int i;
|
||||
uint16_t rca;
|
||||
char* filename;
|
||||
uint32_t cluster;
|
||||
uint8_t* kernel_load;
|
||||
|
||||
clrscr();
|
||||
cprintf("boot\n");
|
||||
|
||||
for (i = 0; i < 16; i++){
|
||||
//cprintf("Mapping %1xxxx to %2xxxx\n", i, i);
|
||||
mapper_write(i, i);
|
||||
}
|
||||
|
||||
cprintf("Enabling Mapper\n");
|
||||
mapper_enable(1);
|
||||
|
||||
mapper_write(0x10, 0xd);
|
||||
mapper_write(0x11, 0xe);
|
||||
mapper_write(0x12, 0xf);
|
||||
|
||||
sd_init();
|
||||
|
||||
rca = sd_get_rca();
|
||||
cprintf("rca: %x\n", rca);
|
||||
|
||||
sd_select_card(rca);
|
||||
|
||||
fat_init();
|
||||
|
||||
filename = (char*)malloc(FAT_MAX_FILE_NAME);
|
||||
|
||||
cluster = fat_parse_path_to_cluster("/kernel.bin");
|
||||
for (kernel_load = (uint8_t*)KERNEL_LOAD_ADDR; cluster < FAT_CLUSTERMASK; kernel_load+=(8*512)) {
|
||||
cprintf("cluster: %lx\n", cluster);
|
||||
cprintf("Writing to %p\n", kernel_load);
|
||||
fat_read_cluster(cluster, kernel_load);
|
||||
cluster = fat_get_chain_value(cluster);
|
||||
}
|
||||
|
||||
cprintf("Done!\n");
|
||||
|
||||
cprintf("Reset vector: %x\n", *((uint16_t*)0xfffc));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user