Skip to content

Commit 2e35dc8

Browse files
v0.17.3
1 parent 0d0eadb commit 2e35dc8

File tree

9 files changed

+240
-5
lines changed

9 files changed

+240
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VERSIONHISTORY.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ Version History
55
## 0.17.3
66
- Added "better-error-messages" (ideas/better-error-messages.md).
77
- Added a section to the README to explain how people can contribute to the kernel's development (README.md).
8+
- Added the data::utf8 module (src/data/utf8).
9+
- Created mod.rs (src/data/utf8/mod.rs).
10+
- Added the data::utf8::types module (src/data/utf8/types.rs).
11+
- Added data::utf8::types module to mod.rs (src/data/utf8/mod.rs).
12+
- Added data::utf8 module to mod.rs (src/data/mod.rs).
13+
- Added data::parse::utf8 module (src/data/parse/utf8.rs).
14+
- Added data::parse::utf8 module to mod.rs (src/data/parse/mod.rs).
15+
- Merged pull-request 5c65ff3.
16+
- Updated Rust nightly version to 1.68.0(2023-01-21).
17+
- Updated bootloader crate to v0.9.23 (Cargo.toml).
18+
- Removed the "abi_efiapi" feature (src/main.rs).
19+
- Removed the "asm_sym" feature (src/lib.rs).
20+
- Removed the "const_fn_fn_ptr_basics" feature (src/lib.rs).
21+
- Updated kernel version number (src/main.rs).
22+
- Updated version number (Cargo.toml).
823

924
## 0.17.2
1025
- Created the data::parser module (src/data/parse).

src/data/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ pub mod parse;
1212

1313
// UCS-2
1414
pub mod ucs2;
15+
16+
// UTF-8
17+
pub mod utf8;

src/data/parse/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33

44
//pub mod json;
5+
6+
pub mod utf8;

src/data/parse/utf8.rs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// src/data/parse/utf8.rs
2+
//
3+
// Parser for UTF-8 data.
4+
// Thank you to Alacritty!
5+
6+
7+
use core::char;
8+
use crate::data::utf8::types::{Action, State};
9+
10+
11+
pub trait Receiver
12+
{
13+
fn codepoint(&mut self, _: char);
14+
fn invalidseq(&mut self);
15+
}
16+
17+
18+
#[derive(Clone, Default, PartialEq, Eq, Debug)]
19+
pub struct Parse
20+
{
21+
point: u32,
22+
state: State,
23+
}
24+
25+
26+
const CONTINUATION_MASK: u8 = 0b0011_1111;
27+
28+
29+
impl Parse
30+
{
31+
// Create a parser
32+
pub fn new() -> Parse
33+
{
34+
Parse
35+
{
36+
point: 0,
37+
// Set state to the default value
38+
state: State::Ground,
39+
}
40+
}
41+
42+
// Advance the parser
43+
pub fn adv<R>(&mut self, receiver: &mut R, byte: u8)
44+
where
45+
R: Receiver,
46+
{
47+
let (state, action) = self.state.adv(byte);
48+
self.perform_action(receiver, byte, action);
49+
self.state = state;
50+
}
51+
52+
fn perform_action<R>(&mut self, receiver: &mut R, byte: u8, action: Action)
53+
where
54+
R: Receiver,
55+
{
56+
match action
57+
{
58+
Action::InvalidSeq =>
59+
{
60+
self.point = 0;
61+
receiver.invalidseq();
62+
},
63+
64+
Action::EmitByte =>
65+
{
66+
receiver.codepoint(byte as char);
67+
},
68+
69+
Action::SetByte1 =>
70+
{
71+
let point = self.point | ((byte & CONTINUATION_MASK) as u32);
72+
let c = unsafe
73+
{
74+
char::from_u32_unchecked(point)
75+
};
76+
77+
self.point = 0;
78+
79+
receiver.codepoint(c);
80+
},
81+
82+
Action::SetByte2 =>
83+
{
84+
self.point |= ((byte & CONTINUATION_MASK) as u32) << 6;
85+
},
86+
87+
Action::SetByte2Top =>
88+
{
89+
self.point |= ((byte & 0b0001_1111) as u32) << 6;
90+
},
91+
92+
Action::SetByte3 =>
93+
{
94+
self.point |= ((byte & CONTINUATION_MASK) as u32) << 12;
95+
},
96+
97+
Action::SetByte3Top =>
98+
{
99+
self.point |= ((byte & 0b0000_1111) as u32) << 12;
100+
},
101+
102+
Action::SetByte4 =>
103+
{
104+
self.point |= ((byte & 0b0000_0111) as u32) << 18;
105+
},
106+
}
107+
}
108+
}
109+

src/data/utf8/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// src/data/utf8/mod.rs
2+
3+
4+
pub mod types;

