Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * setup.S Copyright (C) 1991, 1992 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 | * Move PS/2 aux init code to psaux.c |
| 15 | * (troyer@saifr00.cfsat.Honeywell.COM) 03Oct92 |
| 16 | * |
| 17 | * some changes and additional features by Christoph Niemann, |
| 18 | * March 1993/June 1994 (Christoph.Niemann@linux.org) |
| 19 | * |
| 20 | * add APM BIOS checking by Stephen Rothwell, May 1994 |
| 21 | * (sfr@canb.auug.org.au) |
| 22 | * |
| 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> |
| 26 | * |
| 27 | * Video handling moved to video.S by Martin Mares, March 1996 |
| 28 | * <mj@k332.feld.cvut.cz> |
| 29 | * |
| 30 | * Extended memory detection scheme retwiddled by orc@pell.chi.il.us (david |
| 31 | * parsons) to avoid loadlin confusion, July 1997 |
| 32 | * |
| 33 | * Transcribed from Intel (as86) -> AT&T (gas) by Chris Noe, May 1999. |
| 34 | * <stiker@northlink.com> |
| 35 | * |
Domen Puncer | f454944 | 2005-06-25 14:58:59 -0700 | [diff] [blame] | 36 | * Fix to work around buggy BIOSes which don't use carry bit correctly |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
| 44 | * |
| 45 | * New A20 code ported from SYSLINUX by H. Peter Anvin. AMD Elan bugfixes |
| 46 | * by Robert Schwebel, December 2001 <robert@schwebel.de> |
| 47 | */ |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <asm/segment.h> |
Sam Ravnborg | 63104ee | 2006-07-03 23:30:54 +0200 | [diff] [blame] | 50 | #include <linux/utsrelease.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/compile.h> |
| 52 | #include <asm/boot.h> |
| 53 | #include <asm/e820.h> |
| 54 | #include <asm/page.h> |
| 55 | |
| 56 | /* Signature words to ensure LILO loaded us right */ |
| 57 | #define SIG1 0xAA55 |
| 58 | #define SIG2 0x5A5A |
| 59 | |
| 60 | INITSEG = DEF_INITSEG # 0x9000, we move boot here, out of the way |
| 61 | SYSSEG = DEF_SYSSEG # 0x1000, system loaded at 0x10000 (65536). |
| 62 | SETUPSEG = DEF_SETUPSEG # 0x9020, this is the current segment |
| 63 | # ... and the former contents of CS |
| 64 | |
| 65 | DELTA_INITSEG = SETUPSEG - INITSEG # 0x0020 |
| 66 | |
| 67 | .code16 |
| 68 | .globl begtext, begdata, begbss, endtext, enddata, endbss |
| 69 | |
| 70 | .text |
| 71 | begtext: |
| 72 | .data |
| 73 | begdata: |
| 74 | .bss |
| 75 | begbss: |
| 76 | .text |
| 77 | |
| 78 | start: |
| 79 | jmp trampoline |
| 80 | |
| 81 | # This is the setup header, and it must start at %cs:2 (old 0x9020:2) |
| 82 | |
| 83 | .ascii "HdrS" # header signature |
H. Peter Anvin | f8eeaaf | 2005-09-06 15:17:24 -0700 | [diff] [blame] | 84 | .word 0x0204 # header version number (>= 0x0105) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | # or else old loadlin-1.5 will fail) |
| 86 | realmode_swtch: .word 0, 0 # default_switch, SETUPSEG |
| 87 | start_sys_seg: .word SYSSEG |
| 88 | .word kernel_version # pointing to kernel version string |
| 89 | # above section of header is compatible |
| 90 | # with loadlin-1.5 (header v1.5). Don't |
| 91 | # change it. |
| 92 | |
| 93 | type_of_loader: .byte 0 # = 0, old one (LILO, Loadlin, |
| 94 | # Bootlin, SYSLX, bootsect...) |
| 95 | # See Documentation/i386/boot.txt for |
| 96 | # assigned ids |
| 97 | |
| 98 | # flags, unused bits must be zero (RFU) bit within loadflags |
| 99 | loadflags: |
| 100 | LOADED_HIGH = 1 # If set, the kernel is loaded high |
| 101 | CAN_USE_HEAP = 0x80 # If set, the loader also has set |
| 102 | # heap_end_ptr to tell how much |
| 103 | # space behind setup.S can be used for |
| 104 | # heap purposes. |
| 105 | # Only the loader knows what is free |
| 106 | #ifndef __BIG_KERNEL__ |
| 107 | .byte 0 |
| 108 | #else |
| 109 | .byte LOADED_HIGH |
| 110 | #endif |
| 111 | |
| 112 | setup_move_size: .word 0x8000 # size to move, when setup is not |
| 113 | # loaded at 0x90000. We will move setup |
| 114 | # to 0x90000 then just before jumping |
| 115 | # into the kernel. However, only the |
| 116 | # loader knows how much data behind |
| 117 | # us also needs to be loaded. |
| 118 | |
| 119 | code32_start: # here loaders can put a different |
| 120 | # start address for 32-bit code. |
| 121 | #ifndef __BIG_KERNEL__ |
| 122 | .long 0x1000 # 0x1000 = default for zImage |
| 123 | #else |
| 124 | .long 0x100000 # 0x100000 = default for big kernel |
| 125 | #endif |
| 126 | |
| 127 | ramdisk_image: .long 0 # address of loaded ramdisk image |
| 128 | # Here the loader puts the 32-bit |
| 129 | # address where it loaded the image. |
| 130 | # This only will be read by the kernel. |
| 131 | |
| 132 | ramdisk_size: .long 0 # its size in bytes |
| 133 | |
| 134 | bootsect_kludge: |
| 135 | .long 0 # obsolete |
| 136 | |
| 137 | heap_end_ptr: .word modelist+1024 # (Header version 0x0201 or later) |
| 138 | # space from here (exclusive) down to |
| 139 | # end of setup code can be used by setup |
| 140 | # for local heap purposes. |
| 141 | |
| 142 | pad1: .word 0 |
| 143 | cmd_line_ptr: .long 0 # (Header version 0x0202 or later) |
| 144 | # If nonzero, a 32-bit pointer |
| 145 | # to the kernel command line. |
| 146 | # The command line should be |
| 147 | # located between the start of |
| 148 | # setup and the end of low |
| 149 | # memory (0xa0000), or it may |
| 150 | # get overwritten before it |
| 151 | # gets read. If this field is |
| 152 | # used, there is no longer |
| 153 | # anything magical about the |
| 154 | # 0x90000 segment; the setup |
| 155 | # can be located anywhere in |
| 156 | # low memory 0x10000 or higher. |
| 157 | |
| 158 | ramdisk_max: .long (-__PAGE_OFFSET-(512 << 20)-1) & 0x7fffffff |
| 159 | # (Header version 0x0203 or later) |
| 160 | # The highest safe address for |
| 161 | # the contents of an initrd |
| 162 | |
| 163 | trampoline: call start_of_setup |
| 164 | .align 16 |
| 165 | # The offset at this point is 0x240 |
Venkatesh Pallipadi | f9ba705 | 2005-05-01 08:58:51 -0700 | [diff] [blame] | 166 | .space (0xeff-0x240+1) # E820 & EDD space (ending at 0xeff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | # End of setup header ##################################################### |
| 168 | |
| 169 | start_of_setup: |
| 170 | # Bootlin depends on this being done early |
| 171 | movw $0x01500, %ax |
| 172 | movb $0x81, %dl |
| 173 | int $0x13 |
| 174 | |
| 175 | #ifdef SAFE_RESET_DISK_CONTROLLER |
| 176 | # Reset the disk controller. |
| 177 | movw $0x0000, %ax |
| 178 | movb $0x80, %dl |
| 179 | int $0x13 |
| 180 | #endif |
| 181 | |
| 182 | # Set %ds = %cs, we know that SETUPSEG = %cs at this point |
| 183 | movw %cs, %ax # aka SETUPSEG |
| 184 | movw %ax, %ds |
| 185 | # Check signature at end of setup |
| 186 | cmpw $SIG1, setup_sig1 |
| 187 | jne bad_sig |
| 188 | |
| 189 | cmpw $SIG2, setup_sig2 |
| 190 | jne bad_sig |
| 191 | |
| 192 | jmp good_sig1 |
| 193 | |
| 194 | # Routine to print asciiz string at ds:si |
| 195 | prtstr: |
| 196 | lodsb |
| 197 | andb %al, %al |
| 198 | jz fin |
| 199 | |
| 200 | call prtchr |
| 201 | jmp prtstr |
| 202 | |
| 203 | fin: ret |
| 204 | |
| 205 | # Space printing |
| 206 | prtsp2: call prtspc # Print double space |
| 207 | prtspc: movb $0x20, %al # Print single space (note: fall-thru) |
| 208 | |
| 209 | # Part of above routine, this one just prints ascii al |
| 210 | prtchr: pushw %ax |
| 211 | pushw %cx |
| 212 | movw $7,%bx |
| 213 | movw $0x01, %cx |
| 214 | movb $0x0e, %ah |
| 215 | int $0x10 |
| 216 | popw %cx |
| 217 | popw %ax |
| 218 | ret |
| 219 | |
| 220 | beep: movb $0x07, %al |
| 221 | jmp prtchr |
| 222 | |
| 223 | no_sig_mess: .string "No setup signature found ..." |
| 224 | |
| 225 | good_sig1: |
| 226 | jmp good_sig |
| 227 | |
| 228 | # We now have to find the rest of the setup code/data |
| 229 | bad_sig: |
| 230 | movw %cs, %ax # SETUPSEG |
| 231 | subw $DELTA_INITSEG, %ax # INITSEG |
| 232 | movw %ax, %ds |
| 233 | xorb %bh, %bh |
| 234 | movb (497), %bl # get setup sect from bootsect |
| 235 | subw $4, %bx # LILO loads 4 sectors of setup |
| 236 | shlw $8, %bx # convert to words (1sect=2^8 words) |
| 237 | movw %bx, %cx |
| 238 | shrw $3, %bx # convert to segment |
| 239 | addw $SYSSEG, %bx |
| 240 | movw %bx, %cs:start_sys_seg |
| 241 | # Move rest of setup code/data to here |
| 242 | movw $2048, %di # four sectors loaded by LILO |
| 243 | subw %si, %si |
| 244 | pushw %cs |
| 245 | popw %es |
| 246 | movw $SYSSEG, %ax |
| 247 | movw %ax, %ds |
| 248 | rep |
| 249 | movsw |
| 250 | movw %cs, %ax # aka SETUPSEG |
| 251 | movw %ax, %ds |
| 252 | cmpw $SIG1, setup_sig1 |
| 253 | jne no_sig |
| 254 | |
| 255 | cmpw $SIG2, setup_sig2 |
| 256 | jne no_sig |
| 257 | |
| 258 | jmp good_sig |
| 259 | |
| 260 | no_sig: |
| 261 | lea no_sig_mess, %si |
| 262 | call prtstr |
| 263 | |
| 264 | no_sig_loop: |
| 265 | hlt |
| 266 | jmp no_sig_loop |
| 267 | |
| 268 | good_sig: |
| 269 | movw %cs, %ax # aka SETUPSEG |
| 270 | subw $DELTA_INITSEG, %ax # aka INITSEG |
| 271 | movw %ax, %ds |
| 272 | # Check if an old loader tries to load a big-kernel |
| 273 | testb $LOADED_HIGH, %cs:loadflags # Do we have a big kernel? |
| 274 | jz loader_ok # No, no danger for old loaders. |
| 275 | |
| 276 | cmpb $0, %cs:type_of_loader # Do we have a loader that |
| 277 | # can deal with us? |
| 278 | jnz loader_ok # Yes, continue. |
| 279 | |
| 280 | pushw %cs # No, we have an old loader, |
| 281 | popw %ds # die. |
| 282 | lea loader_panic_mess, %si |
| 283 | call prtstr |
| 284 | |
| 285 | jmp no_sig_loop |
| 286 | |
| 287 | loader_panic_mess: .string "Wrong loader, giving up..." |
| 288 | |
| 289 | loader_ok: |
| 290 | # Get memory size (extended mem, kB) |
| 291 | |
| 292 | xorl %eax, %eax |
| 293 | movl %eax, (0x1e0) |
| 294 | #ifndef STANDARD_MEMORY_BIOS_CALL |
| 295 | movb %al, (E820NR) |
| 296 | # Try three different memory detection schemes. First, try |
| 297 | # e820h, which lets us assemble a memory map, then try e801h, |
| 298 | # which returns a 32-bit memory size, and finally 88h, which |
| 299 | # returns 0-64m |
| 300 | |
| 301 | # method E820H: |
| 302 | # the memory map from hell. e820h returns memory classified into |
| 303 | # a whole bunch of different types, and allows memory holes and |
| 304 | # everything. We scan through this memory map and build a list |
| 305 | # of the first 32 memory areas, which we return at [E820MAP]. |
| 306 | # This is documented at http://www.acpi.info/, in the ACPI 2.0 specification. |
| 307 | |
| 308 | #define SMAP 0x534d4150 |
| 309 | |
| 310 | meme820: |
| 311 | xorl %ebx, %ebx # continuation counter |
| 312 | movw $E820MAP, %di # point into the whitelist |
| 313 | # so we can have the bios |
| 314 | # directly write into it. |
| 315 | |
| 316 | jmpe820: |
| 317 | movl $0x0000e820, %eax # e820, upper word zeroed |
| 318 | movl $SMAP, %edx # ascii 'SMAP' |
| 319 | movl $20, %ecx # size of the e820rec |
| 320 | pushw %ds # data record. |
| 321 | popw %es |
| 322 | int $0x15 # make the call |
| 323 | jc bail820 # fall to e801 if it fails |
| 324 | |
| 325 | cmpl $SMAP, %eax # check the return is `SMAP' |
| 326 | jne bail820 # fall to e801 if it fails |
| 327 | |
| 328 | # cmpl $1, 16(%di) # is this usable memory? |
| 329 | # jne again820 |
| 330 | |
| 331 | # If this is usable memory, we save it by simply advancing %di by |
| 332 | # sizeof(e820rec). |
| 333 | # |
| 334 | good820: |
Venkatesh Pallipadi | f9ba705 | 2005-05-01 08:58:51 -0700 | [diff] [blame] | 335 | movb (E820NR), %al # up to 128 entries |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | cmpb $E820MAX, %al |
Venkatesh Pallipadi | f9ba705 | 2005-05-01 08:58:51 -0700 | [diff] [blame] | 337 | jae bail820 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | incb (E820NR) |
| 340 | movw %di, %ax |
| 341 | addw $20, %ax |
| 342 | movw %ax, %di |
| 343 | again820: |
| 344 | cmpl $0, %ebx # check to see if |
| 345 | jne jmpe820 # %ebx is set to EOF |
| 346 | bail820: |
| 347 | |
| 348 | |
| 349 | # method E801H: |
| 350 | # memory size is in 1k chunksizes, to avoid confusing loadlin. |
| 351 | # we store the 0xe801 memory size in a completely different place, |
| 352 | # because it will most likely be longer than 16 bits. |
| 353 | # (use 1e0 because that's what Larry Augustine uses in his |
| 354 | # alternative new memory detection scheme, and it's sensible |
| 355 | # to write everything into the same place.) |
| 356 | |
| 357 | meme801: |
| 358 | stc # fix to work around buggy |
Domen Puncer | f454944 | 2005-06-25 14:58:59 -0700 | [diff] [blame] | 359 | xorw %cx,%cx # BIOSes which don't clear/set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | xorw %dx,%dx # carry on pass/error of |
| 361 | # e801h memory size call |
| 362 | # or merely pass cx,dx though |
| 363 | # without changing them. |
| 364 | movw $0xe801, %ax |
| 365 | int $0x15 |
| 366 | jc mem88 |
| 367 | |
| 368 | cmpw $0x0, %cx # Kludge to handle BIOSes |
| 369 | jne e801usecxdx # which report their extended |
| 370 | cmpw $0x0, %dx # memory in AX/BX rather than |
| 371 | jne e801usecxdx # CX/DX. The spec I have read |
| 372 | movw %ax, %cx # seems to indicate AX/BX |
| 373 | movw %bx, %dx # are more reasonable anyway... |
| 374 | |
| 375 | e801usecxdx: |
| 376 | andl $0xffff, %edx # clear sign extend |
| 377 | shll $6, %edx # and go from 64k to 1k chunks |
| 378 | movl %edx, (0x1e0) # store extended memory size |
| 379 | andl $0xffff, %ecx # clear sign extend |
| 380 | addl %ecx, (0x1e0) # and add lower memory into |
| 381 | # total size. |
| 382 | |
| 383 | # Ye Olde Traditional Methode. Returns the memory size (up to 16mb or |
| 384 | # 64mb, depending on the bios) in ax. |
| 385 | mem88: |
| 386 | |
| 387 | #endif |
| 388 | movb $0x88, %ah |
| 389 | int $0x15 |
| 390 | movw %ax, (2) |
| 391 | |
| 392 | # Set the keyboard repeat rate to the max |
| 393 | movw $0x0305, %ax |
| 394 | xorw %bx, %bx |
| 395 | int $0x16 |
| 396 | |
| 397 | # Check for video adapter and its parameters and allow the |
| 398 | # user to browse video modes. |
| 399 | call video # NOTE: we need %ds pointing |
| 400 | # to bootsector |
| 401 | |
| 402 | # Get hd0 data... |
| 403 | xorw %ax, %ax |
| 404 | movw %ax, %ds |
| 405 | ldsw (4 * 0x41), %si |
| 406 | movw %cs, %ax # aka SETUPSEG |
| 407 | subw $DELTA_INITSEG, %ax # aka INITSEG |
| 408 | pushw %ax |
| 409 | movw %ax, %es |
| 410 | movw $0x0080, %di |
| 411 | movw $0x10, %cx |
| 412 | pushw %cx |
| 413 | cld |
| 414 | rep |
| 415 | movsb |
| 416 | # Get hd1 data... |
| 417 | xorw %ax, %ax |
| 418 | movw %ax, %ds |
| 419 | ldsw (4 * 0x46), %si |
| 420 | popw %cx |
| 421 | popw %es |
| 422 | movw $0x0090, %di |
| 423 | rep |
| 424 | movsb |
| 425 | # Check that there IS a hd1 :-) |
| 426 | movw $0x01500, %ax |
| 427 | movb $0x81, %dl |
| 428 | int $0x13 |
| 429 | jc no_disk1 |
| 430 | |
| 431 | cmpb $3, %ah |
| 432 | je is_disk1 |
| 433 | |
| 434 | no_disk1: |
| 435 | movw %cs, %ax # aka SETUPSEG |
| 436 | subw $DELTA_INITSEG, %ax # aka INITSEG |
| 437 | movw %ax, %es |
| 438 | movw $0x0090, %di |
| 439 | movw $0x10, %cx |
| 440 | xorw %ax, %ax |
| 441 | cld |
| 442 | rep |
| 443 | stosb |
| 444 | is_disk1: |
| 445 | # check for Micro Channel (MCA) bus |
| 446 | movw %cs, %ax # aka SETUPSEG |
| 447 | subw $DELTA_INITSEG, %ax # aka INITSEG |
| 448 | movw %ax, %ds |
| 449 | xorw %ax, %ax |
| 450 | movw %ax, (0xa0) # set table length to 0 |
| 451 | movb $0xc0, %ah |
| 452 | stc |
| 453 | int $0x15 # moves feature table to es:bx |
| 454 | jc no_mca |
| 455 | |
| 456 | pushw %ds |
| 457 | movw %es, %ax |
| 458 | movw %ax, %ds |
| 459 | movw %cs, %ax # aka SETUPSEG |
| 460 | subw $DELTA_INITSEG, %ax # aka INITSEG |
| 461 | movw %ax, %es |
| 462 | movw %bx, %si |
| 463 | movw $0xa0, %di |
| 464 | movw (%si), %cx |
| 465 | addw $2, %cx # table length is a short |
| 466 | cmpw $0x10, %cx |
| 467 | jc sysdesc_ok |
| 468 | |
| 469 | movw $0x10, %cx # we keep only first 16 bytes |
| 470 | sysdesc_ok: |
| 471 | rep |
| 472 | movsb |
| 473 | popw %ds |
| 474 | no_mca: |
| 475 | #ifdef CONFIG_X86_VOYAGER |
| 476 | movb $0xff, 0x40 # flag on config found |
| 477 | movb $0xc0, %al |
| 478 | mov $0xff, %ah |
| 479 | int $0x15 # put voyager config info at es:di |
| 480 | jc no_voyager |
| 481 | movw $0x40, %si # place voyager info in apm table |
| 482 | cld |
| 483 | movw $7, %cx |
| 484 | voyager_rep: |
| 485 | movb %es:(%di), %al |
| 486 | movb %al,(%si) |
| 487 | incw %di |
| 488 | incw %si |
| 489 | decw %cx |
| 490 | jnz voyager_rep |
| 491 | no_voyager: |
| 492 | #endif |
| 493 | # Check for PS/2 pointing device |
| 494 | movw %cs, %ax # aka SETUPSEG |
| 495 | subw $DELTA_INITSEG, %ax # aka INITSEG |
| 496 | movw %ax, %ds |
Diego Calleja | 606bd58 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 497 | movb $0, (0x1ff) # default is no pointing device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | int $0x11 # int 0x11: equipment list |
| 499 | testb $0x04, %al # check if mouse installed |
| 500 | jz no_psmouse |
| 501 | |
Diego Calleja | 606bd58 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 502 | movb $0xAA, (0x1ff) # device present |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | no_psmouse: |
| 504 | |
| 505 | #if defined(CONFIG_X86_SPEEDSTEP_SMI) || defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE) |
| 506 | movl $0x0000E980, %eax # IST Support |
| 507 | movl $0x47534943, %edx # Request value |
| 508 | int $0x15 |
| 509 | |
| 510 | movl %eax, (96) |
| 511 | movl %ebx, (100) |
| 512 | movl %ecx, (104) |
| 513 | movl %edx, (108) |
| 514 | #endif |
| 515 | |
| 516 | #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE) |
| 517 | # Then check for an APM BIOS... |
| 518 | # %ds points to the bootsector |
| 519 | movw $0, 0x40 # version = 0 means no APM BIOS |
| 520 | movw $0x05300, %ax # APM BIOS installation check |
| 521 | xorw %bx, %bx |
| 522 | int $0x15 |
| 523 | jc done_apm_bios # Nope, no APM BIOS |
| 524 | |
| 525 | cmpw $0x0504d, %bx # Check for "PM" signature |
| 526 | jne done_apm_bios # No signature, no APM BIOS |
| 527 | |
| 528 | andw $0x02, %cx # Is 32 bit supported? |
| 529 | je done_apm_bios # No 32-bit, no (good) APM BIOS |
| 530 | |
| 531 | movw $0x05304, %ax # Disconnect first just in case |
| 532 | xorw %bx, %bx |
| 533 | int $0x15 # ignore return code |
| 534 | movw $0x05303, %ax # 32 bit connect |
| 535 | xorl %ebx, %ebx |
| 536 | xorw %cx, %cx # paranoia :-) |
| 537 | xorw %dx, %dx # ... |
| 538 | xorl %esi, %esi # ... |
| 539 | xorw %di, %di # ... |
| 540 | int $0x15 |
| 541 | jc no_32_apm_bios # Ack, error. |
| 542 | |
| 543 | movw %ax, (66) # BIOS code segment |
| 544 | movl %ebx, (68) # BIOS entry point offset |
| 545 | movw %cx, (72) # BIOS 16 bit code segment |
| 546 | movw %dx, (74) # BIOS data segment |
| 547 | movl %esi, (78) # BIOS code segment lengths |
| 548 | movw %di, (82) # BIOS data segment length |
| 549 | # Redo the installation check as the 32 bit connect |
| 550 | # modifies the flags returned on some BIOSs |
| 551 | movw $0x05300, %ax # APM BIOS installation check |
| 552 | xorw %bx, %bx |
| 553 | xorw %cx, %cx # paranoia |
| 554 | int $0x15 |
| 555 | jc apm_disconnect # error -> shouldn't happen |
| 556 | |
| 557 | cmpw $0x0504d, %bx # check for "PM" signature |
| 558 | jne apm_disconnect # no sig -> shouldn't happen |
| 559 | |
| 560 | movw %ax, (64) # record the APM BIOS version |
| 561 | movw %cx, (76) # and flags |
| 562 | jmp done_apm_bios |
| 563 | |
| 564 | apm_disconnect: # Tidy up |
| 565 | movw $0x05304, %ax # Disconnect |
| 566 | xorw %bx, %bx |
| 567 | int $0x15 # ignore return code |
| 568 | |
| 569 | jmp done_apm_bios |
| 570 | |
| 571 | no_32_apm_bios: |
| 572 | andw $0xfffd, (76) # remove 32 bit support bit |
| 573 | done_apm_bios: |
| 574 | #endif |
| 575 | |
| 576 | #include "edd.S" |
| 577 | |
| 578 | # Now we want to move to protected mode ... |
| 579 | cmpw $0, %cs:realmode_swtch |
| 580 | jz rmodeswtch_normal |
| 581 | |
| 582 | lcall *%cs:realmode_swtch |
| 583 | |
| 584 | jmp rmodeswtch_end |
| 585 | |
| 586 | rmodeswtch_normal: |
| 587 | pushw %cs |
| 588 | call default_switch |
| 589 | |
| 590 | rmodeswtch_end: |
| 591 | # we get the code32 start address and modify the below 'jmpi' |
| 592 | # (loader may have changed it) |
| 593 | movl %cs:code32_start, %eax |
| 594 | movl %eax, %cs:code32 |
| 595 | |
| 596 | # Now we move the system to its rightful place ... but we check if we have a |
| 597 | # big-kernel. In that case we *must* not move it ... |
| 598 | testb $LOADED_HIGH, %cs:loadflags |
| 599 | jz do_move0 # .. then we have a normal low |
| 600 | # loaded zImage |
| 601 | # .. or else we have a high |
| 602 | # loaded bzImage |
| 603 | jmp end_move # ... and we skip moving |
| 604 | |
| 605 | do_move0: |
| 606 | movw $0x100, %ax # start of destination segment |
| 607 | movw %cs, %bp # aka SETUPSEG |
| 608 | subw $DELTA_INITSEG, %bp # aka INITSEG |
| 609 | movw %cs:start_sys_seg, %bx # start of source segment |
| 610 | cld |
| 611 | do_move: |
| 612 | movw %ax, %es # destination segment |
| 613 | incb %ah # instead of add ax,#0x100 |
| 614 | movw %bx, %ds # source segment |
| 615 | addw $0x100, %bx |
| 616 | subw %di, %di |
| 617 | subw %si, %si |
| 618 | movw $0x800, %cx |
| 619 | rep |
| 620 | movsw |
| 621 | cmpw %bp, %bx # assume start_sys_seg > 0x200, |
| 622 | # so we will perhaps read one |
| 623 | # page more than needed, but |
| 624 | # never overwrite INITSEG |
| 625 | # because destination is a |
| 626 | # minimum one page below source |
| 627 | jb do_move |
| 628 | |
| 629 | end_move: |
| 630 | # then we load the segment descriptors |
| 631 | movw %cs, %ax # aka SETUPSEG |
| 632 | movw %ax, %ds |
| 633 | |
| 634 | # Check whether we need to be downward compatible with version <=201 |
| 635 | cmpl $0, cmd_line_ptr |
| 636 | jne end_move_self # loader uses version >=202 features |
| 637 | cmpb $0x20, type_of_loader |
| 638 | je end_move_self # bootsect loader, we know of it |
| 639 | |
| 640 | # Boot loader doesnt support boot protocol version 2.02. |
| 641 | # If we have our code not at 0x90000, we need to move it there now. |
| 642 | # We also then need to move the params behind it (commandline) |
| 643 | # Because we would overwrite the code on the current IP, we move |
| 644 | # it in two steps, jumping high after the first one. |
| 645 | movw %cs, %ax |
| 646 | cmpw $SETUPSEG, %ax |
| 647 | je end_move_self |
| 648 | |
| 649 | cli # make sure we really have |
| 650 | # interrupts disabled ! |
| 651 | # because after this the stack |
| 652 | # should not be used |
| 653 | subw $DELTA_INITSEG, %ax # aka INITSEG |
| 654 | movw %ss, %dx |
| 655 | cmpw %ax, %dx |
| 656 | jb move_self_1 |
| 657 | |
| 658 | addw $INITSEG, %dx |
| 659 | subw %ax, %dx # this will go into %ss after |
| 660 | # the move |
| 661 | move_self_1: |
| 662 | movw %ax, %ds |
| 663 | movw $INITSEG, %ax # real INITSEG |
| 664 | movw %ax, %es |
| 665 | movw %cs:setup_move_size, %cx |
| 666 | std # we have to move up, so we use |
| 667 | # direction down because the |
| 668 | # areas may overlap |
| 669 | movw %cx, %di |
| 670 | decw %di |
| 671 | movw %di, %si |
| 672 | subw $move_self_here+0x200, %cx |
| 673 | rep |
| 674 | movsb |
| 675 | ljmp $SETUPSEG, $move_self_here |
| 676 | |
| 677 | move_self_here: |
| 678 | movw $move_self_here+0x200, %cx |
| 679 | rep |
| 680 | movsb |
| 681 | movw $SETUPSEG, %ax |
| 682 | movw %ax, %ds |
| 683 | movw %dx, %ss |
| 684 | end_move_self: # now we are at the right place |
| 685 | |
| 686 | # |
| 687 | # Enable A20. This is at the very best an annoying procedure. |
| 688 | # A20 code ported from SYSLINUX 1.52-1.63 by H. Peter Anvin. |
| 689 | # AMD Elan bug fix by Robert Schwebel. |
| 690 | # |
| 691 | |
| 692 | #if defined(CONFIG_X86_ELAN) |
| 693 | movb $0x02, %al # alternate A20 gate |
| 694 | outb %al, $0x92 # this works on SC410/SC520 |
| 695 | a20_elan_wait: |
| 696 | call a20_test |
| 697 | jz a20_elan_wait |
| 698 | jmp a20_done |
| 699 | #endif |
| 700 | |
| 701 | |
| 702 | A20_TEST_LOOPS = 32 # Iterations per wait |
| 703 | A20_ENABLE_LOOPS = 255 # Total loops to try |
| 704 | |
| 705 | |
| 706 | #ifndef CONFIG_X86_VOYAGER |
| 707 | a20_try_loop: |
| 708 | |
| 709 | # First, see if we are on a system with no A20 gate. |
| 710 | a20_none: |
| 711 | call a20_test |
| 712 | jnz a20_done |
| 713 | |
| 714 | # Next, try the BIOS (INT 0x15, AX=0x2401) |
| 715 | a20_bios: |
| 716 | movw $0x2401, %ax |
| 717 | pushfl # Be paranoid about flags |
| 718 | int $0x15 |
| 719 | popfl |
| 720 | |
| 721 | call a20_test |
| 722 | jnz a20_done |
| 723 | |
| 724 | # Try enabling A20 through the keyboard controller |
| 725 | #endif /* CONFIG_X86_VOYAGER */ |
| 726 | a20_kbc: |
| 727 | call empty_8042 |
| 728 | |
| 729 | #ifndef CONFIG_X86_VOYAGER |
| 730 | call a20_test # Just in case the BIOS worked |
| 731 | jnz a20_done # but had a delayed reaction. |
| 732 | #endif |
| 733 | |
| 734 | movb $0xD1, %al # command write |
| 735 | outb %al, $0x64 |
| 736 | call empty_8042 |
| 737 | |
| 738 | movb $0xDF, %al # A20 on |
| 739 | outb %al, $0x60 |
| 740 | call empty_8042 |
| 741 | |
| 742 | #ifndef CONFIG_X86_VOYAGER |
| 743 | # Wait until a20 really *is* enabled; it can take a fair amount of |
| 744 | # time on certain systems; Toshiba Tecras are known to have this |
| 745 | # problem. |
| 746 | a20_kbc_wait: |
| 747 | xorw %cx, %cx |
| 748 | a20_kbc_wait_loop: |
| 749 | call a20_test |
| 750 | jnz a20_done |
| 751 | loop a20_kbc_wait_loop |
| 752 | |
| 753 | # Final attempt: use "configuration port A" |
| 754 | a20_fast: |
| 755 | inb $0x92, %al # Configuration Port A |
| 756 | orb $0x02, %al # "fast A20" version |
| 757 | andb $0xFE, %al # don't accidentally reset |
| 758 | outb %al, $0x92 |
| 759 | |
| 760 | # Wait for configuration port A to take effect |
| 761 | a20_fast_wait: |
| 762 | xorw %cx, %cx |
| 763 | a20_fast_wait_loop: |
| 764 | call a20_test |
| 765 | jnz a20_done |
| 766 | loop a20_fast_wait_loop |
| 767 | |
| 768 | # A20 is still not responding. Try frobbing it again. |
| 769 | # |
| 770 | decb (a20_tries) |
| 771 | jnz a20_try_loop |
| 772 | |
| 773 | movw $a20_err_msg, %si |
| 774 | call prtstr |
| 775 | |
| 776 | a20_die: |
| 777 | hlt |
| 778 | jmp a20_die |
| 779 | |
| 780 | a20_tries: |
| 781 | .byte A20_ENABLE_LOOPS |
| 782 | |
| 783 | a20_err_msg: |
| 784 | .ascii "linux: fatal error: A20 gate not responding!" |
| 785 | .byte 13, 10, 0 |
| 786 | |
| 787 | # If we get here, all is good |
| 788 | a20_done: |
| 789 | |
| 790 | #endif /* CONFIG_X86_VOYAGER */ |
| 791 | # set up gdt and idt |
| 792 | lidt idt_48 # load idt with 0,0 |
| 793 | xorl %eax, %eax # Compute gdt_base |
| 794 | movw %ds, %ax # (Convert %ds:gdt to a linear ptr) |
| 795 | shll $4, %eax |
| 796 | addl $gdt, %eax |
| 797 | movl %eax, (gdt_48+2) |
| 798 | lgdt gdt_48 # load gdt with whatever is |
| 799 | # appropriate |
| 800 | |
| 801 | # make sure any possible coprocessor is properly reset.. |
| 802 | xorw %ax, %ax |
| 803 | outb %al, $0xf0 |
| 804 | call delay |
| 805 | |
| 806 | outb %al, $0xf1 |
| 807 | call delay |
| 808 | |
| 809 | # well, that went ok, I hope. Now we mask all interrupts - the rest |
| 810 | # is done in init_IRQ(). |
| 811 | movb $0xFF, %al # mask all interrupts for now |
| 812 | outb %al, $0xA1 |
| 813 | call delay |
| 814 | |
| 815 | movb $0xFB, %al # mask all irq's but irq2 which |
| 816 | outb %al, $0x21 # is cascaded |
| 817 | |
| 818 | # Well, that certainly wasn't fun :-(. Hopefully it works, and we don't |
| 819 | # need no steenking BIOS anyway (except for the initial loading :-). |
| 820 | # The BIOS-routine wants lots of unnecessary data, and it's less |
| 821 | # "interesting" anyway. This is how REAL programmers do it. |
| 822 | # |
| 823 | # Well, now's the time to actually move into protected mode. To make |
| 824 | # things as simple as possible, we do no register set-up or anything, |
| 825 | # we let the gnu-compiled 32-bit programs do that. We just jump to |
| 826 | # absolute address 0x1000 (or the loader supplied one), |
| 827 | # in 32-bit protected mode. |
| 828 | # |
| 829 | # Note that the short jump isn't strictly needed, although there are |
| 830 | # reasons why it might be a good idea. It won't hurt in any case. |
| 831 | movw $1, %ax # protected mode (PE) bit |
| 832 | lmsw %ax # This is it! |
| 833 | jmp flush_instr |
| 834 | |
| 835 | flush_instr: |
| 836 | xorw %bx, %bx # Flag to indicate a boot |
| 837 | xorl %esi, %esi # Pointer to real-mode code |
| 838 | movw %cs, %si |
| 839 | subw $DELTA_INITSEG, %si |
| 840 | shll $4, %esi # Convert to 32-bit pointer |
| 841 | |
| 842 | # jump to startup_32 in arch/i386/boot/compressed/head.S |
| 843 | # |
| 844 | # NOTE: For high loaded big kernels we need a |
| 845 | # jmpi 0x100000,__BOOT_CS |
| 846 | # |
| 847 | # but we yet haven't reloaded the CS register, so the default size |
| 848 | # of the target offset still is 16 bit. |
Domen Puncer | f454944 | 2005-06-25 14:58:59 -0700 | [diff] [blame] | 849 | # However, using an operand prefix (0x66), the CPU will properly |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | # take our 48 bit far pointer. (INTeL 80386 Programmer's Reference |
| 851 | # Manual, Mixing 16-bit and 32-bit code, page 16-6) |
| 852 | |
| 853 | .byte 0x66, 0xea # prefix + jmpi-opcode |
| 854 | code32: .long 0x1000 # will be set to 0x100000 |
| 855 | # for big kernels |
| 856 | .word __BOOT_CS |
| 857 | |
| 858 | # Here's a bunch of information about your current kernel.. |
| 859 | kernel_version: .ascii UTS_RELEASE |
| 860 | .ascii " (" |
| 861 | .ascii LINUX_COMPILE_BY |
| 862 | .ascii "@" |
| 863 | .ascii LINUX_COMPILE_HOST |
| 864 | .ascii ") " |
| 865 | .ascii UTS_VERSION |
| 866 | .byte 0 |
| 867 | |
| 868 | # This is the default real mode switch routine. |
| 869 | # to be called just before protected mode transition |
| 870 | default_switch: |
| 871 | cli # no interrupts allowed ! |
| 872 | movb $0x80, %al # disable NMI for bootup |
| 873 | # sequence |
| 874 | outb %al, $0x70 |
| 875 | lret |
| 876 | |
| 877 | |
| 878 | #ifndef CONFIG_X86_VOYAGER |
| 879 | # This routine tests whether or not A20 is enabled. If so, it |
| 880 | # exits with zf = 0. |
| 881 | # |
| 882 | # The memory address used, 0x200, is the int $0x80 vector, which |
| 883 | # should be safe. |
| 884 | |
| 885 | A20_TEST_ADDR = 4*0x80 |
| 886 | |
| 887 | a20_test: |
| 888 | pushw %cx |
| 889 | pushw %ax |
| 890 | xorw %cx, %cx |
| 891 | movw %cx, %fs # Low memory |
| 892 | decw %cx |
| 893 | movw %cx, %gs # High memory area |
| 894 | movw $A20_TEST_LOOPS, %cx |
| 895 | movw %fs:(A20_TEST_ADDR), %ax |
| 896 | pushw %ax |
| 897 | a20_test_wait: |
| 898 | incw %ax |
| 899 | movw %ax, %fs:(A20_TEST_ADDR) |
| 900 | call delay # Serialize and make delay constant |
| 901 | cmpw %gs:(A20_TEST_ADDR+0x10), %ax |
| 902 | loope a20_test_wait |
| 903 | |
| 904 | popw %fs:(A20_TEST_ADDR) |
| 905 | popw %ax |
| 906 | popw %cx |
| 907 | ret |
| 908 | |
| 909 | #endif /* CONFIG_X86_VOYAGER */ |
| 910 | |
| 911 | # This routine checks that the keyboard command queue is empty |
| 912 | # (after emptying the output buffers) |
| 913 | # |
| 914 | # Some machines have delusions that the keyboard buffer is always full |
| 915 | # with no keyboard attached... |
| 916 | # |
| 917 | # If there is no keyboard controller, we will usually get 0xff |
| 918 | # to all the reads. With each IO taking a microsecond and |
| 919 | # a timeout of 100,000 iterations, this can take about half a |
| 920 | # second ("delay" == outb to port 0x80). That should be ok, |
| 921 | # and should also be plenty of time for a real keyboard controller |
| 922 | # to empty. |
| 923 | # |
| 924 | |
| 925 | empty_8042: |
| 926 | pushl %ecx |
| 927 | movl $100000, %ecx |
| 928 | |
| 929 | empty_8042_loop: |
| 930 | decl %ecx |
| 931 | jz empty_8042_end_loop |
| 932 | |
| 933 | call delay |
| 934 | |
| 935 | inb $0x64, %al # 8042 status port |
| 936 | testb $1, %al # output buffer? |
| 937 | jz no_output |
| 938 | |
| 939 | call delay |
| 940 | inb $0x60, %al # read it |
| 941 | jmp empty_8042_loop |
| 942 | |
| 943 | no_output: |
| 944 | testb $2, %al # is input buffer full? |
| 945 | jnz empty_8042_loop # yes - loop |
| 946 | empty_8042_end_loop: |
| 947 | popl %ecx |
| 948 | ret |
| 949 | |
| 950 | # Read the cmos clock. Return the seconds in al |
| 951 | gettime: |
| 952 | pushw %cx |
| 953 | movb $0x02, %ah |
| 954 | int $0x1a |
| 955 | movb %dh, %al # %dh contains the seconds |
| 956 | andb $0x0f, %al |
| 957 | movb %dh, %ah |
| 958 | movb $0x04, %cl |
| 959 | shrb %cl, %ah |
| 960 | aad |
| 961 | popw %cx |
| 962 | ret |
| 963 | |
| 964 | # Delay is needed after doing I/O |
| 965 | delay: |
| 966 | outb %al,$0x80 |
| 967 | ret |
| 968 | |
| 969 | # Descriptor tables |
| 970 | # |
| 971 | # NOTE: The intel manual says gdt should be sixteen bytes aligned for |
| 972 | # efficiency reasons. However, there are machines which are known not |
| 973 | # to boot with misaligned GDTs, so alter this at your peril! If you alter |
| 974 | # GDT_ENTRY_BOOT_CS (in asm/segment.h) remember to leave at least two |
| 975 | # empty GDT entries (one for NULL and one reserved). |
| 976 | # |
| 977 | # NOTE: On some CPUs, the GDT must be 8 byte aligned. This is |
| 978 | # true for the Voyager Quad CPU card which will not boot without |
| 979 | # This directive. 16 byte aligment is recommended by intel. |
| 980 | # |
| 981 | .align 16 |
| 982 | gdt: |
| 983 | .fill GDT_ENTRY_BOOT_CS,8,0 |
| 984 | |
| 985 | .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb) |
| 986 | .word 0 # base address = 0 |
| 987 | .word 0x9A00 # code read/exec |
| 988 | .word 0x00CF # granularity = 4096, 386 |
| 989 | # (+5th nibble of limit) |
| 990 | |
| 991 | .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb) |
| 992 | .word 0 # base address = 0 |
| 993 | .word 0x9200 # data read/write |
| 994 | .word 0x00CF # granularity = 4096, 386 |
| 995 | # (+5th nibble of limit) |
| 996 | gdt_end: |
| 997 | .align 4 |
| 998 | |
| 999 | .word 0 # alignment byte |
| 1000 | idt_48: |
| 1001 | .word 0 # idt limit = 0 |
| 1002 | .word 0, 0 # idt base = 0L |
| 1003 | |
| 1004 | .word 0 # alignment byte |
| 1005 | gdt_48: |
| 1006 | .word gdt_end - gdt - 1 # gdt limit |
| 1007 | .word 0, 0 # gdt base (filled in later) |
| 1008 | |
| 1009 | # Include video setup & detection code |
| 1010 | |
| 1011 | #include "video.S" |
| 1012 | |
| 1013 | # Setup signature -- must be last |
| 1014 | setup_sig1: .word SIG1 |
| 1015 | setup_sig2: .word SIG2 |
| 1016 | |
| 1017 | # After this point, there is some free space which is used by the video mode |
| 1018 | # handling code to store the temporary mode table (not used by the kernel). |
| 1019 | |
| 1020 | modelist: |
| 1021 | |
| 1022 | .text |
| 1023 | endtext: |
| 1024 | .data |
| 1025 | enddata: |
| 1026 | .bss |
| 1027 | endbss: |