Page 1 of 1

Stack based task switching

Posted: Mon May 12, 2003 12:56 pm
by distantvoices
Oooooyy, imagine, today, I've managed to get stack task switching running. that's but a cool and smooth thingy, lads. I just had to get some things straight and soon after that, I've coded even a small system call interface (for driver tasks to call BLOCK at the moment)

Nevertheless, One question troubled me with heavy headache, for I want to have the isr-stubs work directly with the structure of the actual process. (it is a pointer called prozess_t *p) In the type prozess_t, there is at the very beginning one field called prozess_esp, in which I store the actual position of esp. But this didn't work as I intended for this thing is a pointer.

Given this, I got the adress of the pointer by saying:

Code: Select all

mov eax,[p]
,
instead of the value of the first 4 bytes stored in this procedure, as I expected. so this question arouse:

How do I access members of a structure by a pointer - in assembler. BTW I use nasm.

thanks for your help, lads. Would be nice if you could bring light uon this miracle.

stay safe

Re:Stack based task switching

Posted: Mon May 12, 2003 4:54 pm
by shad
use the members offset + the base,

typedef struct{

dword dog
dword cat
dword mouse

}dog;

dog dog_struct

mov edi, dog
mov eax, 8
mov dword [edi+eax], 20935470927543

Re:Stack based task switching

Posted: Tue May 13, 2003 5:17 am
by Pype.Clicker
but watch out! the compiler may decide to reorder fields or add padding to keep the structure sizeof()-aligned (a dword will be at a *4 offset, a word at a *2 offset)

Re:Stack based task switching

Posted: Tue May 13, 2003 9:16 am
by distantvoices
Of course, one has to take care f compoler paddings and alignments.

But ... how do I do it in this case:

Code: Select all

c code...

prozess_t prozesse[MAXPROC];
prozess_t *p;

p=&prozesse[1];

asm code...
mov eax,[p]
...
or 
lea eax,[p]? (load effective adress ... does this make sense??)

thanks lads for your help

Re:Stack based task switching

Posted: Tue May 13, 2003 9:30 am
by Pype.Clicker

Code: Select all

lea eax,[p] ; eax is now &p ... not what we want.

mov eax,[p] ; eax is now p, thus [eax] is addressing the structure
mov edx,[eax] ; edx receives p->field0. most likely to be p->esp ;-)
mov ecx,[eax+4] ; ecx receives p->field1, whatever field1 is :)

Hope it helps ...

Re:Stack based task switching

Posted: Tue May 13, 2003 9:38 am
by distantvoices
In exactly this moment, it came up to my mind too, that I dit THIS in the wrong way, Pype. Thank you for help, this did the trick!

This shows that one never stops learning :-))