Add support store ddr param in flash.
[xloong.git] / zloader / genram
blobcceb189f785827401f4dae43d4c8d57d4eab8e9d
1 #!/usr/bin/perl
2 my ($myedata,$myend,$initmips,$mystart,$tgt_putchar);
3 open(F,qq(mipsel-linux-objdump -x $ARGV[0]|));
4 while(<F>)
6 chomp;
7 if(/([0-9a-f]+).+_edata/){
8 $myedata=qq(0x$1);
11 if(/([0-9a-f]+).+_end$/){
12 $myend=qq(0x$1);
14 if(/([0-9a-f]+).+initmips$/){
15 $myinitmips=qq(0x$1);
17 if(/([0-9a-f]+).+\s_start$/){
18 $mystart=qq(0x$1);
20 if(/([0-9a-f]+).+\stgt_putchar$/){
21 $tgt_putchar=qq(0x$1);
24 printf(<< "END"
25 #define NOMSG
26 typedef long long off_t;
27 struct callvectors {
28 int (*open) (char *, int, int);
29 int (*close) (int);
30 int (*read) (int, void *, int);
31 int (*write) (int, void *, int);
32 off_t (*lseek) (int, off_t, int);
33 int (*printf) (const char *, ...);
34 void (*cacheflush) (void);
35 char *(*gets) (char *);
37 struct callvectors *cvs;
38 void realinitmips(unsigned int msize);
39 #ifndef NOCACHE2
40 void flush_cache2()
42 asm volatile(\
43 " mfc0 \$3, \$15 # read processor ID register;" \\
44 " li \$2, 0x6303 #godson2f prid;" \\
45 " beq \$2, \$3, godson_2f;" \\
46 " nop;" \\
47 " li \$2, 0x6302 #godson2e prid;" \\
48 " bne \$2, \$3,11f ;"\\
49 " nop;" \\
50 "# godson2e;" \\
51 "godson_2f:;" \\
52 " li \$2, 0x80000000;" \\
53 " addu \$3,\$2,512*1024;" \\
54 "10:;" \\
55 " cache 3, 0(\$2);" \\
56 " cache 3, 1(\$2);" \\
57 " cache 3, 2(\$2);" \\
58 " cache 3, 3(\$2);" \\
59 " addu \$2, 32;" \\
60 " bne \$2,\$3, 10b;" \\
61 " nop;" \\
62 "11:;" \\
64 :"\$2","\$3"
67 #else
68 void flush_cache()
70 asm volatile(\
71 " .set mips3;;" \\
72 " li \$5,0x80000000;" \\
73 " addu \$6,\$5,16384;" \\
74 "1:;" \\
75 " cache 1,0(\$5);" \\
76 " cache 1,1(\$5);" \\
77 " cache 1,2(\$5);" \\
78 " cache 1,3(\$5);" \\
79 " cache 0,(\$5);" \\
80 " add \$5,\$5,32;" \\
81 " bne \$5,\$6,1b;" \\
82 " nop;" \\
83 " .set mips0;;" \\
85 : "\$5","\$6");
87 #endif
88 void initmips(unsigned int msize,struct callvectors *cv)
90 int *edata=(void *)$myedata;
91 int *end=(void *)$myend;
92 int *p;
93 cvs=cv;
94 stringserial("Uncompressing Bios");
95 run_unzip(biosdata,$mystart);
96 stringserial("OK,Booting Bios\\r\\n");
97 for(p=edata;p<=end;p++)
99 *p=0;
101 memset($mystart-0x1000,0,0x1000);//$mystart-0x1000 for frame(registers),memset for pretty
102 // cv->cacheflush();
103 stringserial("flush_cache...");
104 #ifdef NOCACHE2
105 flush_cache();
106 #else
107 flush_cache2();
108 #endif
109 stringserial("done,boot now\\r\\n");
110 realinitmips(msize);
113 void realinitmips(unsigned int msize)
115 asm ("li \$29,$mystart-0x4000;" \
116 "li \$2,$myinitmips;" \
117 "move \$4,\%0;" \
118 "jalr \$2;" \
119 " nop;" \
120 "1: b 1b;nop;"
122 : "r" (msize)
123 : "\$29", "\$2","\$4");
126 static void (*rom_putchar)(char c)=(${tgt_putchar}-${mystart}+0xffffffffbfc00000);
127 void tgt_putchar(char c)
129 #ifndef NOMSG
130 cvs->printf("%%c",c);
131 #endif
133 void stringserial(char *str)
135 #ifndef NOMSG
136 cvs->printf("%%s",str);
137 #endif