psx.wiki
Log in
Main page
Hardware
Hardware tests
System software
SDKs
File formats
Games
Tools
History
All pages
page
view source
history
View source for BIOS C Functions
← BIOS C Functions
You do not have permission to edit this page.
Log in
to edit.
--- title: BIOS C Functions type: component summary: Kernel functions called through address 0xC0 with the function number in R9. category: System software info: Vector = 0x000000C0 info: Number register = R9 --- ## Overview The C functions are called by loading the function number into R9 and jumping to address 0xC0. Most of them are internal to the kernel: they build the interrupt chains, set up kernel memory and install the devices at boot.[^spxfn] GetC0Table() returns the address of the C function jump table.[^spxmisc] Numbers C(1Eh) to C(7Fh) jump to address 0, and numbers from C(80h) up mirror the B functions.[^spxfn] ## Interrupt and Exception Functions The kernel exception handler runs a list of interrupt handlers in four priority chains, and the C functions below build those chains. The [events](/system/bios/events/) page describes the chains and their default contents.[^spxexc] Table: C interrupt and exception functions | Number | Function | Explanation | | --- | --- | --- | | C(00h) | EnqueueTimerAndVblankIrqs(priority) | Installs the timer and vertical blank handlers (used with priority 1) | | C(01h) | EnqueueSyscallHandler(priority) | Installs the syscall handler (used with priority 0) | | C(02h) | SysEnqIntRP(priority, struc) | Inserts a handler at the head of a priority chain | | C(03h) | SysDeqIntRP(priority, struc) | Removes a handler from a priority chain (faulty) | | C(06h) | ExceptionHandler() | Address of the kernel exception handler | | C(07h) | InstallExceptionHandlers() | Copies the exception vector to 0x80000080 (destroys K0 and K1) | | C(0Ah) | ChangeClearRCnt(t, flag) | Selects whether a timer or vertical blank handler ends interrupt processing | | C(0Ch) | InitDefInt(priority) | Installs the default interrupt handler (used with priority 3) | | C(0Dh) | SetIrqAutoAck(irq, flag) | Selects whether the default handler acknowledges IRQ0 to IRQ10 | The element passed to SysEnqIntRP() is 16 bytes. The word at offset 0x00 is the link to the next element and is written by the BIOS. The word at 0x08 points to the first function, which runs first, and the word at 0x04 points to the second function, which runs only when the first returns a nonzero value in R2. The word at 0x0C is not used.[^spxexc] SysDeqIntRP() checks only the first element of a chain correctly and then reads an uninitialized stack value. It can therefore remove only the newest element of a chain, and only when that element is certainly in the chain.[^spxexc] Because the BIOS adds and removes its own handlers at priorities 1 and 2, psx-spx recommends priorities 0 and 3 for a program's own handlers.[^spxexc] The vector at C(06h) is not used by the exception vector itself, which jumps straight to the handler, so patching C(06h) has no effect. A custom handler at 0x80000080 can however read C(06h) to pass control on to the kernel handler without using R9.[^spxexc] ChangeClearRCnt() returns the previous flag. With flag 1 the handler acknowledges the interrupt and returns from the exception at once.[^spxtmr] ## Kernel Setup Functions These functions run during boot and are not normally called by a program.[^spxboot] Table: C kernel setup functions | Number | Function | Explanation | | --- | --- | --- | | C(04h) | get_free_EvCB_slot() | Subfunction of OpenEvent | | C(05h) | get_free_TCB_slot() | Returns the first free TCB, or -1 | | C(08h) | SysInitMemory(addr, size) | Sets the kernel memory area (0xA000E000, 0x2000 bytes) | | C(09h) | SysInitKernelVariables() | Zero-fills the kernel variables | | C(12h) | InstallDevices(ttyflag) | Sets up the FCBs and DCBs and adds the tty, cdrom and bu devices | | C(1Ch) | AdjustA0Table() | Copies the B(32h) to B(3Fh) addresses into the A table | The boot code overwrites the first instruction of SysInitKernelVariables() with the last word of the A table, so the function does not work after boot.[^spxboot] ## Device and Console Functions Table: C device and console functions | Number | Function | Explanation | | --- | --- | --- | | C(13h) | FlushStdInOutPut() | Closes and reopens file descriptors 0 and 1 | | C(15h) | _cdevinput(circ, char) | Internal TTY input buffer function | | C(16h) | _cdevscan() | Internal TTY function | | C(17h) | _circgetc(circ) | Internal TTY input buffer function | | C(18h) | _circputc(char, circ) | Internal TTY output buffer function | | C(19h) | _ioabort(txt1, txt2) | Prints two strings and executes _ioabort_raw(1) | | C(1Ah) | set_card_find_mode(mode) | Sets firstfile2 to find normal (0) or deleted (1) card files | | C(1Bh) | KernelRedirect(ttyflag) | Installs the DUART TTY (1) or the dummy TTY (0) | | C(1Dh) | get_card_find_mode() | Returns the card find mode | KernelRedirect(1) hangs a console that has no DUART hardware. The retail BIOS therefore installs the dummy TTY at boot, and debug messages from printf() go nowhere unless a program redirects them.[^spxtty] ## Unused Numbers C(0Eh) to C(11h) and C(14h) return 0 in retail kernels. In the DTL-H2000 BIOS C(0Eh) to C(11h) are the SIO device functions dev_sio_init, dev_sio_open, dev_sio_in_out and dev_sio_ioctl. C(0Bh) is a SystemError function that loops forever.[^spxfn][^spxna] ## References [^spxfn]: psx-spx. Kernel (BIOS), BIOS Function Summary, C-Functions. https://psx-spx.consoledev.net/kernelbios/ [^spxmisc]: psx-spx. Kernel (BIOS), BIOS Misc Functions, GetC0Table and GetB0Table. https://psx-spx.consoledev.net/kernelbios/ [^spxexc]: psx-spx. Kernel (BIOS), BIOS Interrupt/Exception Handling. https://psx-spx.consoledev.net/kernelbios/ [^spxtmr]: psx-spx. Kernel (BIOS), BIOS Timer Functions, C(0Ah) ChangeClearRCnt. https://psx-spx.consoledev.net/kernelbios/ [^spxboot]: psx-spx. Kernel (BIOS), BIOS Internal Boot Functions. https://psx-spx.consoledev.net/kernelbios/ [^spxtty]: psx-spx. Kernel (BIOS), BIOS TTY Console (std_io). https://psx-spx.consoledev.net/kernelbios/ [^spxna]: psx-spx. Kernel (BIOS), BIOS Misc Functions, N/A functions. https://psx-spx.consoledev.net/kernelbios/