aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap.s13
-rw-r--r--src/main.zig2
-rw-r--r--src/startup.zig41
3 files changed, 42 insertions, 14 deletions
diff --git a/src/bootstrap.s b/src/bootstrap.s
deleted file mode 100644
index 612fac3..0000000
--- a/src/bootstrap.s
+++ /dev/null
@@ -1,13 +0,0 @@
-.cpu cortex-m4
-.thumb
-
-.extern _start
-.extern _tstack
-
-.section .vector_table
-.global init_vector_table
-init_vector_table:
- .word _tstack
- .word _start
- .skip 4 * 14
-
diff --git a/src/main.zig b/src/main.zig
index d6a1aa4..99cb451 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -8,7 +8,7 @@ const gpioa = gpio.gpioa;
const gpioc = gpio.gpioc;
const tick = timer.systick;
-export fn _start() callconv(.C) noreturn {
+pub fn main() void {
cpu.interrupt_disable();
interrupt.initialize();
interrupt.register(.SVCall, svcall);
diff --git a/src/startup.zig b/src/startup.zig
new file mode 100644
index 0000000..f7c7712
--- /dev/null
+++ b/src/startup.zig
@@ -0,0 +1,41 @@
+const main = @import("main.zig");
+
+extern const __data_flash: u32;
+extern const __data: u32;
+extern const __data_size: u32;
+extern const __bss: u32;
+extern const __bss_size: u32;
+
+comptime {
+ asm (
+ \\.extern _start
+ \\.extern _tstack
+ \\
+ \\.section .vector_table
+ \\.global init_vector_table
+ \\init_vector_table:
+ \\ .word _tstack
+ \\ .word _start
+ \\ .skip 4 * 14
+ );
+}
+
+inline fn zero_bss() void {
+ const bss: [*]volatile u8 = @ptrFromInt(@intFromPtr(&__bss));
+ @memset(bss[0..@intFromPtr(&__bss_size)], 0);
+}
+
+inline fn copy_data() void {
+ const data_flash: [*]volatile u8 = @ptrFromInt(@intFromPtr(&__data_flash));
+ const data: [*]volatile u8 = @ptrFromInt(@intFromPtr(&__data));
+ const data_size = @intFromPtr(&__data_size);
+ @memcpy(data[0..data_size], data_flash[0..data_size]);
+}
+
+export fn _start() callconv(.C) noreturn {
+ zero_bss();
+ copy_data();
+ main.main();
+ while (true) {}
+}
+