1
+ mod console;
2
+ pub use self :: console:: Console ;
1
3
pub mod entry;
2
4
pub mod paging;
3
- pub mod serial;
4
5
5
6
use core:: arch:: asm;
6
- use core:: ptr;
7
+ use core:: ptr:: { self , NonNull } ;
7
8
8
9
use align_address:: Align ;
9
10
use goblin:: elf:: header:: header64:: { Header , EI_DATA , ELFDATA2LSB , ELFMAG , SELFMAG } ;
@@ -15,7 +16,7 @@ use log::info;
15
16
use sptr:: Strict ;
16
17
17
18
use crate :: arch:: paging:: * ;
18
- use crate :: arch :: serial :: SerialPort ;
19
+ use crate :: os :: CONSOLE ;
19
20
20
21
extern "C" {
21
22
static loader_end: u8 ;
@@ -29,8 +30,6 @@ extern "C" {
29
30
30
31
/// start address of the RAM at Qemu's virt emulation
31
32
const RAM_START : u64 = 0x40000000 ;
32
- /// Physical address of UART0 at Qemu's virt emulation
33
- const SERIAL_PORT_ADDRESS : u32 = 0x09000000 ;
34
33
/// Default stack size of the kernel
35
34
const KERNEL_STACK_SIZE : usize = 32_768 ;
36
35
/// Qemu assumes for ELF kernel that the DTB is located at
@@ -45,41 +44,6 @@ const PT_MEM: u64 = 0x713;
45
44
const PT_MEM_CD : u64 = 0x70F ;
46
45
const PT_SELF : u64 = 1 << 55 ;
47
46
48
- // VARIABLES
49
- static mut COM1 : SerialPort = SerialPort :: new ( SERIAL_PORT_ADDRESS ) ;
50
-
51
- pub fn message_output_init ( ) {
52
- let dtb = unsafe {
53
- Dtb :: from_raw ( sptr:: from_exposed_addr ( DEVICE_TREE as usize ) )
54
- . expect ( ".dtb file has invalid header" )
55
- } ;
56
-
57
- let property = dtb. get_property ( "/chosen" , "stdout-path" ) ;
58
- let uart_address = if let Some ( stdout) = property {
59
- let stdout = core:: str:: from_utf8 ( stdout)
60
- . unwrap ( )
61
- . trim_matches ( char:: from ( 0 ) ) ;
62
- if let Some ( pos) = stdout. find ( '@' ) {
63
- let len = stdout. len ( ) ;
64
- u32:: from_str_radix ( & stdout[ pos + 1 ..len] , 16 ) . unwrap_or ( SERIAL_PORT_ADDRESS )
65
- } else {
66
- SERIAL_PORT_ADDRESS
67
- }
68
- } else {
69
- SERIAL_PORT_ADDRESS
70
- } ;
71
-
72
- unsafe {
73
- COM1 . set_port ( uart_address) ;
74
- }
75
- }
76
-
77
- pub fn output_message_byte ( byte : u8 ) {
78
- unsafe {
79
- COM1 . write_byte ( byte) ;
80
- }
81
- }
82
-
83
47
pub unsafe fn get_memory ( _memory_size : u64 ) -> u64 {
84
48
( unsafe { ptr:: addr_of!( loader_end) } . addr ( ) as u64 ) . align_up ( LargePageSize :: SIZE as u64 )
85
49
}
@@ -152,7 +116,7 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
152
116
. count ( ) ;
153
117
info ! ( "Detect {} CPU(s)" , cpus) ;
154
118
155
- let uart_address: u32 = unsafe { COM1 . get_port ( ) } ;
119
+ let uart_address: u32 = CONSOLE . lock ( ) . get ( ) . get_stdout ( ) . as_ptr ( ) as u32 ;
156
120
info ! ( "Detect UART at {:#x}" , uart_address) ;
157
121
158
122
let pgt_slice = unsafe { core:: slice:: from_raw_parts_mut ( ptr:: addr_of_mut!( l0_pgtable) , 512 ) } ;
@@ -198,9 +162,10 @@ pub unsafe fn boot_kernel(kernel_info: LoadedKernel) -> ! {
198
162
* entry = RAM_START + ( i * BasePageSize :: SIZE ) as u64 + PT_MEM ;
199
163
}
200
164
201
- unsafe {
202
- COM1 . set_port ( 0x1000 ) ;
203
- }
165
+ CONSOLE
166
+ . lock ( )
167
+ . get ( )
168
+ . set_stdout ( NonNull :: new ( 0x1000 as * mut u8 ) . unwrap ( ) ) ;
204
169
205
170
// Load TTBRx
206
171
unsafe {
0 commit comments