adamdunkels | 2c2a882 | 2004-07-04 21:13:30 +0000 | [diff] [blame] | 1 | |
| 2 | #include <stdio.h> |
| 3 | #include "mt.h" |
| 4 | |
| 5 | struct frame { |
| 6 | unsigned long flags; |
| 7 | unsigned long ebp; |
| 8 | unsigned long edi; |
| 9 | unsigned long esi; |
| 10 | unsigned long edx; |
| 11 | unsigned long ecx; |
| 12 | unsigned long ebx; |
| 13 | unsigned long eax; |
| 14 | unsigned long retaddr; |
| 15 | unsigned long retaddr2; |
| 16 | unsigned long data; |
| 17 | }; |
| 18 | |
| 19 | /*--------------------------------------------------------------------------*/ |
| 20 | void |
| 21 | mtarch_init(void) |
| 22 | { |
| 23 | |
| 24 | } |
| 25 | /*--------------------------------------------------------------------------*/ |
| 26 | void |
| 27 | mtarch_start(struct mtarch_thread *t, |
| 28 | void (*function)(void *), void *data) |
| 29 | { |
| 30 | struct frame *f = (struct frame *)&t->stack[MTARCH_STACKSIZE - sizeof(struct frame)/4]; |
| 31 | memset(f, 0, sizeof(struct frame)); |
| 32 | f->retaddr = (unsigned long)function; |
| 33 | f->data = (unsigned long)data; |
| 34 | t->sp = (unsigned long)&f->flags; |
| 35 | f->ebp = (unsigned long)&f->eax; |
| 36 | } |
| 37 | /*--------------------------------------------------------------------------*/ |
| 38 | static unsigned long spsave, sptmp; |
| 39 | static struct mtarch_thread *running_thread; |
| 40 | |
| 41 | static void |
| 42 | sw(void) |
| 43 | { |
| 44 | |
| 45 | asm("pushl %eax"); |
| 46 | asm("pushl %ebx"); |
| 47 | asm("pushl %ecx"); |
| 48 | asm("pushl %edx"); |
| 49 | asm("pushl %esi"); |
| 50 | asm("pushl %edi"); |
| 51 | asm("pushl %ebp"); |
| 52 | asm("pushl %ebp"); /* XXX: should push FPU flags here. */ |
| 53 | asm("movl %esp, spsave"); |
| 54 | |
| 55 | sptmp = running_thread->sp; |
| 56 | running_thread->sp = spsave; |
| 57 | |
| 58 | asm("movl sptmp, %esp"); |
| 59 | asm("popl %ebp"); /* XXX: should pop FPU flags here. */ |
| 60 | asm("popl %ebp"); |
| 61 | asm("popl %edi"); |
| 62 | asm("popl %esi"); |
| 63 | asm("popl %edx"); |
| 64 | asm("popl %ecx"); |
| 65 | asm("popl %ebx"); |
| 66 | asm("popl %eax"); |
| 67 | } |
| 68 | |
| 69 | /*--------------------------------------------------------------------------*/ |
| 70 | void |
| 71 | mtarch_exec(struct mtarch_thread *t) |
| 72 | { |
| 73 | running_thread = t; |
| 74 | sw(); |
| 75 | running_thread = NULL; |
| 76 | } |
| 77 | /*--------------------------------------------------------------------------*/ |
| 78 | void |
| 79 | mtarch_remove(void) |
| 80 | { |
| 81 | |
| 82 | } |
| 83 | /*--------------------------------------------------------------------------*/ |
| 84 | void |
| 85 | mtarch_yield(void) |
| 86 | { |
| 87 | sw(); |
| 88 | } |
| 89 | /*--------------------------------------------------------------------------*/ |
| 90 | void |
| 91 | mtarch_pstop(void) |
| 92 | { |
| 93 | |
| 94 | } |
| 95 | /*--------------------------------------------------------------------------*/ |
| 96 | void |
| 97 | mtarch_pstart(void) |
| 98 | { |
| 99 | |
| 100 | } |
| 101 | /*--------------------------------------------------------------------------*/ |