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

Build failure due to @newStackCall being removed in 0.6.0 #3

Open
peterhellberg opened this issue Jun 24, 2020 · 4 comments
Open

Build failure due to @newStackCall being removed in 0.6.0 #3

peterhellberg opened this issue Jun 24, 2020 · 4 comments

Comments

@peterhellberg
Copy link
Contributor

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

@cubranic
Copy link

cubranic commented Sep 8, 2020

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

@andrewrk
Copy link
Owner

andrewrk commented Sep 9, 2020

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

@peterhellberg
Copy link
Contributor Author

@andrewrk Ok, will do so right away.

@xyproto
Copy link

xyproto commented Sep 29, 2020

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

andrewrk pushed a commit that referenced this issue Jan 31, 2021
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

4 participants