From 1d4d689bf20186ee8b27d87b51cde2e8bd39ad5c Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Mon, 11 Oct 1999 20:50:33 +0000 Subject: [PATCH] Added new display and reboot code. svn path=/trunk/; revision=691 --- reactos/include/internal/hal/ddk.h | 19 ++++- reactos/include/internal/hal/hal.h | 6 ++ reactos/ntoskrnl/ex/power.c | 61 ++++++++-------- reactos/ntoskrnl/hal/x86/display.c | 110 +++++++++++++++++++++++++++++ reactos/ntoskrnl/hal/x86/reboot.c | 69 ++++++++++++++++++ reactos/ntoskrnl/hal/x86/sources | 3 +- 6 files changed, 236 insertions(+), 32 deletions(-) create mode 100644 reactos/ntoskrnl/hal/x86/display.c create mode 100644 reactos/ntoskrnl/hal/x86/reboot.c diff --git a/reactos/include/internal/hal/ddk.h b/reactos/include/internal/hal/ddk.h index 09c12aace7f..984ded28308 100644 --- a/reactos/include/internal/hal/ddk.h +++ b/reactos/include/internal/hal/ddk.h @@ -12,6 +12,11 @@ #ifndef __INCLUDE_INTERNAL_HAL_DDK_H #define __INCLUDE_INTERNAL_HAL_DDK_H +/* HalReturnToFirmware */ +#define FIRMWARE_HALT 1 +#define FIRMWARE_REBOOT 3 + + enum { DEVICE_DESCRIPTION_VERSION, @@ -54,6 +59,9 @@ typedef struct _DEVICE_DESCRIPTION ULONG DmaPort; } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION; +typedef BOOLEAN STDCALL (*RESET_DISPLAY_ROUTINE)(ULONG SizeX, ULONG SizeY); + +VOID HalAcquireDisplayOwnership(RESET_DISPLAY_ROUTINE ResetRoutine); PVOID HalAllocateCommonBuffer(PADAPTER_OBJECT AdapterObject, ULONG Length, PPHYSICAL_ADDRESS LogicalAddress, @@ -95,8 +103,15 @@ ULONG HalGetInterruptVector(INTERFACE_TYPE InterfaceType, ULONG BusInterruptVector, PKIRQL Irql, PKAFFINITY Affinity); +BOOLEAN HalMakeBeep(ULONG Frequency); +VOID HalQueryDisplayParameters(PULONG DispSizeX, + PULONG DispSizeY, + PULONG CursorPosX, + PULONG CursorPosY); +VOID HalQueryRealTimeClock(PTIME_FIELDS pTime); VOID HalQuerySystemInformation(VOID); ULONG HalReadDmaCounter(PADAPTER_OBJECT AdapterObject); +VOID HalReturnToFirmware(ULONG Action); ULONG HalSetBusData(BUS_DATA_TYPE BusDataType, ULONG BusNumber, ULONG SlotNumber, @@ -108,12 +123,12 @@ ULONG HalSetBusDataByOffset(BUS_DATA_TYPE BusDataType, PVOID Buffer, ULONG Offset, ULONG Length); +VOID HalSetDisplayParameters(ULONG CursorPosX, + ULONG CursorPosY); BOOLEAN HalTranslateBusAddress(INTERFACE_TYPE InterfaceType, ULONG BusNumber, PHYSICAL_ADDRESS BusAddress, PULONG AddressSpace, PPHYSICAL_ADDRESS TranslatedAddress); -BOOLEAN HalMakeBeep(ULONG Frequency); -VOID HalQueryRealTimeClock(PTIME_FIELDS pTime); #endif /* __INCLUDE_INTERNAL_HAL_DDK_H */ diff --git a/reactos/include/internal/hal/hal.h b/reactos/include/internal/hal/hal.h index 21ea94a7546..7578de50909 100644 --- a/reactos/include/internal/hal/hal.h +++ b/reactos/include/internal/hal/hal.h @@ -68,4 +68,10 @@ VOID Hal_bios32_probe(VOID); BOOLEAN Hal_bios32_is_service_present(ULONG service); +/* + * FUNCTION: Initializes the text mode display (blue screen) + */ +VOID HalInitializeDisplay (VOID); + + #endif /* __INTERNAL_HAL_HAL_H */ diff --git a/reactos/ntoskrnl/ex/power.c b/reactos/ntoskrnl/ex/power.c index 559fbe7df12..b0b49763ad3 100644 --- a/reactos/ntoskrnl/ex/power.c +++ b/reactos/ntoskrnl/ex/power.c @@ -24,38 +24,41 @@ NTSTATUS STDCALL NtSetSystemPowerState(VOID) } -static void kb_wait(void) -{ - int i; - - for (i=0; i<10000; i++) - { - if ((inb_p(0x64) & 0x02) == 0) - { - return; - } - } -} - NTSTATUS STDCALL NtShutdownSystem ( - IN SHUTDOWN_ACTION Action + IN SHUTDOWN_ACTION Action ) -/* - * FIXME: Does a reboot only - */ { - int i, j; - - for (;;) - { - for (i=0; i<100; i++) - { - kb_wait(); - for (j=0; j<500; j++); - outb(0xfe, 0x64); - for (j=0; j<500; j++); - } - } + if (Action > ShutdownPowerOff) + return STATUS_INVALID_PARAMETER; + + /* FIXME: notify all registered drivers (MJ_SHUTDOWN) */ + + /* FIXME: notify configuration manager (Registry) */ + + /* FIXME: notify memory manager */ + + /* FIXME: notify all file system drivers (MJ_SHUTDOWN) */ + + if (Action == ShutdownNoReboot) + { +#if 0 + /* Switch off */ + HalReturnToFirmware (FIRMWARE_OFF); +#endif + } + else if (Action == ShutdownReboot) + { + HalReturnToFirmware (FIRMWARE_REBOOT); + } + else + { + HalReturnToFirmware (FIRMWARE_HALT); + } + + return STATUS_SUCCESS; } + +/* EOF */ + diff --git a/reactos/ntoskrnl/hal/x86/display.c b/reactos/ntoskrnl/hal/x86/display.c new file mode 100644 index 00000000000..eb834c72714 --- /dev/null +++ b/reactos/ntoskrnl/hal/x86/display.c @@ -0,0 +1,110 @@ +/* $Id: display.c,v 1.1 1999/10/11 20:50:32 ekohl Exp $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * FILE: ntoskrnl/hal/x86/display.c + * PURPOSE: Text mode display functions (blue screen) + * PROGRAMMER: Eric Kohl (ekohl@abo.rhein-zeitung.de) + * UPDATE HISTORY: + * Created 08/10/99 + */ + +#include +#include + + +/* VARIABLES ****************************************************************/ + +static ULONG CursorX = 0; /* Cursor Position */ +static ULONG CursorY = 0; +static ULONG SizeX = 80; /* Display size */ +static ULONG SizeY = 50; + +static BOOLEAN DisplayInitialized = FALSE; +static BOOLEAN HalOwnsDisplay = TRUE; + +static BYTE *VideoBuffer = NULL; + +static RESET_DISPLAY_ROUTINE ResetRoutine = NULL; + + +/* STATIC FUNCTIONS *********************************************************/ + +static VOID +HalClearDisplay (VOID) +{ + WORD *ptr = (WORD*)VideoBuffer; + ULONG i; + + for (i=0; i < SizeX*SizeY; i++, ptr++) + *ptr = 0x1720; +} + + + +/* PRIVATE FUNCTIONS ********************************************************/ + +VOID +HalInitializeDisplay (VOID) +{ + if (DisplayInitialized == FALSE) + { + DisplayInitialized = TRUE; + + VideoBuffer = (BYTE *)(0xd0000000 + 0xb8000); +// VideoBuffer = HalMapPhysicalMemory (0xb8000, 2); + + HalClearDisplay (); + } +} + + +/* PUBLIC FUNCTIONS *********************************************************/ + + +VOID +STDCALL +HalAcquireDisplayOwnership (RESET_DISPLAY_ROUTINE ResetDisplay) +{ + HalOwnsDisplay = FALSE; + ResetRoutine = ResetDisplay; +} + + +VOID +STDCALL +HalDisplayString (VOID) +{ + + +} + + +VOID +STDCALL +HalQueryDisplayParameters (PULONG DispSizeX, + PULONG DispSizeY, + PULONG CursorPosX, + PULONG CursorPosY) +{ + if (DispSizeX) + *DispSizeX = SizeX; + if (DispSizeY) + *DispSizeY = SizeY; + if (CursorPosX) + *CursorPosX = CursorX; + if (CursorPosY) + *CursorPosY = CursorY; +} + + +VOID +STDCALL +HalSetDisplayParameters (ULONG CursorPosX, + ULONG CursorPosY) +{ + CursorX = (CursorPosX < SizeX) ? CursorPosX : SizeX - 1; + CursorY = (CursorPosY < SizeY) ? CursorPosY : SizeY - 1; +} + +/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/reboot.c b/reactos/ntoskrnl/hal/x86/reboot.c new file mode 100644 index 00000000000..30956eb5595 --- /dev/null +++ b/reactos/ntoskrnl/hal/x86/reboot.c @@ -0,0 +1,69 @@ +/* $Id: reboot.c,v 1.1 1999/10/11 20:50:33 ekohl Exp $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * FILE: ntoskrnl/hal/x86/reboot.c + * PURPOSE: Reboot functions. + * PROGRAMMER: Eric Kohl (ekohl@abo.rhein-zeitung.de) + * UPDATE HISTORY: + * Created 11/10/99 + */ + + +#include +#include +#include + + +static VOID +HalReboot (VOID) +{ + char data; + BYTE *mem; + + /* enable warm reboot */ + mem = (BYTE *)(0xd0000000 + 0x0000); +// mem = HalMapPhysicalMemory (0, 1); + mem[0x472] = 0x34; + mem[0x473] = 0x12; + + /* disable interrupts */ + __asm__("cli\n"); + + /* disable periodic interrupt (RTC) */ + outb_p (0x70, 0x0b); + data = inb_p (0x71); + outb_p (0x71, data & 0xbf); + + /* */ + outb_p (0x70, 0x0a); + data = inb_p (0x71); + outb_p (0x71, (data & 0xf0) | 0x06); + + /* */ + outb_p (0x70, 0x15); + + /* generate RESET signal via keyboard controller */ + outb_p (0x64, 0xfe); + + /* stop the processor */ + __asm__("hlt\n"); +} + + +VOID +HalReturnToFirmware (ULONG Action) +{ + if (Action == FIRMWARE_HALT) + { + DbgPrint ("HalReturnToFirmware called!\n"); + DbgBreakPoint (); + } + else if (Action == FIRMWARE_REBOOT) + { +// HalVideoReboot(); + HalReboot (); + } +} + +/* EOF */ diff --git a/reactos/ntoskrnl/hal/x86/sources b/reactos/ntoskrnl/hal/x86/sources index 2dfae103238..f1ff66360a9 100644 --- a/reactos/ntoskrnl/hal/x86/sources +++ b/reactos/ntoskrnl/hal/x86/sources @@ -2,5 +2,6 @@ HAL_OBJECTS = hal/x86/head.o hal/x86/irq.o hal/x86/exp.o hal/x86/isa.o \ hal/x86/pci.o hal/x86/irqhand.o hal/x86/page.o hal/x86/halinit.o \ hal/x86/irql.o hal/x86/bios32.o hal/x86/thread.o hal/x86/spinlock.o \ hal/x86/printk.o hal/x86/mp.o hal/x86/dma.o hal/x86/bus.o hal/x86/mbr.o \ - hal/x86/sysinfo.o hal/x86/time.o hal/x86/usercall.o hal/x86/beep.o + hal/x86/sysinfo.o hal/x86/time.o hal/x86/usercall.o hal/x86/beep.o \ + hal/x86/display.o hal/x86/reboot.o