initialize_kmc.c
3.45 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <R4300.h>
#include <rcp.h>
#include <ramrom.h>
#include "osint.h"
#include "piint.h"
#include "rdb.h"
typedef struct {
unsigned int inst1; /* lui k0,XXXX */
unsigned int inst2; /* addiu k0,k0,XXXX */
unsigned int inst3; /* jr k0 */
unsigned int inst4; /* nop */
} __osExceptionVector;
extern u64 osClockRate ;
extern int osViClock ; /* Video clock rate (default is NTSC) */
extern s32 __osShutdown ; /* 1 = pre-NMI interrupt has occured */
extern OSIntMask __OSGlobalIntMask ;
#ifdef _FINALROM
extern s32 __osFinalrom;
#else
extern s32 __kmc_pt_mode;
extern void *__printfunc;
#endif
extern void __createSpeedParam(void);
#ifndef _FINALROM
/* 機種依存の print (callback) */
volatile static unsigned *stat= (unsigned *)0xbff08004;
volatile static unsigned *wport=(unsigned *)0xbff08000;
volatile static unsigned *piok= (unsigned *)0xa4600010;
extern s32 __kmc_pt_mode;
static void rmonPutchar(char c)
{
#if 0
while((*piok & 3)!=0) ;
while((*stat & 4)==0) ;
*wport=c;
#else
u32 data;
while(1){
osPiReadIo(stat,&data);
if (data & 4){
osPiWriteIo(wport,c);
break;
}
}
#endif
}
static void *kmc_proutSyncPrintf(void *str, const char *buf, int n)
{
int i;
char c,*p,*q,xbuf[128];
static int column = 0;
p=xbuf;
for(i=0;i<n;++i){
c=*(buf++);
switch (c) {
case '\n':
*(p++)='\n';
column = 0;
break;
case '\t':
do{
*(p++)=' ';
}while(++column % 8);
break;
default:
column++;
*(p++)=c;
break;
}
if(c=='\n' || (p-xbuf)>100){
rmonPutchar((p-xbuf)-1);
q=xbuf;
while(q!=p){
rmonPutchar(*(q++));
}
p=xbuf;
}
}
if(p!=xbuf){
rmonPutchar((p-xbuf)-1);
q=xbuf;
while(q!=p){
rmonPutchar(*(q++));
}
}
return ((void *) 1); /* return a fake pointer so that it's not NULL */
}
#endif
void
__osInitialize_kmc(void)
{
#ifndef _FINALROM
/* デバッガ機種依存の初期化 */
if(__kmc_pt_mode==0){
int (*fnc)();
unsigned *src,*dst;
unsigned monadr;
extern unsigned __ptExceptionPreamble[];
volatile unsigned *mon;
volatile unsigned *stat;
stat= (unsigned *)0xbff08004;
mon=(unsigned *)0xbff00000;
if(*mon!=0x4b4d4300) return;
/*
* Copy partner exception preamble to 0x8000_0180-019f
* Since leoBootID variable starts from 0x8000_01a0,
* exception preamble should not be overwrapped.
*/
src=(unsigned *)__ptExceptionPreamble;
dst=(unsigned *)E_VEC;
*(dst++)=*(src++); /* 0x8000_0180 */
*(dst++)=*(src++); /* 0x8000_0184 */
*(dst++)=*(src++); /* 0x8000_0188 */
src+=2;
dst+=2;
*(dst++)=*(src++); /* 0x8000_0194 */
*(dst++)=*(src++); /* 0x8000_0198 */
*(dst++)=*(src++); /* 0x8000_019c */
osWritebackDCache((void*)E_VEC,9*sizeof(unsigned));
osInvalICache((void*)E_VEC,9*sizeof(unsigned));
__kmc_pt_mode=1;
if((*stat & 0x10)==0){ /* RUN OFF ? */
monadr=*(mon+1);
if(monadr!=0xbff00000){
unsigned *src,*dst;
unsigned ct;
dst=(unsigned *)(monadr | 0x20000000);
ct=0x2000/4;
src=(unsigned *)0xbff00000;
while(ct){
*(dst++)=*(src++);
--ct;
}
}
(unsigned int *)fnc = monadr+8;
(*fnc)(0x4b4d4300,0);
}
__printfunc = (void*)&kmc_proutSyncPrintf;
}
#endif
}
/* デバッガの接続チェック */
int __checkHardware_kmc(void)
{
volatile unsigned *mon;
mon=(unsigned *)0xbff00000;
if(*mon==0x4b4d4300){
mon = (unsigned *)0xbff00010;
if(*mon == 0xb0ffb000)
return 1;
else
return 0;
}
else
return 0;
}