Subversion Repositories Kolibri OS

Rev

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

Rev 10 Rev 11
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
        jz     @f
286
        mov    esi,system_error
286
        mov    esi,system_error
287
        call   sys_msg_board_str
287
        call   sys_msg_board_str
288
      @@:
288
      @@:
289
        
289
        
290
        mov    eax,[0x3000]
290
        mov    eax,[0x3000]
291
        imul   eax,tss_step
291
        imul   eax,tss_step
292
        mov    eax,[eax+tss_data+l.eip-tss_sceleton]
292
        mov    eax,[eax+tss_data+l.eip-tss_sceleton]
293
 
293
 
294
        mov    [write_error_to],process_eip+43
294
        mov    [write_error_to],process_eip+43
295
        call   writehex
295
        call   writehex
296
 
296
 
297
        mov    esi,process_error
297
        mov    esi,process_error
298
        call   sys_msg_board_str
298
        call   sys_msg_board_str
299
 
299
 
300
        mov    esi,process_pid
300
        mov    esi,process_pid
301
        call   sys_msg_board_str
301
        call   sys_msg_board_str
302
 
302
 
303
        mov    esi,process_eip
303
        mov    esi,process_eip
304
        call   sys_msg_board_str
304
        call   sys_msg_board_str
305
 
305
 
306
        ret
306
        ret
307
 
307
 
308
 
308
 
309
 
309
 
310
; irq1  ->  hid/keyboard.inc
310
; irq1  ->  hid/keyboard.inc
311
 
311
 
312
 
312
 
313
macro irqh [num]
313
macro irqh [num]
314
{
314
{
315
  forward
315
  forward
316
  p_irq#num :
316
  p_irq#num :
317
     pushad
317
     pushad
318
     mov   edi, num
318
     mov   edi, num
319
     jmp   irq_c
319
     jmp   irq_c
320
}
320
}
321
 
321
 
322
irqh 2,3,4,5,6,7,8,9,10,11,12,14,15
322
irqh 2,3,4,5,7,8,9,10,11,12,14,15
323
 
323
 
324
 irq_c:
324
 irq_c:
325
     push  ds es
325
     push  ds es
326
     mov   ax, os_data
326
     mov   ax, os_data
327
     mov   ds, ax
327
     mov   ds, ax
328
     mov   es, ax
328
     mov   es, ax
329
     call  irqhandler
329
     call  irqhandler
330
     pop   es ds
330
     pop   es ds
331
     popad
331
     popad
332
     iret
332
     iret
-
 
333
 
-
 
334
p_irq6:
-
 
335
     pushad
-
 
336
     push  ds es
-
 
337
     mov   ax, os_data
-
 
338
     mov   ds, ax
-
 
339
     mov   es, ax
-
 
340
     call  fdc_irq
-
 
341
     pop   es ds
-
 
342
     popad
-
 
343
     iret
333
  	
344
 
334
irqD:
345
irqD:
335
     pushad
346
     pushad
336
     push  ds es
347
     push  ds es
337
     mov   ax, os_data
348
     mov   ax, os_data
338
     mov   ds, ax
349
     mov   ds, ax
339
     mov   es, ax
350
     mov   es, ax
340
     
351
     
341
     mov   dx,0xf0
352
     mov   dx,0xf0
342
     mov   al,0
353
     mov   al,0
343
     out   dx,al
354
     out   dx,al
344
 
355
 
345
     mov   dx,0xa0
356
     mov   dx,0xa0
346
     mov   al,0x20
357
     mov   al,0x20
347
     out   dx,al
358
     out   dx,al
348
     mov   dx,0x20
359
     mov   dx,0x20
349
     out   dx,al     
360
     out   dx,al     
350
     
361
     
351
     pop   es ds
362
     pop   es ds
352
     popad
363
     popad
353
     iret
364
     iret
354
 
365
 
355
 
366
 
356
irqhandler:
367
irqhandler:
357
 
368
 
358
     push   edi
