Blame view

lib_i386/bios.S 9.51 KB
2262cfeef   wdenk   * Patch by Daniel...
1
2
3
  /*
   * (C) Copyright 2002
   * Daniel Engström, Omicron Ceti AB, daniel@omicron.se
8bde7f776   wdenk   * Code cleanup:
4
   *
2262cfeef   wdenk   * Patch by Daniel...
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
   * See file CREDITS for list of people who contributed to this
   * project.
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
   * published by the Free Software Foundation; either version 2 of
   * the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
   * MA 02111-1307 USA
   */
  
  /*
   * Based on msbios.c from rolo 1.6:
   *----------------------------------------------------------------------
   * (C) Copyright 2000
   * Sysgo Real-Time Solutions GmbH
   * Klein-Winternheim, Germany
   *----------------------------------------------------------------------
   */
7a8e9bed1   wdenk   * Patch by Marc S...
32
  #include "bios.h"
2262cfeef   wdenk   * Patch by Daniel...
33
34
35
36
37
38
39
40
41
  /*
   * During it's initialization phase, before switching to protected
   * mode, the Linux Kernel makes a few BIOS calls. This won't work
   * if the board does not have a BIOS.
   *
   * This is a very minimalisic BIOS that supplies just enough
   * functionality to keep the Linux Kernel happy. It is NOT
   * a general purpose replacement for a real BIOS !!
   */
2262cfeef   wdenk   * Patch by Daniel...
42
43
44
45
  
  .section .bios, "ax"
  .code16
  .org 0
8bde7f776   wdenk   * Code cleanup:
46
  	/* a call to f000:0 should warmboot */
7a8e9bed1   wdenk   * Patch by Marc S...
47
  	jmp	realmode_reset
8bde7f776   wdenk   * Code cleanup:
48

2262cfeef   wdenk   * Patch by Daniel...
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
  .globl rm_int00
  rm_int00:
  	pushw	$0
  	jmp	any_interrupt16
  .globl rm_int01
  rm_int01:
  	pushw	$1
  	jmp	any_interrupt16
  .globl rm_int02
  rm_int02:
  	pushw	$2
  	jmp	any_interrupt16
  .globl rm_int03
  rm_int03:
  	pushw	$3
  	jmp	any_interrupt16
  .globl rm_int04
  rm_int04:
  	pushw	$4
  	jmp	any_interrupt16
  .globl rm_int05
  rm_int05:
  	pushw	$5
  	jmp	any_interrupt16
  .globl rm_int06
  rm_int06:
  	pushw	$6
  	jmp	any_interrupt16
  .globl rm_int07
  rm_int07:
  	pushw	$7
  	jmp	any_interrupt16
  .globl rm_int08
  rm_int08:
  	pushw	$8
  	jmp	any_interrupt16
  .globl rm_int09
  rm_int09:
  	pushw	$9
  	jmp	any_interrupt16
  .globl rm_int0a
  rm_int0a:
  	pushw	$10
  	jmp	any_interrupt16
  .globl rm_int0b
  rm_int0b:
  	pushw	$11
  	jmp	any_interrupt16
  .globl rm_int0c
  rm_int0c:
  	pushw	$12
  	jmp	any_interrupt16
  .globl rm_int0d
  rm_int0d:
  	pushw	$13
  	jmp	any_interrupt16
  .globl rm_int0e
  rm_int0e:
  	pushw	$14
  	jmp	any_interrupt16
  .globl rm_int0f
  rm_int0f:
  	pushw	$15
  	jmp	any_interrupt16
  .globl rm_int10
  rm_int10:
  	pushw	$16
  	jmp	any_interrupt16
  .globl rm_int11
  rm_int11:
  	pushw	$17
  	jmp	any_interrupt16
  .globl rm_int12
  rm_int12:
  	pushw	$18
  	jmp	any_interrupt16
  .globl rm_int13
  rm_int13:
  	pushw	$19
  	jmp	any_interrupt16
  .globl rm_int14
  rm_int14:
  	pushw	$20
  	jmp	any_interrupt16
  .globl rm_int15
  rm_int15:
  	pushw	$21
  	jmp	any_interrupt16
  .globl rm_int16
  rm_int16:
  	pushw	$22
  	jmp	any_interrupt16
  .globl rm_int17
  rm_int17:
  	pushw	$23
  	jmp	any_interrupt16
  .globl rm_int18
  rm_int18:
  	pushw	$24
  	jmp	any_interrupt16
  .globl rm_int19
  rm_int19:
  	pushw	$25
  	jmp	any_interrupt16
  .globl rm_int1a
  rm_int1a:
  	pushw	$26
  	jmp	any_interrupt16
  .globl rm_int1b
  rm_int1b:
  	pushw	$27
  	jmp	any_interrupt16
  .globl rm_int1c
  rm_int1c:
  	pushw	$28
  	jmp	any_interrupt16
  .globl rm_int1d
  rm_int1d:
  	pushw	$29
  	jmp	any_interrupt16
  .globl rm_int1e
  rm_int1e:
  	pushw	$30
  	jmp	any_interrupt16
  .globl rm_int1f
  rm_int1f:
  	pushw	$31
  	jmp	any_interrupt16
  .globl rm_def_int
  rm_def_int:
  	iret
