Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

OSNAME = CustomOS
OSNAME = zugiOS

GNUEFI = ../gnu-efi
OVMFDIR = ../OVMFbin
LDS =
CC = x86_64-w64-mingw32-gcc
LDS = kernel.ld
CC = gcc
LD = ld

CFLAGS = -ffreestanding -fshort-wchar
LDFLAGS = -T $(LDS) -shared -Bsymbolic -nostdlib
LDFLAGS = -T $(LDS) -static -no-pie -Bsymbolic -nostdlib

SRCDIR := src
OBJDIR := lib
Expand All @@ -20,6 +21,17 @@ SRC = $(call rwildcard,$(SRCDIR),*.c)
OBJS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRC))
DIRS = $(wildcard $(SRCDIR)/*)

kernel: $(OBJS) link

$(OBJDIR)/%.o: $(SRCDIR)/%.c
@ echo !==== COMPILING $^
@ mkdir -p $(@D)
$(CC) $(CFLAGS) -c $^ -o $@

link:
@ echo !==== LINKING
$(LD) $(LDFLAGS) -o $(BUILDDIR)/kernel.elf $(OBJS)

setup:
@mkdir $(BUILDDIR)
@mkdir $(SRCDIR)
Expand All @@ -32,6 +44,8 @@ buildimg:
mmd -i $(BUILDDIR)/$(OSNAME).img ::/EFI/BOOT
mcopy -i $(BUILDDIR)/$(OSNAME).img $(BOOTEFI) ::/EFI/BOOT
mcopy -i $(BUILDDIR)/$(OSNAME).img startup.nsh ::
mcopy -i $(BUILDDIR)/$(OSNAME).img $(BUILDDIR)/kernel.elf ::
mcopy -i $(BUILDDIR)/$(OSNAME).img $(BUILDDIR)/zap-vga16.psf ::

run:
qemu-system-x86_64 -drive file=$(BUILDDIR)/$(OSNAME).img -m 256M -cpu qemu64 -drive if=pflash,format=raw,unit=0,file="$(OVMFDIR)/OVMF_CODE-pure-efi.fd",readonly=on -drive if=pflash,format=raw,unit=1,file="$(OVMFDIR)/OVMF_VARS-pure-efi.fd" -net none
Binary file added bin/kernel.elf
Binary file not shown.
Binary file added bin/zap-vga16.psf
Binary file not shown.
Empty file.
Binary file added bin/zugiOS.img
Binary file not shown.
23 changes: 23 additions & 0 deletions kernel.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
OUTPUT_FORMAT(elf64-x86-64)
ENTRY(_start)

SECTIONS
{
.text : ALIGN(0x100)
{
*(.text)
}
.data : ALIGN(0x100)
{
*(.data)
}
.rodata : ALIGN(0x100)
{
*(.rodata)
}
.bss : ALIGN(0x100)
{
*(COMMON)
*(.bss)
}
}
Binary file added lib/kernel.o
Binary file not shown.
2 changes: 1 addition & 1 deletion run.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set OSNAME=CustomOS
set OSNAME=zugiOS
set BUILDDIR=%0/../bin
set OVMFDIR=%0/../../OVMFbin

Expand Down
21 changes: 21 additions & 0 deletions src/kernel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#include <stddef.h>
#include <stdint.h>

typedef struct {
void* BaseAddress;
size_t BufferSize;
unsigned int Width;
unsigned int Height;
unsigned int PixelsPerScanLine;
} Framebuffer;

void _start(Framebuffer* framebuffer){
unsigned int y = 50;
unsigned int B8P = 4;

for(unsigned int x = 0; x < framebuffer->Width / 2 * B8P; x+=B8P){
*(unsigned int*)(x + (y * framebuffer->PixelsPerScanLine * B8P) + framebuffer->BaseAddress) = 0xff00ffff;
}
return;
}