1

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?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Lu_dovi_xo
  • 11
  • 1
  • 2
    How does it not work, how do you boot it (usb drive, hard disk, floppy, cdrom), does the real mode part start at least (put something in there)? – Jester Apr 08 '22 at 13:54
  • i boot it from USB. the computer when loading the Bootloader shows nothing and restarts. the real mode start at the beginning – Lu_dovi_xo Apr 08 '22 at 14:36
  • Does it work if you stay in real mode? Such as `mov ax, 0xb800; mov ds, ax; mov word [0], 0x0241; jmp $`? – Jester Apr 08 '22 at 14:42
  • yes, it works. so where is the problem? – Lu_dovi_xo Apr 08 '22 at 15:07
  • Are you booting this on a real computer with a USB stick using Floppy Disk Emulation (FDD)? – Michael Petch Apr 09 '22 at 23:40
  • Best keep setting `ss` and `sp` close together: `mov ss, ax` `mov sp, bp` (Real mode) and `mov ss, ax` `mov esp, ebp` (Protected mode). You forgot to set `ss` in the real mode part! – Sep Roland Apr 10 '22 at 23:52
  • @MichaelPetch no, i am booting this from a normally usb stick using "balenaetcher" – Lu_dovi_xo Apr 11 '22 at 12:18
  • 1
    If the BIOS is set to boot USB media as floppy media then this could be a problem: https://stackoverflow.com/a/47320115/3857942 – Michael Petch Apr 11 '22 at 21:59

0 Answers0