From 4eae38a6ce9110a155715575adcf12bdf45703cb Mon Sep 17 00:00:00 2001 From: Tianhao Wang Date: Tue, 14 Mar 2023 03:16:54 +0100 Subject: CGA cursor location --- src/arch/x86_64/asm/io_port.s | 16 ++++++++-------- src/arch/x86_64/io_port.rs | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 17 deletions(-) (limited to 'src/arch') diff --git a/src/arch/x86_64/asm/io_port.s b/src/arch/x86_64/asm/io_port.s index 9ddc4e6..3aec69d 100644 --- a/src/arch/x86_64/asm/io_port.s +++ b/src/arch/x86_64/asm/io_port.s @@ -11,10 +11,10 @@ ; EXPORTED FUNCTIONS -[GLOBAL outb] -[GLOBAL outw] -[GLOBAL inb] -[GLOBAL inw] +[GLOBAL _outb] +[GLOBAL _outw] +[GLOBAL _inb] +[GLOBAL _inw] ; FUNCTION IMPLEMENTATIONS @@ -24,7 +24,7 @@ ; ; C prototype: void outb (int port, int value); -outb: +_outb: push rbp mov rbp, rsp mov rdx, rdi @@ -37,7 +37,7 @@ outb: ; ; C prototype: void outw (int port, int value); -outw: +_outw: push rbp mov rbp, rsp mov rdx, rdi @@ -50,7 +50,7 @@ outw: ; ; C prototype: unsigned char inb (int port); -inb: +_inb: push rbp mov rbp, rsp mov rdx, rdi @@ -62,7 +62,7 @@ inb: ; ; C prototype: unsigned short inw (int port); -inw: +_inw: push rbp mov rbp, rsp mov rdx, rdi diff --git a/src/arch/x86_64/io_port.rs b/src/arch/x86_64/io_port.rs index 9c24c98..4f629b8 100644 --- a/src/arch/x86_64/io_port.rs +++ b/src/arch/x86_64/io_port.rs @@ -1,13 +1,36 @@ - extern "C" { - fn inb(port:u32) -> u32; - fn inw(port:u32) -> u32; - fn outb(port:u32, val:u32); - fn outw(port:u32, val:u32); + fn _inb(port:u16) -> u8; + fn _inw(port:u16) -> u16; + fn _outb(port:u16, val:u8); + fn _outw(port:u16, val:u16); +} + +// The port addr is 16-bit wide. +// wrappers for in/out[b,w] +// Also I don't feel necessary to have a IO_Port Class give how +// trivial it is +// TODO perhaps use inline asm, because the code is short + +pub fn inw(p:u16) -> u16 { + unsafe{ + _inw(p) + } } -// TODO -// pub struct IO_Port { -// addr: u32, -// } +pub fn inb(p:u16) -> u8 { + unsafe{ + _inb(p) + } +} +pub fn outb(p:u16, val:u8){ + unsafe{ + _outb(p,val); + } +} + +pub fn outw(p:u16, val:u16){ + unsafe{ + _outw(p,val) + } +} -- cgit v1.2.3-70-g09d2