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
46085a34a4
|
|
@ -9,37 +9,48 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
#if defined DATA_MEMORY_ADDR || defined EXECUTABLE_MEMORY_ADDR
|
#if defined DATA_MEMORY_LEN || defined EXECUTABLE_MEMORY_LEN
|
||||||
/* Bare metal implementations */
|
/* Bare metal implementations */
|
||||||
#if not defined(EXECUTABLE_MEMORY_ADDR) || not defined(DATA_MEMORY_ADDR)
|
#if !defined(EXECUTABLE_MEMORY_LEN) || !defined(DATA_MEMORY_LEN)
|
||||||
#error "For bare metal, you must define DATA_MEMORY_ADDR and DATA_EXECUTABLE_MEMORY_ADDR."
|
#error "For bare metal, you must define DATA_MEMORY_LEN and DATA_EXECUTABLE_MEMORY_LEN."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uint8_t executable_memory_pool[EXECUTABLE_MEMORY_LEN];
|
||||||
|
uint8_t data_memory_pool[DATA_MEMORY_LEN];
|
||||||
|
|
||||||
uint8_t *allocate_executable_memory(uint32_t num_bytes) {
|
uint8_t *allocate_executable_memory(uint32_t num_bytes) {
|
||||||
return (uint8_t*)EXECUTABLE_MEMORY_ADDR;
|
if (num_bytes > EXECUTABLE_MEMORY_LEN) return 0;
|
||||||
|
return executable_memory_pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *allocate_data_memory(uint32_t num_bytes) {
|
uint8_t *allocate_data_memory(uint32_t num_bytes) {
|
||||||
return (uint8_t*)DATA_MEMORY_ADDR;
|
if (num_bytes > DATA_MEMORY_LEN) return 0;
|
||||||
|
return data_memory_pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mark_mem_executable(uint8_t *memory, uint32_t memory_len) {
|
int mark_mem_executable(uint8_t *memory, uint32_t memory_len) {
|
||||||
/* No-op for bare metal */
|
/* No-op for bare metal */
|
||||||
|
(void)memory; // Mark as used
|
||||||
|
(void)memory_len; // Mark as used
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deallocate_memory(uint8_t *memory, uint32_t memory_len) {
|
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 */
|
/* 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;
|
uint8_t *d = (uint8_t*)dest;
|
||||||
const uint8_t *s = (const uint8_t*)src;
|
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];
|
d[i] = s[i];
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
|
||||||
#elif defined _WIN32
|
#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);
|
int mark_mem_executable(uint8_t *memory, uint32_t memory_len);
|
||||||
void deallocate_memory(uint8_t *memory, uint32_t memory_len);
|
void deallocate_memory(uint8_t *memory, uint32_t memory_len);
|
||||||
|
|
||||||
#ifdef DATA_MEMORY_ADDR
|
#ifdef DATA_MEMORY_LEN
|
||||||
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);
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
#else
|
#else
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -119,9 +119,9 @@ void free_memory(runmem_t *context) {
|
||||||
deallocate_memory(context->data_memory, context->data_memory_len);
|
deallocate_memory(context->data_memory, context->data_memory_len);
|
||||||
context->executable_memory_len = 0;
|
context->executable_memory_len = 0;
|
||||||
context->data_memory_len = 0;
|
context->data_memory_len = 0;
|
||||||
context->executable_memory = NULL;
|
context->executable_memory = 0;
|
||||||
context->data_memory = NULL;
|
context->data_memory = 0;
|
||||||
context->entr_point = NULL;
|
context->entr_point = 0;
|
||||||
context->data_offs = 0;
|
context->data_offs = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,7 +129,6 @@ int update_data_offs(runmem_t *context) {
|
||||||
if (context->data_memory && context->executable_memory &&
|
if (context->data_memory && context->executable_memory &&
|
||||||
(context->data_memory - context->executable_memory > 0x7FFFFFFF ||
|
(context->data_memory - context->executable_memory > 0x7FFFFFFF ||
|
||||||
context->executable_memory - context->data_memory > 0x7FFFFFFF)) {
|
context->executable_memory - context->data_memory > 0x7FFFFFFF)) {
|
||||||
perror("Error: code and data memory to far apart");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
context->data_offs = (int)(context->data_memory - context->executable_memory);
|
context->data_offs = (int)(context->data_memory - context->executable_memory);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef DATA_MEMORY_ADDR
|
#ifdef DATA_MEMORY_LEN
|
||||||
#define PRINTF(...)
|
#define PRINTF(...)
|
||||||
#else
|
#else
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue