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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. */
  20. FILE_LICENCE ( GPL2_OR_LATER )
  21. /* Initial temporary stack size */
  22. #define EXE_STACK_SIZE 0x400
  23. /* Temporary decompression area (avoid DOS high memory area) */
  24. #define EXE_DECOMPRESS_ADDRESS 0x110000
  25. /* Fields within the Program Segment Prefix */
  26. #define PSP_CMDLINE_LEN 0x80
  27. #define PSP_CMDLINE_START 0x81
  28. .text
  29. .arch i386
  30. .org 0
  31. .code16
  32. .section ".prefix", "awx", @progbits
  33. signature:
  34. /* "MZ" signature */
  35. .ascii "MZ"
  36. last_block:
  37. /* Number of bytes in last block that are really used */
  38. .word 0
  39. blocks:
  40. /* Number of 512-byte blocks */
  41. .word 0
  42. .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
  43. .ascii "ADDW"
  44. .long blocks
  45. .long 512
  46. .long 0
  47. .previous
  48. num_reloc:
  49. /* Number of relocation entries stored after the header */
  50. .word 0
  51. header_pgh:
  52. /* Number of paragraphs in the header */
  53. .word ( ( _exe_start - signature ) / 16 )
  54. min_bss_pgh:
  55. /* Minimum number of paragraphs of additional (BSS) memory */
  56. .word ( EXE_STACK_SIZE / 16 )
  57. max_bss_pgh:
  58. /* Maximum number of paragraphs of additional (BSS) memory */
  59. .word ( EXE_STACK_SIZE / 16 )
  60. init_ss:
  61. /* Initial stack segment (relative to start of executable) */
  62. .word -( ( _exe_start - signature ) / 16 )
  63. .section ".zinfo.fixup", "a", @progbits /* Compressor fixups */
  64. .ascii "ADDW"
  65. .long init_ss
  66. .long 16
  67. .long 0
  68. .previous
  69. init_sp:
  70. /* Initial stack pointer */
  71. .word EXE_STACK_SIZE
  72. checksum:
  73. /* Checksum (ignored) */
  74. .word 0
  75. init_ip:
  76. /* Initial instruction pointer */
  77. .word _exe_start
  78. init_cs:
  79. /* Initial code segment (relative to start of executable) */
  80. .word -( ( _exe_start - signature ) / 16 )
  81. reloc_table:
  82. /* Relocation table offset */
  83. .word 0
  84. overlay:
  85. /* Overlay number */
  86. .word 0
  87. .align 16, 0
  88. .globl _exe_start
  89. _exe_start:
  90. /* Install iPXE. Use a fixed temporary decompression area to
  91. * avoid trashing the DOS high memory area.
  92. */
  93. call alloc_basemem
  94. xorl %esi, %esi
  95. movl $EXE_DECOMPRESS_ADDRESS, %edi
  96. xorl %ebp, %ebp
  97. call install_prealloc
  98. /* Set up real-mode stack */
  99. movw %bx, %ss
  100. movw $_estack16, %sp
  101. /* Jump to .text16 segment */
  102. pushw %ax
  103. pushw $1f
  104. lret
  105. .section ".text16", "awx", @progbits
  106. 1:
  107. /* Terminate command line with a NUL */
  108. movzbw PSP_CMDLINE_LEN, %si
  109. movb $0, PSP_CMDLINE_START(%si)
  110. /* Calculate command line physical address */
  111. xorl %esi, %esi
  112. movw %ds, %si
  113. shll $4, %esi
  114. addl $PSP_CMDLINE_START, %esi
  115. /* Set up %ds for access to .data16 */
  116. movw %bx, %ds
  117. /* Record command line address */
  118. movl %esi, cmdline_phys
  119. /* Run iPXE */
  120. pushl $main
  121. pushw %cs
  122. call prot_call
  123. popl %ecx /* discard */
  124. /* Uninstall iPXE */
  125. call uninstall
  126. /* Exit back to DOS. This is very unlikely to work */
  127. movw $0x4c00, %ax
  128. int $0x21