Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to v0.10 (stage3) #6

Closed
kassane opened this issue Jan 7, 2023 · 3 comments
Closed

Update to v0.10 (stage3) #6

kassane opened this issue Jan 7, 2023 · 3 comments

Comments

@kassane
Copy link

kassane commented Jan 7, 2023

I have made some modifications (nothing conclusive to the point of sending MR).
However, I could not solve the last error involving the linker (ld) not recognizing memcpy.

Output:

error: ld.lld: undefined symbol: memcpy
    note: referenced by main.zig:25
    note:               /home/kassane/Documentos/Projetos/avr-arduino-zig/zig-cache/o/0ab5a5c493c713136f428c7e79480d08/avr-arduino-zig.o:(_start)
error: avr-arduino-zig...
error: The following command exited with error code 1:
/home/kassane/.local/bin/zig build-exe -freference-trace=256 /home/kassane/Documentos/Projetos/avr-arduino-zig/src/start.zig -OReleaseSafe --cache-dir /home/kassane/Documentos/Projetos/avr-arduino-zig/zig-cache --global-cache-dir /home/kassane/.cache/zig --name avr-arduino-zig -fno-compiler-rt -target avr-freestanding-none -mcpu atmega328p --script /home/kassane/Documentos/Projetos/avr-arduino-zig/src/linker.ld --enable-cache

Changes:

diff --git a/build.zig b/build.zig
index 09ec19d..f492a75 100644
--- a/build.zig
+++ b/build.zig
@@ -29,11 +29,11 @@ pub fn build(b: *Builder) !void {
         try tmp.appendSlice("-Uflash:w:");
         try tmp.appendSlice(bin_path);
         try tmp.appendSlice(":e");
-        break :blk tmp.toOwnedSlice();
+        break :blk tmp.toOwnedSlice() catch unreachable;
     };
 
     const upload = b.step("upload", "Upload the code to an Arduino device using avrdude");
-    const avrdude = b.addSystemCommand(&.{
+    const avrdude = b.addSystemCommand(&[_][]const u8{
         "avrdude",
         "-carduino",
         "-patmega328p",
@@ -46,7 +46,7 @@ pub fn build(b: *Builder) !void {
     avrdude.step.dependOn(&exe.install_step.?.step);
 
     const objdump = b.step("objdump", "Show dissassembly of the code using avr-objdump");
-    const avr_objdump = b.addSystemCommand(&.{
+    const avr_objdump = b.addSystemCommand(&[_][]const u8{
         "avr-objdump",
         "-dh",
         bin_path,
@@ -55,7 +55,7 @@ pub fn build(b: *Builder) !void {
     avr_objdump.step.dependOn(&exe.install_step.?.step);
 
     const monitor = b.step("monitor", "Opens a monitor to the serial output");
-    const screen = b.addSystemCommand(&.{
+    const screen = b.addSystemCommand(&[_][]const u8{
         "screen",
         tty,
         "115200",
diff --git a/src/atmega328p.zig b/src/atmega328p.zig
index 06d4880..35b21bb 100644
--- a/src/atmega328p.zig
+++ b/src/atmega328p.zig
@@ -1313,8 +1313,8 @@ pub fn mmioInt(addr: usize, comptime size: usize, comptime T: type) *volatile Mm
 }
 
 const InterruptVector = extern union {
-    C: fn () callconv(.C) void,
-    Naked: fn () callconv(.Naked) void,
+    C: *const fn () callconv(.C) void,
+    Naked: *const fn () callconv(.Naked) void,
     // Interrupt is not supported on arm
 };
 
diff --git a/src/start.zig b/src/start.zig
index 596febc..e60f677 100644
--- a/src/start.zig
+++ b/src/start.zig
@@ -4,8 +4,12 @@ const uart = @import("uart.zig");
 const std = @import("std");
 const builtin = std.builtin;
 
-export const vector_table linksection(".vectors") = blk: {
-    std.debug.assert(std.mem.eql(u8, "RESET", std.meta.fields(atmega328p.VectorTable)[0].name));
+comptime {
+    @export(vector_table, .{ .name = "vector_table", .linkage = .Strong });
+}
+
+const vector_table linksection(".vectors") = blk: {
+    // std.debug.assert(std.mem.eql(u8, "RESET", std.meta.fields(atmega328p.VectorTable)[0].name));
     var asm_str: []const u8 = "jmp _start\n";
 
     const has_interrupts = @hasDecl(main, "interrupts");
@@ -57,7 +61,13 @@ export const vector_table linksection(".vectors") = blk: {
         asm_str = asm_str ++ new_insn ++ "\n";
     }
 
-    break :blk asm (asm_str);
+    const T = struct {
+        fn _start() callconv(.Naked) void {
+            asm volatile (asm_str);
+        }
+    };
+
+    break :blk T._start;
 };
 
 export fn _unhandled_vector() void {
@@ -122,7 +132,7 @@ fn clear_bss() void {
     // Probably a good idea to add clobbers here, but compiler doesn't seem to care
 }
 
-pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
+pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace, _: ?usize) noreturn {
     // Currently assumes that the uart is initialized in main().
     uart.write("PANIC: ");
     uart.write(msg);
@CGenie
Copy link

CGenie commented Mar 16, 2023

I get errors in build.zig with zig at 0.10.1 on the following change:

-        break :blk tmp.toOwnedSlice();
+        break :blk tmp.toOwnedSlice() catch unreachable;

Removing this change gets me to the memcpy error that you mentioned.

@kassane
Copy link
Author

kassane commented Mar 16, 2023

Thx @CGenie - update (0.11-dev)
kassane@764a9a6

@FireFox317
Copy link
Owner

I push a commit to master (4d3d196) that fixes the build for Zig version 0.10.1!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants