forked from fysnet/i440fx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpic.asm
243 lines (216 loc) · 8.93 KB
/
pic.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
comment |*******************************************************************
* Copyright (c) 1984-2024 Forever Young Software Benjamin David Lunt *
* *
* i440FX BIOS ROM v1.0 *
* FILE: pic.asm *
* *
* This code is freeware, not public domain. Please use respectfully. *
* *
* You may: *
* - use this code for learning purposes only. *
* - use this code in your own Operating System development. *
* - distribute any code that you produce pertaining to this code *
* as long as it is for learning purposes only, not for profit, *
* and you give credit where credit is due. *
* *
* You may NOT: *
* - distribute this code for any purpose other than listed above. *
* - distribute this code for profit. *
* *
* You MUST: *
* - include this whole comment block at the top of this file. *
* - include contact information to where the original source is located. *
* https://github.com/fysnet/i440fx *
* *
* DESCRIPTION: *
* pic include file *
* *
* BUILT WITH: NewBasic Assembler *
* http://www.fysnet/newbasic.htm *
* NBASM ver 00.27.15 *
* Command line: nbasm i440fx /z<enter> *
* *
* Last Updated: 8 Dec 2024 *
* *
****************************************************************************
* Notes: *
* *
* Master PIC (08 hex) *
* IRQ 0 – (int 08) system timer (cannot be changed) *
* IRQ 1 – (int 09) keyboard on PS/2 port (cannot be changed) *
* IRQ 2 – cascaded signals from IRQs 8–15 *
* IRQ 3 – (int 0B) serial port 2 (shared with serial port 4, if present) *
* IRQ 4 – (int 0C) serial port 1 (shared with serial port 3, if present) *
* IRQ 5 – (int 0D) parallel port 3 or sound card *
* IRQ 6 – (int 0E) floppy disk controller *
* IRQ 7 – (int 0F) parallel port 1 (shared with port 2, if present) *
* *
* Slave PIC (70 hex) *
* IRQ 8 – (int 70) real-time clock (RTC) *
* IRQ 9 – (int 71) ACPI or device configured to use IRQ 2 will use IRQ 9 *
* IRQ 10 – (int 72) *
* IRQ 11 – (int 73) *
* IRQ 12 – (int 74) mouse on PS/2 port *
* IRQ 13 – (int 75) CPU co-processor *
* IRQ 14 – (int 76) primary ATA channel *
* IRQ 15 – (int 77) secondary ATA channel *
* *
***************************************************************************|
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; initialize the PIC/APIC
; we assume no APIC at this time. Later (smp_probe)
; detects the APIC and if found, initializes it and
; disables this.
; on entry:
; nothing
; on return
; nothing
; destroys none
init_pic proc near uses ax
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; send initialization commands
; ICW1
mov al,0x11 ; initialize through ICW4
out PORT_PIC_MASTER_CMD,al
out PORT_PIC_SLAVE_CMD,al
; ICW2
mov al,0x08 ; irq 0 -> 7 to start at IDT 0x08
out PORT_PIC_MASTER_DATA,al
mov al,0x70 ; irq 8 -> 15 to start at IDT 0x70
out PORT_PIC_SLAVE_DATA,al
; ICW3
mov al,0x04 ; connect the master to the slave
out PORT_PIC_MASTER_DATA,al
mov al,0x02
out PORT_PIC_SLAVE_DATA,al
; ICW4
mov al,0x01 ; 80x86/88 mode
out PORT_PIC_MASTER_DATA,al
out PORT_PIC_SLAVE_DATA,al
; set the masks
mov al,0xB8
out PORT_PIC_MASTER_DATA,al ; master pic: unmask IRQ 0, 1, 2, 6
mov al,0x8F
out PORT_PIC_SLAVE_DATA,al ; slave pic: unmask IRQ 12, 13, 14
; clear any that just fired
call eoi_both_pic
ret
init_pic endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; acknowledge master pic ioe
; on entry:
; nothing
; on return
; nothing
; destroys nothing
eoi_master_pic proc near uses ax
mov al,0x20
out PORT_PIC_MASTER_CMD,al
ret
eoi_master_pic endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; acknowledge slave pic ioe
; on entry:
; nothing
; on return
; nothing
; destroys nothing
; acknowledges the master too
eoi_slave_pic proc near uses ax
mov al,0x20
out PORT_PIC_SLAVE_CMD,al
ret
eoi_slave_pic endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; acknowledge both the master and the slave pic ioe
; on entry:
; nothing
; on return
; nothing
; destroys nothing
; acknowledges the master too
eoi_both_pic proc near uses ax
mov al,0x20
out PORT_PIC_SLAVE_CMD,al
out PORT_PIC_MASTER_CMD,al
ret
eoi_both_pic endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; get interrupt vector number
; on entry:
; al = irq
; on return
; al = intterupt vector number
; destroys nothing
; ax = irq 0->7 = int 08h -> 0Fh
; ax = irq 8->F = int 70h -> 77h
pic_get_int_vector proc near
cmp al,7
ja short @f
; al = 0 -> 7
; simply add 8
add al,8
ret
@@: ; al = 8 -> F
; add 0x70 - 8
add al,(0x70 - 8)
ret
pic_get_int_vector endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; mask an irq
; on entry:
; al = irq
; on return
; nothing
; destroys nothing
pic_mask proc near uses ax cx
; get mask bit
mov cl,al
and cl,7
mov ah,1
shl ah,cl
cmp al,7
ja short @f
; mask the irq
in al,PORT_PIC_MASTER_DATA
or al,ah
out PORT_PIC_MASTER_DATA,al
ret
@@: ; mask the irq
in al,PORT_PIC_SLAVE_DATA
or al,ah
out PORT_PIC_SLAVE_DATA,al
ret
pic_mask endp
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; unmask an irq
; on entry:
; al = irq
; on return
; nothing
; destroys nothing
pic_unmask proc near uses ax cx
; get mask bit
mov cl,al
and cl,7
mov ah,1
shl ah,cl
not ah
cmp al,7
ja short @f
; unmask the irq
in al,PORT_PIC_MASTER_DATA
and al,ah
out PORT_PIC_MASTER_DATA,al
ret
@@: ; unmask the irq
in al,PORT_PIC_SLAVE_DATA
and al,ah
out PORT_PIC_SLAVE_DATA,al
; make sure bit 2 (chain bit) is unmasked as well
in al,PORT_PIC_MASTER_DATA
and al,(~(1<<2))
out PORT_PIC_MASTER_DATA,al
ret
pic_unmask endp
.end