-
Notifications
You must be signed in to change notification settings - Fork 0
/
genrom
executable file
·133 lines (127 loc) · 2.61 KB
/
genrom
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
#!/usr/bin/perl
my ($myedata,$myend,$initmips,$mystart);
open(F,qq(objdump -x $ARGV[0]|));
while(<F>)
{
chomp;
if(/([0-9a-f]+).+_edata/){
$myedata=qq(0x$1);
}
if(/([0-9a-f]+).+_end$/){
$myend=qq(0x$1);
}
if(/([0-9a-f]+).+initmips$/){
$myinitmips=qq(0x$1);
}
if(/([0-9a-f]+).+\s_start$/){
$mystart=qq(0x$1);
}
}
printf(<< "END"
void realinitmips(unsigned int msize);
void enable_cache()
{
__asm__ volatile(
".set mips2;\\n" \\
" mfc0 \$4,\$16;\\n" \\
" and \$4,\$4,0xfffffff8;\\n" \\
" or \$4,\$4,0x3;\\n" \\
" mtc0 \$4,\$16;\\n" \\
" .set mips0;\\n"
::
:"\$4"
);
}
#ifndef NOCACHE2
void flush_cache2()
{
asm volatile(\
".set mips3;\\n" \\
" li \$2, 0x80000000;\\n" \\
" addu \$3,\$2,512*1024/4;\\n" \\
"10:\\n" \\
" cache 3, 0(\$2);\\n" \\
" cache 3, 1(\$2);\\n" \\
" cache 3, 2(\$2);\\n" \\
" cache 3, 3(\$2);\\n" \\
" addu \$2, 32;\\n" \\
" bne \$2,\$3, 10b;\\n" \\
" nop;\\n" \\
:::"\$2","\$3"
);
}
#else
void flush_cache()
{
#ifndef WAYBIT
#define WAYBIT 0
#endif
#define WAY__(x) #x
#define WAY_(x,y) WAY__((x<<y))
#define WAY(x) WAY_(x,WAYBIT)
asm volatile(\
" .set mips3;\\n"
" li \$5,0x80000000;\\n"
" addu \$6,\$5,16384;\\n"
"1:\\n"
" cache 1," WAY(0) "(\$5);\\n"
" cache 1," WAY(1) "(\$5);\\n"
" cache 1," WAY(2) "(\$5);\\n"
" cache 1," WAY(3) "(\$5);\\n"
" cache 0," WAY(0) "(\$5);\\n"
" cache 0," WAY(1) "(\$5);\\n"
" cache 0," WAY(2) "(\$5);\\n"
" cache 0," WAY(3) "(\$5);\\n"
" add \$5,\$5,32;\\n"
" bne \$5,\$6,1b;\\n"
" nop;\\n"
" .set mips0;\\n"
::: "\$5","\$6");
}
#endif
void initmips(unsigned int msize,int dmsize,int dctrl)
{
long *edata=(void *)$myedata;
long *end=(void *)$myend;
int *p;
int debug=(msize==0);
// CPU_TLBClear();
tgt_puts("Uncompressing Bios");
if(!debug||dctrl&1)enable_cache();
while(1)
{
if(run_unzip(biosdata,$mystart)>=0)break;
}
tgt_puts("OK,Booting Bios\\r\\n");
for(p=edata;p<=end;p++)
{
*p=0;
}
memset($mystart-0x1000,0,0x1000);//$mystart-0x1000 for frame(registers),memset for pretty
#ifdef NOCACHE2
flush_cache();
#else
flush_cache2();
#endif
realinitmips(debug?dmsize:msize);
}
void realinitmips(unsigned int msize)
{
asm ("li \$29,$mystart-0x4000;\\n" \\
" li \$2,$myinitmips;\\n" \\
" move \$4,\%0;\\n" \\
" jalr \$2;\\n" \\
" nop;\\n" \\
" 1: b 1b;nop;" \\
:
: "r" (msize)
: "\$29", "\$2","\$4");
}
int tgt_puts(char *str)
{
while(*str)
tgt_putchar(*str++);
return 0;
}
END
);