369
     push   edi
359
 
370
 
360
     mov    esi,edi          ; 1
371
     mov    esi,edi          ; 1
361
     shl    esi,6            ; 1
372
     shl    esi,6            ; 1
362
     add    esi,irq00read    ; 1
373
     add    esi,irq00read    ; 1
363
     shl    edi,12           ; 1
374
     shl    edi,12           ; 1
364
     add    edi,0x2E0000
375
     add    edi,0x2E0000
365
 
376
 
366
     mov    [check_idle_semaphore],5
377
     mov    [check_idle_semaphore],5
367
 
378
 
368
   irqnewread:
379
   irqnewread:
369
 
380
 
370
     mov    dx,[esi]         ; 2+
381
     mov    dx,[esi]         ; 2+
371
 
382
 
372
     cmp    dx,0             ; 1
383
     cmp    dx,0             ; 1
373
     jz     irqover
384
     jz     irqover
374
     cmp    [esi+3],byte 1   ; 2     ; byte read
385
     cmp    [esi+3],byte 1   ; 2     ; byte read
375
     jne    noirqbyte        ; 4-11
386
     jne    noirqbyte        ; 4-11
376
 
387
 
377
     in     al,dx
388
     in     al,dx
378
 
389
 
379
     mov    edx,[edi]
390
     mov    edx,[edi]
380
     cmp    edx,4000
391
     cmp    edx,4000
381
     je     irqfull
392
     je     irqfull
382
     mov    ebx,edi
393
     mov    ebx,edi
383
     add    ebx,0x10
394
     add    ebx,0x10
384
     add    ebx,edx
395
     add    ebx,edx
385
     mov    [ebx],al
396
     mov    [ebx],al
386
     inc    edx
397
     inc    edx
387
     mov    [edi],edx
398
     mov    [edi],edx
388
 
399
 
389
     add    esi,4
400
     add    esi,4
390
     jmp    irqnewread
401
     jmp    irqnewread
391
 
402
 
392
   noirqbyte:
403
   noirqbyte:
393
 
404
 
394
 
405
 
395
     cmp    [esi+3],byte 2     ; word read
406
     cmp    [esi+3],byte 2     ; word read
396
     jne    noirqword
407
     jne    noirqword
397
 
408
 
398
     in     ax,dx
409
     in     ax,dx
399
 
410
 
400
     mov    edx,[edi]
411
     mov    edx,[edi]
401
     cmp    edx,4000
412
     cmp    edx,4000
402
     je     irqfull
413
     je     irqfull
403
     mov    ebx,edi
414
     mov    ebx,edi
404
     add    ebx,0x10
415
     add    ebx,0x10
405
     add    ebx,edx
416
     add    ebx,edx
406
     mov    [ebx],ax
417
     mov    [ebx],ax
407
     add    edx,2
418
     add    edx,2
408
     mov    [edi],edx
419
     mov    [edi],edx
409
     add    esi,4
420
     add    esi,4
410
     jmp    irqnewread
421
     jmp    irqnewread
411
 
422
 
412
   noirqword:
423
   noirqword:
413
   irqfull:
424
   irqfull:
414
   irqover:
425
   irqover:
415
 
426
 
416
     mov    al,0x20            ; ready for next irq
427
     mov    al,0x20            ; ready for next irq
417
     out    0x20,al
428
     out    0x20,al
418
 
429
 
419
     pop    ebx
430
     pop    ebx
420
     cmp    ebx,7
431
     cmp    ebx,7
421
     jbe    noa0
432
     jbe    noa0
422
     out    0xa0,al
433
     out    0xa0,al
423
   noa0:
434
   noa0:
424
 
435
 
425
     ret
436
     ret
426
 
437
 
427
 
438
 
428
 
439
 
429
set_application_table_status:
440
set_application_table_status:
430
        push eax
441
        push eax
431
 
442
 
432
        mov  eax,[0x3000]
443
        mov  eax,[0x3000]
