aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTianhao Wang <shrik3@mailbox.org>2024-04-17 14:53:37 +0200
committerTianhao Wang <shrik3@mailbox.org>2024-06-11 15:16:32 +0200
commit716e39d3808595fda3749d5df1518ae58be4551e (patch)
tree6fa6f80eca320aea254c921bc18865ae4fbb7dbd
parente5733c69740dc492fa82aed35861c40a770e9b50 (diff)
cgascr: init cursor in rust code
-rw-r--r--boot/startup-x86_64.s34
-rw-r--r--src/machine/cgascr.rs28
2 files changed, 24 insertions, 38 deletions
diff --git a/boot/startup-x86_64.s b/boot/startup-x86_64.s
index dfc6262..4c4cc21 100644
--- a/boot/startup-x86_64.s
+++ b/boot/startup-x86_64.s
@@ -9,7 +9,7 @@
;*----------------------------------------------------------------------------*
;* The 'startup' function is the entry point for the whole system. Switching *
;* to 32-bit Protected Mode has already been done (by a boot loader that runs *
-;* before). Here we prepare everything to be able to start running C++ code *
+;* before). Here we prepare everything to be able to start running rust code *
;* in 64-bit Long Mode as quickly as possible. *
;******************************************************************************
@@ -20,9 +20,6 @@
; stack for the main function (renamed to _entry())
STACKSIZE: equ 65536
-; video memory base address
-CGA: equ 0xB8000
-
; 512 GB maximum RAM size for page table
; DON'T MODIFY THIS UNLESS YOU UPDATE THE setup_paging accordingly
MAX_MEM: equ 512
@@ -191,7 +188,6 @@ clear_bss:
; initialize IDT and PICs
call setup_idt
call reprogram_pics
- call setup_cursor
fninit ; activate FPU
@@ -298,34 +294,6 @@ setup_idt:
ret
;
-; make cursor blink (GRUB disables this)
-;
-
-setup_cursor:
- mov al, 0x0a
- mov dx, 0x3d4
- out dx, al
- call delay
- mov dx, 0x3d5
- in al, dx
- call delay
- and al, 0xc0
- or al, 14
- out dx, al
- call delay
- mov al, 0x0b
- mov dx, 0x3d4
- out dx, al
- call delay
- mov dx, 0x3d5
- in al, dx
- call delay
- and al, 0xe0
- or al, 15
- out dx, al
- ret
-
-;
; Reprogram the PICs (programmable interrupt controllers) to have all 15
; hardware interrupts in sequence in the IDT.
;
diff --git a/src/machine/cgascr.rs b/src/machine/cgascr.rs
index be3efa5..33d4bcb 100644
--- a/src/machine/cgascr.rs
+++ b/src/machine/cgascr.rs
@@ -2,9 +2,6 @@ use crate::arch::x86_64::misc::*;
use crate::machine::device_io::*;
use core::{fmt, ptr, slice, str};
-// TODO this is a "hard copy" of the c code, making little use
-// of the rust features. May rework this into cleaner code...
-//
// I would consider these cga parameters constant.
// the scroll() and clear() works with the assumption
// that the CGAScreen memory buffer is 64-bit aligned
@@ -14,6 +11,7 @@ use core::{fmt, ptr, slice, str};
// For each character, it takes 2 byte in the buffer
// (one for char and one for attribute)
// Therefore the MAX_COLS should be a multiple of 4
+
const MAX_COLS: usize = 80;
const MAX_ROWS: usize = 25;
const CGA_BUFFER_START: *mut u8 = 0xb8000 as *mut u8;
@@ -42,7 +40,7 @@ pub struct CGAScreen {
#[allow(dead_code)]
impl CGAScreen {
pub fn new() -> Self {
- Self {
+ let cga = Self {
cga_mem: unsafe {
slice::from_raw_parts_mut(CGA_BUFFER_START, 2 * MAX_COLS * MAX_ROWS)
},
@@ -51,7 +49,9 @@ impl CGAScreen {
attr: 0x0f,
iport: IOPort::new(IR_PORT),
dport: IOPort::new(DR_PORT),
- }
+ };
+ cga.init_cursor();
+ return cga;
}
#[inline(always)]
@@ -175,6 +175,24 @@ impl CGAScreen {
self.cursor_c = col;
}
+ // make cursor blink (is this necessary??)
+ pub fn init_cursor(&self) {
+ self.iport.outb(0x0a);
+ delay();
+ let mut d = self.dport.inb();
+ delay();
+ d = d & 0xc0;
+ d = d | 0xe;
+ self.dport.outb(d);
+ delay();
+ self.iport.outb(0x0b);
+ delay();
+ let mut d = self.dport.inb();
+ d = d & 0xe0;
+ d = d | 0xf;
+ self.dport.outb(d);
+ }
+
pub fn getpos_xy(&self, row: &mut u32, col: &mut u32) {
let offset = self.getpos_offset();
*row = offset % MAX_COLS as u32;