1 个不稳定版本
0.1.1 | 2023 年 11 月 28 日 |
---|---|
0.1.0 |
|
#4 in #freestanding
在 2 个 crate 中使用 (通过 cursor-rs)
4KB
inout_port-rs
在独立 Rust 中的 inb/outb 端口。
如何使用
cargo add inout_port-rs
示例
#![no_std]
#![no_main]
extern crate inout_port_rs;
#[no_mangle]
pub extern "C" fn _start() -> !
{
_ = main();
loop {}
}
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
#[derive(Copy, Clone)]
#[repr(C, packed)]
struct __LowHigh {
l: u8,
h: u8,
}
#[derive(Copy, Clone)]
union __Cursor {
value: u16,
lh: __LowHigh,
}
fn set_cursor(y: usize, x: usize) {
let cursor = __Cursor {
value: (y * 80 + x) as u16,
};
unsafe {
inout_port_rs::outb(0xe, 0x3d4);
inout_port_rs::outb(cursor.lh.h, 0x3d5);
inout_port_rs::outb(0xf, 0x3d4);
inout_port_rs::outb(cursor.lh.l, 0x3d5);
}
}
fn main() {
set_cursor(0,0);
}
联系我
- 网站: https://github.com/hwoy
- 电子邮件: mailto:[email protected]
- Facebook: https://127.0.0.1/watt.duean
lib.rs
:
inout_port-rs
在独立 Rust 中的 inb/outb 端口。
示例#1
#![no_std]
#![no_main]
extern crate inout_port_rs;
#[no_mangle]
pub extern "C" fn _start() -> !
{
_ = main();
loop {}
}
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
#[derive(Copy, Clone)]
#[repr(C, packed)]
struct __LowHigh {
l: u8,
h: u8,
}
#[derive(Copy, Clone)]
union __Cursor {
value: u16,
lh: __LowHigh,
}
fn set_cursor(y: usize, x: usize) {
let cursor = __Cursor {
value: (y * 80 + x) as u16,
};
unsafe {
inout_port_rs::outb(0xe, 0x3d4);
inout_port_rs::outb(cursor.lh.h, 0x3d5);
inout_port_rs::outb(0xf, 0x3d4);
inout_port_rs::outb(cursor.lh.l, 0x3d5);
}
}
fn main() {
set_cursor(0,0);
}