FreeNOS
ARM64IO.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Ivan Tan
3 * Copyright (C) 2015 Niek Linnenbank
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef __LIBARCH_ARM64IO_H
20#define __LIBARCH_ARM64IO_H
21
22#include <Types.h>
23#include <IO.h>
24#include "ARM64Control.h"
25
40class ARM64IO : public IO
41{
42 public:
46 inline void write(u64 reg, u32 data)
47 {
48 dmb();
49 u64 addr = reg + m_base;
50 asm volatile("str %w[data], [%[reg]]"
51 : : [reg]"r"(addr), [data]"r"(data));
52 dmb();
53 }
54
62 inline u32 read(u64 reg) const
63 {
64 dmb();
65 u64 addr = reg + m_base;
66 u32 data;
67 asm volatile("ldr %w[data], [%[reg]]"
68 : [data]"=r"(data) : [reg]"r"(addr));
69 dmb();
70 return data;
71 }
72
80 inline void read(Address addr, Size count, void *buf) const
81 {
82 for (Size i = 0; i < count; i+= sizeof(u32))
83 {
84 *(u32 *)(((u8 *)buf) + i) = read(addr + i);
85 }
86 }
87
95 inline void write(Address addr, Size count, const void *buf)
96 {
97 for (Size i = 0; i < count; i+= sizeof(u32))
98 {
99 write(addr + i, *(u32 *) (((u8 *)buf) + i));
100 }
101 }
102
109 inline void set(Address addr, u32 data)
110 {
111 volatile u32 current = read(addr);
112 current |= data;
113 write(addr, current);
114 }
115
122 inline void unset(Address addr, u32 data)
123 {
124 volatile u32 current = read(addr);
125 current &= ~(data);
126 write(addr, current);
127 }
128};
129
130namespace Arch
131{
132 typedef ARM64IO IO;
133};
134
141#endif /* __LIBARCH_ARM64IO_H */
#define dmb()
Data Memory Barrier.
Input/Output operations specific to the ARM architecture.
Definition ARM64IO.h:41
void set(Address addr, u32 data)
Set bits in memory mapped register.
Definition ARM64IO.h:109
u32 read(u64 reg) const
read from memory mapped I/O register
Definition ARM64IO.h:62
void read(Address addr, Size count, void *buf) const
Read a number of 32-bit values.
Definition ARM64IO.h:80
void write(Address addr, Size count, const void *buf)
Write a number of 32-bit values.
Definition ARM64IO.h:95
void unset(Address addr, u32 data)
Unset bits in memory mapped register.
Definition ARM64IO.h:122
void write(u64 reg, u32 data)
write to memory mapped I/O register
Definition ARM64IO.h:46
Generic I/O functions.
Definition IO.h:36
Address m_base
memory I/O base offset is added to each I/O address.
Definition IO.h:90
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned long Address
A memory address.
Definition Types.h:131
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
unsigned long long u64
Unsigned 64-bit number.
Definition Types.h:50
unsigned char u8
Unsigned 8-bit number.
Definition Types.h:59
ARMIO IO
Definition ARMIO.h:132