Skip to content

IOS

IOS is the operating system that runs on Starlet. It provides the filesystem, ES (eTicket Services) and device drivers. boot2 loads IOS from the NAND filesystem. The loaded IOS starts its own kernel and modules, including the DI (Disc Interface) and OHCI (USB Open Host Controller Interface) drivers.

IOS58 also includes an EHCI (USB 2.0) driver.

IOS80 modules

IOS80 v6944 contains the following module tags in its embedded IOSVersion strings:

Content ID Tag
0x00000001 DIP
0x00000002 OH0
0x00000003 OH1
0x00000004 SDI
0x00000005 SO
0x00000006 KD
0x00000007 WD
0x00000010 WL
0x00000009 NCD
0x0000000A ETH
0x0000000B STM
0x0000000C KBD
0x0000000D SSL
0x0000000E IOSP, FSP and ES

System Menu launch

boot2 selects the System Menu title 00000001-00000002 and loads its required IOS. It carries the launch request across the IOS reload in /sys/launch.sys. The file starts with an 8 byte big-endian title ID followed by a 0xD8 byte ticket view.

During startup, es_worker (0x201015E8) reads this file, obtains the title metadata and configures IPC access rights before calling launch_title (0x20104CF4). The title's boot content is passed to load_executable (0xFFFF0E8C). For a DOL, the loader clears BSS and loads the text and data sections into RAM.

prepare_broadway (0xFFFF0E40) installs the 64 byte g_broadway_reset_stub (0xFFFF8880) through EXI. The stub sets SRR0 to 0x00003400, clears SRR1 and executes rfi. The loaded executable supplies the code at 0x00003400.

Address Width Register IOS use
0x0D800034 32 bits HW_PPCIRQMASK Enables the Broadway IPC interrupt.
0x0D800070 32 bits HW_EXICTRL Controls EXI access around boot-code setup.
0x0D800180 32 bits HW_DIFLAGS Selects the uploaded boot code.
0x0D800194 32 bits HW_RESETS Sequences Broadway reset.
0x0D806840 through 0x0D80687F 32 bit writes EXI boot-code window Holds 16 instruction words.
Register Bits Firmware operation
HW_PPCIRQMASK 30 Set before releasing Broadway.
HW_EXICTRL 0 Set while uploading the stub, cleared before reset release and set again afterwards.
HW_DIFLAGS 20 Set after uploading the stub.
HW_RESETS 5:4 Both cleared first, then bit 5 is set and finally bit 4 is set.

reset_broadway (0xFFFF678C) performs the reset sequence after loading the executable. The uploaded stub runs from Broadway's reset vector at 0xFFF00100 and transfers execution to the loaded title.

Once the System Menu is running, it uses DIP to detect discs and read Disc Channel data.

Certificate identity

read_certificate_identity (0xFFFF1E20) reads the MS identifier, CA identifier, NG key identifier and NG certificate signature from SEEPROM when OTP keys are present. It formats the issuer components as MS%08x and CA%08x.

read_device_id (0xFFFF1CE0) reads OTP word 9 for the device identifier. The certificate name is formatted as NG%08x using this value. These kernel addresses refer to IOS80.

Signature verification

IOS80's verify_rsa_sha1 (0x13A75514) imports the signature, public modulus and exponent as big integers. It computes signature^exponent mod modulus in software through bigint_power_modulo (0x13A77A40), using multiplication and division for modular reduction. It converts the result back to bytes and checks the signature padding, SHA-1 identifier and supplied 20 byte digest. It returns 0 on success or 7 on failure.

verify_rsa2048 (0x13A75664) selects a 256 byte modulus and verify_rsa4096 (0x13A75680) selects a 512 byte modulus. Disc partition verification uses this path before the partition is marked open.

Title hardware access

Syscall 0x54 permits only process ID 1 to change title hardware access. A nonzero low byte of r0 enables access. Zero disables it.

