context switching: getting page faults.
Posted: Sat Apr 14, 2012 3:53 pm
Hi
I am learning to write the basic OS and right now I am experimenting with the tasks.
I wrote the code for context switching for tasks but I am getting page faults. I do not know why though.
This is how the physical mem is set up: kernel 4 MB to 8MB. User process: 8MB to 12 MB.
Kernel is identity mapped and the user process is at virtual addr 128 MB.
I wrote a simple test program to execute the context switch:
In the attachments, I have the paging files I am using.
I am learning to write the basic OS and right now I am experimenting with the tasks.
I wrote the code for context switching for tasks but I am getting page faults. I do not know why though.
This is how the physical mem is set up: kernel 4 MB to 8MB. User process: 8MB to 12 MB.
Kernel is identity mapped and the user process is at virtual addr 128 MB.
I wrote a simple test program to execute the context switch:
Code: Select all
void task()
{
int entry_file=0;
int a;
char *buf_1= (char *)0x8000000; //set the address of the buffer that has the binary file data to virt add 128 MB
a=file_read(buf_1,30);//read the 30 bytes of file data into buffer
entry_file=0x8048234; /entry point into ELF file
/*tss.esp0 is already set to kernel stack 8MB in the main func before the context switch*/
context_switch(entry_file, 0xC00000); //0xC00000=12 MB is the user stack base ptr addr
}
Code: Select all
context_switch:
cli
# Save esp so we can continue accessing arguments
movl %esp, %ebp
# Set up segment registers
movw $USER_DS, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
# Push the interrupt context onto the stack: ss, esp, eflags, cs, eip
pushl $USER_DS # Stack Segment
movl 8(%ebp), %eax # Stack Pointer
pushl %eax
pushf # eflags
# Unmask interrupts by modifying eflags
orl $0x200, (%esp)
pushl $USER_CS # Code Segment
movl 4(%ebp), %eax # Instruction Pointer
pushl %eax
# "return" to user space
iret