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.

exeprefix.S 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. *
  23. */
  24. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
  25. /* Initial temporary stack size */
  26. #define EXE_STACK_SIZE 0x400
  27. /* Temporary decompression area (avoid DOS high memory area) */
  28. #define EXE_DECOMPRESS_ADDRESS 0x110000
  29. /* Fields within the Program Segment Prefix */
  30. #define PSP_CMDLINE_LEN 0x80
  31. #define PSP_CMDLINE_START 0x81
  32. .text
  33. .arch i386
  34. .org 0
  35. .code16
  36. .section ".prefix", "awx", @progbits
  37. signature:
  38. /* "MZ" signature */
  39. .ascii "MZ"
  40. last_block:
  41. /* Number of bytes in last block that are really used */
  42. .word 0
  43. blocks:
  44. /* Number of 512-byte blocks */
  45. .word 0
  46. .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
  47. .ascii "ADDW"
  48. .long blocks
  49. .long 512
  50. .long 0
  51. .previous
  52. num_reloc:
  53. /* Number of relocation entries stored after the header */
  54. .word 0
  55. header_pgh:
  56. /* Number of paragraphs in the header */
  57. .word ( ( _exe_start - signature ) / 16 )
  58. min_bss_pgh:
  59. /* Minimum number of paragraphs of additional (BSS) memory */
  60. .word ( EXE_STACK_SIZE / 16 )
  61. max_bss_pgh:
  62. /* Maximum number of paragraphs of additional (BSS) memory */
  63. .word ( EXE_STACK_SIZE / 16 )
  64. init_ss:
  65. /* Initial stack segment (relative to start of executable) */
  66. .word -( ( _exe_start - signature ) / 16 )
  67. .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
  68. .ascii "ADDW"
  69. .long init_ss
  70. .long 16
  71. .long 0
  72. .previous
  73. init_sp:
  74. /* Initial stack pointer */
  75. .word EXE_STACK_SIZE
  76. checksum:
  77. /* Checksum (ignored) */
  78. .word 0
  79. init_ip:
  80. /* Initial instruction pointer */
  81. .word _exe_start
  82. init_cs:
  83. /* Initial code segment (relative to start of executable) */
  84. .word -( ( _exe_start - signature ) / 16 )
  85. reloc_table:
  86. /* Relocation table offset */
  87. .word 0
  88. overlay:
  89. /* Overlay number */
  90. .word 0
  91. .align 16, 0
  92. .globl _exe_start
  93. _exe_start:
  94. /* Install iPXE. Use a fixed temporary decompression area to
  95. * avoid trashing the DOS high memory area.
  96. */
  97. call alloc_basemem
  98. xorl %esi, %esi
  99. movl $EXE_DECOMPRESS_ADDRESS, %edi
  100. orl $0xffffffff, %ebp /* Allow arbitrary relocation */
  101. call install_prealloc
  102. /* Set up real-mode stack */
  103. movw %bx, %ss
  104. movw $_estack16, %sp
  105. /* Jump to .text16 segment */
  106. pushw %ax
  107. pushw $1f
  108. lret
  109. .section ".text16", "awx", @progbits
  110. 1:
  111. /* Terminate command line with a NUL */
  112. movzbw PSP_CMDLINE_LEN, %si
  113. movb $0, PSP_CMDLINE_START(%si)
  114. /* Calculate command line physical address */
  115. xorl %esi, %esi
  116. movw %ds, %si
  117. shll $4, %esi
  118. addl $PSP_CMDLINE_START, %esi
  119. /* Set up %ds for access to .data16 */
  120. movw %bx, %ds
  121. /* Record command line address */
  122. movl %esi, cmdline_phys
  123. /* Run iPXE */
  124. pushl $main
  125. pushw %cs
  126. call prot_call
  127. popl %ecx /* discard */
  128. /* Uninstall iPXE */
  129. call uninstall
  130. /* Exit back to DOS. This is very unlikely to work */
  131. movw $0x4c00, %ax
  132. int $0x21