Subversion Repositories Kolibri OS

Rev

Rev 183 | Rev 221 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ha 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                               ;;
3
;;  MenuetOS process management, protected ring3                 ;;
4
;;                                                               ;;
5
;;  Distributed under GPL. See file COPYING for details.         ;;
6
;;  Copyright 2003 Ville Turjanmaa                               ;;
7
;;                                                               ;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
 
10
idtreg:
11
     dw   8*0x41-1
12
     dd   idts+8
164 serge 13
;label idts at 0xB100-8
1 ha 14
 
15
 
8 poddubny 16
uglobal
17
 tss_sceleton:
18
  l.back   dw 0,0
19
  l.esp0   dd 0
20
  l.ss0    dw 0,0
21
  l.esp1   dd 0
22
  l.ss1    dw 0,0
23
  l.esp2   dd 0
24
  l.ss2    dw 0,0
25
  l.cr3    dd 0
26
  l.eip    dd 0
27
  l.eflags dd 0
28
  l.eax    dd 0
29
  l.ecx    dd 0
30
  l.edx    dd 0
31
  l.ebx    dd 0
32
  l.esp    dd 0
33
  l.ebp    dd 0
34
  l.esi    dd 0
35
  l.edi    dd 0
36
  l.es     dw 0,0
37
  l.cs     dw 0,0
38
  l.ss     dw 0,0
39
  l.ds     dw 0,0
40
  l.fs     dw 0,0
41
  l.gs     dw 0,0
42
  l.ldt    dw 0,0
43
  l.trap   dw 0
44
  l.io     dw 0
45
endg
46
 
47
 
1 ha 48
build_process_gdt_tss_pointer:
49
 
50
        mov    ecx,tss_data
51
        mov    edi,0
52
      setgdtl2:
53
        mov    [edi+gdts+ tss0 +0], word tss_step
54
        mov    [edi+gdts+ tss0 +2], cx
55
        mov    eax,ecx
56
        shr    eax,16
57
        mov    [edi+gdts+ tss0 +4], al
58
        mov    [edi+gdts+ tss0 +7], ah
59
        mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
60
        add    ecx,tss_step
61
        add    edi,8
62
        cmp    edi,8*(max_processes+5)
63
        jbe    setgdtl2
64
 
65
        ret
66
 
67
 
68
build_interrupt_table:
69
 
6 poddubny 70
        mov    edi, idts+8
71
        mov    esi, sys_int
8 poddubny 72
        mov    ecx, 0x40
6 poddubny 73
     @@:
74
        mov    eax, [esi]
75
        mov    [edi],   ax           ; lower part of offset
76
        mov    [edi+2], word os_code ; segment selector
77
        shr    eax, 16
78
        mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
79
        mov    [edi+6], ax
80
        add    esi, 4
81
        add    edi, 8
82
        dec    ecx
83
        jnz    @b
164 serge 84
 
8 poddubny 85
        ;mov    edi,8*0x40+idts+8
3 halyavin 86
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
87
        mov    [edi + 2], word os_code
88
        mov    [edi + 4], word 11101110b*256
9 halyavin 89
        mov    [edi + 6], word (i40 shr 16)
1 ha 90
 
91
        ret
92
 
93
iglobal
94
  sys_int:
164 serge 95
    dd e0,debug_exc,e2,e3
96
    dd e4,e5,e6,e7
97
    dd e8,e9,e10,e11
98
    dd e12,e13,page_fault_handler,e15
99
 
168 serge 100
    dd except_16, e17,e18, except_19
101
    times 12 dd unknown_interrupt
1 ha 102
 
164 serge 103
    dd   irq0  , irq_serv.irq_1, p_irq2 ,irq_serv.irq_3
104
    dd   p_irq4 ,irq_serv.irq_5,p_irq6,irq_serv.irq_7
105
    dd   irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10
106
    dd   irq_serv.irq_11,p_irq12,irqD ,p_irq14,p_irq15
1 ha 107
 
108
    times 16 dd unknown_interrupt
109
 
110
    dd   i40
111
endg
112
 
40 halyavin 113
macro save_ring3_context
114
{
58 mario79 115
    push    ds es
116
    pushad
40 halyavin 117
}
118
macro restore_ring3_context
119
{
58 mario79 120
    popad
121
    pop    es ds
40 halyavin 122
}
123
 
8 poddubny 124
; simply return control to interrupted process
125
unknown_interrupt:
126
     iret
1 ha 127
 
22 poddubny 128
macro exc_wo_code [num]
8 poddubny 129
{
130
  forward
131
  e#num :
40 halyavin 132
      save_ring3_context
20 mario79 133
      mov bl, num
134
      jmp exc_c
8 poddubny 135
}
1 ha 136
 
22 poddubny 137
macro exc_w_code [num]
138
{
139
  forward
140
  e#num :
141
      add esp, 4
40 halyavin 142
      save_ring3_context
22 poddubny 143
      mov bl, num
144
      jmp exc_c
145
}
146
 
168 serge 147
exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15, 18
22 poddubny 148
exc_w_code 8, 10, 11, 12, 13, 14, 17
149
 
8 poddubny 150
exc_c:
6 poddubny 151
        mov   ax, os_data
152
        mov   ds, ax
153
        mov   es, ax
1 ha 154
 
40 halyavin 155
; test if debugging
156
        cli
157
        mov   eax, [0x3000]
158
        shl   eax, 8
115 poddubny 159
        mov   eax, [0x80000+eax+APPDATA.debugger_slot]
40 halyavin 160
        test  eax, eax
161
        jnz   .debug
162
        sti
163
; not debuggee => say error and terminate
164
        add   esp, 28h
164 serge 165
        movzx eax, bl
8 poddubny 166
        mov   [error_interrupt], eax
1 ha 167
        call  show_error_parameters
164 serge 168
 
8 poddubny 169
        mov   edx, [0x3010]
115 poddubny 170
        mov   [edx + TASKDATA.state], byte 4
164 serge 171
 
1 ha 172
        jmp   change_task
173
 
40 halyavin 174
.debug:
175
; we are debugged process, notify debugger and suspend ourself
176
; eax=debugger PID
113 diamond 177
        cld
40 halyavin 178
        movzx ecx, bl
179
        push  ecx
180
        mov   ecx, [0x3010]
115 poddubny 181
        push  dword [ecx+TASKDATA.pid]    ; PID of current process
40 halyavin 182
        push  12
183
        pop   ecx
58 mario79 184
        push  1        ; 1=exception
40 halyavin 185
        call  debugger_notify
186
        pop   ecx
187
        pop   ecx
188
        pop   ecx
189
        mov   edx, [0x3010]
115 poddubny 190
        mov   byte [edx+TASKDATA.state], 1        ; suspended
40 halyavin 191
        call  change_task
192
        restore_ring3_context
193
        iretd
1 ha 194
 
195
;;;;;;;;;;;;;;;;;;;;;;;
196
;; FPU ERROR HANDLER ;;
197
;;;;;;;;;;;;;;;;;;;;;;;
198
 
199
align 4
8 poddubny 200
e7:
40 halyavin 201
        save_ring3_context
6 poddubny 202
        clts
164 serge 203
        mov ax, os_data
204
        mov ds, ax
205
        mov es, ax
206
 
207
        mov ebx, [fpu_owner]
208
        cmp ebx, [CURRENT_TASK]
209
        je .exit
210
 
211
        shl ebx, 8
212
        mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
213
        bt [cpu_caps], CAPS_FXSR
214
        jnc .no_SSE
215
 
216
        fxsave [eax]
217
        mov ebx, [CURRENT_TASK]
218
        mov [fpu_owner], ebx
219
        shl ebx, 8
220
        cmp dword [ebx+PROC_BASE+APPDATA.fpu_init], 0
221
        je .init
222
        mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
223
        fxrstor [eax]
40 halyavin 224
        restore_ring3_context
6 poddubny 225
        iret
170 serge 226