New tutorial on getting to user mode

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).
Post Reply
xarnze
Posts: 19
Joined: Thu Nov 02, 2006 4:45 pm
Location: United Kingdom
Contact:

New tutorial on getting to user mode

Post by xarnze »

Hi everyone,

I have writen a tutorial on getting to user mode and would be greatfull if some of you would look over it for correctness, the link to the tutorial is Link to tutorial.
Any improvements or suggestions are welcome.

Thank you in advanced for your help.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: New tutorial on getting to user mode

Post by earlz »

I haven't started the read yet, but I would recommend having both a PDF and HTML/In browser version (remember not all of us have PDF-Browser integration)
xarnze
Posts: 19
Joined: Thu Nov 02, 2006 4:45 pm
Location: United Kingdom
Contact:

Re: New tutorial on getting to user mode

Post by xarnze »

I have made a Html copy of the Tutorial, and it is available here
xarnze
Posts: 19
Joined: Thu Nov 02, 2006 4:45 pm
Location: United Kingdom
Contact:

Re: New tutorial on getting to user mode

Post by xarnze »

Hi,
that code was left over from the multiple CPU implimentation, I've now fixed it thank you for pointin it out. the links above now point to the updated version.

Thank You
xarnze
Posts: 19
Joined: Thu Nov 02, 2006 4:45 pm
Location: United Kingdom
Contact:

Re: New tutorial on getting to user mode

Post by xarnze »

I really was aiming at just giving people a idea of how it could be implemented, as when i was implementing it I found it somwhat hard to get all the right parts in it, and all the documents that i looked at to start off with whent over it with huge amounts of detail adding in parts that at the time i was not interested in implementing. My aim was more just to provide the information that you would need to get into user mode to start off with, I thought that it would be better if you could understand how to get to user mode and then start adding extras. As a result some of the detail has been left out just to make it a bit more understandable, off course once you've got into user mode I would still advise you to add to the implementation.

Thank you for your feedback, more is welcome of course.
Cognition
Member
Member
Posts: 191
Joined: Tue Apr 15, 2008 6:37 pm
Location: Gotham, Batmanistan

Re: New tutorial on getting to user mode

Post by Cognition »

I thought it was pretty good, the first page in the HTML version doesn't seem to render as cleanly under Firefox where the second box around eflags forms but it's still readable. A brief explanation of a selector's RPL field and structure might help clarify how the code at the end actually functions as well.
Reserved for OEM use.
apollo
Posts: 2
Joined: Mon Aug 24, 2009 6:33 pm
Location: Earth, Europe, Germany, Heidelberg

Re: New tutorial on getting to user mode

Post by apollo »

This is my first post here so ... Hello everyone :-)

Nice little tutorial you've got there. But i noticed two things:

That's the way you set your TSS descriptor:

Code: Select all

unsigned long addr=(unsigned long)tss;
int size = sizeof(tss_struct)+1;
gdt_set_gate(5,addr,addr+size,0x89,0xCF)
But the intel-docs say "The base address specifies the linear address of byte 0 of the TSS; the segment limit specifies the number of bytes in the TSS." (3A 2.4.4)
I set my limit like this and it works fine for me:

Code: Select all

gdt_set_entry(5, (uint32_t)&tss, sizeof(tss_t), 0x89, 0);
Not sure if it matters at all though :?:

And I believe you misplaced the __attribute__((packed)) statement in your TSS structure:

Code: Select all

typedef volatile struct strtss{
/* ... */
} tss_struct __attribute__((packed));
This little demonstration will output something like "8 5 8".

Code: Select all

#include <stdio.h>
#include <stdint.h>

typedef struct {
	uint8_t a;
	uint32_t b;
} a_t;

typedef struct {
	uint8_t a;
	uint32_t b;
} __attribute__((packed)) b_t;

typedef struct {
	uint8_t a;
	uint32_t b;
} c_t __attribute__((packed));

int main(int argc, char **argv) {
	printf("%u %u %u\n", sizeof(a_t), sizeof(b_t), sizeof(c_t));
	return 0;
}
My gcc even generates a warning on your struct ("warning: ‘packed’ attribute ignored"). But it doesn't matter in your case because you only have 32bit and 2x16bit types in your struct. In this case the compiler is "packing" them even if you don't explicitly tell him to do so.

I hope the above is correct and will help :-)
xarnze
Posts: 19
Joined: Thu Nov 02, 2006 4:45 pm
Location: United Kingdom
Contact:

Re: New tutorial on getting to user mode

Post by xarnze »

Thank you for pointing that out iv'e fixed the tutorial and updated the links. Any more comments would be appreciated.
Post Reply