[feat] Simple graphic
This commit is contained in:
@@ -1,19 +1,38 @@
|
|||||||
all:
|
CFLAGS = -Iinclude -Ignu-efi/inc -ffreestanding -fno-stack-protector -fno-stack-check -fshort-wchar -mno-red-zone -std=c11
|
||||||
mkdir -p build
|
CXXFLAGS = -Iinclude -Ignu-efi/inc -ffreestanding -fno-stack-protector -fno-stack-check -fshort-wchar -mno-red-zone -maccumulate-outgoing-args -std=c++17
|
||||||
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
|
LDFLAGS = -shared -Bsymbolic -Lgnu-efi/x86_64/lib -Lgnu-efi/x86_64/gnuefi -Tgnu-efi/gnuefi/elf_x86_64_efi.lds
|
||||||
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
|
LDLIBS = -lgnuefi -lefi --no-undefined
|
||||||
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
|
SRC_C = $(wildcard *.c)
|
||||||
|
SRC_CPP = $(wildcard */*.cpp)
|
||||||
|
OBJ = $(SRC_C:%.c=build/%.o) $(SRC_CPP:%.cpp=build/%.o)
|
||||||
|
|
||||||
|
_bd:
|
||||||
|
@mkdir -p build/graphics build/kernel
|
||||||
|
|
||||||
|
all: _bd $(OBJ)
|
||||||
|
@echo "* Linking EFI..."
|
||||||
|
@ld $(LDFLAGS) gnu-efi/x86_64/gnuefi/crt0-efi-x86_64.o build/boot.o build/graphics/draw.o build/kernel/main.o -o build/boot.so $(LDLIBS)
|
||||||
|
@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
|
||||||
|
|
||||||
|
build/%.o: %.c
|
||||||
|
@echo "Compile C File $< to $@"
|
||||||
|
@gcc $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
build/%.o: %.cpp
|
||||||
|
@echo "Compile CPP File $< to $@"
|
||||||
|
@g++ $(CXXFLAGS) -c $< -o $@
|
||||||
|
|
||||||
vdir: all
|
vdir: all
|
||||||
mkdir -p vdir
|
@mkdir -p vdir/EFI/BOOT
|
||||||
mkdir -p vdir/EFI/BOOT
|
@cp build/BOOTX64.EFI vdir/EFI/BOOT
|
||||||
cp build/BOOTX64.EFI vdir/EFI/BOOT
|
|
||||||
|
|
||||||
run: vdir
|
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 -serial stdio -s -S
|
@echo "Launching QEMU"
|
||||||
|
@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 -monitor stdio -s -S
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build vdir
|
@echo "Cleaning old files"
|
||||||
|
@rm -rf build vdir
|
||||||
|
|
||||||
.PHONY: all vdir run clean
|
.PHONY: all vdir run clean _bd
|
||||||
@@ -3,16 +3,18 @@
|
|||||||
|
|
||||||
extern void kernel_main();
|
extern void kernel_main();
|
||||||
|
|
||||||
EFI_STATUS EFIAPI efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *ST) {
|
EFI_STATUS EFIAPI efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
|
||||||
InitializeLib(ImageHandle, ST);
|
InitializeLib(ImageHandle, SystemTable);
|
||||||
|
|
||||||
uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
|
uefi_call_wrapper(SystemTable->ConOut->ClearScreen, 1, SystemTable->ConOut);
|
||||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, 1);
|
uefi_call_wrapper(SystemTable->ConOut->SetCursorPosition, 3, SystemTable->ConOut, 0, 1);
|
||||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, L"Welcome to SYLVA OS!\n");
|
uefi_call_wrapper(SystemTable->ConOut->OutputString, 2, SystemTable->ConOut, L"Welcome to SYLVA OS!\n");
|
||||||
uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, 2);
|
uefi_call_wrapper(SystemTable->ConOut->SetCursorPosition, 3, SystemTable->ConOut, 0, 2);
|
||||||
uefi_call_wrapper(ST->ConOut->OutputString, 2, ST->ConOut, L"* The system has booted successfully.\n");
|
uefi_call_wrapper(SystemTable->ConOut->OutputString, 2, SystemTable->ConOut, L"* The system has booted successfully.\n");
|
||||||
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");
|
|
||||||
|
uefi_call_wrapper(SystemTable->ConOut->SetCursorPosition, 3, SystemTable->ConOut, 0, 3);
|
||||||
|
uefi_call_wrapper(SystemTable->ConOut->OutputString, 2, SystemTable->ConOut, L"* Jumping to kernel...\n");
|
||||||
|
|
||||||
kernel_main();
|
kernel_main();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#include <efi.h>
|
||||||
|
|
||||||
|
void draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color,
|
||||||
|
EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP, unsigned int hr, EFI_GRAPHICS_OUTPUT_BLT_PIXEL *base) {
|
||||||
|
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *p = base + (hr * y) + x;
|
||||||
|
|
||||||
|
p->Blue = color.Blue;
|
||||||
|
p->Green = color.Green;
|
||||||
|
p->Red = color.Red;
|
||||||
|
p->Reserved = color.Reserved;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <efi.h>
|
||||||
|
|
||||||
|
void draw_pixel(unsigned int x, unsigned int y, EFI_GRAPHICS_OUTPUT_BLT_PIXEL color,
|
||||||
|
EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP, unsigned int hr, EFI_GRAPHICS_OUTPUT_BLT_PIXEL *base);
|
||||||
+18
-4
@@ -1,12 +1,26 @@
|
|||||||
#include <efi.h>
|
#include <efi.h>
|
||||||
#include <efilib.h>
|
#include <efilib.h>
|
||||||
|
#include <graphics/draw.h>
|
||||||
|
|
||||||
extern "C" void kernel_main();
|
extern "C" void kernel_main() {
|
||||||
|
EFI_GUID gop_guid = {0x9042a9de, 0x23dc, 0x4a38, {0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a}};
|
||||||
|
|
||||||
|
EFI_GRAPHICS_OUTPUT_PROTOCOL *GOP;
|
||||||
|
uefi_call_wrapper((void*)ST->BootServices->SetWatchdogTimer, 4, 0, 0, 0, NULL);
|
||||||
|
uefi_call_wrapper((void*)ST->BootServices->LocateProtocol, 3, &gop_guid, NULL, (void **)&GOP);
|
||||||
|
|
||||||
|
unsigned int hr = GOP->Mode->Info->HorizontalResolution;
|
||||||
|
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *base = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) GOP->Mode->FrameBufferBase;
|
||||||
|
|
||||||
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->SetCursorPosition, 3, ST->ConOut, 0, 5);
|
||||||
uefi_call_wrapper((void*)ST->ConOut->OutputString, 2, ST->ConOut, L"Kernel is running!\n");
|
uefi_call_wrapper((void*)ST->ConOut->OutputString, 2, ST->ConOut, L"Kernel is running!\n");
|
||||||
|
|
||||||
|
for (unsigned int i = 1; i <= 100; i++) {
|
||||||
|
// uefi_call_wrapper((void*)ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, i + 6);
|
||||||
|
// uefi_call_wrapper((void*)ST->ConOut->OutputString, 2, ST->ConOut, L"hello!");
|
||||||
|
for (unsigned int j = 1; j <= 100; j++) {
|
||||||
|
draw_pixel(i, j, {255, 255, 255, 255}, GOP, hr, base);
|
||||||
|
}
|
||||||
|
}
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user