0

我的第一个问题在这里

我正在 32 位模式下开发一个简单的操作系统(只是为了好玩),但我遇到了一个问题,即在切换到(32 位)保护模式后我无法跳转到我的内核

这是我的 bootloader.asm

[  BITS 16 ]
[ ORG 0x7c00 ]

jmp  start_boot

start_boot:

KERNEL_OFFSET equ 0x1000
mov [BOOT_DRIVE] , dl

mov bp , 0x9000
mov sp , bp

mov bx , MSG_REAL_MODE
call print

call load_kernel

mov ax , [0x1000]
mov word [reg16] , ax
call print_hex

call switch_to_pm


jmp $



[ BITS 16 ]

load_kernel :
mov bx , MSG_LOAD_KERNEL
call print

mov bx , KERNEL_OFFSET
mov dh , 15
mov dl , [BOOT_DRIVE]
call disk_load

ret

[ BITS 32 ]


;Including files
%include "bootloader/include/print_pm.asm"
%include "bootloader/include/print_hex_pm.asm"


start_pm:
mov ebx , MSG_PRO_MODE
call print_pm

mov ax , [0x1000]
mov word [reg16] , ax
call print_hex_pm


jmp $

jmp CODE_SEG:0x1000



;Including files

%include "bootloader/include/print.asm"
%include "bootloader/include/print_hex.asm"
%include "bootloader/include/disk.asm"
%include "bootloader/include/gdt.asm"
%include "bootloader/include/switch_to_pm.asm"


;Data 
BOOT_DRIVE db 0
check db "check" , 0
MSG_LOAD_KERNEL db "loading Kernel" , 0
MSG_REAL_MODE db "Boot 16" , 0
MSG_PRO_MODE db "Boot 32 " , 0

;Padding 
times 510- ($ -$$) db 0
dw 0xAA55

代替

call KERNEL_OFFSET 

我用过

jmp KERNEL_OFFSET:0x0

or

jmp CODE_SEG:KERNEL_OFFSET

但这些都不起作用

但是如果我只是加载了我的内核而没有切换到保护模式它可以工作

顺便说一句,这是 bootloader.asm 中包含的我的 disk.asm

disk_load:
push dx
mov ah , 0x02
mov al , dh
mov ch , 0x00
mov dh , 0x00
mov cl , 0x02

int 0x13

jc .error
pop dx
cmp dh , al
jne .error
ret

.error :
    mov bx , Err
    call print 
    call disk_load


;Data
Err db "Disk error" , 0

编辑:所有包含的内容 switch_to_pm.asm

[ BITS 16 ]

switch_to_pm:
CLI
LGDT [ gdtd ]


MOV EAX , CR0
OR EAX , 0x1
MOV CR0 , EAX
JMP CODE_SEG:init_pm

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[ BITS 32 ]

init_pm:


MOV AX , DATA_SEG
MOV DS , AX
MOV ES , AX
MOV SS ,AX
MOV FS , AX
MOV GS , AX

MOV EBP , 0x90000
MOV ESP , EBP


CALL start_pm

gdt.asm

;GDT
gdt_start: 

gdt_null: 
dd 0x0          ; null descriptor
dd 0x0 

; Offset 0x8 bytes from start of GDT: Descriptor code therfore is 8

gdt_code:               ; code descriptor
dw 0xFFFF           ; limit low
dw 0x0              ; base low
db 0x0              ; base middle
db 10011010b            ; access
db 11001111b            ; granularity
db 0x0              ; base high

; Offset 16 bytes (0x10) from start of GDT. Descriptor code therfore is 0x10.

 gdt_data:              ; data descriptor
dw 0xFFFF           ; limit low (Same as code)
dw 0x0              ; base low
db 0x0              ; base middle
db 10010010b            ; access
db 11001111b            ; granularity
db 0x0              ; base high

;...Other descriptors begin at offset 0x18. Remember that each descriptor is 8 bytes in     size?
; Add other descriptors for Ring 3 applications, stack, whatever here...

gdt_end:

gdtd: 
dw gdt_end - gdt_start - 1  ; limit (Size of GDT)
dd gdt_start            ; base of GDT

CODE_SEG equ gdt_code - gdt_start
DATA_SEG equ gdt_data - gdt_start

对不起,我的错误以任何方式编辑标题添加了大部分内容并尝试了 Babysteps,我使用了调试器并加载了内核,所以问题出在哪里

4

3 回答 3

0

我们要求提供所有部分,而不仅仅是“包含的大部分内容”的原因是,我们可以准确地复制您所拥有的内容,并且无需太多麻烦即可做到这一点。毕竟,我们正在努力帮助您。

无论如何,因为您还没有提供所有内容(特别是打印例程和实际内核),所以我不得不删除一些东西以使其组装无误,并添加了由jmp $. 我可以告诉你它适用于 thejmp CODE_SEG:KERNEL_OFFSETjmp KERNEL_OFFSET两者。

于 2013-05-28T21:53:11.343 回答
0

你能贴一下bochs debug之类的吗?根据我的经验,你可能lgdt是一个错误的gdt。有时地址是错误的,有时你gdt的限制是错误的,仔细检查gdt可能会对你有所帮助。

于 2013-06-02T10:33:04.050 回答
0

Mohamed,隐藏在文件中的代码太多%include,看不到这里到底发生了什么。

jmp CODE_SEG:KERNEL_OFFSET应该可以,但我希望它成为switch_to_pm例行程序的一部分。

您似乎忽略了需要设置的段寄存器!我强烈推荐http://www.osdev.org - 从“小步骤”开始,然后继续努力......

于 2013-05-28T13:34:34.350 回答