Skip to content

Commit 26ab005

Browse files
committed
fix to misc BKPT and SWI instructions, fix for 32-bit CPU archs
1 parent 31ffd07 commit 26ab005

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

llarm-emu/src/cpu/core/core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void CORE::initialise(const bool is_headless) {
222222
reg.write(id::reg::R0, 0);
223223
reg.write(id::reg::R1, settings.machine_type);
224224
reg.write(id::reg::R2, settings.dtb_load_address);
225-
reg.write(id::reg::SP, static_cast<u32>(settings.memsize));
225+
reg.write(id::reg::SP, settings.memsize);
226226
reg.force_write(id::reg::R15, settings.binary_load_address);
227227
} else {
228228
reg.switch_mode(id::mode::USER);

llarm-emu/src/cpu/instructions/arm/misc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ void INSTRUCTIONS::arm::misc::SWI() {
9898
reg.write(id::cpsr::I, 1);
9999

100100
if (coprocessor.read(id::cp15::R1_V)) {
101-
reg.write(id::reg::PC, 0xFFFF0004);
101+
reg.write(id::reg::PC, 0xFFFF0008);
102102
} else {
103-
reg.write(id::reg::PC, 0x00000004);
103+
reg.write(id::reg::PC, 0x00000008);
104104
}
105105
}
106106

@@ -126,8 +126,8 @@ void INSTRUCTIONS::arm::misc::BKPT() {
126126
reg.write(id::cpsr::I, true);
127127

128128
if (coprocessor.read(id::cp15::R1_V)) {
129-
reg.write(id::reg::PC, 0xFFFF0008);
129+
reg.write(id::reg::PC, 0xFFFF000C);
130130
} else {
131-
reg.write(id::reg::PC, 0x00000008);
131+
reg.write(id::reg::PC, 0x0000000C);
132132
}
133133
}

llarm-emu/src/cpu/instructions/operation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ bool operation::borrow_sub(const u32 a, const u32 b) {
3333
return (a < b);
3434
}
3535

36-
// CHECK IF THIS WORKS
36+
// TODO CHECK IF THIS WORKS
3737
bool operation::borrow_sub(const u32 a, const u32 b, const u32 c) {
3838
return (a < b) || (a - b < c);
3939
}
4040

4141
bool operation::overflow_add(const u32 a, const u32 b) {
4242
const u32 result = a + b;
43-
// Overflow when both operands have the same sign but the result has a different sign.
4443
return static_cast<bool>(((a ^ result) & (b ^ result)) >> 31);
4544
}
4645

llarm-emu/src/settings.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct SETTINGS {
9898
id::thumb_version thumb_version = id::thumb_version::NO_THUMB; // either 1 or 2, 0 if not supported
9999
/**/ u8 core_count = 0;
100100
/**/ u16 clock_speed_mhz = 0; // 0 will mean no clock speed constraints
101-
/**/ std::size_t memsize = 0;
101+
/**/ u32 memsize = 0;
102102
id::arch arch = id::arch::UNKNOWN;
103103
/**/ id::specific_arch specific_arch = id::specific_arch::UNKNOWN;
104104
id::product_family product_family = id::product_family::UNKNOWN;
@@ -281,7 +281,7 @@ constexpr SETTINGS default_settings() {
281281
constexpr SETTINGS linux_settings() {
282282
SETTINGS tmp = default_settings();
283283

284-
tmp.memsize = 128UL * 1024 * 1024; // 128Mb
284+
tmp.memsize = 128U * 1024U * 1024U; // 128Mb
285285
tmp.fresh_system = true;
286286
tmp.linux_boot = true;
287287
tmp.dtb_load_address = 0x01000000U;
@@ -301,12 +301,12 @@ constexpr SETTINGS linux_settings() {
301301
tmp.has_random_replacement_cache_strategy = true; // bit 14 RR = 0 (random/default)
302302
tmp.r1_sbo_mask = (1U << 16) | (1U << 19); // ARM926EJ-S SBO bits per TRM
303303

304-
// ARM926EJ-S has a full MMU. Enable it so that when the kernel writes to
305-
// CP15 C1 (R1_M bit) to turn on the MMU, LLARM actually activates virtual
306-
// physical translation. Without this the emulator ignores the MCR and keeps
304+
// ARM926EJ-S has a full MMU. Enable it so that when the kernel writes to
305+
// CP15 C1 (R1_M bit) to turn on the MMU, LLARM actually activates virtual to
306+
// physical translation. Without this, the emulator ignores the MCR and keeps
307307
// reading from raw physical addresses even after the kernel has jumped to
308308
// virtual space (0xC0xxxxxx → 0x00xxxxxx).
309-
// Use a unified TLB model for simplicity; real ARM926EJ-S has separate I/D
309+
// Use a unified TLB model for simplicity, real ARM926EJ-S has separate I/D
310310
// TLBs, but the kernel's TLB-invalidation operations map cleanly onto the
311311
// unified table the LLARM TLB implementation exposes.
312312
tmp.is_mmu_enabled = true;
@@ -319,8 +319,8 @@ constexpr SETTINGS linux_settings() {
319319
}
320320

321321

322-
// Linux Image (uncompressed kernel) load directly at the standard ARM physical entry point.
323-
// No decompressor involved; the kernel's head.S runs immediately from 0x8000.
322+
// Linux Image (uncompressed kernel), load directly at the standard ARM physical entry point.
323+
// No decompressor involved, the kernel's head.S runs immediately from 0x8000.
324324
constexpr SETTINGS image_settings() {
325325
SETTINGS tmp = linux_settings();
326326
tmp.binary_load_address = 0x00008000U; // ARM Linux TEXT_OFFSET, physical entry point

0 commit comments

Comments
 (0)