changeset 18:bd4c99e700e8

add close and read, seek
author taiki
date Thu, 07 Feb 2013 06:11:26 +0900
parents 30fd7afa7222
children 2fbe46f63d4c
files boot/bootx64.c boot/bootx64.efi boot/mach-o/mach_o.h
diffstat 3 files changed, 45 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/boot/bootx64.c	Fri Feb 01 14:47:50 2013 +0900
+++ b/boot/bootx64.c	Thu Feb 07 06:11:26 2013 +0900
@@ -6,6 +6,7 @@
  */
 
 #include "bootx64.h"
+#include "mach-o/mach_o.h"
 
 INTN
 efi_error(CHAR16* error_massage, EFI_STATUS status)
@@ -16,25 +17,37 @@
 }
 
 EFI_STATUS
-load_mach_o()
+open(CHAR16 *name, EFI_FILE_HANDLE *fd, fs_t *fs)
 {
-    Print(L"kernel load ... \n");
-    return EFI_SUCCESS;
+    EFI_STATUS status;
+
+    if (name == NULL || fd == NULL) return EFI_INVALID_PARAMETER;
+
+    status = uefi_call_wrapper(fs->volume->Open, 5, fs->volume, &fd, name, EFI_FILE_MODE_READ, (UINT64)0);
+
+    return status;
 }
 
 EFI_STATUS
-open(CHAR16 *name, UINTN *fd, fs_t *fs)
+close(fs_t *fs, EFI_FILE_HANDLE *fd)
 {
-    EFI_STATUS status;
-    EFI_FILE_HANDLE fh;
+    if (fs == NULL || fd == NULL) return EFI_INVALID_PARAMETER;
+
+    return uefi_call_wrapper(fs->volume->Close, 1, fd);
+}
 
-    if (name == NULL || fd == NULL) return EFI_INVALID_PARAMETER;
+EFI_STATUS
+read(fs_t *fs, EFI_FILE_HANDLE *fd, VOID *buf, UINTN *size)
+{
+    if (buf == NULL || fd == NULL || size == NULL) return EFI_INVALID_PARAMETER;
+    return uefi_call_wrapper(fs->volume->Read, 3, fd, size, buf);
+}
 
-    status = uefi_call_wrapper(fs->volume->Open, 5, fs->volume, &fh, name, EFI_FILE_MODE_READ, (UINT64)0);
-    if (status == EFI_SUCCESS) { 
-        *fd = (UINTN)fh;
-    }
-    return status;
+EFI_STATUS
+seek(fs_t *fs, EFI_FILE_HANDLE fd, UINTN newpos)
+{
+    if (newpos <= 0 || fd == NULL || fs == NULL) return EFI_INVALID_PARAMETER; 
+    return uefi_call_wrapper(fs->volume->SetPosition, 2, fd, newpos);
 }
 
 EFI_STATUS
@@ -135,6 +148,19 @@
     return EFI_SUCCESS;
 }
 
+EFI_STATUS
+load(fs_t *fs, EFI_FILE_HANDLE *fd, CHAR16 *kname)
+{
+    VOID *buf = NULL;
+    UINTN size;
+    read(fs ,fd, buf, &size);
+    //seek(fs ,fd);
+
+
+
+    return EFI_SUCCESS;
+}
+
 
 static inline void
 start_kernel()
@@ -165,10 +191,12 @@
     dev_tab_t boot_dev;
     status = config_fs(info->DeviceHandle, &fs, &boot_dev);
 
-    UINTN fd;
+    EFI_FILE_HANDLE fd;
     open(kname, &fd, &fs);
 
-    load_mach_o();
+    load(&fs, &fd, kname);
+
+    close(&fs, &fd);
 
     UINTN cookie = 0;
     uefi_call_wrapper(BS->ExitBootServices, 2, image, cookie);
Binary file boot/bootx64.efi has changed
--- a/boot/mach-o/mach_o.h	Fri Feb 01 14:47:50 2013 +0900
+++ b/boot/mach-o/mach_o.h	Thu Feb 07 06:11:26 2013 +0900
@@ -6,9 +6,9 @@
 #ifndef MACH_O
 #define MACH_O
 
-typedef integer_t	cpu_type_t;
-typedef integer_t	cpu_subtype_t;
-typedef integer_t	cpu_threadtype_t;
+typedef int	cpu_type_t;
+typedef int	cpu_subtype_t;
+typedef int cpu_threadtype_t;
 typedef int vm_prot_t;
 
 struct mach_header_64 {