@specy/risc-v 4.1.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -382,7 +382,7 @@ This interface provides methods to control and interact with a RISC-V simulator
382
382
  * `getConditionFlags(): number[]`: Gets the 8 condition flags (if applicable, typically related to floating-point or custom extensions).
383
383
  * `registerHandler<T extends HandlerName>(name: T, handler: (...args: HandlerMap[T]['in']) => HandlerMap[T]['out'] | Promise<HandlerMap[T]['out']>): void`: Registers a handler function for a specific event (e.g., syscalls). See `HandlerName`, `HandlerMap` and [IO handlers](#io-handlers) for details.
384
384
  * `getUndoStack(): JsBackStep[]`: Returns the undo stack, an array of `JsBackStep` objects representing simulation history.
385
- * `readMemoryBytes(address: number, length: number): number[]`: Reads `length` bytes from memory starting at `address`. Returns an array of byte values. Notifies no memory observer: inspecting memory from the host is not the program reading it.
385
+ * `readMemoryBytes(address: number, length: number): number[]`: Reads `length` bytes from memory starting at `address`. Returns an array of byte values. Notifies no memory observer: inspecting memory from the host is not the program reading it. Text reads as the encodings of the statements it holds, little endian, and as zero where no statement is; the program's own loads from text still fault unless self-modifying code is enabled.
386
386
  * `setMemoryBytes(address: number, bytes: number[]): void`: Writes an array of `bytes` to memory starting at `address`, the way the program does: write observers are notified and, while undo is enabled, an undo step is recorded per byte.
387
387
  * `setPeripheralWord(address: number, value: number): void`: Writes one word-aligned word as a peripheral would, notifying no observer and recording no undo step. See [memory observers](#memory-observers).
388
388
  * `addMemoryWriteObserver(startAddress: number, endAddress: number, handler): number`: Observes every write in an address range. See [memory observers](#memory-observers).
@@ -446,3 +446,28 @@ instructions still expose a serial inside handlers. Match and retain host frames
446
446
  `getUndoGroups`/`getUndoGroupsRange`, never by PC; drop frames whose groups are no longer retained.
447
447
 
448
448
  `initialize` is rejected while an instruction or Poke is active.
449
+
450
+ ### Memory layout and bounds
451
+
452
+ After a successful `assemble()`, `getLayoutItems()` returns an `Int32Array` of
453
+ five-field tuples: address, byte length, kind (`0` code, `1` data, `2` reserved),
454
+ index into `getSectionNames()`, and byte alignment. Convert addresses to unsigned
455
+ 32-bit values in JavaScript (`address >>> 0`). Items describe the assembled program,
456
+ including the kept sections of loaded library members; zero-length items are omitted.
457
+
458
+ `getSymbolNames()` and `getSymbolFiles()` are parallel string arrays.
459
+ `getSymbolValues()` has three integers per name: address, data flag, library flag.
460
+ A library flag of `1` includes locals of data-only library members. The source file
461
+ identifies an included file, rather than only its enclosing compilation unit.
462
+
463
+ After `initialize()`, `getHeapStart()` and `getHeapBreak()` bound the current heap.
464
+ An allocation's previous break is recorded with its instruction, so Undo restores
465
+ it and executing that instruction again makes the same allocation.
466
+
467
+ `getStackTop()` reports the initialized `sp`, fixed until the next initialization.
468
+ The current `sp` is still available in the register file. Tracking a changing top
469
+ inside RARS's instruction loop measured about 6% slower, so this Core retains the
470
+ initial-stack convention.
471
+
472
+ `getTextSegments()` returns half-open start and end pairs for the text segment, which hold
473
+ statements rather than bytes: `readMemoryBytes` reads them, `setMemoryBytes` cannot write them.
package/dist/index.d.mts CHANGED
@@ -460,7 +460,9 @@ declare enum BackStepAction {
460
460
  * generator back, so that stepping the service again draws the same number. The generator's
461
461
  * state is the simulator's own, so `param2`, `oldValue` and `newValue` are 0.
462
462
  */
463
- RANDOM_STREAM_RESTORE = 15
463
+ RANDOM_STREAM_RESTORE = 15,
464
+ /** Internal heap and stack extent restores; no displayed mutation. */
465
+ HEAP_RESTORE = 16
464
466
  }
465
467
  /**
466
468
  * Represents a back step in the simulation undo stack.
@@ -745,6 +747,20 @@ interface JsRiscV {
745
747
  getLabelAtAddress(address: number): string | null;
746
748
  /** Address of a defined label/alias, or -1 if absent. Requires successful assembly. */
747
749
  getAddressOfLabel(label: string): number;
750
+ /** Tuples of address, length, kind (code=0/data=1/reserved=2), section index, alignment. */
751
+ getLayoutItems(): Int32Array;
752
+ getSectionNames(): string[];
753
+ getSymbolFiles(): string[];
754
+ getSymbolNames(): string[];
755
+ /** Tuples of address, data flag, library owner flag. */
756
+ getSymbolValues(): Int32Array;
757
+ getHeapBreak(): number;
758
+ getStackTop(): number;
759
+ /**
760
+ * Half-open start and end pairs of the text segment, which hold statements rather than bytes:
761
+ * `readMemoryBytes` reads them as encodings, `setMemoryBytes` cannot write them.
762
+ */
763
+ getTextSegments(): Int32Array;
748
764
  /**
749
765
  * Where the program's heap, and so the first block sbrk (9) hands out, starts. RARS's heap base,
750
766
  * 0x10040000, unless the program is a `gnu-compiler-v1` Build whose static data (`.data`,
@@ -941,6 +957,9 @@ interface JsRiscV {
941
957
  *
942
958
  * Reading through this method notifies no memory observer: inspecting memory from the host is
943
959
  * not the program reading it, so a memory viewer never drives a memory-mapped register.
960
+ * The text segment reads as the encodings of the statements it holds, little endian, with
961
+ * zero where no statement is; the program's own loads from text still fault unless
962
+ * self-modifying code is enabled.
944
963
  * @param address The starting memory address.
945
964
  * @param length The number of bytes to read.
946
965
  * @returns An array of bytes read from memory.
package/dist/index.d.ts CHANGED
@@ -460,7 +460,9 @@ declare enum BackStepAction {
460
460
  * generator back, so that stepping the service again draws the same number. The generator's
461
461
  * state is the simulator's own, so `param2`, `oldValue` and `newValue` are 0.
462
462
  */
463
- RANDOM_STREAM_RESTORE = 15
463
+ RANDOM_STREAM_RESTORE = 15,
464
+ /** Internal heap and stack extent restores; no displayed mutation. */
465
+ HEAP_RESTORE = 16
464
466
  }
465
467
  /**
466
468
  * Represents a back step in the simulation undo stack.
@@ -745,6 +747,20 @@ interface JsRiscV {
745
747
  getLabelAtAddress(address: number): string | null;
746
748
  /** Address of a defined label/alias, or -1 if absent. Requires successful assembly. */
747
749
  getAddressOfLabel(label: string): number;
750
+ /** Tuples of address, length, kind (code=0/data=1/reserved=2), section index, alignment. */
751
+ getLayoutItems(): Int32Array;
752
+ getSectionNames(): string[];
753
+ getSymbolFiles(): string[];
754
+ getSymbolNames(): string[];
755
+ /** Tuples of address, data flag, library owner flag. */
756
+ getSymbolValues(): Int32Array;
757
+ getHeapBreak(): number;
758
+ getStackTop(): number;
759
+ /**
760
+ * Half-open start and end pairs of the text segment, which hold statements rather than bytes:
761
+ * `readMemoryBytes` reads them as encodings, `setMemoryBytes` cannot write them.
762
+ */
763
+ getTextSegments(): Int32Array;
748
764
  /**
749
765
  * Where the program's heap, and so the first block sbrk (9) hands out, starts. RARS's heap base,
750
766
  * 0x10040000, unless the program is a `gnu-compiler-v1` Build whose static data (`.data`,
@@ -941,6 +957,9 @@ interface JsRiscV {
941
957
  *
942
958
  * Reading through this method notifies no memory observer: inspecting memory from the host is
943
959
  * not the program reading it, so a memory viewer never drives a memory-mapped register.
960
+ * The text segment reads as the encodings of the statements it holds, little endian, with
961
+ * zero where no statement is; the program's own loads from text still fault unless
962
+ * self-modifying code is enabled.
944
963
  * @param address The starting memory address.
945
964
  * @param length The number of bytes to read.
946
965
  * @returns An array of bytes read from memory.