diff --git a/headers/private/kernel/platform.h b/headers/private/kernel/arch/platform.h similarity index 54% rename from headers/private/kernel/platform.h rename to headers/private/kernel/arch/platform.h index 82e838e13c..471a4ecf96 100644 --- a/headers/private/kernel/platform.h +++ b/headers/private/kernel/arch/platform.h @@ -2,8 +2,8 @@ * Copyright 2005, Ingo Weinhold . * All rights reserved. Distributed under the terms of the MIT License. */ -#ifndef _KERNEL_PLATFORM_H -#define _KERNEL_PLATFORM_H +#ifndef _KERNEL_ARCH_PLATFORM_H +#define _KERNEL_ARCH_PLATFORM_H #include @@ -13,12 +13,12 @@ struct kernel_args; extern "C" { #endif -status_t platform_init(struct kernel_args *kernelArgs); -status_t platform_init_post_vm(struct kernel_args *kernelArgs); +status_t arch_platform_init(struct kernel_args *kernelArgs); +status_t arch_platform_init_post_vm(struct kernel_args *kernelArgs); #ifdef __cplusplus } // extern "C" #endif -#endif // _KERNEL_PLATFORM_H +#endif // _KERNEL_ARCH_PLATFORM_H diff --git a/headers/private/kernel/arch/ppc/arch_platform.h b/headers/private/kernel/arch/ppc/arch_platform.h new file mode 100644 index 0000000000..8637eeeada --- /dev/null +++ b/headers/private/kernel/arch/ppc/arch_platform.h @@ -0,0 +1,32 @@ +/* + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_PPC_ARCH_PLATFORM_H +#define _KERNEL_PPC_ARCH_PLATFORM_H + +#include + +namespace BPrivate { + +class PPCPlatform { +public: + PPCPlatform(); + virtual ~PPCPlatform(); + + static PPCPlatform *Default(); + + virtual status_t Init(struct kernel_args *kernelArgs) = 0; + virtual status_t InitSerialDebug(struct kernel_args *kernelArgs) = 0; + virtual status_t InitPostVM(struct kernel_args *kernelArgs) = 0; + + virtual char SerialDebugGetChar() = 0; + virtual void SerialDebugPutChar(char c) = 0; +}; + +} // namespace BPrivate + +using BPrivate::PPCPlatform; + + +#endif // _KERNEL_PPC_ARCH_PLATFORM_H diff --git a/src/system/kernel/arch/ppc/Jamfile b/src/system/kernel/arch/ppc/Jamfile index 78dd758083..2bdee0018d 100644 --- a/src/system/kernel/arch/ppc/Jamfile +++ b/src/system/kernel/arch/ppc/Jamfile @@ -4,12 +4,13 @@ KernelStaticLibrary libppc : arch_atomic.c arch_cpu.c arch_cpu_asm.S - arch_debug_console.c + arch_debug_console.cpp arch_debug.c arch_elf.c arch_exceptions.S arch_int.c arch_mmu.cpp + arch_platform.cpp arch_real_time_clock.c arch_smp.c arch_system_info.c diff --git a/src/system/kernel/arch/ppc/arch_debug_console.c b/src/system/kernel/arch/ppc/arch_debug_console.cpp similarity index 65% rename from src/system/kernel/arch/ppc/arch_debug_console.c rename to src/system/kernel/arch/ppc/arch_debug_console.cpp index 0001cc2ca6..1fd042a208 100644 --- a/src/system/kernel/arch/ppc/arch_debug_console.c +++ b/src/system/kernel/arch/ppc/arch_debug_console.cpp @@ -7,19 +7,15 @@ */ +#include +#include +#include #include #include -#include -#include -#include #include -static int sInput = -1; -static int sOutput = -1; - - char arch_debug_blue_screen_getchar(void) { @@ -30,20 +26,14 @@ arch_debug_blue_screen_getchar(void) char arch_debug_serial_getchar(void) { - int key; - if (of_interpret("key", 0, 1, &key) == OF_FAILED) - return 0; - return (char)key; + return PPCPlatform::Default()->SerialDebugGetChar(); } void arch_debug_serial_putchar(const char c) { - if (c == '\n') - of_write(sOutput, "\r\n", 2); - else - of_write(sOutput, &c, 1); + return PPCPlatform::Default()->SerialDebugPutChar(c); } @@ -67,12 +57,7 @@ arch_debug_serial_early_boot_message(const char *string) status_t arch_debug_console_init(kernel_args *args) { - if (of_getprop(gChosen, "stdin", &sInput, sizeof(int)) == OF_FAILED) - return B_ERROR; - if (of_getprop(gChosen, "stdout", &sOutput, sizeof(int)) == OF_FAILED) - return B_ERROR; - - return B_OK; + return PPCPlatform::Default()->InitSerialDebug(args); } diff --git a/src/system/kernel/arch/ppc/arch_platform.cpp b/src/system/kernel/arch/ppc/arch_platform.cpp new file mode 100644 index 0000000000..41cdbb065d --- /dev/null +++ b/src/system/kernel/arch/ppc/arch_platform.cpp @@ -0,0 +1,172 @@ +/* + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include + +#include + +#include + +#include +#include +#include + + +static PPCPlatform *sPPCPlatform; + + +// constructor +PPCPlatform::PPCPlatform() +{ +} + +// destructor +PPCPlatform::~PPCPlatform() +{ +} + +// Default +PPCPlatform * +PPCPlatform::Default() +{ + return sPPCPlatform; +} + + +// #pragma mark - Open Firmware + + +namespace BPrivate { + +class PPCOpenFirmware : public PPCPlatform { +public: + PPCOpenFirmware(); + virtual ~PPCOpenFirmware(); + + virtual status_t Init(struct kernel_args *kernelArgs); + virtual status_t InitSerialDebug(struct kernel_args *kernelArgs); + virtual status_t InitPostVM(struct kernel_args *kernelArgs); + + virtual char SerialDebugGetChar(); + virtual void SerialDebugPutChar(char c); + +private: + int fInput; + int fOutput; +}; + +} // namespace BPrivate + +using BPrivate::PPCOpenFirmware; + + +// OF debugger commands + +// debug_command_of_exit +static int +debug_command_of_exit(int argc, char **argv) +{ + of_exit(); + kprintf("of_exit() failed!\n"); + return 0; +} + +// debug_command_of_enter +static int +debug_command_of_enter(int argc, char **argv) +{ + of_call_client_function("enter", 0, 0); + return 0; +} + + +// constructor +PPCOpenFirmware::PPCOpenFirmware() + : fInput(-1), + fOutput(-1) +{ +} + +// destructor +PPCOpenFirmware::~PPCOpenFirmware() +{ +} + +// Init +status_t +PPCOpenFirmware::Init(struct kernel_args *kernelArgs) +{ + return of_init( + (int(*)(void*))kernelArgs->platform_args.openfirmware_entry); +} + +// InitSerialDebug +status_t +PPCOpenFirmware::InitSerialDebug(struct kernel_args *kernelArgs) +{ + if (of_getprop(gChosen, "stdin", &fInput, sizeof(int)) == OF_FAILED) + return B_ERROR; + if (of_getprop(gChosen, "stdout", &fOutput, sizeof(int)) == OF_FAILED) + return B_ERROR; + + return B_OK; +} + +// InitPostVM +status_t +PPCOpenFirmware::InitPostVM(struct kernel_args *kernelArgs) +{ + add_debugger_command("of_exit", &debug_command_of_exit, + "Exit to the Open Firmware prompt. No way to get back into the OS!"); + add_debugger_command("of_enter", &debug_command_of_enter, + "Enter a subordinate Open Firmware interpreter. Quitting it returns " + "to KDL."); + + return B_OK; +} + +// DebugSerialGetChar +char +PPCOpenFirmware::SerialDebugGetChar() +{ + int key; + if (of_interpret("key", 0, 1, &key) == OF_FAILED) + return 0; + return (char)key; +} + +// DebugSerialPutChar +void +PPCOpenFirmware::SerialDebugPutChar(char c) +{ + if (c == '\n') + of_write(fOutput, "\r\n", 2); + else + of_write(fOutput, &c, 1); +} + + +// # pragma mark - + + +// static buffer for constructing the actual PPCPlatform +static char *sPPCPlatformBuffer[sizeof(PPCOpenFirmware)]; + +status_t +arch_platform_init(struct kernel_args *kernelArgs) +{ + // only OpenFirmware supported for now + if (true) + sPPCPlatform = new(sPPCPlatformBuffer) PPCOpenFirmware; + + return sPPCPlatform->Init(kernelArgs); +} + + +status_t +arch_platform_init_post_vm(struct kernel_args *kernelArgs) +{ + return sPPCPlatform->InitPostVM(kernelArgs); +} diff --git a/src/system/kernel/arch/x86/Jamfile b/src/system/kernel/arch/x86/Jamfile index 675b8737fd..07203eda4d 100644 --- a/src/system/kernel/arch/x86/Jamfile +++ b/src/system/kernel/arch/x86/Jamfile @@ -10,6 +10,7 @@ KernelStaticLibrary libx86 : arch_debug_console.c arch_elf.c arch_int.c + arch_platform.c # arch_selector.c arch_real_time_clock.c arch_smp.c diff --git a/src/system/kernel/arch/x86/arch_platform.c b/src/system/kernel/arch/x86/arch_platform.c new file mode 100644 index 0000000000..562dbe491a --- /dev/null +++ b/src/system/kernel/arch/x86/arch_platform.c @@ -0,0 +1,20 @@ +/* + * Copyright 2006, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include + + +status_t +arch_platform_init(struct kernel_args *kernelArgs) +{ + return B_OK; +} + + +status_t +arch_platform_init_post_vm(struct kernel_args *kernelArgs) +{ + return B_OK; +} diff --git a/src/system/kernel/main.c b/src/system/kernel/main.c index d5e2cbfab4..cdab79e016 100644 --- a/src/system/kernel/main.c +++ b/src/system/kernel/main.c @@ -11,6 +11,7 @@ #include +#include #include #include #include @@ -24,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -82,7 +82,7 @@ _start(kernel_args *bootKernelArgs, int currentCPU) thread_id thread; // init platform - platform_init(&sKernelArgs); + arch_platform_init(&sKernelArgs); // setup debug output debug_init(&sKernelArgs); @@ -104,7 +104,7 @@ _start(kernel_args *bootKernelArgs, int currentCPU) // the boot loader allocated region is not used anymore // now we can use the heap and create areas - platform_init_post_vm(&sKernelArgs); + arch_platform_init_post_vm(&sKernelArgs); TRACE(("init driver_settings\n")); boot_item_init(); driver_settings_init(&sKernelArgs); diff --git a/src/system/kernel/platform/bios_ia32/platform.cpp b/src/system/kernel/platform/bios_ia32/platform.cpp index 88353217d4..c30c0cc959 100644 --- a/src/system/kernel/platform/bios_ia32/platform.cpp +++ b/src/system/kernel/platform/bios_ia32/platform.cpp @@ -1,21 +1,3 @@ /* - * Copyright 2005, Ingo Weinhold . - * All rights reserved. Distributed under the terms of the MIT License. - */ - -#include - -#include - -status_t -platform_init(struct kernel_args *kernelArgs) -{ - return B_OK; -} - - -status_t -platform_init_post_vm(struct kernel_args *kernelArgs) -{ - return B_OK; -} + Just a dummy. No BIOS services are required in the kernel. +*/ diff --git a/src/system/kernel/platform/openfirmware/Jamfile b/src/system/kernel/platform/openfirmware/Jamfile index cfcd130dba..62a9614f9b 100644 --- a/src/system/kernel/platform/openfirmware/Jamfile +++ b/src/system/kernel/platform/openfirmware/Jamfile @@ -5,5 +5,4 @@ SubDirC++Flags $(TARGET_KERNEL_PIC_CCFLAGS) ; KernelStaticLibrary libopenfirmware.a : openfirmware.c - platform.cpp ; diff --git a/src/system/kernel/platform/openfirmware/platform.cpp b/src/system/kernel/platform/openfirmware/platform.cpp deleted file mode 100644 index 55fff99de1..0000000000 --- a/src/system/kernel/platform/openfirmware/platform.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2005, Ingo Weinhold . - * All rights reserved. Distributed under the terms of the MIT License. - */ - -#include - -#include - -#include -#include - - -static int -debug_command_of_exit(int argc, char **argv) -{ - of_exit(); - kprintf("of_exit() failed!\n"); - return 0; -} - - -static int -debug_command_of_enter(int argc, char **argv) -{ - of_call_client_function("enter", 0, 0); - return 0; -} - - -status_t -platform_init(struct kernel_args *kernelArgs) -{ - return of_init( - (int(*)(void*))kernelArgs->platform_args.openfirmware_entry); -} - - -status_t -platform_init_post_vm(struct kernel_args *kernelArgs) -{ - add_debugger_command("of_exit", &debug_command_of_exit, - "Exit to the Open Firmware prompt. No way to get back into the OS!"); - add_debugger_command("of_enter", &debug_command_of_enter, - "Enter a subordinate Open Firmware interpreter. Quitting it returns " - "to KDL."); - - return B_OK; -} -