Subversion Repositories Kolibri OS

Rev

Rev 9 | Rev 11 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9 Rev 10
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                               ;;
2
;;                                                               ;;
3
;;  MenuetOS process management, protected ring3                 ;;
3
;;  MenuetOS process management, protected ring3                 ;;
4
;;                                                               ;;
4
;;                                                               ;;
5
;;  Distributed under GPL. See file COPYING for details.         ;;
5
;;  Distributed under GPL. See file COPYING for details.         ;;
6
;;  Copyright 2003 Ville Turjanmaa                               ;;
6
;;  Copyright 2003 Ville Turjanmaa                               ;;
7
;;                                                               ;;
7
;;                                                               ;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
 
9
 
10
align 32
10
align 32
11
 
11
 
12
; GDT TABLE
12
; GDT TABLE
13
 
13
 
14
gdts:
14
gdts:
15
 
15
 
16
        dw     gdte-$-1
16
        dw     gdte-$-1
17
        dd     gdts
17
        dd     gdts
18
        dw     0
18
        dw     0
19
 
19
 
20
int_code_l:
20
int_code_l:
21
os_code_l:
21
os_code_l:
22
 
22
 
23
        dw     0xffff
23
        dw     0xffff
24
        dw     0x0000
24
        dw     0x0000
25
        db     0x00
25
        db     0x00
26
        dw     11011111b *256 +10011010b
26
        dw     11011111b *256 +10011010b
27
        db     0x00
27
        db     0x00
28
 
28
 
29
int_data_l:
29
int_data_l:
30
os_data_l:
30
os_data_l:
31
 
31
 
32
        dw     0xffff
32
        dw     0xffff
33
        dw     0x0000
33
        dw     0x0000
34
        db     0x00
34
        db     0x00
35
        dw     11011111b *256 +10010010b
35
        dw     11011111b *256 +10010010b
36
        db     0x00
36
        db     0x00
37
 
37
 
38
app_code_l:
38
app_code_l:
39
      dw ((0x80000000-std_application_base_address) shr 12) and 0xffff
39
      dw ((0x80000000-std_application_base_address) shr 12) and 0xffff
40
      dw 0
40
      dw 0
41
      db 0
41
      db 0
42
      dw 11010000b*256+11111010b+256*((0x80000000-std_application_base_address) shr 28)
42
      dw 11010000b*256+11111010b+256*((0x80000000-std_application_base_address) shr 28)
43
      db std_application_base_address shr 24
43
      db std_application_base_address shr 24
44
 
44
 
45
app_data_l:
45
app_data_l:
46
      dw (0x80000000-std_application_base_address) shr 12 and 0xffff
46
      dw (0x80000000-std_application_base_address) shr 12 and 0xffff
47
      dw 0
47
      dw 0
48
      db 0
48
      db 0
49
      dw 11010000b*256+11110010b+256*((0x80000000-std_application_base_address) shr 28)
49
      dw 11010000b*256+11110010b+256*((0x80000000-std_application_base_address) shr 28)
50
      db std_application_base_address shr 24
50
      db std_application_base_address shr 24
51
 
51
 
52
graph_data_l:
52
graph_data_l:
53
 
53
 
54
        dw     0x3ff
54
        dw     0x3ff
55
        dw     0x0000
55
        dw     0x0000
56
        db     0x00
56
        db     0x00
57
        dw     11010000b *256 +11110010b
57
        dw     11010000b *256 +11110010b
58
        db     0x00
58
        db     0x00
59
 
59
 
60
tss0_l:
60
tss0_l:
61
      times (max_processes+10) dd 0,0
61
      times (max_processes+10) dd 0,0
62
 
62
 
63
gdte:
63
gdte:
64
 
64
 
65
 
65
 
66
 
66
 
67
idtreg:
67
idtreg:
68
     dw   8*0x41-1
68
     dw   8*0x41-1
69
     dd   idts+8
69
     dd   idts+8
70
label idts at 0xB100-8
70
label idts at 0xB100-8
71
 
71
 
72
 
72
 
73
 
73
 
74
uglobal
74
uglobal
75
 tss_sceleton:
75
 tss_sceleton:
76
  l.back   dw 0,0
76
  l.back   dw 0,0
77
  l.esp0   dd 0
77
  l.esp0   dd 0
78
  l.ss0    dw 0,0
78
  l.ss0    dw 0,0
79
  l.esp1   dd 0
79
  l.esp1   dd 0
80
  l.ss1    dw 0,0
80
  l.ss1    dw 0,0
81
  l.esp2   dd 0
81
  l.esp2   dd 0
82
  l.ss2    dw 0,0
82
  l.ss2    dw 0,0
83
  l.cr3    dd 0
83
  l.cr3    dd 0
84
  l.eip    dd 0
84
  l.eip    dd 0
85
  l.eflags dd 0
85
  l.eflags dd 0
86
  l.eax    dd 0
86
  l.eax    dd 0
87
  l.ecx    dd 0
87
  l.ecx    dd 0
88
  l.edx    dd 0
88
  l.edx    dd 0
89
  l.ebx    dd 0
89
  l.ebx    dd 0
90
  l.esp    dd 0
90
  l.esp    dd 0
91
  l.ebp    dd 0
91
  l.ebp    dd 0
92
  l.esi    dd 0
92
  l.esi    dd 0
93
  l.edi    dd 0
93
  l.edi    dd 0
94
  l.es     dw 0,0
94
  l.es     dw 0,0
95
  l.cs     dw 0,0
95
  l.cs     dw 0,0
96
  l.ss     dw 0,0
96
  l.ss     dw 0,0
97
  l.ds     dw 0,0
97
  l.ds     dw 0,0
98
  l.fs     dw 0,0
98
  l.fs     dw 0,0
99
  l.gs     dw 0,0
99
  l.gs     dw 0,0
100
  l.ldt    dw 0,0
100
  l.ldt    dw 0,0
101
  l.trap   dw 0
