setup.S 26 KB

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