mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 18:26:48 +00:00
Feat(tty): add dummy console (#735)
使得riscv能暂时完成stdio_init(将来需要实现riscv的串口console)
This commit is contained in:
parent
1012552dea
commit
418ad41fd8
@ -14,6 +14,17 @@ pub struct WindowSize {
|
||||
pub ypixel: u16,
|
||||
}
|
||||
|
||||
impl WindowSize {
|
||||
pub fn new(row: u16, col: u16, xpixel: u16, ypixel: u16) -> Self {
|
||||
Self {
|
||||
row,
|
||||
col,
|
||||
xpixel,
|
||||
ypixel,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Termios {
|
||||
pub input_mode: InputMode,
|
||||
|
@ -60,6 +60,10 @@ impl TtyPortData {
|
||||
pub fn internal_tty(&self) -> Option<Arc<TtyCore>> {
|
||||
self.internal_tty.upgrade()
|
||||
}
|
||||
|
||||
pub fn tty(&self) -> Option<Arc<TtyCore>> {
|
||||
self.tty.upgrade()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use core::sync::atomic::Ordering;
|
||||
use core::{fmt::Formatter, sync::atomic::Ordering};
|
||||
|
||||
use alloc::{
|
||||
string::{String, ToString},
|
||||
@ -8,13 +8,10 @@ use alloc::{
|
||||
use system_error::SystemError;
|
||||
|
||||
use crate::{
|
||||
driver::{
|
||||
base::device::{
|
||||
driver::base::device::{
|
||||
device_number::{DeviceNumber, Major},
|
||||
device_register, IdTable,
|
||||
},
|
||||
video::fbdev::base::fbcon::framebuffer_console::BlittingFbConsole,
|
||||
},
|
||||
filesystem::devfs::devfs_register,
|
||||
libs::spinlock::SpinLock,
|
||||
};
|
||||
@ -95,16 +92,29 @@ impl Color {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TtyConsoleDriverInner {
|
||||
console: Arc<BlittingFbConsole>,
|
||||
console: Arc<dyn ConsoleSwitch>,
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for TtyConsoleDriverInner {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
||||
write!(f, "TtyConsoleDriverInner")
|
||||
}
|
||||
}
|
||||
|
||||
impl TtyConsoleDriverInner {
|
||||
pub fn new() -> Result<Self, SystemError> {
|
||||
Ok(Self {
|
||||
console: Arc::new(BlittingFbConsole::new()?),
|
||||
})
|
||||
let console = {
|
||||
#[cfg(not(target_arch = "riscv64"))]
|
||||
{
|
||||
Arc::new(crate::driver::video::fbdev::base::fbcon::framebuffer_console::BlittingFbConsole::new()?)
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "riscv64")]
|
||||
crate::driver::video::console::dummycon::dummy_console()
|
||||
};
|
||||
|
||||
Ok(Self { console })
|
||||
}
|
||||
|
||||
fn do_write(&self, tty: &TtyCoreData, buf: &[u8], mut nr: usize) -> Result<usize, SystemError> {
|
||||
|
@ -236,9 +236,8 @@ impl VirtualConsoleData {
|
||||
self.underline_color = 3; // cyan
|
||||
self.half_color = 0x08; // grey
|
||||
|
||||
self.reset(clear);
|
||||
|
||||
self.screen_buf.resize(self.cols * self.rows, 0);
|
||||
self.reset(clear);
|
||||
}
|
||||
|
||||
pub fn should_update(&self) -> bool {
|
||||
|
127
kernel/src/driver/video/console/dummycon.rs
Normal file
127
kernel/src/driver/video/console/dummycon.rs
Normal file
@ -0,0 +1,127 @@
|
||||
use alloc::sync::Arc;
|
||||
use system_error::SystemError;
|
||||
|
||||
use crate::driver::tty::{
|
||||
console::ConsoleSwitch,
|
||||
termios::WindowSize,
|
||||
tty_driver::TtyOperation,
|
||||
virtual_terminal::virtual_console::{CursorOperation, ScrollDir, VirtualConsoleData},
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref DUMMY_CONSOLE: Arc<DummyConsole> = Arc::new(DummyConsole::new());
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub fn dummy_console() -> Arc<DummyConsole> {
|
||||
DUMMY_CONSOLE.clone()
|
||||
}
|
||||
|
||||
pub struct DummyConsole;
|
||||
|
||||
impl DummyConsole {
|
||||
pub const COLUNMS: usize = 80;
|
||||
pub const ROWS: usize = 25;
|
||||
pub const fn new() -> Self {
|
||||
DummyConsole
|
||||
}
|
||||
}
|
||||
|
||||
impl ConsoleSwitch for DummyConsole {
|
||||
fn con_getxy(
|
||||
&self,
|
||||
_vc_data: &VirtualConsoleData,
|
||||
_pos: usize,
|
||||
) -> Result<(usize, usize, usize), SystemError> {
|
||||
Ok((0, 0, 0))
|
||||
}
|
||||
|
||||
fn con_build_attr(
|
||||
&self,
|
||||
_vc_data: &VirtualConsoleData,
|
||||
_color: u8,
|
||||
_intensity: crate::driver::tty::virtual_terminal::virtual_console::VirtualConsoleIntensity,
|
||||
_blink: bool,
|
||||
_underline: bool,
|
||||
_reverse: bool,
|
||||
_italic: bool,
|
||||
) -> Result<u8, SystemError> {
|
||||
Ok(0)
|
||||
}
|
||||
fn con_init(&self, vc_data: &mut VirtualConsoleData, init: bool) -> Result<(), SystemError> {
|
||||
vc_data.color_mode = true;
|
||||
|
||||
if init {
|
||||
vc_data.cols = Self::COLUNMS;
|
||||
vc_data.rows = Self::ROWS;
|
||||
} else {
|
||||
let tty = vc_data.port().port_data().tty().unwrap();
|
||||
tty.resize(
|
||||
tty.clone(),
|
||||
WindowSize::new(Self::ROWS as u16, Self::COLUNMS as u16, 0, 0),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn con_deinit(&self) -> Result<(), SystemError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn con_clear(
|
||||
&self,
|
||||
_vc_data: &mut VirtualConsoleData,
|
||||
_sy: usize,
|
||||
_sx: usize,
|
||||
_height: usize,
|
||||
_width: usize,
|
||||
) -> Result<(), SystemError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn con_putc(
|
||||
&self,
|
||||
_vc_data: &VirtualConsoleData,
|
||||
_ch: u16,
|
||||
_ypos: u32,
|
||||
_xpos: u32,
|
||||
) -> Result<(), SystemError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn con_putcs(
|
||||
&self,
|
||||
_vc_data: &VirtualConsoleData,
|
||||
_buf: &[u16],
|
||||
_count: usize,
|
||||
_ypos: u32,
|
||||
_xpos: u32,
|
||||
) -> Result<(), SystemError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn con_cursor(&self, _vc_data: &VirtualConsoleData, _op: CursorOperation) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
fn con_set_palette(
|
||||
&self,
|
||||
_vc_data: &VirtualConsoleData,
|
||||
_color_table: &[u8],
|
||||
) -> Result<(), SystemError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn con_scroll(
|
||||
&self,
|
||||
_vc_data: &mut VirtualConsoleData,
|
||||
_top: usize,
|
||||
_bottom: usize,
|
||||
_dir: ScrollDir,
|
||||
_nr: usize,
|
||||
) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
1
kernel/src/driver/video/console/mod.rs
Normal file
1
kernel/src/driver/video/console/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod dummycon;
|
@ -40,11 +40,11 @@ impl BlittingFbConsole {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn fb(&self) -> Arc<dyn FrameBuffer> {
|
||||
fn fb(&self) -> Arc<dyn FrameBuffer> {
|
||||
self.fb.lock().clone().unwrap()
|
||||
}
|
||||
|
||||
pub fn get_color(&self, vc_data: &VirtualConsoleData, c: u16, is_fg: bool) -> u32 {
|
||||
fn get_color(&self, vc_data: &VirtualConsoleData, c: u16, is_fg: bool) -> u32 {
|
||||
let fb_info = self.fb();
|
||||
let mut color = 0;
|
||||
|
||||
@ -104,7 +104,7 @@ impl BlittingFbConsole {
|
||||
}
|
||||
|
||||
/// ## 计算单色调的函数
|
||||
pub fn mono_color(&self) -> u32 {
|
||||
fn mono_color(&self) -> u32 {
|
||||
let fb_info = self.fb();
|
||||
let mut max_len = fb_info
|
||||
.current_fb_var()
|
||||
@ -117,7 +117,7 @@ impl BlittingFbConsole {
|
||||
return (!(0xfff << max_len)) & 0xff;
|
||||
}
|
||||
|
||||
pub fn bit_put_string(
|
||||
fn bit_put_string(
|
||||
&self,
|
||||
vc_data: &VirtualConsoleData,
|
||||
buf: &[u16],
|
||||
|
@ -19,6 +19,7 @@ use crate::{
|
||||
use alloc::{boxed::Box, sync::Arc};
|
||||
use system_error::SystemError;
|
||||
|
||||
pub mod console;
|
||||
pub mod fbdev;
|
||||
|
||||
static mut __MAMAGER: Option<VideoRefreshManager> = None;
|
||||
|
@ -34,6 +34,7 @@ fn kernel_init() -> Result<(), SystemError> {
|
||||
// 由于目前加锁,速度过慢,所以先不开启双缓冲
|
||||
// scm_enable_double_buffer().expect("Failed to enable double buffer");
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
ahci_init().expect("Failed to initialize AHCI");
|
||||
|
||||
mount_root_fs().expect("Failed to mount root fs");
|
||||
|
Loading…
x
Reference in New Issue
Block a user