You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

romprefix.S 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /* At entry, the processor is in 16 bit real mode and the code is being
  2. * executed from an address it was not linked to. Code must be pic and
  3. * 32 bit sensitive until things are fixed up.
  4. *
  5. * Also be very careful as the stack is at the rear end of the interrupt
  6. * table so using a noticeable amount of stack space is a no-no.
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER )
  9. #include <config/general.h>
  10. #define PNP_SIGNATURE ( '$' + ( 'P' << 8 ) + ( 'n' << 16 ) + ( 'P' << 24 ) )
  11. #define PMM_SIGNATURE ( '$' + ( 'P' << 8 ) + ( 'M' << 16 ) + ( 'M' << 24 ) )
  12. #define PCI_SIGNATURE ( 'P' + ( 'C' << 8 ) + ( 'I' << 16 ) + ( ' ' << 24 ) )
  13. #define STACK_MAGIC ( 'L' + ( 'R' << 8 ) + ( 'E' << 16 ) + ( 'T' << 24 ) )
  14. #define PNP_GET_BBS_VERSION 0x60
  15. #define PMM_ALLOCATE 0x0000
  16. #define PMM_DEALLOCATE 0x0002
  17. /* ROM banner timeout. Based on the configurable BANNER_TIMEOUT in
  18. * config.h, but converted to a number of (18Hz) timer ticks, and
  19. * doubled to allow for BIOSes that switch video modes immediately
  20. * beforehand, so rendering the message almost invisible to the user.
  21. */
  22. #define ROM_BANNER_TIMEOUT ( 2 * ( 18 * BANNER_TIMEOUT ) / 10 )
  23. .text
  24. .code16
  25. .arch i386
  26. .section ".prefix", "ax", @progbits
  27. .org 0x00
  28. romheader:
  29. .word 0xAA55 /* BIOS extension signature */
  30. romheader_size: .byte 0 /* Size in 512-byte blocks */
  31. jmp init /* Initialisation vector */
  32. checksum:
  33. .byte 0
  34. .org 0x16
  35. .word undiheader
  36. .org 0x18
  37. .word pciheader
  38. .org 0x1a
  39. .word pnpheader
  40. .size romheader, . - romheader
  41. .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
  42. .ascii "ADDB"
  43. .long romheader_size
  44. .long 512
  45. .long 0
  46. .previous
  47. pciheader:
  48. .ascii "PCIR" /* Signature */
  49. .word pci_vendor_id /* Vendor identification */
  50. .word pci_device_id /* Device identification */
  51. .word 0x0000 /* Device list pointer */
  52. .word pciheader_len /* PCI data structure length */
  53. .byte 0x03 /* PCI data structure revision */
  54. .byte 0x02, 0x00, 0x00 /* Class code */
  55. pciheader_image_length:
  56. .word 0 /* Image length */
  57. .word 0x0001 /* Revision level */
  58. .byte 0x00 /* Code type */
  59. .byte 0x80 /* Last image indicator */
  60. pciheader_runtime_length:
  61. .word 0 /* Maximum run-time image length */
  62. .word 0x0000 /* Configuration utility code header */
  63. .word 0x0000 /* DMTF CLP entry point */
  64. .equ pciheader_len, . - pciheader
  65. .size pciheader, . - pciheader
  66. .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
  67. .ascii "ADDW"
  68. .long pciheader_image_length
  69. .long 512
  70. .long 0
  71. .ascii "ADDW"
  72. .long pciheader_runtime_length
  73. .long 512
  74. .long 0
  75. .previous
  76. pnpheader:
  77. .ascii "$PnP" /* Signature */
  78. .byte 0x01 /* Structure revision */
  79. .byte ( pnpheader_len / 16 ) /* Length (in 16 byte increments) */
  80. .word 0x0000 /* Offset of next header */
  81. .byte 0x00 /* Reserved */
  82. .byte 0x00 /* Checksum */
  83. .long 0x00000000 /* Device identifier */
  84. .word mfgstr /* Manufacturer string */
  85. .word prodstr /* Product name */
  86. .byte 0x02 /* Device base type code */
  87. .byte 0x00 /* Device sub-type code */
  88. .byte 0x00 /* Device interface type code */
  89. .byte 0xf4 /* Device indicator */
  90. .word 0x0000 /* Boot connection vector */
  91. .word 0x0000 /* Disconnect vector */
  92. .word bev_entry /* Boot execution vector */
  93. .word 0x0000 /* Reserved */
  94. .word 0x0000 /* Static resource information vector*/
  95. .equ pnpheader_len, . - pnpheader
  96. .size pnpheader, . - pnpheader
  97. /* Manufacturer string */
  98. mfgstr:
  99. .asciz "http://ipxe.org"
  100. .size mfgstr, . - mfgstr
  101. /* Product string
  102. *
  103. * Defaults to PRODUCT_SHORT_NAME. If the ROM image is writable at
  104. * initialisation time, it will be filled in to include the PCI
  105. * bus:dev.fn number of the card as well.
  106. */
  107. prodstr:
  108. .ascii PRODUCT_SHORT_NAME
  109. prodstr_separator:
  110. .byte 0
  111. .ascii "(PCI "
  112. prodstr_pci_id:
  113. .asciz "xx:xx.x)" /* Filled in by init code */
  114. .size prodstr, . - prodstr
  115. .globl undiheader
  116. .weak undiloader
  117. undiheader:
  118. .ascii "UNDI" /* Signature */
  119. .byte undiheader_len /* Length of structure */
  120. .byte 0 /* Checksum */
  121. .byte 0 /* Structure revision */
  122. .byte 0,1,2 /* PXE version: 2.1.0 */
  123. .word undiloader /* Offset to loader routine */
  124. .word _data16_memsz /* Stack segment size */
  125. .word _data16_memsz /* Data segment size */
  126. .word _text16_memsz /* Code segment size */
  127. .ascii "PCIR" /* Bus type */
  128. .equ undiheader_len, . - undiheader
  129. .size undiheader, . - undiheader
  130. /* Initialisation (called once during POST)
  131. *
  132. * Determine whether or not this is a PnP system via a signature
  133. * check. If it is PnP, return to the PnP BIOS indicating that we are
  134. * a boot-capable device; the BIOS will call our boot execution vector
  135. * if it wants to boot us. If it is not PnP, hook INT 19.
  136. */
  137. init:
  138. /* Preserve registers, clear direction flag, set %ds=%cs */
  139. pushaw
  140. pushw %ds
  141. pushw %es
  142. pushw %fs
  143. pushw %gs
  144. cld
  145. pushw %cs
  146. popw %ds
  147. /* Shuffle some registers around. We need %di available for
  148. * the print_xxx functions, and in a register that's
  149. * addressable from %es, so shuffle as follows:
  150. *
  151. * %di (pointer to PnP structure) => %bx
  152. * %bx (runtime segment address, for PCI 3.0) => %gs
  153. */
  154. movw %bx, %gs
  155. movw %di, %bx
  156. /* Print message as early as possible */
  157. movw $init_message, %si
  158. xorw %di, %di
  159. call print_message
  160. call print_pci_busdevfn
  161. /* Fill in product name string, if possible */
  162. movw $prodstr_pci_id, %di
  163. call print_pci_busdevfn
  164. movb $( ' ' ), prodstr_separator
  165. /* Print segment address */
  166. movb $( ' ' ), %al
  167. xorw %di, %di
  168. call print_character
  169. movw %cs, %ax
  170. call print_hex_word
  171. /* Check for PCI BIOS version */
  172. pushl %ebx
  173. pushl %edx
  174. pushl %edi
  175. stc
  176. movw $0xb101, %ax
  177. int $0x1a
  178. jc no_pci3
  179. cmpl $PCI_SIGNATURE, %edx
  180. jne no_pci3
  181. testb %ah, %ah
  182. jnz no_pci3
  183. movw $init_message_pci, %si
  184. xorw %di, %di
  185. call print_message
  186. movb %bh, %al
  187. call print_hex_nibble
  188. movb $( '.' ), %al
  189. call print_character
  190. movb %bl, %al
  191. call print_hex_byte
  192. cmpb $3, %bh
  193. jb no_pci3
  194. /* PCI >=3.0: leave %gs as-is if sane */
  195. movw %gs, %ax
  196. cmpw $0xa000, %ax /* Insane if %gs < 0xa000 */
  197. jb pci3_insane
  198. movw %cs, %bx /* Sane if %cs == %gs */
  199. cmpw %bx, %ax
  200. je 1f
  201. movzbw romheader_size, %cx /* Sane if %cs+len <= %gs */
  202. shlw $5, %cx
  203. addw %cx, %bx
  204. cmpw %bx, %ax
  205. jae 1f
  206. movw %cs, %bx /* Sane if %gs+len <= %cs */
  207. addw %cx, %ax
  208. cmpw %bx, %ax
  209. jbe 1f
  210. pci3_insane: /* PCI 3.0 with insane %gs value: print error and ignore %gs */
  211. movb $( '!' ), %al
  212. call print_character
  213. movw %gs, %ax
  214. call print_hex_word
  215. no_pci3:
  216. /* PCI <3.0: set %gs (runtime segment) = %cs (init-time segment) */
  217. pushw %cs
  218. popw %gs
  219. 1: popl %edi
  220. popl %edx
  221. popl %ebx
  222. /* Check for PnP BIOS. Although %es:di should point to the
  223. * PnP BIOS signature on entry, some BIOSes fail to do this.
  224. */
  225. movw $( 0xf000 - 1 ), %bx
  226. pnp_scan:
  227. incw %bx
  228. jz no_pnp
  229. movw %bx, %es
  230. cmpl $PNP_SIGNATURE, %es:0
  231. jne pnp_scan
  232. xorw %dx, %dx
  233. xorw %si, %si
  234. movzbw %es:5, %cx
  235. 1: es lodsb
  236. addb %al, %dl
  237. loop 1b
  238. jnz pnp_scan
  239. /* Is PnP: print PnP message */
  240. movw $init_message_pnp, %si
  241. xorw %di, %di
  242. call print_message
  243. /* Check for BBS */
  244. pushw %es:0x1b /* Real-mode data segment */
  245. pushw %ds /* &(bbs_version) */
  246. pushw $bbs_version
  247. pushw $PNP_GET_BBS_VERSION
  248. lcall *%es:0xd
  249. addw $8, %sp
  250. testw %ax, %ax
  251. je got_bbs
  252. no_pnp: /* Not PnP-compliant - therefore cannot be BBS-compliant */
  253. no_bbs: /* Not BBS-compliant - must hook INT 19 */
  254. movw $init_message_int19, %si
  255. xorw %di, %di
  256. call print_message
  257. xorw %ax, %ax
  258. movw %ax, %es
  259. pushl %es:( 0x19 * 4 )
  260. popl orig_int19
  261. pushw %gs /* %gs contains runtime %cs */
  262. pushw $int19_entry
  263. popl %es:( 0x19 * 4 )
  264. jmp bbs_done
  265. got_bbs: /* BBS compliant - no need to hook INT 19 */
  266. movw $init_message_bbs, %si
  267. xorw %di, %di
  268. call print_message
  269. bbs_done:
  270. /* Check for PMM */
  271. movw $( 0xe000 - 1 ), %bx
  272. pmm_scan:
  273. incw %bx
  274. jz no_pmm
  275. movw %bx, %es
  276. cmpl $PMM_SIGNATURE, %es:0
  277. jne pmm_scan
  278. xorw %dx, %dx
  279. xorw %si, %si
  280. movzbw %es:5, %cx
  281. 1: es lodsb
  282. addb %al, %dl
  283. loop 1b
  284. jnz pmm_scan
  285. /* PMM found: print PMM message */
  286. movw $init_message_pmm, %si
  287. xorw %di, %di
  288. call print_message
  289. /* We have PMM and so a 1kB stack: preserve upper register halves */
  290. pushal
  291. /* Calculate required allocation size in %esi */
  292. movzbl romheader_size, %eax
  293. shll $9, %eax
  294. addl $_textdata_memsz, %eax
  295. orw $0xffff, %ax /* Ensure allocation size is at least 64kB */
  296. bsrl %eax, %ecx
  297. subw $15, %cx /* Round up and convert to 64kB count */
  298. movw $1, %si
  299. shlw %cl, %si
  300. pmm_loop:
  301. /* Try to allocate block via PMM */
  302. pushw $0x0006 /* Aligned, extended memory */
  303. pushl $0xffffffff /* No handle */
  304. movzwl %si, %eax
  305. shll $12, %eax
  306. pushl %eax /* Allocation size in paragraphs */
  307. pushw $PMM_ALLOCATE
  308. lcall *%es:7
  309. addw $12, %sp
  310. /* Abort if allocation fails */
  311. testw %dx, %dx /* %ax==0 even on success, since align>=64kB */
  312. jz pmm_fail
  313. /* If block has A20==1, free block and try again with twice
  314. * the allocation size (and hence alignment).
  315. */
  316. testw $0x0010, %dx
  317. jz got_pmm
  318. pushw %dx
  319. pushw $0
  320. pushw $PMM_DEALLOCATE
  321. lcall *%es:7
  322. addw $6, %sp
  323. addw %si, %si
  324. jmp pmm_loop
  325. got_pmm: /* PMM allocation succeeded */
  326. movw %dx, ( image_source + 2 )
  327. movw %dx, %ax
  328. xorw %di, %di
  329. call print_hex_word
  330. movb $( '@' ), %al
  331. call print_character
  332. movw %si, %ax
  333. call print_hex_byte
  334. /* Copy ROM to PMM block */
  335. xorw %ax, %ax
  336. movw %ax, %es
  337. movl image_source, %edi
  338. xorl %esi, %esi
  339. movzbl romheader_size, %ecx
  340. shll $9, %ecx
  341. addr32 rep movsb /* PMM presence implies flat real mode */
  342. movl %edi, decompress_to
  343. /* Shrink ROM */
  344. movb $_prefix_memsz_sect, romheader_size
  345. pmm_fail:
  346. /* Restore upper register halves */
  347. popal
  348. no_pmm:
  349. /* Update checksum */
  350. xorw %bx, %bx
  351. xorw %si, %si
  352. movzbw romheader_size, %cx
  353. shlw $9, %cx
  354. 1: lodsb
  355. addb %al, %bl
  356. loop 1b
  357. subb %bl, checksum
  358. /* Copy self to option ROM space. Required for PCI3.0, which
  359. * loads us to a temporary location in low memory. Will be a
  360. * no-op for lower PCI versions.
  361. */
  362. movb $( ' ' ), %al
  363. xorw %di, %di
  364. call print_character
  365. movw %gs, %ax
  366. call print_hex_word
  367. movzbw romheader_size, %cx
  368. shlw $9, %cx
  369. movw %ax, %es
  370. xorw %si, %si
  371. xorw %di, %di
  372. cs rep movsb
  373. /* Prompt for POST-time shell */
  374. movw $init_message_prompt, %si
  375. xorw %di, %di
  376. call print_message
  377. movw $prodstr, %si
  378. call print_message
  379. movw $init_message_dots, %si
  380. call print_message
  381. /* Wait for Ctrl-B */
  382. movw $0xff02, %bx
  383. call wait_for_key
  384. /* Clear prompt */
  385. pushf
  386. xorw %di, %di
  387. call print_kill_line
  388. movw $init_message_done, %si
  389. call print_message
  390. popf
  391. jnz 2f
  392. /* Ctrl-B was pressed: invoke iPXE. The keypress will be
  393. * picked up by the initial shell prompt, and we will drop
  394. * into a shell.
  395. */
  396. pushw %cs
  397. call exec
  398. 2:
  399. /* Restore registers */
  400. popw %gs
  401. popw %fs
  402. popw %es
  403. popw %ds
  404. popaw
  405. /* Indicate boot capability to PnP BIOS, if present */
  406. movw $0x20, %ax
  407. lret
  408. .size init, . - init
  409. /*
  410. * Note to hardware vendors:
  411. *
  412. * If you wish to brand this boot ROM, please do so by defining the
  413. * strings PRODUCT_NAME and PRODUCT_SHORT_NAME in config/general.h.
  414. *
  415. * While nothing in the GPL prevents you from removing all references
  416. * to iPXE or http://ipxe.org, we prefer you not to do so.
  417. *
  418. * If you have an OEM-mandated branding requirement that cannot be
  419. * satisfied simply by defining PRODUCT_NAME and PRODUCT_SHORT_NAME,
  420. * please contact us.
  421. *
  422. * [ Including an ASCII NUL in PRODUCT_NAME is considered to be
  423. * bypassing the spirit of this request! ]
  424. */
  425. init_message:
  426. .ascii "\n"
  427. .ascii PRODUCT_NAME
  428. .ascii "\n"
  429. .asciz "iPXE (http://ipxe.org) - "
  430. .size init_message, . - init_message
  431. init_message_pci:
  432. .asciz " PCI"
  433. .size init_message_pci, . - init_message_pci
  434. init_message_pnp:
  435. .asciz " PnP"
  436. .size init_message_pnp, . - init_message_pnp
  437. init_message_bbs:
  438. .asciz " BBS"
  439. .size init_message_bbs, . - init_message_bbs
  440. init_message_pmm:
  441. .asciz " PMM"
  442. .size init_message_pmm, . - init_message_pmm
  443. init_message_int19:
  444. .asciz " INT19"
  445. .size init_message_int19, . - init_message_int19
  446. init_message_prompt:
  447. .asciz "\nPress Ctrl-B to configure "
  448. .size init_message_prompt, . - init_message_prompt
  449. init_message_dots:
  450. .asciz "..."
  451. .size init_message_dots, . - init_message_dots
  452. init_message_done:
  453. .asciz "\n\n"
  454. .size init_message_done, . - init_message_done
  455. /* ROM image location
  456. *
  457. * May be either within option ROM space, or within PMM-allocated block.
  458. */
  459. .globl image_source
  460. image_source:
  461. .long 0
  462. .size image_source, . - image_source
  463. /* Temporary decompression area
  464. *
  465. * May be either at HIGHMEM_LOADPOINT, or within PMM-allocated block.
  466. */
  467. .globl decompress_to
  468. decompress_to:
  469. .long HIGHMEM_LOADPOINT
  470. .size decompress_to, . - decompress_to
  471. /* BBS version
  472. *
  473. * Filled in by BBS BIOS. We ignore the value.
  474. */
  475. bbs_version:
  476. .word 0
  477. .size bbs_version, . - bbs_version
  478. /* Boot Execution Vector entry point
  479. *
  480. * Called by the PnP BIOS when it wants to boot us.
  481. */
  482. bev_entry:
  483. pushw %cs
  484. call exec
  485. lret
  486. .size bev_entry, . - bev_entry
  487. /* INT19 entry point
  488. *
  489. * Called via the hooked INT 19 if we detected a non-PnP BIOS. We
  490. * attempt to return via the original INT 19 vector (if we were able
  491. * to store it).
  492. */
  493. int19_entry:
  494. pushw %cs
  495. popw %ds
  496. /* Prompt user to press B to boot */
  497. movw $int19_message_prompt, %si
  498. xorw %di, %di
  499. call print_message
  500. movw $prodstr, %si
  501. call print_message
  502. movw $int19_message_dots, %si
  503. call print_message
  504. movw $0xdf4e, %bx
  505. call wait_for_key
  506. pushf
  507. xorw %di, %di
  508. call print_kill_line
  509. movw $int19_message_done, %si
  510. call print_message
  511. popf
  512. jz 1f
  513. /* Leave keypress in buffer and start iPXE. The keypress will
  514. * cause the usual initial Ctrl-B prompt to be skipped.
  515. */
  516. pushw %cs
  517. call exec
  518. 1: /* Try to call original INT 19 vector */
  519. movl %cs:orig_int19, %eax
  520. testl %eax, %eax
  521. je 2f
  522. ljmp *%cs:orig_int19
  523. 2: /* No chained vector: issue INT 18 as a last resort */
  524. int $0x18
  525. .size int19_entry, . - int19_entry
  526. orig_int19:
  527. .long 0
  528. .size orig_int19, . - orig_int19
  529. int19_message_prompt:
  530. .asciz "Press N to skip booting from "
  531. .size int19_message_prompt, . - int19_message_prompt
  532. int19_message_dots:
  533. .asciz "..."
  534. .size int19_message_dots, . - int19_message_dots
  535. int19_message_done:
  536. .asciz "\n\n"
  537. .size int19_message_done, . - int19_message_done
  538. /* Execute as a boot device
  539. *
  540. */
  541. exec: /* Set %ds = %cs */
  542. pushw %cs
  543. popw %ds
  544. /* Print message as soon as possible */
  545. movw $prodstr, %si
  546. xorw %di, %di
  547. call print_message
  548. movw $exec_message, %si
  549. call print_message
  550. /* Store magic word on BIOS stack and remember BIOS %ss:sp */
  551. pushl $STACK_MAGIC
  552. movw %ss, %dx
  553. movw %sp, %bp
  554. /* Obtain a reasonably-sized temporary stack */
  555. xorw %ax, %ax
  556. movw %ax, %ss
  557. movw $0x7c00, %sp
  558. /* Install iPXE */
  559. movl image_source, %esi
  560. movl decompress_to, %edi
  561. call alloc_basemem
  562. call install_prealloc
  563. /* Set up real-mode stack */
  564. movw %bx, %ss
  565. movw $_estack16, %sp
  566. /* Jump to .text16 segment */
  567. pushw %ax
  568. pushw $1f
  569. lret
  570. .section ".text16", "awx", @progbits
  571. 1: /* Call main() */
  572. pushl $main
  573. pushw %cs
  574. call prot_call
  575. popl %ecx /* discard */
  576. /* Uninstall iPXE */
  577. call uninstall
  578. /* Restore BIOS stack */
  579. movw %dx, %ss
  580. movw %bp, %sp
  581. /* Check magic word on BIOS stack */
  582. popl %eax
  583. cmpl $STACK_MAGIC, %eax
  584. jne 1f
  585. /* BIOS stack OK: return to caller */
  586. lret
  587. 1: /* BIOS stack corrupt: use INT 18 */
  588. int $0x18
  589. .previous
  590. exec_message:
  591. .asciz " starting execution\n"
  592. .size exec_message, . - exec_message
  593. /* Wait for key press specified by %bl (masked by %bh)
  594. *
  595. * Used by init and INT19 code when prompting user. If the specified
  596. * key is pressed, it is left in the keyboard buffer.
  597. *
  598. * Returns with ZF set iff specified key is pressed.
  599. */
  600. wait_for_key:
  601. /* Preserve registers */
  602. pushw %cx
  603. pushw %ax
  604. 1: /* Empty the keyboard buffer before waiting for input */
  605. movb $0x01, %ah
  606. int $0x16
  607. jz 2f
  608. xorw %ax, %ax
  609. int $0x16
  610. jmp 1b
  611. 2: /* Wait for a key press */
  612. movw $ROM_BANNER_TIMEOUT, %cx
  613. 3: decw %cx
  614. js 99f /* Exit with ZF clear */
  615. /* Wait for timer tick to be updated */
  616. call wait_for_tick
  617. /* Check to see if a key was pressed */
  618. movb $0x01, %ah
  619. int $0x16
  620. jz 3b
  621. /* Check to see if key was the specified key */
  622. andb %bh, %al
  623. cmpb %al, %bl
  624. je 99f /* Exit with ZF set */
  625. /* Not the specified key: remove from buffer and stop waiting */
  626. pushfw
  627. xorw %ax, %ax
  628. int $0x16
  629. popfw /* Exit with ZF clear */
  630. 99: /* Restore registers and return */
  631. popw %ax
  632. popw %cx
  633. ret
  634. .size wait_for_key, . - wait_for_key
  635. /* Wait for timer tick
  636. *
  637. * Used by wait_for_key
  638. */
  639. wait_for_tick:
  640. pushl %eax
  641. pushw %fs
  642. movw $0x40, %ax
  643. movw %ax, %fs
  644. movl %fs:(0x6c), %eax
  645. 1: pushf
  646. sti
  647. hlt
  648. popf
  649. cmpl %fs:(0x6c), %eax
  650. je 1b
  651. popw %fs
  652. popl %eax
  653. ret
  654. .size wait_for_tick, . - wait_for_tick