Conversation
Implement multiple LDR addressing modes used by Thumb instructions: - LdrImmediate: load word from [Rn + imm5<<2]. - LdrLiteral: load word from literal pool using aligned PC + imm8<<2. - LdrRegister: load word from [Rn + Rm]. - LdrSpRelative: load word from [SP + imm8<<2]. Introduce ReadWordWithCycles helper to centralize memory reads and account for region-dependent cycle costs (SRAM, APB/AHB, SIO, fallback). Update existing memory ops to use the helper so cycle accounting is consistent and correct. These changes add missing instruction handlers and improve timing accuracy when reading words from different bus regions.
Add missing LDR opcode rules to the instruction decoder so the CPU can recognize and dispatch load instructions from various encodings: - Add LDR (register) handler mapped to mask 0xFE00 / value 0x5800. - Add LDR (literal) handler mapped to mask 0xF800 / value 0x4800. - Add LDR (imm5) handler mapped to mask 0xF800 / value 0x6800. - Add LDR (SP, imm8) handler mapped to mask 0xF800 / value 0x9800. These entries complete support for common Thumb LDR encodings and are needed so MemoryOps methods are invoked for load instructions instead of falling through or causing incorrect decoding.
Add methods to InstructionEmiter to emit Thumb LDR variants: - LdrImmediate(rt, rn, imm): LDR (register+imm) using imm>>2 as imm5. - LdrLiteral(rt, imm): PC-relative LDR literal using imm>>2 as imm8. - LdrRegister(rt, rn, rm): LDR register (register offset). - LdrSpRelative(rt, imm): SP-relative LDR using imm>>2 as imm8. Validate low register indexes and throw ArgumentException when out of range. Implement opcodes and field placements per Thumb encoding so the emitter can generate common LDR forms for the RP2040 core.
Add comprehensive unit tests for multiple load (LDMIA) and load
(LDR) instruction variants to expand CPU instruction coverage.
- Add Ldmia tests:
- Should_LoadMultiple_And_WriteBackBaseAddress: verifies multiple
register loads and base register write-back behavior.
- Should_LoadMultiple_WithoutWriteBack_When_BaseIsLoaded:
verifies case where base register is also a destination and no
write-back occurs.
- Should_ConsumeCorrectCycles_ForMultipleLoad: checks cycle
consumption for multiple load.
- Add Ldr tests covering Immediate, Literal and Register forms:
- Immediate: test Rn+immediate load and extra cycle when reading
from peripheral.
- Literal: test PC-relative loads including max offset boundary.
- Register: start of a Register-form test to verify Rn+Rm addressing.
These tests improve correctness checks for memory addressing, data
loads, write-back semantics, and cycle counting in the CPU core.
Add unit tests for LDR variants to InstructionDecoderTests to cover load operations emitted by InstructionEmiter. The new cases include: LdrImmediate, LdrLiteral, LdrRegister and LdrSpRelative. Each test compares the emitted opcode against the corresponding MemoryOps handler to ensure decoding matches expected semantics. This increases coverage for memory load instructions and prevents regressions in decoder handling of immediate, literal, register and SP-relative load encodings.
|
lmSeryi
approved these changes
Feb 3, 2026
Collaborator
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Type of change
Checklist
dotnet test)Screenshots / Hex Dumps (Optional)