Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1063 | tullio | 1 | |
2 | /* |
||
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program; if not, write to the Free Software |
||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
16 | * |
||
17 | */ |
||
18 | |||
2 | pj | 19 | #include <ll/i386/stdlib.h> |
20 | #include <ll/i386/tss-ctx.h> |
||
21 | #include <ll/i386/cons.h> |
||
22 | #include <ll/sys/ll/ll-instr.h> |
||
23 | #include <ll/sys/ll/ll-func.h> |
||
24 | |||
25 | #define STACK_SIZE 4096U /* Stack size in bytes */ |
||
26 | #define USE_FPU 0x0001 |
||
27 | |||
28 | WORD th1, thm; |
||
29 | |||
30 | #define T 1000 |
||
31 | |||
32 | #if 1 |
||
33 | #define TO ll_context_to |
||
34 | #define FROM ll_context_from |
||
35 | #else |
||
36 | #define TO ll_context_load |
||
37 | #define FROM ll_context_save |
||
38 | #endif |
||
39 | |||
40 | /* For stack allocation checking */ |
||
41 | BYTE stack1[STACK_SIZE]; |
||
42 | BYTE stack2[STACK_SIZE]; |
||
43 | |||
44 | void tfunc(void) |
||
45 | { |
||
46 | message("ThreadFunc: Switching to main thread\n"); |
||
47 | TO(thm); |
||
48 | message("ThreadFunc: I'm back\n"); |
||
49 | } |
||
50 | |||
51 | void thread1(void *px) |
||
52 | { |
||
53 | message("Thread 1 running\n"); |
||
54 | message("Calling ThreadFunc\n"); |
||
55 | tfunc(); |
||
56 | message("Another time thread 1\n"); |
||
57 | message("Back to main\n"); |
||
58 | TO(thm); |
||
59 | message("And now, finishing thread 1\n"); |
||
60 | } |
||
61 | |||
62 | void alienfunc(void) |
||
63 | { |
||
64 | message("Who am I???\n"); |
||
65 | } |
||
66 | |||
67 | void killer(void) |
||
68 | { |
||
69 | cli(); |
||
70 | message("Killer!!!\n"); |
||
71 | TO(thm); |
||
72 | } |
||
73 | |||
74 | int main (int argc, char *argv[]) |
||
75 | { |
||
76 | DWORD sp1, sp2; |
||
77 | void *mbi; |
||
78 | |||
79 | sp1 = get_SP(); |
||
80 | cli(); |
||
81 | |||
82 | mbi = ll_init(); |
||
83 | |||
84 | if (mbi == NULL) { |
||
85 | message("Error in LowLevel initialization code...\n"); |
||
86 | sti(); |
||
87 | l1_exit(-1); |
||
88 | } |
||
89 | sti(); |
||
90 | message("LowLevel started...\n"); |
||
91 | th1 = ll_context_create(thread1, &stack1[STACK_SIZE], NULL,killer, 0); |
||
92 | thm = FROM(); |
||
93 | message("Thread 1 created\n"); |
||
94 | message("Switching to it...\n"); |
||
95 | TO(th1); |
||
96 | message("Returned to main\n"); |
||
97 | message("Let's try if the push func works...\n"); |
||
98 | message("It returned %lu\n", ll_push_func(alienfunc)); |
||
99 | message("And now, to thread 1 again!!!\n"); |
||
100 | TO(th1); |
||
101 | message("Main another time...\n"); |
||
102 | TO(th1); |
||
103 | message("OK, now I finish...\n"); |
||
104 | cli(); |
||
105 | ll_end(); |
||
106 | sp2 = get_SP(); |
||
107 | message("End reached!\n"); |
||
108 | message("Actual stack : %lx - ", sp2); |
||
109 | message("Begin stack : %lx\n", sp1); |
||
110 | message("Check if same : %s\n",sp1 == sp2 ? "Ok :-)" : "No :-("); |
||
111 | return 1; |
||
112 | } |