├── .vscode ├── .gitignore └── settings.json ├── LICENSE ├── NativeDebug.png ├── README.md ├── get_started ├── .gitignore ├── .vscode │ ├── .gitignore │ ├── c_cpp_properties.json │ ├── launch.json │ └── tasks.json ├── Makefile ├── comport.txt └── main.c ├── images ├── Redux.png ├── downloadzip.png └── json.png ├── nops.gdb_beta ├── UNIROM_BOOTDISC_8.0.Kish.bin ├── UNIROM_BOOTDISC_8.0.Kish.cue ├── nops.exe ├── unirom_b.exe ├── unirom_datelv2_withcaetla.rom ├── unirom_standalone.rom └── unirom_withcaetla.rom └── third_party ├── .gitignore ├── LICENSE ├── README.md ├── common.mk ├── common ├── crt0 │ ├── crt0.dep │ ├── crt0.o │ ├── crt0.s │ └── uC-sdk-crt0.s ├── hardware │ ├── cdrom.h │ ├── cop0.h │ ├── dma.h │ ├── gpu.h │ ├── hwregs.h │ ├── hwregs.inc │ ├── irq.h │ ├── pcsxhw.h │ ├── sio1.c │ ├── sio1.h │ ├── spu.h │ └── util.h ├── kernel │ ├── events.h │ ├── openbios.h │ └── pcdrv.h ├── psxlibc │ ├── circularbuffer.h │ ├── device.h │ ├── direntry.h │ ├── fastmemset.s │ ├── handlers.h │ ├── ioctl.h │ ├── psxexe.h │ ├── setjmp.h │ ├── stdio.h │ └── string.h ├── syscalls │ ├── printf.dep │ ├── printf.o │ ├── printf.s │ └── syscalls.h └── util │ ├── djbhash.h │ ├── encoder.hh │ ├── sjis-table.h │ └── util.h ├── cpe.ld ├── default.ld ├── nooverlay.ld ├── ps-exe.ld └── psyq ├── README.md └── include └── inline_n.h /.vscode/.gitignore: -------------------------------------------------------------------------------- 1 | *.log -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "makefile.extensionOutputFolder": "./.vscode" 3 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Nadir Zaman Syed 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NativeDebug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/NativeDebug.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VSCodePSX 2 | 3 | Major changes! 4 | 5 | A basic setup to get coding for PSX on Win 10 64bit with VS Code 6 | Use modern day GCC with the unofficial official based SDK 7 | Guide by NDR008, many many contributors to this but definitely: 8 | Schnappy, Nicolas, Sickle, danhans42 and Skitchin. 9 | 10 | 11 | # Youtube Guide 12 | 13 | 14 | # Goals of this Repo 15 | Many people follow tutorials and youtube videos that rely on people setting up virtual machines to use the original Psyq libraries and tookchains. 16 | 17 | This repo is design to allow people to almost follow those tutorials without having to setup such vritual machines but work with modern OSes (I only care about Linux and Windows) while having the luxury of a modern IDE such as VSCode to do all the work from: 18 | - Compile 19 | - Debug together with PCSX-Redux OR real hardware running the latest beta unirom in conjunction with a special version of nops (the latter has not be tested by myself) 20 | 21 | So in reality this repo is mostly a fudge of other people's work that I am not trying to take credit off. 22 | 23 | ## Most of the SDK magic 24 | Most of the magic for getting psyq to work is comming from Nicolas and his nugget toolchain. If you want to compile openbios, and all the other magic nugget has (including a new alternative C++ library called psyqo - then do check his repo): 25 | 26 | 27 | ## NOPS that allows for GDB 28 | 29 | The special version of NOPS is thanks to Skitching: 30 | 31 | 32 | ## Unirom 33 | 34 | From the one and only: 35 | 36 | 37 | ## PCSX-Redux 38 | 39 | I use almost soley PCSX-Redux as my PSX emulator, it is a stable emulator with a lot of debugging and development features as well as a lua script engine (which I use for other projects). 40 | For this guide, it will be mandatory to use PCSX-Redux (for the debugging function). 41 | And if you are still using ePSXe... why? 42 | 43 | 44 | # Setting Things Up 45 | My setup focuses on Windows. I think those that are using Linux natively will know how to adjust the necessary things themselves. 46 | 47 | My instructions however do allow for 3 methods. 48 | 49 | - Method 1a: Windows automated (using Nic's method) 50 | - Method 1b: Windows natively 51 | - Method 2: Windows with WSL 52 | 53 | The main difference between the methods are how to acquire gcc for MIPS, gdb-multiarch and make. All are readily available on Ubuntu, and does, installing WSL and relying on Ubuntu to install those packages is an easy and reliable method. 54 | 55 | However, thanks to Nicolas, there are also Windows builds of those tools. 56 | 57 | So now we are spoiled for choice (and many more method of setting up psyq or alternative SDKs for the PSX). 58 | This git is focused on Visual Studio Code configuration files should work for both methods, with minimal elements of nugget. 59 | 60 | # Common Parts of setting up 61 | 62 | Follow these steps no matter what method you will use. 63 | 64 | ## 0. Grab PCSX-Redux! 65 | 66 | 0.1. Download and unzip somewhere PCSX-Redux 67 | 68 | ## 1. Install Visual Studio and Commonly used Plugins 69 | 70 | 1.1. Install visual studio: 71 | 1.2. Install the C/C++ extension package: 72 | 1.3. Install the task explorer extension: 73 | 1.4. Install the Github extension: 74 | 1.5. Install GDB extension: 75 | 76 | ## 2. Clone this repo and add psyq 77 | 78 | 2.1. If you are familiar with git, clone this repo, if not just download the repo as a zip. 79 | ![Download](./images/downloadzip.png) 80 | 2.2. Download the magic psyq library from here: (you will need 7zip if you do not have it yet...) 81 | 2.3. Unzip the contents into the ```third_party\psyq``` folder (be careful, there is already one file: inline_n.h inside ```third_party\psyq\include``` - do not lose it by overwriting the "include" folder from the the zip in step 2.2 over the existing "include"). 82 | 83 | # Steps for Windows using Nic's script (Method 1a): 84 | 85 | Open the run promots and type: 86 | ```powershell -c "& { iwr -UseBasicParsing https://bit.ly/mips-ps1 | iex }"``` 87 | Then type ```mips``` followed by a restart to install the complete toolchain 88 | (Goto #4) 89 | 90 | # Steps for Windows natively setup (Method 1b) 91 | 92 | The methods are not mutually excluse, but these steps are necessary for a Windows only setup. 93 | 94 | ## 3. Install gcc-mipsel on Windows 95 | 96 | 3.1. Download gcc mipsel from here: 97 | (Nicolas is providing this binary, and he may release newer builds and may share them here: ) 98 | 3.2. Unzip gcc-mipsel to ```C:\g++-mipsel-none-elf-12.1.0\``` 99 | 3.3. Add ```C:\g++-mipsel-none-elf-12.1.0\bin``` to your PATH 100 | 3.4. Download gdb-multiarch from here: 101 | (Nicolas is providing this binary, and he may release newer builds and may share them here: ) 102 | 3.5. Unzip gdb-multiarch to ```C:\gdb-multiarch-12.1``` 103 | 104 | 105 | (Goto #4) 106 | 107 | # Steps for Windows with WSL (Method 2) 108 | 109 | ## 3. Install gcc-mipsel on WSL/Ubuntu 110 | 3.1. Add this plugin for visual studio: 111 | 3.2. Winkey + R and type: ```powershell start-process PowerShell -verb runas ``` 112 | 3.3. In Powershell Type: ```dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart ``` 113 | 3.4. Restart because it is Windows. 114 | 3.5. Install: 115 | 3.6. (If the Ubuntu shell has not launched automatically) Winkey + R and type: wsl 116 | 3.7. Follow the instructions to setup a username and password 117 | 3.8. When Ubuntu is ready type: 118 | ``` 119 | sudo apt-get update 120 | sudo apt-get install -y g++-mipsel-linux-gnu gdb-multiarch make gzip 121 | ``` 122 | 3.9. When above installations are done type "code ." 123 | VSCode should have launched connected to WSL 124 | (Goto #4) 125 | 126 | ## 4. Start Coding 127 | 128 | 4.1. Open PCSX-Redux 129 | 4.2. Go to the `Configuration\Emulation` menu, and turn on GDB and enable ```Enable Debugger``` and ```Enable GDB Server``` 130 | ![Redux Settings](images/Redux.png) 131 | 4.3. Open the ```get_started``` folder in Visual Studio 132 | 4.4. In the terminal type "make" 133 | 4.5. Use the debugger in Visual Studo to debug your code or just load your HelloWorld.ps-exe to run it normally. 134 | 4.6. Use the Task ```Run nops``` if you have a serial cable and unirom setup. 135 | 136 | # Note about WSL 137 | 138 | If you use WSL2 instead of WSL(1) or change other settings you make have to modify launch.json and replace ```127.0.0.1``` with your actual local IP address like ```192.168.11.1``` (of your Windows machine). 139 | 140 | I found that Windows 11 Developer Evaluation image came with WSL2, I changed the default before installing Ubuntu using: ```wsl --set-default-version 1``` 141 | 142 | Enjoy - code should halt/pause at the breakpoint, waiting for you to tell it to continue or not. 143 | -------------------------------------------------------------------------------- /get_started/.gitignore: -------------------------------------------------------------------------------- 1 | *.dep 2 | *.o 3 | *.elf 4 | *.ps-exe -------------------------------------------------------------------------------- /get_started/.vscode/.gitignore: -------------------------------------------------------------------------------- 1 | *.log -------------------------------------------------------------------------------- /get_started/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux/Windows", 5 | "includePath": [ 6 | "${workspaceFolder}/../third_party/**", 7 | "${workspaceFolder}/**" 8 | ], 9 | "defines": [], 10 | "cStandard": "c11", 11 | "cppStandard": "c++17", 12 | "configurationProvider": "ms-vscode.makefile-tools" 13 | } 14 | ], 15 | "version": 4 16 | } -------------------------------------------------------------------------------- /get_started/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | //modify the target and load lines for your elf file 3 | "version": "0.2.0", 4 | "configurations": [ 5 | { 6 | "type": "gdb", 7 | "request": "attach", 8 | "name": "(gdb) Launch GDB (Redux)", 9 | "target": "localhost:3333", 10 | "remote": true, 11 | "stopAtConnect": true, 12 | "executable": "HelloWorld.elf", 13 | "linux": { 14 | "gdbpath": "/usr/bin/gdb-multiarch", 15 | }, 16 | "windows": { 17 | "gdbpath": "C:/gdb-multiarch-12.1/bin/gdb.exe", 18 | }, 19 | "cwd": "${workspaceRoot}", 20 | "autorun": [ 21 | "set substitute-path /project .", 22 | "monitor reset shellhalt", 23 | "load ./HelloWorld.elf", 24 | "tbreak main", 25 | "continue", 26 | ], 27 | "valuesFormatting": "parseText" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /get_started/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "Run nops", 8 | "type": "shell", 9 | "windows": { 10 | // Assumes nops is on the PATH 11 | "command": "${workspaceRoot}/../nops.gdb_beta/nops.exe /fast /gdb 127.0.0.1:3333 COM14 /m", 12 | "options": { 13 | "cwd": "${workspaceFolder}" 14 | } 15 | }, 16 | "linux": { 17 | // Assumes nops is on the PATH 18 | "command": "mono ${workspaceRoot}/../nops.gdb_beta/nops.exe /fast /gdb 127.0.0.1:3333 /dev/ttyUSB0 /m", 19 | "options": { 20 | "cwd": "${workspaceFolder}" 21 | } 22 | }, 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /get_started/Makefile: -------------------------------------------------------------------------------- 1 | TARGET = HelloWorld 2 | TYPE = ps-exe 3 | 4 | SRCS = main.c \ 5 | ../third_party/common/syscalls/printf.s \ 6 | ../third_party/common/crt0/crt0.s \ 7 | 8 | CPPFLAGS += -I../third_party/common 9 | CPPFLAGS += -I../third_party/psyq/include 10 | LDFLAGS += -L../third_party/psyq/lib 11 | LDFLAGS += -Wl,--start-group 12 | LDFLAGS += -lapi 13 | LDFLAGS += -lc 14 | LDFLAGS += -lc2 15 | LDFLAGS += -lcard 16 | LDFLAGS += -lcomb 17 | LDFLAGS += -lds 18 | LDFLAGS += -letc 19 | LDFLAGS += -lgpu 20 | LDFLAGS += -lgs 21 | LDFLAGS += -lgte 22 | LDFLAGS += -lgpu 23 | LDFLAGS += -lgun 24 | LDFLAGS += -lhmd 25 | LDFLAGS += -lmath 26 | LDFLAGS += -lmcrd 27 | LDFLAGS += -lmcx 28 | LDFLAGS += -lpad 29 | LDFLAGS += -lpress 30 | LDFLAGS += -lsio 31 | LDFLAGS += -lsnd 32 | LDFLAGS += -lspu 33 | LDFLAGS += -ltap 34 | LDFLAGS += -Wl,--end-group 35 | 36 | include ../third_party/common.mk 37 | -------------------------------------------------------------------------------- /get_started/comport.txt: -------------------------------------------------------------------------------- 1 | 127.0.0.1:3333 -------------------------------------------------------------------------------- /get_started/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Really basic hello world 3 | * Thanks to much work from the authors of pcsx-redux 4 | * and the members of PSXDEV Netowork on discord 5 | * Author of this setup: NDR008 6 | */ 7 | 8 | #include 9 | 10 | int main() { 11 | printf("Hello world\n"); 12 | while (1); 13 | } 14 | -------------------------------------------------------------------------------- /images/Redux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/images/Redux.png -------------------------------------------------------------------------------- /images/downloadzip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/images/downloadzip.png -------------------------------------------------------------------------------- /images/json.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/images/json.png -------------------------------------------------------------------------------- /nops.gdb_beta/UNIROM_BOOTDISC_8.0.Kish.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/nops.gdb_beta/UNIROM_BOOTDISC_8.0.Kish.bin -------------------------------------------------------------------------------- /nops.gdb_beta/UNIROM_BOOTDISC_8.0.Kish.cue: -------------------------------------------------------------------------------- 1 | FILE "UNIROM_BOOTDISC_8.0.Kish.bin" BINARY 2 | TRACK 01 MODE2/2352 3 | INDEX 01 00:00:00 4 | -------------------------------------------------------------------------------- /nops.gdb_beta/nops.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/nops.gdb_beta/nops.exe -------------------------------------------------------------------------------- /nops.gdb_beta/unirom_b.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/nops.gdb_beta/unirom_b.exe -------------------------------------------------------------------------------- /nops.gdb_beta/unirom_datelv2_withcaetla.rom: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/nops.gdb_beta/unirom_datelv2_withcaetla.rom -------------------------------------------------------------------------------- /nops.gdb_beta/unirom_standalone.rom: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/nops.gdb_beta/unirom_standalone.rom -------------------------------------------------------------------------------- /nops.gdb_beta/unirom_withcaetla.rom: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/nops.gdb_beta/unirom_withcaetla.rom -------------------------------------------------------------------------------- /third_party/.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.elf 3 | *.map 4 | *.cpe 5 | *.ps-exe 6 | *.dep 7 | *.o 8 | *.a 9 | -------------------------------------------------------------------------------- /third_party/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 PCSX-Redux authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /third_party/README.md: -------------------------------------------------------------------------------- 1 | # GCCPsyQSetup 2 | -------------------------------------------------------------------------------- /third_party/common.mk: -------------------------------------------------------------------------------- 1 | BUILD ?= Release 2 | 3 | HAS_LINUX_MIPS_GCC = $(shell which mipsel-linux-gnu-gcc > /dev/null 2> /dev/null && echo true || echo false) 4 | 5 | ifeq ($(HAS_LINUX_MIPS_GCC),true) 6 | PREFIX ?= mipsel-linux-gnu 7 | FORMAT ?= elf32-tradlittlemips 8 | else 9 | PREFIX ?= mipsel-none-elf 10 | FORMAT ?= elf32-littlemips 11 | endif 12 | 13 | ROOTDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) 14 | 15 | CC = $(PREFIX)-gcc 16 | CXX = $(PREFIX)-g++ 17 | 18 | TYPE ?= cpe 19 | LDSCRIPT ?= $(ROOTDIR)/$(TYPE).ld 20 | ifneq ($(strip $(OVERLAYSCRIPT)),) 21 | LDSCRIPT := $(addprefix $(OVERLAYSCRIPT) , -T$(LDSCRIPT)) 22 | else 23 | LDSCRIPT := $(addprefix $(ROOTDIR)/default.ld , -T$(LDSCRIPT)) 24 | endif 25 | 26 | USE_FUNCTION_SECTIONS ?= true 27 | 28 | ARCHFLAGS = -march=mips1 -mabi=32 -EL -fno-pic -mno-shared -mno-abicalls -mfp32 29 | ARCHFLAGS += -fno-stack-protector -nostdlib -ffreestanding 30 | ifeq ($(USE_FUNCTION_SECTIONS),true) 31 | CPPFLAGS += -ffunction-sections 32 | endif 33 | CPPFLAGS += -mno-gpopt -fomit-frame-pointer 34 | CPPFLAGS += -fno-builtin -fno-strict-aliasing -Wno-attributes 35 | CPPFLAGS += $(ARCHFLAGS) 36 | CPPFLAGS += -I$(ROOTDIR) 37 | 38 | LDFLAGS += -Wl,-Map=$(BINDIR)$(TARGET).map -nostdlib -T$(LDSCRIPT) -static -Wl,--gc-sections 39 | LDFLAGS += $(ARCHFLAGS) -Wl,--oformat=$(FORMAT) 40 | 41 | CPPFLAGS_Release += -Os 42 | LDFLAGS_Release += -Os 43 | 44 | CPPFLAGS_Debug += -Og 45 | CPPFLAGS_Coverage += -Og 46 | 47 | LDFLAGS += -g 48 | CPPFLAGS += -g 49 | 50 | CPPFLAGS += $(CPPFLAGS_$(BUILD)) 51 | LDFLAGS += $(LDFLAGS_$(BUILD)) 52 | 53 | OBJS += $(addsuffix .o, $(basename $(SRCS))) 54 | 55 | all: dep $(BINDIR)$(TARGET).$(TYPE) 56 | 57 | $(BINDIR)$(TARGET).$(TYPE): $(BINDIR)$(TARGET).elf 58 | $(PREFIX)-objcopy $(addprefix -R , $(OVERLAYSECTION)) -O binary $< $@ 59 | $(foreach ovl, $(OVERLAYSECTION), $(PREFIX)-objcopy -j $(ovl) -O binary $< $(BINDIR)Overlay$(ovl);) 60 | 61 | $(BINDIR)$(TARGET).elf: $(OBJS) 62 | ifneq ($(strip $(BINDIR)),) 63 | mkdir -p $(BINDIR) 64 | endif 65 | $(CC) -g -o $(BINDIR)$(TARGET).elf $(OBJS) $(LDFLAGS) 66 | 67 | %.o: %.s 68 | $(CC) $(ARCHFLAGS) -I$(ROOTDIR) -g -c -o $@ $< 69 | 70 | %.dep: %.c 71 | $(CC) $(CPPFLAGS) $(CFLAGS) -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $< 72 | 73 | %.dep: %.cpp 74 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $< 75 | 76 | %.dep: %.cc 77 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $< 78 | 79 | # A bit broken, but that'll do in most cases. 80 | %.dep: %.s 81 | touch $@ 82 | 83 | DEPS := $(patsubst %.cpp, %.dep,$(filter %.cpp,$(SRCS))) 84 | DEPS := $(patsubst %.cc, %.dep,$(filter %.cc,$(SRCS))) 85 | DEPS += $(patsubst %.c, %.dep,$(filter %.c,$(SRCS))) 86 | DEPS += $(patsubst %.s, %.dep,$(filter %.s,$(SRCS))) 87 | 88 | dep: $(DEPS) 89 | 90 | clean: 91 | rm -f $(OBJS) $(BINDIR)Overlay.* $(BINDIR)*.elf $(BINDIR)*.ps-exe $(BINDIR)*.map $(DEPS) 92 | 93 | ifneq ($(MAKECMDGOALS), clean) 94 | ifneq ($(MAKECMDGOALS), deepclean) 95 | -include $(DEPS) 96 | endif 97 | endif 98 | 99 | .PHONY: clean dep all 100 | -------------------------------------------------------------------------------- /third_party/common/crt0/crt0.dep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/third_party/common/crt0/crt0.dep -------------------------------------------------------------------------------- /third_party/common/crt0/crt0.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/third_party/common/crt0/crt0.o -------------------------------------------------------------------------------- /third_party/common/crt0/crt0.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | .include "common/hardware/hwregs.inc" 28 | 29 | .section .start, "ax", @progbits 30 | .set noreorder 31 | .align 2 32 | .global main 33 | .global _start 34 | .type _start, @function 35 | 36 | _start: 37 | lw $t2, SBUS_DEV8_CTRL 38 | lui $t0, 8 39 | lui $t1, 1 40 | _check_dev8: 41 | bge $t2, $t0, _store_dev8 42 | nop 43 | b _check_dev8 44 | add $t2, $t1 45 | _store_dev8: 46 | sw $t2, SBUS_DEV8_CTRL 47 | 48 | la $t0, __bss_start 49 | la $t1, __bss_end 50 | 51 | beq $t0, $t1, _bss_init_skip 52 | nop 53 | 54 | _bss_init: 55 | sw $0, 0($t0) 56 | addiu $t0, 4 57 | bne $t0, $t1, _bss_init 58 | nop 59 | 60 | _bss_init_skip: 61 | 62 | la $a1, _mainargv 63 | j main 64 | li $a0, 1 65 | 66 | .section .rodata, "a", @progbits 67 | .align 2 68 | _mainargv: 69 | .word _progname 70 | .word 0 71 | _progname: 72 | .string "PSX.EXE" 73 | -------------------------------------------------------------------------------- /third_party/common/crt0/uC-sdk-crt0.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | .include "common/hardware/hwregs.inc" 28 | 29 | .section .start, "ax", @progbits 30 | .set noreorder 31 | .align 2 32 | .global _ucsdk_start 33 | .global _start 34 | .type _start, @function 35 | 36 | _start: 37 | lw $t2, SBUS_DEV8_CTRL 38 | lui $t0, 8 39 | lui $t1, 1 40 | _check_dev8: 41 | bge $t2, $t0, _store_dev8 42 | nop 43 | b _check_dev8 44 | add $t2, $t1 45 | _store_dev8: 46 | sw $t2, SBUS_DEV8_CTRL 47 | 48 | la $t0, __bss_start 49 | la $t1, __bss_end 50 | 51 | beq $t0, $t1, _bss_init_skip 52 | nop 53 | 54 | _bss_init: 55 | sw $0, 0($t0) 56 | addiu $t0, 4 57 | bne $t0, $t1, _bss_init 58 | nop 59 | 60 | _bss_init_skip: 61 | 62 | j _ucsdk_start 63 | nop 64 | -------------------------------------------------------------------------------- /third_party/common/hardware/cdrom.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "common/hardware/hwregs.h" 30 | 31 | #define CDROM_REG0 HW_U8(0x1f801800) 32 | #define CDROM_REG1 HW_U8(0x1f801801) 33 | #define CDROM_REG2 HW_U8(0x1f801802) 34 | #define CDROM_REG3 HW_U8(0x1f801803) 35 | 36 | #define CDROM_REG0_UC HW_U8(0xbf801800) 37 | #define CDROM_REG1_UC HW_U8(0xbf801801) 38 | #define CDROM_REG2_UC HW_U8(0xbf801802) 39 | #define CDROM_REG3_UC HW_U8(0xbf801803) 40 | 41 | enum { 42 | CDL_SYNC = 0, 43 | CDL_NOP = 1, 44 | CDL_SETLOC = 2, 45 | CDL_PLAY = 3, 46 | CDL_FORWARD = 4, 47 | CDL_BACKWARD = 5, 48 | CDL_READN = 6, 49 | CDL_STANDBY = 7, 50 | CDL_STOP = 8, 51 | CDL_PAUSE = 9, 52 | CDL_INIT = 10, 53 | CDL_MUTE = 11, 54 | CDL_DEMUTE = 12, 55 | CDL_SETFILTER = 13, 56 | CDL_SETMODE = 14, 57 | CDL_GETMODE = 15, 58 | CDL_GETLOCL = 16, 59 | CDL_GETLOCP = 17, 60 | CDL_READT = 18, 61 | CDL_GETTN = 19, 62 | CDL_GETTD = 20, 63 | CDL_SEEKL = 21, 64 | CDL_SEEKP = 22, 65 | CDL_SETCLOCK = 23, 66 | CDL_GETCLOCK = 24, 67 | CDL_TEST = 25, 68 | CDL_GETID = 26, 69 | CDL_READS = 27, 70 | CDL_RESET = 28, 71 | CDL_GETQ = 29, 72 | CDL_READTOC = 30, 73 | }; 74 | -------------------------------------------------------------------------------- /third_party/common/hardware/cop0.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | static __inline__ uint32_t readCOP0Status() { 32 | uint32_t ret; 33 | asm("mfc0 %0, $12\nnop\n" : "=r"(ret)); 34 | return ret; 35 | } 36 | 37 | static __inline__ void writeCOP0Status(uint32_t status) { asm("mtc0 %0, $12\nnop\n" : : "r"(status)); } 38 | -------------------------------------------------------------------------------- /third_party/common/hardware/dma.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | struct DMARegisters { 32 | volatile uintptr_t MADR; 33 | volatile uint32_t BCR, CHCR, padding; 34 | }; 35 | 36 | #define DMA_CTRL ((volatile struct DMARegisters *)0x1f801080) 37 | 38 | enum { 39 | DMA_MDECIN = 0, 40 | DMA_MDECOUT = 1, 41 | DMA_GPU = 2, 42 | DMA_CDROM = 3, 43 | DMA_SPU = 4, 44 | DMA_PIO = 5, 45 | DMA_GPUOTC = 6, 46 | }; 47 | -------------------------------------------------------------------------------- /third_party/common/hardware/gpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2021 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | #include "common/hardware/hwregs.h" 32 | 33 | enum HResolution { 34 | HR_EXTENDED, 35 | HR_256 = 0, 36 | HR_320 = 1, 37 | HR_512 = 2, 38 | HR_640 = 3, 39 | }; 40 | 41 | enum VResolution { 42 | VR_240 = 0, 43 | VR_480 = 1, 44 | }; 45 | 46 | enum VideoMode { 47 | VM_NTSC = 0, 48 | VM_PAL = 1, 49 | }; 50 | 51 | enum ColorDepth { 52 | CD_15BITS = 0, 53 | CD_24BITS = 1, 54 | }; 55 | 56 | enum VideoInterlace { 57 | VI_OFF = 0, 58 | VI_ON = 1, 59 | }; 60 | 61 | enum HResolutionExtended { 62 | HRE_NORMAL = 0, 63 | HRE_368 = 1, 64 | }; 65 | 66 | struct DisplayModeConfig { 67 | enum HResolution hResolution; 68 | enum VResolution vResolution; 69 | enum VideoMode videoMode; 70 | enum ColorDepth colorDepth; 71 | enum VideoInterlace videoInterlace; 72 | enum HResolutionExtended hResolutionExtended; 73 | }; 74 | 75 | static inline void waitGPU() { 76 | while ((GPU_STATUS & 0x04000000) == 0) 77 | ; 78 | } 79 | 80 | static inline void sendGPUData(uint32_t data) { 81 | waitGPU(); 82 | GPU_DATA = data; 83 | } 84 | 85 | static inline void sendGPUStatus(uint32_t status) { GPU_STATUS = status; } 86 | 87 | static inline uint32_t generateDisableDisplay() { return 0x03000001; } 88 | static inline uint32_t generateEnableDisplay() { return 0x03000000; } 89 | static inline void disableDisplay() { sendGPUStatus(generateDisableDisplay()); } 90 | static inline void enableDisplay() { sendGPUStatus(generateEnableDisplay()); } 91 | 92 | static inline uint32_t generateDisplayMode(const struct DisplayModeConfig* config) { 93 | return 0x08000000 | (config->hResolution << 0) | (config->vResolution << 2) | (config->videoMode << 3) | 94 | (config->colorDepth << 4) | (config->videoInterlace << 5) | (config->hResolutionExtended << 6); 95 | } 96 | 97 | static inline void setDisplayMode(const struct DisplayModeConfig* config) { 98 | sendGPUStatus(generateDisplayMode(config)); 99 | } 100 | 101 | static inline uint32_t generateDisplayArea(int16_t x, int16_t y) { return 0x05000000 | x | (y << 10); } 102 | static inline void setDisplayArea(int16_t x, int16_t y) { sendGPUStatus(generateDisplayArea(x, y)); } 103 | 104 | static inline uint32_t generateHorizontalRange(int16_t x1, int16_t x2) { 105 | return 0x06000000 | (x1 + 0x260) | ((x1 + x2 + 0x260) << 12); 106 | } 107 | static inline void setHorizontalRange(int16_t x1, int16_t x2) { sendGPUStatus(generateHorizontalRange(x1, x2)); } 108 | 109 | static inline uint32_t generateVerticalRange(int16_t y1, int16_t y2) { return 0x07000000 | y1 | (y2 << 10); } 110 | static inline void setVerticalRange(int16_t y1, int16_t y2) { sendGPUStatus(generateVerticalRange(y1, y2)); } 111 | 112 | union Color { 113 | struct { 114 | uint8_t r, g, b; 115 | }; 116 | uint32_t packed; 117 | }; 118 | 119 | struct FastFill { 120 | union Color c; 121 | int16_t x, y, w, h; 122 | }; 123 | 124 | static inline void fastFill(const struct FastFill* ff) { 125 | waitGPU(); 126 | GPU_DATA = 0x02000000 | ff->c.r | ff->c.g << 8 | ff->c.b << 16; 127 | GPU_DATA = ff->x | ff->y << 16; 128 | GPU_DATA = ff->w | ff->h << 16; 129 | } 130 | 131 | static inline uint32_t generateDrawingAreaStart(int16_t x, int16_t y) { return 0xe3000000 | x | y << 10; } 132 | static inline uint32_t generateDrawingAreaEnd(int16_t x, int16_t y) { return 0xe4000000 | (x - 1) | (y - 1) << 10; } 133 | static inline void setDrawingArea(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { 134 | sendGPUData(generateDrawingAreaStart(x1, y1)); 135 | sendGPUData(generateDrawingAreaEnd(x2, y2)); 136 | } 137 | 138 | static inline uint32_t generateDrawingOffset(int16_t x, int16_t y) { return 0xe5000000 | x | y << 11; } 139 | static inline void setDrawingOffset(int16_t x, int16_t y) { sendGPUData(generateDrawingOffset(x, y)); } 140 | 141 | enum Shading { 142 | S_FLAT = 0, 143 | S_GOURAUD = 1, 144 | }; 145 | 146 | enum VerticesCount { 147 | VC_3 = 0, 148 | VC_4 = 1, 149 | }; 150 | 151 | enum Textured { 152 | TEX_ON = 1, 153 | TEX_OFF = 0, 154 | }; 155 | 156 | enum Transparency { 157 | TRANS_ON = 1, 158 | TRANS_OFF = 0, 159 | }; 160 | 161 | enum Blending { 162 | BLEND_ON = 1, 163 | BLEND_OFF = 0, 164 | }; 165 | 166 | struct GPUPolygonCommand { 167 | enum Shading shading; 168 | enum VerticesCount verticesCount; 169 | enum Textured textured; 170 | enum Transparency transparency; 171 | enum Blending blending; 172 | union Color color; 173 | }; 174 | 175 | static inline uint32_t generatePolygonCommand(const struct GPUPolygonCommand* c) { 176 | return 0x20000000 | c->shading << 28 | c->verticesCount << 27 | c->textured << 26 | c->transparency << 25 | 177 | c->blending << 24 | c->color.b << 16 | c->color.g << 8 | c->color.r; 178 | } 179 | static inline void startPolygonCommand(const struct GPUPolygonCommand* c) { sendGPUData(generatePolygonCommand(c)); } 180 | 181 | enum LineStyle { 182 | POLY_OFF = 0, 183 | POLY_ON = 1, 184 | }; 185 | 186 | struct GPULineCommand { 187 | enum Shading shading; 188 | enum LineStyle lineStyle; 189 | enum Transparency transparency; 190 | union Color color; 191 | }; 192 | 193 | static inline uint32_t generateLineCommand(const struct GPULineCommand* c) { 194 | return 0x40000000 | c->shading << 28 | c->lineStyle << 27 | c->transparency << 25 | c->color.b << 16 | 195 | c->color.g << 8 | c->color.r; 196 | } 197 | static inline void startLineCommand(const struct GPULineCommand* c) { sendGPUData(generateLineCommand(c)); } 198 | 199 | static inline uint32_t generateFlushGPUCache() { return 0x01000000; } 200 | static inline void flushGPUCache() { sendGPUData(generateFlushGPUCache()); } 201 | -------------------------------------------------------------------------------- /third_party/common/hardware/hwregs.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | struct Counter { 32 | uint16_t value; 33 | uint16_t padding1; 34 | uint16_t mode; 35 | uint16_t padding2; 36 | uint16_t target; 37 | uint8_t padding[6]; 38 | }; 39 | 40 | struct SIO { 41 | uint8_t fifo; 42 | uint8_t preview[3]; 43 | uint16_t stat; 44 | uint16_t padding; 45 | uint16_t mode; 46 | uint16_t ctrl; 47 | uint16_t reserved; 48 | uint16_t baudRate; 49 | }; 50 | 51 | #define HW_U8(x) (*(volatile uint8_t *)(x)) 52 | #define HW_U16(x) (*(volatile uint16_t *)(x)) 53 | #define HW_U32(x) (*(volatile uint32_t *)(x)) 54 | #define HW_S8(x) (*(volatile int8_t *)(x)) 55 | #define HW_S16(x) (*(volatile int16_t *)(x)) 56 | #define HW_S32(x) (*(volatile int32_t *)(x)) 57 | 58 | #define SBUS_DEV4_CTRL HW_U32(0x1f801014) 59 | #define SBUS_DEV5_CTRL HW_U32(0x1f801018) 60 | #define SBUS_COM_CTRL HW_U32(0x1f801020) 61 | 62 | #define SIOS ((volatile struct SIO *)0x1f801040) 63 | 64 | #define RAM_SIZE HW_U32(0x1f801060) 65 | 66 | #define IREG HW_U32(0xbf801070) 67 | #define IMASK HW_U32(0xbf801074) 68 | 69 | #define DPCR HW_U32(0x1f8010f0) 70 | #define DICR HW_U32(0x1f8010f4) 71 | 72 | #define COUNTERS ((volatile struct Counter *)0xbf801100) 73 | 74 | #define GPU_DATA HW_U32(0x1f801810) 75 | #define GPU_STATUS HW_U32(0x1f801814) 76 | 77 | #define ATCONS_STAT HW_U8(0x1f802000) 78 | #define ATCONS_FIFO HW_U8(0x1f802002) 79 | #define ATCONS_IRQ HW_U8(0x1f802030) 80 | #define ATCONS_IRQ2 HW_U8(0x1f802032) 81 | 82 | #define POST HW_U8(0xbf802041) 83 | -------------------------------------------------------------------------------- /third_party/common/hardware/hwregs.inc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | .set SBUS_DEV0_ADDR, 0x1f801000 28 | .set SBUS_DEV8_ADDR, 0x1f801004 29 | 30 | .set SBUS_DEV0_CTRL, 0x1f801008 31 | .set SBUS_DEV1_CTRL, 0x1f80100C 32 | .set SBUS_DEV2_CTRL, 0x1f801010 33 | .set SBUS_DEV4_CTRL, 0x1f801014 34 | .set SBUS_DEV5_CTRL, 0x1f801018 35 | .set SBUS_DEV8_CTRL, 0x1f80101C 36 | 37 | .set SBUS_COM_CTRL, 0x1f801020 38 | 39 | .set RAM_SIZE, 0x1f801060 40 | 41 | .set BIU_CONFIG, 0xfffe0130 42 | -------------------------------------------------------------------------------- /third_party/common/hardware/irq.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | enum IRQ { 32 | IRQ_VBLANK = 1 << 0, 33 | IRQ_GPU = 1 << 1, 34 | IRQ_CDROM = 1 << 2, 35 | IRQ_DMA = 1 << 3, 36 | IRQ_TIMER0 = 1 << 4, 37 | IRQ_TIMER1 = 1 << 5, 38 | IRQ_TIMER2 = 1 << 6, 39 | IRQ_CONTROLLER = 1 << 7, 40 | IRQ_SIO = 1 << 8, 41 | IRQ_SPU = 1 << 9, 42 | IRQ_PIO = 1 << 10, 43 | }; 44 | -------------------------------------------------------------------------------- /third_party/common/hardware/pcsxhw.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | static __inline__ void pcsx_putc(int c) { *((volatile char* const)0x1f802080) = c; } 32 | static __inline__ void pcsx_debugbreak() { *((volatile char* const)0x1f802081) = 0; } 33 | static __inline__ void pcsx_exit(int code) { *((volatile int16_t* const)0x1f802082) = code; } 34 | static __inline__ void pcsx_message(const char* msg) { *((volatile const char** const)0x1f802084) = msg; } 35 | 36 | static __inline__ int pcsx_present() { return *((volatile uint32_t* const)0x1f802080) == 0x58534350; } 37 | -------------------------------------------------------------------------------- /third_party/common/hardware/sio1.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #include "common/hardware/sio1.h" 28 | 29 | #include "common/hardware/hwregs.h" 30 | 31 | void sio1_init() { 32 | // enable TX and RX, and nothing else 33 | SIO1_CTRL = 5; 34 | // 01001110 35 | // Baudrate Reload Factor: MUL16 (2) 36 | // Character length: 8 (3) 37 | // Parity Disabled 38 | // Parity Type: irrelevant 39 | // Stop bit length: 1 (1) 40 | // --> 8N1 41 | SIO1_MODE = 0x4e; 42 | SIO1_BAUD = 2073600 / 115200; 43 | } 44 | 45 | void sio1_putc(uint8_t byte) { 46 | while ((SIO1_STAT & 1) == 0) 47 | ; 48 | SIO1_DATA = byte; 49 | } 50 | -------------------------------------------------------------------------------- /third_party/common/hardware/sio1.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | #include "common/hardware/hwregs.h" 32 | 33 | #define SIO1_DATA HW_U8(0x1f801050) 34 | #define SIO1_STAT HW_U16(0x1f801054) 35 | #define SIO1_MODE HW_U16(0x1f801058) 36 | #define SIO1_CTRL HW_U16(0x1f80105a) 37 | #define SIO1_BAUD HW_U16(0x1f80105e) 38 | 39 | void sio1_init(); 40 | void sio1_putc(uint8_t byte); 41 | -------------------------------------------------------------------------------- /third_party/common/hardware/spu.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "hwregs.h" 30 | 31 | struct SPUVoice { 32 | uint16_t volumeLeft; 33 | uint16_t volumeRight; 34 | uint16_t sampleRate; 35 | uint16_t sampleStartAddr; 36 | uint16_t ad; 37 | uint16_t sr; 38 | uint16_t currentVolume; 39 | uint16_t sampleRepeatAddr; 40 | }; 41 | 42 | #define SPU_VOICES ((volatile struct SPUVoice *)0x1f801c00) 43 | 44 | #define SPU_VOL_MAIN_LEFT HW_U16(0x1f801d80) 45 | #define SPU_VOL_MAIN_RIGHT HW_U16(0x1f801d82) 46 | #define SPU_REVERB_LEFT HW_U16(0x1f801d84) 47 | #define SPU_REVERB_RIGHT HW_U16(0x1f801d86) 48 | #define SPU_KEY_ON_LOW HW_U16(0x1f801d88) 49 | #define SPU_KEY_ON_HIGH HW_U16(0x1f801d8a) 50 | #define SPU_KEY_OFF_LOW HW_U16(0x1f801d8c) 51 | #define SPU_KEY_OFF_HIGH HW_U16(0x1f801d8e) 52 | #define SPU_PITCH_MOD_LOW HW_U16(0x1f801d90) 53 | #define SPU_PITCH_MOD_HIGH HW_U16(0x1f801d92) 54 | #define SPU_NOISE_EN_LOW HW_U16(0x1f801d94) 55 | #define SPU_NOISE_EN_HIGH HW_U16(0x1f801d96) 56 | #define SPU_REVERB_EN_LOW HW_U16(0x1f801d98) 57 | #define SPU_REVERB_EN_HIGH HW_U16(0x1f801d9a) 58 | 59 | #define SPU_RAM_DTA HW_U16(0x1f801da6) 60 | #define SPU_CTRL HW_U16(0x1f801daa) 61 | #define SPU_RAM_DTC HW_U16(0x1f801dac) 62 | #define SPU_STATUS HW_U16(0x1f801dae) 63 | #define SPU_VOL_CD_LEFT HW_U16(0x1f801db0) 64 | #define SPU_VOL_CD_RIGHT HW_U16(0x1f801db2) 65 | #define SPU_VOL_EXT_LEFT HW_U16(0x1f801db4) 66 | #define SPU_VOL_EXT_RIGHT HW_U16(0x1f801db6) 67 | 68 | static __inline__ void muteSpu() { 69 | SPU_REVERB_RIGHT = 0; 70 | SPU_REVERB_LEFT = 0; 71 | SPU_VOL_MAIN_RIGHT = 0; 72 | SPU_VOL_MAIN_LEFT = 0; 73 | } 74 | -------------------------------------------------------------------------------- /third_party/common/hardware/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | static void __inline__ flushWriteQueue() { *((volatile uint8_t *)0xbfc00000); } 30 | -------------------------------------------------------------------------------- /third_party/common/kernel/events.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | enum event_class { 30 | EVENT_VBLANK = 0xf0000001, // IRQ0 31 | EVENT_GPU = 0xf0000002, // IRQ1 32 | EVENT_CDROM = 0xf0000003, // IRQ2 33 | EVENT_DMA = 0xf0000004, // IRQ3 34 | EVENT_RTC0 = 0xf0000005, // IRQ4 - Timer 0 35 | EVENT_RTC1 = 0xf0000006, // IRQ5 - Timer 1 or 2 36 | // 0xf0000007 - unused, should be Timer 2 37 | EVENT_CONTROLLER = 0xf0000008, // IRQ7 38 | EVENT_SPU = 0xf0000009, // IRQ9 39 | EVENT_PIO = 0xf000000a, // IRQ10 40 | EVENT_SIO = 0xf000000b, // IRQ8 41 | EVENT_CARD = 0xf0000011, 42 | EVENT_BU = 0xf4000001, 43 | }; 44 | 45 | enum event_mode { 46 | EVENT_MODE_CALLBACK = 0x1000, 47 | EVENT_MODE_NO_CALLBACK = 0x2000, 48 | }; 49 | 50 | enum event_flag { 51 | EVENT_FLAG_FREE = 0x0000, 52 | EVENT_FLAG_DISABLED = 0x1000, 53 | EVENT_FLAG_ENABLED = 0x2000, 54 | EVENT_FLAG_PENDING = 0x4000, 55 | }; 56 | -------------------------------------------------------------------------------- /third_party/common/kernel/openbios.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2021 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | // https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-18048.html 32 | struct BuildId { 33 | uint32_t namesz; 34 | uint32_t descsz; 35 | uint32_t type; 36 | uint8_t strings[]; 37 | }; 38 | 39 | static inline int isOpenBiosPresent() { 40 | uintptr_t* a0table = (uintptr_t*)0x200; 41 | return (a0table[11] & 3) == 1; 42 | } 43 | 44 | static inline uint32_t getOpenBiosApiVersion() { 45 | if (!isOpenBiosPresent()) return 0; 46 | register int n asm("t1") = 0x00; 47 | __asm__ volatile("" : "=r"(n) : "r"(n)); 48 | uintptr_t* a0table = (uintptr_t*)0x200; 49 | return ((uint32_t(*)())(a0table[11] ^ 1))(); 50 | } 51 | 52 | static inline struct BuildId* getOpenBiosBuildId() { 53 | if (!isOpenBiosPresent()) return 0; 54 | register int n asm("t1") = 0x01; 55 | __asm__ volatile("" : "=r"(n) : "r"(n)); 56 | uintptr_t* a0table = (uintptr_t*)0x200; 57 | return ((struct BuildId * (*)())(a0table[11] ^ 1))(); 58 | } 59 | -------------------------------------------------------------------------------- /third_party/common/kernel/pcdrv.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2021 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | // This is a reverse of the libsn pcdrv API. It doesn't make a lot of sense. 30 | 31 | static inline int PCinit() { 32 | register int r asm("v0"); 33 | __asm__ volatile("break 0, 0x101\n" : "=r"(r)); 34 | return r; 35 | } 36 | 37 | static inline int PCcreat(const char *name, int perms) { 38 | register const char *a0 asm("a0") = name; 39 | register const char *a1 asm("a1") = name; 40 | register int a2 asm("a2") = 0; 41 | register int v0 asm("v0"); 42 | register int v1 asm("v1"); 43 | __asm__ volatile("break 0, 0x102\n" : "=r"(v0), "=r"(v1) : "r"(a0), "r"(a1), "r"(a2)); 44 | if (v0 == 0) return v1; 45 | return -1; 46 | } 47 | 48 | static inline int PCopen(char *name, int flags, int perms) { 49 | register int a2 asm("a2") = flags; 50 | register const char *a0 asm("a0") = name; 51 | register const char *a1 asm("a1") = name; 52 | register int v0 asm("v0"); 53 | register int v1 asm("v1"); 54 | __asm__ volatile("break 0, 0x103\n" : "=r"(v0), "=r"(v1) : "r"(a0), "r"(a1), "r"(a2)); 55 | if (v0 == 0) return v1; 56 | return -1; 57 | } 58 | 59 | static inline int PCclose(int fd) { 60 | register int a0 asm("a0") = fd; 61 | register int a1 asm("a1") = fd; 62 | register int v0 asm("v0"); 63 | __asm__ volatile("break 0, 0x104\n" : "=r"(v0) : "r"(a0), "r"(a1) : "v1"); 64 | return v0; 65 | } 66 | 67 | static inline int PCread(int fd, void *buf, int len) { 68 | register int a0 asm("a0") = 0; 69 | register int a1 asm("a1") = fd; 70 | register int a2 asm("a2") = len; 71 | register void *a3 asm("a3") = buf; 72 | register int v0 asm("v0"); 73 | register int v1 asm("v1"); 74 | __asm__ volatile("break 0, 0x105\n" : "=r"(v0), "=r"(v1) : "r"(a0), "r"(a1), "r"(a2), "r"(a3) : "memory"); 75 | if (v0 == 0) return v1; 76 | return -1; 77 | } 78 | 79 | static inline int PCwrite(int fd, const void *buf, int len) { 80 | register int a0 asm("a0") = 0; 81 | register int a1 asm("a1") = fd; 82 | register int a2 asm("a2") = len; 83 | register const void *a3 asm("a3") = buf; 84 | register int v0 asm("v0"); 85 | register int v1 asm("v1"); 86 | __asm__ volatile("break 0, 0x106\n" : "=r"(v0), "=r"(v1) : "r"(a0), "r"(a1), "r"(a2), "r"(a3)); 87 | if (v0 == 0) return v1; 88 | return -1; 89 | } 90 | 91 | static inline int PClseek(int fd, int offset, int wheel) { 92 | register int a3 asm("a3") = wheel; 93 | register int a2 asm("a2") = offset; 94 | register int a0 asm("a0") = fd; 95 | register int a1 asm("a1") = fd; 96 | register int v0 asm("v0"); 97 | register int v1 asm("v1"); 98 | __asm__ volatile("break 0, 0x107\n" : "=r"(v0), "=r"(v1) : "r"(a0), "r"(a1), "r"(a2), "r"(a3)); 99 | if (v0 == 0) return v1; 100 | return -1; 101 | } 102 | -------------------------------------------------------------------------------- /third_party/common/psxlibc/circularbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | enum { 32 | PSXCIRC_RAW = 1, 33 | PSXCIRC_STOPPED = 2, 34 | PSXCIRC_BREAK = 4, 35 | }; 36 | 37 | struct CircularBuffer { 38 | uint32_t flags; 39 | uint8_t *start, *end; 40 | uint8_t buffer[256]; 41 | }; 42 | -------------------------------------------------------------------------------- /third_party/common/psxlibc/device.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | #include "common/psxlibc/stdio.h" 32 | 33 | struct File; 34 | 35 | enum FileAction { 36 | PSXREAD = 1, 37 | PSXWRITE = 2, 38 | }; 39 | 40 | enum { 41 | PSXDTTYPE_CHAR = 0x01, 42 | PSXDTTYPE_CONS = 0x02, 43 | PSXDTTYPE_BLOCK = 0x04, 44 | PSXDTTYPE_RAW = 0x08, 45 | PSXDTTYPE_FS = 0x10, 46 | }; 47 | 48 | typedef void (*device_init)(); 49 | typedef int (*device_open)(struct File *, const char *filename, int mode); 50 | typedef int (*device_action)(struct File *, enum FileAction); 51 | typedef int (*device_close)(struct File *); 52 | typedef int (*device_ioctl)(struct File *, int cmd, int arg); 53 | typedef int (*device_read)(struct File *, void *buffer, int size); 54 | typedef int (*device_write)(struct File *, void *buffer, int size); 55 | typedef struct DirEntry *(*device_firstFile)(struct File *file, const char *filename, struct DirEntry *entry); 56 | typedef struct DirEntry *(*device_nextFile)(struct File *file, struct DirEntry *entry); 57 | typedef int (*device_format)(struct File *file); 58 | typedef void (*device_deinit)(); 59 | 60 | struct Device { 61 | const char *name; 62 | uint32_t flags /* PSXDTTYPE_* */; 63 | uint32_t blockSize; 64 | const char *desc; 65 | device_init init; 66 | device_open open; 67 | device_action action; 68 | device_close close; 69 | device_ioctl ioctl; 70 | device_read read; 71 | device_write write; 72 | void *erase, *undelete; 73 | device_firstFile firstFile; 74 | device_nextFile nextFile; 75 | device_format format; 76 | void *chdir, *rename; 77 | device_deinit deinit; 78 | void *check; 79 | }; 80 | -------------------------------------------------------------------------------- /third_party/common/psxlibc/direntry.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | struct DirEntry; 32 | 33 | struct DirEntry { 34 | char name[20]; 35 | uint32_t attributes; 36 | uint32_t size; 37 | struct DirEntry* next; 38 | uint32_t LBA; 39 | char fourcc[4]; 40 | }; 41 | -------------------------------------------------------------------------------- /third_party/common/psxlibc/fastmemset.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | .section .ramtext, "ax", @progbits 28 | .align 2 29 | .global fastMemset 30 | .type fastMemset, @function 31 | .set noreorder 32 | 33 | /* void * fastMemset(void * ptr, int value, size_t num); */ 34 | /* http://man7.org/linux/man-pages/man3/memset.3.html */ 35 | 36 | fastMemset: 37 | beqz $a2, out 38 | move $v0, $a0 39 | 40 | sltiu $v1, $a2, 32 41 | beqz $v1, large_enough 42 | move $t0, $a1 43 | 44 | addu $a2, $a0 45 | addiu $a2, -1 46 | small_memset_loop: 47 | sb $a1, 0($a0) 48 | bne $a0, $a2, small_memset_loop 49 | addiu $a0, 1 50 | jr $ra 51 | 52 | large_enough: 53 | sll $t0, 8 54 | or $t0, $a1 55 | move $a1, $t0 56 | sll $t0, 16 57 | or $a1, $t0 58 | 59 | andi $v1, $a0, 3 60 | la $t1, jumptable1 61 | sll $t2, $v1, 2 62 | subu $a2, $v1 63 | addu $t2, $t1 64 | lw $t1, 0($t2) 65 | srl $t0, $a2, 8 66 | jr $t1 67 | andi $t1, $a2, 0xff 68 | 69 | jumptable1: 70 | .word sb0 71 | .word sb3 72 | .word sb2 73 | .word sb1 74 | 75 | sb3: 76 | sb $a1, 0($a0) 77 | addiu $a0, 1 78 | sb2: 79 | sb $a1, 0($a0) 80 | addiu $a0, 1 81 | sb1: 82 | sb $a1, 0($a0) 83 | addiu $a0, 1 84 | sb0: 85 | 86 | /* At this point, we have: 87 | v0 - our return value 88 | a0 - current, aligned pointer 89 | a1 - our word to store 90 | t0 - our big loop counter 91 | t1 - the remainder counter to store 92 | */ 93 | 94 | beqz $t0, skip_big_loop 95 | 96 | big_loop: 97 | addiu $t0, -1 98 | sw $a1, 0x0000($a0) 99 | sw $a1, 0x0004($a0) 100 | sw $a1, 0x0008($a0) 101 | sw $a1, 0x000c($a0) 102 | sw $a1, 0x0010($a0) 103 | sw $a1, 0x0014($a0) 104 | sw $a1, 0x0018($a0) 105 | sw $a1, 0x001c($a0) 106 | sw $a1, 0x0020($a0) 107 | sw $a1, 0x0024($a0) 108 | sw $a1, 0x0028($a0) 109 | sw $a1, 0x002c($a0) 110 | sw $a1, 0x0030($a0) 111 | sw $a1, 0x0034($a0) 112 | sw $a1, 0x0038($a0) 113 | sw $a1, 0x003c($a0) 114 | sw $a1, 0x0040($a0) 115 | sw $a1, 0x0044($a0) 116 | sw $a1, 0x0048($a0) 117 | sw $a1, 0x004c($a0) 118 | sw $a1, 0x0050($a0) 119 | sw $a1, 0x0054($a0) 120 | sw $a1, 0x0058($a0) 121 | sw $a1, 0x005c($a0) 122 | sw $a1, 0x0060($a0) 123 | sw $a1, 0x0064($a0) 124 | sw $a1, 0x0068($a0) 125 | sw $a1, 0x006c($a0) 126 | sw $a1, 0x0070($a0) 127 | sw $a1, 0x0074($a0) 128 | sw $a1, 0x0078($a0) 129 | sw $a1, 0x007c($a0) 130 | sw $a1, 0x0080($a0) 131 | sw $a1, 0x0084($a0) 132 | sw $a1, 0x0088($a0) 133 | sw $a1, 0x008c($a0) 134 | sw $a1, 0x0090($a0) 135 | sw $a1, 0x0094($a0) 136 | sw $a1, 0x0098($a0) 137 | sw $a1, 0x009c($a0) 138 | sw $a1, 0x00a0($a0) 139 | sw $a1, 0x00a4($a0) 140 | sw $a1, 0x00a8($a0) 141 | sw $a1, 0x00ac($a0) 142 | sw $a1, 0x00b0($a0) 143 | sw $a1, 0x00b4($a0) 144 | sw $a1, 0x00b8($a0) 145 | sw $a1, 0x00bc($a0) 146 | sw $a1, 0x00c0($a0) 147 | sw $a1, 0x00c4($a0) 148 | sw $a1, 0x00c8($a0) 149 | sw $a1, 0x00cc($a0) 150 | sw $a1, 0x00d0($a0) 151 | sw $a1, 0x00d4($a0) 152 | sw $a1, 0x00d8($a0) 153 | sw $a1, 0x00dc($a0) 154 | sw $a1, 0x00e0($a0) 155 | sw $a1, 0x00e4($a0) 156 | sw $a1, 0x00e8($a0) 157 | sw $a1, 0x00ec($a0) 158 | sw $a1, 0x00f0($a0) 159 | sw $a1, 0x00f4($a0) 160 | sw $a1, 0x00f8($a0) 161 | sw $a1, 0x00fc($a0) 162 | bnez $t0, big_loop 163 | addiu $a0, 0x0100 164 | 165 | skip_big_loop: 166 | beqz $t1, out 167 | 168 | addu $a2, $t1, $a0 169 | b small_memset_loop 170 | addiu $a2, -1 171 | 172 | out: 173 | jr $ra 174 | nop 175 | -------------------------------------------------------------------------------- /third_party/common/psxlibc/handlers.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | struct HandlerInfo; 32 | 33 | struct HandlerInfo { 34 | struct HandlerInfo* next; 35 | void (*handler)(int); 36 | int (*verifier)(); 37 | uint32_t padding; 38 | }; 39 | 40 | struct HandlersStorage { 41 | struct HandlerInfo* first; 42 | uint32_t padding; 43 | }; 44 | -------------------------------------------------------------------------------- /third_party/common/psxlibc/ioctl.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #define MAKEIOCTL(c, s) ((c << 8 | s)) 30 | 31 | #define PSXFIOCNBLOCK MAKEIOCTL('f', 1) 32 | #define PSXFIOCSCAN MAKEIOCTL('f', 2) 33 | 34 | #define PSXTIOCRAW MAKEIOCTL('t', 1) 35 | #define PSXTIOCFLUSH MAKEIOCTL('t', 2) 36 | #define PSXTIOCREOPEN MAKEIOCTL('t', 3) 37 | #define PSXTIOCBAUD MAKEIOCTL('t', 4) 38 | #define PSXTIOCEXIT MAKEIOCTL('t', 5) 39 | #define PSXTIOCDTR MAKEIOCTL('t', 6) 40 | #define PSXTIOCRTS MAKEIOCTL('t', 7) 41 | #define PSXTIOCLEN MAKEIOCTL('t', 8) 42 | #define PSXTIOCPARITY MAKEIOCTL('t', 9) 43 | #define PSXTIOSTATUS MAKEIOCTL('t', 10) 44 | #define PSXTIOERRRST MAKEIOCTL('t', 11) 45 | #define PSXTIOEXIST MAKEIOCTL('t', 12) 46 | #define PSXTIORLEN MAKEIOCTL('t', 13) 47 | 48 | #define PSXDIOFORMAT MAKEIOCTL('d', 1) 49 | -------------------------------------------------------------------------------- /third_party/common/psxlibc/psxexe.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | struct psxExeHeader { 32 | uint32_t pc; 33 | uint32_t gp; 34 | uint32_t text_addr; 35 | uint32_t text_size; 36 | uint32_t data_addr; 37 | uint32_t data_size; 38 | uint32_t bss_addr; 39 | uint32_t bss_size; 40 | uint32_t stack_start; 41 | uint32_t stack_size; 42 | uint32_t savedSP; 43 | uint32_t savedS8; 44 | uint32_t savedGP; 45 | uint32_t savedRA; 46 | uint32_t savedS0; 47 | uint32_t unknown; 48 | }; 49 | -------------------------------------------------------------------------------- /third_party/common/psxlibc/setjmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | struct JmpBuf { 32 | uint32_t ra, sp, s8, s0, s1, s2, s3, s4, s5, s6, s7, gp; 33 | }; 34 | -------------------------------------------------------------------------------- /third_party/common/psxlibc/stdio.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | #include "common/psxlibc/device.h" 32 | 33 | enum { 34 | PSXENOERR, 35 | PSXEPERM, 36 | PSXENOENT, 37 | PSXESRCH, 38 | PSXEINTR, 39 | PSXEIO, 40 | PSXENXIO, 41 | PSXE2BIG, 42 | PSXENOEXEC, 43 | PSXEBADF, 44 | PSXECHILD, 45 | PSXEAGAIN, 46 | PSXENOMEM, 47 | PSXEACCESS, 48 | PSXEFAULT, 49 | PSXENOTBLK, 50 | PSXEBUSY, 51 | PSXEEXIST, 52 | PSXEXDEV, 53 | PSXENODEV, 54 | PSXENOTDIR, 55 | PSXEISDIR, 56 | PSXEINVAL, 57 | PSXENFILE, 58 | PSXEMFILE, 59 | PSXENOTTY, 60 | PSXETXTBSY, 61 | PSXEFBIG, 62 | PSXENOSPC, 63 | PSXESPIPE, 64 | PSXEROFS, 65 | PSXEFORMAT, 66 | PSXEPIPE, 67 | PSXEDOM, 68 | PSXERANGE, 69 | PSXEWOULDBLOCK, 70 | PSXEINPROGRESS, 71 | PSXEALREADY, 72 | }; 73 | 74 | enum { 75 | PSXF_READ = 0x0001, 76 | PSXF_WRITE = 0x0002, 77 | PSXF_NBLOCK = 0x0004, 78 | PSXF_SCAN = 0x0008, 79 | PSXF_RLOCK = 0x0010, 80 | PSXF_WLOCK = 0x0020, 81 | PSXF_APPEND = 0x0100, 82 | PSXF_CREAT = 0x0200, 83 | PSXF_TRUNC = 0x0400, 84 | PSXF_SCAN2 = 0x1000, 85 | PSXF_RCOM = 0x2000, 86 | PSXF_NBUF = 0x4000, 87 | PSXF_ASYNC = 0x8000, 88 | }; 89 | 90 | enum { 91 | PSXSEEK_SET = 0, 92 | PSXSEEK_CUR = 1, 93 | PSXSEEK_END = 2, 94 | }; 95 | 96 | struct File { 97 | uint32_t flags /* PSXF_* */, deviceId; 98 | char* buffer; 99 | uint32_t count, offset, deviceFlags, errno; 100 | struct Device* device; 101 | uint32_t length, LBA, fd; 102 | }; 103 | -------------------------------------------------------------------------------- /third_party/common/psxlibc/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include 31 | 32 | static __attribute__((always_inline)) uint8_t* safeMemZero(uint8_t* ptr, int size) { 33 | if (!ptr || size <= 0) return NULL; 34 | uint8_t* orig = ptr; 35 | for (; size >= 0; ptr++) { 36 | size--; 37 | *ptr = 0; 38 | } 39 | return orig; 40 | } 41 | -------------------------------------------------------------------------------- /third_party/common/syscalls/printf.dep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/third_party/common/syscalls/printf.dep -------------------------------------------------------------------------------- /third_party/common/syscalls/printf.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NDR008/VSCodePSX/8df1214cf0cd19f73796a369637a8dd9da3f1598/third_party/common/syscalls/printf.o -------------------------------------------------------------------------------- /third_party/common/syscalls/printf.s: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | .set push 28 | .set noreorder 29 | .section .ramtext, "ax", @progbits 30 | .align 2 31 | .global ramsyscall_printf 32 | .type ramsyscall_printf, @function 33 | 34 | ramsyscall_printf: 35 | li $t2, 0xa0 36 | jr $t2 37 | li $t1, 0x3f 38 | -------------------------------------------------------------------------------- /third_party/common/syscalls/syscalls.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2020 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "common/psxlibc/circularbuffer.h" 34 | #include "common/psxlibc/device.h" 35 | #include "common/psxlibc/handlers.h" 36 | 37 | struct JmpBuf; 38 | 39 | static __attribute__((always_inline)) int enterCriticalSection() { 40 | register int n asm("a0") = 1; 41 | register int r asm("v0"); 42 | __asm__ volatile("syscall\n" 43 | : "=r"(n), "=r"(r) 44 | : "r"(n) 45 | : "at", "v1", "a1", "a2", "a3", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", 46 | "memory"); 47 | return r; 48 | } 49 | 50 | static __attribute__((always_inline)) void leaveCriticalSection() { 51 | register int n asm("a0") = 2; 52 | __asm__ volatile("syscall\n" 53 | : "=r"(n) 54 | : "r"(n) 55 | : "at", "v0", "v1", "a1", "a2", "a3", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", 56 | "memory"); 57 | } 58 | 59 | static __attribute__((always_inline)) int changeThreadSubFunction(uint32_t address) { 60 | register int n asm("a0") = 3; 61 | register int tcb asm("a1") = address; 62 | register int r asm("v0"); 63 | __asm__ volatile("syscall\n" 64 | : "=r"(r), "=r"(n), "=r"(tcb) 65 | : "r"(n), "r"(tcb) 66 | : "at", "v1", "a2", "a3", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9", "memory"); 67 | return r; 68 | } 69 | 70 | /* A0 table */ 71 | static __attribute__((always_inline)) int syscall_setjmp(struct JmpBuf *buf) { 72 | register int n asm("t1") = 0x13; 73 | __asm__ volatile("" : "=r"(n) : "r"(n)); 74 | return ((int (*)(struct JmpBuf * buf))0xa0)(buf); 75 | } 76 | 77 | static __attribute__((always_inline)) __attribute__((noreturn)) void syscall_longjmp(struct JmpBuf *buf, int ret) { 78 | register int n asm("t1") = 0x14; 79 | __asm__ volatile("" : "=r"(n) : "r"(n)); 80 | ((void (*)(struct JmpBuf *, int))0xa0)(buf, ret); 81 | } 82 | 83 | static __attribute__((always_inline)) char *syscall_strcat(char *dst, const char *src) { 84 | register int n asm("t1") = 0x15; 85 | __asm__ volatile("" : "=r"(n) : "r"(n)); 86 | return ((char *(*)(char *, const char *))0xa0)(dst, src); 87 | } 88 | 89 | static __attribute__((always_inline)) char *syscall_strncat(char *dst, const char *src, size_t size) { 90 | register int n asm("t1") = 0x16; 91 | __asm__ volatile("" : "=r"(n) : "r"(n)); 92 | return ((char *(*)(char *, const char *, size_t))0xa0)(dst, src, size); 93 | } 94 | 95 | static __attribute__((always_inline)) int syscall_strcmp(const char *s1, const char *s2) { 96 | register int n asm("t1") = 0x17; 97 | __asm__ volatile("" : "=r"(n) : "r"(n)); 98 | return ((int (*)(const char *, const char *))0xa0)(s1, s2); 99 | } 100 | 101 | static __attribute__((always_inline)) int syscall_strncmp(const char *s1, const char *s2, size_t size) { 102 | register int n asm("t1") = 0x18; 103 | __asm__ volatile("" : "=r"(n) : "r"(n)); 104 | return ((int (*)(const char *, const char *, size_t))0xa0)(s1, s2, size); 105 | } 106 | 107 | static __attribute__((always_inline)) char *syscall_strcpy(char *dst, const char *src) { 108 | register int n asm("t1") = 0x19; 109 | __asm__ volatile("" : "=r"(n) : "r"(n)); 110 | return ((char *(*)(char *, const char *))0xa0)(dst, src); 111 | } 112 | 113 | static __attribute__((always_inline)) char *syscall_strncpy(char *dst, const char *src, size_t size) { 114 | register int n asm("t1") = 0x1a; 115 | __asm__ volatile("" : "=r"(n) : "r"(n)); 116 | return ((char *(*)(char *, const char *, size_t))0xa0)(dst, src, size); 117 | } 118 | 119 | static __attribute__((always_inline)) size_t syscall_strlen(const char *s) { 120 | register int n asm("t1") = 0x1b; 121 | __asm__ volatile("" : "=r"(n) : "r"(n)); 122 | return ((size_t(*)(const char *))0xa0)(s); 123 | } 124 | 125 | static __attribute__((always_inline)) char *syscall_index(const char *s, int c) { 126 | register int n asm("t1") = 0x1c; 127 | __asm__ volatile("" : "=r"(n) : "r"(n)); 128 | return ((char *(*)(const char *, int c))0xa0)(s, c); 129 | } 130 | 131 | static __attribute__((always_inline)) char *syscall_rindex(const char *s, int c) { 132 | register int n asm("t1") = 0x1d; 133 | __asm__ volatile("" : "=r"(n) : "r"(n)); 134 | return ((char *(*)(const char *, int c))0xa0)(s, c); 135 | } 136 | 137 | static __attribute__((always_inline)) char *syscall_strchr(const char *s, int c) { 138 | register int n asm("t1") = 0x1e; 139 | __asm__ volatile("" : "=r"(n) : "r"(n)); 140 | return ((char *(*)(const char *, int c))0xa0)(s, c); 141 | } 142 | 143 | static __attribute__((always_inline)) char *syscall_strrchr(const char *s, int c) { 144 | register int n asm("t1") = 0x1f; 145 | __asm__ volatile("" : "=r"(n) : "r"(n)); 146 | return ((char *(*)(const char *, int c))0xa0)(s, c); 147 | } 148 | 149 | static __attribute__((always_inline)) void *syscall_memcpy(void *dst, const void *src, size_t count) { 150 | register int n asm("t1") = 0x2a; 151 | __asm__ volatile("" : "=r"(n) : "r"(n)); 152 | return ((void *(*)(void *, const void *, size_t))0xa0)(dst, src, count); 153 | } 154 | 155 | static __attribute__((always_inline)) void *syscall_memset(void *dst, int c, size_t count) { 156 | register int n asm("t1") = 0x2b; 157 | __asm__ volatile("" : "=r"(n) : "r"(n)); 158 | return ((void *(*)(void *, int, size_t))0xa0)(dst, c, count); 159 | } 160 | 161 | static __attribute__((always_inline)) void syscall_qsort(void *base, size_t nel, size_t width, 162 | int (*compar)(const void *, const void *)) { 163 | register int n asm("t1") = 0x31; 164 | __asm__ volatile("" : "=r"(n) : "r"(n)); 165 | ((void (*)(void *, size_t, size_t, int (*)(const void *, const void *)))0xa0)(base, nel, width, compar); 166 | } 167 | 168 | static __attribute__((always_inline)) void *syscall_userMalloc(size_t size) { 169 | register int n asm("t1") = 0x33; 170 | __asm__ volatile("" : "=r"(n) : "r"(n)); 171 | return ((void *(*)(size_t))0xa0)(size); 172 | } 173 | 174 | static __attribute__((always_inline)) void syscall_userFree(void *ptr) { 175 | register int n asm("t1") = 0x34; 176 | __asm__ volatile("" : "=r"(n) : "r"(n)); 177 | ((void (*)(void *))0xa0)(ptr); 178 | } 179 | 180 | static __attribute__((always_inline)) void syscall_userInitheap(void *ptr, size_t size) { 181 | register int n asm("t1") = 0x39; 182 | __asm__ volatile("" : "=r"(n) : "r"(n)); 183 | ((void (*)(void *, size_t))0xa0)(ptr, size); 184 | } 185 | 186 | static __attribute__((always_inline)) void syscall__exit(int code) { 187 | register int n asm("t1") = 0x3a; 188 | __asm__ volatile("" : "=r"(n) : "r"(n)); 189 | ((void (*)(int))0xa0)(code); 190 | } 191 | 192 | // doing this one in raw inline assembly would prove tricky, 193 | // and there's already enough voodoo in this file. 194 | // this is syscall a0:3f 195 | #ifdef __cplusplus 196 | extern "C" { 197 | #endif 198 | int romsyscall_printf(const char *fmt, ...); 199 | int ramsyscall_printf(const char *fmt, ...); 200 | #ifdef __cplusplus 201 | } 202 | #endif 203 | 204 | static __attribute__((always_inline)) int syscall_unresolvedException() { 205 | register int n asm("t1") = 0x40; 206 | __asm__ volatile("" : "=r"(n) : "r"(n)); 207 | return ((int (*)())0xa0)(); 208 | } 209 | 210 | static __attribute__((always_inline)) void syscall_flushCache() { 211 | register int n asm("t1") = 0x44; 212 | __asm__ volatile("" : "=r"(n) : "r"(n)); 213 | ((void (*)())0xa0)(); 214 | } 215 | 216 | static __attribute__((always_inline)) int syscall_cdromSeekL(uint8_t *msf) { 217 | register int n asm("t1") = 0x78; 218 | __asm__ volatile("" : "=r"(n) : "r"(n)); 219 | return ((int (*)(uint8_t *))0xa0)(msf); 220 | } 221 | 222 | static __attribute__((always_inline)) int syscall_cdromGetStatus(uint8_t *ptr) { 223 | register int n asm("t1") = 0x7c; 224 | __asm__ volatile("" : "=r"(n) : "r"(n)); 225 | return ((int (*)(uint8_t *))0xa0)(ptr); 226 | } 227 | 228 | static __attribute__((always_inline)) int syscall_cdromRead(int count, void *buffer, uint32_t mode) { 229 | register int n asm("t1") = 0x7e; 230 | __asm__ volatile("" : "=r"(n) : "r"(n)); 231 | return ((int (*)(int, void *, uint32_t))0xa0)(count, buffer, mode); 232 | } 233 | 234 | static __attribute__((always_inline)) int syscall_cdromInnerInit() { 235 | register int n asm("t1") = 0x95; 236 | __asm__ volatile("" : "=r"(n) : "r"(n)); 237 | return ((int (*)())0xa0)(); 238 | } 239 | 240 | static __attribute__((always_inline)) int syscall_addCDRomDevice() { 241 | register int n asm("t1") = 0x96; 242 | __asm__ volatile("" : "=r"(n) : "r"(n)); 243 | return ((int (*)())0xa0)(); 244 | } 245 | 246 | static __attribute__((always_inline)) int syscall_addMemoryCardDevice() { 247 | register int n asm("t1") = 0x97; 248 | __asm__ volatile("" : "=r"(n) : "r"(n)); 249 | return ((int (*)())0xa0)(); 250 | } 251 | 252 | static __attribute__((always_inline)) int syscall_addConsoleDevice() { 253 | register int n asm("t1") = 0x98; 254 | __asm__ volatile("" : "=r"(n) : "r"(n)); 255 | return ((int (*)())0xa0)(); 256 | } 257 | 258 | static __attribute__((always_inline)) int syscall_addDummyConsoleDevice() { 259 | register int n asm("t1") = 0x99; 260 | __asm__ volatile("" : "=r"(n) : "r"(n)); 261 | return ((int (*)())0xa0)(); 262 | } 263 | 264 | static __attribute__((always_inline)) void syscall_exception(int code1, int code2) { 265 | register int n asm("t1") = 0xa1; 266 | __asm__ volatile("" : "=r"(n) : "r"(n)); 267 | ((void (*)(int, int))0xa0)(code1, code2); 268 | } 269 | 270 | static __attribute__((always_inline)) void syscall_enqueueCDRomHandlers() { 271 | register int n asm("t1") = 0xa2; 272 | __asm__ volatile("" : "=r"(n) : "r"(n)); 273 | ((void (*)())0xa0)(); 274 | } 275 | 276 | static __attribute__((always_inline)) void syscall_dequeueCDRomHandlers() { 277 | register int n asm("t1") = 0xa3; 278 | __asm__ volatile("" : "=r"(n) : "r"(n)); 279 | ((void (*)())0xa0)(); 280 | } 281 | 282 | static __attribute__((always_inline)) void syscall_buLowLevelOpCompleted() { 283 | register int n asm("t1") = 0xa7; 284 | __asm__ volatile("" : "=r"(n) : "r"(n)); 285 | ((void (*)())0xa0)(); 286 | } 287 | 288 | static __attribute__((always_inline)) void syscall_buLowLevelOpError1() { 289 | register int n asm("t1") = 0xa8; 290 | __asm__ volatile("" : "=r"(n) : "r"(n)); 291 | ((void (*)())0xa0)(); 292 | } 293 | 294 | static __attribute__((always_inline)) void syscall_buLowLevelOpError2() { 295 | register int n asm("t1") = 0xa9; 296 | __asm__ volatile("" : "=r"(n) : "r"(n)); 297 | ((void (*)())0xa0)(); 298 | } 299 | 300 | static __attribute__((always_inline)) void syscall_buLowLevelOpError3() { 301 | register int n asm("t1") = 0xaa; 302 | __asm__ volatile("" : "=r"(n) : "r"(n)); 303 | ((void (*)())0xa0)(); 304 | } 305 | 306 | static __attribute__((always_inline)) void syscall_buLowLevelOpError4() { 307 | register int n asm("t1") = 0xae; 308 | __asm__ volatile("" : "=r"(n) : "r"(n)); 309 | ((void (*)())0xa0)(); 310 | } 311 | 312 | static __attribute__((always_inline)) int syscall_ioabortraw(int code) { 313 | register int n asm("t1") = 0xb2; 314 | __asm__ volatile("" : "=r"(n) : "r"(n)); 315 | return ((int (*)(int))0xa0)(code); 316 | } 317 | 318 | /* B0 table */ 319 | static __attribute__((always_inline)) void *syscall_kmalloc(unsigned size) { 320 | register int n asm("t1") = 0x00; 321 | __asm__ volatile("" : "=r"(n) : "r"(n)); 322 | return ((void *(*)(unsigned))0xb0)(size); 323 | } 324 | 325 | static __attribute__((always_inline)) void syscall_kfree(void *ptr) { 326 | register int n asm("t1") = 0x01; 327 | __asm__ volatile("" : "=r"(n) : "r"(n)); 328 | ((void (*)(void *))0xb0)(ptr); 329 | } 330 | 331 | static __attribute__((always_inline)) int syscall_initTimer(uint32_t timer, uint16_t target, uint16_t flags) { 332 | register int n asm("t1") = 0x02; 333 | __asm__ volatile("" : "=r"(n) : "r"(n)); 334 | return ((int (*)(uint32_t, uint16_t, uint16_t))0xb0)(timer, target, flags); 335 | } 336 | 337 | static __attribute__((always_inline)) int syscall_getTimer(uint32_t timer) { 338 | register int n asm("t1") = 0x03; 339 | __asm__ volatile("" : "=r"(n) : "r"(n)); 340 | return ((int (*)(uint32_t))0xb0)(timer); 341 | } 342 | 343 | static __attribute__((always_inline)) int syscall_enableTimerIRQ(uint32_t timer) { 344 | register int n asm("t1") = 0x04; 345 | __asm__ volatile("" : "=r"(n) : "r"(n)); 346 | return ((int (*)(uint32_t))0xb0)(timer); 347 | } 348 | 349 | static __attribute__((always_inline)) int syscall_disableTimerIRQ(uint32_t timer) { 350 | register int n asm("t1") = 0x05; 351 | __asm__ volatile("" : "=r"(n) : "r"(n)); 352 | return ((int (*)(uint32_t))0xb0)(timer); 353 | } 354 | 355 | static __attribute__((always_inline)) int syscall_restartTimer(uint32_t timer) { 356 | register int n asm("t1") = 0x06; 357 | __asm__ volatile("" : "=r"(n) : "r"(n)); 358 | return ((int (*)(uint32_t))0xb0)(timer); 359 | } 360 | 361 | static __attribute__((always_inline)) void syscall_deliverEvent(uint32_t classId, uint32_t spec) { 362 | register int n asm("t1") = 0x07; 363 | __asm__ volatile("" : "=r"(n) : "r"(n)); 364 | ((void (*)(uint32_t, uint32_t))0xb0)(classId, spec); 365 | } 366 | 367 | static __attribute__((always_inline)) uint32_t syscall_openEvent(uint32_t classId, uint32_t spec, uint32_t mode, 368 | void (*handler)()) { 369 | register int n asm("t1") = 0x08; 370 | __asm__ volatile("" : "=r"(n) : "r"(n)); 371 | return ((uint32_t(*)(uint32_t, uint32_t, uint32_t, void (*)()))0xb0)(classId, spec, mode, handler); 372 | } 373 | 374 | static __attribute__((always_inline)) int syscall_closeEvent(uint32_t event) { 375 | register int n asm("t1") = 0x09; 376 | __asm__ volatile("" : "=r"(n) : "r"(n)); 377 | return ((uint32_t(*)(uint32_t))0xb0)(event); 378 | } 379 | 380 | static __attribute__((always_inline)) int syscall_testEvent(uint32_t event) { 381 | register int n asm("t1") = 0x0b; 382 | __asm__ volatile("" : "=r"(n) : "r"(n)); 383 | return ((int (*)(uint32_t))0xb0)(event); 384 | } 385 | 386 | static __attribute__((always_inline)) int syscall_enableEvent(uint32_t event) { 387 | register int n asm("t1") = 0x0c; 388 | __asm__ volatile("" : "=r"(n) : "r"(n)); 389 | return ((int (*)(uint32_t))0xb0)(event); 390 | } 391 | 392 | static __attribute__((always_inline)) void syscall_initPad(void *buffer1, size_t size1, void *buffer2, size_t size2) { 393 | register int n asm("t1") = 0x12; 394 | __asm__ volatile("" : "=r"(n) : "r"(n)); 395 | ((void (*)(void *, size_t, void *, size_t))0xb0)(buffer1, size1, buffer2, size2); 396 | } 397 | 398 | static __attribute__((always_inline)) void syscall_startPad() { 399 | register int n asm("t1") = 0x13; 400 | __asm__ volatile("" : "=r"(n) : "r"(n)); 401 | ((void (*)())0xb0)(); 402 | } 403 | 404 | static __attribute__((always_inline)) void syscall_stopPad() { 405 | register int n asm("t1") = 0x14; 406 | __asm__ volatile("" : "=r"(n) : "r"(n)); 407 | ((void (*)())0xb0)(); 408 | } 409 | 410 | static __attribute__((noreturn)) __attribute__((always_inline)) void syscall_returnFromException() { 411 | register int n asm("t1") = 0x17; 412 | __asm__ volatile("" : "=r"(n) : "r"(n)); 413 | ((__attribute__((noreturn)) void (*)())0xb0)(); 414 | } 415 | 416 | static __attribute__((always_inline)) void syscall_setDefaultExceptionJmpBuf() { 417 | register int n asm("t1") = 0x18; 418 | __asm__ volatile("" : "=r"(n) : "r"(n)); 419 | ((void (*)())0xb0)(); 420 | } 421 | 422 | static __attribute__((always_inline)) void syscall_undeliverEvent(uint32_t classId, uint32_t mode) { 423 | register int n asm("t1") = 0x20; 424 | __asm__ volatile("" : "=r"(n) : "r"(n)); 425 | ((void (*)(uint32_t, uint32_t))0xb0)(classId, mode); 426 | } 427 | 428 | static __attribute__((always_inline)) int syscall_open(const char *filename, int mode) { 429 | register int n asm("t1") = 0x32; 430 | __asm__ volatile("" : "=r"(n) : "r"(n)); 431 | return ((int (*)(const char *, int))0xb0)(filename, mode); 432 | } 433 | 434 | static __attribute__((always_inline)) int syscall_read(int fd, void *buffer, int size) { 435 | register int n asm("t1") = 0x34; 436 | __asm__ volatile("" : "=r"(n) : "r"(n)); 437 | return ((int (*)(int, void *, int))0xb0)(fd, buffer, size); 438 | } 439 | 440 | static __attribute__((always_inline)) int syscall_close(int fd) { 441 | register int n asm("t1") = 0x36; 442 | __asm__ volatile("" : "=r"(n) : "r"(n)); 443 | return ((int (*)(int))0xb0)(fd); 444 | } 445 | 446 | static __attribute__((always_inline)) void syscall_putchar(int c) { 447 | register int n asm("t1") = 0x3d; 448 | __asm__ volatile("" : "=r"(n) : "r"(n)); 449 | ((void (*)(int))0xb0)(c); 450 | } 451 | 452 | static __attribute__((always_inline)) int syscall_addDevice(const struct Device *device) { 453 | register int n asm("t1") = 0x47; 454 | __asm__ volatile("" : "=r"(n) : "r"(n)); 455 | return ((int (*)(const struct Device *))0xb0)(device); 456 | } 457 | 458 | static __attribute__((always_inline)) int syscall_cardInfoInternal(int deviceID) { 459 | register int n asm("t1") = 0x4d; 460 | __asm__ volatile("" : "=r"(n) : "r"(n)); 461 | return ((int (*)(int))0xb0)(deviceID); 462 | } 463 | 464 | static __attribute__((always_inline)) int syscall_mcWriteSector(int deviceID, int sector, const uint8_t *buffer) { 465 | register int n asm("t1") = 0x4e; 466 | __asm__ volatile("" : "=r"(n) : "r"(n)); 467 | return ((int (*)(int, int, const uint8_t *))0xb0)(deviceID, sector, buffer); 468 | } 469 | 470 | static __attribute__((always_inline)) int syscall_mcReadSector(int deviceID, int sector, uint8_t *buffer) { 471 | register int n asm("t1") = 0x4f; 472 | __asm__ volatile("" : "=r"(n) : "r"(n)); 473 | return ((int (*)(int, int, uint8_t *))0xb0)(deviceID, sector, buffer); 474 | } 475 | 476 | static __attribute__((always_inline)) void syscall_mcAllowNewCard() { 477 | register int n asm("t1") = 0x50; 478 | __asm__ volatile("" : "=r"(n) : "r"(n)); 479 | ((void (*)())0xb0)(); 480 | } 481 | 482 | static __attribute__((always_inline)) int syscall_mcGetLastDevice() { 483 | register int n asm("t1") = 0x58; 484 | __asm__ volatile("" : "=r"(n) : "r"(n)); 485 | return ((int (*)())0xb0)(); 486 | } 487 | 488 | /* C0 table */ 489 | static __attribute__((always_inline)) int syscall_enqueueRCntIrqs(int priority) { 490 | register int n asm("t1") = 0x00; 491 | __asm__ volatile("" : "=r"(n) : "r"(n)); 492 | return ((int (*)(int))0xc0)(priority); 493 | } 494 | 495 | static __attribute__((always_inline)) int syscall_enqueueSyscallHandler(int priority) { 496 | register int n asm("t1") = 0x01; 497 | __asm__ volatile("" : "=r"(n) : "r"(n)); 498 | return ((int (*)(int))0xc0)(priority); 499 | } 500 | 501 | static __attribute__((always_inline)) int syscall_sysEnqIntRP(int priority, struct HandlerInfo *info) { 502 | register int n asm("t1") = 0x02; 503 | __asm__ volatile("" : "=r"(n) : "r"(n)); 504 | return ((int (*)(int, struct HandlerInfo *))0xc0)(priority, info); 505 | } 506 | 507 | static __attribute__((always_inline)) int syscall_sysDeqIntRP(int priority, struct HandlerInfo *info) { 508 | register int n asm("t1") = 0x03; 509 | __asm__ volatile("" : "=r"(n) : "r"(n)); 510 | return ((int (*)(int, struct HandlerInfo *))0xc0)(priority, info); 511 | } 512 | 513 | static __attribute__((always_inline)) void syscall_installExceptionHandler() { 514 | register int n asm("t1") = 0x07; 515 | __asm__ volatile("" : "=r"(n) : "r"(n)); 516 | ((void (*)())0xc0)(); 517 | } 518 | 519 | static __attribute__((always_inline)) void syscall_kernInitheap(void *base, size_t size) { 520 | register int n asm("t1") = 0x08; 521 | __asm__ volatile("" : "=r"(n) : "r"(n)); 522 | ((void (*)(void *, size_t))0xc0)(base, size); 523 | } 524 | 525 | static __attribute__((always_inline)) int syscall_setTimerAutoAck(uint32_t timer, int value) { 526 | register int n asm("t1") = 0x0a; 527 | __asm__ volatile("" : "=r"(n) : "r"(n)); 528 | return ((int (*)(uint32_t, int))0xc0)(timer, value); 529 | } 530 | 531 | static __attribute__((always_inline)) int syscall_enqueueIrqHandler(int priority) { 532 | register int n asm("t1") = 0x0c; 533 | __asm__ volatile("" : "=r"(n) : "r"(n)); 534 | return ((int (*)(int))0xc0)(priority); 535 | } 536 | 537 | static __attribute__((always_inline)) void syscall_setIrqAutoAck(uint32_t irq, int value) { 538 | register int n asm("t1") = 0x0d; 539 | __asm__ volatile("" : "=r"(n) : "r"(n)); 540 | ((void (*)(uint32_t, int))0xc0)(irq, value); 541 | } 542 | 543 | static __attribute__((always_inline)) void syscall_setupFileIO(int installTTY) { 544 | register int n asm("t1") = 0x12; 545 | __asm__ volatile("" : "=r"(n) : "r"(n)); 546 | ((void (*)(int))0xc0)(installTTY); 547 | } 548 | 549 | static __attribute__((always_inline)) void syscall_cdevinput(struct CircularBuffer *circ, int c) { 550 | register int n asm("t1") = 0x15; 551 | __asm__ volatile("" : "=r"(n) : "r"(n)); 552 | ((void (*)(struct CircularBuffer *, int))0xc0)(circ, c); 553 | } 554 | 555 | static __attribute__((always_inline)) void syscall_cdevscan() { 556 | register int n asm("t1") = 0x16; 557 | __asm__ volatile("" : "=r"(n) : "r"(n)); 558 | ((void (*)())0xc0)(); 559 | } 560 | 561 | static __attribute__((always_inline)) int syscall_circgetc(struct CircularBuffer *circ) { 562 | register int n asm("t1") = 0x17; 563 | __asm__ volatile("" : "=r"(n) : "r"(n)); 564 | return ((int (*)(struct CircularBuffer *))0xc0)(circ); 565 | } 566 | 567 | static __attribute__((always_inline)) int syscall_ioabort(const char *msg) { 568 | register int n asm("t1") = 0x19; 569 | __asm__ volatile("" : "=r"(n) : "r"(n)); 570 | return ((int (*)(const char *))0xc0)(msg); 571 | } 572 | 573 | static __attribute__((always_inline)) void syscall_setDeviceStatus(int status) { 574 | register int n asm("t1") = 0x1a; 575 | __asm__ volatile("" : "=r"(n) : "r"(n)); 576 | ((void (*)(int))0xc0)(status); 577 | } 578 | 579 | static __attribute__((always_inline)) void syscall_patchA0table() { 580 | register int n asm("t1") = 0x1c; 581 | __asm__ volatile("" : "=r"(n) : "r"(n)); 582 | ((void (*)())0xc0)(); 583 | } 584 | 585 | static __attribute__((always_inline)) int syscall_getDeviceStatus() { 586 | register int n asm("t1") = 0x1d; 587 | __asm__ volatile("" : "=r"(n) : "r"(n)); 588 | return ((int (*)())0xc0)(); 589 | } 590 | -------------------------------------------------------------------------------- /third_party/common/util/djbhash.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | static inline uint32_t djbProcess(uint32_t hash, const char str[], unsigned n) { 32 | return n ? djbProcess(((hash << 5) + hash) ^ str[0], str + 1, n - 1) : hash; 33 | } 34 | 35 | static inline uint32_t djbHash(const char* str, unsigned n) { return djbProcess(5381, str, n); } 36 | -------------------------------------------------------------------------------- /third_party/common/util/encoder.hh: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2021 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | namespace Mips { 32 | namespace Encoder { 33 | 34 | // clang-format off 35 | enum class Reg { 36 | R0, AT, V0, V1, A0, A1, A2, A3, // 00 to 07 37 | T0, T1, T2, T3, T4, T5, T6, T7, // 08 to 0f 38 | S0, S1, S2, S3, S4, S5, S6, S7, // 10 to 17 39 | T8, T9, K0, K1, GP, SP, S8, RA, // 18 to 1f 40 | }; 41 | // clang-format on 42 | 43 | constexpr uint32_t iclass(uint32_t v) { return v << 26; } 44 | constexpr uint32_t dstVal(Reg r) { return uint32_t(r) << 11; } 45 | constexpr uint32_t tgtVal(Reg r) { return uint32_t(r) << 16; } 46 | constexpr uint32_t srcVal(Reg r) { return uint32_t(r) << 21; } 47 | 48 | // ALU 49 | constexpr uint32_t add(Reg dst, Reg src, Reg tgt) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b100000; } 50 | constexpr uint32_t addu(Reg dst, Reg src, Reg tgt) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b100001; } 51 | constexpr uint32_t addi(Reg tgt, Reg src, int16_t value) { 52 | uint32_t v = value; 53 | v &= 0xffff; 54 | return iclass(0b001000) | srcVal(src) | tgtVal(tgt) | v; 55 | } 56 | constexpr uint32_t addiu(Reg tgt, Reg src, int16_t value) { 57 | uint32_t v = value; 58 | v &= 0xffff; 59 | return iclass(0b001001) | srcVal(src) | tgtVal(tgt) | v; 60 | } 61 | constexpr uint32_t andd(Reg dst, Reg src, Reg tgt) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b100100; } 62 | constexpr uint32_t andi(Reg tgt, Reg src, uint16_t value) { 63 | return iclass(0b001100) | srcVal(src) | tgtVal(tgt) | value; 64 | } 65 | constexpr uint32_t lui(Reg tgt, uint16_t value) { return iclass(0b001111) | tgtVal(tgt) | value; } 66 | constexpr uint32_t nor(Reg dst, Reg src, Reg tgt) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b100111; } 67 | constexpr uint32_t orr(Reg dst, Reg src, Reg tgt) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b100101; } 68 | constexpr uint32_t ori(Reg tgt, Reg src, uint16_t value) { 69 | return iclass(0b001101) | srcVal(src) | tgtVal(tgt) | value; 70 | } 71 | constexpr uint32_t slt(Reg dst, Reg src, Reg tgt) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b101010; } 72 | constexpr uint32_t sltu(Reg dst, Reg src, Reg tgt) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b101011; } 73 | constexpr uint32_t slti(Reg tgt, Reg src, int16_t value) { 74 | uint32_t v = value; 75 | v &= 0xffff; 76 | return iclass(0b001010) | srcVal(src) | tgtVal(tgt) | v; 77 | } 78 | constexpr uint32_t sltiu(Reg tgt, Reg src, uint16_t value) { 79 | return iclass(0b001011) | srcVal(src) | tgtVal(tgt) | value; 80 | } 81 | constexpr uint32_t sub(Reg dst, Reg src, Reg tgt) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b100010; } 82 | constexpr uint32_t subu(Reg dst, Reg src, Reg tgt) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b100011; } 83 | constexpr uint32_t xorr(Reg dst, Reg src, Reg tgt) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b100110; } 84 | constexpr uint32_t xori(Reg tgt, Reg src, uint16_t value) { 85 | return iclass(0b001110) | srcVal(src) | tgtVal(tgt) | value; 86 | } 87 | 88 | // shifts 89 | constexpr uint32_t sll(Reg dst, Reg tgt, uint16_t sa) { return dstVal(dst) | tgtVal(tgt) | (sa << 6) | 0b000000; } 90 | constexpr uint32_t sllv(Reg dst, Reg tgt, Reg src) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b000100; } 91 | constexpr uint32_t sra(Reg dst, Reg tgt, uint16_t sa) { return dstVal(dst) | tgtVal(tgt) | (sa << 6) | 0b000011; } 92 | constexpr uint32_t srav(Reg dst, Reg tgt, Reg src) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b000111; } 93 | constexpr uint32_t srl(Reg dst, Reg tgt, uint16_t sa) { return dstVal(dst) | tgtVal(tgt) | (sa << 6) | 0b000010; } 94 | constexpr uint32_t srlv(Reg dst, Reg tgt, Reg src) { return dstVal(dst) | tgtVal(tgt) | srcVal(src) | 0b000110; } 95 | 96 | // mults 97 | constexpr uint32_t div(Reg src, Reg tgt) { return tgtVal(tgt) | srcVal(src) | 0b011010; } 98 | constexpr uint32_t divu(Reg src, Reg tgt) { return tgtVal(tgt) | srcVal(src) | 0b011011; } 99 | constexpr uint32_t mfhi(Reg dst) { return dstVal(dst) | 0b010000; } 100 | constexpr uint32_t mflo(Reg dst) { return dstVal(dst) | 0b010010; } 101 | constexpr uint32_t mthi(Reg dst) { return dstVal(dst) | 0b010001; } 102 | constexpr uint32_t mtlo(Reg dst) { return dstVal(dst) | 0b010011; } 103 | constexpr uint32_t mult(Reg src, Reg tgt) { return tgtVal(tgt) | srcVal(src) | 0b011000; } 104 | constexpr uint32_t multu(Reg src, Reg tgt) { return tgtVal(tgt) | srcVal(src) | 0b011001; } 105 | 106 | // branches 107 | constexpr uint32_t beq(Reg src, Reg tgt, int16_t offset) { 108 | uint32_t o = offset >> 2; 109 | o &= 0xffff; 110 | return iclass(0b000100) | tgtVal(tgt) | srcVal(src) | o; 111 | } 112 | constexpr uint32_t bgez(Reg src, int16_t offset) { 113 | uint32_t o = offset >> 2; 114 | o &= 0xffff; 115 | return iclass(0b000001) | tgtVal(Reg(0b00001)) | srcVal(src) | o; 116 | } 117 | constexpr uint32_t bgezal(Reg src, int16_t offset) { 118 | uint32_t o = offset >> 2; 119 | o &= 0xffff; 120 | return iclass(0b000001) | tgtVal(Reg(0b10001)) | srcVal(src) | o; 121 | } 122 | constexpr uint32_t bgtz(Reg src, int16_t offset) { 123 | uint32_t o = offset >> 2; 124 | o &= 0xffff; 125 | return iclass(0b000111) | tgtVal(Reg(0b00000)) | srcVal(src) | o; 126 | } 127 | constexpr uint32_t blez(Reg src, int16_t offset) { 128 | uint32_t o = offset >> 2; 129 | o &= 0xffff; 130 | return iclass(0b000110) | tgtVal(Reg(0b00000)) | srcVal(src) | o; 131 | } 132 | constexpr uint32_t bltz(Reg src, int16_t offset) { 133 | uint32_t o = offset >> 2; 134 | o &= 0xffff; 135 | return iclass(0b000001) | tgtVal(Reg(0b00000)) | srcVal(src) | o; 136 | } 137 | constexpr uint32_t bltzal(Reg src, int16_t offset) { 138 | uint32_t o = offset >> 2; 139 | o &= 0xffff; 140 | return iclass(0b000001) | tgtVal(Reg(0b10000)) | srcVal(src) | o; 141 | } 142 | constexpr uint32_t bne(Reg src, Reg tgt, int16_t offset) { 143 | uint32_t o = offset >> 2; 144 | o &= 0xffff; 145 | return iclass(0b000101) | tgtVal(tgt) | srcVal(src) | o; 146 | } 147 | constexpr uint32_t brk(uint32_t code) { return (code << 6) | 0b001101; } 148 | constexpr uint32_t j(uint32_t addr) { return iclass(0b000010) | ((addr >> 2) & 0x03ffffff); } 149 | constexpr uint32_t jal(uint32_t addr) { return iclass(0b000011) | ((addr >> 2) & 0x03ffffff); } 150 | constexpr uint32_t jalr(Reg src, Reg dst = Reg::RA) { return dstVal(dst) | srcVal(src) | 0b001001; } 151 | constexpr uint32_t jr(Reg src) { return srcVal(src) | 0b001000; } 152 | constexpr uint32_t syscall() { return 0b001100; } 153 | 154 | // memory 155 | constexpr uint32_t lb(Reg tgt, int16_t offset, Reg src) { 156 | uint32_t o = offset; 157 | o &= 0xffff; 158 | return iclass(0b100000) | tgtVal(tgt) | srcVal(src) | o; 159 | } 160 | constexpr uint32_t lbu(Reg tgt, int16_t offset, Reg src) { 161 | uint32_t o = offset; 162 | o &= 0xffff; 163 | return iclass(0b100100) | tgtVal(tgt) | srcVal(src) | o; 164 | } 165 | constexpr uint32_t lh(Reg tgt, int16_t offset, Reg src) { 166 | uint32_t o = offset; 167 | o &= 0xffff; 168 | return iclass(0b100001) | tgtVal(tgt) | srcVal(src) | o; 169 | } 170 | constexpr uint32_t lhu(Reg tgt, int16_t offset, Reg src) { 171 | uint32_t o = offset; 172 | o &= 0xffff; 173 | return iclass(0b100101) | tgtVal(tgt) | srcVal(src) | o; 174 | } 175 | constexpr uint32_t lw(Reg tgt, int16_t offset, Reg src) { 176 | uint32_t o = offset; 177 | o &= 0xffff; 178 | return iclass(0b100011) | tgtVal(tgt) | srcVal(src) | o; 179 | } 180 | constexpr uint32_t lwl(Reg tgt, int16_t offset, Reg src) { 181 | uint32_t o = offset; 182 | o &= 0xffff; 183 | return iclass(0b100010) | tgtVal(tgt) | srcVal(src) | o; 184 | } 185 | constexpr uint32_t lwr(Reg tgt, int16_t offset, Reg src) { 186 | uint32_t o = offset; 187 | o &= 0xffff; 188 | return iclass(0b100110) | tgtVal(tgt) | srcVal(src) | o; 189 | } 190 | constexpr uint32_t sb(Reg tgt, int16_t offset, Reg src) { 191 | uint32_t o = offset; 192 | o &= 0xffff; 193 | return iclass(0b101000) | tgtVal(tgt) | srcVal(src) | o; 194 | } 195 | constexpr uint32_t sh(Reg tgt, int16_t offset, Reg src) { 196 | uint32_t o = offset; 197 | o &= 0xffff; 198 | return iclass(0b101001) | tgtVal(tgt) | srcVal(src) | o; 199 | } 200 | constexpr uint32_t sw(Reg tgt, int16_t offset, Reg src) { 201 | uint32_t o = offset; 202 | o &= 0xffff; 203 | return iclass(0b101011) | tgtVal(tgt) | srcVal(src) | o; 204 | } 205 | constexpr uint32_t swl(Reg tgt, int16_t offset, Reg src) { 206 | uint32_t o = offset; 207 | o &= 0xffff; 208 | return iclass(0b101010) | tgtVal(tgt) | srcVal(src) | o; 209 | } 210 | constexpr uint32_t swr(Reg tgt, int16_t offset, Reg src) { 211 | uint32_t o = offset; 212 | o &= 0xffff; 213 | return iclass(0b101110) | tgtVal(tgt) | srcVal(src) | o; 214 | } 215 | 216 | // cop0 217 | constexpr uint32_t mfc0(Reg tgt, uint8_t dst) { return iclass(0b010000) | tgtVal(tgt) | (dst << 11); } 218 | constexpr uint32_t mtc0(Reg tgt, uint8_t dst) { return iclass(0b010000) | (4 << 21) | tgtVal(tgt) | (dst << 11); } 219 | constexpr uint32_t rfe() { return 0x42000010; } 220 | 221 | // pseudo 222 | constexpr uint32_t nop() { return 0; } 223 | 224 | } // namespace Encoder 225 | } // namespace Mips 226 | -------------------------------------------------------------------------------- /third_party/common/util/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2021 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | static __inline__ uint32_t readUnaligned(const void *in, int pos) { 32 | const uint8_t *buffer = (uint8_t *)in; 33 | uint32_t r = 0; 34 | pos += 4; 35 | r <<= 8; 36 | r += buffer[--pos]; 37 | r <<= 8; 38 | r += buffer[--pos]; 39 | r <<= 8; 40 | r += buffer[--pos]; 41 | r <<= 8; 42 | r += buffer[--pos]; 43 | return r; 44 | } 45 | -------------------------------------------------------------------------------- /third_party/cpe.ld: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | OUTPUT_FORMAT("binary") 28 | 29 | EXTERN(_start) 30 | ENTRY(_start) 31 | 32 | TLOAD_ADDR = DEFINED(TLOAD_ADDR) ? TLOAD_ADDR : 0x80010000; 33 | 34 | MEMORY { 35 | loader : ORIGIN = (TLOAD_ADDR - 22), LENGTH = 22 36 | ram (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 37 | dcache : ORIGIN = 0x1f800000, LENGTH = 0x400 38 | } 39 | 40 | __ram_top = ORIGIN(ram) + LENGTH(ram); 41 | __sp = __ram_top - 0x100; 42 | 43 | __dcache = ORIGIN(dcache); 44 | __dcache_top = ORIGIN(dcache) + LENGTH(dcache); 45 | 46 | __bss_len = (__bss_end - __bss_start); 47 | __ftext_len = (__ftext_end - __ftext_start); 48 | __fdata_len = (__fdata_end - __fdata_start); 49 | 50 | __stack_start = ORIGIN(ram) + LENGTH(ram); 51 | 52 | SECTIONS { 53 | .CPE_Header : { 54 | BYTE(67); BYTE(80); BYTE(69); BYTE(1); 55 | BYTE(8); BYTE(0); 56 | BYTE(3); BYTE(144); BYTE(0); 57 | LONG(ABSOLUTE(_start)); 58 | BYTE(1); 59 | LONG(TLOAD_ADDR); 60 | LONG(__ftext_len + __fdata_len); 61 | } > loader 62 | 63 | __ftext_start = ABSOLUTE(.); 64 | .text TLOAD_ADDR : { 65 | *(.start) 66 | *(.init) 67 | KEEP (*(SORT_NONE(.fini))) 68 | *(.text.unlikely .text.*_unlikely .text.unlikely.*) 69 | *(.text.exit .text.exit.*) 70 | *(.text.startup .text.startup.*) 71 | *(.text.hot .text.hot.*) 72 | *(.text .stub .text.* .gnu.linkonce.t.*) 73 | 74 | . = ALIGN(16); 75 | KEEP(*(.init)) 76 | . = ALIGN(16); 77 | KEEP(*(.fini)) 78 | } > ram 79 | 80 | . = ALIGN(16); 81 | __text_end = .; 82 | __ftext_end = ABSOLUTE(.); 83 | 84 | __fdata_start = ABSOLUTE(.); 85 | 86 | .rodata : { 87 | *(.rodata .rodata.* .rdata .rdata.* .gnu.linkonce.r.*) 88 | . = ALIGN(16); 89 | __preinit_array_start = .; 90 | KEEP (*(.preinit_array)) 91 | __preinit_array_end = .; 92 | 93 | . = ALIGN(16); 94 | __init_array_start = .; 95 | KEEP (*(SORT(.init_array.*))) 96 | KEEP (*(.init_array)) 97 | 98 | . = ALIGN(16); 99 | KEEP (*crtbegin.o(.ctors)) 100 | KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) 101 | KEEP (*(SORT(.ctors.*))) 102 | KEEP (*crtend.o(.ctors)) 103 | __init_array_end = .; 104 | 105 | . = ALIGN(16); 106 | __fini_array_start = .; 107 | KEEP (*(.fini_array)) 108 | KEEP (*(SORT(.fini_array.*))) 109 | 110 | KEEP (*crtbegin.o(.dtors)) 111 | KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) 112 | KEEP (*(SORT(.dtors.*))) 113 | KEEP (*crtend.o(.dtors)) 114 | __fini_array_end = .; 115 | __build_id = .; 116 | *(.note.gnu.build-id) 117 | __build_id_end = .; 118 | } > ram 119 | 120 | .rodata1 : { 121 | *(.rodata1) 122 | } > ram 123 | 124 | __data_start = .; 125 | .data : { 126 | *(.a0table) 127 | *(.data .data.* .gnu.linkonce.d.*) 128 | *(.data1) 129 | *(.sdata .sdata.* .gnu.linkonce.s.*) 130 | *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) 131 | *(.got.plt) 132 | *(.got) 133 | } > ram 134 | 135 | . = ALIGN(4); 136 | __data_end = .; 137 | __fdata_end = .; 138 | .data1 : { 139 | BYTE(0); 140 | } > ram 141 | . = ALIGN(4); 142 | __bss_start = .; 143 | .sbss (NOLOAD) : { 144 | *(.dynsbss) 145 | *(.sbss .sbss.* .gnu.linkonce.sb.*) 146 | *(.scommon) 147 | *(.dynbss) 148 | *(.bss .bss.* .gnu.linkonce.b.*) 149 | *(COMMON) 150 | } > ram 151 | 152 | . = ALIGN(4); 153 | __bss_end = .; 154 | 155 | __heap_start = __heap_base; 156 | 157 | __end = .; 158 | 159 | /DISCARD/ : { *(.MIPS.abiflags) } 160 | 161 | /* Everything is statically linked, so discard PLTs. */ 162 | /DISCARD/ : { *(.rel.iplt) *(.rela.iplt) *(.rel.plt) *(.rela.plt) *(.plt) *(.iplt) } 163 | 164 | /* Discard things that the standard link script drops, too. */ 165 | /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } 166 | 167 | .scratchpad (NOLOAD) : { 168 | $(.scratchpad) 169 | } > dcache 170 | } 171 | -------------------------------------------------------------------------------- /third_party/default.ld: -------------------------------------------------------------------------------- 1 | __heap_base = __bss_end; -------------------------------------------------------------------------------- /third_party/nooverlay.ld: -------------------------------------------------------------------------------- 1 | __heap_base = __bss_end; -------------------------------------------------------------------------------- /third_party/ps-exe.ld: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | MIT License 4 | 5 | Copyright (c) 2019 PCSX-Redux authors 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | */ 26 | 27 | OUTPUT_FORMAT("binary") 28 | 29 | EXTERN(_start) 30 | ENTRY(_start) 31 | 32 | TLOAD_ADDR = DEFINED(TLOAD_ADDR) ? TLOAD_ADDR : 0x80010000; 33 | 34 | MEMORY { 35 | loader : ORIGIN = (TLOAD_ADDR - 0x800), LENGTH = 2048 36 | ram (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 37 | dcache : ORIGIN = 0x1f800000, LENGTH = 0x400 38 | } 39 | 40 | __ram_top = ORIGIN(ram) + LENGTH(ram); 41 | __sp = __ram_top - 0x100; 42 | 43 | __dcache = ORIGIN(dcache); 44 | __dcache_top = ORIGIN(dcache) + LENGTH(dcache); 45 | 46 | __bss_len = (__bss_end - __bss_start); 47 | __ftext_len = (__ftext_end - __ftext_start); 48 | __fdata_len = (__fdata_end - __fdata_start); 49 | 50 | __stack_start = ORIGIN(ram) + LENGTH(ram); 51 | 52 | SECTIONS { 53 | .PSX_EXE_Header : { 54 | /* 55 | 0x0000 - 0x0007 : "PS-X EXE" 56 | */ 57 | BYTE(80); BYTE(83); BYTE(45); BYTE(88); BYTE(32); BYTE(69); BYTE(88); BYTE(69); 58 | 59 | /* 0x0008 - 0x000F : skip text_off and data_off since they're not supported by the PS1 BIOS */ 60 | LONG(0); LONG(0); 61 | 62 | /* 0x0010 - 0x0013 : entry point */ 63 | LONG(ABSOLUTE(_start)); 64 | 65 | /* 0x0014 - 0x0017 : initial value of $gp */ 66 | LONG(0); 67 | 68 | /* 0x0018 - 0x001B : Memory address to load "text" section to. */ 69 | /* 70 | NOTE: The "text" section is actually all of the "load" 71 | sections of the file including .text, .rodata, .data. 72 | etc. 73 | */ 74 | LONG(TLOAD_ADDR); 75 | 76 | /* 0x001C - 0x001F : size, in bytes, of the "text" section. */ 77 | LONG(__ftext_len + __fdata_len); 78 | 79 | /* 0x0020 - 0x002F : 80 | Skip "data_addr", "data_size", "bss_addr" and "bss_size". 81 | None of these are supported by retail PS1 BIOS. 82 | */ 83 | LONG(0); LONG(0); 84 | LONG(0); LONG(0); 85 | 86 | /* 0x0030 - 0x0033 : Initial stack address. */ 87 | LONG(DEFINED(_sp) ? ABSOLUTE(_sp) : 0x801FFF00); 88 | 89 | /* 0x0034 - 0x0037 : Initial stack size, set it to 0. */ 90 | LONG(0); 91 | 92 | /* Skip the remaining fields as they're not supported by the BIOS */ 93 | /* e.g. 2048 header bytes minus whatever we've actually used */ 94 | . = . + 1992; 95 | } > loader 96 | 97 | __ftext_start = ABSOLUTE(.); 98 | .text TLOAD_ADDR : { 99 | *(.start) 100 | *(.init) 101 | KEEP (*(SORT_NONE(.fini))) 102 | *(.text.unlikely .text.*_unlikely .text.unlikely.*) 103 | *(.text.exit .text.exit.*) 104 | *(.text.startup .text.startup.*) 105 | *(.text.hot .text.hot.*) 106 | *(.text .stub .text.* .gnu.linkonce.t.*) 107 | 108 | . = ALIGN(16); 109 | KEEP(*(.init)) 110 | . = ALIGN(16); 111 | KEEP(*(.fini)) 112 | } > ram 113 | 114 | . = ALIGN(16); 115 | __text_end = .; 116 | __ftext_end = ABSOLUTE(.); 117 | 118 | __fdata_start = ABSOLUTE(.); 119 | 120 | .rodata : { 121 | *(.rodata .rodata.* .rdata .rdata.* .gnu.linkonce.r.*) 122 | . = ALIGN(16); 123 | __preinit_array_start = .; 124 | KEEP (*(.preinit_array)) 125 | __preinit_array_end = .; 126 | 127 | . = ALIGN(16); 128 | __init_array_start = .; 129 | KEEP (*(SORT(.init_array.*))) 130 | KEEP (*(.init_array)) 131 | 132 | . = ALIGN(16); 133 | KEEP (*crtbegin.o(.ctors)) 134 | KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) 135 | KEEP (*(SORT(.ctors.*))) 136 | KEEP (*crtend.o(.ctors)) 137 | __init_array_end = .; 138 | 139 | . = ALIGN(16); 140 | __fini_array_start = .; 141 | KEEP (*(.fini_array)) 142 | KEEP (*(SORT(.fini_array.*))) 143 | 144 | KEEP (*crtbegin.o(.dtors)) 145 | KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) 146 | KEEP (*(SORT(.dtors.*))) 147 | KEEP (*crtend.o(.dtors)) 148 | __fini_array_end = .; 149 | __build_id = .; 150 | *(.note.gnu.build-id) 151 | __build_id_end = .; 152 | } > ram 153 | 154 | .rodata1 : { 155 | *(.rodata1) 156 | } > ram 157 | 158 | __data_start = .; 159 | .data : { 160 | *(.a0table) 161 | *(.data .data.* .gnu.linkonce.d.*) 162 | *(.data1) 163 | *(.sdata .sdata.* .gnu.linkonce.s.*) 164 | *(.sdata2 .sdata2.* .gnu.linkonce.s2.*) 165 | *(.got.plt) 166 | *(.got) 167 | /* pad file to be a multiple of 2048 bytes. Needed for loading from CD-ROM. */ 168 | . = ALIGN(2048); 169 | } > ram 170 | 171 | __data_end = .; 172 | __fdata_end = .; 173 | __bss_start = .; 174 | .sbss (NOLOAD) : { 175 | *(.dynsbss) 176 | *(.sbss .sbss.* .gnu.linkonce.sb.*) 177 | *(.scommon) 178 | *(.dynbss) 179 | *(.bss .bss.* .gnu.linkonce.b.*) 180 | *(COMMON) 181 | } > ram 182 | 183 | . = ALIGN(4); 184 | __bss_end = .; 185 | 186 | __heap_start = __heap_base; 187 | 188 | . = ADDR(.text) - 0x800; 189 | __end = .; 190 | 191 | /DISCARD/ : { *(.MIPS.abiflags) } 192 | 193 | /* Everything is statically linked, so discard PLTs. */ 194 | /DISCARD/ : { *(.rel.iplt) *(.rela.iplt) *(.rel.plt) *(.rela.plt) *(.plt) *(.iplt) } 195 | 196 | /* Discard things that the standard link script drops, too. */ 197 | /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } 198 | 199 | .scratchpad (NOLOAD) : { 200 | *(.scratchpad) 201 | } > dcache 202 | } 203 | -------------------------------------------------------------------------------- /third_party/psyq/README.md: -------------------------------------------------------------------------------- 1 | # Conversion of the official Sony libraries 2 | 3 | Using the psyq-obj-parser tool, one can convert the Sony libraries into something usable for modern compilers. This is a bit of complex juggling act, as the original code was compiled with ccpsx, which is an utterly broken compiler. Making everything work fine between this old compiler and a newer gcc is a bit of a round hole square peg situation. Nonetheless, this sorts of works, and it has some advantages for further reverse engineering work. 4 | 5 | ## Extracting the old libraries 6 | 7 | There is a tool in the old toolkit that can be used to extract all object files from a .LIB file: PSYLIBD. Alternatively, the other similar project called psyq2elf contains a dumper for these files: https://gitlab.com/jype/psyq2elf/-/blob/master/src/psyqdump.c 8 | 9 | ## Converting all the files 10 | 11 | Simply compile and run the psyq-obj-parser tool: 12 | 13 | ``` 14 | $ psyq-obj-parser input.obj -o output.o 15 | ``` 16 | 17 | ## Re-creating object files 18 | 19 | The generated object files will be compatible to use by modern gcc, so you can simply use mipsel-linux-elf-ar to re-create .a files: 20 | 21 | ``` 22 | $ mipsel-linux-elf-ar rcs libsomething.a *.o 23 | ``` 24 | 25 | ## Directory structure 26 | 27 | This folder should contain a lib folder and an include folder. It ideally contains the following files: 28 | 29 | ``` 30 | include: 31 | abs.h gtereg.h libcd.h libhmd.h libsnd.h r3000.h string.h 32 | asm.h gtereg_s.h libcomb.h libmath.h libspu.h rand.h strings.h 33 | assert.h inline_a.h libds.h libmcrd.h libtap.h romio.h sys/ 34 | convert.h inline_c.h libetc.h libmcx.h limits.h setjmp.h 35 | ctype.h inline_o.h libgpu.h libpad.h malloc.h stdarg.h 36 | fs.h inline_s.h libgs.h libpress.h mcgui.h stddef.h 37 | gtemac.h kernel.h libgte.h libsio.h memory.h stdio.h 38 | gtenom.h libapi.h libgun.h libsn.h qsort.h stdlib.h 39 | 40 | include/sys: 41 | errno.h fcntl.h file.h ioctl.h types.h 42 | 43 | lib: 44 | libapi.a libcomb.a libgte.a libmcx.a libspu.a poweron.obj.o 45 | libc.a libds.a libgun.a libpad.a libtap.a 46 | libc2.a libetc.a libhmd.a libpress.a mcgui.obj.o 47 | libcard.a libgpu.a libmath.a libsio.a mcgui_e.obj.o 48 | libcd.a libgs.a libmcrd.a libsnd.a noprint.obj.o 49 | ``` 50 | 51 | ## Caveats of the conversion 52 | 53 | The crt0 files (the files typically named 2MBYTE.OBJ, 8MBYTE.OBJ, NOHEAP.OBJ, and NONE3.OBJ) cannot be properly converted. The provided crt0 in the common folder should be providing an appropriate replacement however. 54 | -------------------------------------------------------------------------------- /third_party/psyq/include/inline_n.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GTE Macro definitions - special version for Nugget (NO DMPSX) 3 | */ 4 | 5 | /* 6 | * Type 1 functions 7 | */ 8 | 9 | #define gte_ldv0(r0) \ 10 | __asm__ volatile( \ 11 | "lwc2 $0, 0( %0 );" \ 12 | "lwc2 $1, 4( %0 )" \ 13 | : \ 14 | : "r"(r0)) 15 | 16 | #define gte_ldv1(r0) \ 17 | __asm__ volatile( \ 18 | "lwc2 $2, 0( %0 );" \ 19 | "lwc2 $3, 4( %0 )" \ 20 | : \ 21 | : "r"(r0)) 22 | 23 | #define gte_ldv2(r0) \ 24 | __asm__ volatile( \ 25 | "lwc2 $4, 0( %0 );" \ 26 | "lwc2 $5, 4( %0 )" \ 27 | : \ 28 | : "r"(r0)) 29 | 30 | #define gte_ldv3(r0, r1, r2) \ 31 | __asm__ volatile( \ 32 | "lwc2 $0, 0( %0 );" \ 33 | "lwc2 $1, 4( %0 );" \ 34 | "lwc2 $2, 0( %1 );" \ 35 | "lwc2 $3, 4( %1 );" \ 36 | "lwc2 $4, 0( %2 );" \ 37 | "lwc2 $5, 4( %2 )" \ 38 | : \ 39 | : "r"(r0), "r"(r1), "r"(r2)) 40 | 41 | #define gte_ldv3c(r0) \ 42 | __asm__ volatile( \ 43 | "lwc2 $0, 0( %0 );" \ 44 | "lwc2 $1, 4( %0 );" \ 45 | "lwc2 $2, 8( %0 );" \ 46 | "lwc2 $3, 12( %0 );" \ 47 | "lwc2 $4, 16( %0 );" \ 48 | "lwc2 $5, 20( %0 )" \ 49 | : \ 50 | : "r"(r0)) 51 | 52 | #define gte_ldv3c_vertc(r0) \ 53 | __asm__ volatile( \ 54 | "lwc2 $0, 0( %0 );" \ 55 | "lwc2 $1, 4( %0 );" \ 56 | "lwc2 $2, 12( %0 );" \ 57 | "lwc2 $3, 16( %0 );" \ 58 | "lwc2 $4, 24( %0 );" \ 59 | "lwc2 $5, 28( %0 )" \ 60 | : \ 61 | : "r"(r0)) 62 | 63 | #define gte_ldv01(r0, r1) \ 64 | __asm__ volatile( \ 65 | "lwc2 $0, 0( %0 );" \ 66 | "lwc2 $1, 4( %0 );" \ 67 | "lwc2 $2, 0( %1 );" \ 68 | "lwc2 $3, 4( %1 )" \ 69 | : \ 70 | : "r"(r0), "r"(r1)) 71 | 72 | #define gte_ldv01c(r0) \ 73 | __asm__ volatile( \ 74 | "lwc2 $0, 0( %0 );" \ 75 | "lwc2 $1, 4( %0 );" \ 76 | "lwc2 $2, 8( %0 );" \ 77 | "lwc2 $3, 12( %0 )" \ 78 | : \ 79 | : "r"(r0)) 80 | 81 | #define gte_ldrgb(r0) __asm__ volatile("lwc2 $6, 0( %0 )" : : "r"(r0)) 82 | 83 | #define gte_ldrgb3(r0, r1, r2) \ 84 | __asm__ volatile( \ 85 | "lwc2 $20, 0( %0 );" \ 86 | "lwc2 $21, 0( %1 );" \ 87 | "lwc2 $22, 0( %2 );" \ 88 | "lwc2 $6, 0( %2 )" \ 89 | : \ 90 | : "r"(r0), "r"(r1), "r"(r2)) 91 | 92 | #define gte_ldrgb3c(r0) \ 93 | __asm__ volatile( \ 94 | "lwc2 $20, 0( %0 );" \ 95 | "lwc2 $21, 4( %0 );" \ 96 | "lwc2 $22, 8( %0 );" \ 97 | "lwc2 $6, 8( %0 )" \ 98 | : \ 99 | : "r"(r0)) 100 | 101 | #define gte_ldlv0(r0) \ 102 | __asm__ volatile( \ 103 | "lhu $13, 4( %0 );" \ 104 | "lhu $12, 0( %0 );" \ 105 | "sll $13, $13, 16;" \ 106 | "or $12, $12, $13;" \ 107 | "mtc2 $12, $0;" \ 108 | "lwc2 $1, 8( %0 )" \ 109 | : \ 110 | : "r"(r0) \ 111 | : "$12", "$13") 112 | 113 | #define gte_ldlvl(r0) \ 114 | __asm__ volatile( \ 115 | "lwc2 $9, 0( %0 );" \ 116 | "lwc2 $10, 4( %0 );" \ 117 | "lwc2 $11, 8( %0 )" \ 118 | : \ 119 | : "r"(r0)) 120 | 121 | #define gte_ldsv(r0) \ 122 | __asm__ volatile( \ 123 | "lhu $12, 0( %0 );" \ 124 | "lhu $13, 2( %0 );" \ 125 | "lhu $14, 4( %0 );" \ 126 | "mtc2 $12, $9;" \ 127 | "mtc2 $13, $10;" \ 128 | "mtc2 $14, $11" \ 129 | : \ 130 | : "r"(r0) \ 131 | : "$12", "$13", "$14") 132 | 133 | #define gte_ldbv(r0) \ 134 | __asm__ volatile( \ 135 | "lbu $12, 0( %0 );" \ 136 | "lbu $13, 1( %0 );" \ 137 | "mtc2 $12, $9;" \ 138 | "mtc2 $13, $10" \ 139 | : \ 140 | : "r"(r0) \ 141 | : "$12", "$13") 142 | 143 | #define gte_ldcv(r0) \ 144 | __asm__ volatile( \ 145 | "lbu $12, 0( %0 );" \ 146 | "lbu $13, 1( %0 );" \ 147 | "lbu $14, 2( %0 );" \ 148 | "mtc2 $12, $9;" \ 149 | "mtc2 $13, $10;" \ 150 | "mtc2 $14, $11" \ 151 | : \ 152 | : "r"(r0) \ 153 | : "$12", "$13", "$14") 154 | 155 | #define gte_ldclmv(r0) \ 156 | __asm__ volatile( \ 157 | "lhu $12, 0( %0 );" \ 158 | "lhu $13, 6( %0 );" \ 159 | "lhu $14, 12( %0 );" \ 160 | "mtc2 $12, $9;" \ 161 | "mtc2 $13, $10;" \ 162 | "mtc2 $14, $11" \ 163 | : \ 164 | : "r"(r0) \ 165 | : "$12", "$13", "$14") 166 | 167 | #define gte_lddp(r0) __asm__ volatile("mtc2 %0, $8" : : "r"(r0)) 168 | 169 | #define gte_ldsxy0(r0) __asm__ volatile("mtc2 %0, $12" : : "r"(r0)) 170 | 171 | #define gte_ldsxy1(r0) __asm__ volatile("mtc2 %0, $13" : : "r"(r0)) 172 | 173 | #define gte_ldsxy2(r0) __asm__ volatile("mtc2 %0, $14" : : "r"(r0)) 174 | 175 | #define gte_ldsxy3(r0, r1, r2) \ 176 | __asm__ volatile( \ 177 | "mtc2 %0, $12;" \ 178 | "mtc2 %2, $14;" \ 179 | "mtc2 %1, $13" \ 180 | : \ 181 | : "r"(r0), "r"(r1), "r"(r2)) 182 | 183 | #define gte_ldsxy3c(r0) \ 184 | __asm__ volatile( \ 185 | "lwc2 $12, 0( %0 );" \ 186 | "lwc2 $13, 4( %0 );" \ 187 | "lwc2 $14, 8( %0 )" \ 188 | : \ 189 | : "r"(r0)) 190 | 191 | #define gte_ldsz3(r0, r1, r2) \ 192 | __asm__ volatile( \ 193 | "mtc2 %0, $17;" \ 194 | "mtc2 %1, $18;" \ 195 | "mtc2 %2, $19" \ 196 | : \ 197 | : "r"(r0), "r"(r1), "r"(r2)) 198 | 199 | #define gte_ldsz4(r0, r1, r2, r3) \ 200 | __asm__ volatile( \ 201 | "mtc2 %0, $16;" \ 202 | "mtc2 %1, $17;" \ 203 | "mtc2 %2, $18;" \ 204 | "mtc2 %3, $19" \ 205 | : \ 206 | : "r"(r0), "r"(r1), "r"(r2), "r"(r3)) 207 | 208 | #define gte_ldopv1(r0) \ 209 | __asm__ volatile( \ 210 | "lw $12, 0( %0 );" \ 211 | "lw $13, 4( %0 );" \ 212 | "ctc2 $12, $0;" \ 213 | "lw $14, 8( %0 );" \ 214 | "ctc2 $13, $2;" \ 215 | "ctc2 $14, $4" \ 216 | : \ 217 | : "r"(r0) \ 218 | : "$12", "$13", "$14") 219 | 220 | #define gte_ldopv2(r0) \ 221 | __asm__ volatile( \ 222 | "lwc2 $11, 8( %0 );" \ 223 | "lwc2 $9, 0( %0 );" \ 224 | "lwc2 $10, 4( %0 )" \ 225 | : \ 226 | : "r"(r0)) 227 | 228 | #define gte_ldlzc(r0) __asm__ volatile("mtc2 %0, $30" : : "r"(r0)) 229 | 230 | #define gte_SetRGBcd(r0) __asm__ volatile("lwc2 $6, 0( %0 )" : : "r"(r0)) 231 | 232 | #define gte_ldbkdir(r0, r1, r2) \ 233 | __asm__ volatile( \ 234 | "ctc2 %0, $13;" \ 235 | "ctc2 %1, $14;" \ 236 | "ctc2 %2, $15" \ 237 | : \ 238 | : "r"(r0), "r"(r1), "r"(r2)) 239 | 240 | #define gte_SetBackColor(r0, r1, r2) \ 241 | __asm__ volatile( \ 242 | "sll $12, %0, 4;" \ 243 | "sll $13, %1, 4;" \ 244 | "sll $14, %2, 4;" \ 245 | "ctc2 $12, $13;" \ 246 | "ctc2 $13, $14;" \ 247 | "ctc2 $14, $15" \ 248 | : \ 249 | : "r"(r0), "r"(r1), "r"(r2) \ 250 | : "$12", "$13", "$14") 251 | 252 | #define gte_ldfcdir(r0, r1, r2) \ 253 | __asm__ volatile( \ 254 | "ctc2 %0, $21;" \ 255 | "ctc2 %1, $22;" \ 256 | "ctc2 %2, $23" \ 257 | : \ 258 | : "r"(r0), "r"(r1), "r"(r2)) 259 | 260 | #define gte_SetFarColor(r0, r1, r2) \ 261 | __asm__ volatile( \ 262 | "sll $12, %0, 4;" \ 263 | "sll $13, %1, 4;" \ 264 | "sll $14, %2, 4;" \ 265 | "ctc2 $12, $21;" \ 266 | "ctc2 $13, $22;" \ 267 | "ctc2 $14, $23" \ 268 | : \ 269 | : "r"(r0), "r"(r1), "r"(r2) \ 270 | : "$12", "$13", "$14") 271 | 272 | #define gte_SetGeomOffset(r0, r1) \ 273 | __asm__ volatile( \ 274 | "sll $12, %0, 16;" \ 275 | "sll $13, %1, 16;" \ 276 | "ctc2 $12, $24;" \ 277 | "ctc2 $13, $25" \ 278 | : \ 279 | : "r"(r0), "r"(r1) \ 280 | : "$12", "$13") 281 | 282 | #define gte_SetGeomScreen(r0) __asm__ volatile("ctc2 %0, $26" : : "r"(r0)) 283 | 284 | #define gte_ldsvrtrow0(r0) \ 285 | __asm__ volatile( \ 286 | "lw $12, 0( %0 );" \ 287 | "lw $13, 4( %0 );" \ 288 | "ctc2 $12, $0;" \ 289 | "ctc2 $13, $1" \ 290 | : \ 291 | : "r"(r0) \ 292 | : "$12", "$13") 293 | 294 | #define gte_SetRotMatrix(r0) \ 295 | __asm__ volatile( \ 296 | "lw $12, 0( %0 );" \ 297 | "lw $13, 4( %0 );" \ 298 | "ctc2 $12, $0;" \ 299 | "ctc2 $13, $1;" \ 300 | "lw $12, 8( %0 );" \ 301 | "lw $13, 12( %0 );" \ 302 | "lw $14, 16( %0 );" \ 303 | "ctc2 $12, $2;" \ 304 | "ctc2 $13, $3;" \ 305 | "ctc2 $14, $4" \ 306 | : \ 307 | : "r"(r0) \ 308 | : "$12", "$13", "$14") 309 | 310 | #define gte_ldsvllrow0(r0) \ 311 | __asm__ volatile( \ 312 | "lw $12, 0( %0 );" \ 313 | "lw $13, 4( %0 );" \ 314 | "ctc2 $12, $8;" \ 315 | "ctc2 $13, $9" \ 316 | : \ 317 | : "r"(r0) \ 318 | : "$12", "$13") 319 | 320 | #define gte_SetLightMatrix(r0) \ 321 | __asm__ volatile( \ 322 | "lw $12, 0( %0 );" \ 323 | "lw $13, 4( %0 );" \ 324 | "ctc2 $12, $8;" \ 325 | "ctc2 $13, $9;" \ 326 | "lw $12, 8( %0 );" \ 327 | "lw $13, 12( %0 );" \ 328 | "lw $14, 16( %0 );" \ 329 | "ctc2 $12, $10;" \ 330 | "ctc2 $13, $11;" \ 331 | "ctc2 $14, $12" \ 332 | : \ 333 | : "r"(r0) \ 334 | : "$12", "$13", "$14") 335 | 336 | #define gte_ldsvlcrow0(r0) \ 337 | __asm__ volatile( \ 338 | "lw $12, 0( %0 );" \ 339 | "lw $13, 4( %0 );" \ 340 | "ctc2 $12, $16;" \ 341 | "ctc2 $13, $17" \ 342 | : \ 343 | : "r"(r0) \ 344 | : "$12", "$13") 345 | 346 | #define gte_SetColorMatrix(r0) \ 347 | __asm__ volatile( \ 348 | "lw $12, 0( %0 );" \ 349 | "lw $13, 4( %0 );" \ 350 | "ctc2 $12, $16;" \ 351 | "ctc2 $13, $17;" \ 352 | "lw $12, 8( %0 );" \ 353 | "lw $13, 12( %0 );" \ 354 | "lw $14, 16( %0 );" \ 355 | "ctc2 $12, $18;" \ 356 | "ctc2 $13, $19;" \ 357 | "ctc2 $14, $20" \ 358 | : \ 359 | : "r"(r0) \ 360 | : "$12", "$13", "$14") 361 | 362 | #define gte_SetTransMatrix(r0) \ 363 | __asm__ volatile( \ 364 | "lw $12, 20( %0 );" \ 365 | "lw $13, 24( %0 );" \ 366 | "ctc2 $12, $5;" \ 367 | "lw $14, 28( %0 );" \ 368 | "ctc2 $13, $6;" \ 369 | "ctc2 $14, $7" \ 370 | : \ 371 | : "r"(r0) \ 372 | : "$12", "$13", "$14") 373 | 374 | #define gte_ldtr(r0, r1, r2) \ 375 | __asm__ volatile( \ 376 | "ctc2 %0, $5;" \ 377 | "ctc2 %1, $6;" \ 378 | "ctc2 %2, $7" \ 379 | : \ 380 | : "r"(r0), "r"(r1), "r"(r2)) 381 | 382 | #define gte_SetTransVector(r0) \ 383 | __asm__ volatile( \ 384 | "lw $12, 0( %0 );" \ 385 | "lw $13, 4( %0 );" \ 386 | "lw $14, 8( %0 );" \ 387 | "ctc2 $12, $5;" \ 388 | "ctc2 $13, $6;" \ 389 | "ctc2 $14, $7" \ 390 | : \ 391 | : "r"(r0) \ 392 | : "$12", "$13", "$14") 393 | 394 | #define gte_ld_intpol_uv0(r0) \ 395 | __asm__ volatile( \ 396 | "lbu $12, 0( %0 );" \ 397 | "lbu $13, 1( %0 );" \ 398 | "ctc2 $12, $21;" \ 399 | "ctc2 $13, $22" \ 400 | : \ 401 | : "r"(r0) \ 402 | : "$12", "$13") 403 | 404 | #define gte_ld_intpol_uv1(r0) \ 405 | __asm__ volatile( \ 406 | "lbu $12, 0( %0 );" \ 407 | "lbu $13, 1( %0 );" \ 408 | "mtc2 $12, $9;" \ 409 | "mtc2 $13, $10" \ 410 | : \ 411 | : "r"(r0) \ 412 | : "$12", "$13") 413 | 414 | #define gte_ld_intpol_bv0(r0) \ 415 | __asm__ volatile( \ 416 | "lbu $12, 0( %0 );" \ 417 | "lbu $13, 1( %0 );" \ 418 | "ctc2 $12, $21;" \ 419 | "ctc2 $13, $22" \ 420 | : \ 421 | : "r"(r0) \ 422 | : "$12", "$13") 423 | 424 | #define gte_ld_intpol_bv1(r0) \ 425 | __asm__ volatile( \ 426 | "lbu $12, 0( %0 );" \ 427 | "lbu $13, 1( %0 );" \ 428 | "mtc2 $12, $9;" \ 429 | "mtc2 $13, $10" \ 430 | : \ 431 | : "r"(r0) \ 432 | : "$12", "$13") 433 | 434 | #define gte_ld_intpol_sv0(r0) \ 435 | __asm__ volatile( \ 436 | "lh $12, 0( %0 );" \ 437 | "lh $13, 2( %0 );" \ 438 | "lh $14, 4( %0 );" \ 439 | "ctc2 $12, $21;" \ 440 | "ctc2 $13, $22;" \ 441 | "ctc2 $14, $23" \ 442 | : \ 443 | : "r"(r0) \ 444 | : "$12", "$13", "$14") 445 | 446 | #define gte_ld_intpol_sv1(r0) \ 447 | __asm__ volatile( \ 448 | "lh $12, 0( %0 );" \ 449 | "lh $13, 2( %0 );" \ 450 | "lh $14, 4( %0 );" \ 451 | "mtc2 $12, $9;" \ 452 | "mtc2 $13, $10;" \ 453 | "mtc2 $14, $11" \ 454 | : \ 455 | : "r"(r0) \ 456 | : "$12", "$13", "$14") 457 | 458 | #define gte_ldfc(r0) \ 459 | __asm__ volatile( \ 460 | "lw $12, 0( %0 );" \ 461 | "lw $13, 4( %0 );" \ 462 | "lw $14, 8( %0 );" \ 463 | "ctc2 $12, $21;" \ 464 | "ctc2 $13, $22;" \ 465 | "ctc2 $14, $23" \ 466 | : \ 467 | : "r"(r0) \ 468 | : "$12", "$13", "$14") 469 | 470 | #define gte_ldopv2SV(r0) \ 471 | __asm__ volatile( \ 472 | "lh $12, 0( %0 );" \ 473 | "lh $13, 2( %0 );" \ 474 | "lh $14, 4( %0 );" \ 475 | "mtc2 $12, $9;" \ 476 | "mtc2 $13, $10;" \ 477 | "mtc2 $14, $11" \ 478 | : \ 479 | : "r"(r0) \ 480 | : "$12", "$13", "$14") 481 | 482 | #define gte_ldopv1SV(r0) \ 483 | __asm__ volatile( \ 484 | "lh $12, 0( %0 );" \ 485 | "lh $13, 2( %0 );" \ 486 | "ctc2 $12, $0;" \ 487 | "lh $14, 4( %0 );" \ 488 | "ctc2 $13, $2;" \ 489 | "ctc2 $14, $4" \ 490 | : \ 491 | : "r"(r0) \ 492 | : "$12", "$13", "$14") 493 | 494 | /* 495 | * Type 2 functions 496 | */ 497 | 498 | #define gte_rtps() \ 499 | __asm__ volatile( \ 500 | "nop;" \ 501 | "nop;" \ 502 | "cop2 0x0180001;") 503 | 504 | #define gte_rtpt() \ 505 | __asm__ volatile( \ 506 | "nop;" \ 507 | "nop;" \ 508 | "cop2 0x0280030;") 509 | 510 | #define gte_rt() \ 511 | __asm__ volatile( \ 512 | "nop;" \ 513 | "nop;" \ 514 | "cop2 0x0480012;") 515 | 516 | #define gte_rtv0() \ 517 | __asm__ volatile( \ 518 | "nop;" \ 519 | "nop;" \ 520 | "cop2 0x0486012;") 521 | 522 | #define gte_rtv1() \ 523 | __asm__ volatile( \ 524 | "nop;" \ 525 | "nop;" \ 526 | "cop2 0x048E012;") 527 | 528 | #define gte_rtv2() \ 529 | __asm__ volatile( \ 530 | "nop;" \ 531 | "nop;" \ 532 | "cop2 0x0496012;") 533 | 534 | #define gte_rtir() \ 535 | __asm__ volatile( \ 536 | "nop;" \ 537 | "nop;" \ 538 | "cop2 0x049E012;") 539 | 540 | #define gte_rtir_sf0() \ 541 | __asm__ volatile( \ 542 | "nop;" \ 543 | "nop;" \ 544 | "cop2 0x041E012;") 545 | 546 | #define gte_rtv0tr() \ 547 | __asm__ volatile( \ 548 | "nop;" \ 549 | "nop;" \ 550 | "cop2 0x0480012;") 551 | 552 | #define gte_rtv1tr() \ 553 | __asm__ volatile( \ 554 | "nop;" \ 555 | "nop;" \ 556 | "cop2 0x0488012;") 557 | 558 | #define gte_rtv2tr() \ 559 | __asm__ volatile( \ 560 | "nop;" \ 561 | "nop;" \ 562 | "cop2 0x0490012;") 563 | 564 | #define gte_rtirtr() \ 565 | __asm__ volatile( \ 566 | "nop;" \ 567 | "nop;" \ 568 | "cop2 0x0498012;") 569 | 570 | #define gte_rtv0bk() \ 571 | __asm__ volatile( \ 572 | "nop;" \ 573 | "nop;" \ 574 | "cop2 0x0482012;") 575 | 576 | #define gte_rtv1bk() \ 577 | __asm__ volatile( \ 578 | "nop;" \ 579 | "nop;" \ 580 | "cop2 0x048A012;") 581 | 582 | #define gte_rtv2bk() \ 583 | __asm__ volatile( \ 584 | "nop;" \ 585 | "nop;" \ 586 | "cop2 0x0492012;") 587 | 588 | #define gte_rtirbk() \ 589 | __asm__ volatile( \ 590 | "nop;" \ 591 | "nop;" \ 592 | "cop2 0x049A012;") 593 | 594 | #define gte_ll() \ 595 | __asm__ volatile( \ 596 | "nop;" \ 597 | "nop;" \ 598 | "cop2 0x04A6412;") 599 | 600 | #define gte_llv0() \ 601 | __asm__ volatile( \ 602 | "nop;" \ 603 | "nop;" \ 604 | "cop2 0x04A6012;") 605 | 606 | #define gte_llv1() \ 607 | __asm__ volatile( \ 608 | "nop;" \ 609 | "nop;" \ 610 | "cop2 0x04AE012;") 611 | 612 | #define gte_llv2() \ 613 | __asm__ volatile( \ 614 | "nop;" \ 615 | "nop;" \ 616 | "cop2 0x04B6012;") 617 | 618 | #define gte_llir() \ 619 | __asm__ volatile( \ 620 | "nop;" \ 621 | "nop;" \ 622 | "cop2 0x04BE012;") 623 | 624 | #define gte_llv0tr() \ 625 | __asm__ volatile( \ 626 | "nop;" \ 627 | "nop;" \ 628 | "cop2 0x04A0012;") 629 | 630 | #define gte_llv1tr() \ 631 | __asm__ volatile( \ 632 | "nop;" \ 633 | "nop;" \ 634 | "cop2 0x04A8012;") 635 | 636 | #define gte_llv2tr() \ 637 | __asm__ volatile( \ 638 | "nop;" \ 639 | "nop;" \ 640 | "cop2 0x04B0012;") 641 | 642 | #define gte_llirtr() \ 643 | __asm__ volatile( \ 644 | "nop;" \ 645 | "nop;" \ 646 | "cop2 0x04B8012;") 647 | 648 | #define gte_llv0bk() \ 649 | __asm__ volatile( \ 650 | "nop;" \ 651 | "nop;" \ 652 | "cop2 0x04A2012;") 653 | 654 | #define gte_llv1bk() \ 655 | __asm__ volatile( \ 656 | "nop;" \ 657 | "nop;" \ 658 | "cop2 0x04AA012;") 659 | 660 | #define gte_llv2bk() \ 661 | __asm__ volatile( \ 662 | "nop;" \ 663 | "nop;" \ 664 | "cop2 0x04B2012;") 665 | 666 | #define gte_llirbk() \ 667 | __asm__ volatile( \ 668 | "nop;" \ 669 | "nop;" \ 670 | "cop2 0x04BA012;") 671 | 672 | #define gte_lc() \ 673 | __asm__ volatile( \ 674 | "nop;" \ 675 | "nop;" \ 676 | "cop2 0x04DA412;") 677 | 678 | #define gte_lcv0() \ 679 | __asm__ volatile( \ 680 | "nop;" \ 681 | "nop;" \ 682 | "cop2 0x04C6012;") 683 | 684 | #define gte_lcv1() \ 685 | __asm__ volatile( \ 686 | "nop;" \ 687 | "nop;" \ 688 | "cop2 0x04CE012;") 689 | 690 | #define gte_lcv2() \ 691 | __asm__ volatile( \ 692 | "nop;" \ 693 | "nop;" \ 694 | "cop2 0x04D6012;") 695 | 696 | #define gte_lcir() \ 697 | __asm__ volatile( \ 698 | "nop;" \ 699 | "nop;" \ 700 | "cop2 0x04DE012;") 701 | 702 | #define gte_lcv0tr() \ 703 | __asm__ volatile( \ 704 | "nop;" \ 705 | "nop;" \ 706 | "cop2 0x04C0012;") 707 | 708 | #define gte_lcv1tr() \ 709 | __asm__ volatile( \ 710 | "nop;" \ 711 | "nop;" \ 712 | "cop2 0x04C8012;") 713 | 714 | #define gte_lcv2tr() \ 715 | __asm__ volatile( \ 716 | "nop;" \ 717 | "nop;" \ 718 | "cop2 0x04D0012;") 719 | 720 | #define gte_lcirtr() \ 721 | __asm__ volatile( \ 722 | "nop;" \ 723 | "nop;" \ 724 | "cop2 0x04D8012;") 725 | 726 | #define gte_lcv0bk() \ 727 | __asm__ volatile( \ 728 | "nop;" \ 729 | "nop;" \ 730 | "cop2 0x04C2012;") 731 | 732 | #define gte_lcv1bk() \ 733 | __asm__ volatile( \ 734 | "nop;" \ 735 | "nop;" \ 736 | "cop2 0x04CA012;") 737 | 738 | #define gte_lcv2bk() \ 739 | __asm__ volatile( \ 740 | "nop;" \ 741 | "nop;" \ 742 | "cop2 0x04D2012;") 743 | 744 | #define gte_lcirbk() \ 745 | __asm__ volatile( \ 746 | "nop;" \ 747 | "nop;" \ 748 | "cop2 0x04DA012;") 749 | 750 | #define gte_dpcl() \ 751 | __asm__ volatile( \ 752 | "nop;" \ 753 | "nop;" \ 754 | "cop2 0x0680029;") 755 | 756 | #define gte_dpcs() \ 757 | __asm__ volatile( \ 758 | "nop;" \ 759 | "nop;" \ 760 | "cop2 0x0780010;") 761 | 762 | #define gte_dpct() \ 763 | __asm__ volatile( \ 764 | "nop;" \ 765 | "nop;" \ 766 | "cop2 0x0F8002A;") 767 | 768 | #define gte_intpl() \ 769 | __asm__ volatile( \ 770 | "nop;" \ 771 | "nop;" \ 772 | "cop2 0x0980011;") 773 | 774 | #define gte_sqr12() \ 775 | __asm__ volatile( \ 776 | "nop;" \ 777 | "nop;" \ 778 | "cop2 0x0A80428;") 779 | 780 | #define gte_sqr0() \ 781 | __asm__ volatile( \ 782 | "nop;" \ 783 | "nop;" \ 784 | "cop2 0x0A00428;") 785 | 786 | #define gte_ncs() \ 787 | __asm__ volatile( \ 788 | "nop;" \ 789 | "nop;" \ 790 | "cop2 0x0C8041E;") 791 | 792 | #define gte_nct() \ 793 | __asm__ volatile( \ 794 | "nop;" \ 795 | "nop;" \ 796 | "cop2 0x0D80420;") 797 | 798 | #define gte_ncds() \ 799 | __asm__ volatile( \ 800 | "nop;" \ 801 | "nop;" \ 802 | "cop2 0x0E80413;") 803 | 804 | #define gte_ncdt() \ 805 | __asm__ volatile( \ 806 | "nop;" \ 807 | "nop;" \ 808 | "cop2 0x0F80416;") 809 | 810 | #define gte_nccs() \ 811 | __asm__ volatile( \ 812 | "nop;" \ 813 | "nop;" \ 814 | "cop2 0x0108041B;") 815 | 816 | #define gte_ncct() \ 817 | __asm__ volatile( \ 818 | "nop;" \ 819 | "nop;" \ 820 | "cop2 0x0118043F;") 821 | 822 | #define gte_cdp() \ 823 | __asm__ volatile( \ 824 | "nop;" \ 825 | "nop;" \ 826 | "cop2 0x01280414;") 827 | 828 | #define gte_cc() \ 829 | __asm__ volatile( \ 830 | "nop;" \ 831 | "nop;" \ 832 | "cop2 0x0138041C;") 833 | 834 | #define gte_nclip() \ 835 | __asm__ volatile( \ 836 | "nop;" \ 837 | "nop;" \ 838 | "cop2 0x01400006;") 839 | 840 | #define gte_avsz3() \ 841 | __asm__ volatile( \ 842 | "nop;" \ 843 | "nop;" \ 844 | "cop2 0x0158002D;") 845 | 846 | #define gte_avsz4() \ 847 | __asm__ volatile( \ 848 | "nop;" \ 849 | "nop;" \ 850 | "cop2 0x0168002E;") 851 | 852 | #define gte_op12() \ 853 | __asm__ volatile( \ 854 | "nop;" \ 855 | "nop;" \ 856 | "cop2 0x0178000C;") 857 | 858 | #define gte_op0() \ 859 | __asm__ volatile( \ 860 | "nop;" \ 861 | "nop;" \ 862 | "cop2 0x0170000C;") 863 | 864 | #define gte_gpf12() \ 865 | __asm__ volatile( \ 866 | "nop;" \ 867 | "nop;" \ 868 | "cop2 0x0198003D;") 869 | 870 | #define gte_gpf0() \ 871 | __asm__ volatile( \ 872 | "nop;" \ 873 | "nop;" \ 874 | "cop2 0x0190003D;") 875 | 876 | #define gte_gpl12() \ 877 | __asm__ volatile( \ 878 | "nop;" \ 879 | "nop;" \ 880 | "cop2 0x01A8003E;") 881 | 882 | #define gte_gpl0() \ 883 | __asm__ volatile( \ 884 | "nop;" \ 885 | "nop;" \ 886 | "cop2 0x01A0003E0") 887 | 888 | #define gte_mvmva_core(r0) \ 889 | __asm__ volatile( \ 890 | "nop;" \ 891 | "nop;" \ 892 | "cop2 %0" \ 893 | : \ 894 | : "g"(r0)) 895 | 896 | #define gte_mvmva(sf, mx, v, cv, lm) \ 897 | gte_mvmva_core(0x0400012 | ((sf) << 19) | ((mx) << 17) | ((v) << 15) | ((cv) << 13) | ((lm) << 10)) 898 | 899 | /* 900 | * Type 2 functions without nop 901 | */ 902 | 903 | #define gte_rtps_b() __asm__ volatile("cop2 0x0180001;") 904 | #define gte_rtpt_b() __asm__ volatile("cop2 0x0280030;") 905 | #define gte_rt_b() __asm__ volatile("cop2 0x0480012;") 906 | #define gte_rtv0_b() __asm__ volatile("cop2 0x0486012;") 907 | #define gte_rtv1_b() __asm__ volatile("cop2 0x048E012;") 908 | #define gte_rtv2_b() __asm__ volatile("cop2 0x0496012;") 909 | #define gte_rtir_b() __asm__ volatile("cop2 0x049E012;") 910 | #define gte_rtir_sf0_b() __asm__ volatile("cop2 0x041E012;") 911 | #define gte_rtv0tr_b() __asm__ volatile("cop2 0x0480012;") 912 | #define gte_rtv1tr_b() __asm__ volatile("cop2 0x0488012;") 913 | #define gte_rtv2tr_b() __asm__ volatile("cop2 0x0490012;") 914 | #define gte_rtirtr_b() __asm__ volatile("cop2 0x0498012;") 915 | #define gte_rtv0bk_b() __asm__ volatile("cop2 0x0482012;") 916 | #define gte_rtv1bk_b() __asm__ volatile("cop2 0x048A012;") 917 | #define gte_rtv2bk_b() __asm__ volatile("cop2 0x0492012;") 918 | #define gte_rtirbk_b() __asm__ volatile("cop2 0x049A012;") 919 | #define gte_ll_b() __asm__ volatile("cop2 0x04A6412;") 920 | #define gte_llv0_b() __asm__ volatile("cop2 0x04A6012;") 921 | #define gte_llv1_b() __asm__ volatile("cop2 0x04AE012;") 922 | #define gte_llv2_b() __asm__ volatile("cop2 0x04B6012;") 923 | #define gte_llir_b() __asm__ volatile("cop2 0x04BE012;") 924 | #define gte_llv0tr_b() __asm__ volatile("cop2 0x04A0012;") 925 | #define gte_llv1tr_b() __asm__ volatile("cop2 0x04A8012;") 926 | #define gte_llv2tr_b() __asm__ volatile("cop2 0x04B0012;") 927 | #define gte_llirtr_b() __asm__ volatile("cop2 0x04B8012;") 928 | #define gte_llv0bk_b() __asm__ volatile("cop2 0x04A2012;") 929 | #define gte_llv1bk_b() __asm__ volatile("cop2 0x04AA012;") 930 | #define gte_llv2bk_b() __asm__ volatile("cop2 0x04B2012;") 931 | #define gte_llirbk_b() __asm__ volatile("cop2 0x04BA012;") 932 | #define gte_lc_b() __asm__ volatile("cop2 0x04DA412;") 933 | #define gte_lcv0_b() __asm__ volatile("cop2 0x04C6012;") 934 | #define gte_lcv1_b() __asm__ volatile("cop2 0x04CE012;") 935 | #define gte_lcv2_b() __asm__ volatile("cop2 0x04D6012;") 936 | #define gte_lcir_b() __asm__ volatile("cop2 0x04DE012;") 937 | #define gte_lcv0tr_b() __asm__ volatile("cop2 0x04C0012;") 938 | #define gte_lcv1tr_b() __asm__ volatile("cop2 0x04C8012;") 939 | #define gte_lcv2tr_b() __asm__ volatile("cop2 0x04D0012;") 940 | #define gte_lcirtr_b() __asm__ volatile("cop2 0x04D8012;") 941 | #define gte_lcv0bk_b() __asm__ volatile("cop2 0x04C2012;") 942 | #define gte_lcv1bk_b() __asm__ volatile("cop2 0x04CA012;") 943 | #define gte_lcv2bk_b() __asm__ volatile("cop2 0x04D2012;") 944 | #define gte_lcirbk_b() __asm__ volatile("cop2 0x04DA012;") 945 | #define gte_dpcl_b() __asm__ volatile("cop2 0x0680029;") 946 | #define gte_dpcs_b() __asm__ volatile("cop2 0x0780010;") 947 | #define gte_dpct_b() __asm__ volatile("cop2 0x0F8002A;") 948 | #define gte_intpl_b() __asm__ volatile("cop2 0x0980011;") 949 | #define gte_sqr12_b() __asm__ volatile("cop2 0x0A80428;") 950 | #define gte_sqr0_b() __asm__ volatile("cop2 0x0A00428;") 951 | #define gte_ncs_b() __asm__ volatile("cop2 0x0C8041E;") 952 | #define gte_nct_b() __asm__ volatile("cop2 0x0D80420;") 953 | #define gte_ncds_b() __asm__ volatile("cop2 0x0E80413;") 954 | #define gte_ncdt_b() __asm__ volatile("cop2 0x0F80416;") 955 | #define gte_nccs_b() __asm__ volatile("cop2 0x0108041B;") 956 | #define gte_ncct_b() __asm__ volatile("cop2 0x0118043F;") 957 | #define gte_cdp_b() __asm__ volatile("cop2 0x01280414;") 958 | #define gte_cc_b() __asm__ volatile("cop2 0x0138041C;") 959 | #define gte_nclip_b() __asm__ volatile("cop2 0x01400006;") 960 | #define gte_avsz3_b() __asm__ volatile("cop2 0x0158002D;") 961 | #define gte_avsz4_b() __asm__ volatile("cop2 0x0168002E;") 962 | #define gte_op12_b() __asm__ volatile("cop2 0x0178000C;") 963 | #define gte_op0_b() __asm__ volatile("cop2 0x0170000C;") 964 | #define gte_gpf12_b() __asm__ volatile("cop2 0x0198003D;") 965 | #define gte_gpf0_b() __asm__ volatile("cop2 0x0190003D;") 966 | #define gte_gpl12_b() __asm__ volatile("cop2 0x01A8003E;") 967 | #define gte_gpl0_b() __asm__ volatile("cop2 0x01A0003E0;") 968 | #define gte_mvmva_core_b(r0) __asm__ volatile("cop2 %0" : : "g"(r0)) 969 | #define gte_mvmva_b(sf, mx, v, cv, lm) \ 970 | gte_mvmva_core_b(0x0400012 | ((sf) << 19) | ((mx) << 17) | ((v) << 15) | ((cv) << 13) | ((lm) << 10)) 971 | 972 | /* 973 | * Type 3 functions 974 | */ 975 | 976 | #define gte_stsxy(r0) __asm__ volatile("swc2 $14, 0( %0 )" : : "r"(r0) : "memory") 977 | 978 | #define gte_stsxy3(r0, r1, r2) \ 979 | __asm__ volatile( \ 980 | "swc2 $12, 0( %0 );" \ 981 | "swc2 $13, 0( %1 );" \ 982 | "swc2 $14, 0( %2 )" \ 983 | : \ 984 | : "r"(r0), "r"(r1), "r"(r2) \ 985 | : "memory") 986 | 987 | #define gte_stsxy3c(r0) \ 988 | __asm__ volatile( \ 989 | "swc2 $12, 0( %0 );" \ 990 | "swc2 $13, 4( %0 );" \ 991 | "swc2 $14, 8( %0 )" \ 992 | : \ 993 | : "r"(r0) \ 994 | : "memory") 995 | 996 | #define gte_stsxy2(r0) __asm__ volatile("swc2 $14, 0( %0 )" : : "r"(r0) : "memory") 997 | 998 | #define gte_stsxy1(r0) __asm__ volatile("swc2 $13, 0( %0 )" : : "r"(r0) : "memory") 999 | 1000 | #define gte_stsxy0(r0) __asm__ volatile("swc2 $12, 0( %0 )" : : "r"(r0) : "memory") 1001 | 1002 | #define gte_stsxy01(r0, r1) \ 1003 | __asm__ volatile( \ 1004 | "swc2 $12, 0( %0 );" \ 1005 | "swc2 $13, 0( %1 )" \ 1006 | : \ 1007 | : "r"(r0), "r"(r1) \ 1008 | : "memory") 1009 | 1010 | #define gte_stsxy01c(r0) \ 1011 | __asm__ volatile( \ 1012 | "swc2 $12, 0( %0 );" \ 1013 | "swc2 $13, 4( %0 )" \ 1014 | : \ 1015 | : "r"(r0) \ 1016 | : "memory") 1017 | 1018 | #define gte_stsxy3_f3(r0) \ 1019 | __asm__ volatile( \ 1020 | "swc2 $12, 8( %0 );" \ 1021 | "swc2 $13, 12( %0 );" \ 1022 | "swc2 $14, 16( %0 )" \ 1023 | : \ 1024 | : "r"(r0) \ 1025 | : "memory") 1026 | 1027 | #define gte_stsxy3_g3(r0) \ 1028 | __asm__ volatile( \ 1029 | "swc2 $12, 8( %0 );" \ 1030 | "swc2 $13, 16( %0 );" \ 1031 | "swc2 $14, 24( %0 )" \ 1032 | : \ 1033 | : "r"(r0) \ 1034 | : "memory") 1035 | 1036 | #define gte_stsxy3_ft3(r0) \ 1037 | __asm__ volatile( \ 1038 | "swc2 $12, 8( %0 );" \ 1039 | "swc2 $13, 16( %0 );" \ 1040 | "swc2 $14, 24( %0 )" \ 1041 | : \ 1042 | : "r"(r0) \ 1043 | : "memory") 1044 | 1045 | #define gte_stsxy3_gt3(r0) \ 1046 | __asm__ volatile( \ 1047 | "swc2 $12, 8( %0 );" \ 1048 | "swc2 $13, 20( %0 );" \ 1049 | "swc2 $14, 32( %0 )" \ 1050 | : \ 1051 | : "r"(r0) \ 1052 | : "memory") 1053 | 1054 | #define gte_stsxy3_f4(r0) \ 1055 | __asm__ volatile( \ 1056 | "swc2 $12, 8( %0 );" \ 1057 | "swc2 $13, 12( %0 );" \ 1058 | "swc2 $14, 16( %0 )" \ 1059 | : \ 1060 | : "r"(r0) \ 1061 | : "memory") 1062 | 1063 | #define gte_stsxy3_g4(r0) \ 1064 | __asm__ volatile( \ 1065 | "swc2 $12, 8( %0 );" \ 1066 | "swc2 $13, 16( %0 );" \ 1067 | "swc2 $14, 24( %0 )" \ 1068 | : \ 1069 | : "r"(r0) \ 1070 | : "memory") 1071 | 1072 | #define gte_stsxy3_ft4(r0) \ 1073 | __asm__ volatile( \ 1074 | "swc2 $12, 8( %0 );" \ 1075 | "swc2 $13, 16( %0 );" \ 1076 | "swc2 $14, 24( %0 )" \ 1077 | : \ 1078 | : "r"(r0) \ 1079 | : "memory") 1080 | 1081 | #define gte_stsxy3_gt4(r0) \ 1082 | __asm__ volatile( \ 1083 | "swc2 $12, 8( %0 );" \ 1084 | "swc2 $13, 20( %0 );" \ 1085 | "swc2 $14, 32( %0 )" \ 1086 | : \ 1087 | : "r"(r0) \ 1088 | : "memory") 1089 | 1090 | #define gte_stdp(r0) __asm__ volatile("swc2 $8, 0( %0 )" : : "r"(r0) : "memory") 1091 | 1092 | #define gte_stflg(r0) \ 1093 | __asm__ volatile( \ 1094 | "cfc2 $12, $31;" \ 1095 | "nop;" \ 1096 | "sw $12, 0( %0 )" \ 1097 | : \ 1098 | : "r"(r0) \ 1099 | : "$12", "memory") 1100 | 1101 | #define gte_stflg_4(r0) \ 1102 | __asm__ volatile( \ 1103 | "cfc2 $12, $31;" \ 1104 | "addi $13, $0, 4;" \ 1105 | "sll $13, $13, 16;" \ 1106 | "and $12, $12, $13;" \ 1107 | "sw $12, 0( %0 )" \ 1108 | : \ 1109 | : "r"(r0) \ 1110 | : "$12", "$13", "memory") 1111 | 1112 | #define gte_stsz(r0) __asm__ volatile("swc2 $19, 0( %0 )" : : "r"(r0) : "memory") 1113 | 1114 | #define gte_stsz3(r0, r1, r2) \ 1115 | __asm__ volatile( \ 1116 | "swc2 $17, 0( %0 );" \ 1117 | "swc2 $18, 0( %1 );" \ 1118 | "swc2 $19, 0( %2 )" \ 1119 | : \ 1120 | : "r"(r0), "r"(r1), "r"(r2) \ 1121 | : "memory") 1122 | 1123 | #define gte_stsz4(r0, r1, r2, r3) \ 1124 | __asm__ volatile( \ 1125 | "swc2 $16, 0( %0 );" \ 1126 | "swc2 $17, 0( %1 );" \ 1127 | "swc2 $18, 0( %2 );" \ 1128 | "swc2 $19, 0( %3 )" \ 1129 | : \ 1130 | : "r"(r0), "r"(r1), "r"(r2), "r"(r3) \ 1131 | : "memory") 1132 | 1133 | #define gte_stsz3c(r0) \ 1134 | __asm__ volatile( \ 1135 | "swc2 $17, 0( %0 );" \ 1136 | "swc2 $18, 4( %0 );" \ 1137 | "swc2 $19, 8( %0 )" \ 1138 | : \ 1139 | : "r"(r0) \ 1140 | : "memory") 1141 | 1142 | #define gte_stsz4c(r0) \ 1143 | __asm__ volatile( \ 1144 | "swc2 $16, 0( %0 );" \ 1145 | "swc2 $17, 4( %0 );" \ 1146 | "swc2 $18, 8( %0 );" \ 1147 | "swc2 $19, 12( %0 )" \ 1148 | : \ 1149 | : "r"(r0) \ 1150 | : "memory") 1151 | 1152 | #define gte_stszotz(r0) \ 1153 | __asm__ volatile( \ 1154 | "mfc2 $12, $19;" \ 1155 | "nop;" \ 1156 | "sra $12, $12, 2;" \ 1157 | "sw $12, 0( %0 )" \ 1158 | : \ 1159 | : "r"(r0) \ 1160 | : "$12", "memory") 1161 | 1162 | #define gte_stotz(r0) __asm__ volatile("swc2 $7, 0( %0 )" : : "r"(r0) : "memory") 1163 | 1164 | #define gte_stopz(r0) __asm__ volatile("swc2 $24, 0( %0 )" : : "r"(r0) : "memory") 1165 | 1166 | #define gte_stlvl(r0) \ 1167 | __asm__ volatile( \ 1168 | "swc2 $9, 0( %0 );" \ 1169 | "swc2 $10, 4( %0 );" \ 1170 | "swc2 $11, 8( %0 )" \ 1171 | : \ 1172 | : "r"(r0) \ 1173 | : "memory") 1174 | 1175 | #define gte_stlvnl(r0) \ 1176 | __asm__ volatile( \ 1177 | "swc2 $25, 0( %0 );" \ 1178 | "swc2 $26, 4( %0 );" \ 1179 | "swc2 $27, 8( %0 )" \ 1180 | : \ 1181 | : "r"(r0) \ 1182 | : "memory") 1183 | 1184 | #define gte_stlvnl0(r0) __asm__ volatile("swc2 $25, 0( %0 )" : : "r"(r0) : "memory") 1185 | 1186 | #define gte_stlvnl1(r0) __asm__ volatile("swc2 $26, 0( %0 )" : : "r"(r0) : "memory") 1187 | 1188 | #define gte_stlvnl2(r0) __asm__ volatile("swc2 $27, 0( %0 )" : : "r"(r0) : "memory") 1189 | 1190 | #define gte_stsv(r0) \ 1191 | __asm__ volatile( \ 1192 | "mfc2 $12, $9;" \ 1193 | "mfc2 $13, $10;" \ 1194 | "mfc2 $14, $11;" \ 1195 | "sh $12, 0( %0 );" \ 1196 | "sh $13, 2( %0 );" \ 1197 | "sh $14, 4( %0 )" \ 1198 | : \ 1199 | : "r"(r0) \ 1200 | : "$12", "$13", "$14", "memory") 1201 | 1202 | #define gte_stclmv(r0) \ 1203 | __asm__ volatile( \ 1204 | "mfc2 $12, $9;" \ 1205 | "mfc2 $13, $10;" \ 1206 | "mfc2 $14, $11;" \ 1207 | "sh $12, 0( %0 );" \ 1208 | "sh $13, 6( %0 );" \ 1209 | "sh $14, 12( %0 )" \ 1210 | : \ 1211 | : "r"(r0) \ 1212 | : "$12", "$13", "$14", "memory") 1213 | 1214 | #define gte_stbv(r0) \ 1215 | __asm__ volatile( \ 1216 | "mfc2 $12, $9;" \ 1217 | "mfc2 $13, $10;" \ 1218 | "sb $12, 0( %0 );" \ 1219 | "sb $13, 1( %0 )" \ 1220 | : \ 1221 | : "r"(r0) \ 1222 | : "$12", "$13", "memory") 1223 | 1224 | #define gte_stcv(r0) \ 1225 | __asm__ volatile( \ 1226 | "mfc2 $12, $9;" \ 1227 | "mfc2 $13, $10;" \ 1228 | "mfc2 $14, $11;" \ 1229 | "sb $12, 0( %0 );" \ 1230 | "sb $13, 1( %0 );" \ 1231 | "sb $14, 2( %0 )" \ 1232 | : \ 1233 | : "r"(r0) \ 1234 | : "$12", "$13", "$14", "memory") 1235 | 1236 | #define gte_strgb(r0) __asm__ volatile("swc2 $22, 0( %0 )" : : "r"(r0) : "memory") 1237 | 1238 | #define gte_strgb3(r0, r1, r2) \ 1239 | __asm__ volatile( \ 1240 | "swc2 $20, 0( %0 );" \ 1241 | "swc2 $21, 0( %1 );" \ 1242 | "swc2 $22, 0( %2 )" \ 1243 | : \ 1244 | : "r"(r0), "r"(r1), "r"(r2) \ 1245 | : "memory") 1246 | 1247 | #define gte_strgb3_g3(r0) \ 1248 | __asm__ volatile( \ 1249 | "swc2 $20, 4( %0 );" \ 1250 | "swc2 $21, 12( %0 );" \ 1251 | "swc2 $22, 20( %0 )" \ 1252 | : \ 1253 | : "r"(r0) \ 1254 | : "memory") 1255 | 1256 | #define gte_strgb3_gt3(r0) \ 1257 | __asm__ volatile( \ 1258 | "swc2 $20, 4( %0 );" \ 1259 | "swc2 $21, 16( %0 );" \ 1260 | "swc2 $22, 28( %0 )" \ 1261 | : \ 1262 | : "r"(r0) \ 1263 | : "memory") 1264 | 1265 | #define gte_strgb3_g4(r0) \ 1266 | __asm__ volatile( \ 1267 | "swc2 $20, 4( %0 );" \ 1268 | "swc2 $21, 12( %0 );" \ 1269 | "swc2 $22, 20( %0 )" \ 1270 | : \ 1271 | : "r"(r0) \ 1272 | : "memory") 1273 | 1274 | #define gte_strgb3_gt4(r0) \ 1275 | __asm__ volatile( \ 1276 | "swc2 $20, 4( %0 );" \ 1277 | "swc2 $21, 16( %0 );" \ 1278 | "swc2 $22, 28( %0 )" \ 1279 | : \ 1280 | : "r"(r0) \ 1281 | : "memory") 1282 | 1283 | #define gte_ReadGeomOffset(r0, r1) \ 1284 | __asm__ volatile( \ 1285 | "cfc2 $12, $24;" \ 1286 | "cfc2 $13, $25;" \ 1287 | "sra $12, $12, 16;" \ 1288 | "sra $13, $13, 16;" \ 1289 | "sw $12, 0( %0 );" \ 1290 | "sw $13, 0( %1 )" \ 1291 | : \ 1292 | : "r"(r0), "r"(r1) \ 1293 | : "$12", "$13", "memory") 1294 | 1295 | #define gte_ReadGeomScreen(r0) \ 1296 | __asm__ volatile( \ 1297 | "cfc2 $12, $26;" \ 1298 | "nop;" \ 1299 | "sw $12, 0( %0 )" \ 1300 | : \ 1301 | : "r"(r0) \ 1302 | : "$12", "memory") 1303 | 1304 | #define gte_ReadRotMatrix(r0) \ 1305 | __asm__ volatile( \ 1306 | "cfc2 $12, $0;" \ 1307 | "cfc2 $13, $1;" \ 1308 | "sw $12, 0( %0 );" \ 1309 | "sw $13, 4( %0 );" \ 1310 | "cfc2 $12, $2;" \ 1311 | "cfc2 $13, $3;" \ 1312 | "cfc2 $14, $4;" \ 1313 | "sw $12, 8( %0 );" \ 1314 | "sw $13, 12( %0 );" \ 1315 | "sw $14, 16( %0 );" \ 1316 | "cfc2 $12, $5;" \ 1317 | "cfc2 $13, $6;" \ 1318 | "cfc2 $14, $7;" \ 1319 | "sw $12, 20( %0 );" \ 1320 | "sw $13, 24( %0 );" \ 1321 | "sw $14, 28( %0 )" \ 1322 | : \ 1323 | : "r"(r0) \ 1324 | : "$12", "$13", "$14", "memory") 1325 | 1326 | #define gte_sttr(r0) \ 1327 | __asm__ volatile( \ 1328 | "cfc2 $12, $5;" \ 1329 | "cfc2 $13, $6;" \ 1330 | "cfc2 $14, $7;" \ 1331 | "sw $12, 0( %0 );" \ 1332 | "sw $13, 4( %0 );" \ 1333 | "sw $14, 8( %0 )" \ 1334 | : \ 1335 | : "r"(r0) \ 1336 | : "$12", "$13", "$14", "memory") 1337 | 1338 | #define gte_ReadLightMatrix(r0) \ 1339 | __asm__ volatile( \ 1340 | "cfc2 $12, $8;" \ 1341 | "cfc2 $13, $9;" \ 1342 | "sw $12, 0( %0 );" \ 1343 | "sw $13, 4( %0 );" \ 1344 | "cfc2 $12, $10;" \ 1345 | "cfc2 $13, $11;" \ 1346 | "cfc2 $14, $12;" \ 1347 | "sw $12, 8( %0 );" \ 1348 | "sw $13, 12( %0 );" \ 1349 | "sw $14, 16( %0 );" \ 1350 | "cfc2 $12, $13;" \ 1351 | "cfc2 $13, $14;" \ 1352 | "cfc2 $14, $15;" \ 1353 | "sw $12, 20( %0 );" \ 1354 | "sw $13, 24( %0 );" \ 1355 | "sw $14, 28( %0 )" \ 1356 | : \ 1357 | : "r"(r0) \ 1358 | : "$12", "$13", "$14", "memory") 1359 | 1360 | #define gte_ReadColorMatrix(r0) \ 1361 | __asm__ volatile( \ 1362 | "cfc2 $12, $16;" \ 1363 | "cfc2 $13, $17;" \ 1364 | "sw $12, 0( %0 );" \ 1365 | "sw $13, 4( %0 );" \ 1366 | "cfc2 $12, $18;" \ 1367 | "cfc2 $13, $19;" \ 1368 | "cfc2 $14, $20;" \ 1369 | "sw $12, 8( %0 );" \ 1370 | "sw $13, 12( %0 );" \ 1371 | "sw $14, 16( %0 );" \ 1372 | "cfc2 $12, $21;" \ 1373 | "cfc2 $13, $22;" \ 1374 | "cfc2 $14, $23;" \ 1375 | "sw $12, 20( %0 );" \ 1376 | "sw $13, 24( %0 );" \ 1377 | "sw $14, 28( %0 )" \ 1378 | : \ 1379 | : "r"(r0) \ 1380 | : "$12", "$13", "$14", "memory") 1381 | 1382 | #define gte_stlzc(r0) __asm__ volatile("swc2 $31, 0( %0 )" : : "r"(r0) : "memory") 1383 | 1384 | #define gte_stfc(r0) \ 1385 | __asm__ volatile( \ 1386 | "cfc2 $12, $21;" \ 1387 | "cfc2 $13, $22;" \ 1388 | "cfc2 $14, $23;" \ 1389 | "sw $12, 0( %0 );" \ 1390 | "sw $13, 4( %0 );" \ 1391 | "sw $14, 8( %0 )" \ 1392 | : \ 1393 | : "r"(r0) \ 1394 | : "$12", "$13", "$14", "memory") 1395 | 1396 | #define gte_mvlvtr() \ 1397 | __asm__ volatile( \ 1398 | "mfc2 $12, $25;" \ 1399 | "mfc2 $13, $26;" \ 1400 | "mfc2 $14, $27;" \ 1401 | "ctc2 $12, $5;" \ 1402 | "ctc2 $13, $6;" \ 1403 | "ctc2 $14, $7" \ 1404 | : \ 1405 | : \ 1406 | : "$12", "$13", "$14") 1407 | 1408 | #define gte_nop() __asm__ volatile("nop") 1409 | 1410 | #define gte_subdvl(r0, r1, r2) \ 1411 | __asm__ volatile( \ 1412 | "lw $12, 0( %0 );" \ 1413 | "lw $13, 0( %1 );" \ 1414 | "mtc2 $12, $9;" \ 1415 | "mtc2 $13, $10;" \ 1416 | "sra $12, $12, 16;" \ 1417 | "sra $13, $13, 16;" \ 1418 | "subu $15, $12, $13;" \ 1419 | "mfc2 $12, $9;" \ 1420 | "mfc2 $13, $10;" \ 1421 | "sw $15, 4( %2 );" \ 1422 | "subu $12, $12, $13;" \ 1423 | "sw $12, 0( %2 )" \ 1424 | : \ 1425 | : "r"(r0), "r"(r1), "r"(r2) \ 1426 | : "$12", "$13", "$14", "$15", "memory") 1427 | 1428 | #define gte_subdvd(r0, r1, r2) \ 1429 | __asm__ volatile( \ 1430 | "lw $12, 0( %0 );" \ 1431 | "lw $13, 0( %1 );" \ 1432 | "mtc2 $12, $9;" \ 1433 | "mtc2 $13, $10;" \ 1434 | "sra $12, $12, 16;" \ 1435 | "sra $13, $13, 16;" \ 1436 | "subu $15, $12, $13;" \ 1437 | "mfc2 $12, $9;" \ 1438 | "mfc2 $13, $10;" \ 1439 | "sh $15, 2( %2 );" \ 1440 | "subu $12, $12, $13;" \ 1441 | "sh $12, 0( %2 )" \ 1442 | : \ 1443 | : "r"(r0), "r"(r1), "r"(r2) \ 1444 | : "$12", "$13", "$14", "$15", "memory") 1445 | 1446 | #define gte_adddvl(r0, r1, r2) \ 1447 | __asm__ volatile( \ 1448 | "lw $12, 0( %0 );" \ 1449 | "lw $13, 0( %1 );" \ 1450 | "mtc2 $12, $9;" \ 1451 | "mtc2 $13, $10;" \ 1452 | "sra $12, $12, 16;" \ 1453 | "sra $13, $13, 16;" \ 1454 | "addu $15, $12, $13;" \ 1455 | "mfc2 $12, $9;" \ 1456 | "mfc2 $13, $10;" \ 1457 | "sw $15, 4( %2 );" \ 1458 | "addu $12, $12, $13;" \ 1459 | "sw $12, 0( %2 )" \ 1460 | : \ 1461 | : "r"(r0), "r"(r1), "r"(r2) \ 1462 | : "$12", "$13", "$14", "$15", "memory") 1463 | 1464 | #define gte_adddvd(r0, r1, r2) \ 1465 | __asm__ volatile( \ 1466 | "lw $12, 0( %0 );" \ 1467 | "lw $13, 0( %1 );" \ 1468 | "mtc2 $12, $9;" \ 1469 | "mtc2 $13, $10;" \ 1470 | "sra $12, $12, 16;" \ 1471 | "sra $13, $13, 16;" \ 1472 | "addu $15, $12, $13;" \ 1473 | "mfc2 $12, $9;" \ 1474 | "mfc2 $13, $10;" \ 1475 | "sh $15, 2( %2 );" \ 1476 | "addu $12, $12, $13;" \ 1477 | "sh $12, 0( %2 )" \ 1478 | : \ 1479 | : "r"(r0), "r"(r1), "r"(r2) \ 1480 | : "$12", "$13", "$14", "$15", "memory") 1481 | 1482 | #define gte_FlipRotMatrixX() \ 1483 | __asm__ volatile( \ 1484 | "cfc2 $12, $0;" \ 1485 | "cfc2 $13, $1;" \ 1486 | "sll $14, $12, 16;" \ 1487 | "sra $14, $14, 16;" \ 1488 | "subu $14, $0, $14;" \ 1489 | "sra $15, $12, 16;" \ 1490 | "subu $15, $0, $15;" \ 1491 | "sll $15, $15, 16;" \ 1492 | "sll $14, $14, 16;" \ 1493 | "srl $14, $14, 16;" \ 1494 | "or $14, $14, $15;" \ 1495 | "ctc2 $14, $0;" \ 1496 | "sll $14, $13, 16;" \ 1497 | "sra $14, $14, 16;" \ 1498 | "subu $14, $0, $14;" \ 1499 | "sra $15, $13, 16;" \ 1500 | "sll $15, $15, 16;" \ 1501 | "sll $14, $14, 16;" \ 1502 | "srl $14, $14, 16;" \ 1503 | "or $14, $14, $15;" \ 1504 | "ctc2 $14, $1" \ 1505 | : \ 1506 | : \ 1507 | : "$12", "$13", "$14", "$15") 1508 | 1509 | #define gte_FlipTRX() \ 1510 | __asm__ volatile( \ 1511 | "cfc2 $12, $5;" \ 1512 | "nop;" \ 1513 | "subu $12, $0, $12;" \ 1514 | "ctc2 $12, $5" \ 1515 | : \ 1516 | : \ 1517 | : "$12") 1518 | --------------------------------------------------------------------------------