| author | |
| committer | |
| log | 31828572249883f99fad307dc6b27df9d1678a8d |
| tree | 6f68110ee33640786e23f117880333240aa25341 |
| parent | ad438cfd40aba682a0bcd88ed607c2cbd378f647 |
6 files changed, 120 insertions(+), 4 deletions(-)
CMakeLists.txt+1| ... | @@ -440,6 +440,7 @@ set(ZIG_STD_FILES | ... | @@ -440,6 +440,7 @@ set(ZIG_STD_FILES |
| 440 | "os/windows/error.zig" | 440 | "os/windows/error.zig" |
| 441 | "os/windows/index.zig" | 441 | "os/windows/index.zig" |
| 442 | "os/windows/util.zig" | 442 | "os/windows/util.zig" |
| 443 | "os/zen.zig" | ||
| 443 | "rand.zig" | 444 | "rand.zig" |
| 444 | "sort.zig" | 445 | "sort.zig" |
| 445 | "special/bootstrap.zig" | 446 | "special/bootstrap.zig" |
src/link.cpp+7| ... | @@ -334,6 +334,13 @@ static void construct_linker_job_elf(LinkJob *lj) { | ... | @@ -334,6 +334,13 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 334 | if (!g->is_native_target) { | 334 | if (!g->is_native_target) { |
| 335 | lj->args.append("--allow-shlib-undefined"); | 335 | lj->args.append("--allow-shlib-undefined"); |
| 336 | } | 336 | } |
| 337 | |||
| 338 | if (g->zig_target.os == OsZen) { | ||
| 339 | lj->args.append("-e"); | ||
| 340 | lj->args.append("main"); | ||
| 341 | |||
| 342 | lj->args.append("--image-base=0x10000000"); | ||
| 343 | } | ||
| 337 | } | 344 | } |
| 338 | 345 | ||
| 339 | //static bool is_target_cyg_mingw(const ZigTarget *target) { | 346 | //static bool is_target_cyg_mingw(const ZigTarget *target) { |
std/os/index.zig+2| ... | @@ -7,9 +7,11 @@ const os = this; | ... | @@ -7,9 +7,11 @@ const os = this; |
| 7 | pub const windows = @import("windows/index.zig"); | 7 | pub const windows = @import("windows/index.zig"); |
| 8 | pub const darwin = @import("darwin.zig"); | 8 | pub const darwin = @import("darwin.zig"); |
| 9 | pub const linux = @import("linux.zig"); | 9 | pub const linux = @import("linux.zig"); |
| 10 | pub const zen = @import("zen.zig"); | ||
| 10 | pub const posix = switch(builtin.os) { | 11 | pub const posix = switch(builtin.os) { |
| 11 | Os.linux => linux, | 12 | Os.linux => linux, |
| 12 | Os.macosx, Os.ios => darwin, | 13 | Os.macosx, Os.ios => darwin, |
| 14 | Os.zen => zen, | ||
| 13 | else => @compileError("Unsupported OS"), | 15 | else => @compileError("Unsupported OS"), |
| 14 | }; | 16 | }; |
| 15 | 17 |
std/os/zen.zig created+94| ... | @@ -0,0 +1,94 @@ | ||
| 1 | ////////////////////////////// | ||
| 2 | //// Reserved mailboxes //// | ||
| 3 | ////////////////////////////// | ||
| 4 | |||
| 5 | pub const MBOX_TERMINAL = 1; | ||
| 6 | |||
| 7 | |||
| 8 | /////////////////////////// | ||
| 9 | //// Syscall numbers //// | ||
| 10 | /////////////////////////// | ||
| 11 | |||
| 12 | pub const SYS_createMailbox = 0; | ||
| 13 | pub const SYS_send = 1; | ||
| 14 | pub const SYS_receive = 2; | ||
| 15 | pub const SYS_map = 3; | ||
| 16 | |||
| 17 | |||
| 18 | //////////////////// | ||
| 19 | //// Syscalls //// | ||
| 20 | //////////////////// | ||
| 21 | |||
| 22 | pub fn createMailbox(id: u16) { | ||
| 23 | _ = syscall1(SYS_createMailbox, id); | ||
| 24 | } | ||
| 25 | |||
| 26 | pub fn send(mailbox_id: u16, data: usize) { | ||
| 27 | _ = syscall2(SYS_send, mailbox_id, data); | ||
| 28 | } | ||
| 29 | |||
| 30 | pub fn receive(mailbox_id: u16) -> usize { | ||
| 31 | return syscall1(SYS_receive, mailbox_id); | ||
| 32 | } | ||
| 33 | |||
| 34 | pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) -> bool { | ||
| 35 | return syscall4(SYS_map, v_addr, p_addr, size, usize(writable)) != 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | ///////////////////////// | ||
| 40 | //// Syscall stubs //// | ||
| 41 | ///////////////////////// | ||
| 42 | |||
| 43 | pub inline fn syscall0(number: usize) -> usize { | ||
| 44 | return asm volatile ("int $0x80" | ||
| 45 | : [ret] "={eax}" (-> usize) | ||
| 46 | : [number] "{eax}" (number)); | ||
| 47 | } | ||
| 48 | |||
| 49 | pub inline fn syscall1(number: usize, arg1: usize) -> usize { | ||
| 50 | return asm volatile ("int $0x80" | ||
| 51 | : [ret] "={eax}" (-> usize) | ||
| 52 | : [number] "{eax}" (number), | ||
| 53 | [arg1] "{ecx}" (arg1)); | ||
| 54 | } | ||
| 55 | |||
| 56 | pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { | ||
| 57 | return asm volatile ("int $0x80" | ||
| 58 | : [ret] "={eax}" (-> usize) | ||
| 59 | : [number] "{eax}" (number), | ||
| 60 | [arg1] "{ecx}" (arg1), | ||
| 61 | [arg2] "{edx}" (arg2)); | ||
| 62 | } | ||
| 63 | |||
| 64 | pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { | ||
| 65 | return asm volatile ("int $0x80" | ||
| 66 | : [ret] "={eax}" (-> usize) | ||
| 67 | : [number] "{eax}" (number), | ||
| 68 | [arg1] "{ecx}" (arg1), | ||
| 69 | [arg2] "{edx}" (arg2), | ||
| 70 | [arg3] "{ebx}" (arg3)); | ||
| 71 | } | ||
| 72 | |||
| 73 | pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { | ||
| 74 | return asm volatile ("int $0x80" | ||
| 75 | : [ret] "={eax}" (-> usize) | ||
| 76 | : [number] "{eax}" (number), | ||
| 77 | [arg1] "{ecx}" (arg1), | ||
| 78 | [arg2] "{edx}" (arg2), | ||
| 79 | [arg3] "{ebx}" (arg3), | ||
| 80 | [arg4] "{esi}" (arg4)); | ||
| 81 | } | ||
| 82 | |||
| 83 | pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, | ||
| 84 | arg4: usize, arg5: usize) -> usize | ||
| 85 | { | ||
| 86 | return asm volatile ("int $0x80" | ||
| 87 | : [ret] "={eax}" (-> usize) | ||
| 88 | : [number] "{eax}" (number), | ||
| 89 | [arg1] "{ecx}" (arg1), | ||
| 90 | [arg2] "{edx}" (arg2), | ||
| 91 | [arg3] "{ebx}" (arg3), | ||
| 92 | [arg4] "{esi}" (arg4), | ||
| 93 | [arg5] "{edi}" (arg5)); | ||
| 94 | } | ||
std/special/bootstrap.zig+8| ... | @@ -11,6 +11,8 @@ comptime { | ... | @@ -11,6 +11,8 @@ comptime { |
| 11 | const strong_linkage = builtin.GlobalLinkage.Strong; | 11 | const strong_linkage = builtin.GlobalLinkage.Strong; |
| 12 | if (builtin.link_libc) { | 12 | if (builtin.link_libc) { |
| 13 | @export("main", main, strong_linkage); | 13 | @export("main", main, strong_linkage); |
| 14 | } else if (builtin.os == builtin.Os.zen) { | ||
| 15 | @export("main", zenMain, strong_linkage); | ||
| 14 | } else if (builtin.os == builtin.Os.windows) { | 16 | } else if (builtin.os == builtin.Os.windows) { |
| 15 | @export("WinMainCRTStartup", WinMainCRTStartup, strong_linkage); | 17 | @export("WinMainCRTStartup", WinMainCRTStartup, strong_linkage); |
| 16 | } else { | 18 | } else { |
| ... | @@ -18,6 +20,12 @@ comptime { | ... | @@ -18,6 +20,12 @@ comptime { |
| 18 | } | 20 | } |
| 19 | } | 21 | } |
| 20 | 22 | ||
| 23 | extern fn zenMain() -> noreturn { | ||
| 24 | // TODO: call exit. | ||
| 25 | root.main() %% {}; | ||
| 26 | while (true) {} | ||
| 27 | } | ||
| 28 | |||
| 21 | nakedcc fn _start() -> noreturn { | 29 | nakedcc fn _start() -> noreturn { |
| 22 | switch (builtin.arch) { | 30 | switch (builtin.arch) { |
| 23 | builtin.Arch.x86_64 => { | 31 | builtin.Arch.x86_64 => { |
std/special/panic.zig+8-4| ... | @@ -6,9 +6,13 @@ | ... | @@ -6,9 +6,13 @@ |
| 6 | const builtin = @import("builtin"); | 6 | const builtin = @import("builtin"); |
| 7 | 7 | ||
| 8 | pub coldcc fn panic(msg: []const u8) -> noreturn { | 8 | pub coldcc fn panic(msg: []const u8) -> noreturn { |
| 9 | if (builtin.os == builtin.Os.freestanding) { | 9 | switch (builtin.os) { |
| 10 | while (true) {} | 10 | // TODO: fix panic in zen. |
| 11 | } else { | 11 | builtin.Os.freestanding, builtin.Os.zen => { |
| 12 | @import("std").debug.panic("{}", msg); | 12 | while (true) {} |
| 13 | }, | ||
| 14 | else => { | ||
| 15 | @import("std").debug.panic("{}", msg); | ||
| 16 | }, | ||
| 13 | } | 17 | } |
| 14 | } | 18 | } |