[feat] Kernel jump
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
all:
|
||||
all:
|
||||
mkdir -p build
|
||||
gcc -Ignu-efi/inc -fpic -ffreestanding -fno-stack-protector -fno-stack-check -fshort-wchar -mno-red-zone -maccumulate-outgoing-args -c boot.c -o build/boot.o
|
||||
ld -shared -Bsymbolic -Lgnu-efi/x86_64/lib -Lgnu-efi/x86_64/gnuefi -Tgnu-efi/gnuefi/elf_x86_64_efi.lds gnu-efi/x86_64/gnuefi/crt0-efi-x86_64.o build/boot.o -o build/boot.so -lgnuefi -lefi
|
||||
gcc -Ignu-efi/inc -ffreestanding -fno-stack-protector -fno-stack-check -fshort-wchar -mno-red-zone -maccumulate-outgoing-args -std=c17 -c boot.c -o build/boot.o
|
||||
g++ -Iinclude -Ignu-efi/inc -ffreestanding -fno-stack-protector -fno-stack-check -fshort-wchar -mno-red-zone -maccumulate-outgoing-args -std=c++17 -c kernel/main.cpp -o build/kernel.o
|
||||
ld -shared -Bsymbolic -Lgnu-efi/x86_64/lib -Lgnu-efi/x86_64/gnuefi -Tgnu-efi/gnuefi/elf_x86_64_efi.lds gnu-efi/x86_64/gnuefi/crt0-efi-x86_64.o build/boot.o build/kernel.o -o build/boot.so -lgnuefi -lefi --no-undefined
|
||||
objcopy -j .text -j .sdata -j .data -j .rodata -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --output-target efi-app-x86_64 --subsystem=10 build/boot.so build/BOOTX64.EFI
|
||||
|
||||
vdir: all
|
||||
@@ -10,7 +11,7 @@ vdir: all
|
||||
cp build/BOOTX64.EFI vdir/EFI/BOOT
|
||||
|
||||
run: vdir
|
||||
qemu-system-x86_64 -bios /usr/share/ovmf/OVMF.fd -net none -drive file=fat:rw:vdir,index=0,format=vvfat -serial file:serial.log
|
||||
qemu-system-x86_64 -bios /usr/share/ovmf/OVMF.fd -net none -drive file=fat:rw:vdir,index=0,format=vvfat -serial file:serial.log -serial stdio -s -S
|
||||
|
||||
clean:
|
||||
rm -rf build vdir
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
extern void kernel_main();
|
||||
|
||||
EFI_STATUS EFIAPI efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *ST) {
|
||||
InitializeLib(ImageHandle, ST);
|
||||
|
||||
// 不能直接ST->ConOut之类的,会GP,不知道为什么
|
||||
// uefi_call_wrapper可以解决,而且比较安全(不过就是宏)
|
||||
// 看着挺长,反正就在boot这里用到UEFI Out,后面不用,也就算了
|
||||
uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, 1);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, L"Welcome to SYLVA OS!\n");
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, 2);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, L"* The system has booted successfully.\n");
|
||||
while (1); // 否则会直接跳到QEMU Setup
|
||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, 3);
|
||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, L"* Jumping to kernel...\n");
|
||||
|
||||
kernel_main();
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
extern "C" void kernel_main();
|
||||
|
||||
void kernel_main() {
|
||||
// uefi_call_wrapper((void*)ST->ConOut->ClearScreen, 1, ST->ConOut);
|
||||
uefi_call_wrapper((void*)ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, 5);
|
||||
uefi_call_wrapper((void*)ST->ConOut->OutputString, 2, ST->ConOut, L"Kernel is running!\n");
|
||||
|
||||
while (1);
|
||||
}
|
||||
Reference in New Issue
Block a user