Subversion Repositories Kolibri OS

Rev

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

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