Making a task switcher “from scratch”. Some problems..
Hi all :)
Since more days, I develop "from scratch" my "task switcher" on FreeDos in asm/c++
for preemption. * I succeeded to create stack memory in array, for each
tasks added. * I was not able to "switch" with two stack in asm inline (in Task_Switch() function) .. CRASH
If someone can take his time resolve my problem ? What i forgot ? :-(
Re: Making a task switcher “from scratch”. Some problems..
> Since more days, I develop "from scratch" my "task switcher" on FreeDos in asm/c++
> for preemption.
Have you tried improving the existing TriDOS instead?
> * I succeeded to create stack memory in array, for each
> tasks added.
> * I was not able to "switch" with two stack in asm inline
Try to switch only at "smart" moments. For example let programs
switch when they try to call int 21, by hooking int 21, but do
NOT switch while int 21 is already busy. Check the InDOS flag,
as well as related data. The problem is similar to what you get
with some TSR / hotkey systems, so a howto for that will also
help you to understand task switching. When switching between
tasks, you may also want to swap the contents of the SDA (DOS
swappable data area) and the DOS stack. Basically it is tricky
enough to swap tasks to give MS a good excuse why Windows even
refused to do it on non-Microsoft DOS in the beginning... :-p
Note that using DJGPP makes things even a lot more complicated,
because DJGPP programs always are DPMI tasks in protected mode,
usually with CWSDPMI as their protected mode host... So even for
simply calling DOS or BIOS from a DJGPP program, you have to be
careful to not fall into the gap between protected mode and DOS
and DJGPP only does it automatically for you in easy cases. For
others, you have to explicitly tell DJGPP how to bridge that gap.
Thank you very much for your explanations, I'm a bit more brightens. :)
But I think that I not explained the conditions, it's not explicitely "Task switcher for FreeDos" but more "Task Switcher for internal threads/functions" / "Stack switcher" or "Context switcher" In my .exe program directly.
During more years, i used Pthead or LWC for DJGPP, but his task manager is cooperative. "yelding" all loops is very dirty, and not serious for our project. And I want that my DOS exe program can switch his task (current stack pointer) by timer handler managed by IRQ0 with 0x08 vector (Or 0x09 for switch manually with keyboard). Mutexs and seamphores are not a problem ;).
I've tested more Borland C 16bits programs online source code for switch tasks between functions with « while(1); » under FreeDos this works.!
I must to use GCC / G++ / DJGPP for DOS, I started to write my task switching (for internal function) and I've some difficulties :/
In my ZIP in my first post, I have agood beginning, I can create tasks with his stack memory and stask pointer location and a task pool array. (After i will include priorities etc..) I've toto() and tata() functions, he blocks to toto() with while(1); it's normal. My Task switcher must to interrupt this current loop in toto() task, saving his registers, switching this current stack pointer with the new stack pointer tata(), pop his registers and continue..
It's just this part that I despair :( I'm sure that i forgot c++/asm steps! ) I've "task switcher documentation" but I blocking, if you can help me .. :/