8bde7f776   wdenk   * Code cleanup:
180

2262cfeef   wdenk   * Patch by Daniel...
181
182
183
184
185
186
  	/*
  	 * All interrupt jumptable entries jump to here
  	 * after pushing the interrupt vector number onto the
  	 * stack.
  	 */
  any_interrupt16:
8bde7f776   wdenk   * Code cleanup:
187
  	MAKE_BIOS_STACK
2262cfeef   wdenk   * Patch by Daniel...
188
189
190
  
  gs	movw	OFFS_VECTOR(%bp), %ax
  	cmpw	$0x10, %ax
8bde7f776   wdenk   * Code cleanup:
191
  	je	Lint_10h
2262cfeef   wdenk   * Patch by Daniel...
192
193
  	cmpw	$0x11, %ax
  	je	Lint_11h
7a8e9bed1   wdenk   * Patch by Marc S...
194
195
  	cmpw	$0x12, %ax
  	je	Lint_12h
2262cfeef   wdenk   * Patch by Daniel...
196
197
198
199
200
201
  	cmpw	$0x13, %ax
  	je	Lint_13h
  	cmpw	$0x15, %ax
  	je	Lint_15h
  	cmpw	$0x16, %ax
  	je	Lint_16h
7a8e9bed1   wdenk   * Patch by Marc S...
202
203
  	cmpw	$0x1a, %ax
  	je	Lint_1ah
2262cfeef   wdenk   * Patch by Daniel...
204
205
206
207
208
  	movw	$0xffff, %ax
  	jmp	Lout
  Lint_10h:					/* VGA BIOS services */
  	call	bios_10h
  	jmp	Lout
8bde7f776   wdenk   * Code cleanup:
209
  Lint_11h:
2262cfeef   wdenk   * Patch by Daniel...
210
211
  	call	bios_11h
  	jmp	Lout
8bde7f776   wdenk   * Code cleanup:
212
  Lint_12h:
7a8e9bed1   wdenk   * Patch by Marc S...
213
214
  	call	bios_12h
  	jmp	Lout
2262cfeef   wdenk   * Patch by Daniel...
215
216
217
218
219
220
221
222
223
  Lint_13h:					/* BIOS disk services */
  	call	bios_13h
  	jmp	Lout
  Lint_15h:					/* Misc. BIOS services */
  	call	bios_15h
  	jmp	Lout
  Lint_16h:					/* keyboard services */
  	call	bios_16h
  	jmp	Lout
