Skip to content

Commit

Permalink
boot: fix ljmp offset
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSnowfield committed Sep 2, 2024
1 parent 1d07656 commit 7b07c2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
20 changes: 6 additions & 14 deletions boot/startup.s
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
.intel_syntax noprefix
.equ BOOTSTART, 0x07c0
.equ KRNLNBOOT, 0x07e0

.text
.global _start

.code16

_start:
Expand Down Expand Up @@ -32,11 +31,9 @@
cmp ax, 0
jnz _flag_panic

# 原神,啓動!
call _func_print_newline
lea ax, _msg_booting
call _func_print
call _func_print_newline

# 進入保護模式
xor eax, eax
Expand All @@ -48,12 +45,11 @@
or al, 1 # 啓用保護位
mov cr0, eax

# 起!
# xchg bx,bx

# jmp 0x08:_krnl_MMain # 超級遠跳轉
# # 一去不復返 2333
# 原神,啓動!
xchg bx, bx

# 加載內核入口偏移
ljmp [0x8000]
hlt

# 打印字串
Expand Down Expand Up @@ -129,7 +125,7 @@
# movw [si + 2], 127 # 要讀取的扇區數
# movw [bx + 4], 0x0000 # 偏移
movw [si + 6], 0x0800 # 段
movw [si + 8], 3 # LBA48 低32位 (內核在第3扇區)
movw [si + 8], 2 # LBA48 低32位 (內核在第3扇區)
# movw [bx + 10], 0 # LBA48 低32位
# movw [bx + 12], 0 # LBA48 高16位

Expand Down Expand Up @@ -169,16 +165,12 @@
# 繼續讀取下一個塊
jmp _read_continue

# bootim 入口函數地址
_read_end:
mov ax, ds:0x8000
ret

_flag_no_bootim:
jmp _flag_panic

ret

# 寄存器 AX [AL 驅動器號, AH]
# 寄存器 BX 目的內存段偏移
# 寄存器 ES 目的內存段號
Expand Down
3 changes: 2 additions & 1 deletion src/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ ENTRY(_krnl_MMain);
SECTIONS {

.head ALIGN(4) : {
LONG(_krnl_MMain);
SHORT(_krnl_MMain);
SHORT(0x0008)
LONG(0x00000000)
LONG(0x00000000)
LONG(0x00000000)
Expand Down

0 comments on commit 7b07c2e

Please sign in to comment.