Assembly kernel does not work.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Octocontrabass
Member
Member
Posts: 5754
Joined: Mon Mar 25, 2013 7:01 pm

Re: Assembly kernel does not work.

Post by Octocontrabass »

core2extreme wrote: Fri Mar 07, 2025 5:57 pmBecause the GDT loads fine and the PE bit is set fine.
The CPU doesn't check the GDT when you load GDTR or set the PE bit. Neither of those things are proof that your GDT is correct.

The CPU does check the GDT when you do a far jump.
core2extreme
Posts: 9
Joined: Thu Mar 06, 2025 5:21 pm

Re: Assembly kernel does not work.

Post by core2extreme »

Octocontrabass wrote: Fri Mar 07, 2025 6:04 pm
core2extreme wrote: Fri Mar 07, 2025 5:57 pmBecause the GDT loads fine and the PE bit is set fine.
The CPU doesn't check the GDT when you load GDTR or set the PE bit. Neither of those things are proof that your GDT is correct.

The CPU does check the GDT when you do a far jump.
Oh, wait, really? Guess I better get to reading the wiki and writing my own GDT... thanks for the help!
MichaelPetch
Member
Member
Posts: 829
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Assembly kernel does not work.

Post by MichaelPetch »

You can use LGDT to load complete rubbish from the GDT record and it won't fail. You can have a valid GDT record and bogus entries in the GDT and LGDT won't fail. You can enable the protected mode bit and it won't immediately fail. The failures will occur when the processor attempt to read a selector into a segment register (ES/DS/CS/GS/FS/SS). CS in your code is set with the FAR JMP. So your code could have bad GDT table or GDT record and have set the PE bit and only start failing at the FAR JMP instruction because CS is being reloaded and the CPU needs to get the selector info from the GDT.

Update: I started writing this up before Octo posted his last comment.
sanzenyou
Posts: 3
Joined: Tue Apr 02, 2024 4:24 am
Libera.chat IRC: sanzenyou

Re: Assembly kernel does not work.

Post by sanzenyou »

you can use bochsdbg.exe to trace cpu execute step by step, that's convenient than qemu.
Post Reply