Making a task switcher “from scratch”. Some problems..

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Making a task switcher “from scratch”. Some problems..

cpcdos
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 ? :-(

This is my complet code with Batch file for compile with GCC/G++ (DJGPP for DOS)
http://cpcdos.e-monsite.com/medias/files/task-switch-test.zip

It would be really nice of you..
Best regards,
Sébastien FAVIER

ps:Excuse me for my bad english level, i'm French student :/
and
Sorry to give everything abruptly my code, I prefer to have the same vision of code from your home.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Freedos-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freedos-devel
Reply | Threaded
Open this post in threaded view
|

Re: Making a task switcher “from scratch”. Some problems..

Eric Auer-3

Bonsoir Sebastien!

> 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.

> This is my complete code with Batch file for compile with GCC/G++ (DJGPP for DOS)
> http://cpcdos.e-monsite.com/medias/files/task-switch-test.zip

Cheers, Eric



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Freedos-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freedos-devel
Reply | Threaded
Open this post in threaded view
|

Re: Making a task switcher “from scratch”. Some problems..

cpcdos
In reply to this post by cpcdos
Bonjour Eric!

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 a good 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 .. :/

Regards
Sébastien FAVIER

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Freedos-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freedos-devel