[BITS 64]
SECTION .text
; read a byte from port
; or write a byte to port
global kInPortByte, kOutPortByte
; function that reads one byte from port
; this function follows IA-32e mode function convention
; param:
; port address (word): memory address where data is stored
kInPortByte:
push rdx
mov rax, 0 ; initialize register to zero
mov rdx, rdi ; move first parameter (port addr) to rax
in al, dx ; read byte
pop rdx
ret
; function that writes one byte to port
; this function follows IA-32e mode function convention
; param:
; port address (word): I/O port address to write data
; data (byte): data to write
kOutPortByte:
push rdx
push rax
mov rdx, rdi ; move first parameter (port addr) to rdi
mov rax, rsi ; move second parameter (data) to rax
out dx, al ; write byte
pop rax
pop rdx
ret-
PS/2 Controller (often called a Keyboard controller) is located on the motherboard, and it uses I/O ports to communicate with CPU. The above code is utility functions that keyboard-related code depends on.
-
The functions are simple. kInPortByte reads data from a I/O port address and kOutputByte writes data to a I/O port address
-
Unlike protected mode, long mode utilizes
registers firstfor parameters. If number of registers for parameters is not enough,stackis also utilizes for extra parameters. -
Depending on
parameter type, they are stored in the following order- Integer: RDI, RSI, RDX, RCX, R8, R9 (6 registers)
- Float: XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7 (8 registers)
-
Unlike protected mode,
left parameteris inserted into register or stack first. Right-most one is the last. -
Depending on
return typethey are stored in different registers in the following order. Only if the return value size is big, two registers are used- Integer: RAX, RDX
- Float: XMM0, XMM1