Rev 3022 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3022 | Rev 4055 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include <efi.h> |
1 | #include <efi.h> |
2 | #include <efilib.h> |
2 | #include <efilib.h> |
3 | 3 | ||
- | 4 | #include <../../../../../../kernel/arch/ia64/include/bootinfo.h> |
|
- | 5 | ||
4 | #define KERNEL_LOAD_ADDRESS 0x4400000 |
6 | #define KERNEL_LOAD_ADDRESS 0x4400000 |
5 | 7 | ||
- | 8 | #define MEM_MAP_DESCRIPTOR_OFFSET_TYPE 0 |
|
- | 9 | #define MEM_MAP_DESCRIPTOR_OFFSET_BASE 8 |
|
- | 10 | #define MEM_MAP_DESCRIPTOR_OFFSET_PAGES 24 |
|
- | 11 | ||
- | 12 | ||
- | 13 | ||
- | 14 | //Link image as a data array into hello - usefull with network boot |
|
- | 15 | //#define IMAGE_LINKED |
|
- | 16 | ||
- | 17 | bootinfo_t *bootinfo=(bootinfo_t *)BOOTINFO_ADDRESS; |
|
- | 18 | ||
- | 19 | ||
- | 20 | #ifdef IMAGE_LINKED |
|
- | 21 | extern char HOSimage[]; |
|
- | 22 | extern int HOSimagesize; |
|
- | 23 | #endif |
|
- | 24 | ||
- | 25 | ||
6 | 26 | ||
7 | static CHAR16 * |
27 | static CHAR16 * |
8 | a2u (char *str) |
28 | a2u (char *str) |
9 | { |
29 | { |
10 | static CHAR16 mem[2048]; |
30 | static CHAR16 mem[2048]; |
Line 13... | Line 33... | ||
13 | for (i = 0; str[i]; ++i) |
33 | for (i = 0; str[i]; ++i) |
14 | mem[i] = (CHAR16) str[i]; |
34 | mem[i] = (CHAR16) str[i]; |
15 | mem[i] = 0; |
35 | mem[i] = 0; |
16 | return mem; |
36 | return mem; |
17 | } |
37 | } |
18 | char HEX[256]; |
- | |
19 | - | ||
20 | char hexs[]="0123456789ABCDEF"; |
- | |
21 | /* |
- | |
22 | void to_hex(unsigned long long num) |
- | |
23 | { |
- | |
24 | int a; |
- | |
25 | for(a=15;a>=0;a--) |
- | |
26 | { |
- | |
27 | char c=num - (num & 0xfffffffffffffff0LL); |
- | |
28 | num/=16; |
- | |
29 | c=hexs[c]; |
- | |
30 | HEX[a]=c; |
- | |
31 | } |
- | |
32 | - | ||
33 | } |
- | |
34 | */ |
- | |
35 | 38 | ||
36 | EFI_STATUS |
39 | EFI_STATUS |
37 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) |
40 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) |
38 | { |
41 | { |
39 | SIMPLE_TEXT_OUTPUT_INTERFACE *conout; |
42 | SIMPLE_TEXT_OUTPUT_INTERFACE *conout; |
Line 70... | Line 73... | ||
70 | 73 | ||
71 | EFI_FILE *CurDir; |
74 | EFI_FILE *CurDir; |
72 | EFI_FILE *FileHandle; |
75 | EFI_FILE *FileHandle; |
73 | 76 | ||
74 | BS->HandleProtocol(LoadedImage->DeviceHandle, &FileSystemProtocol, &Vol); |
77 | BS->HandleProtocol(LoadedImage->DeviceHandle, &FileSystemProtocol, &Vol); |
75 | Vol->OpenVolume (Vol, &CurDir); |
- | |
76 | 78 | ||
77 | char FileName[1024]; |
79 | char FileName[1024]; |
78 | char *OsKernelBuffer; |
80 | char *OsKernelBuffer; |
79 | int i; |
81 | int i; |
- | 82 | int defaultLoad; |
|
- | 83 | int imageLoad; |
|
80 | UINTN Size; |
84 | UINTN Size; |
81 | 85 | ||
82 | StrCpy(FileName,DevicePathToStr(LoadedImage->FilePath)); |
86 | StrCpy(FileName,DevicePathToStr(LoadedImage->FilePath)); |
83 | for(i=StrLen(FileName);i>=0 && FileName[i]!='\\';i--); |
87 | for(i=StrLen(FileName);i>=0 && FileName[i]!='\\';i--); |
84 | FileName[i] = 0; |
88 | FileName[i] = 0; |
- | 89 | FileName[0] = 0; |
|
85 | 90 | ||
86 | Print(L"%s\n",LoadedImage->LoadOptions); |
91 | Print(L"%s\n",LoadedImage->LoadOptions); |
87 | 92 | ||
88 | i=0; |
93 | i=0; |
89 | CHAR16 *LoadOptions = LoadedImage->LoadOptions; |
94 | CHAR16 *LoadOptions = LoadedImage->LoadOptions; |
Line 95... | Line 100... | ||
95 | if(LoadOptions[i]==0) break; |
100 | if(LoadOptions[i]==0) break; |
96 | i++; |
101 | i++; |
97 | } |
102 | } |
98 | while(LoadOptions[i]==L' ') if(LoadOptions[i++]==0) break; |
103 | while(LoadOptions[i]==L' ') if(LoadOptions[i++]==0) break; |
99 | 104 | ||
100 | if(LoadOptions[i++]==0) |
105 | if(LoadOptions[i++]==0){ |
101 | StrCat(FileName,L"\\image.bin"); |
106 | StrCat(FileName,L"\\image.bin"); |
- | 107 | defaultLoad=1; |
|
- | 108 | } |
|
102 | else{ |
109 | /* else{ |
103 | CHAR16 buf[1024]; |
110 | CHAR16 buf[1024]; |
104 | buf[0]='\\'; |
111 | //buf[0]='\\'; |
105 | i--; |
112 | i--; |
106 | int j; |
113 | int j; |
107 | for(j=0;LoadOptions[i+j]!=L' '&&LoadOptions[i+j]!=0;j++) |
114 | for(j=0;LoadOptions[i+j]!=L' '&&LoadOptions[i+j]!=0;j++) |
108 | buf[j+1]=LoadOptions[i+j]; |
115 | buf[j+1]=LoadOptions[i+j]; |
109 | buf[j+1]=0; |
116 | buf[j+1]=0; |
110 | StrCat(FileName,buf); |
117 | StrCat(FileName,buf); |
- | 118 | defaultLoad=0; |
|
- | 119 | }*/ |
|
- | 120 | else{ |
|
- | 121 | CHAR16 buf[1024]; |
|
- | 122 | //buf[0]='\\'; |
|
- | 123 | i--; |
|
- | 124 | int j; |
|
- | 125 | for(j=0;LoadOptions[i+j]!=L' '&&LoadOptions[i+j]!=0;j++) |
|
- | 126 | buf[j]=LoadOptions[i+j]; |
|
- | 127 | buf[j+1]=0; |
|
- | 128 | StrCat(FileName,buf); |
|
- | 129 | defaultLoad=0; |
|
111 | } |
130 | } |
112 | - | ||
113 | //Print(L"%s\n",FileName); |
- | |
114 | 131 | ||
115 | EFI_STATUS stat; |
132 | imageLoad=1; |
116 | stat=CurDir->Open(CurDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0); |
133 | #ifdef IMAGE_LINKED |
117 | if(EFI_ERROR(stat)){ |
134 | if(defaultLoad) { |
118 | Print(L"Error Opening Image %s\n",FileName); |
135 | Print(L"Using Linked Image\n"); |
119 | return 0; |
136 | imageLoad=0; |
120 | } |
137 | } |
121 | Size = 0x00400000; |
138 | #endif |
122 | BS->AllocatePool(EfiLoaderData, Size, &OsKernelBuffer); |
- | |
123 | FileHandle->Read(FileHandle, &Size, OsKernelBuffer); |
- | |
124 | FileHandle->Close(FileHandle); |
- | |
- | 139 | ||
125 | 140 | ||
- | 141 | char * HOS; |
|
- | 142 | if(imageLoad) |
|
- | 143 | { |
|
126 | if(Size<1) return 0; |
144 | Size = 0x00400000; |
127 | 145 | ||
- | 146 | Vol->OpenVolume (Vol, &CurDir); |
|
128 | 147 | ||
- | 148 | EFI_STATUS stat; |
|
- | 149 | stat=CurDir->Open(CurDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0); |
|
- | 150 | if(EFI_ERROR(stat)){ |
|
- | 151 | Print(L"Error Opening Image %s\n",FileName); |
|
- | 152 | return 0; |
|
- | 153 | } |
|
- | 154 | BS->AllocatePool(EfiLoaderData, Size, &OsKernelBuffer); |
|
- | 155 | FileHandle->Read(FileHandle, &Size, OsKernelBuffer); |
|
- | 156 | FileHandle->Close(FileHandle); |
|
129 | char * HOS = OsKernelBuffer; |
157 | HOS = OsKernelBuffer; |
- | 158 | if(Size<1) return 0; |
|
- | 159 | ||
- | 160 | } |
|
- | 161 | #ifdef IMAGE_LINKED |
|
- | 162 | else { |
|
- | 163 | HOS = HOSimage; |
|
- | 164 | Size = HOSimagesize; |
|
- | 165 | Print(L"Image start %llX\n",(long long)HOS); |
|
- | 166 | Print(L"Image size %llX\n",(long long)Size); |
|
- | 167 | Print(L"Image &size %llX\n",(long long)&Size); |
|
- | 168 | } |
|
- | 169 | #endif |
|
130 | int HOSSize = Size; |
170 | int HOSSize = Size; |
131 | 171 | ||
132 | 172 | ||
- | 173 | rArg rSAL; |
|
- | 174 | rArg rPAL; |
|
- | 175 | ||
- | 176 | //Setup AP's wake up address |
|
- | 177 | LibSalProc(0x01000000,2,0x4400200,0,0,0,0,0,&rSAL); |
|
- | 178 | ||
- | 179 | ||
- | 180 | //Get System Frequency |
|
- | 181 | UINT64 sys_freq; |
|
- | 182 | LibSalProc(0x01000012,0,0,0,0,0,0,0,&rSAL); |
|
- | 183 | sys_freq=rSAL.p1; |
|
133 | { |
184 | |
- | 185 | ||
- | 186 | UINT64 freq_scale; |
|
- | 187 | //Get CPU Frequency to System Frequency ratio |
|
- | 188 | LibPalProc(14,0,0,0,&rPAL); |
|
- | 189 | freq_scale=rPAL.p1; |
|
- | 190 | ||
- | 191 | ||
- | 192 | UINT64 sapic; |
|
- | 193 | LibGetSalIpiBlock(&sapic); |
|
- | 194 | Print (L"SAPIC:%X\n", sapic); |
|
- | 195 | //bootinfo->sapic=sapic; |
|
- | 196 | ||
- | 197 | ||
- | 198 | UINT64 wakeup_intno; |
|
- | 199 | LibGetSalWakeupVector(&wakeup_intno); |
|
- | 200 | Print (L"WAKEUP INTNO:%X\n", wakeup_intno); |
|
- | 201 | ||
- | 202 | ||
- | 203 | ||
- | 204 | ||
- | 205 | ||
134 | UINTN cookie; |
206 | UINTN cookie; |
135 | void *p=(void *)KERNEL_LOAD_ADDRESS; |
207 | void *p=(void *)KERNEL_LOAD_ADDRESS; |
136 | UINTN mapsize,descsize; |
208 | UINTN mapsize,descsize; |
137 | UINT32 desver; |
209 | UINT32 desver; |
138 | EFI_STATUS status; |
210 | EFI_STATUS status; |
139 | EFI_MEMORY_DESCRIPTOR emd[1024]; |
- | |
140 | 211 | ||
141 | 212 | ||
142 | mapsize=1024*sizeof(emd); |
- | |
143 | 213 | ||
144 | status=BS->AllocatePages(AllocateAnyPages,EfiLoaderData,/*(HOSSize>>12)+1*/ 1,p); |
214 | status=BS->AllocatePages(AllocateAnyPages,EfiLoaderData,/*(HOSSize>>12)+1*/ 1,p); |
145 | if(EFI_ERROR(status)){ |
215 | if(EFI_ERROR(status)){ |
146 | Print(L"Error 0\n"); |
216 | Print(L"Error 0\n"); |
147 | if(status == EFI_OUT_OF_RESOURCES) Print(L"EFI_OUT_OF_RESOURCES\n"); |
217 | if(status == EFI_OUT_OF_RESOURCES) Print(L"EFI_OUT_OF_RESOURCES\n"); |
148 | if(status == EFI_INVALID_PARAMETER) Print(L"EFI_INVALID_PARAMETER\n"); |
218 | if(status == EFI_INVALID_PARAMETER) Print(L"EFI_INVALID_PARAMETER\n"); |
149 | if(status == EFI_NOT_FOUND) Print(L"EFI_NOT_FOUND\n"); |
219 | if(status == EFI_NOT_FOUND) Print(L"EFI_NOT_FOUND\n"); |
150 | return EFI_SUCCESS; |
220 | return EFI_SUCCESS; |
151 | } |
221 | } |
152 | 222 | ||
- | 223 | UINTN no_entryes; |
|
- | 224 | void * mds; |
|
153 | status=BS->GetMemoryMap(&mapsize,emd,&cookie,&descsize,&desver); |
225 | mds=LibMemoryMap(&no_entryes,&cookie,&descsize,&desver); |
- | 226 | ||
154 | if(EFI_ERROR(status)){ |
227 | for(i=0;i<no_entryes;i++) |
155 | Print(L"Error 1\n"); |
228 | { |
- | 229 | ||
- | 230 | unsigned int type=*((unsigned int *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_TYPE)); |
|
- | 231 | unsigned long long base=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_BASE)); |
|
- | 232 | unsigned long long pages=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_PAGES)); |
|
156 | return EFI_SUCCESS; |
233 | Print(L"T:%02d %016llX %016llX\n",type,base,pages*EFI_PAGE_SIZE); |
- | 234 | ||
157 | } |
235 | } |
158 | status=BS->ExitBootServices(image,cookie); |
236 | status=BS->ExitBootServices(image,cookie); |
159 | if(EFI_ERROR(status)){ |
237 | if(EFI_ERROR(status)){ |
160 | Print(L"Error 2\n"); |
238 | Print(L"Error 2\n"); |
161 | return EFI_SUCCESS; |
239 | return EFI_SUCCESS; |
162 | } |
240 | } |
163 | 241 | ||
164 | } |
242 | |
165 | int a; |
243 | int a; |
166 | 244 | ||
167 | for(a=0;a<HOSSize;a++){ |
245 | for(a=0;a<HOSSize;a++){ |
168 | ((char *)(0x4400000))[a]=HOS[a]; |
246 | ((char *)(0x4400000))[a]=HOS[a]; |
169 | } |
247 | } |
- | 248 | bootinfo->sapic=(unsigned long *)sapic; |
|
- | 249 | bootinfo->wakeup_intno=wakeup_intno; |
|
- | 250 | bootinfo->sys_freq=sys_freq; |
|
- | 251 | bootinfo->freq_scale=freq_scale; |
|
- | 252 | bootinfo->hello_configured=1; |
|
- | 253 | ||
- | 254 | ||
- | 255 | bootinfo->memmap_items=0; |
|
- | 256 | ||
- | 257 | for(i=0;i<no_entryes;i++) |
|
- | 258 | { |
|
- | 259 | ||
- | 260 | unsigned int type=*((unsigned int *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_TYPE)); |
|
- | 261 | unsigned long long base=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_BASE)); |
|
- | 262 | unsigned long long pages=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_PAGES)); |
|
- | 263 | ||
- | 264 | ||
- | 265 | ||
- | 266 | switch (type) |
|
- | 267 | { |
|
- | 268 | case EfiConventionalMemory: |
|
- | 269 | bootinfo->memmap[bootinfo->memmap_items].type=EFI_MEMMAP_FREE_MEM; |
|
- | 270 | bootinfo->memmap[bootinfo->memmap_items].base=base; |
|
- | 271 | bootinfo->memmap[bootinfo->memmap_items].size=pages*EFI_PAGE_SIZE; |
|
- | 272 | bootinfo->memmap_items++; |
|
- | 273 | break; |
|
- | 274 | case EfiMemoryMappedIO: |
|
- | 275 | bootinfo->memmap[bootinfo->memmap_items].type=EFI_MEMMAP_IO; |
|
- | 276 | bootinfo->memmap[bootinfo->memmap_items].base=base; |
|
- | 277 | bootinfo->memmap[bootinfo->memmap_items].size=pages*EFI_PAGE_SIZE; |
|
- | 278 | bootinfo->memmap_items++; |
|
- | 279 | break; |
|
- | 280 | case EfiMemoryMappedIOPortSpace: |
|
- | 281 | bootinfo->memmap[bootinfo->memmap_items].type=EFI_MEMMAP_IO_PORTS; |
|
- | 282 | bootinfo->memmap[bootinfo->memmap_items].base=base; |
|
- | 283 | bootinfo->memmap[bootinfo->memmap_items].size=pages*EFI_PAGE_SIZE; |
|
- | 284 | bootinfo->memmap_items++; |
|
- | 285 | break; |
|
- | 286 | ||
- | 287 | default : |
|
- | 288 | break; |
|
- | 289 | } |
|
- | 290 | ||
- | 291 | ||
- | 292 | ||
- | 293 | ||
- | 294 | ||
- | 295 | } |
|
- | 296 | ||
- | 297 | ||
170 | 298 | ||
171 | //Run Kernel |
299 | //Run Kernel |
172 | asm volatile( |
300 | asm volatile( |
173 | "nop.i 0x00 ;;\n" |
301 | "nop.i 0x00 ;;\n" |
174 | "movl r15 = 0x4400000 ;;\n" |
302 | "movl r15 = 0x4400000 ;;\n" |
175 | "mov b0 = r15;;" |
303 | "mov b0 = r15;;" |
176 | "br.few b0;;\n" |
304 | "br.few b0;;\n" |
177 | ); |
305 | ); |
178 | 306 | ||
179 | 307 | ||
180 | while(1){ |
308 | //Not reached |
181 | ((volatile int *)(0x80000000000b8000))[0]++; |
- | |
182 | } |
- | |
183 | return EFI_SUCCESS; |
309 | return EFI_SUCCESS; |
184 | } |
310 | } |