[haiku-commits] BRANCH tqh-github.efi_pm [f54e16d] src/system/boot/platform/efi

  • From: tqh-github.efi_pm <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 30 Nov 2013 21:45:34 +0100 (CET)

added 6 changesets to branch 'refs/remotes/tqh-github/efi_pm'
old head: bb5bf245dfaad45ddffb08539db4f37a14f92703
new head: f54e16df3fa250de9d957d97de7d55cecc11c1e8
overview: https://github.com/tqh/haiku/compare/bb5bf24...f54e16d

----------------------------------------------------------------------------

5f6ad5e: Add EFI platform header for files using EFI.

d7043f6: Implement console code.

ab99e37: Init console.

4a4a71c: Remove old start.c.

899d67c: Update Jamfile to build console, remove old rules.

f54e16d: Remove old EFI string writing test code.

                         [ Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx> ]

----------------------------------------------------------------------------

6 files changed, 332 insertions(+), 88 deletions(-)
src/system/boot/platform/efi/Jamfile        |  35 +----
src/system/boot/platform/efi/console.cpp    | 188 ++++++++++++++++++++++++
src/system/boot/platform/efi/console.h      |  14 ++
src/system/boot/platform/efi/efi_platform.h |  20 +++
src/system/boot/platform/efi/start.c        |  58 --------
src/system/boot/platform/efi/start.cpp      | 105 +++++++++++++

############################################################################

Commit:      5f6ad5ead4b76b4057922824d96e95b9806d40b1
Author:      Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx>
Date:        Sat Nov 30 20:33:02 2013 UTC

Add EFI platform header for files using EFI.

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/efi/efi_platform.h 
b/src/system/boot/platform/efi/efi_platform.h
new file mode 100644
index 0000000..b1a8750
--- /dev/null
+++ b/src/system/boot/platform/efi/efi_platform.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2013, Fredrik Holmqvist, fredrik.holmqvist@xxxxxxxxx. All rights 
reserved.
+ * Distributed under the terms of the Haiku License.
+ */
+
+
+#ifndef EFI_PLATFORM_H
+#define EFI_PLATFORM_H
+
+#include "efibind.h"
+#include "efidef.h"
+#include "efidevp.h"
+#include "eficon.h"
+#include "efierr.h"
+#include "efiapi.h"
+
+
+extern const EFI_SYSTEM_TABLE *kSystemTable;
+
+#endif /* EFI_PLATFORM_H */

############################################################################

Commit:      d7043f6d35472d011f3f3e9b04cd5ea0c1a000ce
Author:      Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx>
Date:        Sat Nov 30 20:35:06 2013 UTC

Implement console code.

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/efi/console.cpp 
b/src/system/boot/platform/efi/console.cpp
new file mode 100644
index 0000000..4db2f29
--- /dev/null
+++ b/src/system/boot/platform/efi/console.cpp
@@ -0,0 +1,188 @@
+/*
+ * Copyright 2013, Fredrik Holmqvist, fredrik.holmqvist@xxxxxxxxx. All rights 
reserved.
+ * Distributed under the terms of the Haiku License.
+ */
+
+
+#include "console.h"
+#include "efi_platform.h"
+
+#include <SupportDefs.h>
+#include <util/kernel_cpp.h>
+#include <boot/stage2.h>
+
+#include <string.h>
+
+
+class Console : public ConsoleNode {
+       public:
+               Console();
+
+               virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, 
size_t bufferSize);
+               virtual ssize_t WriteAt(void *cookie, off_t pos, const void 
*buffer, size_t bufferSize);
+};
+
+static uint32 sScreenWidth;
+static uint32 sScreenHeight;
+static Console sInput, sOutput;
+FILE *stdin, *stdout, *stderr;
+
+
+//     #pragma mark -
+
+
+Console::Console()
+       : ConsoleNode()
+{
+}
+
+
+ssize_t
+Console::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
+{
+       // don't seek in character devices
+       // not implemented (and not yet? needed)
+       return B_ERROR;
+}
+
+
+ssize_t
+Console::WriteAt(void *cookie, off_t /*pos*/, const void *buffer, size_t 
bufferSize)
+{
+       const char *string = (const char *)buffer;
+       CHAR16 ucsBuffer[bufferSize + 3];
+       uint32 j = 0;
+
+       for (uint32 i = 0; i < bufferSize; i++) {
+               switch (string[i]) {
+                       case '\n': {
+                               ucsBuffer[j++] = '\r';
+                               ucsBuffer[j++] = '\n';
+                       } //fallthrough
+                       case 0 : {
+                               //Not sure if we should keep going or abort for 
0.
+                               //Keep going was easy anyway.
+                               ucsBuffer[j] = 0;
+                               
kSystemTable->ConOut->OutputString(kSystemTable->ConOut, ucsBuffer);
+                               j = 0;
+                               continue;
+                       }
+                       default:
+                               ucsBuffer[j++] = (CHAR16) string[i];
+               }
+       }
+
+       if (j > 0) {
+               ucsBuffer[j] = 0;
+               kSystemTable->ConOut->OutputString(kSystemTable->ConOut, 
ucsBuffer);
+       }
+       return bufferSize;
+}
+
+
+//     #pragma mark -
+
+
+void
+console_clear_screen(void)
+{
+       kSystemTable->ConOut->ClearScreen(kSystemTable->ConOut);
+}
+
+
+int32
+console_width(void)
+{
+       return sScreenWidth;
+}
+
+
+int32
+console_height(void)
+{
+       return sScreenHeight;
+}
+
+
+void
+console_set_cursor(int32 x, int32 y)
+{
+       kSystemTable->ConOut->SetCursorPosition(kSystemTable->ConOut, x, y);
+}
+
+
+void
+console_show_cursor(void)
+{
+       kSystemTable->ConOut->EnableCursor(kSystemTable->ConOut, true);
+}
+
+
+void
+console_hide_cursor(void)
+{
+       kSystemTable->ConOut->EnableCursor(kSystemTable->ConOut, false);
+}
+
+
+void
+console_set_color(int32 foreground, int32 background)
+{
+       kSystemTable->ConOut->SetAttribute(kSystemTable->ConOut,
+               EFI_TEXT_ATTR((foreground & 0xf), (background & 0xf)));
+}
+
+
+int
+console_wait_for_key(void)
+{
+       UINTN index;
+       EFI_EVENT event = kSystemTable->ConIn->WaitForKey;
+       kSystemTable->BootServices->WaitForEvent(1, &event, &index);
+       EFI_INPUT_KEY key;
+       kSystemTable->ConIn->ReadKeyStroke(kSystemTable->ConIn, &key);
+       if (key.UnicodeChar > 0)
+               return (int) key.UnicodeChar;
+
+       switch (key.ScanCode) {
+               case SCAN_UP:
+                       return TEXT_CONSOLE_KEY_UP;
+               case SCAN_DOWN:
+                       return TEXT_CONSOLE_KEY_DOWN;
+               case SCAN_LEFT:
+                       return TEXT_CONSOLE_KEY_LEFT;
+               case SCAN_RIGHT:
+                       return TEXT_CONSOLE_KEY_RIGHT;
+               case SCAN_PAGE_UP:
+                       return TEXT_CONSOLE_KEY_PAGE_UP;
+               case SCAN_PAGE_DOWN:
+                       return TEXT_CONSOLE_KEY_PAGE_DOWN;
+               case SCAN_HOME:
+                       return TEXT_CONSOLE_KEY_HOME;
+               case SCAN_END:
+                       return TEXT_CONSOLE_KEY_END;
+       }
+       return 0;
+}
+
+static void updateScreenSize(void)
+{
+       UINTN width, height;
+       kSystemTable->ConOut->QueryMode(kSystemTable->ConOut,
+               kSystemTable->ConOut->Mode->Mode, &width, &height);
+
+       sScreenWidth = width;
+       sScreenHeight = height;
+}
+
+status_t
+console_init(void)
+{
+       updateScreenSize();
+       console_clear_screen();
+       // enable stdio functionality
+       stdin = (FILE *)&sInput;
+       stdout = stderr = (FILE *)&sOutput;
+       return B_OK;
+}
+
diff --git a/src/system/boot/platform/efi/console.h 
b/src/system/boot/platform/efi/console.h
new file mode 100644
index 0000000..aa2acfb
--- /dev/null
+++ b/src/system/boot/platform/efi/console.h
@@ -0,0 +1,14 @@
+/*
+** Copyright 2004, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. All rights reserved.
+** Distributed under the terms of the Haiku License.
+*/
+#ifndef CONSOLE_H
+#define CONSOLE_H
+
+#include <boot/platform/generic/text_console.h>
+
+
+extern "C" status_t console_init(void);
+
+
+#endif /* CONSOLE_H */

############################################################################

Commit:      ab99e370835b045f6ab3bee8e757539280e276ec
Author:      Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx>
Date:        Sat Nov 30 20:35:38 2013 UTC

Init console.

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/efi/start.cpp 
b/src/system/boot/platform/efi/start.cpp
new file mode 100644
index 0000000..5f6814e
--- /dev/null
+++ b/src/system/boot/platform/efi/start.cpp
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2013, Fredrik Holmqvist, fredrik.holmqvist@xxxxxxxxx. All rights 
reserved.
+ * Distributed under the terms of the Haiku License.
+ */
+
+
+#include <string.h>
+
+#include <KernelExport.h>
+
+#include <arch/cpu.h>
+#include <boot/platform.h>
+#include <boot/heap.h>
+#include <boot/stage2.h>
+#include <stdio.h>
+
+#include "efi_platform.h"
+
+#include "console.h"
+#include "interrupts.h"
+
+
+extern void (*__ctor_list)(void);
+extern void (*__ctor_end)(void);
+extern uint8 __bss_start;
+extern uint8 _end;
+
+
+const EFI_SYSTEM_TABLE *kSystemTable;
+
+
+static void
+clear_bss(void)
+{
+       memset(&__bss_start, 0, &_end - &__bss_start);
+}
+
+
+static void
+call_ctors(void)
+{
+       void (**f)(void);
+
+       for (f = &__ctor_list; f < &__ctor_end; f++) {
+               (**f)();
+       }
+}
+
+
+/**
+ * efi_main - The entry point for the EFI application
+ * @image: firmware-allocated handle that identifies the image
+ * @SystemTable: EFI system table
+ */
+extern "C" EFI_STATUS
+efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systemTable)
+{
+       stage2_args args;
+
+       kSystemTable = systemTable;
+       asm("cld");                     // Ain't nothing but a GCC thang.
+       asm("fninit");          // initialize floating point unit
+
+       /* Needed, Intel Beyond BIOS 
http://software.intel.com/en-us/articles/uefi-application
+        * No direct support
+        * New and Delete can be mapped to malloc/free
+        */
+       clear_bss();
+       call_ctors();
+               // call C++ constructors before doing anything else
+
+  //Do all the necessary things needed...
+
+  /* serial - ignore for now */
+       /* interrupts_init(); */
+       console_init();
+  /* console - EFI console handling */
+  /* cpu init - TODO */
+  /* mmu init - TODO */
+  /* debug_init_post_mmu - TODO */
+  /* parse_multiboot_commandline - probably not */
+  /* check for boot keys */
+
+  /* APM - skip entirely */
+  /* ACPI - do we need to mmap/checksum it ? Or does EFI help with that.. Is 
it needed */
+  /* smp - TODO */
+  /* HPET - TODO */
+  /* dump_multiboot_info */
+
+
+  /* Map runtime services to virtual memory
+   * Get/Set EFI Variables
+   * Get/Set time (with timezone)
+   * Get/Set Wakup time
+   * Reset system
+   * Send 'capsules'? to EFI to be executed
+   */
+  /* Exit boot services - Only use runtime ( and maybe some system services) 
from here on.
+   * See info on memory map and much more in docs. */
+
+  //launch kernel (main(&args);)
+
+/*
+       UINTN index;
+       EFI_EVENT event = systemTable->ConIn->WaitForKey;
+
+       SIMPLE_INPUT_INTERFACE *conIn = systemTable->ConIn;
+       SIMPLE_TEXT_OUTPUT_INTERFACE *conOut = systemTable->ConOut;
+       conOut->OutputString(conOut, exampleText);
+
+       systemTable->BootServices->WaitForEvent(1, &event, &index);
+*/
+       console_wait_for_key();
+       return EFI_SUCCESS;
+}

############################################################################

Commit:      4a4a71cdf655148f3d253ef328dd94f8062b3f00
Author:      Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx>
Date:        Sat Nov 30 20:36:14 2013 UTC

