setup.S 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  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. # Now we move the system to its rightful place ... but we check if we have a
  506. # big-kernel. In that case we *must* not move it ...
  507. testb $LOADED_HIGH, %cs:loadflags
  508. jz do_move0 # .. then we have a normal low
  509. # loaded zImage
  510. # .. or else we have a high
  511. # loaded bzImage
  512. jmp end_move # ... and we skip moving
  513. do_move0:
  514. movw $0x100, %ax # start of destination segment
  515. movw %cs, %bp # aka SETUPSEG
  516. subw $DELTA_INITSEG, %bp # aka INITSEG
  517. movw %cs:start_sys_seg, %bx # start of source segment
  518. cld
  519. do_move:
  520. movw %ax, %es # destination segment
  521. incb %ah # instead of add ax,#0x100
  522. movw %bx, %ds # source segment
  523. addw $0x100, %bx
  524. subw %di, %di
  525. subw %si, %si
  526. movw $0x800, %cx
  527. rep
  528. movsw
  529. cmpw %bp, %bx # assume start_sys_seg > 0x200,
  530. # so we will perhaps read one
  531. # page more than needed, but
  532. # never overwrite INITSEG
  533. # because destination is a
  534. # minimum one page below source
  535. jb do_move
  536. end_move:
  537. # then we load the segment descriptors
  538. movw %cs, %ax # aka SETUPSEG
  539. movw %ax, %ds
  540. # Check whether we need to be downward compatible with version <=201
  541. cmpl $0, cmd_line_ptr
  542. jne end_move_self # loader uses version >=202 features
  543. cmpb $0x20, type_of_loader
  544. je end_move_self # bootsect loader, we know of it
  545. # Boot loader doesnt support boot protocol version 2.02.
  546. # If we have our code not at 0x90000, we need to move it there now.
  547. # We also then need to move the params behind it (commandline)
  548. # Because we would overwrite the code on the current IP, we move
  549. # it in two steps, jumping high after the first one.
  550. movw %cs, %ax
  551. cmpw $SETUPSEG, %ax
  552. je end_move_self
  553. cli # make sure we really have
  554. # interrupts disabled !
  555. # because after this the stack
  556. # should not be used
  557. subw $DELTA_INITSEG, %ax # aka INITSEG
  558. movw %ss, %dx
  559. cmpw %ax, %dx
  560. jb move_self_1
  561. addw $INITSEG, %dx
  562. subw %ax, %dx # this will go into %ss after
  563. # the move
  564. move_self_1:
  565. movw %ax, %ds
  566. movw $INITSEG, %ax # real INITSEG
  567. movw %ax, %es
  568. movw %cs:setup_move_size, %cx
  569. std # we have to move up, so we use
  570. # direction down because the
  571. # areas may overlap
  572. movw %cx, %di
  573. decw %di
  574. movw %di, %si
  575. subw $move_self_here+0x200, %cx
  576. rep
  577. movsb
  578. ljmp $SETUPSEG, $move_self_here
  579. move_self_here:
  580. movw $move_self_here+0x200, %cx
  581. rep
  582. movsb
  583. movw $SETUPSEG, %ax
  584. movw %ax, %ds
  585. movw %dx, %ss
  586. end_move_self: # now we are at the right place
  587. #
  588. # Enable A20. This is at the very best an annoying procedure.
  589. # A20 code ported from SYSLINUX 1.52-1.63 by H. Peter Anvin.
  590. # AMD Elan bug fix by Robert Schwebel.
  591. #
  592. #if defined(CONFIG_X86_ELAN)
  593. movb $0x02, %al # alternate A20 gate
  594. outb %al, $0x92 # this works on SC410/SC520
  595. a20_elan_wait:
  596. call a20_test
  597. jz a20_elan_wait
  598. jmp a20_done
  599. #endif
  600. A20_TEST_LOOPS = 32 # Iterations per wait
  601. A20_ENABLE_LOOPS = 255 # Total loops to try
  602. #ifndef CONFIG_X86_VOYAGER
  603. a20_try_loop:
  604. # First, see if we are on a system with no A20 gate.
  605. a20_none:
  606. call a20_test
  607. jnz a20_done
  608. # Next, try the BIOS (INT 0x15, AX=0x2401)
  609. a20_bios:
  610. movw $0x2401, %ax
  611. pushfl # Be paranoid about flags
  612. int $0x15
  613. popfl
  614. call a20_test
  615. jnz a20_done
  616. # Try enabling A20 through the keyboard controller
  617. #endif /* CONFIG_X86_VOYAGER */
  618. a20_kbc:
  619. call empty_8042
  620. #ifndef CONFIG_X86_VOYAGER
  621. call a20_test # Just in case the BIOS worked
  622. jnz a20_done # but had a delayed reaction.
  623. #endif
  624. movb $0xD1, %al # command write
  625. outb %al, $0x64
  626. call empty_8042
  627. movb $0xDF, %al # A20 on
  628. outb %al, $0x60
  629. call empty_8042
  630. #ifndef CONFIG_X86_VOYAGER
  631. # Wait until a20 really *is* enabled; it can take a fair amount of
  632. # time on certain systems; Toshiba Tecras are known to have this
  633. # problem.
  634. a20_kbc_wait:
  635. xorw %cx, %cx
  636. a20_kbc_wait_loop:
  637. call a20_test
  638. jnz a20_done
  639. loop a20_kbc_wait_loop
  640. # Final attempt: use "configuration port A"
  641. a20_fast:
  642. inb $0x92, %al # Configuration Port A
  643. orb $0x02, %al # "fast A20" version
  644. andb $0xFE, %al # don't accidentally reset
  645. outb %al, $0x92
  646. # Wait for configuration port A to take effect
  647. a20_fast_wait:
  648. xorw %cx, %cx
  649. a20_fast_wait_loop:
  650. call a20_test
  651. jnz a20_done
  652. loop a20_fast_wait_loop
  653. # A20 is still not responding. Try frobbing it again.
  654. #
  655. decb (a20_tries)
  656. jnz a20_try_loop
  657. movw $a20_err_msg, %si
  658. call prtstr
  659. a20_die:
  660. hlt
  661. jmp a20_die
  662. a20_tries:
  663. .byte A20_ENABLE_LOOPS
  664. a20_err_msg:
  665. .ascii "linux: fatal error: A20 gate not responding!"
  666. .byte 13, 10, 0
  667. # If we get here, all is good
  668. a20_done:
  669. #endif /* CONFIG_X86_VOYAGER */
  670. # set up gdt and idt and 32bit start address
  671. lidt idt_48 # load idt with 0,0
  672. xorl %eax, %eax # Compute gdt_base
  673. movw %ds, %ax # (Convert %ds:gdt to a linear ptr)
  674. shll $4, %eax
  675. addl %eax, code32
  676. addl $gdt, %eax
  677. movl %eax, (gdt_48+2)
  678. lgdt gdt_48 # load gdt with whatever is
  679. # appropriate
  680. # make sure any possible coprocessor is properly reset..
  681. xorw %ax, %ax
  682. outb %al, $0xf0
  683. call delay
  684. outb %al, $0xf1
  685. call delay
  686. # well, that went ok, I hope. Now we mask all interrupts - the rest
  687. # is done in init_IRQ().
  688. movb $0xFF, %al # mask all interrupts for now
  689. outb %al, $0xA1
  690. call delay
  691. movb $0xFB, %al # mask all irq's but irq2 which
  692. outb %al, $0x21 # is cascaded
  693. # Well, that certainly wasn't fun :-(. Hopefully it works, and we don't
  694. # need no steenking BIOS anyway (except for the initial loading :-).
  695. # The BIOS-routine wants lots of unnecessary data, and it's less
  696. # "interesting" anyway. This is how REAL programmers do it.
  697. #
  698. # Well, now's the time to actually move into protected mode. To make
  699. # things as simple as possible, we do no register set-up or anything,
  700. # we let the gnu-compiled 32-bit programs do that. We just jump to
  701. # absolute address 0x1000 (or the loader supplied one),
  702. # in 32-bit protected mode.
  703. #
  704. # Note that the short jump isn't strictly needed, although there are
  705. # reasons why it might be a good idea. It won't hurt in any case.
  706. movw $1, %ax # protected mode (PE) bit
  707. lmsw %ax # This is it!
  708. jmp flush_instr
  709. flush_instr:
  710. xorw %bx, %bx # Flag to indicate a boot
  711. xorl %esi, %esi # Pointer to real-mode code
  712. movw %cs, %si
  713. subw $DELTA_INITSEG, %si
  714. shll $4, %esi # Convert to 32-bit pointer
  715. # jump to startup_32 in arch/i386/boot/compressed/head.S
  716. #
  717. # NOTE: For high loaded big kernels we need a
  718. # jmpi 0x100000,__BOOT_CS
  719. #
  720. # but we yet haven't reloaded the CS register, so the default size
  721. # of the target offset still is 16 bit.
  722. # However, using an operand prefix (0x66), the CPU will properly
  723. # take our 48 bit far pointer. (INTeL 80386 Programmer's Reference
  724. # Manual, Mixing 16-bit and 32-bit code, page 16-6)
  725. .byte 0x66, 0xea # prefix + jmpi-opcode
  726. code32: .long startup_32 # will be set to %cs+startup_32
  727. .word __BOOT_CS
  728. .code32
  729. startup_32:
  730. movl $(__BOOT_DS), %eax
  731. movl %eax, %ds
  732. movl %eax, %es
  733. movl %eax, %fs
  734. movl %eax, %gs
  735. movl %eax, %ss
  736. xorl %eax, %eax
  737. 1: incl %eax # check that A20 really IS enabled
  738. movl %eax, 0x00000000 # loop forever if it isn't
  739. cmpl %eax, 0x00100000
  740. je 1b
  741. # Jump to the 32bit entry point
  742. jmpl *(code32_start - start + (DELTA_INITSEG << 4))(%esi)
  743. .code16
  744. # Here's a bunch of information about your current kernel..
  745. kernel_version: .ascii UTS_RELEASE
  746. .ascii " ("
  747. .ascii LINUX_COMPILE_BY
  748. .ascii "@"
  749. .ascii LINUX_COMPILE_HOST
  750. .ascii ") "
  751. .ascii UTS_VERSION
  752. .byte 0
  753. # This is the default real mode switch routine.
  754. # to be called just before protected mode transition
  755. default_switch:
  756. cli # no interrupts allowed !
  757. movb $0x80, %al # disable NMI for bootup
  758. # sequence
  759. outb %al, $0x70
  760. lret
  761. #ifndef CONFIG_X86_VOYAGER
  762. # This routine tests whether or not A20 is enabled. If so, it
  763. # exits with zf = 0.
  764. #
  765. # The memory address used, 0x200, is the int $0x80 vector, which
  766. # should be safe.
  767. A20_TEST_ADDR = 4*0x80
  768. a20_test:
  769. pushw %cx
  770. pushw %ax
  771. xorw %cx, %cx
  772. movw %cx, %fs # Low memory
  773. decw %cx
  774. movw %cx, %gs # High memory area
  775. movw $A20_TEST_LOOPS, %cx
  776. movw %fs:(A20_TEST_ADDR), %ax
  777. pushw %ax
  778. a20_test_wait:
  779. incw %ax
  780. movw %ax, %fs:(A20_TEST_ADDR)
  781. call delay # Serialize and make delay constant
  782. cmpw %gs:(A20_TEST_ADDR+0x10), %ax
  783. loope a20_test_wait
  784. popw %fs:(A20_TEST_ADDR)
  785. popw %ax
  786. popw %cx
  787. ret
  788. #endif /* CONFIG_X86_VOYAGER */
  789. # This routine checks that the keyboard command queue is empty
  790. # (after emptying the output buffers)
  791. #
  792. # Some machines have delusions that the keyboard buffer is always full
  793. # with no keyboard attached...
  794. #
  795. # If there is no keyboard controller, we will usually get 0xff
  796. # to all the reads. With each IO taking a microsecond and
  797. # a timeout of 100,000 iterations, this can take about half a
  798. # second ("delay" == outb to port 0x80). That should be ok,
  799. # and should also be plenty of time for a real keyboard controller
  800. # to empty.
  801. #
  802. empty_8042:
  803. pushl %ecx
  804. movl $100000, %ecx
  805. empty_8042_loop:
  806. decl %ecx
  807. jz empty_8042_end_loop
  808. call delay
  809. inb $0x64, %al # 8042 status port
  810. testb $1, %al # output buffer?
  811. jz no_output
  812. call delay
  813. inb $0x60, %al # read it
  814. jmp empty_8042_loop
  815. no_output:
  816. testb $2, %al # is input buffer full?
  817. jnz empty_8042_loop # yes - loop
  818. empty_8042_end_loop:
  819. popl %ecx
  820. ret
  821. # Read the cmos clock. Return the seconds in al
  822. gettime:
  823. pushw %cx
  824. movb $0x02, %ah
  825. int $0x1a
  826. movb %dh, %al # %dh contains the seconds
  827. andb $0x0f, %al
  828. movb %dh, %ah
  829. movb $0x04, %cl
  830. shrb %cl, %ah
  831. aad
  832. popw %cx
  833. ret
  834. # Delay is needed after doing I/O
  835. delay:
  836. outb %al,$0x80
  837. ret
  838. # Descriptor tables
  839. #
  840. # NOTE: The intel manual says gdt should be sixteen bytes aligned for
  841. # efficiency reasons. However, there are machines which are known not
  842. # to boot with misaligned GDTs, so alter this at your peril! If you alter
  843. # GDT_ENTRY_BOOT_CS (in asm/segment.h) remember to leave at least two
  844. # empty GDT entries (one for NULL and one reserved).
  845. #
  846. # NOTE: On some CPUs, the GDT must be 8 byte aligned. This is
  847. # true for the Voyager Quad CPU card which will not boot without
  848. # This directive. 16 byte aligment is recommended by intel.
  849. #
  850. .align 16
  851. gdt:
  852. .fill GDT_ENTRY_BOOT_CS,8,0
  853. .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
  854. .word 0 # base address = 0
  855. .word 0x9A00 # code read/exec
  856. .word 0x00CF # granularity = 4096, 386
  857. # (+5th nibble of limit)
  858. .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
  859. .word 0 # base address = 0
  860. .word 0x9200 # data read/write
  861. .word 0x00CF # granularity = 4096, 386
  862. # (+5th nibble of limit)
  863. gdt_end:
  864. .align 4
  865. .word 0 # alignment byte
  866. idt_48:
  867. .word 0 # idt limit = 0
  868. .word 0, 0 # idt base = 0L
  869. .word 0 # alignment byte
  870. gdt_48:
  871. .word gdt_end - gdt - 1 # gdt limit
  872. .word 0, 0 # gdt base (filled in later)
  873. # Include video setup & detection code
  874. #include "video.S"
  875. # Setup signature -- must be last
  876. setup_sig1: .word SIG1
  877. setup_sig2: .word SIG2
  878. # After this point, there is some free space which is used by the video mode
  879. # handling code to store the temporary mode table (not used by the kernel).
  880. modelist:
  881. .text
  882. endtext:
  883. .data
  884. enddata:
  885. .bss
  886. endbss: