Subversion Repositories Kolibri OS

Rev

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

Rev 5 Rev 6
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
graph_data_l:
38
graph_data_l:
39
 
39
 
40
        dw     0x3ff
40
        dw     0x3ff
41
        dw     0x0000
41
        dw     0x0000
42
        db     0x00
42
        db     0x00
43
        dw     11010000b *256 +11110010b
43
        dw     11010000b *256 +11110010b
44
        db     0x00
44
        db     0x00
45
 
45
 
46
tss0_l:
46
tss0_l:
47
      times (max_processes+10) dd 0,0
47
      times (max_processes+10) dd 0,0
48
 
48
 
49
tss0i_l:
49
tss0i_l:
50
      times 0x41 dq 0 ;(256+10) dd 0,0
50
      times 0x41 dq 0 ;(256+10) dd 0,0
51
 
51
 
52
app_code_l:
52
app_code_l:
53
      dw ((0x80000000-std_application_base_address) shr 12) and 0xffff
53
      dw ((0x80000000-std_application_base_address) shr 12) and 0xffff
54
      dw 0
54
      dw 0
55
      db 0
55
      db 0
56
      dw 11010000b*256+11111010b+256*((0x80000000-std_application_base_address) shr 28)
56
      dw 11010000b*256+11111010b+256*((0x80000000-std_application_base_address) shr 28)
57
      db std_application_base_address shr 24
57
      db std_application_base_address shr 24
58
 
58
 
59
app_data_l:
59
app_data_l:
60
      dw (0x80000000-std_application_base_address) shr 12 and 0xffff
60
      dw (0x80000000-std_application_base_address) shr 12 and 0xffff
61
      dw 0
61
      dw 0
62
      db 0
62
      db 0
63
      dw 11010000b*256+11110010b+256*((0x80000000-std_application_base_address) shr 28)
63
      dw 11010000b*256+11110010b+256*((0x80000000-std_application_base_address) shr 28)
64
      db std_application_base_address shr 24
64
      db std_application_base_address shr 24
65
 
65
 
66
 
66
 
67
gdte:
67
gdte:
68
 
68
 
69
 
69
 
70
 
-
 
71
; 
70
 
72
idtreg:
71
idtreg:
73
     dw   8*0x41-1
72
     dw   8*0x41-1
74
     dd   idts+8
73
     dd   idts+8
75
 
74
 
76
label idts at 0xB100-8
75
label idts at 0xB100-8
77
;idte = idts + 8 + 0x60
76
;idte = idts + 8 + 0x60
78
 
-
 
79
;  ; old code below:
-
 
80
 
-
 
81
 
-
 
82
;align 32
-
 
83
 
-
 
84
;idts:
-
 
85
;      dw  idte-$-1
-
 
86
;      dd  idts+8
-
 
87
;      dw  0
-
 
88
 
-
 
89
;      times 0x62 dd 0,0
-
 
90
 
77
 
91
;idte:
78
 
92
 
79
 
93
build_process_gdt_tss_pointer:
80
build_process_gdt_tss_pointer:
94
 
81
 
95
        mov    ecx,tss_data
82
        mov    ecx,tss_data
96
        mov    edi,0
83
        mov    edi,0
97
      setgdtl2:
84
      setgdtl2:
98
        mov    [edi+gdts+ tss0 +0], word tss_step
85
        mov    [edi+gdts+ tss0 +0], word tss_step
99
        mov    [edi+gdts+ tss0 +2], cx
86
        mov    [edi+gdts+ tss0 +2], cx
100
        mov    eax,ecx
87
        mov    eax,ecx
101
        shr    eax,16
88
        shr    eax,16
102
        mov    [edi+gdts+ tss0 +4], al
89
        mov    [edi+gdts+ tss0 +4], al
103
        mov    [edi+gdts+ tss0 +7], ah
90
        mov    [edi+gdts+ tss0 +7], ah
104
        mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
91
        mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
105
        add    ecx,tss_step
92
        add    ecx,tss_step
106
        add    edi,8
93
        add    edi,8
107
        cmp    edi,8*(max_processes+5)
94
        cmp    edi,8*(max_processes+5)
108
        jbe    setgdtl2
95
        jbe    setgdtl2
109
 
96
 
110
        ret
97
        ret
111
 
98
 
112
 
99
 
113
build_interrupt_table:
100
build_interrupt_table:
114
 
101
 
115
        mov  [l.eflags],dword 0x11002
102
        mov  [l.eflags],dword 0x11002
116
        mov  [l.ss0], int_data
103
        mov  [l.ss0], int_data
117
        ;mov  [l.ss1], ring1_data
104
        ;mov  [l.ss1], ring1_data
118
        ;mov  [l.ss2], ring2_data
105
        ;mov  [l.ss2], ring2_data
119
        mov  [l.esp0], 0x52000
106
        mov  [l.esp0], 0x52000
120
        mov  [l.esp1], 0x53000
107
        mov  [l.esp1], 0x53000
121
        mov  [l.esp2], 0x54000
108
        mov  [l.esp2], 0x54000
122
 
109
 
123
        mov  eax,cr3
110
        mov  eax,cr3
124
        mov  [l.cr3],eax
111
        mov  [l.cr3],eax
125
        mov  [l.cs],int_code
112
        mov  [l.cs],int_code
126
        mov  [l.ss],int_data
113
        mov  [l.ss],int_data
127
        mov  [l.ds],int_data
114
        mov  [l.ds],int_data
128
        mov  [l.es],int_data
115
        mov  [l.es],int_data
129
        mov  [l.fs],int_data
116
        mov  [l.fs],int_data
130
        mov  [l.gs],int_data
117
        mov  [l.gs],int_data
131
 
118
 
132
        mov  eax,sys_int
119
        mov  eax,sys_int
133
        mov  [l.esp],0x720000
120
        mov  [l.esp],0x720000
134
        mov  edi,0x290000
121
        mov  edi,0x290000
135
 
122
 
136
     newint:
123
     newint:
137
        push edi
124
        push edi
138
        mov  ebx,[eax]
125
        mov  ebx,[eax]
139
        mov  [l.eip],ebx
126
        mov  [l.eip],ebx
140
        mov  esi,tss_sceleton
127
        mov  esi,tss_sceleton
141
        mov  ecx,120/4
128
        mov  ecx,120/4
142
        cld
129
        cld
143
        rep  movsd
130
        rep  movsd
144
        pop  edi
131
        pop  edi
145
 
132
 
146
        add  edi,128
133
        add  edi,128
147
        add  [l.esp],1024
134
        add  [l.esp],1024
148
        add  eax,4
135
        add  eax,4
149
 
136
 
150
        cmp  eax,sys_int+4*0x40 ;0x60
137
        cmp  eax,sys_int+4*0x40 ;0x60
151
        jbe  newint  ;jb
138
        jbe  newint  ;jb
152
 
139
 
153
;;
140
;;
154
 
141
 
155
        mov    esi,boot_sched_3_2
142
        mov    esi,boot_sched_3_2
156
        call   boot_log
143
        call   boot_log
157
 
144
 
158
        mov    ecx,0x290000
145
        mov    ecx,0x290000
159
        mov    edi,0
146
        mov    edi,0
160
      setgdtl2i:
147
      setgdtl2i:
161
        mov    [edi+gdts+ tss0i +0], word 128
148
        mov    [edi+gdts+ tss0i +0], word 128
162
        mov    [edi+gdts+ tss0i +2], cx
149
        mov    [edi+gdts+ tss0i +2], cx
163
        mov    eax,ecx
150
        mov    eax,ecx
164
        shr    eax,16
151
        shr    eax,16
165
        mov    [edi+gdts+ tss0i +4], al
152
        mov    [edi+gdts+ tss0i +4], al
166
        mov    [edi+gdts+ tss0i +7], ah
153
        mov    [edi+gdts+ tss0i +7], ah
167
        mov    [edi+gdts+ tss0i +5], word 01010000b *256 +11101001b
154
        mov    [edi+gdts+ tss0i +5], word 01010000b *256 +11101001b
168
        add    ecx,128
155
        add    ecx,128
169
        add    edi,8
156
        add    edi,8
170
        cmp    edi,8*0x40 ;0x60
157
        cmp    edi,8*0x40 ;0x60
171
        jbe    setgdtl2i
158
        jbe    setgdtl2i
172
 
159
 
173
;;
160
;;
174
 
161
 
175
        mov    esi,boot_sched_3_3
162
        mov    esi,boot_sched_3_3
176
        call   boot_log
163
        call   boot_log
177
 
164
 
178
        mov    edi,0
165
        mov    edi,0
179
        mov    edx,tss0i
166
        mov    edx,tss0i
180
      setidtl2:
167
     @@:
181
        mov    [edi+idts+ 8 +0], word 0
168
        mov    [edi+idts+ 8 +0], word 0
182
        mov    [edi+idts+ 8 +2], dx
169
        mov    [edi+idts+ 8 +2], dx
183
        mov    [edi+idts+ 8 +4], word 10000101b*256 ; task gate DPL=0
170
        mov    [edi+idts+ 8 +4], word 10000101b*256 ; task gate DPL=0
184
;        cmp    edi,0x40*8
-
 
185
;        jne    no_sw_int
-
 
186
;        mov    [edi+idts+ 8 +4], word 11100101b*256 ; task gate DPL=3
-
 
187
;      no_sw_int:
-
 
188
        mov    [edi+idts+ 8 +6], word 0
171
        mov    [edi+idts+ 8 +6], word 0
189
        add    edx,8
172
        add    edx,8
190
        add    edi,8
173
        add    edi,8
191
 
174
 
192
        cmp    edi,8*0x40 ;0x60
175
        cmp    edi,8*0x40
193
        jbe    setidtl2 ;jb
-
 
194
 
-
 
195
; 
-
 
196
; THIS CODE WON'T WORK ;-(
-
 
197
; because each process's 0-level stack points to the same area
176
        jb     @b
198
; and if task switch occurs and another process is being interrupted
-
 
199
; a stack overflow happens
-
 
200
; The only way to solve that problem is to disable interrupts
-
 
201
; while 0x40-handler is working
177
        
