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