433
        shl  eax, 5
444
        shl  eax, 5
434
        add  eax,0x3000+4
445
        add  eax,0x3000+4
435
        mov  eax,[eax]
446
        mov  eax,[eax]
436
 
447
 
437
        mov  [application_table_status],eax
448
        mov  [application_table_status],eax
438
 
449
 
439
        pop  eax
450
        pop  eax
440
 
451
 
441
        ret
452
        ret
442
 
453
 
443
 
454
 
444
clear_application_table_status:
455
clear_application_table_status:
445
        push eax
456
        push eax
446
 
457
 
447
        mov  eax,[0x3000]
458
        mov  eax,[0x3000]
448
        shl  eax, 5
459
        shl  eax, 5
449
        add  eax,0x3000+4
460
        add  eax,0x3000+4
450
        mov  eax,[eax]
461
        mov  eax,[eax]
451
 
462
 
452
        cmp  eax,[application_table_status]
463
        cmp  eax,[application_table_status]
453
        jne  apptsl1
464
        jne  apptsl1
454
        mov  [application_table_status],0
465
        mov  [application_table_status],0
455
      apptsl1:
466
      apptsl1:
456
 
467
 
457
        pop  eax
468
        pop  eax
458
 
469
 
459
        ret
470
        ret
460
 
471
 
461
 
472
 
462
 
473
 
463
sys_resize_app_memory:
474
sys_resize_app_memory:
464
        ; eax = 1 - resize
475
        ; eax = 1 - resize
465
        ;     ebx = new amount of memory
476
        ;     ebx = new amount of memory
466
 
477
 
467
        cmp    eax,1
478
        cmp    eax,1
468
        jne    .no_application_mem_resize
479
        jne    .no_application_mem_resize
469
        
480
        
470
        jmp    new_mem_resize ;resize for new type of processes
481
        jmp    new_mem_resize ;resize for new type of processes
471
 
482
 
472
 
483
 
473
     .no_application_mem_resize:
484
     .no_application_mem_resize:
474
 
485
 
475
        ret
486
        ret
476
 
487
 
477
 
488
 
478
 
489
 
479
get_app_params:
490
get_app_params:
480
 
491
 
481
    push eax
492
    push eax
482
 
493
 
483
    cmp  [0x90000+6],word '00'
494
    cmp  [0x90000+6],word '00'
484
    jne  no_00_header
495
    jne  no_00_header
485
 
496
 
486
    mov  eax,[0x90000+12]
497
    mov  eax,[0x90000+12]
487
    mov  [app_start],eax
498
    mov  [app_start],eax
488
    mov  eax,[0x90000+16]
499
    mov  eax,[0x90000+16]
489
    mov  [app_i_end],eax
500
    mov  [app_i_end],eax
490
    mov  eax,[0x90000+20]
501
    mov  eax,[0x90000+20]
491
    mov  [app_mem],eax
502
    mov  [app_mem],eax
492
    shr  eax,1
503
    shr  eax,1
493
    sub  eax,0x10
504
    sub  eax,0x10
494
    mov  [app_esp],eax
505
    mov  [app_esp],eax
495
    mov  eax,[0x90000+24]
506
    mov  eax,[0x90000+24]
496
    mov  [app_i_param],eax
507
    mov  [app_i_param],eax
497
    mov  [app_i_icon],dword 0
508
    mov  [app_i_icon],dword 0
498
 
509
 
499
    pop  eax
510
    pop  eax
500
    mov  esi,1
511
    mov  esi,1
501
    ret
512
    ret
502
 
513
 
503
  no_00_header:
514
  no_00_header:
504
 
515
 
505
 
516
 
506
    cmp  [0x90000+6],word '01'
517
    cmp  [0x90000+6],word '01'
507
    jne  no_01_header
518
    jne  no_01_header
508
 
519
 
509
    mov  eax,[0x90000+12]
520
    mov  eax,[0x90000+12]
510
    mov  [app_start],eax
