diff --git a/arch/riscv/rules.mk b/arch/riscv/rules.mk index 428c1ea2..208ece7b 100644 --- a/arch/riscv/rules.mk +++ b/arch/riscv/rules.mk @@ -38,7 +38,7 @@ else ifeq ($(SUBARCH),64) ifndef TOOLCHAIN_PREFIX TOOLCHAIN_PREFIX := riscv64-elf- endif -ARCH_COMPILEFLAGS := -march=rv64imafdc -mabi=lp64d -mcmodel=medany +ARCH_COMPILEFLAGS := -march=rv64imac -mabi=lp64 -mcmodel=medany else $(error SUBARCH not set or set to something unknown) diff --git a/platform/sifive/rules.mk b/platform/sifive/rules.mk index 709f0f14..c8bccfa3 100644 --- a/platform/sifive/rules.mk +++ b/platform/sifive/rules.mk @@ -26,9 +26,4 @@ endif # sifive_e or _u? GLOBAL_DEFINES += PLATFORM_${VARIANT}=1 -# set some global defines based on capability -GLOBAL_DEFINES += PLATFORM_HAS_DYNAMIC_TIMER=1 -GLOBAL_DEFINES += ARCH_RISCV_CLINT_BASE=0x02000000 -GLOBAL_DEFINES += ARCH_RISCV_MTIME_RATE=32768 - include make/module.mk diff --git a/project/sifive-unleashed-test.mk b/project/sifive-unleashed-test.mk new file mode 100644 index 00000000..f4124b8d --- /dev/null +++ b/project/sifive-unleashed-test.mk @@ -0,0 +1,2 @@ +include project/target/sifive-unleashed.mk +include project/virtual/test.mk diff --git a/project/target/sifive-unleashed.mk b/project/target/sifive-unleashed.mk new file mode 100644 index 00000000..2d57c889 --- /dev/null +++ b/project/target/sifive-unleashed.mk @@ -0,0 +1,3 @@ +TARGET := sifive-unleashed +SUBARCH := 64 + diff --git a/platform/sifive/include/platform/sifive.h b/target/sifive-e/include/platform/sifive.h similarity index 100% rename from platform/sifive/include/platform/sifive.h rename to target/sifive-e/include/platform/sifive.h diff --git a/target/sifive-e/rules.mk b/target/sifive-e/rules.mk index b28d4be6..eedeeabf 100644 --- a/target/sifive-e/rules.mk +++ b/target/sifive-e/rules.mk @@ -13,5 +13,10 @@ GLOBAL_DEFINES += SIFIVE_FREQ=16000000 MODULE_SRCS := $(LOCAL_DIR)/target.c +# set some global defines based on capability +GLOBAL_DEFINES += PLATFORM_HAS_DYNAMIC_TIMER=1 +GLOBAL_DEFINES += ARCH_RISCV_CLINT_BASE=0x02000000 +GLOBAL_DEFINES += ARCH_RISCV_MTIME_RATE=32768 + include make/module.mk diff --git a/target/sifive-unleashed/include/platform/sifive.h b/target/sifive-unleashed/include/platform/sifive.h new file mode 100644 index 00000000..8351cfec --- /dev/null +++ b/target/sifive-unleashed/include/platform/sifive.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2019 Elliot Berman + * + * Use of this source code is governed by a MIT-style + * license that can be found in the LICENSE file or at + * https://opensource.org/licenses/MIT + */ +#pragma once + +#define SIFIVE_IRQ_UART0 4 +#define SIFIVE_IRQ_UART1 5 + +#define SIFIVE_NUM_IRQS 53 + +#define CLINT_BASE 0x02000000 +#define PLIC_BASE 0x0c000000 +#define PRCI_BASE 0x10000000 +#define UART0_BASE 0x10010000 +#define UART1_BASE 0x10011000 +#define PWM0_BASE 0x10020000 +#define PWM1_BASE 0x10021000 +#define GPIO_BASE 0x10060000 diff --git a/target/sifive-unleashed/rules.mk b/target/sifive-unleashed/rules.mk new file mode 100644 index 00000000..976df500 --- /dev/null +++ b/target/sifive-unleashed/rules.mk @@ -0,0 +1,19 @@ +LOCAL_DIR := $(GET_LOCAL_DIR) +MODULE := $(LOCAL_DIR) + +PLATFORM := sifive +VARIANT := sifive_u + +GLOBAL_DEFINES += SIFIVE_FREQ=500000000 # 500 MHz + +MEMBASE ?= 0x080000000 +MEMSIZE ?= 0x200000000 # 8 GiB + +MODULE_SRCS := $(LOCAL_DIR)/target.c +# set some global defines based on capability +GLOBAL_DEFINES += TARGET_HAS_DEBUG_LED=1 +GLOBAL_DEFINES += PLATFORM_HAS_DYNAMIC_TIMER=1 +GLOBAL_DEFINES += ARCH_RISCV_CLINT_BASE=0x02000000 +GLOBAL_DEFINES += ARCH_RISCV_MTIME_RATE=1000000 # 1 MHz + +include make/module.mk \ No newline at end of file diff --git a/target/sifive-unleashed/target.c b/target/sifive-unleashed/target.c new file mode 100644 index 00000000..cd425970 --- /dev/null +++ b/target/sifive-unleashed/target.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019 Elliot Berman + * + * Use of this source code is governed by a MIT-style + * license that can be found in the LICENSE file or at + * https://opensource.org/licenses/MIT + */ + +#include +#include +#include + +static volatile struct { + volatile uint32_t pwmcfg; + volatile uint32_t res0; + volatile uint32_t pwmcount; + volatile uint32_t res1; + volatile uint32_t pwms; + volatile uint32_t res2[3]; + volatile uint32_t pwmcmp[4]; +} *const pwm0_base = (void*)PWM0_BASE; + +void target_early_init(void) { + pwm0_base->pwmcfg = 0x100f; // enable always and max scaling + target_set_debug_led(0, false); + target_set_debug_led(1, false); + target_set_debug_led(2, false); + target_set_debug_led(3, false); +} + +void target_init(void) { +} + +void target_set_debug_led(unsigned int led, bool on) { + if(led > 3) + return; + pwm0_base->pwmcmp[led] = (0xffff + on) & 0xffff; +}