Skip to content

Latest commit

 

History

History
177 lines (144 loc) · 34.4 KB

APP-PROBLEMS.md

File metadata and controls

177 lines (144 loc) · 34.4 KB

App problems found (2026-11-29)

Review of picsim at commit ed2833b (the dsPIC33CK64MC105 addition and what came after REVIEW-2026-11-11.md). The main target is the new dsPIC33 code: dspic*.rs, machine_ds.rs, the dsPIC paths of basil-sim, pic-sim, the debug adapter and stimulus.rs. The PIC18/PIC16 cores were checked only where they share code with the dsPIC.

The source was not changed during the review; fixes made afterwards are marked Fixed in their row. Each finding says how it was established:

  • T = reproduced: with a throw-away test against the library (since removed), or with scripts/dspic_try.py, which runs the same snippet in MDB and in picsim.
  • R = found by reading the code; not run.

Priority: H wrong results in ordinary use; M wrong or misleading in a narrower case; L minor, dead code or cleanup.

The data-sheet PDFs are deleted in the working tree (docs/pdf/ is gone, so the pic-docs server finds no documents). No finding below relies on a data-sheet fact. Each one is either a disagreement with MDB (the oracle the dsPIC work already uses) or a contradiction inside the code. Items that need a data sheet to settle are listed separately under "To check".

State of the tree

Check Result
cargo test --workspace --release passes: 81 test binaries, 0 failed
cargo clippy --workspace --all-targets fails: 1 error (erasing_op, see Q1), 72 warnings in the library
after the fixes (2026-11-30) tests: 81 binaries, 740 passed, 0 failed; clippy: no errors, 57 warnings in the library, none in the dsPIC files
after W1-W9 (2026-11-30) tests: 81 binaries, 746 passed, 0 failed; clippy: no errors, none in the dsPIC files; dspic_exec_check.py 31/31; dspic_diff.py --tests 400 --seed 7: the same 25 differences

Summary

Area Count Worst
dsPIC core and DSP engine 6 S1: ED/EDAC square the wrong value; S2: a negative accumulator written through ACCxU turns positive
dsPIC peripherals, reset and sleep 7 P1: the watchdog can never wake the part from Sleep; P2: Timer1 keeps counting after a warm reset
Timing and stimulus (dsPIC) 4 K1: the CLI runs a dsPIC at a quarter of real time and the window at half
Window (pic-sim), dsPIC paths 4 G1: the "only changed" SFR filter flags every CPU register as changed
Debug adapter 1 A1: variables are read from raw memory
Tests, tooling, docs 5 Q1: clippy fails; Q2: the dsPIC scripts leave their temp folders behind

dsPIC core and DSP engine

