Initial commit
Added base code, can run ELF files and simulate RV32I instructions
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#include "bootloader.h"
|
||||
#include "elf/elf.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
uint32_t bootload(char* file_path)
|
||||
{
|
||||
// Open the file
|
||||
FILE* f = fopen(file_path, "r");
|
||||
if(!f)
|
||||
{
|
||||
fprintf(stderr, "Could not open file '%s': %s\n", file_path, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Obtain file size
|
||||
fseek(f, 0, SEEK_END);
|
||||
size_t file_size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
// Load the file in memory
|
||||
void* file = malloc(file_size);
|
||||
if(fread(file, file_size, 1, f) != 1)
|
||||
{
|
||||
fprintf(stderr, "Could not read file '%s': %s\n", file_path, strerror(errno));
|
||||
fclose(f);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Close the file
|
||||
fclose(f);
|
||||
|
||||
// TODO: Check file type (for now we only bootload ELF)
|
||||
return elf_32_load(file);
|
||||
}
|
||||
Reference in New Issue
Block a user