OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 13, 2021 8:12 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Task switching - Interruption 1Ch
PostPosted: Sat Apr 28, 2018 11:49 am 
Offline
Member
Member
User avatar

Joined: Sat Feb 02, 2013 4:16 pm
Posts: 35
Location: France [Lyon]
My work is to switch stack between 2 or more functions (Preemptible multi-task) between main, _mytask1 and _mytask_2 functions

For begin, this is my code FreeBasic/GAS (AT&T)

INIT_INTERRUPT()
Code:
jmp saut_1%f
DS_SEL: .short 0
INT1C_OFF: .int 0
INT1C_SEL: .short 0

saut_1:
push ds
pop DS_SEL
push cs
pop WORD PTR [cs_]
push ds
pop WORD PTR [ds_]
push es
pop WORD PTR [es_]
push ss
pop WORD PTR [ss_]

mov ax, 0x204
mov bl, 0x1c
int 0x31
jc saut_2%f
mov INT1C_SEL, cx
mov INT1C_OFF, edx
saut_2:

START_INTERRUPT()
Code:
mov ax, 0x205
mov bl, 0x1c
push cs
pop cx
mov edx, OFFSET _MY_INTERRUPT_FUNCTION
int 0x31
jc saut_3%f
saut_3:

This code work perfectly, MY_INTERRUPT_FUNCTION() is executed during "1Ch tic"
And this is my problem :
MY_INTERRUPT_FUNCTION()
Code:
sti
' Save registers
push ds
push es
push fs
push gs

' Entry point of DS
mov dx, ds

' Load data section in DS
mov ax, cs:DS_SEL
mov ds, ax

' Restaure seg values
mov ax, cs
mov cs_, ax
mov ds_, dx
mov ax, es
mov es_, ax
mov ax, ss
mov ss_, ax

mov fs_, fs
mov gs_, gs

' Push all registers on stack
pushad

' ===== SWITCH STACK =====
push esp
CALL SWITCH_TASK
mov esp, eax
pop esp
' ===== SWITCH STACK =====

' Restaure registers
popad

pop gs
pop fs
pop es
pop ds

sti
iret

This not work, iret return to the original EIP position, so i search how interrupt stack work, according this stack representation (Without error code) :
Image
About iret instruction, if i want modify the "Return EIP register" on my current interrupt i must write my new EIP on it ? Yes ? So after my CALL, i push like this _mytask1 for test :
Code:
push eax
mov eax, _mytask1
mov ss:[esp]+0, eax
pop eax


But this not work..

I've seeing the content of "ss:[ESP]+0", the famous "Return EIP" before modifications, and i've every "0x16F".. what?? :-|

I've already executed on ring0, with cwsdpr0.exe on FreeDOS..
I'm lost, if someone can help me?

Thank you a lot,

_________________
FAVIER S├ębastien
Sorry for my bad bad English level, I'm young French studient .. :)


Top
 Profile  
 
 Post subject: Re: Task switching - Interruption 1Ch
PostPosted: Sat Apr 28, 2018 1:34 pm 
Offline
Member
Member

Joined: Fri Aug 19, 2016 10:28 pm
Posts: 360
I haven't looked through the rest, but this seems unintentional:
Code:
push eax  ;Old ss:[esp] is now ss:[esp+4], eax is stored in ss:[esp]
mov eax, _mytask1
mov ss:[esp], eax ; Changes stored eax on stack to _mytask1
pop eax

It should be:
Code:
push eax
mov eax, _mytask1
mov ss:[esp+4], eax
pop eax

Edit: some assembly syntax


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group