521
    mov  [app_start],eax
511
    mov  eax,[0x90000+16]
522
    mov  eax,[0x90000+16]
512
    mov  [app_i_end],eax
523
    mov  [app_i_end],eax
513
    mov  eax,[0x90000+20]
524
    mov  eax,[0x90000+20]
514
    mov  [app_mem],eax
525
    mov  [app_mem],eax
515
    mov  eax,[0x90000+24]
526
    mov  eax,[0x90000+24]
516
    mov  [app_esp],eax
527
    mov  [app_esp],eax
517
    mov  eax,[0x90000+28]
528
    mov  eax,[0x90000+28]
518
    mov  [app_i_param],eax
529
    mov  [app_i_param],eax
519
    mov  eax,[0x90000+32]
530
    mov  eax,[0x90000+32]
520
    mov  [app_i_icon],eax
531
    mov  [app_i_icon],eax
521
 
532
 
522
    pop  eax
533
    pop  eax
523
    mov  esi,1
534
    mov  esi,1
524
    ret
535
    ret
525
 
536
 
526
   no_01_header:
537
   no_01_header:
527
 
538
 
528
    pop  eax
539
    pop  eax
529
    mov  esi,0
540
    mov  esi,0
530
    ret
541
    ret
531
 
542
 
532
 
543
 
533
start_application_fl:
544
start_application_fl:
534
    jmp new_start_application_fl
545
    jmp new_start_application_fl
535
 
546
 
536
;************************************************************************
547
;************************************************************************
537
 
548
 
538
start_application_floppy:
549
start_application_floppy:
539
    jmp  new_start_application_floppy
550
    jmp  new_start_application_floppy
540
 
551
 
541
;********************************************************************
552
;********************************************************************
542
 
553
 
543
start_application_hd:
554
start_application_hd:
544
    jmp   new_start_application_hd
555
    jmp   new_start_application_hd
545
 
556
 
546
uglobal
557
uglobal
547
  new_process_place  dd  0x0
558
  new_process_place  dd  0x0
548
  app_start    dd  0x0
559
  app_start    dd  0x0
549
  app_i_end    dd  0x0
560
  app_i_end    dd  0x0
550
  app_mem      dd  0x0
561
  app_mem      dd  0x0
551
  app_esp      dd  0x0
562
  app_esp      dd  0x0
552
  app_i_param  dd  0x0
563
  app_i_param  dd  0x0
553
  app_i_icon   dd  0x0
564
  app_i_icon   dd  0x0
554
  app_mem_pos  dd  0x0
565
  app_mem_pos  dd  0x0
555
  appl_path        dd 0x0
566
  appl_path        dd 0x0
556
  appl_path_size   dd 0x0         
567
  appl_path_size   dd 0x0         
557
endg
568
endg
558
 
569
 
559
iglobal
570
iglobal
560
  hd_app_string      db  'HDAPP       '
571
  hd_app_string      db  'HDAPP       '
561
  process_loading    db 'K : Process - loading ',13,10,0
572
  process_loading    db 'K : Process - loading ',13,10,0
562
  process_running    db 'K : Process - done',13,10,0
573
  process_running    db 'K : Process - done',13,10,0
563
  first_gdt_search   dd 0x2
574
  first_gdt_search   dd 0x2
564
endg
575
endg
565
 
576
 
566
 
577
 
567
sys_threads:
578
sys_threads:
568
 
579
 
569
; eax=1 create thread
580
; eax=1 create thread
570
;
581
;
571
;   ebx=thread start
582
;   ebx=thread start
572
;   ecx=thread stack value
583
;   ecx=thread stack value
573
;
584
;
574
; on return : eax = pid
585
; on return : eax = pid
575
jmp new_sys_threads
586
jmp new_sys_threads
576
 
587
 
577
iglobal
588
iglobal
578
  process_terminating   db 'K : Process - terminating',13,10,0
589
  process_terminating   db 'K : Process - terminating',13,10,0
