0
org 0x7c00
bits 16
jmp start
resb 0x50

start: 
   mov ax, 0x2401
   int 0x15

   mov ax, 0x3
   int 0x10

   cli
   lgdt[gdt_pointer]

   mov eax, cr0
   mov eax, 1
   mov cr0, eax
   jmp 0x08:enter_pmode

gdt_start:
    dq 0x0
gdt_code:
    dw 0xFFFF
    dw 0x0
    db 0x0
    db 10011010b
    db 11001111b
    db 0x0
gdt_data:
    dw 0xFFFF
    dw 0x0
    db 0x0
    db 10010010b
    db 11001111b
    db 0x0
gdt_end:
gdt_pointer:
    dw gdt_end - gdt_start-1
    dd gdt_start

DATA_SEG equ gdt_data - gdt_start
CODE_SEG equ gdt_code - gdt_start

bits 32
enter_pmode:
    mov ah, 0x0f
    mov al, 65
    mov [0xb8000], ax
    
    jmp $


times 510 - ($ - $$) db 0
dw 0xaa55

I have a bootloader but when I try boot from usb stick it restarts It work fine with Real Mode

Codes that I used

nasm -f bin boot.asm -o boot.bin
sudo dd status=progress if=boot.bin of=/dev/sdb

When I try the Test Code to See if Your BIOS is Overwriting the BPB code here, I get the this output:

7C00: EB 3C 90 AA AA AA AA AA
7C08: AA AA AA AA AA AA AA AA
7C10: AA AA AA AA AA AA AA AA
7C18: AA AA AA AA 00 00 00 00
7C20: AA AA AA AA 00 AA AA AA
7C28: AA AA AA AA AA AA AA AA
7C30: AA AA AA AA AA AA AA AA
7C38: AA AA AA AA AA AA

I think my BIOS is overwriting BPB I looked the question but it didn't work

  • You have other unsafe assumptions in your code like not setting DS=0 ([Boot loader doesn't jump to kernel code](https://stackoverflow.com/a/32705076)), or not loading DS after entering protected mode to increase the segment limit, so I'd expect the `mov [0xb8000], ax` store to video RAM to fault since DS should still have base=unknown and limit=64k from real mode. But probably the first problem is the `lgdt` executing with an unknown `DS`. – Peter Cordes Jun 09 '22 at 20:05
  • What should I do? –  Jun 09 '22 at 20:12
  • `xor ax,ax` / `mov ds,ax` before `lgdt`, as shown in [Boot loader doesn't jump to kernel code](https://stackoverflow.com/q/32701854). You may also need to `mov` a non-zero segment selector (for your `gdt_data` entry) into DS after entering protected mode, to change the segment limit. You can single-step that in QEMU + GDB, or better Bochs, to make sure you get that part right in a simulator before testing on bare metal. – Peter Cordes Jun 09 '22 at 20:14
  • finally solved, I've been dealing with this for a day. thanks a lot –  Jun 09 '22 at 20:18

0 Answers0