main.c 3.7 KB

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