Thanks for the replies!
LtG wrote:
it's usually better to just use a debugger (gdb), it might take a few hours to learn or a few days but if you are going to continue osdev you're going to need it anyway so might as well pay the price now and get the benefits going forward instead of postponing it and paying for that for as long as you postpone it.
I'm quite aware of gdb, and I've been using it for some time (for osdev and other projects). With this particular issue, however, gdb throws an error when trying to connect to the remote target (qemu):
Code:
Remote 'g' packet reply is too long: 000000000000000000000000000000000000000000000000630 (snip)
I assumed this has to do with my bug and tried debugging without gdb, though you're right; using gdb would be better.
LtG wrote:
It seems you have enabled protected mode and paging and you have set a CR3 to point to 0x00126000, however what's there? Remember the CR3 points to physical memory, not virtual though that's probably not the issue here (guessing)..
AFAIK CR3 should point to the page directory used during boot. I haven't checked this, however.
LtG wrote:
Also it could be that the issue is with your stack, given that CALL uses stack implicitly. You can easily test that by replacing the CALL with a JMP and seeing does the error happen later.
That's what I thought, though everything that has something to do with the stack looks sane to me (and is copied directly from the tutorial)
LtG wrote:
You could also do a disassembly of the whole thing (if it's not too large) and post it here, it might help.
There you go:
https://pastebin.com/2Sqj0ngJKeep in mind that I have a lot of other stuff in there, though 99% of it isn't called due to the while(1); in init().
LtG wrote:
Finally, did you do a full copy/paste of the wiki tutorial? I'm assuming it should work if you follow the tutorial and don't deviate from it at all, and only then start modifying, that way it's easier for you to find out what deviations (change you want) causes crashes and focus on those..
The tutorial doesn't provide much (it's just a Bare Bones thing), but I've copied the init code and the linker script 1:1 (which is a closed system as far as I understand it).
iansjack wrote:
According to CR2 the faulting address is 0x40. So why would your code be trying to read or write that address? You really need to implement a minimal exception handler for page faults that halts execution. You can then examine the error code pushed to the stack.
I do have proper exception handlers, though I can't get to a point where I can register them since I can't even call init.
I've wondered about 0x40 too. I guess gdb could really help me here, but for some reason it doesn't work for this issue.
iansjack wrote:
Another thing you can do is to manually inspect your page table to see that it looks reasonable.
How would I go about doing that? I can't set up the serial connection, I can't print to the screen, I can't use gdb.
In conclusion, I think my best bet is getting gdb to work again... (unless someone can spot my issue just from the code)