ID Pri How Where Finding
S1 H T dspic_dsp.rs:201-216 ED/EDAC put the square of the difference of the two prefetched words into the accumulator. They ignore the decoded Wm*Wm operand (m, which decode_mac_sq fills in and the disassembler prints). MDB squares Wm. Snippet mov #3,w4; [w8]=10; [w10]=4; clr a; ed w4*w4,a,[w8]+=2,[w10]+=2,w5: MDB ACCAL = 0x12 (3·3·2), picsim 0x48 (6·6·2). W5 = 6 in both. MDB also leaves SR = 0x0101 (C and DC, as if from the subtraction); picsim leaves SR = 0. Fixed 2026-11-29: the accumulator gets Wm*Wm (mac_product, with CORCON.US and IF), taken before Wxd is written; Wxd gets the difference. SR is left alone: DS70000157G lists only OA/OB/OAB/SA/SB/SAB as affected (MDB's C/DC is not followed). Test ed_squares_wm_and_puts_the_difference_in_wxd.
S2 H T dspic.rs:528, :531 (core_write of ACCAU/ACCBU) The accumulators are kept as sign-extended i64, but a write to ACCxU clears bits 63:40, so a negative value becomes a large positive one. Everything that reads acc directly (sac_value, MAX/MIN, NORM, ADD/SUB acc) then gets the wrong sign. mov #0xFF,w0; mov w0,ACCAU; sac a,w1: MDB W1 = 0x8000, picsim 0x7FFF. Fix: sext40 the result as acc_store does. Fixed 2026-11-29: the result is sign-extended from bit 39 (sext40). Test a_negative_accau_write_stays_negative.
S3 M R dspic_exc.rs:117, dspic_exec.rs:879 context_enter and context_return are empty. The alternate W register sets (alt, CTXTSWP) exist, but interrupt entry and RETFIE never switch context. The CTXTSTAT field is written only by CTXTSWP. Nothing raises a note, so a program that relies on automatic context switching corrupts its registers without warning. Either model it (settle the rule against the data sheet, see "To check") or add an unmodelled/notes entry when the configuration enables it. Fixed 2026-11-29: a register context is W0-W14, ACCA/ACCB, CORCON's DSP bits (US, SATA, SATB, SATDW, ACCSAT, RND, IF) and SR's OA/OB/SA/SB (DS70005158C 4.2, 4.2.2; DS70000157G table 3-9 note 3). Interrupt entry switches to the context whose FALTREG CTXTn names the interrupt's priority; RETFIE switches to the context of the level it returns to, or to MCTXI when none is assigned. CORCON writes in the default context are copied to all contexts until one is written in another. CTXTSWP now sets CCTXI too (MDB: 0x0101), takes 2 cycles, and CTXTSTAT is read only. MDB switches W0-W14 on CTXTSWP only (no accumulators, no automatic switching); the manuals are followed. Tests ctxtswp_switches_the_register_context, corcon_dsp_bits_belong_to_the_context, an_interrupt_at_an_assigned_level_runs_in_its_context.
S4 M R dspic.rs:894-902, :876 Stack-underflow detection is switched off by if sp < 0x0800 && false, and stack_check (called from every store) is an empty function. A runaway POP/RETURN reads below the stack without a trap. The disabled check also uses 0x0800, while apply_por takes W15's reset value from the device file and RAM starts at ram.0. At minimum, remove the dead code or add a note. Fixed 2026-11-29: a pop (pop16, and [--W15], which POP Wd is) that takes W15 below 0x1000 is a stack error trap (DS70005158C 5.4; MDB does not trap). W15 now resets to 0x1000 as DS70005399D 4.5.1.2 says (the device file and MDB give 0x0800, which would underflow on the first RETURN). The empty stack_check is gone. Test a_pop_below_ram_is_a_stack_error.
S5 L R dspic_exc.rs:106-115 Exception entry pushes with push_raw, which bypasses the SPLIM check that push16 makes. An interrupt or trap taken with W15 at the limit overruns it silently. Fixed 2026-11-30: exception entry makes the SPLIM check too (DS70005158C 5.3 note: an interrupt with W15 above the limit is a stack error). The frame is still written so the handler can return; the stack error trap follows the entry. It also follows a math error trap's entry (stack error is level 12, math 11, DS70000600E 3.1). Under the generic soft trap (level 13, DS70000600E 3.1.4) and the hard traps it waits: STKERR is set at once and the trap is taken when the priority level is below 12 again (3.2.1). It is not raised again by its own entry. Tests an_interrupt_that_pushes_past_splim_is_a_stack_error, a_stack_error_under_a_hard_trap_waits_for_its_handler.
S6 L R various Dead or no-op code that clippy also reports: dspic.rs:431 (a line overwritten by the next one), dspic_exec.rs:808-814 (both DIV2 branches identical), dspic_exc.rs:71 (t.number() + 0), dspic_exec.rs:833 (r >> 0), dspic_exec.rs:876 (& 0xF8 | 0), dspic_dsp.rs:331 (let _ = diff), dspic_dsp.rs:398-401 and :60-62 (empty helpers), dspic.rs:368 (settle empty), dspic_isa.rs:1242 (an if with identical blocks). Fixed 2026-11-30: all removed or merged (the dead SR line, the identical DIV2 and disassembler branches, + 0, >> 0, | 0, let _ = diff, the empty sr_acc_flags and acc_flags_after); settle stays, documented, because every machine has it for the debugger. The other clippy warnings in the dsPIC files are fixed too: there are none left there.

dsPIC peripherals, reset and sleep

