Boilerplate + Protected mode
Added make debug to Makefile Added the gdb script from the kernel for easy debugging now makes it to protected mode and shows a green box when done Added a gdt (of course)
This commit is contained in:
parent
8af79bc140
commit
7266661097
5 changed files with 93 additions and 17 deletions
9
Makefile
9
Makefile
|
|
@ -1,7 +1,7 @@
|
||||||
# Makefile
|
# Makefile
|
||||||
SRC_DIR = src
|
SRC_DIR = src
|
||||||
BUILD_DIR = build
|
BUILD_DIR = build
|
||||||
BOOTLOADER_SRC = $(SRC_DIR)/boot.asm
|
BOOTLOADER_SRC = $(SRC_DIR)/boot.s
|
||||||
BOOTLOADER_IMG = $(BUILD_DIR)/boot.img
|
BOOTLOADER_IMG = $(BUILD_DIR)/boot.img
|
||||||
|
|
||||||
QEMU = qemu-system-i386
|
QEMU = qemu-system-i386
|
||||||
|
|
@ -12,8 +12,13 @@ $(BUILD_DIR):
|
||||||
mkdir -p $(BUILD_DIR)
|
mkdir -p $(BUILD_DIR)
|
||||||
|
|
||||||
$(BOOTLOADER_IMG): $(BOOTLOADER_SRC) | $(BUILD_DIR)
|
$(BOOTLOADER_IMG): $(BOOTLOADER_SRC) | $(BUILD_DIR)
|
||||||
nasm -f bin $(BOOTLOADER_SRC) -o $(BOOTLOADER_IMG)
|
nasm -f bin $(BOOTLOADER_SRC) -i $(SRC_DIR) -o $(BOOTLOADER_IMG)
|
||||||
|
|
||||||
|
.PHONY: debug
|
||||||
|
debug:
|
||||||
|
$(QEMU) $(QEMU_FLAGS) -s -S -drive format=raw,file=$(BOOTLOADER_IMG)
|
||||||
|
|
||||||
|
.PHONY: run
|
||||||
run: all
|
run: all
|
||||||
$(QEMU) -drive format=raw,file=$(BOOTLOADER_IMG) -display gtk
|
$(QEMU) -drive format=raw,file=$(BOOTLOADER_IMG) -display gtk
|
||||||
|
|
||||||
|
|
|
||||||
5
connect_gdb.sh
Executable file
5
connect_gdb.sh
Executable file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
i686-elf-gdb build/ukern.elf \
|
||||||
|
-ex "target remote localhost:1234" \
|
||||||
|
-ex "break start" \
|
||||||
15
src/boot.asm
15
src/boot.asm
|
|
@ -1,15 +0,0 @@
|
||||||
; boot.asm - simple boot sector
|
|
||||||
BITS 16
|
|
||||||
ORG 0x7C00
|
|
||||||
|
|
||||||
start:
|
|
||||||
mov ah, 0x0E
|
|
||||||
mov al, 'H'
|
|
||||||
int 0x10
|
|
||||||
mov al, 'i'
|
|
||||||
int 0x10
|
|
||||||
|
|
||||||
jmp $
|
|
||||||
|
|
||||||
times 510 - ($ - $$) db 0
|
|
||||||
dw 0xAA55
|
|
||||||
55
src/boot.s
Normal file
55
src/boot.s
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
; boot.asm - simple boot sector
|
||||||
|
[ORG 0x7C00]
|
||||||
|
[BITS 16]
|
||||||
|
jmp start
|
||||||
|
|
||||||
|
%include "gdt.s"
|
||||||
|
|
||||||
|
;Opting against using ORG 0x7C00 as I want to access memory literally for clarity.
|
||||||
|
;Remember to set a segment to 0x07C0 :)
|
||||||
|
;ORG 0x7C00
|
||||||
|
|
||||||
|
|
||||||
|
start:
|
||||||
|
;Hello world! Let's get protected mode moving so we don't have to work in real mode the whole time.
|
||||||
|
cli
|
||||||
|
;gimme dat
|
||||||
|
lgdt [gdtr]
|
||||||
|
;Enable protected mode bit
|
||||||
|
mov eax, cr0
|
||||||
|
or eax, 1
|
||||||
|
mov cr0, eax
|
||||||
|
|
||||||
|
;32 bits!
|
||||||
|
jmp 0x08:prot_mode
|
||||||
|
|
||||||
|
|
||||||
|
[BITS 32]
|
||||||
|
prot_mode:
|
||||||
|
;Hello 32 bit!
|
||||||
|
;Some real setup now...
|
||||||
|
;Set the segments
|
||||||
|
mov ax, 0x10
|
||||||
|
mov ds, ax
|
||||||
|
mov es, ax
|
||||||
|
mov fs, ax
|
||||||
|
mov gs, ax
|
||||||
|
mov ss, ax
|
||||||
|
|
||||||
|
;Clear the screen
|
||||||
|
mov ax, 0x0720
|
||||||
|
mov edi, 0xB8000
|
||||||
|
mov ecx, 80*25
|
||||||
|
rep stosw
|
||||||
|
|
||||||
|
|
||||||
|
done:
|
||||||
|
mov cx, 0x2220
|
||||||
|
mov [0xB8000], cx
|
||||||
|
|
||||||
|
jmp $
|
||||||
|
|
||||||
|
;Bootloader should be 512 bytes. So we are defining a padding of zeroes that would round out the size. 510 to account for the 0xAA55 after.
|
||||||
|
times 510 - ($ - $$) db 0
|
||||||
|
;Old BIOS expect the sector to end in 0xAA55. We are, in fact, targeting old hardware.
|
||||||
|
dw 0xAA55
|
||||||
26
src/gdt.s
Normal file
26
src/gdt.s
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
;GDT code taken straight from Untitled Kernel. The Kernel mode ranges will do just fine.
|
||||||
|
align 8
|
||||||
|
gdt:
|
||||||
|
;Null descriptor
|
||||||
|
dd 0x00000000
|
||||||
|
dd 0x00000000
|
||||||
|
;Kernel code segment.
|
||||||
|
dw 0xFFFF
|
||||||
|
dw 0
|
||||||
|
db 0
|
||||||
|
db 0b10011010
|
||||||
|
db 0b11001111
|
||||||
|
db 0
|
||||||
|
;Kernel data segment.
|
||||||
|
dw 0xFFFF
|
||||||
|
dw 0x0000
|
||||||
|
db 0x00
|
||||||
|
db 0b10010010
|
||||||
|
db 0b11001111
|
||||||
|
db 0x00
|
||||||
|
gdt_end:
|
||||||
|
gdtr:
|
||||||
|
;size of the gdt
|
||||||
|
dw gdt_end - gdt - 1
|
||||||
|
;location of the gdt
|
||||||
|
dd gdt
|
||||||
Loading…
Reference in a new issue