aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTianhao Wang <shrik3@riseup.net>2023-03-11 01:35:16 +0100
committerTianhao Wang <shrik3@riseup.net>2023-03-11 01:35:16 +0100
commitaec1686102abc5c9099c198e7798bcb7c94b3402 (patch)
treea9534130e2bad697251d3bb4fb04b9420aaf9695 /src
parent2625fd044547c7e8b8de287963ba9422aff1f051 (diff)
adding io port
Diffstat (limited to 'src')
-rw-r--r--src/arch/x86_64/io_port.rs13
-rw-r--r--src/lib.rs6
-rw-r--r--src/machine/cgascr.rs44
3 files changed, 49 insertions, 14 deletions
diff --git a/src/arch/x86_64/io_port.rs b/src/arch/x86_64/io_port.rs
index e69de29..9c24c98 100644
--- a/src/arch/x86_64/io_port.rs
+++ b/src/arch/x86_64/io_port.rs
@@ -0,0 +1,13 @@
+
+extern "C" {
+ fn inb(port:u32) -> u32;
+ fn inw(port:u32) -> u32;
+ fn outb(port:u32, val:u32);
+ fn outw(port:u32, val:u32);
+}
+
+// TODO
+// pub struct IO_Port {
+// addr: u32,
+// }
+
diff --git a/src/lib.rs b/src/lib.rs
index c10460c..1057e26 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -12,7 +12,11 @@ fn panic(_info: &PanicInfo) -> ! {
#[no_mangle]
pub extern "C" fn _entry() -> ! {
- let scr = CGAScreen::new(80,25);
+ let scr = CGAScreen::new(25,80);
+ // scr.show(0,0,'X',0x0f);
+ // scr.show(0,79,'X',0x0f);
+ // scr.show(24,0,'X',0x0f);
+ // scr.show(24,79,'X',0x0f);
scr.test();
loop {}
}
diff --git a/src/machine/cgascr.rs b/src/machine/cgascr.rs
index f67501c..091c50d 100644
--- a/src/machine/cgascr.rs
+++ b/src/machine/cgascr.rs
@@ -8,29 +8,47 @@ pub struct CGAScreen{
#[allow(dead_code)]
impl CGAScreen{
- pub fn new(cows:u32, rows:u32) -> Self {
- Self {max_cows: cows, max_rows:rows,}
+ pub fn new(rows:u32, cols:u32) -> Self {
+ Self {max_rows:rows, max_cows:cols}
+ }
+
+
+ fn get_index(&self,row:u32, col:u32) -> u32{
+ col + row*self.max_cows
}
-
// this function should be the only one that "directly touches"
// the memory by address.
// and since it's unsafe, it shouldn't be public
- //
- // fn show(&self, x:u32, y:u32, c:char, attr:u8){
- //
- // }
+ pub fn show(&self, row:u32, col:u32, c:char, attr:u8){
+ let index = self.get_index(row, col);
+
+ unsafe{
+ *vga_buffer.offset(index as isize * 2) = c as u8;
+ *vga_buffer.offset(index as isize * 2 + 1) = attr;
+ }
+
+ }
+
+ pub fn putchar(&self, ch:char){
+
+ }
+
+ pub fn setpos(){}
+ pub fn getpos(){}
+
+
+ // Sanity Check of the cgascreen
pub fn test(&self){
let mut r = 0;
let mut c = 0;
-
+
+ let mut counter = 0;
while r<self.max_rows {
while c<self.max_cows {
- let index:u32 = r*self.max_cows + c;
- unsafe {
- *vga_buffer.offset(index as isize * 2) = index as u8;
- *vga_buffer.offset(index as isize * 2 + 1) = index as u8;
- }
+ let ch = (counter & 0xff) as u8;
+ self.show(r,c,ch as char, ch);
+ counter += 1;
c+=1;
}
r+=1;