Start EFI port
This commit is contained in:
1
efi-port/.gitignore
vendored
Normal file
1
efi-port/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
out/
|
||||
6
efi-port/core/src/efi.c
Normal file
6
efi-port/core/src/efi.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "efi.h"
|
||||
#include "main.h"
|
||||
|
||||
int efi_main(void *imageHandle, EfiSystemTable* systemTable) {
|
||||
return kernel_main(systemTable);
|
||||
}
|
||||
49
efi-port/core/src/efi.h
Normal file
49
efi-port/core/src/efi.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef EFI_H
|
||||
#define EFI_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
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
|
||||
15
efi-port/core/src/main.c
Normal file
15
efi-port/core/src/main.c
Normal file
@@ -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;
|
||||
}
|
||||
8
efi-port/core/src/main.h
Normal file
8
efi-port/core/src/main.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "efi.h"
|
||||
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
int kernel_main(EfiSystemTable* systemTable);
|
||||
|
||||
#endif
|
||||
9
efi-port/scripts/build_c.sh
Executable file
9
efi-port/scripts/build_c.sh
Executable file
@@ -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
|
||||
19
efi-port/scripts/out_to_iso.sh
Executable file
19
efi-port/scripts/out_to_iso.sh
Executable file
@@ -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
|
||||
22
efi-port/scripts/run_vbox.sh
Executable file
22
efi-port/scripts/run_vbox.sh
Executable file
@@ -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"
|
||||
Reference in New Issue
Block a user