| ... | ... | @@ -64,7 +64,7 @@ pub const callee_preserved_regs = [_]Register{ |
| 64 | 64 | }; |
| 65 | 65 | |
| 66 | 66 | pub const c_abi_int_param_regs = [_]Register{ .x0, .x1, .x2, .x3, .x4, .x5, .x6, .x7 }; |
| 67 | | pub const c_abi_int_return_regs = [_]Register{ .x0, .x1 }; |
| 67 | pub const c_abi_int_return_regs = [_]Register{ .x0, .x1, .x2, .x3, .x4, .x5, .x6, .x7 }; |
| 68 | 68 | |
| 69 | 69 | test "Register.id" { |
| 70 | 70 | testing.expectEqual(@as(u5, 0), Register.x0.id()); |
| ... | ... | @@ -699,17 +699,18 @@ pub const Instruction = union(enum) { |
| 699 | 699 | |
| 700 | 700 | // Load or store register |
| 701 | 701 | |
| 702 | | pub const LdrArgs = struct { |
| 703 | | rn: ?Register = null, |
| 704 | | offset: LoadStoreOffset = LoadStoreOffset.none, |
| 705 | | literal: ?u19 = null, |
| 702 | pub const LdrArgs = union(enum) { |
| 703 | register: struct { |
| 704 | rn: Register, |
| 705 | offset: LoadStoreOffset = LoadStoreOffset.none, |
| 706 | }, |
| 707 | literal: u19, |
| 706 | 708 | }; |
| 707 | 709 | |
| 708 | 710 | pub fn ldr(rt: Register, args: LdrArgs) Instruction { |
| 709 | | if (args.rn) |rn| { |
| 710 | | return loadStoreRegister(rt, rn, args.offset, true); |
| 711 | | } else { |
| 712 | | return loadLiteral(rt, args.literal.?); |
| 711 | switch (args) { |
| 712 | .register => |info| return loadStoreRegister(rt, info.rn, info.offset, true), |
| 713 | .literal => |literal| return loadLiteral(rt, literal), |
| 713 | 714 | } |
| 714 | 715 | } |
| 715 | 716 | |
| ... | ... | @@ -911,19 +912,19 @@ test "serialize instructions" { |
| 911 | 912 | .expected = 0b1_00101_00_0000_0000_0000_0000_0000_0100, |
| 912 | 913 | }, |
| 913 | 914 | .{ // ldr x2, [x1] |
| 914 | | .inst = Instruction.ldr(.x2, .{ .rn = .x1 }), |
| 915 | .inst = Instruction.ldr(.x2, .{ .register = .{ .rn = .x1 } }), |
| 915 | 916 | .expected = 0b11_111_0_01_01_000000000000_00001_00010, |
| 916 | 917 | }, |
| 917 | 918 | .{ // ldr x2, [x1, #1]! |
| 918 | | .inst = Instruction.ldr(.x2, .{ .rn = .x1, .offset = Instruction.LoadStoreOffset.imm_pre_index(1) }), |
| 919 | .inst = Instruction.ldr(.x2, .{ .register = .{ .rn = .x1, .offset = Instruction.LoadStoreOffset.imm_pre_index(1) } }), |
| 919 | 920 | .expected = 0b11_111_0_00_01_0_000000001_11_00001_00010, |
| 920 | 921 | }, |
| 921 | 922 | .{ // ldr x2, [x1], #-1 |
| 922 | | .inst = Instruction.ldr(.x2, .{ .rn = .x1, .offset = Instruction.LoadStoreOffset.imm_post_index(-1) }), |
| 923 | .inst = Instruction.ldr(.x2, .{ .register = .{ .rn = .x1, .offset = Instruction.LoadStoreOffset.imm_post_index(-1) } }), |
| 923 | 924 | .expected = 0b11_111_0_00_01_0_111111111_01_00001_00010, |
| 924 | 925 | }, |
| 925 | 926 | .{ // ldr x2, [x1], (x3) |
| 926 | | .inst = Instruction.ldr(.x2, .{ .rn = .x1, .offset = Instruction.LoadStoreOffset.reg(.x3) }), |
| 927 | .inst = Instruction.ldr(.x2, .{ .register = .{ .rn = .x1, .offset = Instruction.LoadStoreOffset.reg(.x3) } }), |
| 927 | 928 | .expected = 0b11_111_0_00_01_1_00011_011_0_10_00001_00010, |
| 928 | 929 | }, |
| 929 | 930 | .{ // ldr x2, label |