OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 3:19 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: TSS/Ring 3 tutorial
PostPosted: Wed Jun 03, 2009 5:16 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
I wrote a tutorial in the past 2 hours over getting to ring 3 and such(it's still not done for theory and such and the code is rather hackish)

But I think it's close enough to be counted as a tutorial... so what section should it be under in the tutorials? cause it's not bare bones and it's not "kernel basics"

I think a new section should be created but I'm not sure.. also, I'm not sure on the rating either.. I would probably give it a 2 or 3..

The link is http://wiki.osdev.org/Getting_to_Ring_3 btw..

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Wed Jun 03, 2009 6:28 pm 
Offline
Member
Member

Joined: Sat Dec 30, 2006 2:31 pm
Posts: 729
Location: East Coast, USA
Only one comment. I am sure that during an interrupt in user mode only the ss and esp from the TSS are loaded by the processor. The ISR has to load the segment registers for itself, all except cs.

_________________
My OS: Fuzzy Logic


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Wed Jun 03, 2009 7:17 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
frank wrote:
Only one comment. I am sure that during an interrupt in user mode only the ss and esp from the TSS are loaded by the processor. The ISR has to load the segment registers for itself, all except cs.


oh yea, that makes sense.. I didn't pay too much attention to the manuals lol

I'll have to change that..

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Mon Jun 08, 2009 6:20 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 03, 2008 4:13 am
Posts: 153
Location: Ogre, Latvia, EU
I have additional comment.

Recently I was wondering, why my userspace code is not GPFing on I/O port access, when it should. My write_tss() code was similar to one in JamesM tutorial.

However, when not using iomap, limit should be:
Code:
uint32_t limit = sizeof(tss_entry)-1;  // 0x67

_________________
If something looks overcomplicated, most likely it is.


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Mon Jun 08, 2009 10:25 am 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
I really do not know much on the io permission bitmap stuff.. if anyone can add some info like that to my article, it'd be great..

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Mon Jun 08, 2009 4:28 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
I doubt JamesM likes you ripping off his code. Especially since he hasn't ever said you could do so.

Killed half the page until you have asked for permission.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Mon Jun 08, 2009 6:23 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
If you look at it, really the only "exact" rip off of the code is the tss_flush and set_kernel_stack

Really, how would you make the structure any different? it's not even the same cause I use uint32_t and friends. The write_tss is derived from his code, but much different because of how I treat the GDT plus, I removed his "bug" about writing the segments into the TSS(really it has no effect, which is exactly the point. It's not needed, so I removed it)

the entering ring 3 portion also is only derived from it. The tutorial involves a slightly complex method of jumping to EIP in ring 3. where I use a simple label to enter ring 3. I think every OS does this to a certain extent.

My own OS code is closer to JamesM tutorial than this code and such here. And all of the text is based nothing off of his tutorial. I wrote it from scratch without consulting any other sources..

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Tue Jun 09, 2009 1:54 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7614
Location: Germany
IMHO, and without being a good judge on TSS stuff as I have never written such myself:

Anything offered as tutorial to other people should be written in full knowledge of the manuals, ideally while teaching the elementary knowledge behind the code as instructive as possible.

I've seen too much "this works for me" code being perpetuated by someone putting it on the 'net and others copypasting it to feel comfortable with this.

As I said, I'm not the TSS guru. Your page is a start, but it has a long way to go.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Tue Jun 09, 2009 3:24 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
@Earl: copyright infringement happens independent of the size of the copied portion. Converting ATT syntax to its exact intel counterpart doesn't solve the problem either - it's still someone else's code, presented in a different fashion.

It's like changing variable names to foil school's fraud checker.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Tue Jun 09, 2009 5:00 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7614
Location: Germany
Just ask JamesM's permission to use his code as a basis. I'd be surprised if he wouldn't give it. That's really the easiest way to solve this.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Tue Jun 09, 2009 6:18 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
If someone asks me I'd be happy to give permission (on the proviso that the information's original source is stated somewhere).

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Tue Jun 09, 2009 9:16 am 
Offline
Member
Member
User avatar

