sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Loading...
Searching...
No Matches
getkernel.c
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Licenced under Academic Free License version 2.0
7# Review ps2sdk README & LICENSE files for further details.
8*/
9
14
15#include <kernel.h>
16
17static u32 *g_pSyscallTable = NULL;
18
20static void InitSyscallTable(void)
21{
22 u32 oldintr, oldop;
23 u32 *pAddr;
24
25 oldintr = DIntr();
26 oldop = ee_set_opmode(0);
27 pAddr = (u32 *)0x800002f0;
28 g_pSyscallTable = (u32 *)((pAddr[0] << 16) | (pAddr[2] & 0xFFFF));
29 ee_set_opmode(oldop);
30 if (oldintr) {
31 EIntr();
32 }
33}
34
39void *GetSyscallHandler(int syscall_no)
40{
41 u32 oldintr, oldop;
42 u32 addr = 0;
43
44 if (g_pSyscallTable == NULL) {
45 InitSyscallTable();
46 }
47
48 if (g_pSyscallTable != NULL) {
49 oldintr = DIntr();
50 oldop = ee_set_opmode(0);
51 addr = g_pSyscallTable[syscall_no];
52 ee_set_opmode(oldop);
53 if (oldintr) {
54 EIntr();
55 }
56 }
57
58 return (void *)addr;
59}
60
65void *GetSyscall(int syscall_no) { return (GetSyscallHandler(syscall_no)); }
66
67
68extern void *GetSyscallHandler(int syscall_no);
69
74void *GetExceptionHandler(int ex_cause_no)
75{
76 u32 oldintr, oldop;
77 u32 addr, table_addr;
78 u16 lo16, hi16;
79
80 if ((ex_cause_no < 1) || (ex_cause_no > 15)) {
81 return (NULL);
82 }
83
84 // get address of the syscall "SetVTLBRefillHandler"
85 addr = (u32)GetSyscallHandler(13);
86
87 // suspend interrupts and enter "kernel" operating mode.
88 oldintr = DIntr();
89 oldop = ee_set_opmode(0);
90
91 // harvest the address of the exception handler table.
92 lo16 = ((vu32 *)addr)[0x20 / 4];
93 hi16 = ((vu32 *)addr)[0x14 / 4];
94 table_addr = ((u32)(hi16 << 16) | lo16);
95
96 addr = ((u32 *)table_addr)[ex_cause_no];
97
98 // return to the old operating mode and resume interrupts.
99 ee_set_opmode(oldop);
100 if (oldintr) {
101 EIntr();
102 }
103
104 return ((void *)addr);
105}
106
107
108extern void *GetSyscallHandler(int syscall_no);
109
114void *GetInterruptHandler(int intr_cause_no)
115{
116 u32 oldintr, oldop;
117 u32 addr;
118 u16 lo16, hi16;
119
120 // make sure intr_cause_no is between 0 and 7
121 if ((intr_cause_no < 0) || (intr_cause_no > 7)) {
122 return (NULL);
123 }
124
125 // get address of the syscall "SetVInterruptHandler"
126 addr = (u32)GetSyscallHandler(15);
127
128 // suspend interrupts and enter "kernel" operating mode.
129 oldintr = DIntr();
130 oldop = ee_set_opmode(0);
131
132 // harvest the address of the corresponding exception handler table.
133 hi16 = ((vu32 *)addr)[0x10 / 4];
134 lo16 = ((vu32 *)addr)[0x1C / 4];
135
136 addr = ((u32 *)((u32)(hi16 << 16) | lo16))[intr_cause_no];
137
138 // return to the old operating mode and resume interrupts.
139 ee_set_opmode(oldop);
140 if (oldintr) {
141 EIntr();
142 }
143
144 return (void *)addr;
145}
void * GetSyscall(int syscall_no)
Definition getkernel.c:65
void * GetExceptionHandler(int except_no)
Definition getkernel.c:74
void * GetSyscallHandler(int syscall_no)
Definition getkernel.c:39
void * GetInterruptHandler(int intr_no)
Definition getkernel.c:114