Task State Segment: Difference between revisions
[unchecked revision] | [unchecked revision] |
Content deleted Content added
Revolution (talk | contribs) Redo wikitables and flesh out article information around tables. |
|||
Line 1:
==
For its use in hardware task switching, a '''TSS''' contains a program's state, including '''[[CPU Registers x86#General Purpose Registers|General Purpose Registers]]''', '''[[Segment Selector|Segment Selectors]]''', the '''[[CPU Registers x86#General Pointer Registers|Instruction Pointer]]''', the '''[[CPU Registers x86#EFLAGS Register|EFLAGS Register]]''' and '''[[CPU Registers x86#CR3|Control Register 3]]'''. It contains certain other fields described below.
{|class="wikitable"
|-
!style="width: 20%;"| 0x3
!style="width: 20%;"| 0x2
!style="width: 20%;"| 0x1
!style="width: 20%;"| 0x0
!style="width: 20%;"| Offset
|-
|colspan=4 style="text-align: center;"| '''SSP'''
!0x68
|-
|colspan=2 style="text-align: center;"| '''IOPB'''
|
!0x64
|-
|colspan=2 style="text-align: center;"| Reserved
|colspan=2 style="text-align: center;"| '''LDTR'''
!0x60
|-
|colspan=2 style="text-align: center;"| Reserved
|
!0x5C
|-
|colspan=2 style="text-align: center;"| Reserved
|colspan=2 style="text-align: center;"| '''FS'''
!0x58
|-
|colspan=2 style="text-align: center;"| Reserved
|
!0x54
|-
|colspan=2 style="text-align: center;"| Reserved
|colspan=2 style="text-align: center;"| '''SS'''
!0x50
|-
|colspan=2 style="text-align: center;"| Reserved
|
!0x4C
|-
|colspan=2 style="text-align: center;"| Reserved
|
!0x48
|-
|colspan=4 style="text-align: center;"| '''EDI'''
!0x44
|-
|colspan=4 style="text-align: center;"| '''ESI'''
!0x40
|-
|colspan=4 style="text-align: center;"| '''EBP'''
!0x3C
|-
|colspan=4 style="text-align: center;"| '''ESP'''
!0x38
|-
|colspan=4 style="text-align: center;"| '''EBX'''
!0x34
|-
|colspan=4 style="text-align: center;"| '''EDX'''
!0x30
|-
|colspan=4 style="text-align: center;"| '''ECX'''
!0x2C
|-
|colspan=4 style="text-align: center;"| '''EAX'''
!0x28
|-
|colspan=4 style="text-align: center;"| '''EFLAGS'''
!0x24
|-
|colspan=4 style="text-align: center;"| '''EIP'''
!0x20
|-
|colspan=4 style="text-align: center;"| '''CR3'''
!0x1C
|-
|colspan=2 style="text-align: center;"| Reserved
|colspan=2 style="text-align: center;"| '''SS2'''
!0x18
|-
|colspan=4 style="text-align: center;"| '''ESP2'''
!0x14
|-
|colspan=2 style="text-align: center;"| Reserved
|colspan=2 style="text-align: center;"| '''SS1'''
!0x10
|-
|colspan=4 style="text-align: center;"| '''ESP1'''
!0x0C
|-
|colspan=2 style="text-align: center;"| Reserved
|colspan=2 style="text-align: center;"| '''SS0'''
!0x08
|-
|colspan=4 style="text-align: center;"| '''ESP0'''
!0x04
|-
|colspan=2 style="text-align: center;"| Reserved
|colspan=2 style="text-align: center;"| '''LINK'''
!0x00
|}
* '''LINK:''' Previous Task Link Field. Contains the '''Segment Selector''' for the '''TSS''' of the previous task.
* '''SS0, SS1, SS2:''' The '''Segment Selectors''' used to load the stack when a privilege level change occurs from a lower privilege level to a higher one.
* '''ESP0, ESP1, ESP2:''' The '''Stack Pointers''' used to load the stack when a privilege level change occurs from a lower privilege level to a higher one.
* '''IOPB:''' I/O Map Base Address Field. Contains a 16-bit offset from the base of the '''TSS''' to the '''I/O Permission Bit Map'''.
* '''SSP:''' Shadow Stack Pointer.
== Long Mode ==
In '''[[Long Mode]]''', the '''TSS''' does not store information on a task's execution state, instead it is used to store the '''Interrupt Stack Table'''.
{|class="wikitable"
|-
!style="width: 20%;"| 0x3
!style="width: 20%;"| 0x1
!style="width: 20%;"| 0x0
!style="width: 20%;"| Offset
|-
|colspan=2 style="text-align: center;"| '''IOPB'''
|
!0x64
|-
|colspan=4 style="text-align: center;"| Reserved
!0x60
|-
|colspan=4 style="text-align: center;"| Reserved
!0x5C
|-
|colspan=4 style="text-align: center;"| '''IST7''' (High)
!0x58
|-
|colspan=4 style="text-align: center;"| '''IST7''' (Low)
!0x54
|-
|colspan=4 style="text-align: center;"| '''IST6''' (High)
!0x50
|-
|colspan=4 style="text-align: center;"| '''IST6''' (Low)
!0x4C
|-
|colspan=4 style="text-align: center;"| '''IST5''' (High)
!0x48
|-
|colspan=4 style="text-align: center;"| '''IST5''' (Low)
!0x44
|-
|colspan=4 style="text-align: center;"| '''IST4''' (High)
!0x40
|-
|colspan=4 style="text-align: center;"| '''IST4''' (Low)
!0x3C
|-
|colspan=4 style="text-align: center;"| '''IST3''' (High)
!0x38
|-
|colspan=4 style="text-align: center;"| '''IST3''' (Low)
!0x34
|-
|colspan=4 style="text-align: center;"| '''IST2''' (High)
!0x30
|-
|colspan=4 style="text-align: center;"| '''IST2''' (Low)
!0x2C
|-
|colspan=4 style="text-align: center;"| '''IST1''' (High)
!0x28
|-
|colspan=4 style="text-align: center;"| '''IST1''' (Low)
!0x24
|-
|colspan=4 style="text-align: center;"| Reserved
!0x20
|-
|colspan=4 style="text-align: center;"| Reserved
!0x1C
|-
|colspan=4 style="text-align: center;"| '''RSP2''' (High)
!0x18
|-
|colspan=4 style="text-align: center;"| '''RSP2''' (Low)
!0x14
|-
|colspan=4 style="text-align: center;"| '''RSP1''' (High)
!0x10
|-
|colspan=4 style="text-align: center;"| '''RSP1''' (Low)
!0x0C
|-
|colspan=4 style="text-align: center;"| '''RSP0''' (High)
!0x08
|-
|colspan=4 style="text-align: center;"| '''RSP0''' (Low)
!0x04
|-
|colspan=4 style="text-align: center;"| Reserved
!0x00
|}
* '''RSP0, RSP1, RSP2:''' The '''Stack Pointers''' used to load the stack when a privilege level change occurs from a lower privilege level to a higher one.
* '''IST#:''' Interrupt Stack Table. The '''Stack Pointers''' used to load the stack when an entry in the '''[[Interrupt Descriptor Table#Long Mode|Interrupt Descriptor Table]]''' has an '''IST''' value other than 0.
* '''IOPB:''' I/O Map Base Address Field. Contains a 16-bit offset from the base of the '''TSS''' to the '''I/O Permission Bit Map'''.
== TSS in software multitasking ==
For each CPU which executes processes possibly wanting to do system calls via interrupts, one TSS is required. The only interesting fields are SS0 and ESP0. Whenever a system call occurs, the CPU gets the SS0 and ESP0-value in its TSS and assigns the stack-pointer to it. So one or more kernel-stacks need to be set up for processes doing system calls. Be aware that a thread's/process' time-slice may end during a system call, passing control to another thread/process which may as well perform a system call, ending up in the same stack. Solutions are to create a private kernel-stack for each thread/process and re-assign esp0 at any task-switch or to disable scheduling during a system-call (see also [[Kernel Multitasking]]).
|