Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
56 pj 1
/*
2
 * PC/HW routine collection v1.0 for DOS/DJGPP
3
 *
4
 *  Copyright (C) 2002 - Borca Daniel
5
 *  Email : dborca@yahoo.com
6
 *  Web   : http://www.geocities.com/dborca
7
 */
8
 
9
 
10
		.file	"pc_irq.S"
11
 
12
		.text
13
 
14
#define	IRQ_STACK_SIZE	16384
15
 
16
#define	IRQ_WRAPPER_LEN	(__irq_wrapper_1-__irq_wrapper_0)
17
#define	IRQ_OLD		(__irq_old_0-__irq_wrapper_0)
18
#define	IRQ_HOOK	(__irq_hook_0-__irq_wrapper_0)
19
#define	IRQ_STACK	(__irq_stack_0-__irq_wrapper_0)
20
 
21
		.balign	4
22
common:
23
		movw	$0x0400, %ax
24
		int	$0x31
25
 
26
		movl	%ss:8(%ebp), %ebx
27
		cmpl	$15, %ebx
28
		jbe	0f
29
	fail:
30
		orl	$-1, %eax
31
		popl	%edi
32
		popl	%ebx
33
		leave
34
		ret
35
 
36
	0:
37
		movl	%ebx, %edi
38
		imull	$IRQ_WRAPPER_LEN, %edi
39
		addl	$__irq_wrapper_0, %edi
40
 
41
		cmpb	$7, %bl
42
		jbe	1f
43
		movb	%dl, %dh
44
		subb	$8, %dh
45
	1:
46
		addb	%dh, %bl
47
		ret
48
 
49
		.balign	4
50
		.global	_pc_install_irq
51
_pc_install_irq:
52
		pushl	%ebp
53
		movl	%esp, %ebp
54
		pushl	%ebx
55
		pushl	%edi
56
 
57
		call	common
58
 
59
		cmpl	$0, IRQ_HOOK(%edi)
60
		jne	fail
61
 
62
		pushl	$IRQ_WRAPPER_LEN
63
		pushl	%edi
64
		call	__go32_dpmi_lock_code
65
		addl	$8, %esp
66
		testl	%eax, %eax
67
		jnz	fail
68
 
69
		pushl	$IRQ_STACK_SIZE
70
		call	_pc_malloc
71
		popl	%edx
72
		testl	%eax, %eax
73
		jz	fail
74
		addl	%edx, %eax
75
		movl	%eax, IRQ_STACK(%edi)
76
 
77
		movl	%ss:12(%ebp), %eax
78
		movl	%eax, IRQ_HOOK(%edi)
79
 
80
		movw	$0x0204, %ax
81
		int	$0x31
82
		movl	%edx, IRQ_OLD(%edi)
83
		movw	%cx, IRQ_OLD+4(%edi)
84
		movw	$0x0205, %ax
85
		movl	%edi, %edx
86
		movl	%cs, %ecx
87
		int	$0x31
88
 
89
	done:
90
		xorl	%eax, %eax
91
		popl	%edi
92
		popl	%ebx
93
		leave
94
		ret
95
 
96
		.balign	4
97
		.global	_pc_remove_irq
98
_pc_remove_irq:
99
		pushl	%ebp
100
		movl	%esp, %ebp
101
		pushl	%ebx
102
		pushl	%edi
103
 
104
		call	common
105
 
106
		cmpl	$0, IRQ_HOOK(%edi)
107
		je	fail
108
 
109
		movl	$0, IRQ_HOOK(%edi)
110
 
111
		movw	$0x0205, %ax
112
		movl	IRQ_OLD(%edi), %edx
113
		movl	IRQ_OLD+4(%edi), %ecx
114
		int	$0x31
115
 
116
		movl	IRQ_STACK(%edi), %eax
117
		subl	$IRQ_STACK_SIZE, %eax
118
		pushl	%eax
119
		call	_free
120
		popl	%eax
121
 
122
		jmp	done
123
 
124
#define	WRAPPER(x)							   ; \
125
		.balign	4						   ; \
126
__irq_wrapper_##x:							   ; \
127
		pushal							   ; \
128
		pushl	%ds						   ; \
129
		pushl	%es						   ; \
130
		pushl	%fs						   ; \
131
		pushl	%gs						   ; \
132
		movl	%ss, %ebx					   ; \
133
		movl	%esp, %esi					   ; \
134
		movl	%cs:___djgpp_ds_alias, %ss			   ; \
135
		movl	%cs:__irq_stack_##x, %esp			   ; \
136
		pushl	%ss						   ; \
137
		pushl	%ss						   ; \
138
		popl	%es						   ; \
139
		popl	%ds						   ; \
140
		movl	___djgpp_dos_sel, %fs				   ; \
141
		pushl	%fs						   ; \
142
		popl	%gs						   ; \
143
		call	*__irq_hook_##x					   ; \
144
		movl	%ebx, %ss					   ; \
145
		movl	%esi, %esp					   ; \
146
		testl	%eax, %eax					   ; \
147
		popl	%gs						   ; \
148
		popl	%fs						   ; \
149
		popl	%es						   ; \
150
		popl	%ds						   ; \
151
		popal							   ; \
152
		jz	__irq_ignore_##x				   ; \
153
__irq_bypass_##x:							   ; \
154
		ljmp	*%cs:__irq_old_##x				   ; \
155
__irq_ignore_##x:							   ; \
156
		iret							   ; \
157
		.balign	4						   ; \
158
__irq_old_##x:								   ; \
159
		.long	0, 0						   ; \
160
__irq_hook_##x:								   ; \
161
		.long	0						   ; \
162
__irq_stack_##x:							   ; \
163
		.long	0
164
 
165
		WRAPPER(0);
166
		WRAPPER(1);
167
		WRAPPER(2);
168
		WRAPPER(3);
169
		WRAPPER(4);
170
		WRAPPER(5);
171
		WRAPPER(6);
172
		WRAPPER(7);
173
		WRAPPER(8);
174
		WRAPPER(9);
175
		WRAPPER(10);
176
		WRAPPER(11);
177
		WRAPPER(12);
178
		WRAPPER(13);
179
		WRAPPER(14);
180
		WRAPPER(15);