| 1 | pub const encoding = @import("../codegen.zig").aarch64.encoding; |
| 2 | |
| 3 | pub fn writeAddImmInst(value: u12, code: *[4]u8) void { |
| 4 | var inst: encoding.Instruction = .read(code); |
| 5 | inst.data_processing_immediate.add_subtract_immediate.group.imm12 = value; |
| 6 | inst.write(code); |
| 7 | } |
| 8 | |
| 9 | pub fn writeLoadStoreRegInst(value: u12, code: *[4]u8) void { |
| 10 | var inst: encoding.Instruction = .read(code); |
| 11 | inst.load_store.register_unsigned_immediate.group.imm12 = value; |
| 12 | inst.write(code); |
| 13 | } |
| 14 | |
| 15 | pub fn calcNumberOfPages(saddr: i64, taddr: i64) error{Overflow}!i33 { |
| 16 | return math.cast(i21, (taddr >> 12) - (saddr >> 12)) orelse error.Overflow; |
| 17 | } |
| 18 | |
| 19 | pub fn writeAdrInst(imm: i33, code: *[4]u8) void { |
| 20 | var inst: encoding.Instruction = .read(code); |
| 21 | inst.data_processing_immediate.pc_relative_addressing.group.immhi = @intCast(imm >> 2); |
| 22 | inst.data_processing_immediate.pc_relative_addressing.group.immlo = @bitCast(@as(i2, @truncate(imm))); |
| 23 | inst.write(code); |
| 24 | } |
| 25 | |
| 26 | pub fn writeBranchImm(disp: i28, code: *[4]u8) void { |
| 27 | var inst: encoding.Instruction = .read(code); |
| 28 | inst.branch_exception_generating_system.unconditional_branch_immediate.group.imm26 = @intCast(@shrExact(disp, 2)); |
| 29 | inst.write(code); |
| 30 | } |
| 31 | |
| 32 | pub fn writeCondBrImm(disp: i19, code: *[4]u8) void { |
| 33 | var inst: encoding.Instruction = .read(code); |
| 34 | inst.branch_exception_generating_system.conditional_branch_immediate.group.imm19 = @intCast(@shrExact(disp, 2)); |
| 35 | inst.write(code); |
| 36 | } |
| 37 | |
| 38 | const assert = std.debug.assert; |
| 39 | const builtin = @import("builtin"); |
| 40 | const math = std.math; |
| 41 | const mem = std.mem; |
| 42 | const std = @import("std"); |