diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-28 18:20:31 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-28 18:20:31 +0100 |
| commit | 4a789fd64c44e38ed0c3d9fb597e62afd17a337d (patch) | |
| tree | dff9c68b5adacd7aaf55fcd284f2fdb4ad504f1c /Private/NewBoot/Source | |
| parent | 87913aa62de0edfcbde9d9fdb938968d1b511a5f (diff) | |
Ongoing effort to reimplement core protocol of EFI into EFIKit.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot/Source')
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/ATA.cxx | 172 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/ATA.hxx | 106 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc | 4 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/makefile | 37 | ||||
| -rw-r--r-- | Private/NewBoot/Source/MPT/.hgkeep | 0 | ||||
| -rw-r--r-- | Private/NewBoot/Source/MPT/API.hxx | 17 | ||||
| -rw-r--r-- | Private/NewBoot/Source/MPT/Detail.hxx | 45 | ||||
| -rw-r--r-- | Private/NewBoot/Source/MPT/MPT.hxx | 30 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 12 |
9 files changed, 8 insertions, 415 deletions
diff --git a/Private/NewBoot/Source/HEL/AMD64/ATA.cxx b/Private/NewBoot/Source/HEL/AMD64/ATA.cxx deleted file mode 100644 index 7bcd304a..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/ATA.cxx +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2024 Mahrouss Logic, all rights reserved - */ - -#include "ATA.hxx" -#include <ArchKit/Arch.hpp> - -using namespace hCore::HAL; - -static Boolean kATADetected = false; - -void IDESelect(UInt8 Bus, Boolean isMaster) -{ - if (Bus == ATA_PRIMARY) - out8(ATA_PRIMARY_IO + ATA_REG_HDDEVSEL, - isMaster ? ATA_PRIMARY_SEL : ATA_SECONDARY_SEL); - else - out8(ATA_SECONDARY_IO + ATA_REG_HDDEVSEL, - isMaster ? ATA_PRIMARY_SEL : ATA_SECONDARY_SEL); -} - -Boolean ATAInitDriver(UInt8 Bus, UInt8 Drive) -{ - UInt16 IO = (Bus == ATA_PRIMARY) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO; - - IDESelect(Bus, Drive); - - out8(IO + ATA_REG_SEC_COUNT0, 0); - out8(IO + ATA_REG_LBA0, 0); - out8(IO + ATA_REG_LBA1, 0); - out8(IO + ATA_REG_LBA2, 0); - - out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - - UInt8 status = in8(IO + ATA_REG_STATUS); - - if (status) - { - while ((status = in8(IO + ATA_REG_STATUS) & ATA_SR_BSY)) - ; - - if (status & ATA_REG_ERROR) - { - return false; - } - - kATADetected = true; - return status; - } - - return false; -} - -void ATAWait(UInt16 IO) -{ - for (int i = 0; i < 4000; i++) - in8(IO + ATA_REG_ALT_STATUS); -} - -void IDEPoll(UInt16 IO) { ATAWait(IO); } - -UInt16 ATAReadLba(UInt32 lba, UInt8 bus, Boolean master) -{ - UInt16 IO = bus; - IDESelect(IO, master ? ATA_MASTER : ATA_SLAVE); - - out8(IO + ATA_REG_LBA5, (UInt8)(lba >> 24) & 0xF); - - out8(IO + ATA_REG_SEC_COUNT0, lba / 512); - - out8(IO + ATA_REG_LBA0, (UInt8)lba); - out8(IO + ATA_REG_LBA1, (UInt8)(lba >> 8)); - out8(IO + ATA_REG_LBA2, (UInt8)(lba >> 16)); - - out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - - IDEPoll(IO); - - UInt16 data = in16(IO + ATA_REG_DATA); - - while ((in8(ATA_COMMAND(IO))) & 0x88) - ATAWait(IO); - - return data; -} - -Void ATAWriteLba(UInt16 Byte, UInt32 lba, UInt8 bus, Boolean master) -{ - UInt16 IO = bus; - IDESelect(IO, master ? ATA_MASTER : ATA_SLAVE); - - out8(IO + ATA_REG_LBA5, (UInt8)(lba >> 24) & 0xF); - - out8(IO + ATA_REG_SEC_COUNT0, lba / 512); - - out8(IO + ATA_REG_LBA0, (UInt8)lba); - out8(IO + ATA_REG_LBA1, (UInt8)(lba >> 8)); - out8(IO + ATA_REG_LBA2, (UInt8)(lba >> 16)); - - out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); // TODO: support DMA - - IDEPoll(IO); - - out32(IO + ATA_REG_DATA, Byte); - - while ((in8(ATA_COMMAND(IO))) & 0x88) - ATAWait(IO); -} - -Boolean ATAIsDetected(Void) { return kATADetected; } - -extern "C" void _start(void) -{ - ATAInitDriver(ATA_PRIMARY, true); - ATAInitDriver(ATA_PRIMARY, false); - - ATAInitDriver(ATA_SECONDARY, true); - ATAInitDriver(ATA_SECONDARY, false); -} - -extern "C" void out8(UInt16 port, UInt8 value) -{ - asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -extern "C" void out16(UInt16 port, UInt16 value) -{ - asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -extern "C" void out32(UInt16 port, UInt32 value) -{ - asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory"); -} - -extern "C" UInt8 in8(UInt16 port) -{ - UInt8 value = 0UL; - asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - -extern "C" UInt16 in16(UInt16 port) -{ - UInt16 value = 0UL; - asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - -extern "C" UInt32 in32(UInt16 port) -{ - UInt32 value = 0UL; - asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory"); - - return value; -} - -extern "C" int init_ata_mpt(void) -{ - for (int i = 0; i < 255; ++i) - { - if (ATAInitDriver(i, ATA_MASTER)) - { - ATAInitDriver(i, ATA_SLAVE); - return 1; - } - } - - return 0; -}
\ No newline at end of file diff --git a/Private/NewBoot/Source/HEL/AMD64/ATA.hxx b/Private/NewBoot/Source/HEL/AMD64/ATA.hxx deleted file mode 100644 index 09cc4007..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/ATA.hxx +++ /dev/null @@ -1,106 +0,0 @@ -#pragma once - -#include <NewKit/Defines.hpp> - -using namespace hCore; - -// Status register -#define ATA_SR_BSY 0x80 -#define ATA_SR_DRDY 0x40 -#define ATA_SR_DF 0x20 -#define ATA_SR_DSC 0x10 -#define ATA_SR_DRQ 0x08 -#define ATA_SR_CORR 0x04 -#define ATA_SR_IDX 0x02 -#define ATA_SR_ERR 0x01 - -// Error register -#define ATA_ER_BBK 0x80 -#define ATA_ER_UNC 0x40 -#define ATA_ER_MC 0x20 -#define ATA_ER_IDNF 0x10 -#define ATA_ER_MCR 0x08 -#define ATA_ER_ABRT 0x04 -#define ATA_ER_TK0NF 0x02 -#define ATA_ER_AMNF 0x01 - -#define ATA_CMD_READ_PIO 0x20 -#define ATA_CMD_READ_PIO_EXT 0x24 -#define ATA_CMD_READ_DMA 0xC8 -#define ATA_CMD_READ_DMA_EXT 0x25 -#define ATA_CMD_WRITE_PIO 0x30 -#define ATA_CMD_WRITE_PIO_EXT 0x34 -#define ATA_CMD_WRITE_DMA 0xCA -#define ATA_CMD_WRITE_DMA_EXT 0x35 -#define ATA_CMD_CACHE_FLUSH 0xE7 -#define ATA_CMD_CACHE_FLUSH_EXT 0xEA -#define ATA_CMD_PACKET 0xA0 -#define ATA_CMD_IDENTIFY_PACKET 0xA1 -#define ATA_CMD_IDENTIFY 0xEC - -#define ATA_IDENT_DEVICE_TYPE 0 -#define ATA_IDENT_CYLINDERS 2 -#define ATA_IDENT_HEADS 6 -#define ATA_IDENT_SECTORS 12 -#define ATA_IDENT_SERIAL 20 -#define ATA_IDENT_MODEL 54 -#define ATA_IDENT_CAPABILITIES 98 -#define ATA_IDENT_FIELDVALID 106 -#define ATA_IDENT_MAX_LBA 120 -#define ATA_IDENT_COMMANDSETS 164 -#define ATA_IDENT_MAX_LBA_EXT 200 - - -#define ATA_MASTER 0x00 -#define ATA_SLAVE 0x01 - -// Register -#define ATA_REG_DATA 0x00 -#define ATA_REG_ERROR 0x01 -#define ATA_REG_FEATURES 0x01 -#define ATA_REG_SEC_COUNT0 0x02 -#define ATA_REG_LBA0 0x03 -#define ATA_REG_LBA1 0x04 -#define ATA_REG_LBA2 0x05 -#define ATA_REG_HDDEVSEL 0x06 -#define ATA_REG_COMMAND 0x07 -#define ATA_REG_STATUS 0x07 -#define ATA_REG_SEC_COUNT1 0x08 -#define ATA_REG_LBA3 0x09 -#define ATA_REG_LBA4 0x0A -#define ATA_REG_LBA5 0x0B -#define ATA_REG_CONTROL 0x0C -#define ATA_REG_ALT_STATUS 0x0C -#define ATA_REG_DEV_ADDRESS 0x0D - -#define ATA_PRIMARY_IO 0x1F0 -#define ATA_SECONDARY_IO 0x170 -#define ATA_PRIMARY_DCR_AS 0x3F6 -#define ATA_SECONDARY_DCR_AS 0x376 - -// Irq -#define ATA_PRIMARY_IRQ 14 -#define ATA_SECONDARY_IRQ 15 - -// Channels -#define ATA_PRIMARY 0x00 -#define ATA_SECONDARY 0x01 - -// IO Direction -#define ATA_READ 0x00 -#define ATA_WRITE 0x013 - -#define ATA_PRIMARY_SEL 0xA0 -#define ATA_SECONDARY_SEL 0xB0 - -// ATA Helpers -#define ATA_ADDRESS1(x) (x + 3) -#define ATA_ADDRESS2(x) (x + 4) -#define ATA_ADDRESS3(x) (x + 5) -#define ATA_COMMAND(x) (x + 7) - -Boolean ATAInitDriver(UInt8 bus, UInt8 drive); -Void ATAWait(UInt16 IO); -UInt16 ATAReadLba(UInt32 lba, UInt8 bus, Boolean master); -Void ATAWriteLba(UInt16 byte, UInt32 lba, UInt8 bus, Boolean master); -Boolean ATAIsDetected(Void);
\ No newline at end of file diff --git a/Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc b/Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc index 5b007434..551cf0f6 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc +++ b/Private/NewBoot/Source/HEL/AMD64/BIOSAllocApi.inc @@ -13,7 +13,7 @@ __LoadGDT: lgdt [ebp - 8] ret -;; This memory resides in the BIOS Memory Region BMR (0x9000-0x9000 + 4096) +;; This memory resides in the BIOS Memory Region BMR (0x9000-(0x9000 + 0x1000)) ;; It contains bootloader data. __BIOSAlloc: @@ -37,4 +37,4 @@ __BIOSAllocDone: __bios_lookup_table: resb 8096 * 4 -__end_bios_lookup_table:
\ No newline at end of file +__end_bios_lookup_table: diff --git a/Private/NewBoot/Source/HEL/AMD64/makefile b/Private/NewBoot/Source/HEL/AMD64/makefile deleted file mode 100644 index 576bb12b..00000000 --- a/Private/NewBoot/Source/HEL/AMD64/makefile +++ /dev/null @@ -1,37 +0,0 @@ -ASM = nasm - -# The kernel entrypoint -ENTRY = NBRuntimeZero - -# Where the text segment is. -TEXT = 0x7c00 - -# we want a flat binary -FMT = binary - -ASMFLAGS = -f elf64 - -KERNEL = hBoot.bin -ATAMOD = ATA.bin - -LD = x86_64-elf-ld -CC = x86_64-elf-gcc -CCFLAGS = -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__hCore__ -I./ -I../../../ -I$(HOME)/hCore/ - -.PHONY: build-crt0-bios -build-crt0-bios: - $(CC) $(CCFLAGS) BIOSRuntime.cxx - $(CC) $(CCFLAGS) ATA.cxx - $(CC) $(CCFLAGS) Processor.cxx - $(ASM) $(ASMFLAGS) BIOSRuntime0.asm - - $(LD) --oformat $(FMT) ATA.o -o $(ATAMOD) - $(LD) -e $(ENTRY) -Ttext $(TEXT) --oformat $(FMT) BIOSRuntime.o BIOSRuntime0.o -o $(KERNEL) - -.PHONY: all -all: build-crt0-bios - @echo "Done (CRT-0)" - -.PHONY: clean -clean: - rm -f $(wildcard *.o) $(wildcard *.bin)
\ No newline at end of file diff --git a/Private/NewBoot/Source/MPT/.hgkeep b/Private/NewBoot/Source/MPT/.hgkeep deleted file mode 100644 index e69de29b..00000000 --- a/Private/NewBoot/Source/MPT/.hgkeep +++ /dev/null diff --git a/Private/NewBoot/Source/MPT/API.hxx b/Private/NewBoot/Source/MPT/API.hxx deleted file mode 100644 index 5958f1c3..00000000 --- a/Private/NewBoot/Source/MPT/API.hxx +++ /dev/null @@ -1,17 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#pragma once - -#ifdef __MPT_NEED_ATA_SUPPORT -extern "C" int init_ata_mpt(void); -#endif // __MPT_NEED_ATA_SUPPORT - -#include "Detail.hxx" -#include "MPT.hxx" diff --git a/Private/NewBoot/Source/MPT/Detail.hxx b/Private/NewBoot/Source/MPT/Detail.hxx deleted file mode 100644 index 420387d1..00000000 --- a/Private/NewBoot/Source/MPT/Detail.hxx +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#pragma once - -namespace detail -{ -inline void hang(); -inline void panic(const char *msg, const char *expr) -{ -} - -inline void assert_expr(bool expr, const char *str_expr) -{ - if (!expr) - { - detail::panic("assertion failed!", str_expr); - detail::hang(); - } -} - -inline void hang() -{ - while (1) - { - } -} - -enum -{ - okay = 1, - failed = 0, -}; -} // namespace detail - -#ifdef assert -#undef assert -#define assert(expr) detail::assert_expr(expr, #expr) -#endif // ifdef assert diff --git a/Private/NewBoot/Source/MPT/MPT.hxx b/Private/NewBoot/Source/MPT/MPT.hxx deleted file mode 100644 index 9ac79cd1..00000000 --- a/Private/NewBoot/Source/MPT/MPT.hxx +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ======================================================== - * - * NewBoot - * Copyright 2024 Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#pragma once - -/// @brief 255 size partition header. -/// we use that to gather information about this hard drive. - -struct MasterPartitionTable final -{ - char fPartName[32]; - int fPartType; - int fPartSectorSz; - int fPartSectorCnt; - char fReserved[211]; -}; - -enum -{ - kPartEfi = 0x10, - kPartEpm = 0x11, - kPartEbr = 0x12, -}; - diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 75993507..25eb7983 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -1,16 +1,16 @@ # (C) Mahrouss Logic, 2024, all rights reserved. -CC_GNU=x86_64-elf-g++ -LD_GNU=x86_64-elf-ld -OBJCOPY_GNU=x86_64-elf-objcopy +CC_GNU=x86_64-w64-mingw32-g++ +LD_GNU=x86_64-w64-mingw32-ld + FLAG_GNU=-I../ -I../../ -I../../efiSDK/inc -I./ -c -fPIC -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__hCore__ -I./ -I$(HOME)/ .PHONY: arch-amd64 arch-amd64: $(CC_GNU) $(FLAG_GNU) -D__DBG__ HEL/AMD64/*.cxx - $(LD_GNU) *.o -e Main -shared -o HCORELDR.ELF - $(OBJCOPY_GNU) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target efi-app-x86_64 --subsystem=10 HCORELDR.ELF HCORELDR.EFI + $(LD_GNU) *.o --script=../../efiSDK/gnuefi/coff_x86_64_efi.lds ../../efiSDK/x86_64/gnuefi/crt0-efi-x86_64.o \ + --subsystem=10 ../../efiSDK/x86_64/gnuefi/reloc_x86_64.o -L../../efiSDK/x86_64/gnuefi/ -lgnuefi -o HCORELDR.EXE .PHONY: clean clean: - rm -f *.o + rm -f *.o *.EFI *.EXE |
