Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* Project:     OSLib
2
 * Description: The OS Construction Kit
3
 * Date:                1.6.2000
4
 * Idea by:             Luca Abeni & Gerardo Lamastra
5
 *
6
 * OSLib is an SO project aimed at developing a common, easy-to-use
7
 * low-level infrastructure for developing OS kernels and Embedded
8
 * Applications; it partially derives from the HARTIK project but it
9
 * currently is independently developed.
10
 *
11
 * OSLib is distributed under GPL License, and some of its code has
12
 * been derived from the Linux kernel source; also some important
13
 * ideas come from studying the DJGPP go32 extender.
14
 *
15
 * We acknowledge the Linux Community, Free Software Foundation,
16
 * D.J. Delorie and all the other developers who believe in the
17
 * freedom of software and ideas.
18
 *
19
 * For legalese, check out the included GPL license.
20
 */
21
 
22
/*      Context Switch Demo     */
23
 
24
#include <ll/i386/stdlib.h>
25
#include <ll/i386/tss-ctx.h>
26
#include <ll/i386/error.h>
27
#include <ll/sys/ll/ll-instr.h>
28
#include <ll/sys/ll/ll-func.h>
29
 
30
#define STACK_SIZE      4096U           /* Stack size in bytes          */
31
#define USE_FPU         0x0001
32
 
33
WORD th1, thm;
34
 
35
#define T 1000
36
 
37
#if 1
38
#define TO     ll_context_to
39
#define FROM   ll_context_from 
40
#else
41
#define TO     ll_context_load
42
#define FROM   ll_context_save 
43
#endif
44
 
45
/* For stack allocation checking */
46
BYTE stack1[STACK_SIZE];
47
BYTE stack2[STACK_SIZE];
48
 
49
void thread1(void *px)
50
{
51
        message("Thread 1 running\n");
52
        message("Switching to main thread\n");
53
        TO(thm);
54
        message("Another time thread 1\n");
55
        message("Back to main\n");
56
        TO(thm);
57
        message("And now, finishing thread 1\n");
58
}
59
 
60
void killer(void)
61
{
62
        cli();
63
        message("Killer!!!\n");
64
        TO(thm);
65
}
66
 
67
int main (int argc, char *argv[])
68
{
69
    DWORD sp1, sp2;
70
    void *mbi;
71
 
72
    sp1 = get_SP();
73
    cli();
74
 
75
    mbi = ll_init();
76
 
77
    if (mbi == NULL) {
78
            message("Error in LowLevel initialization code...\n");
79
            sti();
80
            l1_exit(-1);
81
    }
82
    sti();
83
    message("LowLevel started...\n");
84
    th1 = ll_context_create(thread1, &stack1[STACK_SIZE], NULL,killer, 0);
85
    thm = FROM();
86
    message("Thread 1 created\n");
87
    message("Switching to it...\n");
88
    TO(th1);
89
    message("Returned to main\n");
90
    message("And now, to thread 1 again!!!\n");
91
    TO(th1);
92
    message("Main another time...\n");
93
    TO(th1);
94
    message("OK, now I finish...\n");
95
    cli();
96
    ll_end();
97
    sp2 = get_SP();
98
    message("End reached!\n");
99
    message("Actual stack : %lx - ", sp2);
100
    message("Begin stack : %lx\n", sp1);
101
    message("Check if same : %s\n",sp1 == sp2 ? "Ok :-)" : "No :-(");
102
    return 1;
103
}