authorgravatar for shawn@anastas.ioShawn Anastasio <shawn@anastas.io> 2020-07-01 16:13:14-05:00
committergravatar for shawn@anastas.ioShawn Anastasio <shawn@anastas.io> 2020-07-01 16:13:14-05:00
log51fcf949f97d068e917c0c3301ba63a4a305ab6e
treea526f0e47e19ffa390e453d1de9e801b2b278cd8
parent8574861ca0bc5e8103c27e3c78866e3a4eb56f98

Implement std.start for powerpc64le

This is a bit hacky since we end up doing more than just grabbing the stack pointer in the inline assembly block. Ideally _start would be implemented in pure asm for powerpc64le, but this will do for now. Still to be implemented is powerpc, powerpc64, and powerpc64 (ELFv2) support. The latter will just require correctly determing target ABI for powerpc64 and enabling the existing powerpc64le implementation for it.

1 files changed, 15 insertions(+), 0 deletions(-)

lib/std/start.zig+15
...@@ -116,6 +116,21 @@ fn _start() callconv(.Naked) noreturn {...@@ -116,6 +116,21 @@ fn _start() callconv(.Naked) noreturn {
116 : [argc] "=r" (-> [*]usize)116 : [argc] "=r" (-> [*]usize)
117 );117 );
118 },118 },
119 .powerpc64le => {
120 // Before returning the stack pointer, we have to set up a backchain
121 // and a few other registers required by the ELFv2 ABI.
122 // TODO: Support powerpc64 (big endian) on ELFv2.
123 starting_stack_ptr = asm (
124 \\ mr 4, 1
125 \\ subi 1, 1, 32
126 \\ li 5, 0
127 \\ std 5, 0(1)
128 \\ mr %[argc], 4
129 : [argc] "=r" (-> [*]usize)
130 :
131 : "r4", "r5"
132 );
133 },
119 else => @compileError("unsupported arch"),134 else => @compileError("unsupported arch"),
120 }135 }
121 // If LLVM inlines stack variables into _start, they will overwrite136 // If LLVM inlines stack variables into _start, they will overwrite