generic timer safeguard

This commit is contained in:
Vladimir Serbinenko committed 2016-02-20 09:12:02 +01:00
1 parent ba6d40e8bb
commit 84939af253
2 files changed
+20 -3

No files matched your search

+4
View File
@@ -29,6 +29,10 @@
.thumb
#endif
FUNCTION(grub_arm_pfr1)
mrc p15, 0, r0, c0, c1, 1
bx lr
FUNCTION(grub_armv7_get_timer_value)
isb
mrrc p15, 1, r0, r1, c14
+16 -3
View File
@@ -42,6 +42,9 @@ grub_armv7_get_timer_value(void);
grub_uint32_t
grub_armv7_get_timer_frequency(void);
grub_uint32_t
grub_arm_pfr1(void);
void __attribute__ ((noreturn))
grub_exit (void)
{
@@ -93,6 +96,18 @@ get_time_ms (void)
return grub_divmod64 (grub_armv7_get_timer_value(), timer_frequency_in_khz, 0);
}
static int
try_generic_timer (void)
{
if (((grub_arm_pfr1 () >> 16) & 0xf) != 1)
return 0;
timer_frequency_in_khz = grub_armv7_get_timer_frequency() / 1000;
if (timer_frequency_in_khz == 0)
return 0;
grub_install_get_time_ms (get_time_ms);
return 1;
}
void
grub_machine_init (void)
{
@@ -109,10 +124,8 @@ grub_machine_init (void)
grub_font_init ();
grub_gfxterm_init ();
timer_frequency_in_khz = grub_armv7_get_timer_frequency() / 1000;
if (timer_frequency_in_khz == 0)
if (!try_generic_timer ())
grub_fatal ("No timer found");
grub_install_get_time_ms (get_time_ms);
}
void