Joined: Fri Apr 18, 2008 4:40 pm
Posts: 1686
Location: Langley, Vancouver, BC, Canada
Combuster wrote:
It's like changing variable names to foil school's fraud checker.

Or using mibbit to get around a school's IRC/MSN blocker (and yes, I am known to do that.. :mrgreen: ) Any way you look at ways to get around copyright, it's just another attempt to mask the truth.

JamesM wrote:
If someone asks me I'd be happy to give permission (on the proviso that the information's original source is stated somewhere).

And there you have it. The answer. :)

_________________
Image
Image
Solar wrote:
It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.

I wish I could add more tex


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Tue Jun 09, 2009 6:42 pm 
Offline
Member
Member

Joined: Sun Oct 05, 2008 5:00 am
Posts: 163
Location: Copenhagen, Denmark
Hi

Combuster wrote:
@Earl: copyright infringement happens independent of the size of the copied portion. Converting ATT syntax to its exact intel counterpart doesn't solve the problem either - it's still someone else's code, presented in a different fashion.

It's like changing variable names to foil school's fraud checker.

The case is actually not nearly as clear as you try to indicate. Similarities in code are often dictated by functional contraints of the hardware. Therefore two pieces of code written independtly can often be very similiar. Even more so with low-level code as the code in question.

A famous case is NEC vs. Intel. NEC produced a clean room implementation of the micro code in question that was more similiar than the code Intel disputed. PDF

I know the circumstances are different here. Earlz openly says he has seen JamesM's code (and is basing his own on it). Just remeber that copright issues are not always clear :D

clange


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Mon Jul 04, 2011 4:07 pm 
Offline

Joined: Tue Dec 15, 2009 1:04 am
Posts: 8
for those wondering...but you still neeed a TSS and syscalls:

this is CLOSE(and I use FPC)[need to rectify my bugs]:
(must be in OS init prt0 or similar file or it WILL NOT WORK.)

extern UserESP
global switch_to_user_mode
switch_to_user_mode:
cli ;there is especial way to turn interrupts on for user mode, sti will NOT do it.
mov dword eax,$23
mov word ds,ax
mov word es,ax
mov word fs,ax
mov word gs,ax
mov eax,UserESP
push dword $23
pushf
push dword $1b
push dword eax

push dword $23
iret
jmp 0x1b:user
user:


----
as per comments:
This is how hardware is interfaced via INTEL specs, not Mike or JamesM.....READ the FARKING manual next time....they just so happenstace to do it semi-correct in C.

Noticed quite a few issues with JamesM's code myself. His code is those learning. You cant learn if you dont code or know.Check his forums, he fixes the code, but does not update it.

Secondly:
I dont think he cares so much. Its FOR PERSONAL code(USE ONLY), and its GNU Licensed.If he didnt want to code copied, he should have posted a DIFFERENT licence. There's no going back now.

Think HARD BEFORE you CHOOSE a licence.It determines how much money and credit you get ALSO.

Tuff cookies if you didnt think ahead of time. Even Lawyers will tell you that. If youve gotten this far, THIS ISNT homework, why not quit bickering and help work on the LOGIC to make *NIX (or whatever) BETTER for whatever ARCH or system you are writing for instead of flaming one another?

..or is that ALL you can do instead of code?

i dont know about YALL, but I CODE for a LIVING.


Top
 Profile  
 
 Post subject: Re: TSS/Ring 3 tutorial
PostPosted: Mon Jul 04, 2011 4:11 pm 
Offline

Joined: Tue Dec 15, 2009 1:04 am
Posts: 8
Like so, pardon my bad code before:
(just like the C example)

;THIS IS HOW ITS DONE BOYS!!
extern UserESP
global switch_to_user_mode
switch_to_user_mode:
cli ;there is especial way to turn interrupts on for user mode, sti will NOT do it.
mov dword ax,$23
mov word ds,ax
mov word es,ax
mov word fs,ax
mov word gs,ax
mov eax,UserESP
push dword $23
push dword eax
pushf
push dword $1b
jmp 0x1b:user
iret
user:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group