Hello all.

Tell me about the purpose of 'LTR(load task register)' command.
I don't know why LTR command used.
In the x86 datasheets, they described LTR command generally is used during system initialization.
But, i dont know when the task register(stored during system initialization) is used after setting up..

In my codes, i just jumped to TSS32 DESCRIPTOR right away without setting initial TASK REGISTER value.
Afterwards, my program was crushed.
So, i set the initial TASK REGISTER same as TSS32 DESCRIPTOR. (in my codes, only one TSS32 descriptor exist)
And, this codes work okay without no errors!
why..????? why should i set the initial task register value???

thankyou for reading.
regards..
Posted on 2003-08-24 10:06:49 by Yeori
you know, that task registers are just selectors of gdt-entries with the flags set as tss. by that register the cpu knows to what segment the current taskstate has to be duped to.
i handle things that way in my os:
i initialize the complete system with all its hardware and paging-thingys. then i reserve some memory for the tss of the system (the os-task) and set up a gdt-entry for that place as tss. and load that selector with ltr - the cpu now knows where to store the taskstate on the first taskswitch.
when there is just one task, never jump/switch to the current tss (i.e. current tss != new tss), it will cause a gpf.
Posted on 2003-08-24 14:01:45 by hartyl
Is the TSS descriptor(which was loaded by 'LTR' instruction during system initialization) never used again???

and, How many TSS descriptors are necessary to complete the multi-tasking?
Posted on 2003-08-24 19:03:18 by Yeori
well, again from beginning (i've written half of that text before my system crashed...):
i'll start off the basics: a tss (taskstate segment) is a piece of memory (at least 104 bytes) containing the information (registers, cr3, stacks for other previlege levels) of one task. a tss (taskstate selector) is a gdt-entry (i don't know if ldt also, but i don't believe). that entry must have some bits set to make it a 32bit tss. the base of that entry "points" to a piece of memory reserved for a task where the cpu can store te taskstate to.
now, here comes the basic multitasking (the simple one):
the cpu has some built in features to make an easy taskswitch.
- create a ts-selector and reserve enough memory for the taskstate. load the task-register with that tss (with the ltr-instruction).
- make some more tasks; each one needs its own ts-selector and ts-segment. when you create the tasks, you have to kind of initialize that task. i.e. set the eip-value to the entry-point, set cs, ds, ss, esp, eflags, maybe cr3
- now, to cause a taskswitch make an intersegmented jump to a tss (jmp tss:0x00000000), or its also possible to make that with an iret-instruction when the nt-flag of the elfags-register is set.
- the make the multitasking complete you need an external trigger that causes that taskswitch, usually you use a timer at 100 or 1000Hz. the timer-handler switches to the next task each time.

backgrounds of the taskswitch:
the taskregister holds the currently used tss. if a taskswitch is caused the cpu transfers (almost) all its information into the memory and gets the new task-info. so, say you have that code:


mov ax,0x0030
ltr ax
jmp 0x0038:0x00000000

assuming 0x0030 and 0x0038 are tss. the ltr-instruction loads the value of ax (0x0030) into the task-register. 0x0030 and 0x0038 are gdt-entries that "point" to at least 104 bytes memory the cpu can use (each one to a seperate).
when the cpu executes the jump-instruction following happens:
- all taskstate-information is stored to the current tss (which holds the task-register)
- the new task-register is loaded (0x0038 in that case)
- all taskstate-information is loaded from the new tss
- the execution continues for the new task, the old task will continue executing if you make a jump to 0x0030

you see, it's damn easy since you just need tss (as many as there are tasks) and jump the the selectors - everything else does the cpu.
i hope that essay helped.
Posted on 2003-08-25 16:19:06 by hartyl
I did it!

Four threads run okay within my poor os.. :)
Thank you!
Posted on 2003-08-26 15:29:10 by Yeori
congrats, man; this is a big step in the system-development.
i've reimplemented it im my paging-approach of my system. i have 256 tasks running... :cool:
Posted on 2003-08-26 15:33:41 by hartyl
You both are The Greatest !!! Everything you done is before me and it sounds like black magic. :(
Posted on 2003-09-06 11:01:45 by etn
thanks man, but don't worry. everybody started off from zero. i was in the same situation as you are when i begun developing. things get clearer when you read into them and make the first tries. i didn't know anything of what i'm doing now when i started coding.
Posted on 2003-09-06 14:33:16 by hartyl