Skip to content

Commit 9938442

Browse files
committed
serial: enable or diable serial from grub
1 parent 90b9521 commit 9938442

4 files changed

Lines changed: 40 additions & 5 deletions

File tree

grub/grub.cfg

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
timeout=2
22

3-
menuentry "elsOS (azerty)" {
3+
menuentry "elsOS with serial, azerty" {
4+
multiboot2 /boot/elsos.bin serial
5+
boot
6+
}
7+
8+
menuentry "elsOS with serial, qwerty ansi" {
9+
multiboot2 /boot/elsos.bin serial qwerty
10+
boot
11+
}
12+
13+
menuentry "elsOS, azerty" {
414
multiboot2 /boot/elsos.bin
515
boot
616
}
717

8-
menuentry "elsOS (qwerty)" {
18+
menuentry "elsOS, qwerty ansi" {
919
multiboot2 /boot/elsos.bin qwerty
1020
boot
1121
}

src/elsos.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,24 @@ static EXTRAVERSION: &str = env!("EXTRAVERSION");
2121

2222
pub struct Settings
2323
{
24+
has_serial: bool,
2425
layout: u8
2526
}
2627

2728
pub static mut SETTINGS: Settings = Settings
2829
{
30+
has_serial: false,
2931
layout: 0
3032
};
3133

3234
#[no_mangle]
3335
pub extern "C" fn kernel_main(magic: u32, address: u32)
3436
{
3537
init_vga();
36-
init_serial();
3738
vga::cursor::Cursor::init(0, 15);
3839
if multiboot::check_magic(magic) && multiboot::parse(address)
3940
{
41+
init_serial();
4042
logln!("\n");
4143
logln!(" ::: :::::::: __ __ __ _ ____ ____ ");
4244
logln!(" :+: :+: :+: .' `'._.'` '. ( / )( __)/ ___) ");

src/multiboot.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ fn handle_qwerty()
113113
}
114114
}
115115

116+
fn handle_serial()
117+
{
118+
unsafe
119+
{
120+
crate::SETTINGS.has_serial = true;
121+
}
122+
}
123+
116124
fn parse_args(args: &[u8])
117125
{
118126
let mut previous_index: usize = 0;
@@ -129,6 +137,7 @@ fn parse_args(args: &[u8])
129137
match arg
130138
{
131139
"qwerty" => handle_qwerty(),
140+
"serial" => handle_serial(),
132141
_ => {}
133142
};
134143

src/serial.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ fn check_serial_chip(port: u32) -> bool
2424

2525
pub fn init(port: u32) -> bool
2626
{
27+
unsafe
28+
{
29+
if !crate::SETTINGS.has_serial
30+
{
31+
return false;
32+
}
33+
}
2734
outb(port + 1, 0x00); // Disable all interrupts
2835
outb(port + 3, 0x80); // Enable DLAB (set baud rate divisor)
2936
outb(port + 0, 0x03); // Set divisor to 3 (lo byte) (115 200 / 3 => 38400 baud)
@@ -129,9 +136,16 @@ pub static mut W: Writer = Writer
129136
#[doc(hidden)]
130137
pub fn _print(args: fmt::Arguments)
131138
{
132-
use core::fmt::Write;
133139
unsafe
134140
{
135-
W.write_fmt(args).unwrap();
141+
if !crate::SETTINGS.has_serial
142+
{
143+
return;
144+
}
145+
else
146+
{
147+
use core::fmt::Write;
148+
W.write_fmt(args).unwrap();
149+
}
136150
}
137151
}

0 commit comments

Comments
 (0)