diff options
-rw-r--r-- | include/lib/mem.h | 7 | ||||
-rw-r--r-- | src/lib/mem.c | 13 |
2 files changed, 20 insertions, 0 deletions
diff --git a/include/lib/mem.h b/include/lib/mem.h index eff6445..04056f7 100644 --- a/include/lib/mem.h +++ b/include/lib/mem.h @@ -12,9 +12,16 @@ struct MemTab { void* data; } __attribute__((packed)); +struct RotBuffer { + void* base; + unsigned int size; + unsigned int offset; +}; + void memset(unsigned char* dest, unsigned char value, unsigned int n); void memcpy(unsigned char* src, unsigned char* dest, unsigned int n); unsigned char memcmp(unsigned char* a, unsigned char* b, unsigned int n); +void memcpyrot(unsigned char* src, struct RotBuffer* rb, unsigned int n); void memshow32(unsigned long* addr, unsigned int n); void memset32(unsigned long* dest, unsigned long value, unsigned int n); diff --git a/src/lib/mem.c b/src/lib/mem.c index 91fed94..dc915e6 100644 --- a/src/lib/mem.c +++ b/src/lib/mem.c @@ -1,6 +1,19 @@ #include <drivers/uart.h> #include <lib/mem.h> +void memcpyrot(unsigned char* src, struct RotBuffer* rb, unsigned int n) +{ + if (n > rb->size) + return; + unsigned char* addr = rb->base + rb->offset; + for (unsigned int i = 0; i < n; i++) { + if (addr >= (unsigned char*)(rb->base + rb->size)) + addr = rb->base; + *addr = src[i]; + addr++; + } +} + void memshow32(unsigned long* addr, unsigned int n) { for(unsigned int i = 0; i < n; i++) { |