triple fault when enabling paging

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.
Post Reply
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

triple fault when enabling paging

Post by clementttttttttt »

I modified the page table setup code a bit to make it identity map the kernel. However, it crashes instantly when I try to set the paging bit in cr0. Here's my code:

Code: Select all

paging:
    mov esi,0
    mov ecx,1024
.1:
    cmp esi,_kernel_start
    jl .2
    cmp esi,_kernel_end
    jge .3
    mov edx,esi
    or edx,3
    mov [edi],edx
.2:
    add esi,4096
    add edi,4
    loop .1
.3:
    mov dword [boot_page_directory],(boot_page_table1+3)
    mov dword [boot_page_directory+(768*4)],(boot_page_table1+0x3)
    mov ecx,boot_page_directory
    mov cr3,ecx
    mov ecx,cr0
    or ecx,0x80010000
    mov cr0,ecx 
    jmp $ ;cr2 pointed to this. replaced with hlt, still the same.

and the register contents are:
cr0=0xe0010011
cr2=0x001010d1
cr3=0x105000
cr4=0
Also, how do I find the corresponding code in my assembly source from the cr2 register?
Last edited by clementttttttttt on Tue Sep 08, 2020 8:48 pm, edited 1 time in total.
Octocontrabass
Member
Member
Posts: 5601
Joined: Mon Mar 25, 2013 7:01 pm

Re: triple fault when enabling paging

Post by Octocontrabass »

Do "_kernel_start" and "_kernel_end" span a range of addresses that include the MOV to CR0 and the subsequent JMP that are used to enable paging?

I believe objdump will show you addresses that you can match to CR2, but in this case it's safe to say the fault is happening at the JMP instruction.
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

Re: triple fault when enabling paging

Post by clementttttttttt »

_kernel_start and _kernel_end includes the .text section. Also, I replaced the jmp with hlt, and cr2 still points to 0x1010d1.
Octocontrabass
Member
Member
Posts: 5601
Joined: Mon Mar 25, 2013 7:01 pm

Re: triple fault when enabling paging

Post by Octocontrabass »

Is the code you posted in the .text section?

I'd expect the HLT instruction is located at the same address as the JMP instruction you replaced, so CR2 won't change.
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

Re: triple fault when enabling paging

Post by clementttttttttt »

Yes, the code is in the .text section.
edit: problem solved, I used the code from "Setting up paging" instead.
Post Reply