kernel/x86: Enable machine check exceptions if supported.

This enables generation of exceptions that are due to uncorrected
hardware errors. The exception handlers were already in place and will
now actually trigger kernel panics.

Note that this is the simplest form of MCE "handling" and does not add
anything of the broader machine check architecture (MCA) that also allow
reporting of corrected errors. As MCEs are generally hard to decode due
to their hardware specifity, this merely makes such problems more
obvious.

Might help to discern hardware issues in cases that would otherwise just
triple fault and cause a reboot.

Change-Id: I9e3a2640458f7c562066478d0ca90e3a46c3a325
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3155
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Reviewed-by: Axel Dörfler <axeld@pinc-software.de>
This commit is contained in:
Michael Lotz 2020-08-17 21:35:43 +02:00 committed by Axel Dörfler
parent f9b3a3b1f3
commit 4df4ae2e80
2 changed files with 4 additions and 0 deletions

View File

@ -352,6 +352,7 @@
// cr4 flags
#define IA32_CR4_PAE (1UL << 5)
#define IA32_CR4_MCE (1UL << 6)
#define IA32_CR4_GLOBAL_PAGES (1UL << 7)
#define CR4_OS_FXSR (1UL << 9)
#define CR4_OS_XMM_EXCEPTION (1UL << 10)

View File

@ -1350,6 +1350,9 @@ arch_cpu_init_percpu(kernel_args* args, int cpu)
gCpuIdleFunc = halt_idle;
}
if (x86_check_feature(IA32_FEATURE_MCE, FEATURE_COMMON))
x86_write_cr4(x86_read_cr4() | IA32_CR4_MCE);
#ifdef __x86_64__
// if RDTSCP is available write cpu number in TSC_AUX
if (x86_check_feature(IA32_FEATURE_AMD_EXT_RDTSCP, FEATURE_EXT_AMD))