diff --git a/.github/workflows/github_ci.yml b/.github/workflows/github_ci.yml index 8942779d..fcf059dd 100644 --- a/.github/workflows/github_ci.yml +++ b/.github/workflows/github_ci.yml @@ -48,6 +48,8 @@ jobs: make demo_riscv make demo_helios_avr make demo_helios_riscv + make demo_qemu_sifive_e + make demo_ibex_ss - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 diff --git a/mk/elf.mk b/mk/elf.mk index fb0d34c2..0ce895d0 100644 --- a/mk/elf.mk +++ b/mk/elf.mk @@ -20,6 +20,10 @@ ELF := $(addprefix $(OUT)/,$(PROJECT).elf) LD_SCRIPT := $(addprefix $(OUT)/,$(LD_SCRIPT:.ld.sx=.ld)) LD_SUPPLEMENT := $(addprefix $(OUT)/,$(LD_SUPPLEMENT:.ld.sx=.ld)) +ifneq ($(FLASH_START),) +SIZE_ARGS := -m Flash $(FLASH_START) $(FLASH_SIZE) +endif + elf: $(ELF) .SECONDEXPANSION: @@ -30,8 +34,7 @@ $(ELF): $(DEP_LIBS) $(DEP_OBJS) $(LD_SCRIPT) $(LD_SUPPLEMENT) | $$(SIZE) $(OD) -Dx -h --wide $@ > $(@:.elf=.lst) $(OC) -O binary $@ $(@:.elf=.bin) $(OC) -O ihex $@ $(@:.elf=.hex) - @cd $(@D); $(SIZE) -f $(@F) -m Flash $(FLASH_START) $(FLASH_SIZE) \ - -m RAM $(RAM_START) $(RAM_SIZE) $(MEMSIZE_ARGS) + @cd $(@D); $(SIZE) -f $(@F) $(SIZE_ARGS) -m RAM $(RAM_START) $(RAM_SIZE) $(MEMSIZE_ARGS) @echo "" $(OUT)/%.ld: %.ld.sx diff --git a/projects/demo_ibex_ss/build.mk b/projects/demo_ibex_ss/build.mk new file mode 100644 index 00000000..d65ffcf6 --- /dev/null +++ b/projects/demo_ibex_ss/build.mk @@ -0,0 +1,20 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : build.mk +# Description : This file builds and gathers project properties +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +PROJECT_DIR := $(GET_PATH) + +OPTIMIZATION := s + +EXE_MODE := terravisor + +include $(PROJECT_DIR)/config.mk + +DIR := $(PROJECT_DIR) +include mk/obj.mk diff --git a/projects/demo_ibex_ss/config.mk b/projects/demo_ibex_ss/config.mk new file mode 100644 index 00000000..5a7b1385 --- /dev/null +++ b/projects/demo_ibex_ss/config.mk @@ -0,0 +1,18 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019, Cyancore Team +# +# File Name : config.mk +# Description : This file consists of project config +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +COMPILER := gcc +FAMILY := ibex +PLATFORM := simple_system +STDLOG_MEMBUF := 1 +BOOTMSGS := 1 +EARLYCON_SERIAL := 1 +OBRDLED_ENABLE := 0 +TERRAKERN := 0 diff --git a/projects/demo_ibex_ss/project.c b/projects/demo_ibex_ss/project.c new file mode 100644 index 00000000..89c64a0e --- /dev/null +++ b/projects/demo_ibex_ss/project.c @@ -0,0 +1,43 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2022, Cyancore Team + * + * File Name : project.c + * Description : This file consists of project srouces + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include +#include +#include +#include +#include +#include + +void plug() +{ + bootstrap(); + driver_setup_all(); + + printf("Demo Program!\n"); + return; +} + + +void play() +{ + static unsigned char i = 0; + char progress[] = "-\\|/"; + uint64_t time; + char c = progress[(i++) % strlen(progress)]; + get_timestamp(&time); + time /= 1000U; + + printf("[%012llu] Running Blinky ... [%c]", time, c); + + mdelay(500); + + printf("\r"); + return; +} diff --git a/src/arch/riscv/32/i/terravisor/arch.c b/src/arch/riscv/32/i/terravisor/arch.c index 64eb4026..2b1e19d2 100644 --- a/src/arch/riscv/32/i/terravisor/arch.c +++ b/src/arch/riscv/32/i/terravisor/arch.c @@ -62,7 +62,9 @@ void arch_early_setup() arch_di_mei(); arch_di_mtime(); arch_di_msoftirq(); +#ifndef RV_VEC_MODE riscv_update_vector(); +#endif return; } diff --git a/src/arch/riscv/32/i/terravisor/asm.S b/src/arch/riscv/32/i/terravisor/asm.S index 4684e6f9..2a39efe6 100644 --- a/src/arch/riscv/32/i/terravisor/asm.S +++ b/src/arch/riscv/32/i/terravisor/asm.S @@ -69,9 +69,16 @@ function exception_handler_base EPILOGUE mret +#ifndef RV_VEC_MODE function riscv_update_vector la a0, exception_handler_base csrw mtvec, a0 mv a0, zero fence.i ret +#else +vectors vtors +.rept 32 + j exception_handler_base +.endr +#endif diff --git a/src/arch/riscv/32/i/terravisor/include/arch.h b/src/arch/riscv/32/i/terravisor/include/arch.h index 58751f2e..1121b5c3 100644 --- a/src/arch/riscv/32/i/terravisor/include/arch.h +++ b/src/arch/riscv/32/i/terravisor/include/arch.h @@ -156,11 +156,13 @@ static inline void arch_nop() static inline void arch_wfi() { +#ifndef RV_NO_WFI asm volatile("wfi"); #if ERRATA_CIP578 arch_nop(); arch_nop(); #endif +#endif } static inline void arch_isb() diff --git a/src/arch/riscv/32/imc/README.md b/src/arch/riscv/32/imc/README.md new file mode 100644 index 00000000..26b18c43 --- /dev/null +++ b/src/arch/riscv/32/imc/README.md @@ -0,0 +1,9 @@ +# RV32 IMC-Extension + +#### Supported Extensions +* RV32I baseline +* M - Hardware multiplication +* C - Compressed instructions + +#### Supported execution level +* Terravisor diff --git a/src/arch/riscv/32/imc/terravisor/README.md b/src/arch/riscv/32/imc/terravisor/README.md new file mode 100644 index 00000000..34a1b42f --- /dev/null +++ b/src/arch/riscv/32/imc/terravisor/README.md @@ -0,0 +1,7 @@ +# RV32 IMAC [Terravisor] + +Home directory for RV32imac Terravisor + +For terravisor documentation please read [Terravisor README](../../../../../visor/terravisor/README.md) + +Please refer [README.md](../../i/terravisor/README.md) in i/terravisor directory. diff --git a/src/arch/riscv/32/imc/terravisor/build.mk b/src/arch/riscv/32/imc/terravisor/build.mk new file mode 100644 index 00000000..e4ddc9a6 --- /dev/null +++ b/src/arch/riscv/32/imc/terravisor/build.mk @@ -0,0 +1,16 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : build.mk +# Description : Build script for this directory. +# Primary Authod : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +RV32IMC_T_ARCH_DIR := $(GET_PATH) + +include $(RV32IMC_T_ARCH_DIR)/../../i/terravisor/build.mk + +DIR := $(RV32IMC_T_ARCH_DIR) +include mk/obj.mk diff --git a/src/driver/console/con_serial_ibex/build.mk b/src/driver/console/con_serial_ibex/build.mk new file mode 100644 index 00000000..bb4d4ec4 --- /dev/null +++ b/src/driver/console/con_serial_ibex/build.mk @@ -0,0 +1,20 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2019, Cyancore Team +# +# File Name : build.mk +# Description : This file accumulates sources of console serial +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +DIR := $(GET_PATH) + +EARLYCON_SERIAL ?= 0 +CONSOLE_SERIAL := 0 + +$(eval $(call add_define,EARLYCON_SERIAL)) + +ifeq ($(filter $(CONSOLE_SERIAL) $(EARLYCON_SERIAL),1),1) +include mk/obj.mk +endif diff --git a/src/driver/console/con_serial_ibex/earlycon_serial.c b/src/driver/console/con_serial_ibex/earlycon_serial.c new file mode 100644 index 00000000..8898787e --- /dev/null +++ b/src/driver/console/con_serial_ibex/earlycon_serial.c @@ -0,0 +1,92 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2019, Cyancore Team + * + * File Name : earlycon_serial.c + * Description : This file contains sources of uart earlycon + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static uart_port_t *earlycon_port; + +static status_t earlycon_serial_setup() +{ + uart_get_properties(earlycon_port, console_uart); + + sysdbg2("UART engine @ %p\n", earlycon_port->baddr); + /* + * If memory mapping is applicable, + * put it in mmu supported guide. + */ + return success; +} + +static status_t earlycon_serial_write(const char c) +{ + status_t ret; + ret = uart_tx(earlycon_port, c); + return ret; +} + +static console_t *earlycon_serial_driver; + +status_t earlycon_serial_driver_exit() +{ + status_t ret; + ret = console_release_device(); + free(earlycon_port); + free(earlycon_serial_driver); + return ret; +} + +status_t earlycon_serial_driver_setup() +{ + status_t ret; + + earlycon_port = (uart_port_t *)malloc(sizeof(uart_port_t)); + if(!earlycon_port) + { + ret = error_memory_low; + goto cleanup_1; + } + + earlycon_serial_driver = (console_t *)malloc(sizeof(console_t)); + if(!earlycon_serial_driver) + { + ret = error_memory_low; + goto cleanup_1; + } + earlycon_serial_driver->write = &earlycon_serial_write; + + ret = earlycon_serial_setup(); + if(ret) + goto cleanup_1; + ret = console_attach_device(ret, earlycon_serial_driver); + if(!ret) + goto exit; +cleanup_1: + earlycon_serial_driver_exit(); +exit: + return ret; +} + +#if EARLYCON_SERIAL==1 +INCLUDE_DRIVER(earlycon, earlycon_serial_driver_setup, earlycon_serial_driver_exit, 0, 2, 2); +#endif diff --git a/src/lib/libc/include/stdio.h b/src/lib/libc/include/stdio.h index ae15c575..8e19fb5f 100644 --- a/src/lib/libc/include/stdio.h +++ b/src/lib/libc/include/stdio.h @@ -30,6 +30,7 @@ extern FILE stddev[]; int __printf(const char *fmt, ...); int __eprintf(const char *fmt, ...); +int scanf(const char *fmt, ...); int fputs(const FILE *, const char *); int fputc(const FILE *, const char); int fgetc(const FILE *, char *); @@ -39,6 +40,7 @@ char getchar(); #ifdef _STDBOOL_H_ int fprintf(const FILE *, bool, const char *fmt, ...); #ifdef _STDARG_H_ +int vscanf(const FILE *, const char *fmt, va_list args); int vprintf(const FILE *, bool, const char *fmt, va_list args); #endif #endif diff --git a/src/lib/libc/printf.c b/src/lib/libc/printf.c index e6558a96..849863cb 100644 --- a/src/lib/libc/printf.c +++ b/src/lib/libc/printf.c @@ -109,8 +109,10 @@ static int fltprint(const FILE *dev, bool en_stdout, double flt, { frac *= 10.0; padf--; + d = (long) frac; + if (!d) + __fputc(dev, en_stdout, '0'); } - d = (long) frac; ret += unumprint(dev, en_stdout, d,10, '0', 0); return ret; diff --git a/src/lib/libc/scanf.c b/src/lib/libc/scanf.c index 9700bff8..b0bfe3dc 100644 --- a/src/lib/libc/scanf.c +++ b/src/lib/libc/scanf.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include int fgetc(const FILE *dev, char *c) { @@ -42,3 +44,201 @@ char getchar() } while(temp != '\r'); return c; } + +int vscanf(const FILE *dev, const char *fmt, va_list args) +{ + int ret = 0; + int l_ret; + int N; + char c; + while (*fmt != '\0') + { + l_ret = 0; + if (*fmt == '%') + { + fmt++; +loop: + switch (*fmt) + { + case 'i': + case 'd': + { + int a = 0; + N = 0; + // skip leading whitespaces + do + { + fgetc(dev, &c); + if (c == '\r') + fputc(stdout, '\n'); + else + fputc(stdout, c); + } while (isSpace(c)); + // initialize first int digit + if (c == '-') + N = 1; + else if (isDigit(c)) + a = c - '0'; + // append rest of digits till whitespace + do + { + fgetc(dev, &c); + if (isDigit(c)) + { + a *= 10; + a += (c - '0'); + fputc(stdout, c); + } + else if (a && (c == 0x7f || c== 0x08)) + { + a /= 10; + fputs(stdout, "\b \b"); + } + } while (!isSpace(c)); + (c == '\r') ? fputc(stdout, '\n') : fputc(stdout, c); + if (l_ret >= 2) + *(int64_t *)va_arg(args, int64_t *) = (N) ? -(a) : a; + else if (l_ret == 1) + *(long *)va_arg(args, long *) = (N) ? -(a) : a; + else + *(int *)va_arg(args, int *) = (N) ? -(a) : a; + ret++; + break; + } + case 'l': + { + l_ret++; + fmt++; + goto loop; + } +#if USE_FLOAT == 1 + case 'f': + { + float a = 0; + unsigned int rp = 0; // radix point + float e = 1; + unsigned int fl = 1; // floating length - length after radix point + N = 0; + // skip leading whitespaces + do + { + fgetc(dev, &c); + if (c == '\r') + fputc(stdout, '\n'); + else + fputc(stdout, c); + } while (isSpace(c)); + if (c == '.') + rp = 1; + else if (c == '-') + N = 1; + else if (isDigit(c)) + a = (float)(c - '0'); + // append rest of digits till whitespace + do + { + fgetc(dev, &c); + if (!rp && c == '.') + { + rp = 1; + fputc(stdout, c); + } + else if (isDigit(c)) + { + if (rp) + { + e /= 10.0; + a += (e * (float)(c - '0')); + fl *= 10; + } + else + { + a *= 10.0; + a += (float)(c - '0'); + } + fputc(stdout, c); + } + else if (a && (c == 0x7f || c == 0x08)) + { + long d = (long)a; + float frac = a - (float)d; + if (frac == 0.0 && rp) + rp = 0; + else if (rp) + { + fl /= 10; + frac *= fl; + frac = (long)frac / (float)fl; + a = d + frac; + } + else + a = (int)a / 10; + fputs(stdout, "\b \b"); + } + } while (!isSpace(c)); + (c == '\r') ? fputc(stdout, '\n') : fputc(stdout, c); + *(float *)va_arg(args, float *) = (N) ? -(a) : a; + ret++; + break; + } +#endif + case 'c': + { + *(char *)va_arg(args, char *) = getchar(); + ret++; + break; + } + case 's': + { + int i = 0; + char *s = va_arg(args, char *); + //skip leading whitespaces + do + { + fgetc(dev, &c); + if (c == '\r') + fputc(stdout, '\n'); + else + fputc(stdout, c); + } while (isSpace(c)); + s[i++] = c; + do + { + fgetc(dev, &c); + if (isSpace(c)) + break; + else if (i && (c == 0x7f || c == 0x08)) + { + i--; + fputs(stdout, "\b \b"); + } + else + s[i++] = c; + fputc(stdout, c); + } while (!isSpace(c)); + (c == '\r') ? fputc(stdout, '\n') : fputc(stdout, c); + s[i] = '\0'; + ret++; + break; + } + default: + return -1; + } + continue; + } + /* increment pointer if % not found */ + fmt++; + } + fputc(stdout, '\n'); + return ret; +} + +int scanf(const char *fmt, ...) +{ + int ret; + va_list va; + va_start(va, fmt); + ret = vscanf(stdin, fmt, va); + va_end(va); + return ret; +} diff --git a/src/platform/ibex/simple_system/arch/build.mk b/src/platform/ibex/simple_system/arch/build.mk new file mode 100644 index 00000000..bbae2cf7 --- /dev/null +++ b/src/platform/ibex/simple_system/arch/build.mk @@ -0,0 +1,14 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : build.mk +# Description : This file accumulates the build ibex simple system +# platform arch sources +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +DIR := $(GET_PATH) + +include mk/obj.mk diff --git a/src/platform/ibex/simple_system/arch/panic.S b/src/platform/ibex/simple_system/arch/panic.S new file mode 100644 index 00000000..49bdf97e --- /dev/null +++ b/src/platform/ibex/simple_system/arch/panic.S @@ -0,0 +1,15 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : panic.S + * Description : This file contains platform panic handler + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include + +function plat_panic_handler + wfi + j plat_panic_handler diff --git a/src/platform/ibex/simple_system/arch/platform_cpu.c b/src/platform/ibex/simple_system/arch/platform_cpu.c new file mode 100644 index 00000000..bef54124 --- /dev/null +++ b/src/platform/ibex/simple_system/arch/platform_cpu.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include +#include + +void platform_print_cpu_info() +{ + unsigned int core_id = arch_core_index(), + isa = arch_core_isa(), + arch_id = arch_core_archid(), + imp_id = arch_core_impid(), + vendor_id = arch_core_vendor(); + + syslog(info, "CPU Info: ID = %u\n-------------------------------\nISA\t\t: 0x%x\nArch ID\t\t: 0x%x\nImp ID\t\t: 0x%x\nVendor ID\t: 0x%x\n\n", core_id, isa, arch_id, imp_id, vendor_id); +}; diff --git a/src/platform/ibex/simple_system/arch/platform_mem.c b/src/platform/ibex/simple_system/arch/platform_mem.c new file mode 100644 index 00000000..4f1b6026 --- /dev/null +++ b/src/platform/ibex/simple_system/arch/platform_mem.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include + +extern uintptr_t _bss_start, _bss_size; + +status_t platform_bss_clear() +{ + memset(&_bss_start, 0, (size_t)&_bss_size); + return success; +} + diff --git a/src/platform/ibex/simple_system/build.mk b/src/platform/ibex/simple_system/build.mk new file mode 100644 index 00000000..031ef60c --- /dev/null +++ b/src/platform/ibex/simple_system/build.mk @@ -0,0 +1,35 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : build.mk +# Description : This file provides and accumulates configs +# and sources for simple system by ibex +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +SIMSYS_DIR := $(GET_PATH) + +ARCH := riscv +BIT := 32 +ARCH_VARIANT := imc +ARCH_ABI := ilp32 +TARGET_FLAGS += -march=rv32imc -mabi=$(ARCH_ABI) +PLAT_INCLUDE += $(SIMSYS_DIR)/include +OUTPUT_FORMAT := elf32-littleriscv + + +LD_SCRIPT := $(SIMSYS_DIR)/sections.ld.sx +PLAT_INCLUDE += $(SIMSYS_DIR)/include +LINT_FLAGS += --platform=unix32 + +USE_DEFAULT_RESOURCES := 1 +LOCAL_INTERRUPT_DEVICE := 1 +PLAT_INTERRUPT_DEVICE := 0 + +include $(SIMSYS_DIR)/config.mk +include $(SIMSYS_DIR)/arch/build.mk +include $(SIMSYS_DIR)/hal/build.mk +include $(SIMSYS_DIR)/platform/build.mk +$(eval $(call check_and_include,USE_DEFAULT_RESOURCES,$(SIMSYS_DIR)/resources/build.mk)) diff --git a/src/platform/ibex/simple_system/config.mk b/src/platform/ibex/simple_system/config.mk new file mode 100644 index 00000000..d80f6d02 --- /dev/null +++ b/src/platform/ibex/simple_system/config.mk @@ -0,0 +1,80 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : config.mk +# Description : This file defines configuration for ibex Simple System +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +#====================================================================== +# Configuration file for Platforms +#====================================================================== + +#====================================================================== +# Platform Configuration +# Do not alter below FLAGS unless explicitly mentioned +#====================================================================== +N_CORES := 1 +$(eval $(call add_define,N_CORES)) + +CCSMP := 0 +$(eval $(call add_define,CCSMP)) + +$(eval $(call add_define,BIT)) + +RV_VEC_MODE := 1 +$(eval $(call add_define,RV_VEC_MODE)) + +RV_NO_WFI := 1 +$(eval $(call add_define,RV_NO_WFI)) + +BOOT_CORE_ID:= 0 +$(eval $(call add_define,BOOT_CORE_ID)) + +RAM_START := 0x100000 +RAM_SIZE := 0x100000 # 1M +HEAP_SIZE ?= 50K +STACK_SIZE ?= 0x2000 +STACK_SIZE_PCPU ?= 0x2000 + +$(eval $(call add_define,HEAP_SIZE)) +$(eval $(call add_define,STACK_SIZE)) +$(eval $(call add_define,STACK_SIZE_PCPU)) + +N_EXCEP := 12 +$(eval $(call add_define,N_EXCEP)) + +N_IRQ := 12 +$(eval $(call add_define,N_IRQ)) + +N_PLAT_IRQS := 0 +$(eval $(call add_define,N_PLAT_IRQS)) + +MAX_INTERRUPTS_PER_DEVICE := 1 +$(eval $(call add_define,MAX_INTERRUPTS_PER_DEVICE)) + +USE_SPINLOCK ?= 1 +$(eval $(call add_define,USE_SPINLOCK)) + +#====================================================================== +# MEMBUF Configuration +#====================================================================== +MEMBUF_SIZE ?= 1024 +$(eval $(call add_define,MEMBUF_SIZE)) +#====================================================================== + +#====================================================================== +# Timer: Sched timer/wall clock +#====================================================================== +USE_TIMER ?= 1 +$(eval $(call add_define,USE_TIMER)) +#====================================================================== + +#====================================================================== +# PRNG: Use upgraded prng +#====================================================================== +USE_PRNG ?= 1 +$(eval $(call add_define,USE_PRNG)) +#====================================================================== diff --git a/src/platform/ibex/simple_system/hal/build.mk b/src/platform/ibex/simple_system/hal/build.mk new file mode 100644 index 00000000..22696c79 --- /dev/null +++ b/src/platform/ibex/simple_system/hal/build.mk @@ -0,0 +1,19 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : build.mk +# Description : This file accumulates HAL sources for ibex simple system +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +#====================================================================== +# Configuration file for Platforms +#====================================================================== +# Do not make changes to this file or variables + +HAL_DIR := $(GET_PATH) + +include $(HAL_DIR)/uart/build.mk +include $(HAL_DIR)/clint/build.mk diff --git a/src/platform/ibex/simple_system/hal/clint/build.mk b/src/platform/ibex/simple_system/hal/clint/build.mk new file mode 100644 index 00000000..0c5deaa9 --- /dev/null +++ b/src/platform/ibex/simple_system/hal/clint/build.mk @@ -0,0 +1,18 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : build.mk +# Description : This file accumulates sources of interrupt controller +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +CLINT_PATH := $(GET_PATH) + +ifeq ($(ARCH), riscv) + +DIR := $(CLINT_PATH) +include mk/obj.mk + +endif diff --git a/src/platform/ibex/simple_system/hal/clint/clint.c b/src/platform/ibex/simple_system/hal/clint/clint.c new file mode 100644 index 00000000..5ea4c3f8 --- /dev/null +++ b/src/platform/ibex/simple_system/hal/clint/clint.c @@ -0,0 +1,69 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : clint.c + * Description : This file contains sources of CLINT core + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "clint_private.h" + +static clint_port_t *port; + +static status_t clint_setup() +{ + vret_t vres; + const module_t *dp; + + arch_visor_call(fetch_dp, clint, 0, 0, &vres); + + if(vres.status != success) + return vres.status; + + port = (clint_port_t *)malloc(sizeof(clint_port_t)); + if(!port) + return error_memory_low; + + dp = (module_t *)vres.p; + port->baddr = dp->baddr; + port->stride = dp->stride; + port->port_id = clint; + MMIO64(port->baddr + MTIME_OFFSET) = 0; + return success; +} + +static status_t clint_exit() +{ + free(port); + return success; +} + +status_t clint_config_tcmp(size_t core_id, uint64_t value) +{ + STATUS_CHECK_COREID(core_id); + MMIO64(port->baddr + MTCMP_OFFSET) = value; + arch_dsb(); + return success; +} + +uint64_t clint_read_time() +{ + uint64_t time_stamp; + time_stamp = MMIO64(port->baddr + MTIME_OFFSET); + return time_stamp; +} + +INCLUDE_DRIVER(plat_clint, clint_setup, clint_exit, 0, 0, 0); diff --git a/src/platform/ibex/simple_system/hal/clint/clint_private.h b/src/platform/ibex/simple_system/hal/clint/clint_private.h new file mode 100644 index 00000000..89f738ea --- /dev/null +++ b/src/platform/ibex/simple_system/hal/clint/clint_private.h @@ -0,0 +1,22 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : clint_private.h + * Description : This file contains CLINT core register offsets + * and other private variables + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#pragma once + +#define MTCMP_OFFSET (0x8) +#define MTIME_OFFSET (0x0) + +typedef struct clint_port +{ + hw_devid_t port_id; + uintptr_t baddr; + uintptr_t stride; +} clint_port_t; diff --git a/src/platform/ibex/simple_system/hal/uart/build.mk b/src/platform/ibex/simple_system/hal/uart/build.mk new file mode 100644 index 00000000..833737f0 --- /dev/null +++ b/src/platform/ibex/simple_system/hal/uart/build.mk @@ -0,0 +1,13 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : build.mk +# Description : This file builds sources of ibex simple system HAL uart +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +DIR :=$(GET_PATH) + +include mk/obj.mk diff --git a/src/platform/ibex/simple_system/hal/uart/uart.c b/src/platform/ibex/simple_system/hal/uart/uart.c new file mode 100644 index 00000000..99676029 --- /dev/null +++ b/src/platform/ibex/simple_system/hal/uart/uart.c @@ -0,0 +1,59 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : uart.c + * Description : This file contains sources for ibex simple system + * HAL uart apis (uart here is sys-out) + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "uart_private.h" + +status_t uart_get_properties(uart_port_t *port, sw_devid_t dev) +{ + vret_t vres; + swdev_t *sp; + module_t *dp; + hw_devid_t devid; + + arch_visor_call(fetch_sp, dev, 0, 0, &vres); + if(vres.status != success) + { + sysdbg3("%p - sp node could not be found!\n", dev); + return vres.status; + } + sp = (swdev_t *) vres.p; + devid = sp->hwdev_id; + port->pmux = sp->pmux; + + arch_visor_call(fetch_dp, (devid & 0xff00), (devid & 0xff), 0, &vres); + if(vres.status != success) + { + sysdbg3("UART Device %d not found!\n", devid); + return vres.status; + } + dp = (module_t *) vres.p; + port->port_id = dp->id; + port->clk_id = dp->clk_id; + port->baddr = dp->baddr; + port->baud = dp->clk; + port->irq = &dp->interrupt[0]; + return success; +} + +status_t uart_tx(const uart_port_t *port, const char data) +{ + MMIO32(port->baddr + TXDATA_OFFSET) = data; + return success; +} + diff --git a/src/platform/ibex/simple_system/hal/uart/uart_private.h b/src/platform/ibex/simple_system/hal/uart/uart_private.h new file mode 100644 index 00000000..0518c9a2 --- /dev/null +++ b/src/platform/ibex/simple_system/hal/uart/uart_private.h @@ -0,0 +1,13 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : uart_private.h + * Description : This file contains macros used by uart HAL + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#pragma once + +#define TXDATA_OFFSET 0x00 diff --git a/src/platform/ibex/simple_system/include/plat_mem.h b/src/platform/ibex/simple_system/include/plat_mem.h new file mode 100644 index 00000000..c1848b02 --- /dev/null +++ b/src/platform/ibex/simple_system/include/plat_mem.h @@ -0,0 +1,18 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : plat_mem.h + * Description : This file contains memory config of + * ibex simple system + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#pragma once + +#define RAM_START 0x100000 +#define RAM_LENGTH 0x100000 + +#define ALIGN_BOUND 4 +#define HEAP_ALIGN ALIGN_BOUND diff --git a/src/platform/ibex/simple_system/include/platform.h b/src/platform/ibex/simple_system/include/platform.h new file mode 100644 index 00000000..28ed3471 --- /dev/null +++ b/src/platform/ibex/simple_system/include/platform.h @@ -0,0 +1,20 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : platform.h + * Description : This file contains prototypes of platform apis + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#pragma once +#define _IBEX_SS_PLATFORM_H_ + +#include + +void plat_panic_handler(void); +void platform_print_cpu_info(void); +status_t platform_bss_clear(void); +status_t platform_resources_setup(void); + diff --git a/src/platform/ibex/simple_system/platform/build.mk b/src/platform/ibex/simple_system/platform/build.mk new file mode 100644 index 00000000..58ef887b --- /dev/null +++ b/src/platform/ibex/simple_system/platform/build.mk @@ -0,0 +1,17 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : build.mk +# Description : This file builds sources from ibex simple system +# common platform directory +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +DIR := $(GET_PATH) + +PRINT_MEMORY_LAYOUT ?= 0 +$(eval $(call add_define,PRINT_MEMORY_LAYOUT)) + +include mk/obj.mk diff --git a/src/platform/ibex/simple_system/platform/plat_timer.c b/src/platform/ibex/simple_system/platform/plat_timer.c new file mode 100644 index 00000000..230f29c3 --- /dev/null +++ b/src/platform/ibex/simple_system/platform/plat_timer.c @@ -0,0 +1,207 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : plat_timer.c + * Description : This file contains sources for platform + * timer + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * tmr_cb - Timer event call back + */ +static void (*tmr_cb)(void); + +/** + * ticks - Driver variable for keeping track of timer ticks + * for event + */ +static uint64_t ticks; + +/** + * tm - timer device module + */ +static module_t *tm; + +/** + * plat_tmr_isr - platform timer isr handler + * + * @brief This function is timer event handler. This function + * updated timercmp reg to raise event after 'ticks' have elapsed. + * Also, this function executes registered timer callback additionally + * which will be used by scheduler. + */ +static void plat_tmr_isr(void) +{ + arch_di_mtime(); + uint64_t t = clint_read_time(); + status_t ret = clint_config_tcmp(arch_core_index(), (t + ticks)); + if(ret) + { + syslog_stdout_enable(); + syslog(fail, "Failed to configure timer, Err = %p\n", ret); + plat_panic_handler(); + } + arch_ei_mtime(); + + if(tmr_cb != NULL) + tmr_cb(); +} + +/** + * plat_timer_reg_cb - Funtion to register call back + */ +static void plat_timer_reg_cb(void *cb) +{ + arch_di_mtime(); + tmr_cb = cb; + arch_ei_mtime(); +} + +/** + * plat_get_timer_prop - Helper function to fetch timer properties + */ +static status_t plat_get_timer_prop(void) +{ + vret_t vres; + swdev_t *sp; + hw_devid_t devid; + + arch_visor_call(fetch_sp, sched_timer, 0, 0, &vres); + if(vres.status != success) + { + sysdbg3("%p - sp node could not be found!\n", sched_timer); + return vres.status; + } + sp = (swdev_t *) vres.p; + devid = sp->hwdev_id; + + arch_visor_call(fetch_dp, (devid & 0xff00), (devid & 0xff), 0, &vres); + if(vres.status != success) + { + sysdbg3("Timer Device %d not found!\n", devid); + return vres.status; + } + tm = (module_t *) vres.p; + return success; +} + +/** + * plat_get_timer_ticks_msec - Helper function to get tick/msec + */ +static uint64_t plat_get_timer_ticks_msec(uint64_t freq) +{ + /* Compute ticks needed for 1 msec */ + return (uint64_t)(freq/1000); +} + +/** + * plat_timer_set_period - Sets period for the timer events + * + * @brief This function configures timer to raise event after the + * programmed value. + * + * @param[in] p: Period of events in milli seconds + */ +static void plat_timer_set_period(unsigned int p) +{ + uint64_t nt; + arch_di_mtime(); + ticks = plat_get_timer_ticks_msec(tm->clk); + ticks *= p; + nt = ticks + clint_read_time(); + status_t ret = clint_config_tcmp(arch_core_index(), nt); + if(ret) + { + syslog_stdout_enable(); + syslog(fail, "Failed to configure timer, Err = %p\n", ret); + plat_panic_handler(); + } + arch_ei_mtime(); +} + +/** + * plat_read_time - This function returns time + * + * @brief This function returns time based on timer events. + * The value might not be accurate to wall clock. + * + * @return time in microseconds + */ +static uint64_t plat_read_time(void) +{ + uint64_t stamp = clint_read_time(); + stamp *= 1000000U; + return (uint64_t)(stamp / tm->clk); +} + +/** + * Driver ops for linking timer + */ +static tvisor_timer_t *plat_timer_port; + +/** + * plat_timer_setup - Timer driver setup function + * To be exported to driver table. + */ +status_t plat_timer_setup(void) +{ + status_t ret = success; + const irqs_t *irq; + arch_di_mtime(); + + plat_timer_port = (tvisor_timer_t *)malloc(sizeof(tvisor_timer_t)); + if(!plat_timer_port) + return error_memory_low; + plat_timer_port->read_ticks = &clint_read_time; + plat_timer_port->read_time = &plat_read_time; + plat_timer_port->set_period = &plat_timer_set_period; + plat_timer_port->reg_cb = &plat_timer_reg_cb; + + /* This funcition fetches device properties */ + ret |= plat_get_timer_prop(); + + irq = &tm->interrupt[0]; + + /* Link timer isr handle */ + ret |= link_interrupt(irq->module, irq->id, &plat_tmr_isr); + ret |= timer_attach_device(ret, plat_timer_port); + plat_timer_set_period(1); + return ret; +} + +/** + * plat_timer_exit - Timer driver shutdown function + * To be exported to driver table. + */ +status_t plat_timer_exit(void) +{ + const irqs_t *irq; + arch_di_mtime(); + tmr_cb = (void *) 0; + ticks = 0; + irq = &tm->interrupt[0]; + unlink_interrupt(irq->module, irq->id); + free(plat_timer_port); + return timer_release_device(); +} + +#if USE_TIMER +INCLUDE_DRIVER(plat_timer, plat_timer_setup, plat_timer_exit, 0, 1, 1); +#endif diff --git a/src/platform/ibex/simple_system/platform/platform.c b/src/platform/ibex/simple_system/platform/platform.c new file mode 100644 index 00000000..40a3d0fd --- /dev/null +++ b/src/platform/ibex/simple_system/platform/platform.c @@ -0,0 +1,86 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : platform.c + * Description : This file contains sources for platform functions + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +void platform_early_setup() +{ + status_t ret = success; +#if USE_PRNG + unsigned int temp_randomnumber = rand(); +#endif + ret |= platform_bss_clear(); + ret |= platform_init_heap(); + ret |= platform_resources_setup(); +#if USE_PRNG + srand(temp_randomnumber); +#endif + syslog_stdout_disable(); + driver_setup("mslog"); + + if(ret != success) + exit(EXIT_FAILURE); + return; +} + +static void platform_memory_layout() +{ + extern uint32_t _text_start, _text_size, _text_end, + _rodata_start, _rodata_size, _rodata_end, + _data_vstart, _data_size, _data_vend, + _stack_start, _stack_end, _stack_size, + _bss_start, _bss_size, _bss_end, + _heap_start, _heap_size, _heap_end, + _ram_size; + + syslog(info, "\n"); + syslog(info, "Program Memory Layout >\n"); + syslog(info, "RAM Size\t: %u\n", &_ram_size); + syslog(info, "text Region\t: %010p - %010p : Size: %u\n", + &_text_start, &_text_end, &_text_size); + syslog(info, "rodata Region\t: %010p - %010p : Size: %u\n", + &_rodata_start, &_rodata_end, &_rodata_size); + syslog(info, "bss Region\t: %010p - %010p : Size: %u\n", + &_bss_start, &_bss_end, &_bss_size); + syslog(info, "data Region\t: %010p - %010p : Size: %u\n", + &_data_vstart, &_data_vend, &_data_size); + syslog(info, "stack Region\t: %010p - %010p : Size: %u\n", + &_stack_end, &_stack_start, &_stack_size); + syslog(info, "heap Region\t: %010p - %010p : Size: %u\n", + &_heap_start, &_heap_end, &_heap_size); + syslog(info, "\n"); +} + +void platform_setup() +{ + driver_setup("earlycon"); + bootmsgs_enable(); + cyancore_insignia(); + platform_print_cpu_info(); + platform_memory_layout(); + return; +} + +void platform_cpu_setup() +{ + arch_ei(); + return; +} diff --git a/src/platform/ibex/simple_system/platform/platform_reset.c b/src/platform/ibex/simple_system/platform/platform_reset.c new file mode 100644 index 00000000..888e7721 --- /dev/null +++ b/src/platform/ibex/simple_system/platform/platform_reset.c @@ -0,0 +1,49 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : platform_reset.c + * Description : This file contains sources for platform + * reset apis + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include +#include +#include +#include +#include + +/** + * platform_get_reset_syndrome - returns the cause of reset + * + * @brief This function returns the information related to + * the reset sources. + * + * @return reset_cause: This function returs the reset cause + */ +reset_t platform_get_reset_syndrome() +{ + return power_on_reset; +} + + +/** + * platform_reset_handler - handles the reset conditions + * + * @brief This function is responsible to handle the reset + * sources like watchdog, brownout, external reset, etc. + * + * @param[in] rsyn: Reset syndrome + * + * @return void + */ +void platform_reset_handler(reset_t rsyn) +{ + if(rsyn == power_on_reset) + return; + else + plat_panic_handler(); +} + diff --git a/src/platform/ibex/simple_system/platform/platform_resource.c b/src/platform/ibex/simple_system/platform/platform_resource.c new file mode 100644 index 00000000..8235f0dd --- /dev/null +++ b/src/platform/ibex/simple_system/platform/platform_resource.c @@ -0,0 +1,100 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : platform_resource.c + * Description : This file contains sources for platform + * resource apis + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include +#include +#include +#include +#include +#include +#include + +/** + * platform_resources_setup - Updates platform DP and SP + * + * @brief This function is responsible to update platform DP + * and make it accessible to the system. This function needs + * to be called during platform setup. + * + * @return status: return the function execution status + */ +status_t platform_resources_setup() +{ + status_t ret = success; + extern dp_t device_prop; + extern sp_t software_prop; + ret = dp_init(&device_prop); + ret |= sp_init(&software_prop); + return ret; +} + +/** + * platform_fetch_sp - vcall handler for fetch_sp + * + * @brief This function is a machine call hander for fetch_sp + * access code. It is responsible to respond with hardware ID + * to corresponding software properties. + * + * @param[in] a0: arg0 + * @param[in] a1: arg1 + * @param[in] a2: arg2 + * + * @return status: return the function execution status + */ +static void platform_fetch_sp(call_arg_t a0, call_arg_t a1 _UNUSED, + call_arg_t a2 _UNUSED, vret_t *ret) +{ + sysdbg5("Fetch SP: Got request for %x\n", a0); + ret->p = (uintptr_t) sp_terravisor_dev_info(a0); + ret->size = (ret->p) ? sizeof(hw_devid_t) : 0; + ret->status = (ret->p) ? success : error_device_id_inval; + return; +} + +INCLUDE_VCALL(ibex_ss_fetch_sp, fetch_sp, platform_fetch_sp); + +/** + * platform_fetch_dp - vcall handler for fetch_dp + * + * @brief This function is a machine call hander for fetch_dp + * access code. It is responsible to respond with pointer to + * corresponding device properties. + * + * @param[in] a0: arg0 + * @param[in] a1: arg1 + * @param[in] a2: arg2 + * + * @return status: return the function execution status + */ +static void platform_fetch_dp(call_arg_t a0, call_arg_t a1 _UNUSED, + call_arg_t a2 _UNUSED, vret_t *ret) +{ + sysdbg5("Fetch DP: Got request for %x\n", a0); + switch(a0) + { + case clock: + ret->p = (uintptr_t)dp_get_base_clock(); + ret->size = (ret->p) ? sizeof(uint64_t) : 0; + break; + case gpio: + ret->p = (uintptr_t)dp_get_port_info(a0 | a1); + ret->size = (ret->p) ? sizeof(gpio_module_t) : 0; + break; + default: + ret->p = (uintptr_t) dp_get_module_info(a0 | a1); + ret->size = (ret->p) ? sizeof(module_t) : 0; + break; + } + ret->status = (ret->p) ? success : error_device_id_inval; + return; +} + +INCLUDE_VCALL(ibex_ss_fetch_dp, fetch_dp, platform_fetch_dp); diff --git a/src/platform/ibex/simple_system/resources/build.mk b/src/platform/ibex/simple_system/resources/build.mk new file mode 100644 index 00000000..ab8cbf6f --- /dev/null +++ b/src/platform/ibex/simple_system/resources/build.mk @@ -0,0 +1,13 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : build.mk +# Description : This file builds resources sources +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +DIR := $(GET_PATH) + +include mk/obj.mk diff --git a/src/platform/ibex/simple_system/resources/dp.c b/src/platform/ibex/simple_system/resources/dp.c new file mode 100644 index 00000000..cc2c814c --- /dev/null +++ b/src/platform/ibex/simple_system/resources/dp.c @@ -0,0 +1,38 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : dp.c + * Description : This file contains sources for platform + * device properties + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include +#include +#include +#include + +#ifndef XCLK +#define XCLK 0 +INFO(< ! > XCLK is not defined!) +#endif + +create_cpu(core0, "riscv-ibex", 0); + +create_memory(mem, RAM_START, RAM_LENGTH); + +create_module(uart0, (uart | 0), 0x20000, 0x1, 0, 0); + +create_module(timer_core0, (timer | 0), 0, 0, 2000000, 0, + add_irq(0, int_local, 7, int_level)); + +create_module(clint0, clint, 0x30000, 16, 0, 0); + +create_gpio_list(port_list, 0); + +create_module_list(mod_list, &uart0, &clint0, &timer_core0); + +create_dp(device_prop, XCLK, mem, port_list, mod_list, + add_cpu(0, core0)); diff --git a/src/platform/ibex/simple_system/resources/sp.c b/src/platform/ibex/simple_system/resources/sp.c new file mode 100644 index 00000000..971ce9f1 --- /dev/null +++ b/src/platform/ibex/simple_system/resources/sp.c @@ -0,0 +1,26 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : sp.c + * Description : This file contains sources for platform + * software properties + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include +#include + +create_swdev(consoleUart, console_uart, (uart | 0), 0); + +create_swdev(schedTimer, sched_timer, (timer | 0)); + +create_visor(terravisor, console_uart, sched_timer); + +create_swdev_list(sw_devs, &consoleUart, &schedTimer); + +create_sp(software_prop, + add_swdev(sw_devs), + add_terravisor(terravisor), + ); diff --git a/src/platform/ibex/simple_system/sections.ld.sx b/src/platform/ibex/simple_system/sections.ld.sx new file mode 100644 index 00000000..5c6d8f4e --- /dev/null +++ b/src/platform/ibex/simple_system/sections.ld.sx @@ -0,0 +1,128 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : sections.ld.sx + * Description : This file contains memory layout for the + * cyancore framework + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include +#include + +MEMORY +{ + /* VM Addresses */ + ram (airwx) : ORIGIN = RAM_START, LENGTH = RAM_LENGTH +} + +ENTRY(entry) + +SECTIONS +{ + .text : ALIGN(4) + { + KEEP(*(.vtors)) + KEEP(*(.text.entry)) + *(.text) + *(.text.*) + . = ALIGN(8); + } > ram + + .rodata : ALIGN(4) + { + *(.version) + KEEP(*(.version)) + KEEP(*(.rdata)) + KEEP(*(.rodata)) + *(.rodata.*) + *(.srodata) + *(.srodata.*) + KEEP(*(.srodata)) + . = ALIGN(8); + } > ram + + .bss : ALIGN(4) + { + *(.bss) + *(.bss.*) + KEEP(*(.bss)) + *(COMMON) + } > ram + + .static_bss_global : ALIGN(4) + { + *(.sbss) + *(.sbss.*) + KEEP(*(.sbss)) + } > ram + + .static_global_var : + { + } > ram + + .static_data_global : ALIGN(4) + { + *(.sdata) + *(.sdata.*) + KEEP(*(.sdata)) + } > ram + + .data : ALIGN(4) + { + *(.data) + *(.data.*) + KEEP(*(.data)) + DRIVER_TABLE + VCALL_TABLE + } > ram + + .heap : ALIGN(HEAP_ALIGN) + { + *(.heap) + KEEP(*(.heap)) + . = . + HEAP_SIZE; + } > ram + + .stack : ALIGN(16) + { + *(.stack) + KEEP(*(.stack)) + . = . + STACK_SIZE; + } > ram + + PROVIDE(_text_start = ADDR(.text)); + PROVIDE(_text_size = SIZEOF(.text)); + PROVIDE(_text_end = _text_start + _text_size - 1); + + PROVIDE(_rodata_start = ADDR(.rodata)); + PROVIDE(_rodata_size = SIZEOF(.rodata)); + PROVIDE(_rodata_end = _rodata_start + _rodata_size - 1); + + PROVIDE(_tls_start = ADDR(.data)); + PROVIDE(_data_size = SIZEOF(.data) + SIZEOF(.static_data_global)); + PROVIDE(_data_vstart = ADDR(.static_data_global)); + PROVIDE(_data_vend = _data_vstart + _data_size - 1); + + PROVIDE(_global_start = ADDR(.static_global_var) + 0x800); + PROVIDE(_stack_size = SIZEOF(.stack)); + PROVIDE(_stack_end = ADDR(.stack)); + PROVIDE(_stack_start = _stack_end + _stack_size); + + PROVIDE(_bss_start = ADDR(.bss)); + PROVIDE(_bss_size = SIZEOF(.bss) + SIZEOF(.static_bss_global)); + PROVIDE(_bss_end = _bss_start + _bss_size - 1); + + PROVIDE(_heap_start = ADDR(.heap)); + PROVIDE(_heap_size = SIZEOF(.heap)); + PROVIDE(_heap_end = _heap_start + _heap_size - 1); + + PROVIDE(_ram_size = _bss_size + _data_size + SIZEOF(.stack) + \ + SIZEOF(.heap) + SIZEOF(.text) + SIZEOF(.rodata)); + + ASSERT((_ram_size < RAM_LENGTH), "< x > RAM size exceeded ...") + + /DISCARD/ : { *(.comment .trampolines) } +}