101
  l.trap   dw 0
102
  l.io     dw 0
102
  l.io     dw 0
103
endg
103
endg
104
 
104
 
105
 
105
 
106
build_process_gdt_tss_pointer:
106
build_process_gdt_tss_pointer:
107
 
107
 
108
        mov    ecx,tss_data
108
        mov    ecx,tss_data
109
        mov    edi,0
109
        mov    edi,0
110
      setgdtl2:
110
      setgdtl2:
111
        mov    [edi+gdts+ tss0 +0], word tss_step
111
        mov    [edi+gdts+ tss0 +0], word tss_step
112
        mov    [edi+gdts+ tss0 +2], cx
112
        mov    [edi+gdts+ tss0 +2], cx
113
        mov    eax,ecx
113
        mov    eax,ecx
114
        shr    eax,16
114
        shr    eax,16
115
        mov    [edi+gdts+ tss0 +4], al
115
        mov    [edi+gdts+ tss0 +4], al
116
        mov    [edi+gdts+ tss0 +7], ah
116
        mov    [edi+gdts+ tss0 +7], ah
117
        mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
117
        mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
118
        add    ecx,tss_step
118
        add    ecx,tss_step
119
        add    edi,8
119
        add    edi,8
120
        cmp    edi,8*(max_processes+5)
120
        cmp    edi,8*(max_processes+5)
121
        jbe    setgdtl2
121
        jbe    setgdtl2
122
 
122
 
123
        ret
123
        ret
124
 
124
 
125
 
125
 
126
build_interrupt_table:
126
build_interrupt_table:
127
 
127
 
128
        mov    edi, idts+8
128
        mov    edi, idts+8
129
        mov    esi, sys_int
129
        mov    esi, sys_int
130
        mov    ecx, 0x40
130
        mov    ecx, 0x40
131
     @@:
131
     @@:
132
        mov    eax, [esi]
132
        mov    eax, [esi]
133
        mov    [edi],   ax           ; lower part of offset
133
        mov    [edi],   ax           ; lower part of offset
134
        mov    [edi+2], word os_code ; segment selector
134
        mov    [edi+2], word os_code ; segment selector
135
        shr    eax, 16
135
        shr    eax, 16
136
        mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
136
        mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
137
        mov    [edi+6], ax
137
        mov    [edi+6], ax
138
        add    esi, 4
138
        add    esi, 4
139
        add    edi, 8
139
        add    edi, 8
140
        dec    ecx
140
        dec    ecx
141
        jnz    @b
141
        jnz    @b
142
        
142
        
143
        ;mov    edi,8*0x40+idts+8
143
        ;mov    edi,8*0x40+idts+8
144
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
144
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
145
        mov    [edi + 2], word os_code
145
        mov    [edi + 2], word os_code
146
        mov    [edi + 4], word 11101110b*256
146
        mov    [edi + 4], word 11101110b*256
147
        mov    [edi + 6], word (i40 shr 16)
147
        mov    [edi + 6], word (i40 shr 16)
148
 
148
 
149
        ret
149
        ret
150
 
150
 
151
 
151
 
152
 
152
 
153
iglobal
153
iglobal
154
  sys_int:
154
  sys_int:
155
    dd   e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15
155
    dd   e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15
156
    dd   e16,e17
156
    dd   e16,e17
157
    times 14 dd unknown_interrupt
157
    times 14 dd unknown_interrupt
158
 
158
 
159
    dd   irq0  ,irq1  ,p_irq2 ,p_irq3 ,p_irq4 ,p_irq5,p_irq6 ,p_irq7
159
    dd   irq0  ,irq1  ,p_irq2 ,p_irq3 ,p_irq4 ,p_irq5,p_irq6 ,p_irq7
160
    dd   p_irq8,p_irq9,p_irq10,p_irq11,p_irq12,irqD  ,p_irq14,p_irq15
160
    dd   p_irq8,p_irq9,p_irq10,p_irq11,p_irq12,irqD  ,p_irq14,p_irq15
161
 
161
 
162
    times 16 dd unknown_interrupt
162
    times 16 dd unknown_interrupt
163
 
163
 
164
    dd   i40
164
    dd   i40
165
endg
165
endg
166
 
166
 
167
; simply return control to interrupted process
167
; simply return control to interrupted process
168
unknown_interrupt:
168
unknown_interrupt:
169
     iret
169
     iret
170
 
170
 
171
macro exceptions [num]
171
macro exceptions [num]
172
{
172
{
173
  forward
173
  forward
174
  e#num :
174
  e#num :
175
  	mov bl, num
175
  	mov bl, num
176
  	jmp exc_c
176
  	jmp exc_c
177
}
177
}
178
 
178
 
179
exceptions 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
179
exceptions 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
180
exc_c:
180
exc_c:
181
        mov   ax, os_data
181
        mov   ax, os_data
182
        mov   ds, ax
182
        mov   ds, ax
183
        mov   es, ax
183
        mov   es, ax
184
 
184
 
185
        movzx eax, bl        
185
        movzx eax, bl        
186
        mov   [error_interrupt], eax
186
        mov   [error_interrupt], eax
187
        call  show_error_parameters
187
        call  show_error_parameters
188
        
188
        
189
        mov   edx, [0x3010]
189
        mov   edx, [0x3010]
190
        mov   [edx + 0xA], byte 4
190
        mov   [edx + 0xA], byte 4
191
        
191
        
192
        jmp   change_task
192
        jmp   change_task
193
 
193
 
194
 
194
 
195
;;;;;;;;;;;;;;;;;;;;;;;
195
;;;;;;;;;;;;;;;;;;;;;;;
196
;; FPU ERROR HANDLER ;;
196
;; FPU ERROR HANDLER ;;
197
;;;;;;;;;;;;;;;;;;;;;;;
197
;;;;;;;;;;;;;;;;;;;;;;;
198
 
198
 
199
align 4
199
align 4
200
e7:
200
e7:
201
        clts
