blob: c34f3e435cd7b6e954e0fdf96a8ec17612fafbf5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/nekernel-org/nekernel
#ifndef KERNELKIT_IO_H
#define KERNELKIT_IO_H
#include <ArchKit/ArchKit.h>
#include <NeKit/Array.h>
#include <NeKit/Config.h>
#include <NeKit/Ref.h>
namespace Kernel {
template <SizeT Sz>
class IOArray final {
public:
IOArray() = delete;
IOArray(nullPtr) = delete;
explicit IOArray(Array<UShort, Sz>& ports) : fPorts(ports) {}
~IOArray() {}
IOArray& operator=(const IOArray&) = default;
IOArray(const IOArray&) = default;
operator bool() { return !fPorts.Empty(); }
public:
template <typename T>
T In(SizeT index);
template <typename T>
void Out(SizeT index, T value);
private:
Array<UShort, Sz> fPorts;
};
inline constexpr UInt16 kMaxPorts = 16;
using IOArray16 = IOArray<kMaxPorts>;
template <SizeT Sz>
inline Array<UShort, Sz> make_ports(UShort base) {
Array<UShort, Sz> ports;
for (UShort i = 0; i < Sz; ++i) {
ports[i] = base + i;
}
return ports;
}
} // namespace Kernel
#ifdef __NE_AMD64__
#include "IOArray+AMD64.inl"
#else
#error Please provide platform specific code for the I/O
#endif // ifdef __NE_AMD64__
#endif
|