Stack based task switching

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Stack based task switching

Post 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
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
shad

Re:Stack based task switching

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Stack based task switching

Post 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)
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Stack based task switching

Post 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
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Stack based task switching

Post 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 ...
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Stack based task switching

Post 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 :-))
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
Post Reply