Reputation: 25
Are there any Go wrappers for the following Linux syscalls used for low-level port input-output?
#include <sys/io.h>
unsigned char inb(unsigned short int port);
void outb(unsigned char value, unsigned short int port);
I have only managed to find a wrapper for sister call:
int ioperm(unsigned long from, unsigned long num, int turn_on);
which sets access to aforementioned ports. Wrapper is in syscall Go package:
func Ioperm(from int, num int, on int) (err error)
but not a trace of inb() and outb(). I do not want to use cgo for this calls to not lose easy cross-compilation.
Upvotes: 0
Views: 1234
Reputation: 15576
inb
and outb
are not system calls, they are processor instructions. You can write wrapper functions in C for these and call them with cgo
.
Here's the C functions (unless you do have them available in sys/io.h
):
unsigned char inb(unsigned short port)
{
unsigned char ret;
asm volatile("in %%dx, %%al" : "=a"(ret) : "d"(port) : "memory");
return ret;
}
void outb(unsigned char value, unsigned short port)
{
asm volatile("out %%al, %%dx" : : "a"(value), "d"(port) : "memory");
}
And a little header file you can use with cgo
:
#ifndef IOPORT_H_
#define IOPORT_H_ 1
unsigned char inb(unsigned short port);
void outb(unsigned char value, unsigned short port);
#endif
Upvotes: 2