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