Skip to content

Commit

Permalink
[platform][qemu-virt-arm] update the uart driver to use the new mmio …
Browse files Browse the repository at this point in the history
…routines

This was the driver that triggered the whole thing, since GCC 14.1 was
starting to use more fancier addressing modes that was causing QEMU to
bomb out when using KVM.
  • Loading branch information
travisg committed May 13, 2024
1 parent 86267ca commit e848660
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions platform/qemu-virt-arm/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,12 @@

static cbuf_t uart_rx_buf[NUM_UART];

// ARM & ARM64 specific register accessors that use specific instructions to avoid
// trapping into a virtual machine.
// TODO: make a generic version of this since trapping nonstandard instructions is
// a general problem while running under a VM.
#if __aarch64__
static inline uint32_t __arm64_read_reg32(uint32_t *addr) {
uint32_t val;
__asm__ volatile("ldr %w0, %1" : "=r"(val) : "m"(*addr) : "memory");
return val;
}

static inline void __arm64_write_reg32(uint32_t *addr, uint32_t val) {
__asm__ volatile("str %w0, %1" :: "r"(val), "m"(*addr) : "memory");
}
#elif __arm__
static inline uint32_t __arm64_read_reg32(uint32_t *addr) {
uint32_t val;
__asm__ volatile("ldr %0, %1" : "=r"(val) : "m"(*addr) : "memory");
return val;
}

static inline void __arm64_write_reg32(uint32_t *addr, uint32_t val) {
__asm__ volatile("str %0, %1" :: "r"(val), "m"(*addr) : "memory");
}
#else
#error need for this arch
#endif

static inline void write_uart_reg(uintptr_t base, size_t offset, uint32_t val) {
__arm64_write_reg32((uint32_t *)(base + offset), val);
mmio_write32((uint32_t *)(base + offset), val);
}

static inline uint32_t read_uart_reg(uintptr_t base, size_t offset) {
return __arm64_read_reg32((uint32_t *)(base + offset));
return mmio_read32((uint32_t *)(base + offset));
}

static inline void set_uart_reg_bits(uintptr_t base, size_t offset, uint32_t bits) {
Expand Down

0 comments on commit e848660

Please sign in to comment.