diff --git a/sdk/xtdk/hlfuncs.h b/sdk/xtdk/hlfuncs.h index 3ee35d9..1939845 100644 --- a/sdk/xtdk/hlfuncs.h +++ b/sdk/xtdk/hlfuncs.h @@ -15,6 +15,10 @@ /* HAL library routines forward references */ +XTAPI +VOID +HlClearScreen(VOID); + XTCDECL XTSTATUS HlComPortGetByte(IN PCPPORT Port, @@ -32,6 +36,12 @@ UCHAR HlComPortReadLsr(IN PCPPORT Port, IN UCHAR Byte); +XTAPI +VOID +HlDrawPixel(IN ULONG PosX, + IN ULONG PosY, + IN ULONG Color); + XTCDECL XTSTATUS HlInitializeComPort(IN OUT PCPPORT Port, @@ -39,4 +49,8 @@ HlInitializeComPort(IN OUT PCPPORT Port, IN PUCHAR PortAddress, IN ULONG BaudRate); +XTAPI +XTSTATUS +HlInitializeDisplay(VOID); + #endif /* __XTDK_HLFUNCS_H */ diff --git a/sdk/xtdk/hltypes.h b/sdk/xtdk/hltypes.h index 37701ca..0fe2e62 100644 --- a/sdk/xtdk/hltypes.h +++ b/sdk/xtdk/hltypes.h @@ -98,4 +98,16 @@ typedef struct _CPPORT USHORT Flags; } CPPORT, *PCPPORT; +typedef struct _HAL_FRAMEBUFFER_DATA +{ + BOOLEAN Initialized; + PULONG Address; + ULONG_PTR BufferSize; + UINT Width; + UINT Height; + UINT PixelsPerScanLine; + UINT BitsPerPixel; + UINT Pitch; +} HAL_FRAMEBUFFER_DATA, *PHAL_FRAMEBUFFER_DATA; + #endif /* __XTDK_HLTYPES_H */ diff --git a/xtoskrnl/CMakeLists.txt b/xtoskrnl/CMakeLists.txt index 50e5acd..9d85d3d 100644 --- a/xtoskrnl/CMakeLists.txt +++ b/xtoskrnl/CMakeLists.txt @@ -9,6 +9,7 @@ include_directories( # Specify list of source code files list(APPEND XTOSKRNL_SOURCE ${XTOSKRNL_SOURCE_DIR}/hl/cport.c + ${XTOSKRNL_SOURCE_DIR}/hl/efifb.c ${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/cpufunc.c ${XTOSKRNL_SOURCE_DIR}/ke/globals.c ${XTOSKRNL_SOURCE_DIR}/ke/krnlinit.c diff --git a/xtoskrnl/hl/efifb.c b/xtoskrnl/hl/efifb.c new file mode 100644 index 0000000..9888a57 --- /dev/null +++ b/xtoskrnl/hl/efifb.c @@ -0,0 +1,118 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/hl/efifb.c + * DESCRIPTION: EFI framebuffer support + * DEVELOPERS: Rafal Kupiec + */ + +#include + + +/** + * Clears the screen by drawing a filled black box. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +HlClearScreen(VOID) +{ + SIZE_T PositionX, PositionY; + + /* Fill the screen with a black box */ + for(PositionX = 0; PositionX < HlpFrameBufferData.Width; PositionX++) + { + for(PositionY = 0; PositionY < HlpFrameBufferData.Height; PositionY++) + { + HlDrawPixel(PositionX, PositionY, 0x00000000); + } + } +} + +/** + * Draw a pixel on the screen at the given position and color. + * + * @param PositionX + * Supplies the X coordinate of the pixel. + * + * @param PositionY + * Supplies the Y coordinate of the pixel. + * + * @param Color + * Specifies the color of the pixel. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +HlDrawPixel(IN ULONG PositionX, + IN ULONG PositionY, + IN ULONG Color) +{ + /* Make sure frame buffer is already initialized */ + if(HlpFrameBufferData.Initialized == FALSE) + { + /* Unable to operate on non-initialized frame buffer */ + return; + } + + /* Make sure point is not offscreen */ + if(PositionX >= HlpFrameBufferData.Width || PositionY >= HlpFrameBufferData.Height || Color > 0xFFFFFFFF) + { + /* Invalid pixel position or color given */ + return; + } + + /* Calculate the index of the pixel in the frame buffer memory using the provided x and y coordinates */ + SIZE_T FrameBufferIndex = PositionY * HlpFrameBufferData.PixelsPerScanLine + PositionX; + + /* Set the color of the pixel by writing to the corresponding memory location */ + HlpFrameBufferData.Address[FrameBufferIndex] = Color; +} + +/** + * Initializes frame buffer display. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +HlInitializeDisplay(VOID) +{ + /* Check if display already initialized */ + if(HlpFrameBufferData.Initialized) + { + /* Nothing to do */ + return STATUS_SUCCESS; + } + + /* Check if framebuffer initialized by bootloader */ + if(!KeInitializationBlock->LoaderInformation.FrameBuffer.Initialized || + !KeInitializationBlock->LoaderInformation.FrameBuffer.Address) + { + /* Display not initialized */ + return STATUS_DEVICE_NOT_READY; + } + + /* Save framebuffer information and mark display as initialized */ + HlpFrameBufferData.Address = (PULONG)KeInitializationBlock->LoaderInformation.FrameBuffer.Address; + HlpFrameBufferData.Width = KeInitializationBlock->LoaderInformation.FrameBuffer.Width; + HlpFrameBufferData.Height = KeInitializationBlock->LoaderInformation.FrameBuffer.Height; + HlpFrameBufferData.BitsPerPixel = KeInitializationBlock->LoaderInformation.FrameBuffer.BitsPerPixel; + HlpFrameBufferData.PixelsPerScanLine = KeInitializationBlock->LoaderInformation.FrameBuffer.PixelsPerScanLine; + HlpFrameBufferData.Pitch = KeInitializationBlock->LoaderInformation.FrameBuffer.Pitch; + HlpFrameBufferData.Initialized = TRUE; + + /* Clear screen */ + HlClearScreen(); + + /* Return success */ + return STATUS_SUCCESS; +} diff --git a/xtoskrnl/includes/globals.h b/xtoskrnl/includes/globals.h index a5cf9ee..90503f2 100644 --- a/xtoskrnl/includes/globals.h +++ b/xtoskrnl/includes/globals.h @@ -12,6 +12,9 @@ #include +/* FrameBuffer information */ +EXTERN HAL_FRAMEBUFFER_DATA HlpFrameBufferData; + /* Kernel initialization block passed by boot loader */ EXTERN PKERNEL_INITIALIZATION_BLOCK KeInitializationBlock; diff --git a/xtoskrnl/ke/globals.c b/xtoskrnl/ke/globals.c index ef16a76..8213ad7 100644 --- a/xtoskrnl/ke/globals.c +++ b/xtoskrnl/ke/globals.c @@ -9,6 +9,9 @@ #include +/* FrameBuffer information */ +HAL_FRAMEBUFFER_DATA HlpFrameBufferData; + /* Kernel initialization block passed by boot loader */ PKERNEL_INITIALIZATION_BLOCK KeInitializationBlock;