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 19KB

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