setup.S 21 KB

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