Reserved exception when a page fault SHOULD happen

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
Optimizer601
Posts: 13
Joined: Mon Oct 21, 2019 5:57 am

Reserved exception when a page fault SHOULD happen

Post by Optimizer601 »

Hey. I was trying to enable paging and I think I successfully did but when I do something(like one showed below) that should trigger a page fault, I get a 0xF(15) reserved interrupt. I searched the code but I couldn't find a cause. Would really appreciate if you can help.

Also note that when I manually(software) interrupt 0xE(14) I get a page fault.

What I think should cause a page fault.

Code: Select all

char* addr = (char*)0x1900000; // I have only defined pages up to 1000000
char val = *addr;
This triggers a reserved interrupt.

my paging code: (Page_Tables and Page_Directory are defined in bss section)

Code: Select all

start:
    cli
    
    mov esp, $stack_top

    ; Load GDT

    mov dword [GDTDescriptor + 2], GDT
    mov dword eax, GDTDescriptor
    lgdt [eax]

    mov dword eax, 0x10
    mov word ds, eax
    mov word es, eax
    mov word fs, eax
    mov word gs, eax
    mov word ss, eax

    jmp 8:FlushGDT
FlushGDT:

    call SetupPaging

    call LoadIDT

    sti

    call kernel_main

    cli
_loop:  
    hlt
    jmp _loop

SetupPaging:
    lea eax, [Page_Tables] 
    mov ebx, 7
    mov ecx, (1024 * 4) ; Page Tables - 4
    .Loop1:
        mov [eax], ebx
        add eax, 4
        add ebx, 4096
    loop .Loop1

    lea edx, [Page_Directory]
    lea ebx, [Page_Tables]
    or ebx, 7
    mov ecx, 1024
    .Loop2:
        mov [edx], ebx
        add edx, 4
        add ebx, 4096
    loop .Loop2

    lea ecx, [Page_Directory]
    mov cr3, ecx

    mov ecx, cr0
    or ecx, 0x80000000
    mov cr0, ecx
    ret
Thank you.
Octocontrabass
Member
Member
Posts: 5581
Joined: Mon Mar 25, 2013 7:01 pm

Re: Reserved exception when a page fault SHOULD happen

Post by Octocontrabass »

I see you're enabling IRQs before you configure any of the hardware that controls IRQs. Are you sure it's not a poorly-directed IRQ?
Optimizer601
Posts: 13
Joined: Mon Oct 21, 2019 5:57 am

Re: Reserved exception when a page fault SHOULD happen

Post by Optimizer601 »

Thank you for replying.
I actually configure hardware IRQs in LoadIDT function.

Code: Select all

LoadIDT:
    ; Fill IDT
    mov dword ebx, IDT

    ; ISR
    FillIDT isr, 0
    FillIDT isr, 1
    FillIDT isr, 2
    FillIDT isr, 3
    FillIDT isr, 4
    FillIDT isr, 5
    FillIDT isr, 6
    FillIDT isr, 7
    FillIDT isr, 8
    FillIDT isr, 9
    FillIDT isr, 10
    FillIDT isr, 11
    FillIDT isr, 12
    FillIDT isr, 13
    FillIDT isr, 14
    FillIDT isr, 15
    FillIDT isr, 16
    FillIDT isr, 17
    FillIDT isr, 18
    FillIDT isr, 19
    FillIDT isr, 20
    FillIDT isr, 21
    FillIDT isr, 22
    FillIDT isr, 23
    FillIDT isr, 24
    FillIDT isr, 25
    FillIDT isr, 26
    FillIDT isr, 27
    FillIDT isr, 28
    FillIDT isr, 29
    FillIDT isr, 30
    FillIDT isr, 31

    ; Remap PIC
    mov edx, 0x20
    mov eax, 0x11
    out dx, al
    mov edx, 0xA0
    mov eax, 0x11
    out dx, al
    mov edx, 0x21
    mov eax, 0x20
    out dx, al
    mov edx, 0xA1
    mov eax, 0x28
    out dx, al
    mov edx, 0x21
    mov eax, 0x04
    out dx, al
    mov edx, 0xA1
    mov eax, 0x02
    out dx, al
    mov edx, 0x21
    mov eax, 0x01
    out dx, al
    mov edx, 0xA1
    mov eax, 0x01
    out dx, al
    mov edx, 0x21
    mov eax, 0x0
    out dx, al
    mov edx, 0xA1
    mov eax, 0x0
    out dx, al

    ; IRQ
    FillIDT irq, 0
    FillIDT irq, 1
    FillIDT irq, 2
    FillIDT irq, 3
    FillIDT irq, 4
    FillIDT irq, 5
    FillIDT irq, 6
    FillIDT irq, 7
    FillIDT irq, 8
    FillIDT irq, 9
    FillIDT irq, 10
    FillIDT irq, 11
    FillIDT irq, 12
    FillIDT irq, 13
    FillIDT irq, 14
    FillIDT irq, 15

    ; Load IDT
    mov dword [IDTDescriptor + 2], IDT
    mov dword eax, IDTDescriptor
    lidt [eax]

    ret
and I don't get an interrupt untill I try to do a page fault.
Octocontrabass
Member
Member
Posts: 5581
Joined: Mon Mar 25, 2013 7:01 pm

Re: Reserved exception when a page fault SHOULD happen

Post by Octocontrabass »

That's an interesting choice.

Nothing else jumps out at me, so the bug is probably in some part of your code you haven't shown us yet. Do you have an online repository?
Optimizer601
Posts: 13
Joined: Mon Oct 21, 2019 5:57 am

Re: Reserved exception when a page fault SHOULD happen

Post by Optimizer601 »

Really thank you for taking your time.

I just created a repo.

https://github.com/Optimizer0/IAOS
User avatar
iansjack
Member
Member
Posts: 4705
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Reserved exception when a page fault SHOULD happen

Post by iansjack »

You have a comma missing in your interrupt messages array, after "Stack fault". All messages after that are out by one.
Optimizer601
Posts: 13
Joined: Mon Oct 21, 2019 5:57 am

Re: Reserved exception when a page fault SHOULD happen

Post by Optimizer601 »

That was the case. I feel stupid for asking this here.
Thank you so much.
Post Reply