579
  process_terminated    db 'K : Process - done',13,10,0
590
  process_terminated    db 'K : Process - done',13,10,0
580
endg
591
endg
581
 
592
 
582
 
593
 
583
terminate: ; terminate application
594
terminate: ; terminate application
584
    push   esi
595
    push   esi
585
    mov    esi,process_terminating
596
    mov    esi,process_terminating
586
    call   sys_msg_board_str
597
    call   sys_msg_board_str
587
    pop    esi
598
    pop    esi
588
 
599
 
589
    cli
600
    cli
590
    cmp   [application_table_status],0
601
    cmp   [application_table_status],0
591
    je    term9
602
    je    term9
592
    sti
603
    sti
593
    call  change_task
604
    call  change_task
594
    jmp   terminate
605
    jmp   terminate
595
  term9:
606
  term9:
596
 
607
 
597
    call  set_application_table_status
608
    call  set_application_table_status
598
    
609
    
599
    mov    eax,esi
610
    mov    eax,esi
600
    call   dispose_app_cr3_table
611
    call   dispose_app_cr3_table
601
 
612
 
602
    cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
613
    cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
603
    jne   fpu_ok_1
614
    jne   fpu_ok_1
604
    mov   [prev_user_of_fpu],1
615
    mov   [prev_user_of_fpu],1
605
  fpu_ok_1:
616
  fpu_ok_1:
606
 
617
 
607
    mov   [0xf400],byte 0           ; empty keyboard buffer
618
    mov   [0xf400],byte 0           ; empty keyboard buffer
608
    mov   [0xf500],byte 0           ; empty button buffer
619
    mov   [0xf500],byte 0           ; empty button buffer
609
 
620
 
610
 
621
 
611
    mov   ecx,esi                 ; remove buttons
622
    mov   ecx,esi                 ; remove buttons
612
  bnewba2:
623
  bnewba2:
613
    mov   edi,[0xfe88]
624
    mov   edi,[0xfe88]
614
    mov   eax,edi
625
    mov   eax,edi
615
    cld
626
    cld
616
    movzx ebx,word [edi]
627
    movzx ebx,word [edi]
617
    inc   bx
628
    inc   bx
618
  bnewba:
629
  bnewba:
619
    dec   bx
630
    dec   bx
620
    jz    bnmba
631
    jz    bnmba
621
    add   eax,0x10
632
    add   eax,0x10
622
    cmp   cx,[eax]
633
    cmp   cx,[eax]
623
    jnz   bnewba
634
    jnz   bnewba
624
    pusha
635
    pusha
625
    mov   ecx,ebx
636
    mov   ecx,ebx
626
    inc   ecx
637
    inc   ecx
627
    shl   ecx,4
638
    shl   ecx,4
628
    mov   ebx,eax
639
    mov   ebx,eax
629
    add   eax,0x10
640
    add   eax,0x10
630
    call  memmove
641
    call  memmove
631
    dec   dword [edi]
642
    dec   dword [edi]
632
    popa
643
    popa
633
    jmp   bnewba2
644
    jmp   bnewba2
634
  bnmba:
645
  bnmba:
635
 
646
 
636
    pusha     ; save window coordinates for window restoring
647
    pusha     ; save window coordinates for window restoring
637
    cld
648
    cld
638
    shl   esi,5
649
    shl   esi,5
639
    add   esi,window_data
650
    add   esi,window_data
640
    mov   ax,[esi+0]
651
    mov   ax,[esi+0]
641
    mov   word [dlx],ax
652
    mov   word [dlx],ax
642
    mov   bx,[esi+8]
653
    mov   bx,[esi+8]
643
    add   ax,bx
654
    add   ax,bx
644
    mov   word [dlxe],ax
655
    mov   word [dlxe],ax
645
    mov   ax,[esi+4]
656
    mov   ax,[esi+4]
646
    mov   word [dly],ax
657
    mov   word [dly],ax
647
    mov   bx,[esi+12]
