2 * setup.S Copyright (C) 1991, 1992 Linus Torvalds
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.
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
14 * Move PS/2 aux init code to psaux.c
15 * (troyer@saifr00.cfsat.Honeywell.COM) 03Oct92
17 * some changes and additional features by Christoph Niemann,
18 * March 1993/June 1994 (Christoph.Niemann@linux.org)
20 * add APM BIOS checking by Stephen Rothwell, May 1994
21 * (sfr@canb.auug.org.au)
23 * High load stuff, initrd support and position independency
24 * by Hans Lermen & Werner Almesberger, February 1996
25 * <lermen@elserv.ffm.fgan.de>, <almesber@lrc.epfl.ch>
27 * Video handling moved to video.S by Martin Mares, March 1996
28 * <mj@k332.feld.cvut.cz>
30 * Extended memory detection scheme retwiddled by orc@pell.chi.il.us (david
31 * parsons) to avoid loadlin confusion, July 1997
33 * Transcribed from Intel (as86) -> AT&T (gas) by Chris Noe, May 1999.
34 * <stiker@northlink.com>
36 * Fix to work around buggy BIOSes which dont use carry bit correctly
37 * and/or report extended memory in CX/DX for e801h memory size detection
38 * call. As a result the kernel got wrong figures. The int15/e801h docs
39 * from Ralf Brown interrupt list seem to indicate AX/BX should be used
40 * anyway. So to avoid breaking many machines (presumably there was a reason
41 * to orginally use CX/DX instead of AX/BX), we do a kludge to see
42 * if CX/DX have been changed in the e801 call and if so use AX/BX .
43 * Michael Miller, April 2001 <michaelm@mjmm.org>
45 * New A20 code ported from SYSLINUX by H. Peter Anvin. AMD Elan bugfixes
46 * by Robert Schwebel, December 2001 <robert@schwebel.de>
48 * BIOS Enhanced Disk Drive support
49 * by Matt Domsch <Matt_Domsch@dell.com> October 2002
50 * conformant to T13 Committee www.t13.org
51 * projects 1572D, 1484D, 1386D, 1226DT
52 * disk signature read by Matt Domsch <Matt_Domsch@dell.com>
53 * and Andrew Wilks <Andrew_Wilks@dell.com> September 2003
56 #include <linux/config.h>
57 #include <asm/segment.h>
58 #include <linux/version.h>
59 #include <linux/compile.h>
65 /* Signature words to ensure LILO loaded us right */
69 INITSEG = DEF_INITSEG # 0x9000, we move boot here, out of the way
70 SYSSEG = DEF_SYSSEG # 0x1000, system loaded at 0x10000 (65536).
71 SETUPSEG = DEF_SETUPSEG # 0x9020, this is the current segment
72 # ... and the former contents of CS
74 DELTA_INITSEG = SETUPSEG - INITSEG # 0x0020
77 .globl begtext, begdata, begbss, endtext, enddata, endbss
90 # This is the setup header, and it must start at %cs:2 (old 0x9020:2)
92 .ascii "HdrS" # header signature
93 .word 0x0203 # header version number (>= 0x0105)
94 # or else old loadlin-1.5 will fail)
95 realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
96 start_sys_seg: .word SYSSEG
97 .word kernel_version # pointing to kernel version string
98 # above section of header is compatible
99 # with loadlin-1.5 (header v1.5). Don't
102 type_of_loader: .byte 0 # = 0, old one (LILO, Loadlin,
103 # Bootlin, SYSLX, bootsect...)
104 # See Documentation/i386/boot.txt for
107 # flags, unused bits must be zero (RFU) bit within loadflags
109 LOADED_HIGH = 1 # If set, the kernel is loaded high
110 CAN_USE_HEAP = 0x80 # If set, the loader also has set
111 # heap_end_ptr to tell how much
112 # space behind setup.S can be used for
114 # Only the loader knows what is free
115 #ifndef __BIG_KERNEL__
121 setup_move_size: .word 0x8000 # size to move, when setup is not
122 # loaded at 0x90000. We will move setup
123 # to 0x90000 then just before jumping
124 # into the kernel. However, only the
125 # loader knows how much data behind
126 # us also needs to be loaded.
128 code32_start: # here loaders can put a different
129 # start address for 32-bit code.
130 #ifndef __BIG_KERNEL__
131 .long 0x1000 # 0x1000 = default for zImage
133 .long 0x100000 # 0x100000 = default for big kernel
136 ramdisk_image: .long 0 # address of loaded ramdisk image
137 # Here the loader puts the 32-bit
138 # address where it loaded the image.
139 # This only will be read by the kernel.
141 ramdisk_size: .long 0 # its size in bytes
144 .word bootsect_helper, SETUPSEG
146 heap_end_ptr: .word modelist+1024 # (Header version 0x0201 or later)
147 # space from here (exclusive) down to
148 # end of setup code can be used by setup
149 # for local heap purposes.
152 cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
153 # If nonzero, a 32-bit pointer
154 # to the kernel command line.
155 # The command line should be
156 # located between the start of
157 # setup and the end of low
158 # memory (0xa0000), or it may
159 # get overwritten before it
160 # gets read. If this field is
161 # used, there is no longer
162 # anything magical about the
163 # 0x90000 segment; the setup
164 # can be located anywhere in
165 # low memory 0x10000 or higher.
167 ramdisk_max: .long __MAXMEM-1 # (Header version 0x0203 or later)
168 # The highest safe address for
169 # the contents of an initrd
171 trampoline: call start_of_setup
173 # End of setup header #####################################################
176 # Bootlin depends on this being done early
181 #ifdef SAFE_RESET_DISK_CONTROLLER
182 # Reset the disk controller.
188 # Set %ds = %cs, we know that SETUPSEG = %cs at this point
189 movw %cs, %ax # aka SETUPSEG
191 # Check signature at end of setup
192 cmpw $SIG1, setup_sig1
195 cmpw $SIG2, setup_sig2
200 # Routine to print asciiz string at ds:si
212 prtsp2: call prtspc # Print double space
213 prtspc: movb $0x20, %al # Print single space (note: fall-thru)
215 # Part of above routine, this one just prints ascii al
226 beep: movb $0x07, %al
229 no_sig_mess: .string "No setup signature found ..."
234 # We now have to find the rest of the setup code/data
236 movw %cs, %ax # SETUPSEG
237 subw $DELTA_INITSEG, %ax # INITSEG
240 movb (497), %bl # get setup sect from bootsect
241 subw $4, %bx # LILO loads 4 sectors of setup
242 shlw $8, %bx # convert to words (1sect=2^8 words)
244 shrw $3, %bx # convert to segment
246 movw %bx, %cs:start_sys_seg
247 # Move rest of setup code/data to here
248 movw $2048, %di # four sectors loaded by LILO
256 movw %cs, %ax # aka SETUPSEG
258 cmpw $SIG1, setup_sig1
261 cmpw $SIG2, setup_sig2
275 movw %cs, %ax # aka SETUPSEG
276 subw $DELTA_INITSEG, %ax # aka INITSEG
278 # Check if an old loader tries to load a big-kernel
279 testb $LOADED_HIGH, %cs:loadflags # Do we have a big kernel?
280 jz loader_ok # No, no danger for old loaders.
282 cmpb $0, %cs:type_of_loader # Do we have a loader that
284 jnz loader_ok # Yes, continue.
286 pushw %cs # No, we have an old loader,
288 lea loader_panic_mess, %si
293 loader_panic_mess: .string "Wrong loader, giving up..."
296 # Get memory size (extended mem, kB)
300 #ifndef STANDARD_MEMORY_BIOS_CALL
302 # Try three different memory detection schemes. First, try
303 # e820h, which lets us assemble a memory map, then try e801h,
304 # which returns a 32-bit memory size, and finally 88h, which
308 # the memory map from hell. e820h returns memory classified into
309 # a whole bunch of different types, and allows memory holes and
310 # everything. We scan through this memory map and build a list
311 # of the first 32 memory areas, which we return at [E820MAP].
312 # This is documented at http://www.teleport.com/~acpi/acpihtml/topic245.htm
314 #define SMAP 0x534d4150
317 xorl %ebx, %ebx # continuation counter
318 movw $E820MAP, %di # point into the whitelist
319 # so we can have the bios
320 # directly write into it.
323 movl $0x0000e820, %eax # e820, upper word zeroed
324 movl $SMAP, %edx # ascii 'SMAP'
325 movl $20, %ecx # size of the e820rec
326 pushw %ds # data record.
328 int $0x15 # make the call
329 jc bail820 # fall to e801 if it fails
331 cmpl $SMAP, %eax # check the return is `SMAP'
332 jne bail820 # fall to e801 if it fails
334 # cmpl $1, 16(%di) # is this usable memory?
337 # If this is usable memory, we save it by simply advancing %di by
341 movb (E820NR), %al # up to 32 entries
350 cmpl $0, %ebx # check to see if
351 jne jmpe820 # %ebx is set to EOF
356 # memory size is in 1k chunksizes, to avoid confusing loadlin.
357 # we store the 0xe801 memory size in a completely different place,
358 # because it will most likely be longer than 16 bits.
359 # (use 1e0 because that's what Larry Augustine uses in his
360 # alternative new memory detection scheme, and it's sensible
361 # to write everything into the same place.)
364 stc # fix to work around buggy
365 xorw %cx,%cx # BIOSes which dont clear/set
366 xorw %dx,%dx # carry on pass/error of
367 # e801h memory size call
368 # or merely pass cx,dx though
369 # without changing them.
374 cmpw $0x0, %cx # Kludge to handle BIOSes
375 jne e801usecxdx # which report their extended
376 cmpw $0x0, %dx # memory in AX/BX rather than
377 jne e801usecxdx # CX/DX. The spec I have read
378 movw %ax, %cx # seems to indicate AX/BX
379 movw %bx, %dx # are more reasonable anyway...
382 andl $0xffff, %edx # clear sign extend
383 shll $6, %edx # and go from 64k to 1k chunks
384 movl %edx, (0x1e0) # store extended memory size
385 andl $0xffff, %ecx # clear sign extend
386 addl %ecx, (0x1e0) # and add lower memory into
389 # Ye Olde Traditional Methode. Returns the memory size (up to 16mb or
390 # 64mb, depending on the bios) in ax.
398 # Set the keyboard repeat rate to the max
403 # Check for video adapter and its parameters and allow the
404 # user to browse video modes.
405 call video # NOTE: we need %ds pointing
412 movw %cs, %ax # aka SETUPSEG
413 subw $DELTA_INITSEG, %ax # aka INITSEG
431 # Check that there IS a hd1 :-)
441 movw %cs, %ax # aka SETUPSEG
442 subw $DELTA_INITSEG, %ax # aka INITSEG
451 # check for Micro Channel (MCA) bus
452 movw %cs, %ax # aka SETUPSEG
453 subw $DELTA_INITSEG, %ax # aka INITSEG
456 movw %ax, (0xa0) # set table length to 0
459 int $0x15 # moves feature table to es:bx
465 movw %cs, %ax # aka SETUPSEG
466 subw $DELTA_INITSEG, %ax # aka INITSEG
471 addw $2, %cx # table length is a short
475 movw $0x10, %cx # we keep only first 16 bytes
481 # Check for PS/2 pointing device
482 movw %cs, %ax # aka SETUPSEG
483 subw $DELTA_INITSEG, %ax # aka INITSEG
485 movw $0, (0x1ff) # default is no pointing device
486 int $0x11 # int 0x11: equipment list
487 testb $0x04, %al # check if mouse installed
490 movw $0xAA, (0x1ff) # device present
493 #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
494 # Then check for an APM BIOS...
495 # %ds points to the bootsector
496 movw $0, 0x40 # version = 0 means no APM BIOS
497 movw $0x05300, %ax # APM BIOS installation check
500 jc done_apm_bios # Nope, no APM BIOS
502 cmpw $0x0504d, %bx # Check for "PM" signature
503 jne done_apm_bios # No signature, no APM BIOS
505 andw $0x02, %cx # Is 32 bit supported?
506 je done_apm_bios # No 32-bit, no (good) APM BIOS
508 movw $0x05304, %ax # Disconnect first just in case
510 int $0x15 # ignore return code
511 movw $0x05303, %ax # 32 bit connect
513 xorw %cx, %cx # paranoia :-)
515 xorl %esi, %esi # ...
518 jc no_32_apm_bios # Ack, error.
520 movw %ax, (66) # BIOS code segment
521 movl %ebx, (68) # BIOS entry point offset
522 movw %cx, (72) # BIOS 16 bit code segment
523 movw %dx, (74) # BIOS data segment
524 movl %esi, (78) # BIOS code segment lengths
525 movw %di, (82) # BIOS data segment length
526 # Redo the installation check as the 32 bit connect
527 # modifies the flags returned on some BIOSs
528 movw $0x05300, %ax # APM BIOS installation check
530 xorw %cx, %cx # paranoia
532 jc apm_disconnect # error -> shouldn't happen
534 cmpw $0x0504d, %bx # check for "PM" signature
535 jne apm_disconnect # no sig -> shouldn't happen
537 movw %ax, (64) # record the APM BIOS version
538 movw %cx, (76) # and flags
541 apm_disconnect: # Tidy up
542 movw $0x05304, %ax # Disconnect
544 int $0x15 # ignore return code
549 andw $0xfffd, (76) # remove 32 bit support bit
553 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
554 # Read the first sector of device 80h and store the 4-byte signature
555 movl $0xFFFFFFFF, %eax
556 movl %eax, (DISK80_SIG_BUFFER) # assume failure
557 movb $READ_SECTORS, %ah
558 movb $1, %al # read 1 sector
559 movb $0x80, %dl # from device 80
560 movb $0, %dh # at head 0
561 movw $1, %cx # cylinder 0, sector 0
568 movl (EDDBUF+MBR_SIG_OFFSET), %eax
569 movl %eax, (DISK80_SIG_BUFFER) # store success
573 # Do the BIOS Enhanced Disk Drive calls
574 # This consists of two calls:
575 # int 13h ah=41h "Check Extensions Present"
576 # int 13h ah=48h "Get Device Parameters"
578 # A buffer of size EDDMAXNR*(EDDEXTSIZE+EDDPARMSIZE) is reserved for our use
579 # in the empty_zero_page at EDDBUF. The first four bytes of which are
580 # used to store the device number, interface support map and version
581 # results from fn41. The following 74 bytes are used to store
582 # the results from fn48. Starting from device 80h, fn41, then fn48
583 # are called and their results stored in EDDBUF+n*(EDDEXTSIZE+EDDPARMIZE).
584 # Then the pointer is incremented to store the data for the next call.
585 # This repeats until either a device doesn't exist, or until EDDMAXNR
586 # devices have been stored.
587 # The one tricky part is that ds:si always points four bytes into
588 # the structure, and the fn41 results are stored at offsets
589 # from there. This removes the need to increment the pointer for
590 # every store, and leaves it ready for the fn48 call.
591 # A second one-byte buffer, EDDNR, in the empty_zero_page stores
592 # the number of BIOS devices which exist, up to EDDMAXNR.
593 # In setup.c, copy_edd() stores both empty_zero_page buffers away
594 # for later use, as they would get overwritten otherwise.
595 # This code is sensitive to the size of the structs in edd.h
597 # %ds points to the bootsector
598 # result buffer for fn48
599 movw $EDDBUF+EDDEXTSIZE, %si # in ds:si, fn41 results
600 # kept just before that
601 movb $0, (EDDNR) # zero value at EDDNR
602 movb $0x80, %dl # BIOS device 0x80
605 movb $CHECKEXTENSIONSPRESENT, %ah # Function 41
606 movw $EDDMAGIC1, %bx # magic
607 int $0x13 # make the call
608 jc edd_done # no more BIOS devices
610 cmpw $EDDMAGIC2, %bx # is magic right?
611 jne edd_next # nope, next...
613 movb %dl, %ds:-4(%si) # store device number
614 movb %ah, %ds:-3(%si) # store version
615 movw %cx, %ds:-2(%si) # store extensions
616 incb (EDDNR) # note that we stored something
618 edd_get_device_params:
619 movw $EDDPARMSIZE, %ds:(%si) # put size
620 movb $GETDEVICEPARAMETERS, %ah # Function 48
621 int $0x13 # make the call
622 # Don't check for fail return
624 movw %si, %ax # increment si
625 addw $EDDPARMSIZE+EDDEXTSIZE, %ax
629 incb %dl # increment to next device
630 cmpb $EDDMAXNR, (EDDNR) # Out of space?
631 jb edd_check_ext # keep looping
636 # Now we want to move to protected mode ...
637 cmpw $0, %cs:realmode_swtch
640 lcall %cs:realmode_swtch
649 # we get the code32 start address and modify the below 'jmpi'
650 # (loader may have changed it)
651 movl %cs:code32_start, %eax
652 movl %eax, %cs:code32
654 # Now we move the system to its rightful place ... but we check if we have a
655 # big-kernel. In that case we *must* not move it ...
656 testb $LOADED_HIGH, %cs:loadflags
657 jz do_move0 # .. then we have a normal low
659 # .. or else we have a high
661 jmp end_move # ... and we skip moving
664 movw $0x100, %ax # start of destination segment
665 movw %cs, %bp # aka SETUPSEG
666 subw $DELTA_INITSEG, %bp # aka INITSEG
667 movw %cs:start_sys_seg, %bx # start of source segment
670 movw %ax, %es # destination segment
671 incb %ah # instead of add ax,#0x100
672 movw %bx, %ds # source segment
679 cmpw %bp, %bx # assume start_sys_seg > 0x200,
680 # so we will perhaps read one
681 # page more than needed, but
682 # never overwrite INITSEG
683 # because destination is a
684 # minimum one page below source
688 # then we load the segment descriptors
689 movw %cs, %ax # aka SETUPSEG
692 # Check whether we need to be downward compatible with version <=201
693 cmpl $0, cmd_line_ptr
694 jne end_move_self # loader uses version >=202 features
695 cmpb $0x20, type_of_loader
696 je end_move_self # bootsect loader, we know of it
698 # Boot loader doesnt support boot protocol version 2.02.
699 # If we have our code not at 0x90000, we need to move it there now.
700 # We also then need to move the params behind it (commandline)
701 # Because we would overwrite the code on the current IP, we move
702 # it in two steps, jumping high after the first one.
707 cli # make sure we really have
708 # interrupts disabled !
709 # because after this the stack
711 subw $DELTA_INITSEG, %ax # aka INITSEG
717 subw %ax, %dx # this will go into %ss after
721 movw $INITSEG, %ax # real INITSEG
723 movw %cs:setup_move_size, %cx
724 std # we have to move up, so we use
725 # direction down because the
730 subw $move_self_here+0x200, %cx
733 ljmp $SETUPSEG, $move_self_here
736 movw $move_self_here+0x200, %cx
742 end_move_self: # now we are at the right place
745 # Enable A20. This is at the very best an annoying procedure.
746 # A20 code ported from SYSLINUX 1.52-1.63 by H. Peter Anvin.
747 # AMD Elan bug fix by Robert Schwebel.
750 #if defined(CONFIG_MELAN)
751 movb $0x02, %al # alternate A20 gate
752 outb %al, $0x92 # this works on SC410/SC520
760 A20_TEST_LOOPS = 32 # Iterations per wait
761 A20_ENABLE_LOOPS = 255 # Total loops to try
766 # First, see if we are on a system with no A20 gate.
771 # Next, try the BIOS (INT 0x15, AX=0x2401)
774 pushfl # Be paranoid about flags
781 # Try enabling A20 through the keyboard controller
785 call a20_test # Just in case the BIOS worked
786 jnz a20_done # but had a delayed reaction.
788 movb $0xD1, %al # command write
792 movb $0xDF, %al # A20 on
796 # Wait until a20 really *is* enabled; it can take a fair amount of
797 # time on certain systems; Toshiba Tecras are known to have this
804 loop a20_kbc_wait_loop
806 # Final attempt: use "configuration port A"
808 inb $0x92, %al # Configuration Port A
809 orb $0x02, %al # "fast A20" version
810 andb $0xFE, %al # don't accidentally reset
813 # Wait for configuration port A to take effect
819 loop a20_fast_wait_loop
821 # A20 is still not responding. Try frobbing it again.
826 movw $a20_err_msg, %si
834 .byte A20_ENABLE_LOOPS
837 .ascii "linux: fatal error: A20 gate not responding!"
840 # If we get here, all is good
844 lidt idt_48 # load idt with 0,0
845 xorl %eax, %eax # Compute gdt_base
846 movw %ds, %ax # (Convert %ds:gdt to a linear ptr)
849 movl %eax, (gdt_48+2)
850 lgdt gdt_48 # load gdt with whatever is
853 # make sure any possible coprocessor is properly reset..
861 # well, that went ok, I hope. Now we mask all interrupts - the rest
862 # is done in init_IRQ().
863 movb $0xFF, %al # mask all interrupts for now
867 movb $0xFB, %al # mask all irq's but irq2 which
868 outb %al, $0x21 # is cascaded
870 # Well, that certainly wasn't fun :-(. Hopefully it works, and we don't
871 # need no steenking BIOS anyway (except for the initial loading :-).
872 # The BIOS-routine wants lots of unnecessary data, and it's less
873 # "interesting" anyway. This is how REAL programmers do it.
875 # Well, now's the time to actually move into protected mode. To make
876 # things as simple as possible, we do no register set-up or anything,
877 # we let the gnu-compiled 32-bit programs do that. We just jump to
878 # absolute address 0x1000 (or the loader supplied one),
879 # in 32-bit protected mode.
881 # Note that the short jump isn't strictly needed, although there are
882 # reasons why it might be a good idea. It won't hurt in any case.
883 movw $1, %ax # protected mode (PE) bit
884 lmsw %ax # This is it!
888 xorw %bx, %bx # Flag to indicate a boot
889 xorl %esi, %esi # Pointer to real-mode code
891 subw $DELTA_INITSEG, %si
892 shll $4, %esi # Convert to 32-bit pointer
893 # NOTE: For high loaded big kernels we need a
894 # jmpi 0x100000,__KERNEL_CS
896 # but we yet haven't reloaded the CS register, so the default size
897 # of the target offset still is 16 bit.
898 # However, using an operand prefix (0x66), the CPU will properly
899 # take our 48 bit far pointer. (INTeL 80386 Programmer's Reference
900 # Manual, Mixing 16-bit and 32-bit code, page 16-6)
902 .byte 0x66, 0xea # prefix + jmpi-opcode
903 code32: .long 0x1000 # will be set to 0x100000
907 # Here's a bunch of information about your current kernel..
908 kernel_version: .ascii UTS_RELEASE
910 .ascii LINUX_COMPILE_BY
912 .ascii LINUX_COMPILE_HOST
917 # This is the default real mode switch routine.
918 # to be called just before protected mode transition
920 cli # no interrupts allowed !
921 movb $0x80, %al # disable NMI for bootup
926 # This routine only gets called, if we get loaded by the simple
927 # bootsect loader _and_ have a bzImage to load.
928 # Because there is no place left in the 512 bytes of the boot sector,
929 # we must emigrate to code space here.
931 cmpw $0, %cs:bootsect_es
934 movb $0x20, %cs:type_of_loader
937 movb %ah, %cs:bootsect_src_base+2
939 movw %ax, %cs:bootsect_es
941 lret # nothing else to do for now
947 testw %bx, %bx # 64K full?
950 movw $0x8000, %cx # full 64K, INT15 moves words
953 movw $bootsect_gdt, %si
956 jc bootsect_panic # this, if INT15 fails
958 movw %cs:bootsect_es, %es # we reset %es to always point
959 incb %cs:bootsect_dst_base+2 # to 0x10000
961 movb %cs:bootsect_dst_base+2, %ah
962 shlb $4, %ah # we now have the number of
963 # moved frames in %ax
978 .byte 0x00, 0x00, 0x01 # base = 0x010000
980 .word 0 # limit16,base24 =0
986 .byte 0x00, 0x00, 0x10 # base = 0x100000
988 .word 0 # limit16,base24 =0
989 .word 0, 0, 0, 0 # BIOS CS
990 .word 0, 0, 0, 0 # BIOS DS
999 leaw bootsect_panic_mess, %si
1002 bootsect_panic_loop:
1003 jmp bootsect_panic_loop
1005 bootsect_panic_mess:
1006 .string "INT15 refuses to access high mem, giving up."
1009 # This routine tests whether or not A20 is enabled. If so, it
1010 # exits with zf = 0.
1012 # The memory address used, 0x200, is the int $0x80 vector, which
1015 A20_TEST_ADDR = 4*0x80
1021 movw %cx, %fs # Low memory
1023 movw %cx, %gs # High memory area
1024 movw $A20_TEST_LOOPS, %cx
1025 movw %fs:(A20_TEST_ADDR), %ax
1029 movw %ax, %fs:(A20_TEST_ADDR)
1030 call delay # Serialize and make delay constant
1031 cmpw %gs:(A20_TEST_ADDR+0x10), %ax
1034 popw %fs:(A20_TEST_ADDR)
1039 # This routine checks that the keyboard command queue is empty
1040 # (after emptying the output buffers)
1042 # Some machines have delusions that the keyboard buffer is always full
1043 # with no keyboard attached...
1045 # If there is no keyboard controller, we will usually get 0xff
1046 # to all the reads. With each IO taking a microsecond and
1047 # a timeout of 100,000 iterations, this can take about half a
1048 # second ("delay" == outb to port 0x80). That should be ok,
1049 # and should also be plenty of time for a real keyboard controller
1059 jz empty_8042_end_loop
1063 inb $0x64, %al # 8042 status port
1064 testb $1, %al # output buffer?
1068 inb $0x60, %al # read it
1072 testb $2, %al # is input buffer full?
1073 jnz empty_8042_loop # yes - loop
1074 empty_8042_end_loop:
1078 # Read the cmos clock. Return the seconds in al
1083 movb %dh, %al # %dh contains the seconds
1092 # Delay is needed after doing I/O
1099 .word 0, 0, 0, 0 # dummy
1100 .word 0, 0, 0, 0 # unused
1102 .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
1103 .word 0 # base address = 0
1104 .word 0x9A00 # code read/exec
1105 .word 0x00CF # granularity = 4096, 386
1106 # (+5th nibble of limit)
1108 .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
1109 .word 0 # base address = 0
1110 .word 0x9200 # data read/write
1111 .word 0x00CF # granularity = 4096, 386
1112 # (+5th nibble of limit)
1114 .word 0 # idt limit = 0
1115 .word 0, 0 # idt base = 0L
1117 .word 0x8000 # gdt limit=2048,
1120 .word 0, 0 # gdt base (filled in later)
1122 # Include video setup & detection code
1126 # Setup signature -- must be last
1127 setup_sig1: .word SIG1
1128 setup_sig2: .word SIG2
1130 # After this point, there is some free space which is used by the video mode
1131 # handling code to store the temporary mode table (not used by the kernel).