Sony PlayStation2 Study
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

498 lines
18 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __SPS2_BASIC_SYSTEM_HEADER__
  2. #define __SPS2_BASIC_SYSTEM_HEADER__
  3. #include "../../core/base/basicTypes.h"
  4. #include "sifdma.h"
  5. #define DI DIntr
  6. #define EI EIntr
  7. // Workaround for EE kernel bug: call this immediately before returning from any interrupt handler.
  8. #define ExitHandler() asm volatile("sync\nei\n")
  9. // note: 'sync' is the same as 'sync.l'
  10. #define EE_SYNC() __asm__ volatile ("sync")
  11. #define EE_SYNCL() __asm__ volatile ("sync.l")
  12. #define EE_SYNCP() __asm__ volatile ("sync.p")
  13. #define UNCACHED_SEG(x) \
  14. ((void *)(((uint32_t)(x)) | 0x20000000))
  15. #define IS_UNCACHED_SEG(x) \
  16. (((uint32_t)(x)) & 0x20000000)
  17. #define UCAB_SEG(x) \
  18. ((void *)(((uint32_t)(x)) | 0x30000000))
  19. #define PUSHDATA( t, x, v, l) \
  20. *(t *)(x) = (v); (l) = sizeof(t)
  21. #define POPDATA( t, x, v, l) \
  22. (v) = *(t *)(x); (l) = sizeof(t)
  23. #define ALIGNED(x) __attribute__((aligned((x))))
  24. // GP functions
  25. void * ChangeGP(void *gp);
  26. void SetGP(void *gp);
  27. void * GetGP(void);
  28. extern void *_gp;
  29. #define SetModuleGP() ChangeGP(&_gp)
  30. /** Special thread ID for referring to the running thread.
  31. Unlike the IOP kernel, this is only supported by ReferThreadStatus() and ChangeThreadPriority().
  32. It can also be used by the iWakeupThread() _syscall_.
  33. But because the libkernel patch may call WakeupThread() to avoid the defect within iWakeupThread() that prevents the running thread from being woken up,
  34. THS_SELF should not be used with iWakeupThread(). */
  35. #define TH_SELF 0
  36. /** Limits */
  37. #define MAX_THREADS 256 //A few will be used for the kernel patches. Thread 0 is always the idle thread.
  38. #define MAX_SEMAPHORES 256 //A few will be used for the kernel patches.
  39. #define MAX_PRIORITY 128
  40. #define MAX_HANDLERS 128
  41. #define MAX_ALARMS 64
  42. /** Modes for FlushCache */
  43. #define WRITEBACK_DCACHE 0
  44. #define INVALIDATE_DCACHE 1
  45. #define INVALIDATE_ICACHE 2
  46. #define INVALIDATE_CACHE 3 //Invalidate both data & instruction caches.
  47. /** EE Interrupt Controller (INTC) interrupt numbers */
  48. typedef enum e_initc_irq {
  49. INTC_GS = 0,
  50. INTC_SBUS = 1,
  51. INTC_VBLANK_S = 2,
  52. INTC_VBLANK_E = 3,
  53. INTC_VIF0 = 4,
  54. INTC_VIF1 = 5,
  55. INTC_VU0 = 6,
  56. INTC_VU1 = 7,
  57. INTC_IPU = 8,
  58. INTC_TIM0 = 9,
  59. INTC_TIM1 = 10,
  60. INTC_TIM2 = 11,
  61. INTC_TIM3 = 12, //Reserved by the EE kernel for alarms (do not use)
  62. INTC_SFIFO = 13, //Error encountered during SFIFO transfer
  63. INTC_VU0WD = 14 //VU0 WatchDog; ForceBreak is sent to VU0 if left in RUN state for extended periods of time.
  64. }initc_irq_t;
  65. //For backward-compatibility
  66. #define kINTC_GS INTC_GS
  67. #define kINTC_SBUS INTC_SBUS
  68. #define kINTC_VBLANK_START INTC_VBLANK_S
  69. #define kINTC_VBLANK_END INTC_VBLANK_E
  70. #define kINTC_VIF0 INTC_VIF0
  71. #define kINTC_VIF1 INTC_VIF1
  72. #define kINTC_VU0 INTC_VU0
  73. #define kINTC_VU1 INTC_VU1
  74. #define kINTC_IPU INTC_IPU
  75. #define kINTC_TIMER0 INTC_TIM0
  76. #define kINTC_TIMER1 INTC_TIM1
  77. /** EE Direct Memory Access Controller (DMAC) interrupt numbers */
  78. typedef enum e_dmac_irq {
  79. DMAC_VIF0 = 0,
  80. DMAC_VIF1 = 1,
  81. DMAC_GIF = 3,
  82. DMAC_FROM_IPU = 4,
  83. DMAC_TO_IPU = 5,
  84. DMAC_SIF0 = 6,
  85. DMAC_SIF1 = 7,
  86. DMAC_SIF2 = 8,
  87. DMAC_FROM_SPR = 9,
  88. DMAC_TO_SPR = 10,
  89. DMAC_CIS = 13, //Channel interrupt
  90. DMAC_MEIS = 14, //MemFIFO empty interrupt
  91. DMAC_BEIS = 15, //Bus error interrupt
  92. } dmac_irq_t;
  93. /** ResetEE argument bits */
  94. #define INIT_DMAC 0x01
  95. #define INIT_VU1 0x02
  96. #define INIT_VIF1 0x04
  97. #define INIT_GIF 0x08
  98. #define INIT_VU0 0x10
  99. #define INIT_VIF0 0x20
  100. #define INIT_IPU 0x40
  101. static inline void nopdelay(void){
  102. uint32_t i = 0xfffff;
  103. do{ __asm__ ("nop\nnop\nnop\nnop\nnop\n"); } while( i-- );
  104. };
  105. static inline uint32_t ee_get_opmode(void) {
  106. uint32_t status;
  107. __asm__ volatile (
  108. ".set\tpush\n\t" \
  109. ".set\tnoreorder\n\t" \
  110. "mfc0\t%0, $12\n\t" \
  111. ".set\tpop\n\t" : "=r" (status));
  112. return (status >> 3) & 3;
  113. };
  114. static inline uint32_t ee_set_opmode( uint32_t opmode ){
  115. uint32_t status, mask;
  116. __asm__ volatile (
  117. ".set\tpush\n\t" \
  118. ".set\tnoreorder\n\t" \
  119. "mfc0\t%0, $12\n\t" \
  120. "li\t%1, 0xffffffe7\n\t" \
  121. "and\t%0, %1\n\t" \
  122. "or\t%0, %2\n\t" \
  123. "mtc0\t%0, $12\n\t" \
  124. "sync.p\n\t"
  125. ".set\tpop\n\t" : "=r" (status), "=r" (mask) : "r" (opmode));
  126. return (status >> 3) & 3;
  127. };
  128. static inline uint32_t ee_kmode_enter(){
  129. uint32_t status, mask;
  130. __asm__ volatile (
  131. ".set\tpush\n\t" \
  132. ".set\tnoreorder\n\t" \
  133. "mfc0\t%0, $12\n\t" \
  134. "li\t%1, 0xffffffe7\n\t" \
  135. "and\t%0, %1\n\t" \
  136. "mtc0\t%0, $12\n\t" \
  137. "sync.p\n\t"
  138. ".set\tpop\n\t" : "=r" (status), "=r" (mask));
  139. return status;
  140. };
  141. static inline uint32_t ee_kmode_exit(){
  142. uint32_t status;
  143. __asm__ volatile (
  144. ".set\tpush\n\t" \
  145. ".set\tnoreorder\n\t" \
  146. "mfc0\t%0, $12\n\t" \
  147. "ori\t%0, 0x10\n\t" \
  148. "mtc0\t%0, $12\n\t" \
  149. "sync.p\n\t" \
  150. ".set\tpop\n\t" : "=r" (status));
  151. return status;
  152. };
  153. typedef struct s_ee_sema{
  154. uint32_t count,
  155. max_count,
  156. init_count,
  157. wait_threads;
  158. uint32_t attr,
  159. option;
  160. } ee_sema_t;
  161. typedef struct s_ee_thread {
  162. uint32_t status; // 0x00
  163. void * func; // 0x04
  164. void * stack; // 0x08
  165. uint32_t stack_size; // 0x0C
  166. void * gp_reg; // 0x10
  167. uint32_t initial_priority; // 0x14
  168. uint32_t current_priority; // 0x18
  169. uint32_t attr; // 0x1C
  170. uint32_t option; // 0x20 Do not use - officially documented to not work.
  171. } ee_thread_t;
  172. /** Thread status */
  173. #define THS_RUN 0x01
  174. #define THS_READY 0x02
  175. #define THS_WAIT 0x04
  176. #define THS_SUSPEND 0x08
  177. #define THS_WAITSUSPEND 0x0c
  178. #define THS_DORMANT 0x10
  179. /** Thread WAIT Status */
  180. #define TSW_NONE 0 //Thread is not in WAIT state
  181. #define TSW_SLEEP 1
  182. #define TSW_SEMA 2
  183. // sizeof() == 0x30
  184. typedef struct s_ee_thread_status{
  185. uint32_t status; // 0x00
  186. void * func; // 0x04
  187. void * stack; // 0x08
  188. uint32_t stack_size; // 0x0C
  189. void * gp_reg; // 0x10
  190. uint32_t initial_priority; // 0x14
  191. uint32_t current_priority; // 0x18
  192. uint32_t attr; // 0x1C
  193. uint32_t option; // 0x20
  194. uint32_t waitType; // 0x24
  195. uint32_t waitId; // 0x28
  196. uint32_t wakeupCount; // 0x2C
  197. } ee_thread_status_t;
  198. /** CpuConfig options */
  199. enum CPU_CONFIG {
  200. CPU_CONFIG_ENABLE_DIE = 0, //Enable Dual Issue
  201. CPU_CONFIG_ENABLE_ICE, //Enable Instruction Cache
  202. CPU_CONFIG_ENABLE_DCE, //Enable Data Cache
  203. CPU_CONFIG_DISBLE_DIE, //Disable Dual Issue
  204. CPU_CONFIG_DISBLE_ICE, //Disable Instruction Cache
  205. CPU_CONFIG_DISBLE_DCE //Disable Data Cache
  206. };
  207. /** EnableCache & DisableCache options (multiple options may be specified) */
  208. #define CPU_DATA_CACHE 1
  209. #define CPU_INSTRUCTION_CACHE 2
  210. #ifdef __cplusplus
  211. extern "C" {
  212. #endif
  213. /* Initialization/deinitialization routines. */
  214. void _InitSys(void); //Run by crt0
  215. void TerminateLibrary(void); //Run by crt0
  216. /* Thread update functions */
  217. int InitThread(void); //Run by _InitSys
  218. int32_t iWakeupThread(int32_t thread_id );
  219. int32_t iRotateThreadReadyQueue(int32_t priority);
  220. int32_t iSuspendThread(int32_t thread_id);
  221. /* TLB update functions */
  222. void InitTLBFunctions(void); //Run by _InitSys
  223. void InitTLB(void);
  224. void Exit(int32_t exit_code) __attribute__((noreturn));
  225. int32_t ExecPS2(void *entry, void *gp, int num_args, char *args[]);
  226. void LoadExecPS2(const char *filename, int32_t num_args, char *args[]) __attribute__((noreturn));
  227. void ExecOSD(int num_args, char *args[]) __attribute__((noreturn));
  228. /* Alarm update functions */
  229. void InitAlarm(void); //Run by _InitSys
  230. /* libosd update functions */
  231. void InitExecPS2(void); //ExecPS2 patch only. Run by _InitSys, Exit, LoadExecPS2, ExecPS2 and ExecOSD
  232. void InitOsd(void); //ExecPS2 + System Configuration patches. Please refer to the comments within libosd_full.c
  233. int PatchIsNeeded(void); //Indicates whether the patch is required.
  234. /* Glue routines. */
  235. int DIntr(void);
  236. int EIntr(void);
  237. int EnableIntc(int intc);
  238. int DisableIntc(int intc);
  239. int EnableDmac(int dmac);
  240. int DisableDmac(int dmac);
  241. int iEnableIntc(int intc);
  242. int iDisableIntc(int intc);
  243. int iEnableDmac(int dmac);
  244. int iDisableDmac(int dmac);
  245. void SyncDCache(void *start, void *end);
  246. void iSyncDCache(void *start, void *end);
  247. void InvalidDCache(void *start, void *end);
  248. void iInvalidDCache(void *start, void *end);
  249. /* System call prototypes */
  250. void ResetEE( uint32_t init_bitfield );
  251. void SetGsCrt(int16_t interlace, int16_t pal_ntsc, int16_t field);
  252. void _Exit(int32_t exit_code) __attribute__((noreturn));
  253. void _LoadExecPS2(const char *filename, int32_t num_args, char *args[]) __attribute__((noreturn));
  254. int32_t _ExecPS2(void *entry, void *gp, int num_args, char *args[]);
  255. void RFU009(uint32_t arg0, uint32_t arg1);
  256. int32_t AddSbusIntcHandler(int32_t cause, void (*handler)(int call));
  257. int32_t RemoveSbusIntcHandler(int32_t cause);
  258. int32_t Interrupt2Iop(int32_t cause);
  259. void SetVTLBRefillHandler(int32_t handler_num, void* handler_func);
  260. void SetVCommonHandler(int32_t handler_num, void* handler_func);
  261. void SetVInterruptHandler(int32_t handler_num, void* handler_func);
  262. int32_t AddIntcHandler(int32_t cause, int32_t(*handler_func)(int32_t cause), int32_t next);
  263. int32_t AddIntcHandler2(int32_t cause, int32_t(*handler_func)(int32_t cause, void* arg, void* addr), int32_t next, void* arg);
  264. int32_t RemoveIntcHandler(int32_t cause, int32_t handler_id);
  265. int32_t AddDmacHandler(int32_t channel, int32_t (*handler)(int32_t channel), int32_t next);
  266. int32_t AddDmacHandler2(int32_t channel, int32_t (*handler)(int32_t channel, void *arg, void *addr), int32_t next, void* arg);
  267. int32_t RemoveDmacHandler(int32_t channel, int32_t handler_id);
  268. int32_t _EnableIntc(int32_t cause);
  269. int32_t _DisableIntc(int32_t cause);
  270. int32_t _EnableDmac(int32_t channel);
  271. int32_t _DisableDmac(int32_t channel);
  272. //Alarm value is in H-SYNC ticks.
  273. int32_t SetAlarm(uint16_t time, void (*callback)(int32_t alarm_id, uint16_t time, void *common), void *common);
  274. int32_t _SetAlarm(uint16_t time, void (*callback)(int32_t alarm_id, uint16_t time, void *common), void *common);
  275. int32_t ReleaseAlarm(int32_t alarm_id);
  276. int32_t _ReleaseAlarm(int32_t alarm_id);
  277. int32_t _iEnableIntc(int32_t cause);
  278. int32_t _iDisableIntc(int32_t cause);
  279. int32_t _iEnableDmac(int32_t channel);
  280. int32_t _iDisableDmac(int32_t channel);
  281. int32_t iSetAlarm(uint16_t time, void (*callback)(int32_t alarm_id, uint16_t time, void *common), void *common);
  282. int32_t _iSetAlarm(uint16_t time, void (*callback)(int32_t alarm_id, uint16_t time, void *common), void *common);
  283. int32_t iReleaseAlarm(int32_t alarm_id);
  284. int32_t _iReleaseAlarm(int32_t alarm_id);
  285. int32_t CreateThread(ee_thread_t *thread);
  286. int32_t DeleteThread(int32_t thread_id);
  287. int32_t StartThread(int32_t thread_id, void *args);
  288. void ExitThread(void);
  289. void ExitDeleteThread(void);
  290. int32_t TerminateThread(int32_t thread_id);
  291. int32_t iTerminateThread(int32_t thread_id);
  292. // void DisableDispatchThread(void); // not supported
  293. // void EnableDispatchThread(void); // not supported
  294. int32_t ChangeThreadPriority(int32_t thread_id, int32_t priority);
  295. int32_t iChangeThreadPriority(int32_t thread_id, int32_t priority);
  296. int32_t RotateThreadReadyQueue(int32_t priority);
  297. int32_t _iRotateThreadReadyQueue(int32_t priority);
  298. int32_t ReleaseWaitThread(int32_t thread_id);
  299. int32_t iReleaseWaitThread(int32_t thread_id);
  300. int32_t GetThreadId(void);
  301. int32_t _iGetThreadId(void); //This is actually GetThreadId(), used for a hack by SCE to work around the iWakeupThread design flaw.
  302. int32_t ReferThreadStatus(int32_t thread_id, ee_thread_status_t *info);
  303. int32_t iReferThreadStatus(int32_t thread_id, ee_thread_status_t *info);
  304. int32_t SleepThread(void);
  305. int32_t WakeupThread(int32_t thread_id);
  306. int32_t _iWakeupThread(int32_t thread_id);
  307. int32_t CancelWakeupThread(int32_t thread_id);
  308. int32_t iCancelWakeupThread(int32_t thread_id);
  309. int32_t SuspendThread(int32_t thread_id);
  310. int32_t _iSuspendThread(int32_t thread_id);
  311. int32_t ResumeThread(int32_t thread_id);
  312. int32_t iResumeThread(int32_t thread_id);
  313. uint8_t RFU059(void);
  314. void * SetupThread(void * gp, void * stack, int32_t stack_size, void * args, void * root_func);
  315. void SetupHeap(void * heap_start, int32_t heap_size);
  316. void *EndOfHeap(void);
  317. int32_t CreateSema(ee_sema_t *sema);
  318. int32_t DeleteSema(int32_t sema_id);
  319. int32_t SignalSema(int32_t sema_id);
  320. int32_t iSignalSema(int32_t sema_id);
  321. int32_t WaitSema(int32_t sema_id);
  322. int32_t PollSema(int32_t sema_id);
  323. int32_t iPollSema(int32_t sema_id);
  324. int32_t ReferSemaStatus(int32_t sema_id, ee_sema_t *sema);
  325. int32_t iReferSemaStatus(int32_t sema_id, ee_sema_t *sema);
  326. int32_t iDeleteSema(int32_t sema_id);
  327. void SetOsdConfigParam(void* addr);
  328. void GetOsdConfigParam(void* addr);
  329. void GetGsHParam(void* addr1, void* addr2, void* addr3);
  330. int32_t GetGsVParam(void);
  331. void SetGsHParam(void* addr1, void* addr2, void* addr3, void* addr4);
  332. void SetGsVParam(int32_t arg1);
  333. //TLB functions are only available if InitTLBFunctions() is run (Normally run by crt0).
  334. int PutTLBEntry(unsigned int PageMask, unsigned int EntryHi, unsigned int EntryLo0, unsigned int EntryLo1);
  335. int iPutTLBEntry(unsigned int PageMask, unsigned int EntryHi, unsigned int EntryLo0, unsigned int EntryLo1);
  336. int _SetTLBEntry(unsigned int index, unsigned int PageMask, unsigned int EntryHi, unsigned int EntryLo0, unsigned int EntryLo1);
  337. int iSetTLBEntry(unsigned int index, unsigned int PageMask, unsigned int EntryHi, unsigned int EntryLo0, unsigned int EntryLo1);
  338. int GetTLBEntry(unsigned int index, unsigned int *PageMask, unsigned int *EntryHi, unsigned int *EntryLo0, unsigned int *EntryLo1);
  339. int iGetTLBEntry(unsigned int index, unsigned int *PageMask, unsigned int *EntryHi, unsigned int *EntryLo0, unsigned int *EntryLo1);
  340. int ProbeTLBEntry(unsigned int EntryHi, unsigned int *PageMask, unsigned int *EntryLo0, unsigned int *EntryLo1);
  341. int iProbeTLBEntry(unsigned int EntryHi, unsigned int *PageMask, unsigned int *EntryLo0, unsigned int *EntryLo1);
  342. int ExpandScratchPad(unsigned int page);
  343. void EnableIntcHandler(uint32_t cause);
  344. void iEnableIntcHandler(uint32_t cause);
  345. void DisableIntcHandler(uint32_t cause);
  346. void iDisableIntcHandler(uint32_t cause);
  347. void EnableDmacHandler(uint32_t channel);
  348. void iEnableDmacHandler(uint32_t channel);
  349. void DisableDmacHandler(uint32_t channel);
  350. void iDisableDmacHandler(uint32_t channel);
  351. void KSeg0(int32_t arg1);
  352. int32_t EnableCache(int32_t cache);
  353. int32_t DisableCache(int32_t cache);
  354. uint32_t GetCop0(int32_t reg_id);
  355. void FlushCache(int32_t operation);
  356. uint32_t CpuConfig(uint32_t config);
  357. uint32_t iGetCop0(int32_t reg_id);
  358. void iFlushCache(int32_t operation);
  359. uint32_t iCpuConfig(uint32_t config);
  360. void SetCPUTimerHandler(void (*handler)(void));
  361. void SetCPUTimer(int32_t compval);
  362. //These two are not available in the unpatched Protokernel (Unpatched SCPH-10000 and SCPH-15000 kernels).
  363. void SetOsdConfigParam2(void* config, int32_t size, int32_t offset);
  364. void GetOsdConfigParam2(void* config, int32_t size, int32_t offset);
  365. uint64_t GsGetIMR(void);
  366. uint64_t iGsGetIMR(void);
  367. uint64_t GsPutIMR(uint64_t imr);
  368. uint64_t iGsPutIMR(uint64_t imr);
  369. void SetPgifHandler(void* handler);
  370. void SetVSyncFlag(uint32_t *, uint64_t *);
  371. void SetSyscall(int32_t syscall_num, void* handler);
  372. //void _print(const char *fmt, ...); // null function
  373. void SifStopDma(void); //Disables SIF0 (IOP -> EE).
  374. uint32_t SifDmaStat( uint32_t id );
  375. uint32_t iSifDmaStat( uint32_t id );
  376. uint32_t SifSetDma( sif_dma_transfer_t *sdd, uint32_t len);
  377. uint32_t iSifSetDma( sif_dma_transfer_t *sdd, uint32_t len);
  378. //Enables SIF0 (IOP -> EE). Sets channel 5 CHCR to 0x184 (CHAIN, TIE and STR).
  379. void SifSetDChain(void);
  380. void iSifSetDChain(void);
  381. //Sets/gets SIF register values (Refer to sifdma.h for a register list).
  382. int SifSetReg(uint32_t register_num, int register_value);
  383. int SifGetReg(uint32_t register_num);
  384. void _ExecOSD(int num_args, char *args[]) __attribute__((noreturn));
  385. int32_t Deci2Call(int32_t , uint32_t *);
  386. void PSMode(void);
  387. int32_t MachineType(void);
  388. int32_t GetMemorySize(void);
  389. //Internal function for getting board-specific offsets, only present in later kernels (ROMVER > 20010608).
  390. void _GetGsDxDyOffset(int mode, int *dx, int *dy, int *dw, int *dh);
  391. //Internal function for reinitializing the TLB, only present in later kernels. Please use InitTLB() instead to initialize the TLB with all kernels.
  392. int _InitTLB(void);
  393. /* (PSX only) Sets the memory size. 0 = 64MB mode, 1 = 32MB mode. The mode is only binding when either _InitTLB() or the PSX ExecPS2() syscall is called.
  394. The stack pointer must remain in range of usable memory, or a TLB exception will occur. */
  395. int SetMemoryMode(int mode); //Arbitrarily named.
  396. void _SyncDCache(void *start, void *end);
  397. void _InvalidDCache(void *start, void *end);
  398. /* stdlib - program termination */
  399. void abort(void) __attribute__((noreturn));
  400. void exit(int retval) __attribute__((noreturn));
  401. void _exit(int retval) __attribute__((noreturn));
  402. /* errno.h */
  403. #ifndef errno
  404. extern int errno __attribute__((section("data")));
  405. int *__errno(void);
  406. #endif
  407. void *GetSyscallHandler(int syscall_no);
  408. void *GetExceptionHandler(int except_no);
  409. void *GetInterruptHandler(int intr_no);
  410. /* Helper functions for kernel patching */
  411. int kCopy(void *dest, const void *src, int size);
  412. int kCopyBytes(void *dest, const void *src, int size);
  413. int Copy(void *dest, const void *src, int size);
  414. void setup(int syscall_num, void* handler); //alias of "SetSyscall"
  415. void *GetEntryAddress(int syscall);
  416. #ifdef __cplusplus
  417. }
  418. #endif
  419. __externC uint32_t *sps2_syscall( uint32_t syscall_no, ... );
  420. #endif /* __KERNEL_H__ */