setup.S 27 KB

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