658
    mov   bx,[esi+12]
648
    add   ax,bx
659
    add   ax,bx
649
    mov   word [dlye],ax
660
    mov   word [dlye],ax
650
    mov   [esi+0],word 0
661
    mov   [esi+0],word 0
651
    mov   [esi+8],word 5
662
    mov   [esi+8],word 5
652
    mov   ax,[0xFE04]
663
    mov   ax,[0xFE04]
653
    mov   [esi+4],ax
664
    mov   [esi+4],ax
654
    mov   [esi+12],word 5
665
    mov   [esi+12],word 5
655
    xor   eax, eax
666
    xor   eax, eax
656
    mov   [esi+16],eax;dword 0
667
    mov   [esi+16],eax;dword 0
657
    mov   [esi+20],eax;dword 0
668
    mov   [esi+20],eax;dword 0
658
    mov   [esi+24],eax;dword 0
669
    mov   [esi+24],eax;dword 0
659
    mov   [esi+28],eax;dword 0
670
    mov   [esi+28],eax;dword 0
660
    popa
671
    popa
661
 
672
 
662
    pusha
673
    pusha
663
    mov   edi,esi
674
    mov   edi,esi
664
    shl   edi,5
675
    shl   edi,5
665
    add   edi,window_data
676
    add   edi,window_data
666
    mov   ecx,32/4
677
    mov   ecx,32/4
667
    xor   eax, eax
678
    xor   eax, eax
668
  ;  cld
679
  ;  cld
669
    rep   stosd
680
    rep   stosd
670
 
681
 
671
    mov   eax,[0xFE04]      ; set window to start from maxy+1
682
    mov   eax,[0xFE04]      ; set window to start from maxy+1
672
    add   eax,2
683
    add   eax,2
673
 
684
 
674
    mov   edi,esi
685
    mov   edi,esi
675
    shl   edi,5
686
    shl   edi,5
676
    add   edi,window_data
687
    add   edi,window_data
677
    mov   [edi+4],eax
688
    mov   [edi+4],eax
678
 
689
 
679
    popa
690
    popa
680
 
691
 
681
    pusha
692
    pusha
682
    mov   edi,esi
693
    mov   edi,esi
683
    shl   edi,5
694
    shl   edi,5
684
    add   edi,draw_data
695
    add   edi,draw_data
685
    mov   ecx,32/4
696
    mov   ecx,32/4
686
    xor   eax, eax
697
    xor   eax, eax
687
  ;  cld
698
  ;  cld
688
    rep   stosd
699
    rep   stosd
689
    popa
700
    popa
690
 
701
 
691
    pusha         ; at 0x80000+
702
    pusha         ; at 0x80000+
692
    mov   edi,esi
703
    mov   edi,esi
693
    shl   edi,8
704
    shl   edi,8
694
    add   edi,0x80000
705
    add   edi,0x80000
695
    mov   ecx,256/4
706
    mov   ecx,256/4
696
    xor   eax, eax
707
    xor   eax, eax
697
  ;  cld
708
  ;  cld
698
    rep   stosd
709
    rep   stosd
699
    popa
710
    popa
700
 
711
 
701
    pusha          ; name to spaces
712
    pusha          ; name to spaces
702
    mov   edi,esi
713
    mov   edi,esi
703
    shl   edi,8
714
    shl   edi,8
704
    add   edi,0x80000
715
    add   edi,0x80000
705
    mov   ecx,11
716
    mov   ecx,11
706
    mov   eax,' '
717
    mov   eax,' '
707
  ;  cld
718
  ;  cld
708
    rep   stosb
719
    rep   stosb
709
    popa
720
    popa
710
 
721
 
711
    pusha                ; C000 --> C400
722
    pusha                ; C000 --> C400
712
    mov   eax, 0xc000
723
    mov   eax, 0xc000
713
    mov   esi, 0
724
    mov   esi, 0
714
  nlc40:
725
  nlc40:
715
    add   eax, 2
