calculate end-of-stack value from chip configs (#12)

wch-ch32v003
Matt Knight 3 years ago committed by GitHub
parent 1b5cc2ad1f
commit 38110fb3bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,7 +16,7 @@ pub fn build(b: *std.build.Builder) !void {
const BuildConfig = struct { name: []const u8, backing: Backing, supports_uart: bool = true };
const all_backings = [_]BuildConfig{
//BuildConfig{ .name = "boards.arduino_nano", .backing = Backing{ .board = pkgs.boards.arduino_nano } },
//BuildConfig{ .name = "boards.arduino_nano", .backing = Backing{ .board = boards.arduino_nano } },
BuildConfig{ .name = "boards.mbed_lpc1768", .backing = Backing{ .board = boards.mbed_lpc1768 } },
//BuildConfig{ .name = "chips.atmega328p", .backing = Backing{ .chip = pkgs.chips.atmega328p } },
BuildConfig{ .name = "chips.lpc1768", .backing = Backing{ .chip = chips.lpc1768 } },

@ -63,6 +63,18 @@ pub fn addEmbeddedExecutable(
};
{
// TODO: let the user override which ram section to use the stack on,
// for now just using the first ram section in the memory region list
const first_ram = blk: {
for (chip.memory_regions) |region| {
if (region.kind == .ram)
break :blk region;
} else {
std.log.err("no ram memory region found for setting the end-of-stack address", .{});
return error.NoRam;
}
};
std.fs.cwd().makeDir(std.fs.path.dirname(config_file_name).?) catch {};
var config_file = try std.fs.cwd().createFile(config_file_name, .{});
defer config_file.close();
@ -74,6 +86,7 @@ pub fn addEmbeddedExecutable(
try writer.print("pub const chip_name = .@\"{}\";\n", .{std.fmt.fmtSliceEscapeUpper(chip.name)});
try writer.print("pub const cpu_name = .@\"{}\";\n", .{std.fmt.fmtSliceEscapeUpper(chip.cpu.name)});
try writer.print("pub const end_of_stack = 0x{X:0>8};\n\n", .{first_ram.offset + first_ram.length});
}
const microzig_pkg = Pkg{
@ -81,6 +94,11 @@ pub fn addEmbeddedExecutable(
.path = .{ .path = root_path ++ "core/microzig.zig" },
};
const config_pkg = Pkg{
.name = "microzig-config",
.path = .{ .path = config_file_name },
};
const chip_pkg = Pkg{
.name = "chip",
.path = .{ .path = chip.path },
@ -90,16 +108,11 @@ pub fn addEmbeddedExecutable(
Pkg{
.name = "cpu",
.path = .{ .path = chip.cpu.path },
.dependencies = &[_]Pkg{ microzig_pkg, pkgs.mmio },
.dependencies = &[_]Pkg{ microzig_pkg, pkgs.mmio, config_pkg },
},
},
};
const config_pkg = Pkg{
.name = "microzig-config",
.path = .{ .path = config_file_name },
};
const exe = builder.addExecutable(name, root_path ++ "core/start.zig");
// might not be true for all machines (Pi Pico), but

@ -1,4 +1,5 @@
const std = @import("std");
const config = @import("microzig-config");
pub fn sei() void {
asm volatile ("cpsie i");
@ -56,8 +57,7 @@ pub const startup_logic = struct {
};
export const vectors linksection("microzig_flash_start") = VectorTable{
// TODO: How to compute/get the initial stack pointer?
.initial_stack_pointer = 0x1000_7FFC, // HACK: hardcoded, do not keep!
.initial_stack_pointer = config.end_of_stack,
.reset = _start,
};

@ -1,4 +1,5 @@
const std = @import("std");
const config = @import("microzig-config");
pub fn sei() void {
asm volatile ("cpsie i");
@ -56,8 +57,7 @@ pub const startup_logic = struct {
};
export const vectors linksection("microzig_flash_start") = VectorTable{
// TODO: How to compute/get the initial stack pointer?
.initial_stack_pointer = 0x2000_A000, // HACK: hardcoded, do not keep!
.initial_stack_pointer = config.end_of_stack,
.reset = _start,
};

Loading…
Cancel
Save