blob: 60f62643b39e454d7a5d31dc22d600dd2232e507 [file] [log] [blame]
adamdunkels2c2a8822004-07-04 21:13:30 +00001
2#include <stdio.h>
3#include "mt.h"
4
5struct 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/*--------------------------------------------------------------------------*/
20void
21mtarch_init(void)
22{
23
24}
25/*--------------------------------------------------------------------------*/
26void
27mtarch_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/*--------------------------------------------------------------------------*/
38static unsigned long spsave, sptmp;
39static struct mtarch_thread *running_thread;
40
41static void
42sw(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/*--------------------------------------------------------------------------*/
70void
71mtarch_exec(struct mtarch_thread *t)
72{
73 running_thread = t;
74 sw();
75 running_thread = NULL;
76}
77/*--------------------------------------------------------------------------*/
78void
79mtarch_remove(void)
80{
81
82}
83/*--------------------------------------------------------------------------*/
84void
85mtarch_yield(void)
86{
87 sw();
88}
89/*--------------------------------------------------------------------------*/
90void
91mtarch_pstop(void)
92{
93
94}
95/*--------------------------------------------------------------------------*/
96void
97mtarch_pstart(void)
98{
99
100}
101/*--------------------------------------------------------------------------*/