From 5f556df0accd8e17d23959790a023acba0f886c2 Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Fri, 10 Jul 2026 05:16:34 +0000 Subject: [PATCH] ptos/amd64: Add port I/O headers Signed-off-by: Chloe M. --- service/ptos/Makefile | 11 +++++- service/ptos/head/arch/amd64/pio.h | 56 ++++++++++++++++++++++++++++++ service/ptos/ke/init.c | 1 + 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 service/ptos/head/arch/amd64/pio.h diff --git a/service/ptos/Makefile b/service/ptos/Makefile index bcf1b1c..b2b0166 100644 --- a/service/ptos/Makefile +++ b/service/ptos/Makefile @@ -9,7 +9,12 @@ include ../mk/ptos.mk .PHONY: all -all: spkg ke machine +all: target spkg ke machine post + +.PHONY: target +target: + mkdir -p target/machine/ + rsync -avr head/arch/$(PT_TARGET_ARCH)/*.h target/machine/ .PHONY: ke ke: @@ -22,3 +27,7 @@ spkg: .PHONY: machine machine: cd arch/$(PT_TARGET_ARCH)/; $(MAKE) $(PASSDOWN_ARGS) + +.PHONY: post +post: + rm -rf target/ diff --git a/service/ptos/head/arch/amd64/pio.h b/service/ptos/head/arch/amd64/pio.h new file mode 100644 index 0000000..54e09e9 --- /dev/null +++ b/service/ptos/head/arch/amd64/pio.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Port I/O helpers + * Author: Chloe M. + */ + +#ifndef _MACHINE_PIO_H_ +#define _MACHINE_PIO_H_ 1 + +#include + +ALWAYS_INLINE static inline UCHAR +MdInb(USHORT Port) +{ + UCHAR result; + ASMV("in %%dx, %%al" : "=a" (result) : "d" (Port)); + return result; +} + +ALWAYS_INLINE static inline USHORT +MdInw(USHORT Port) +{ + USHORT Val; + ASMV("inw %w1, %w0" : "=a" (Val) : "Nd" (Port)); + return Val; +} + +ALWAYS_INLINE static inline ULONG +MdInl(USHORT Port) +{ + ULONG Val; + ASMV("inl %w1, %0" : "=a" (Val) : "Nd" (Port)); + return Val; +} + +ALWAYS_INLINE static inline VOID +MdOutb(USHORT Port, UCHAR Val) +{ + ASMV("out %%al, %%dx" : :"a" (Val), "d" (Port)); +} + +ALWAYS_INLINE static inline VOID +MdOutw(USHORT Port, USHORT Val) +{ + ASMV("outw %w0, %w1" : : "a" (Val), "Nd" (Port)); +} + +ALWAYS_INLINE static inline VOID +MdOutl(USHORT Port, ULONG Val) +{ + ASMV("outl %0, %w1" : : "a" (Val), "Nd" (Port)); +} + +#endif /* !_MACHINE_PIO_H_ */ diff --git a/service/ptos/ke/init.c b/service/ptos/ke/init.c index 7567459..5ae5f17 100644 --- a/service/ptos/ke/init.c +++ b/service/ptos/ke/init.c @@ -8,6 +8,7 @@ #include #include +#include #include /*