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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. .text
  9. .code16
  10. .arch i386
  11. .section ".prefix", "ax", @progbits
  12. .org 0x00
  13. romheader:
  14. .word 0xAA55 /* BIOS extension signature */
  15. .byte _rom_size /* Size in 512-byte blocks */
  16. jmp init_vector /* Initialisation vector */
  17. .org 0x16
  18. .word undiheader
  19. .org 0x18
  20. .word pciheader
  21. .org 0x1a
  22. .word pnpheader
  23. .size romheader, . - romheader
  24. pciheader:
  25. .ascii "PCIR" /* Signature */
  26. .word pci_vendor_id /* Vendor ID */
  27. .word pci_device_id /* Device ID */
  28. .word 0x0000 /* pointer to vital product data */
  29. .word pciheader_len /* PCI data structure length */
  30. .byte 0x00 /* PCI data structure revision */
  31. .byte 0x02 /* Device Base Type code */
  32. .byte 0x00 /* Device Sub-Type code */
  33. .byte 0x00 /* Device Interface Type code */
  34. .word _rom_size /* Image length same as offset 02h */
  35. .word 0x0001 /* revision level of code/data */
  36. .byte 0x00 /* code type */
  37. .byte 0x80 /* Flags (last PCI data structure) */
  38. .word 0x0000 /* reserved */
  39. .equ pciheader_len, . - pciheader
  40. .size pciheader, . - pciheader
  41. pnpheader:
  42. .ascii "$PnP" /* Signature */
  43. .byte 0x01 /* Structure revision */
  44. .byte ( pnpheader_len / 16 ) /* Length (in 16 byte increments) */
  45. .word 0x0000 /* Offset of next header */
  46. .byte 0x00 /* Reserved */
  47. .byte 0x00 /* Checksum */
  48. .long 0x00000000 /* Device identifier */
  49. .word mfgstr /* Manufacturer string */
  50. .word prodstr /* Product name */
  51. .byte 0x02 /* Device base type code */
  52. .byte 0x00 /* Device sub-type code */
  53. .byte 0x00 /* Device interface type code */
  54. .byte 0x54 /* Device indicator */
  55. .word 0x0000 /* Boot connection vector */
  56. .word 0x0000 /* Disconnect vector */
  57. .word exec_vector /* Boot execution vector */
  58. .word 0x0000 /* Reserved */
  59. .word 0x0000 /* Static resource information vector*/
  60. .equ pnpheader_len, . - pnpheader
  61. .size pnpheader, . - pnpheader
  62. mfgstr:
  63. .asciz "http://etherboot.org"
  64. .size mfgstr, . - mfgstr
  65. prodstr:
  66. .asciz "Etherboot"
  67. .size prodstr, . - prodstr
  68. undiheader:
  69. .ascii "UNDI" /* Signature */
  70. .byte undiheader_len /* Length of structure */
  71. .byte 0 /* Checksum */
  72. .byte 0 /* Structure revision */
  73. .byte 0,1,2 /* PXE version: 2.1.0 */
  74. .word undiloader /* Offset to loader routine */
  75. .word _data16_size /* Stack segment size */
  76. .word _data16_size /* Data segment size */
  77. .word _text16_size /* Code segment size */
  78. .equ undiheader_len, . - undiheader
  79. .size undiheader, . - undiheader
  80. /* Initialisation vector
  81. *
  82. * Determine whether or not this is a PnP system via a signature
  83. * check. If it is PnP, return to the PnP BIOS indicating that we are
  84. * a boot-capable device; the BIOS will call our boot execution vector
  85. * if it wants to boot us. If it is not PnP, hook INT 19.
  86. */
  87. init_vector:
  88. pushw %si
  89. cmpw $'$'+'P'*256, %es:0(%di)
  90. jne notpnp
  91. cmpw $'n'+'P'*256, %es:2(%di)
  92. jne notpnp
  93. ispnp:
  94. movw $ispnp_message, %si
  95. jmp 99f
  96. notpnp:
  97. pushw %ds
  98. pushw $0
  99. popw %ds
  100. pushw %cs
  101. pushw $exec_vector
  102. popl ( 0x19 * 4 )
  103. popw %ds
  104. movw $notpnp_message, %si
  105. 99:
  106. call print_message
  107. movw $0x20, %ax
  108. popw %si
  109. lret
  110. .size init_vector, . - init_vector
  111. ispnp_message:
  112. .asciz "Etherboot detected PnP BIOS\r\n"
  113. .size ispnp_message, . - ispnp_message
  114. notpnp_message:
  115. .asciz "Etherboot detected non-PnP BIOS\r\n"
  116. .size notpnp_message, . - notpnp_message
  117. /* Boot execution vector
  118. *
  119. * Called by the PnP BIOS when it wants to boot us, or via the hooked
  120. * INT 19 if we detected a non-PnP BIOS.
  121. */
  122. exec_vector:
  123. /* Obtain a reasonably-sized stack */
  124. xorw %ax, %ax
  125. movw %ax, %ss
  126. movw $0x7c00, %sp
  127. movw $exec_message, %si
  128. call print_message
  129. call install
  130. /* Set up real-mode stack */
  131. movw %bx, %ss
  132. movw $_estack16, %sp
  133. /* Jump to .text16 segment */
  134. pushw %ax
  135. pushw $1f
  136. lret
  137. .section ".text16", "awx", @progbits
  138. 1:
  139. pushl $main
  140. pushw %cs
  141. call prot_call
  142. popl %eax /* discard */
  143. /* Boot next device */
  144. int $0x18
  145. .previous
  146. exec_message:
  147. .asciz "Etherboot starting boot\r\n"
  148. .size exec_message, . - exec_message
  149. /* UNDI loader
  150. *
  151. * Called by an external program to load our PXE stack.
  152. */
  153. undiloader:
  154. .size undiloader, . - undiloader
  155. /* Utility function: print string
  156. */
  157. print_message:
  158. pushw %ax
  159. pushw %bx
  160. pushw %bp
  161. movw $0x0007, %bx
  162. 1: cs lodsb
  163. testb %al, %al
  164. je 2f
  165. movb $0x0e, %ah /* write char, tty mode */
  166. int $0x10
  167. jmp 1b
  168. 2: popw %bp
  169. popw %bx
  170. popw %ax
  171. ret
  172. .size print_message, . - print_message