Rev 3386 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3386 | Rev 4153 | ||
---|---|---|---|
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]; |
11 | int i; |
31 | int i; |
12 | 32 | ||
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; |
40 | 43 | ||
41 | EFI_INPUT_KEY efi_input_key; |
44 | EFI_INPUT_KEY efi_input_key; |
42 | EFI_STATUS efi_status; |
45 | EFI_STATUS efi_status; |
43 | 46 | ||
44 | InitializeLib(image, systab); |
47 | InitializeLib(image, systab); |
45 | 48 | ||
46 | Print(L"HelloLib application started\n"); |
49 | Print(L"HelloLib application started\n"); |
47 | 50 | ||
48 | EFI_GUID LoadedImageProtocol=LOADED_IMAGE_PROTOCOL; |
51 | EFI_GUID LoadedImageProtocol=LOADED_IMAGE_PROTOCOL; |
49 | EFI_GUID DevicePathProtocol=DEVICE_PATH_PROTOCOL; |
52 | EFI_GUID DevicePathProtocol=DEVICE_PATH_PROTOCOL; |
50 | EFI_GUID FileSystemProtocol=SIMPLE_FILE_SYSTEM_PROTOCOL; |
53 | EFI_GUID FileSystemProtocol=SIMPLE_FILE_SYSTEM_PROTOCOL; |
51 | 54 | ||
52 | 55 | ||
53 | EFI_LOADED_IMAGE *LoadedImage; |
56 | EFI_LOADED_IMAGE *LoadedImage; |
54 | EFI_DEVICE_PATH *DevicePath; |
57 | EFI_DEVICE_PATH *DevicePath; |
55 | 58 | ||
56 | BS->HandleProtocol(image, |
59 | BS->HandleProtocol(image, |
57 | &LoadedImageProtocol, |
60 | &LoadedImageProtocol, |
58 | &LoadedImage); |
61 | &LoadedImage); |
59 | BS->HandleProtocol(LoadedImage->DeviceHandle, |
62 | BS->HandleProtocol(LoadedImage->DeviceHandle, |
60 | &DevicePathProtocol, |
63 | &DevicePathProtocol, |
61 | &DevicePath); |
64 | &DevicePath); |
62 | Print (L"Image device : %s\n", DevicePathToStr (DevicePath)); |
65 | Print (L"Image device : %s\n", DevicePathToStr (DevicePath)); |
63 | Print (L"Image file : %s\n", DevicePathToStr (LoadedImage->FilePath)); |
66 | Print (L"Image file : %s\n", DevicePathToStr (LoadedImage->FilePath)); |
64 | Print (L"Image Base : %X\n", LoadedImage->ImageBase); |
67 | Print (L"Image Base : %X\n", LoadedImage->ImageBase); |
65 | Print (L"Image Size : %X\n", LoadedImage->ImageSize); |
68 | Print (L"Image Size : %X\n", LoadedImage->ImageSize); |
66 | 69 | ||
67 | 70 | ||
68 | 71 | ||
69 | EFI_FILE_IO_INTERFACE *Vol; |
72 | EFI_FILE_IO_INTERFACE *Vol; |
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; |
90 | 95 | ||
91 | 96 | ||
92 | 97 | ||
93 | while(1) if(LoadOptions[i++]!=L' ') break; |
98 | while(1) if(LoadOptions[i++]!=L' ') break; |
94 | while(LoadOptions[i]!=L' '){ |
99 | while(LoadOptions[i]!=L' '){ |
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 | 131 | ||
- | 132 | imageLoad=1; |
|
- | 133 | #ifdef IMAGE_LINKED |
|
- | 134 | if(defaultLoad) { |
|
113 | //Print(L"%s\n",FileName); |
135 | Print(L"Using Linked Image\n"); |
- | 136 | imageLoad=0; |
|
- | 137 | } |
|
- | 138 | #endif |
|
- | 139 | ||
- | 140 | ||
- | 141 | char * HOS; |
|
- | 142 | if(imageLoad) |
|
- | 143 | { |
|
- | 144 | Size = 0x00400000; |
|
- | 145 | ||
- | 146 | Vol->OpenVolume (Vol, &CurDir); |
|
114 | 147 | ||
115 | EFI_STATUS stat; |
148 | EFI_STATUS stat; |
116 | stat=CurDir->Open(CurDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0); |
149 | stat=CurDir->Open(CurDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0); |
117 | if(EFI_ERROR(stat)){ |
150 | if(EFI_ERROR(stat)){ |
118 | Print(L"Error Opening Image %s\n",FileName); |
151 | Print(L"Error Opening Image %s\n",FileName); |
119 | return 0; |
152 | return 0; |
120 | } |
153 | } |
121 | Size = 0x00400000; |
- | |
122 | BS->AllocatePool(EfiLoaderData, Size, &OsKernelBuffer); |
154 | BS->AllocatePool(EfiLoaderData, Size, &OsKernelBuffer); |
123 | FileHandle->Read(FileHandle, &Size, OsKernelBuffer); |
155 | FileHandle->Read(FileHandle, &Size, OsKernelBuffer); |
124 | FileHandle->Close(FileHandle); |
156 | FileHandle->Close(FileHandle); |
125 | - | ||
- | 157 | HOS = OsKernelBuffer; |
|
126 | if(Size<1) return 0; |
158 | if(Size<1) return 0; |
127 | 159 | ||
- | 160 | } |
|
- | 161 | #ifdef IMAGE_LINKED |
|
128 | 162 | else { |
|
129 | char * HOS = OsKernelBuffer; |
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 | } |
185 | 311 |