-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgenram
executable file
·140 lines (137 loc) · 2.8 KB
/
genram
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
#!/usr/bin/perl
my ($myedata,$myend,$initmips,$mystart,$tgt_putchar);
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);
}
if(/([0-9a-f]+).+\stgt_putchar$/){
$tgt_putchar=qq(0x$1);
}
}
printf(<< "END"
#define NOMSG
typedef long long off_t;
struct callvectors {
int (*open) (char *, int, int);
int (*close) (int);
int (*read) (int, void *, int);
int (*write) (int, void *, int);
off_t (*lseek) (int, off_t, int);
int (*printf) (const char *, ...);
void (*cacheflush) (void);
char *(*gets) (char *);
};
struct callvectors *cvs;
void realinitmips(unsigned int msize);
#ifndef NOCACHE2
void flush_cache2()
{
asm volatile(\
" mfc0 \$3, \$15 # read processor ID register;" \\
" li \$2, 0x6303 #godson2f prid;" \\
" beq \$2, \$3, godson_2f;" \\
" nop;" \\
" li \$2, 0x6302 #godson2e prid;" \\
" bne \$2, \$3,11f ;"\\
" nop;" \\
"# godson2e;" \\
"godson_2f:;" \\
" li \$2, 0x80000000;" \\
" addu \$3,\$2,512*1024;" \\
"10:;" \\
" cache 3, 0(\$2);" \\
" cache 3, 1(\$2);" \\
" cache 3, 2(\$2);" \\
" cache 3, 3(\$2);" \\
" addu \$2, 32;" \\
" bne \$2,\$3, 10b;" \\
" nop;" \\
"11:;" \\
::
:"\$2","\$3"
);
}
#else
void flush_cache()
{
asm volatile(\
" .set mips3;;" \\
" li \$5,0x80000000;" \\
" addu \$6,\$5,16384;" \\
"1:;" \\
" cache 1,0(\$5);" \\
" cache 1,1(\$5);" \\
" cache 1,2(\$5);" \\
" cache 1,3(\$5);" \\
" cache 0,(\$5);" \\
" add \$5,\$5,32;" \\
" bne \$5,\$6,1b;" \\
" nop;" \\
" .set mips0;;" \\
::
: "\$5","\$6");
}
#endif
void initmips(unsigned int msize,struct callvectors *cv)
{
int *edata=(void *)$myedata;
int *end=(void *)$myend;
int *p;
cvs=cv;
tgt_puts("Uncompressing Bios");
run_unzip(biosdata,$mystart);
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
// cv->cacheflush();
tgt_puts("flush_cache...");
#ifdef NOCACHE2
flush_cache();
#else
flush_cache2();
#endif
tgt_puts("done,boot now\\r\\n");
realinitmips(msize);
}
void realinitmips(unsigned int msize)
{
asm ("li \$29,$mystart-0x4000;" \
"li \$2,$myinitmips;" \
"move \$4,\%0;" \
"jalr \$2;" \
" nop;" \
"1: b 1b;nop;"
:
: "r" (msize)
: "\$29", "\$2","\$4");
}
static void (*rom_putchar)(char c)=(${tgt_putchar}-${mystart}+0xffffffffbfc00000);
void tgt_putchar(char c)
{
#ifndef NOMSG
cvs->printf("%%c",c);
#endif
}
int tgt_puts(char *str)
{
#ifndef NOMSG
cvs->printf("%%s",str);
#endif
}
END
);