How to write a TSS (in assembly)

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.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: How to write a TSS (in assembly)

Post by kzinti »

thewrongchristian wrote:I can sort of perhaps see that it aligns with the 32-bit TSS, and its offsets for ESP[0,1,2], but why did they have to? They literally had no compatibility baggage to worry about.
What do you base that conclusion on? It seems to me that this would simplify the hardware design. It totally makes sense to keep both structures aligned to re-use common silicon paths. Not that I know how it was implemented... Perhaps they just wanted to re-use part of the existing design and copy it somewhere else on the chip. Who knows what other hardware constraints / optimizations are relevant here?

For example, it is very likely that the "io map" of both structures are driven by the same silicon or the same design. Hence it makes sense for them to be in the same location and format. It also probably make it possible to reuse the same validation tests.
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: How to write a TSS (in assembly)

Post by Schol-R-LEA »

bzt wrote:
rizxt wrote:Also, it's written in C and generated at runtime. I'm not a fan of that.
[...] you could create 255 TSS segments statically [...] It isn't more complicated than to create 256 IDT entries statically.
Yes, but isn't that a moot point, though? It is easy enough to have a dynamically generated TSS in assembly using (assuming NASM, which is what rizxt is using) the struc directive to define the structure.

Code: Select all

struc Task_State_Segment
    .reserved_0              resd 1        
    .RSP                     resq 3          ; RSP0 - RSP2
    .reserved_1              resq 2
    .interrupt_stack_table   resq 7          ; IST1 - IST7
    .reserved_2              resq 2
    .reserved_3              resw 1
    .IOPB_offset             resw 1
endstruc 
You can define the structure with that, then set aside memory space for it at runtime from some preset pool.

If you definitely want some or all of them to be defined statically, you can still use an istruc to initialize it at assemble time.

Code: Select all

TSS_0:
    istruc Task_State_Segment
        at reserved_0,             dd 0        
        at RSP,                    dq ring0, ring1, ring2 
        at reserved_1,             dd 0
        at interrupt_stack_table,  dq i1, i2, i3, i4, i5, i6, i7             
        at reserved_2,             dd 0
        at reserved_3,             dw 0    
        at IOPB_offset,            dw quux
    iend 
You might want to define one or more macros for manipulating the RSP and IST arrays.
Last edited by Schol-R-LEA on Fri Feb 19, 2021 3:52 pm, edited 4 times in total.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

Re: How to write a TSS (in assembly)

Post by austanss »

I must mention this thread has grown irrelevant for me as I have managed to write a functional TSS, although not in assembly. Currently I am working on syscalls, namely configuring the stack on entry.

Your insight is still welcome.
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: How to write a TSS (in assembly)

Post by Schol-R-LEA »

Ah, just as well; I realized I'd made at least one mistake in my post (which I corrected, but there may be others).
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
sj95126
Member
Member
Posts: 151
Joined: Tue Aug 11, 2020 12:14 pm

Re: How to write a TSS (in assembly)

Post by sj95126 »

bzt wrote:You can easily generate the TSS from Assembly
It's not even that hard. I dynamically generate a TSS and add it to the GDT in about 15 or so assembly instructions.
Post Reply