Rev 3343 | Rev 3665 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3343 | Rev 3593 | ||
|---|---|---|---|
| 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 | //Link image as a data array into hello - usefull with network boot |
|
| - | 9 | //#define IMAGE_LINKED |
|
| - | 10 | ||
| - | 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 | ||
| 6 | 20 | ||
| 7 | static CHAR16 * |
21 | static CHAR16 * |
| 8 | a2u (char *str) |
22 | a2u (char *str) |
| 9 | { |
23 | { |
| 10 | static CHAR16 mem[2048]; |
24 | static CHAR16 mem[2048]; |
| Line 13... | Line 27... | ||
| 13 | for (i = 0; str[i]; ++i) |
27 | for (i = 0; str[i]; ++i) |
| 14 | mem[i] = (CHAR16) str[i]; |
28 | mem[i] = (CHAR16) str[i]; |
| 15 | mem[i] = 0; |
29 | mem[i] = 0; |
| 16 | return mem; |
30 | return mem; |
| 17 | } |
31 | } |
| 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 | 32 | ||
| 36 | EFI_STATUS |
33 | EFI_STATUS |
| 37 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) |
34 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) |
| 38 | { |
35 | { |
| 39 | SIMPLE_TEXT_OUTPUT_INTERFACE *conout; |
36 | SIMPLE_TEXT_OUTPUT_INTERFACE *conout; |
| Line 70... | Line 67... | ||
| 70 | 67 | ||
| 71 | EFI_FILE *CurDir; |
68 | EFI_FILE *CurDir; |
| 72 | EFI_FILE *FileHandle; |
69 | EFI_FILE *FileHandle; |
| 73 | 70 | ||
| 74 | BS->HandleProtocol(LoadedImage->DeviceHandle, &FileSystemProtocol, &Vol); |
71 | BS->HandleProtocol(LoadedImage->DeviceHandle, &FileSystemProtocol, &Vol); |
| 75 | Vol->OpenVolume (Vol, &CurDir); |
- | |
| 76 | 72 | ||
| 77 | char FileName[1024]; |
73 | char FileName[1024]; |
| 78 | char *OsKernelBuffer; |
74 | char *OsKernelBuffer; |
| 79 | int i; |
75 | int i; |
| - | 76 | int defaultLoad; |
|
| - | 77 | int imageLoad; |
|
| 80 | UINTN Size; |
78 | UINTN Size; |
| 81 | 79 | ||
| 82 | StrCpy(FileName,DevicePathToStr(LoadedImage->FilePath)); |
80 | StrCpy(FileName,DevicePathToStr(LoadedImage->FilePath)); |
| 83 | for(i=StrLen(FileName);i>=0 && FileName[i]!='\\';i--); |
81 | for(i=StrLen(FileName);i>=0 && FileName[i]!='\\';i--); |
| 84 | FileName[i] = 0; |
82 | FileName[i] = 0; |
| Line 95... | Line 93... | ||
| 95 | if(LoadOptions[i]==0) break; |
93 | if(LoadOptions[i]==0) break; |
| 96 | i++; |
94 | i++; |
| 97 | } |
95 | } |
| 98 | while(LoadOptions[i]==L' ') if(LoadOptions[i++]==0) break; |
96 | while(LoadOptions[i]==L' ') if(LoadOptions[i++]==0) break; |
| 99 | 97 | ||
| 100 | if(LoadOptions[i++]==0) |
98 | if(LoadOptions[i++]==0){ |
| 101 | StrCat(FileName,L"\\image.bin"); |
99 | StrCat(FileName,L"\\image.bin"); |
| - | 100 | defaultLoad=1; |
|
| - | 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 | } |
112 | } |
| 112 | - | ||
| 113 | //Print(L"%s\n",FileName); |
- | |
| 114 | 113 | ||
| 115 | EFI_STATUS stat; |
114 | imageLoad=1; |
| 116 | stat=CurDir->Open(CurDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0); |
115 | #ifdef IMAGE_LINKED |
| 117 | if(EFI_ERROR(stat)){ |
116 | if(defaultLoad) { |
| 118 | Print(L"Error Opening Image %s\n",FileName); |
117 | Print(L"Using Linked Image\n"); |
| 119 | return 0; |
118 | imageLoad=0; |
| 120 | } |
119 | } |
| 121 | Size = 0x00400000; |
120 | #endif |
| 122 | BS->AllocatePool(EfiLoaderData, Size, &OsKernelBuffer); |
- | |
| 123 | FileHandle->Read(FileHandle, &Size, OsKernelBuffer); |
- | |
| 124 | FileHandle->Close(FileHandle); |
- | |
| - | 121 | ||
| 125 | 122 | ||
| - | 123 | char * HOS; |
|
| - | 124 | if(imageLoad) |
|
| - | 125 | { |
|
| 126 | if(Size<1) return 0; |
126 | Size = 0x00400000; |
| 127 | 127 | ||
| - | 128 | Vol->OpenVolume (Vol, &CurDir); |
|
| 128 | 129 | ||
| - | 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); |
|
| 129 | char * HOS = OsKernelBuffer; |
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 |
|
| 130 | int HOSSize = Size; |
152 | int HOSSize = Size; |
| 131 | 153 | ||
| 132 | 154 | ||
| - | 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 | ||
| 133 | { |
189 | { |
| 134 | UINTN cookie; |
190 | UINTN cookie; |
| 135 | void *p=(void *)KERNEL_LOAD_ADDRESS; |
191 | void *p=(void *)KERNEL_LOAD_ADDRESS; |
| 136 | UINTN mapsize,descsize; |
192 | UINTN mapsize,descsize; |
| 137 | UINT32 desver; |
193 | UINT32 desver; |
| Line 165... | Line 221... | ||
| 165 | int a; |
221 | int a; |
| 166 | 222 | ||
| 167 | for(a=0;a<HOSSize;a++){ |
223 | for(a=0;a<HOSSize;a++){ |
| 168 | ((char *)(0x4400000))[a]=HOS[a]; |
224 | ((char *)(0x4400000))[a]=HOS[a]; |
| 169 | } |
225 | } |
| - | 226 | bootinfo->sapic=(unsigned long *)sapic; |
|
| - | 227 | bootinfo->wakeup_intno=wakeup_intno; |
|
| - | 228 | bootinfo->sys_freq=sys_freq; |
|
| - | 229 | bootinfo->freq_scale=freq_scale; |
|
| 170 | 230 | ||
| 171 | //Run Kernel |
231 | //Run Kernel |
| 172 | asm volatile( |
232 | asm volatile( |
| 173 | "nop.i 0x00 ;;\n" |
233 | "nop.i 0x00 ;;\n" |
| 174 | "movl r15 = 0x4400000 ;;\n" |
234 | "movl r15 = 0x4400000 ;;\n" |
| 175 | "mov b0 = r15;;" |
235 | "mov b0 = r15;;" |
| 176 | "br.few b0;;\n" |
236 | "br.few b0;;\n" |
| 177 | ); |
237 | ); |
| 178 | 238 | ||
| 179 | 239 | ||
| 180 | while(1){ |
240 | //Not reached |
| 181 | ((volatile int *)(0x80000000000b8000))[0]++; |
- | |
| 182 | } |
- | |
| 183 | return EFI_SUCCESS; |
241 | return EFI_SUCCESS; |
| 184 | } |
242 | } |