From 94cd54f10aeaa5a99bc31a254796992fbb4c0e50 Mon Sep 17 00:00:00 2001 From: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com> Date: Wed, 28 Oct 2026 23:44:57 -0400 Subject: [PATCH 1/2] jit: honour the zero register and 32-bit forms in AND and ORR In the logical (shifted register) group a register field of 31 selects the zero register, not the stack pointer stored at guest slot 31, and a write to a 32-bit W register clears bits 63:32 of the 64-bit register. The AND handler read guest slot 31 for register operands and computed every result 64 bits wide, and the ORR handler had the same 32-bit gap; both silently corrupted guest state because the corpus seeds start with zeroed registers. AND now clears the destination when either source is the zero register. The 32-bit forms zero-extend their result with a 32-bit register copy; LSR zero-extends its source first, and ASR realigns bit 31 into the 64-bit sign position before a single SAR. Flag-setting forms needing 32-bit compare semantics, W-form shift amounts above 31, and W-form rotates needing a 32-bit rotate macro are rejected explicitly instead of being computed with 64-bit rules. Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com> --- src/backend/x86/bal_x86_tier1_compiler.c | 158 +++++++++++++++++++---- 1 file changed, 131 insertions(+), 27 deletions(-) diff --git a/src/backend/x86/bal_x86_tier1_compiler.c b/src/backend/x86/bal_x86_tier1_compiler.c index a71c3d81..685dee30 100644 --- a/src/backend/x86/bal_x86_tier1_compiler.c +++ b/src/backend/x86/bal_x86_tier1_compiler.c @@ -94,6 +94,12 @@ static void translate_or_reg(bal_tier1_compiler_t *compiler, const bal_decoder_instruction_metadata_t *metadata, uint32_t instruction); +static void push_shift_macro(bal_tier1_compiler_t *compiler, + bal_x86_register_t x86_register, + uint32_t shift_amount, + uint32_t shift_type, + const bool is_32bit); + static void translate_ldr(bal_tier1_compiler_t *compiler, const bal_decoder_instruction_metadata_t *metadata, uint32_t instruction); @@ -1363,6 +1369,7 @@ translate_and_reg(bal_tier1_compiler_t *BAL_RESTRICT compile const bool is_setting_flags = 'S' == metadata->name[3]; const bool is_zero_register = 31 == rd; + const bool is_32bit = BAL_OPERAND_TYPE_REGISTER_32 == operands[1].type; // AND targeting the zero register doesn't alter the state. if (is_zero_register && !is_setting_flags) @@ -1378,6 +1385,45 @@ translate_and_reg(bal_tier1_compiler_t *BAL_RESTRICT compile return; } + if (is_setting_flags && (is_32bit || 31U == rn || 31U == rm)) + { + BAL_LOG_ERROR(&bal_thread_logger, + "Aborting function: unsupported flag-setting form of AND"); + compiler->status = BAL_ERROR_UNKNOWN_INSTRUCTION; + return; + } + + if (is_32bit && (shift_amount > 31U || 0b11 == shift_type)) + { + BAL_LOG_ERROR(&bal_thread_logger, + "Aborting function: unsupported shift for 32-bit AND: type %u amount %u", + shift_type, + shift_amount); + compiler->status = BAL_ERROR_UNKNOWN_INSTRUCTION; + return; + } + + if (31U == rn || 31U == rm) + { + const bool skip_load_rd = true; + const bal_x86_register_t x86_rd = allocate_x86_register(compiler, rd, skip_load_rd); + + if (BAL_UNLIKELY(BAL_X86_INVALID == x86_rd)) + { + compiler->status = BAL_ERROR_INCORRECT_REGISTER_TYPE; + return; + } + + const bal_x86_macro_t mov_macro = { + .opcode = BAL_X86_MACRO_MOV_REGISTER_IMMEDIATE, + .destination = x86_rd, + .immediate_or_offset = 0ULL, + }; + bal_sliding_window_push(&compiler->window, mov_macro); + compiler->is_dirty |= 1U << rd; + return; + } + const bool skip_load_rn = false; const bal_x86_register_t x86_rn = allocate_x86_register(compiler, rn, skip_load_rn); const bool skip_load_rm = false; @@ -1402,20 +1448,6 @@ translate_and_reg(bal_tier1_compiler_t *BAL_RESTRICT compile if (shift_amount > 0) { - bal_x86_macro_opcode_t shift_opcode = BAL_X86_MACRO_SHL_REGISTER_IMMEDIATE; - - if (0b01 == shift_type) - { - shift_opcode = BAL_X86_MACRO_SHR_REGISTER_IMMEDIATE; - } - else if (0b10 == shift_type) - { - shift_opcode = BAL_X86_MACRO_SAR_REGISTER_IMMEDIATE; - } - else if (0b11 == shift_type) - { - shift_opcode = BAL_X86_MACRO_ROR_REGISTER_IMMEDIATE; - } if (rd != rm || is_zero_register) { const bal_x86_macro_t mov_macro = { @@ -1427,12 +1459,7 @@ translate_and_reg(bal_tier1_compiler_t *BAL_RESTRICT compile x86_operand2 = BAL_X86_REGISTER_DISCARD_RESULT; } - const bal_x86_macro_t shift_macro = { - .opcode = shift_opcode, - .destination = x86_operand2, - .immediate_or_offset = shift_amount, - }; - bal_sliding_window_push(&compiler->window, shift_macro); + push_shift_macro(compiler, x86_operand2, shift_amount, shift_type, is_32bit); } if (is_zero_register) @@ -1471,6 +1498,16 @@ translate_and_reg(bal_tier1_compiler_t *BAL_RESTRICT compile }; bal_sliding_window_push(&compiler->window, and_macro); compiler->is_dirty |= 1U << rd; + + if (is_32bit) + { + const bal_x86_macro_t extend_macro = { + .opcode = BAL_X86_MACRO_MOV_REGISTER_REGISTER_32, + .destination = x86_rd, + .source = x86_rd, + }; + bal_sliding_window_push(&compiler->window, extend_macro); + } } if (is_setting_flags) @@ -1509,8 +1546,40 @@ static void push_shift_macro(bal_tier1_compiler_t *compiler, bal_x86_register_t x86_register, uint32_t shift_amount, - uint32_t shift_type) + uint32_t shift_type, + const bool is_32bit) { + if (is_32bit) + { + if (0b10 == shift_type) + { + const bal_x86_macro_t align_macro = { + .opcode = BAL_X86_MACRO_SHL_REGISTER_IMMEDIATE, + .destination = x86_register, + .immediate_or_offset = 32ULL, + }; + bal_sliding_window_push(&compiler->window, align_macro); + + const bal_x86_macro_t sign_macro = { + .opcode = BAL_X86_MACRO_SAR_REGISTER_IMMEDIATE, + .destination = x86_register, + .immediate_or_offset = shift_amount + 32ULL, + }; + bal_sliding_window_push(&compiler->window, sign_macro); + return; + } + + if (0b01 == shift_type) + { + const bal_x86_macro_t extend_macro = { + .opcode = BAL_X86_MACRO_MOV_REGISTER_REGISTER_32, + .destination = x86_register, + .source = x86_register, + }; + bal_sliding_window_push(&compiler->window, extend_macro); + } + } + bal_x86_macro_opcode_t shift_opcode = BAL_X86_MACRO_SHL_REGISTER_IMMEDIATE; if (0b01 == shift_type) @@ -1559,6 +1628,18 @@ translate_or_reg(bal_tier1_compiler_t *BAL_RESTRICT compiler return; } + const bool is_32bit = BAL_OPERAND_TYPE_REGISTER_32 == operands[1].type; + + if (is_32bit && (shift_amount > 31U || 0b11 == shift_type)) + { + BAL_LOG_ERROR(&bal_thread_logger, + "Aborting function: unsupported shift for 32-bit ORR: type %u amount %u", + shift_type, + shift_amount); + compiler->status = BAL_ERROR_UNKNOWN_INSTRUCTION; + return; + } + const bool rn_is_zero = 31U == rn; const bool rm_is_zero = 31U == rm; @@ -1616,7 +1697,8 @@ translate_or_reg(bal_tier1_compiler_t *BAL_RESTRICT compiler if (x86_rd != x86_rn) { const bal_x86_macro_t mov_macro = { - .opcode = BAL_X86_MACRO_MOV_REGISTER_REGISTER, + .opcode = is_32bit ? BAL_X86_MACRO_MOV_REGISTER_REGISTER_32 + : BAL_X86_MACRO_MOV_REGISTER_REGISTER, .destination = x86_rd, .source = x86_rn, }; @@ -1640,10 +1722,11 @@ translate_or_reg(bal_tier1_compiler_t *BAL_RESTRICT compiler }; bal_sliding_window_push(&compiler->window, copy_macro); push_shift_macro(compiler, BAL_X86_REGISTER_DISCARD_RESULT, shift_amount, - shift_type); + shift_type, is_32bit); const bal_x86_macro_t result_macro = { - .opcode = BAL_X86_MACRO_MOV_REGISTER_REGISTER, + .opcode = is_32bit ? BAL_X86_MACRO_MOV_REGISTER_REGISTER_32 + : BAL_X86_MACRO_MOV_REGISTER_REGISTER, .destination = x86_rd, .source = BAL_X86_REGISTER_DISCARD_RESULT, }; @@ -1651,13 +1734,24 @@ translate_or_reg(bal_tier1_compiler_t *BAL_RESTRICT compiler } else { - push_shift_macro(compiler, x86_rm, shift_amount, shift_type); + push_shift_macro(compiler, x86_rm, shift_amount, shift_type, is_32bit); + + if (is_32bit) + { + const bal_x86_macro_t extend_macro = { + .opcode = BAL_X86_MACRO_MOV_REGISTER_REGISTER_32, + .destination = x86_rd, + .source = x86_rd, + }; + bal_sliding_window_push(&compiler->window, extend_macro); + } } } else if (x86_rd != x86_rm) { const bal_x86_macro_t mov_macro = { - .opcode = BAL_X86_MACRO_MOV_REGISTER_REGISTER, + .opcode = is_32bit ? BAL_X86_MACRO_MOV_REGISTER_REGISTER_32 + : BAL_X86_MACRO_MOV_REGISTER_REGISTER, .destination = x86_rd, .source = x86_rm, }; @@ -1683,7 +1777,7 @@ translate_or_reg(bal_tier1_compiler_t *BAL_RESTRICT compiler x86_operand2 = BAL_X86_REGISTER_DISCARD_RESULT; } - push_shift_macro(compiler, x86_operand2, shift_amount, shift_type); + push_shift_macro(compiler, x86_operand2, shift_amount, shift_type, is_32bit); } bal_x86_register_t x86_or_source = x86_operand2; @@ -1709,6 +1803,16 @@ translate_or_reg(bal_tier1_compiler_t *BAL_RESTRICT compiler }; bal_sliding_window_push(&compiler->window, or_macro); compiler->is_dirty |= 1U << rd; + + if (is_32bit) + { + const bal_x86_macro_t extend_macro = { + .opcode = BAL_X86_MACRO_MOV_REGISTER_REGISTER_32, + .destination = x86_rd, + .source = x86_rd, + }; + bal_sliding_window_push(&compiler->window, extend_macro); + } } void From f3da7a0e6dd6e89c970e451a0cd1fa479607cac1 Mon Sep 17 00:00:00 2001 From: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com> Date: Wed, 28 Oct 2026 23:44:57 -0400 Subject: [PATCH 2/2] tests: add Tier 1 AND (shifted register) translation tests Ten tests exercise the zero-register sources, the discarded zero-register destination, and the 32-bit shift forms with non-zero state and a stack pointer deliberately set to a sentinel value that the old code would have read through register field 31. Two further tests cover the 32-bit ORR destination: an all-ones source pair must clear bits 63:32, and a left shift of a W register must drop the bits it shifts past bit 31. Signed-off-by: bluetoe-99 <102478736+bluetoe-99@users.noreply.github.com> --- tests/CMakeLists.txt | 1 + tests/unit/bal_tier1/test_bal_tier1_and.c | 227 ++++++++++++++++++++++ tests/unit/bal_tier1/test_bal_tier1_orr.c | 32 +++ 3 files changed, 260 insertions(+) create mode 100644 tests/unit/bal_tier1/test_bal_tier1_and.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c45c5e0c..ec272cb7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -47,6 +47,7 @@ target_link_libraries(test_bal_assembler_sub PUBLIC BallisticTestAssemblerFixtur add_ballistic_test(test_bal_decoder_integrity unit/bal_decoder/test_bal_decoder_integrity.c) add_ballistic_test(test_bal_tier1_orr unit/bal_tier1/test_bal_tier1_orr.c) +add_ballistic_test(test_bal_tier1_and unit/bal_tier1/test_bal_tier1_and.c) add_ballistic_test(test_bal_jit_debug_lifecycle unit/bal_jit_debug/test_bal_jit_debug_lifecycle.c) add_ballistic_test(test_bal_jit_debug_add_block unit/bal_jit_debug/test_bal_jit_debug_add_block.c) diff --git a/tests/unit/bal_tier1/test_bal_tier1_and.c b/tests/unit/bal_tier1/test_bal_tier1_and.c new file mode 100644 index 00000000..3c98ebee --- /dev/null +++ b/tests/unit/bal_tier1/test_bal_tier1_and.c @@ -0,0 +1,227 @@ +#include "bal_engine.h" +#include "bal_engine_flags.h" +#include "bal_memory.h" +#include "unity.h" +#include + +/* Engine-level tests: AND (shifted register), zero-register fields, W-forms. */ + +#define ARM64_RET_ENCODING 0xD65F03C0U +#define TEST_GUEST_MEMORY_SIZE 4096U + +/* AND X8, X9, X10 */ +#define AND_X8_X9_X10 0x8A0A0128U +/* AND X8, X9, X10, LSL #4 */ +#define AND_X8_X9_X10_LSL4 0x8A0A1128U +/* AND X8, X9, XZR */ +#define AND_X8_X9_XZR 0x8A1F0128U +/* AND X8, XZR, X10 */ +#define AND_X8_XZR_X10 0x8A0A03E8U +/* AND X8, XZR, XZR */ +#define AND_X8_XZR_XZR 0x8A1F03E8U +/* AND XZR, X9, X10 */ +#define AND_XZR_X9_X10 0x8A0A01E8U +/* AND W8, W9, W10 */ +#define AND_W8_W9_W10 0x0A0A0128U +/* AND W8, W9, W10, LSL #4 */ +#define AND_W8_W9_W10_LSL4 0x0A0A1128U +/* AND W8, W9, W10, LSR #4 */ +#define AND_W8_W9_W10_LSR4 0x0A4A1128U +/* AND W8, W9, W10, ASR #4 */ +#define AND_W8_W9_W10_ASR4 0x0A8A1128U + +static uint32_t bal_test_guest_memory[TEST_GUEST_MEMORY_SIZE / sizeof(uint32_t)]; + +void +setUp(void) +{ + (void)memset(bal_test_guest_memory, 0, sizeof(bal_test_guest_memory)); +} + +void +tearDown(void) +{ +} + +static void +run_single_guest_instruction(const uint32_t instruction, bal_cpu_t *BAL_RESTRICT cpu) +{ + bal_test_guest_memory[0] = instruction; + bal_test_guest_memory[1] = ARM64_RET_ENCODING; + + bal_allocator_t allocator = {}; + bal_allocator_default_init(&allocator); + + bal_memory_interface_t memory_interface = {}; + TEST_ASSERT_EQUAL(BAL_SUCCESS, + bal_flat_translation_interface_init(&allocator, + &memory_interface, + bal_test_guest_memory, + sizeof(bal_test_guest_memory))); + + cpu->pc = 0ULL; + + bal_engine_t engine = {}; + TEST_ASSERT_EQUAL(BAL_SUCCESS, bal_engine_init(&engine, cpu, &allocator, &memory_interface)); + + engine.flags |= BAL_ENGINE_FLAG_SINGLE_STEP; + + const bal_error_t run_status = bal_engine_run_thread(&engine); + + bal_engine_destroy(&engine); + (void)bal_flat_translation_interface_destroy(&allocator, &memory_interface); + + TEST_ASSERT_EQUAL(BAL_SUCCESS, run_status); +} + +static void +test_BalTier1And_CombinesBothSourceRegisters(void) +{ + bal_cpu_t cpu = {}; + cpu.x[8] = 0xAAAAAAAAAAAAAAAAULL; + cpu.x[9] = 0xFFFFFFFFFFFFFF00ULL; + cpu.x[10] = 0x00FF00FF00FF00FFULL; + + run_single_guest_instruction(AND_X8_X9_X10, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0x00FF00FF00FF0000ULL, cpu.x[8]); +} + +static void +test_BalTier1And_AppliesLeftShiftToSecondSource(void) +{ + bal_cpu_t cpu = {}; + cpu.x[8] = 0xDEADBEEFDEADBEEFULL; + cpu.x[9] = 0x00000000000000FFULL; + cpu.x[10] = 0x0000000000000001ULL; + + run_single_guest_instruction(AND_X8_X9_X10_LSL4, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0x0000000000000010ULL, cpu.x[8]); +} + +static void +test_BalTier1And_SecondSourceZeroRegisterClearsResult(void) +{ + bal_cpu_t cpu = {}; + cpu.x[8] = 0xAAAAAAAAAAAAAAAAULL; + cpu.x[9] = 0x0F0F0F0F0F0F0F0FULL; + /* Slot 31 stores SP: a source field of 31 must read zero, never this. */ + cpu.x[31] = 0xCAFEBABE00000000ULL; + + run_single_guest_instruction(AND_X8_X9_XZR, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0x0000000000000000ULL, cpu.x[8]); + TEST_ASSERT_EQUAL_HEX64(0xCAFEBABE00000000ULL, cpu.x[31]); +} + +static void +test_BalTier1And_FirstSourceZeroRegisterClearsResult(void) +{ + bal_cpu_t cpu = {}; + cpu.x[8] = 0xAAAAAAAAAAAAAAAAULL; + cpu.x[10] = 0x0123456789ABCDEFULL; + cpu.x[31] = 0xCAFEBABE00000000ULL; + + run_single_guest_instruction(AND_X8_XZR_X10, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0x0000000000000000ULL, cpu.x[8]); + TEST_ASSERT_EQUAL_HEX64(0xCAFEBABE00000000ULL, cpu.x[31]); +} + +static void +test_BalTier1And_BothSourcesZeroRegisterClearsResult(void) +{ + bal_cpu_t cpu = {}; + cpu.x[8] = 0xAAAAAAAAAAAAAAAAULL; + cpu.x[31] = 0xCAFEBABE00000000ULL; + + run_single_guest_instruction(AND_X8_XZR_XZR, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0x0000000000000000ULL, cpu.x[8]); +} + +static void +test_BalTier1And_WriteToZeroRegisterIsDiscarded(void) +{ + bal_cpu_t cpu = {}; + /* Slot 31 stores SP; AND targets XZR, so the slot must be untouched. */ + cpu.x[9] = 0xFFFFFFFFFFFFFF00ULL; + cpu.x[10] = 0x00FF00FF00FF00FFULL; + cpu.x[31] = 0xCAFEBABE00000000ULL; + + run_single_guest_instruction(AND_XZR_X9_X10, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0xCAFEBABE00000000ULL, cpu.x[31]); +} + +static void +test_BalTier1And_ThirtyTwoBitResultClearsUpperHalf(void) +{ + bal_cpu_t cpu = {}; + cpu.x[8] = 0xAAAAAAAAAAAAAAAAULL; + cpu.x[9] = 0xFFFFFFFFFFFFFFFFULL; + cpu.x[10] = 0xDEAD000000BCF000ULL; + + run_single_guest_instruction(AND_W8_W9_W10, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0x0000000000BCF000ULL, cpu.x[8]); +} + +static void +test_BalTier1And_ThirtyTwoBitLeftShiftIgnoresUpperHalf(void) +{ + bal_cpu_t cpu = {}; + cpu.x[8] = 0xAAAAAAAAAAAAAAAAULL; + cpu.x[9] = 0xFFFFFFFFFFFFFFFFULL; + cpu.x[10] = 0x000000FF000000F0ULL; + + run_single_guest_instruction(AND_W8_W9_W10_LSL4, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0x0000000000000F00ULL, cpu.x[8]); +} + +static void +test_BalTier1And_ThirtyTwoBitLogicalShiftUsesThirtyTwoBits(void) +{ + bal_cpu_t cpu = {}; + cpu.x[8] = 0xAAAAAAAAAAAAAAAAULL; + cpu.x[9] = 0xFFFFFFFFFFFFFFFFULL; + cpu.x[10] = 0x000000FF00000F00ULL; + + run_single_guest_instruction(AND_W8_W9_W10_LSR4, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0x00000000000000F0ULL, cpu.x[8]); +} + +static void +test_BalTier1And_ThirtyTwoBitArithmeticShiftExtendsSignBit(void) +{ + bal_cpu_t cpu = {}; + cpu.x[8] = 0xAAAAAAAAAAAAAAAAULL; + cpu.x[9] = 0xFFFFFFFFFFFFFFFFULL; + cpu.x[10] = 0x0000000080000010ULL; + + run_single_guest_instruction(AND_W8_W9_W10_ASR4, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0x00000000F8000001ULL, cpu.x[8]); +} + +int +main(void) +{ + UNITY_BEGIN(); + RUN_TEST(test_BalTier1And_CombinesBothSourceRegisters); + RUN_TEST(test_BalTier1And_AppliesLeftShiftToSecondSource); + RUN_TEST(test_BalTier1And_SecondSourceZeroRegisterClearsResult); + RUN_TEST(test_BalTier1And_FirstSourceZeroRegisterClearsResult); + RUN_TEST(test_BalTier1And_BothSourcesZeroRegisterClearsResult); + RUN_TEST(test_BalTier1And_WriteToZeroRegisterIsDiscarded); + RUN_TEST(test_BalTier1And_ThirtyTwoBitResultClearsUpperHalf); + RUN_TEST(test_BalTier1And_ThirtyTwoBitLeftShiftIgnoresUpperHalf); + RUN_TEST(test_BalTier1And_ThirtyTwoBitLogicalShiftUsesThirtyTwoBits); + RUN_TEST(test_BalTier1And_ThirtyTwoBitArithmeticShiftExtendsSignBit); + return UNITY_END(); +} + +/*** end of file ***/ diff --git a/tests/unit/bal_tier1/test_bal_tier1_orr.c b/tests/unit/bal_tier1/test_bal_tier1_orr.c index 72b063b3..26cecb7a 100644 --- a/tests/unit/bal_tier1/test_bal_tier1_orr.c +++ b/tests/unit/bal_tier1/test_bal_tier1_orr.c @@ -16,6 +16,10 @@ #define ORR_X8_X9_XZR 0xAA1F0128U #define ORR_X8_XZR_XZR 0xAA1F03E8U #define ORR_X8_XZR_X8_LSL4 0xAA0813E8U +/* ORR W8, W9, W10 */ +#define ORR_W8_W9_W10 0x2A0A0128U +/* ORR W8, W9, W10, LSL #4 */ +#define ORR_W8_W9_W10_LSL4 0x2A0A1128U static uint32_t bal_test_guest_memory[TEST_GUEST_MEMORY_SIZE / sizeof(uint32_t)]; @@ -174,6 +178,32 @@ test_BalTier1Orr_ZeroRegisterSourceShiftOfDestinationItself(void) TEST_ASSERT_EQUAL_HEX64(0x0000000000000FF0ULL, cpu.x[8]); } +static void +test_BalTier1Orr_ThirtyTwoBitResultClearsUpperHalf(void) +{ + bal_cpu_t cpu = {}; + cpu.x[8] = 0xDEADBEEFDEADBEEFULL; + cpu.x[9] = 0xFFFFFFFFFFFFFFFFULL; + cpu.x[10] = 0xDEAD00000000FFFFULL; + + run_single_guest_instruction(ORR_W8_W9_W10, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0x00000000FFFFFFFFULL, cpu.x[8]); +} + +static void +test_BalTier1Orr_ThirtyTwoBitLeftShiftIgnoresUpperHalf(void) +{ + bal_cpu_t cpu = {}; + cpu.x[8] = 0xDEADBEEFDEADBEEFULL; + cpu.x[9] = 0xFFFFFFFF00000000ULL; + cpu.x[10] = 0x000000FF000000F0ULL; + + run_single_guest_instruction(ORR_W8_W9_W10_LSL4, &cpu); + + TEST_ASSERT_EQUAL_HEX64(0x0000000000000F00ULL, cpu.x[8]); +} + int main(void) { @@ -187,6 +217,8 @@ main(void) RUN_TEST(test_BalTier1Orr_SecondSourceZeroRegisterKeepsFirstOperand); RUN_TEST(test_BalTier1Orr_BothSourcesZeroRegisterClearDestination); RUN_TEST(test_BalTier1Orr_ZeroRegisterSourceShiftOfDestinationItself); + RUN_TEST(test_BalTier1Orr_ThirtyTwoBitResultClearsUpperHalf); + RUN_TEST(test_BalTier1Orr_ThirtyTwoBitLeftShiftIgnoresUpperHalf); return UNITY_END(); }