/* * ps1-bare-metal - Copyright (C) 2023-2026 spicyjpeg * SPDX-License-Identifier: MIT */ ENTRY(_start) MEMORY { /* * Only 2 MB of main RAM are available on a stock PS1, but some development * kits are fitted with 8 MB and PS1-based arcade systems often come with 4 * or even 16 MB; consoles may also be modified with additional RAM. You may * change the length below from 0x1f0000 to 0x3f0000, 0x7f0000 or 0xff0000 * to allow the linker to use the additional memory, though with some * caveats: * - the first 64 KB at 0x80000000-0x8000ffff are reserved for use by the * BIOS kernel during executable loading. They can be overwritten once * your code is running (as long as it doesn't depend on the kernel), but * initialized sections such as .text or .data cannot be placed there; * - most ways to load executables, including the BIOS as well as serial * loaders, are not capable of handling initialized sections that cross * the 2 MB boundary for a variety of reasons (conflicts with the default * stack top or the loader itself, incorrect default RAM configuration and * so on). */ APP_RAM (rwx) : ORIGIN = 0x80010000, LENGTH = 0x1f0000 } SECTIONS { /* Code sections */ .text : ALIGN(4) { _textStart = .; *(.text .text.* .gnu.linkonce.t.*) *(.plt .MIPS.stubs) } > APP_RAM .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) _textEnd = .; } > APP_RAM /* Global constructor/destructor arrays */ .init_array : ALIGN(4) { _initArrayStart = .; KEEP(*(SORT(.preinit_array.*))) KEEP(*(.preinit_array)) KEEP(*(SORT(.init_array.*) SORT(.ctors.*))) KEEP(*(.init_array .ctors)) _initArrayEnd = .; } > APP_RAM .fini_array : ALIGN(4) { _finiArrayStart = .; KEEP(*(.fini_array .dtors)) KEEP(*(SORT(.fini_array.*) SORT(.dtors.*))) _finiArrayEnd = .; } > APP_RAM /* Data sections */ .data : { _dataStart = .; *(.data .data.* .gnu.linkonce.d.*) } > APP_RAM /* * Set _gp (copied to $gp) to point to the beginning of .sdata plus 0x8000, * so anything within .sdata and .sbss can be accessed using the $gp * register as base plus a signed 16-bit immediate. */ .sdata : { _gp = ALIGN(16) + 0x7ff0; *(.sdata .sdata.* .gnu.linkonce.s.*) _dataEnd = .; } > APP_RAM /* * Ensure the entire BSS region is aligned at both ends in order to allow * for fast clearing. */ .sbss (NOLOAD) : ALIGN(4) { _bssStart = .; *(.sbss .sbss.* .gnu.linkonce.sb.*) *(.scommon) } > APP_RAM .bss (NOLOAD) : { *(.bss .bss.* .gnu.linkonce.b.*) *(COMMON) . = ALIGN(4); _bssEnd = .; } > APP_RAM /* Dummy sections */ .dummy (NOLOAD) : { KEEP(*(.dummy)) } > APP_RAM /DISCARD/ : { *(.note.* .gnu_debuglink .gnu.lto_*) *(.MIPS.abiflags) } }