Rev 2726 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2726 | Rev 3386 | ||
---|---|---|---|
1 | #include <efi.h> |
1 | #include <efi.h> |
2 | #include <efilib.h> |
2 | #include <efilib.h> |
3 | 3 | ||
4 | #define KERNEL_LOAD_ADDRESS 0x4400000 |
4 | #define KERNEL_LOAD_ADDRESS 0x4400000 |
5 | 5 | ||
6 | 6 | ||
7 | static CHAR16 * |
7 | static CHAR16 * |
8 | a2u (char *str) |
8 | a2u (char *str) |
9 | { |
9 | { |
10 | static CHAR16 mem[2048]; |
10 | static CHAR16 mem[2048]; |
11 | int i; |
11 | int i; |
12 | 12 | ||
13 | for (i = 0; str[i]; ++i) |
13 | for (i = 0; str[i]; ++i) |
14 | mem[i] = (CHAR16) str[i]; |
14 | mem[i] = (CHAR16) str[i]; |
15 | mem[i] = 0; |
15 | mem[i] = 0; |
16 | return mem; |
16 | return mem; |
17 | } |
17 | } |
18 | char HEX[256]; |
18 | char HEX[256]; |
19 | 19 | ||
20 | char hexs[]="0123456789ABCDEF"; |
20 | char hexs[]="0123456789ABCDEF"; |
21 | /* |
21 | /* |
22 | void to_hex(unsigned long long num) |
22 | void to_hex(unsigned long long num) |
23 | { |
23 | { |
24 | int a; |
24 | int a; |
25 | for(a=15;a>=0;a--) |
25 | for(a=15;a>=0;a--) |
26 | { |
26 | { |
27 | char c=num - (num & 0xfffffffffffffff0LL); |
27 | char c=num - (num & 0xfffffffffffffff0LL); |
28 | num/=16; |
28 | num/=16; |
29 | c=hexs[c]; |
29 | c=hexs[c]; |
30 | HEX[a]=c; |
30 | HEX[a]=c; |
31 | } |
31 | } |
32 | 32 | ||
33 | } |
33 | } |
34 | */ |
34 | */ |
35 | 35 | ||
36 | EFI_STATUS |
36 | EFI_STATUS |
37 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) |
37 | efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) |
38 | { |
38 | { |
39 | SIMPLE_TEXT_OUTPUT_INTERFACE *conout; |
39 | SIMPLE_TEXT_OUTPUT_INTERFACE *conout; |
40 | 40 | ||
41 | EFI_INPUT_KEY efi_input_key; |
41 | EFI_INPUT_KEY efi_input_key; |
42 | EFI_STATUS efi_status; |
42 | EFI_STATUS efi_status; |
43 | 43 | ||
44 | InitializeLib(image, systab); |
44 | InitializeLib(image, systab); |
45 | 45 | ||
46 | Print(L"HelloLib application started\n"); |
46 | Print(L"HelloLib application started\n"); |
47 | 47 | ||
48 | EFI_GUID LoadedImageProtocol=LOADED_IMAGE_PROTOCOL; |
48 | EFI_GUID LoadedImageProtocol=LOADED_IMAGE_PROTOCOL; |
49 | EFI_GUID DevicePathProtocol=DEVICE_PATH_PROTOCOL; |
49 | EFI_GUID DevicePathProtocol=DEVICE_PATH_PROTOCOL; |
50 | EFI_GUID FileSystemProtocol=SIMPLE_FILE_SYSTEM_PROTOCOL; |
50 | EFI_GUID FileSystemProtocol=SIMPLE_FILE_SYSTEM_PROTOCOL; |
51 | 51 | ||
52 | 52 | ||
53 | EFI_LOADED_IMAGE *LoadedImage; |
53 | EFI_LOADED_IMAGE *LoadedImage; |
54 | EFI_DEVICE_PATH *DevicePath; |
54 | EFI_DEVICE_PATH *DevicePath; |
55 | 55 | ||
56 | BS->HandleProtocol(image, |
56 | BS->HandleProtocol(image, |
57 | &LoadedImageProtocol, |
57 | &LoadedImageProtocol, |
58 | &LoadedImage); |
58 | &LoadedImage); |
59 | BS->HandleProtocol(LoadedImage->DeviceHandle, |
59 | BS->HandleProtocol(LoadedImage->DeviceHandle, |
60 | &DevicePathProtocol, |
60 | &DevicePathProtocol, |
61 | &DevicePath); |
61 | &DevicePath); |
62 | Print (L"Image device : %s\n", DevicePathToStr (DevicePath)); |
62 | Print (L"Image device : %s\n", DevicePathToStr (DevicePath)); |
63 | Print (L"Image file : %s\n", DevicePathToStr (LoadedImage->FilePath)); |
63 | Print (L"Image file : %s\n", DevicePathToStr (LoadedImage->FilePath)); |
64 | Print (L"Image Base : %X\n", LoadedImage->ImageBase); |
64 | Print (L"Image Base : %X\n", LoadedImage->ImageBase); |
65 | Print (L"Image Size : %X\n", LoadedImage->ImageSize); |
65 | Print (L"Image Size : %X\n", LoadedImage->ImageSize); |
66 | 66 | ||
67 | 67 | ||
68 | 68 | ||
69 | EFI_FILE_IO_INTERFACE *Vol; |
69 | EFI_FILE_IO_INTERFACE *Vol; |
70 | 70 | ||
71 | EFI_FILE *CurDir; |
71 | EFI_FILE *CurDir; |
72 | EFI_FILE *FileHandle; |
72 | EFI_FILE *FileHandle; |
73 | 73 | ||
74 | BS->HandleProtocol(LoadedImage->DeviceHandle, &FileSystemProtocol, &Vol); |
74 | BS->HandleProtocol(LoadedImage->DeviceHandle, &FileSystemProtocol, &Vol); |
75 | Vol->OpenVolume (Vol, &CurDir); |
75 | Vol->OpenVolume (Vol, &CurDir); |
76 | 76 | ||
77 | char FileName[1024]; |
77 | char FileName[1024]; |
78 | char *OsKernelBuffer; |
78 | char *OsKernelBuffer; |
79 | int i; |
79 | int i; |
80 | UINTN Size; |
80 | UINTN Size; |
81 | 81 | ||
82 | StrCpy(FileName,DevicePathToStr(LoadedImage->FilePath)); |
82 | StrCpy(FileName,DevicePathToStr(LoadedImage->FilePath)); |
83 | for(i=StrLen(FileName);i>=0 && FileName[i]!='\\';i--); |
83 | for(i=StrLen(FileName);i>=0 && FileName[i]!='\\';i--); |
84 | FileName[i] = 0; |
84 | FileName[i] = 0; |
85 | 85 | ||
86 | Print(L"%s\n",LoadedImage->LoadOptions); |
86 | Print(L"%s\n",LoadedImage->LoadOptions); |
87 | 87 | ||
88 | i=0; |
88 | i=0; |
89 | CHAR16 *LoadOptions = LoadedImage->LoadOptions; |
89 | CHAR16 *LoadOptions = LoadedImage->LoadOptions; |
90 | 90 | ||
91 | 91 | ||
92 | 92 | ||
93 | while(1) if(LoadOptions[i++]!=L' ') break; |
93 | while(1) if(LoadOptions[i++]!=L' ') break; |
94 | while(LoadOptions[i]!=L' '){ |
94 | while(LoadOptions[i]!=L' '){ |
95 | if(LoadOptions[i]==0) break; |
95 | if(LoadOptions[i]==0) break; |
96 | i++; |
96 | i++; |
97 | } |
97 | } |
98 | while(LoadOptions[i]==L' ') if(LoadOptions[i++]==0) break; |
98 | while(LoadOptions[i]==L' ') if(LoadOptions[i++]==0) break; |
99 | 99 | ||
100 | if(LoadOptions[i++]==0) |
100 | if(LoadOptions[i++]==0) |
101 | StrCat(FileName,L"\\image.bin"); |
101 | StrCat(FileName,L"\\image.bin"); |
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 | } |
111 | } |
112 | 112 | ||
113 | //Print(L"%s\n",FileName); |
113 | //Print(L"%s\n",FileName); |
114 | 114 | ||
115 | EFI_STATUS stat; |
115 | EFI_STATUS stat; |
116 | stat=CurDir->Open(CurDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0); |
116 | stat=CurDir->Open(CurDir, &FileHandle, FileName, EFI_FILE_MODE_READ, 0); |
117 | if(EFI_ERROR(stat)){ |
117 | if(EFI_ERROR(stat)){ |
118 | Print(L"Error Opening Image %s\n",FileName); |
118 | Print(L"Error Opening Image %s\n",FileName); |
119 | return 0; |
119 | return 0; |
120 | } |
120 | } |
121 | Size = 0x00400000; |
121 | Size = 0x00400000; |
122 | BS->AllocatePool(EfiLoaderData, Size, &OsKernelBuffer); |
122 | BS->AllocatePool(EfiLoaderData, Size, &OsKernelBuffer); |
123 | FileHandle->Read(FileHandle, &Size, OsKernelBuffer); |
123 | FileHandle->Read(FileHandle, &Size, OsKernelBuffer); |
124 | FileHandle->Close(FileHandle); |
124 | FileHandle->Close(FileHandle); |
125 | 125 | ||
126 | if(Size<1) return 0; |
126 | if(Size<1) return 0; |
127 | 127 | ||
128 | 128 | ||
129 | char * HOS = OsKernelBuffer; |
129 | char * HOS = OsKernelBuffer; |
130 | int HOSSize = Size; |
130 | int HOSSize = Size; |
131 | 131 | ||
132 | 132 | ||
133 | { |
133 | { |
134 | UINTN cookie; |
134 | UINTN cookie; |
135 | void *p=(void *)KERNEL_LOAD_ADDRESS; |
135 | void *p=(void *)KERNEL_LOAD_ADDRESS; |
136 | UINTN mapsize,descsize; |
136 | UINTN mapsize,descsize; |
137 | UINT32 desver; |
137 | UINT32 desver; |
138 | EFI_STATUS status; |
138 | EFI_STATUS status; |
139 | EFI_MEMORY_DESCRIPTOR emd[1024]; |
139 | EFI_MEMORY_DESCRIPTOR emd[1024]; |
140 | 140 | ||
141 | 141 | ||
142 | mapsize=1024*sizeof(emd); |
142 | mapsize=1024*sizeof(emd); |
143 | 143 | ||
144 | status=BS->AllocatePages(AllocateAnyPages,EfiLoaderData,/*(HOSSize>>12)+1*/ 1,p); |
144 | status=BS->AllocatePages(AllocateAnyPages,EfiLoaderData,/*(HOSSize>>12)+1*/ 1,p); |
145 | if(EFI_ERROR(status)){ |
145 | if(EFI_ERROR(status)){ |
146 | Print(L"Error 0\n"); |
146 | Print(L"Error 0\n"); |
147 | if(status == EFI_OUT_OF_RESOURCES) Print(L"EFI_OUT_OF_RESOURCES\n"); |
147 | 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"); |
148 | if(status == EFI_INVALID_PARAMETER) Print(L"EFI_INVALID_PARAMETER\n"); |
149 | if(status == EFI_NOT_FOUND) Print(L"EFI_NOT_FOUND\n"); |
149 | if(status == EFI_NOT_FOUND) Print(L"EFI_NOT_FOUND\n"); |
150 | return EFI_SUCCESS; |
150 | return EFI_SUCCESS; |
151 | } |
151 | } |
152 | 152 | ||
153 | status=BS->GetMemoryMap(&mapsize,emd,&cookie,&descsize,&desver); |
153 | status=BS->GetMemoryMap(&mapsize,emd,&cookie,&descsize,&desver); |
154 | if(EFI_ERROR(status)){ |
154 | if(EFI_ERROR(status)){ |
155 | Print(L"Error 1\n"); |
155 | Print(L"Error 1\n"); |
156 | return EFI_SUCCESS; |
156 | return EFI_SUCCESS; |
157 | } |
157 | } |
158 | status=BS->ExitBootServices(image,cookie); |
158 | status=BS->ExitBootServices(image,cookie); |
159 | if(EFI_ERROR(status)){ |
159 | if(EFI_ERROR(status)){ |
160 | Print(L"Error 2\n"); |
160 | Print(L"Error 2\n"); |
161 | return EFI_SUCCESS; |
161 | return EFI_SUCCESS; |
162 | } |
162 | } |
163 | 163 | ||
164 | } |
164 | } |
165 | int a; |
165 | int a; |
166 | 166 | ||
167 | for(a=0;a<HOSSize;a++){ |
167 | for(a=0;a<HOSSize;a++){ |
168 | ((char *)(0x4400000))[a]=HOS[a]; |
168 | ((char *)(0x4400000))[a]=HOS[a]; |
169 | } |
169 | } |
170 | 170 | ||
171 | //Run Kernel |
171 | //Run Kernel |
172 | asm volatile( |
172 | asm volatile( |
173 | "nop.i 0x00 ;;\n" |
173 | "nop.i 0x00 ;;\n" |
174 | "movl r15 = 0x4400000 ;;\n" |
174 | "movl r15 = 0x4400000 ;;\n" |
175 | "mov b0 = r15;;" |
175 | "mov b0 = r15;;" |
176 | "br.few b0;;\n" |
176 | "br.few b0;;\n" |
177 | ); |
177 | ); |
178 | 178 | ||
179 | 179 | ||
180 | while(1){ |
180 | while(1){ |
181 | ((volatile int *)(0x80000000000b8000))[0]++; |
181 | ((volatile int *)(0x80000000000b8000))[0]++; |
182 | } |
182 | } |
183 | return EFI_SUCCESS; |
183 | return EFI_SUCCESS; |
184 | } |
184 | } |
185 | 185 |