Implement grub_sleep() and grub_ticksleep()
PATCH 1/1 Implement grub_sleep() and grub_ticksleep()
This patch implements grub_sleep() and grub_ticksleep().
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
2007-10-15 Robert Millan <[email protected]>
* include/grub/time.h: New file.
* include/grub/i386/pc/time.h (KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
* include/grub/powerpc/ieee1275/time.h: Likewise.
* include/grub/sparc64/ieee1275/time.h: Likewise.
* kern/i386/efi/init.c: Include `grub/time.h'. (grub_ticksleep): New function.
* kern/i386/pc/init.c: Likewise.
* kern/powerpc/ieee1275/init.c: Likewise.
* kern/sparc64/ieee1275/init.c: Likewise.
include/grub/i386/pc/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/powerpc/ieee1275/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/sparc64/ieee1275/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/time.h +42 -0
42 lines not on this page · raw message
kern/i386/efi/init.c +10 -0
@@ -25,6 +25,16 @@#include <grub/cache.h> #include <grub/kernel.h> #include <grub/efi/efi.h> +#include <grub/time.h> + +void +grub_ticksleep (grub_uint32_t ticks) +{ +grub_uint32_t end_at; + end_at =grub_get_rtc () + ticks; +while (grub_get_rtc () < end_at) +grub_cpu_idle (); +}void grub_machine_init (void )
kern/i386/pc/init.c +10 -0
@@ -30,6 +30,7 @@#include <grub/loader.h> #include <grub/env.h> #include <grub/cache.h> +#include <grub/time.h> struct mem_region {
@@ -46,6 +47,15 @@grub_size_t grub_os_area_size;grub_size_t grub_lower_mem, grub_upper_mem; +void +grub_ticksleep (grub_uint32_t ticks) +{ +grub_uint32_t end_at; + end_at =grub_get_rtc () + ticks; +while (grub_get_rtc () < end_at) +grub_cpu_idle (); +} +void grub_arch_sync_caches (void *address __attribute__ ((unused)),grub_size_t len __attribute__ ((unused)))
kern/powerpc/ieee1275/init.c +10 -1
@@ -27,8 +27,8 @@#include <grub/setjmp.h> #include <grub/env.h> #include <grub/misc.h> +#include <grub/time.h> #include <grub/machine/console.h> -#include <grub/machine/time.h> #include <grub/machine/kernel.h> #include <grub/ieee1275/ofdisk.h> #include <grub/ieee1275/ieee1275.h>
@@ -47,6 +47,15 @@extern char _end[];void +grub_ticksleep (grub_uint32_t ticks) +{ +grub_uint32_t end_at; + end_at =grub_get_rtc () + ticks; +while (grub_get_rtc () < end_at) +grub_cpu_idle (); +} + +void grub_exit (void ) {/* Trap to Open Firmware. */
kern/sparc64/ieee1275/init.c +10 -0
@@ -27,6 +27,7 @@#include <grub/setjmp.h> #include <grub/env.h> #include <grub/misc.h> +#include <grub/time.h> #include <grub/machine/console.h> #include <grub/machine/time.h> #include <grub/machine/kernel.h>
@@ -66,6 +67,15 @@/* Never reached. */ } +void +grub_ticksleep (grub_uint32_t ticks) +{ +grub_uint32_t end_at; + end_at =grub_get_rtc () + ticks; +while (grub_get_rtc () < end_at) +grub_cpu_idle (); +} +int grub_ieee1275_test_flag (enum grub_ieee1275_flag flag) {
Quoted 1 line · Robert Millan
This patch implements
grub_sleep()andgrub_ticksleep().
Great!
Quoted 9 lines
2007-10-15 Robert Millan <[email protected]>
*
include/grub/time.h: New file.*
include/grub/i386/pc/time.h(KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
*include/grub/powerpc/ieee1275/time.h: Likewise.
*include/grub/sparc64/ieee1275/time.h: Likewise.
Better just repeat the same process for the last two lines.
Quoted 5 lines
*
kern/i386/efi/init.c: Include `grub/time.h'. (grub_ticksleep): New function.
*kern/i386/pc/init.c: Likewise.
*kern/powerpc/ieee1275/init.c: Likewise.
*kern/sparc64/ieee1275/init.c: Likewise.
Please repeat is. Only use likewise when the change to one function is the same. Better do too much instead of not enough.
include/grub/time.h line 31
Quoted 10 lines
include/grub/time.h +10
-0+#include <grub/symbol.h> +#include <grub/machine/time.h> + +void EXPORT_FUNC (grub_ticksleep ) (grub_uint32_t ticks); + +static __inlinevoid +grub_sleep (grub_uint32_t s) +{ +grub_ticksleep (s *GRUB_TICKS_PER_SECOND ); +}
Sleeping entire seconds is a bit much. Can you also add this for smaller time instances? If you divide, please round up so that no waiting at all is avoided. Most of the time you can better wait a bit too long, I think.
include/grub/time.h line 40
Quoted 8 lines
include/grub/time.h +8
-0+static __inlinevoid +grub_cpu_idle () +{ +#if defined(__i386__) + __asm__ __volatile__ ("hlt" ); +/* FIXME: add other CPUs here */ +#endif +}
This should go into a arch specific headerfile.
Quoted 8 lines
+#endif /* !
KERNEL_TIME_HEADER*/
diff -Nurgrub2/kern/i386/efi/init.cgrub2.ticks/kern/i386/efi/init.ckern/i386/efi/init.c +0
-0@@ -25,6 +25,16 @@#include <grub/cache.h> #include <grub/kernel.h> #include <grub/efi/efi.h>
kern/i386/efi/init.c line 37
Quoted 10 lines
kern/i386/efi/init.c +10
-0+#include <grub/time.h> + +void +grub_ticksleep (grub_uint32_t ticks) +{ +grub_uint32_t end_at; + end_at =grub_get_rtc () + ticks; +while (grub_get_rtc () < end_at) +grub_cpu_idle (); +}
Why do you recreate this for every arch? This seems portable as long as you can sleep a bit from time to time.
--
Marco
Quoted 18 lines · Marco Gerards
Quoted 1 line · Robert Millan
This patch implements
grub_sleep()andgrub_ticksleep().Great!
Quoted 9 lines
2007-10-15 Robert Millan <[email protected]>
*
include/grub/time.h: New file.*
include/grub/i386/pc/time.h(KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
*include/grub/powerpc/ieee1275/time.h: Likewise.
*include/grub/sparc64/ieee1275/time.h: Likewise.Better just repeat the same process for the last two lines.
Quoted 8 lines
Quoted 5 lines
*
kern/i386/efi/init.c: Include `grub/time.h'. (grub_ticksleep): New function.
*kern/i386/pc/init.c: Likewise.
*kern/powerpc/ieee1275/init.c: Likewise.
*kern/sparc64/ieee1275/init.c: Likewise.Please repeat is. Only use likewise when the change to one function is the same. Better do too much instead of not enough.
Ok
Quoted 5 lines
Quoted 5 lines
include/grub/time.h +5
-0+#include <grub/symbol.h> +#include <grub/machine/time.h> + +void EXPORT_FUNC (grub_ticksleep ) (grub_uint32_t ticks); +
Quoted 8 lines
include/grub/time.h line 31
Quoted 5 lines
include/grub/time.h +5
-0+static __inlinevoid +grub_sleep (grub_uint32_t s) +{ +grub_ticksleep (s *GRUB_TICKS_PER_SECOND ); +}Sleeping entire seconds is a bit much. Can you also add this for smaller time instances?
That's what grub_ticksleep does. grub_sleep() counts in seconds because I tried to mimic POSIX which seems to be a trend for grub_* functions. I think it can be used for menu timeout although I didn't have time to look.
Quoted 10 lines
include/grub/time.h line 40
Quoted 8 lines
include/grub/time.h +8
-0+static __inlinevoid +grub_cpu_idle () +{ +#if defined(__i386__) + __asm__ __volatile__ ("hlt" ); +/* FIXME: add other CPUs here */ +#endif +}This should go into a arch specific headerfile.
Is this really necessary? It simplifies things a lot, since every cpu would need a time.h just for that, whereas currently non-i386 gets a dummy stub for free.
OTOH, this wouldn't be the first place in grub where __i386__ is tested ;-)
Quoted 13 lines
Quoted 13 lines
+#endif /* !
KERNEL_TIME_HEADER*/
diff -Nurgrub2/kern/i386/efi/init.cgrub2.ticks/kern/i386/efi/init.ckern/i386/efi/init.c +5
-0@@ -25,6 +25,16 @@#include <grub/cache.h> #include <grub/kernel.h> #include <grub/efi/efi.h> +#include <grub/time.h> + +void +grub_ticksleep (grub_uint32_t ticks) +{
Quoted 8 lines
kern/i386/efi/init.c line 37
Quoted 5 lines
kern/i386/efi/init.c +5
-0+grub_uint32_t end_at; + end_at =grub_get_rtc () + ticks; +while (grub_get_rtc () < end_at) +grub_cpu_idle (); +}Why do you recreate this for every arch? This seems portable as long as you can sleep a bit from time to time.
What if a platform provides a sleep-like mechanism, but not a get_rtc-like one? You can implement sleep around get_rtc easily, but not the other way around. This is the case for LB (simply because grub_get_rtc is not implemented yet), but it could also happen on platforms that are designed not to provide it or are just buggy.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
Robert Millan <[email protected]> writes:
Hi,
[...]
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
include/grub/time.h +5
-0+#include <grub/symbol.h> +#include <grub/machine/time.h> + +void EXPORT_FUNC (grub_ticksleep ) (grub_uint32_t ticks); +Quoted 8 lines
include/grub/time.h line 31
Quoted 5 lines
include/grub/time.h +5
-0+static __inlinevoid +grub_sleep (grub_uint32_t s) +{ +grub_ticksleep (s *GRUB_TICKS_PER_SECOND ); +}Sleeping entire seconds is a bit much. Can you also add this for smaller time instances?
Quoted 3 lines
That's what
grub_ticksleepdoes.grub_sleep()counts in seconds because I tried to mimic POSIX which seems to be a trend for grub_* functions. I think it can be used for menu timeout although I didn't have time to look.
Right. Although I do not like setting the time in GRUB_TICKS_PER_SECOND for millisecond stuff, etc. In that case everyone has to implement the same functionality.
Quoted 11 lines
Quoted 10 lines
include/grub/time.h line 40
Quoted 8 lines
include/grub/time.h +8
-0+static __inlinevoid +grub_cpu_idle () +{ +#if defined(__i386__) + __asm__ __volatile__ ("hlt" ); +/* FIXME: add other CPUs here */ +#endif +}This should go into a arch specific headerfile.
Quoted 3 lines
Is this really necessary? It simplifies things a lot, since every cpu would need a
time.hjust for that, whereas currently non-i386 gets a dummy stub for free.
Most of the time we use the arch specific header files. That is what they are for.
Quoted 1 line
OTOH, this wouldn't be the first place in grub where
__i386__is tested ;-)
Oh? Perhaps that code is wrong?
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
+#endif /* !
KERNEL_TIME_HEADER*/
diff -Nurgrub2/kern/i386/efi/init.cgrub2.ticks/kern/i386/efi/init.ckern/i386/efi/init.c +5
-0@@ -25,6 +25,16 @@#include <grub/cache.h> #include <grub/kernel.h> #include <grub/efi/efi.h> +#include <grub/time.h> + +void +grub_ticksleep (grub_uint32_t ticks) +{Quoted 8 lines
kern/i386/efi/init.c line 37
Quoted 5 lines
kern/i386/efi/init.c +5
-0+grub_uint32_t end_at; + end_at =grub_get_rtc () + ticks; +while (grub_get_rtc () < end_at) +grub_cpu_idle (); +}Why do you recreate this for every arch? This seems portable as long as you can sleep a bit from time to time.
Quoted 5 lines
What if a platform provides a sleep-like mechanism, but not a get_rtc-like one? You can implement sleep around
get_rtceasily, but not the other way around. This is the case for LB (simply becausegrub_get_rtcis not implemented yet), but it could also happen on platforms that are designed not to provide it or are just buggy.
Well, I have no objections to this approach. Are you sure init.c is the right place?
--
Marco
Quoted 8 lines · Marco Gerards
Quoted 4 lines
That's what
grub_ticksleepdoes.grub_sleep()counts in seconds because I tried to mimic POSIX which seems to be a trend for grub_* functions. I think it can be used for menu timeout although I didn't have time to look.Right. Although I do not like setting the time in
GRUB_TICKS_PER_SECONDfor millisecond stuff, etc. In that case everyone has to implement the same functionality.
Moved to grub_millisleep().
Quoted 3 lines
Quoted 1 line
OTOH, this wouldn't be the first place in grub where
__i386__is tested ;-)Oh? Perhaps that code is wrong?
Actually now that I check it's only in one file. But the code is right afaict.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Review
Quoted 9 lines
(quoted diff) +9
-0+ +void +grub_ticksleep (grub_uint32_t ticks) +{ + grub_uint32_t end_at; + end_at = grub_get_rtc () + ticks; + while (grub_get_rtc () < end_at) + grub_cpu_idle (); +}Why do you recreate this for every arch? This seems portable as long as you can sleep a bit from time to time.
Quoted 7 lines
Quoted 5 lines
What if a platform provides a sleep-like mechanism, but not a get_rtc-like one? You can implement sleep around
get_rtceasily, but not the other way around. This is the case for LB (simply becausegrub_get_rtcis not implemented yet), but it could also happen on platforms that are designed not to provide it or are just buggy.Well, I have no objections to this approach.
Ok. I made it a bit better by implementing grub_millisleep_generic in kern/misc.c and making each port just use that, having the option to do it their way if preferred.
Quoted 2 lines
Are you sure
init.cis
the right place?
Mostly. I've observed that for code that doesn't obviously belong somewhere else, it tends to be in init.c if it's in C and startup.S if it's in asm (in i386/pc/startup.S it actually gets to the extreme, since only a small part of it is used for "startup" as such).
So I think init.c is fine.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
2007-10-15 Robert Millan <[email protected]>
* include/grub/time.h: New file.
* include/grub/i386/time.h: Likewise.
* include/grub/powerpc/time.h: Likewise.
* include/grub/sparc64/time.h: Likewise.
* include/grub/i386/pc/time.h (KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
* include/grub/powerpc/ieee1275/time.h (KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
* include/grub/sparc64/ieee1275/time.h (KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
* kern/i386/efi/init.c: Include `grub/time.h'. (grub_millisleep): New function.
* kern/i386/pc/init.c: Include `grub/time.h'. (grub_millisleep): New function.
* kern/powerpc/ieee1275/init.c: Include grub/time.h'. Remove grub/machine/time.h' include. (grub_millisleep): New function.
* kern/sparc64/ieee1275/init.c: Include grub/time.h'. Remove grub/machine/time.h' include. (grub_millisleep): New function.
* kern/misc.c: Include `grub/time.h'.
(grub_millisleep_generic): New function.
include/grub/i386/pc/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/i386/time.h +28 -0
@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ + __asm__ __volatile__ ("hlt" ); +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */
include/grub/powerpc/ieee1275/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/powerpc/time.h +28 -0
@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ +/* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */
include/grub/sparc64/ieee1275/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/sparc64/time.h +28 -0
@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ +/* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */
include/grub/time.h +38 -0
@@ -0,0 +1,38 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_TIME_HEADER +#define KERNEL_TIME_HEADER 1 + +#include <grub/symbol.h> +#include <grub/machine/time.h> +#include <grub/cpu/time.h> + +void EXPORT_FUNC (grub_millisleep ) (grub_uint32_t ms); +void EXPORT_FUNC (grub_millisleep_generic ) (grub_uint32_t ms); + +static __inlinevoid +grub_sleep (grub_uint32_t s) +{ +grub_millisleep (1000 * s); +} + +/* Duration of a tick in milliseconds, rounded up */ +#define TICK_DURATION_IN_MS ((1000 + GRUB_TICKS_PER_SECOND) / GRUB_TICKS_PER_SECOND) + +#endif /* ! KERNEL_TIME_HEADER */
kern/i386/efi/init.c +7 -0
@@ -25,6 +25,13 @@#include <grub/cache.h> #include <grub/kernel.h> #include <grub/efi/efi.h> +#include <grub/time.h> + +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +}void grub_machine_init (void )
kern/i386/pc/init.c +7 -0
@@ -30,6 +30,7 @@#include <grub/loader.h> #include <grub/env.h> #include <grub/cache.h> +#include <grub/time.h> struct mem_region {
@@ -46,6 +47,12 @@ grub_addr_t grub_os_area_addr;grub_size_t grub_os_area_size;grub_size_t grub_lower_mem, grub_upper_mem; +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} +void grub_arch_sync_caches (void *address __attribute__ ((unused)),grub_size_t len __attribute__ ((unused)))
kern/misc.c +18 -0
@@ -23,6 +23,7 @@#include <stdarg.h> #include <grub/term.h> #include <grub/env.h> +#include <grub/time.h> void *grub_memmove (void *dest,const void *src,grub_size_t n)
@@ -1041,6 +1042,23 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest,return p - dest; } +void +grub_millisleep_generic (grub_uint32_t ms) +{ +grub_uint32_t time; +int i; + +for (; ms >0 ; ms -=TICK_DURATION_IN_MS ) +/* wait for the lowest fraction of milliseconds we can (rounded up) */ +for (i =0 ; i <TICK_DURATION_IN_MS ; i++) + { +/* wait for next tick */ + time =grub_get_rtc (); +while (time ==grub_get_rtc ()) +grub_cpu_idle (); + } +} +/* Abort GRUB. This function does not return. */ void grub_abort (void )
kern/powerpc/ieee1275/init.c +7 -1
@@ -27,8 +27,8 @@#include <grub/setjmp.h> #include <grub/env.h> #include <grub/misc.h> +#include <grub/time.h> #include <grub/machine/console.h> -#include <grub/machine/time.h> #include <grub/machine/kernel.h> #include <grub/ieee1275/ofdisk.h> #include <grub/ieee1275/ieee1275.h>
@@ -47,6 +47,12 @@ extern char _start[];extern char _end[];void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} + +void grub_exit (void ) {/* Trap to Open Firmware. */
kern/sparc64/ieee1275/init.c +7 -1
@@ -27,8 +27,8 @@#include <grub/setjmp.h> #include <grub/env.h> #include <grub/misc.h> +#include <grub/time.h> #include <grub/machine/console.h> -#include <grub/machine/time.h> #include <grub/machine/kernel.h> #include <grub/ieee1275/ofdisk.h> #include <grub/ieee1275/ieee1275.h>
@@ -66,6 +66,12 @@ _start (uint64_t r0 __attribute__((unuse/* Never reached. */ } +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} +int grub_ieee1275_test_flag (enum grub_ieee1275_flag flag) {
Quoted 11 lines · Robert Millan
Quoted 8 lines · Marco Gerards
Quoted 4 lines
That's what
grub_ticksleepdoes.grub_sleep()counts in seconds because I tried to mimic POSIX which seems to be a trend for grub_* functions. I think it can be used for menu timeout although I didn't have time to look.Right. Although I do not like setting the time in
GRUB_TICKS_PER_SECONDfor millisecond stuff, etc. In that case everyone has to implement the same functionality.Moved to
grub_millisleep().
Good :)
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
OTOH, this wouldn't be the first place in grub where
__i386__is tested ;-)Oh? Perhaps that code is wrong?
Actually now that I check it's only in one file. But the code is right afaict.
What I mean is that this might be a wrong approach in this other file as well.
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 4 lines
Quoted 4 lines
kern/i386/efi/init.c +4
-0+ +void +grub_ticksleep (grub_uint32_t ticks) +{Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ grub_uint32_t end_at; + end_at = grub_get_rtc () + ticks; + while (grub_get_rtc () < end_at) + grub_cpu_idle (); +}Why do you recreate this for every arch? This seems portable as long as you can sleep a bit from time to time.
What if a platform provides a sleep-like mechanism, but not a get_rtc-like one? You can implement sleep around
get_rtceasily, but not the other way around. This is the case for LB (simply becausegrub_get_rtcis not implemented yet), but it could also happen on platforms that are designed not to provide it or are just buggy.
Quoted 5 lines
Quoted 1 line
Well, I have no objections to this approach.
Ok. I made it a bit better by implementing
grub_millisleep_genericinkern/misc.cand making each port just use that, having the option to do it their way if preferred.
Great.
Quoted 9 lines
Quoted 2 lines
Are you sure
init.cis
the right place?Mostly. I've observed that for code that doesn't obviously belong somewhere else, it tends to be in
init.cif it's in C andstartup.Sif it's in asm (ini386/pc/startup.Sit actually gets to the extreme, since only a small part of it is used for "startup" as such).So I think
init.cis fine.
Ok.
Quoted 17 lines
2007-10-15 Robert Millan <[email protected]>
*
include/grub/time.h: New file.
*include/grub/i386/time.h: Likewise.
*include/grub/powerpc/time.h: Likewise.
*include/grub/sparc64/time.h: Likewise.*
include/grub/i386/pc/time.h(KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
*include/grub/powerpc/ieee1275/time.h(KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
*include/grub/sparc64/ieee1275/time.h(KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
Quoted 1 line
*
kern/i386/efi/init.c: Include `grub/time.h'.
<grub/time.h> is preferred.
[...]
Quoted 6 lines
kern/misc.c +6
-0+void +grub_millisleep_generic (grub_uint32_t ms) +{ +grub_uint32_t time; +int i; +
kern/misc.c grub_utf8_to_ucs4 (grub_uint32_t *dest, · line 1060
Quoted 10 lines
kern/misc.c +10
-0+for (; ms >0 ; ms -=TICK_DURATION_IN_MS ) +/* wait for the lowest fraction of milliseconds we can (rounded up) */ +for (i =0 ; i <TICK_DURATION_IN_MS ; i++) + { +/* wait for next tick */ + time =grub_get_rtc (); +while (time ==grub_get_rtc ()) +grub_cpu_idle (); + } +}
The problem with this is when TICK_DURATION_IN_MS is not very accurate. I think you can be more accurate if you use TICKS_PER_SECOND and use it to calculate the total amount of ticks to wait. This will avoid rounding problems. Accuracy is not always that important, but I prefer to have it, if we can.
--
Marco
Quoted 3 lines · Marco Gerards
Quoted 1 line
*
kern/i386/efi/init.c: Include `grub/time.h'.<
grub/time.h> is preferred.
Fixed.
Quoted 14 lines
Quoted 14 lines
(quoted diff) +14
-0+void +grub_millisleep_generic (grub_uint32_t ms) +{ + grub_uint32_t time; + int i; + + for (; ms > 0; ms -= TICK_DURATION_IN_MS) + /* wait for the lowest fraction of milliseconds we can (rounded up) */ + for (i = 0; i < TICK_DURATION_IN_MS; i++) + { + /* wait for next tick */ + time = grub_get_rtc (); + while (time == grub_get_rtc ()) + grub_cpu_idle ();
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ } +}The problem with this is when
TICK_DURATION_IN_MSis not very accurate. I think you can be more accurate if you useTICKS_PER_SECONDand use it to calculate the total amount of ticks to wait. This will avoid rounding problems. Accuracy is not always that important, but I prefer to have it, if we can.
Fixed, I think.
Attached new patch.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
2007-10-19 Robert Millan <[email protected]>
* include/grub/time.h: New file.
* include/grub/i386/time.h: Likewise.
* include/grub/powerpc/time.h: Likewise.
* include/grub/sparc64/time.h: Likewise.
* include/grub/i386/pc/time.h (KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
* include/grub/powerpc/ieee1275/time.h (KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
* include/grub/sparc64/ieee1275/time.h (KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
* kern/i386/efi/init.c: Include `<grub/time.h>'. (grub_millisleep): New function.
* kern/i386/pc/init.c: Include `<grub/time.h>'. (grub_millisleep): New function.
* kern/powerpc/ieee1275/init.c: Include <grub/time.h>'. Remove grub/machine/time.h' include. (grub_millisleep): New function.
* kern/sparc64/ieee1275/init.c: Include <grub/time.h>'. Remove grub/machine/time.h' include. (grub_millisleep): New function.
* include/grub/misc.h (grub_div_roundup): New function.
* kern/misc.c: Include `<grub/time.h>'.
(grub_millisleep_generic): New function.
include/grub/i386/pc/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/i386/time.h +28 -0
@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ + __asm__ __volatile__ ("hlt" ); +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */
include/grub/misc.h +8 -0
@@ -83,6 +83,7 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) grub_uint32_t d, grub_uint32_t *r);/* Inline functions. */ +static inline unsigned int grub_abs (int x) {
@@ -92,4 +93,11 @@ grub_abs (int x) return (unsigned int) x; } +/* Rounded-up division */ +static inline unsigned int +grub_div_roundup (unsigned int x,unsigned int y) +{ +return (x + (y -1 ) / y); +} +#endif /* ! GRUB_MISC_HEADER */
include/grub/powerpc/ieee1275/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/powerpc/time.h +28 -0
@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ +/* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */
include/grub/sparc64/ieee1275/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/sparc64/time.h +28 -0
@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ +/* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */
include/grub/time.h +35 -0
@@ -0,0 +1,35 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_TIME_HEADER +#define KERNEL_TIME_HEADER 1 + +#include <grub/symbol.h> +#include <grub/machine/time.h> +#include <grub/cpu/time.h> + +void EXPORT_FUNC (grub_millisleep ) (grub_uint32_t ms); +void EXPORT_FUNC (grub_millisleep_generic ) (grub_uint32_t ms); + +static __inlinevoid +grub_sleep (grub_uint32_t s) +{ +grub_millisleep (1000 * s); +} + +#endif /* ! KERNEL_TIME_HEADER */
kern/i386/efi/init.c +7 -0
@@ -25,6 +25,13 @@#include <grub/cache.h> #include <grub/kernel.h> #include <grub/efi/efi.h> +#include <grub/time.h> + +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +}void grub_machine_init (void )
kern/i386/pc/init.c +7 -0
@@ -30,6 +30,7 @@#include <grub/loader.h> #include <grub/env.h> #include <grub/cache.h> +#include <grub/time.h> struct mem_region {
@@ -46,6 +47,12 @@ grub_addr_t grub_os_area_addr;grub_size_t grub_os_area_size;grub_size_t grub_lower_mem, grub_upper_mem; +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} +void grub_arch_sync_caches (void *address __attribute__ ((unused)),grub_size_t len __attribute__ ((unused)))
kern/misc.c +12 -0
@@ -23,6 +23,7 @@#include <stdarg.h> #include <grub/term.h> #include <grub/env.h> +#include <grub/time.h> void *grub_memmove (void *dest,const void *src,grub_size_t n)
@@ -1041,6 +1042,17 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest,return p - dest; } +void +grub_millisleep_generic (grub_uint32_t ms) +{ +grub_uint32_t end_at; + + end_at =grub_get_rtc () +grub_div_roundup (ms *GRUB_TICKS_PER_SECOND ,1000 ); + +while (grub_get_rtc () < end_at) +grub_cpu_idle (); +} +/* Abort GRUB. This function does not return. */ void grub_abort (void )
kern/powerpc/ieee1275/init.c +7 -1
@@ -27,8 +27,8 @@#include <grub/setjmp.h> #include <grub/env.h> #include <grub/misc.h> +#include <grub/time.h> #include <grub/machine/console.h> -#include <grub/machine/time.h> #include <grub/machine/kernel.h> #include <grub/ieee1275/ofdisk.h> #include <grub/ieee1275/ieee1275.h>
@@ -47,6 +47,12 @@ extern char _start[];extern char _end[];void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} + +void grub_exit (void ) {/* Trap to Open Firmware. */
kern/sparc64/ieee1275/init.c +7 -1
@@ -27,8 +27,8 @@#include <grub/setjmp.h> #include <grub/env.h> #include <grub/misc.h> +#include <grub/time.h> #include <grub/machine/console.h> -#include <grub/machine/time.h> #include <grub/machine/kernel.h> #include <grub/ieee1275/ofdisk.h> #include <grub/ieee1275/ieee1275.h>
@@ -66,6 +66,12 @@ _start (uint64_t r0 __attribute__((unuse/* Never reached. */ } +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} +int grub_ieee1275_test_flag (enum grub_ieee1275_flag flag) {
Robert Millan <[email protected]> writes:
Hi,
[...]
Quoted 1 line
Fixed, I think.
Yes, I think it is :-)
include/grub/misc.h grub_uint64_t EXPORT_FUNC(grub_divmod64) · line 88
Quoted 13 lines
Attached new patch.
diff -Nurp
grub2/include/grub/misc.hgrub2.time/include/grub/misc.hinclude/grub/misc.h +1
-0@@ -83,6 +83,7 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) grub_uint32_t d, grub_uint32_t *r);/* Inline functions. */ +static inline unsigned int grub_abs (int x)
You accidently added a whitespace above.
Please remove this before you apply.
--
Marco
Hi Marco,
Quoted 6 lines · Marco Gerards
Quoted 6 lines
diff -Nurp
grub2/include/grub/misc.hgrub2.time/include/grub/misc.hinclude/grub/misc.h +0
-0@@ -83,6 +83,7 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) grub_uint32_t d, grub_uint32_t *r);
Quoted 8 lines
include/grub/misc.h grub_uint64_t EXPORT_FUNC(grub_divmod64) · line 88
Quoted 4 lines
include/grub/misc.h +1
-0/* Inline functions. */ +static inline unsigned int grub_abs (int x)You accidently added a whitespace above.
Please remove this before you apply.
It looks accidental, but it was intended. The whole code was changed from:
/* Inline functions. */
grub_just_one_inline_function ()
{
stuff;
}to:
/* Inline functions. */
grub_first_inline_function ()
{
stuff;
}
/* Comments on the second function */
grub_second_inline_function ()
{
stuff;
}But if you still don't like that empty line, I have no objection on removing it of course :-)
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
I noticed that one also needs to update time.h headers in conf/*.rmk to make the build system happy about symbol dependencies. See new patch.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)
2007-10-21 Robert Millan <[email protected]>
* include/grub/time.h: New file.
* include/grub/i386/time.h: Likewise.
* include/grub/powerpc/time.h: Likewise.
* include/grub/sparc64/time.h: Likewise.
* include/grub/i386/pc/time.h (KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
* include/grub/powerpc/ieee1275/time.h (KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
* include/grub/sparc64/ieee1275/time.h (KERNEL_TIME_HEADER): Rename all instances to ...
(KERNEL_MACHINE_TIME_HEADER): ... this.
* kern/i386/efi/init.c: Include `<grub/time.h>'. (grub_millisleep): New function.
* kern/i386/pc/init.c: Include `<grub/time.h>'. (grub_millisleep): New function.
* kern/powerpc/ieee1275/init.c: Include <grub/time.h>'. Remove grub/machine/time.h' include. (grub_millisleep): New function.
* kern/sparc64/ieee1275/init.c: Include <grub/time.h>'. Remove grub/machine/time.h' include. (grub_millisleep): New function.
* include/grub/misc.h (grub_div_roundup): New function.
* kern/misc.c: Include `<grub/time.h>'.
(grub_millisleep_generic): New function.
* conf/i386-efi.rmk (kernel_mod_HEADERS): Remove i386/efi/time.h'. Add time.h'.
* conf/i386-pc.rmk (kernel_img_HEADERS): Remove machine/time.h'. Add time.h'.
* conf/powerpc-ieee1275.rmk (kernel_elf_HEADERS): Remove machine/time.h'. Add time.h'.
* conf/sparc64-ieee1275.rmk (kernel_elf_HEADERS): Likewise.
conf/i386-efi.rmk +2 -2
@@ -88,8 +88,8 @@ kernel_mod_SOURCES = kern/i386/efi/start term/efi/console.c disk/efi/efidisk.c kernel_mod_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h pc_partition.h rescue.h symbol.h term.h types.h \ - i386/efi/time.h efi/efi.h efi/time.h efi/disk.h + partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \ + efi/efi.h efi/time.h efi/disk.h kernel_mod_CFLAGS = $(COMMON_CFLAGS) kernel_mod_ASFLAGS = $(COMMON_ASFLAGS) kernel_mod_LDFLAGS = $(COMMON_LDFLAGS)
conf/i386-pc.rmk +2 -3
@@ -32,10 +32,9 @@ kernel_img_SOURCES = kern/i386/pc/startu symlist.c kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h pc_partition.h rescue.h symbol.h term.h types.h \ + partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \ machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ - machine/memory.h machine/loader.h machine/time.h machine/vga.h \ - machine/vbe.h + machine/memory.h machine/loader.h machine/vga.h machine/vbe.h kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200 $(COMMON_CFLAGS)
conf/powerpc-ieee1275.rmk +2 -2
@@ -12,8 +12,8 @@ DEFSYMFILES += kernel_syms.lst kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \ - symbol.h term.h types.h powerpc/libgcc.h loader.h partition.h \ - pc_partition.h ieee1275/ieee1275.h machine/time.h machine/kernel.h + symbol.h term.h time.h types.h powerpc/libgcc.h loader.h partition.h \ + pc_partition.h ieee1275/ieee1275.h machine/kernel.h kernel_elf_symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
conf/sparc64-ieee1275.rmk +2 -2
@@ -12,8 +12,8 @@ DEFSYMFILES += kernel_syms.lst kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \ - symbol.h term.h types.h sparc64/libgcc.h loader.h partition.h \ - pc_partition.h ieee1275/ieee1275.h machine/time.h machine/kernel.h + symbol.h term.h time.h types.h sparc64/libgcc.h loader.h partition.h \ + pc_partition.h ieee1275/ieee1275.h machine/kernel.h kernel_elf_symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)
include/grub/i386/pc/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/i386/time.h +28 -0
@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ + __asm__ __volatile__ ("hlt" ); +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */
include/grub/misc.h +8 -0
@@ -83,6 +83,7 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) grub_uint32_t d, grub_uint32_t *r);/* Inline functions. */ +static inline unsigned int grub_abs (int x) {
@@ -92,4 +93,11 @@ grub_abs (int x) return (unsigned int) x; } +/* Rounded-up division */ +static inline unsigned int +grub_div_roundup (unsigned int x,unsigned int y) +{ +return (x + (y -1 ) / y); +} +#endif /* ! GRUB_MISC_HEADER */
include/grub/powerpc/ieee1275/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/powerpc/time.h +28 -0
@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ +/* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */
include/grub/sparc64/ieee1275/time.h +3 -3
@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h>
@@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */
include/grub/sparc64/time.h +28 -0
@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ +/* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */
include/grub/time.h +35 -0
@@ -0,0 +1,35 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_TIME_HEADER +#define KERNEL_TIME_HEADER 1 + +#include <grub/symbol.h> +#include <grub/machine/time.h> +#include <grub/cpu/time.h> + +void EXPORT_FUNC (grub_millisleep ) (grub_uint32_t ms); +void EXPORT_FUNC (grub_millisleep_generic ) (grub_uint32_t ms); + +static __inlinevoid +grub_sleep (grub_uint32_t s) +{ +grub_millisleep (1000 * s); +} + +#endif /* ! KERNEL_TIME_HEADER */
kern/i386/efi/init.c +7 -0
@@ -25,6 +25,13 @@#include <grub/cache.h> #include <grub/kernel.h> #include <grub/efi/efi.h> +#include <grub/time.h> + +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +}void grub_machine_init (void )
kern/i386/pc/init.c +7 -0
@@ -30,6 +30,7 @@#include <grub/loader.h> #include <grub/env.h> #include <grub/cache.h> +#include <grub/time.h> struct mem_region {
@@ -46,6 +47,12 @@ grub_addr_t grub_os_area_addr;grub_size_t grub_os_area_size;grub_size_t grub_lower_mem, grub_upper_mem; +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} +void grub_arch_sync_caches (void *address __attribute__ ((unused)),grub_size_t len __attribute__ ((unused)))
kern/misc.c +12 -0
@@ -23,6 +23,7 @@#include <stdarg.h> #include <grub/term.h> #include <grub/env.h> +#include <grub/time.h> void *grub_memmove (void *dest,const void *src,grub_size_t n)
@@ -1041,6 +1042,17 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest,return p - dest; } +void +grub_millisleep_generic (grub_uint32_t ms) +{ +grub_uint32_t end_at; + + end_at =grub_get_rtc () +grub_div_roundup (ms *GRUB_TICKS_PER_SECOND ,1000 ); + +while (grub_get_rtc () < end_at) +grub_cpu_idle (); +} +/* Abort GRUB. This function does not return. */ void grub_abort (void )
kern/powerpc/ieee1275/init.c +7 -1
@@ -27,8 +27,8 @@#include <grub/setjmp.h> #include <grub/env.h> #include <grub/misc.h> +#include <grub/time.h> #include <grub/machine/console.h> -#include <grub/machine/time.h> #include <grub/machine/kernel.h> #include <grub/ieee1275/ofdisk.h> #include <grub/ieee1275/ieee1275.h>
@@ -47,6 +47,12 @@ extern char _start[];extern char _end[];void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} + +void grub_exit (void ) {/* Trap to Open Firmware. */
kern/sparc64/ieee1275/init.c +7 -1
@@ -27,8 +27,8 @@#include <grub/setjmp.h> #include <grub/env.h> #include <grub/misc.h> +#include <grub/time.h> #include <grub/machine/console.h> -#include <grub/machine/time.h> #include <grub/machine/kernel.h> #include <grub/ieee1275/ofdisk.h> #include <grub/ieee1275/ieee1275.h>
@@ -66,6 +66,12 @@ _start (uint64_t r0 __attribute__((unuse/* Never reached. */ } +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} +int grub_ieee1275_test_flag (enum grub_ieee1275_flag flag) {
Committed.
Quoted 455 lines · Robert Millan
I noticed that one also needs to update
time.hheaders in conf/*.rmk to make the build system happy about symbol dependencies. See new patch.Signature · 48 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.) 2007-10-21 Robert Millan <[email protected]> * include/grub/time.h: New file. * include/grub/i386/time.h: Likewise. * include/grub/powerpc/time.h: Likewise. * include/grub/sparc64/time.h: Likewise. * include/grub/i386/pc/time.h (KERNEL_TIME_HEADER): Rename all instances to ... (KERNEL_MACHINE_TIME_HEADER): ... this. * include/grub/powerpc/ieee1275/time.h (KERNEL_TIME_HEADER): Rename all instances to ... (KERNEL_MACHINE_TIME_HEADER): ... this. * include/grub/sparc64/ieee1275/time.h (KERNEL_TIME_HEADER): Rename all instances to ... (KERNEL_MACHINE_TIME_HEADER): ... this. * kern/i386/efi/init.c: Include `<grub/time.h>'. (grub_millisleep): New function. * kern/i386/pc/init.c: Include `<grub/time.h>'. (grub_millisleep): New function. * kern/powerpc/ieee1275/init.c: Include `<grub/time.h>'. Remove `grub/machine/time.h' include. (grub_millisleep): New function. * kern/sparc64/ieee1275/init.c: Include `<grub/time.h>'. Remove `grub/machine/time.h' include. (grub_millisleep): New function. * include/grub/misc.h (grub_div_roundup): New function. * kern/misc.c: Include `<grub/time.h>'. (grub_millisleep_generic): New function. * conf/i386-efi.rmk (kernel_mod_HEADERS): Remove `i386/efi/time.h'. Add `time.h'. * conf/i386-pc.rmk (kernel_img_HEADERS): Remove `machine/time.h'. Add `time.h'. * conf/powerpc-ieee1275.rmk (kernel_elf_HEADERS): Remove `machine/time.h'. Add `time.h'. * conf/sparc64-ieee1275.rmk (kernel_elf_HEADERS): Likewise. diff -Nurp grub2/conf/i386-efi.rmk grub2.time/conf/i386-efi.rmkconf/i386-efi.rmk +2
-2@@ -88,8 +88,8 @@ kernel_mod_SOURCES = kern/i386/efi/start term/efi/console.c disk/efi/efidisk.c kernel_mod_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h pc_partition.h rescue.h symbol.h term.h types.h \ - i386/efi/time.h efi/efi.h efi/time.h efi/disk.h + partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \ + efi/efi.h efi/time.h efi/disk.h kernel_mod_CFLAGS = $(COMMON_CFLAGS) kernel_mod_ASFLAGS = $(COMMON_ASFLAGS) kernel_mod_LDFLAGS = $(COMMON_LDFLAGS)diff -Nurp grub2/conf/i386-pc.rmk grub2.time/conf/i386-pc.rmk
conf/i386-pc.rmk +2
-3@@ -32,10 +32,9 @@ kernel_img_SOURCES = kern/i386/pc/startu symlist.c kernel_img_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \ - partition.h pc_partition.h rescue.h symbol.h term.h types.h \ + partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \ machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ - machine/memory.h machine/loader.h machine/time.h machine/vga.h \ - machine/vbe.h + machine/memory.h machine/loader.h machine/vga.h machine/vbe.h kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200 $(COMMON_CFLAGS)diff -Nurp grub2/conf/powerpc-ieee1275.rmk grub2.time/conf/powerpc-ieee1275.rmk
conf/powerpc-ieee1275.rmk +2
-2@@ -12,8 +12,8 @@ DEFSYMFILES += kernel_syms.lst kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \ - symbol.h term.h types.h powerpc/libgcc.h loader.h partition.h \ - pc_partition.h ieee1275/ieee1275.h machine/time.h machine/kernel.h + symbol.h term.h time.h types.h powerpc/libgcc.h loader.h partition.h \ + pc_partition.h ieee1275/ieee1275.h machine/kernel.h kernel_elf_symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)diff -Nurp grub2/conf/sparc64-ieee1275.rmk grub2.time/conf/sparc64-ieee1275.rmk
conf/sparc64-ieee1275.rmk +2
-2@@ -12,8 +12,8 @@ DEFSYMFILES += kernel_syms.lst kernel_elf_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \ env.h err.h file.h fs.h kernel.h misc.h mm.h net.h parser.h rescue.h \ - symbol.h term.h types.h sparc64/libgcc.h loader.h partition.h \ - pc_partition.h ieee1275/ieee1275.h machine/time.h machine/kernel.h + symbol.h term.h time.h types.h sparc64/libgcc.h loader.h partition.h \ + pc_partition.h ieee1275/ieee1275.h machine/kernel.h kernel_elf_symlist.c: $(addprefix include/grub/,$(kernel_elf_HEADERS)) config.h gensymlist.sh /bin/sh gensymlist.sh $(filter %.h,$^) > $@ || (rm -f $@; exit 1)diff -Nurp
grub2/include/grub/i386/pc/time.hgrub2.time/include/grub/i386/pc/time.hinclude/grub/i386/pc/time.h +3
-3@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h> @@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */ diff -Nurp
grub2/include/grub/i386/time.hgrub2.time/include/grub/i386/time.hinclude/grub/i386/time.h +28
-0@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ + __asm__ __volatile__ ("hlt" ); +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff -Nurp
grub2/include/grub/misc.hgrub2.time/include/grub/misc.hinclude/grub/misc.h +8
-0@@ -83,6 +83,7 @@ grub_uint64_t EXPORT_FUNC(grub_divmod64) grub_uint32_t d, grub_uint32_t *r);/* Inline functions. */ +static inline unsigned int grub_abs (int x) {@@ -92,4 +93,11 @@ grub_abs (int x) return (unsigned int) x; } +/* Rounded-up division */ +static inline unsigned int +grub_div_roundup (unsigned int x,unsigned int y) +{ +return (x + (y -1 ) / y); +} +#endif /* ! GRUB_MISC_HEADER */ diff -Nurp
grub2/include/grub/powerpc/ieee1275/time.hgrub2.time/include/grub/powerpc/ieee1275/time.hinclude/grub/powerpc/ieee1275/time.h +3
-3@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h> @@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */ diff -Nurp
grub2/include/grub/powerpc/time.hgrub2.time/include/grub/powerpc/time.hinclude/grub/powerpc/time.h +28
-0@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ +/* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff -Nurp
grub2/include/grub/sparc64/ieee1275/time.hgrub2.time/include/grub/sparc64/ieee1275/time.hinclude/grub/sparc64/ieee1275/time.h +3
-3@@ -16,8 +16,8 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef KERNEL_TIME_HEADER -#define KERNEL_TIME_HEADER 1 +#ifndef KERNEL_MACHINE_TIME_HEADER +#define KERNEL_MACHINE_TIME_HEADER 1#include <grub/symbol.h> @@ -26,4 +26,4 @@/* Return the real time in ticks. */ grub_uint32_t EXPORT_FUNC (grub_get_rtc ) (void ); -#endif /* ! KERNEL_TIME_HEADER */ +#endif /* ! KERNEL_MACHINE_TIME_HEADER */ diff -Nurp
grub2/include/grub/sparc64/time.hgrub2.time/include/grub/sparc64/time.hinclude/grub/sparc64/time.h +28
-0@@ -0,0 +1,28 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inlinevoid +grub_cpu_idle () +{ +/* FIXME: not implemented */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff -Nurp
grub2/include/grub/time.hgrub2.time/include/grub/time.hinclude/grub/time.h +35
-0@@ -0,0 +1,35 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2007 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/>. +*/ + +#ifndef KERNEL_TIME_HEADER +#define KERNEL_TIME_HEADER 1 + +#include <grub/symbol.h> +#include <grub/machine/time.h> +#include <grub/cpu/time.h> + +void EXPORT_FUNC (grub_millisleep ) (grub_uint32_t ms); +void EXPORT_FUNC (grub_millisleep_generic ) (grub_uint32_t ms); + +static __inlinevoid +grub_sleep (grub_uint32_t s) +{ +grub_millisleep (1000 * s); +} + +#endif /* ! KERNEL_TIME_HEADER */ diff -Nurp
grub2/kern/i386/efi/init.cgrub2.time/kern/i386/efi/init.ckern/i386/efi/init.c +7
-0@@ -25,6 +25,13 @@#include <grub/cache.h> #include <grub/kernel.h> #include <grub/efi/efi.h> +#include <grub/time.h> + +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +}void grub_machine_init (void )diff -Nurp
grub2/kern/i386/pc/init.cgrub2.time/kern/i386/pc/init.ckern/i386/pc/init.c +7
-0@@ -30,6 +30,7 @@#include <grub/loader.h> #include <grub/env.h> #include <grub/cache.h> +#include <grub/time.h> struct mem_region {@@ -46,6 +47,12 @@ grub_addr_t grub_os_area_addr;grub_size_t grub_os_area_size;grub_size_t grub_lower_mem, grub_upper_mem; +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} +void grub_arch_sync_caches (void *address __attribute__ ((unused)),grub_size_t len __attribute__ ((unused)))diff -Nurp
grub2/kern/misc.cgrub2.time/kern/misc.ckern/misc.c +12
-0@@ -23,6 +23,7 @@#include <stdarg.h> #include <grub/term.h> #include <grub/env.h> +#include <grub/time.h> void *grub_memmove (void *dest,const void *src,grub_size_t n)@@ -1041,6 +1042,17 @@ grub_utf8_to_ucs4 (grub_uint32_t *dest,return p - dest; } +void +grub_millisleep_generic (grub_uint32_t ms) +{ +grub_uint32_t end_at; + + end_at =grub_get_rtc () +grub_div_roundup (ms *GRUB_TICKS_PER_SECOND ,1000 ); + +while (grub_get_rtc () < end_at) +grub_cpu_idle (); +} +/* Abort GRUB. This function does not return. */ void grub_abort (void )diff -Nurp
grub2/kern/powerpc/ieee1275/init.cgrub2.time/kern/powerpc/ieee1275/init.ckern/powerpc/ieee1275/init.c +7
-1@@ -27,8 +27,8 @@#include <grub/setjmp.h> #include <grub/env.h> #include <grub/misc.h> +#include <grub/time.h> #include <grub/machine/console.h> -#include <grub/machine/time.h> #include <grub/machine/kernel.h> #include <grub/ieee1275/ofdisk.h> #include <grub/ieee1275/ieee1275.h> @@ -47,6 +47,12 @@ extern char _start[];extern char _end[];void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} + +void grub_exit (void ) {/* Trap to Open Firmware. */ diff -Nurp
grub2/kern/sparc64/ieee1275/init.cgrub2.time/kern/sparc64/ieee1275/init.ckern/sparc64/ieee1275/init.c +7
-1@@ -27,8 +27,8 @@#include <grub/setjmp.h> #include <grub/env.h> #include <grub/misc.h> +#include <grub/time.h> #include <grub/machine/console.h> -#include <grub/machine/time.h> #include <grub/machine/kernel.h> #include <grub/ieee1275/ofdisk.h> #include <grub/ieee1275/ieee1275.h> @@ -66,6 +66,12 @@ _start (uint64_t r0 __attribute__((unuse/* Never reached. */ } +void +grub_millisleep (grub_uint32_t ms) +{ +grub_millisleep_generic (ms); +} +int grub_ieee1275_test_flag (enum grub_ieee1275_flag flag) {_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call, if you are unable to speak? (as seen on /.)