Skip to content

Commit

Permalink
lib: add IO port read/write helper functions
Browse files Browse the repository at this point in the history
Add 16bit and 32bit IN helper. Add 32bit OUT helper.

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Aug 6, 2021
1 parent 9aa0060 commit b46ca32
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions include/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,22 @@ static inline uint8_t inb(io_port_t port) {
return value;
}

static inline uint16_t inw(io_port_t port) {
uint16_t value;

asm volatile("inw %1, %0" : "=a"(value) : "Nd"(port));

return value;
}

static inline uint32_t ind(io_port_t port) {
uint32_t value;

asm volatile("in %1, %0" : "=a"(value) : "Nd"(port));

return value;
}

static inline void outb(io_port_t port, uint8_t value) {
asm volatile("outb %0, %1" ::"a"(value), "Nd"(port));
}
Expand All @@ -340,6 +356,10 @@ static inline void outw(io_port_t port, uint16_t value) {
asm volatile("outw %0, %1" ::"a"(value), "Nd"(port));
}

static inline void outd(io_port_t port, uint32_t value) {
asm volatile("out %0, %1" ::"a"(value), "Nd"(port));
}

static inline void putc(io_port_t port, int c) { outb(port, c); }

static inline void puts(io_port_t port, const char *buf, size_t len) {
Expand Down

0 comments on commit b46ca32

Please sign in to comment.