Initial Release

This commit is contained in:
graham sanderson
2021-01-20 10:44:27 -06:00
commit 26653ea81e
404 changed files with 135614 additions and 0 deletions

View File

@ -0,0 +1,52 @@
if (NOT TARGET pico_mem_ops)
#shims for ROM functions for -lgcc functions (listed below)
add_library(pico_mem_ops INTERFACE)
# no custom implementation; falls thru to compiler
add_library(pico_mem_ops_compiler INTERFACE)
# PICO_BUILD_DEFINE: PICO_MEM_OPS_COMPILER, whether compiler provided mem_ops memcpy etc. support is being used, type=bool, default=0, but dependent on CMake options, group=pico_mem_ops
target_compile_definitions(pico_mem_ops_compiler INTERFACE
PICO_MEM_OPS_COMPILER=1
)
# add alias "default" which is just pico.
add_library(pico_mem_ops_default INTERFACE)
target_link_libraries(pico_mem_ops_default INTERFACE pico_mem_ops_pico)
set(PICO_DEFAULT_MEM_OPS_IMPL pico_mem_ops_default)
add_library(pico_mem_ops_pico INTERFACE)
target_link_libraries(pico_mem_ops INTERFACE
$<IF:$<BOOL:$<TARGET_PROPERTY:PICO_TARGET_MEM_OPS_IMPL>>,$<TARGET_PROPERTY:PICO_TARGET_MEM_OPS_IMPL>,${PICO_DEFAULT_MEM_OPS_IMPL}>)
# PICO_BUILD_DEFINE: PICO_MEM_OPS_PICO, whether optimized pico/bootrom provided mem_ops memcpy etc. support is being used, type=bool, default=1, but dependent on CMake options, group=pico_mem_ops
target_compile_definitions(pico_mem_ops_pico INTERFACE
PICO_MEM_OPS_PICO=1
)
target_sources(pico_mem_ops_pico INTERFACE
${CMAKE_CURRENT_LIST_DIR}/mem_ops_aeabi.S
)
target_link_libraries(pico_mem_ops INTERFACE pico_bootrom)
pico_wrap_function(pico_mem_ops_pico memcpy)
pico_wrap_function(pico_mem_ops_pico memset)
pico_wrap_function(pico_mem_ops_pico __aeabi_memcpy)
pico_wrap_function(pico_mem_ops_pico __aeabi_memset)
pico_wrap_function(pico_mem_ops_pico __aeabi_memcpy4)
pico_wrap_function(pico_mem_ops_pico __aeabi_memset4)
pico_wrap_function(pico_mem_ops_pico __aeabi_memcpy8)
pico_wrap_function(pico_mem_ops_pico __aeabi_memset8)
macro(pico_set_mem_ops_implementation TARGET IMPL)
get_target_property(target_type ${TARGET} TYPE)
if ("EXECUTABLE" STREQUAL "${target_type}")
set_target_properties(${TARGET} PROPERTIES PICO_TARGET_MEM_OPS_IMPL "pico_mem_ops_${IMPL}")
else()
message(FATAL_ERROR "mem_ops implementation must be set on executable not library")
endif()
endmacro()
endif()

View File

@ -0,0 +1,22 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _PICO_MEMORY_H
#define _PICO_MEMORY_H
#include "pico/types.h"
/** \file mem_ops.h
* \defgroup pico_mem_ops pico_mem_ops
*
* Provides optimized replacement implementations of the compiler built-in memcpy, memset and related functions:
*
* - memset, memcpy
* - __aeabi_memset, __aeabi_memset4, __aeabi_memset8, __aeabi_memcpy, __aeabi_memcpy4, __aeabi_memcpy8
*
* This library does not provide any additional functions
*/
#endif

View File

@ -0,0 +1,7 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "pico/mem_ops.h"

View File

@ -0,0 +1,98 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
.syntax unified
.cpu cortex-m0plus
.thumb
#include "pico/asm_helper.S"
__pre_init __aeabi_mem_init, 00001
.macro mem_section name
#if PICO_MEM_IN_RAM
.section RAM_SECTION_NAME(\name), "ax"
#else
.section SECTION_NAME(\name), "ax"
#endif
.endm
.equ MEMSET, 0
.equ MEMCPY, 4
.equ MEMSET4, 8
.equ MEMCPY4, 12
.equ MEM_FUNC_COUNT, 4
# NOTE: All code sections are placed in RAM (at the expense of some veneer cost for calls from flash) because
# otherwise code using basic c division operators will require XIP flash access.
.section .data.aeabi_mem_funcs
.global aeabi_mem_funcs, aeabi_mem_funcs_end
.align 2
aeabi_mem_funcs:
.word rom_table_code('M','S')
.word rom_table_code('M','C')
.word rom_table_code('S','4')
.word rom_table_code('C','4')
aeabi_mem_funcs_end:
.section .text
regular_func __aeabi_mem_init
ldr r0, =aeabi_mem_funcs
movs r1, #MEM_FUNC_COUNT
ldr r3, =rom_funcs_lookup
bx r3
# lump them both together because likely both to be used, in which case doing so saves 1 word
# and it only costs 1 word if not
// Note from Run-time ABI for the ARM architecture 4.3.4:
// If there is an attached device with efficient memory copying or clearing operations
// (such as a DMA engine), its device supplement specifies whether it may be used in
// implementations of these functions and what effect such use has on the devices state.
mem_section aeabi_memset_memcpy
wrapper_func __aeabi_memset
// args are backwards
eors r0, r1
eors r1, r0
eors r0, r1
ldr r3, =aeabi_mem_funcs
ldr r3, [r3, #MEMSET]
bx r3
wrapper_func __aeabi_memset4
wrapper_func __aeabi_memset8
// args are backwards
eors r0, r1
eors r1, r0
eors r0, r1
ldr r3, =aeabi_mem_funcs
ldr r3, [r3, #MEMSET4]
bx r3
wrapper_func __aeabi_memcpy4
wrapper_func __aeabi_memcpy8
ldr r3, =aeabi_mem_funcs
ldr r3, [r3, #MEMCPY4]
bx r3
mem_section memset
wrapper_func memset
ldr r3, =aeabi_mem_funcs
ldr r3, [r3, #MEMSET]
bx r3
mem_section memcpy
wrapper_func __aeabi_memcpy
wrapper_func memcpy
ldr r3, =aeabi_mem_funcs
ldr r3, [r3, #MEMCPY]
bx r3