set_broadway_access (0xFFFF6FC0) sets or clears the HW_AHBPROT mask 0x80000DFE without changing other bits. It also sets or clears HW_SRNPROT[AHPEN] to match. Enabling writes the 16 bit value 0 to 0x0D8B4202. Disabling writes the 16 bit value 0x18 to 0x0D8B4200.

MEM2 protection

protect_mem2 (0xFFFF6F94) programs the MEM2 protection registers with 16 bit stores. It writes 1 to MEM_PROT then writes (start - 0x10000000) >> 12 to MEM_PROT_START and (end - 0x10000000) >> 12 to MEM_PROT_END. The arguments are physical addresses and the final page is included. The routine delays after the three writes.

Thread waits

receive_queued_message (0xFFFF2968) blocks when the queue is empty and its nonblocking argument is zero. It marks the current thread as waiting and yields to the scheduler. After a successful wakeup, it checks the queue again before it reads a message.

Once the service threads are started, the initialization thread lowers its own priority to zero and enters an idle loop at 0xFFFF0C6A. The loop reads g_debug_requests (0xFFFF9ECC) repeatedly while it is zero. When the word is nonzero, the loop passes its value to print_debug_state (0xFFFF6084) to select diagnostic output then clears the word. The loop does not execute a wait-for-interrupt instruction.

Firmware g_debug_requests print_debug_state
IOS80 v6944 0xFFFF9ECC 0xFFFF6084
IOS70 v6687 0xFFFF9E8C 0xFFFF6078
IOS35 v3608 0xFFFF9BCC 0xFFFF5E24

Every IOS kernel build implements the loop with the same three Thumb instructions, where R4 holds the address of g_debug_requests.

loop:
    LDR R3, [R4]
    CMP R3, #0
    BEQ loop

Only the loop's address differs between builds. The kernel build column gives the date and time from the kernel module's version string.

Kernel build IOS versions Idle loop
03/01/10 02:53 and 03:05 IOS9, IOS12, IOS13, IOS14, IOS15, IOS17, IOS21, IOS22 0xFFFF0C3C
03/01/10 03:13 and 03:37 IOS28, IOS31, IOS33, IOS34, IOS35, IOS36, IOS38 0xFFFF0C4C
03/01/10 03:28 IOS37, IOS41, IOS43, IOS45, IOS46, IOS48, IOS53, IOS55 0xFFFF0C4E
11/24/08, 06/03/09, 03/03/10 and 02/27/12 IOS16, IOS40, IOS50, IOS51, IOS52, IOS56, IOS57, IOS58, IOS60, IOS61, IOS62, IOS70, IOS80 0xFFFF0C6A

For an undefined instruction that does not match the syscall encoding, undefined_exception (0xFFFF1F24) saves the exception return address, marks the current thread as faulted with state 6 and calls dispatch_thread (0xFFFF2340). The faulted thread is no longer runnable. The idle loop can therefore run while a service thread is faulted and other services are waiting for messages.

IPC requests

Broadway requests IOS services through shared RAM and the IPC mailboxes. The request in RAM contains a command, a result field and command-specific arguments. The mailbox carries the request's physical address. File paths and transfer buffers are referenced by pointers in the request.

Broadway makes the request visible in RAM before writing its address to the request mailbox and signaling a new request through IPC control. An enabled IPC interrupt notifies Starlet. IOS acknowledges receipt separately from completing the operation, allowing Broadway to submit another request while earlier work remains pending.

IOS dispatches the request to the appropriate service. On completion, it supplies the result in shared RAM and publishes the reply pointer through the return mailbox. Broadway handles the reply interrupt, invalidates the relevant cache lines before reading the result and acknowledges the reply.

Mailboxes and control flags

Broadway physical address Starlet physical address Width Name IOS use
0x0D000000 0x0D800000 32 bits PPCMSG Physical address of a request from Broadway.
0x0D000004 0x0D800004 32 bits PPCCTRL Broadway's handshake flags and interrupt enables.
0x0D000008 0x0D800008 32 bits ARMMSG Physical address of a reply from IOS.

Starlet accesses ARMCTRL at 0x0D80000C. The control registers expose the same four handshake flags at different bit positions:

