1/*
2 * Copyright 2006-2022, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include <arch/generic/debug_uart.h>
8
9
10void
11DebugUART::Out8(int reg, uint8 value)
12{
13#if defined(__ARM__) || defined(__aarch64__)
14	// 32-bit aligned
15	*((uint8 *)Base() + reg * sizeof(uint32)) = value;
16#elif defined(__i386__) || defined(__x86_64__)
17	// outb for access to IO space.
18	if ((Base() + reg) <= 0xFFFF)
19		__asm__ volatile ("outb %%al,%%dx" : : "a" (value), "d" (Base() + reg));
20	else
21		*((uint8 *)Base() + reg) = value;
22#else
23	*((uint8 *)Base() + reg) = value;
24#endif
25}
26
27
28uint8
29DebugUART::In8(int reg)
30{
31#if defined(__ARM__) || defined(__aarch64__)
32	// 32-bit aligned
33	return *((uint8 *)Base() + reg * sizeof(uint32));
34#elif defined(__i386__) || defined(__x86_64__)
35	// inb for access to IO space.
36	if ((Base() + reg) <= 0xFFFF) {
37		uint8 _v;
38		__asm__ volatile ("inb %%dx,%%al" : "=a" (_v) : "d" (Base() + reg));
39		return _v;
40	}
41	return *((uint8 *)Base() + reg);
42#else
43	return *((uint8 *)Base() + reg);
44#endif
45}
46
47
48void
49DebugUART::Barrier()
50{
51	// Simple memory barriers
52#if defined(__POWERPC__)
53	asm volatile("eieio; sync");
54#elif defined(__ARM__) || defined(__aarch64__)
55	asm volatile ("" : : : "memory");
56#endif
57}
58