程序集保护模式不适用于真实硬件

发布于 01-19 23:43 字数 1581 浏览 4 评论 0原文

我尝试在汇编中创建自己的操作系统。 我学习了实模式(16 位),现在我正在

QEMU 模拟器中学习保护模式(32 位),操作系统运行完美,但是当我将其加载到计算机(32 位)上时,它无法运行。

这是代码:

   [org 0x7c00]        

   xor ax, ax
   mov ds, ax
   mov es, ax
   mov bp, 0x8000
   mov sp, bp

   mov ah, 0x0
   mov al, 0x3
   int 0x10
   
   
   CODE_SEG equ GDT_code - GDT_start
   DATA_SEG equ GDT_data - GDT_start
   
   cli
   lgdt [GDT_descriptor]
   mov eax, cr0
   or eax, 1
   mov cr0, eax
   jmp CODE_SEG:start_protected_mode
   
   ;jmp $
                                
                                 
   GDT_start:                          ; must be at the end of real mode code
       GDT_null:
          dd 0x0
          dd 0x0
         
       GDT_code:
          dw 0xffff
          dw 0x0
          db 0x0
          db 0b10011010
          db 0b11001111
          db 0x0
       
       GDT_data:
          dw 0xffff
          dw 0x0
          db 0x0
          db 0b10010010
          db 0b11001111
          db 0x0
        
   GDT_end:

   GDT_descriptor:
       dw GDT_end - GDT_start - 1
       dd GDT_start
     
   [bits 32]
   start_protected_mode:
       mov ax, DATA_SEG
       mov ss, ax
       mov ds, ax
       mov es, ax
       mov fs, ax
       mov gs, ax
       mov ebp, 0x90000
       mov esp, ebp
        
       mov al, 'A'
       mov ah, byte 0x02
       mov [0xb8000], ax
       hlt 
       jmp $
       
     times 510-($-$$) db 0              
     dw 0xaa55

对于编译,我使用这些命令:

nasm -f bin bootloader.asm -o boot.bin
qemu-system-x86_64 boot.bin

错误在哪里?

i've tryied to create my own OS in assembly.
i learned real mode (16 bit) and now i'm learning protected mode (32 bit)

in the QEMU emulator the OS works perfectly but when i load it on my computer (32 bit) it doesn't work.

this is the code:

   [org 0x7c00]        

   xor ax, ax
   mov ds, ax
   mov es, ax
   mov bp, 0x8000
   mov sp, bp

   mov ah, 0x0
   mov al, 0x3
   int 0x10
   
   
   CODE_SEG equ GDT_code - GDT_start
   DATA_SEG equ GDT_data - GDT_start
   
   cli
   lgdt [GDT_descriptor]
   mov eax, cr0
   or eax, 1
   mov cr0, eax
   jmp CODE_SEG:start_protected_mode
   
   ;jmp $
                                
                                 
   GDT_start:                          ; must be at the end of real mode code
       GDT_null:
          dd 0x0
          dd 0x0
         
       GDT_code:
          dw 0xffff
          dw 0x0
          db 0x0
          db 0b10011010
          db 0b11001111
          db 0x0
       
       GDT_data:
          dw 0xffff
          dw 0x0
          db 0x0
          db 0b10010010
          db 0b11001111
          db 0x0
        
   GDT_end:

   GDT_descriptor:
       dw GDT_end - GDT_start - 1
       dd GDT_start
     
   [bits 32]
   start_protected_mode:
       mov ax, DATA_SEG
       mov ss, ax
       mov ds, ax
       mov es, ax
       mov fs, ax
       mov gs, ax
       mov ebp, 0x90000
       mov esp, ebp
        
       mov al, 'A'
       mov ah, byte 0x02
       mov [0xb8000], ax
       hlt 
       jmp $
       
     times 510-($-$) db 0              
     dw 0xaa55

and for the compilation I use these commands:

nasm -f bin bootloader.asm -o boot.bin
qemu-system-x86_64 boot.bin

where is the mistake?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文