201
        clts
202
          
202
          
203
        push  eax
203
        push  eax
204
        push  ds es
204
        push  ds es
205
        
205
        
206
        mov   ax, os_data
206
        mov   ax, os_data
207
        mov   ds, ax
207
        mov   ds, ax
208
        mov   es, ax
208
        mov   es, ax
209
        
209
        
210
        mov   eax, [prev_user_of_fpu]
210
        mov   eax, [prev_user_of_fpu]
211
        shl   eax, 8
211
        shl   eax, 8
212
        add   eax, 0x80000 + 0x10
212
        add   eax, 0x80000 + 0x10
213
        fsave [eax]
213
        fsave [eax]
214
        
214
        
215
        mov   eax, [0x3000]
215
        mov   eax, [0x3000]
216
        mov   [prev_user_of_fpu], eax
216
        mov   [prev_user_of_fpu], eax
217
        shl   eax, 8
217
        shl   eax, 8
218
        add   eax, 0x80000
218
        add   eax, 0x80000
219
        cmp   [eax + 0x7f], byte 0
219
        cmp   [eax + 0x7f], byte 0
220
        je    @f
220
        je    @f
221
        frstor [eax+0x10]
221
        frstor [eax+0x10]
222
     @@:
222
     @@:
223
        mov   [eax + 0x7f], byte 1
223
        mov   [eax + 0x7f], byte 1
224
        
224
        
225
        pop   es ds
225
        pop   es ds
226
        pop   eax
226
        pop   eax
227
        
227
        
228
        iret
228
        iret
229
        
229
        
230
iglobal
230
iglobal
231
  prev_user_of_fpu dd 1
231
  prev_user_of_fpu dd 1
232
endg
232
endg
233
 
233
 
234
 
234
 
235
writehex:
235
writehex:
236
      pusha
236
      pusha
237
      
237
      
238
      mov  edi, [write_error_to]
238
      mov  edi, [write_error_to]
239
      mov  esi, 8
239
      mov  esi, 8
240
    @@:
240
    @@:
241
      mov  ecx, eax
241
      mov  ecx, eax
242
      and  ecx, 0xf
242
      and  ecx, 0xf
243
 
243
 
244
      mov  cl,[ecx+hexletters]
244
      mov  cl,[ecx+hexletters]
245
      mov  [edi],cl
245
      mov  [edi],cl
246
      dec  edi
246
      dec  edi
247
 
247
 
248
      shr  eax,4
248
      shr  eax,4
249
      dec  esi
249
      dec  esi
250
      jnz  @b
250
      jnz  @b
251
 
251
 
252
      popa
252
      popa
253
      ret
253
      ret
254
 
254
 
255
iglobal
255
iglobal
256
  hexletters  db '0123456789ABCDEF'
256
  hexletters  db '0123456789ABCDEF'
257
 
257
 
258
  error_interrupt         dd  -1
258
  error_interrupt         dd  -1
259
 
259
 
260
  process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
260
  process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
261
  process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
261
  process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
262
  process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
262
  process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
263
  system_error   db 'K : Kernel error',13,10,0
263
  system_error   db 'K : Kernel error',13,10,0
264
endg
264
endg
265
 
265
 
266
uglobal
266
uglobal
267
  write_error_to  dd  0x0
267
  write_error_to  dd  0x0
268
endg
268
endg
269
 
269
 
270
show_error_parameters:
270
show_error_parameters:
271
        
271
        
272
        mov    [write_error_to],process_pid+43
272
        mov    [write_error_to],process_pid+43
273
        mov    eax,[0x3000]
273
        mov    eax,[0x3000]
274
        shl    eax, 5
274
        shl    eax, 5
275
        mov    eax,[0x3000+4+eax]
275
        mov    eax,[0x3000+4+eax]
276
        call   writehex
276
        call   writehex
277
        
277
        
278
        mov    [write_error_to],process_error+43
278
        mov    [write_error_to],process_error+43
279
        mov    eax,[error_interrupt]
279
        mov    eax,[error_interrupt]
280
        call   writehex
280
        call   writehex
281
        
281
        
282
        mov    eax,[0x3000]
282
        mov    eax,[0x3000]
283
        shl    eax,8
283
        shl    eax,8
284
        cmp    [0x80000+eax+0xB0],byte 0
284
        cmp    [0x80000+eax+0xB0],byte 0
-
 
285
        jz     @f
285
        jnz    .system_error
286
        mov    esi,system_error
-
 
287
        call   sys_msg_board_str
-
 
288
      @@:
286
 
289
        
287
        mov    eax,[0x3000]
290
        mov    eax,[0x3000]
288
        imul   eax,tss_step
291
        imul   eax,tss_step
289
        mov    eax,[eax+tss_data+l.eip-tss_sceleton]
292
        mov    eax,[eax+tss_data+l.eip-tss_sceleton]
290
.out_eip:        
293
 
291
        mov    [write_error_to],process_eip+43
294
        mov    [write_error_to],process_eip+43
292
        call   writehex
295
        call   writehex
293
 
296
 
294
        mov    esi,process_error
297
        mov    esi,process_error
295
        call   sys_msg_board_str
298
        call   sys_msg_board_str
296
 
299
 
297
        mov    esi,process_pid
300
        mov    esi,process_pid
298
        call   sys_msg_board_str
301
        call   sys_msg_board_str
299
 
302
 
300
        mov    esi,process_eip
303
        mov    esi,process_eip
301
        call   sys_msg_board_str
304
        call   sys_msg_board_str
302
 
305
 
303
        ret
306
        ret
304
        
-
 
305
.system_error:
-
 
306
        mov    esi,system_error
-
 
307
        call   sys_msg_board_str
-
 
308
        mov    eax,[0x3000]
-
 
309
        shl    eax,7
-
 
310
        mov    eax,[eax+0x298000+l.eip-tss_sceleton]
-
 
311
        jmp    .out_eip        
-
 
312
 
-
 
313
 
307
 