Flag PPCCTRL bit ARMCTRL bit IOS protocol
X1 0 2 Broadway signals a new request. IOS clears it by writing 1 to the ARMCTRL field.
X2 3 1 Broadway acknowledges a reply. IOS clears it by writing 1 to the ARMCTRL field.
Y1 2 0 IOS signals a reply. Broadway clears it by writing 1 to the PPCCTRL field.
Y2 1 3 IOS acknowledges receipt of a request. Broadway clears it by writing 1 to the PPCCTRL field.
Register Bit Field Interrupt enable
PPCCTRL 4 IY1 Reply notification through Hollywood interrupt 30.
PPCCTRL 5 IY2 Request acknowledgement through Hollywood interrupt 30.
ARMCTRL 4 IX1 New request through Hollywood interrupt 31.
ARMCTRL 5 IX2 Reply acknowledgement through Hollywood interrupt 31.

Writing a mailbox supplies its value. Software signals the corresponding control flag separately. Clearing Y1 consumes the reply notification. Setting X2 tells IOS that it can publish another queued reply.

Broadway sets X1 or X2 by writing 1 to the corresponding PPCCTRL field.

Tip

Writing zero to PPCCTRL clears neither flag!! We tested this on hardware!!

Startup notification

On success, set_ipc_access_rights (0xFFFF2ED4) writes 0x38 to ARMCTRL after updating the registered devices' access permissions. This enables IX1 and IX2 and sets Y2, as defined in the control flag tables. The routine does not read a request from PPCMSG or publish a reply through ARMMSG. This startup notification can therefore assert Y2 independently of request receipt.

IOS reload

Broadway requests an IOS reload through /dev/es with IPC command 7 (ioctlv) and ES operation 0x08. The request has two input vectors and no output vectors: an 8 byte title ID and a 0xD8 byte ticket view.

The old IOS acknowledges receipt with Y2 before executing the reload. The input vectors remain in use after this acknowledgement. A successful reload does not return a normal Y1 reply from the old IOS. The new IOS sets Y2 again through its startup notification. These are two separate notifications: request receipt followed by initialization of the new IOS's IPC access rights.

Request layout

The request header occupies 32 bytes. Its words are big endian and buffer pointers are physical addresses.

Byte offset Size Field Meaning
0x00 4 bytes Command Requested IOS operation.
0x04 4 bytes Result Signed result returned by IOS.
0x08 4 bytes Descriptor / original command Input descriptor for operations on an open handle. IOS replaces it with the original command before dispatch.
0x0C 20 bytes Arguments Five command-specific words.

For an open request, command 1 uses a path pointer at 0x0C and a mode at 0x10. IOS checks that the path terminates within 64 bytes. A successful open returns a nonnegative handle. A close request uses command 2 and supplies that handle at 0x08.

Broadway IPC worker

ipc_worker (0xFFFF4ABC) creates a queue with capacity for 50 messages and stores its handle in g_ipc_queue (0xFFFFCE1C). It registers hardware event 31 on that queue with a pointer to g_ipc_event_message (0xFFFFCDFC), whose value is 9. It then waits for queue messages.

Before waiting, the worker reads PPCCTRL. If both IY1 and IY2 are clear, it writes zero to PPCCTRL. If either interrupt enable is set, it leaves PPCCTRL unchanged. The fields are defined in the control flag tables.

rearm_ipc_interrupt (0xFFFF5E2C) clears the IPC interrupt flag and enables its mask. IPC uses bit 31 in HW_ARMIRQFLAG and HW_ARMIRQMASK.

On an IPC interrupt, irq_handler (0xFFFF20D4) clears the IPC mask bit, acknowledges the pending interrupt and calls deliver_event (0xFFFF1FF4) for event 31. Event delivery appends the registered message to its queue and makes a waiting receiver runnable. An unregistered event or a full queue receives no message. Returning from the IRQ handler does not itself unmask IPC.

