]> code.bitgloo.com Git - clyne/zig-stm32l476.git/commitdiff
initial commit
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 5 Oct 2024 16:13:49 +0000 (12:13 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 5 Oct 2024 16:13:49 +0000 (12:13 -0400)
.gitignore [new file with mode: 0644]
build.zig [new file with mode: 0644]
link.ld [new file with mode: 0644]
src/bootstrap.s [new file with mode: 0644]
src/main.zig [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..6e988fa
--- /dev/null
@@ -0,0 +1,3 @@
+*.sw*
+.zig-cache/
+zig-out/
diff --git a/build.zig b/build.zig
new file mode 100644 (file)
index 0000000..10fe592
--- /dev/null
+++ b/build.zig
@@ -0,0 +1,23 @@
+const std = @import("std");
+
+pub fn build(b: *std.Build) void {
+    const target = b.resolveTargetQuery(.{
+        .cpu_arch = .thumb,
+        .os_tag = .freestanding,
+        .abi = .none
+    });
+    const optimize = .Debug; // .ReleaseSmall
+
+    const exe = b.addExecutable(.{
+        .name = "stm32",
+        .root_source_file = b.path("src/main.zig"),
+        .target = target,
+        .optimize = optimize,
+        .linkage = .static,
+    });
+
+    exe.addAssemblyFile(b.path("src/bootstrap.s"));
+    exe.setLinkerScriptPath(b.path("link.ld"));
+
+    b.installArtifact(exe);
+}
diff --git a/link.ld b/link.ld
new file mode 100644 (file)
index 0000000..403ba71
--- /dev/null
+++ b/link.ld
@@ -0,0 +1,44 @@
+ENTRY(_start)
+
+/* description of memory regions */
+MEMORY {
+       FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
+       RAM (rwx)  : ORIGIN = 0x20000000,  LENGTH = 96K
+}
+
+/* description of ELF sections */
+SECTIONS {
+       .text : {
+               . = ALIGN(8);
+               *(.isr_vector)
+               *(.text)
+               *(.text*)
+       } > FLASH
+
+       /* read-only data sections */
+       .rodata : {
+               . = ALIGN(8);
+               *(.rodata)
+               *(.rodata*)
+       } > FLASH
+
+       /* initialized data */
+       _sidata = LOADADDR(.data);
+       .data : {
+               . = ALIGN(8);
+               _sdata = .;
+               *(.data)
+               . = ALIGN(8);
+               _edata = .;
+       } > RAM AT > FLASH
+
+       /* uninitialized data */
+       .bss : {
+               . = ALIGN(8);
+               _sbss = .;
+               *(.bss)
+               . = ALIGN(8);
+               _ebss = .;
+       } > RAM
+}
+
diff --git a/src/bootstrap.s b/src/bootstrap.s
new file mode 100644 (file)
index 0000000..22f66f0
--- /dev/null
@@ -0,0 +1,38 @@
+.cpu cortex-m4
+.thumb
+
+.extern _start
+.extern fault_handler
+
+.section .text
+
+fault1:
+    mov r0, 1
+    b fault_handler
+fault2:
+    mov r0, 2
+    b fault_handler
+fault3:
+    mov r0, 3
+    b fault_handler
+fault4:
+    mov r0, 4
+    b fault_handler
+fault5:
+    mov r0, 5
+    b fault_handler
+
+.section .bss
+.skip 128
+stack_top:
+
+.section .isr_vector
+    .word stack_top
+    .word _start
+    .word fault1
+    .word fault2
+    .word fault3
+    .word fault4
+    .word fault5
+    .skip 4 * 91
+
diff --git a/src/main.zig b/src/main.zig
new file mode 100644 (file)
index 0000000..de602dd
--- /dev/null
@@ -0,0 +1,13 @@
+//! By convention, main.zig is where your main function lives in the case that
+//! you are building an executable. If you are making a library, the convention
+//! is to delete this file and start with root.zig instead.
+//const std = @import("std");
+
+export fn _start() callconv(.C) noreturn {
+    while (true) {}
+}
+
+export fn fault_handler() callconv(.C) void {
+    while (true) {}
+}
+