7a8e9bed1   wdenk   * Patch by Marc S...
224
225
226
  Lint_1ah:					/* PCI bios */
  	call	bios_1ah
  	jmp	Lout
8bde7f776   wdenk   * Code cleanup:
227
  Lout:
2262cfeef   wdenk   * Patch by Daniel...
228
229
  	cmpw	$0, %ax
  	je	Lhandeled
8bde7f776   wdenk   * Code cleanup:
230

2262cfeef   wdenk   * Patch by Daniel...
231
232
  	/* Insert code for unhandeled INTs here.
  	 *
8bde7f776   wdenk   * Code cleanup:
233
  	 * ROLO prints a message to the console
2262cfeef   wdenk   * Patch by Daniel...
234
235
236
237
238
239
  	 * (we could do that but then we're in 16bit mode
  	 * so we'll have to get back into 32bit mode
  	 * to use the console I/O routines (if we do this
  	 * we shuls make int 0x10 and int 0x16 work as well))
  	 */
  Lhandeled:
7a8e9bed1   wdenk   * Patch by Marc S...
240
  	RESTORE_CALLERS_STACK
2262cfeef   wdenk   * Patch by Daniel...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
  	addw	$2,%sp				/* dump vector number */
  	iret					/* return from interrupt */
  
  
  /*
   ************************************************************
   * BIOS 	interrupt 10h -- VGA services
   ************************************************************
   */
  bios_10h:
  gs	movw	OFFS_AX(%bp), %ax
  	shrw	$8, %ax
  	cmpw	$0x3, %ax
  	je	Lcur_pos
  	cmpw	$0xf, %ax
  	je	Lvid_state
  	cmpw	$0x12, %ax
  	je	Lvid_cfg
  	movw	$0xffff, %ax
  	ret
  Lcur_pos:					/* Read Cursor Position and Size */
  gs	movw	$0, OFFS_CX(%bp)
  gs	movw	$0, OFFS_DX(%bp)
  	xorw	%ax, %ax
  	ret
  Lvid_state:					/* Get Video State */
  gs	movw	$(80 << 8|0x03), OFFS_AX(%bp)	/* 80 columns, 80x25, 16 colors */
  gs	movw	$0, OFFS_BX(%bp)
  	xorw	%ax, %ax
  	ret
  Lvid_cfg:	/* Video Subsystem Configuration (EGA/VGA) */
  gs	movw	$0x10, OFFS_BX(%bp)		/* indicate CGA/MDA/HGA */
  	xorw	%ax, %ax
  	ret
  
  
  /*
   ************************************************************
   * BIOS interrupt 11h -- Equipment determination
   ************************************************************
   */
  
  bios_11h:
7a8e9bed1   wdenk   * Patch by Marc S...
284
  cs	movw	bios_equipment, %ax
8bde7f776   wdenk   * Code cleanup:
285
  gs	movw	%ax, OFFS_AX(%bp)
2262cfeef   wdenk   * Patch by Daniel...
286
287
288
289
290
291
  	xorw	%ax, %ax
  	ret
  
  
  /*
   ************************************************************
7a8e9bed1   wdenk   * Patch by Marc S...
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
   * BIOS 	interrupt 12h -- Get Memory Size
   ************************************************************
   */
  bios_12h:
  cs	movw	ram_in_64kb_chunks, %ax
  	cmpw	$0xa, %ax
  	ja	b12_more_than_640k
  	shlw	$6, %ax
  	jmp	b12_return
  b12_more_than_640k:
  	movw	$0x280, %ax
  b12_return:
  gs	movw	%ax, OFFS_AX(%bp)		/* return number of kilobytes in ax */
  
  gs	movw	OFFS_FLAGS(%bp), %ax
  	andw	$0xfffe, %ax			/* clear carry -- function succeeded */
  gs	movw	%ax, OFFS_FLAGS(%bp)
  
  	xorw	%ax, %ax
  	ret
  
  
  /*
   ************************************************************
2262cfeef   wdenk   * Patch by Daniel...
316
317
318
319
320
321
322
323
324
325
   * BIOS interrupt 13h -- Disk services
   ************************************************************
   */
  bios_13h:
  gs	movw	OFFS_AX(%bp), %ax
  	shrw	$8, %ax
  	cmpw	$0x15, %ax
  	je	Lfunc_15h
  	movw	$0xffff, %ax
  	ret
8bde7f776   wdenk   * Code cleanup:
326
  Lfunc_15h:
2262cfeef   wdenk   * Patch by Daniel...
327
328
329
330
331
  gs	movw	OFFS_AX(%bp), %ax
  	andw	$0xff, %ax			/* return AH=0->drive not present */
  gs	movw	%ax, OFFS_AX(%bp)
  	xorw	%ax, %ax
  	ret
8bde7f776   wdenk   * Code cleanup:
332

2262cfeef   wdenk   * Patch by Daniel...
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
  
  /*
   ***********************************************************
   * BIOS interrupt 15h -- Miscellaneous services
   ***********************************************************
   */
  bios_15h:
  gs	movw	OFFS_AX(%bp), %ax
  	shrw	$8, %ax
  	cmpw	$0xc0, %ax
  	je	Lfunc_c0h
  	cmpw	$0xe8, %ax
  	je	Lfunc_e8h
  	cmpw	$0x88, %ax
  	je	Lfunc_88h
  	movw	$0xffff, %ax
  	ret
  
  Lfunc_c0h: 					/* Return System Configuration Parameters (PS2 only) */
  gs	movw	OFFS_FLAGS(%bp), %ax
  	orw	$1, %ax				/* return carry -- function not supported */
  gs	movw	%ax, OFFS_FLAGS(%bp)
  	xorw	%ax, %ax
  	ret
8bde7f776   wdenk   * Code cleanup:
357

2262cfeef   wdenk   * Patch by Daniel...
358
359
360
361
362
363
364
365
366
367
  Lfunc_e8h:
  gs	movw	OFFS_AX(%bp), %ax
  	andw	$0xff, %ax
  	cmpw	$1, %ax
  	je	Lfunc_e801h
  gs	movw	OFFS_FLAGS(%bp), %ax
  	orw	$1, %ax				/* return carry -- function not supported */
  gs	movw	%ax, OFFS_FLAGS(%bp)
  	xorw	%ax, %ax
  	ret
8bde7f776   wdenk   * Code cleanup:
368

2262cfeef   wdenk   * Patch by Daniel...
369
  Lfunc_e801h:					/* Get memory size for >64M Configurations */
7a8e9bed1   wdenk   * Patch by Marc S...
370
371
372
373
374
  cs	movw	ram_in_64kb_chunks, %ax
  	cmpw	$0x100, %ax
  	ja	e801_more_than_16mb
  	shlw	$6, %ax				/* multiply by 64 */
  	subw	$0x400, %ax			/* 1st meg does not count */
8bde7f776   wdenk   * Code cleanup:
375

7a8e9bed1   wdenk   * Patch by Marc S...
376
  gs	movw	%ax, OFFS_AX(%bp)   		/* return memory size between 1M and 16M in 1kb chunks in AX and CX */
2262cfeef   wdenk   * Patch by Daniel...
377
  gs	movw	%ax, OFFS_CX(%bp)
7a8e9bed1   wdenk   * Patch by Marc S...
378
  gs	movw	$0, OFFS_BX(%bp)		/* set BX and DX to 0*/
8bde7f776   wdenk   * Code cleanup:
379
  gs	movw	$0, OFFS_DX(%bp)
2262cfeef   wdenk   * Patch by Daniel...
380
381
382
383
384
  gs	movw	OFFS_FLAGS(%bp), %ax
  	andw	$0xfffe, %ax			/* clear carry -- function succeeded */
  gs	movw	%ax, OFFS_FLAGS(%bp)
  	xorw	%ax, %ax
  	ret
8bde7f776   wdenk   * Code cleanup:
385

7a8e9bed1   wdenk   * Patch by Marc S...
386
  e801_more_than_16mb:
8bde7f776   wdenk   * Code cleanup:
387
  	subw	$0x100, %ax			/* subtract 16MB */
7a8e9bed1   wdenk   * Patch by Marc S...
388
  gs	movw	$0x3c00, OFFS_AX(%bp)		/* return 0x3c00 (16MB-1MB) in AX and CX */
2262cfeef   wdenk   * Patch by Daniel...
389
  gs	movw	$0x3c00, OFFS_CX(%bp)
7a8e9bed1   wdenk   * Patch by Marc S...
390
  gs	movw	%ax, OFFS_BX(%bp)		/* set BX and DX to number of 64kb chunks above 16MB */
8bde7f776   wdenk   * Code cleanup:
391
  gs	movw	%ax, OFFS_DX(%bp)
2262cfeef   wdenk   * Patch by Daniel...
392
393
394
395
396
397
398
399
  
  gs	movw	OFFS_FLAGS(%bp), %ax
  	andw	$0xfffe, %ax			/* clear carry -- function succeeded */
  gs	movw	%ax, OFFS_FLAGS(%bp)
  	xorw	%ax, %ax
  	ret
  
  Lfunc_88h:
7a8e9bed1   wdenk   * Patch by Marc S...
400
401
402
403
404
  cs	movw	ram_in_64kb_chunks, %ax
  	cmpw	$0x100, %ax
  	jna	b88_not_more_than16
  	movw	$0x100, %ax
  b88_not_more_than16:
2262cfeef   wdenk   * Patch by Daniel...
405
  	shlw	$6, %ax
7a8e9bed1   wdenk   * Patch by Marc S...
406
  	subw	$0x400, %ax			/* 1st meg does not count */
8bde7f776   wdenk   * Code cleanup:
407

7a8e9bed1   wdenk   * Patch by Marc S...
408
  gs	movw	%ax, OFFS_AX(%bp)		/* return number of kilobytes between 16MB and 16MB in ax */
2262cfeef   wdenk   * Patch by Daniel...
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
  
  gs	movw	OFFS_FLAGS(%bp), %ax
  	andw	$0xfffe, %ax			/* clear carry -- function succeeded */
  gs	movw	%ax, OFFS_FLAGS(%bp)
  
  	xorw	%ax, %ax
  	ret
  
  
  /*
   ************************************************************
   * BIOS interrupt 16h -- keyboard services
   ************************************************************
   */
  bios_16h:
  gs	movw	OFFS_AX(%bp), %ax
  	shrw	$8, %ax
  	cmpw	$0x03, %ax
  	je	Lfunc_03h
  	movw	$0xffff, %ax
  	ret
  Lfunc_03h:
  	xorw	%ax, %ax			/* do nothing -- function not supported */
  	ret
7a8e9bed1   wdenk   * Patch by Marc S...
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
  /*
   ************************************************************
   * BIOS interrupt 1ah -- PCI bios
   ************************************************************
   */
  bios_1ah:
  gs	movw	OFFS_AX(%bp), %ax
  	cmpb	$0xb1, %ah
  	je	Lfunc_b1h
  	movw	$0xffff, %ax
  	ret
  Lfunc_b1h:
  	call	realmode_pci_bios
  	xorw	%ax, %ax			/* do nothing -- function not supported */
  	ret
2262cfeef   wdenk   * Patch by Daniel...
448
449
450
451
452
453
454
455
  
  .globl ram_in_64kb_chunks
  ram_in_64kb_chunks:
  	.word 	0
  
  .globl bios_equipment
  bios_equipment:
  	.word 	0