Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

romprefix.S 21KB

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