setup.S 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  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. * Added long mode checking and SSE force. March 2003, Andi Kleen.
  46. */
  47. #include <asm/segment.h>
  48. #include <linux/utsrelease.h>
  49. #include <linux/compile.h>
  50. #include <asm/boot.h>
  51. #include <asm/e820.h>
  52. #include <asm/page.h>
  53. /* Signature words to ensure LILO loaded us right */
  54. #define SIG1 0xAA55
  55. #define SIG2 0x5A5A
  56. INITSEG = DEF_INITSEG # 0x9000, we move boot here, out of the way
  57. SYSSEG = DEF_SYSSEG # 0x1000, system loaded at 0x10000 (65536).
  58. SETUPSEG = DEF_SETUPSEG # 0x9020, this is the current segment
  59. # ... and the former contents of CS
  60. DELTA_INITSEG = SETUPSEG - INITSEG # 0x0020
  61. .code16
  62. .globl begtext, begdata, begbss, endtext, enddata, endbss
  63. .text
  64. begtext:
  65. .data
  66. begdata:
  67. .bss
  68. begbss:
  69. .text
  70. start:
  71. jmp trampoline
  72. # This is the setup header, and it must start at %cs:2 (old 0x9020:2)
  73. .ascii "HdrS" # header signature
  74. .word 0x0205 # header version number (>= 0x0105)
  75. # or else old loadlin-1.5 will fail)
  76. realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
  77. start_sys_seg: .word SYSSEG
  78. .word kernel_version # pointing to kernel version string
  79. # above section of header is compatible
  80. # with loadlin-1.5 (header v1.5). Don't
  81. # change it.
  82. type_of_loader: .byte 0 # = 0, old one (LILO, Loadlin,
  83. # Bootlin, SYSLX, bootsect...)
  84. # See Documentation/i386/boot.txt for
  85. # assigned ids
  86. # flags, unused bits must be zero (RFU) bit within loadflags
  87. loadflags:
  88. LOADED_HIGH = 1 # If set, the kernel is loaded high
  89. CAN_USE_HEAP = 0x80 # If set, the loader also has set
  90. # heap_end_ptr to tell how much
  91. # space behind setup.S can be used for
  92. # heap purposes.
  93. # Only the loader knows what is free
  94. #ifndef __BIG_KERNEL__
  95. .byte 0
  96. #else
  97. .byte LOADED_HIGH
  98. #endif
  99. setup_move_size: .word 0x8000 # size to move, when setup is not
  100. # loaded at 0x90000. We will move setup
  101. # to 0x90000 then just before jumping
  102. # into the kernel. However, only the
  103. # loader knows how much data behind
  104. # us also needs to be loaded.
  105. code32_start: # here loaders can put a different
  106. # start address for 32-bit code.
  107. #ifndef __BIG_KERNEL__
  108. .long 0x1000 # 0x1000 = default for zImage
  109. #else
  110. .long 0x100000 # 0x100000 = default for big kernel
  111. #endif
  112. ramdisk_image: .long 0 # address of loaded ramdisk image
  113. # Here the loader puts the 32-bit
  114. # address where it loaded the image.
  115. # This only will be read by the kernel.
  116. ramdisk_size: .long 0 # its size in bytes
  117. bootsect_kludge:
  118. .long 0 # obsolete
  119. heap_end_ptr: .word modelist+1024 # (Header version 0x0201 or later)
  120. # space from here (exclusive) down to
  121. # end of setup code can be used by setup
  122. # for local heap purposes.
  123. pad1: .word 0
  124. cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
  125. # If nonzero, a 32-bit pointer
  126. # to the kernel command line.
  127. # The command line should be
  128. # located between the start of
  129. # setup and the end of low
  130. # memory (0xa0000), or it may
  131. # get overwritten before it
  132. # gets read. If this field is
  133. # used, there is no longer
  134. # anything magical about the
  135. # 0x90000 segment; the setup
  136. # can be located anywhere in
  137. # low memory 0x10000 or higher.
  138. ramdisk_max: .long 0xffffffff
  139. kernel_alignment: .long 0x200000 # physical addr alignment required for
  140. # protected mode relocatable kernel
  141. #ifdef CONFIG_RELOCATABLE
  142. relocatable_kernel: .byte 1
  143. #else
  144. relocatable_kernel: .byte 0
  145. #endif
  146. pad2: .byte 0
  147. pad3: .word 0
  148. trampoline: call start_of_setup
  149. .align 16
  150. # The offset at this point is 0x240
  151. .space (0xeff-0x240+1) # E820 & EDD space (ending at 0xeff)
  152. # End of setup header #####################################################
  153. start_of_setup:
  154. # Bootlin depends on this being done early
  155. movw $0x01500, %ax
  156. movb $0x81, %dl
  157. int $0x13
  158. #ifdef SAFE_RESET_DISK_CONTROLLER
  159. # Reset the disk controller.
  160. movw $0x0000, %ax
  161. movb $0x80, %dl
  162. int $0x13
  163. #endif
  164. # Set %ds = %cs, we know that SETUPSEG = %cs at this point
  165. movw %cs, %ax # aka SETUPSEG
  166. movw %ax, %ds
  167. # Check signature at end of setup
  168. cmpw $SIG1, setup_sig1
  169. jne bad_sig
  170. cmpw $SIG2, setup_sig2
  171. jne bad_sig
  172. jmp good_sig1
  173. # Routine to print asciiz string at ds:si
  174. prtstr:
  175. lodsb
  176. andb %al, %al
  177. jz fin
  178. call prtchr
  179. jmp prtstr
  180. fin: ret
  181. # Space printing
  182. prtsp2: call prtspc # Print double space
  183. prtspc: movb $0x20, %al # Print single space (note: fall-thru)
  184. prtchr:
  185. pushw %ax
  186. pushw %cx
  187. movw $0007,%bx
  188. movw $0x01, %cx
  189. movb $0x0e, %ah
  190. int $0x10
  191. popw %cx
  192. popw %ax
  193. ret
  194. beep: movb $0x07, %al
  195. jmp prtchr
  196. no_sig_mess: .string "No setup signature found ..."
  197. good_sig1:
  198. jmp good_sig
  199. # We now have to find the rest of the setup code/data
  200. bad_sig:
  201. movw %cs, %ax # SETUPSEG
  202. subw $DELTA_INITSEG, %ax # INITSEG
  203. movw %ax, %ds
  204. xorb %bh, %bh
  205. movb (497), %bl # get setup sect from bootsect
  206. subw $4, %bx # LILO loads 4 sectors of setup
  207. shlw $8, %bx # convert to words (1sect=2^8 words)
  208. movw %bx, %cx
  209. shrw $3, %bx # convert to segment
  210. addw $SYSSEG, %bx
  211. movw %bx, %cs:start_sys_seg
  212. # Move rest of setup code/data to here
  213. movw $2048, %di # four sectors loaded by LILO
  214. subw %si, %si
  215. movw %cs, %ax # aka SETUPSEG
  216. movw %ax, %es
  217. movw $SYSSEG, %ax
  218. movw %ax, %ds
  219. rep
  220. movsw
  221. movw %cs, %ax # aka SETUPSEG
  222. movw %ax, %ds
  223. cmpw $SIG1, setup_sig1
  224. jne no_sig
  225. cmpw $SIG2, setup_sig2
  226. jne no_sig
  227. jmp good_sig
  228. no_sig:
  229. lea no_sig_mess, %si
  230. call prtstr
  231. no_sig_loop:
  232. jmp no_sig_loop
  233. good_sig:
  234. movw %cs, %ax # aka SETUPSEG
  235. subw $DELTA_INITSEG, %ax # aka INITSEG
  236. movw %ax, %ds
  237. # Check if an old loader tries to load a big-kernel
  238. testb $LOADED_HIGH, %cs:loadflags # Do we have a big kernel?
  239. jz loader_ok # No, no danger for old loaders.
  240. cmpb $0, %cs:type_of_loader # Do we have a loader that
  241. # can deal with us?
  242. jnz loader_ok # Yes, continue.
  243. pushw %cs # No, we have an old loader,
  244. popw %ds # die.
  245. lea loader_panic_mess, %si
  246. call prtstr
  247. jmp no_sig_loop
  248. loader_panic_mess: .string "Wrong loader, giving up..."
  249. loader_ok:
  250. /* check for long mode. */
  251. /* we have to do this before the VESA setup, otherwise the user
  252. can't see the error message. */
  253. pushw %ds
  254. movw %cs,%ax
  255. movw %ax,%ds
  256. call verify_cpu
  257. testl %eax,%eax
  258. jz sse_ok
  259. no_longmode:
  260. call beep
  261. lea long_mode_panic,%si
  262. call prtstr
  263. no_longmode_loop:
  264. jmp no_longmode_loop
  265. long_mode_panic:
  266. .string "Your CPU does not support long mode. Use a 32bit distribution."
  267. .byte 0
  268. #include "../kernel/verify_cpu.S"
  269. sse_ok:
  270. popw %ds
  271. # tell BIOS we want to go to long mode
  272. movl $0xec00,%eax # declare target operating mode
  273. movl $2,%ebx # long mode
  274. int $0x15
  275. # Get memory size (extended mem, kB)
  276. xorl %eax, %eax
  277. movl %eax, (0x1e0)
  278. #ifndef STANDARD_MEMORY_BIOS_CALL
  279. movb %al, (E820NR)
  280. # Try three different memory detection schemes. First, try
  281. # e820h, which lets us assemble a memory map, then try e801h,
  282. # which returns a 32-bit memory size, and finally 88h, which
  283. # returns 0-64m
  284. # method E820H:
  285. # the memory map from hell. e820h returns memory classified into
  286. # a whole bunch of different types, and allows memory holes and
  287. # everything. We scan through this memory map and build a list
  288. # of the first 32 memory areas, which we return at [E820MAP].
  289. # This is documented at http://www.acpi.info/, in the ACPI 2.0 specification.
  290. #define SMAP 0x534d4150
  291. meme820:
  292. xorl %ebx, %ebx # continuation counter
  293. movw $E820MAP, %di # point into the whitelist
  294. # so we can have the bios
  295. # directly write into it.
  296. jmpe820:
  297. movl $0x0000e820, %eax # e820, upper word zeroed
  298. movl $SMAP, %edx # ascii 'SMAP'
  299. movl $20, %ecx # size of the e820rec
  300. pushw %ds # data record.
  301. popw %es
  302. int $0x15 # make the call
  303. jc bail820 # fall to e801 if it fails
  304. cmpl $SMAP, %eax # check the return is `SMAP'
  305. jne bail820 # fall to e801 if it fails
  306. # cmpl $1, 16(%di) # is this usable memory?
  307. # jne again820
  308. # If this is usable memory, we save it by simply advancing %di by
  309. # sizeof(e820rec).
  310. #
  311. good820:
  312. movb (E820NR), %al # up to 128 entries
  313. cmpb $E820MAX, %al
  314. jae bail820
  315. incb (E820NR)
  316. movw %di, %ax
  317. addw $20, %ax
  318. movw %ax, %di
  319. again820:
  320. cmpl $0, %ebx # check to see if
  321. jne jmpe820 # %ebx is set to EOF
  322. bail820:
  323. # method E801H:
  324. # memory size is in 1k chunksizes, to avoid confusing loadlin.
  325. # we store the 0xe801 memory size in a completely different place,
  326. # because it will most likely be longer than 16 bits.
  327. # (use 1e0 because that's what Larry Augustine uses in his
  328. # alternative new memory detection scheme, and it's sensible
  329. # to write everything into the same place.)
  330. meme801:
  331. stc # fix to work around buggy
  332. xorw %cx,%cx # BIOSes which don't clear/set
  333. xorw %dx,%dx # carry on pass/error of
  334. # e801h memory size call
  335. # or merely pass cx,dx though
  336. # without changing them.
  337. movw $0xe801, %ax
  338. int $0x15
  339. jc mem88
  340. cmpw $0x0, %cx # Kludge to handle BIOSes
  341. jne e801usecxdx # which report their extended
  342. cmpw $0x0, %dx # memory in AX/BX rather than
  343. jne e801usecxdx # CX/DX. The spec I have read
  344. movw %ax, %cx # seems to indicate AX/BX
  345. movw %bx, %dx # are more reasonable anyway...
  346. e801usecxdx:
  347. andl $0xffff, %edx # clear sign extend
  348. shll $6, %edx # and go from 64k to 1k chunks
  349. movl %edx, (0x1e0) # store extended memory size
  350. andl $0xffff, %ecx # clear sign extend
  351. addl %ecx, (0x1e0) # and add lower memory into
  352. # total size.
  353. # Ye Olde Traditional Methode. Returns the memory size (up to 16mb or
  354. # 64mb, depending on the bios) in ax.
  355. mem88:
  356. #endif
  357. movb $0x88, %ah
  358. int $0x15
  359. movw %ax, (2)
  360. # Set the keyboard repeat rate to the max
  361. movw $0x0305, %ax
  362. xorw %bx, %bx
  363. int $0x16
  364. # Check for video adapter and its parameters and allow the
  365. # user to browse video modes.
  366. call video # NOTE: we need %ds pointing
  367. # to bootsector
  368. # Get hd0 data...
  369. xorw %ax, %ax
  370. movw %ax, %ds
  371. ldsw (4 * 0x41), %si
  372. movw %cs, %ax # aka SETUPSEG
  373. subw $DELTA_INITSEG, %ax # aka INITSEG
  374. pushw %ax
  375. movw %ax, %es
  376. movw $0x0080, %di
  377. movw $0x10, %cx
  378. pushw %cx
  379. cld
  380. rep
  381. movsb
  382. # Get hd1 data...
  383. xorw %ax, %ax
  384. movw %ax, %ds
  385. ldsw (4 * 0x46), %si
  386. popw %cx
  387. popw %es
  388. movw $0x0090, %di
  389. rep
  390. movsb
  391. # Check that there IS a hd1 :-)
  392. movw $0x01500, %ax
  393. movb $0x81, %dl
  394. int $0x13
  395. jc no_disk1
  396. cmpb $3, %ah
  397. je is_disk1
  398. no_disk1:
  399. movw %cs, %ax # aka SETUPSEG
  400. subw $DELTA_INITSEG, %ax # aka INITSEG
  401. movw %ax, %es
  402. movw $0x0090, %di
  403. movw $0x10, %cx
  404. xorw %ax, %ax
  405. cld
  406. rep
  407. stosb
  408. is_disk1:
  409. # Check for PS/2 pointing device
  410. movw %cs, %ax # aka SETUPSEG
  411. subw $DELTA_INITSEG, %ax # aka INITSEG
  412. movw %ax, %ds
  413. movb $0, (0x1ff) # default is no pointing device
  414. int $0x11 # int 0x11: equipment list
  415. testb $0x04, %al # check if mouse installed
  416. jz no_psmouse
  417. movb $0xAA, (0x1ff) # device present
  418. no_psmouse:
  419. #include "../../i386/boot/edd.S"
  420. # Now we want to move to protected mode ...
  421. cmpw $0, %cs:realmode_swtch
  422. jz rmodeswtch_normal
  423. lcall *%cs:realmode_swtch
  424. jmp rmodeswtch_end
  425. rmodeswtch_normal:
  426. pushw %cs
  427. call default_switch
  428. rmodeswtch_end:
  429. # we get the code32 start address and modify the below 'jmpi'
  430. # (loader may have changed it)
  431. movl %cs:code32_start, %eax
  432. movl %eax, %cs:code32
  433. # Now we move the system to its rightful place ... but we check if we have a
  434. # big-kernel. In that case we *must* not move it ...
  435. testb $LOADED_HIGH, %cs:loadflags
  436. jz do_move0 # .. then we have a normal low
  437. # loaded zImage
  438. # .. or else we have a high
  439. # loaded bzImage
  440. jmp end_move # ... and we skip moving
  441. do_move0:
  442. movw $0x100, %ax # start of destination segment
  443. movw %cs, %bp # aka SETUPSEG
  444. subw $DELTA_INITSEG, %bp # aka INITSEG
  445. movw %cs:start_sys_seg, %bx # start of source segment
  446. cld
  447. do_move:
  448. movw %ax, %es # destination segment
  449. incb %ah # instead of add ax,#0x100
  450. movw %bx, %ds # source segment
  451. addw $0x100, %bx
  452. subw %di, %di
  453. subw %si, %si
  454. movw $0x800, %cx
  455. rep
  456. movsw
  457. cmpw %bp, %bx # assume start_sys_seg > 0x200,
  458. # so we will perhaps read one
  459. # page more than needed, but
  460. # never overwrite INITSEG
  461. # because destination is a
  462. # minimum one page below source
  463. jb do_move
  464. end_move:
  465. # then we load the segment descriptors
  466. movw %cs, %ax # aka SETUPSEG
  467. movw %ax, %ds
  468. # Check whether we need to be downward compatible with version <=201
  469. cmpl $0, cmd_line_ptr
  470. jne end_move_self # loader uses version >=202 features
  471. cmpb $0x20, type_of_loader
  472. je end_move_self # bootsect loader, we know of it
  473. # Boot loader doesnt support boot protocol version 2.02.
  474. # If we have our code not at 0x90000, we need to move it there now.
  475. # We also then need to move the params behind it (commandline)
  476. # Because we would overwrite the code on the current IP, we move
  477. # it in two steps, jumping high after the first one.
  478. movw %cs, %ax
  479. cmpw $SETUPSEG, %ax
  480. je end_move_self
  481. cli # make sure we really have
  482. # interrupts disabled !
  483. # because after this the stack
  484. # should not be used
  485. subw $DELTA_INITSEG, %ax # aka INITSEG
  486. movw %ss, %dx
  487. cmpw %ax, %dx
  488. jb move_self_1
  489. addw $INITSEG, %dx
  490. subw %ax, %dx # this will go into %ss after
  491. # the move
  492. move_self_1:
  493. movw %ax, %ds
  494. movw $INITSEG, %ax # real INITSEG
  495. movw %ax, %es
  496. movw %cs:setup_move_size, %cx
  497. std # we have to move up, so we use
  498. # direction down because the
  499. # areas may overlap
  500. movw %cx, %di
  501. decw %di
  502. movw %di, %si
  503. subw $move_self_here+0x200, %cx
  504. rep
  505. movsb
  506. ljmp $SETUPSEG, $move_self_here
  507. move_self_here:
  508. movw $move_self_here+0x200, %cx
  509. rep
  510. movsb
  511. movw $SETUPSEG, %ax
  512. movw %ax, %ds
  513. movw %dx, %ss
  514. end_move_self: # now we are at the right place
  515. lidt idt_48 # load idt with 0,0
  516. xorl %eax, %eax # Compute gdt_base
  517. movw %ds, %ax # (Convert %ds:gdt to a linear ptr)
  518. shll $4, %eax
  519. addl $gdt, %eax
  520. movl %eax, (gdt_48+2)
  521. lgdt gdt_48 # load gdt with whatever is
  522. # appropriate
  523. # that was painless, now we enable a20
  524. call empty_8042
  525. movb $0xD1, %al # command write
  526. outb %al, $0x64
  527. call empty_8042
  528. movb $0xDF, %al # A20 on
  529. outb %al, $0x60
  530. call empty_8042
  531. #
  532. # You must preserve the other bits here. Otherwise embarrasing things
  533. # like laptops powering off on boot happen. Corrected version by Kira
  534. # Brown from Linux 2.2
  535. #
  536. inb $0x92, %al #
  537. orb $02, %al # "fast A20" version
  538. outb %al, $0x92 # some chips have only this
  539. # wait until a20 really *is* enabled; it can take a fair amount of
  540. # time on certain systems; Toshiba Tecras are known to have this
  541. # problem. The memory location used here (0x200) is the int 0x80
  542. # vector, which should be safe to use.
  543. xorw %ax, %ax # segment 0x0000
  544. movw %ax, %fs
  545. decw %ax # segment 0xffff (HMA)
  546. movw %ax, %gs
  547. a20_wait:
  548. incw %ax # unused memory location <0xfff0
  549. movw %ax, %fs:(0x200) # we use the "int 0x80" vector
  550. cmpw %gs:(0x210), %ax # and its corresponding HMA addr
  551. je a20_wait # loop until no longer aliased
  552. # make sure any possible coprocessor is properly reset..
  553. xorw %ax, %ax
  554. outb %al, $0xf0
  555. call delay
  556. outb %al, $0xf1
  557. call delay
  558. # well, that went ok, I hope. Now we mask all interrupts - the rest
  559. # is done in init_IRQ().
  560. movb $0xFF, %al # mask all interrupts for now
  561. outb %al, $0xA1
  562. call delay
  563. movb $0xFB, %al # mask all irq's but irq2 which
  564. outb %al, $0x21 # is cascaded
  565. # Well, that certainly wasn't fun :-(. Hopefully it works, and we don't
  566. # need no steenking BIOS anyway (except for the initial loading :-).
  567. # The BIOS-routine wants lots of unnecessary data, and it's less
  568. # "interesting" anyway. This is how REAL programmers do it.
  569. #
  570. # Well, now's the time to actually move into protected mode. To make
  571. # things as simple as possible, we do no register set-up or anything,
  572. # we let the gnu-compiled 32-bit programs do that. We just jump to
  573. # absolute address 0x1000 (or the loader supplied one),
  574. # in 32-bit protected mode.
  575. #
  576. # Note that the short jump isn't strictly needed, although there are
  577. # reasons why it might be a good idea. It won't hurt in any case.
  578. movw $1, %ax # protected mode (PE) bit
  579. lmsw %ax # This is it!
  580. jmp flush_instr
  581. flush_instr:
  582. xorw %bx, %bx # Flag to indicate a boot
  583. xorl %esi, %esi # Pointer to real-mode code
  584. movw %cs, %si
  585. subw $DELTA_INITSEG, %si
  586. shll $4, %esi # Convert to 32-bit pointer
  587. # NOTE: For high loaded big kernels we need a
  588. # jmpi 0x100000,__KERNEL_CS
  589. #
  590. # but we yet haven't reloaded the CS register, so the default size
  591. # of the target offset still is 16 bit.
  592. # However, using an operand prefix (0x66), the CPU will properly
  593. # take our 48 bit far pointer. (INTeL 80386 Programmer's Reference
  594. # Manual, Mixing 16-bit and 32-bit code, page 16-6)
  595. .byte 0x66, 0xea # prefix + jmpi-opcode
  596. code32: .long 0x1000 # will be set to 0x100000
  597. # for big kernels
  598. .word __KERNEL_CS
  599. # Here's a bunch of information about your current kernel..
  600. kernel_version: .ascii UTS_RELEASE
  601. .ascii " ("
  602. .ascii LINUX_COMPILE_BY
  603. .ascii "@"
  604. .ascii LINUX_COMPILE_HOST
  605. .ascii ") "
  606. .ascii UTS_VERSION
  607. .byte 0
  608. # This is the default real mode switch routine.
  609. # to be called just before protected mode transition
  610. default_switch:
  611. cli # no interrupts allowed !
  612. movb $0x80, %al # disable NMI for bootup
  613. # sequence
  614. outb %al, $0x70
  615. lret
  616. # This routine checks that the keyboard command queue is empty
  617. # (after emptying the output buffers)
  618. #
  619. # Some machines have delusions that the keyboard buffer is always full
  620. # with no keyboard attached...
  621. #
  622. # If there is no keyboard controller, we will usually get 0xff
  623. # to all the reads. With each IO taking a microsecond and
  624. # a timeout of 100,000 iterations, this can take about half a
  625. # second ("delay" == outb to port 0x80). That should be ok,
  626. # and should also be plenty of time for a real keyboard controller
  627. # to empty.
  628. #
  629. empty_8042:
  630. pushl %ecx
  631. movl $100000, %ecx
  632. empty_8042_loop:
  633. decl %ecx
  634. jz empty_8042_end_loop
  635. call delay
  636. inb $0x64, %al # 8042 status port
  637. testb $1, %al # output buffer?
  638. jz no_output
  639. call delay
  640. inb $0x60, %al # read it
  641. jmp empty_8042_loop
  642. no_output:
  643. testb $2, %al # is input buffer full?
  644. jnz empty_8042_loop # yes - loop
  645. empty_8042_end_loop:
  646. popl %ecx
  647. ret
  648. # Read the cmos clock. Return the seconds in al
  649. gettime:
  650. pushw %cx
  651. movb $0x02, %ah
  652. int $0x1a
  653. movb %dh, %al # %dh contains the seconds
  654. andb $0x0f, %al
  655. movb %dh, %ah
  656. movb $0x04, %cl
  657. shrb %cl, %ah
  658. aad
  659. popw %cx
  660. ret
  661. # Delay is needed after doing I/O
  662. delay:
  663. outb %al,$0x80
  664. ret
  665. # Descriptor tables
  666. gdt:
  667. .word 0, 0, 0, 0 # dummy
  668. .word 0, 0, 0, 0 # unused
  669. .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
  670. .word 0 # base address = 0
  671. .word 0x9A00 # code read/exec
  672. .word 0x00CF # granularity = 4096, 386
  673. # (+5th nibble of limit)
  674. .word 0xFFFF # 4Gb - (0x100000*0x1000 = 4Gb)
  675. .word 0 # base address = 0
  676. .word 0x9200 # data read/write
  677. .word 0x00CF # granularity = 4096, 386
  678. # (+5th nibble of limit)
  679. gdt_end:
  680. idt_48:
  681. .word 0 # idt limit = 0
  682. .word 0, 0 # idt base = 0L
  683. gdt_48:
  684. .word gdt_end-gdt-1 # gdt limit
  685. .word 0, 0 # gdt base (filled in later)
  686. # Include video setup & detection code
  687. #include "video.S"
  688. # Setup signature -- must be last
  689. setup_sig1: .word SIG1
  690. setup_sig2: .word SIG2
  691. # After this point, there is some free space which is used by the video mode
  692. # handling code to store the temporary mode table (not used by the kernel).
  693. modelist:
  694. .text
  695. endtext:
  696. .data
  697. enddata:
  698. .bss
  699. endbss: