]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - lib_i386/bios.S
* Switch LWMON board default config from FRAM to EEPROM;
[karo-tx-uboot.git] / lib_i386 / bios.S
1 /*
2  * (C) Copyright 2002
3  * Daniel Engström, Omicron Ceti AB, daniel@omicron.se
4  * 
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 /*
25  * Based on msbios.c from rolo 1.6:
26  *----------------------------------------------------------------------
27  * (C) Copyright 2000
28  * Sysgo Real-Time Solutions GmbH
29  * Klein-Winternheim, Germany
30  *----------------------------------------------------------------------
31  */
32
33 /*
34  * During it's initialization phase, before switching to protected
35  * mode, the Linux Kernel makes a few BIOS calls. This won't work
36  * if the board does not have a BIOS.
37  *
38  * This is a very minimalisic BIOS that supplies just enough
39  * functionality to keep the Linux Kernel happy. It is NOT
40  * a general purpose replacement for a real BIOS !!
41  */
42
43 #define OFFS_ES      0
44 #define OFFS_GS      2
45 #define OFFS_DS      4
46 #define OFFS_DI      6
47 #define OFFS_SI      8
48 #define OFFS_BP      10
49 #define OFFS_SP      12
50 #define OFFS_BX      14
51 #define OFFS_DX      16
52 #define OFFS_CX      18
53 #define OFFS_AX      20
54 #define OFFS_VECTOR  22
55 #define OFFS_IP      24
56 #define OFFS_CS      26
57 #define OFFS_FLAGS   28
58
59 #define SEGMENT      0x40
60 #define STACK        0x800                      /* stack at 0x40:0x800 -> 0x800 */
61
62 .section .bios, "ax"
63 .code16
64 .org 0
65
66 .globl rm_int00
67 rm_int00:
68         pushw   $0
69         jmp     any_interrupt16
70 .globl rm_int01
71 rm_int01:
72         pushw   $1
73         jmp     any_interrupt16
74 .globl rm_int02
75 rm_int02:
76         pushw   $2
77         jmp     any_interrupt16
78 .globl rm_int03
79 rm_int03:
80         pushw   $3
81         jmp     any_interrupt16
82 .globl rm_int04
83 rm_int04:
84         pushw   $4
85         jmp     any_interrupt16
86 .globl rm_int05
87 rm_int05:
88         pushw   $5
89         jmp     any_interrupt16
90 .globl rm_int06
91 rm_int06:
92         pushw   $6
93         jmp     any_interrupt16
94 .globl rm_int07
95 rm_int07:
96         pushw   $7
97         jmp     any_interrupt16
98 .globl rm_int08
99 rm_int08:
100         pushw   $8
101         jmp     any_interrupt16
102 .globl rm_int09
103 rm_int09:
104         pushw   $9
105         jmp     any_interrupt16
106 .globl rm_int0a
107 rm_int0a:
108         pushw   $10
109         jmp     any_interrupt16
110 .globl rm_int0b
111 rm_int0b:
112         pushw   $11
113         jmp     any_interrupt16
114 .globl rm_int0c
115 rm_int0c:
116         pushw   $12
117         jmp     any_interrupt16
118 .globl rm_int0d
119 rm_int0d:
120         pushw   $13
121         jmp     any_interrupt16
122 .globl rm_int0e
123 rm_int0e:
124         pushw   $14
125         jmp     any_interrupt16
126 .globl rm_int0f
127 rm_int0f:
128         pushw   $15
129         jmp     any_interrupt16
130 .globl rm_int10
131 rm_int10:
132         pushw   $16
133         jmp     any_interrupt16
134 .globl rm_int11
135 rm_int11:
136         pushw   $17
137         jmp     any_interrupt16
138 .globl rm_int12
139 rm_int12:
140         pushw   $18
141         jmp     any_interrupt16
142 .globl rm_int13
143 rm_int13:
144         pushw   $19
145         jmp     any_interrupt16
146 .globl rm_int14
147 rm_int14:
148         pushw   $20
149         jmp     any_interrupt16
150 .globl rm_int15
151 rm_int15:
152         pushw   $21
153         jmp     any_interrupt16
154 .globl rm_int16
155 rm_int16:
156         pushw   $22
157         jmp     any_interrupt16
158 .globl rm_int17
159 rm_int17:
160         pushw   $23
161         jmp     any_interrupt16
162 .globl rm_int18
163 rm_int18:
164         pushw   $24
165         jmp     any_interrupt16
166 .globl rm_int19
167 rm_int19:
168         pushw   $25
169         jmp     any_interrupt16
170 .globl rm_int1a
171 rm_int1a:
172         pushw   $26
173         jmp     any_interrupt16
174 .globl rm_int1b
175 rm_int1b:
176         pushw   $27
177         jmp     any_interrupt16
178 .globl rm_int1c
179 rm_int1c:
180         pushw   $28
181         jmp     any_interrupt16
182 .globl rm_int1d
183 rm_int1d:
184         pushw   $29
185         jmp     any_interrupt16
186 .globl rm_int1e
187 rm_int1e:
188         pushw   $30
189         jmp     any_interrupt16
190 .globl rm_int1f
191 rm_int1f:
192         pushw   $31
193         jmp     any_interrupt16
194 .globl rm_def_int
195 rm_def_int:
196         iret
197
198  
199         /*
200          * All interrupt jumptable entries jump to here
201          * after pushing the interrupt vector number onto the
202          * stack.
203          */
204 any_interrupt16:
205         pusha                                   /* save general registers */
206         pushw   %ds                             /* save some segments     */
207         pushw   %gs
208         pushw   %es
209         pushw   %ss                             /* save callers stack segment .. */
210         popw    %gs                             /* ... in gs */
211         movw    $SEGMENT,%ax                    /* setup my segments */
212         movw    %ax,%ds
213         movw    %ax,%es
214         movw    %ax,%ss
215         movw    %sp,%bp
216         movw    $STACK,%sp                      /* setup BIOS stackpointer */
217
218 gs      movw    OFFS_VECTOR(%bp), %ax
219         cmpw    $0x10, %ax
220         je      Lint_10h         
221         cmpw    $0x11, %ax
222         je      Lint_11h
223         cmpw    $0x13, %ax
224         je      Lint_13h
225         cmpw    $0x15, %ax
226         je      Lint_15h
227         cmpw    $0x16, %ax
228         je      Lint_16h
229         movw    $0xffff, %ax
230         jmp     Lout
231 Lint_10h:                                       /* VGA BIOS services */
232         call    bios_10h
233         jmp     Lout
234 Lint_11h:       
235         call    bios_11h
236         jmp     Lout
237 Lint_13h:                                       /* BIOS disk services */
238         call    bios_13h
239         jmp     Lout
240 Lint_15h:                                       /* Misc. BIOS services */
241         call    bios_15h
242         jmp     Lout
243 Lint_16h:                                       /* keyboard services */
244         call    bios_16h
245         jmp     Lout
246 Lout:   
247         cmpw    $0, %ax
248         je      Lhandeled
249         
250         /* Insert code for unhandeled INTs here.
251          *
252          * ROLO prints a message to the console 
253          * (we could do that but then we're in 16bit mode
254          * so we'll have to get back into 32bit mode
255          * to use the console I/O routines (if we do this
256          * we shuls make int 0x10 and int 0x16 work as well))
257          */
258 Lhandeled:
259
260         pushw   %gs                             /* restore callers stack segment */
261         popw    %ss
262         movw    %bp,%sp                         /* restore stackpointer */
263
264         popw    %es                             /* restore segment selectors */
265         popw    %gs
266         popw    %ds
267         
268         popa                                    /* restore GP registers */
269         addw    $2,%sp                          /* dump vector number */
270         iret                                    /* return from interrupt */
271
272
273 /*
274  ************************************************************
275  * BIOS         interrupt 10h -- VGA services
276  ************************************************************
277  */
278 bios_10h:
279 gs      movw    OFFS_AX(%bp), %ax
280         shrw    $8, %ax
281         cmpw    $0x3, %ax
282         je      Lcur_pos
283         cmpw    $0xf, %ax
284         je      Lvid_state
285         cmpw    $0x12, %ax
286         je      Lvid_cfg
287         movw    $0xffff, %ax
288         ret
289 Lcur_pos:                                       /* Read Cursor Position and Size */
290 gs      movw    $0, OFFS_CX(%bp)
291 gs      movw    $0, OFFS_DX(%bp)
292         xorw    %ax, %ax
293         ret
294 Lvid_state:                                     /* Get Video State */
295 gs      movw    $(80 << 8|0x03), OFFS_AX(%bp)   /* 80 columns, 80x25, 16 colors */
296 gs      movw    $0, OFFS_BX(%bp)
297         xorw    %ax, %ax
298         ret
299 Lvid_cfg:       /* Video Subsystem Configuration (EGA/VGA) */
300 gs      movw    $0x10, OFFS_BX(%bp)             /* indicate CGA/MDA/HGA */
301         xorw    %ax, %ax
302         ret
303
304
305 /*
306  ************************************************************
307  * BIOS interrupt 11h -- Equipment determination
308  ************************************************************
309  */
310
311 bios_11h:
312         movw    bios_equipment, %ax
313 gs      movw    %ax, OFFS_AX(%bp)  
314         xorw    %ax, %ax
315         ret
316
317
318 /*
319  ************************************************************
320  * BIOS interrupt 13h -- Disk services
321  ************************************************************
322  */
323 bios_13h:
324 gs      movw    OFFS_AX(%bp), %ax
325         shrw    $8, %ax
326         cmpw    $0x15, %ax
327         je      Lfunc_15h
328         movw    $0xffff, %ax
329         ret
330 Lfunc_15h:      
331 gs      movw    OFFS_AX(%bp), %ax
332         andw    $0xff, %ax                      /* return AH=0->drive not present */
333 gs      movw    %ax, OFFS_AX(%bp)
334         xorw    %ax, %ax
335         ret
336         
337         
338
339 /*
340  ***********************************************************
341  * BIOS interrupt 15h -- Miscellaneous services
342  ***********************************************************
343  */
344 bios_15h:
345 gs      movw    OFFS_AX(%bp), %ax
346         shrw    $8, %ax
347         cmpw    $0xc0, %ax
348         je      Lfunc_c0h
349         cmpw    $0xe8, %ax
350         je      Lfunc_e8h
351         cmpw    $0x88, %ax
352         je      Lfunc_88h
353         movw    $0xffff, %ax
354         ret
355
356 Lfunc_c0h:                                      /* Return System Configuration Parameters (PS2 only) */
357 gs      movw    OFFS_FLAGS(%bp), %ax
358         orw     $1, %ax                         /* return carry -- function not supported */
359 gs      movw    %ax, OFFS_FLAGS(%bp)
360         xorw    %ax, %ax
361         ret
362         
363 Lfunc_e8h:
364 gs      movw    OFFS_AX(%bp), %ax
365         andw    $0xff, %ax
366         cmpw    $1, %ax
367         je      Lfunc_e801h
368 gs      movw    OFFS_FLAGS(%bp), %ax
369         orw     $1, %ax                         /* return carry -- function not supported */
370 gs      movw    %ax, OFFS_FLAGS(%bp)
371         xorw    %ax, %ax
372         ret
373         
374 Lfunc_e801h:                                    /* Get memory size for >64M Configurations */
375         movw    $ram_in_64kb_chunks, %ax
376         cmpw    $256, %ax
377         ja      Lmore_than_16mb
378         shlw    $6, %ax                         /* multiply by 64 */    
379 gs      movw    %ax, OFFS_AX(%bp)               /* return memory size in 1kb chunks in AX and CX */
380 gs      movw    %ax, OFFS_CX(%bp)
381         xorw    %ax, %ax
382 gs      movw    %ax, OFFS_BX(%bp)               /* set BX and DX to 0*/
383 gs      movw    %ax, OFFS_DX(%bp)       
384 gs      movw    OFFS_FLAGS(%bp), %ax
385         andw    $0xfffe, %ax                    /* clear carry -- function succeeded */
386 gs      movw    %ax, OFFS_FLAGS(%bp)
387         xorw    %ax, %ax
388         ret
389         
390 Lmore_than_16mb:
391         subw    $0x100, %ax                     /* subtract 16MB */     
392         
393 gs      movw    $0x3c00, OFFS_AX(%bp)           /* return 0x3c00 (16MB-384k) in AX and CX */
394 gs      movw    $0x3c00, OFFS_CX(%bp)
395 gs      movw    %ax, OFFS_BX(%bp)               /* set BX and DX to number of 64kb chunks - 256 */
396 gs      movw    %ax, OFFS_DX(%bp)       
397
398 gs      movw    OFFS_FLAGS(%bp), %ax
399         andw    $0xfffe, %ax                    /* clear carry -- function succeeded */
400 gs      movw    %ax, OFFS_FLAGS(%bp)
401         xorw    %ax, %ax
402         ret
403
404 Lfunc_88h:
405         movw    ram_in_64kb_chunks, %ax
406         subw    $16, %ax
407         shlw    $6, %ax
408         
409 gs      movw    %ax, OFFS_AX(%bp)               /* return number of kilobytes in ax */
410
411 gs      movw    OFFS_FLAGS(%bp), %ax
412         andw    $0xfffe, %ax                    /* clear carry -- function succeeded */
413 gs      movw    %ax, OFFS_FLAGS(%bp)
414
415         xorw    %ax, %ax
416         ret
417
418
419 /*
420  ************************************************************
421  * BIOS interrupt 16h -- keyboard services
422  ************************************************************
423  */
424 bios_16h:
425 gs      movw    OFFS_AX(%bp), %ax
426         shrw    $8, %ax
427         cmpw    $0x03, %ax
428         je      Lfunc_03h
429         movw    $0xffff, %ax
430         ret
431 Lfunc_03h:
432         xorw    %ax, %ax                        /* do nothing -- function not supported */
433         ret
434
435
436 .globl ram_in_64kb_chunks
437 ram_in_64kb_chunks:
438         .word   0
439
440 .globl bios_equipment
441 bios_equipment:
442         .word   0
443