]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2008-08-05 Robert Millan <rmh@aybabtu.com>
authorrobertmh <robertmh@localhost>
Tue, 5 Aug 2008 20:24:00 +0000 (20:24 +0000)
committerrobertmh <robertmh@localhost>
Tue, 5 Aug 2008 20:24:00 +0000 (20:24 +0000)
        * conf/i386-pc.rmk (kernel_img_SOURCES): Add `kern/i386/pit.c'.
        * conf/i386-efi.rmk (kernel_mod_SOURCES): Likewise.
        * conf/i386-coreboot.rmk (kernel_elf_SOURCES): Likewise. Also add
        `kern/i386/tsc.c', `kern/generic/rtc_get_time_ms.c' and
        `kern/generic/millisleep.c'.

        * kern/i386/tsc.c (calibrate_tsc): Rewrite using grub_pit_wait()
        instead of grub_get_rtc().
        (grub_tsc_init): Initialize `tsc_boot_time'.

        * kern/i386/linuxbios/init.c (grub_millisleep): Remove stub.
        (grub_machine_init): Use grub_tsc_init() rather than
        installing an RTC-based handler via grub_install_get_time_ms().

        * kern/i386/pit.c: New file.
        * include/grub/i386/pit.h: Likewise.

ChangeLog
DISTLIST
conf/i386-coreboot.rmk
conf/i386-efi.rmk
conf/i386-pc.rmk
include/grub/i386/pit.h [new file with mode: 0644]
kern/i386/linuxbios/init.c
kern/i386/pit.c [new file with mode: 0644]
kern/i386/tsc.c

index d7d6a820cbac47b932f789dfb9c5129b2dca06fc..85117e75c30ef720b3d9f8d1ac6d7f1eb521b735 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2008-08-05  Robert Millan  <rmh@aybabtu.com>
+
+       * conf/i386-pc.rmk (kernel_img_SOURCES): Add `kern/i386/pit.c'.
+       * conf/i386-efi.rmk (kernel_mod_SOURCES): Likewise.
+       * conf/i386-coreboot.rmk (kernel_elf_SOURCES): Likewise. Also add
+       `kern/i386/tsc.c', `kern/generic/rtc_get_time_ms.c' and
+       `kern/generic/millisleep.c'.
+
+       * kern/i386/tsc.c (calibrate_tsc): Rewrite using grub_pit_wait()
+       instead of grub_get_rtc().
+       (grub_tsc_init): Initialize `tsc_boot_time'.
+
+       * kern/i386/linuxbios/init.c (grub_millisleep): Remove stub.
+       (grub_machine_init): Use grub_tsc_init() rather than
+       installing an RTC-based handler via grub_install_get_time_ms().
+
+       * kern/i386/pit.c: New file.
+       * include/grub/i386/pit.h: Likewise.
+
 2008-08-05  Bean  <bean123ch@gmail.com>
 
        * boot/i386/pc/pxeboot.S (_start): Use drive number 0x7F for pxe.
index 6a7fffccea0165b71fef37492dd9ab989e287033..649cb9085de59c3b2df2f75401900c8e89293541 100644 (file)
--- a/DISTLIST
+++ b/DISTLIST
@@ -159,6 +159,7 @@ include/grub/i386/pc/vbefill.h
 include/grub/i386/pc/vbe.h
 include/grub/i386/pc/vbeutil.h
 include/grub/i386/pc/vga.h
+include/grub/i386/pit.h
 include/grub/i386/setjmp.h
 include/grub/i386/time.h
 include/grub/i386/types.h
@@ -240,6 +241,7 @@ kern/i386/loader.S
 kern/i386/pc/init.c
 kern/i386/pc/lzo1x.S
 kern/i386/pc/startup.S
+kern/i386/pit.c
 kern/i386/realmode.S
 kern/ieee1275/cmain.c
 kern/ieee1275/ieee1275.c
index c4ca95e8ce7ac01a9f8c393f2a964a54fae68358..5535dab7ac0eab4921bfd6082f7534b8483ada87 100644 (file)
@@ -18,6 +18,9 @@ kernel_elf_SOURCES = kern/i386/linuxbios/startup.S kern/i386/linuxbios/init.c \
        kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
        kern/time.c \
        kern/i386/dl.c kern/parser.c kern/partition.c \
+       kern/i386/tsc.c kern/i386/pit.c \
+       kern/generic/rtc_get_time_ms.c \
+       kern/generic/millisleep.c \
        kern/env.c \
        term/i386/pc/console.c \
        term/i386/pc/at_keyboard.c term/i386/pc/vga_text.c \
index e35a5c9a7adba185dde57eb63da9b49e034b1df0..a3234b596628b16691ab830985afb9f8fe9a8764 100644 (file)
@@ -85,7 +85,7 @@ kernel_mod_SOURCES = kern/i386/efi/startup.S kern/main.c kern/device.c \
        kern/i386/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \
        kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \
        term/efi/console.c disk/efi/efidisk.c \
-       kern/i386/tsc.c \
+       kern/i386/tsc.c kern/i386/pit.c \
        kern/generic/rtc_get_time_ms.c \
        kern/generic/millisleep.c
 kernel_mod_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
index 3e8469e000d521ad036ab63033385e0ddd07a90c..c1e4ac4a919c3887e140c3221646b636ff3ba86d 100644 (file)
@@ -44,7 +44,7 @@ kernel_img_SOURCES = kern/i386/pc/startup.S kern/main.c kern/device.c \
        kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
        kern/time.c \
        kern/i386/dl.c kern/i386/pc/init.c kern/parser.c kern/partition.c \
