boot.c
4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <ultra64.h>
#ifdef __sgi__
#include <bstring.h>
#endif
#include "gng.h"
#include "rdramTest_data.h"
char bootStack[STACKSIZE];
extern char _codeSegmentRomStart[];
extern char _codeSegmentRomEnd[];
extern char _codeSegmentStart[];
extern char _codeSegmentTextStart[];
extern char _codeSegmentTextEnd[];
extern char _codeSegmentDataStart[];
extern char _codeSegmentDataEnd[];
extern char _codeSegmentBssStart[];
extern char _codeSegmentBssEnd[];
#ifndef __sgi__
/* exports from libultra/nintendo/pi/pirawdma.c */
extern s32 __osPiRawStartDma(s32, u32, void *, u32);
#endif
/*
* The boot() function MUST be the first function in this module, otherwise
* the original boot thread (loaded at 2MB in rdram) will be unable to invoke
* this secondary boot procedure, which loads the program low in rdram.
*
* The FIRST thing the boot program does is run the rdram diagnostic, if it
* has not been run already. That way we minimize the amount of time we spend
* executing instructions from rdram (the test itself runs in dmem).
*/
boot(void *arg)
{
void (*func)(void);
unsigned volatile int *pDmem, *pTest;
int wordCount, rdramDiagErrors, rdramDiagStatus;
u32 rdramDiagSasano,rdramDiagExpect,rdramDiagReaddt;
gngstatus *pstatus;
/*
* osAppNMIBuffer == 0x8000031c in locore rdram
*/
pstatus = (gngstatus *)osAppNMIBuffer;
/*
* Save the rdram diagnostic status in a global variable, as it will be
* cleared by osInitialize.
*/
if (pstatus->rdram_diag_status != 0xdeadbeef) pstatus->rdram_diag_status=0x0;
rdramDiagStatus = pstatus->rdram_diag_status;
rdramDiagSasano = pstatus->rdram_diag_sasano;
rdramDiagExpect = pstatus->rdram_diag_expect;
rdramDiagReaddt = pstatus->rdram_diag_readdt;
/*
* Check to see if this is a cold reset. If so, load the
* rdram diagnostic into dmem and jump to it; when the rdram diagnostic
* completes, it will reload, then invoke this boot function again.
*
* osResetType will be set to 1 whenever an nmi is induced by the reset
* button.
*
* (we don't want to run the memory test after an nmi interrupt brings
* us here)
*/
/*DLE*/ if(0) {
//DLE if ( ( osResetType == 0 ) && (rdramDiagStatus != 0xdeadbeef) ) {
/* deadbeefを初期化しないと、RDRAMのテストにいかない可能性があるので
testDriver.cの一番最初の部分でステータスをクリアする。 sasano */
/*
* Halt the SP.
*/
__osSpSetStatus(SP_SET_HALT);
/*
* Disable interrupts, flush caches.
*/
osSetIntMask(OS_IM_NONE);
osInvalICache(_codeSegmentTextStart,
_codeSegmentTextEnd-_codeSegmentTextStart);
osInvalDCache(_codeSegmentDataStart,
_codeSegmentDataEnd-_codeSegmentDataStart);
/*
* Copy the rdramTest program from a global array into dmem.
*/
for (wordCount = 0, pTest = (unsigned int *)rdramTest_data,
pDmem = ( (unsigned int *)( PHYS_TO_K1(SP_DMEM_START) ) );
wordCount < (rdramTest_data_size >> 2); wordCount++) {
*pDmem++ = *pTest++;
}
func = (void (*)(void))( PHYS_TO_K1(SP_DMEM_START) );
osInvalICache(func, rdramTest_data_size);
func();
/* never reached */
#ifndef _FINALROM
osExit();
#endif
} else {
/*
* Save the rdram test reserved memory variables, as both osInitialize()
* and bzero() below will clobber the reserved memory locations used
* by the rdram test.
*/
rdramDiagErrors = pstatus->rdram_diag_errors;
}
osInitialize();
/*
* Load in the code segment. The "boot" portion of the code segment
* will load in the texture segment and the static segment.
*/
#ifdef __sgi__
osPiRawStartDma(OS_READ, (u32)_codeSegmentRomStart, _codeSegmentStart,
_codeSegmentRomEnd-_codeSegmentRomStart);
#else
__osPiRawStartDma(OS_READ, (u32)_codeSegmentRomStart, _codeSegmentStart,
_codeSegmentRomEnd-_codeSegmentRomStart);
#endif
while(osPiGetStatus() & PI_STATUS_DMA_BUSY);
osInvalICache(_codeSegmentTextStart,
_codeSegmentTextEnd-_codeSegmentTextStart);
osInvalDCache(_codeSegmentDataStart,
_codeSegmentDataEnd-_codeSegmentDataStart);
bzero(_codeSegmentBssStart, _codeSegmentBssEnd-_codeSegmentBssStart);
/*
* Restore the reserved memory locations used by the rdram test, so that
* they can be queried by functions in the codeSegment.
*/
pstatus->rdram_diag_status = rdramDiagStatus;
pstatus->rdram_diag_errors = rdramDiagErrors;
pstatus->rdram_diag_sasano = rdramDiagSasano;
pstatus->rdram_diag_expect = rdramDiagExpect;
pstatus->rdram_diag_readdt = rdramDiagReaddt;
func = (void (*)(void))_codeSegmentStart;
func();
}