Subversion Repositories Kolibri OS

Rev

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

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