202
; Then we have to make all entries in the IDT INTERRUPT gates, not TASK
178
    ; Exceptions
203
;        mov    edi, idts+8
179
        mov    edi, idts+8
204
;        mov    esi, sys_int
180
        mov    esi, sys_int
205
;        mov    ecx, 32
181
        mov    ecx, 32
206
;     @@:
182
     @@:
207
;        mov    eax, [esi]
183
        mov    eax, [esi]
208
;        mov    [edi],   ax           ; lower part of offset
184
        mov    [edi],   ax           ; lower part of offset
209
;        mov    [edi+2], word os_code ; segment selector
185
        mov    [edi+2], word os_code ; segment selector
210
;        shr    eax, 16
186
        shr    eax, 16
211
;        mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
187
        mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
212
;        mov    [edi+6], ax
188
        mov    [edi+6], ax
213
;        add    esi, 4
189
        add    esi, 4
214
;        add    edi, 8
190
        add    edi, 8
215
;        dec    ecx
-
 
216
;        jnz    @b
191
        dec    ecx
217
; 
192
        jnz    @b
218
 
193
 
219
        ret
194
        ret
220
 
195
 
221
build_syscall_interrupt_table:
196
build_syscall_interrupt_table:
222
 
197
 
223
        ;mov    dx,tss0sys
198
        ;mov    dx,tss0sys
224
        mov    edi,8*0x40+idts+8
199
        mov    edi,8*0x40+idts+8
225
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
200
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
226
        mov    [edi + 2], word os_code
201
        mov    [edi + 2], word os_code
227
        mov    [edi + 4], word 11101110b*256
202
        mov    [edi + 4], word 11101110b*256
228
        mov    [edi + 6], word (i40 shr 16)
203
        mov    [edi + 6], word (i40 shr 16)
229
 
204
 
230
        ret
205
        ret
231
 
206
 
232
 
-
 
233
align 4
-
 
234
i38:
-
 
235
        ; load data selectors
-
 
236
        pushfd
-
 
237
        push    ds es
-
 
238
        push    eax
-
 
239
        mov     ax, os_data
-
 
240
        mov     ds, ax
-
 
241
        mov     es, ax
-
 
242
        pop     eax
-
 
243
 
-
 
244
        pushad
-
 
245
        push    edi
-
 
246
        mov     edi, eax
-
 
247
        mov     eax, ebx
-
 
248
        mov     ebx, ecx
-
 
249
        mov     ecx, edx
-
 
250
        mov     esi, [esp]
-
 
251
        and     edi, 0xFF
-
 
252
        call    dword [servetable+edi*4]
-
 
253
        add     esp, 4
-
 
254
        popad
-
 
255
        pop     es ds
-
 
256
        popfd
-
 
257
iret
-
 
258
 
207
 
259
 
208
 
260
iglobal
209
iglobal
261
  sys_int:
210
  sys_int:
262
    dd   s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sa,sb,sc,sd,se,sf
211
    dd   s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sa,sb,sc,sd,se,sf
263
 
212
 
264
    dd   s10        ,s11      ;  ,i_unknown12,i_unknown13
213
    dd   s10        ,s11      ;  ,i_unknown12,i_unknown13
265
;    dd   i_unknown14,i_unknown15,i_unknown16,i_unknown17
214
;    dd   i_unknown14,i_unknown15,i_unknown16,i_unknown17
266
;    dd   i_unknown18,i_unknown19,i_unknown1a,i_unknown1b
215
;    dd   i_unknown18,i_unknown19,i_unknown1a,i_unknown1b
267
;    dd   i_unknown1c,i_unknown1d,i_unknown1e,i_unknown1f
216
;    dd   i_unknown1c,i_unknown1d,i_unknown1e,i_unknown1f
268
    times 14 dd unknown_interrupt
217
    times 14 dd unknown_interrupt
269
 
218
 
270
    dd   irq0  ,irq1  ,p_irq2 ,p_irq3 ,p_irq4 ,p_irq5,p_irq6 ,p_irq7
219
    dd   irq0  ,irq1  ,p_irq2 ,p_irq3 ,p_irq4 ,p_irq5,p_irq6 ,p_irq7
271
    dd   p_irq8,p_irq9,p_irq10,p_irq11,p_irq12,irqD  ,p_irq14,p_irq15
220
    dd   p_irq8,p_irq9,p_irq10,p_irq11,p_irq12,irqD  ,p_irq14,p_irq15
272
 
221
 
273
    ;dd   i_unknown30,i_unknown31,i_unknown32,i_unknown33
222
    ;dd   i_unknown30,i_unknown31,i_unknown32,i_unknown33
274
    ;dd   i_unknown34,i_unknown35,i_unknown36,i_unknown37
223
    ;dd   i_unknown34,i_unknown35,i_unknown36,i_unknown37
275
    ;dd   i_unknown38,i_unknown39,i_unknown3a,i_unknown3b
224
    ;dd   i_unknown38,i_unknown39,i_unknown3a,i_unknown3b
276
    ;dd   i_unknown3c,i_unknown3d,i_unknown3e,i_unknown3f
225
    ;dd   i_unknown3c,i_unknown3d,i_unknown3e,i_unknown3f
277
    times 16 dd unknown_interrupt
226
    times 16 dd unknown_interrupt
278
 
227
 
279
    dd   i40
228
    dd   i40
280
endg
229
endg
281
 
230
 
282
uglobal
231
uglobal
283
 tss_sceleton:
232
 tss_sceleton:
284
  l.back   dw 0,0
233
  l.back   dw 0,0
285
  l.esp0   dd 0
234
  l.esp0   dd 0
286
  l.ss0    dw 0,0
235
  l.ss0    dw 0,0
287
  l.esp1   dd 0
236
  l.esp1   dd 0
288
  l.ss1    dw 0,0
237
  l.ss1    dw 0,0
289
  l.esp2   dd 0
238
  l.esp2   dd 0
290
  l.ss2    dw 0,0
239
  l.ss2    dw 0,0
291
  l.cr3    dd 0
240
  l.cr3    dd 0
292
  l.eip    dd 0
241
  l.eip    dd 0
293
  l.eflags dd 0
242
  l.eflags dd 0
294
  l.eax    dd 0
243
  l.eax    dd 0
295
  l.ecx    dd 0
244
  l.ecx    dd 0
296
  l.edx    dd 0
245
  l.edx    dd 0
297
  l.ebx    dd 0
246
  l.ebx    dd 0
298
  l.esp    dd 0
247
  l.esp    dd 0
299
  l.ebp    dd 0
248
  l.ebp    dd 0
300
  l.esi    dd 0
249
  l.esi    dd 0
301
  l.edi    dd 0
250
  l.edi    dd 0
302
  l.es     dw 0,0
251
  l.es     dw 0,0
303
  l.cs     dw 0,0
252
  l.cs     dw 0,0
304
  l.ss     dw 0,0
253
  l.ss     dw 0,0
305
  l.ds     dw 0,0
254
  l.ds     dw 0,0
306
  l.fs     dw 0,0
255
  l.fs     dw 0,0
307
  l.gs     dw 0,0
256
  l.gs     dw 0,0
308
  l.ldt    dw 0,0
257
  l.ldt    dw 0,0
309
  l.trap   dw 0
258
  l.trap   dw 0
310
  l.io     dw 0
259
  l.io     dw 0
311
endg
260
endg
312
 
261
 
313
s0:
262
s0:
-
 
263
        mov   ax, os_data
-
 
264
        mov   ds, ax
314
        cli
265
        mov   es, ax
315
 
266
 
316
        mov   [error_interrupt],0x0
267
        mov   [error_interrupt],0x0
317
        mov   [error_interrupt_entry],dword s0
268
        mov   [error_interrupt_entry],dword s0
318
 
269
 
319
        call  show_error_parameters
270
        call  show_error_parameters
320
 
271
 
321
        mov   edx,[0x3010]
272
        mov   edx,[0x3010]
322
        mov   [edx+0xa],byte 4
273
        mov   [edx+0xa],byte 4
323
 
274
 
324
        jmp   change_task
275
        jmp   change_task
325
 
276
 
326
 
277
 
327
s1:
278
s1:
-
 
279
        mov   ax, os_data
-
 
280
        mov   ds, ax
328
        cli
281
        mov   es, ax
329
 
282
 
330
        mov   [error_interrupt],0x1
283
        mov   [error_interrupt],0x1
331
        mov   [error_interrupt_entry],dword s1
284
        mov   [error_interrupt_entry],dword s1
332
 
285
 
333
        call  show_error_parameters
286
        call  show_error_parameters
334
 
287
 
335
        mov   edx,[0x3010]
288
        mov   edx,[0x3010]
336
        mov   [edx+0xa],byte 4
289
        mov   [edx+0xa],byte 4
337
 
290
 
338
        jmp   change_task
291
        jmp   change_task
339
 
292
 
340
s2:
293
s2:
-
 
294
        mov   ax, os_data
-
 
295
        mov   ds, ax
341
        cli
296
        mov   es, ax
342
 
297
 
343
        mov   [error_interrupt],0x2
298
        mov   [error_interrupt],0x2
344
        mov   [error_interrupt_entry],dword s2
299
        mov   [error_interrupt_entry],dword s2
345
 
300
 
346
        call  show_error_parameters
301
        call  show_error_parameters
347
 
302
 
348
        mov   edx,[0x3010]
303
        mov   edx,[0x3010]
349
        mov   [edx+0xa],byte 4
304
        mov   [edx+0xa],byte 4
350
 
305
 
351
        jmp   change_task
306
        jmp   change_task
352
 
307
 
353
s3:
308
s3:
-
 
309
        mov   ax, os_data
-
 
310
        mov   ds, ax
354
        cli
311
        mov   es, ax
355
 
312
 
356
        mov   [error_interrupt],0x3
313
        mov   [error_interrupt],0x3
357
        mov   [error_interrupt_entry],dword s3
314
        mov   [error_interrupt_entry],dword s3
358
 
315
 
359
        call  show_error_parameters
316
        call  show_error_parameters
360
 
317
 
361
        mov   edx,[0x3010]
318
        mov   edx,[0x3010]
362
        mov   [edx+0xa],byte 4
319
        mov   [edx+0xa],byte 4
363
 
320
 
364
        jmp   change_task
321
        jmp   change_task
365
 
322
 
366
s4:
323
s4:
-
 
324
        mov   ax, os_data
-
 
325
        mov   ds, ax
367
        cli
326
        mov   es, ax
368
 
327
 
369
        mov   [error_interrupt],0x4
328
        mov   [error_interrupt],0x4
370
        mov   [error_interrupt_entry],dword s4
329
        mov   [error_interrupt_entry],dword s4
371
 
330
 
372
        call  show_error_parameters
331
        call  show_error_parameters
373
 
332
 
374
        mov   edx,[0x3010]
333
        mov   edx,[0x3010]
375
        mov   [edx+0xa],byte 4
334
        mov   [edx+0xa],byte 4
376
 
335
 
377
        jmp   change_task
336
        jmp   change_task
378
 
337
 
379
s5:
338
s5:
-
 
339
        mov   ax, os_data
-
 
340
        mov   ds, ax
380
        cli
341
        mov   es, ax
381
 
342
 
382
        mov   [error_interrupt],0x5
343
        mov   [error_interrupt],0x5
383
        mov   [error_interrupt_entry],dword s5
344
        mov   [error_interrupt_entry],dword s5
384
 
345
 
385
        call  show_error_parameters
346
        call  show_error_parameters
386
 
347
 
387
        mov   edx,[0x3010]
348
        mov   edx,[0x3010]
388
        mov   [edx+0xa],byte 4
349
        mov   [edx+0xa],byte 4
389
 
350
 
390
        jmp   change_task
351
        jmp   change_task
391
 
352
 
392
s6:
353
s6:
-
 
354
        mov   ax, os_data
-
 
355
        mov   ds, ax
393
        cli
356
        mov   es, ax
394
 
357
 
395
        mov   [error_interrupt],0x6
358
        mov   [error_interrupt],0x6
396
        mov   [error_interrupt_entry],dword s6
359
        mov   [error_interrupt_entry],dword s6
397
 
360
 
398
        call  show_error_parameters
361
        call  show_error_parameters
399
 
362
 
400
        mov   edx,[0x3010]
363
        mov   edx,[0x3010]
401
        mov   [edx+0xa],byte 4
364
        mov   [edx+0xa],byte 4
402
 
365
 
403
        jmp   change_task
366
        jmp   change_task
404
 
367
 
405
 
368
 
406
;;;;;;;;;;;;;;;;;;;;;;;
369
;;;;;;;;;;;;;;;;;;;;;;;
407
;; FPU ERROR HANDLER ;;
370
;; FPU ERROR HANDLER ;;
408
;;;;;;;;;;;;;;;;;;;;;;;
371
;;;;;;;;;;;;;;;;;;;;;;;
409
 
372
 
410
align 4
373
align 4
411
s7:
374
s7:
412
        ; 
-
 
413
        cli
375
        clts
414
        ; 
-
 
415
        mov    edi, 7*8
-
 
416
        mov    [edi+gdts+ tss0i +5], word 01010000b *256 +11101001b
-
 
417
 
376
          
418
        mov    edi,[0x3000]
377
        push  eax
419
        shl    edi, 3
-
 
-
 
378
        push  ds es
-
 
379
        
-
 
380
        mov   ax, os_data
420
        mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
-
 
421
 
381
        mov   ds, ax
422
 
382
        mov   es, ax
423
        ; save a copy of current task's TSS to fpu_tss
383
        
424
        mov    esi,[0x3000]
-
 
425
        imul   esi,tss_step
-
 
426
        add    esi,tss_data
-
 
427
        mov    edi,fpu_tss
384
        mov   eax, [prev_user_of_fpu]
428
        mov    ecx,120/4
-
 
429
        cld
385
        shl   eax, 8
430
        rep    movsd
386
        add   eax, 0x80000 + 0x10
431
 
387
        fsave [eax]
432
        ; get base address of our TSS and...
-
 
433
        mov    esi,[0x3000]
388
        
434
        imul   esi,tss_step
-
 
435
        add    esi,tss_data
389
        mov   eax, [0x3000]
436
 
390
        mov   [prev_user_of_fpu], eax
437
        ; ...init segments, stack, eip, flags
391
        shl   eax, 8
438
        mov    word [esi+l.cs-tss_sceleton],int_code
392
        add   eax, 0x80000
439
        mov    word [esi+l.ss-tss_sceleton],int_data
393
        cmp   [eax + 0x7f], byte 0
440
        mov    word [esi+l.ds-tss_sceleton],int_data
-
 
441
        mov    word [esi+l.es-tss_sceleton],int_data
-
 
442
        mov    word [esi+l.fs-tss_sceleton],int_data
-
 
443
        mov    word [esi+l.gs-tss_sceleton],int_data
-
 
444
        mov    dword [esi+l.esp-tss_sceleton],fpu_stack+4*8
394
        je    @f
445
        mov    dword [esi+l.eip-tss_sceleton],fpu_handler
395
        frstor [eax+0x10]
446
        mov    dword [esi+l.eflags-tss_sceleton],0x11002
-
 
447
 
-
 
448
        ; then execute this task
396
     @@:
-
 
397
        mov   [eax + 0x7f], byte 1
-
 
398
        
-
 
399
        pop   es ds
-
 
400
        pop   eax
449
        mov    ebx, [0x3000]
-
 
450
        shl    ebx,3
401
        
-
 
402
        iret
-
 
403
        
-
 
404
iglobal
451
        add    ebx, tss0 ;t
405
  prev_user_of_fpu dd 1
452
        mov    [0xB004], bx
406
endg
453
 
407
 
454
        jmp    pword [0xB000]
408
 
455
 
409
s8:
456
        jmp    s7
410
        add   esp, 4 ; zero on the stack!
457
 
411
        mov   ax, os_data
458
s8:
412
        mov   ds, ax
459
        cli
413
        mov   es, ax
460
 
414
 
461
        mov   [error_interrupt],0x8
415
        mov   [error_interrupt],0x8
462
        mov   [error_interrupt_entry],dword s8
416
        mov   [error_interrupt_entry],dword s8
463
 
417
 
464
        call  show_error_parameters
418
        call  show_error_parameters
465
 
419
 
466
        mov   edx,[0x3010]
420
        mov   edx,[0x3010]
467
        mov   [edx+0xa],byte 4
421
        mov   [edx+0xa],byte 4
468
 
422
 
469
        jmp   change_task
423
        jmp   change_task
470
 
424
 
471
s9:
425
s9:
-
 
426
        mov   ax, os_data
-
 
427
        mov   ds, ax
472
        cli
428
        mov   es, ax
473
 
429
 
474
        mov   [error_interrupt],0x9
430
        mov   [error_interrupt],0x9
475
        mov   [error_interrupt_entry],dword s9
431
        mov   [error_interrupt_entry],dword s9
476
 
432
 
477
        call  show_error_parameters
433
        call  show_error_parameters
478
 
434
 
479
        mov   edx,[0x3010]
435
        mov   edx,[0x3010]
480
        mov   [edx+0xa],byte 4
436
        mov   [edx+0xa],byte 4
481
 
437
 
482
        jmp   change_task
438
        jmp   change_task
-
 
439
 
483
 
440
; Invalid TSS
-
 
441
sa:
-
 
442
        add   esp, 4 ; error code
-
 
443
        mov   ax, os_data
484
sa:
444
        mov   ds, ax
485
        cli
445
        mov   es, ax
486
 
446
 
487
        mov   [error_interrupt],0xa
447
        mov   [error_interrupt],0xa
488
        mov   [error_interrupt_entry],dword sa
448
        mov   [error_interrupt_entry],dword sa
489
 
449
 
490
        call  show_error_parameters
450
        call  show_error_parameters
491
 
451
 
492
        mov   edx,[0x3010]
452
        mov   edx,[0x3010]
493
        mov   [edx+0xa],byte 4
453
        mov   [edx+0xa],byte 4
494
 
454
 
495
        jmp   change_task
455
        jmp   change_task
-
 
456
 
496
 
457
; Segment not present
-
 
458
sb:
-
 
459
	add   esp, 4
-
 
460
        mov   ax, os_data
497
sb:
461
        mov   ds, ax
498
        cli
462
        mov   es, ax
499
 
463
 
500
        mov   [error_interrupt],0xb
464
        mov   [error_interrupt],0xb
501
        mov   [error_interrupt_entry],dword sb
465
        mov   [error_interrupt_entry],dword sb
502
 
466
 
503
        call  show_error_parameters
467
        call  show_error_parameters
504
 
468
 
505
        mov   edx,[0x3010]
469
        mov   edx,[0x3010]
506
        mov   [edx+0xa],byte 4
470
        mov   [edx+0xa],byte 4
507
 
471
 
508
        jmp   change_task
472
        jmp   change_task
-
 
473
 
509
 
474
; Stack fault exception
-
 
475
sc:
-
 
476
	add   esp, 4
-
 
477
        mov   ax, os_data
510
sc:
478
        mov   ds, ax
511
        cli
479
        mov   es, ax
512
 
480
 
513
        mov   [error_interrupt],0xc
481
        mov   [error_interrupt],0xc
514
        mov   [error_interrupt_entry],dword sc
482
        mov   [error_interrupt_entry],dword sc
515
 
483
 
516
        call  show_error_parameters
484
        call  show_error_parameters
517
 
485
 
518
        mov   edx,[0x3010]
486
        mov   edx,[0x3010]
519
        mov   [edx+0xa],byte 4
487
        mov   [edx+0xa],byte 4
520
 
488
 
521
        jmp   change_task
489
        jmp   change_task
-
 
490
 
522
 
491
; General Protection Fault
-
 
492
sd:
-
 
493
	add   esp, 4
-
 
494
        mov   ax, os_data
523
sd:
495
        mov   ds, ax
524
        cli
496
        mov   es, ax
525
 
497
 
526
        mov   [error_interrupt],0xd
498
        mov   [error_interrupt],0xd
527
        mov   [error_interrupt_entry],dword sd
499
        mov   [error_interrupt_entry],dword sd
528
 
500
 
529
        call  show_error_parameters
501
        call  show_error_parameters
530
 
502
 
531
        mov   edx,[0x3010]
503
        mov   edx,[0x3010]
532
        mov   [edx+0xa],byte 4
504
        mov   [edx+0xa],byte 4
533
 
505
 
534
        jmp   change_task
506
        jmp   change_task
-
 
507
 
535
 
508
; Page-Fault Exception
-
 
509
se:
-
 
510
	add   esp, 4
-
 
511
        mov   ax, os_data
536
se:
512
        mov   ds, ax
537
        cli
513
        mov   es, ax
538
 
514
 
539
        mov   [error_interrupt],0xe
515
        mov   [error_interrupt],0xe
540
        mov   [error_interrupt_entry],dword se
516
        mov   [error_interrupt_entry],dword se
541
 
517
 
542
        call  show_error_parameters
518
        call  show_error_parameters
543
 
519
 
544
        mov   edx,[0x3010]
520
        mov   edx,[0x3010]
545
        mov   [edx+0xa],byte 4
521
        mov   [edx+0xa],byte 4
546
 
522
 
547
        jmp   change_task
523
        jmp   change_task
-
 
524
 
548
 
525
; ??
-
 
526
sf:
-
 
527
        mov   ax, os_data
549
sf:
528
        mov   ds, ax
550
        cli
529
        mov   es, ax
551
 
530
 
552
        mov   [error_interrupt],0xf
531
        mov   [error_interrupt],0xf
553
        mov   [error_interrupt_entry],dword sf
532
        mov   [error_interrupt_entry],dword sf
554
 
533
 
555
        call  show_error_parameters
534
        call  show_error_parameters
556
 
535
 
557
        mov   edx,[0x3010]
536
        mov   edx,[0x3010]
558
        mov   [edx+0xa],byte 4
537
        mov   [edx+0xa],byte 4
559
 
538
 
560
        jmp   change_task
539
        jmp   change_task
-
 
540
 
561
 
541
; x87 FPU Floating-Point Error
-
 
542
s10:
-
 
543
        mov   ax, os_data
562
s10:
544
        mov   ds, ax
563
        cli
545
        mov   es, ax
564
 
546
 
565
        mov   [error_interrupt],0x10
547
        mov   [error_interrupt],0x10
566
        mov   [error_interrupt_entry],dword s10
548
        mov   [error_interrupt_entry],dword s10
567
 
549
 
568
        call  show_error_parameters
550
        call  show_error_parameters
569
 
551
 
570
        mov   edx,[0x3010]
552
        mov   edx,[0x3010]
571
        mov   [edx+0xa],byte 4
553
        mov   [edx+0xa],byte 4
572
 
554
 
573
        jmp   change_task
555
        jmp   change_task
-
 
556
 
574
 
557
; Alignment Check Exception
-
 
558
s11:
-
 
559
	add   esp, 4
-
 
560
        mov   ax, os_data
575
s11:
561
        mov   ds, ax
576
        cli
562
        mov   es, ax
577
 
563
 
578
        mov   [error_interrupt],0x11
564
        mov   [error_interrupt],0x11
579
        mov   [error_interrupt_entry],dword s11
565
        mov   [error_interrupt_entry],dword s11
580
 
566
 
581
        call  show_error_parameters
567
        call  show_error_parameters
582
 
568
 
583
        mov   edx,[0x3010]
569
        mov   edx,[0x3010]
584
        mov   [edx+0xa],byte 4
570
        mov   [edx+0xa],byte 4
585
 
571
 
586
        jmp   change_task
572
        jmp   change_task
-
 
573
 
-
 
574
 
-
 
575
 
587
 
576
 
588
writehex:
577
writehex:
589
 
578
 
590
      pusha
579
      pusha
591
 
580
 
592
      mov  ecx,eax
581
      mov  ecx,eax
593
      mov  ax,word [printerrorat]
582
      mov  ax,word [printerrorat]
594
      shl  eax,16
583
      shl  eax,16
595
      mov  ax,[esp+32+4]
584
      mov  ax,[esp+32+4]
596
      sub  ax,60
585
      sub  ax,60
597
      mov  edx,1
586
      mov  edx,1
598
      mov  esi,8
587
      mov  esi,8
599
      mov  ebx,0xffffff
588
      mov  ebx,0xffffff
600
    whl1:
589
    whl1:
601
      push ecx
590
      push ecx
602
      and  ecx,0xf
591
      and  ecx,0xf
603
      add  ecx,hexletters
592
      add  ecx,hexletters
604
      mov  edi,1
593
      mov  edi,1
605
 
594
 
606
      mov  cl,[ecx]
595
      mov  cl,[ecx]
607
      mov  edi,[write_error_to]
596
      mov  edi,[write_error_to]
608
      mov  [edi],cl
597
      mov  [edi],cl
609
      dec  [write_error_to]
598
      dec  [write_error_to]
610
 
599
 
611
      pop  ecx
600
      pop  ecx
612
      shr  ecx,4
601
      shr  ecx,4
613
      sub  eax,6*65536
602
      sub  eax,6*65536
614
      dec  esi
603
      dec  esi
615
      jnz  whl1
604
      jnz  whl1
616
 
605
 
617
      popa
606
      popa
618
      ret
607
      ret
619
 
608
 
620
iglobal
609
iglobal
621
  hexletters  db '0123456789ABCDEF'
610
  hexletters  db '0123456789ABCDEF'
622
 
611
 
623
  error_interrupt         dd  -1
612
  error_interrupt         dd  -1
624
  error_interrupt_entry   dd  -1
613
  error_interrupt_entry   dd  -1
625
 
614
 
626
  printerrorat            dd 300
615
  printerrorat            dd 300
627
 
616
 
628
  process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
617
  process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
629
  process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
618
  process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
630
  process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
619
  process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
631
  system_error   db 'K : Kernel error',13,10,0
620
  system_error   db 'K : Kernel error',13,10,0
632
endg
621
endg
633
 
622
 
634
uglobal
623
uglobal
635
  write_error_to  dd  0x0
624
  write_error_to  dd  0x0
636
endg
625
endg
637
 
626
 
638
show_error_parameters:
627
show_error_parameters:
639
        
628
        
640
        mov    [write_error_to],process_pid+43
629
        mov    [write_error_to],process_pid+43
641
        mov    eax,[0x3000]
630
        mov    eax,[0x3000]
642
        shl    eax, 5
631
        shl    eax, 5
643
        mov    eax,[0x3000+4+eax]
632
        mov    eax,[0x3000+4+eax]
644
        call   writehex
633
        call   writehex
645
        
634
        
646
        mov    [write_error_to],process_error+43
635
        mov    [write_error_to],process_error+43
647
        mov    eax,[error_interrupt]
636
        mov    eax,[error_interrupt]
648
        call   writehex
637
        call   writehex
649
        
638
        
650
        mov    eax,[0x3000]
639
        mov    eax,[0x3000]
651
        shl    eax,8
640
        shl    eax,8
652
        cmp    [0x80000+eax+0xB0],dword 0
641
        cmp    [0x80000+eax+0xB0],dword 0
653
        jnz    .system_error
642
        jnz    .system_error
654
 
643
 
655
        mov    eax,[0x3000]
644
        mov    eax,[0x3000]
656
        imul   eax,tss_step
645
        imul   eax,tss_step
657
        mov    eax,[eax+tss_data+l.eip-tss_sceleton]
646
        mov    eax,[eax+tss_data+l.eip-tss_sceleton]
658
.out_eip:        
647
.out_eip:        
659
        mov    [write_error_to],process_eip+43
648
        mov    [write_error_to],process_eip+43
660
        call   writehex
649
        call   writehex
661
 
650
 
662
        mov    esi,process_error
651
        mov    esi,process_error
663
        call   sys_msg_board_str
652
        call   sys_msg_board_str
664
 
653
 
665
        mov    esi,process_pid
654
        mov    esi,process_pid
666
        call   sys_msg_board_str
655
        call   sys_msg_board_str
667
 
656
 
668
        mov    esi,process_eip
657
        mov    esi,process_eip
669
        call   sys_msg_board_str
658
        call   sys_msg_board_str
670
 
659
 
671
        ret
660
        ret
672
        
661
        
673
.system_error:
662
.system_error:
674
        mov    esi,system_error
663
        mov    esi,system_error
675
        call   sys_msg_board_str
664
        call   sys_msg_board_str
676
        mov    eax,[0x3000]
665
        mov    eax,[0x3000]
677
        shl    eax,7
666
        shl    eax,7
678
        mov    eax,[eax+0x298000+l.eip-tss_sceleton]
667
        mov    eax,[eax+0x298000+l.eip-tss_sceleton]
679
        jmp    .out_eip        
668
        jmp    .out_eip        
680
 
669
 
681
 
-
 
682
irq5:
-
 
683
 
-
 
684
     call   restore_caller
-
 
685
 
-
 
686
     mov    dx,word [sb16]
-
 
687
     add    dx,0xe
-
 
688
     in     al,dx
-
 
689
 
-
 
690
;     mov    byte [SB16_Status],0
-
 
691
 
-
 
692
     mov    [check_idle_semaphore],5
-
 
693
 
-
 
694
     mov    al,0x20
670
 
695
     out    0x20,al
-
 
696
 
-
 
697
     call  return_to_caller
-
 
698
 
-
 
699
     jmp   irq5
-
 
700
 
-
 
701
irqD:
-
 
702
 
-
 
703
     call   restore_caller
-
 
704
 
-
 
705
     mov   dx,0xf0
-
 
706
     mov   al,0
-
 
707
     out   dx,al
-
 
708
 
-
 
709
     mov   dx,0xa0
-
 
710
     mov   al,0x20
-
 
711
     out   dx,al
-
 
712
     mov   dx,0x20
-
 
713
     out   dx,al
-
 
714
 
-
 
715
     mov   ds,cx
-
 
716
     mov   es,cx
-
 
717
     mov   fs,cx
-
 
718
 
-
 
719
     call  return_to_caller
671
 
720
 
672
 
721
     jmp   irqD
673
; irq1  ->  hid/keyboard.inc
722
 
674
 
723
p_irq2:
675
p_irq2:
724
 
676
 
725
     call  restore_caller
677
     call  restore_caller
726
 
678
 
727
     mov   edi,2               ; 1
679
     mov   edi,2               ; 1
728
     call  irqhandler          ; 2/5
680
     call  irqhandler          ; 2/5
729
 
681
 
730
     call  return_to_caller
682
     call  return_to_caller
731
 
683
 
732
     jmp   p_irq2
684
     jmp   p_irq2
733
 
685
 
734
p_irq3:
686
p_irq3:
735
 
687
 
736
     call  restore_caller
688
     call  restore_caller
737
 
689
 
738
     mov   edi,3
690
     mov   edi,3
739
     call  irqhandler
691
     call  irqhandler
740
 
692
 
741
     call  return_to_caller
693
     call  return_to_caller
742
 
694
 
743
     jmp   p_irq3
695
     jmp   p_irq3
744
 
696
 
745
p_irq4:
697
p_irq4:
746
 
698
 
747
     call  restore_caller
699
     call  restore_caller
748
 
700
 
749
     mov   edi,4
701
     mov   edi,4
750
     call  irqhandler
702
     call  irqhandler
751
 
703
 
752
     call  return_to_caller
704
     call  return_to_caller
753
 
705
 
754
     jmp   p_irq4
706
     jmp   p_irq4
755
 
707
 
756
p_irq5:
708
p_irq5:
757
 
709
 
758
     call  restore_caller
710
     call  restore_caller
759
 
711
 
760
     mov   edi,5
712
     mov   edi,5
761
     call  irqhandler
713
     call  irqhandler
762
 
714
 
763
     call  return_to_caller
715
     call  return_to_caller
764
 
716
 
765
     jmp   p_irq5
717
     jmp   p_irq5
766
 
718
 
767
p_irq6:
719
p_irq6:
768
 
720
 
769
     call  restore_caller
721
     call  restore_caller
770
 
722
 
771
     call  fdc_irq
723
     call  fdc_irq
772
 
724
 
773
     mov   edi,6
725
     mov   edi,6
774
     call  irqhandler
726
     call  irqhandler
775
 
727
 
776
     call  return_to_caller
728
     call  return_to_caller
777
 
729
 
778
     jmp   p_irq6
730
     jmp   p_irq6
779
 
731
 
780
p_irq7:
732
p_irq7:
781
 
733
 
782
     call  restore_caller
734
     call  restore_caller
783
 
735
 
784
     mov   edi,7
736
     mov   edi,7
785
     call  irqhandler
737
     call  irqhandler
786
 
738
 
787
     call  return_to_caller
739
     call  return_to_caller
788
 
740
 
789
     jmp   p_irq7
741
     jmp   p_irq7
790
 
742
 
791
p_irq8:
743
p_irq8:
792
 
744
 
793
     call  restore_caller
745
     call  restore_caller
794
 
746
 
795
     mov   edi,8
747
     mov   edi,8
796
     call  irqhandler
748
     call  irqhandler
797
 
749
 
798
     call  return_to_caller
750
     call  return_to_caller
799
 
751
 
800
     jmp   p_irq8
752
     jmp   p_irq8
801
 
753
 
802
p_irq9:
754
p_irq9:
803
 
755
 
804
     call  restore_caller
756
     call  restore_caller
805
 
757
 
806
     mov   edi,9
758
     mov   edi,9
807
     call  irqhandler
759
     call  irqhandler
808
 
760
 
809
     call  return_to_caller
761
     call  return_to_caller
810
 
762
 
811
     jmp   p_irq9
763
     jmp   p_irq9
812
 
764
 
813
p_irq10:
765
p_irq10:
814
 
766
 
815
     call  restore_caller
767
     call  restore_caller
816
 
768
 
817
     mov   edi,10
769
     mov   edi,10
818
     call  irqhandler
770
     call  irqhandler
819
 
771
 
820
     call  return_to_caller
772
     call  return_to_caller
821
 
773
 
822
     jmp   p_irq10
774
     jmp   p_irq10
823
 
775
 
824
p_irq11:
776
p_irq11:
825
 
777
 
826
     call  restore_caller
778
     call  restore_caller
827
 
779
 
828
     mov   edi,11
780
     mov   edi,11
829
     call  irqhandler
781
     call  irqhandler
830
 
782
 
831
     call  return_to_caller
783
     call  return_to_caller
832
 
784
 
833
     jmp   p_irq11
785
     jmp   p_irq11
834
 
786
 
835
p_irq12:
787
p_irq12:
836
 
788
 
837
      call  restore_caller
789
      call  restore_caller
838
 
790
 
839
      mov   edi,12
791
      mov   edi,12
840
      call  irqhandler
792
      call  irqhandler
841
 
793
 
842
      call  return_to_caller
794
      call  return_to_caller
843
 
795
 
844
      jmp   p_irq12
796
      jmp   p_irq12
845
 
797
 
846
p_irq13:
-
 
847
 
798
irqD:
-
 
799
     call   restore_caller
848
     call  restore_caller
800
 
-
 
801
     mov   dx,0xf0
-
 
802
     mov   al,0
-
 
803
     out   dx,al
-
 
804
 
-
 
805
     mov   dx,0xa0
-
 
806
     mov   al,0x20
849
 
807
     out   dx,al
850
     mov   edi,13
808
     mov   dx,0x20
851
     call  irqhandler
809
     out   dx,al
852
 
810
 
853
     call  return_to_caller
811
     call  return_to_caller
854
 
812
 
-
 
813
     jmp   irqD
855
     jmp   p_irq13
814
     
856
 
815
 
857
p_irq14:
816
p_irq14:
858
 
817
 
859
     call  restore_caller
818
     call  restore_caller
860
     
819
     
861
     mov   edi,14
820
     mov   edi,14
862
     call  irqhandler
821
     call  irqhandler
863
 
822
 
864
     call  return_to_caller
823
     call  return_to_caller
865
 
824
 
866
     jmp   p_irq14
825
     jmp   p_irq14
867
 
826
 
868
p_irq15:
827
p_irq15:
869
 
828
 
870
     call  restore_caller
829
     call  restore_caller
871
 
830
 
872
     mov   edi,15
831
     mov   edi,15
873
     call  irqhandler
832
     call  irqhandler
874
 
833
 
875
     call  return_to_caller
834
     call  return_to_caller
876
 
835
 
877
     jmp   p_irq15
836
     jmp   p_irq15
878
 
837
 
879
 
838
 
880
 
839
 
881
align 4
840
align 4
882
restore_caller:
841
restore_caller:
883
 
842
 
884
      mov    edi,[0x3000]
843
      mov    edi,[0x3000]
885
      shl    edi, 3
844
      shl    edi, 3
886
      mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
845
      mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
887
 
846
 
888
      ret
847
      ret
889
 
848
 
890
align 4
849
align 4
891
return_to_caller:
850
return_to_caller:
892
 
851
 
893
      mov   ebx,[0x3000]
852
      mov   ebx,[0x3000]
894
      shl   bx,3
853
      shl   bx,3
895
      add   bx,tss0;t
854
      add   bx,tss0;t
896
      mov   [tss_irq12],bx
855
      mov   [tss_irq12],bx
897
 
856
 
898
           db    0xea
857
           db    0xea
899
           dd    0
858
           dd    0
900
tss_irq12  dw    tss0;t
859
tss_irq12  dw    tss0;t
901
 
860
 
902
           ret
861
           ret
903
 
862
 
904
uglobal
863
uglobal
905
  irqh dd 0x0
864
  irqh dd 0x0
906
endg
865
endg
907
 
866
 
908
irqhandler:
867
irqhandler:
909
 
868
 
910
     push   edi
869
     push   edi
911
 
870
 
912
     mov    esi,edi          ; 1
871
     mov    esi,edi          ; 1
913
     shl    esi,6            ; 1
872
     shl    esi,6            ; 1
914
     add    esi,irq00read    ; 1
873
     add    esi,irq00read    ; 1
915
     shl    edi,12           ; 1
874
     shl    edi,12           ; 1
916
     add    edi,0x2E0000
875
     add    edi,0x2E0000
917
 
876
 
918
     mov    [check_idle_semaphore],5
877
     mov    [check_idle_semaphore],5
919
 
878
 
920
   irqnewread:
879
   irqnewread:
921
 
880
 
922
     mov    dx,[esi]         ; 2+
881
     mov    dx,[esi]         ; 2+
923
 
882
 
924
     cmp    dx,0             ; 1
883
     cmp    dx,0             ; 1
925
     jz     irqover
884
     jz     irqover
926
     cmp    [esi+3],byte 1   ; 2     ; byte read
885
     cmp    [esi+3],byte 1   ; 2     ; byte read
927
     jne    noirqbyte        ; 4-11
886
     jne    noirqbyte        ; 4-11
928
 
887
 
929
     in     al,dx
888
     in     al,dx
930
 
889
 
931
     mov    edx,[edi]
890
     mov    edx,[edi]
932
     cmp    edx,4000
891
     cmp    edx,4000
933
     je     irqfull
892
     je     irqfull
934
     mov    ebx,edi
893
     mov    ebx,edi
935
     add    ebx,0x10
894
     add    ebx,0x10
936
     add    ebx,edx
895
     add    ebx,edx
937
     mov    [ebx],al
896
     mov    [ebx],al
938
     inc    edx
897
     inc    edx
939
     mov    [edi],edx
898
     mov    [edi],edx
940
 
899
 
941
     add    esi,4
900
     add    esi,4
942
     jmp    irqnewread
901
     jmp    irqnewread
943
 
902
 
944
   noirqbyte:
903
   noirqbyte:
945
 
904
 
946
 
905
 
947
     cmp    [esi+3],byte 2     ; word read
906
     cmp    [esi+3],byte 2     ; word read
948
     jne    noirqword
907
     jne    noirqword
949
 
908
 
950
     in     ax,dx
909
     in     ax,dx
951
 
910
 
952
     mov    edx,[edi]
911
     mov    edx,[edi]
953
     cmp    edx,4000
912
     cmp    edx,4000
954
     je     irqfull
913
     je     irqfull
955
     mov    ebx,edi
914
     mov    ebx,edi
956
     add    ebx,0x10
915
     add    ebx,0x10
957
     add    ebx,edx
916
     add    ebx,edx
958
     mov    [ebx],ax
917
     mov    [ebx],ax
959
     add    edx,2
918
     add    edx,2
960
     mov    [edi],edx
919
     mov    [edi],edx
961
     add    esi,4
920
     add    esi,4
962
     jmp    irqnewread
921
     jmp    irqnewread
963
 
922
 
964
   noirqword:
923
   noirqword:
965
   irqfull:
924
   irqfull:
966
   irqover:
925
   irqover:
967
 
926
 
968
     mov    al,0x20            ; ready for next irq
927
     mov    al,0x20            ; ready for next irq
969
     out    0x20,al
928
     out    0x20,al
970
 
929
 
971
     pop    ebx
930
     pop    ebx
972
     cmp    ebx,7
931
     cmp    ebx,7
973
     jbe    noa0
932
     jbe    noa0
974
     out    0xa0,al
933
     out    0xa0,al
975
   noa0:
934
   noa0:
976
 
935
 
977
     ret
936
     ret
978
 
937
 
979
 
-
 
980
; this code should never get control!
938
 
981
; applications can use only 0x40 interrupt
939
; simply return control to interrupted process
982
unknown_interrupt:
-
 
983
 @@: call   change_task
940
unknown_interrupt:
984
     jmp    @b
941
     iret
985
 
942
 
986
 
943
 
987
 
944
 
988
 
945
 
989
set_application_table_status:
946
set_application_table_status:
990
        push eax
947
        push eax
991
 
948
 
992
        mov  eax,[0x3000]
949
        mov  eax,[0x3000]
993
        ;imul eax,32
950
        ;imul eax,32
994
        shl  eax, 5
951
        shl  eax, 5
995
        add  eax,0x3000+4
952
        add  eax,0x3000+4
996
        mov  eax,[eax]
953
        mov  eax,[eax]
997
 
954
 
998
        mov  [application_table_status],eax
955
        mov  [application_table_status],eax
999
 
956
 
1000
        pop  eax
957
        pop  eax
1001
 
958
 
1002
        ret
959
        ret
1003
 
960
 
1004
 
961
 
1005
clear_application_table_status:
962
clear_application_table_status:
1006
        push eax
963
        push eax
1007
 
964
 
1008
        mov  eax,[0x3000]
965
        mov  eax,[0x3000]
1009
        ;imul eax,32
966
        ;imul eax,32
1010
        shl  eax, 5
967
        shl  eax, 5
1011
        add  eax,0x3000+4
968
        add  eax,0x3000+4
1012
        mov  eax,[eax]
969
        mov  eax,[eax]
1013
 
970
 
1014
        cmp  eax,[application_table_status]
971
        cmp  eax,[application_table_status]
1015
        jne  apptsl1
972
        jne  apptsl1
1016
        mov  [application_table_status],0
973
        mov  [application_table_status],0
1017
      apptsl1:
974
      apptsl1:
1018
 
975
 
1019
        pop  eax
976
        pop  eax
1020
 
977
 
1021
        ret
978
        ret
1022
 
-
 
1023
uglobal
-
 
1024
  old_code_0 dd 0x0
-
 
1025
  old_code_1 dd 0x0
-
 
1026
 
-
 
1027
  ;
-
 
1028
 
-
 
1029
  new_code_0 dd 0x0
-
 
1030
  new_code_1 dd 0x0
-
 
1031
 
-
 
1032
  new_data_0 dd 0x0
-
 
1033
  new_data_1 dd 0x0
-
 
1034
 
-
 
1035
  new_pos    dd 0x0
-
 
1036
  new_amount dd 0x0
-
 
1037
endg
979
 
1038
 
980
 
1039
 
981
 
1040
sys_resize_app_memory:
982
sys_resize_app_memory:
1041
        ; eax = 1 - resize
983
        ; eax = 1 - resize
1042
        ;     ebx = new amount of memory
984
        ;     ebx = new amount of memory
1043
 
985
 
1044
        cmp    eax,1
986
        cmp    eax,1
1045
        jne    .no_application_mem_resize
987
        jne    .no_application_mem_resize
1046
        
988
        
1047
        jmp    new_mem_resize ;resize for new type of processes
989
        jmp    new_mem_resize ;resize for new type of processes
1048
 
990
 
1049
 
991
 
1050
     .no_application_mem_resize:
992
     .no_application_mem_resize:
1051
 
993
 
1052
        ret
994
        ret
1053
 
995
 
1054
 
996
 
1055
 
997
 
1056
get_app_params:
998
get_app_params:
1057
 
999
 
1058
    push eax
1000
    push eax
1059
 
1001
 
1060
    cmp  [0x90000+6],word '00'
1002
    cmp  [0x90000+6],word '00'
1061
    jne  no_00_header
1003
    jne  no_00_header
1062
 
1004
 
1063
    mov  eax,[0x90000+12]
1005
    mov  eax,[0x90000+12]
1064
    mov  [app_start],eax
1006
    mov  [app_start],eax
1065
    mov  eax,[0x90000+16]
1007
    mov  eax,[0x90000+16]
1066
    mov  [app_i_end],eax
1008
    mov  [app_i_end],eax
1067
    mov  eax,[0x90000+20]
1009
    mov  eax,[0x90000+20]
1068
    mov  [app_mem],eax
1010
    mov  [app_mem],eax
1069
    shr  eax,1
1011
    shr  eax,1
1070
    sub  eax,0x10
1012
    sub  eax,0x10
1071
    mov  [app_esp],eax
1013
    mov  [app_esp],eax
1072
    mov  eax,[0x90000+24]
1014
    mov  eax,[0x90000+24]
1073
    mov  [app_i_param],eax
1015
    mov  [app_i_param],eax
1074
    mov  [app_i_icon],dword 0
1016
    mov  [app_i_icon],dword 0
1075
 
1017
 
1076
    pop  eax
1018
    pop  eax
1077
    mov  esi,1
1019
    mov  esi,1
1078
    ret
1020
    ret
1079
 
1021
 
1080
  no_00_header:
1022
  no_00_header:
1081
 
1023
 
1082
 
1024
 
1083
    cmp  [0x90000+6],word '01'
1025
    cmp  [0x90000+6],word '01'
1084
    jne  no_01_header
1026
    jne  no_01_header
1085
 
1027
 
1086
    mov  eax,[0x90000+12]
1028
    mov  eax,[0x90000+12]
1087
    mov  [app_start],eax
1029
    mov  [app_start],eax
1088
    mov  eax,[0x90000+16]
1030
    mov  eax,[0x90000+16]
1089
    mov  [app_i_end],eax
1031
    mov  [app_i_end],eax
1090
    mov  eax,[0x90000+20]
1032
    mov  eax,[0x90000+20]
1091
    mov  [app_mem],eax
1033
    mov  [app_mem],eax
1092
    mov  eax,[0x90000+24]
1034
    mov  eax,[0x90000+24]
1093
    mov  [app_esp],eax
1035
    mov  [app_esp],eax
1094
    mov  eax,[0x90000+28]
1036
    mov  eax,[0x90000+28]
1095
    mov  [app_i_param],eax
1037
    mov  [app_i_param],eax
1096
    mov  eax,[0x90000+32]
1038
    mov  eax,[0x90000+32]
1097
    mov  [app_i_icon],eax
1039
    mov  [app_i_icon],eax
1098
 
1040
 
1099
    pop  eax
1041
    pop  eax
1100
    mov  esi,1
1042
    mov  esi,1
1101
    ret
1043
    ret
1102
 
1044
 
1103
   no_01_header:
1045
   no_01_header:
1104
 
1046
 
1105
    pop  eax
1047
    pop  eax
1106
    mov  esi,0
1048
    mov  esi,0
1107
    ret
1049
    ret
1108
 
1050
 
1109
 
1051
 
1110
start_application_fl:
1052
start_application_fl:
1111
    jmp new_start_application_fl
1053
    jmp new_start_application_fl
1112
 
1054
 
1113
;************************************************************************
1055
;************************************************************************
1114
 
1056
 
1115
start_application_floppy:
1057
start_application_floppy:
1116
    jmp  new_start_application_floppy
1058
    jmp  new_start_application_floppy
1117
 
1059
 
1118
;********************************************************************
1060
;********************************************************************
1119
 
1061
 
1120
start_application_hd:
1062
start_application_hd:
1121
    jmp   new_start_application_hd
1063
    jmp   new_start_application_hd
1122
 
1064
 
1123
uglobal
1065
uglobal
1124
  ;threadstring       dd  0x0
-
 
1125
  new_process_place  dd  0x0
1066
  new_process_place  dd  0x0
1126
  ;check_processes    dd  0x0
-
 
1127
  ;dec3004            db  0x0
-
 
1128
  app_start    dd  0x0
1067
  app_start    dd  0x0
1129
  app_i_end    dd  0x0
1068
  app_i_end    dd  0x0
1130
  app_mem      dd  0x0
1069
  app_mem      dd  0x0
1131
  app_esp      dd  0x0
1070
  app_esp      dd  0x0
1132
  app_i_param  dd  0x0
1071
  app_i_param  dd  0x0
1133
  app_i_icon   dd  0x0
1072
  app_i_icon   dd  0x0
1134
  app_mem_pos  dd  0x0
1073
  app_mem_pos  dd  0x0
1135
  ;thread_create    dd 0x0
-
 
1136
  ;gdt_place        dd 0x0
-
 
1137
  appl_path        dd 0x0
1074
  appl_path        dd 0x0
1138
  appl_path_size   dd 0x0         
1075
  appl_path_size   dd 0x0         
1139
endg
1076
endg
1140
 
1077
 
1141
iglobal
1078
iglobal
1142
  hd_app_string      db  'HDAPP       '
1079
  hd_app_string      db  'HDAPP       '
1143
  process_loading    db 'K : Process - loading ',13,10,0
1080
  process_loading    db 'K : Process - loading ',13,10,0
1144
  process_running    db 'K : Process - done',13,10,0
1081
  process_running    db 'K : Process - done',13,10,0
1145
  first_gdt_search   dd 0x2
1082
  first_gdt_search   dd 0x2
1146
endg
1083
endg
1147
 
1084
 
1148
 
1085
 
1149
sys_threads:
1086
sys_threads:
1150
 
1087
 
1151
; eax=1 create thread
1088
; eax=1 create thread
1152
;
1089
;
1153
;   ebx=thread start
1090
;   ebx=thread start
1154
;   ecx=thread stack value
1091
;   ecx=thread stack value
1155
;
1092
;
1156
; on return : eax = pid
1093
; on return : eax = pid
1157
jmp new_sys_threads
1094
jmp new_sys_threads
1158
 
1095
 
1159
iglobal
1096
iglobal
1160
  process_terminating   db 'K : Process - terminating',13,10,0
1097
  process_terminating   db 'K : Process - terminating',13,10,0
1161
  process_terminated    db 'K : Process - done',13,10,0
1098
  process_terminated    db 'K : Process - done',13,10,0
1162
endg
1099
endg
1163
 
1100
 
1164
 
1101
 
1165
terminate: ; terminate application
1102
terminate: ; terminate application
1166
    push   esi
1103
    push   esi
1167
    mov    esi,process_terminating
1104
    mov    esi,process_terminating
1168
    call   sys_msg_board_str
1105
    call   sys_msg_board_str
1169
    pop    esi
1106
    pop    esi
1170
;start memory manager code    
1107
;start memory manager code    
1171
;    mov    eax,esi
1108
;    mov    eax,esi
1172
;    call   MEM_Heap_Clean
1109
;    call   MEM_Heap_Clean
1173
;end memory manager code
1110
;end memory manager code
1174
    
1111
    
1175
 
1112
 
1176
    cli
1113
    cli
1177
    cmp   [application_table_status],0
1114
    cmp   [application_table_status],0
1178
    je    term9
1115
    je    term9
1179
    sti
1116
    sti
1180
    call  change_task
1117
    call  change_task
1181
    jmp   terminate
1118
    jmp   terminate
1182
  term9:
1119
  term9:
1183
 
1120
 
1184
    call  set_application_table_status
1121
    call  set_application_table_status
1185
    
1122
    
1186
    mov    eax,esi
1123
    mov    eax,esi
1187
    call   dispose_app_cr3_table
1124
    call   dispose_app_cr3_table
1188
 
-
 
1189
    mov   [first_gdt_search],0x2   ; start gdt search from beginning
-
 
1190
 
1125
 
1191
    cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
1126
    cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
1192
    jne   fpu_ok_1
1127
    jne   fpu_ok_1
1193
    mov   [prev_user_of_fpu],1
1128
    mov   [prev_user_of_fpu],1
1194
  fpu_ok_1:
1129
  fpu_ok_1:
1195
 
1130
 
1196
    mov   [0xf400],byte 0           ; empty keyboard buffer
1131
    mov   [0xf400],byte 0           ; empty keyboard buffer
1197
    mov   [0xf500],byte 0           ; empty button buffer
1132
    mov   [0xf500],byte 0           ; empty button buffer
1198
 
-
 
1199
;    mov   ecx,esi                               ; clear memory reserv.
-
 
1200
;    shl   ecx,3
-
 
1201
;    mov   [ecx+gdts+ app_code-3 +0],dword 0
-
 
1202
;    mov   [ecx+gdts+ app_code-3 +4],dword 0
-
 
1203
;    mov   [ecx+gdts+ app_data-3 +0],dword 0
-
 
1204
;    mov   [ecx+gdts+ app_data-3 +4],dword 0
-
 
1205
 
-
 
1206
    mov   edi, esi
-
 
1207
 
-
 
1208
 
-
 
1209
    mov   [usedi40+eax],byte 0
-
 
1210
 
1133
 
1211
 
1134
 
1212
    mov   ecx,esi                 ; remove buttons
1135
    mov   ecx,esi                 ; remove buttons
1213
  bnewba2:
1136
  bnewba2:
1214
    mov   edi,[0xfe88]
1137
    mov   edi,[0xfe88]
1215
    mov   eax,edi
1138
    mov   eax,edi
1216
    cld
1139
    cld
1217
    movzx ebx,word [edi]
1140
    movzx ebx,word [edi]
1218
    inc   bx
1141
    inc   bx
1219
  bnewba:
1142
  bnewba:
1220
    dec   bx
1143
    dec   bx
1221
    jz    bnmba
1144
    jz    bnmba
1222
    add   eax,0x10
1145
    add   eax,0x10
1223
    cmp   cx,[eax]
1146
    cmp   cx,[eax]
1224
    jnz   bnewba
1147
    jnz   bnewba
1225
    pusha
1148
    pusha
1226
    mov   ecx,ebx
1149
    mov   ecx,ebx
1227
    inc   ecx
1150
    inc   ecx
1228
    shl   ecx,4
1151
    shl   ecx,4
1229
    mov   ebx,eax
1152
    mov   ebx,eax
1230
    add   eax,0x10
1153
    add   eax,0x10
1231
    call  memmove
1154
    call  memmove
1232
    dec   dword [edi]
1155
    dec   dword [edi]
1233
    popa
1156
    popa
1234
    jmp   bnewba2
1157
    jmp   bnewba2
1235
  bnmba:
1158
  bnmba:
1236
 
1159
 
1237
    pusha     ; save window coordinates for window restoring
1160
    pusha     ; save window coordinates for window restoring
1238
    cld
1161
    cld
1239
    shl   esi,5
1162
    shl   esi,5
1240
    add   esi,window_data
1163
    add   esi,window_data
1241
    mov   ax,[esi+0]
1164
    mov   ax,[esi+0]
1242
    mov   word [dlx],ax
1165
    mov   word [dlx],ax
1243
    mov   bx,[esi+8]
1166
    mov   bx,[esi+8]
1244
    add   ax,bx
1167
    add   ax,bx
1245
    mov   word [dlxe],ax
1168
    mov   word [dlxe],ax
1246
    mov   ax,[esi+4]
1169
    mov   ax,[esi+4]
1247
    mov   word [dly],ax
1170
    mov   word [dly],ax
1248
    mov   bx,[esi+12]
1171
    mov   bx,[esi+12]
1249
    add   ax,bx
1172
    add   ax,bx
1250
    mov   word [dlye],ax
1173
    mov   word [dlye],ax
1251
    mov   [esi+0],word 0
1174
    mov   [esi+0],word 0
1252
    mov   [esi+8],word 5
1175
    mov   [esi+8],word 5
1253
    mov   ax,[0xFE04]
1176
    mov   ax,[0xFE04]
1254
    mov   [esi+4],ax
1177
    mov   [esi+4],ax
1255
    mov   [esi+12],word 5
1178
    mov   [esi+12],word 5
1256
    xor   eax, eax
1179
    xor   eax, eax
1257
    mov   [esi+16],eax;dword 0
1180
    mov   [esi+16],eax;dword 0
1258
    mov   [esi+20],eax;dword 0
1181
    mov   [esi+20],eax;dword 0
1259
    mov   [esi+24],eax;dword 0
1182
    mov   [esi+24],eax;dword 0
1260
    mov   [esi+28],eax;dword 0
1183
    mov   [esi+28],eax;dword 0
1261
    popa
1184
    popa
1262
 
1185
 
1263
    pusha
1186
    pusha
1264
    mov   edi,esi
1187
    mov   edi,esi
1265
    shl   edi,5
1188
    shl   edi,5
1266
    add   edi,window_data
1189
    add   edi,window_data
1267
    mov   ecx,32/4
1190
    mov   ecx,32/4
1268
    xor   eax, eax
1191
    xor   eax, eax
1269
  ;  cld
1192
  ;  cld
1270
    rep   stosd
1193
    rep   stosd
1271
 
1194
 
1272
    mov   eax,[0xFE04]      ; set window to start from maxy+1
1195
    mov   eax,[0xFE04]      ; set window to start from maxy+1
1273
    add   eax,2
1196
    add   eax,2
1274
 
1197
 
1275
    mov   edi,esi
1198
    mov   edi,esi
1276
    shl   edi,5
1199
    shl   edi,5
1277
    add   edi,window_data
1200
    add   edi,window_data
1278
    mov   [edi+4],eax
1201
    mov   [edi+4],eax
1279
 
1202
 
1280
    popa
1203
    popa
1281
 
1204
 
1282
    pusha
1205
    pusha
1283
    mov   edi,esi
1206
    mov   edi,esi
1284
    shl   edi,5
1207
    shl   edi,5
1285
    add   edi,draw_data
1208
    add   edi,draw_data
1286
    mov   ecx,32/4
1209
    mov   ecx,32/4
1287
    xor   eax, eax
1210
    xor   eax, eax
1288
  ;  cld
1211
  ;  cld
1289
    rep   stosd
1212
    rep   stosd
1290
    popa
1213
    popa
1291
 
1214
 
1292
    pusha         ; at 0x80000+
1215
    pusha         ; at 0x80000+
1293
    mov   edi,esi
1216
    mov   edi,esi
1294
    shl   edi,8
1217
    shl   edi,8
1295
    add   edi,0x80000
1218
    add   edi,0x80000
1296
    mov   ecx,256/4
1219
    mov   ecx,256/4
1297
    xor   eax, eax
1220
    xor   eax, eax
1298
  ;  cld
1221
  ;  cld
1299
    rep   stosd
1222
    rep   stosd
1300
    popa
1223
    popa
1301
 
1224
 
1302
    pusha          ; name to spaces
1225
    pusha          ; name to spaces
1303
    mov   edi,esi
1226
    mov   edi,esi
1304
    shl   edi,8
1227
    shl   edi,8
1305
    add   edi,0x80000
1228
    add   edi,0x80000
1306
    mov   ecx,11
1229
    mov   ecx,11
1307
    mov   eax,' '
1230
    mov   eax,' '
1308
  ;  cld
1231
  ;  cld
1309
    rep   stosb
1232
    rep   stosb
1310
    popa
1233
    popa
1311
 
1234
 
1312
    pusha                ; C000 --> C400
1235
    pusha                ; C000 --> C400
1313
    mov   eax, 0xc000
1236
    mov   eax, 0xc000
1314
    mov   esi, 0
1237
    mov   esi, 0
1315
  nlc40:
1238
  nlc40:
1316
    add   eax, 2
1239
    add   eax, 2
1317
    inc   esi
1240
    inc   esi
1318
    cmp   esi, [0x3004]
1241
    cmp   esi, [0x3004]
1319
    jae   nlc41
1242
    jae   nlc41
1320
    movzx ecx, word [eax]
1243
    movzx ecx, word [eax]
1321
    mov   [0xC400 + ecx*2], si
1244
    mov   [0xC400 + ecx*2], si
1322
    jmp   nlc40
1245
    jmp   nlc40
1323
  nlc41:
1246
  nlc41:
1324
    popa
1247
    popa
1325
 
1248
 
1326
    pusha ; remove hd1 reservation
1249
    pusha ; remove hd1 reservation
1327
    mov   edx,esi
1250
    mov   edx,esi
1328
    shl   edx, 5 ;imul  edx,0x20
1251
    shl   edx, 5 ;imul  edx,0x20
1329
    add   edx,0x3000
1252
    add   edx,0x3000
1330
    mov   edx,[edx+4]
1253
    mov   edx,[edx+4]
1331
    cmp   [hd1_status],edx
1254
    cmp   [hd1_status],edx
1332
    jne   no_hd1_s_remove
1255
    jne   no_hd1_s_remove
1333
    mov   [hd1_status],0
1256
    mov   [hd1_status],0
1334
  no_hd1_s_remove:
1257
  no_hd1_s_remove:
1335
    popa
1258
    popa
1336
 
1259
 
1337
    pusha ; remove all irq reservations
1260
    pusha ; remove all irq reservations
1338
    mov   edx,esi
1261
    mov   edx,esi
1339
    shl   edx, 5 ;imul  edx,0x20
1262
    shl   edx, 5 ;imul  edx,0x20
1340
    add   edx,0x3000
1263
    add   edx,0x3000
1341
    mov   edx,[edx+4]
1264
    mov   edx,[edx+4]
1342
    mov   edi,irq_owner
1265
    mov   edi,irq_owner
1343
    mov   ecx,16
1266
    mov   ecx,16
1344
  newirqfree:
1267
  newirqfree:
1345
    cmp   [edi],edx
1268
    cmp   [edi],edx
1346
    jne   nofreeirq
1269
    jne   nofreeirq
1347
    mov   [edi],dword 0
1270
    mov   [edi],dword 0
1348
  nofreeirq:
1271
  nofreeirq:
1349
    add    edi,4
1272
    add    edi,4
1350
    loop   newirqfree
1273
    loop   newirqfree
1351
    popa
1274
    popa
1352
 
1275
 
1353
 
1276
 
1354
    pusha                     ; remove all port reservations
1277
    pusha                     ; remove all port reservations
1355
 
1278
 
1356
    mov   edx,esi
1279
    mov   edx,esi
1357
    shl   edx, 5 ;imul  edx,0x20
1280
    shl   edx, 5 ;imul  edx,0x20
1358
    add   edx,0x3000
1281
    add   edx,0x3000
1359
    mov   edx,[edx+4]
1282
    mov   edx,[edx+4]
1360
 
1283
 
1361
  rmpr0:
1284
  rmpr0:
1362
 
1285
 
1363
    mov   esi,[0x2d0000]
1286
    mov   esi,[0x2d0000]
1364
 
1287
 
1365
    cmp   esi,0
1288
    cmp   esi,0
1366
    je    rmpr9
1289
    je    rmpr9
1367
 
1290
 
1368
  rmpr3:
1291
  rmpr3:
1369
 
1292
 
1370
    mov   edi,esi
1293
    mov   edi,esi
1371
    shl   edi,4
1294
    shl   edi,4
1372
    add   edi,0x2d0000
1295
    add   edi,0x2d0000
1373
 
1296
 
1374
    cmp   edx,[edi]
1297
    cmp   edx,[edi]
1375
    je    rmpr4
1298
    je    rmpr4
1376
 
1299
 
1377
    dec   esi
1300
    dec   esi
1378
    jnz   rmpr3
1301
    jnz   rmpr3
1379
 
1302
 
1380
    jmp   rmpr9
1303
    jmp   rmpr9
1381
 
1304
 
1382
  rmpr4:
1305
  rmpr4:
1383
 
1306
 
1384
    mov   ecx,256
1307
    mov   ecx,256
1385
    sub   ecx,esi
1308
    sub   ecx,esi
1386
    shl   ecx,4
1309
    shl   ecx,4
1387
 
1310
 
1388
    mov   esi,edi
1311
    mov   esi,edi
1389
    add   esi,16
1312
    add   esi,16
1390
    cld
1313
    cld
1391
    rep   movsb
1314
    rep   movsb
1392
 
1315
 
1393
    dec   dword [0x2d0000]
1316
    dec   dword [0x2d0000]
1394
 
1317
 
1395
    jmp   rmpr0
1318
    jmp   rmpr0
1396
 
1319
 
1397
  rmpr9:
1320
  rmpr9:
1398
 
1321
 
1399
    popa
1322
    popa
1400
    mov  edi,esi         ; do not run this process slot
1323
    mov  edi,esi         ; do not run this process slot
1401
    shl  edi, 5 ;imul edi,0x20
-
 
1402
;    add  edi,0x3000
1324
    shl  edi, 5
1403
    mov  [edi+0x300A],byte 9
1325
    mov  [edi+0x300A],byte 9
1404
;    call  systest
1326
;    call  systest
1405
    sti  ; .. and life goes on
1327
    sti  ; .. and life goes on
1406
 
1328
 
1407
;    movzx eax,word [dlx]
1329
;    movzx eax,word [dlx]
1408
;    movzx ebx,word [dly]
1330
;    movzx ebx,word [dly]
1409
;    movzx ecx,word [dlxe]
1331
;    movzx ecx,word [dlxe]
1410
;    movzx edx,word [dlye]
1332
;    movzx edx,word [dlye]
1411
    call  calculatescreen
1333
    call  calculatescreen
1412
 
1334
 
1413
    xor   eax, eax
1335
    xor   eax, eax
1414
    xor   esi, esi
1336
    xor   esi, esi
1415
    call  redrawscreen
1337
    call  redrawscreen
1416
 
1338
 
1417
    mov   [0xfff4],byte 0  ; no mouse background
1339
    mov   [0xfff4],byte 0  ; no mouse background
1418
    mov   [0xfff5],byte 0  ; draw mouse
1340
    mov   [0xfff5],byte 0  ; draw mouse
1419
 
1341
 
1420
    mov   [application_table_status],0
1342
    mov   [application_table_status],0
1421
 
1343
 
1422
    mov   esi,process_terminated
1344
    mov   esi,process_terminated
1423
    call  sys_msg_board_str
1345
    call  sys_msg_board_str
1424
 
1346
 
1425
;* start code - fix error redraw for terminate (2) - Mario79
1347
;* start code - fix error redraw for terminate (2) - Mario79
1426
;     cmp  [draw_present],1
1348
;     cmp  [draw_present],1
1427
;     je  no_draw_background_temp
1349
;     je  no_draw_background_temp
1428
;     mov   [0xfff0],byte 1
1350
;     mov   [0xfff0],byte 1
1429
;no_draw_background_temp:
1351
;no_draw_background_temp:
1430
;    mov   [draw_present],0
1352
;    mov   [draw_present],0
1431
    ret
1353
    ret
1432
;draw_present db 0
1354
;draw_present db 0
1433
;* end code - fix error redraw for terminate (2) - Mario79
1355
;* end code - fix error redraw for terminate (2) - Mario79
1434
 
1356
 
1435
iglobal
1357
iglobal
1436
  boot_sched_1    db   'Building gdt tss pointer',0
1358
  boot_sched_1    db   'Building gdt tss pointer',0
1437
  ;boot_sched_2    db   'Building gdt gate pointer',0
1359
  ;boot_sched_2    db   'Building gdt gate pointer',0
1438
  boot_sched_3    db   'Building interrupt table - TSS',0
1360
  boot_sched_3    db   'Building interrupt table - TSS',0
1439
  boot_sched_3_2  db   'Building interrupt table - GDT',0
1361
  boot_sched_3_2  db   'Building interrupt table - GDT',0
1440
  boot_sched_3_3  db   'Building interrupt table - IDT',0
1362
  boot_sched_3_3  db   'Building interrupt table - IDT',0
1441
  boot_sched_4    db   'Building syscall interrupt table',0
1363
  boot_sched_4    db   'Building syscall interrupt table',0
1442
endg
1364
endg
1443
 
1365
 
1444
 
1366
 
1445
build_scheduler:
1367
build_scheduler:
1446
      ; { Ivan 06.03.2005
-
 
1447
        mov    edi, usedi40
-
 
1448
        mov    ecx, 256/4
-
 
1449
        xor    eax, eax
-
 
1450
        rep    stosd
-
 
1451
      ; } Ivan 06.03.2005
-
 
1452
 
1368
 
1453
        mov    esi,boot_sched_1
1369
        mov    esi,boot_sched_1
1454
        call   boot_log
1370
        call   boot_log
1455
        call   build_process_gdt_tss_pointer
1371
        call   build_process_gdt_tss_pointer
1456
 
1372
 
1457
;        mov    esi,boot_sched_2
1373
;        mov    esi,boot_sched_2
1458
;        call   boot_log
1374
;        call   boot_log
1459
;        call   build_process_gdt_gate_pointer
1375
;        call   build_process_gdt_gate_pointer
1460
 
1376
 
1461
        mov    esi,boot_sched_3
1377
        mov    esi,boot_sched_3
1462
        call   boot_log
1378
        call   boot_log
1463
        call   build_interrupt_table
1379
        call   build_interrupt_table
1464
 
1380
 
1465
        mov    esi,boot_sched_4
1381
        mov    esi,boot_sched_4
1466
        call   boot_log
1382
        call   boot_log
1467
        call   build_syscall_interrupt_table
1383
        call   build_syscall_interrupt_table
1468
 
1384
 
1469
        ret
1385
        ret