File tree 3 files changed +49
-15
lines changed 3 files changed +49
-15
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2022 The Firefly Authors.
2
+ //
3
+ // Use of this source code is governed by a BSD 3-clause
4
+ // license that can be found in the LICENSE file.
5
+
6
+ //! Analyses the CPU for supported features and branding.
7
+
8
+ use crate :: println;
9
+ use lazy_static:: lazy_static;
10
+ use raw_cpuid:: CpuId ;
11
+
12
+ lazy_static ! {
13
+ static ref CPU_ID : CpuId = CpuId :: new( ) ;
14
+ }
15
+
16
+ /// Checks that the CPU supports all the features we need.
17
+ ///
18
+ /// # Panics
19
+ ///
20
+ /// `init` will panic if the CPU does not support any features
21
+ /// Firefly requires.
22
+ ///
23
+ pub fn init ( ) {
24
+ match CPU_ID . get_feature_info ( ) {
25
+ None => panic ! ( "unable to determine CPU features" ) ,
26
+ Some ( features) => {
27
+ if !features. has_sysenter_sysexit ( ) {
28
+ panic ! ( "CPU does not support the sysexit instruction" ) ;
29
+ }
30
+ }
31
+ }
32
+ }
33
+
34
+ /// Prints the CPU's branding information.
35
+ ///
36
+ pub fn print_branding ( ) {
37
+ if let Some ( branding) = CPU_ID . get_processor_brand_string ( ) {
38
+ println ! ( "Kernel running on {} CPU." , branding. as_str( ) ) ;
39
+ } else if let Some ( version) = CPU_ID . get_vendor_info ( ) {
40
+ println ! ( "Kernel running on {} CPU." , version. as_str( ) ) ;
41
+ } else {
42
+ println ! ( "Kernel running on unknown CPU." ) ;
43
+ }
44
+ }
Original file line number Diff line number Diff line change @@ -42,10 +42,9 @@ use crate::memory::KERNEL_STACK_0;
42
42
use crate :: multitasking:: { cpu_local, thread} ;
43
43
use bootloader:: BootInfo ;
44
44
use core:: panic:: PanicInfo ;
45
- use lazy_static:: lazy_static;
46
- use raw_cpuid:: CpuId ;
47
45
use x86_64:: instructions:: port:: Port ;
48
46
47
+ pub mod cpu;
49
48
pub mod drivers;
50
49
pub mod gdt;
51
50
pub mod interrupts;
@@ -56,15 +55,11 @@ pub mod random;
56
55
pub mod time;
57
56
pub mod utils;
58
57
59
- lazy_static ! {
60
- #[ doc( hidden) ]
61
- pub static ref CPU_ID : CpuId = CpuId :: new( ) ;
62
- }
63
-
64
58
/// Initialise the kernel and its core components.
65
59
///
66
60
/// `init` currently performs the following steps:
67
61
///
62
+ /// - Check that the CPU supports the features we need.
68
63
/// - Initialise the [Global Descriptor Table](gdt).
69
64
/// - Initialise the [Programmable Interrupt Controller](interrupts).
70
65
/// - Initialise the [Real-time clock and Programmable Interval Timer](time)
@@ -74,6 +69,7 @@ lazy_static! {
74
69
/// - Initialise the [scheduler](multitasking/thread).
75
70
///
76
71
pub fn init ( boot_info : & ' static BootInfo ) {
72
+ cpu:: init ( ) ;
77
73
gdt:: init ( ) ;
78
74
interrupts:: init ( ) ;
79
75
time:: init ( ) ;
Original file line number Diff line number Diff line change @@ -55,17 +55,11 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
55
55
#[ cfg( not( test) ) ]
56
56
fn kmain ( ) {
57
57
use kernel:: multitasking:: thread:: { scheduler, Thread } ;
58
- use kernel:: { network , time , CPU_ID } ;
58
+ use kernel:: { cpu , network , time } ;
59
59
60
60
println ! ( "Kernel ready!" ) ;
61
61
println ! ( "Kernel booted at {}." , time:: boot_time( ) ) ;
62
- if let Some ( branding) = CPU_ID . get_processor_brand_string ( ) {
63
- println ! ( "Kernel running on {} CPU." , branding. as_str( ) ) ;
64
- } else if let Some ( version) = CPU_ID . get_vendor_info ( ) {
65
- println ! ( "Kernel running on {} CPU." , version. as_str( ) ) ;
66
- } else {
67
- println ! ( "Kernel running on unknown CPU." ) ;
68
- }
62
+ cpu:: print_branding ( ) ;
69
63
70
64
// Set up our initial workload for when
71
65
// we get a DHCP configuration.
You can’t perform that action at this time.
0 commit comments