mirror of https://github.com/Nonannet/copapy.git
memory compile flags for runner for bare metal updated
This commit is contained in:
parent
534f0ac793
commit
af92a4303b
|
|
@ -9,37 +9,51 @@
|
|||
#include <stdint.h>
|
||||
|
||||
|
||||
#if defined DATA_MEMORY_ADDR || defined EXECUTABLE_MEMORY_ADDR
|
||||
#if defined DATA_MEMORY_LEN || defined EXECUTABLE_MEMORY_LEN
|
||||
/* Bare metal implementations */
|
||||
#if not defined(EXECUTABLE_MEMORY_ADDR) || not defined(DATA_MEMORY_ADDR)
|
||||
#error "For bare metal, you must define DATA_MEMORY_ADDR and DATA_EXECUTABLE_MEMORY_ADDR."
|
||||
#if !defined(EXECUTABLE_MEMORY_LEN) || !defined(DATA_MEMORY_LEN)
|
||||
#error "For bare metal, you must define DATA_MEMORY_LEN and DATA_EXECUTABLE_MEMORY_LEN."
|
||||
#endif
|
||||
|
||||
uint8_t *allocate_executable_memory(uint32_t num_bytes) {
|
||||
return (uint8_t*)EXECUTABLE_MEMORY_ADDR;
|
||||
__attribute__((section(".mem_exec_itcm"), used))
|
||||
volatile uint8_t executable_memory_pool[EXECUTABLE_MEMORY_LEN];
|
||||
|
||||
__attribute__((section(".mem_data_itcm"), used))
|
||||
volatile uint8_t data_memory_pool[DATA_MEMORY_LEN];
|
||||
|
||||
volatile uint8_t *allocate_executable_memory(uint32_t num_bytes) {
|
||||
if (num_bytes > EXECUTABLE_MEMORY_LEN) return 0;
|
||||
return executable_memory_pool;
|
||||
}
|
||||
|
||||
uint8_t *allocate_data_memory(uint32_t num_bytes) {
|
||||
return (uint8_t*)DATA_MEMORY_ADDR;
|
||||
volatile uint8_t *allocate_data_memory(uint32_t num_bytes) {
|
||||
if (num_bytes > DATA_MEMORY_LEN) return 0;
|
||||
return data_memory_pool;
|
||||
}
|
||||
|
||||
int mark_mem_executable(uint8_t *memory, uint32_t memory_len) {
|
||||
/* No-op for bare metal */
|
||||
(void)memory; // Mark as used
|
||||
(void)memory_len; // Mark as used
|
||||
return 1;
|
||||
}
|
||||
|
||||
void deallocate_memory(uint8_t *memory, uint32_t memory_len) {
|
||||
(void)memory; // Mark as used
|
||||
(void)memory_len; // Mark as used
|
||||
/* No-op for bare metal */
|
||||
}
|
||||
|
||||
void memcpy(void *dest, const void *src, size_t n) {
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
|
||||
void memcpy(void *dest, const void *src, unsigned int n) {
|
||||
uint8_t *d = (uint8_t*)dest;
|
||||
const uint8_t *s = (const uint8_t*)src;
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
for (unsigned int i = 0; i < n; i++) {
|
||||
d[i] = s[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
|
||||
#elif defined _WIN32
|
||||
|
|
|
|||
|
|
@ -7,8 +7,11 @@ uint8_t *allocate_buffer_memory(uint32_t num_bytes);
|
|||
int mark_mem_executable(uint8_t *memory, uint32_t memory_len);
|
||||
void deallocate_memory(uint8_t *memory, uint32_t memory_len);
|
||||
|
||||
#ifdef DATA_MEMORY_ADDR
|
||||
void memcpy(void *dest, const void *src, size_t n);
|
||||
#ifdef DATA_MEMORY_LEN
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
|
||||
void memcpy(void *dest, const void *src, unsigned int n);
|
||||
#pragma GCC diagnostic pop
|
||||
#else
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,6 +8,21 @@
|
|||
#include "runmem.h"
|
||||
#include "mem_man.h"
|
||||
|
||||
void runmem_init(runmem_t *context)
|
||||
{
|
||||
context->data_memory = NULL;
|
||||
context->data_memory_len = 0;
|
||||
context->executable_memory = NULL;
|
||||
context->executable_memory_len = 0;
|
||||
context->data_offs = 0;
|
||||
context->entr_point = NULL;
|
||||
context->rx_state = RX_STATE_IDLE;
|
||||
context->state_flag = STATE_FLAG_NONE;
|
||||
context->data_src = NULL;
|
||||
context->data_dest = NULL;
|
||||
context->data_size = 0;
|
||||
}
|
||||
|
||||
void patch(uint8_t *patch_addr, uint32_t patch_mask, int32_t value) {
|
||||
uint32_t *val_ptr = (uint32_t*)patch_addr;
|
||||
uint32_t original = *val_ptr;
|
||||
|
|
@ -119,9 +134,9 @@ void free_memory(runmem_t *context) {
|
|||
deallocate_memory(context->data_memory, context->data_memory_len);
|
||||
context->executable_memory_len = 0;
|
||||
context->data_memory_len = 0;
|
||||
context->executable_memory = NULL;
|
||||
context->data_memory = NULL;
|
||||
context->entr_point = NULL;
|
||||
context->executable_memory = 0;
|
||||
context->data_memory = 0;
|
||||
context->entr_point = 0;
|
||||
context->data_offs = 0;
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +144,6 @@ int update_data_offs(runmem_t *context) {
|
|||
if (context->data_memory && context->executable_memory &&
|
||||
(context->data_memory - context->executable_memory > 0x7FFFFFFF ||
|
||||
context->executable_memory - context->data_memory > 0x7FFFFFFF)) {
|
||||
perror("Error: code and data memory to far apart");
|
||||
return 0;
|
||||
}
|
||||
context->data_offs = (int)(context->data_memory - context->executable_memory);
|
||||
|
|
|
|||
|
|
@ -9,8 +9,9 @@
|
|||
#define RUNMEM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef DATA_MEMORY_ADDR
|
||||
#ifdef DATA_MEMORY_LEN
|
||||
#define PRINTF(...)
|
||||
#else
|
||||
#include <stdio.h>
|
||||
|
|
@ -82,6 +83,9 @@ typedef struct runmem_s {
|
|||
an error flag (0 on success according to current code) */
|
||||
int parse_commands(runmem_t *context, uint8_t *bytes, uint32_t lengths);
|
||||
|
||||
/* Initialize runmem context to default/empty state */
|
||||
void runmem_init(runmem_t *context);
|
||||
|
||||
/* Free program and data memory */
|
||||
void free_memory(runmem_t *context);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue