diff --git a/src/system/kernel/arch/riscv64/Htif.cpp b/src/system/kernel/arch/riscv64/Htif.cpp new file mode 100644 index 0000000000..b8767621af --- /dev/null +++ b/src/system/kernel/arch/riscv64/Htif.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2021, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include + + +uint64 +HtifCmd(uint32 device, uint8 cmd, uint32 arg) +{ + if (gHtifRegs == 0) + return 0; + + uint64 htifTohost = ((uint64)device << 56) + + ((uint64)cmd << 48) + arg; + gHtifRegs->toHostLo = htifTohost % ((uint64)1 << 32); + gHtifRegs->toHostHi = htifTohost / ((uint64)1 << 32); + return (uint64)gHtifRegs->fromHostLo + + ((uint64)gHtifRegs->fromHostHi << 32); +} + + +void +HtifShutdown() +{ + HtifCmd(0, 0, 1); +} + + +void +HtifOutChar(char ch) +{ + HtifCmd(1, 1, ch); +} + + +void +HtifOutString(const char *str) +{ + for (; *str != '\0'; str++) + HtifOutChar(*str); +} + + +void +HtifOutString(const char *str, size_t len) +{ + for (; len > 0; str++, len--) + HtifOutChar(*str); +} diff --git a/src/system/kernel/arch/riscv64/Jamfile b/src/system/kernel/arch/riscv64/Jamfile index e6d005b3ef..34971887dc 100644 --- a/src/system/kernel/arch/riscv64/Jamfile +++ b/src/system/kernel/arch/riscv64/Jamfile @@ -21,6 +21,7 @@ KernelMergeObject kernel_arch_riscv64.o : arch_vm.cpp arch_vm_translation_map.cpp RISCV64VMTranslationMap.cpp + Htif.cpp : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused :