Add a simple boot section
This commit is contained in:
parent
234221cbff
commit
797a308764
4 changed files with 17 additions and 4 deletions
|
@ -1,4 +1,6 @@
|
||||||
example: example.c
|
example: example.c Makefile boot.s linker.ld
|
||||||
riscv32-none-elf-gcc -fno-builtin -fvisibility=hidden -nostdlib -nostartfiles -march=rv32im -mabi=ilp32 -o example example.c -T linker.ld
|
riscv32-none-elf-as -march=rv32i -mabi=ilp32 boot.s -o boot.o
|
||||||
|
riscv32-none-elf-gcc -fno-builtin -fvisibility=hidden -nostdlib -nostartfiles -march=rv32im -mabi=ilp32 -c example.c -o example.o
|
||||||
|
riscv32-none-elf-ld boot.o example.o -T linker.ld -o example
|
||||||
riscv32-none-elf-strip -R .riscv.attributes example
|
riscv32-none-elf-strip -R .riscv.attributes example
|
||||||
riscv32-none-elf-strip -R .comment example
|
riscv32-none-elf-strip -R .comment example
|
||||||
|
|
6
example/boot.s
Normal file
6
example/boot.s
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
.globl _boot
|
||||||
|
_boot:
|
||||||
|
lui x2, 0x80004
|
||||||
|
jal main
|
||||||
|
sbreak
|
||||||
|
j .
|
|
@ -1,7 +1,7 @@
|
||||||
ENTRY(_start)
|
ENTRY(_start)
|
||||||
|
|
||||||
SECTIONS {
|
SECTIONS {
|
||||||
. = 0x1000; /* Start address of the program */
|
. = 0x0000; /* Start address of the program */
|
||||||
|
|
||||||
.text : {
|
.text : {
|
||||||
*(.text) /* Place all .text sections (code) here */
|
*(.text) /* Place all .text sections (code) here */
|
||||||
|
|
|
@ -23,7 +23,8 @@ void eval(uint8_t* memory, size_t memory_size) {
|
||||||
return instruction;
|
return instruction;
|
||||||
};
|
};
|
||||||
|
|
||||||
while (pc < memory_size) {
|
bool running = true;
|
||||||
|
while (pc < memory_size && running) {
|
||||||
uint32_t instr = fetch_instruction();
|
uint32_t instr = fetch_instruction();
|
||||||
if (instr == 0) break;
|
if (instr == 0) break;
|
||||||
// std::cout << "pc: " << pc << "\n";
|
// std::cout << "pc: " << pc << "\n";
|
||||||
|
@ -248,6 +249,10 @@ void eval(uint8_t* memory, size_t memory_size) {
|
||||||
registers[rd] = pc + (imm << 12); // Add the immediate (shifted left) to the current PC
|
registers[rd] = pc + (imm << 12); // Add the immediate (shifted left) to the current PC
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 0x73: { // EBREAK
|
||||||
|
running = false; // Flag to stop the emulator
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error("Unknown opcode");
|
throw std::runtime_error("Unknown opcode");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue