Subversion Repositories shark

Rev

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

Rev Author Line No. Line
2 pj 1
/* Project:     OSLib
2
 * Description: The OS Construction Kit
3
 * Date:                1.6.2000
4
 * Idea by:             Luca Abeni & Gerardo Lamastra
5
 *
6
 * OSLib is an SO project aimed at developing a common, easy-to-use
7
 * low-level infrastructure for developing OS kernels and Embedded
8
 * Applications; it partially derives from the HARTIK project but it
9
 * currently is independently developed.
10
 *
11
 * OSLib is distributed under GPL License, and some of its code has
12
 * been derived from the Linux kernel source; also some important
13
 * ideas come from studying the DJGPP go32 extender.
14
 *
15
 * We acknowledge the Linux Community, Free Software Foundation,
16
 * D.J. Delorie and all the other developers who believe in the
17
 * freedom of software and ideas.
18
 *
19
 * For legalese, check out the included GPL license.
20
 */
21
 
22
/*	Exc/IRQ handlers (asm part)	*/
23
/* TODO: Unify the Exc/Int Mechanism... */
24
 
25
#include <ll/i386/sel.h>
26
#include <ll/i386/linkage.h>
27
#include <ll/i386/int.h>
28
#include <ll/i386/defs.h>
29
 
30
.extern SYMBOL_NAME(GDT_base)
31
.data
32
 
33
ASMFILE(Exc)
34
 
35
.globl SYMBOL_NAME(ll_irq_table)
36
.globl SYMBOL_NAME(ll_exc_table)
37
 
38
SYMBOL_NAME_LABEL(ll_irq_table)	.space  64, 0
39
SYMBOL_NAME_LABEL(ll_exc_table)	.space  64, 65
40
 
41
.text
42
 
43
.extern  SYMBOL_NAME(ll_exc_hook)
44
.extern  SYMBOL_NAME(ll_FPU_hook)
45
 
46
.globl SYMBOL_NAME(h13_bis)
47
.globl SYMBOL_NAME(exc7)
48
 
49
/* These are the hardware handlers; they all jump to ll_handler setting */
50
/* the interrupt number into EAX & save the registers on stack		*/
51
INT(1)
52
INT(2)
53
INT(3)
54
INT(4)
55
INT(5)
56
INT(6)
57
INT(7)
58
INT(8)
59
INT(9)
60
INT(10)
61
INT(11)
62
INT(12)
63
INT(13)
64
INT(14)
65
INT(15)
66
 
67
#if 0
68
/* MPF... If we have an external FPU, it will generate
69
 * INT 13 instead of EXC 16...
70
 * We must remap it to EXC 16...
71
 */
72
#if 1
73
SYMBOL_NAME_LABEL(h13_bis)
74
			/* Send EOI for 8086 coprocessor trick	*/
75
			/* Send 0H on Coprocessor port 0F0H	*/
76
			pushl	%eax
77
			xorb    %al, %al
78
			outb    %al, $0x0F0
79
			movb    $0x020, %al
80
			outb    %al, $0x0A0
81
			outb    %al, $0x020
82
			popl	%eax
83
			movl    $16, %eax
84
			jmp	ll_handler2
85
#else
86
SYMBOL_NAME_LABEL(h13_bis)	pushal
87
			/* Send EOI for 8086 coprocessor trick	*/
88
			/* Send 0H on Coprocessor port 0F0H	*/
89
 
90
			xorb    %al,%al
91
			outb    %al,$0x0F0
92
			movb    $0x020,%al
93
			outb    %al,$0x0A0
94
			outb    %al,$0x020
95
			pushl   %ds
96
			pushl   %ss
97
			pushl   %es
98
			pushl   %fs
99
			pushl   %gs
100
			movw	$(X_FLATDATA_SEL),%ax
101
			movw	%ax,%es
102
			movw	%ax,%ds
103
			movl    $(MATH_EXC),%eax
104
			pushl	%eax
105
		/* LL_ABORT OR EXC_HOOK?? */
106
/*THIS SURELY WRONG!!!! FIX IT!!!! Gerardo, help me!!! */
107
			hlt
108
/*			call    SYMBOL_NAME(ll_abort) */
109
			addl    $4,%esp
110
			popl    %gs
111
			popl    %fs
112
			popl    %es
113
			popl    %ss
114
			popl    %ds
115
			popal
116
			ret
117
#endif
118
#endif
119
 
120
/* The ll_handler process the request using the kernel function act_int() */
121
/* Then sends EOI & schedules any eventual new task!			  */
122
 
123
ll_handler:
124
			/* We do not know what is the DS value	*/
125
			/* Then we save it & set it correctly  	*/
126
 
127
			pushl	%ds
128
			pushl	%ss
129
			pushl	%es
130
			pushl	%fs
131
			pushl	%gs
132
			/* But we first transfer to the _act_int  */
133
			/* the interrupt number which is required */
134
			/* as second argument			  */
135
			pushl   %eax
136
			movw    $(X_FLATDATA_SEL),%ax
137
			movw    %ax,%es
138
			mov     %ax,%ds
139
 
140
			/* Now save the actual context on stack		*/
141
			/* to pass it to _act_int (C caling convention)	*/
142
			/* CLD is necessary when calling a C function	*/
143
 
144
			cld
145
 
146
			/* The following could be optimized a little... */
147
			popl %eax
148
			xorl %ebx, %ebx
149
			movw %ss, %bx
150
			/* We must switch to a ``safe stack'' */
151
#if 0
152
	/*
153
	 * OK, this is the idea: in %esp we have the address of the
154
	 * stack pointer in the APPLICATION address space...
155
	 * We assume that address spaces are implemented through segments...
156
	 * What we have to do is to add the segment base to %esp:
157
	 *	- Load the GDT base in a register
158
	 *	- Add DS * 8 to that value
159
	 *	- Read the corresponding GDT entry (the segment descriptor)
160
	 *	- Compute the base...
161
	 *	It is (*p & 0xFC) | (*(p +1)  & 0x0F) << 16) | *(p + 2)
162
	 */
163
			movl SYMBOL_NAME(GDT_base), %edi
164
			addl %ebx, %edi
165
			xorl %ebx, %ebx
166
			movb 7(%edi), %bh
167
			movb 4(%edi), %bl
168
			shl $16, %ebx
169
			movw 2(%edi), %bx
170
			/* Is it correct? I think so... Test it!!! */
171
			addl %ebx, %esp
172
			/* Save EBX for returning to our stack... */
173
			movw %ss, %dx
174
			movw %ds, %bx
175
			movw %bx, %ss
176
			pushl %ebx
177
			pushl %edx
178
#endif
179
			pushl %eax
180
 
181
			movl	SYMBOL_NAME(ll_irq_table)(, %eax, 4), %ebx
182
			call    *%ebx
183
 
184
			popl	%ebx    /* Store in EBX the Int number	*/
185
#if 0
186
			popl	%eax
187
			popl	%ecx	/* We must subtract it from ESP...*/
188
			subl	%ecx, %esp
189
			movw	%ax, %ss
190
#endif
191
			/* Send EOI to master & slave (if necessary) PIC */
192
			movb	$0x20,%al
193
			cmpl	$0x08,%ebx
194
			jb	eoi_master
195
eoi_slave:              movl	$0xA0,%edx
196
			outb	%al,%dx
197
eoi_master:             movl	$0x20,%edx
198
			outb	%al,%dx
199
 
200
			/* Resume the return value of _act_int 		*/
201
			/* & do the context switch if necessary!	*/
202
#ifdef __VIRCSW__
203
			movw SYMBOL_NAME(currCtx), %ax
204
			cmpw    JmpSel,%ax
205
			je      NoPreempt3
206
			movw    %ax,JmpSel
207
			ljmp    JmpZone
208
#endif
209
NoPreempt3:             popl	%gs
210
			popl	%fs
211
			popl	%es
212
			popl	%ss
213
			popl	%ds
214
			popal
215
			iret
216
 
217
 
218
EXC(0)
219
EXC(1)
220
EXC(2)
221
EXC(3)
222
EXC(4)
223
EXC(5)
224
EXC(6)
225
EXC(8)
226
EXC(9)
227
EXC(10)
228
EXC(11)
229
EXC(12)
230
EXC(13)
231
EXC(14)
232
EXC(15)
233
EXC(16)
234
 
235
/* OK, this is Exception 7, and it is generated when an ESC or WAIT
236
 * intruction is reached, and the MP and TS bits are set... Basically,
237
 * it means that the FPU context must be switched
238
 */
239
SYMBOL_NAME_LABEL(exc7)	pushal
240
            		pushl	%ds
241
			pushl	%ss
242
			pushl	%es
243
			pushl	%fs
244
			pushl	%gs
245
			movw	$(X_FLATDATA_SEL),%ax
246
			movw	%ax,%es
247
			movw	%ax,%ds
248
			cld
249
			call	SYMBOL_NAME(ll_FPU_hook)
250
			popl	%gs
251
			popl	%fs
252
			popl	%es
253
			popl	%ss
254
			popl	%ds
255
			popal
256
			iret
257
 
258
ll_handler2:
259
			pushl	%eax
260
			movw	$(X_FLATDATA_SEL),%ax
261
			movw	%ax,%ds
262
			movw	%ax,%es
263
 
264
 
265
			/* Again, the following could be optimized... */
266
/*
267
    If the Exception raised in a different address space, we have to
268
    access the task stack from the kernel address space (the linear one...)
269
*/
270
			popl %eax
271
			movw %ss, %bx
272
			/* We must switch to a ``safe stack'' */
273
			movl SYMBOL_NAME(GDT_base), %edi
274
			addl %ebx, %edi
275
			xorl %ebx, %ebx
276
			movb 7(%edi), %bh
277
			movb 4(%edi), %bl
278
			shl $16, %ebx
279
			movw 2(%edi), %bx
280
			/* Is it correct? I think so... Test it!!! */
281
			addl %ebx, %esp
282
			/* Save EBX for returning to our stack... */
283
			movw %ss, %dx
284
			movw %ds, %bx
285
			movw %bx, %ss
286
			pushl %ebx
287
			pushl %edx
288
			pushl %eax
289
			call	*SYMBOL_NAME(ll_exc_table)(, %eax, 4)
290
			addl	$4,%esp
291
 
292
			/* Restore the stack pointer!!! */
293
			popl %eax
294
			popl %ebx
295
			movw %ax, %ss
296
			subl %ebx, %esp
297
			iret