Register Bits Worker use
ARM control (0x0D80000C) 1 Handle Broadway's response acknowledgement.
ARM control (0x0D80000C) 2 Read a new Broadway request pointer from 0x0D800000.

For an event message with value 9, the worker checks the control register. It checks response acknowledgement before a new request. When handling a new request, it reads the request pointer, updates the control register and rearms the interrupt before validating and dispatching the request.

If neither X2 nor X1 is set when the worker processes the event message, it returns to waiting for queue messages without rearming the IPC interrupt.

For a new request, it writes the preserved interrupt enables together with 0x0C to ARMCTRL: clear X1 and set Y2. If 47 requests are already pending, it writes 0x04 instead and withholds the receipt acknowledgement for the next request.

Open requests block the worker despite the asynchronous interface. open_async (0xFFFF31D0) calls open_device (0xFFFF3020), which waits for the device service to reply. If another IPC interrupt arrives in the meantime, the IRQ handler masks the source and queues its event. The worker cannot process that event or rearm IPC until the open returns.

queue_ipc_reply (0xFFFF4A0C) places a completed request pointer in a ring with 48 entries. send_ipc_reply (0xFFFF4994) publishes a queued reply only when the reply mailbox is available. It flushes the 32 byte request header, writes the pointer to ARMMSG and sets Y1 through ARMCTRL. It then marks the reply mailbox unavailable until Broadway signals X2.

Publishing a reply reduces the pending request count. When that count is 48 before publication, the control write also sets Y2 to release the withheld receipt acknowledgement. The worker preserves IX1 and IX2 when it writes handshake flags.

Timer alarm

program_alarm (0xFFFF4190) clamps the requested delay to at least two timer ticks. It reads HW_TIMER (0x0D800010) once and saves that sample in g_last_timer_tick (0xFFFFCC14). It adds the delay to the sample with 32 bit wraparound and writes the result to HW_ALARM (0x0D800014).

delay_ticks = max(delay_ticks, 2)
now = HW_TIMER
g_last_timer_tick = now
HW_ALARM = (now + delay_ticks) & 0xFFFFFFFF

Timers

The kernel keeps up to 256 timers in a table at 0xFFFE60C0 with 28 byte entries. g_timer_list (0xFFFFCC18) heads a doubly linked list of the armed timers in expiry order. Each entry's delay counts from the expiry of the entry before it. These addresses refer to IOS80.

Offset Size Field Meaning
0x00 4 bytes Delay Ticks until expiry, relative to the previous armed timer
0x04 4 bytes Period Repeat interval in microseconds, 0 for a one-shot timer
0x08 4 bytes Queue Pointer to the destination message queue
0x0C 4 bytes Message Message word sent on expiry
0x10 4 bytes Process Owning process ID
0x14 4 bytes Previous Previous armed timer or 0 while stopped
0x18 4 bytes Next Next armed timer or 0 while stopped

create_timer (0xFFFF432C) rejects a queue ID above 255 with -4 and a queue owned by another process with -1. It takes the first free entry (one whose queue pointer is 0) and returns -5 when none is free. It stores the period, queue, message and process, converts the initial delay (or the period when the delay is 0) to ticks with microseconds_to_ticks (0xFFFF7128) and arms the entry through insert_timer (0xFFFF41B8) unless the conversion yields zero ticks. It returns the entry index.

restart_timer (0xFFFF43DC) only accepts a stopped one-shot timer, one whose period, delay and both links are zero. Any other state returns -4, including a one-shot timer that expired without being stopped. A timer owned by another process returns -1. For an accepted timer it stores the new period and arms the entry like create_timer.

insert_timer first subtracts the ticks elapsed since g_last_timer_tick from the head entry's delay. It then walks the list to the first entry whose delay is at least the remaining delay, subtracts the new delay from that entry and links the new entry before it. When the new entry becomes the head, it calls program_alarm with its delay.

timer_worker (0xFFFF423C) runs in its own thread and waits for the timer interrupt event. For each head entry whose delay has elapsed, it unlinks the entry, re-arms it if the period is nonzero and sends the message to the queue with the nonblocking flag, ignoring a full queue. An expired one-shot timer keeps its last delay value in the entry. Afterwards the worker subtracts the elapsed ticks from the new head's delay and programs the alarm for it.

