header.S 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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_types.h>
  22. #include <asm/setup.h>
  23. #include "boot.h"
  24. #include "voffset.h"
  25. #include "zoffset.h"
  26. BOOTSEG = 0x07C0 /* original address of boot-sector */
  27. SYSSEG = 0x1000 /* historical load address >> 4 */
  28. #ifndef SVGA_MODE
  29. #define SVGA_MODE ASK_VGA
  30. #endif
  31. #ifndef RAMDISK
  32. #define RAMDISK 0
  33. #endif
  34. #ifndef ROOT_RDONLY
  35. #define ROOT_RDONLY 1
  36. #endif
  37. .code16
  38. .section ".bstext", "ax"
  39. .global bootsect_start
  40. bootsect_start:
  41. # Normalize the start address
  42. ljmp $BOOTSEG, $start2
  43. start2:
  44. movw %cs, %ax
  45. movw %ax, %ds
  46. movw %ax, %es
  47. movw %ax, %ss
  48. xorw %sp, %sp
  49. sti
  50. cld
  51. movw $bugger_off_msg, %si
  52. msg_loop:
  53. lodsb
  54. andb %al, %al
  55. jz bs_die
  56. movb $0xe, %ah
  57. movw $7, %bx
  58. int $0x10
  59. jmp msg_loop
  60. bs_die:
  61. # Allow the user to press a key, then reboot
  62. xorw %ax, %ax
  63. int $0x16
  64. int $0x19
  65. # int 0x19 should never return. In case it does anyway,
  66. # invoke the BIOS reset code...
  67. ljmp $0xf000,$0xfff0
  68. .section ".bsdata", "a"
  69. bugger_off_msg:
  70. .ascii "Direct booting from floppy is no longer supported.\r\n"
  71. .ascii "Please use a boot loader program instead.\r\n"
  72. .ascii "\n"
  73. .ascii "Remove disk and press any key to reboot . . .\r\n"
  74. .byte 0
  75. # Kernel attributes; used by setup. This is part 1 of the
  76. # header, from the old boot sector.
  77. .section ".header", "a"
  78. .globl hdr
  79. hdr:
  80. setup_sects: .byte 0 /* Filled in by build.c */
  81. root_flags: .word ROOT_RDONLY
  82. syssize: .long 0 /* Filled in by build.c */
  83. ram_size: .word 0 /* Obsolete */
  84. vid_mode: .word SVGA_MODE
  85. root_dev: .word 0 /* Filled in by build.c */
  86. boot_flag: .word 0xAA55
  87. # offset 512, entry point
  88. .globl _start
  89. _start:
  90. # Explicitly enter this as bytes, or the assembler
  91. # tries to generate a 3-byte jump here, which causes
  92. # everything else to push off to the wrong offset.
  93. .byte 0xeb # short (2-byte) jump
  94. .byte start_of_setup-1f
  95. 1:
  96. # Part 2 of the header, from the old setup.S
  97. .ascii "HdrS" # header signature
  98. .word 0x020a # header version number (>= 0x0105)
  99. # or else old loadlin-1.5 will fail)
  100. .globl realmode_swtch
  101. realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
  102. start_sys_seg: .word SYSSEG # obsolete and meaningless, but just
  103. # in case something decided to "use" it
  104. .word kernel_version-512 # pointing to kernel version string
  105. # above section of header is compatible
  106. # with loadlin-1.5 (header v1.5). Don't
  107. # change it.
  108. type_of_loader: .byte 0 # 0 means ancient bootloader, newer
  109. # bootloaders know to change this.
  110. # See Documentation/i386/boot.txt for
  111. # assigned ids
  112. # flags, unused bits must be zero (RFU) bit within loadflags
  113. loadflags:
  114. LOADED_HIGH = 1 # If set, the kernel is loaded high
  115. CAN_USE_HEAP = 0x80 # If set, the loader also has set
  116. # heap_end_ptr to tell how much
  117. # space behind setup.S can be used for
  118. # heap purposes.
  119. # Only the loader knows what is free
  120. .byte LOADED_HIGH
  121. setup_move_size: .word 0x8000 # size to move, when setup is not
  122. # loaded at 0x90000. We will move setup
  123. # to 0x90000 then just before jumping
  124. # into the kernel. However, only the
  125. # loader knows how much data behind
  126. # us also needs to be loaded.
  127. code32_start: # here loaders can put a different
  128. # start address for 32-bit code.
  129. .long 0x100000 # 0x100000 = default for big kernel
  130. ramdisk_image: .long 0 # address of loaded ramdisk image
  131. # Here the loader puts the 32-bit
  132. # address where it loaded the image.
  133. # This only will be read by the kernel.
  134. ramdisk_size: .long 0 # its size in bytes
  135. bootsect_kludge:
  136. .long 0 # obsolete
  137. heap_end_ptr: .word _end+STACK_SIZE-512
  138. # (Header version 0x0201 or later)
  139. # space from here (exclusive) down to
  140. # end of setup code can be used by setup
  141. # for local heap purposes.
  142. pad1: .word 0
  143. cmd_line_ptr: .long 0 # (Header version 0x0202 or later)
  144. # If nonzero, a 32-bit pointer
  145. # to the kernel command line.
  146. # The command line should be
  147. # located between the start of
  148. # setup and the end of low
  149. # memory (0xa0000), or it may
  150. # get overwritten before it
  151. # gets read. If this field is
  152. # used, there is no longer
  153. # anything magical about the
  154. # 0x90000 segment; the setup
  155. # can be located anywhere in
  156. # low memory 0x10000 or higher.
  157. ramdisk_max: .long 0x7fffffff
  158. # (Header version 0x0203 or later)
  159. # The highest safe address for
  160. # the contents of an initrd
  161. # The current kernel allows up to 4 GB,
  162. # but leave it at 2 GB to avoid
  163. # possible bootloader bugs.
  164. kernel_alignment: .long CONFIG_PHYSICAL_ALIGN #physical addr alignment
  165. #required for protected mode
  166. #kernel
  167. #ifdef CONFIG_RELOCATABLE
  168. relocatable_kernel: .byte 1
  169. #else
  170. relocatable_kernel: .byte 0
  171. #endif
  172. min_alignment: .byte MIN_KERNEL_ALIGN_LG2 # minimum alignment
  173. pad3: .word 0
  174. cmdline_size: .long COMMAND_LINE_SIZE-1 #length of the command line,
  175. #added with boot protocol
  176. #version 2.06
  177. hardware_subarch: .long 0 # subarchitecture, added with 2.07
  178. # default to 0 for normal x86 PC
  179. hardware_subarch_data: .quad 0
  180. payload_offset: .long ZO_input_data
  181. payload_length: .long ZO_z_input_len
  182. setup_data: .quad 0 # 64-bit physical pointer to
  183. # single linked list of
  184. # struct setup_data
  185. pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
  186. #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_extract_offset)
  187. #define VO_INIT_SIZE (VO__end - VO__text)
  188. #if ZO_INIT_SIZE > VO_INIT_SIZE
  189. #define INIT_SIZE ZO_INIT_SIZE
  190. #else
  191. #define INIT_SIZE VO_INIT_SIZE
  192. #endif
  193. init_size: .long INIT_SIZE # kernel initialization size
  194. # End of setup header #####################################################
  195. .section ".inittext", "ax"
  196. start_of_setup:
  197. #ifdef SAFE_RESET_DISK_CONTROLLER
  198. # Reset the disk controller.
  199. movw $0x0000, %ax # Reset disk controller
  200. movb $0x80, %dl # All disks
  201. int $0x13
  202. #endif
  203. # Force %es = %ds
  204. movw %ds, %ax
  205. movw %ax, %es
  206. cld
  207. # Apparently some ancient versions of LILO invoked the kernel with %ss != %ds,
  208. # which happened to work by accident for the old code. Recalculate the stack
  209. # pointer if %ss is invalid. Otherwise leave it alone, LOADLIN sets up the
  210. # stack behind its own code, so we can't blindly put it directly past the heap.
  211. movw %ss, %dx
  212. cmpw %ax, %dx # %ds == %ss?
  213. movw %sp, %dx
  214. je 2f # -> assume %sp is reasonably set
  215. # Invalid %ss, make up a new stack
  216. movw $_end, %dx
  217. testb $CAN_USE_HEAP, loadflags
  218. jz 1f
  219. movw heap_end_ptr, %dx
  220. 1: addw $STACK_SIZE, %dx
  221. jnc 2f
  222. xorw %dx, %dx # Prevent wraparound
  223. 2: # Now %dx should point to the end of our stack space
  224. andw $~3, %dx # dword align (might as well...)
  225. jnz 3f
  226. movw $0xfffc, %dx # Make sure we're not zero
  227. 3: movw %ax, %ss
  228. movzwl %dx, %esp # Clear upper half of %esp
  229. sti # Now we should have a working stack
  230. # We will have entered with %cs = %ds+0x20, normalize %cs so
  231. # it is on par with the other segments.
  232. pushw %ds
  233. pushw $6f
  234. lretw
  235. 6:
  236. # Check signature at end of setup
  237. cmpl $0x5a5aaa55, setup_sig
  238. jne setup_bad
  239. # Zero the bss
  240. movw $__bss_start, %di
  241. movw $_end+3, %cx
  242. xorl %eax, %eax
  243. subw %di, %cx
  244. shrw $2, %cx
  245. rep; stosl
  246. # Jump to C code (should not return)
  247. calll main
  248. # Setup corrupt somehow...
  249. setup_bad:
  250. movl $setup_corrupt, %eax
  251. calll puts
  252. # Fall through...
  253. .globl die
  254. .type die, @function
  255. die:
  256. hlt
  257. jmp die
  258. .size die, .-die
  259. .section ".initdata", "a"
  260. setup_corrupt:
  261. .byte 7
  262. .string "No setup signature found...\n"