setup.S 25 KB

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