314
 
308
 
315
 
309
 
316
; irq1  ->  hid/keyboard.inc
310
; irq1  ->  hid/keyboard.inc
317
 
311
 
318
 
312
 
319
macro irqhh [num]
313
macro irqh [num]
320
{
314
{
321
  forward
315
  forward
322
  p_irq#num :
316
  p_irq#num :
323
     pushad
317
     pushad
324
     mov   edi, num
318
     mov   edi, num
325
     jmp   irq_c
319
     jmp   irq_c
326
}
320
}
327
 
321
 
328
irqhh 2,3,4,5,6,7,8,9,10,11,12,14,15
322
irqh 2,3,4,5,6,7,8,9,10,11,12,14,15
329
 
323
 
330
 irq_c:
324
 irq_c:
331
     push  ds es
325
     push  ds es
332
     mov   ax, os_data
326
     mov   ax, os_data
333
     mov   ds, ax
327
     mov   ds, ax
334
     mov   es, ax
328
     mov   es, ax
335
     call  irqhandler
329
     call  irqhandler
336
     pop   es ds
330
     pop   es ds
337
     popad
331
     popad
338
     iret
332
     iret
339
  	
333
  	
340
irqD:
334
irqD:
341
     pushad
335
     pushad
342
     push  ds es
336
     push  ds es
343
     mov   ax, os_data
337
     mov   ax, os_data
344
     mov   ds, ax
338
     mov   ds, ax
345
     mov   es, ax
339
     mov   es, ax
346
     
340
     
347
     mov   dx,0xf0
341
     mov   dx,0xf0
348
     mov   al,0
342
     mov   al,0
349
     out   dx,al
343
     out   dx,al
350
 
344
 
351
     mov   dx,0xa0
345
     mov   dx,0xa0
352
     mov   al,0x20
346
     mov   al,0x20
353
     out   dx,al
347
     out   dx,al
354
     mov   dx,0x20
348
     mov   dx,0x20
355
     out   dx,al     
349
     out   dx,al     
356
     
350
     
357
     pop   es ds
351
     pop   es ds
358
     popad
352
     popad
359
     iret
353
     iret
360
 
-
 
361
 
354
 
362
 
355
 
363
irqhandler:
356
irqhandler:
364
 
357
 
365
     push   edi
358
     push   edi
366
 
359
 
367
     mov    esi,edi          ; 1
360
     mov    esi,edi          ; 1
368
     shl    esi,6            ; 1
361
     shl    esi,6            ; 1
369
     add    esi,irq00read    ; 1
362
     add    esi,irq00read    ; 1
370
     shl    edi,12           ; 1
363
     shl    edi,12           ; 1
371
     add    edi,0x2E0000
364
     add    edi,0x2E0000
372
 
365
 
373
     mov    [check_idle_semaphore],5
366
     mov    [check_idle_semaphore],5
374
 
367
 
375
   irqnewread:
368
   irqnewread:
376
 
369
 
377
     mov    dx,[esi]         ; 2+
370
     mov    dx,[esi]         ; 2+
378
 
371
 
379
     cmp    dx,0             ; 1
372
     cmp    dx,0             ; 1
380
     jz     irqover
373
     jz     irqover
381
     cmp    [esi+3],byte 1   ; 2     ; byte read
374
     cmp    [esi+3],byte 1   ; 2     ; byte read
382
     jne    noirqbyte        ; 4-11
375
     jne    noirqbyte        ; 4-11
383
 
376
 
384
     in     al,dx
377
     in     al,dx
385
 
378
 
386
     mov    edx,[edi]
379
     mov    edx,[edi]
387
     cmp    edx,4000
380
     cmp    edx,4000
388
     je     irqfull
381
     je     irqfull
389
     mov    ebx,edi
382
     mov    ebx,edi
390
     add    ebx,0x10
383
     add    ebx,0x10
391
     add    ebx,edx
384
     add    ebx,edx
392
     mov    [ebx],al
385
     mov    [ebx],al
393
     inc    edx
386
     inc    edx
394
     mov    [edi],edx
387
     mov    [edi],edx
395
 
388
 
396
     add    esi,4
389
     add    esi,4
397
     jmp    irqnewread
390
     jmp    irqnewread
398
 
391
 
399
   noirqbyte:
392
   noirqbyte:
400
 
393
 
401
 
394
 
402
     cmp    [esi+3],byte 2     ; word read
395
     cmp    [esi+3],byte 2     ; word read
403
     jne    noirqword
396
     jne    noirqword
404
 
397
 
405
     in     ax,dx
398
     in     ax,dx
406
 
399
 
407
     mov    edx,[edi]
400
     mov    edx,[edi]
408
     cmp    edx,4000
401
     cmp    edx,4000
409
     je     irqfull
402
     je     irqfull
410
     mov    ebx,edi
403
     mov    ebx,edi
411
     add    ebx,0x10
404
     add    ebx,0x10
412
     add    ebx,edx
405
     add    ebx,edx
413
     mov    [ebx],ax
406
     mov    [ebx],ax
414
     add    edx,2
407
     add    edx,2
415
     mov    [edi],edx
408
     mov    [edi],edx
416
     add    esi,4
409
     add    esi,4
417
     jmp    irqnewread
410
     jmp    irqnewread
418
 
411
 
419
   noirqword:
412
   noirqword:
420
   irqfull:
413
   irqfull:
421
   irqover:
414
   irqover:
422
 
415
 
423
     mov    al,0x20            ; ready for next irq
416
     mov    al,0x20            ; ready for next irq
424
     out    0x20,al
417
     out    0x20,al
425
 
418
 
426
     pop    ebx
419
     pop    ebx
427
     cmp    ebx,7
420
     cmp    ebx,7
428
     jbe    noa0
421
     jbe    noa0
429
     out    0xa0,al
422
     out    0xa0,al
430
   noa0:
423
   noa0:
431
 
424
 
432
     ret
425
     ret
433
 
426
 
