first task enabling 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
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

first task enabling question

Post by kop99 »

Hi, everybody...

I'm trying to implement of multitasking now.
And I already read intel manuals and searched a lot of OSDev post.
So I have a little picture of multitasking.
But I have some question.

if after all initializing(gdt, idt, pm, page, etc), I load valid tss using "ltr" asm command,
then first task was starting that point?

And if anyone know the url or source code about first task enabling and software multitasking, please let me know.....

Thanks for your reguards
User avatar
Combuster
Member
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: first task enabling question

Post by Combuster »

Define "first task", then know the answer
"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 ]
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: first task enabling question

Post by kop99 »

If I want to enable the single task or multitasking, the first thing is maybe the initialization of tss.
Then I've initialized tss, and load that to tr register.
Following is my code.

tss structure...

Code: Select all

#pragma pack(push, 1)

typedef struct tss {
	WORD	ptl;
	WORD	rsv1;
	DWORD	esp0;
	WORD	ss0;
	WORD	rsv2;
	DWORD	esp1;
	WORD	ss1;
	WORD	rsv3;
	DWORD	esp2;
	WORD	ss2;
	WORD	rsv4;
	DWORD	cr3;
	DWORD	eip;
	DWORD	eflags;
	DWORD	eax;
	DWORD	ecx;
	DWORD	edx;
	DWORD	ebx;
	DWORD	esp;
	DWORD	ebp;
	DWORD	esi;
	DWORD	edi;
	WORD	es;
	WORD	rsv5;
	WORD	cs;
	WORD	rsv6;
	WORD	ss;
	WORD	rsv7;
	WORD	ds;
	WORD	rsv8;
	WORD	fs;
	WORD	rsv9;
	WORD	gs;
	WORD	rsv10;
	WORD	ldtss;
	WORD	rsv11;
	WORD	trsv;
	WORD	iomba;
} tss;

#pragma pack(pop)
tss load with ltr command...

Code: Select all

tss    task0;

void init_tss(tss *ptss)
{
	ptss->esp0 = get_esp();
	ptss->ss0 = __KERNEL_DS;
	ptss->cr3 = get_cr3();
	ptss->es = __KERNEL_DS;
	ptss->ds = __KERNEL_DS;
	ptss->fs = __KERNEL_DS;
	ptss->gs = __KERNEL_DS;
	ptss->ss = __KERNEL_DS;
	ptss->cs = __KERNEL_CS;
	ptss->ldtss = 0;
	ptss->trsv = 0xFFFF;
}

void init_task()
{
	init_tss(&task0);
	set_gdt_table_entry(5, (DWORD)&task0, sizeof(task0),
		GDT_ACC_TSSPRESENT | GDT_ACC_TSSTYPE, GDT_ATT_DEFBIT);
	load_tr((WORD)0x28);

	while (1);
}
in asm file...

Code: Select all

_load_tr:
	push  ebp
	mov   ebp, esp 
	push  eax
	
	mov		ax, word [ss:ebp + 8]
	ltr		ax
	
	pop      eax
	pop      ebp
	retn
and it works fine without no fault or error....
But then, is that success of task enabling?
So, What is the first task?
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: first task enabling question

Post by kop99 »

I'm going to implement software multitasking...
But I don't have clear picture of it.
So any software multitasking tutorial, code, or implementation spec is very helpful...
Please tell me, where to start.......
Post Reply