From 4f3312b85d6c18d0e3a10dba62e850113b0c2220 Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Thu, 29 Jun 2017 07:12:51 +0100 Subject: [PATCH] Implement functions for reading/writing from/to IO ports --- src/gopheros/kernel/cpu/cpu_amd64.go | 18 +++++++++++++ src/gopheros/kernel/cpu/cpu_amd64.s | 38 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/gopheros/kernel/cpu/cpu_amd64.go b/src/gopheros/kernel/cpu/cpu_amd64.go index 4d5cac4..46cf66c 100644 --- a/src/gopheros/kernel/cpu/cpu_amd64.go +++ b/src/gopheros/kernel/cpu/cpu_amd64.go @@ -38,3 +38,21 @@ func IsIntel() bool { edx == 0x49656e69 && // "ineI" ecx == 0x6c65746e // "ntel" } + +// PortWriteByte writes a uint8 value to the requested port. +func PortWriteByte(port uint16, val uint8) + +// PortWriteWord writes a uint16 value to the requested port. +func PortWriteWord(port uint16, val uint16) + +// PortWriteDword writes a uint32 value to the requested port. +func PortWriteDword(port uint16, val uint32) + +// PortReadByte reads a uint8 value from the requested port. +func PortReadByte(port uint16) uint8 + +// PortReadWord reads a uint16 value from the requested port. +func PortReadWord(port uint16) uint16 + +// PortReadDword reads a uint32 value from the requested port. +func PortReadDword(port uint16) uint32 diff --git a/src/gopheros/kernel/cpu/cpu_amd64.s b/src/gopheros/kernel/cpu/cpu_amd64.s index 554b9b5..0f855c5 100644 --- a/src/gopheros/kernel/cpu/cpu_amd64.s +++ b/src/gopheros/kernel/cpu/cpu_amd64.s @@ -40,3 +40,41 @@ TEXT ·ID(SB),NOSPLIT,$0 MOVL CX, ret+8(FP) MOVL DX, ret+12(FP) RET + +TEXT ·PortWriteByte(SB),NOSPLIT,$0 + MOVW port+0(FP), DX + MOVB val+0(FP), AX + BYTE $0xee // out al, dx + RET + +TEXT ·PortWriteWord(SB),NOSPLIT,$0 + MOVW port+0(FP), DX + MOVW val+0(FP), AX + BYTE $0x66 + BYTE $0xef // out ax, dx + RET + +TEXT ·PortWriteDword(SB),NOSPLIT,$0 + MOVW port+0(FP), DX + MOVL val+0(FP), AX + BYTE $0xef // out eax, dx + RET + +TEXT ·PortReadByte(SB),NOSPLIT,$0 + MOVW port+0(FP), DX + BYTE $0xec // in al, dx + MOVB AX, ret+0(FP) + RET + +TEXT ·PortReadWord(SB),NOSPLIT,$0 + MOVW port+0(FP), DX + BYTE $0x66 + BYTE $0xed // in ax, dx + MOVW AX, ret+0(FP) + RET + +TEXT ·PortReadDword(SB),NOSPLIT,$0 + MOVW port+0(FP), DX + BYTE $0xed // in eax, dx + MOVL AX, ret+0(FP) + RET