src/data/utf8/types.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// src/data/utf8/types.rs
2+
//
3+
// UTF-8 types.
4+
// Thank you to Alacritty for their crate "utf8parse"!
5+
6+
7+
8+
// What to do when byte is received
9+
#[derive(Debug, Copy, Clone)]
10+
pub enum Action
11+
{
12+
InvalidSeq = 0,
13+
EmitByte = 1,
14+
SetByte1 = 2,
15+
SetByte2 = 3,
16+
SetByte2Top = 4,
17+
SetByte3 = 5,
18+
SetByte3Top = 6,
19+
SetByte4 = 7,
20+
}
21+
22+
23+
// These are the states that the parser can be in
24+
#[allow(non_camel_case_types)]
25+
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
26+
pub enum State
27+
{
28+
#[default]
29+
Ground = 0,
30+
Tail3 = 1,
31+
Tail2 = 2,
32+
Tail1 = 3,
33+
U3_2_e0 = 4,
34+
U3_2_ed = 5,
35+
UTF8_4_3_f0 = 6,
36+
UTF8_4_3_f4 = 7,
37+
}
38+
39+
40+
impl State
41+
{
42+
#[inline]
43+
pub fn adv(self, byte: u8) -> (State, Action)
44+
{
45+
match self
46+
{
47+
State::Ground => match byte
48+
{
49+
0x00..=0x7f => (State::Ground, Action::EmitByte),
50+
0xc2..=0xdf => (State::Tail1, Action::SetByte2Top),
51+
0xe0 => (State::U3_2_e0, Action::SetByte2Top),
52+
0xe1..=0xec => (State::Tail2, Action::SetByte3Top),
53+
0xed => (State::U3_2_ed, Action::SetByte3Top),
54+
0xee..=0xef => (State::Tail2, Action::SetByte3Top),
55+
0xf0 => (State::UTF8_4_3_f0, Action::SetByte4),
56+
0xf1..=0xf3 => (State::Tail3, Action::SetByte4),
57+
0xf4 => (State::UTF8_4_3_f4, Action::SetByte4),
58+
_ => (State::Ground, Action::InvalidSeq),
59+
},
60+
61+
State::U3_2_e0 => match byte
62+
{
63+
0xa0..=0xbf => (State::Tail1, Action::SetByte2),
64+
_ => (State::Ground, Action::InvalidSeq),
65+
},
66+
67+
State::U3_2_ed => match byte
68+
{
69+
0x80..=0x9f => (State::Tail1, Action::SetByte2),
70+
_ => (State::Ground, Action::InvalidSeq),
71+
},
72+
73+
State::UTF8_4_3_f0 => match byte
74+
{
75+
0x90..=0xbf => (State::Tail2, Action::SetByte3),
76+
_ => (State::Ground, Action::InvalidSeq),
77+
},
78+
79+
State::UTF8_4_3_f4 => match byte
80+
{
81+
0x80..=0x8f => (State::Tail2, Action::SetByte3),
82+
_ => (State::Ground, Action::InvalidSeq),
83+
},
84+
85+
State::Tail3 => match byte
86+
{
87+
0x80..=0xbf => (State::Tail2, Action::SetByte3),
88+
_ => (State::Ground, Action::InvalidSeq),
89+
},
90+
91+
92+
State::Tail2 => match byte
93+
{
94+
0x80..=0xbf => (State::Tail1, Action::SetByte2),
95+
_ => (State::Ground, Action::InvalidSeq),
96+
},
97+
98+
State::Tail1 => match byte
99+
{
100+
0x80..=0xbf => (State::Ground, Action::SetByte1),
101+
_ => (State::Ground, Action::InvalidSeq),
102+
},
103+
}
104+
}
105+
}

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#![allow(unused_variables)]
88
#![feature(abi_x86_interrupt)]
99
#![feature(alloc_error_handler)]
10-
#![feature(asm_sym)]
11-
#![feature(const_fn_fn_ptr_basics)]
1210
#![feature(const_mut_refs)]
1311
#![feature(core_intrinsics)]
1412
#![feature(custom_test_frameworks)]

src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![no_std]
22
#![no_main]
3-
#![feature(abi_efiapi)]
43
#![feature(custom_test_frameworks)]
54
#![feature(type_ascription)]
65
#![test_runner(libertyos_kernel::testexec)]
@@ -36,7 +35,7 @@ fn kernel_main(bootinfo: &'static BootInfo) -> !
3635

3736

3837
libertyos_kernel::init::start(bootinfo);
39-
println!("LIBERTYOS v0.17.2");
38+
println!("LIBERTYOS v0.17.3");
4039
print!("\x1b[?25h");
4140
println!();
4241

0 commit comments

Comments
 (0)