-       kern/i386/tsc.c \
+       kern/i386/tsc.c kern/i386/pit.c \
        kern/generic/rtc_get_time_ms.c \
        kern/generic/millisleep.c \
        kern/env.c \
diff --git a/include/grub/i386/pit.h b/include/grub/i386/pit.h
new file mode 100644 (file)
index 0000000..7ac0256
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+extern void grub_pit_wait (grub_uint16_t tics);
index 1d25986b75853affbe744a6be1b4322a5915a0ab..0e6567b9df49041e69b17b62d9e347489290a17c 100644 (file)
@@ -60,11 +60,6 @@ grub_stop_floppy (void)
   grub_outb (0, GRUB_FLOPPY_REG_DIGITAL_OUTPUT);
 }
 
-void
-grub_millisleep (grub_uint32_t ms __attribute__ ((unused)))
-{
-}
-
 void
 grub_exit (void)
 {
@@ -144,7 +139,7 @@ grub_machine_init (void)
   /* This variable indicates size, not offset.  */
   grub_upper_mem -= GRUB_MEMORY_MACHINE_UPPER_START;
 
-  grub_install_get_time_ms (grub_rtc_get_time_ms);
+  grub_tsc_init ();
 }
 
 void
diff --git a/kern/i386/pit.c b/kern/i386/pit.c
new file mode 100644 (file)
index 0000000..0dbbf1c
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2008  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/types.h>
+#include <grub/cpu/io.h>
+
+#define TIMER2_REG_CONTROL     0x42
+#define TIMER_REG_COMMAND      0x43
+#define TIMER2_REG_LATCH       0x61
+
+#define TIMER2_SELECT          0x80
+#define TIMER_ENABLE_LSB       0x20
+#define TIMER_ENABLE_MSB       0x10
+#define TIMER2_LATCH           0x20
+
+void
+grub_pit_wait (grub_uint16_t tics)
+{
+  grub_outb (TIMER2_SELECT | TIMER_ENABLE_LSB | TIMER_ENABLE_MSB, TIMER_REG_COMMAND);
+  grub_outb (tics & 0xff, TIMER2_REG_CONTROL);
+  grub_outb (tics >> 8, TIMER2_REG_CONTROL);
+
+  while ((grub_inb (TIMER2_REG_LATCH) & TIMER2_LATCH) == 0x00);
+}
index a142e3d64e5620d165e103faae9d8c1c4aaf4e27..458fc0ec9e5f3019ae9c9a51d28c608588330870 100644 (file)
@@ -25,8 +25,7 @@
 #include <grub/misc.h>
 #include <grub/i386/tsc.h>
 
-/* Calibrated reference for TSC=0.  This defines the time since the epoch in 
-   milliseconds that TSC=0 refers to. */
+/* This defines the value TSC had at the epoch (that is, when we calibrated it). */
 static grub_uint64_t tsc_boot_time;
 
 /* Calibrated TSC rate.  (In TSC ticks per millisecond.) */
@@ -47,44 +46,15 @@ grub_tsc_get_time_ms (void)
 static void
 calibrate_tsc (void)
 {
-  /* First calbrate the TSC rate (relative, not absolute time). */
+  /* First calibrate the TSC rate (relative, not absolute time). */
   grub_uint64_t start_tsc;
   grub_uint64_t end_tsc;
-  grub_uint32_t initial_tick;
-  grub_uint32_t start_tick;
-  grub_uint32_t end_tick;
 
-  /* Wait for the start of the next tick;
-     we'll base out timing off this edge. */
-  initial_tick = grub_get_rtc ();
-  do
-    {
-      start_tick = grub_get_rtc ();
-    }
-  while (start_tick == initial_tick);
   start_tsc = grub_get_tsc ();
-
-  /* Wait for the start of the next tick.  This will
-     be the end of the 1-tick period. */
-  do
-    {
-      end_tick = grub_get_rtc ();
-    }
-  while (end_tick - start_tick < CALIBRATION_TICKS);
+  grub_pit_wait (0xffff);
   end_tsc = grub_get_tsc ();
 
-  tsc_ticks_per_ms =
-    grub_divmod64 (grub_divmod64
-                   (end_tsc - start_tsc, end_tick - start_tick, 0)
-                   * GRUB_TICKS_PER_SECOND, 1000, 0);
-
-  /* Reference the TSC zero (boot time) to the epoch to 
-     get an absolute real time reference. */
-  grub_uint64_t ms_since_boot = grub_divmod64 (end_tsc, tsc_ticks_per_ms, 0);
-  grub_uint64_t mstime_now = grub_divmod64 ((grub_uint64_t) 1000 * end_tick,
-                                            GRUB_TICKS_PER_SECOND,
-                                            0);
-  tsc_boot_time = mstime_now - ms_since_boot;
+  tsc_ticks_per_ms = grub_divmod64 (end_tsc - start_tsc, 55, 0);
 }
 
 void
@@ -92,6 +62,7 @@ grub_tsc_init (void)
 {
   if (grub_cpu_is_tsc_supported ())
     {
+      tsc_boot_time = grub_get_tsc ();
       calibrate_tsc ();
       grub_install_get_time_ms (grub_tsc_get_time_ms);
     }