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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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. #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. .asciz " (http://ipxe.org)"
  560. .size init_message, . - init_message
  561. .ifeqs BUSTYPE, "PCIR"
  562. init_message_pci:
  563. .asciz " PCI"
  564. .size init_message_pci, . - init_message_pci
  565. .endif /* PCIR */
  566. init_message_pnp:
  567. .asciz " PnP"
  568. .size init_message_pnp, . - init_message_pnp
  569. init_message_pmm:
  570. .asciz " PMM"
  571. .size init_message_pmm, . - init_message_pmm
  572. init_message_int19:
  573. .asciz " INT19"
  574. .size init_message_int19, . - init_message_int19
  575. init_message_prompt:
  576. .asciz "\nPress Ctrl-B to configure "
  577. .size init_message_prompt, . - init_message_prompt
  578. init_message_dots:
  579. .asciz "..."
  580. .size init_message_dots, . - init_message_dots
  581. init_message_done:
  582. .asciz "\n\n"
  583. .size init_message_done, . - init_message_done
  584. /* PCI bus:dev.fn
  585. *
  586. */
  587. .ifeqs BUSTYPE, "PCIR"
  588. init_pci_busdevfn:
  589. .word 0
  590. .size init_pci_busdevfn, . - init_pci_busdevfn
  591. .endif /* PCIR */
  592. /* Image source area
  593. *
  594. * May be either zero (indicating to use option ROM space as source),
  595. * or within a PMM-allocated block.
  596. */
  597. .globl image_source
  598. image_source:
  599. .long 0
  600. .size image_source, . - image_source
  601. /* Additional image source size (in 512-byte sectors)
  602. *
  603. */
  604. extra_size:
  605. .word 0
  606. .size extra_size, . - extra_size
  607. /* Temporary decompression area
  608. *
  609. * May be either zero (indicating to use default decompression area in
  610. * high memory), or within a PMM-allocated block.
  611. */
  612. .globl decompress_to
  613. decompress_to:
  614. .long 0
  615. .size decompress_to, . - decompress_to
  616. /* Boot Execution Vector entry point
  617. *
  618. * Called by the PnP BIOS when it wants to boot us.
  619. */
  620. bev_entry:
  621. orl $0xffffffff, %ebp /* Allow arbitrary relocation */
  622. pushw %cs
  623. call exec
  624. lret
  625. .size bev_entry, . - bev_entry
  626. /* INT19 entry point
  627. *
  628. * Called via the hooked INT 19 if we detected a non-PnP BIOS. We
  629. * attempt to return via the original INT 19 vector (if we were able
  630. * to store it).
  631. */
  632. int19_entry:
  633. pushw %cs
  634. popw %ds
  635. /* Prompt user to press B to boot */
  636. movw $int19_message_prompt, %si
  637. xorw %di, %di
  638. call print_message
  639. movw $prodstr, %si
  640. call print_message
  641. movw $int19_message_dots, %si
  642. call print_message
  643. movw $0xdf4e, %bx
  644. call wait_for_key
  645. pushf
  646. xorw %di, %di
  647. call print_kill_line
  648. movw $int19_message_done, %si
  649. call print_message
  650. popf
  651. jz 1f
  652. /* Leave keypress in buffer and start iPXE. The keypress will
  653. * cause the usual initial Ctrl-B prompt to be skipped.
  654. */
  655. orl $0xffffffff, %ebp /* Allow arbitrary relocation */
  656. pushw %cs
  657. call exec
  658. 1: /* Try to call original INT 19 vector */
  659. movl %cs:orig_int19, %eax
  660. testl %eax, %eax
  661. je 2f
  662. ljmp *%cs:orig_int19
  663. 2: /* No chained vector: issue INT 18 as a last resort */
  664. int $0x18
  665. .size int19_entry, . - int19_entry
  666. orig_int19:
  667. .long 0
  668. .size orig_int19, . - orig_int19
  669. int19_message_prompt:
  670. .asciz "Press N to skip booting from "
  671. .size int19_message_prompt, . - int19_message_prompt
  672. int19_message_dots:
  673. .asciz "..."
  674. .size int19_message_dots, . - int19_message_dots
  675. int19_message_done:
  676. .asciz "\n\n"
  677. .size int19_message_done, . - int19_message_done
  678. /* Execute as a boot device
  679. *
  680. */
  681. exec: /* Set %ds = %cs */
  682. pushw %cs
  683. popw %ds
  684. /* Print message as soon as possible */
  685. movw $prodstr, %si
  686. xorw %di, %di
  687. call print_message
  688. movw $exec_message_pre_install, %si
  689. call print_message
  690. /* Store magic word on BIOS stack and remember BIOS %ss:sp */
  691. pushl $STACK_MAGIC
  692. movw %ss, %cx
  693. movw %sp, %dx
  694. /* Obtain a reasonably-sized temporary stack */
  695. xorw %bx, %bx
  696. movw %bx, %ss
  697. movw $0x7c00, %sp
  698. /* Install iPXE */
  699. call alloc_basemem
  700. movl image_source, %esi
  701. movl decompress_to, %edi
  702. call install_prealloc
  703. /* Print message indicating successful installation */
  704. movw $exec_message_post_install, %si
  705. xorw %di, %di
  706. call print_message
  707. /* Set up real-mode stack */
  708. movw %bx, %ss
  709. movw $_estack16, %sp
  710. /* Jump to .text16 segment */
  711. pushw %ax
  712. pushw $1f
  713. lret
  714. .section ".text16", "awx", @progbits
  715. 1:
  716. /* Retrieve PCI bus:dev.fn, if applicable */
  717. .ifeqs BUSTYPE, "PCIR"
  718. movw init_pci_busdevfn, %ax
  719. .endif
  720. /* Set up %ds for access to .data16 */
  721. movw %bx, %ds
  722. /* Store PCI bus:dev.fn, if applicable */
  723. .ifeqs BUSTYPE, "PCIR"
  724. movw %ax, autoboot_busdevfn
  725. .endif
  726. /* Call main() */
  727. pushl $main
  728. pushw %cs
  729. call prot_call
  730. popl %eax /* discard */
  731. /* Set up flat real mode for return to BIOS */
  732. call flatten_real_mode
  733. /* Uninstall iPXE */
  734. call uninstall
  735. /* Restore BIOS stack */
  736. movw %cx, %ss
  737. movw %dx, %sp
  738. /* Check magic word on BIOS stack */
  739. popl %eax
  740. cmpl $STACK_MAGIC, %eax
  741. jne 1f
  742. /* BIOS stack OK: return to caller */
  743. lret
  744. 1: /* BIOS stack corrupt: use INT 18 */
  745. int $0x18
  746. .previous
  747. exec_message_pre_install:
  748. .asciz " starting execution..."
  749. .size exec_message_pre_install, . - exec_message_pre_install
  750. exec_message_post_install:
  751. .asciz "ok\n"
  752. .size exec_message_post_install, . - exec_message_post_install
  753. /* Wait for key press specified by %bl (masked by %bh)
  754. *
  755. * Used by init and INT19 code when prompting user. If the specified
  756. * key is pressed, it is left in the keyboard buffer.
  757. *
  758. * Returns with ZF set iff specified key is pressed.
  759. */
  760. wait_for_key:
  761. /* Preserve registers */
  762. pushw %cx
  763. pushw %ax
  764. 1: /* Empty the keyboard buffer before waiting for input */
  765. movb $0x01, %ah
  766. int $0x16
  767. jz 2f
  768. xorw %ax, %ax
  769. int $0x16
  770. jmp 1b
  771. 2: /* Wait for a key press */
  772. movw $ROM_BANNER_TIMEOUT_TICKS, %cx
  773. 3: decw %cx
  774. js 99f /* Exit with ZF clear */
  775. /* Wait for timer tick to be updated */
  776. call wait_for_tick
  777. /* Check to see if a key was pressed */
  778. movb $0x01, %ah
  779. int $0x16
  780. jz 3b
  781. /* Check to see if key was the specified key */
  782. andb %bh, %al
  783. cmpb %al, %bl
  784. je 99f /* Exit with ZF set */
  785. /* Not the specified key: remove from buffer and stop waiting */
  786. pushfw
  787. xorw %ax, %ax
  788. int $0x16
  789. popfw /* Exit with ZF clear */
  790. 99: /* Restore registers and return */
  791. popw %ax
  792. popw %cx
  793. ret
  794. .size wait_for_key, . - wait_for_key
  795. /* Wait for timer tick
  796. *
  797. * Used by wait_for_key
  798. */
  799. wait_for_tick:
  800. pushl %eax
  801. pushw %fs
  802. movw $0x40, %ax
  803. movw %ax, %fs
  804. movl %fs:(0x6c), %eax
  805. 1: pushf
  806. sti
  807. hlt
  808. popf
  809. cmpl %fs:(0x6c), %eax
  810. je 1b
  811. popw %fs
  812. popl %eax
  813. ret
  814. .size wait_for_tick, . - wait_for_tick