Skip to content

Commit

Permalink
<ibex> Add support for ibex simple system platform
Browse files Browse the repository at this point in the history
- Fixed elf.mk to print size when flash is absent
- Add support for rv32imc cpu
- Add platform drivers for ibex
- Add console driver for ibex family
  • Loading branch information
akashkollipara committed Jun 28, 2024
1 parent 35b69a7 commit 6c78930
Show file tree
Hide file tree
Showing 37 changed files with 1,380 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mk/elf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions projects/demo_ibex_ss/build.mk
Original file line number Diff line number Diff line change
@@ -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 [[email protected]]
# 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
18 changes: 18 additions & 0 deletions projects/demo_ibex_ss/config.mk
Original file line number Diff line number Diff line change
@@ -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 [[email protected]]
# Organisation : Cyancore Core-Team
#

COMPILER := gcc
FAMILY := ibex
PLATFORM := simple_system
STDLOG_MEMBUF := 1
BOOTMSGS := 1
EARLYCON_SERIAL := 1
OBRDLED_ENABLE := 0
TERRAKERN := 0
43 changes: 43 additions & 0 deletions projects/demo_ibex_ss/project.c
Original file line number Diff line number Diff line change
@@ -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 [[email protected]]
* Organisation : Cyancore Core-Team
*/

#include <status.h>
#include <stdio.h>
#include <string.h>
#include <terravisor/bootstrap.h>
#include <driver.h>
#include <time.h>

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;
}
2 changes: 2 additions & 0 deletions src/arch/riscv/32/i/terravisor/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 7 additions & 0 deletions src/arch/riscv/32/i/terravisor/asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions src/arch/riscv/32/imc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# RV32 IMC-Extension

#### Supported Extensions
* RV32I baseline
* M - Hardware multiplication
* C - Compressed instructions

#### Supported execution level
* Terravisor
7 changes: 7 additions & 0 deletions src/arch/riscv/32/imc/terravisor/README.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 16 additions & 0 deletions src/arch/riscv/32/imc/terravisor/build.mk
Original file line number Diff line number Diff line change
@@ -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 [[email protected]]
# 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
20 changes: 20 additions & 0 deletions src/driver/console/con_serial_ibex/build.mk
Original file line number Diff line number Diff line change
@@ -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 [[email protected]]
# 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
92 changes: 92 additions & 0 deletions src/driver/console/con_serial_ibex/earlycon_serial.c
Original file line number Diff line number Diff line change
@@ -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 [[email protected]]
* Organisation : Cyancore Core-Team
*/

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <status.h>
#include <stdlib.h>
#include <syslog.h>
#include <lock/spinlock.h>
#include <resource.h>
#include <visor_call.h>
#include <arch.h>
#include <driver.h>
#include <interrupt.h>
#include <hal/uart.h>
#include <driver/console.h>
#include <driver/sysclk.h>

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
14 changes: 14 additions & 0 deletions src/platform/ibex/simple_system/arch/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2019, Cyancore Team
#
# File Name : build.mk
# Description : This file accumulates the build fe310 series
# platform arch sources
# Primary Author : Akash Kollipara [[email protected]]
# Organisation : Cyancore Core-Team
#

DIR := $(GET_PATH)

include mk/obj.mk
15 changes: 15 additions & 0 deletions src/platform/ibex/simple_system/arch/panic.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2019, Cyancore Team
*
* File Name : panic.S
* Description : This file contains platform panic handler
* Primary Author : Akash Kollipara [[email protected]]
* Organisation : Cyancore Core-Team
*/

#include <asm.inc>

function plat_panic_handler
wfi
j plat_panic_handler
16 changes: 16 additions & 0 deletions src/platform/ibex/simple_system/arch/platform_cpu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdint.h>
#include <status.h>
#include <syslog.h>
#include <arch.h>
#include <platform.h>

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);
};
13 changes: 13 additions & 0 deletions src/platform/ibex/simple_system/arch/platform_mem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdint.h>
#include <status.h>
#include <string.h>
#include <platform.h>

extern uintptr_t _bss_start, _bss_size;

status_t platform_bss_clear()
{
memset(&_bss_start, 0, (size_t)&_bss_size);
return success;
}

35 changes: 35 additions & 0 deletions src/platform/ibex/simple_system/build.mk
Original file line number Diff line number Diff line change
@@ -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 [[email protected]]
# 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))
Loading

0 comments on commit 6c78930

Please sign in to comment.