diff options
author | Christian Cunningham <cc@localhost> | 2022-02-04 23:55:05 -0700 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-02-04 23:55:05 -0700 |
commit | e3eb5a92ae3991cdfbb5a5cf553eac476bc5822f (patch) | |
tree | b6f8b98b8e9b970dc08c218c07b1351b0eaf2944 | |
parent | 1b14e08247393af5f4e8f2a3c31406ce750ca2f0 (diff) |
Removed old mem
-rw-r--r-- | include/globals.h | 3 | ||||
-rw-r--r-- | include/lib/ll.h | 26 | ||||
-rw-r--r-- | include/lib/mem.h | 48 | ||||
-rw-r--r-- | include/lib/q.h | 31 | ||||
-rw-r--r-- | src/cpu/irq.c | 2 | ||||
-rw-r--r-- | src/globals.c | 3 | ||||
-rw-r--r-- | src/lib/ll.c | 57 | ||||
-rw-r--r-- | src/lib/mem.c | 340 | ||||
-rw-r--r-- | src/lib/q.c | 54 | ||||
-rw-r--r-- | src/sys/core.c | 2 | ||||
-rw-r--r-- | src/sys/schedule.c | 5 | ||||
-rw-r--r-- | src/util/status.c | 4 |
12 files changed, 2 insertions, 573 deletions
diff --git a/include/globals.h b/include/globals.h index 423425f..ff67315 100644 --- a/include/globals.h +++ b/include/globals.h @@ -1,6 +1,5 @@ #ifndef GLOBALS_H #define GLOBALS_H -#include <lib/mem.h> #include <sys/schedule.h> #ifndef GLOBALS_C @@ -13,8 +12,6 @@ unsigned char kmem_begin[0x2000000]; unsigned char kmem_lookup[0xD000]; extern unsigned long exe_cnt; extern struct Mutex exe_cnt_m; -extern unsigned char rpi_heap[MAX_MM]; -extern void* rpi_heap_top; extern unsigned long nextpid; extern unsigned long stimel; extern unsigned long stimeh; diff --git a/include/lib/ll.h b/include/lib/ll.h deleted file mode 100644 index a9c3722..0000000 --- a/include/lib/ll.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef LIB_LL_H -#define LIB_LL_H - -struct LL { - struct LL* prev; - struct LL* next; - void* data; -} __attribute__((packed)); - -struct LL* new_ll(void* val); -void push_ll(struct LL* l, void* val); -void pop_ll(struct LL* l); -void remove_ll(struct LL* l, unsigned long idx); -unsigned long length_ll(struct LL* l); - -#define show_ll(L, TYPE) { \ - struct LL* t = L; \ - do { \ - uart_hex(*(TYPE*)t->data); \ - t = t->next; \ - if (t != l) \ - uart_char(' '); \ - } while (t != l); \ -} - -#endif diff --git a/include/lib/mem.h b/include/lib/mem.h deleted file mode 100644 index 655e648..0000000 --- a/include/lib/mem.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef LIB_MEM_H -#define LIB_MEM_H - -#define MEM_SIZE_OFFSET 0 -#define MEM_USE_OFFSET 1 -#define MEM_BASE_SIZE 2 -#define MEM_META_SIZE 3 -#define NULL 0 -#define MAX_MM 0x100000 - -struct MemTab { - unsigned char size; - unsigned char in_use; - void* data; -} __attribute__((packed)); - -struct RotBuffer { - void* base; - unsigned int size; - unsigned int roffset; - unsigned int woffset; -}; - -void memshow(unsigned char* addr, unsigned int n); -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); -void memcpy32(unsigned long* src, unsigned long* dest, unsigned int n); -unsigned char memcmp32(unsigned long* a, unsigned long* b, unsigned int n); - -void* realloc(void* old, unsigned char size); -void* malloc(unsigned char size); -void* calloc(unsigned char size); -void* realloca(void* old, unsigned char size, unsigned char amnt); -void* malloca(unsigned char size, unsigned char amnt); -void* calloca(unsigned char size, unsigned char amnt); -void free(void* memloc); -void* heap_base(void); -void* heap_top(void); -void vheap_info(void); -void heap_info(void); -void heap_info_u(void); - -#endif diff --git a/include/lib/q.h b/include/lib/q.h deleted file mode 100644 index 11d7ab7..0000000 --- a/include/lib/q.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef LIB_Q_H -#define LIB_Q_H - -struct Q_base { - struct Q* next; - struct Q* last; -} __attribute__((packed)); - -struct Q { - struct Q* next; - void* data; -} __attribute__((packed)); - -struct Q_base* new_q(); -void push_q(struct Q_base* qb, void* val); -void pop_q(struct Q_base* qb); -unsigned long length_q(struct Q_base* qb); - -#define show_q(QQ, TYPE) { \ - if (QQ->next != 0) { \ - struct Q* t = QQ->next; \ - while (t->next != 0) { \ - uart_hex(*(TYPE*)t->data); \ - t = t->next; \ - uart_char(' '); \ - } \ - uart_hex(*(TYPE*)t->data); \ - } \ -} - -#endif diff --git a/src/cpu/irq.c b/src/cpu/irq.c index 6be4bc7..9685b0a 100644 --- a/src/cpu/irq.c +++ b/src/cpu/irq.c @@ -101,7 +101,5 @@ void handle_data(unsigned char data) release_mutex(&exe_cnt_m, SYS_PID); } else if (data == 0x61) { add_thread(uart_scheduler, 0, 2); - } else if (data == 0x62) { - add_thread(heap_info, 0, 2); } } diff --git a/src/globals.c b/src/globals.c index 5d3369d..8334a60 100644 --- a/src/globals.c +++ b/src/globals.c @@ -1,5 +1,4 @@ #define GLOBALS_C -//#include <lib/mem.h> #include <lib/kmem.h> #include <util/mutex.h> #include <graphics/drawer.h> @@ -25,6 +24,4 @@ __attribute__((section(".bss"))) unsigned int gwidth; __attribute__((section(".bss"))) unsigned int gheight; __attribute__((section(".bss"))) unsigned int gpitch; __attribute__((section(".bss"))) unsigned int gisrgb; -__attribute__((section(".bss.mmheap"))) unsigned char rpi_heap[MAX_MM]; -__attribute__((section(".bss.mmheap.base"))) void* rpi_heap_top; __attribute__((section(".bss"))) unsigned char stacks_table[MAX_THREADS]; diff --git a/src/lib/ll.c b/src/lib/ll.c deleted file mode 100644 index 4918194..0000000 --- a/src/lib/ll.c +++ /dev/null @@ -1,57 +0,0 @@ -#include <lib/ll.h> -#include <lib/mem.h> - -struct LL* new_ll(void* val) -{ - struct LL* ll = (struct LL*)malloc(sizeof(struct LL)); - ll->prev = ll; - ll->next = ll; - ll->data = val; - return ll; -} - -void push_ll(struct LL* l, void* val) -{ - struct LL* ll = (struct LL*)malloc(sizeof(struct LL)); - l->prev->next = ll; - ll->prev = l->prev; - ll->next = l; - l->prev = ll; - ll->data = val; -} - -void pop_ll(struct LL* l) -{ - if ((l->prev == l->next) && (l->prev == l)) - l->data = 0; - else { - l->prev->next = l->next; - l->next->prev = l->prev; - free(l); - } -} - -void remove_ll(struct LL* l, unsigned long idx) -{ - struct LL* t = l; - for(unsigned long i = 0; i < idx; i++) { - t = t->next; - } - t->prev->next = t->next; - t->next->prev = t->prev; - free(t); -} - -unsigned long length_ll(struct LL* l) -{ - struct LL* t = l; - unsigned long len = 0; - while (1) { - if (t->next == l) { - return len; - } - len++; - t = t->next; - } - return len; -} diff --git a/src/lib/mem.c b/src/lib/mem.c deleted file mode 100644 index 2f50d3d..0000000 --- a/src/lib/mem.c +++ /dev/null @@ -1,340 +0,0 @@ -#include <drivers/uart.h> -#include <globals.h> -#include <graphics/lfb.h> -#include <lib/mem.h> -#include <sys/schedule.h> - -void memcpyrot(unsigned char* src, struct RotBuffer* rb, unsigned int n) -{ - if (n > rb->size) - return; - unsigned char* base = rb->base; - unsigned int offset = rb->woffset; - for (unsigned int i = 0; i < n; i++) { - if (offset >= rb->size) - offset = 0; - base[offset] = src[i]; - offset++; - } - rb->woffset = offset; -} - -void memshow(unsigned char* addr, unsigned int n) -{ - unsigned char temp; - for(unsigned int i = 0; i < n; i++) { - temp = addr[i] >> 4; - temp += 0x30; - if (temp > 0x39) - temp += 7; - uart_char(temp); - temp = addr[i]; - temp += 0x30; - if (temp > 0x39) - temp += 7; - uart_char(temp); - if (i+1 != n) - uart_char(0x20); - } - uart_char(0x0a); -} - -void memshow32(unsigned long* addr, unsigned int n) -{ - for(unsigned int i = 0; i < n; i++) { - uart_hex(addr[i]); - if (i+1 != n) - uart_char(0x20); - } - uart_char(0x0a); -} - -void memset(unsigned char* dest, unsigned char value, unsigned int n) -{ - for(unsigned int i = 0; i < n; i++) { - dest[i] = value; - } -} - -void memcpy(unsigned char* src, unsigned char* dest, unsigned int n) -{ - for(unsigned int i = 0; i < n; i++) { - dest[i] = src[i]; - } -} - -unsigned char memcmp(unsigned char* a, unsigned char* b, unsigned int n) -{ - for(unsigned int i = 0; i < n; i++) { - if (a[i] != b[i]) - return 0; - } - return 1; -} - -void memset32(unsigned long* dest, unsigned long value, unsigned int n) -{ - for(unsigned int i = 0; i < n; i++) { - dest[i] = value; - } -} - -void memcpy32(unsigned long* src, unsigned long* dest, unsigned int n) -{ - for(unsigned int i = 0; i < n; i++) { - dest[i] = src[i]; - } -} - -unsigned char memcmp32(unsigned long* a, unsigned long* b, unsigned int n) -{ - for(unsigned int i = 0; i < n; i++) { - if (a[i] != b[i]) - return 0; - } - return 1; -} - - -void* malloc(unsigned char size) -{ - unsigned char* mem = (unsigned char*)rpi_heap; - unsigned long i = 0; - // TODO: Use Null PID - while (((void*)(mem + i) < rpi_heap_top) && !(mem[i + MEM_SIZE_OFFSET] == size && mem[i + MEM_USE_OFFSET]==0)) { - i += mem[i] + MEM_META_SIZE; - } - if (mem + i >= (unsigned char*)(rpi_heap_top + MAX_MM)) - return NULL; - // Update top of heap - if (mem[i] == 0) - rpi_heap_top = (void*)&mem[i + MEM_META_SIZE + size]; - mem[i] = size; - mem[i + MEM_BASE_SIZE + size] = size; - // Use allocator's PID - mem[i + MEM_USE_OFFSET] = 1; - return (void*)&mem[i + MEM_BASE_SIZE]; -} - -void* calloc(unsigned char size) -{ - void* addr = malloc(size); - if (addr != NULL) { - memset(addr, 0, size); - return addr; - } - return NULL; -} -void* realloc(void* old, unsigned char size) -{ - unsigned char osize = *(unsigned char*)(old - MEM_BASE_SIZE); - if (size <= osize) - return old; - void* new = malloc(size); - if (new != NULL) { - free(old); - return new; - } - return NULL; -} - -void* malloca(unsigned char size, unsigned char amnt) -{ - // Return malloc if alignment size is 0 or 1 - trivial alignment - if(amnt == 0 || amnt == 1) - return malloc(size); - unsigned char* mem = (unsigned char*)rpi_heap; - unsigned long i = 0; - // TODO: Use Null PID - while(mem + i < rpi_heap + MAX_MM) { - unsigned long diff = (unsigned long)mem + i + MEM_BASE_SIZE; - diff %= amnt; - diff = amnt - diff; - diff %= amnt; - if((mem[i + MEM_SIZE_OFFSET] == size) && mem[i + MEM_USE_OFFSET]==0) { - if(diff == 0) { - mem[i + MEM_SIZE_OFFSET] = size; - mem[i + MEM_BASE_SIZE + size] = size; - mem[i + MEM_USE_OFFSET] = 1; - return (void*)&mem[i + MEM_BASE_SIZE]; - } - } else if (mem[i] == 0) { - if(diff == 0) { - mem[i + MEM_SIZE_OFFSET] = size; - mem[i + MEM_BASE_SIZE + size] = size; - mem[i + MEM_USE_OFFSET] = 1; - rpi_heap_top = (void*)&mem[i + MEM_META_SIZE + size]; - return (void*)&mem[i + MEM_BASE_SIZE]; - } else { - while (diff <= MEM_BASE_SIZE) { - diff += amnt; - } - unsigned long empty_size = diff - MEM_META_SIZE; - if(empty_size == 0) { - empty_size += amnt; - diff += amnt; - } - mem[i + MEM_SIZE_OFFSET] = empty_size; - mem[i + MEM_BASE_SIZE + empty_size] = empty_size; - i += diff; - mem[i + MEM_SIZE_OFFSET] = size; - mem[i + MEM_BASE_SIZE + size] = size; - mem[i + MEM_USE_OFFSET] = 1; - rpi_heap_top = (void*)&mem[i + MEM_META_SIZE + size]; - return (void*)&mem[i + MEM_BASE_SIZE]; - } - } - - i += mem[i] + MEM_META_SIZE; - } - return NULL; -} - -void* calloca(unsigned char size, unsigned char amnt) -{ - void* addr = malloca(size, amnt); - if (addr != NULL) { - memset(addr, 0, size); - return addr; - } - return NULL; -} - -void* realloca(void* old, unsigned char size, unsigned char amnt) -{ - unsigned char osize = *(unsigned char*)(old - MEM_BASE_SIZE); - if (size <= osize) - return old; - void* new = malloca(size, amnt); - if (new != NULL) { - free(old); - return new; - } - return NULL; -} - -void free(void* memloc) -{ - // Don't try to free memory outside of heap - if(!(((void*)rpi_heap <= memloc) && (memloc < rpi_heap_top))) - return; - unsigned char* base = memloc - MEM_BASE_SIZE; - unsigned char size = base[MEM_SIZE_OFFSET]; - // TODO: Use Null PID - base[MEM_USE_OFFSET] = 0; - // Clear out old memory - for(unsigned int i = 0; i < size; i++) { - base[i + MEM_BASE_SIZE] = 0; - } - // If it is the last entry, clear it and move the heap top down - if (base + size + MEM_META_SIZE == rpi_heap_top) { - while(base[MEM_USE_OFFSET] == 0 && base >= rpi_heap) { - base[MEM_SIZE_OFFSET] = 0; - base[MEM_BASE_SIZE + size] = 0; - rpi_heap_top = base; - unsigned long psize = *(base - 1); - base -= psize + MEM_META_SIZE; - } - } -} - -void* heap_base(void) -{ - return (void*)rpi_heap; -} - -void* heap_top(void) -{ - return rpi_heap_top; -} - -void vheap_info(void) -{ - unsigned char* base = rpi_heap; - unsigned long ioff = STACK_DRAW_WIDTH*STACK_DRAW_SIZE; - unsigned long yoff = STACK_DRAW_YOFF; - draw_cbox(ioff, yoff, STACK_DRAW_SIZE*STACK_DRAW_WIDTH, STACK_DRAW_SIZE * 8, 0x0); - while ((void*)base < rpi_heap_top) { - unsigned char size = base[MEM_SIZE_OFFSET]; - if(base[MEM_USE_OFFSET] == 0) { - draw_cbox(ioff, yoff, STACK_DRAW_SIZE, STACK_DRAW_SIZE, 0x00FF00); - } else { - draw_cbox(ioff, yoff, STACK_DRAW_SIZE, STACK_DRAW_SIZE, 0xFF0000); - } - ioff += STACK_DRAW_SIZE; - if(ioff % STACK_DRAW_WIDTH == 0) { - yoff += STACK_DRAW_SIZE; - ioff = STACK_DRAW_WIDTH*STACK_DRAW_SIZE; - } - base += size + MEM_META_SIZE; - } -} - -void heap_info(void) -{ - unsigned char* base = rpi_heap; - while ((void*)base < rpi_heap_top) { - unsigned char size = base[MEM_SIZE_OFFSET]; - if(base[MEM_USE_OFFSET] == 0) { - uart_char('F'); - uart_char(' '); - } else { - } - uart_hex((unsigned long)(base + MEM_BASE_SIZE)); - uart_string(" Size: "); - uart_10(size); - uart_string("\n"); - static char* data = "00 \0"; - static unsigned char temp = 0; - for(unsigned int i = 0; i < size; i++) { - temp = (base[MEM_BASE_SIZE + i]>>4)&0xF; - if(temp > 9) - temp += 7; - temp += 0x30; - data[0] = temp; - temp = (base[MEM_BASE_SIZE + i])&0xF; - if(temp > 9) - temp += 7; - temp += 0x30; - data[1] = temp; - uart_string(data); - } - uart_char('\n'); - base += size + MEM_META_SIZE; - } - uart_char('\n'); -} - -void heap_info_u(void) -{ - unsigned char* base = rpi_heap; - while ((void*)base < rpi_heap_top) { - unsigned char size = base[MEM_SIZE_OFFSET]; - if(base[MEM_USE_OFFSET] == 0) { - base += size + MEM_META_SIZE; - continue; - } - uart_hex((unsigned long)(base + MEM_BASE_SIZE)); - uart_string(" Size: "); - uart_10(size); - uart_string("\n"); - static char* data = "00 \0"; - static unsigned char temp = 0; - for(unsigned int i = 0; i < size; i++) { - temp = (base[MEM_BASE_SIZE + i]>>4)&0xF; - if(temp > 9) - temp += 7; - temp += 0x30; - data[0] = temp; - temp = (base[MEM_BASE_SIZE + i])&0xF; - if(temp > 9) - temp += 7; - temp += 0x30; - data[1] = temp; - uart_string(data); - } - uart_char('\n'); - base += size + MEM_META_SIZE; - } - uart_char('\n'); -} diff --git a/src/lib/q.c b/src/lib/q.c deleted file mode 100644 index 2ade143..0000000 --- a/src/lib/q.c +++ /dev/null @@ -1,54 +0,0 @@ -#include <lib/q.h> -#include <lib/mem.h> - -struct Q_base* new_q() -{ - struct Q_base* q = (struct Q_base*)malloc(sizeof(struct Q_base)); - q->next = 0; - q->last = 0; - return q; -} - -void push_q(struct Q_base* qb, void* val) -{ - struct Q* n = (struct Q*)malloc(sizeof(struct Q)); - n->next = 0; - n->data = val; - if (qb->last != 0) - qb->last->next = n; - else { - qb->next = n; - } - qb->last = n; -} - -void pop_q(struct Q_base* qb) -{ - if (qb->next == 0) - return; - if (qb->next == qb->last) { - free(qb->next->data); - free(qb->next); - qb->next = 0; - qb->last = 0; - return; - } - struct Q* t = qb->next; - qb->next = qb->next->next; - free(t->data); - free(t); -} - -unsigned long length_q(struct Q_base* qb) -{ - unsigned long length = 0; - if(qb->next == 0) - return length; - length++; - struct Q* q = qb->next; - while (q != qb->last) { - length++; - q = q->next; - } - return length; -} diff --git a/src/sys/core.c b/src/sys/core.c index a42b581..65ee526 100644 --- a/src/sys/core.c +++ b/src/sys/core.c @@ -5,7 +5,6 @@ #include <graphics/drawer.h> #include <graphics/lfb.h> #include <lib/kmem.h> -#include <lib/mem.h> #include <lib/strings.h> #include <symbols.h> #include <sys/core.h> @@ -21,7 +20,6 @@ void sysinit(void) // Initialize System Globals exe_cnt_m.addr = &exe_cnt; exe_cnt_m.pid = NULL_PID; - rpi_heap_top = &rpi_heap; stimeh = *(unsigned long*)SYS_TIMER_CHI; stimel = *(unsigned long*)SYS_TIMER_CLO; *(unsigned long*) SYS_TIMER_C0 = 60000000 + stimeh; // 60 second trigger diff --git a/src/sys/schedule.c b/src/sys/schedule.c index acd6098..7bc86c3 100644 --- a/src/sys/schedule.c +++ b/src/sys/schedule.c @@ -110,7 +110,7 @@ void uart_scheduler(void) uart_string("Scheduler Info\n==============\nCurrent\n"); uart_hex((unsigned long)scheduler.rthread); uart_char(' '); - memshow32((void*)scheduler.rthread, 6); + //memshow32((void*)scheduler.rthread, 6); struct ThreadQueues* tq; for(int p = 0; p < PRIORITIES; p++) { uart_string("Priority "); @@ -131,8 +131,7 @@ void uart_scheduler(void) while (roffset != trb->woffset) { uart_hex((unsigned long)trb->queue[roffset]); uart_char(' '); - memshow32((void*)trb->queue[roffset], 6); - //memshow32((void*)trb->queue[roffset]->sp, 14); + //memshow32((void*)trb->queue[roffset], 6); roffset++; roffset %= TQUEUE_MAX; } diff --git a/src/util/status.c b/src/util/status.c index 4959431..9044b1a 100644 --- a/src/util/status.c +++ b/src/util/status.c @@ -2,7 +2,6 @@ #include <globals.h> #include <graphics/drawer.h> #include <graphics/lfb.h> -#include <lib/mem.h> #include <symbols.h> #include <sys/core.h> #include <sys/schedule.h> @@ -180,7 +179,4 @@ void status(void) g_Drawer.x = x; g_Drawer.y = y; - - draw_stacks(); - vheap_info(); } |