ID Pri How Where Finding
P1 H T dspic_periph.rs:112-114, dspic_exc.rs:136-138, machine_ds.rs:163, :230 Periph::can_wake always returns false, so sleep_dead is true whenever no interrupt is enabled, even with the watchdog on. MachineDs::run, line_step, the CLI, the window and the debug adapter all stop with Stop::Sleep on the first cycle of PWRSAV #0. The watchdog wake-up that wdt_advance implements (wdt_woke) is therefore unreachable. Reproduced: FWDTEN on with a 1 ms period, pwrsav #0 at 0 → run returns Sleep at cycle 1. can_wake should return wdt_enabled(). Fixed 2026-11-29: sleep_dead asks Dspic::wdt_enabled (can_wake removed). Tests the_watchdog_wakes_the_part_from_sleep, sleep_with_nothing_to_wake_it_stops_the_run.
P2 H T dspic_clock.rs:129-135, dspic.rs:281-328 A warm reset (RESET, watchdog time-out, reset_with) resets the SFR bytes through apply_por but not the peripheral state in Dspic::p. t1_on stays true, so Timer1 keeps counting with T1CON = 0. Reproduced: TON set, reset_with(0x40), 50 instructions → T1CON reads 0000 and TMR1 = 200. The same applies to the UART FIFOs and shifter (a queued character goes out after the program enables the UART again), a pending ADC conversion (it lands in ADCBUFn after the reset), the NVM unlock state and pin_events/wdt_count. Rebuild or clear Periph the way the PIC18 reset_cond/carry_over does, keeping what must survive (stimulus queues, logs). Fixed 2026-11-29: apply_por calls Periph::reset, which clears Timer1, the NVM unlock, the watchdog count and wake flag, the UART FIFOs, shifter and receiver, and a pending ADC conversion; the pin levels and events, UART receive streams, [[adc]] values, transmit log and Fosc override are kept. Test a_warm_reset_clears_the_peripheral_state.
P3 M T dspic.rs:719-730, dspic_periph.rs:152-181, dspic_uart.rs:78-106, dspic_adc.rs:53-75 Dspic::peek (used by the debugger, --dump, the window's views, watchpoints and conditions) returns the stored byte for SFRs. sfr_read computes PORTx (from LAT/TRIS/pins), UxSTA/UxSTAH (FIFO flags) and ADCON5L. Reproduced: TRISB = 0, LATB = 5 → rd16(PORTB) = 0005, peek(PORTB) = 00. A watch or a condition on a port or a UART flag never fires, and --dump PORTB prints 0. Fixed 2026-11-29: peek reads SFRs through Dspic::sfr_view, which computes PORTx, UxSTA/UxSTAH, UxRXREG (the oldest character, not removed) and ADCON5L without side effects. Test peek_reads_computed_sfrs_as_the_cpu_does.
P4 M R dspic_periph.rs:296-309 Timer1 catches up with a loop that runs once per period: ticks / (PR1 + 1) iterations. With PR1 = 0 or 1 and a large dc (an advance_periph after a long gap, such as a run of SFR-free instructions or a debugger write), that is millions of iterations per call. Replace it with a division: fired = tmr + ticks > pr, tmr = (tmr + ticks) % (pr + 1). Fixed 2026-11-29: worked out with a remainder. Test timer1_catches_up_in_one_step checks it against counting tick by tick.
P5 L R dspic_exec.rs:12-17 Asleep, step advances one cycle per call, with a full advance_periph and irq_wake scan (12 IFS/IEC pairs). A 1 s watchdog sleep at 100 MHz is 50 M steps. It could jump to the next event (watchdog period end, pin event, UART character). This is the same issue as P6 of the 2026-11-11 review, now on the dsPIC. Fixed 2026-11-30: inside a run, a Sleep or Idle step goes straight to the next thing a peripheral does (sleep_next_event: watchdog time-out, Timer1 match, stimulus pin change, UART character, end of an ADC conversion or a clock switch), bounded by the end of the run; this replaces the watchdog-only skip of F1. With a watchpoint, condition or recording there is no skip, so they see every value of an SFR that counts by itself (test a_watchpoint_sees_every_tick_while_the_part_sleeps). Test a_sleep_skips_to_the_next_timer1_match checks the wake-up cycle and TMR1 against stepping cycle by cycle.
P6 L R dspic_uart.rs:200-241 While a receiver is off (URXEN = 0 or the UART off), the stimulus queue keeps its times. When the receiver is turned on, every character whose time has passed arrives at once (back to back, start = front.at in the past), which overflows the 8-deep FIFO and sets OERR. Characters sent while the receiver was off should be dropped, or their times moved. Fixed 2026-11-30: with the receiver off, a character in flight and every stimulus character whose Start bit falls meanwhile are lost, in every queued stream, as the PIC UART models do. Tests uart_characters_sent_while_the_receiver_is_off_are_lost, uart_streams_queued_behind_another_also_lose_their_characters.
P7 L R dspic_exc.rs:121-123, dspic_clock.rs:130-134, :160, dspic_periph.rs:238 Addresses are hard-coded (RCON 0xF80, OSCCON 0xF84, INTCON1 0x8C0, the ADC 0xB00/0xC00, the UART bases) next to Addrs, which looks the same registers up by name. That is harmless for the one part, but a second dsPIC33 device file with a different map would be wrong without an error. dspic_periph.rs:403 also lists 0x248..0x24A, which is already inside 0x238..0x24C. Fixed 2026-11-30: the bare addresses are named constants (RCON, INTCON1, INTCON3, OSCCON...), and Dspic::new refuses a device file that puts any of the registers used at a fixed address (all the CPU registers, the interrupt controller from IFS0 to IPC47, RCON, the oscillator, the ADC registers, the UART bases) elsewhere. The duplicate 0x248..0x24A range is gone. Test a_device_file_with_another_register_map_is_refused.

Timing and stimulus (dsPIC)

ID Pri How Where Finding
K1 H R tools/picsim/src/main.rs:505, pace.rs:52, tools/picsim-gui/src/main.rs:652-662, :862 Pace assumes one instruction cycle per 4 Fosc clocks. Dspic::time_ns (and its doc comment) uses 2 Fosc clocks per cycle. The CLI passes fosc_mhz() / 2.0 to paced_run, which divides by 4 again: --speed 1 runs a dsPIC at Fosc/8 cycles per second, a quarter of real time. The window passes the plain Fosc: half of real time, and the status line's "% of real time" is twice too high. The CLI should pass fosc * 2.0, or Pace should take the clocks per cycle. Fixed 2026-11-29: Pace has clocks_per_cycle (4 by default); the CLI and the window set 2 for a dsPIC (Fcy = Fosc/2, DS70005399D section 9.2) and pass the plain Fosc; the status line divides by the same figure.
K2 H R stimulus.rs:707-710, :259-260 Stimulus times in ns/us/ms/s are converted with fosc_mhz * 1e6 / 4 cycles per second, so on a dsPIC every physical time comes out at half the intended length (at = "1ms" happens after 0.5 ms). fosc_mhz is also limited to 0..64, so a dsPIC stimulus file cannot give its real clock (up to 200 MHz, fosc_max of the device file), and physical units then refuse to work. Parsing happens before the family is known, so the factor (4 or 2) and the limit (the part's fosc_max) have to be applied in apply_dspic, or the times kept unresolved until then. Fixed 2026-11-29: Stimulus::parse_for(text, dev) converts at 2 clocks per cycle on a dsPIC33 and accepts fosc_mhz up to the part's fosc_max; MachineDs (load and reset) and the dspic_run example use it. parse keeps the PIC16/PIC18 rule. Test stimulus_times_on_a_dspic_use_fosc_over_two.
K3 M R stimulus.rs:507-530 apply_dspic refuses [[spi]], [[i2c]], [[i2c_host]], [[analog]], [[mclr]], [[clock]] and [[bounce]], but silently ignores [[led]], [[oled]], [[uart_device]] and [clb]. A board in the file does nothing, with no message. apply16 refuses what it cannot do; apply_dspic should too. Fixed 2026-11-29: [[led]], [[oled]], [[uart_device]] and [clb] are refused too. Test a_dspic_stimulus_refuses_what_it_cannot_drive.
K4 L R stimulus.rs:225, dspic_periph.rs:419-424 [[port]] without mask defaults to 0xFF, so on the 16-bit dsPIC ports value = 0x1234 drives only the low byte. [[pin]]/[[port]] bits outside Port::mask are accepted. Fixed 2026-11-30: on a dsPIC a [[port]] without mask drives the whole 16-bit port (0xFFFF: the pins the port has, so value = 0xFFFF sets them all); a mask, or a level under an explicit mask, or a [[pin]] naming a pin the port lacks is refused. The PIC16/PIC18 default stays 0xFF. Test a_dspic_port_entry_drives_the_whole_port.

Window (pic-sim), dsPIC paths

ID Pri How Where Finding
G1 M R tools/picsim-gui/src/main.rs:521, :1386-1390 For a dsPIC, snapshot stores m.cpu.mem.clone() as view_snap, while the SFR and Memory tabs compare it with m.cpu.peek (the PIC18/PIC16 branches snapshot with peek). W0-W15, SR, CORCON, the accumulators and the other CPU registers live in Dspic fields, not in mem, so their snapshot is 0. With "only changed" on, every non-zero CPU register is listed as changed after every step, and change highlighting is wrong for them. (The PORTx and UART status values from P3 are also stale there.) Fixed 2026-11-29: the dsPIC snapshot is taken with peek, like the other parts.
G2 M R tools/picsim-gui/src/main.rs:1318-1320, :442-499 The Fosc box is applied to a dsPIC on every frame when it is above 0, and set_fosc_override cannot be undone. Setting the box back to 0 ("0 = firmware") leaves the last override in force until the next Load. load_ds does not copy a stimulus file's fosc_mhz into the box, as load/load16 do (the earlier G1 fix), so a non-zero box overrides the file. A value left in the box from a PIC18 session (often 64) silently replaces the program's own PLL set-up. Fixed 2026-11-29: load_ds puts the stimulus file's fosc_mhz in the box, or 0 (the firmware's clock) when the file has none; the box is applied only when it differs from the override in force, and 0 clears the override (clear_fosc_override).
G3 L R tools/picsim-gui/src/main.rs:767-781 Step over on a dsPIC runs Job::Until(pc + n), and MachineDs::run ignores until when the PC arrives there by a call (called && !until_routine). In a recursive routine it stops at the return address of the deeper call: the earlier G6 issue, carried over to the dsPIC. Fixed 2026-11-30: Step over on a dsPIC keeps W15 at the call and runs with MachineDs::run_over, where the return address counts only with W15 back at that level; a breakpoint or condition there still stops a deeper call. Test step_over_a_recursive_call_stops_in_its_own_frame. (G6 of the 2026-11-11 review, the PIC18 and PIC16 side, is still open.)
G4 L R tools/picsim-gui/src/main.rs:713-737 Browse and Load stay enabled while a program runs or a step job is under way. load() stops the run and drops the job first, so this is safe today. Note it as an invariant: anything later added to load() before self.running = false runs mid-run. (A dropped file is already guarded by !self.running.) Done 2026-11-30: written down on load: it stops the run and drops the job before anything else, and stays that way (runs and jobs go on in logic, on the same thread).

Debug adapter

ID Pri How Where Finding
A1 L R tools/picsim/src/dap.rs:48-54, :506, :522, :604 Variables, setVariable replies and evaluate format values from t.mem() (the raw data array) through data_view, while data breakpoints and conditions use peek. On a dsPIC (and on any part where a variable is placed on an SFR whose value is computed), the Variables pane can disagree with what the CPU reads. Same root cause as P3. Fixed 2026-11-30: Variables, setVariable replies and evaluate read the data memory through peek (Target::view), as data breakpoints and conditions do. The window's Variables tab and its change snapshot do the same now, for all three cores (they read raw mem too).

Tests, tooling and docs

ID Pri How Where Finding
Q1 M T dspic_periph.rs:342-343 cargo clippy --workspace --all-targets fails again: v | (old & 0x0000) is erasing_op, which is deny by default. Both lines of nvmcon_write are no-ops (v &= !0x1000 | 0). Say what NVMCON bits should keep their old value, or delete the lines. Other clippy warnings worth reading: periph.rs:2797, :2815 ((pr + 1) * 4 << sh precedence), periph/quart.rs:488 (a wildcard pattern that hides the arms after it), periph/quart.rs:162. Fixed 2026-11-29: nvmcon_write keeps WREN, NVMSIDL, RPDF and NVMOP as written, lets software only clear WRERR and URERR, and sets WRERR for a WR without the unlock sequence (DS70005399D Register 5-1). The old code cleared NVMSIDL. Clippy has no errors now. Test nvmcon_keeps_its_writable_bits.
Q2 M T scripts/dspic_try.py:13, dspic_roundtrip.py:36, dspic_exec_check.py:21, dspic_diff.py:68, :155 Every run makes a tempfile.mkdtemp folder under /tmp (dstry-*, dsrt-*, dsx-*, dsdf-*) and never removes it. dspic_diff.py makes one per batch. This is the pattern that filled the /tmp tmpfs in T1 of REVIEW-FINDINGS.md. Seen: each dspic_try.py call in this review left a /tmp/dstry-* folder (removed afterwards). Use TemporaryDirectory or atexit + rmtree, as gpr_snapshot.py does. dspic_try.py also runs cargo build without checking its status, so a build error shows up later as a regex AttributeError. Fixed 2026-11-29: the four scripts remove their folders (atexit, or after each batch in dspic_diff.py; --keep keeps them where the script has it), and dspic_try.py stops with the compiler's message when cargo build fails.
Q3 M R crates/picsim/tests/dspic_programs.rs No test covers the paths above: ED/EDAC results, an ACCxU write, Sleep with the watchdog on, peripheral state after RESET or a watchdog reset, peek of PORTx, or pacing at --speed 1 on a dsPIC. the_watchdog_resets_a_program_that_never_clears_it drives Dspic::step directly and so misses P1. Fixed 2026-11-29: dspic_programs.rs has a test for each of the H and M fixes (21 tests).
Q4 L R docs/REVIEW-2026-11-11.md The status column is out of date. B1/B2 (hook 244: Timer4-6 now use codes 64-73), B9 (carry_over keeps the EEPROM), C4 (all UARTs are printed), C5 (INTCON0 is in the trace), Q1 (crc.rs) and D2 (README and LICENSE exist) were fixed in the code but not marked, so a reader could not tell which items were still open. Done: those seven rows now carry a dated Fixed note.
Q5 L R dspic_periph.rs:116-117, dspic_clock.rs:20-21 Stale doc comments: "The oscillator frequency in MHz (the FRC at 8 MHz until the clock models are in)" is attached to set_fosc_override; Clock::wdt_run is documented as "the oscillator's own frequency in MHz…" but is a bool. Fixed 2026-11-30: set_fosc_override has the right comment (with the M fixes); Clock::wdt_run was never used and is gone.

Found while fixing (2026-11-29)

A review of the H fixes and the MDB runs made while fixing turned up these; the first five are fixed.

ID Pri How Where Finding
F1 H T dspic_exec.rs (step asleep), machine_ds.rs (run) Made worse by the P1 fix: erased configuration words enable the watchdog with a 2^31 ms Sleep period, so PWRSAV #0 stepped one cycle at a time to the cycle limit. Fixed: asleep with no peripheral busy (periph_quiet), the step goes straight to the watchdog time-out, but not past the end of the run under way (sleep_horizon). It never jumps outside MachineDs::run (a debugger step, --trace), and never while a wake is already due (an interrupt flagged, a trap pending). Tests a_long_watchdog_sleep_is_skipped_to_the_end_of_the_run, a_pending_interrupt_wakes_the_part_before_any_sleep_skip. This also covered P5 for that case; since the P5 fix the skip goes to the next peripheral event of any kind (sleep_next_event).
F2 M R dspic_exc.rs (sleep_dead) Sleep with an interrupt enabled but not yet flagged and a pin change or UART character still to come was stopped as a dead sleep. Fixed: it is dead only when no interrupt is enabled or nothing is still to come. Test sleep_with_an_enabled_interrupt_waits_for_what_is_still_to_come.
F3 M R stimulus.rs (apply_dspic) fosc_mhz = 0 set a 0 MHz clock instead of the firmware's. Fixed: 0 clears the override.
F4 M R machine_ds.rs (reset) A power-on reset dropped a --fosc override. Fixed: the override in force is kept. Test a_reset_keeps_the_clock_override.
F5 L R dspic_clock.rs (wdt_enabled) On a part without WDTCONL the address is 0 and W0 was read. Fixed.
F6 L T dspic_exec.rs (CTXTSWP) CTXTSWP took 1 cycle; DS70000157G and MDB give 2. Fixed with S3.
F7 L T dspic.rs (rd16) A MAC-class prefetch from the SFR space ([w8]-=2 from 0x1000) costs picsim the one-cycle SFR read penalty; MDB charges nothing. Open.
F8 L T dspic_dsp.rs (mac_product) With US = 11 (reserved) MDB multiplies ED and MPY differently from picsim (signed). Open; a program should not use the reserved setting.
F9 L R dspic_exc.rs (sleep_dead) A Sleep counts as dead only when no interrupt at all is enabled, or no peripheral has anything to come; the two are not paired per source. With Timer1 running and T1IE clear but another IEC bit set, nothing can wake the part, yet the run goes on to its cycle limit instead of stopping with Sleep. Since the P5 fix that costs little (the run jumps from event to event). Pairing each source with its own enable would need the pin events too, which raise no interrupt in the model yet. Open.

The review also said the watchdog uses the Sleep postscaler in Idle; that is right (DS70005250: SLPDIV is the Sleep and Idle postscaler), so nothing was changed.

Found while writing the manual's dsPIC33 chapter (2026-11-30)

Checked against DS70005399D, DS70000602C (Reset FRM) and DS70000157G (LNK) through the PDF reader, and by running basil and XC-DSC programs.

ID Pri How Where Finding
W1 M T tools/picsim-gui/src/main.rs (list_devices), debuginfo.rs (device_of), tools/picsim/src/main.rs The window's device box left the dsPIC out, no tool took the part from a dsPIC ELF, and basil-sim without --device ran a dsPIC program on the PIC18F27Q10 (undefined opcodes, a run to --max-cycles). Fixed: the box lists DSPIC* files; hex::dspic_part reads the part from the __33CK64MC105 symbol the XC-DSC linker defines (basil's dsPIC ELF has it too) in an ELF of machine EM_DSPIC30F; basil-sim takes the part from the ELF (or a COFF build's log) when --device is not given, as the window and the debug adapter do (an ELF part with no device file gives a note and the default part, as before); a PIC ELF on the dsPIC, or the reverse, gives the "ELF was built for" note.
W2 M T tools/picsim/src/main.rs --fosc was refused above 64 MHz for every part, the dsPIC's 200 MHz included. Fixed: any positive value up to the part's own maximum.
W3 M T lines.rs, debuginfo.rs The debug information of an XC-DSC ELF could not be read (unexpected end of input), so a C program had no names, and the debug adapter refused to launch it. XC-DSC stores every byte of its DWARF sections followed by a zero byte. Fixed: lines::debug_section drops the padding on a dsPIC ELF; the XC-DSC units are read (lines, routines, globals, structures, DW_OP_breg14 parameters and locals); MachineDs::frames follows the W14 chain that LNK builds (DS70000157G p.281), not below an interrupt handler (a routine with RETFIE) or a routine without debug information; XC16 producers are taken too; peek reads the PSV window (8000h up, where XC-DSC keeps const data) through DSRPAG; a file name relative to DW_AT_comp_dir is made absolute so a debugger client's breakpoints match. Test an_xc_dsc_program_gives_lines_routines_and_the_locals_of_each_call (fixture tests/data/xcdsc_frames.c); the debug adapter was checked by hand (line breakpoint, call stack, each recursion's locals, data breakpoint).
W4 M R dspic_exec.rs (step) An illegal opcode took the address error trap. DS70005399D section 6.0 and DS70000602C 3.8.1 make it a device Reset with IOPUWR (RCON bit 14). Fixed, with a note. Test an_illegal_opcode_resets_the_part.
W5 M R dspic_periph.rs (timer1), dspic_uart.rs Sleep was treated like Idle: Timer1 and the UARTs kept running and could wake the part. In Sleep the system clock is off (DS70005399D 27.2.1). Fixed: Timer1 holds in Sleep (except as an asynchronous FRC counter, which section 19.0 says runs in Sleep) and, with SIDL, in Idle; a UART's baud clock stops in Sleep unless SLPEN and in Idle with USIDL (Registers 15-1, 15-2): a character being sent waits, one arriving is lost; such a module no longer counts as something that can end a Sleep. Tests timer1_stops_in_sleep_and_with_sidl_in_idle, a_uart_waits_in_sleep_unless_slpen; the two Timer1 sleep tests now use Idle.
W6 L R dspic_exc.rs (on_pwrsav) Entering Sleep or Idle did not clear the watchdog (DS70005399D 27.2.1, 27.2.2). Fixed.
W7 L R dspic_periph.rs (port_read) ANSELx had no effect: an analog input read the driven level; DS70005399D 8.2 says it reads 0. A write could also set ANSEL bits of pins without an analog function. Fixed. Test an_analog_input_reads_0.
W8 L R dspic_clock.rs (osccon_write) FCKSM = 1x (the erased value) disables clock switching (Register 28-5), but a switch went ahead. Fixed: OSWEN stays clear, with a note. Test fcksm_disables_clock_switching.
W9 L R dspic_clock.rs (fosc_mhz) A primary oscillator (EC/XT/HS) was taken as 8 MHz without a word. Fixed: a note while no clock override is given (Dspic::set_fosc_override now keeps it up to date).
W10 L R dspic_exec.rs The Uninitialized W Register Reset (DS70000602C 3.8.2: W0-W14 are cleared at a Reset and count as uninitialized until written; using one as an address pointer resets the part) is not modelled. The W registers are written in about 30 places, not all through set_w, so tracking it safely needs those writes gathered first. Open.
W11 L R dspic_uart.rs, dspic_adc.rs Not modelled in the power-saving modes: a UART's WAKE (an interrupt on a falling RX edge), the ADC (it carries on in Sleep), and a clock switch in Sleep. Open.
W12 L T pic18.rs (sleep_step) Not dsPIC: a PIC18 asleep jumps to the watchdog's time-out in one step, past the end of the run, so basil-sim --max-cycles 1000 can report millions of cycles (seen with a dsPIC hex run on the PIC18F27Q10). The dsPIC bounds the jump by the run (sleep_horizon). Open.
W13 L R dspic_exec.rs (PWRSAV) The cycle of the PWRSAV instruction itself is counted as asleep (the peripherals are brought up to date after it), so Timer1 in Sleep or a UART stopped by it loses one cycle against the part. Open (review nit).

