Page 1 of 1

Using LDT for only some tasks

Posted: Mon Dec 30, 2013 8:58 pm
by yee1
Hey,

How if I would like to use LDT for only some tasks ?

Is it possible or not ? If not, then why ?

I am currently adding LDT (code, data, stack, screen memory b8000) to my kernel and I have spotted some problems. I have 4 tasks and I have added LDT to one task and it seems to be working in strange way, task switching in Bochs stopped working but no error message, but virtual box returns exception.

I have prepared new entry in GDT (ATTRIBUTE=82h). For task that is using LDT i set offset 0x60 where i set selector of gdt's entry. All seems to be fine, but it's not working.

What may be the reason ?

Thank you for help, yee1

Re: Using LDT for only some tasks

Posted: Mon Dec 30, 2013 11:01 pm
by thepowersgang
You have not provided us with any really useful information for debugging (bochs' debug output is always useful, even nicer if you actually read it yourself).

Without this, I'm forced to question why you are using LDTs. Usually the only use an LDT would have is for providing selectors for thread-local storage (which from your post, I'd assume you're not doing). We generally suggest that inexpirenced members stick to a flat memory model and avoid using segmentation past what is strictly nessesary, and avoid using hardware task switching.

Re: Using LDT for only some tasks

Posted: Tue Dec 31, 2013 3:32 am
by rdos
The typical use of the LDT is to support a segmented memory model for applications. Thus, the LDT would be shared between threads in an application, and another application could use a second LDT. You should especially note that two programs (or tasks as in your example) using different LDTs cannot exchange LDT descriptors, but then need to share memory mapped to GDT selectors. That's also why threads in the same application should have the same LDT.

In short, in a segmented memory model, the GDT is used in kernel because selectors in the kernel typically need to be global, while applications would use LDT selectors.

Re: Using LDT for only some tasks

Posted: Tue Dec 31, 2013 4:48 pm
by yee1
It seems I have solved this problem.

Problem was that i was using IRQ0 and IRQ1 interrupts in same context of DS segment before I have written code of LDT mechanism. After LDT was added to one of the tasks problem occurred, because IRQ0 and IRQ1 were referencing to some data of DS segment (like number of ticks, keyboard buffer) and task with LDT implemented (different base address and limit than before) lost access to it and was referencing to some address space that was wrong. After changing DS base address and limit (temporary) to common with other tasks all started working fine.

Sorry I haven't posted any code, but I wasn't able to define my problem precisely and I wasn't also able to cut some parts of my code to show where is the problem, because my kernel is quite "big" at the moment.

Thanks for suggestions!