main.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright 2007 rPath, Inc. - All Rights Reserved
  5. * Copyright 2009 Intel Corporation; author H. Peter Anvin
  6. *
  7. * This file is part of the Linux kernel, and is made available under
  8. * the terms of the GNU General Public License version 2.
  9. *
  10. * ----------------------------------------------------------------------- */
  11. /*
  12. * Main module for the real-mode kernel code
  13. */
  14. #include "boot.h"
  15. struct boot_params boot_params __attribute__((aligned(16)));
  16. char *HEAP = _end;
  17. char *heap_end = _end; /* Default end of heap = no heap */
  18. /*
  19. * Copy the header into the boot parameter block. Since this
  20. * screws up the old-style command line protocol, adjust by
  21. * filling in the new-style command line pointer instead.
  22. */
  23. static void copy_boot_params(void)
  24. {
  25. struct old_cmdline {
  26. u16 cl_magic;
  27. u16 cl_offset;
  28. };
  29. const struct old_cmdline * const oldcmd =
  30. (const struct old_cmdline *)OLD_CL_ADDRESS;
  31. BUILD_BUG_ON(sizeof boot_params != 4096);
  32. memcpy(&boot_params.hdr, &hdr, sizeof hdr);
  33. if (!boot_params.hdr.cmd_line_ptr &&
  34. oldcmd->cl_magic == OLD_CL_MAGIC) {
  35. /* Old-style command line protocol. */
  36. u16 cmdline_seg;
  37. /* Figure out if the command line falls in the region
  38. of memory that an old kernel would have copied up
  39. to 0x90000... */
  40. if (oldcmd->cl_offset < boot_params.hdr.setup_move_size)
  41. cmdline_seg = ds();
  42. else
  43. cmdline_seg = 0x9000;
  44. boot_params.hdr.cmd_line_ptr =
  45. (cmdline_seg << 4) + oldcmd->cl_offset;
  46. }
  47. }
  48. /*
  49. * Set the keyboard repeat rate to maximum. Unclear why this
  50. * is done here; this might be possible to kill off as stale code.
  51. */
  52. static void keyboard_set_repeat(void)
  53. {
  54. struct biosregs ireg;
  55. initregs(&ireg);
  56. ireg.ax = 0x0305;
  57. intcall(0x16, &ireg, NULL);
  58. }
  59. /*
  60. * Get Intel SpeedStep (IST) information.
  61. */
  62. static void query_ist(void)
  63. {
  64. struct biosregs ireg, oreg;
  65. /* Some older BIOSes apparently crash on this call, so filter
  66. it from machines too old to have SpeedStep at all. */
  67. if (cpu.level < 6)
  68. return;
  69. initregs(&ireg);
  70. ireg.ax = 0xe980; /* IST Support */
  71. ireg.edx = 0x47534943; /* Request value */
  72. intcall(0x15, &ireg, &oreg);
  73. boot_params.ist_info.signature = oreg.eax;
  74. boot_params.ist_info.command = oreg.ebx;
  75. boot_params.ist_info.event = oreg.ecx;
  76. boot_params.ist_info.perf_level = oreg.edx;
  77. }
  78. /*
  79. * Tell the BIOS what CPU mode we intend to run in.
  80. */
  81. static void set_bios_mode(void)
  82. {
  83. #ifdef CONFIG_X86_64
  84. struct biosregs ireg;
  85. initregs(&ireg);
  86. ireg.ax = 0xec00;
  87. ireg.bx = 2;
  88. intcall(0x15, &ireg, NULL);
  89. #endif
  90. }
  91. static void init_heap(void)
  92. {
  93. char *stack_end;
  94. if (boot_params.hdr.loadflags & CAN_USE_HEAP) {
  95. asm("leal %P1(%%esp),%0"
  96. : "=r" (stack_end) : "i" (-STACK_SIZE));
  97. heap_end = (char *)
  98. ((size_t)boot_params.hdr.heap_end_ptr + 0x200);
  99. if (heap_end > stack_end)
  100. heap_end = stack_end;
  101. } else {
  102. /* Boot protocol 2.00 only, no heap available */
  103. puts("WARNING: Ancient bootloader, some functionality "
  104. "may be limited!\n");
  105. }
  106. }
  107. void main(void)
  108. {
  109. /* First, copy the boot header into the "zeropage" */
  110. copy_boot_params();
  111. /* Initialize the early-boot console */
  112. console_init();
  113. if (cmdline_find_option_bool("debug"))
  114. puts("early console in setup code\n");
  115. /* End of heap check */
  116. init_heap();
  117. /* Make sure we have all the proper CPU support */
  118. if (validate_cpu()) {
  119. puts("Unable to boot - please use a kernel appropriate "
  120. "for your CPU.\n");
  121. die();
  122. }
  123. /* Tell the BIOS what CPU mode we intend to run in. */
  124. set_bios_mode();
  125. /* Detect memory layout */
  126. detect_memory();
  127. /* Set keyboard repeat rate (why?) */
  128. keyboard_set_repeat();
  129. /* Query MCA information */
  130. query_mca();
  131. /* Query Intel SpeedStep (IST) information */
  132. query_ist();
  133. /* Query APM information */
  134. #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
  135. query_apm_bios();
  136. #endif
  137. /* Query EDD information */
  138. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  139. query_edd();
  140. #endif
  141. /* Set the video mode */
  142. set_video();
  143. /* Do the last things and invoke protected mode */
  144. go_to_protected_mode();
  145. }