726
    add   eax, 2
716
    inc   esi
727
    inc   esi
717
    cmp   esi, [0x3004]
728
    cmp   esi, [0x3004]
718
    jae   nlc41
729
    jae   nlc41
719
    movzx ecx, word [eax]
730
    movzx ecx, word [eax]
720
    mov   [0xC400 + ecx*2], si
731
    mov   [0xC400 + ecx*2], si
721
    jmp   nlc40
732
    jmp   nlc40
722
  nlc41:
733
  nlc41:
723
    popa
734
    popa
724
 
735
 
725
    pusha ; remove hd1 reservation
736
    pusha ; remove hd1 reservation
726
    mov   edx,esi
737
    mov   edx,esi
727
    shl   edx, 5 ;imul  edx,0x20
738
    shl   edx, 5 ;imul  edx,0x20
728
    add   edx,0x3000
739
    add   edx,0x3000
729
    mov   edx,[edx+4]
740
    mov   edx,[edx+4]
730
    cmp   [hd1_status],edx
741
    cmp   [hd1_status],edx
731
    jne   no_hd1_s_remove
742
    jne   no_hd1_s_remove
732
    mov   [hd1_status],0
743
    mov   [hd1_status],0
733
  no_hd1_s_remove:
744
  no_hd1_s_remove:
734
    popa
745
    popa
735
 
746
 
736
    pusha ; remove all irq reservations
747
    pusha ; remove all irq reservations
737
    mov   edx,esi
748
    mov   edx,esi
738
    shl   edx, 5 ;imul  edx,0x20
749
    shl   edx, 5 ;imul  edx,0x20
739
    add   edx,0x3000
750
    add   edx,0x3000
740
    mov   edx,[edx+4]
751
    mov   edx,[edx+4]
741
    mov   edi,irq_owner
752
    mov   edi,irq_owner
742
    mov   ecx,16
753
    mov   ecx,16
743
  newirqfree:
754
  newirqfree:
744
    cmp   [edi],edx
755
    cmp   [edi],edx
745
    jne   nofreeirq
756
    jne   nofreeirq
746
    mov   [edi],dword 0
757
    mov   [edi],dword 0
747
  nofreeirq:
758
  nofreeirq:
748
    add    edi,4
759
    add    edi,4
749
    loop   newirqfree
760
    loop   newirqfree
750
    popa
761
    popa
751
 
762
 
752
 
763
 
753
    pusha                     ; remove all port reservations
764
    pusha                     ; remove all port reservations
754
 
765
 
755
    mov   edx,esi
766
    mov   edx,esi
756
    shl   edx, 5 ;imul  edx,0x20
767
    shl   edx, 5 ;imul  edx,0x20
757
    add   edx,0x3000
768
    add   edx,0x3000
758
    mov   edx,[edx+4]
769
    mov   edx,[edx+4]
759
 
770
 
760
  rmpr0:
771
  rmpr0:
761
 
772
 
762
    mov   esi,[0x2d0000]
773
    mov   esi,[0x2d0000]
763
 
774
 
764
    cmp   esi,0
775
    cmp   esi,0
765
    je    rmpr9
776
    je    rmpr9
766
 
777
 
767
  rmpr3:
778
  rmpr3:
768
 
779
 
769
    mov   edi,esi
780
    mov   edi,esi
770
    shl   edi,4
781
    shl   edi,4
771
    add   edi,0x2d0000
782
    add   edi,0x2d0000
772
 
783
 
773
    cmp   edx,[edi]
784
    cmp   edx,[edi]
774
    je    rmpr4
785
    je    rmpr4
775
 
786
 
776
    dec   esi
787
    dec   esi
777
    jnz   rmpr3
788
    jnz   rmpr3
778
 
789
 
779
    jmp   rmpr9
790
    jmp   rmpr9
780
 
791
 
781
  rmpr4:
792
  rmpr4:
782
 
793
 
783
    mov   ecx,256
794
    mov   ecx,256
