main.c 3.7 KB

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