TSS/Ring 3 tutorial
TSS/Ring 3 tutorial
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..
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..
Re: TSS/Ring 3 tutorial
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.
Re: TSS/Ring 3 tutorial
oh yea, that makes sense.. I didn't pay too much attention to the manuals lolfrank 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.
I'll have to change that..
Re: TSS/Ring 3 tutorial
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:
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: Select all
uint32_t limit = sizeof(tss_entry)-1; // 0x67
If something looks overcomplicated, most likely it is.
Re: TSS/Ring 3 tutorial
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..
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: TSS/Ring 3 tutorial
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.
Killed half the page until you have asked for permission.
Re: TSS/Ring 3 tutorial
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..
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..
Re: TSS/Ring 3 tutorial
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.
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.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: TSS/Ring 3 tutorial
@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.
It's like changing variable names to foil school's fraud checker.
Re: TSS/Ring 3 tutorial
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.
Re: TSS/Ring 3 tutorial
If someone asks me I'd be happy to give permission (on the proviso that the information's original source is stated somewhere).
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: TSS/Ring 3 tutorial
Or using mibbit to get around a school's IRC/MSN blocker (and yes, I am known to do that.. ) Any way you look at ways to get around copyright, it's just another attempt to mask the truth.Combuster wrote:It's like changing variable names to foil school's fraud checker.
And there you have it. The answer.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).
Re: TSS/Ring 3 tutorial
Hi
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
clange
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.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.
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
clange
Re: TSS/Ring 3 tutorial
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.
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.
Re: TSS/Ring 3 tutorial
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:
(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: