Skip to content

Commit

Permalink
Add Global Descriptor Table
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinperera00 committed Oct 1, 2023
1 parent 669afc4 commit c1b4368
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FILES = ./build/kernel.asm.o

all: ./bin/boot.bin $(FILES)
dd -f=./bin/boot.bin >> ./bin/os.bin

./bin/boot.bin: ./src/boot/boot.asm
nasm -f bin ./src/boot/boot.asm -o ./bin/boot.bin
./build/kernel.asm.o: ./src/kernel.asm
nasm -f elf -g ./src/kernel.asm -o ./build/kernel.asm.o
clean:
rm -rf ./bin/boot.bin
Binary file added bin/boot.bin
Binary file not shown.
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#/bin/bash
export PREFIX="$HOME/opt/cross"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"
make all
62 changes: 62 additions & 0 deletions src/boot/boot.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
ORG 0x7c00
BITS 16

CODE_SEG equ gdt_code - gdt_start
DATA_SEG equ gdt_data - gdt_start

_start:
jmp short start
nop
times 33 db 0

start:
jmp 0:step2

step2:
cli ; disable interrupts
mov ax, 0x00
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x7c00
sti ; enable interrupts

load_protected:
cli
lgdt[gdt_descriptor]
mov eax, cr0
or eax, 1
mov cr0, eax
;jmp CODE_SEG:load32
jmp $


;GDT
gdt_start:
gdt_null:
dd 0x0
dd 0x0

gdt_code:
dw 0xffff
dw 0
db 0
db 0x9a
db 11001111b
db 0

gdt_data:
dw 0xffff
dw 0
db 0
db 0x92
db 11001111b
db 0
gdt_end:

gdt_descriptor:
dw gdt_end - gdt_start - 1
dd gdt_start

times 510-($-$$) db 0
dw 0xAA55
17 changes: 17 additions & 0 deletions src/kernel.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
BITS 32

load32:
mov ax, DATA_SEG
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov ebp, 0x00200000
mov esp, ebp

in al, 0x92
or al, 2
out 0x92, al

jmp $
26 changes: 26 additions & 0 deletions src/linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ENTRY(_start)
OUTPUT_FORMAT(binary)
SECTIONS
{
. = 1M;
.text :
{
*(.text)
}

.rodata :
{
*(.rodata)
}

.data :
{
*(.data)
}

.bss :
{
*(COMMON)
*(.bss)
}
}

0 comments on commit c1b4368

Please sign in to comment.