summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/KernelKit/PCI/IOArray+AMD64.inl
blob: 2b9125e0bdc24e348d0b180dfb32218c78ed416d (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
/* ========================================

  Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.

  File: IO-Impl-AMD64.h
  Purpose: I/O for AMD64.

  Revision History:

  30/01/24: Add file. (amlel)
  02/02/24: Update I/O routines. (amlel)

======================================== */

namespace Kernel {
template <SizeT Sz>
template <typename T>
T IOArray<Sz>::In(SizeT index) {
  switch (sizeof(T)) {
#ifdef __NE_AMD64__
    case 4:
      return HAL::rt_in32(fPorts[index].Leak());
    case 2:
      return HAL::rt_in16(fPorts[index].Leak());
    case 1:
      return HAL::rt_in8(fPorts[index].Leak());
#endif
    default:
      return 0xFFFF;
  }
}

template <SizeT Sz>
template <typename T>
void IOArray<Sz>::Out(SizeT index, T value) {
  switch (sizeof(T)) {
#ifdef __NE_AMD64__
    case 4:
      HAL::rt_out32(fPorts[index].Leak(), value);
    case 2:
      HAL::rt_out16(fPorts[index].Leak(), value);
    case 1:
      HAL::rt_out8(fPorts[index].Leak(), value);
#endif
    default:
      break;
  }
}
}  // namespace Kernel