kernel vs user space question

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
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

kernel vs user space question

Post by ITchimp »

I have 2 gdt segments for kernel, one for code, the other for data

I have 2 gdt segments for user space, one for code, the other for data

all segments span the entire 4gb address space

Now my kernel data and code is mapped into virtual address space by setting the page table bit to supervisory only... (not accessed by all)

now I transitioned my kernel process into user mode and tries to make syscalls.... I got an error saying that page fault
for the stack I am trying to access...

The segment selector value is 0x23
last 2 bit is rpl which is segment selector indicates it is user mode... after switch to user mode, is my cpl 3?

what did I do wrong? I find that rpl, dpl and cpl confusing...

should I set kernel code and data to supervisory or to all? will that make user code able to execute kernel code??

I am drowning in questions ! pulling me out of my misery!!!
User avatar
bellezzasolo
Member
Member
Posts: 110
Joined: Sun Feb 20, 2011 2:01 pm

Re: kernel vs user space question

Post by bellezzasolo »

ITchimp wrote:I have 2 gdt segments for kernel, one for code, the other for data

I have 2 gdt segments for user space, one for code, the other for data

all segments span the entire 4gb address space

Now my kernel data and code is mapped into virtual address space by setting the page table bit to supervisory only... (not accessed by all)

now I transitioned my kernel process into user mode and tries to make syscalls.... I got an error saying that page fault
for the stack I am trying to access...

The segment selector value is 0x23
last 2 bit is rpl which is segment selector indicates it is user mode... after switch to user mode, is my cpl 3?

what did I do wrong? I find that rpl, dpl and cpl confusing...

should I set kernel code and data to supervisory or to all? will that make user code able to execute kernel code??

I am drowning in questions ! pulling me out of my misery!!!
Have you set up ESP0 of your TSS to a valid stack?

When transitioning from ring 3 to ring 0, the CPU loads the stack from the TSS, rather than executing an interrupt handler on a user stack.

Alternatively, if you haven't changed stack when transitioning from ring 0 to ring 3, then you'll be trying to access a ring 0 stack.
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS
Post Reply