BIOS Boot: Difference between revisions
| Revision as of 02:44, 23 October 2026 RemmyLee (CPU and system bus at register depth: instruction set, COP0, I/O map, memory control, interrupts, DMA, timers) | Revision as of 02:45, 23 October 2026 RemmyLee (BIOS and kernel: A, B, C functions, syscalls, events, threads, file I/O, boot, PS-X EXE) | ||
| Line 1: | Line 1: | ||
| + | --- | ||
| + | title: BIOS Boot | ||
| + | type: component | ||
| + | summary: Boot sequence from power on to the start of the boot executable on a disc. | ||
| + | category: System software | ||
| + | info: Reset vector = 0xBFC00000 | ||
| + | info: Boot file = SYSTEM.CNF BOOT line, or PSX.EXE | ||
| + | --- | ||
| + | |||
| + | ## Overview | ||
| + | |||
| + | Immediately after power on reset the program counter is 0xBFC00000, which is the start of the OS ROM.[^hw27] The kernel first checks the hardware connected to the PlayStation, such as the CD-ROM drive, and then checks for a suitable disc. If it finds one, it reads the configuration file [SYSTEM.CNF](/system/system-cnf/) and starts the boot executable. If there is no disc, a ROM-resident demonstration program plays repeatedly.[^lo104][^os23] | ||
| + | |||
| + | On a retail console the program in the second half of the ROM shows the Sony Computer Entertainment intro and then the PlayStation intro before the game starts. Without a disc it shows the boot menu, which plays audio CDs and manages Memory Cards.[^spxover][^spxver] The intro also performs the license and region checks, and it refuses to boot unlicensed discs, copies and discs for other regions.[^spxover] | ||
| + | |||
| + | ## Boot Sequence | ||
| + | |||
| + | The kernel boot sequence is shown below.[^lo105] | ||
| + | |||
| + | Table: Boot sequence | ||
| + | |||
| + | | Step | Operation | | ||
| + | | --- | --- | | ||
| + | | 1 | Initialize system operation memory | | ||
| + | | 2 | Set system stack | | ||
| + | | 3 | Initialize kernel memory | | ||
| + | | 4 | Initialize system memory control capability | | ||
| + | | 5 | Initialize IO manager | | ||
| + | | 6 | Set error handler | | ||
| + | | 7 | Read system setting file (system.cnf) | | ||
| + | | 8 | Analyze system setting file | | ||
| + | | 9 | Maintain all system table types | | ||
| + | | 10 | Read boot execution file | | ||
| + | | 11 | Set stack | | ||
| + | | 12 | Execute boot execution file | | ||
| + | |||
| + | psx-spx lists the internal functions used by the boot code: C(07h) InstallExceptionHandlers(), C(08h) SysInitMemory(), C(09h) SysInitKernelVariables(), C(12h) InstallDevices() and A(45h) init_a0_b0_c0_vectors(). The boot code also copies the shared file function addresses into the A table with C(1Ch) AdjustA0Table().[^spxboot] Before it starts the boot executable, the BIOS calls _96_init() so that the CD-ROM file functions are ready for use.[^spxcd] | ||
| + | |||
| + | ## Start Modes | ||
| + | |||
| + | The PS-X OS has two start modes on a development system, selected by the DIP switches of the target box when it is turned on or reset.[^os23] In hardware mode the OS boots as the PlayStation hardware does. When the switches select booting from a PC/AT compatible host, the kernel is set in its default configuration and the remote debugger starts. In this case the boot executable is read and executed by hand, and the kernel configuration cannot be altered.[^os23] | ||
| + | |||
| + | ## Disc Checks | ||
| + | |||
| + | The CD-ROM controller reports the type of disc with its GetID command. The reply includes a licensed flag and a four-letter region string read from the disc. The string is "SCEI" for Japan, "SCEA" for America, and "SCEE" for Europe.[^spxgetid] The string is displayed in the intro, and the console refuses to boot a disc whose string does not match its own region.[^spxgetid] The region of the drive is reported by the test command 19h,22h, which returns "for Europe", "for U/C" or "for Japan" on retail drives.[^spxregion] | ||
| + | |||
| + | The first 16 sectors of the first track of a PlayStation disc are the ISO 9660 system area. Sector 4 holds the license string, two 32-character lines that read "Licensed by" and "Sony Computer Entertainment Inc." or the Europe or America version of the name. Sectors 5 to 11 hold the PlayStation logo as 0x3278 bytes of TMD model data, and the remaining sectors are zero-filled.[^spxsysarea] The logo is the model drawn in the PlayStation intro.[^spxsysarea] | ||
| + | |||
| + | Table: System area of a PlayStation disc | ||
| + | |||
| + | | Sector | Contents | | ||
| + | | --- | --- | | ||
| + | | 0 to 3 | Zero-filled (Mode 2 Form 1) | | ||
| + | | 4 | License string | | ||
| + | | 5 to 11 | PlayStation logo (0x3278 bytes, rest filled with 0xFF) | | ||
| + | | 12 to 15 | Zero-filled (Mode 2 Form 2) | | ||
| + | |||
| + | Some BIOS versions compare the logo with a copy in ROM and refuse a disc whose logo differs. The NTSC US and Asia BIOS always accept a changed logo, the PAL BIOS accepts it up to v3.0E and refuses it from v4.0E, and the Japanese BIOS never accepts it.[^spxsysarea] | ||
| + | |||
| + | ## Loading the Boot Executable | ||
| + | |||
| + | The kernel reads SYSTEM.CNF and allocates its system tables from the TCB and EVENT values. It then loads the file named on the BOOT line, sets the stack to the STACK value and executes the file.[^lo105][^lo203] The stack values from SYSTEM.CNF replace the stack fields in the header of the boot executable.[^spxexe] The boot executable is a [PS-X EXE](/system/ps-x-exe/) file, and its name is the product code of the game. A disc without SYSTEM.CNF boots PSX.EXE.[^spxcnf] | ||
| + | |||
| + | The entry point of an execution file may be any function chosen at link time. When none is specified, main() is used, and the entry function cannot take an argument.[^os44] A program needs a stack pointer value as well as a start address. If the stack pointer holds an address that cannot be accessed, a bus error occurs.[^os45] | ||
| + | |||
| + | The kernel does not initialize the heap.[^os44] A program linked with 2mbyte.obj clears its bss area, sets the stack pointer to 0x80200000 and calls InitHeap() at start-up, while a program linked with none2.obj does none of these, and must call InitHeap() itself before using malloc().[^faq17][^faq18] With libsn the heap at start-up is 2 MB less the 32K standard stack, the 64K kernel RAM and the text, data and bss of the program.[^faq19] | ||
| + | |||
| + | ## Loading Further Executables | ||
| + | |||
| + | A game loads further programs with the kernel functions below. Load() and Exec() need the ISO 9660 file system installed by _96_init().[^lr146][^lr125] | ||
| + | |||
| + | Table: Executable functions | ||
| + | |||
| + | | Function | BIOS | Explanation | | ||
| + | | --- | --- | --- | | ||
| + | | LoadTest(name, exec) | A(41h) | Writes the execution file information of a file to exec and returns its start address[^lr148] | | ||
| + | | Load(name, exec) | A(42h) | Reads a file to the address in its header and calls FlushCache()[^lr146] | | ||
| + | | Exec(exec, argc, argv) | A(43h) | Executes a loaded module and returns when it returns[^lr125] | | ||
| + | | LoadExec(name, s_addr, s_size) | A(51h) | Calls Load() and Exec() with the given stack[^lr147] | | ||
| + | | FlushCache() | A(44h) | Flushes the instruction cache[^lr128] | | ||
| + | | _boot() | A(A0h) | Reboots the system[^lr180] | | ||
| + | | SetConf(ev, tcb, sp) | A(9Ch) | Changes the numbers of EvCBs and TCBs[^lr162] | | ||
| + | | GetConf(ev, tcb, sp) | A(9Dh) | Reads the configuration set by SetConf()[^lr132] | | ||
| + | | SetMem(n) | A(9Fh) | Sets the valid memory size to 2 or 8 MB[^lr163] | | ||
| + | |||
| + | Overlay processing on the PlayStation takes the form of a resident module executing a child process. The OS starts the boot file, but the application must drive the loading and starting of an overlay itself.[^os43] Child processes started by Exec() may be nested, although memory management then becomes difficult.[^faq13] | ||
| + | |||
| + | Load() and LoadExec() call FlushCache() because code loaded by DMA from the CD-ROM is not seen by the instruction cache. A program that loads code with read() or CdReadSector() must call FlushCache() itself.[^spxload] FlushCache() must be executed in a critical section.[^lr128] psx-spx finds, however, that the BIOS FlushCache() uses K0 with interrupts enabled. An interrupt at that point traps the function in an endless loop, and Load() and LoadExec() call it in that state.[^spxload] | ||
| + | |||
| + | LoadExec() takes a file name of fewer than 19 characters.[^lr147] It loads and executes the file, and if that file returns, it tries to reload and restart the boot executable.[^spxload] psx-spx finds that this restart reads the first four characters of the file name as an address and fails with a memory exception. The function then stops in an endless loop.[^spxload] | ||
| + | |||
| + | SetConf() destroys the event and task control blocks and every event handler and callback setting. It also removes the ISO 9660 file system, so _96_init() must be called again, and it invalidates all patches to the kernel. Sony therefore advises calling it at the head of the first execution file.[^lr162] Sony documents the third argument of SetConf() and GetConf() as ignored.[^lr162][^lr132] psx-spx finds that the BIOS stores it as the stack top while keeping the current stack pointer.[^spxload] | ||
| + | |||
| + | _boot() is for demonstration programs and not for general titles.[^lr180] It resets the kernel and boots the CD-ROM again without the intro screens, the logo check or the boot menu. Because it does not read SYSTEM.CNF again, it works only with the same disc or a disc with an identical SYSTEM.CNF.[^spxmisc] | ||
| + | |||
| + | SetMem() changes the valid memory size to 2 or 8 megabytes and ignores other values. Memory access outside the valid range causes a CPU exception regardless of the physical memory present.[^lr163] The retail boot code stores 2 MB at address 0x60 but sets the memory controller to 8 MB, in which the physical 2 MB is mirrored.[^spxheap] | ||
| + | |||
| + | ## References | ||
| + | |||
| + | [^hw27]: Sony Computer Entertainment Inc. PlayStation Hardware. August 1998. Page 2-7, Figure 2-3. | ||
| + | [^os23]: Sony Computer Entertainment Inc. PlayStation Operating System. August 1998. Page 2-3. | ||
| + | [^os43]: Sony Computer Entertainment Inc. PlayStation Operating System. August 1998. Page 4-3. | ||
| + | [^os44]: Sony Computer Entertainment Inc. PlayStation Operating System. August 1998. Page 4-4. | ||
| + | [^os45]: Sony Computer Entertainment Inc. PlayStation Operating System. August 1998. Page 4-5. | ||
| + | [^lo104]: Sony Computer Entertainment Inc. Run-Time Library Overview. January 1999. Page 1-4. | ||
| + | [^lo105]: Sony Computer Entertainment Inc. Run-Time Library Overview. January 1999. Page 1-5, Figure 1-1. | ||
| + | [^lo203]: Sony Computer Entertainment Inc. Run-Time Library Overview. January 1999. Page 2-3. | ||
| + | [^lr125]: Sony Computer Entertainment Inc. Run-Time Library Reference. January 1999. Page 1-25, Exec. | ||
| + | [^lr128]: Sony Computer Entertainment Inc. Run-Time Library Reference. January 1999. Page 1-28, FlushCache. | ||
| + | [^lr132]: Sony Computer Entertainment Inc. Run-Time Library Reference. January 1999. Page 1-32, GetConf. | ||
| + | [^lr146]: Sony Computer Entertainment Inc. Run-Time Library Reference. January 1999. Page 1-46, Load. | ||
| + | [^lr147]: Sony Computer Entertainment Inc. Run-Time Library Reference. January 1999. Page 1-47, LoadExec. | ||
| + | [^lr148]: Sony Computer Entertainment Inc. Run-Time Library Reference. January 1999. Page 1-48, LoadTest. | ||
| + | [^lr162]: Sony Computer Entertainment Inc. Run-Time Library Reference. January 1999. Page 1-62, SetConf. | ||
| + | [^lr163]: Sony Computer Entertainment Inc. Run-Time Library Reference. January 1999. Page 1-63, SetMem. | ||
| + | [^lr180]: Sony Computer Entertainment Inc. Run-Time Library Reference. January 1999. Page 1-80, _boot. | ||
| + | [^faq13]: Sony Computer Entertainment. PlayStation Development FAQ, OS Conference. Release v1.2, 29 February 1996. Item 1.3. | ||
| + | [^faq17]: Sony Computer Entertainment. PlayStation Development FAQ, OS Conference. Release v1.2, 29 February 1996. Item 1.7. | ||
| + | [^faq18]: Sony Computer Entertainment. PlayStation Development FAQ, OS Conference. Release v1.2, 29 February 1996. Item 1.8. | ||
| + | [^faq19]: Sony Computer Entertainment. PlayStation Development FAQ, OS Conference. Release v1.2, 29 February 1996. Item 1.9. | ||
| + | [^spxover]: psx-spx. Kernel (BIOS), BIOS Overview. https://psx-spx.consoledev.net/kernelbios/ | ||
| + | [^spxver]: psx-spx. Kernel (BIOS), BIOS Versions, Bootmenu/Intro Versions. https://psx-spx.consoledev.net/kernelbios/ | ||
| + | [^spxboot]: psx-spx. Kernel (BIOS), BIOS Internal Boot Functions. https://psx-spx.consoledev.net/kernelbios/ | ||
| + | [^spxcd]: psx-spx. Kernel (BIOS), BIOS CDROM Functions. https://psx-spx.consoledev.net/kernelbios/ | ||
| + | [^spxload]: psx-spx. Kernel (BIOS), BIOS File Execute and Flush Cache. https://psx-spx.consoledev.net/kernelbios/ | ||
| + | [^spxmisc]: psx-spx. Kernel (BIOS), BIOS Misc Functions, A(A0h) _boot. https://psx-spx.consoledev.net/kernelbios/ | ||
| + | [^spxheap]: psx-spx. Kernel (BIOS), BIOS Memory Allocation, A(9Fh) SetMem. https://psx-spx.consoledev.net/kernelbios/ | ||
| + | [^spxexe]: psx-spx. CDROM File Formats, CDROM File Playstation EXE and SYSTEM.CNF. https://psx-spx.consoledev.net/cdromfileformats/ | ||
| + | [^spxcnf]: psx-spx. CDROM File Formats, SYSTEM.CNF. https://psx-spx.consoledev.net/cdromfileformats/ | ||
| + | [^spxgetid]: psx-spx. CDROM Drive, GetID - Command 1Ah. https://psx-spx.consoledev.net/cdromdrive/ | ||
| + | [^spxregion]: psx-spx. CDROM Drive, CDROM - Test Commands - Version, Switches, Region, Chipset, SCEx. https://psx-spx.consoledev.net/cdromdrive/ | ||
| + | [^spxsysarea]: psx-spx. CDROM Format, System Area (prior to Volume Descriptors). https://psx-spx.consoledev.net/cdromformat/ | ||