Language:
None specified     Change language:
Pastebin: 90529
Author: asd
Subject: Untitled
Created: 2008-07-02 16:30:26
Download and save
Toggle line numbers
1cli; 
2jmp thread_init; 
3 
4//== Thread parameters ======================================================== 
5alloc thread1_esp; 
6alloc thread2_esp; 
7 
8interrupt_table: 
9  alloc 512; 
10 
11alloc curthread; 
12//============================================================================= 
13 
14//============================================================================= 
15// Thread switcher interrupt 
16//============================================================================= 
17thread_switch: 
18    cli; 
19    //Switch to what task? 
20    cmp #curthread,0; 
21    jne switch_to1; 
22    je switch_to2; 
23 
24    switch_return: 
25    sti; 
26  nmiret; 
27 
28switch_to1: 
29  //switch to thread1 stack 
30  mov ss,thread1_stack; 
31 
32  mov #thread2_esp,esp; 
33  mov esp,#thread1_esp; 
34 
35  mov #curthread,0; 
36 
37  jmp switch_return; 
38 
39switch_to2: 
40  //switch to thread2 stack 
41  mov ss,thread2_stack; 
42 
43  mov #thread1_esp,esp; 
44  mov esp,#thread2_esp; 
45 
46  mov #curthread,1; 
47 
48  jmp switch_return; 
49//============================================================================= 
50 
51 
52//============================================================================= 
53// Thread initialization 
54//============================================================================= 
55thread_init: 
56  //Setup interrupt handler 
57  lidtr interrupt_table; 
58  mov edi,interrupt_table; 
59  add edi,64; //INT 32; 
60  mov #edi,thread_switch; 
61  inc edi; 
62  mov #edi,32; 
63 
64  stp; 
65 
66  //Setup stack 
67  mov #thread1_esp,2047; 
68  mov #thread2_esp,2047; 
69 
70  //Setup thread switcher 
71  mov #curthread,0; 
72 
73  //Initialize task 2 NMI return stuff 
74  mov ss,thread2_stack; 
75  mov esp,#thread2_esp; 
76  push es; 
77  push gs; 
78  push fs; 
79  push ds; 
80  push ss; 
81  push cs; 
82 
83  push edi; 
84  push esi; 
85  push esp; 
86  push ebp; 
87  push edx; 
88  push ecx; 
89  push ebx; 
90  push eax; 
91 
92  push 0; //CMPR 
93  push thread2; //ENTRYPOINT 
94 
95  push 0; 
96  push 0; 
97 
98  mov #thread2_esp,esp; 
99 
100 
101 
102  //Initialize task 1 NMI return stuff 
103  mov ss,thread1_stack; 
104  mov esp,#thread1_esp; 
105  push es; 
106  push gs; 
107  push fs; 
108  push ds; 
109  push ss; 
110  push cs; 
111 
112  push edi; 
113  push esi; 
114  push esp; 
115  push ebp; 
116  push edx; 
117  push ecx; 
118  push ebx; 
119  push eax; 
120 
121  push 0; //CMPR 
122  push thread1; //ENTRYPOINT 
123 
124  push 0; 
125  push 0; 
126 
127  mov #thread1_esp,esp; 
128 
129  //Start task 1 
130  sti; 
131  nmiret; 
132//============================================================================= 
133 
134//4KB per thread 
135//2KB code 
136//2KB stack 
137 
138//== Thread 1 ================================================================= 
139ORG 4096; 
140thread1: 
141 
142  mov eax,0; 
143  thread1_loop: 
144    add eax,1; 
145    mov port0,eax; 
146    jmp thread1_loop; 
147 
148ORG 6144; 
149thread1_stack: 
150//============================================================================= 
151 
152 
153 
154//== Thread 2 ================================================================= 
155ORG 8192; 
156thread2: 
157 
158  mov eax,0; 
159  thread2_loop: 
160    add eax,1; 
161    mov port1,eax; 
162//    nmiint 32; //This makes task IDLE until next task switch! 
163    jmp thread2_loop; 
164 
165ORG 10240; 
166thread2_stack: 
167//============================================================================= 
Download and save
Toggle line numbers
Thread:
[90529] Untitled by asd at 2008-07-02 16:30:26
  [90589] Re: Untitled by Anonymous at 2008-07-03 19:50:29 (diff)
  [90666] Re: Untitled by Anonymous at 2008-07-05 18:10:17 (diff)
    [92391] linyfx vxlnithez by bofhzgs mtyzlhsf at 2008-07-24 18:42:14 (diff)
  [98589] Re: Untitled by Anonymous at 2008-10-17 15:32:55 (diff)
Tip: Click the line numbers to toggle highliting on that line.

Paste followup:

Language:
Author:
Subject:


    Tabstop:     bigger biggest
Note: You can prefix a line with "@@@" to highlight it.