Remove old start.c.

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/efi/start.c 
b/src/system/boot/platform/efi/start.c
deleted file mode 100644
index 11ab239..0000000
--- a/src/system/boot/platform/efi/start.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2011, Intel Corporation
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *    * Redistributions of source code must retain the above copyright
- *      notice, this list of conditions and the following disclaimer.
- *    * Redistributions in binary form must reproduce the above copyright
- *      notice, this list of conditions and the following disclaimer
- *      in the documentation and/or other materials provided with the
- *      distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- 
-#include "efibind.h"
-#include "efidef.h"
-#include "efidevp.h"
-#include "eficon.h"
-#include "efiapi.h"
-#include "efierr.h"
-
-
-static CHAR16 *exampleText = L"Example EFI Application. Press any key!";
-
-/**
- * efi_main - The entry point for the EFI application
- * @image: firmware-allocated handle that identifies the image
- * @SystemTable: EFI system table
- */
-EFI_STATUS
-efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systemTable)
-{
-       UINTN index;
-       EFI_EVENT event = systemTable->ConIn->WaitForKey;
-
-//     SIMPLE_INPUT_INTERFACE *conIn = systemTable->ConIn;
-       SIMPLE_TEXT_OUTPUT_INTERFACE *conOut = systemTable->ConOut;
-       conOut->OutputString(conOut, exampleText);
-
-       systemTable->BootServices->WaitForEvent(1, &event, &index);
-
-       return EFI_SUCCESS;
-}

############################################################################

Commit:      899d67c6ba4ef5a91229cfe079d6e9422fbf3dcd
Author:      Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx>
Date:        Sat Nov 30 20:36:36 2013 UTC

Update Jamfile to build console, remove old rules.

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/efi/Jamfile 
b/src/system/boot/platform/efi/Jamfile
index 913f8ed..4e92da3 100644
--- a/src/system/boot/platform/efi/Jamfile
+++ b/src/system/boot/platform/efi/Jamfile
@@ -12,10 +12,6 @@ UsePrivateHeaders [ FDirName kernel boot platform efi arch 
$(TARGET_ARCH) ] ;
        SubDirC++Flags $(defines) -fno-rtti ;
 }
 
-#local TARGET_BOOT_CCFLAGS = ;
-#local TARGET_BOOT_C++FLAGS = ;
-#local TARGET_BOOT_LINKFLAGS = ;
-
 local efi_glue_src =
        relocation_func.cpp
        start_func.S
@@ -24,35 +20,14 @@ local efi_glue_src =
 BootMergeObject boot_platform_efi.o :
        start.cpp
        console.cpp
-       debug.cpp
-       devices.cpp
-       interrupts.cpp
-       mmu.cpp
+#      debug.cpp
+#      devices.cpp
+#      interrupts.cpp
+#      interrupts_asm.S
+#      mmu.cpp
        $(efi_glue_src)
        :
        : boot_platform_generic.a
        ;
 
-#BootLd haiku_efi_bootloader.so
-#  : boot_platform_efi.o
-#  : $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/boot_loader_efi.ld
-#  : -Bsymbolic -shared -nostdlib -znocombreloc ;
-
-
-rule EFIApplication {
-       local efiApplication = $(1) ;
-       local elfLibrary = $(2) ;
-
-       Depends $(efiApplication) : $(elfLibrary) ;
-       MakeLocateDebug $(efiApplication) ;
-}
-
-actions EFIApplication {
-       rm -f $(1)
-       $(TARGET_OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j 
.rel \
-       -j .rela -j .reloc -S --target=efi-app-x86-64 $(2) $(1)
-}
-
-EFIApplication haiku.efi : haiku_efi_bootloader.so ;
-
 SEARCH on [ FGristFiles $(efi_glue_src)  ] = [ FDirName $(HAIKU_TOP) src 
system boot platform efi arch $(TARGET_ARCH) ] ;

############################################################################

Commit:      f54e16df3fa250de9d957d97de7d55cecc11c1e8
Author:      Fredrik Holmqvist <fredrik.holmqvist@xxxxxxxxx>
Date:        Sat Nov 30 20:44:03 2013 UTC

Remove old EFI string writing test code.

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/efi/start.cpp 
b/src/system/boot/platform/efi/start.cpp
index 5f6814e..1831efa 100644
--- a/src/system/boot/platform/efi/start.cpp
+++ b/src/system/boot/platform/efi/start.cpp
@@ -100,16 +100,6 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systemTable)
 
   //launch kernel (main(&args);)
 
-/*
-       UINTN index;
-       EFI_EVENT event = systemTable->ConIn->WaitForKey;
-
-       SIMPLE_INPUT_INTERFACE *conIn = systemTable->ConIn;
-       SIMPLE_TEXT_OUTPUT_INTERFACE *conOut = systemTable->ConOut;
-       conOut->OutputString(conOut, exampleText);
-
-       systemTable->BootServices->WaitForEvent(1, &event, &index);
-*/
        console_wait_for_key();
        return EFI_SUCCESS;
 }


Other related posts:

  • » [haiku-commits] BRANCH tqh-github.efi_pm [f54e16d] src/system/boot/platform/efi - tqh-github . efi_pm