Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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