commit f529a3b0f8ee24229997e995021a2ee8cb25f065 Author: Clyne Sullivan Date: Sat Oct 5 12:13:49 2024 -0400 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e988fa --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.sw* +.zig-cache/ +zig-out/ diff --git a/build.zig b/build.zig new file mode 100644 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 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 index 0000000..22f66f0 --- /dev/null +++ b/src/bootstrap.s @@ -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 index 0000000..de602dd --- /dev/null +++ b/src/main.zig @@ -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) {} +} +