The re-armed delay for a periodic timer is delay - elapsed + period_ticks - 1 when delay + period_ticks is at least elapsed, otherwise 1. When the worker runs exactly period_ticks after the timer expired, the delay becomes 0xFFFFFFFF and the timer does not expire again for 2^32 ticks.

DMA buffer addresses

dma_address (0xFFFF52D4) translates a buffer's virtual address through the active page tables and converts SRAM CPU addresses to DMA addresses. The AES and SHA-1 services use the converted address when programming their engines. These addresses refer to IOS80.

SRAM bank CPU physical start CPU physical end (inclusive) DMA start DMA end (inclusive)
A 0xFFFF0000 0xFFFFFFFF 0x0D400000 0x0D40FFFF
B 0xFFFE0000 0xFFFE7FFF 0x0D410000 0x0D417FFF

The conversion preserves the offset within the bank. MEM1 and MEM2 keep their translated physical addresses. The page tables map MEM1, MEM2 and both SRAM windows to their own physical addresses, so translation changes only the SRAM DMA view.

Cache and AHB flush

Four syscalls keep the Starlet data cache and AHB device writes coherent. Each one disables interrupts while it runs. These addresses refer to IOS80.

invalidate_data_range (0xFFFF5BE0) first calls check_pointer_range (0xFFFF45C8) to confirm that the calling process may write the range. If it may not, the syscall prints bad invalidate requested and returns without touching the cache. A zero length also returns immediately. Otherwise it invalidates every 32 byte line that covers the range. When the length exceeds 0x4000 bytes it cleans and invalidates the whole data cache instead. It then calls flush_device_and_cpu(0) (0xFFFF6740).

flush_data_range (0xFFFF5C50) returns immediately for a zero length. Otherwise it cleans every line that covers the range. When the length exceeds 0x4000 bytes it cleans the whole data cache instead. It then drains the write buffer and calls flush_device_writes(1) (0xFFFF6684).

flush_from_device (0xFFFF5CC8) only calls flush_device_writes(device). flush_to_device (0xFFFF5CE4) only calls flush_device_and_cpu(device).

flush_device_writes looks up the mask for the device and writes it as a 16 bit value to 0x0D8B4228. It then waits for the 16 bit register at 0x0D8B422A to return the same mask. Each poll goes through memreg_read_sync(0x22A) (0xFFFF6664), which reads the register and runs ahb_sync_dev(0) (0xFFFF642C) before it returns the value. The function calls delay(1) (0xFFFF7030) between polls. After 1,000,000 polls it gives up and prints ERROR: ahbMemFlush(0x%x) did not ack!. Whether or not the mask arrives, it finishes by writing 0 to 0x0D8B4228. boot1 performs the same engine handshake.

Device Mask
0, 1, 11, 13 1
4, 5, 12, 14 2
2, 6, 15 4
3, 7, 8, 9, 10, 16 8
17 15
18 and above 0

flush_device_and_cpu runs ahb_sync_dev(device). For a nonzero device it then also runs ahb_sync_dev(0). ahb_sync_dev selects one bit of the 32 bit register at 0x0D8B0008 and reads the register through read_0d8b_register (0xFFFF63E0). That helper behaves exactly like boot1's mc_read (0xFFF014A0), including the four discarded reads of 0x0D800138 and the two reads of 0x0D800214. If the selected bit is already set, ahb_sync_dev returns. Otherwise devices 2 through 10 run boot1's status wait before device synchronization unchanged, with both HW_BOOT0 polls and the writes that clear and set the bit. Devices 0, 1 and 11 write the register once with the bit clear and then three times with it set, as boot1 does for device 0.

Device 0x0D8B0008 bit Sequence
0 15 One write with the bit clear, three set
1 14 One write with the bit clear, three set
11 12 One write with the bit clear, three set
2 through 10 device - 2 Full status wait
12 and above None Returns without writing

