# Project Frankenstein: Volume XX

## Flash Status Registers & Error States

This volume provides the technical mapping of the Flash Memory Controller registers within the GCC-4241N (MN103S). While real-time monitoring of a physical burn is restricted by the hardware's halt state during RAM-stub execution, understanding these registers is vital for the RAM Stub logic to verify sector erasures and program success before signaling a safe completion [cite: User Summary, Volume XIX: Flash Programming Algorithm].

## 1. Flash Controller Register Map (VMA)

The MN103S interfaces with the on-board flash memory through dedicated peripheral registers. These are mapped in the high I/O space [cite: User Summary].

Register Name | Address (VMA) | Description
--- | --- | ---
`FLASH_STATUS` | `0x9000F000` | Read-only register reporting the state of the internal flash state machine.
`FLASH_CMD` | `0x9000F008` | Command register used to issue Erase, Program, and Reset sequences.
`FLASH_ADDR` | `0x9000F00C` | Sets the internal address counter for physical block operations.

## 2. Status Register Bit-Field Analysis

The `FLASH_STATUS` register (`0x9000F000`) provides granular feedback on the physical state of the flash cells [cite: User Summary].

Bit | Mnemonic | Description / Hybrid Relevance
--- | --- | ---
$7$ | `RY/BY#` | Ready/Busy: 1 = Ready (Operation Complete); 0 = Busy [cite: Volume XIX: Flash Programming Algorithm].
$5$ | `EERR` | Erase Error: Set to 1 if a sector erase operation fails. Indicates physical cell degradation.
$4$ | `PERR` | Program Error: Set to 1 if the current data write fails to verify.
$1$ | `VPPERR` | Vpp Error: Set to 1 if the programming voltage (Vpp) is insufficient for a write.

## 3. The RAM Stub Verification Loop

### Theory: Safe Exit Logic

Because the Host cannot monitor the burn, the RAM Stub must perform internal validation. If a write fails, the stub must purposefully enter an infinite "Panic" loop (LED Flash) rather than signaling success to prevent booting a corrupted kernel [cite: Volume XIX: Flash Programming Algorithm].

### MN103S Assembly: Verification Check

    ; Check Flash Status for Program Error
    ; Location: Inside the RAM Stub burn loop
    check_flash_status:
        mov     0x9000F000, a0  ; Point to FLASH_STATUS
        movbu   (a0), d0        ; Load current status

        ; Test Bit 7 (Ready)
        btst    7, d0
        beq     check_flash_status ; Wait if Busy (0)

        ; Test Bit 4 (Program Error)
        btst    4, d0
        bne     flash_panic_loop ; If PERR=1, jump to failure handler

        ret                     ; Success, continue to next chunk

## 4. Flash Error Diagnostics

If a drive is bricked, the developer can use Method B or Peek (if the bootloader is intact) to inspect `0x9000F000` to determine if the hardware physically failed during the last burn [cite: Project_Frankenstein_Vol_VIII_Peek_Poke.html].

- Status 0x80: Ready, No Errors (Success).
- Status 0x90: Ready, Program Error (Possible bad data or double-encryption).
- Status 0xA0: Ready, Erase Error (Physical hardware failure).