434
 
427
 
435
 
428
 
436
set_application_table_status:
429
set_application_table_status:
437
        push eax
430
        push eax
438
 
431
 
439
        mov  eax,[0x3000]
432
        mov  eax,[0x3000]
440
        shl  eax, 5
433
        shl  eax, 5
441
        add  eax,0x3000+4
434
        add  eax,0x3000+4
442
        mov  eax,[eax]
435
        mov  eax,[eax]
443
 
436
 
444
        mov  [application_table_status],eax
437
        mov  [application_table_status],eax
445
 
438
 
446
        pop  eax
439
        pop  eax
447
 
440
 
448
        ret
441
        ret
449
 
442
 
450
 
443
 
451
clear_application_table_status:
444
clear_application_table_status:
452
        push eax
445
        push eax
453
 
446
 
454
        mov  eax,[0x3000]
447
        mov  eax,[0x3000]
455
        shl  eax, 5
448
        shl  eax, 5
456
        add  eax,0x3000+4
449
        add  eax,0x3000+4
457
        mov  eax,[eax]
450
        mov  eax,[eax]
458
 
451
 
459
        cmp  eax,[application_table_status]
452
        cmp  eax,[application_table_status]
460
        jne  apptsl1
453
        jne  apptsl1
461
        mov  [application_table_status],0
454
        mov  [application_table_status],0
462
      apptsl1:
455
      apptsl1:
463
 
456
 
464
        pop  eax
457
        pop  eax
465
 
458
 
466
        ret
459
        ret
467
 
460
 
468
 
461
 
469
 
462
 
470
sys_resize_app_memory:
463
sys_resize_app_memory:
471
        ; eax = 1 - resize
464
        ; eax = 1 - resize
472
        ;     ebx = new amount of memory
465
        ;     ebx = new amount of memory
473
 
466
 
474
        cmp    eax,1
467
        cmp    eax,1
475
        jne    .no_application_mem_resize
468
        jne    .no_application_mem_resize
476
        
469
        
477
        jmp    new_mem_resize ;resize for new type of processes
470
        jmp    new_mem_resize ;resize for new type of processes
478
 
471
 
479
 
472
 
480
     .no_application_mem_resize:
473
     .no_application_mem_resize:
481
 
474
 
482
        ret
475
        ret
483
 
476
 
484
 
477
 
485
 
478
 
486
get_app_params:
479
get_app_params:
487
 
480
 
488
    push eax
481
    push eax
489
 
482
 
490
    cmp  [0x90000+6],word '00'
483
    cmp  [0x90000+6],word '00'
491
    jne  no_00_header
484
    jne  no_00_header
492
 
485
 
493
    mov  eax,[0x90000+12]
486
    mov  eax,[0x90000+12]
494
    mov  [app_start],eax
487
    mov  [app_start],eax
495
    mov  eax,[0x90000+16]
488
    mov  eax,[0x90000+16]
496
    mov  [app_i_end],eax
489
    mov  [app_i_end],eax
497
    mov  eax,[0x90000+20]
490
    mov  eax,[0x90000+20]
498
    mov  [app_mem],eax
491
    mov  [app_mem],eax
499
    shr  eax,1
492
    shr  eax,1
500
    sub  eax,0x10
493
    sub  eax,0x10
501
    mov  [app_esp],eax
494
    mov  [app_esp],eax
502
    mov  eax,[0x90000+24]
495
    mov  eax,[0x90000+24]
503
    mov  [app_i_param],eax
496
    mov  [app_i_param],eax
504
    mov  [app_i_icon],dword 0
497
    mov  [app_i_icon],dword 0
505
 
498
 
506
    pop  eax
499
    pop  eax
507
    mov  esi,1
500
    mov  esi,1
508
    ret
501
    ret
509
 
502
 
510
  no_00_header:
503
  no_00_header:
511
 
504
 
512
 
505
 
513
    cmp  [0x90000+6],word '01'
506
    cmp  [0x90000+6],word '01'
514
    jne  no_01_header
507
    jne  no_01_header
515
 
508
 
516
    mov  eax,[0x90000+12]
509
    mov  eax,[0x90000+12]
517
    mov  [app_start],eax
510
    mov  [app_start],eax
518
    mov  eax,[0x90000+16]
511
    mov  eax,[0x90000+16]
519
    mov  [app_i_end],eax
512
    mov  [app_i_end],eax
520
    mov  eax,[0x90000+20]
513
    mov  eax,[0x90000+20]
521
    mov  [app_mem],eax
514
    mov  [app_mem],eax
522
    mov  eax,[0x90000+24]
515
    mov  eax,[0x90000+24]
523
    mov  [app_esp],eax
516
    mov  [app_esp],eax
524
    mov  eax,[0x90000+28]
517
    mov  eax,[0x90000+28]
525
    mov  [app_i_param],eax
518
    mov  [app_i_param],eax
526
    mov  eax,[0x90000+32]
519
    mov  eax,[0x90000+32]
527
    mov  [app_i_icon],eax
520
    mov  [app_i_icon],eax
528
 
521
 
529
    pop  eax
522
    pop  eax
530
    mov  esi,1
523
    mov  esi,1
531
    ret
524
    ret
532
 
525
 
533
   no_01_header:
526
   no_01_header:
534
 
527
 
535
    pop  eax
528
    pop  eax
536
    mov  esi,0
529
    mov  esi,0
537
    ret
530
    ret
538
 
531
 
539
 
532
 
540
start_application_fl:
533
start_application_fl:
541
    jmp new_start_application_fl
534
    jmp new_start_application_fl
542
 
535
 
543
;************************************************************************
536
;************************************************************************
544
 
537
 
545
start_application_floppy:
538
start_application_floppy:
546
    jmp  new_start_application_floppy
539
    jmp  new_start_application_floppy
547
 
540
 
548
;********************************************************************
541
;********************************************************************
549
 
542
 
550
start_application_hd:
543
start_application_hd:
551
    jmp   new_start_application_hd
