diff --git a/efi-port/.gitignore b/efi-port/.gitignore new file mode 100644 index 0000000..466e248 --- /dev/null +++ b/efi-port/.gitignore @@ -0,0 +1 @@ +out/ \ No newline at end of file diff --git a/efi-port/core/src/efi.c b/efi-port/core/src/efi.c new file mode 100644 index 0000000..5d1ce07 --- /dev/null +++ b/efi-port/core/src/efi.c @@ -0,0 +1,6 @@ +#include "efi.h" +#include "main.h" + +int efi_main(void *imageHandle, EfiSystemTable* systemTable) { + return kernel_main(systemTable); +} \ No newline at end of file diff --git a/efi-port/core/src/efi.h b/efi-port/core/src/efi.h new file mode 100644 index 0000000..ad61ddc --- /dev/null +++ b/efi-port/core/src/efi.h @@ -0,0 +1,49 @@ +#ifndef EFI_H +#define EFI_H + +#include + +typedef struct EfiTableHeader { + uint64_t signature; + uint32_t revision; + uint32_t headerSize; + uint32_t crc32; + uint32_t reserved; +} EfiTableHeader; + +struct EfiSimpleTextOutputProtocol; +typedef uint64_t (__attribute__((ms_abi)) *EfiTextReset)(struct EfiSimpleTextOutputProtocol* this, uint8_t ExtendedVerification); +typedef uint64_t (__attribute__((ms_abi)) *EfiTextString)(struct EfiSimpleTextOutputProtocol* this, uint16_t* string); +typedef uint64_t (__attribute__((ms_abi)) *EfiTextSetAttribute)(struct EfiSimpleTextOutputProtocol* this, uint64_t Attribute); +typedef uint64_t (__attribute__((ms_abi)) *EfiTextClearScreen)(struct EfiSimpleTextOutputProtocol* this); + +typedef struct EfiSimpleTextOutputProtocol { + EfiTextReset reset; + EfiTextString output_string; + uint64_t test_string; + uint64_t query_mode; + uint64_t set_mode; + EfiTextSetAttribute set_attribute; + EfiTextClearScreen clear_screen; + uint64_t set_cursor_position; + uint64_t enable_cursor; + uint64_t mode; +} EfiSimpleTextOutputProtocol; + +typedef struct EfiSystemTable { + EfiTableHeader hdr; + uint16_t* firmwareVendor; + uint32_t firmwareRevision; + void* consoleInHandle; + uint64_t conIn; + void* consoleOutHandle; + EfiSimpleTextOutputProtocol* conOut; + void* standardErrorHandle; + uint64_t stdErr; + uint64_t runtimeServices; + uint64_t bootServices; + uint64_t numberOfTableEntries; + uint64_t configurationTable; +} EfiSystemTable; + +#endif diff --git a/efi-port/core/src/main.c b/efi-port/core/src/main.c new file mode 100644 index 0000000..f982359 --- /dev/null +++ b/efi-port/core/src/main.c @@ -0,0 +1,15 @@ +#include "main.h" +#include "efi.h" + +void halt() { + for (;;) {} +} + +int kernel_main(EfiSystemTable* systemTable) { + systemTable->conOut->clear_screen(systemTable->conOut); + systemTable->conOut->output_string(systemTable->conOut, L"Hello, World!\n"); + + halt(); + + return 0; +} diff --git a/efi-port/core/src/main.h b/efi-port/core/src/main.h new file mode 100644 index 0000000..efdd121 --- /dev/null +++ b/efi-port/core/src/main.h @@ -0,0 +1,8 @@ +#include "efi.h" + +#ifndef MAIN_H +#define MAIN_H + +int kernel_main(EfiSystemTable* systemTable); + +#endif \ No newline at end of file diff --git a/efi-port/scripts/build_c.sh b/efi-port/scripts/build_c.sh new file mode 100755 index 0000000..dcc1c86 --- /dev/null +++ b/efi-port/scripts/build_c.sh @@ -0,0 +1,9 @@ +mkdir -p out +mkdir -p out/core +mkdir -p out/img/EFI/BOOT + + +clang -target x86_64-pc-win32-coff -fno-stack-protector -fshort-wchar -mno-red-zone -c core/src/efi.c -o out/core/efi.o +clang -target x86_64-pc-win32-coff -fno-stack-protector -fshort-wchar -mno-red-zone -c core/src/main.c -o out/core/main.o + +lld-link -filealign:16 -subsystem:efi_application -nodefaultlib -dll -entry:efi_main out/core/main.o out/core/efi.o -out:out/img/EFI/BOOT/BOOTX64.EFI diff --git a/efi-port/scripts/out_to_iso.sh b/efi-port/scripts/out_to_iso.sh new file mode 100755 index 0000000..3bfedfa --- /dev/null +++ b/efi-port/scripts/out_to_iso.sh @@ -0,0 +1,19 @@ +# Create a FAT12 image +dd if=/dev/zero of=out/fat.img bs=1k count=1440 +mformat -i out/fat.img -f 1440 :: + +# Create EFI directory structure +mmd -i out/fat.img ::/EFI +mmd -i out/fat.img ::/EFI/BOOT + +# Copy the EFI application +mcopy -i out/fat.img out/img/EFI/BOOT/BOOTX64.EFI ::/EFI/BOOT + +# Verify content +echo "Verifying FAT image content:" +mdir -i out/fat.img -/ :: + +# Create the ISO +# -e specifies the boot image (the FAT image) +# -no-emul-boot is required for UEFI +xorriso -as mkisofs -R -f -e /fat.img -no-emul-boot -o out/lints.iso out/img out/fat.img \ No newline at end of file diff --git a/efi-port/scripts/run_vbox.sh b/efi-port/scripts/run_vbox.sh new file mode 100755 index 0000000..771ead7 --- /dev/null +++ b/efi-port/scripts/run_vbox.sh @@ -0,0 +1,22 @@ +#!/bin/bash +VM_NAME="LintsEFI" +ISO_PATH="$(pwd)/out/lints.iso" + +# Check if VM exists +if VBoxManage list vms | grep -q "\"$VM_NAME\""; then + echo "VM '$VM_NAME' already exists." +else + echo "Creating VM '$VM_NAME'..." + VBoxManage createvm --name "$VM_NAME" --ostype "Other_64" --register + VBoxManage modifyvm "$VM_NAME" --memory 128 --firmware efi --graphicscontroller vmsvga + VBoxManage storagectl "$VM_NAME" --name "IDE Controller" --add ide +fi + +# Attach ISO (force unmount first just in case) +echo "Attaching ISO..." +VBoxManage storageattach "$VM_NAME" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium emptydrive --forceunmount +VBoxManage storageattach "$VM_NAME" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium "$ISO_PATH" + +# Start VM +echo "Starting VM..." +VBoxManage startvm "$VM_NAME"