Cooperative Multitasking and Program Execution

General FreeBASIC programming questions.
Post Reply
Schnapsidee
Posts: 10
Joined: Jul 07, 2017 20:20

Cooperative Multitasking and Program Execution

Post by Schnapsidee »

Hey :)

Sorry about the title, I couldn't think about a better one. I am working on a cooperative multitasking process scheduler. I want my program to execute several other programs the same time. It sorta works, but my concept has some big weaknesses. Basically, I am loading an .EXE binary and then "call" it (with Inline ASM). Since I don't want to modify the OS-Systemcalls, I am replacing every Systemcall (Interupt) during loading with a "Return", so the program-execution stops, returns to my scheduler and continues the execution of the next task. Like This:

Code: Select all

'Load program
Do
	Get #file,,opcode
	If opcode=Systemcall Then    'INT Interupt
	    opcode=Return  		     'RET Return
	    Add_Interupt(Seek(ff))
	End If
	program+=opcode
Loop Until Eof(file)

'...

Sub Execute()
	current_interupt=Get_Next_Interupt()
	position=current_interupt.position
	program_pointer=@program+position
	
	Asm
		Call [program_pointer]
	End Asm
	
	If current_interupt=OS_Interupt Then
		'Catch Systemcall and do something
	End If
End Sub
This works for very basic programs, but not with programs manipulating the stack or using their own "calls".

So I need a different possibility to implement Multitasking (without using Threads). I need to catch systemcalls (Interupts), so preemptive multitasking wouldn't work I guess.
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Cooperative Multitasking and Program Execution

Post by marcov »

But the windows system calls are not in loaded EXEs, but in kernel32.dll and user32.dll ? So how does it work even for simple programs?!?
Schnapsidee
Posts: 10
Joined: Jul 07, 2017 20:20

Re: Cooperative Multitasking and Program Execution

Post by Schnapsidee »

It's for DOS-programs only.

EDIT: I am using preemptive Multitasking now, as described in the "isrtimer.bas" example.
Post Reply