[RESOLVED] Need help with paging problems
-
- Member
- Posts: 68
- Joined: Thu May 28, 2009 11:46 pm
[RESOLVED] Need help with paging problems
I have a problem with the kernel... I set up paging in the bootloader to map the kernel to 3gb, and identity map the first 4 mb. Then I jump to the kernel.
I do the same in the kernel, so it has it's own page directory, to be easily set up... but when I try to switch to the new page directory I get a triple fault. What could be the problem?
I posted my virtual and physical memory manager, the kernel entry (the C part) and the parts related to paging in the bootloader. I also attached the linker script, maybe it helps...
Here are the links [they will expire in 1 month]:
[links removed]
memory/mmngr.asm
memory/mmngr_vi.c
memory/mmngr_ph.c
memory/lib/pde.c + pte.c
main.c
bootloader/stage2.asm + paging.inc
linker_script.ld
I tried setting up the kernel at 0x100000 instead of 0xC0000000, but I get other errors, like page fault, or coprocessor fault... I have no idea what the problem could be. I've been trying to find a solution for about two weeks already... i can't seem to find any...
Thanks in advance,
Chibici Tiberiu
Currently developing CTA Operating System.
I do the same in the kernel, so it has it's own page directory, to be easily set up... but when I try to switch to the new page directory I get a triple fault. What could be the problem?
I posted my virtual and physical memory manager, the kernel entry (the C part) and the parts related to paging in the bootloader. I also attached the linker script, maybe it helps...
Here are the links [they will expire in 1 month]:
[links removed]
memory/mmngr.asm
memory/mmngr_vi.c
memory/mmngr_ph.c
memory/lib/pde.c + pte.c
main.c
bootloader/stage2.asm + paging.inc
linker_script.ld
I tried setting up the kernel at 0x100000 instead of 0xC0000000, but I get other errors, like page fault, or coprocessor fault... I have no idea what the problem could be. I've been trying to find a solution for about two weeks already... i can't seem to find any...
Thanks in advance,
Chibici Tiberiu
Currently developing CTA Operating System.
Last edited by chibicitiberiu on Wed Aug 04, 2010 6:37 am, edited 1 time in total.
Tibi,
Currently working on the Lux Operating System
Currently working on the Lux Operating System
Re: Need help with paging problems
Which file, which line crashes ?. but when I try to switch to the new page directory I get a triple fault. What could be the problem?
If a trainstation is where trains stop, what is a workstation ?
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Re: Need help with paging problems
It's a game we're supposed to play, find the bug and fix it.. for free!
-
- Member
- Posts: 68
- Joined: Thu May 28, 2009 11:46 pm
Re: Need help with paging problems
It's the highlighted line in mmngr_vi.c (line 170)... sorry that I forgot to mentiongerryg400 wrote:Which file, which line crashes ?. but when I try to switch to the new page directory I get a triple fault. What could be the problem?
And I've been trying to find the problem for 2 weeks and I just can't seem to find any way to fix it.
Why does it triple fault when changing the page directory, when changing register cr3? The possible problems I see is either the physical memory manager doesn't work properly, or there is a bug I haven't found yet.
About the physical memory manager, I tried a dozen of things... like only initializing memory above 0x100000 + kernel size... I just can't find the problem.
I'm thinking of not enabling paging in the bootloader, but then how do I make the kernel execute code, and all variables to start at 0xC0000000? and don't tell me about the gdt trick, i won't listen.
Tibi,
Currently working on the Lux Operating System
Currently working on the Lux Operating System
-
- Member
- Posts: 68
- Joined: Thu May 28, 2009 11:46 pm
Re: Need help with paging problems
Maybe you are right... but i'm not so experienced and I need help. This forum is like the last forum I want to post to, because I see that most of you are selfish and don't want to help, just to show off what amazing OS you created, and how smart you are, and how stupid is everybody else.Brynet-Inc wrote:It's a game we're supposed to play, find the bug and fix it.. for free!
But who am I to judge...?
Maybe I didn't have such a great day...or month, nothing seems to work right for me... and because of that i'm a pessimist...but who cares...
Tibi,
Currently working on the Lux Operating System
Currently working on the Lux Operating System
Re: Need help with paging problems
Hi,
I'd assume the last problem is a lot more likely. To check, use something like Bochs debugger and stop the emulator just before the "mov cr3" is executed (e.g. with a breakpoint). Then check what you're about to load into CR3 ("r" to see the contents of general registers) and examine the new page directory, page table, etc (e.g. "xp" to examine physical memory) to confirm that the physical page at EIP in the new virtual address space is the same as the physical page in the previous virtual address space (or at least contains the same data).
If that's not the problem, then at a minimum you'll have a nice log from Bochs saying which exception was caused at which virtual address, etc...
Cheers,
Brendan
If it crashes when doing the "mov cr3" instruction, then there's only 2 possible causes (that I can think of) - either you're not running at CPL=0 (and any attempt to modify any control register causes a general protection fault); or the physical address of the page at EIP isn't the same in the new virtual address space (you change CR3, the instruction after the "mov cr3" vanishes, you crash).chibicitiberiu wrote:Why does it triple fault when changing the page directory, when changing register cr3?
I'd assume the last problem is a lot more likely. To check, use something like Bochs debugger and stop the emulator just before the "mov cr3" is executed (e.g. with a breakpoint). Then check what you're about to load into CR3 ("r" to see the contents of general registers) and examine the new page directory, page table, etc (e.g. "xp" to examine physical memory) to confirm that the physical page at EIP in the new virtual address space is the same as the physical page in the previous virtual address space (or at least contains the same data).
If that's not the problem, then at a minimum you'll have a nice log from Bochs saying which exception was caused at which virtual address, etc...
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
-
- Member
- Posts: 68
- Joined: Thu May 28, 2009 11:46 pm
Re: Need help with paging problems
Brendan wrote:Hi,
If it crashes when doing the "mov cr3" instruction, then there's only 2 possible causes (that I can think of) - either you're not running at CPL=0 (and any attempt to modify any control register causes a general protection fault); or the physical address of the page at EIP isn't the same in the new virtual address space (you change CR3, the instruction after the "mov cr3" vanishes, you crash).chibicitiberiu wrote:Why does it triple fault when changing the page directory, when changing register cr3?
I'd assume the last problem is a lot more likely. To check, use something like Bochs debugger and stop the emulator just before the "mov cr3" is executed (e.g. with a breakpoint). Then check what you're about to load into CR3 ("r" to see the contents of general registers) and examine the new page directory, page table, etc (e.g. "xp" to examine physical memory) to confirm that the physical page at EIP in the new virtual address space is the same as the physical page in the previous virtual address space (or at least contains the same data).
If that's not the problem, then at a minimum you'll have a nice log from Bochs saying which exception was caused at which virtual address, etc...
Cheers,
Brendan
The first option is very unlikely because i have managed that irq, and it should display a screen of death. I'm going to try Bochs, although i'm kind of unfamiliar with using this tool.
Thanks for reply anyway . I have a question, how can I know the address of a specific instruction, because in Bochs breakpoints are based on addresses, right? I don't think I want to go through each and every instruction until I find it (I tried this before... didn't find it, and I only wasted time with Bochs, and did not find the problem).
Tibi,
Currently working on the Lux Operating System
Currently working on the Lux Operating System
Re: Need help with paging problems
Hi,
For old versions of Bochs you can do something like:
This will lock up the computer. When the computer has locked up, you can break into the debugger (control+c) then change ECX with the debugger ("set ecx=1") and then single-step from there.
The other alternative is to use a tool like "objdump" to find out where you want a breakpoint, then set a breakpoint in Bochs before executing any code. This is probably the hardest way (especially if you're using a high level language, where the source code looks nothing like a disassembly).
Cheers,
Brendan
For newer versions of Bochs you can insert a magic breakpoint instruction ("xchg bx,bx") in the code, and Bochs debugger will stop when it executes this instruction. This instruction is harmless and has no effect on normal CPUs or when Bochs is running without the debugger enabled.chibicitiberiu wrote:I have a question, how can I know the address of a specific instruction, because in Bochs breakpoints are based on addresses, right? I don't think I want to go through each and every instruction until I find it (I tried this before... didn't find it, and I only wasted time with Bochs, and did not find the problem).
For old versions of Bochs you can do something like:
Code: Select all
push ecx
mov ecx,0
.stop:
jecxz .stop
pop ecx
The other alternative is to use a tool like "objdump" to find out where you want a breakpoint, then set a breakpoint in Bochs before executing any code. This is probably the hardest way (especially if you're using a high level language, where the source code looks nothing like a disassembly).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
-
- Member
- Posts: 68
- Joined: Thu May 28, 2009 11:46 pm
Re: Need help with paging problems
FINALLY found the bug. It was mapping 0x0 to 0xC0000000 instead of 0x100000. Fixed it and now the kernel works.
Tibi,
Currently working on the Lux Operating System
Currently working on the Lux Operating System