From e3eb5a92ae3991cdfbb5a5cf553eac476bc5822f Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Fri, 4 Feb 2022 23:55:05 -0700 Subject: Removed old mem --- src/cpu/irq.c | 2 - src/globals.c | 3 - src/lib/ll.c | 57 --------- src/lib/mem.c | 340 ----------------------------------------------------- src/lib/q.c | 54 --------- src/sys/core.c | 2 - src/sys/schedule.c | 5 +- src/util/status.c | 4 - 8 files changed, 2 insertions(+), 465 deletions(-) delete mode 100644 src/lib/ll.c delete mode 100644 src/lib/mem.c delete mode 100644 src/lib/q.c (limited to 'src') 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 #include #include #include @@ -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 -#include - -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 -#include -#include -#include -#include - -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 -#include - -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 #include #include -#include #include #include #include @@ -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 #include #include -#include #include #include #include @@ -180,7 +179,4 @@ void status(void) g_Drawer.x = x; g_Drawer.y = y; - - draw_stacks(); - vheap_info(); } -- cgit v1.2.1