From 4ebcf64864eeec6c2086826242f53eedc69275ad Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 21 Sep 2019 23:00:36 +0200 Subject: Initial support for mipsel architecture¬ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/analyze.cpp | 2 ++ src/link.cpp | 6 +++++- src/target.cpp | 7 ++++++- src/target.hpp | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/analyze.cpp b/src/analyze.cpp index 5a3551a7c2..c03d145c5d 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -918,6 +918,8 @@ bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id) { return abi_class == X64CABIClass_MEMORY; } else if (target_is_arm(g->zig_target)) { return type_size(g, fn_type_id->return_type) > 16; + } else if (g->zig_target->arch == ZigLLVM_mipsel) { + return false; } zig_panic("TODO implement C ABI for this architecture. See https://github.com/ziglang/zig/issues/1481"); } diff --git a/src/link.cpp b/src/link.cpp index 785b522993..6690f48838 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -1813,10 +1813,14 @@ static void construct_linker_job_elf(LinkJob *lj) { lj->args.append("--allow-shlib-undefined"); } - if (g->zig_target->os == OsZen) { + // MIPS entry point name is __start instead of _start, force the linker to + // use the latter + if (target_is_mips(g->zig_target) || g->zig_target->os == OsZen) { lj->args.append("-e"); lj->args.append("_start"); + } + if (g->zig_target->os == OsZen) { lj->args.append("--image-base=0x10000000"); } } diff --git a/src/target.cpp b/src/target.cpp index 70c5b169ce..3f7bd75011 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -1450,6 +1450,7 @@ const char *arch_stack_pointer_register_name(ZigLLVM_ArchType arch) { case ZigLLVM_aarch64_32: case ZigLLVM_riscv32: case ZigLLVM_riscv64: + case ZigLLVM_mipsel: return "sp"; case ZigLLVM_amdgcn: @@ -1469,7 +1470,6 @@ const char *arch_stack_pointer_register_name(ZigLLVM_ArchType arch) { case ZigLLVM_mips: case ZigLLVM_mips64: case ZigLLVM_mips64el: - case ZigLLVM_mipsel: case ZigLLVM_msp430: case ZigLLVM_nvptx: case ZigLLVM_nvptx64: @@ -1886,6 +1886,11 @@ bool target_is_riscv(const ZigTarget *target) { return target->arch == ZigLLVM_riscv32 || target->arch == ZigLLVM_riscv64; } +bool target_is_mips(const ZigTarget *target) { + return target->arch == ZigLLVM_mips || target->arch == ZigLLVM_mipsel || + target->arch == ZigLLVM_mips64 || target->arch == ZigLLVM_mips64el; +} + unsigned target_fn_align(const ZigTarget *target) { return 16; } diff --git a/src/target.hpp b/src/target.hpp index b89b0bdc9d..c157b40011 100644 --- a/src/target.hpp +++ b/src/target.hpp @@ -172,6 +172,7 @@ bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target ZigLLVM_OSType get_llvm_os_type(Os os_type); bool target_is_arm(const ZigTarget *target); +bool target_is_mips(const ZigTarget *target); bool target_allows_addr_zero(const ZigTarget *target); bool target_has_valgrind_support(const ZigTarget *target); bool target_os_is_darwin(Os os); -- cgit v1.2.3 From c8e4108c5b822af0cc99d35baea108c1738d55ff Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 26 Sep 2019 17:13:57 +0200 Subject: Export _start as __start for MIPS targets --- lib/std/special/start.zig | 7 +++++++ src/link.cpp | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/lib/std/special/start.zig b/lib/std/special/start.zig index 69ae65be5e..205766d05b 100644 --- a/lib/std/special/start.zig +++ b/lib/std/special/start.zig @@ -13,6 +13,11 @@ const is_wasm = switch (builtin.arch) { else => false, }; +const is_mips = switch (builtin.arch) { + .mips, .mipsel, .mips64, .mips64el => true, + else => false, +}; + comptime { if (builtin.link_libc) { @export("main", main, .Strong); @@ -22,6 +27,8 @@ comptime { @export("_start", wasm_freestanding_start, .Strong); } else if (builtin.os == .uefi) { @export("EfiMain", EfiMain, .Strong); + } else if (is_mips) { + if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong); } else { if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong); } diff --git a/src/link.cpp b/src/link.cpp index 6690f48838..41fb2ca415 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -1813,14 +1813,9 @@ static void construct_linker_job_elf(LinkJob *lj) { lj->args.append("--allow-shlib-undefined"); } - // MIPS entry point name is __start instead of _start, force the linker to - // use the latter - if (target_is_mips(g->zig_target) || g->zig_target->os == OsZen) { + if (g->zig_target->os == OsZen) { lj->args.append("-e"); lj->args.append("_start"); - } - - if (g->zig_target->os == OsZen) { lj->args.append("--image-base=0x10000000"); } } -- cgit v1.2.3