0

My code looks like so:



[org 0x7c00]
[bits 16]
cli

;  %include 'gdt.asm'   , what is wrong if i set the gdt here instead of bellow the long jump?


lgdt [gdt_32_descriptor] ; gdt_32_descriptor is contained in gdt.asm

mov eax, cr0
or eax, 0x00000001
mov cr0, eax

jmp 0x8:init_pm     ; 0x8 -> second segment of the gdt


%include 'gdt.asm'  ; contains the global descriptor table and gdt descriptor (why does it only work in  this position)

[bits 32 ]
init_pm :

%include 'print_msg_32_bit.asm'   ; prints a message on screen 

What i dont get is that if i put the global descriptor table in a different position (specifically before the long jump) the message is not printed . Why does this happen ? hIm using qemu and nasm.

  • 2
    You didn't show the contents of that file but I assume it contains the data that makes up the GDT. If you place it before the `lgdt` instruction it is in the way of your control flow, so the machine will try to read your data as if they're supposed to be instructions. This will cause a crash. – ecm Mar 04 '22 at 22:32
  • Yes, I guess it's confusing the processor . I keep forgetting it. Thanks a lot!! – Νίκος Αντωνετσής Mar 05 '22 at 05:28

0 Answers0