setup.S 26 KB

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