28#define ExitHandler() asm volatile("sync\nei\n")
31#define EE_SYNC() __asm__ volatile("sync")
32#define EE_SYNCL() __asm__ volatile("sync.l")
33#define EE_SYNCP() __asm__ volatile("sync.p")
35#define UNCACHED_SEG(x) \
36 ((void *)(((u32)(x)) | 0x20000000))
38#define IS_UNCACHED_SEG(x) \
39 (((u32)(x)) & 0x20000000)
42 ((void *)(((u32)(x)) | 0x30000000))
44#define PUSHDATA(t, x, v, l) \
48#define POPDATA(t, x, v, l) \
52#define ALIGNED(x) __attribute__((aligned((x))))
55extern void *ChangeGP(
void *gp);
56extern void SetGP(
void *gp);
57extern void *GetGP(
void);
60#define SetModuleGP() ChangeGP(&_gp)
70#define MAX_THREADS 256
71#define MAX_SEMAPHORES 256
72#define MAX_PRIORITY 128
73#define MAX_HANDLERS 128
77#define WRITEBACK_DCACHE 0
78#define INVALIDATE_DCACHE 1
79#define INVALIDATE_ICACHE 2
80#define INVALIDATE_CACHE 3
102#define kINTC_GS INTC_GS
103#define kINTC_SBUS INTC_SBUS
104#define kINTC_VBLANK_START INTC_VBLANK_S
105#define kINTC_VBLANK_END INTC_VBLANK_E
106#define kINTC_VIF0 INTC_VIF0
107#define kINTC_VIF1 INTC_VIF1
108#define kINTC_VU0 INTC_VU0
109#define kINTC_VU1 INTC_VU1
110#define kINTC_IPU INTC_IPU
111#define kINTC_TIMER0 INTC_TIM0
112#define kINTC_TIMER1 INTC_TIM1
133#define INIT_DMAC 0x01
135#define INIT_VIF1 0x04
138#define INIT_VIF0 0x20
141static inline void nopdelay(
void)
146 __asm__(
"nop\nnop\nnop\nnop\nnop\n");
150static inline int ee_get_opmode(
void)
156 ".set\tnoreorder\n\t"
161 return ((status >> 3) & 3);
164static inline int ee_set_opmode(u32 opmode)
170 ".set\tnoreorder\n\t"
172 "li\t%1, 0xffffffe7\n\t"
178 :
"=r"(status),
"=r"(mask)
181 return ((status >> 3) & 3);
184static inline int ee_kmode_enter()
190 ".set\tnoreorder\n\t"
192 "li\t%1, 0xffffffe7\n\t"
197 :
"=r"(status),
"=r"(mask));
202static inline int ee_kmode_exit()
208 ".set\tnoreorder\n\t"
236 int initial_priority;
237 int current_priority;
245#define THS_READY 0x02
247#define THS_SUSPEND 0x08
248#define THS_WAITSUSPEND 0x0c
249#define THS_DORMANT 0x10
264 int initial_priority;
265 int current_priority;
275 CPU_CONFIG_ENABLE_DIE = 0,
276 CPU_CONFIG_ENABLE_ICE,
277 CPU_CONFIG_ENABLE_DCE,
278 CPU_CONFIG_DISBLE_DIE,
279 CPU_CONFIG_DISBLE_ICE,
280 CPU_CONFIG_DISBLE_DCE
284#define CPU_DATA_CACHE 1
285#define CPU_INSTRUCTION_CACHE 2
321extern void _InitSys(
void);
323extern void TerminateLibrary(
void);
326extern int InitThread(
void);
328extern s32 iWakeupThread(s32 thread_id);
329extern s32 iRotateThreadReadyQueue(s32 priority);
330extern s32 iSuspendThread(s32 thread_id);
333extern void InitTLBFunctions(
void);
335extern void InitTLB(
void);
337extern s32 ExecPS2(
void *entry,
void *gp,
int num_args,
char *args[]);
338extern void LoadExecPS2(
const char *filename, s32 num_args,
char *args[])
__attribute__((noreturn));
339extern void ExecOSD(
int num_args,
char *args[])
__attribute__((noreturn));
342extern void InitAlarm(
void);
345extern void InitExecPS2(
void);
346extern void InitOsd(
void);
348extern int PatchIsNeeded(
void);
351extern void InitDebug(
void);
354extern int DIntr(
void);
355extern int EIntr(
void);
357extern int EnableIntc(
int intc);
358extern int DisableIntc(
int intc);
359extern int EnableDmac(
int dmac);
360extern int DisableDmac(
int dmac);
362extern int iEnableIntc(
int intc);
363extern int iDisableIntc(
int intc);
364extern int iEnableDmac(
int dmac);
365extern int iDisableDmac(
int dmac);
367extern void SyncDCache(
void *start,
void *end);
368extern void iSyncDCache(
void *start,
void *end);
369extern void InvalidDCache(
void *start,
void *end);
370extern void iInvalidDCache(
void *start,
void *end);
373extern void ResetEE(u32 init_bitfield);
374extern void SetGsCrt(s16 interlace, s16 pal_ntsc, s16 field);
376extern void _LoadExecPS2(
const char *filename, s32 num_args,
char *args[])
__attribute__((noreturn));
377extern s32 _ExecPS2(
void *entry,
void *gp,
int num_args,
char *args[]);
378extern void RFU009(u32 arg0, u32 arg1);
379extern s32 AddSbusIntcHandler(s32 cause,
void (*handler)(
int call));
380extern s32 RemoveSbusIntcHandler(s32 cause);
381extern s32 Interrupt2Iop(s32 cause);
382extern void SetVTLBRefillHandler(s32 handler_num,
void *handler_func);
383extern void SetVCommonHandler(s32 handler_num,
void *handler_func);
384extern void SetVInterruptHandler(s32 handler_num,
void *handler_func);
385extern s32 AddIntcHandler(s32 cause, s32 (*handler_func)(s32 cause), s32 next);
386extern s32 AddIntcHandler2(s32 cause, s32 (*handler_func)(s32 cause,
void *arg,
void *addr), s32 next,
void *arg);
387extern s32 RemoveIntcHandler(s32 cause, s32 handler_id);
388extern s32 AddDmacHandler(s32 channel, s32 (*handler)(s32 channel), s32 next);
389extern s32 AddDmacHandler2(s32 channel, s32 (*handler)(s32 channel,
void *arg,
void *addr), s32 next,
void *arg);
390extern s32 RemoveDmacHandler(s32 channel, s32 handler_id);
391extern s32 _EnableIntc(s32 cause);
392extern s32 _DisableIntc(s32 cause);
393extern s32 _EnableDmac(s32 channel);
394extern s32 _DisableDmac(s32 channel);
397extern s32 SetAlarm(u16 time,
void (*callback)(s32 alarm_id, u16 time,
void *common),
void *common);
398extern s32 _SetAlarm(u16 time,
void (*callback)(s32 alarm_id, u16 time,
void *common),
void *common);
399extern s32 ReleaseAlarm(s32 alarm_id);
400extern s32 _ReleaseAlarm(s32 alarm_id);
402extern s32 _iEnableIntc(s32 cause);
403extern s32 _iDisableIntc(s32 cause);
404extern s32 _iEnableDmac(s32 channel);
405extern s32 _iDisableDmac(s32 channel);
407extern s32 iSetAlarm(u16 time,
void (*callback)(s32 alarm_id, u16 time,
void *common),
void *common);
408extern s32 _iSetAlarm(u16 time,
void (*callback)(s32 alarm_id, u16 time,
void *common),
void *common);
409extern s32 iReleaseAlarm(s32 alarm_id);
410extern s32 _iReleaseAlarm(s32 alarm_id);
413extern s32 DeleteThread(s32 thread_id);
414extern s32 StartThread(s32 thread_id,
void *args);
415extern void ExitThread(
void);
416extern void ExitDeleteThread(
void);
417extern s32 TerminateThread(s32 thread_id);
418extern s32 iTerminateThread(s32 thread_id);
421extern s32 ChangeThreadPriority(s32 thread_id, s32 priority);
422extern s32 iChangeThreadPriority(s32 thread_id, s32 priority);
423extern s32 RotateThreadReadyQueue(s32 priority);
424extern s32 _iRotateThreadReadyQueue(s32 priority);
425extern s32 ReleaseWaitThread(s32 thread_id);
426extern s32 iReleaseWaitThread(s32 thread_id);
427extern s32 GetThreadId(
void);
428extern s32 _iGetThreadId(
void);
431extern s32 SleepThread(
void);
432extern s32 WakeupThread(s32 thread_id);
433extern s32 _iWakeupThread(s32 thread_id);
434extern s32 CancelWakeupThread(s32 thread_id);
435extern s32 iCancelWakeupThread(s32 thread_id);
436extern s32 SuspendThread(s32 thread_id);
437extern s32 _iSuspendThread(s32 thread_id);
438extern s32 ResumeThread(s32 thread_id);
439extern s32 iResumeThread(s32 thread_id);
441extern u8 RFU059(
void);
443extern void *SetupThread(
void *gp,
void *stack, s32 stack_size,
void *args,
void *root_func);
444extern void SetupHeap(
void *heap_start, s32 heap_size);
445extern void *EndOfHeap(
void);
448extern s32 DeleteSema(s32 sema_id);
449extern s32 SignalSema(s32 sema_id);
450extern s32 iSignalSema(s32 sema_id);
451extern s32 WaitSema(s32 sema_id);
452extern s32 PollSema(s32 sema_id);
453extern s32 iPollSema(s32 sema_id);
454extern s32 ReferSemaStatus(s32 sema_id,
ee_sema_t *sema);
455extern s32 iReferSemaStatus(s32 sema_id,
ee_sema_t *sema);
456extern s32 iDeleteSema(s32 sema_id);
457extern void SetOsdConfigParam(
void *addr);
458extern void GetOsdConfigParam(
void *addr);
459extern void GetGsHParam(
void *addr1,
void *addr2,
void *addr3);
460extern s32 GetGsVParam(
void);
461extern void SetGsHParam(
void *addr1,
void *addr2,
void *addr3,
void *addr4);
462extern void SetGsVParam(s32 arg1);
465extern int PutTLBEntry(
unsigned int PageMask,
unsigned int EntryHi,
unsigned int EntryLo0,
unsigned int EntryLo1);
466extern int iPutTLBEntry(
unsigned int PageMask,
unsigned int EntryHi,
unsigned int EntryLo0,
unsigned int EntryLo1);
467extern int _SetTLBEntry(
unsigned int index,
unsigned int PageMask,
unsigned int EntryHi,
unsigned int EntryLo0,
unsigned int EntryLo1);
468extern int iSetTLBEntry(
unsigned int index,
unsigned int PageMask,
unsigned int EntryHi,
unsigned int EntryLo0,
unsigned int EntryLo1);
469extern int GetTLBEntry(
unsigned int index,
unsigned int *PageMask,
unsigned int *EntryHi,
unsigned int *EntryLo0,
unsigned int *EntryLo1);
470extern int iGetTLBEntry(
unsigned int index,
unsigned int *PageMask,
unsigned int *EntryHi,
unsigned int *EntryLo0,
unsigned int *EntryLo1);
471extern int ProbeTLBEntry(
unsigned int EntryHi,
unsigned int *PageMask,
unsigned int *EntryLo0,
unsigned int *EntryLo1);
472extern int iProbeTLBEntry(
unsigned int EntryHi,
unsigned int *PageMask,
unsigned int *EntryLo0,
unsigned int *EntryLo1);
473extern int ExpandScratchPad(
unsigned int page);
475extern void EnableIntcHandler(u32 cause);
476extern void iEnableIntcHandler(u32 cause);
477extern void DisableIntcHandler(u32 cause);
478extern void iDisableIntcHandler(u32 cause);
479extern void EnableDmacHandler(u32 channel);
480extern void iEnableDmacHandler(u32 channel);
481extern void DisableDmacHandler(u32 channel);
482extern void iDisableDmacHandler(u32 channel);
483extern void KSeg0(s32 arg1);
484extern s32 EnableCache(s32 cache);
485extern s32 DisableCache(s32 cache);
486extern u32 GetCop0(s32 reg_id);
487extern void FlushCache(s32 operation);
488extern u32 CpuConfig(u32 config);
489extern u32 iGetCop0(s32 reg_id);
490extern void iFlushCache(s32 operation);
491extern u32 iCpuConfig(u32 config);
492extern void SetCPUTimerHandler(
void (*handler)(
void));
493extern void SetCPUTimer(s32 compval);
496extern void SetOsdConfigParam2(
void *config, s32 size, s32 offset);
497extern void GetOsdConfigParam2(
void *config, s32 size, s32 offset);
499extern u64 GsGetIMR(
void);
500extern u64 iGsGetIMR(
void);
501extern u64 GsPutIMR(u64 imr);
502extern u64 iGsPutIMR(u64 imr);
503extern void SetPgifHandler(
void *handler);
504extern void SetVSyncFlag(u32 *, u64 *);
505extern void SetSyscall(s32 syscall_num,
void *handler);
506extern void _print(
const char *fmt, ...);
508extern void SifStopDma(
void);
510extern s32 SifDmaStat(u32
id);
511extern s32 iSifDmaStat(u32
id);
516extern void SifSetDChain(
void);
517extern void iSifSetDChain(
void);
520extern int SifSetReg(u32 register_num,
int register_value);
521extern int SifGetReg(u32 register_num);
523extern void _ExecOSD(
int num_args,
char *args[])
__attribute__((noreturn));
524extern s32 Deci2Call(s32, u32 *);
525extern void PSMode(
void);
526extern s32 MachineType(
void);
527extern s32 GetMemorySize(
void);
530extern void _GetGsDxDyOffset(
int mode,
int *dx,
int *dy,
int *dw,
int *dh);
533extern int _InitTLB(
void);
536extern int SetMemoryMode(
int mode);
538extern void _SyncDCache(
void *start,
void *end);
539extern void _InvalidDCache(
void *start,
void *end);
541extern void *GetSyscallHandler(
int syscall_no);
542extern void *GetExceptionHandler(
int except_no);
543extern void *GetInterruptHandler(
int intr_no);
546extern int kCopy(
void *dest,
const void *src,
int size);
547extern int kCopyBytes(
void *dest,
const void *src,
int size);
548extern int Copy(
void *dest,
const void *src,
int size);
549extern void setup(
int syscall_num,
void *handler);
550extern void *GetEntryAddress(
int syscall);
554#define DISABLE_PATCHED_Exit() \
555 void Exit(s32 exit_code) { KExit(exit_code); }
557#define DISABLE_PATCHED_LoadExecPS2() \
558 void LoadExecPS2(const char *filename, s32 num_args, char *args[]) { _LoadExecPS2(filename, num_args, args); }
560#define NO_PATCHED_ExecOSD() \
561 void ExecOSD(int num_args, char *args[]) { _ExecOSD(num_args, args); }
563#define DISABLE_TimerSystemTime() \
564 s32 InitTimer(s32 in_mode) {(void)in_mode; return 0;} \
565 s32 EndTimer(void) {return 0;} \
566 s32 StartTimerSystemTime(void) {return 0;} \
567 s32 StopTimerSystemTime(void) {return 0;}
569#define DISABLE_TimerAlarm() \
570 void ForTimer_InitAlarm(void) {}
572#define DISABLE_PATCHED_ALARMS() \
573 void InitAlarm(void) {}
575#define DISABLE_PATCHED_THREADS() \
576 int InitThread(void) { return 0; } \
577 s32 iRotateThreadReadyQueue(s32 priority) { return _iRotateThreadReadyQueue(priority); } \
578 s32 iWakeupThread(s32 thread_id) { return _iWakeupThread(thread_id); } \
579 s32 iSuspendThread(s32 thread_id) { return _iSuspendThread(thread_id); }
581#define DISABLE_PATCHED_ExecPS2() \
582 void InitExecPS2(void) {} \
583 s32 ExecPS2(void *entry, void *gp, int num_args, char *args[]) { return _ExecPS2(entry, gp, num_args, args); }
585#define DISABLE_PATCHED_TLBFunctions() \
586 void InitTLBFunctions(void) {} \
587 void InitTLB(void) {}
589#define DISABLE_PATCHED_FUNCTIONS() \
590 DISABLE_PATCHED_ALARMS() \
591 DISABLE_PATCHED_THREADS() \
592 DISABLE_PATCHED_ExecPS2() \
593 DISABLE_PATCHED_TLBFunctions() \
594 DISABLE_PATCHED_Exit() \
595 DISABLE_PATCHED_LoadExecPS2()
597#define DISABLE_EXTRA_TIMERS_FUNCTIONS() \
598 DISABLE_TimerSystemTime() \