From 25fb041d1c9059843a14c6efe91225c49748a86b Mon Sep 17 00:00:00 2001 From: qwang Date: Wed, 25 Nov 2020 13:37:30 +0800 Subject: [PATCH] Add basic C++ support --- components/bl602/bl602/evb/ld/flash_rom.ld | 17 +++++++++++++++ .../bl602/bl602/evb/src/boot/gcc/start.S | 21 +++++++++++++++++++ components/hal_drv/bl602.mk | 6 ++++-- .../platform_hal/platform_hal_device.cpp | 9 ++++---- make_scripts_riscv/component_wrapper.mk | 2 +- make_scripts_riscv/project.mk | 11 +++++++--- 6 files changed, 56 insertions(+), 10 deletions(-) diff --git a/components/bl602/bl602/evb/ld/flash_rom.ld b/components/bl602/bl602/evb/ld/flash_rom.ld index bfa3bd06..93f6ad7c 100644 --- a/components/bl602/bl602/evb/ld/flash_rom.ld +++ b/components/bl602/bl602/evb/ld/flash_rom.ld @@ -80,6 +80,23 @@ SECTIONS _rom_framework_audio_device_end = .; } > flash + .preinit_array : + { + . = ALIGN(4); + __preinit_array_start = .; + KEEP (*(.preinit_array)) + __preinit_array_end = .; + } > flash + + .init_array : + { + . = ALIGN(4); + __init_array_start = .; + KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*))) + KEEP (*(.init_array)) + __init_array_end = .; + } > flash + /*put wifibss in the first place*/ .wifibss (NOLOAD) : { diff --git a/components/bl602/bl602/evb/src/boot/gcc/start.S b/components/bl602/bl602/evb/src/boot/gcc/start.S index a4e15174..8467a839 100644 --- a/components/bl602/bl602/evb/src/boot/gcc/start.S +++ b/components/bl602/bl602/evb/src/boot/gcc/start.S @@ -119,6 +119,27 @@ bl602_start: sd ra, 8(sp) #endif +// call global obj constructors + la s1, __preinit_array_start + la s2, __preinit_array_end + li s3, 4 +1: + bgeu s1, s2, 2f + lw a3, (s1) + jalr a3 + add s1, s1, s3 + j 1b +2: + la s1, __init_array_start + la s2, __init_array_end + li s3, 4 +1: + bgeu s1, s2, 2f + lw a3, (s1) + jalr a3 + add s1, s1, s3 + j 1b +2: /* argc = argv = 0 */ li a0, 0 li a1, 0 diff --git a/components/hal_drv/bl602.mk b/components/hal_drv/bl602.mk index 1170c36c..62dd7492 100644 --- a/components/hal_drv/bl602.mk +++ b/components/hal_drv/bl602.mk @@ -1,7 +1,7 @@ # Component Makefile # ## These include paths would be exported to project level -COMPONENT_ADD_INCLUDEDIRS += bl602_hal +COMPONENT_ADD_INCLUDEDIRS += bl602_hal platform_hal ## not be exported to project level COMPONENT_PRIV_INCLUDEDIRS := @@ -50,8 +50,10 @@ COMPONENT_SRCS := bl602_hal/bl_uart.c \ bl602_hal/hal_spi.c \ bl602_hal/hal_adc.c \ bl602_hal/hal_wifi.c \ + platform_hal/platform_hal_device.cpp \ -COMPONENT_SRCDIRS := bl602_hal + +COMPONENT_SRCDIRS := bl602_hal platform_hal COMPONENT_OBJS := $(patsubst %.c,%.o, $(COMPONENT_SRCS)) COMPONENT_OBJS := $(patsubst %.cpp,%.o, $(COMPONENT_OBJS)) diff --git a/components/hal_drv/platform_hal/platform_hal_device.cpp b/components/hal_drv/platform_hal/platform_hal_device.cpp index 8f0b5d6b..1a6578b6 100644 --- a/components/hal_drv/platform_hal/platform_hal_device.cpp +++ b/components/hal_drv/platform_hal/platform_hal_device.cpp @@ -32,23 +32,23 @@ extern "C" void* operator new(size_t size) { - printf("[C++] new %d\r\n", size); + /* printf("[C++] new %d\r\n", size); */ return pvPortMalloc(size); } extern "C" void* operator new[](size_t size) { - printf("[C++] new[] %d\r\n", size); + /* printf("[C++] new[] %d\r\n", size); */ return pvPortMalloc(size); } extern "C" void operator delete(void* ptr) { - printf("[C++] delete %p\r\n", ptr); + /* printf("[C++] delete %p\r\n", ptr); */ vPortFree(ptr); } extern "C" void operator delete[](void* ptr) { - printf("[C++] delete[] %p\r\n", ptr); + /* printf("[C++] delete[] %p\r\n", ptr); */ vPortFree(ptr); } @@ -242,6 +242,7 @@ extern "C" int platform_hal_device_init(void) class BLAesRequest *aes_request = new BLAesRequest[6]; aes_engine = new BLAesEngine(); + (void)aes_request; #if 0 aes_engine->encryption(aes_request[0]); #endif diff --git a/make_scripts_riscv/component_wrapper.mk b/make_scripts_riscv/component_wrapper.mk index 46ec6412..961257c6 100644 --- a/make_scripts_riscv/component_wrapper.mk +++ b/make_scripts_riscv/component_wrapper.mk @@ -281,7 +281,7 @@ $(2)/%.o: $$(COMPONENT_PATH)/$(1)/%.c $(COMMON_MAKEFILES) $(COMPONENT_MAKEFILE) $(2)/%.o: $$(COMPONENT_PATH)/$(1)/%.cpp $(COMMON_MAKEFILES) $(COMPONENT_MAKEFILE) | $(COMPONENT_OBJDIRS) $$(summary) CXX $$(patsubst $$(PWD)/%,%,$$(CURDIR))/$$@ - $$(CXX) $$(CFLAGS) $$(CXXFLAGS) -D __FILENAME__=\"$$(notdir $$<)\" -D __FILENAME_WO_SUFFIX__=\"$$(subst .c,,$$(notdir $$<))\" -D __FILENAME_WO_SUFFIX_DEQUOTED__=$$(subst .c,,$$(notdir $$<)) -D __COMPONENT_NAME__=\"$$(COMPONENT_NAME)\" -D __COMPONENT_NAME_DEQUOTED__=$$(COMPONENT_NAME) -D __COMPONENT_FILE_NAME__=\"$$(COMPONENT_NAME)$$(subst .c,,$$(notdir $$<))\" -D__COMPONENT_FILE_NAMED__=$$(COMPONENT_NAME).$$(subst .c,,$$(notdir $$<)) -D__COMPONENT_FILE_NAME_DEQUOTED__=$$(COMPONENT_NAME)$$(subst .c,,$$(notdir $$<)) $$(CPPFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I $(1) -c $$(abspath $$<) -o $$@ + $$(CXX) $$(CXXFLAGS) $$(CPPFLAGS) -D __FILENAME__=\"$$(notdir $$<)\" -D __FILENAME_WO_SUFFIX__=\"$$(subst .c,,$$(notdir $$<))\" -D __FILENAME_WO_SUFFIX_DEQUOTED__=$$(subst .c,,$$(notdir $$<)) -D __COMPONENT_NAME__=\"$$(COMPONENT_NAME)\" -D __COMPONENT_NAME_DEQUOTED__=$$(COMPONENT_NAME) -D __COMPONENT_FILE_NAME__=\"$$(COMPONENT_NAME)$$(subst .c,,$$(notdir $$<))\" -D__COMPONENT_FILE_NAMED__=$$(COMPONENT_NAME).$$(subst .c,,$$(notdir $$<)) -D__COMPONENT_FILE_NAME_DEQUOTED__=$$(COMPONENT_NAME)$$(subst .c,,$$(notdir $$<)) $$(CPPFLAGS) $$(addprefix -I ,$$(COMPONENT_INCLUDES)) $$(addprefix -I ,$$(COMPONENT_EXTRA_INCLUDES)) -I $(1) -c $$(abspath $$<) -o $$@ $(call AppendSourceToDependencies,$$<,$$@) $(2)/%.o: $$(COMPONENT_PATH)/$(1)/%.cc $(COMMON_MAKEFILES) $(COMPONENT_MAKEFILE) | $(COMPONENT_OBJDIRS) diff --git a/make_scripts_riscv/project.mk b/make_scripts_riscv/project.mk index 9b041798..2df88bbe 100644 --- a/make_scripts_riscv/project.mk +++ b/make_scripts_riscv/project.mk @@ -341,8 +341,11 @@ CFLAGS := $(strip \ -save-temps=obj CXXFLAGS := $(strip \ - $(CPPFLAGS) \ - $(OPTIMIZATION_FLAGS) \ + -std=c++11 \ + $(OPTIMIZATION_FLAGS) $(DEBUG_FLAGS) \ + $(COMMON_FLAGS) \ + $(COMMON_WARNING_FLAGS) \ + $(CXXFLAGS) \ $(E21_CPU_CFLAGS) \ -nostdlib \ -g3 \ @@ -357,7 +360,9 @@ CXXFLAGS := $(strip \ -Wswitch-default \ -Wunused \ -Wundef \ - -fno-rtti -fno-exceptions) + -fno-rtti -fno-exceptions \ + -save-temps=obj \ + ) export CFLAGS CPPFLAGS CXXFLAGS ASMFLAGS