Mercurial > hg > Members > taiki > EFIKernel
comparison boot/bootx64.c @ 18:bd4c99e700e8
add close and read, seek
author | taiki |
---|---|
date | Thu, 07 Feb 2013 06:11:26 +0900 |
parents | 2013da6b3211 |
children | 2fbe46f63d4c |
comparison
equal
deleted
inserted
replaced
17:30fd7afa7222 | 18:bd4c99e700e8 |
---|---|
4 * | 4 * |
5 * Author: Taiki TAIRA. | 5 * Author: Taiki TAIRA. |
6 */ | 6 */ |
7 | 7 |
8 #include "bootx64.h" | 8 #include "bootx64.h" |
9 #include "mach-o/mach_o.h" | |
9 | 10 |
10 INTN | 11 INTN |
11 efi_error(CHAR16* error_massage, EFI_STATUS status) | 12 efi_error(CHAR16* error_massage, EFI_STATUS status) |
12 { | 13 { |
13 Print(L"%s", error_massage); | 14 Print(L"%s", error_massage); |
14 if (status < 0) return ERROR; | 15 if (status < 0) return ERROR; |
15 return SUCCESS; | 16 return SUCCESS; |
16 } | 17 } |
17 | 18 |
18 EFI_STATUS | 19 EFI_STATUS |
19 load_mach_o() | 20 open(CHAR16 *name, EFI_FILE_HANDLE *fd, fs_t *fs) |
20 { | |
21 Print(L"kernel load ... \n"); | |
22 return EFI_SUCCESS; | |
23 } | |
24 | |
25 EFI_STATUS | |
26 open(CHAR16 *name, UINTN *fd, fs_t *fs) | |
27 { | 21 { |
28 EFI_STATUS status; | 22 EFI_STATUS status; |
29 EFI_FILE_HANDLE fh; | |
30 | 23 |
31 if (name == NULL || fd == NULL) return EFI_INVALID_PARAMETER; | 24 if (name == NULL || fd == NULL) return EFI_INVALID_PARAMETER; |
32 | 25 |
33 status = uefi_call_wrapper(fs->volume->Open, 5, fs->volume, &fh, name, EFI_FILE_MODE_READ, (UINT64)0); | 26 status = uefi_call_wrapper(fs->volume->Open, 5, fs->volume, &fd, name, EFI_FILE_MODE_READ, (UINT64)0); |
34 if (status == EFI_SUCCESS) { | 27 |
35 *fd = (UINTN)fh; | |
36 } | |
37 return status; | 28 return status; |
29 } | |
30 | |
31 EFI_STATUS | |
32 close(fs_t *fs, EFI_FILE_HANDLE *fd) | |
33 { | |
34 if (fs == NULL || fd == NULL) return EFI_INVALID_PARAMETER; | |
35 | |
36 return uefi_call_wrapper(fs->volume->Close, 1, fd); | |
37 } | |
38 | |
39 EFI_STATUS | |
40 read(fs_t *fs, EFI_FILE_HANDLE *fd, VOID *buf, UINTN *size) | |
41 { | |
42 if (buf == NULL || fd == NULL || size == NULL) return EFI_INVALID_PARAMETER; | |
43 return uefi_call_wrapper(fs->volume->Read, 3, fd, size, buf); | |
44 } | |
45 | |
46 EFI_STATUS | |
47 seek(fs_t *fs, EFI_FILE_HANDLE fd, UINTN newpos) | |
48 { | |
49 if (newpos <= 0 || fd == NULL || fs == NULL) return EFI_INVALID_PARAMETER; | |
50 return uefi_call_wrapper(fs->volume->SetPosition, 2, fd, newpos); | |
38 } | 51 } |
39 | 52 |
40 EFI_STATUS | 53 EFI_STATUS |
41 config_fs_one(EFI_HANDLE dev, VOID *fs) | 54 config_fs_one(EFI_HANDLE dev, VOID *fs) |
42 { | 55 { |
133 } | 146 } |
134 | 147 |
135 return EFI_SUCCESS; | 148 return EFI_SUCCESS; |
136 } | 149 } |
137 | 150 |
151 EFI_STATUS | |
152 load(fs_t *fs, EFI_FILE_HANDLE *fd, CHAR16 *kname) | |
153 { | |
154 VOID *buf = NULL; | |
155 UINTN size; | |
156 read(fs ,fd, buf, &size); | |
157 //seek(fs ,fd); | |
158 | |
159 | |
160 | |
161 return EFI_SUCCESS; | |
162 } | |
163 | |
138 | 164 |
139 static inline void | 165 static inline void |
140 start_kernel() | 166 start_kernel() |
141 { | 167 { |
142 } | 168 } |
163 | 189 |
164 fs_t fs; | 190 fs_t fs; |
165 dev_tab_t boot_dev; | 191 dev_tab_t boot_dev; |
166 status = config_fs(info->DeviceHandle, &fs, &boot_dev); | 192 status = config_fs(info->DeviceHandle, &fs, &boot_dev); |
167 | 193 |
168 UINTN fd; | 194 EFI_FILE_HANDLE fd; |
169 open(kname, &fd, &fs); | 195 open(kname, &fd, &fs); |
170 | 196 |
171 load_mach_o(); | 197 load(&fs, &fd, kname); |
198 | |
199 close(&fs, &fd); | |
172 | 200 |
173 UINTN cookie = 0; | 201 UINTN cookie = 0; |
174 uefi_call_wrapper(BS->ExitBootServices, 2, image, cookie); | 202 uefi_call_wrapper(BS->ExitBootServices, 2, image, cookie); |
175 | 203 |
176 start_kernel(); | 204 start_kernel(); |