HellOS icon indicating copy to clipboard operation
HellOS copied to clipboard

Build failure due to @newStackCall being removed in 0.6.0

Open peterhellberg opened this issue 4 years ago • 4 comments

I found this neat little project today, and thought I should look into making it compile using Zig 0.6.0

(Mainly as a fun challenge, since I do not yet know much about Zig)

Making the following changes allows the code to build

zig build-exe hellos.zig -target i386-freestanding --linker-script linker.ld

diff --git a/hellos.zig b/hellos.zig
index 8563852..506f2c9 100644
--- a/hellos.zig
+++ b/hellos.zig
@@ -20,8 +20,9 @@ export var multiboot align(4) linksection(".multiboot") = MultiBoot{
 export var stack_bytes: [16 * 1024]u8 align(16) linksection(".bss") = undefined;
 const stack_bytes_slice = stack_bytes[0..];
 
-export nakedcc fn _start() noreturn {
-    @newStackCall(stack_bytes_slice, kmain);
+export fn _start() callconv(.Naked) noreturn {
+    @call(.{ .stack = stack_bytes_slice }, kmain, .{});
+
     while (true) {}
 }
 
@@ -34,7 +35,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
 
 fn kmain() void {
     terminal.initialize();
-    terminal.write("Hello, kernel World!");
+    terminal.write("Hello, Kernel World from Zig 0.6.0!");
 }
 
 // Hardware text mode color constants
@@ -61,23 +62,26 @@ fn vga_entry_color(fg: VgaColor, bg: VgaColor) u8 {
 }
 
 fn vga_entry(uc: u8, color: u8) u16 {
-    return u16(uc) | (u16(color) << 8);
+    var c: u16 = color;
+
+    return uc | (c << 8);
 }
 
 const VGA_WIDTH = 80;
 const VGA_HEIGHT = 25;
 
 const terminal = struct {
-    var row = usize(0);
-    var column = usize(0);
+    var row: usize = 0;
+    var column: usize = 0;
+
     var color = vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK);
 
     const buffer = @intToPtr([*]volatile u16, 0xB8000);
 
     fn initialize() void {
-        var y = usize(0);
+        var y: usize = 0;
         while (y < VGA_HEIGHT) : (y += 1) {
-            var x = usize(0);
+            var x: usize = 0;
             while (x < VGA_WIDTH) : (x += 1) {
                 putCharAt(' ', color, x, y);
             }

Screenshot

hellos

Gist

https://gist.github.com/peterhellberg/e81128eae5adc6293d5c1bbeef3a3380

peterhellberg avatar Jun 24 '20 17:06 peterhellberg

I can verify that this patch got HellOS to compile and run with Zig 0.6.0.

cubranic avatar Sep 08 '20 21:09 cubranic

Happy to merge it, do you want to make it a PR and get authorship for it?

andrewrk avatar Sep 09 '20 00:09 andrewrk

@andrewrk Ok, will do so right away.

peterhellberg avatar Sep 09 '20 06:09 peterhellberg

I can confirm that the patch-1 branch from @peterhellberg compiles, using zig 0.6.0+281fc10ec.

xyproto avatar Sep 29 '20 10:09 xyproto