544
    jmp   new_start_application_hd
552
 
545
 
553
uglobal
546
uglobal
554
  new_process_place  dd  0x0
547
  new_process_place  dd  0x0
555
  app_start    dd  0x0
548
  app_start    dd  0x0
556
  app_i_end    dd  0x0
549
  app_i_end    dd  0x0
557
  app_mem      dd  0x0
550
  app_mem      dd  0x0
558
  app_esp      dd  0x0
551
  app_esp      dd  0x0
559
  app_i_param  dd  0x0
552
  app_i_param  dd  0x0
560
  app_i_icon   dd  0x0
553
  app_i_icon   dd  0x0
561
  app_mem_pos  dd  0x0
554
  app_mem_pos  dd  0x0
562
  appl_path        dd 0x0
555
  appl_path        dd 0x0
563
  appl_path_size   dd 0x0         
556
  appl_path_size   dd 0x0         
564
endg
557
endg
565
 
558
 
566
iglobal
559
iglobal
567
  hd_app_string      db  'HDAPP       '
560
  hd_app_string      db  'HDAPP       '
568
  process_loading    db 'K : Process - loading ',13,10,0
561
  process_loading    db 'K : Process - loading ',13,10,0
569
  process_running    db 'K : Process - done',13,10,0
562
  process_running    db 'K : Process - done',13,10,0
570
  first_gdt_search   dd 0x2
563
  first_gdt_search   dd 0x2
571
endg
564
endg
572
 
565
 
573
 
566
 
574
sys_threads:
567
sys_threads:
575
 
568
 
576
; eax=1 create thread
569
; eax=1 create thread
577
;
570
;
578
;   ebx=thread start
571
;   ebx=thread start
579
;   ecx=thread stack value
572
;   ecx=thread stack value
580
;
573
;
581
; on return : eax = pid
574
; on return : eax = pid
582
jmp new_sys_threads
575
jmp new_sys_threads
583
 
576
 
584
iglobal
577
iglobal
585
  process_terminating   db 'K : Process - terminating',13,10,0
578
  process_terminating   db 'K : Process - terminating',13,10,0
586
  process_terminated    db 'K : Process - done',13,10,0
579
  process_terminated    db 'K : Process - done',13,10,0
587
endg
580
endg
588
 
581
 
589
 
582
 
590
terminate: ; terminate application
583
terminate: ; terminate application
591
    push   esi
584
    push   esi
592
    mov    esi,process_terminating
585
    mov    esi,process_terminating
593
    call   sys_msg_board_str
586
    call   sys_msg_board_str
594
    pop    esi
587
    pop    esi
595
 
588
 
596
    cli
589
    cli
597
    cmp   [application_table_status],0
590
    cmp   [application_table_status],0
598
    je    term9
591
    je    term9
599
    sti
592
    sti
600
    call  change_task
593
    call  change_task
601
    jmp   terminate
594
    jmp   terminate
602
  term9:
595
  term9:
603
 
596
 
604
    call  set_application_table_status
597
    call  set_application_table_status
605
    
598
    
606
    mov    eax,esi
599
    mov    eax,esi
607
    call   dispose_app_cr3_table
600
    call   dispose_app_cr3_table
608
 
601
 
609
    cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
602
    cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
610
    jne   fpu_ok_1
603
    jne   fpu_ok_1
611
    mov   [prev_user_of_fpu],1
604
    mov   [prev_user_of_fpu],1
612
  fpu_ok_1:
605
  fpu_ok_1:
613
 
606
 
614
    mov   [0xf400],byte 0           ; empty keyboard buffer
607
    mov   [0xf400],byte 0           ; empty keyboard buffer
615
    mov   [0xf500],byte 0           ; empty button buffer
608
    mov   [0xf500],byte 0           ; empty button buffer
616
 
609
 
617
 
610
 
618
    mov   ecx,esi                 ; remove buttons
611
    mov   ecx,esi                 ; remove buttons
619
  bnewba2:
612
  bnewba2:
620
    mov   edi,[0xfe88]
613
    mov   edi,[0xfe88]
621
    mov   eax,edi
614
    mov   eax,edi
622
    cld
615
    cld
623
    movzx ebx,word [edi]
616
    movzx ebx,word [edi]
624
    inc   bx
617
    inc   bx
625
  bnewba:
618
  bnewba:
626
    dec   bx
619
    dec   bx
627
    jz    bnmba
620
    jz    bnmba
628
    add   eax,0x10
621
    add   eax,0x10
629
    cmp   cx,[eax]
622
    cmp   cx,[eax]
630
    jnz   bnewba
623
    jnz   bnewba
631
    pusha
624
    pusha
632
    mov   ecx,ebx
625
    mov   ecx,ebx
633
    inc   ecx
626
    inc   ecx
634
    shl   ecx,4
627
    shl   ecx,4
635
    mov   ebx,eax
628
    mov   ebx,eax
636
    add   eax,0x10
629
    add   eax,0x10
637
    call  memmove
630
    call  memmove
638
    dec   dword [edi]
631
    dec   dword [edi]
639
    popa
632
    popa
640
    jmp   bnewba2
633
    jmp   bnewba2
641
  bnmba:
634
  bnmba:
642
 
635
 
643
    pusha     ; save window coordinates for window restoring
636
    pusha     ; save window coordinates for window restoring
644
    cld
637
    cld
645
    shl   esi,5
638
    shl   esi,5
646
    add   esi,window_data
639
    add   esi,window_data
647
    mov   ax,[esi+0]
640
    mov   ax,[esi+0]
648
    mov   word [dlx],ax
641
    mov   word [dlx],ax
649
    mov   bx,[esi+8]
642
    mov   bx,[esi+8]
650
    add   ax,bx
643
    add   ax,bx
651
    mov   word [dlxe],ax
644
    mov   word [dlxe],ax
652
    mov   ax,[esi+4]
645
    mov   ax,[esi+4]
