From 8e74d1080e9c5397f67c4a69b670ca44a4649ac8 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Fri, 9 Apr 2021 12:49:19 +0000 Subject: [PATCH] - fixed git-svn-id: http://moon:8086/svn/mips@169 a8ebac50-d88d-4704-bea3-6648445a41b3 --- src/asm/Makefile | 7 +++++-- src/asm/libsys/utils.c | 40 +++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/asm/Makefile b/src/asm/Makefile index 7d14009..046c20c 100644 --- a/src/asm/Makefile +++ b/src/asm/Makefile @@ -12,7 +12,9 @@ ROMGEN=romgen FLASHGEN=flashgen ENDIAN_FLAGS := -EB -CFLAGS := $(ENDIAN_FLAGS) -march=$(TARGET) -L. -T link/link.ld -Wl,--gc-sections -G 0 -O0 +INCLUDES := -I libsys/boards/sim + +CFLAGS := $(ENDIAN_FLAGS) -march=$(TARGET) -L. -T link/link.ld -Wl,--gc-sections -G 0 -O0 $(INCLUDES) CFLAGS += -fno-exceptions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostartfiles LIBS := -lsys -lc @@ -22,7 +24,8 @@ libsys.a: $(CC) $(CFLAGS) -c libsys/startup.s -o startup.o $(CC) $(CFLAGS) -c libsys/kernel.s -o kernel.o $(CC) $(CFLAGS) -c libsys/utils.c -o utils.o - $(AR) -r libsys.a startup.o kernel.o utils.o + $(CC) $(CFLAGS) -c libsys/boards/sim/board.c -o board.o + $(AR) -r libsys.a startup.o kernel.o utils.o board.o testbench.elf: libsys.a diff --git a/src/asm/libsys/utils.c b/src/asm/libsys/utils.c index b704173..0542749 100644 --- a/src/asm/libsys/utils.c +++ b/src/asm/libsys/utils.c @@ -2,31 +2,41 @@ #include #include #include +#include char readchar(void) { - volatile char *pUART_stat = (char*)0x80000008; - volatile char *pUART_data = (char*)0x80000004; + volatile uint32_t *pUART_stat = (uint32_t*)SYS_UART_STAT; + volatile uint32_t *pUART_data = (uint32_t*)SYS_UART_DATA; - while(!(0x10 & *pUART_stat)); + while(!(SYS_UART_BIT_RX_AVAIL & *pUART_stat)); return *pUART_data; } +void _putchar(char c) +{ + if (c == 0x0A) + { + writechar(0x0D); + } + writechar(c); +} + void writechar(char c) { - volatile char *pUART_stat = (char*)0x80000008; - volatile char *pUART_data = (char*)0x80000004; + volatile uint32_t *pUART_stat = (uint32_t*)SYS_UART_STAT; + volatile uint32_t *pUART_data = (uint32_t*)SYS_UART_DATA; - while((0x02 & *pUART_stat) != 0); + while((SYS_UART_BIT_TX_FULL & *pUART_stat) != 0); *pUART_data = c; } clock_t times(struct tms *buffer) { - volatile long *pReg_usec = (long*)0x80000010; - volatile long *pReg_sec = (long*)0x80000014; + volatile uint32_t *pReg_usec = (uint32_t*)SYS_TIMER_USEC; + volatile uint32_t *pReg_sec = (uint32_t*)SYS_TIMER_SEC; long sec; sec = *pReg_sec; @@ -44,8 +54,8 @@ clock_t times(struct tms *buffer) int gettimeofday(struct timeval *tp, void *tzp) { - volatile long *pReg_usec = (long*)0x80000010; - volatile long *pReg_sec = (long*)0x80000014; + volatile uint32_t *pReg_usec = (uint32_t*)SYS_TIMER_USEC; + volatile uint32_t *pReg_sec = (uint32_t*)SYS_TIMER_SEC; if (tp) { @@ -58,8 +68,8 @@ int gettimeofday(struct timeval *tp, void *tzp) int settimeofday(const struct timeval *tp, const struct timezone *tzp) { - volatile long *pReg_usec = (long*)0x80000010; - volatile long *pReg_sec = (long*)0x80000014; + volatile uint32_t *pReg_usec = (uint32_t*)SYS_TIMER_USEC; + volatile uint32_t *pReg_sec = (uint32_t*)SYS_TIMER_SEC; div_t res; res = div(tp->tv_usec, 1E6); @@ -124,7 +134,7 @@ int write(int file, char *ptr, int len) int i; for (i=0; i < len; i++) - writechar(*ptr++); + _putchar(*ptr++); return i; } @@ -140,7 +150,7 @@ int sputs(char *pStr) start = pStr; while(*pStr) - writechar(*(pStr++)); + _putchar(*(pStr++)); return pStr - start; } @@ -160,7 +170,7 @@ void print_byte(char byte) else c = nibble + 'A' - 10; - writechar(c); + _putchar(c); } }