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

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