arturo-fixed-files-branch #4

Merged
Kittycannon merged 2 commits from arturo-fixed-files-branch into main 2026-04-01 16:38:57 +00:00
Member

CHANGES MADE: HOPE THESE CHANGES DO NOT BREAK SOMEONE ELSE'S BASE CODE.

  1. fetchInstr() — added static_cast to _addrm and _size assignments to suppress -Wconversion warnings raised by the stricter makefile flags.

  2. fetchOperSrc() — added '& 0b111' mask when indexing addrModes[]: (this->*(CPU::addrModes[_addrm & 0b111]))(); Without the mask, _addrm can be up to 0x1F (31), causing an out-of-bounds access on addrModes[] which only has 8 entries (0–7). This caused a segmentation fault when executing two-operand instructions like FMUL.

  3. fetchOperDst() — added '& 0b111' mask (same reason as fetchOperSrc). Necessary for single-operand instructions that call fetchOperDst() directly without fetchOperSrc() running first, where _addrm has not yet been shifted and can exceed 7.

  4. reg() — added '_opers[0] = _alu' after '_alu = &GPR[reg]'. Without this line, _dst was never updated after fetchOperDst() called reg(), leaving _dst as nullptr and causing a segfault inside the instruction body when trying to write the result.

  5. execute() — changed from: (this->(CPU::addrModes[_opcode]))(); // wrong array, out of bounds to:
    (this->
    (CPU::instrMap[_opcode]))(); // correct dispatch table
    addrModes has 8 entries; instrMap has 512. Using addrModes with an opcode value caused an out-of-bounds call on any opcode above 7.

Changes in LiveDebug.cpp

  1. Terminal::ENTER handler — changed from:
    runtime.cpu.fetchInstr();
    runtime.cpu.fetchOperDst();
    to:
    runtime.cpu.fetchInstr();
    runtime.cpu.execute();

fetchOperDst() only fetches the destination operand, it never calls the instruction itself, leaving _src unfetched for two-operand instructions and causing crashes. execute() correctly dispatches through instrMap[] to the full instruction method, which handles both operand fetches and the operation internally. This makes the Enter key properly step the CPU by one complete instruction cycle.

Changes in Terminal.cpp

  1. getKey() line 228 — replaced:
    newt.c_lflag &= (ICANON | ECHO);
    with:
    newt.c_lflag &= static_cast<tcflag_t>(
    (ICANON | ECHO));

The bitwise NOT of (ICANON | ECHO) produces a negative int value which cannot be implicitly converted to tcflag_t (unsigned int). The explicit cast suppresses the -Werror=sign-conversion error introduced when the makefile added -Werror.

  1. getKey() line 257 — replaced:
    result = (u8)ch;
    with:
    result = static_cast(ch);

C-style casts are flagged by -Werror=old-style-cast. The static_cast the correct C++ equivalent and makes the conversion intent explicit.

CHANGES MADE: HOPE THESE CHANGES DO NOT BREAK SOMEONE ELSE'S BASE CODE. 1. fetchInstr() — added static_cast<u8> to _addrm and _size assignments to suppress -Wconversion warnings raised by the stricter makefile flags. 2. fetchOperSrc() — added '& 0b111' mask when indexing addrModes[]: (this->*(CPU::addrModes[_addrm & 0b111]))(); Without the mask, _addrm can be up to 0x1F (31), causing an out-of-bounds access on addrModes[] which only has 8 entries (0–7). This caused a segmentation fault when executing two-operand instructions like FMUL. 3. fetchOperDst() — added '& 0b111' mask (same reason as fetchOperSrc). Necessary for single-operand instructions that call fetchOperDst() directly without fetchOperSrc() running first, where _addrm has not yet been shifted and can exceed 7. 4. reg() — added '_opers[0] = _alu' after '_alu = &GPR[reg]'. Without this line, _dst was never updated after fetchOperDst() called reg(), leaving _dst as nullptr and causing a segfault inside the instruction body when trying to write the result. 5. execute() — changed from: (this->*(CPU::addrModes[_opcode]))(); // wrong array, out of bounds to: (this->*(CPU::instrMap[_opcode]))(); // correct dispatch table addrModes has 8 entries; instrMap has 512. Using addrModes with an opcode value caused an out-of-bounds call on any opcode above 7. Changes in LiveDebug.cpp 6. Terminal::ENTER handler — changed from: runtime.cpu.fetchInstr(); runtime.cpu.fetchOperDst(); to: runtime.cpu.fetchInstr(); runtime.cpu.execute(); fetchOperDst() only fetches the destination operand, it never calls the instruction itself, leaving _src unfetched for two-operand instructions and causing crashes. execute() correctly dispatches through instrMap[] to the full instruction method, which handles both operand fetches and the operation internally. This makes the Enter key properly step the CPU by one complete instruction cycle. Changes in Terminal.cpp 1. getKey() line 228 — replaced: newt.c_lflag &= ~(ICANON | ECHO); with: newt.c_lflag &= static_cast<tcflag_t>(~(ICANON | ECHO)); The bitwise NOT of (ICANON | ECHO) produces a negative int value which cannot be implicitly converted to tcflag_t (unsigned int). The explicit cast suppresses the -Werror=sign-conversion error introduced when the makefile added -Werror. 2. getKey() line 257 — replaced: result = (u8)ch; with: result = static_cast<u8>(ch); C-style casts are flagged by -Werror=old-style-cast. The static_cast the correct C++ equivalent and makes the conversion intent explicit.
CesarBalam added 2 commits 2026-03-31 07:37:27 +00:00
Kittycannon merged commit 36889e160b into main 2026-04-01 16:38:57 +00:00
Kittycannon deleted branch arturo-fixed-files-branch 2026-04-01 16:39:01 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SpiderLang/spider-runtime#4