OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / boottools / himemloader.c
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6
7 #ifdef CONFIG_BOOTTOOLS_HIMEMLOADER_EMULATE_CHIP_RESET
8 #include <linux/config.h>
9 #ifdef CONFIG_UCSIMM
10 #include <asm/MC68EZ328.h>
11 #endif
12 #ifdef CONFIG_M68VZ328
13 #include <asm/MC68VZ328.h>
14 #endif
15 #endif
16
17 #define BUFSIZE 4096
18 #define HIMEM_LOCATION 0x00600000
19
20 char spinner[] = { 8, '|' , 8, '\\' , 8, '-', 8, '/'};
21
22 void trap(void) {
23   __asm__ __volatile__ ("oriw #0x2700,%sp@; rte;");
24 };
25
26 int main(int argc,char* argv[]) {
27
28   int fd,cnt,i,b=0;
29   char *file;
30   unsigned char *himem, buf[BUFSIZE];
31
32   if(argc!=2) {
33     printf("usage: himemloader <image.bin>\n");
34     return 0;
35   };
36
37   file=argv[1];
38
39   fd=open(file,O_RDONLY);
40   if(fd==-1) {
41     printf("error opening file [%s]\n",file);
42     return -1;
43   };
44
45   printf("Loading file [%s]\n", file);
46
47   himem=(char*)HIMEM_LOCATION;
48
49   while((cnt=read(fd,buf,BUFSIZE))) {
50     write(1, &spinner[(b++ & 3) << 1], 2);
51     for(i=0;i<cnt;i++) {
52       *himem++=buf[i];
53     };
54   };
55
56   close(fd);
57
58   // switch to supervisor mode
59   *((int*)0x000000a8)=(int)trap;
60   __asm__ __volatile__ ("trap #10");
61
62 #if CONFIG_BOOTTOOLS_HIMEMLOADER_EMULATE_CHIP_RESET
63   SCR = 0x1C;
64   CSGBA = 0x0000;
65   CSGBB = 0x0000;
66   CSGBC = 0x0000;
67   CSGBD = 0x0000;
68   CSA = 0x00E0;
69   CSB = 0x0000;
70   CSC = 0x0000;
71   CSD = 0x0200;
72   EMUCS = 0x0060;
73   PLLCR = 0x2340;
74   PLLFSR = 0x0123;
75   PCTRL = 0x1F;
76   IVR = 0x00;
77   ICR = 0x0000;
78   IMR = 0x00FFFFFF;
79   ISR = 0x00000000;
80   IPR = 0x00000000;
81   PADIR = 0x00;
82   PADATA = 0x00;
83   PAPUEN = 0xFF;
84   PBDIR = 0x00;
85   PBDATA = 0x00;
86   PBPUEN = 0xFF;
87   PBSEL = 0xFF;
88   PCDIR = 0x00;
89   PCDATA = 0x00;
90   PCPDEN = 0xFF;
91   PCSEL = 0xFF;
92   PDDIR = 0x00;
93   PDDATA = 0x00;
94   PDPUEN = 0xFF;
95   PDSEL = 0xF0;
96   PDPOL = 0x00;
97   PDIRQEN = 0x00;
98   PDKBEN = 0x00;
99   PDIQEG = 0x00;
100   PEDIR = 0x00;
101   PEDATA = 0x00;
102   PEPUEN = 0xFF;
103   PESEL = 0xFF;
104   PFDIR = 0x00;
105   PFDATA = 0x00;
106   PFPUEN = 0xFF;
107   PFSEL = 0x00;
108   PGDIR = 0x00;
109   PGDATA = 0x00;
110   PGPUEN = 0x3D;
111   PGSEL = 0x08;
112   PWMC = 0x0020;
113   PWMP = 0xFE;
114   PWMCNT = 0x00;
115   TCTL = 0x0000;
116   TPRER = 0x0000;
117   TCMP = 0xFFFF;
118   TCR = 0x0000;
119   TCN = 0x0000;
120   TSTAT = 0x0000;
121   SPIMDATA = 0x0000;
122   SPIMCONT = 0x0000;
123   USTCNT = 0x0000;
124   UBAUD = 0x003F;
125   URX = 0x0000;
126   UTX = 0x0000;
127   UMISC = 0x0000;
128   NIPR = 0x0000;
129   LSSA = 0x00000000;
130   LVPW = 0xFF;
131   LXMAX = 0x03FF;
132   LYMAX = 0x01FF;
133   LCXP = 0x0000;
134   LCYP = 0x0000;
135   LCWCH = 0x0101;
136   LBLKC = 0x7F;
137   LPICF = 0x00;
138   LPOLCF = 0x00;
139   LACDRC = 0x00;
140   LPXCD = 0x00;
141   LCKCON = 0x40;
142   LRRA = 0xFF;
143   LPOSR = 0x00;
144   LFRCM = 0xB9;
145   LGPMR = 0x84;
146   PWMR = 0x0000;
147   RTCTIME = 0x00000000;
148   RTCALRM = 0x00000000;
149   WATCHDOG = 0x0001;
150   RTCCTL = 0x00;
151   RTCISR = 0x00;
152   RTCIENR = 0x00;
153   STPWCH = 0x00;
154   DAYALARM = 0x0000;
155   // DRAMMC = 0x00000000;
156   // DRAMC = 0x00000000;
157   ICEMACR = 0x00000000;
158   ICEMAMR = 0x00000000;
159   ICEMCCR = 0x0000;
160   ICEMCMR = 0x0000;
161   ICEMCR = 0x0000;
162   ICEMSR = 0x0000;
163 #endif
164
165   // start loaded kernel
166   __asm__ __volatile__ ("movel #0x00600004,%a0; jmp (%a0);");
167
168   return 0;
169 };