0

I am going to write a simple operating system. An error have been occurred while switch from 16 bits' real mode to 32 bits' protected mode.

After loading the GDT register and setting the GDT, the protected mode has been turned on successfully. I'd like to jump to 0x0 address in memory but failed and the information of GDT shows that there are thousands of GDT describer.

'''

    lgdt    (gdt_48 - _start + 0x7c00)
    movw    $0x1, %ax
    lmsw    %ax         // switch protect mode on 

    jmp $0x8, $0x0      // jmp 0:0

gdt:
    .word   0, 0, 0, 0

    .word   0x07ff
    .word   0x0000
    .word   0x9a00
    .word   0x00c0

    .word   0x07ff
    .word   0x0000
    .word   0x9200
    .word   0x00c0

gdt_48:
    .word   0x7ff       // 2048/8=256
    .word   gdt, 0   

'''

Here is debug info: enter image description here

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Zhi-An Zhu
  • 49
  • 3
  • 3
    Instead of taking a picture of the screen with your phone, please copy/paste the contents of the error message into your question. – fuz Jan 22 '22 at 09:59
  • Normally you read a CR and OR in a bit you want to set, rather than `mov` a whole constant. (`smsw` / `lmsw` access the low 16 bits of CR0, which you could do with `mov %cr0, %eax` etc.) But anyway, without seeing the `.code16` and `.code32` directives in your code, and an actual error message or debug details about how it failed, this isn't a [mcve] – Peter Cordes Jan 22 '22 at 19:38
  • `.word gdt` probably needs to be gdt - _start + 0x7c00 – prl Jan 22 '22 at 20:05

0 Answers0