header.S 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * header.S
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. *
  6. * Based on bootsect.S and setup.S
  7. * modified by more people than can be counted
  8. *
  9. * Rewritten as a common file by H. Peter Anvin (Apr 2007)
  10. *
  11. * BIG FAT NOTE: We're in real mode using 64k segments. Therefore segment
  12. * addresses must be multiplied by 16 to obtain their respective linear
  13. * addresses. To avoid confusion, linear addresses are written using leading
  14. * hex while segment addresses are written as segment:offset.
  15. *
  16. */
  17. #include <asm/segment.h>
  18. #include <linux/utsrelease.h>
  19. #include <asm/boot.h>
  20. #include <asm/e820.h>
  21. #include <asm/page.h>
  22. #include <asm/setup.h>
  23. #include "boot.h"
  24. SETUPSECTS = 4 /* default nr of setup-sectors */
  25. BOOTSEG = 0x07C0 /* original address of boot-sector */
  26. SYSSEG = DEF_SYSSEG /* system loaded at 0x10000 (65536) */
  27. SYSSIZE = DEF_SYSSIZE /* system size: # of 16-byte clicks */
  28. /* to be loaded */
  29. ROOT_DEV = 0 /* ROOT_DEV is now written by "build" */
  30. SWAP_DEV = 0 /* SWAP_DEV is now written by "build" */
  31. #ifndef SVGA_MODE
  32. #define SVGA_MODE ASK_VGA
  33. #endif
  34. #ifndef RAMDISK
  35. #define RAMDISK 0
  36. #endif
  37. #ifndef ROOT_RDONLY
  38. #define ROOT_RDONLY 1
  39. #endif
  40. .code16
  41. .section ".bstext", "ax"
  42. .global bootsect_start
  43. bootsect_start:
  44. # Normalize the start address
  45. ljmp $BOOTSEG, $start2
  46. start2:
  47. movw %cs, %ax
  48. movw %ax, %ds
  49. movw %ax, %es
  50. movw %ax, %ss
  51. xorw %sp, %sp
  52. sti
  53. cld
  54. movw $bugger_off_msg, %si
  55. msg_loop:
  56. lodsb
  57. andb %al, %al
  58. jz bs_die
  59. movb $0xe, %ah
  60. movw $7, %bx
  61. int $0x10
  62. jmp msg_loop
  63. bs_die:
  64. # Allow the user to press a key, then reboot
  65. xorw %ax, %ax
  66. int $0x16
  67. int $0x19
  68. # int 0x19 should never return. In case it does anyway,
  69. # invoke the BIOS reset code...
  70. ljmp $0xf000,$0xfff0
  71. .section ".bsdata", "a"
  72. bugger_off_msg:
  73. .ascii "Direct booting from floppy is no longer supported.\r\n"
  74. .ascii "Please use a boot loader program instead.\r\n"
  75. .ascii "\n"
  76. .ascii "Remove disk and press any key to reboot . . .\r\n"
  77. .byte 0
  78. # Kernel attributes; used by setup. This is part 1 of the
  79. # header, from the old boot sector.
  80. .section ".header", "a"
  81. .globl hdr
  82. hdr:
  83. setup_sects: .byte SETUPSECTS
  84. root_flags: .word ROOT_RDONLY
  85. syssize: .long SYSSIZE
  86. ram_size: .word RAMDISK
  87. vid_mode: .word SVGA_MODE
  88. root_dev: .word ROOT_DEV
  89. boot_flag: .word 0xAA55
  90. # offset 512, entry point
  91. .globl _start
  92. _start:
  93. # Explicitly enter this as bytes, or the assembler
  94. # tries to generate a 3-byte jump here, which causes
  95. # everything else to push off to the wrong offset.
  96. .byte 0xeb # short (2-byte) jump
  97. .byte start_of_setup-1f
  98. 1:
  99. # Part 2 of the header, from the old setup.S
  100. .ascii "HdrS" # header signature
  101. .word 0x0206 # header version number (>= 0x0105)
  102. # or else old loadlin-1.5 will fail)
  103. .globl realmode_swtch
  104. realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
  105. start_sys_seg: .word SYSSEG
  106. .word kernel_version-512 # pointing to kernel version string
  107. # above section of header is compatible
  108. # with loadlin-1.5 (header v1.5). Don't
  109. # change it.
  110. type_of_loader: .byte 0 # = 0, old one (LILO, Loadlin,
  111. # Bootlin, SYSLX, bootsect...)
  112. # See Documentation/i386/boot.txt for
  113. # assigned ids
  114. # flags, unused bits must be zero (RFU) bit within loadflags
  115. loadflags:
  116. LOADED_HIGH = 1 # If set, the kernel is loaded high
  117. CAN_USE_HEAP = 0x80 # If set, the loader also has set
  118. # heap_end_ptr to tell how much
  119. # space behind setup.S can be used for
  120. # heap purposes.
  121. # Only the loader knows what is free
  122. #ifndef __BIG_KERNEL__
  123. .byte 0
  124. #else
  125. .byte LOADED_HIGH
  126. #endif
  127. setup_move_size: .word 0x8000 # size to move, when setup is not
  128. # loaded at 0x90000. We will move setup
  129. # to 0x90000 then just before jumping
  130. # into the kernel. However, only the
  131. # loader knows how much data behind
  132. # us also needs to be loaded.
  133. code32_start: # here loaders can put a different
  134. # start address for 32-bit code.
  135. #ifndef __BIG_KERNEL__
  136. .long 0x1000 # 0x1000 = default for zImage
  137. #else
  138. .long 0x100000 # 0x100000 = default for big kernel
  139. #endif
  140. ramdisk_image: .long 0 # address of loaded ramdisk image
  141. # Here the loader puts the 32-bit
  142. # address where it loaded the image.
  143. # This only will be read by the kernel.
  144. ramdisk_size: .long 0 # its size in bytes
  145. bootsect_kludge:
  146. .long 0 # obsolete
  147. heap_end_ptr: .word _end+1024 # (Header version 0x0201 or later)
  148. # space from here (exclusive) down to
  149. # end of setup code can be used by setup
  150. # for local heap purposes.
  151. pad1: .word 0
  152. cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
  153. # If nonzero, a 32-bit pointer
  154. # to the kernel command line.
  155. # The command line should be
  156. # located between the start of
  157. # setup and the end of low
  158. # memory (0xa0000), or it may
  159. # get overwritten before it
  160. # gets read. If this field is
  161. # used, there is no longer
  162. # anything magical about the
  163. # 0x90000 segment; the setup
  164. # can be located anywhere in
  165. # low memory 0x10000 or higher.
  166. ramdisk_max: .long (-__PAGE_OFFSET-(512 << 20)-1) & 0x7fffffff
  167. # (Header version 0x0203 or later)
  168. # The highest safe address for
  169. # the contents of an initrd
  170. kernel_alignment: .long CONFIG_PHYSICAL_ALIGN #physical addr alignment
  171. #required for protected mode
  172. #kernel
  173. #ifdef CONFIG_RELOCATABLE
  174. relocatable_kernel: .byte 1
  175. #else
  176. relocatable_kernel: .byte 0
  177. #endif
  178. pad2: .byte 0
  179. pad3: .word 0
  180. cmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line,
  181. #added with boot protocol
  182. #version 2.06
  183. # End of setup header #####################################################
  184. .section ".inittext", "ax"
  185. start_of_setup:
  186. #ifdef SAFE_RESET_DISK_CONTROLLER
  187. # Reset the disk controller.
  188. movw $0x0000, %ax # Reset disk controller
  189. movb $0x80, %dl # All disks
  190. int $0x13
  191. #endif
  192. # We will have entered with %cs = %ds+0x20, normalize %cs so
  193. # it is on par with the other segments.
  194. pushw %ds
  195. pushw $setup2
  196. lretw
  197. setup2:
  198. # Force %es = %ds
  199. movw %ds, %ax
  200. movw %ax, %es
  201. cld
  202. # Stack paranoia: align the stack and make sure it is good
  203. # for both 16- and 32-bit references. In particular, if we
  204. # were meant to have been using the full 16-bit segment, the
  205. # caller might have set %sp to zero, which breaks %esp-based
  206. # references.
  207. andw $~3, %sp # dword align (might as well...)
  208. jnz 1f
  209. movw $0xfffc, %sp # Make sure we're not zero
  210. 1: movzwl %sp, %esp # Clear upper half of %esp
  211. sti
  212. # Check signature at end of setup
  213. cmpl $0x5a5aaa55, setup_sig
  214. jne setup_bad
  215. # Zero the bss
  216. movw $__bss_start, %di
  217. movw $_end+3, %cx
  218. xorl %eax, %eax
  219. subw %di, %cx
  220. shrw $2, %cx
  221. rep; stosl
  222. # Jump to C code (should not return)
  223. calll main
  224. # Setup corrupt somehow...
  225. setup_bad:
  226. movl $setup_corrupt, %eax
  227. calll puts
  228. # Fall through...
  229. .globl die
  230. .type die, @function
  231. die:
  232. hlt
  233. jmp die
  234. .size die, .-die
  235. .section ".initdata", "a"
  236. setup_corrupt:
  237. .byte 7
  238. .string "No setup signature found...\n"