653
    mov   word [dly],ax
646
    mov   word [dly],ax
654
    mov   bx,[esi+12]
647
    mov   bx,[esi+12]
655
    add   ax,bx
648
    add   ax,bx
656
    mov   word [dlye],ax
649
    mov   word [dlye],ax
657
    mov   [esi+0],word 0
650
    mov   [esi+0],word 0
658
    mov   [esi+8],word 5
651
    mov   [esi+8],word 5
659
    mov   ax,[0xFE04]
652
    mov   ax,[0xFE04]
660
    mov   [esi+4],ax
653
    mov   [esi+4],ax
661
    mov   [esi+12],word 5
654
    mov   [esi+12],word 5
662
    xor   eax, eax
655
    xor   eax, eax
663
    mov   [esi+16],eax;dword 0
656
    mov   [esi+16],eax;dword 0
664
    mov   [esi+20],eax;dword 0
657
    mov   [esi+20],eax;dword 0
665
    mov   [esi+24],eax;dword 0
658
    mov   [esi+24],eax;dword 0
666
    mov   [esi+28],eax;dword 0
659
    mov   [esi+28],eax;dword 0
667
    popa
660
    popa
668
 
661
 
669
    pusha
662
    pusha
670
    mov   edi,esi
663
    mov   edi,esi
671
    shl   edi,5
664
    shl   edi,5
672
    add   edi,window_data
665
    add   edi,window_data
673
    mov   ecx,32/4
666
    mov   ecx,32/4
674
    xor   eax, eax
667
    xor   eax, eax
675
  ;  cld
668
  ;  cld
676
    rep   stosd
669
    rep   stosd
677
 
670
 
678
    mov   eax,[0xFE04]      ; set window to start from maxy+1
671
    mov   eax,[0xFE04]      ; set window to start from maxy+1
679
    add   eax,2
672
    add   eax,2
680
 
673
 
681
    mov   edi,esi
674
    mov   edi,esi
682
    shl   edi,5
675
    shl   edi,5
683
    add   edi,window_data
676
    add   edi,window_data
684
    mov   [edi+4],eax
677
    mov   [edi+4],eax
685
 
678
 
686
    popa
679
    popa
687
 
680
 
688
    pusha
681
    pusha
689
    mov   edi,esi
682
    mov   edi,esi
690
    shl   edi,5
683
    shl   edi,5
691
    add   edi,draw_data
684
    add   edi,draw_data
692
    mov   ecx,32/4
685
    mov   ecx,32/4
693
    xor   eax, eax
686
    xor   eax, eax
694
  ;  cld
687
  ;  cld
695
    rep   stosd
688
    rep   stosd
696
    popa
689
    popa
697
 
690
 
698
    pusha         ; at 0x80000+
691
    pusha         ; at 0x80000+
699
    mov   edi,esi
692
    mov   edi,esi
700
    shl   edi,8
693
    shl   edi,8
701
    add   edi,0x80000
694
    add   edi,0x80000
702
    mov   ecx,256/4
695
    mov   ecx,256/4
703
    xor   eax, eax
696
    xor   eax, eax
704
  ;  cld
697
  ;  cld
705
    rep   stosd
698
    rep   stosd
706
    popa
699
    popa
707
 
700
 
708
    pusha          ; name to spaces
701
    pusha          ; name to spaces
709
    mov   edi,esi
702
    mov   edi,esi
710
    shl   edi,8
703
    shl   edi,8
711
    add   edi,0x80000
704
    add   edi,0x80000
712
    mov   ecx,11
705
    mov   ecx,11
713
    mov   eax,' '
706
    mov   eax,' '
714
  ;  cld
707
  ;  cld
715
    rep   stosb
708
    rep   stosb
716
    popa
709
    popa
717
 
710
 
718
    pusha                ; C000 --> C400
711
    pusha                ; C000 --> C400
719
    mov   eax, 0xc000
712
    mov   eax, 0xc000
720
    mov   esi, 0
713
    mov   esi, 0
721
  nlc40:
714
  nlc40:
722
    add   eax, 2
715
    add   eax, 2
723
    inc   esi
716
    inc   esi
724
    cmp   esi, [0x3004]
717
    cmp   esi, [0x3004]
725
    jae   nlc41
718
    jae   nlc41
726
    movzx ecx, word [eax]
719
    movzx ecx, word [eax]
727
    mov   [0xC400 + ecx*2], si
720
    mov   [0xC400 + ecx*2], si
728
    jmp   nlc40
721
    jmp   nlc40
729
  nlc41:
722
  nlc41:
730
    popa
723
    popa
731
 
724
 
732
    pusha ; remove hd1 reservation
725
    pusha ; remove hd1 reservation
733
    mov   edx,esi
726
    mov   edx,esi
734
    shl   edx, 5 ;imul  edx,0x20
727
    shl   edx, 5 ;imul  edx,0x20
735
    add   edx,0x3000
728
    add   edx,0x3000
736
    mov   edx,[edx+4]
729
    mov   edx,[edx+4]
737
    cmp   [hd1_status],edx
730
    cmp   [hd1_status],edx
738
    jne   no_hd1_s_remove
731
    jne   no_hd1_s_remove
739
    mov   [hd1_status],0
732
    mov   [hd1_status],0
740
  no_hd1_s_remove:
733
  no_hd1_s_remove:
741
    popa
734
    popa
742
 
735
 
743
    pusha ; remove all irq reservations
736
    pusha ; remove all irq reservations
744
    mov   edx,esi
737
    mov   edx,esi
745
    shl   edx, 5 ;imul  edx,0x20
738
    shl   edx, 5 ;imul  edx,0x20
746
    add   edx,0x3000
739
    add   edx,0x3000
747
    mov   edx,[edx+4]
740
    mov   edx,[edx+4]
748
    mov   edi,irq_owner
741
    mov   edi,irq_owner
749
    mov   ecx,16
742
    mov   ecx,16
750
  newirqfree:
743
  newirqfree:
751
    cmp   [edi],edx
744
    cmp   [edi],edx
752
    jne   nofreeirq
745
    jne   nofreeirq
753
    mov   [edi],dword 0
746
    mov   [edi],dword 0
754
  nofreeirq:
747
  nofreeirq:
755
    add    edi,4
748
    add    edi,4
756
    loop   newirqfree
749
    loop   newirqfree
757
    popa
750
    popa
758
 
751
 
759
 
752
 
760
    pusha                     ; remove all port reservations
753
    pusha                     ; remove all port reservations
761
 
754
 
762
    mov   edx,esi
755
    mov   edx,esi
763
    shl   edx, 5 ;imul  edx,0x20
756
    shl   edx, 5 ;imul  edx,0x20
764
    add   edx,0x3000
757
    add   edx,0x3000
765
    mov   edx,[edx+4]
758
    mov   edx,[edx+4]
766
 
759
 
767
  rmpr0:
760
  rmpr0:
768
 
761
 
769
    mov   esi,[0x2d0000]
762
    mov   esi,[0x2d0000]
770
 
763
 
771
    cmp   esi,0
764
    cmp   esi,0
772
    je    rmpr9
765
    je    rmpr9
773
 
766
 
774
  rmpr3:
767
  rmpr3:
775
 
768
 
776
    mov   edi,esi
769
    mov   edi,esi
777
    shl   edi,4
770
    shl   edi,4
778
    add   edi,0x2d0000
771
    add   edi,0x2d0000
779
 
772
 
780
    cmp   edx,[edi]
773
    cmp   edx,[edi]
781
    je    rmpr4
774
    je    rmpr4
782
 
775
 
783
    dec   esi
776
    dec   esi
784
    jnz   rmpr3
777
    jnz   rmpr3
785
 
778
 
786
    jmp   rmpr9
779
    jmp   rmpr9
787
 
780
 
788
  rmpr4:
781
  rmpr4:
789
 
782
 
790
    mov   ecx,256
783
    mov   ecx,256
791
    sub   ecx,esi
784
    sub   ecx,esi
792
    shl   ecx,4
785
    shl   ecx,4
793
 
786
 
794
    mov   esi,edi
787
    mov   esi,edi
795
    add   esi,16
788
    add   esi,16
796
    cld
789
    cld
797
    rep   movsb
790
    rep   movsb
798
 
791
 
799
    dec   dword [0x2d0000]
792
    dec   dword [0x2d0000]
800
 
793
 
801
    jmp   rmpr0
794
    jmp   rmpr0
802
 
795
 
803
  rmpr9:
796
  rmpr9:
804
 
797
 
805
    popa
798
    popa
806
    mov  edi,esi         ; do not run this process slot
799
    mov  edi,esi         ; do not run this process slot
807
    shl  edi, 5
800
    shl  edi, 5
808
    mov  [edi+0x300A],byte 9
801
    mov  [edi+0x300A],byte 9
809
;    call  systest
802
;    call  systest
810
    sti  ; .. and life goes on
803
    sti  ; .. and life goes on
811
 
804
 
812
;    movzx eax,word [dlx]
805
;    movzx eax,word [dlx]
813
;    movzx ebx,word [dly]
806
;    movzx ebx,word [dly]
814
;    movzx ecx,word [dlxe]
807
;    movzx ecx,word [dlxe]
815
;    movzx edx,word [dlye]
808
;    movzx edx,word [dlye]
816
    call  calculatescreen
809
    call  calculatescreen
817
 
810
 
818
    xor   eax, eax
811
    xor   eax, eax
819
    xor   esi, esi
812
    xor   esi, esi
820
    call  redrawscreen
813
    call  redrawscreen
821
 
814
 
822
    mov   [0xfff4],byte 0  ; no mouse background
815
    mov   [0xfff4],byte 0  ; no mouse background
823
    mov   [0xfff5],byte 0  ; draw mouse
816
    mov   [0xfff5],byte 0  ; draw mouse
824
 
817
 
825
    mov   [application_table_status],0
818
    mov   [application_table_status],0
826
 
819
 
827
    mov   esi,process_terminated
820
    mov   esi,process_terminated
828
    call  sys_msg_board_str
821
    call  sys_msg_board_str
829
 
822
 
830
;* start code - fix error redraw for terminate (2) - Mario79
823
;* start code - fix error redraw for terminate (2) - Mario79
831
;     cmp  [draw_present],1
824
;     cmp  [draw_present],1
832
;     je  no_draw_background_temp
825
;     je  no_draw_background_temp
833
;     mov   [0xfff0],byte 1
826
;     mov   [0xfff0],byte 1
834
;no_draw_background_temp:
827
;no_draw_background_temp:
835
;    mov   [draw_present],0
828
;    mov   [draw_present],0
836
    ret
829
    ret
837
;draw_present db 0
830
;draw_present db 0
838
;* end code - fix error redraw for terminate (2) - Mario79
831
;* end code - fix error redraw for terminate (2) - Mario79
839
 
832
 
840
iglobal
833
iglobal
841
  boot_sched_1    db   'Building gdt tss pointer',0
834
  boot_sched_1    db   'Building gdt tss pointer',0
842
  boot_sched_2    db   'Building IDT table',0
835
  boot_sched_2    db   'Building IDT table',0
843
endg
836
endg
844
 
837
 
845
 
838
 
846
build_scheduler:
839
build_scheduler:
847
 
840
 
848
        mov    esi,boot_sched_1
841
        mov    esi,boot_sched_1
849
        call   boot_log
842
        call   boot_log
850
        call   build_process_gdt_tss_pointer
843
        call   build_process_gdt_tss_pointer
851
 
844
 
852
        mov    esi,boot_sched_2
845
        mov    esi,boot_sched_2
853
        call   boot_log
846
        call   boot_log
854
        call   build_interrupt_table
847
        call   build_interrupt_table
855
 
848
 
856
        ret
849
        ret