AES completion

IOS80's AES service thread aes_worker (0x13A7414C) registers event 2 with message value 0 on its completion queue. It submits the AES command with the completion interrupt enabled and waits on that queue.

The kernel IRQ handler acknowledges the AES interrupt by writing 0x00000004 to HW_ARMIRQFLAG (0x0D800038) and then delivers event 2.

SHA-1 completion

IOS80's SHA-1 service thread sha_worker (0x13A74750) registers event 3 with message value 0 on its completion queue. process_sha (0x13A74440) submits whole input blocks with the completion interrupt enabled and waits on that queue. For a single 64 byte block, it writes 0xC0000000 to the SHA-1 control register (0x0D030000).

IOCTLV command 0 requires one input vector and two output vectors. The first output vector supplies the SHA-1 context address. Its declared length is not checked. Operation 0 writes the five SHA-1 initial state words followed by two zero length words to this address even when the input length is zero. A zero length request returns after these 28 bytes are written without starting the SHA-1 engine or writing the digest output vector.

The kernel IRQ handler acknowledges the SHA-1 interrupt by writing 0x00000008 to HW_ARMIRQFLAG (0x0D800038) and then delivers event 3.

Syscalls

Syscalls are undefined ARM instructions. Executing one raises an Undefined Instruction exception and the vector at 0xFFFF0004 jumps to undefined_exception. The handler accepts the instruction word only if every bit outside the index field matches 0xE6000010.

Bits Field Value
31:13 Fixed Same as 0xE6000010
12:5 Index Syscall index
4:0 Fixed Same as 0xE6000010

For example, 0xE6000130 selects index 9. Arguments are passed in r0 through r3 and the result is returned in r0. Execution then resumes at the instruction after the syscall. Indices above 0x7A return immediately with r0 unchanged.

Index Function Arguments Result
0x03 get_thread_id (0xFFFF04A0) None Current thread's index in the kernel thread table
0x08 get_thread_priority (0xFFFF0760) r0 = thread ID (0 selects the current thread) Priority or -4 if the thread ID or process access is rejected
0x09 set_thread_priority (0xFFFF07B0) r0 = thread ID (0 selects the current thread), r1 = priority 0 on success or -4 if the thread or priority is rejected
0x0C send_message (0xFFFF27F8) r0 = queue ID, r1 = message word, r2 = nonblocking flag 0 on success or a negative error
0x0E receive_message (0xFFFF29E4) r0 = queue ID, r1 = writable message-word pointer, r2 = nonblocking flag 0 on success or a negative error
0x11 create_timer (0xFFFF432C) r0 = delay in microseconds, r1 = period in microseconds, r2 = queue ID, r3 = message word Timer index or -4, -1 or -5, see Timers
0x12 restart_timer (0xFFFF43DC) r0 = timer index, r1 = delay in microseconds, r2 = period in microseconds 0 on success, -1 for another process's timer or -4, see Timers
0x15 get_timer (0xFFFF4530) None Current 32 bit HW_TIMER value
0x2A reply_request (0xFFFF408C) r0 = dispatched request pointer, r1 = signed service result Reply delivery result or -4 for a rejected request
0x2F flush_from_device (0xFFFF5CC8) r0 = device None, see Cache and AHB flush
0x30 flush_to_device (0xFFFF5CE4) r0 = device None, see Cache and AHB flush
0x3F invalidate_data_range (0xFFFF5BE0) r0 = address, r1 = length None, see Cache and AHB flush
0x40 flush_data_range (0xFFFF5C50) r0 = address, r1 = length None, see Cache and AHB flush
0x54 set_title_access (0xFFFF6234) Low byte of r0 = enable flag 0 on success or -1 unless the caller belongs to process ID 1

The message queue calls accept a nonblocking flag of 0 or 1. With 0, a send to a full queue or a receive from an empty queue suspends the calling thread as described in Thread waits. With 1, the call returns without suspending. Both calls check the queue's owning process. A receive also validates the 4 byte message destination before it accesses the queue.