aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/common.h14
-rw-r--r--src/main.c12
-rw-r--r--src/ppu.c4
-rw-r--r--src/start.s9
4 files changed, 25 insertions, 14 deletions
diff --git a/src/common.h b/src/common.h
index c71455d..39b2c91 100644
--- a/src/common.h
+++ b/src/common.h
@@ -25,6 +25,14 @@ void delay(u64 ticks);
25// Clear N bytes at the given address 8 bytes at a time. Implemented in start.s. 25// Clear N bytes at the given address 8 bytes at a time. Implemented in start.s.
26void memzero64(void *src, u64 n); 26void memzero64(void *src, u64 n);
27 27
28static void
29memzero8(void *src, u64 n) {
30 u8 * ptr = src;
31 for (size_t i = 0; i < n; i++) {
32 ptr[i] = 0;
33 }
34}
35
28// 36//
29// GPIO Registers. 37// GPIO Registers.
30// 38//
@@ -249,7 +257,7 @@ typedef struct TimerRegs {
249 257
250#define TIMER ((TimerRegs *)(MEM_BASE + 0x00003000)) 258#define TIMER ((TimerRegs *)(MEM_BASE + 0x00003000))
251 259
252u64 260static u64
253timer_get_ticks(void) { 261timer_get_ticks(void) {
254 u32 high = TIMER->counter_high; 262 u32 high = TIMER->counter_high;
255 u32 low = TIMER->counter_low; 263 u32 low = TIMER->counter_low;
@@ -263,7 +271,7 @@ timer_get_ticks(void) {
263 return ((u64)high << 32) | low; 271 return ((u64)high << 32) | low;
264} 272}
265 273
266void 274static void
267wait(u64 usec) { 275wait(u64 usec) {
268 u64 current_ticks = timer_get_ticks(); 276 u64 current_ticks = timer_get_ticks();
269 // The system timer clock runs at 1 Mhz. 277 // The system timer clock runs at 1 Mhz.
@@ -274,7 +282,7 @@ wait(u64 usec) {
274// Utilities. 282// Utilities.
275// 283//
276 284
277void * 285static void *
278memcpy(void *dest, const void *src, u32 n) { 286memcpy(void *dest, const void *src, u32 n) {
279 u8 *from = (u8*)src; 287 u8 *from = (u8*)src;
280 u8 *to = (u8*)dest; 288 u8 *to = (u8*)dest;
diff --git a/src/main.c b/src/main.c
index 8ab3cf5..b18b129 100644
--- a/src/main.c
+++ b/src/main.c
@@ -129,10 +129,7 @@ init_uxn() {
129 uart_puts("Initializing UXN.\n"); 129 uart_puts("Initializing UXN.\n");
130 130
131 // Clear UXN memory. 131 // Clear UXN memory.
132 u8 * uxnptr = (u8*)&u; 132 memzero8(&u, sizeof(Uxn));
133 for (size_t i = 0; i < sizeof(Uxn); i++) {
134 uxnptr[i] = 0;
135 }
136 133
137 ppu_init(&ppu, SCREEN_WIDTH / 8, SCREEN_HEIGHT / 8); 134 ppu_init(&ppu, SCREEN_WIDTH / 8, SCREEN_HEIGHT / 8);
138 135
@@ -164,10 +161,13 @@ void
164clear_bss(void) { 161clear_bss(void) {
165 extern u64 __bss_start; 162 extern u64 __bss_start;
166 extern u64 __bss_end; 163 extern u64 __bss_end;
167 memzero64(&__bss_start, &__bss_end - &__bss_start); 164 u64 bss_size = &__bss_end - &__bss_start;
165 memzero64(&__bss_start, bss_size);
168} 166}
169 167
170void main(void) { 168void
169main(void) {
170 // Initialization.
171 clear_bss(); 171 clear_bss();
172 uart_init(); 172 uart_init();
173 init_uxn(); 173 init_uxn();
diff --git a/src/ppu.c b/src/ppu.c
index ac0feeb..50e95d5 100644
--- a/src/ppu.c
+++ b/src/ppu.c
@@ -151,9 +151,7 @@ ppu_init(Ppu *p, Uint8 hor, Uint8 ver) {
151 palette[3] = 0xff7777; 151 palette[3] = 0xff7777;
152 152
153 // Clear pixel buffer memory. 153 // Clear pixel buffer memory.
154 for (size_t i = 0; i < sizeof(pixels_buf); i++) { 154 memzero8(pixels_buf, sizeof(pixels_buf));
155 p->pixels[i] = 0;
156 }
157 155
158 // Make sure we perform an initial screen drawing. 156 // Make sure we perform an initial screen drawing.
159 reqdraw = 1; 157 reqdraw = 1;
diff --git a/src/start.s b/src/start.s
index b6a6d0f..8f8ca2f 100644
--- a/src/start.s
+++ b/src/start.s
@@ -11,9 +11,14 @@ _start:
11// Helper function to clear x1 bytes starting at the x0 memory address. 11// Helper function to clear x1 bytes starting at the x0 memory address.
12.globl memzero64 12.globl memzero64
13memzero64: 13memzero64:
14 mov x2, x1
15 lsr x2, x2, #3
16 cbz x2, memzero64_ret
17memzero64_loop:
14 str xzr, [x0], #8 18 str xzr, [x0], #8
15 subs x1, x1, #8 19 subs x2, x2, #1
16 b.gt memzero64 20 b.gt memzero64_loop
21memzero64_ret:
17 ret 22 ret
18 23
19// Helper function wait for N cycles before returning. 24// Helper function wait for N cycles before returning.