Skip to content

Commit 76ae2c0

Browse files
committed
fix: 所有 \n 转义 \r\n
Signed-off-by: YdrMaster <[email protected]>
1 parent b93a537 commit 76ae2c0

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

see/src/extensions.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use core::sync::atomic::{AtomicU8, Ordering};
12
use hal::{
23
clint::{msip, mtimecmp},
34
pac::UART0,
@@ -17,11 +18,7 @@ pub fn init() {
1718
rustsbi::init_ipi(&Ipi);
1819
}
1920

20-
impl rustsbi::legacy_stdio::LegacyStdio for LegacyConsole {
21-
fn getchar(&self) -> u8 {
22-
unimplemented!()
23-
}
24-
21+
impl LegacyConsole {
2522
fn putchar(&self, ch: u8) {
2623
let uart = unsafe { &*UART0::ptr() };
2724
// 等待 FIFO 空位
@@ -32,6 +29,20 @@ impl rustsbi::legacy_stdio::LegacyStdio for LegacyConsole {
3229
}
3330
}
3431

32+
impl rustsbi::legacy_stdio::LegacyStdio for LegacyConsole {
33+
fn getchar(&self) -> u8 {
34+
unimplemented!()
35+
}
36+
37+
fn putchar(&self, ch: u8) {
38+
static LAST: AtomicU8 = AtomicU8::new(0);
39+
if ch == b'\n' && LAST.swap(ch, Ordering::Relaxed) != b'\r' {
40+
self.putchar(b'\r');
41+
}
42+
self.putchar(ch);
43+
}
44+
}
45+
3546
impl rustsbi::Timer for Timer {
3647
fn set_timer(&self, stime_value: u64) {
3748
mtimecmp::write(stime_value);

spl/src/logging.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use core::ops::Shl;
1+
use core::{
2+
ops::Shl,
3+
sync::atomic::{AtomicU8, Ordering},
4+
};
25
use hal::pac::UART0;
36

47
pub struct Out;
@@ -10,17 +13,27 @@ pub enum Hex {
1013
Fmt(usize),
1114
}
1215

16+
impl Out {
17+
fn putchar(&self, ch: u8) {
18+
let uart = unsafe { &*UART0::ptr() };
19+
// 等待 FIFO 空位
20+
while uart.usr.read().tfnf().is_full() {
21+
core::hint::spin_loop();
22+
}
23+
uart.thr().write(|w| w.thr().variant(ch));
24+
}
25+
}
26+
1327
impl Shl<u8> for Out {
1428
type Output = Self;
1529

1630
#[inline]
1731
fn shl(self, rhs: u8) -> Self::Output {
18-
let uart = unsafe { &*UART0::ptr() };
19-
// 等待 FIFO 空位
20-
while uart.usr.read().tfnf().is_full() {
21-
core::hint::spin_loop();
32+
static LAST: AtomicU8 = AtomicU8::new(0);
33+
if rhs == b'\n' && LAST.swap(rhs, Ordering::Relaxed) != b'\r' {
34+
self.putchar(b'\r');
2235
}
23-
uart.thr().write(|w| w.thr().variant(rhs));
36+
self.putchar(rhs);
2437
self
2538
}
2639
}

xtask/src/components.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{xfel::Xfel, AsmArg, FlashArgs, Package, Target, XError, DIRS};
2-
use command_ext::{CommandExt, Ext};
2+
use command_ext::{dir, CommandExt, Ext};
33
use common::uninit;
44
use std::{
55
ffi::OsStr,
@@ -68,6 +68,7 @@ impl Components {
6868
.target
6969
.join(dt.file_stem().unwrap_or_else(|| OsStr::new("nezha")))
7070
.with_extension("dtb");
71+
dir::create_parent(&dtb).unwrap();
7172
Ext::new("dtc").arg("-o").arg(&dtb).arg(&dt).invoke();
7273
ans.dtb.replace(dtb);
7374
} else {
@@ -98,6 +99,7 @@ impl Components {
9899
let path = if output.is_dir() {
99100
output.join(package.name()).with_extension("asm")
100101
} else {
102+
dir::create_parent(&output).unwrap();
101103
output
102104
};
103105
// 保存

0 commit comments

Comments
 (0)