Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
285 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
ENTRY(boot) | ||
|
||
SECTIONS { | ||
kernel_main = 0x100; /* Must match value from kernel linker script */ | ||
|
||
. = 0x8800000; /* Must match debug.bootloader_address */ | ||
|
||
.text : ALIGN(4K) { | ||
KEEP(*(.text.first)) | ||
*(.text) | ||
} | ||
|
||
.rodata : ALIGN(4K) { | ||
*(.rodata) | ||
} | ||
|
||
.data : ALIGN(4K) { | ||
*(.data) | ||
} | ||
|
||
.bss : ALIGN(4K) { | ||
__bss_start = .; | ||
*(COMMON) | ||
*(.bss) | ||
__bss_end = .; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// The bootloader is a separate executable, the hardware does not boot | ||
// directly into it. When the kernel wants to load a new image from the | ||
// serial port, it copies the bootloader executable code into memory at | ||
// address bootloader_address which matches the linker script for the bootloader | ||
// executable. Then the kernel jumps to bootloader_address. The bootloader then | ||
// overwrites the kernel's code, which is why a separate bootloader | ||
// executable is necessary. | ||
const std = @import("std"); | ||
const builtin = @import("builtin"); | ||
const debug = @import("debug.zig"); | ||
const serial = @import("serial.zig"); | ||
|
||
export fn bootloader_main(start_addr: [*]u8, len: usize) linksection(".text.first") noreturn { | ||
var i: usize = 0; | ||
while (i < len) : (i += 1) { | ||
start_addr[i] = serial.readByte(); | ||
} | ||
asm volatile ( | ||
\\mov sp,#0x08000000 | ||
\\bl kernel_main | ||
); | ||
unreachable; | ||
} | ||
|
||
pub fn panic(message: []const u8, stack_trace: ?*builtin.StackTrace) noreturn { | ||
serial.log("BOOTLOADER PANIC: {}\n", message); | ||
debug.wfe_hang(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.