aboutsummaryrefslogtreecommitdiff
path: root/src/arch/x86_64/asm/io_port.s
diff options
context:
space:
mode:
authorTianhao Wang <shrik3@riseup.net>2023-03-10 19:26:31 +0100
committerTianhao Wang <shrik3@riseup.net>2023-03-10 19:26:31 +0100
commit29e28bc9c67378d0d9a7174dec6a0b541fb7f4d5 (patch)
treeff9cd708e41ffb7f3b84347d404ffde758c18ab5 /src/arch/x86_64/asm/io_port.s
parent285508a3c9c2fa35b608e3a561f0c7a63cfacf62 (diff)
a minimal working demo on bare metal
Diffstat (limited to 'src/arch/x86_64/asm/io_port.s')
-rw-r--r--src/arch/x86_64/asm/io_port.s71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/arch/x86_64/asm/io_port.s b/src/arch/x86_64/asm/io_port.s
index e69de29..9ddc4e6 100644
--- a/src/arch/x86_64/asm/io_port.s
+++ b/src/arch/x86_64/asm/io_port.s
@@ -0,0 +1,71 @@
+;***************************************************************************
+;* Operating-System Construction *
+;*---------------------------------------------------------------------------*
+;* *
+;* I O _ P O R T *
+;* *
+;*---------------------------------------------------------------------------*
+;* The functions defined here encapsulate the machine instructions 'in' and *
+;* 'out' for class IO_Port. *
+;*****************************************************************************
+
+; EXPORTED FUNCTIONS
+
+[GLOBAL outb]
+[GLOBAL outw]
+[GLOBAL inb]
+[GLOBAL inw]
+
+; FUNCTION IMPLEMENTATIONS
+
+[SECTION .text]
+
+; OUTB: Byte-wise output via an I/O port.
+;
+; C prototype: void outb (int port, int value);
+
+outb:
+ push rbp
+ mov rbp, rsp
+ mov rdx, rdi
+ mov rax, rsi
+ out dx, al
+ pop rbp
+ ret
+
+; OUTW: Word-wise output via an I/O port.
+;
+; C prototype: void outw (int port, int value);
+
+outw:
+ push rbp
+ mov rbp, rsp
+ mov rdx, rdi
+ mov rax, rsi
+ out dx, ax
+ pop rbp
+ ret
+
+; INB: Byte-wise input via an I/O port.
+;
+; C prototype: unsigned char inb (int port);
+
+inb:
+ push rbp
+ mov rbp, rsp
+ mov rdx, rdi
+ in al, dx
+ pop rbp
+ ret
+
+; INW: Word-wise input via an I/O port.
+;
+; C prototype: unsigned short inw (int port);
+
+inw:
+ push rbp
+ mov rbp, rsp
+ mov rdx, rdi
+ in ax, dx
+ pop rbp
+ ret