implement c coroutine
This commit is contained in:
@ -49,7 +49,7 @@ void Coroutine_init(struct CoroutineState* regs, unsigned int* stack, void (*kic
|
|||||||
// wird, sie darf also nicht terminieren, sonst kracht's.
|
// wird, sie darf also nicht terminieren, sonst kracht's.
|
||||||
|
|
||||||
*(--sp) = (unsigned int*)object; // Parameter
|
*(--sp) = (unsigned int*)object; // Parameter
|
||||||
*(--sp) = (unsigned int*)0x131155; // Ruecksprungadresse
|
*(--sp) = (unsigned int*)0x131155; // Ruecksprungadresse (Dummy)
|
||||||
|
|
||||||
// Nun legen wir noch die Adresse der Funktion "kickoff" ganz oben auf
|
// Nun legen wir noch die Adresse der Funktion "kickoff" ganz oben auf
|
||||||
// den Stack. Wenn dann bei der ersten Aktivierung dieser Koroutine der
|
// den Stack. Wenn dann bei der ersten Aktivierung dieser Koroutine der
|
||||||
@ -67,7 +67,7 @@ void Coroutine_init(struct CoroutineState* regs, unsigned int* stack, void (*kic
|
|||||||
regs->esi = 0;
|
regs->esi = 0;
|
||||||
regs->edi = 0;
|
regs->edi = 0;
|
||||||
regs->ebp = 0;
|
regs->ebp = 0;
|
||||||
regs->esp = sp;
|
regs->esp = sp; // esp now points to the location of the address of kickoff
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -107,6 +107,8 @@ Coroutine::Coroutine(unsigned int* stack) {
|
|||||||
void Coroutine::switchToNext() {
|
void Coroutine::switchToNext() {
|
||||||
|
|
||||||
/* hier muss Code eingefügt werden */
|
/* hier muss Code eingefügt werden */
|
||||||
|
|
||||||
|
Coroutine_switch(&this->regs, &((Coroutine*)this->next)->regs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -117,6 +119,8 @@ void Coroutine::switchToNext() {
|
|||||||
void Coroutine::start() {
|
void Coroutine::start() {
|
||||||
|
|
||||||
/* hier muss Code eingefügt werden */
|
/* hier muss Code eingefügt werden */
|
||||||
|
|
||||||
|
Coroutine_start(&this->regs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -127,4 +131,6 @@ void Coroutine::start() {
|
|||||||
void Coroutine::setNext(Chain* next) {
|
void Coroutine::setNext(Chain* next) {
|
||||||
|
|
||||||
/* hier muss Code eingefügt werden */
|
/* hier muss Code eingefügt werden */
|
||||||
|
|
||||||
|
this->next = next;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,7 +48,6 @@ public:
|
|||||||
|
|
||||||
// Verweis auf nächste Coroutine setzen
|
// Verweis auf nächste Coroutine setzen
|
||||||
void setNext(Chain* next);
|
void setNext(Chain* next);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user