To check (needs the data sheet / FRM; not stated as errors)

These are places where the code makes a hardware choice that this review could not confirm, because the PDFs are not in the working tree. Each is a question for DS70005399 (data sheet), DS70000157 (programmer's reference manual) or the dsPIC33 family reference manuals, or for MDB.

  1. dspic_periph.rs:296-309: with TMR1 written above PR1, the model matches on the next tick (to_match = 0) instead of counting up to 0xFFFF and wrapping. Which does the part do?
  2. dspic_periph.rs:152-157: port_read ignores ANSELx. Does a pin configured as analog read as 0 in PORTx?
  3. dspic_exc.rs:71: every trap is entered at IPL 15. Do the traps have distinct priority levels that decide which of two pending traps is taken, and whether a trap can interrupt another trap's handler? Partly answered (DS70000600E section 3): the traps have fixed levels, DMAC error 10, math error 11, stack error 12, generic soft trap 13, address error 14, oscillator failure 15; a higher one suspends a lower one, which stays pending (3.2.1). picsim still enters every trap at IPL 15 and takes a pending one at once; only a stack error found under a higher trap waits (S5).
  4. S3: FALTREG CTXTn assigns them (DS70005399D Register 28-15). Still open: RETFIE to a level with no context assigned goes to MCTXI (DS70005158C 3.3). An ISR with no context of its own that interrupted an ISR running in an alternate context, and was itself interrupted, would come back in MCTXI's context, not the one it ran in. The manuals do not show that case, and MDB does not model the switching. The same rule means code that raises its own IPL to an assigned level (SR.IPL = 4 with CTXT1 = IPL4) while in the default context comes back from an unassigned higher interrupt in context 1. The stacked frame holds only PC, SRL and IPL3, so the part can only go by the IPL and MCTXI too, but no manual says so.
  5. The overflow test is unchanged. Underflow: yes, below 0x1000 (DS70005158C 5.4; now modelled, S4).
  6. ED/EDAC in mixed-sign mode (US = 10): picsim applies DS70005158C 7.2.1 (an even register is unsigned), so ed w6*w6 squares W6 as unsigned; MDB squares it as signed. Which does the part do?
  7. dspic_periph.rs:283-285: with TCS = 1 and TECS != 0, Timer1 counts at the instruction clock. Which sources does TECS select?

Method

  1. cargo test --workspace --release and cargo clippy --workspace --all-targets --release.
  2. Read in full: dspic.rs, dspic_dsp.rs, dspic_exc.rs, dspic_periph.rs, dspic_uart.rs, dspic_adc.rs, machine_ds.rs, cofinfo.rs, oscillator.rs; the step loop and the divide, FLIM and CTXTSWP parts of dspic_exec.rs; the clock and watchdog part of dspic_clock.rs; the dsPIC paths of tools/picsim/src/main.rs; the load, run, step and dsPIC view code of tools/picsim-gui/src/main.rs; the target, launch, variables, data-breakpoint and run code of tools/picsim/src/dap.rs; time parsing and apply_dspic in stimulus.rs; the scripts under scripts/.
  3. Concurrency: the window runs the simulator on the UI thread in 30 ms slices (no worker threads, no shared state), and the debug adapter is a single loop. The checks were therefore which controls stay enabled while a run or step job is active (G4), and every reader of cached state: view_snap (G1), fosc_override (G2, K1), Periph across resets (P2) and mem against computed SFRs (P3, A1).
  4. S1, S2 and the ED flags were run in MDB and picsim with scripts/dspic_try.py. P1, P2 and P3 were reproduced with a throw-away test file, deleted afterwards. The working tree is unchanged apart from this file.