Subversion Repositories shark

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
#include <ll/i386/stdlib.h>
2
#include <ll/i386/tss-ctx.h>
3
#include <ll/i386/cons.h>
4
#include <ll/sys/ll/ll-instr.h>
5
#include <ll/sys/ll/ll-func.h>
6
 
7
#define STACK_SIZE      4096U           /* Stack size in bytes          */
8
#define USE_FPU         0x0001
9
 
10
WORD th1, thm;
11
 
12
#define T 1000
13
 
14
#if 1
15
#define TO     ll_context_to
16
#define FROM   ll_context_from 
17
#else
18
#define TO     ll_context_load
19
#define FROM   ll_context_save 
20
#endif
21
 
22
/* For stack allocation checking */
23
BYTE stack1[STACK_SIZE];
24
BYTE stack2[STACK_SIZE];
25
 
26
void tfunc(void)
27
{
28
        message("ThreadFunc: Switching to main thread\n");
29
        TO(thm);
30
        message("ThreadFunc: I'm back\n");
31
}
32
 
33
void thread1(void *px)
34
{
35
        message("Thread 1 running\n");
36
        message("Calling ThreadFunc\n");
37
        tfunc();
38
        message("Another time thread 1\n");
39
        message("Back to main\n");
40
        TO(thm);
41
        message("And now, finishing thread 1\n");
42
}
43
 
44
void alienfunc(void)
45
{
46
        message("Who am I???\n");
47
}
48
 
49
void killer(void)
50
{
51
        cli();
52
        message("Killer!!!\n");
53
        TO(thm);
54
}
55
 
56
int main (int argc, char *argv[])
57
{
58
    DWORD sp1, sp2;
59
    void *mbi;
60
 
61
    sp1 = get_SP();
62
    cli();
63
 
64
    mbi = ll_init();
65
 
66
    if (mbi == NULL) {
67
            message("Error in LowLevel initialization code...\n");
68
            sti();
69
            l1_exit(-1);
70
    }
71
    sti();
72
    message("LowLevel started...\n");
73
    th1 = ll_context_create(thread1, &stack1[STACK_SIZE], NULL,killer, 0);
74
    thm = FROM();
75
    message("Thread 1 created\n");
76
    message("Switching to it...\n");
77
    TO(th1);
78
    message("Returned to main\n");
79
    message("Let's try if the push func works...\n");
80
    message("It returned %lu\n", ll_push_func(alienfunc));
81
    message("And now, to thread 1 again!!!\n");
82
    TO(th1);
83
    message("Main another time...\n");
84
    TO(th1);
85
    message("OK, now I finish...\n");
86
    cli();
87
    ll_end();
88
    sp2 = get_SP();
89
    message("End reached!\n");
90
    message("Actual stack : %lx - ", sp2);
91
    message("Begin stack : %lx\n", sp1);
92
    message("Check if same : %s\n",sp1 == sp2 ? "Ok :-)" : "No :-(");
93
    return 1;
94
}