authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-05-26 13:24:57+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-05-26 13:48:29+07:00
log3923722cc617251de91d5bc9a5d4f9c0ca93ee1a
tree937db6c3273471c39544c06a83711442036287bb
parent5fa971610e0f987938d43da9d3a40e2a31fe4605

stage2: sparc64: Account for stack bias & reserved area in genSetReg

genSetReg with ptr_stack_offset should add the bias and reserved area before emitting the instruction.

2 files changed, 13 insertions(+), 13 deletions(-)

src/arch/sparc64/CodeGen.zig+6-6
......@@ -352,7 +352,7 @@ fn gen(self: *Self) !void {
352352 if (cc != .Naked) {
353353 // TODO Finish function prologue and epilogue for sparc64.
354354
355 // save %sp, stack_save_area, %sp
355 // save %sp, stack_reserved_area, %sp
356356 const save_inst = try self.addInst(.{
357357 .tag = .save,
358358 .data = .{
......@@ -360,7 +360,7 @@ fn gen(self: *Self) !void {
360360 .is_imm = true,
361361 .rd = .sp,
362362 .rs1 = .sp,
363 .rs2_or_imm = .{ .imm = -abi.stack_save_area },
363 .rs2_or_imm = .{ .imm = -abi.stack_reserved_area },
364364 },
365365 },
366366 });
......@@ -407,7 +407,7 @@ fn gen(self: *Self) !void {
407407 }
408408
409409 // Backpatch stack offset
410 const total_stack_size = self.max_end_stack + abi.stack_save_area; // TODO + self.saved_regs_stack_space;
410 const total_stack_size = self.max_end_stack + abi.stack_reserved_area; // TODO + self.saved_regs_stack_space;
411411 const stack_size = mem.alignForwardGeneric(u32, total_stack_size, self.stack_align);
412412 if (math.cast(i13, stack_size)) |size| {
413413 self.mir_instructions.set(save_inst, .{
......@@ -2299,7 +2299,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
22992299 return self.genSetReg(ty, reg, .{ .immediate = 0xaaaaaaaaaaaaaaaa });
23002300 },
23012301 .ptr_stack_offset => |off| {
2302 const simm13 = math.cast(u12, off) catch
2302 const simm13 = math.cast(u12, off + abi.stack_bias + abi.stack_reserved_area) catch
23032303 return self.fail("TODO larger stack offsets", .{});
23042304
23052305 _ = try self.addInst(.{
......@@ -2431,7 +2431,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
24312431 try self.genLoad(reg, reg, i13, 0, ty.abiSize(self.target.*));
24322432 },
24332433 .stack_offset => |off| {
2434 const real_offset = off + abi.stack_bias + abi.stack_save_area;
2434 const real_offset = off + abi.stack_bias + abi.stack_reserved_area;
24352435 const simm13 = math.cast(i13, real_offset) catch
24362436 return self.fail("TODO larger stack offsets", .{});
24372437 try self.genLoad(reg, .sp, i13, simm13, ty.abiSize(self.target.*));
......@@ -2465,7 +2465,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
24652465 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
24662466 },
24672467 .register => |reg| {
2468 const real_offset = stack_offset + abi.stack_bias + abi.stack_save_area;
2468 const real_offset = stack_offset + abi.stack_bias + abi.stack_reserved_area;
24692469 const simm13 = math.cast(i13, real_offset) catch
24702470 return self.fail("TODO larger stack offsets", .{});
24712471 return self.genStore(reg, .sp, i13, simm13, abi_size);
src/arch/sparc64/abi.zig+7-7
......@@ -3,17 +3,17 @@ const bits = @import("bits.zig");
33const Register = bits.Register;
44const RegisterManagerFn = @import("../../register_manager.zig").RegisterManager;
55
6// SPARCv9 stack constants.
6// SPARCv9 SysV ABI stack constants.
77// See: Registers and the Stack Frame, page 3P-8, SCD 2.4.1.
88
9// On SPARCv9, %sp points to top of stack + stack bias,
10// and %fp points to top of previous frame + stack bias.
9// The ABI specifies that %sp points to top of stack - stack bias,
10// and %fp points to top of previous frame - stack bias.
1111pub const stack_bias = 2047;
1212
13// The first 176 bytes of the stack is reserved for register saving purposes.
14// SPARCv9 requires to reserve space in the stack for the first six arguments,
15// even though they are usually passed in registers.
16pub const stack_save_area = 176;
13// The first 128 bytes of the stack is reserved for register saving purposes.
14// The ABI also requires to reserve space in the stack for the first six
15// outgoing arguments, even though they are usually passed in registers.
16pub const stack_reserved_area = 128 + 48;
1717
1818// There are no callee-preserved registers since the windowing
1919// mechanism already takes care of them.