Implement HlHalt() intrinsic routine and add basic definitions for kernel services
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Rafal Kupiec 2022-12-11 23:09:35 +01:00
parent 0572b208f1
commit 9f4db475bb
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
11 changed files with 80 additions and 13 deletions

View File

@ -22,6 +22,10 @@ XTAPI
BOOLEAN
HlCpuId(IN OUT PCPUID_REGISTERS Registers);
XTAPI
VOID
HlHalt();
XTAPI
UCHAR
HlIoPortInByte(IN USHORT Port);

22
sdk/xtdk/amd64/ketypes.h Normal file
View File

@ -0,0 +1,22 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: sdk/xtdk/amd64/ketypes.h
* DESCRIPTION: Kernel services related structures definitions specific to AMD64 architecture
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#ifndef __XTDK_AMD64_KETYPES_H
#define __XTDK_AMD64_KETYPES_H
/* Static Kernel-Mode Address start */
#define KSEG0_BASE 0xFFFFF80000000000
/* XTOS Kernel address base */
#define KERNEL_ADDRESS_BASE 0x0000000800000000
/* XTOS Kernel stack size */
#define KERNEL_STACK_SIZE 8
#endif /* __XTDK_AMD64_KETYPES_H */

View File

@ -22,6 +22,10 @@ XTAPI
BOOLEAN
HlCpuId(IN OUT PCPUID_REGISTERS Registers);
XTAPI
VOID
HlHalt();
XTAPI
UCHAR
HlIoPortInByte(IN USHORT Port);

22
sdk/xtdk/i686/ketypes.h Normal file
View File

@ -0,0 +1,22 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: sdk/xtdk/i686/ketypes.h
* DESCRIPTION: Kernel services related structures definitions specific to i686 architecture
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#ifndef __XTDK_I686_KETYPES_H
#define __XTDK_I686_KETYPES_H
/* Static Kernel-Mode address start */
#define KSEG0_BASE 0x80000000
/* XTOS Kernel address base */
#define KERNEL_ADDRESS_BASE 0x01800000
/* XTOS Kernel stack size */
#define KERNEL_STACK_SIZE 8
#endif /* __XTDK_I686_KETYPES_H */

View File

@ -31,6 +31,7 @@
/* Architecture-specific low level data types headers */
#include ARCH_HEADER(hltypes.h)
#include ARCH_HEADER(ketypes.h)
#include ARCH_HEADER(mmtypes.h)
/* XT routines */

View File

@ -21,17 +21,11 @@
#define _ARCH_I686 1
#define _XT32 1
#define EFI_ERROR_MASK 0x80000000
#define XTOS_KERNEL_ADDRESS 0x81800000
#define XTOS_KERNEL_STACK_SIZE 8
#define XTOS_VIRTUAL_MEMORY_AREA 0x80000000
#elif defined(__amd64__) || defined(__x86_64__)
#define _ARCH amd64
#define _ARCH_AMD64 1
#define _XT64 1
#define EFI_ERROR_MASK 0x8000000000000000
#define XTOS_KERNEL_ADDRESS 0xFFFFF80800000000
#define XTOS_KERNEL_STACK_SIZE 8
#define XTOS_VIRTUAL_MEMORY_AREA 0xFFFFF80000000000
#else
#error Unknown architecture
#endif

View File

@ -91,7 +91,7 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
/* Map the stack */
BlGetStackPointer(&Stack);
Status = BlAddVirtualMemoryMapping(MemoryMappings, Stack, Stack, XTOS_KERNEL_STACK_SIZE,
Status = BlAddVirtualMemoryMapping(MemoryMappings, Stack, Stack, KERNEL_STACK_SIZE,
LoaderOsloaderStack);
if(Status != STATUS_EFI_SUCCESS)
{

View File

@ -101,7 +101,7 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
BlDbgPrint(L"Physical Address Extension (PAE) available\n");
/* Calculate physical address based on KSEG0 base */
PhysicalAddress = (UINT_PTR)VirtualAddress - XTOS_VIRTUAL_MEMORY_AREA;
PhysicalAddress = (UINT_PTR)VirtualAddress - KSEG0_BASE;
/* Iterate over all descriptors from memory map to find satisfying address for PDPT */
for(Index = 0; Index < DescriptorCount; Index++)
@ -142,7 +142,7 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
}
/* Set virtual address based on new PDPT address mapped to KSEG0 base */
VirtualAddress = (void*)(UINT_PTR)(PDPTAddress + EFI_PAGE_SIZE + XTOS_VIRTUAL_MEMORY_AREA);
VirtualAddress = (void*)(UINT_PTR)(PDPTAddress + EFI_PAGE_SIZE + KSEG0_BASE);
/* Set base page frame number */
Address = 0x100000; // MEM_TOP_DOWN ?
@ -191,7 +191,7 @@ BlEnablePaging(IN PLIST_ENTRY MemoryMappings,
/* Map the stack */
BlGetStackPointer(&Stack);
Status = BlAddVirtualMemoryMapping(MemoryMappings, Stack, Stack, XTOS_KERNEL_STACK_SIZE,
Status = BlAddVirtualMemoryMapping(MemoryMappings, Stack, Stack, KERNEL_STACK_SIZE,
LoaderOsloaderStack);
if(Status != STATUS_EFI_SUCCESS)
{

View File

@ -361,7 +361,7 @@ BlStartNewStack()
/* Infinite bootloader loop */
BlEfiPrint(L"System halted!");
for(;;);
HlHalt();
/* Return success */
return STATUS_EFI_SUCCESS;
@ -437,12 +437,12 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle,
BlEnumerateEfiBlockDevices();
/* Create new bootloader stack */
BlCreateStack(&EfiLoaderStack, XTOS_KERNEL_STACK_SIZE, &BlStartNewStack);
BlCreateStack(&EfiLoaderStack, KERNEL_STACK_SIZE, &BlStartNewStack);
/* Infinite bootloader loop */
BlDbgPrint(L"ERROR: Unexpected exception occurred, probably did not create a new stack\n");
BlEfiPrint(L"System halted!");
for(;;);
HlHalt();
/* Return success */
return STATUS_EFI_SUCCESS;

View File

@ -51,6 +51,16 @@ HlCpuId(IN OUT PCPUID_REGISTERS Registers)
return TRUE;
}
XTAPI
VOID
HlHalt()
{
while(TRUE)
{
asm volatile("hlt");
}
}
/**
* Reads the data from the specified I/O port.
*

View File

@ -51,6 +51,16 @@ HlCpuId(IN OUT PCPUID_REGISTERS Registers)
return TRUE;
}
XTAPI
VOID
HlHalt()
{
while(TRUE)
{
asm volatile("hlt");
}
}
/**
* Reads the data from the specified I/O port.
*