Rev 2787 | Rev 3623 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2726 | vana | 1 | #include <efi.h> |
2 | #include <efilib.h> |
||
3 | |||
3597 | svoboda | 4 | #include <../../../../../../kernel/arch/ia64/include/bootinfo.h> |
5 | |||
2726 | vana | 6 | #define KERNEL_LOAD_ADDRESS 0x4400000 |
7 | |||
3597 | svoboda | 8 | //Link image as a data array into hello - usefull with network boot |
9 | //#define IMAGE_LINKED |
||
2726 | vana | 10 | |
3597 | svoboda | 11 | bootinfo_t *bootinfo=(bootinfo_t *)BOOTINFO_ADDRESS; |
12 | |||
13 | |||
14 | #ifdef IMAGE_LINKED |
||
15 | extern char HOSimage[]; |
||
16 | extern int HOSimagesize; |
||
17 | #endif |
||
18 | |||
19 | |||
20 | |||
2726 | vana | 21 | static CHAR16 * |
22 | a2u (char *str) |
||
23 | { |
||
24 | static CHAR16 mem[2048]; |
||
25 | int i; |
||
26 | |||
27 | for (i = 0; str[i]; ++i) |
||
28 | mem[i] = (CHAR16) str[i]; |
||
29 | mem[i] = 0; |
||
30 | return mem; |
||
31 | } |
||
32 | |||
33 | EFI_STATUS |
||
34 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) |
||
35 | { |
||
36 | SIMPLE_TEXT_OUTPUT_INTERFACE *conout; |
||
37 | |||
38 | EFI_INPUT_KEY efi_input_key; |
||
39 | EFI_STATUS efi_status; |
||
40 | |||
41 | InitializeLib(image, systab); |
||
42 | |||
43 | Print(L"HelloLib application started\n"); |
||
44 | |||
45 | EFI_GUID LoadedImageProtocol=LOADED_IMAGE_PROTOCOL; |
||
46 | EFI_GUID DevicePathProtocol=DEVICE_PATH_PROTOCOL; |
||
47 | EFI_GUID FileSystemProtocol=SIMPLE_FILE_SYSTEM_PROTOCOL; |
||
48 | |||
49 | |||
50 | EFI_LOADED_IMAGE *LoadedImage; |
||
51 | EFI_DEVICE_PATH *DevicePath; |
||
52 | |||
53 | BS->HandleProtocol(image, |
||
54 | &LoadedImageProtocol, |
||
55 | &LoadedImage); |
||
56 | BS->HandleProtocol(LoadedImage->DeviceHandle, |
||
57 | &DevicePathProtocol, |
||
58 | &DevicePath); |
||
59 | Print (L"Image device : %s\n", DevicePathToStr (DevicePath)); |
||
60 | Print (L"Image file : %s\n", DevicePathToStr (LoadedImage->FilePath)); |
||
61 | Print (L"Image Base : %X\n", LoadedImage->ImageBase); |
||
62 | Print (L"Image Size : %X\n", LoadedImage->ImageSize); |
||
63 | |||
64 | |||
65 | |||
66 | EFI_FILE_IO_INTERFACE *Vol; |
||
67 | |||
68 | EFI_FILE *CurDir; |
||
69 | EFI_FILE *FileHandle; |
||
70 | |||
71 | BS->HandleProtocol(LoadedImage->DeviceHandle, &FileSystemProtocol, &Vol); |
||
72 | |||
73 | char FileName[1024]; |
||
74 | char *OsKernelBuffer; |
||
75 | int i; |
||
3597 | svoboda | 76 | int defaultLoad; |
77 | int imageLoad; |
||
2726 | vana | 78 | UINTN Size; |
79 | |||
80 | StrCpy(FileName,DevicePathToStr(LoadedImage->FilePath)); |
||
81 | for(i=StrLen(FileName);i>=0 && FileName[i]!='\\';i--); |
||
82 | FileName[i] = 0; |
||
83 | |||
84 | Print(L"%s\n",LoadedImage->LoadOptions); |
||
85 | |||
86 | i=0; |
||
87 | CHAR16 *LoadOptions = LoadedImage->LoadOptions; |
||
88 | |||
89 | |||
90 | |||
91 | while(1) if(LoadOptions[i++]!=L' ') break; |
||
92 | while(LoadOptions[i]!=L' '){ |
||
93 | if(LoadOptions[i]==0) break; |
||
94 | i++; |
||
95 | } |
||
96 | while(LoadOptions[i]==L' ') if(LoadOptions[i++]==0) break; |
||
97 | |||
3597 | svoboda | 98 | if(LoadOptions[i++]==0){ |
2726 | vana | 99 | StrCat(FileName,L"\\image.bin"); |
3597 | svoboda | 100 | defaultLoad=1; |
101 | } |
||
2726 | vana | 102 | else{ |
103 | CHAR16 buf[1024]; |
||
104 | buf[0]='\\'; |
||
105 | i--; |
||
106 | int j; |
||
107 | for(j=0;LoadOptions[i+j]!=L' '&&LoadOptions[i+j]!=0;j++) |
||
108 | buf[j+1]=LoadOptions[i+j]; |
||
109 | buf[j+1]=0; |
||
110 | StrCat(FileName,buf); |
||
3597 | svoboda | 111 | defaultLoad=0; |
2726 | vana | 112 | } |
113 | |||
3597 | svoboda | 114 | imageLoad=1; |
115 | #ifdef IMAGE_LINKED |
||
116 | if(defaultLoad) { |
||
117 | Print(L"Using Linked Image\n"); |
||
118 | imageLoad=0; |
||
2726 | vana | 119 | } |
3597 | svoboda | 120 | #endif |
121 | |||
2726 | vana | 122 | |
3597 | svoboda | 123 | char * HOS; |
124 | if(imageLoad) |
||
125 | { |
||
126 | Size = 0x00400000; |
||
2726 | vana | 127 | |
3597 | svoboda | 128 | Vol->OpenVolume (Vol, &CurDir); |
2726 | vana | 129 | |
3597 | svoboda | 130 | EFI_STATUS stat; |
131 | stat=CurDir->Open(CurDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0); |
||
132 | if(EFI_ERROR(stat)){ |
||
133 | Print(L"Error Opening Image %s\n",FileName); |
||
134 | return 0; |
||
135 | } |
||
136 | BS->AllocatePool(EfiLoaderData, Size, &OsKernelBuffer); |
||
137 | FileHandle->Read(FileHandle, &Size, OsKernelBuffer); |
||
138 | FileHandle->Close(FileHandle); |
||
139 | HOS = OsKernelBuffer; |
||
140 | if(Size<1) return 0; |
||
141 | |||
142 | } |
||
143 | #ifdef IMAGE_LINKED |
||
144 | else { |
||
145 | HOS = HOSimage; |
||
146 | Size = HOSimagesize; |
||
147 | Print(L"Image start %llX\n",(long long)HOS); |
||
148 | Print(L"Image size %llX\n",(long long)Size); |
||
149 | Print(L"Image &size %llX\n",(long long)&Size); |
||
150 | } |
||
151 | #endif |
||
2726 | vana | 152 | int HOSSize = Size; |
153 | |||
154 | |||
3597 | svoboda | 155 | rArg rSAL; |
156 | rArg rPAL; |
||
157 | |||
158 | //Setup AP's wake up address |
||
159 | LibSalProc(0x01000000,2,0x4400200,0,0,0,0,0,&rSAL); |
||
160 | |||
161 | |||
162 | //Get System Frequency |
||
163 | UINT64 sys_freq; |
||
164 | LibSalProc(0x01000012,0,0,0,0,0,0,0,&rSAL); |
||
165 | sys_freq=rSAL.p1; |
||
166 | |||
167 | |||
168 | UINT64 freq_scale; |
||
169 | //Get CPU Frequency to System Frequency ratio |
||
170 | LibPalProc(14,0,0,0,&rPAL); |
||
171 | freq_scale=rPAL.p1; |
||
172 | |||
173 | |||
174 | UINT64 sapic; |
||
175 | LibGetSalIpiBlock(&sapic); |
||
176 | Print (L"SAPIC:%X\n", sapic); |
||
177 | //bootinfo->sapic=sapic; |
||
178 | |||
179 | |||
180 | int wakeup_intno; |
||
181 | wakeup_intno=0xf0; |
||
182 | Print (L"WAKEUP INTNO:%X\n", wakeup_intno); |
||
183 | //bootinfo->wakeup_intno=wakeup_intno; |
||
184 | |||
185 | |||
186 | |||
187 | |||
188 | |||
2726 | vana | 189 | { |
190 | UINTN cookie; |
||
191 | void *p=(void *)KERNEL_LOAD_ADDRESS; |
||
192 | UINTN mapsize,descsize; |
||
193 | UINT32 desver; |
||
194 | EFI_STATUS status; |
||
195 | EFI_MEMORY_DESCRIPTOR emd[1024]; |
||
196 | |||
197 | |||
198 | mapsize=1024*sizeof(emd); |
||
199 | |||
200 | status=BS->AllocatePages(AllocateAnyPages,EfiLoaderData,/*(HOSSize>>12)+1*/ 1,p); |
||
201 | if(EFI_ERROR(status)){ |
||
202 | Print(L"Error 0\n"); |
||
203 | if(status == EFI_OUT_OF_RESOURCES) Print(L"EFI_OUT_OF_RESOURCES\n"); |
||
204 | if(status == EFI_INVALID_PARAMETER) Print(L"EFI_INVALID_PARAMETER\n"); |
||
205 | if(status == EFI_NOT_FOUND) Print(L"EFI_NOT_FOUND\n"); |
||
206 | return EFI_SUCCESS; |
||
207 | } |
||
208 | |||
209 | status=BS->GetMemoryMap(&mapsize,emd,&cookie,&descsize,&desver); |
||
210 | if(EFI_ERROR(status)){ |
||
211 | Print(L"Error 1\n"); |
||
212 | return EFI_SUCCESS; |
||
213 | } |
||
214 | status=BS->ExitBootServices(image,cookie); |
||
215 | if(EFI_ERROR(status)){ |
||
216 | Print(L"Error 2\n"); |
||
217 | return EFI_SUCCESS; |
||
218 | } |
||
219 | |||
220 | } |
||
221 | int a; |
||
222 | |||
223 | for(a=0;a<HOSSize;a++){ |
||
224 | ((char *)(0x4400000))[a]=HOS[a]; |
||
225 | } |
||
3597 | svoboda | 226 | bootinfo->sapic=(unsigned long *)sapic; |
227 | bootinfo->wakeup_intno=wakeup_intno; |
||
228 | bootinfo->sys_freq=sys_freq; |
||
229 | bootinfo->freq_scale=freq_scale; |
||
2726 | vana | 230 | |
231 | //Run Kernel |
||
232 | asm volatile( |
||
233 | "nop.i 0x00 ;;\n" |
||
234 | "movl r15 = 0x4400000 ;;\n" |
||
235 | "mov b0 = r15;;" |
||
236 | "br.few b0;;\n" |
||
237 | ); |
||
238 | |||
239 | |||
3597 | svoboda | 240 | //Not reached |
2726 | vana | 241 | return EFI_SUCCESS; |
242 | } |