refactor: move multiboot struct from kernel to loader
This commit is contained in:
parent
e71c7ce555
commit
060c2835f6
|
@ -9,7 +9,8 @@ STAGE0_SRCS = boot0.asm \
|
|||
|
||||
STAGE1_SRCS = boot1.asm \
|
||||
const.inc \
|
||||
a20.inc
|
||||
a20.inc \
|
||||
multiboot.inc
|
||||
|
||||
.PHONY: all
|
||||
all: $(TARGET)
|
||||
|
@ -27,3 +28,5 @@ clean:
|
|||
.PHONY: install
|
||||
install: $(TARGET)
|
||||
@ mkdir -p $(DESTDIR)
|
||||
install stpdboot.sys $(DESTDIR)
|
||||
|
||||
|
|
|
@ -1,2 +1,33 @@
|
|||
#+TITLE: StupidOS Bootloader
|
||||
|
||||
#+begin_src
|
||||
0x100000 +-----------------------+
|
||||
| |
|
||||
| Reserved |
|
||||
| |
|
||||
0x080000 +-----------------------+
|
||||
| |
|
||||
| Kernel preload |
|
||||
| |
|
||||
0x00F000 +-----------------------+
|
||||
| |
|
||||
| buffer |
|
||||
| |
|
||||
0x008000 +-----------------------+
|
||||
| |
|
||||
| Boot0 |
|
||||
| |
|
||||
0x007000 +-----------------------+
|
||||
| |
|
||||
| Real mode stack |
|
||||
| |
|
||||
0x006000 +-----------------------+
|
||||
| |
|
||||
| Boot1 |
|
||||
| |
|
||||
0x001000 +-----------------------+
|
||||
| |
|
||||
| Reserved (BIOS & IVT) |
|
||||
| |
|
||||
0x000000 +-----------------------+
|
||||
#+end_src
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
INCLUDE 'const.inc'
|
||||
INCLUDE 'multiboot.inc'
|
||||
|
||||
ORG STAGE1_BASE
|
||||
USE16
|
||||
|
||||
stage2:
|
||||
jmp _start
|
||||
|
||||
mb_header MultibootHeader mb_header
|
||||
|
||||
_start:
|
||||
cmp eax, MULTIBOOT_MAGIC
|
||||
je .multiboot
|
||||
|
||||
;; non multiboot process
|
||||
push cs
|
||||
pop ds
|
||||
|
||||
|
@ -13,9 +22,22 @@ stage2:
|
|||
call a20_enable
|
||||
jc .error_a20
|
||||
|
||||
; detect memory
|
||||
call memory_get_map
|
||||
jc .error_memory
|
||||
xchg bx, bx
|
||||
|
||||
call video_setup
|
||||
|
||||
.multiboot:
|
||||
jmp .hang
|
||||
|
||||
.error_memory:
|
||||
mov si, msg_error_memory
|
||||
jmp .error
|
||||
.error_a20:
|
||||
mov si, msg_error_a20
|
||||
.error:
|
||||
call bios_print
|
||||
.hang:
|
||||
hlt
|
||||
|
@ -23,6 +45,21 @@ stage2:
|
|||
|
||||
INCLUDE 'a20.inc'
|
||||
INCLUDE 'utils.inc'
|
||||
INCLUDE 'memory.inc'
|
||||
INCLUDE 'video.inc'
|
||||
|
||||
msg_stage2 db "StupidOS Bootloader (Stage 1)", 0x0D, 0x0A, 0
|
||||
msg_error_a20 db "ERROR: can't enable a20 line", 0x0D, 0x0A, 0
|
||||
msg_stage2 db "StupidOS Bootloader (Stage 1)", CR, LF, 0
|
||||
msg_error_a20 db "ERROR: can't enable a20 line", CR, LF, 0
|
||||
msg_error_memory db "ERROR: can't detect available memory", CR, LF, 0
|
||||
|
||||
|
||||
;;
|
||||
bi_screen_width: dw 0
|
||||
bi_screen_height: dw 0
|
||||
|
||||
_edata:
|
||||
|
||||
; BSS
|
||||
rb 0x4000
|
||||
|
||||
_end:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
CR = 0x0D
|
||||
LF = 0x0A
|
||||
|
||||
; -------- Address ----------
|
||||
STAGE0_BASE = 0x7C00
|
||||
STAGE1_BASE = 0x1000
|
||||
|
@ -7,3 +8,7 @@ DISK_BUFFER = 0x8000
|
|||
KERNEL_PRELOAD = 0xF000
|
||||
STACK_TOP = 0x7000
|
||||
|
||||
; ---------- Video ------------
|
||||
VIDEO_WIDTH = 1024
|
||||
VIDEO_HEIGHT = 768
|
||||
VIDEO_DEPTH = 32
|
||||
|
|
28
boot/memory.inc
Normal file
28
boot/memory.inc
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
; 0xE820 Get System Memory Map
|
||||
; EAX=0x0000E820
|
||||
; EDX=0x534D4150
|
||||
; EBX=0x0 or continuation value
|
||||
; ECX=buffer size
|
||||
; ES:SI = buffer
|
||||
memory_do_E820:
|
||||
|
||||
ret
|
||||
|
||||
memory_get_map:
|
||||
call memory_do_E820
|
||||
jnc .end
|
||||
|
||||
; try 0x88
|
||||
clc
|
||||
mov ah, 0x88
|
||||
int 0x15
|
||||
jc .error
|
||||
test ax, ax
|
||||
je .error
|
||||
.end:
|
||||
clc
|
||||
ret
|
||||
.error:
|
||||
stc
|
||||
ret
|
|
@ -4,25 +4,26 @@ MULTIBOOT_MAGIC = 0x2BADB002
|
|||
MULTIBOOT_HDR_ALIGN = 0x1
|
||||
MULTIBOOT_HDR_MEMINFO = 0x2
|
||||
MULTIBOOT_HDR_VIDEO = 0x4
|
||||
MULTIBOOT_FLAGS = MULTIBOOT_HDR_ALIGN or MULTIBOOT_HDR_MEMINFO or MULTIBOOT_HDR_VIDEO
|
||||
|
||||
struc MultibootHeader flags,addr,width,height,depth
|
||||
struc MultibootHeader addr
|
||||
{
|
||||
.magic dd MULTIBOOT_HDR_MAGIC
|
||||
.flags dd flags
|
||||
.checksum dd -(MULTIBOOT_HDR_MAGIC + flags)
|
||||
.flags dd MULTIBOOT_FLAGS
|
||||
.checksum dd -(MULTIBOOT_HDR_MAGIC + MULTIBOOT_FLAGS)
|
||||
|
||||
; address fields (we'll just skip them)
|
||||
.header_addr dd addr
|
||||
.load_addr dd 0x100000
|
||||
.load_end_addr dd _edata - KBASE
|
||||
.bss_end_addr dd _end - KBASE
|
||||
.load_addr dd STAGE1_BASE
|
||||
.load_end_addr dd _edata - STAGE1_BASE
|
||||
.bss_end_addr dd _end - STAGE1_BASE
|
||||
.entry_addr dd _start
|
||||
|
||||
; Video mode
|
||||
.mode_type dd 0x0
|
||||
.width dd width
|
||||
.height dd height
|
||||
.depth dd depth
|
||||
.width dd VIDEO_WIDTH
|
||||
.height dd VIDEO_HEIGHT
|
||||
.depth dd VIDEO_DEPTH
|
||||
}
|
||||
|
||||
struc MultibootData
|
3
boot/video.inc
Normal file
3
boot/video.inc
Normal file
|
@ -0,0 +1,3 @@
|
|||
video_setup:
|
||||
ret
|
||||
|
|
@ -2,11 +2,9 @@ AS = fasm
|
|||
RM = rm -f
|
||||
INSTALL = install
|
||||
|
||||
KERNEL = vmstupid
|
||||
KERNEL = vmstupid.sys
|
||||
SRCS = kernel.asm \
|
||||
const.inc \
|
||||
boot/multiboot.inc \
|
||||
boot/boot.inc \
|
||||
mm/mm.inc
|
||||
|
||||
.PHONY: all
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
ORG 0x100000
|
||||
ALIGN 4
|
||||
USE32
|
||||
|
||||
INCLUDE 'boot/multiboot.inc'
|
||||
INCLUDE 'const.inc'
|
||||
|
||||
mb_header MultibootHeader MB_FLAGS, mb_header, VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_DEPTH
|
||||
|
||||
_start:
|
||||
cli
|
||||
cmp eax, MULTIBOOT_MAGIC
|
||||
jne hang
|
||||
|
||||
; iterate over memory
|
||||
|
||||
;
|
||||
|
||||
;
|
||||
xor esi, esi
|
||||
mov edi, kernel_page_table - KBASE
|
||||
|
||||
mov ecx, kernel_page_directory - KBASE
|
||||
mov cr3, ecx
|
||||
|
||||
mov ecx, cr0
|
||||
|
||||
|
||||
hang:
|
||||
hlt
|
||||
jmp $-1
|
||||
|
||||
; SEGMENT readable writable
|
||||
|
||||
boot_struct dd 0x0
|
|
@ -5,13 +5,6 @@ PSIZE = 0x1000
|
|||
VERSION_MAJOR = 1
|
||||
VERSION_MINOR = 0
|
||||
|
||||
|
||||
; --------- BOOT PARAMS ---------
|
||||
MB_FLAGS = MULTIBOOT_HDR_ALIGN or MULTIBOOT_HDR_MEMINFO or MULTIBOOT_HDR_VIDEO
|
||||
VIDEO_WIDTH = 1024
|
||||
VIDEO_HEIGHT = 768
|
||||
VIDEO_DEPTH = 32
|
||||
|
||||
; --------- Registers ------------
|
||||
CR0_PE = 0x00000001
|
||||
CR0_MP = 0x00000002
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
INCLUDE 'boot/boot.inc'
|
||||
INCLUDE 'const.inc'
|
||||
|
||||
ORG $ + KBASE
|
||||
ORG KBASE
|
||||
USE32
|
||||
|
||||
jmp kmain
|
||||
|
||||
INCLUDE 'mm/mm.inc'
|
||||
|
||||
|
|
Loading…
Reference in a new issue