tut23 - User Land

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator: Moderators

tut23 - User Land

Postby Insightsoft » Tue Jun 07, 2011 12:22 pm

Hi,

I need a small explanation about this chapter... more about your insight

about running code on user land.. on machine point of view

01) user type 'user'
02) -There is GDT entry 5, pointing to TSS structure
03) -TSS: some fields are pointing to kernel (code and data) with rpl=3
04) -TSS: ss0 and espy are pointing to kernel:stack for (safety return); TR is set (LTR)
05) -There is 2 GDT entries, for user (code and data)
06) -segments are set to use 5)
07) -Artificial stack is builded to use iretd
08) -after iretd the system will be at 0x1b:label (at user land)
09) -...int 0x80
10) An IDT entry that will catch the Dispatcher;
11) Dispatcher get the index that will correspond to one function entry point
12) Execute that function and return...

My question is: what is the correlation with TSS? (since we don't jump or call that particular gdt entry... (we set TR). And setting only ss0 and esp0, living all others fields with '0', works in same way)
_____________
Think it, build it, bit by bit...
Insightsoft
 
Posts: 63
Joined: Wed Jul 22, 2009 6:44 am

Re: tut23 - User Land

Postby Mike » Fri Jun 10, 2011 7:29 pm

Hello,

TSS is required when returning from user mode to kernel mode. This is a CPU requirement. Because we dont use the TSS for any other purpose, we only set the required fields used by the CPU when the task switch occurs.

-...during process initialization...
-LTR loads TSS segment into TR;
-CPU caches TSS base and limit into invisible portions of TR;
-...when we enter user mode with IRETD and CPL=3...
-...int 0x80 is executed...
-CPU uses TR information to find TSS;
-CPU loads SS:ESP with kernel mode stack from TSS;
-CPU calls syscall dispatcher

Additional use of the TSS for hardware tasking, PIO, or INT permissions are not used so other fields are unused.
User avatar
Mike
Site Admin
 
Posts: 463
Joined: Sat Oct 20, 2007 7:58 pm

Re: tut23 - User Land

Postby Insightsoft » Sun Jun 12, 2011 7:01 pm

Thank you Mike...
_____________
Think it, build it, bit by bit...
Insightsoft
 
Posts: 63
Joined: Wed Jul 22, 2009 6:44 am


Return to Beginning OS Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron