|
|
1.1 root 1: !
2: ! setup.s (C) 1991 Linus Torvalds
3: !
4: ! setup.s is responsible for getting the system data from the BIOS,
5: ! and putting them into the appropriate places in system memory.
6: ! both setup.s and system has been loaded by the bootblock.
7: !
8: ! This code asks the bios for memory/disk/other parameters, and
9: ! puts them in a "safe" place: 0x90000-0x901FF, ie where the
10: ! boot-block used to be. It is then up to the protected mode
11: ! system to read them from there before the area is overwritten
12: ! for buffer-blocks.
13: !
14:
15: ! NOTE! These had better be the same as in bootsect.s!
16: #include <linux/config.h>
17:
18: INITSEG = DEF_INITSEG ! we move boot here - out of the way
19: SYSSEG = DEF_SYSSEG ! system loaded at 0x10000 (65536).
20: SETUPSEG = DEF_SETUPSEG ! this is the current segment
21:
22: .globl begtext, begdata, begbss, endtext, enddata, endbss
23: .text
24: begtext:
25: .data
26: begdata:
27: .bss
28: begbss:
29: .text
30:
31: entry start
32: start:
33:
34: ! ok, the read went well so we get current cursor position and save it for
35: ! posterity.
36:
37: mov ax,#INITSEG ! this is done in bootsect already, but...
38: mov ds,ax
39:
40: ! Get memory size (extended mem, kB)
41:
42: mov ah,#0x88
43: int 0x15
44: mov [2],ax
45:
46: ! check for EGA/VGA and some config parameters
47:
48: mov ah,#0x12
49: mov bl,#0x10
50: int 0x10
51: mov [8],ax
52: mov [10],bx
53: mov [12],cx
54: mov ax,#0x5019
55: cmp bl,#0x10
56: je novga
57: call chsvga
58: novga: mov [14],ax
59: mov ah,#0x03 ! read cursor pos
60: xor bh,bh
61: int 0x10 ! save it in known place, con_init fetches
62: mov [0],dx ! it from 0x90000.
63:
64: ! Get video-card data:
65:
66: mov ah,#0x0f
67: int 0x10
68: mov [4],bx ! bh = display page
69: mov [6],ax ! al = video mode, ah = window width
70:
71: ! Get hd0 data
72:
73: mov ax,#0x0000
74: mov ds,ax
75: lds si,[4*0x41]
76: mov ax,#INITSEG
77: mov es,ax
78: mov di,#0x0080
79: mov cx,#0x10
1.1.1.2 ! root 80: cld
1.1 root 81: rep
82: movsb
83:
84: ! Get hd1 data
85:
86: mov ax,#0x0000
87: mov ds,ax
88: lds si,[4*0x46]
89: mov ax,#INITSEG
90: mov es,ax
91: mov di,#0x0090
92: mov cx,#0x10
1.1.1.2 ! root 93: cld
1.1 root 94: rep
95: movsb
96:
97: ! Check that there IS a hd1 :-)
98:
99: mov ax,#0x01500
100: mov dl,#0x81
101: int 0x13
102: jc no_disk1
103: cmp ah,#3
104: je is_disk1
105: no_disk1:
106: mov ax,#INITSEG
107: mov es,ax
108: mov di,#0x0090
109: mov cx,#0x10
110: mov ax,#0x00
1.1.1.2 ! root 111: cld
1.1 root 112: rep
113: stosb
114: is_disk1:
115:
116: ! now we want to move to protected mode ...
117:
118: cli ! no interrupts allowed !
119:
120: ! first we move the system to it's rightful place
121:
122: mov ax,#0x0000
123: cld ! 'direction'=0, movs moves forward
124: do_move:
125: mov es,ax ! destination segment
126: add ax,#0x1000
127: cmp ax,#0x9000
128: jz end_move
129: mov ds,ax ! source segment
130: sub di,di
131: sub si,si
132: mov cx,#0x8000
133: rep
134: movsw
135: jmp do_move
136:
137: ! then we load the segment descriptors
138:
139: end_move:
140: mov ax,#SETUPSEG ! right, forgot this at first. didn't work :-)
141: mov ds,ax
142: lidt idt_48 ! load idt with 0,0
143: lgdt gdt_48 ! load gdt with whatever appropriate
144:
145: ! that was painless, now we enable A20
146:
147: call empty_8042
148: mov al,#0xD1 ! command write
149: out #0x64,al
150: call empty_8042
151: mov al,#0xDF ! A20 on
152: out #0x60,al
153: call empty_8042
154:
155: ! well, that went ok, I hope. Now we have to reprogram the interrupts :-(
156: ! we put them right after the intel-reserved hardware interrupts, at
157: ! int 0x20-0x2F. There they won't mess up anything. Sadly IBM really
158: ! messed this up with the original PC, and they haven't been able to
159: ! rectify it afterwards. Thus the bios puts interrupts at 0x08-0x0f,
160: ! which is used for the internal hardware interrupts as well. We just
161: ! have to reprogram the 8259's, and it isn't fun.
162:
163: mov al,#0x11 ! initialization sequence
164: out #0x20,al ! send it to 8259A-1
165: .word 0x00eb,0x00eb ! jmp $+2, jmp $+2
166: out #0xA0,al ! and to 8259A-2
167: .word 0x00eb,0x00eb
168: mov al,#0x20 ! start of hardware int's (0x20)
169: out #0x21,al
170: .word 0x00eb,0x00eb
171: mov al,#0x28 ! start of hardware int's 2 (0x28)
172: out #0xA1,al
173: .word 0x00eb,0x00eb
174: mov al,#0x04 ! 8259-1 is master
175: out #0x21,al
176: .word 0x00eb,0x00eb
177: mov al,#0x02 ! 8259-2 is slave
178: out #0xA1,al
179: .word 0x00eb,0x00eb
180: mov al,#0x01 ! 8086 mode for both
181: out #0x21,al
182: .word 0x00eb,0x00eb
183: out #0xA1,al
184: .word 0x00eb,0x00eb
185: mov al,#0xFF ! mask off all interrupts for now
186: out #0x21,al
187: .word 0x00eb,0x00eb
188: out #0xA1,al
189:
190: ! well, that certainly wasn't fun :-(. Hopefully it works, and we don't
191: ! need no steenking BIOS anyway (except for the initial loading :-).
192: ! The BIOS-routine wants lots of unnecessary data, and it's less
193: ! "interesting" anyway. This is how REAL programmers do it.
194: !
195: ! Well, now's the time to actually move into protected mode. To make
196: ! things as simple as possible, we do no register set-up or anything,
197: ! we let the gnu-compiled 32-bit programs do that. We just jump to
198: ! absolute address 0x00000, in 32-bit protected mode.
199:
200: mov ax,#0x0001 ! protected mode (PE) bit
201: lmsw ax ! This is it!
202: jmpi 0,8 ! jmp offset 0 of segment 8 (cs)
203:
204: ! This routine checks that the keyboard command queue is empty
205: ! No timeout is used - if this hangs there is something wrong with
206: ! the machine, and we probably couldn't proceed anyway.
207: empty_8042:
208: .word 0x00eb,0x00eb
209: in al,#0x64 ! 8042 status port
210: test al,#2 ! is input buffer full?
211: jnz empty_8042 ! yes - loop
212: ret
213:
214: ! Routine trying to recognize type of SVGA-board present (if any)
215: ! and if it recognize one gives the choices of resolution it offers.
216: ! If one is found the resolution chosen is given by al,ah (rows,cols).
217:
218: chsvga: cld
219: push ds
220: push cs
221: pop ds
222: mov ax,#0xc000
223: mov es,ax
224: lea si,msg1
225: call prtstr
1.1.1.2 ! root 226: flush: in al,#0x60 ! Flush the keyboard buffer
! 227: cmp al,#0x82
! 228: jb nokey
! 229: jmp flush
1.1 root 230: nokey: in al,#0x60
231: cmp al,#0x82
232: jb nokey
233: cmp al,#0xe0
234: ja nokey
235: cmp al,#0x9c
236: je svga
237: mov ax,#0x5019
238: pop ds
239: ret
1.1.1.2 ! root 240: svga: cld
! 241: lea si,idati ! Check ATI 'clues'
1.1 root 242: mov di,#0x31
243: mov cx,#0x09
244: repe
245: cmpsb
246: jne noati
247: lea si,dscati
248: lea di,moati
249: lea cx,selmod
250: jmp cx
251: noati: mov ax,#0x200f ! Check Ahead 'clues'
252: mov dx,#0x3ce
253: out dx,ax
254: inc dx
255: in al,dx
256: cmp al,#0x20
257: je isahed
258: cmp al,#0x21
259: jne noahed
260: isahed: lea si,dscahead
261: lea di,moahead
262: lea cx,selmod
263: jmp cx
264: noahed: mov dx,#0x3c3 ! Check Chips & Tech. 'clues'
265: in al,dx
266: or al,#0x10
267: out dx,al
268: mov dx,#0x104
269: in al,dx
270: mov bl,al
271: mov dx,#0x3c3
272: in al,dx
273: and al,#0xef
274: out dx,al
275: cmp bl,[idcandt]
276: jne nocant
277: lea si,dsccandt
278: lea di,mocandt
279: lea cx,selmod
280: jmp cx
281: nocant: mov dx,#0x3d4 ! Check Cirrus 'clues'
282: mov al,#0x0c
283: out dx,al
284: inc dx
285: in al,dx
286: mov bl,al
287: xor al,al
288: out dx,al
289: dec dx
290: mov al,#0x1f
291: out dx,al
292: inc dx
293: in al,dx
294: mov bh,al
295: xor ah,ah
296: shl al,#4
297: mov cx,ax
298: mov al,bh
299: shr al,#4
300: add cx,ax
301: shl cx,#8
302: add cx,#6
303: mov ax,cx
304: mov dx,#0x3c4
305: out dx,ax
306: inc dx
307: in al,dx
308: and al,al
309: jnz nocirr
310: mov al,bh
311: out dx,al
312: in al,dx
313: cmp al,#0x01
314: jne nocirr
315: call rst3d4
316: lea si,dsccirrus
317: lea di,mocirrus
318: lea cx,selmod
319: jmp cx
320: rst3d4: mov dx,#0x3d4
321: mov al,bl
322: xor ah,ah
323: shl ax,#8
324: add ax,#0x0c
325: out dx,ax
326: ret
327: nocirr: call rst3d4 ! Check Everex 'clues'
328: mov ax,#0x7000
329: xor bx,bx
330: int 0x10
331: cmp al,#0x70
332: jne noevrx
333: shr dx,#4
334: cmp dx,#0x678
335: je istrid
336: cmp dx,#0x236
337: je istrid
338: lea si,dsceverex
339: lea di,moeverex
340: lea cx,selmod
341: jmp cx
342: istrid: lea cx,ev2tri
343: jmp cx
344: noevrx: lea si,idgenoa ! Check Genoa 'clues'
345: xor ax,ax
346: seg es
347: mov al,[0x37]
348: mov di,ax
349: mov cx,#0x04
350: dec si
351: dec di
352: l1: inc si
353: inc di
354: mov al,(si)
355: seg es
356: and al,(di)
357: cmp al,(si)
358: loope l1
359: cmp cx,#0x00
360: jne nogen
361: lea si,dscgenoa
362: lea di,mogenoa
363: lea cx,selmod
364: jmp cx
1.1.1.2 ! root 365: nogen: cld
! 366: lea si,idparadise ! Check Paradise 'clues'
1.1 root 367: mov di,#0x7d
368: mov cx,#0x04
369: repe
370: cmpsb
371: jne nopara
372: lea si,dscparadise
373: lea di,moparadise
374: lea cx,selmod
375: jmp cx
376: nopara: mov dx,#0x3c4 ! Check Trident 'clues'
377: mov al,#0x0e
378: out dx,al
379: inc dx
380: in al,dx
381: xchg ah,al
382: mov al,#0x00
383: out dx,al
384: in al,dx
385: xchg al,ah
386: mov bl,al ! Strange thing ... in the book this wasn't
387: and bl,#0x02 ! necessary but it worked on my card which
388: jz setb2 ! is a trident. Without it the screen goes
389: and al,#0xfd ! blurred ...
390: jmp clrb2 !
391: setb2: or al,#0x02 !
392: clrb2: out dx,al
393: and ah,#0x0f
394: cmp ah,#0x02
395: jne notrid
396: ev2tri: lea si,dsctrident
397: lea di,motrident
398: lea cx,selmod
399: jmp cx
400: notrid: mov dx,#0x3cd ! Check Tseng 'clues'
401: in al,dx ! Could things be this simple ! :-)
402: mov bl,al
403: mov al,#0x55
404: out dx,al
405: in al,dx
406: mov ah,al
407: mov al,bl
408: out dx,al
409: cmp ah,#0x55
410: jne notsen
411: lea si,dsctseng
412: lea di,motseng
413: lea cx,selmod
414: jmp cx
415: notsen: mov dx,#0x3cc ! Check Video7 'clues'
416: in al,dx
417: mov dx,#0x3b4
418: and al,#0x01
419: jz even7
420: mov dx,#0x3d4
421: even7: mov al,#0x0c
422: out dx,al
423: inc dx
424: in al,dx
425: mov bl,al
426: mov al,#0x55
427: out dx,al
428: in al,dx
429: dec dx
430: mov al,#0x1f
431: out dx,al
432: inc dx
433: in al,dx
434: mov bh,al
435: dec dx
436: mov al,#0x0c
437: out dx,al
438: inc dx
439: mov al,bl
440: out dx,al
441: mov al,#0x55
442: xor al,#0xea
443: cmp al,bh
444: jne novid7
445: lea si,dscvideo7
446: lea di,movideo7
447: selmod: push si
448: lea si,msg2
449: call prtstr
450: xor cx,cx
451: mov cl,(di)
452: pop si
453: push si
454: push cx
455: tbl: pop bx
456: push bx
457: mov al,bl
458: sub al,cl
459: call dprnt
460: call spcing
461: lodsw
462: xchg al,ah
463: call dprnt
464: xchg ah,al
465: push ax
466: mov al,#0x78
467: call prnt1
468: pop ax
469: call dprnt
470: call docr
471: loop tbl
472: pop cx
473: call docr
474: lea si,msg3
475: call prtstr
476: pop si
477: add cl,#0x80
478: nonum: in al,#0x60 ! Quick and dirty...
479: cmp al,#0x82
480: jb nonum
481: cmp al,#0x8b
482: je zero
483: cmp al,cl
484: ja nonum
485: jmp nozero
486: zero: sub al,#0x0a
487: nozero: sub al,#0x80
488: dec al
489: xor ah,ah
490: add di,ax
491: inc di
492: push ax
493: mov al,(di)
494: int 0x10
495: pop ax
496: shl ax,#1
497: add si,ax
498: lodsw
499: pop ds
500: ret
501: novid7: pop ds ! Here could be code to support standard 80x50,80x30
502: mov ax,#0x5019
503: ret
504:
505: ! Routine that 'tabs' to next col.
506:
507: spcing: mov al,#0x2e
508: call prnt1
509: mov al,#0x20
510: call prnt1
511: mov al,#0x20
512: call prnt1
513: mov al,#0x20
514: call prnt1
515: mov al,#0x20
516: call prnt1
517: ret
518:
519: ! Routine to print asciiz-string at DS:SI
520:
521: prtstr: lodsb
522: and al,al
523: jz fin
524: call prnt1
525: jmp prtstr
526: fin: ret
527:
528: ! Routine to print a decimal value on screen, the value to be
529: ! printed is put in al (i.e 0-255).
530:
531: dprnt: push ax
532: push cx
533: mov ah,#0x00
534: mov cl,#0x0a
535: idiv cl
536: cmp al,#0x09
537: jbe lt100
538: call dprnt
539: jmp skip10
540: lt100: add al,#0x30
541: call prnt1
542: skip10: mov al,ah
543: add al,#0x30
544: call prnt1
545: pop cx
546: pop ax
547: ret
548:
549: ! Part of above routine, this one just prints ascii al
550:
551: prnt1: push ax
552: push cx
553: mov bh,#0x00
554: mov cx,#0x01
555: mov ah,#0x0e
556: int 0x10
557: pop cx
558: pop ax
559: ret
560:
561: ! Prints <CR> + <LF>
562:
563: docr: push ax
564: push cx
565: mov bh,#0x00
566: mov ah,#0x0e
567: mov al,#0x0a
568: mov cx,#0x01
569: int 0x10
570: mov al,#0x0d
571: int 0x10
572: pop cx
573: pop ax
574: ret
575:
576: gdt:
577: .word 0,0,0,0 ! dummy
578:
579: .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb)
580: .word 0x0000 ! base address=0
581: .word 0x9A00 ! code read/exec
582: .word 0x00C0 ! granularity=4096, 386
583:
584: .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb)
585: .word 0x0000 ! base address=0
586: .word 0x9200 ! data read/write
587: .word 0x00C0 ! granularity=4096, 386
588:
589: idt_48:
590: .word 0 ! idt limit=0
591: .word 0,0 ! idt base=0L
592:
593: gdt_48:
594: .word 0x800 ! gdt limit=2048, 256 GDT entries
595: .word 512+gdt,0x9 ! gdt base = 0X9xxxx
596:
597: msg1: .ascii "Press <RETURN> to see SVGA-modes available or any other key to continue."
598: db 0x0d, 0x0a, 0x0a, 0x00
599: msg2: .ascii "Mode: COLSxROWS:"
600: db 0x0d, 0x0a, 0x0a, 0x00
601: msg3: .ascii "Choose mode by pressing the corresponding number."
602: db 0x0d, 0x0a, 0x00
603:
604: idati: .ascii "761295520"
605: idcandt: .byte 0xa5
606: idgenoa: .byte 0x77, 0x00, 0x66, 0x99
607: idparadise: .ascii "VGA="
608:
609: ! Manufacturer: Numofmodes: Mode:
610:
611: moati: .byte 0x02, 0x23, 0x33
612: moahead: .byte 0x05, 0x22, 0x23, 0x24, 0x2f, 0x34
613: mocandt: .byte 0x02, 0x60, 0x61
614: mocirrus: .byte 0x04, 0x1f, 0x20, 0x22, 0x31
615: moeverex: .byte 0x0a, 0x03, 0x04, 0x07, 0x08, 0x0a, 0x0b, 0x16, 0x18, 0x21, 0x40
616: mogenoa: .byte 0x0a, 0x58, 0x5a, 0x60, 0x61, 0x62, 0x63, 0x64, 0x72, 0x74, 0x78
617: moparadise: .byte 0x02, 0x55, 0x54
618: motrident: .byte 0x07, 0x50, 0x51, 0x52, 0x57, 0x58, 0x59, 0x5a
619: motseng: .byte 0x05, 0x26, 0x2a, 0x23, 0x24, 0x22
620: movideo7: .byte 0x06, 0x40, 0x43, 0x44, 0x41, 0x42, 0x45
621:
622: ! msb = Cols lsb = Rows:
623:
624: dscati: .word 0x8419, 0x842c
625: dscahead: .word 0x842c, 0x8419, 0x841c, 0xa032, 0x5042
626: dsccandt: .word 0x8419, 0x8432
627: dsccirrus: .word 0x8419, 0x842c, 0x841e, 0x6425
628: dsceverex: .word 0x5022, 0x503c, 0x642b, 0x644b, 0x8419, 0x842c, 0x501e, 0x641b, 0xa040, 0x841e
629: dscgenoa: .word 0x5020, 0x642a, 0x8419, 0x841d, 0x8420, 0x842c, 0x843c, 0x503c, 0x5042, 0x644b
630: dscparadise: .word 0x8419, 0x842b
631: dsctrident: .word 0x501e, 0x502b, 0x503c, 0x8419, 0x841e, 0x842b, 0x843c
632: dsctseng: .word 0x503c, 0x6428, 0x8419, 0x841c, 0x842c
633: dscvideo7: .word 0x502b, 0x503c, 0x643c, 0x8419, 0x842c, 0x841c
634:
635: .text
636: endtext:
637: .data
638: enddata:
639: .bss
640: endbss:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.