Code: Select all
memcpy((char *)gdtp.base, (char *)gdt, gdtp.limit+1);
Code: Select all
# Default make target
all: os.img
# Build the os image
os.img: boot.bin kernel.bin
cat boot.bin kernel.bin > os.img
# Build the kernel binary
kernel.bin: kernel_entry.o kernel.o scrn.o gdt.o
ld -nostdlib --file-alignment 0 --section-alignment 32 -o kernel.tmp -Ttext 0x1000 kernel_entry.o kernel.o scrn.o gdt.o
objcopy -O binary kernel.tmp kernel.bin
# Build the kernel object file
kernel.o: kernel.c
gcc -mno-ms-bitfields -ffreestanding -c kernel.c -o kernel.o
# Build the scrn object file
scrn.o: scrn.c
gcc -mno-ms-bitfields -ffreestanding -c scrn.c -o scrn.o
# Build the gdt object file
gdt.o: gdt.c
gcc -mno-ms-bitfields -ffreestanding -c gdt.c -o gdt.o
# Build the kernel entry object file
kernel_entry.o: kernel_entry.asm
nasm kernel_entry.asm -f win32 -o kernel_entry.o
# Build the boot binary
boot.bin: boot.asm
nasm -f bin -o boot.bin boot.asm
clean:
rm -f *.o *.tmp *.bin
Code: Select all
[bits 32]
section .text
extern _kmain
call _kmain
jmp $
global _load_gdtr
extern _gdtp
_load_gdtr:
lgdt [_gdtp]
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:next
next:
ret