osInitialize.c (5038B)
1 #include "libultra_internal.h" 2 #include "PR/R4300.h" 3 #include "piint.h" 4 #include "PR/rcp.h" 5 #include "PR/ique.h" 6 #include <macros.h> 7 8 typedef struct { 9 u32 inst1; 10 u32 inst2; 11 u32 inst3; 12 u32 inst4; 13 } __osExceptionVector; 14 extern __osExceptionVector __osExceptionPreamble; 15 16 #if defined(VERSION_EU) || defined(VERSION_SH) || defined(VERSION_CN) 17 extern u32 __osSetHWintrRoutine(OSHWIntr, s32 (*)); 18 extern s32 __osLeoInterrupt(void); 19 #endif 20 21 u32 __osFinalrom; // maybe initialized? 22 u64 osClockRate = OS_CLOCK_RATE; 23 24 #if defined(VERSION_SH) || defined(VERSION_CN) 25 u32 osViClock = VI_NTSC_CLOCK; 26 #endif 27 28 u32 __osShutdown = 0; // used in __osException 29 30 #if defined(VERSION_EU) || defined(VERSION_SH) || defined(VERSION_CN) 31 u32 EU_D_80336C40; 32 u32 EU_D_80336C44; 33 34 u32 __OSGlobalIntMask = OS_IM_ALL; 35 u32 osDDActive = 0; 36 u8 EU_unusedZeroes[8] = { 0 }; 37 #endif 38 39 40 #ifdef VERSION_CN 41 42 void __createSpeedParam(void) { 43 __Dom1SpeedParam.type = DEVICE_TYPE_INIT; 44 __Dom1SpeedParam.latency = IO_READ(PI_BSD_DOM1_LAT_REG); 45 __Dom1SpeedParam.pulse = IO_READ(PI_BSD_DOM1_PWD_REG); 46 __Dom1SpeedParam.pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); 47 __Dom1SpeedParam.relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); 48 49 __Dom2SpeedParam.type = DEVICE_TYPE_INIT; 50 __Dom2SpeedParam.latency = IO_READ(PI_BSD_DOM2_LAT_REG); 51 __Dom2SpeedParam.pulse = IO_READ(PI_BSD_DOM2_PWD_REG); 52 __Dom2SpeedParam.pageSize = IO_READ(PI_BSD_DOM2_PGS_REG); 53 __Dom2SpeedParam.relDuration = IO_READ(PI_BSD_DOM2_RLS_REG); 54 } 55 #endif 56 57 #ifdef VERSION_CN 58 void __osInitialize_common(void) 59 #else 60 void osInitialize(void) 61 #endif 62 { 63 u32 pifdata; 64 #ifndef VERSION_CN 65 u32 clock = 0; 66 #endif 67 #ifdef VERSION_CN 68 u32 intrMask1, intrMask2; 69 #endif 70 71 #ifdef VERSION_EU 72 u32 leoStatus; 73 u32 status; 74 #endif 75 76 UNUSED u32 ptr; 77 78 __osFinalrom = TRUE; 79 __osSetSR(__osGetSR() | SR_CU1); 80 __osSetFpcCsr(FPCSR_FS | FPCSR_EV); 81 #ifdef VERSION_CN 82 __osSetWatchLo(0x4900000); 83 intrMask1 = IO_WRITE(MI_HW_INTR_MASK_REG, 0x22000); 84 intrMask2 = IO_WRITE(MI_HW_INTR_MASK_REG, 0x11000); 85 __osBbIsBb = (intrMask1 & 0x140) == 0x140 && (intrMask2 & 0x140) == 0 ? 1 : 0; 86 if (__osBbIsBb != 0 && (IO_READ(PI_MISC_REG) & 0xC0000000) != 0) { 87 __osBbIsBb = 2; 88 } 89 if (__osBbIsBb != 0) { 90 osTvType = TV_TYPE_NTSC; 91 osRomType = DEVICE_TYPE_CART; 92 osResetType = RESET_TYPE_COLD_RESET; 93 osVersion = 1; 94 osMemSize = 4 * 1024 * 1024; 95 } 96 if (__osBbIsBb == 0) { 97 #endif 98 while (__osSiRawReadIo(PIF_RAM_END - 3, &pifdata)) { 99 ; 100 } 101 while (__osSiRawWriteIo(PIF_RAM_END - 3, pifdata | 8)) { 102 ; 103 } 104 #ifdef VERSION_CN 105 } 106 #endif 107 *(__osExceptionVector *) UT_VEC = __osExceptionPreamble; 108 *(__osExceptionVector *) XUT_VEC = __osExceptionPreamble; 109 *(__osExceptionVector *) ECC_VEC = __osExceptionPreamble; 110 *(__osExceptionVector *) E_VEC = __osExceptionPreamble; 111 osWritebackDCache((void *) UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); 112 osInvalICache((void *) UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); 113 #ifdef VERSION_CN 114 __createSpeedParam(); 115 osUnmapTLBAll(); 116 #endif 117 osMapTLBRdb(); 118 #ifndef VERSION_CN 119 osPiRawReadIo(4, &clock); 120 clock &= ~0xf; 121 if (clock) { 122 osClockRate = clock; 123 } 124 #endif 125 osClockRate = osClockRate * 3 / 4; 126 if (osResetType == RESET_TYPE_COLD_RESET) { 127 bzero(osAppNmiBuffer, sizeof(osAppNmiBuffer)); 128 } 129 #if defined(VERSION_SH) || defined(VERSION_CN) 130 if (osTvType == TV_TYPE_PAL) { 131 osViClock = VI_PAL_CLOCK; 132 } else if (osTvType == TV_TYPE_MPAL) { 133 osViClock = VI_MPAL_CLOCK; 134 } else { 135 osViClock = VI_NTSC_CLOCK; 136 } 137 #elif defined(VERSION_EU) 138 WAIT_ON_IO_BUSY(status); 139 140 if (!((leoStatus = IO_READ(LEO_STATUS)) & LEO_STATUS_PRESENCE_MASK)) { 141 osDDActive = 1; 142 __osSetHWIntrRoutine(1, __osLeoInterrupt); 143 } else { 144 osDDActive = 0; 145 } 146 #endif 147 148 #ifdef VERSION_CN 149 if (__osGetCause() & 0x1000) { 150 while (TRUE) { 151 } 152 } 153 if (__osBbIsBb == 0) { 154 __osBbEepromSize = 0x200; 155 __osBbPakSize = 0x8000; 156 __osBbFlashSize = 0x20000; 157 __osBbEepromAddress = (u8 *) 0x803FFE00; 158 __osBbPakAddress[0] = (u32 *) 0x803F7E00; 159 __osBbPakAddress[1] = NULL; 160 __osBbPakAddress[2] = NULL; 161 __osBbPakAddress[3] = NULL; 162 __osBbFlashAddress = 0x803E0000; 163 __osBbSramSize = __osBbFlashSize; 164 __osBbSramAddress = __osBbFlashAddress; 165 } 166 if (__osBbIsBb != 0) { 167 IO_WRITE(PI_BASE_REG+0x64, IO_READ(PI_BASE_REG+0x64) & 0x7FFFFFFF); 168 IO_WRITE(MI_HW_INTR_MASK_REG, 0x20000); 169 IO_WRITE(SI_BASE_REG+0x0C, 0); // a "reserved" register 170 IO_WRITE(SI_BASE_REG+0x1C, (IO_READ(SI_BASE_REG+0x1C) & 0x80FFFFFF) | 0x2F400000); 171 } 172 173 IO_WRITE(AI_CONTROL_REG, 1); 174 IO_WRITE(AI_DACRATE_REG, 0x3fff); 175 IO_WRITE(AI_BITRATE_REG, 0xf); 176 #endif 177 } 178 179 #ifdef VERSION_CN 180 void __osInitialize_autodetect(void) { 181 } 182 #endif