784
    sub   ecx,esi
795
    sub   ecx,esi
785
    shl   ecx,4
796
    shl   ecx,4
786
 
797
 
787
    mov   esi,edi
798
    mov   esi,edi
788
    add   esi,16
799
    add   esi,16
789
    cld
800
    cld
790
    rep   movsb
801
    rep   movsb
791
 
802
 
792
    dec   dword [0x2d0000]
803
    dec   dword [0x2d0000]
793
 
804
 
794
    jmp   rmpr0
805
    jmp   rmpr0
795
 
806
 
796
  rmpr9:
807
  rmpr9:
797
 
808
 
798
    popa
809
    popa
799
    mov  edi,esi         ; do not run this process slot
810
    mov  edi,esi         ; do not run this process slot
800
    shl  edi, 5
811
    shl  edi, 5
801
    mov  [edi+0x300A],byte 9
812
    mov  [edi+0x300A],byte 9
802
;    call  systest
813
;    call  systest
803
    sti  ; .. and life goes on
814
    sti  ; .. and life goes on
804
 
815
 
805
;    movzx eax,word [dlx]
816
;    movzx eax,word [dlx]
806
;    movzx ebx,word [dly]
817
;    movzx ebx,word [dly]
807
;    movzx ecx,word [dlxe]
818
;    movzx ecx,word [dlxe]
808
;    movzx edx,word [dlye]
819
;    movzx edx,word [dlye]
809
    call  calculatescreen
820
    call  calculatescreen
810
 
821
 
811
    xor   eax, eax
822
    xor   eax, eax
812
    xor   esi, esi
823
    xor   esi, esi
813
    call  redrawscreen
824
    call  redrawscreen
814
 
825
 
815
    mov   [0xfff4],byte 0  ; no mouse background
826
    mov   [0xfff4],byte 0  ; no mouse background
816
    mov   [0xfff5],byte 0  ; draw mouse
827
    mov   [0xfff5],byte 0  ; draw mouse
817
 
828
 
818
    mov   [application_table_status],0
829
    mov   [application_table_status],0
819
 
830
 
820
    mov   esi,process_terminated
831
    mov   esi,process_terminated
821
    call  sys_msg_board_str
832
    call  sys_msg_board_str
822
 
833
 
823
;* start code - fix error redraw for terminate (2) - Mario79
834
;* start code - fix error redraw for terminate (2) - Mario79
824
;     cmp  [draw_present],1
835
;     cmp  [draw_present],1
825
;     je  no_draw_background_temp
836
;     je  no_draw_background_temp
826
;     mov   [0xfff0],byte 1
837
;     mov   [0xfff0],byte 1
827
;no_draw_background_temp:
838
;no_draw_background_temp:
828
;    mov   [draw_present],0
839
;    mov   [draw_present],0
829
    ret
840
    ret
830
;draw_present db 0
841
;draw_present db 0
831
;* end code - fix error redraw for terminate (2) - Mario79
842
;* end code - fix error redraw for terminate (2) - Mario79
832
 
843
 
833
iglobal
844
iglobal
834
  boot_sched_1    db   'Building gdt tss pointer',0
845
  boot_sched_1    db   'Building gdt tss pointer',0
835
  boot_sched_2    db   'Building IDT table',0
846
  boot_sched_2    db   'Building IDT table',0
836
endg
847
endg
837
 
848
 
838
 
849
 
839
build_scheduler:
850
build_scheduler:
840
 
851
 
841
        mov    esi,boot_sched_1
852
        mov    esi,boot_sched_1
842
        call   boot_log
853
        call   boot_log
843
        call   build_process_gdt_tss_pointer
854
        call   build_process_gdt_tss_pointer
844
 
855
 
845
        mov    esi,boot_sched_2
856
        mov    esi,boot_sched_2
846
        call   boot_log
857
        call   boot_log
847
        call   build_interrupt_table
858
        call   build_interrupt_table
848
 
859
 
849
        ret
860
        ret