source: mainline/boot/arch/ia64/loader/gefi/HelenOS/hello.c@ 4b8f1c3

lfn serial ticket/834-toolchain-update topic/fix-logger-deadlock topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4b8f1c3 was bb74e8ab, checked in by Jakub Vana <jakub.vana@…>, 17 years ago

IA64:Disable searching for image in actual directory in hello, fix Makefile

  • Property mode set to 100644
File size: 6.8 KB
Line 
1#include <efi.h>
2#include <efilib.h>
3
4#include <../../../../../../kernel/arch/ia64/include/bootinfo.h>
5
6#define KERNEL_LOAD_ADDRESS 0x4400000
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
17bootinfo_t *bootinfo=(bootinfo_t *)BOOTINFO_ADDRESS;
18
19
20#ifdef IMAGE_LINKED
21extern char HOSimage[];
22extern int HOSimagesize;
23#endif
24
25
26
27static CHAR16 *
28a2u (char *str)
29{
30 static CHAR16 mem[2048];
31 int i;
32
33 for (i = 0; str[i]; ++i)
34 mem[i] = (CHAR16) str[i];
35 mem[i] = 0;
36 return mem;
37}
38
39EFI_STATUS
40efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
41{
42 SIMPLE_TEXT_OUTPUT_INTERFACE *conout;
43
44 EFI_INPUT_KEY efi_input_key;
45 EFI_STATUS efi_status;
46
47 InitializeLib(image, systab);
48
49 Print(L"HelloLib application started\n");
50
51 EFI_GUID LoadedImageProtocol=LOADED_IMAGE_PROTOCOL;
52 EFI_GUID DevicePathProtocol=DEVICE_PATH_PROTOCOL;
53 EFI_GUID FileSystemProtocol=SIMPLE_FILE_SYSTEM_PROTOCOL;
54
55
56 EFI_LOADED_IMAGE *LoadedImage;
57 EFI_DEVICE_PATH *DevicePath;
58
59 BS->HandleProtocol(image,
60 &LoadedImageProtocol,
61 &LoadedImage);
62 BS->HandleProtocol(LoadedImage->DeviceHandle,
63 &DevicePathProtocol,
64 &DevicePath);
65 Print (L"Image device : %s\n", DevicePathToStr (DevicePath));
66 Print (L"Image file : %s\n", DevicePathToStr (LoadedImage->FilePath));
67 Print (L"Image Base : %X\n", LoadedImage->ImageBase);
68 Print (L"Image Size : %X\n", LoadedImage->ImageSize);
69
70
71
72 EFI_FILE_IO_INTERFACE *Vol;
73
74 EFI_FILE *CurDir;
75 EFI_FILE *FileHandle;
76
77 BS->HandleProtocol(LoadedImage->DeviceHandle, &FileSystemProtocol, &Vol);
78
79 char FileName[1024];
80 char *OsKernelBuffer;
81 int i;
82 int defaultLoad;
83 int imageLoad;
84 UINTN Size;
85
86 StrCpy(FileName,DevicePathToStr(LoadedImage->FilePath));
87 for(i=StrLen(FileName);i>=0 && FileName[i]!='\\';i--);
88 FileName[i] = 0;
89 FileName[0] = 0;
90
91 Print(L"%s\n",LoadedImage->LoadOptions);
92
93 i=0;
94 CHAR16 *LoadOptions = LoadedImage->LoadOptions;
95
96
97
98 while(1) if(LoadOptions[i++]!=L' ') break;
99 while(LoadOptions[i]!=L' '){
100 if(LoadOptions[i]==0) break;
101 i++;
102 }
103 while(LoadOptions[i]==L' ') if(LoadOptions[i++]==0) break;
104
105 if(LoadOptions[i++]==0){
106 StrCat(FileName,L"\\image.bin");
107 defaultLoad=1;
108 }
109 else{
110 CHAR16 buf[1024];
111 //buf[0]='\\';
112 i--;
113 int j;
114 for(j=0;LoadOptions[i+j]!=L' '&&LoadOptions[i+j]!=0;j++)
115 buf[j+1]=LoadOptions[i+j];
116 buf[j+1]=0;
117 StrCat(FileName,buf);
118 defaultLoad=0;
119 }
120
121 imageLoad=1;
122#ifdef IMAGE_LINKED
123 if(defaultLoad) {
124 Print(L"Using Linked Image\n");
125 imageLoad=0;
126 }
127#endif
128
129
130 char * HOS;
131 if(imageLoad)
132 {
133 Size = 0x00400000;
134
135 Vol->OpenVolume (Vol, &CurDir);
136
137 EFI_STATUS stat;
138 stat=CurDir->Open(CurDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0);
139 if(EFI_ERROR(stat)){
140 Print(L"Error Opening Image %s\n",FileName);
141 return 0;
142 }
143 BS->AllocatePool(EfiLoaderData, Size, &OsKernelBuffer);
144 FileHandle->Read(FileHandle, &Size, OsKernelBuffer);
145 FileHandle->Close(FileHandle);
146 HOS = OsKernelBuffer;
147 if(Size<1) return 0;
148
149 }
150#ifdef IMAGE_LINKED
151 else {
152 HOS = HOSimage;
153 Size = HOSimagesize;
154 Print(L"Image start %llX\n",(long long)HOS);
155 Print(L"Image size %llX\n",(long long)Size);
156 Print(L"Image &size %llX\n",(long long)&Size);
157 }
158#endif
159 int HOSSize = Size;
160
161
162 rArg rSAL;
163 rArg rPAL;
164
165 //Setup AP's wake up address
166 LibSalProc(0x01000000,2,0x4400200,0,0,0,0,0,&rSAL);
167
168
169 //Get System Frequency
170 UINT64 sys_freq;
171 LibSalProc(0x01000012,0,0,0,0,0,0,0,&rSAL);
172 sys_freq=rSAL.p1;
173
174
175 UINT64 freq_scale;
176 //Get CPU Frequency to System Frequency ratio
177 LibPalProc(14,0,0,0,&rPAL);
178 freq_scale=rPAL.p1;
179
180
181 UINT64 sapic;
182 LibGetSalIpiBlock(&sapic);
183 Print (L"SAPIC:%X\n", sapic);
184 //bootinfo->sapic=sapic;
185
186
187 UINT64 wakeup_intno;
188 LibGetSalWakeupVector(&wakeup_intno);
189 Print (L"WAKEUP INTNO:%X\n", wakeup_intno);
190
191
192
193
194
195 UINTN cookie;
196 void *p=(void *)KERNEL_LOAD_ADDRESS;
197 UINTN mapsize,descsize;
198 UINT32 desver;
199 EFI_STATUS status;
200
201
202
203 status=BS->AllocatePages(AllocateAnyPages,EfiLoaderData,/*(HOSSize>>12)+1*/ 1,p);
204 if(EFI_ERROR(status)){
205 Print(L"Error 0\n");
206 if(status == EFI_OUT_OF_RESOURCES) Print(L"EFI_OUT_OF_RESOURCES\n");
207 if(status == EFI_INVALID_PARAMETER) Print(L"EFI_INVALID_PARAMETER\n");
208 if(status == EFI_NOT_FOUND) Print(L"EFI_NOT_FOUND\n");
209 return EFI_SUCCESS;
210 }
211
212 UINTN no_entryes;
213 void * mds;
214 mds=LibMemoryMap(&no_entryes,&cookie,&descsize,&desver);
215
216 for(i=0;i<no_entryes;i++)
217 {
218
219 unsigned int type=*((unsigned int *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_TYPE));
220 unsigned long long base=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_BASE));
221 unsigned long long pages=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_PAGES));
222 Print(L"T:%02d %016llX %016llX\n",type,base,pages*EFI_PAGE_SIZE);
223
224 }
225 status=BS->ExitBootServices(image,cookie);
226 if(EFI_ERROR(status)){
227 Print(L"Error 2\n");
228 return EFI_SUCCESS;
229 }
230
231
232 int a;
233
234 for(a=0;a<HOSSize;a++){
235 ((char *)(0x4400000))[a]=HOS[a];
236 }
237 bootinfo->sapic=(unsigned long *)sapic;
238 bootinfo->wakeup_intno=wakeup_intno;
239 bootinfo->sys_freq=sys_freq;
240 bootinfo->freq_scale=freq_scale;
241 bootinfo->hello_configured=1;
242
243
244 bootinfo->memmap_items=0;
245
246 for(i=0;i<no_entryes;i++)
247 {
248
249 unsigned int type=*((unsigned int *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_TYPE));
250 unsigned long long base=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_BASE));
251 unsigned long long pages=*((unsigned long long *)(mds+i*descsize+MEM_MAP_DESCRIPTOR_OFFSET_PAGES));
252
253
254
255 switch (type)
256 {
257 case EfiConventionalMemory:
258 bootinfo->memmap[bootinfo->memmap_items].type=EFI_MEMMAP_FREE_MEM;
259 bootinfo->memmap[bootinfo->memmap_items].base=base;
260 bootinfo->memmap[bootinfo->memmap_items].size=pages*EFI_PAGE_SIZE;
261 bootinfo->memmap_items++;
262 break;
263 case EfiMemoryMappedIO:
264 bootinfo->memmap[bootinfo->memmap_items].type=EFI_MEMMAP_IO;
265 bootinfo->memmap[bootinfo->memmap_items].base=base;
266 bootinfo->memmap[bootinfo->memmap_items].size=pages*EFI_PAGE_SIZE;
267 bootinfo->memmap_items++;
268 break;
269 case EfiMemoryMappedIOPortSpace:
270 bootinfo->memmap[bootinfo->memmap_items].type=EFI_MEMMAP_IO_PORTS;
271 bootinfo->memmap[bootinfo->memmap_items].base=base;
272 bootinfo->memmap[bootinfo->memmap_items].size=pages*EFI_PAGE_SIZE;
273 bootinfo->memmap_items++;
274 break;
275
276 default :
277 break;
278 }
279
280
281
282
283
284 }
285
286
287
288 //Run Kernel
289 asm volatile(
290 "nop.i 0x00 ;;\n"
291 "movl r15 = 0x4400000 ;;\n"
292 "mov b0 = r15;;"
293 "br.few b0;;\n"
294 );
295
296
297 //Not reached
298 return EFI_SUCCESS;
299}
Note: See TracBrowser for help on using the repository browser.