Modify interrupt eip return (Preemptive task-switching)

DOS specific questions.
Post Reply
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Modify interrupt eip return (Preemptive task-switching)

Post by Cpcdos »

Hi,

I investigate to create preemptive multitasking tool project for FB/ DOS, but i've strange problem

First, this is my base :

Code: Select all

INIT_INTERRUPT()
START_INTERRUPT()

while(1)
	print "# Main
Wend

End
' ------------------------------------

sub Task1()
	while(1)
		print " #### Task1"
	wend
end sub

sub Task2()
	while(1)
		print " ######## Task2"
	wend
end sub

' ----------------------------------
Sub INIT_INTERRUPT()

	asm
		jmp 0%f
		DS_SEL:     .short 0
		INT1C_OFF:  .int   0
		INT1C_SEL:  .short 0
	  0:
		mov ax, 0x204
		mov bl, 0x1c
		int 0x31
		jc 1%f
		mov INT1C_SEL, cx
		mov INT1C_OFF, edx
	  1:
	end asm
	
	ISR_ACTIVE = true
End sub

Sub START_INTERRUPT()
	if ISR_ACTIVE = true then
		asm
			mov ax, 0x205
			mov bl, 0x1c   ' I use 1Ch timer
			push cs
			pop cx
			mov edx, OFFSET _MY_INTERRUPT
			int 0x31
			jc 2%f
		  2:
		end asm
	end if
End sub

And my interrupt function :

Code: Select all

sub MY_INTERRUPT naked	
	push eax
	
	' FOR TESTS ONLY , i push directly Task1 address to eax
	mov eax, _Task1
	
	' Push "return eip address" in interrupt stack
	' !!! I add +4 because i've pushed eax before !!!
	mov ss:[esp+4], eax 	

	pop eax
	iret
end sub
I want switch main to Task1 just with EIP (eax, ebx, edx, cr3, others register... and sheduler ... after! ;) )

According to the stack model (Without errors):
Image
We are ok if i push another EIP address in interrupt stack (ss:[ESP]), when iret is executed, it will continue execution from this new EIP ?

This not work.. CRASH :(

PS : According GDB, my new EIP address has been pushed to ss:[ESP] !

Someone have ideas ?
Thank
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Modify interrupt eip return (Preemptive task-switching)

Post by MrSwiss »

Cpcdos wrote:This not work.. CRASH :( Someone have ideas ?
Well, afair, on ISR's you'll have to do:

Code: Select all

Asm
    pusha ' all registers (of interrupted process), onto stack (aka: save)
    ...   ' your code
    popa  ' all registers (of interrupted process), from stack (aka: restore)
    iret
End Asm
This seems to indicate also, that your current ISR attempt, won't work. Sorry.
Last edited by MrSwiss on May 11, 2018 13:51, edited 1 time in total.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Modify interrupt eip return (Preemptive task-switching)

Post by marcov »

Moreover, maybe go32 plays a role too.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Modify interrupt eip return (Preemptive task-switching)

Post by MrSwiss »

marcov wrote:Moreover, maybe go32 plays a role too.
This is yet another problem, since it isn't clean DOS (16 bit's), any longer.

Maybe a struct (FB = Type) resembling all saved/restored registers, could
be used, to overcome the situation (used instead of: pusha/popa).
(This is a conceptional idea, only.)
I'm defintely far to long, 'out' of DOS, as well as Assembly, to really help.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: Modify interrupt eip return (Preemptive task-switching)

Post by Cpcdos »

Thank you for your replies
I've already do this, and i don't know why this crash, i've investigate during more days, i've test with 1 task ditectly on code, it's crashes, then i test to modify just 1 register pour tests only and i conclude it's crashes here when i want modify the famouse EIP register from stack.

there are maybe a "DPMI wrapper" who executes my interrupt function.. I don't know.
I've respected the task switching basics, looked lot of tutorials that say the same things, this works on any independants kernels without dpmi. Fichtre! :(
Post Reply