Add files via upload
This commit is contained in:
parent
5e150e9ad1
commit
51c77ec3d1
8 changed files with 2291 additions and 0 deletions
106
any_rtos.ld
Normal file
106
any_rtos.ld
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2006 by Michael Fischer. All rights reserved.
|
||||
****************************************************************************
|
||||
*
|
||||
* History:
|
||||
*
|
||||
* 30.03.06 mifi First Version
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
ENTRY(ResetHandler)
|
||||
SEARCH_DIR(.)
|
||||
|
||||
/*
|
||||
* Define stack size here
|
||||
*/
|
||||
FIQ_STACK_SIZE = 0x0100;
|
||||
IRQ_STACK_SIZE = 0x0100;
|
||||
ABT_STACK_SIZE = 0x0100;
|
||||
UND_STACK_SIZE = 0x0100;
|
||||
SVC_STACK_SIZE = 0x0100;
|
||||
|
||||
|
||||
MEMORY
|
||||
{
|
||||
ram : org = 0x00000000, len = 256k
|
||||
}
|
||||
|
||||
/*
|
||||
* Do not change the next code
|
||||
*/
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
*(.vectors);
|
||||
. = ALIGN(4);
|
||||
*(.init);
|
||||
. = ALIGN(4);
|
||||
*(.text);
|
||||
. = ALIGN(4);
|
||||
*(.rodata);
|
||||
. = ALIGN(4);
|
||||
*(.rodata*);
|
||||
. = ALIGN(4);
|
||||
*(.glue_7t);
|
||||
. = ALIGN(4);
|
||||
*(.glue_7);
|
||||
. = ALIGN(4);
|
||||
etext = .;
|
||||
} > ram
|
||||
|
||||
.data :
|
||||
{
|
||||
PROVIDE (__data_start = .);
|
||||
*(.data)
|
||||
. = ALIGN(4);
|
||||
edata = .;
|
||||
_edata = .;
|
||||
PROVIDE (__data_end = .);
|
||||
} > ram
|
||||
|
||||
.bss :
|
||||
{
|
||||
PROVIDE (__bss_start = .);
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
PROVIDE (__bss_end = .);
|
||||
|
||||
. = ALIGN(256);
|
||||
|
||||
PROVIDE (__stack_start = .);
|
||||
|
||||
PROVIDE (__stack_fiq_start = .);
|
||||
. += FIQ_STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
PROVIDE (__stack_fiq_end = .);
|
||||
|
||||
PROVIDE (__stack_irq_start = .);
|
||||
. += IRQ_STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
PROVIDE (__stack_irq_end = .);
|
||||
|
||||
PROVIDE (__stack_abt_start = .);
|
||||
. += ABT_STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
PROVIDE (__stack_abt_end = .);
|
||||
|
||||
PROVIDE (__stack_und_start = .);
|
||||
. += UND_STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
PROVIDE (__stack_und_end = .);
|
||||
|
||||
PROVIDE (__stack_svc_start = .);
|
||||
. += SVC_STACK_SIZE;
|
||||
. = ALIGN(4);
|
||||
PROVIDE (__stack_svc_end = .);
|
||||
PROVIDE (__stack_end = .);
|
||||
PROVIDE (__heap_start = .);
|
||||
} > ram
|
||||
|
||||
}
|
||||
/*** EOF ***/
|
||||
160
lwmem.h
Normal file
160
lwmem.h
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
/**
|
||||
* \file lwmem.h
|
||||
* \brief Lightweight dynamic memory manager
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 Tilen MAJERLE
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||
*
|
||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||
* Version: v2.2.1
|
||||
*/
|
||||
#ifndef LWMEM_HDR_H
|
||||
#define LWMEM_HDR_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "lwmem_opt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* \defgroup LWMEM Lightweight dynamic memory manager
|
||||
* \brief Lightweight dynamic memory manager
|
||||
* \{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Get size of statically allocated array
|
||||
* \param[in] x: Object to get array size of
|
||||
* \return Number of elements in array
|
||||
*/
|
||||
#define LWMEM_ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
/**
|
||||
* \brief Memory block structure
|
||||
*/
|
||||
typedef struct lwmem_block {
|
||||
struct lwmem_block* next; /*!< Next free memory block on linked list.
|
||||
Set to \ref LWMEM_BLOCK_ALLOC_MARK when block is allocated and in use */
|
||||
size_t size; /*!< Size of block, including metadata part.
|
||||
MSB bit is set to `1` when block is allocated and in use,
|
||||
or `0` when block is considered free */
|
||||
} lwmem_block_t;
|
||||
|
||||
/**
|
||||
* \brief Statistics structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t mem_size_bytes; /*!< Total memory size of all regions combined */
|
||||
uint32_t mem_available_bytes; /*!< Free memory available for allocation */
|
||||
uint32_t minimum_ever_mem_available_bytes; /*!< Minimum amount of total free memory there has been
|
||||
in the heap since the system booted. */
|
||||
uint32_t nr_alloc; /*!< Number of all allocated blocks in single instance */
|
||||
uint32_t nr_free; /*!< Number of frees in the LwMEM instance */
|
||||
} lwmem_stats_t;
|
||||
|
||||
/**
|
||||
* \brief LwMEM main structure
|
||||
*/
|
||||
typedef struct lwmem {
|
||||
size_t mem_available_bytes; /*!< Memory size available for allocation */
|
||||
#if LWMEM_CFG_FULL
|
||||
lwmem_block_t start_block; /*!< Holds beginning of memory allocation regions */
|
||||
lwmem_block_t* end_block; /*!< Pointer to the last memory location in regions linked list */
|
||||
size_t mem_regions_count; /*!< Number of regions used for allocation */
|
||||
#else
|
||||
uint8_t* mem_next_available_ptr; /*!< Pointer for next allocation */
|
||||
uint8_t is_initialized; /*!< Set to `1` when initialized */
|
||||
#endif
|
||||
|
||||
#if LWMEM_CFG_OS || __DOXYGEN__
|
||||
LWMEM_CFG_OS_MUTEX_HANDLE mutex; /*!< System mutex for OS */
|
||||
#endif /* LWMEM_CFG_OS || __DOXYGEN__ */
|
||||
#if LWMEM_CFG_ENABLE_STATS || __DOXYGEN__
|
||||
lwmem_stats_t stats; /*!< Statistics */
|
||||
#endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */
|
||||
#if defined(LWMEM_DEV) && !__DOXYGEN__
|
||||
lwmem_block_t start_block_first_use; /*!< Value of start block for very first time.
|
||||
This is used only during validation process and is removed in final use */
|
||||
#endif /* defined(LWMEM_DEV) && !__DOXYGEN__ */
|
||||
} lwmem_t;
|
||||
|
||||
/**
|
||||
* \brief Memory region descriptor
|
||||
*/
|
||||
typedef struct {
|
||||
void* start_addr; /*!< Region start address */
|
||||
size_t size; /*!< Size of region in units of bytes */
|
||||
} lwmem_region_t;
|
||||
|
||||
size_t lwmem_assignmem_ex(lwmem_t* lwobj, const lwmem_region_t* regions);
|
||||
void* lwmem_malloc_ex(lwmem_t* lwobj, const lwmem_region_t* region, const size_t size);
|
||||
void* lwmem_calloc_ex(lwmem_t* lwobj, const lwmem_region_t* region, const size_t nitems, const size_t size);
|
||||
#if LWMEM_CFG_FULL || __DOXYGEN__
|
||||
void* lwmem_realloc_ex(lwmem_t* lwobj, const lwmem_region_t* region, void* const ptr, const size_t size);
|
||||
int lwmem_realloc_s_ex(lwmem_t* lwobj, const lwmem_region_t* region, void** const ptr, const size_t size);
|
||||
void lwmem_free_ex(lwmem_t* lwobj, void* const ptr);
|
||||
void lwmem_free_s_ex(lwmem_t* lwobj, void** const ptr);
|
||||
size_t lwmem_get_size_ex(lwmem_t* lwobj, void* ptr);
|
||||
#endif /* LWMEM_CFG_FULL || __DOXYGEN__ */
|
||||
#if LWMEM_CFG_ENABLE_STATS || __DOXYGEN__
|
||||
void lwmem_get_stats_ex(lwmem_t* lwobj, lwmem_stats_t* stats);
|
||||
void lwmem_get_size(lwmem_stats_t* stats);
|
||||
#endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */
|
||||
|
||||
size_t lwmem_assignmem(const lwmem_region_t* regions);
|
||||
void* lwmem_malloc(size_t size);
|
||||
void* lwmem_calloc(size_t nitems, size_t size);
|
||||
|
||||
#if LWMEM_CFG_FULL || __DOXYGEN__
|
||||
void* lwmem_realloc(void* ptr, size_t size);
|
||||
int lwmem_realloc_s(void** ptr2ptr, size_t size);
|
||||
void lwmem_free(void* ptr);
|
||||
void lwmem_free_s(void** ptr2ptr);
|
||||
size_t lwmem_get_size(void* ptr);
|
||||
#endif /* LWMEM_CFG_FULL || __DOXYGEN__ */
|
||||
|
||||
#if defined(LWMEM_DEV) && !__DOXYGEN__
|
||||
unsigned char lwmem_debug_create_regions(lwmem_region_t** regs_out, size_t count, size_t size);
|
||||
void lwmem_debug_save_state(void);
|
||||
void lwmem_debug_restore_to_saved(void);
|
||||
void lwmem_debug_print(unsigned char print_alloc, unsigned char print_free);
|
||||
void lwmem_debug_test_region(void* region_start, size_t region_size, uint8_t** region_start_calc,
|
||||
size_t* region_size_calc);
|
||||
#endif /* defined(LWMEM_DEV) && !__DOXYGEN__ */
|
||||
|
||||
/**
|
||||
* \}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* LWMEM_HDR_H */
|
||||
161
lwmem_opt.h
Normal file
161
lwmem_opt.h
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
/**
|
||||
* \file lwmem_opt.h
|
||||
* \brief LwMEM options
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 Tilen MAJERLE
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||
*
|
||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||
* Version: v2.2.1
|
||||
*/
|
||||
#ifndef LWMEM_OPT_HDR_H
|
||||
#define LWMEM_OPT_HDR_H
|
||||
|
||||
/* Uncomment to ignore user options (or set macro in compiler flags) */
|
||||
/* #define LWMEM_IGNORE_USER_OPTS */
|
||||
|
||||
/* Include application options */
|
||||
#ifndef LWMEM_IGNORE_USER_OPTS
|
||||
#include "lwmem_opts.h"
|
||||
#endif /* LWMEM_IGNORE_USER_OPTS */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* \defgroup LWMEM_OPT Configuration
|
||||
* \brief LwMEM options
|
||||
* \{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Enables `1` or disables `0` operating system support in the library
|
||||
*
|
||||
* \note When `LWMEM_CFG_OS` is enabled, user must implement functions in \ref LWMEM_SYS group.
|
||||
*/
|
||||
#ifndef LWMEM_CFG_OS
|
||||
#define LWMEM_CFG_OS 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Mutex handle type
|
||||
*
|
||||
* \note This value must be set in case \ref LWMEM_CFG_OS is set to `1`.
|
||||
* If data type is not known to compiler, include header file with
|
||||
* definition before you define handle type
|
||||
*/
|
||||
#ifndef LWMEM_CFG_OS_MUTEX_HANDLE
|
||||
#define LWMEM_CFG_OS_MUTEX_HANDLE void*
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Number of bits to align memory address and memory size
|
||||
*
|
||||
* Some CPUs do not offer unaligned memory access (Cortex-M0 as an example)
|
||||
* therefore it is important to have alignment of data addresses and potentialy length of data
|
||||
*
|
||||
* \note This value must be a power of `2` for number of bytes.
|
||||
* Usually alignment of `4` bytes fits to all processors.
|
||||
*/
|
||||
#ifndef LWMEM_CFG_ALIGN_NUM
|
||||
#define LWMEM_CFG_ALIGN_NUM 4
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Enables `1` or disables `0` full memory management support.
|
||||
*
|
||||
* When enabled (default config), library supports allocation, reallocation and freeing of the memory.
|
||||
* - Memory [c]allocation
|
||||
* - Memory reallocation
|
||||
* - Memory allocation in user defined memory regions
|
||||
* - Memory freeing
|
||||
*
|
||||
* When disabled, library only supports allocation and does not provide any other service.
|
||||
* - Its purpose is for memory allocation at the start of firmware initialization only
|
||||
*
|
||||
* \note When disabled, statistics functionaltiy is not available
|
||||
* and only one region is supported (for now, may be updated later).
|
||||
* API to allocate memory remains the same as for full configuration.
|
||||
*/
|
||||
#ifndef LWMEM_CFG_FULL
|
||||
#define LWMEM_CFG_FULL 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Enables `1` or disables `0` memory cleanup on free operation (or realloc).
|
||||
*
|
||||
* It resets unused memory to `0x00` and prevents other applications seeing old data.
|
||||
* It is disabled by default since it has performance penalties.
|
||||
*/
|
||||
#ifndef LWMEM_CFG_CLEAN_MEMORY
|
||||
#define LWMEM_CFG_CLEAN_MEMORY 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Enables `1` or disables `0` statistics in the library
|
||||
*
|
||||
*/
|
||||
#ifndef LWMEM_CFG_ENABLE_STATS
|
||||
#define LWMEM_CFG_ENABLE_STATS 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Memory set function
|
||||
*
|
||||
* \note Function footprint is the same as \ref memset
|
||||
*/
|
||||
#ifndef LWMEM_MEMSET
|
||||
#define LWMEM_MEMSET(dst, val, len) memset((dst), (val), (len))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Memory copy function
|
||||
*
|
||||
* \note Function footprint is the same as \ref memcpy
|
||||
*/
|
||||
#ifndef LWMEM_MEMCPY
|
||||
#define LWMEM_MEMCPY(dst, src, len) memcpy((dst), (src), (len))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief Memory move function
|
||||
*
|
||||
* \note Function footprint is the same as \ref memmove
|
||||
*/
|
||||
#ifndef LWMEM_MEMMOVE
|
||||
#define LWMEM_MEMMOVE(dst, src, len) memmove((dst), (src), (len))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* LWMEM_OPT_HDR_H */
|
||||
44
lwmem_opts.h
Normal file
44
lwmem_opts.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* \file lwmem_opts_template.h
|
||||
* \brief Template config file
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2024 Tilen MAJERLE
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||
*
|
||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||
* Version: v2.2.1
|
||||
*/
|
||||
#ifndef LWMEM_OPTS_HDR_H
|
||||
#define LWMEM_OPTS_HDR_H
|
||||
|
||||
/* Rename this file to "lwmem_opts.h" for your application */
|
||||
|
||||
/*
|
||||
* Open "include/lwmem/lwmem_opt.h" and
|
||||
* copy & replace here settings you want to change values
|
||||
*/
|
||||
|
||||
#endif /* LWMEM_OPTS_HDR_H */
|
||||
131
makefile
Normal file
131
makefile
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
##############################################################################################
|
||||
# Start of default section
|
||||
#
|
||||
|
||||
TRGT = arm-none-eabi-
|
||||
CC = $(TRGT)gcc -fPIC -fPIE
|
||||
CP = $(TRGT)objcopy
|
||||
AS = $(TRGT)gcc -x assembler-with-cpp
|
||||
HEX = $(CP) -O ihex
|
||||
BIN = $(CP) -O binary
|
||||
OBJDUMP = $(TRGT)objdump
|
||||
|
||||
#MCU = arm7tdmi
|
||||
MCU = cortex-a9
|
||||
|
||||
# List all default C defines here, like -D_DEBUG=1
|
||||
DDEFS =
|
||||
|
||||
# List all default ASM defines here, like -D_DEBUG=1
|
||||
DADEFS =
|
||||
|
||||
# List all default directories to look for include files here
|
||||
DINCDIR =
|
||||
|
||||
# List the default directory to look for the libraries here
|
||||
DLIBDIR =
|
||||
|
||||
# List all default libraries here
|
||||
DLIBS =
|
||||
|
||||
#
|
||||
# End of default section
|
||||
##############################################################################################
|
||||
|
||||
##############################################################################################
|
||||
# Start of user section
|
||||
#
|
||||
|
||||
# Define project name here
|
||||
PROJECT = os_wrapper
|
||||
|
||||
# Define linker script file here
|
||||
LDSCRIPT = any_rtos.ld
|
||||
|
||||
# List all user C define here, like -D_DEBUG=1
|
||||
UDEFS =
|
||||
|
||||
# Define ASM defines here
|
||||
UADEFS =
|
||||
|
||||
# List C source files here
|
||||
SRC = lwmem.c
|
||||
|
||||
# List ASM source files here
|
||||
ASRC = wrapper_bx.s
|
||||
|
||||
# List all user directories here
|
||||
UINCDIR =
|
||||
|
||||
# List the user directory to look for the libraries here
|
||||
ULIBDIR =
|
||||
|
||||
# List all user libraries here
|
||||
ULIBS =
|
||||
|
||||
# Define optimisation level here
|
||||
OPT = -O2
|
||||
|
||||
#
|
||||
# End of user defines
|
||||
##############################################################################################
|
||||
|
||||
|
||||
INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
|
||||
LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
|
||||
DEFS = $(DDEFS) $(UDEFS)
|
||||
ADEFS = $(DADEFS) $(UADEFS)
|
||||
OBJS = $(ASRC:.s=.o) $(SRC:.c=.o)
|
||||
LIBS = $(DLIBS) $(ULIBS)
|
||||
MCFLAGS = -mcpu=$(MCU)
|
||||
|
||||
ASFLAGS = $(MCFLAGS) -g -gdwarf-2 -Wa,-amhls=$(<:.s=.lst) $(ADEFS) -c
|
||||
CPFLAGS = $(MCFLAGS) $(OPT) -gdwarf-2 -mthumb-interwork -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS) -c
|
||||
LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch -nostdlib $(LIBDIR)
|
||||
|
||||
# Generate dependency information
|
||||
#CPFLAGS += -MD -MP -MF .dep/$(@F).d
|
||||
|
||||
#
|
||||
# makefile rules
|
||||
#
|
||||
|
||||
all: $(OBJS) $(PROJECT).elf $(PROJECT).hex $(PROJECT).bin $(PROJECT).lst
|
||||
|
||||
%o : %c
|
||||
$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@
|
||||
|
||||
%o : %s
|
||||
$(AS) -c $(ASFLAGS) $< -o $@
|
||||
|
||||
%elf: $(OBJS)
|
||||
$(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
|
||||
|
||||
%hex: %elf
|
||||
$(HEX) $< $@
|
||||
|
||||
%bin: %elf
|
||||
$(BIN) $< $@
|
||||
|
||||
%.lst: %.elf
|
||||
$(OBJDUMP) -h -S $< > $@
|
||||
|
||||
clean:
|
||||
-rm -f $(OBJS)
|
||||
-rm -f $(PROJECT).elf
|
||||
-rm -f $(PROJECT).map
|
||||
-rm -f $(PROJECT).hex
|
||||
-rm -f $(PROJECT).bin
|
||||
-rm -f $(PROJECT).lst
|
||||
-rm -f $(SRC:.c=.c.bak)
|
||||
-rm -f $(SRC:.c=.lst)
|
||||
-rm -f $(ASRC:.s=.s.bak)
|
||||
-rm -f $(ASRC:.s=.lst)
|
||||
-rm -fR .dep
|
||||
|
||||
#
|
||||
# Include the dependency files, should be the last of the makefile
|
||||
#
|
||||
#-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
||||
|
||||
# *** EOF ***
|
||||
131
makefile_big
Normal file
131
makefile_big
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
##############################################################################################
|
||||
# Start of default section
|
||||
#
|
||||
|
||||
TRGT = arm-none-eabi-
|
||||
CC = $(TRGT)gcc -fPIC -fPIE -mbig-endian -mbe32
|
||||
CP = $(TRGT)objcopy
|
||||
AS = $(TRGT)gcc -x assembler-with-cpp
|
||||
HEX = $(CP) -O ihex
|
||||
BIN = $(CP) -O binary
|
||||
OBJDUMP = $(TRGT)objdump
|
||||
|
||||
#MCU = arm7tdmi
|
||||
MCU = cortex-a9
|
||||
|
||||
# List all default C defines here, like -D_DEBUG=1
|
||||
DDEFS =
|
||||
|
||||
# List all default ASM defines here, like -D_DEBUG=1
|
||||
DADEFS =
|
||||
|
||||
# List all default directories to look for include files here
|
||||
DINCDIR =
|
||||
|
||||
# List the default directory to look for the libraries here
|
||||
DLIBDIR =
|
||||
|
||||
# List all default libraries here
|
||||
DLIBS =
|
||||
|
||||
#
|
||||
# End of default section
|
||||
##############################################################################################
|
||||
|
||||
##############################################################################################
|
||||
# Start of user section
|
||||
#
|
||||
|
||||
# Define project name here
|
||||
PROJECT = os_wrapper_be
|
||||
|
||||
# Define linker script file here
|
||||
LDSCRIPT = any_rtos.ld
|
||||
|
||||
# List all user C define here, like -D_DEBUG=1
|
||||
UDEFS =
|
||||
|
||||
# Define ASM defines here
|
||||
UADEFS =
|
||||
|
||||
# List C source files here
|
||||
SRC = lwmem.c
|
||||
|
||||
# List ASM source files here
|
||||
ASRC = wrapper_bx.s
|
||||
|
||||
# List all user directories here
|
||||
UINCDIR =
|
||||
|
||||
# List the user directory to look for the libraries here
|
||||
ULIBDIR =
|
||||
|
||||
# List all user libraries here
|
||||
ULIBS =
|
||||
|
||||
# Define optimisation level here
|
||||
OPT = -O2
|
||||
|
||||
#
|
||||
# End of user defines
|
||||
##############################################################################################
|
||||
|
||||
|
||||
INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
|
||||
LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
|
||||
DEFS = $(DDEFS) $(UDEFS)
|
||||
ADEFS = $(DADEFS) $(UADEFS)
|
||||
OBJS = $(ASRC:.s=.o) $(SRC:.c=.o)
|
||||
LIBS = $(DLIBS) $(ULIBS)
|
||||
MCFLAGS = -mcpu=$(MCU) -mbig-endian -mbe32
|
||||
|
||||
ASFLAGS = $(MCFLAGS) -g -gdwarf-2 -Wa,-amhls=$(<:.s=.lst) $(ADEFS) -c
|
||||
CPFLAGS = $(MCFLAGS) $(OPT) -gdwarf-2 -mthumb-interwork -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS) -c
|
||||
LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch -nostdlib $(LIBDIR)
|
||||
|
||||
# Generate dependency information
|
||||
#CPFLAGS += -MD -MP -MF .dep/$(@F).d
|
||||
|
||||
#
|
||||
# makefile rules
|
||||
#
|
||||
|
||||
all: $(OBJS) $(PROJECT).elf $(PROJECT).hex $(PROJECT).bin $(PROJECT).lst
|
||||
|
||||
%o : %c
|
||||
$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@
|
||||
|
||||
%o : %s
|
||||
$(AS) -c $(ASFLAGS) $< -o $@
|
||||
|
||||
%elf: $(OBJS)
|
||||
$(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
|
||||
|
||||
%hex: %elf
|
||||
$(HEX) $< $@
|
||||
|
||||
%bin: %elf
|
||||
$(BIN) $< $@
|
||||
|
||||
%.lst: %.elf
|
||||
$(OBJDUMP) -h -S $< > $@
|
||||
|
||||
clean:
|
||||
-rm -f $(OBJS)
|
||||
-rm -f $(PROJECT).elf
|
||||
-rm -f $(PROJECT).map
|
||||
-rm -f $(PROJECT).hex
|
||||
-rm -f $(PROJECT).bin
|
||||
-rm -f $(PROJECT).lst
|
||||
-rm -f $(SRC:.c=.c.bak)
|
||||
-rm -f $(SRC:.c=.lst)
|
||||
-rm -f $(ASRC:.s=.s.bak)
|
||||
-rm -f $(ASRC:.s=.lst)
|
||||
-rm -fR .dep
|
||||
|
||||
#
|
||||
# Include the dependency files, should be the last of the makefile
|
||||
#
|
||||
#-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
||||
|
||||
# *** EOF ***
|
||||
119
wrapper_bx.s
Normal file
119
wrapper_bx.s
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
p_assign_mem:
|
||||
b mem_init /* Startup - 00 */
|
||||
p_malloc:
|
||||
b lwmem_malloc /* Malloc - 04 */
|
||||
p_memcpy:
|
||||
b memcpy /* Memcpy - 08 */
|
||||
p_free:
|
||||
b lwmem_free /* Free - 0c */
|
||||
p_memset:
|
||||
b memset /* Memset - 10 */
|
||||
p_calloc:
|
||||
b lwmem_calloc /* Calloc - 14 */
|
||||
p_realloc:
|
||||
b lwmem_realloc /* Realloc - 18 */
|
||||
p_memmove:
|
||||
b memmove /* Memmove - 1c */
|
||||
p_exit:
|
||||
b p_exit /* Exit - 20 */
|
||||
|
||||
.thumb_func
|
||||
malloc_thumb:
|
||||
push {R4-R7, LR} /* save registers */
|
||||
blx p_malloc
|
||||
pop {R4-R7, PC} /* restore registers and return */
|
||||
memcpy_thumb:
|
||||
push {R4-R7, LR} /* save registers */
|
||||
blx p_memcpy
|
||||
pop {R4-R7, PC} /* restore registers and return */
|
||||
free_thumb:
|
||||
push {R4-R7, LR} /* save registers */
|
||||
blx p_free
|
||||
pop {R4-R7, PC} /* restore registers and return */
|
||||
mmemset_thumb:
|
||||
push {R4-R7, LR} /* save registers */
|
||||
blx p_memset
|
||||
pop {R4-R7, PC} /* restore registers and return */
|
||||
calloc_thumb:
|
||||
push {R4-R7, LR} /* save registers */
|
||||
blx p_calloc
|
||||
pop {R4-R7, PC} /* restore registers and return */
|
||||
realloc_thumb:
|
||||
push {R4-R7, LR} /* save registers */
|
||||
blx p_realloc
|
||||
pop {R4-R7, PC} /* restore registers and return */
|
||||
exit_thumb:
|
||||
push {R4-R7, LR} /* save registers */
|
||||
blx p_exit
|
||||
pop {R4-R7, PC} /* restore registers and return */
|
||||
.arm
|
||||
|
||||
mem_init:
|
||||
mov r0, #0
|
||||
adr r0, mem_init_regs
|
||||
/* ldr r0, [r0] */
|
||||
b lwmem_assignmem
|
||||
|
||||
mem_init_regs:
|
||||
.word 0xa0000000
|
||||
.word 0x00800000
|
||||
.word 0x00000000
|
||||
.word 0x00000000
|
||||
|
||||
.ascii "Memstub (c) 2025 Wrapper"
|
||||
.global null_function
|
||||
null_function:
|
||||
mov pc, lr
|
||||
.global memcpy
|
||||
memcpy:
|
||||
mov r12, r0
|
||||
memcpy_loop:
|
||||
subs r2, r2, #1
|
||||
bmi memcpy_end
|
||||
ldrb r3, [r1], #1
|
||||
strb r3, [r0], #1
|
||||
b memcpy_loop
|
||||
memcpy_end:
|
||||
mov r0, r12
|
||||
bx lr
|
||||
|
||||
.global memset
|
||||
memset:
|
||||
mov r12, r0
|
||||
memset_loop:
|
||||
subs r2, r2, #1
|
||||
bmi memset_end
|
||||
strb r1, [r0], #1
|
||||
b memset_loop
|
||||
memset_end:
|
||||
mov r0, r12
|
||||
bx lr
|
||||
|
||||
.global memmove
|
||||
memmove:
|
||||
mov r12, r0
|
||||
cmp r0, r1
|
||||
ble .fw
|
||||
add r3, r1, r2
|
||||
cmp r0, r3
|
||||
bgt .fw
|
||||
|
||||
@ copying the memory in reverse order
|
||||
add r0, r0, r2
|
||||
add r1, r1, r2
|
||||
.bw:
|
||||
subs r2, r2, #1
|
||||
bmi .ret
|
||||
ldrb r3, [r1, #-1]!
|
||||
strb r3, [r0, #-1]!
|
||||
b .bw
|
||||
.fw:
|
||||
subs r2, r2, #1
|
||||
bmi .ret
|
||||
ldrb r3, [r1], #1
|
||||
strb r3, [r0], #1
|
||||
b .fw
|
||||
.ret:
|
||||
mov r0, r12
|
||||
bx lr
|
||||
.ascii "ASM ENDS HERE."
|
||||
Loading…
Add table
Add a link
Reference in a new issue