Page Fault

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
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Page Fault

Post by JoeTheProgrammer »

I am using the tutorial JamesM has written. I am trying to do a system call, but every time I try to do int 80h in the kernel's main function with ebx set to the string to display (monitor_write system call) , I get a page fault. I am a total newbie at kernel development, but can anyone help me figure out what is wrong?

Thanks,
Joseph
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post by piranha »

1) Are you using the exact same code as the tutorial?
2) This is the latest (User-Mode) tutorial, right?
3) When does this pagefault happen?
4) What info does it give?
JamesM's Tutorial wrote:If you keep getting page faults when jumping to user mode, make sure that your kernel code/data is set to be user-accessible. When you actually load user programs you won't want this to be the case, however at the moment we merely jump back to the kernel and execute code in main(), so it needs to be accessible in user mode!
-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Post by JoeTheProgrammer »

piranha wrote:1) Are you using the exact same code as the tutorial?
2) This is the latest (User-Mode) tutorial, right?
3) When does this pagefault happen?
4) What info does it give?
JamesM's Tutorial wrote:If you keep getting page faults when jumping to user mode, make sure that your kernel code/data is set to be user-accessible. When you actually load user programs you won't want this to be the case, however at the moment we merely jump back to the kernel and execute code in main(), so it needs to be accessible in user mode!
-JL
1) I am using the same code, except for the code to display the string using the system call
2) Yes
3) It gives me the pagefault right after the int 80h system call
4)Here is the info it gives: "Page fault! (present user-mode ) at 0x0x2d2d2d2d -EIP: 0x100050"

Thanks,
Joseph
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post by piranha »

Is the code that you've written good?

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Post by JoeTheProgrammer »

piranha wrote:Is the code that you've written good?

-JL
Here it is:

In boot.asm

Code: Select all

global _testMonitorWriteSysCall

int80h_eax0:     db 'Int 80h EAX=0 Called...',23
          
_testMonitorWriteSysCall:
    mov eax, 0
    mov ebx, int80h_eax0
    int 80h
In main:

Code: Select all

int main(struct multiboot *mboot_ptr, u32int initial_stack)
{
    page_directory_t *dir;
    initial_esp = initial_stack;
    // Initialise all the ISRs and segmentation
    init_descriptor_tables();
    // Initialise the screen (by clearing it)
    monitor_clear();

    // Initialise the PIT to 100Hz
    asm volatile("sti");
    init_timer(50);

    // Start paging.
    initialise_paging();

    // Start multitasking.
    initialise_tasking();
    
    initialise_syscalls();
    
    monitor_write(" ----------------------------------------- \n");
    monitor_write("| Welcome                                   |\n");
    monitor_write(" ----------------------------------------- \n");
    
    switch_to_user_mode();
    
    testMonitorWriteSysCall();

    return 0;
}
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Hi,
Here is the info it gives: "Page fault! (present user-mode ) at 0x0x2d2d2d2d -EIP: 0x100050"
Do you think that 0x2d2d2d2d is a valid address?

The EIP is 0x100050 - so what code is it executing? Have you disassembled the binary (objdump -d kernel)

Cheers,

James
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Post by JoeTheProgrammer »

JamesM wrote:Hi,
Here is the info it gives: "Page fault! (present user-mode ) at 0x0x2d2d2d2d -EIP: 0x100050"
Do you think that 0x2d2d2d2d is a valid address?

The EIP is 0x100050 - so what code is it executing? Have you disassembled the binary (objdump -d kernel)

Cheers,

James
No that is not a valid address. Now it is working, so it seems I have somehow fixed the problem.

Thanks,
Joseph
Post Reply