mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-10 16:26:48 +00:00
修复了未初始化时ui显示模块内存越界的问题,优化了代码结构 (#789)
This commit is contained in:
parent
0722a06a09
commit
bde4a334c1
@ -30,36 +30,38 @@ pub fn textui_init_no_alloc(video_enabled: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn next_line() {
|
||||||
|
NO_ALLOC_OPERATIONS_INDEX.store(0, Ordering::SeqCst);
|
||||||
|
NO_ALLOC_OPERATIONS_LINE.fetch_add(1, Ordering::SeqCst);
|
||||||
|
if NO_ALLOC_OPERATIONS_LINE.load(Ordering::SeqCst) >= TRUE_LINE_NUM.load(Ordering::SeqCst) {
|
||||||
|
NO_ALLOC_OPERATIONS_LINE.store(0, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn no_init_textui_putchar_window(
|
pub fn no_init_textui_putchar_window(
|
||||||
character: char,
|
character: char,
|
||||||
frcolor: FontColor,
|
frcolor: FontColor,
|
||||||
bkcolor: FontColor,
|
bkcolor: FontColor,
|
||||||
is_put_to_window: bool,
|
is_put_to_window: bool,
|
||||||
) -> Result<(), SystemError> {
|
) -> Result<(), SystemError> {
|
||||||
if NO_ALLOC_OPERATIONS_LINE.load(Ordering::SeqCst) >= TRUE_LINE_NUM.load(Ordering::SeqCst) {
|
|
||||||
NO_ALLOC_OPERATIONS_LINE.store(0, Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
//字符'\0'代表ASCII码表中的空字符,表示字符串的结尾
|
//字符'\0'代表ASCII码表中的空字符,表示字符串的结尾
|
||||||
if unlikely(character == '\0') {
|
if unlikely(character == '\0') {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
send_to_default_serial8250_port(&[character as u8]);
|
send_to_default_serial8250_port(&[character as u8]);
|
||||||
|
|
||||||
|
if is_put_to_window {
|
||||||
|
match character {
|
||||||
// 进行换行操作
|
// 进行换行操作
|
||||||
if unlikely(character == '\n') {
|
'\n' => {
|
||||||
// 换行时还需要输出\r
|
|
||||||
send_to_default_serial8250_port(&[b'\r']);
|
send_to_default_serial8250_port(&[b'\r']);
|
||||||
if is_put_to_window {
|
if is_put_to_window {
|
||||||
NO_ALLOC_OPERATIONS_LINE.fetch_add(1, Ordering::SeqCst);
|
next_line();
|
||||||
NO_ALLOC_OPERATIONS_INDEX.store(0, Ordering::SeqCst);
|
|
||||||
}
|
}
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
// 输出制表符
|
// 输出制表符
|
||||||
else if character == '\t' {
|
'\t' => {
|
||||||
if is_put_to_window {
|
|
||||||
let char = TextuiCharChromatic::new(Some(' '), frcolor, bkcolor);
|
let char = TextuiCharChromatic::new(Some(' '), frcolor, bkcolor);
|
||||||
|
|
||||||
//打印的空格数(注意将每行分成一个个表格,每个表格为8个字符)
|
//打印的空格数(注意将每行分成一个个表格,每个表格为8个字符)
|
||||||
let mut space_to_print = 8 - NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst) % 8;
|
let mut space_to_print = 8 - NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst) % 8;
|
||||||
while space_to_print > 0 {
|
while space_to_print > 0 {
|
||||||
@ -70,12 +72,9 @@ pub fn no_init_textui_putchar_window(
|
|||||||
NO_ALLOC_OPERATIONS_INDEX.fetch_add(1, Ordering::SeqCst);
|
NO_ALLOC_OPERATIONS_INDEX.fetch_add(1, Ordering::SeqCst);
|
||||||
space_to_print -= 1;
|
space_to_print -= 1;
|
||||||
}
|
}
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 字符 '\x08' 代表 ASCII 码中的退格字符。它在输出中的作用是将光标向左移动一个位置,并在该位置上输出后续的字符,从而实现字符的删除或替换。
|
// 字符 '\x08' 代表 ASCII 码中的退格字符。它在输出中的作用是将光标向左移动一个位置,并在该位置上输出后续的字符,从而实现字符的删除或替换。
|
||||||
else if character == '\x08' {
|
'\x08' => {
|
||||||
if is_put_to_window {
|
|
||||||
NO_ALLOC_OPERATIONS_INDEX.fetch_sub(1, Ordering::SeqCst);
|
NO_ALLOC_OPERATIONS_INDEX.fetch_sub(1, Ordering::SeqCst);
|
||||||
let op_char = NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst);
|
let op_char = NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst);
|
||||||
if op_char >= 0 {
|
if op_char >= 0 {
|
||||||
@ -98,15 +97,16 @@ pub fn no_init_textui_putchar_window(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if is_put_to_window {
|
|
||||||
// 输出其他字符
|
// 输出其他字符
|
||||||
|
_ => {
|
||||||
let char = TextuiCharChromatic::new(Some(character), frcolor, bkcolor);
|
let char = TextuiCharChromatic::new(Some(character), frcolor, bkcolor);
|
||||||
|
|
||||||
if NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst) == CHAR_PER_LINE.load(Ordering::SeqCst)
|
if NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst)
|
||||||
|
== CHAR_PER_LINE.load(Ordering::SeqCst)
|
||||||
{
|
{
|
||||||
NO_ALLOC_OPERATIONS_INDEX.store(0, Ordering::SeqCst);
|
next_line();
|
||||||
NO_ALLOC_OPERATIONS_LINE.fetch_add(1, Ordering::SeqCst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char.no_init_textui_render_chromatic(
|
char.no_init_textui_render_chromatic(
|
||||||
LineId::new(NO_ALLOC_OPERATIONS_LINE.load(Ordering::SeqCst)),
|
LineId::new(NO_ALLOC_OPERATIONS_LINE.load(Ordering::SeqCst)),
|
||||||
LineIndex::new(NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst)),
|
LineIndex::new(NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst)),
|
||||||
@ -114,6 +114,7 @@ pub fn no_init_textui_putchar_window(
|
|||||||
|
|
||||||
NO_ALLOC_OPERATIONS_INDEX.fetch_add(1, Ordering::SeqCst);
|
NO_ALLOC_OPERATIONS_INDEX.fetch_add(1, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user