From cf233c4d81d1e671bf63c0201e0b93e74507cc12 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Wed, 18 Jan 2017 22:28:07 +0000 Subject: [PATCH] - fixed bootloader - bootloader added board file - refactored header files - constify constants git-svn-id: http://moon:8086/svn/mips@99 a8ebac50-d88d-4704-bea3-6648445a41b3 --- src/bootloader/Makefile | 36 ++++++----- src/bootloader/boards/denano/board.c | 89 +++++++++++++++++++++++++ src/bootloader/boards/ml402/board.c | 89 +++++++++++++++++++++++++ src/bootloader/bootloader.c | 1 + src/bootloader/bootloader_with_flash.c | 7 +- src/bootloader/libsys.c | 30 ++++----- src/bootloader/libsys.h | 90 -------------------------- src/bootloader/startup.S | 11 ++-- src/cfiflash.c | 2 - src/hpi.h | 1 + src/libsys/boards/denano/board.c | 5 +- src/libsys/boards/denano/board.h | 10 +-- src/libsys/boards/ml402/board.c | 33 ++++++++-- src/libsys/boards/ml402/board.h | 7 -- src/libsys/mips_ps2.c | 8 +-- src/libsys/screen.c | 2 +- src/libsys/uart.c | 13 ++-- src/test_hpi.c | 8 +-- src/test_irq.c | 5 +- src/test_vga.c | 6 +- src/testbench.c | 8 ++- 21 files changed, 289 insertions(+), 172 deletions(-) create mode 100644 src/bootloader/boards/denano/board.c create mode 100644 src/bootloader/boards/ml402/board.c diff --git a/src/bootloader/Makefile b/src/bootloader/Makefile index 6379939..e97d68c 100644 --- a/src/bootloader/Makefile +++ b/src/bootloader/Makefile @@ -12,7 +12,7 @@ else ENDIAN_FLAGS=-EB endif -CFLAGS=$(ENDIAN_FLAGS) -Os -I. -I../ -I../libsys -msoft-float -march=r3000 -G0 +CFLAGS=$(ENDIAN_FLAGS) -Os -I. -I../libsys -msoft-float -march=r3000 -G0 -I../libsys/boards/$(BOARD) -D$(BOARD) LFLAGS=$(ENDIAN_FLAGS) ifeq ($(TLB),yes) @@ -38,9 +38,15 @@ ROMGEN=$(MIPS_HOME)/tools/romgen all: $(BUILD_DIR) $(BUILD_DIR)/bootloader.elf $(BUILD_DIR)/bootloader_with_flash.elf -OBJS-ml402=$(addprefix $(BUILD_DIR)/, startup.o kernel.o libsys.o) -OBJS-denano=$(addprefix $(BUILD_DIR)/, startup.o kernel.o libsys.o) - +OBJS-ml402=$(addprefix $(BUILD_DIR)/, startup.o kernel.o libsys.o board.o uart.o) +OBJS-denano=$(addprefix $(BUILD_DIR)/, startup.o kernel.o libsys.o board.o uart.o) + +$(BUILD_DIR)/uart.o : ../libsys/uart.c + $(CC) $(CFLAGS) -c -o $@ $< + +$(BUILD_DIR)/board.o : boards/$(BOARD)/board.c + $(CC) $(CFLAGS) -c -o $@ $< + $(BUILD_DIR)/%.o : %.c $(CC) $(CFLAGS) -c -o $@ $< @@ -48,20 +54,20 @@ $(BUILD_DIR)/%.o : %.S $(CC) $(CFLAGS) -c -o $@ $< $(BUILD_DIR)/bootloader.elf: $(OBJS-$(BOARD)) bootloader.c - $(CC) $(CFLAGS) -g -c bootloader.c - $(LD) $(LFLAGS) $(LIB_DIRS) $(OBJS-$(BOARD)) bootloader.o -o $@.elf $(LIBS) >$@.map - $(OBJDUMP) -D $@.elf > $@.dis - $(OBJCOPY) $@.elf -j ROM --output-target=binary $@.ROM.bin - $(OBJCOPY) -O srec $@.elf $@.srec + $(CC) $(CFLAGS) -o $(BUILD_DIR)/bootloader.o -g -c bootloader.c + $(LD) $(LFLAGS) $(LIB_DIRS) $(OBJS-$(BOARD)) bootloader.o -o $@ $(LIBS) >$@.map + $(OBJDUMP) -D $@ > $@.dis + $(OBJCOPY) $@ -j ROM --output-target=binary $@.ROM.bin + $(OBJCOPY) -O srec $@ $@.srec $(ROMGEN) $@.ROM.bin 11 $(ENDIAN_FLAGS) $(BUILD_DIR)/bootloader_with_flash.elf: $(OBJS-$(BOARD)) bootloader_with_flash.c ../cfiflash.c - $(CC) $(CFLAGS) -g -c bootloader_with_flash.c - $(CC) $(CFLAGS) -g -c ../cfiflash.c - $(LD) $(LFLAGS) $(LIB_DIRS) $(OBJS-$(BOARD)) cfiflash.o bootloader_with_flash.o -o $@.elf $(LIBS) >$@.map - $(OBJDUMP) -D $@.elf > $@.dis - $(OBJCOPY) $@.elf -j ROM --output-target=binary $@.ROM.bin - $(OBJCOPY) -O srec $@.elf $@.srec + $(CC) $(CFLAGS) -o $(BUILD_DIR)/bootloader_with_flash.o -g -c bootloader_with_flash.c + $(CC) $(CFLAGS) -o $(BUILD_DIR)/cfiflash.o -g -c ../cfiflash.c + $(LD) $(LFLAGS) $(LIB_DIRS) $(OBJS-$(BOARD)) cfiflash.o bootloader_with_flash.o -o $@ $(LIBS) >$@.map + $(OBJDUMP) -D $@ > $@.dis + $(OBJCOPY) $@ -j ROM --output-target=binary $@.ROM.bin + $(OBJCOPY) -O srec $@ $@.srec $(ROMGEN) $@.ROM.bin 11 $(ENDIAN_FLAGS) $(BUILD_DIR): diff --git a/src/bootloader/boards/denano/board.c b/src/bootloader/boards/denano/board.c new file mode 100644 index 0000000..e3288d0 --- /dev/null +++ b/src/bootloader/boards/denano/board.c @@ -0,0 +1,89 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +#include +#include "../../../libsys/boards/denano/board.h" +#include "../../../libsys/uart.h" +#include "../../../libsys/irq.h" + +#define DEBUGGER gdb_stub + +extern uart_if_t uart_if[]; + +#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0])) + +static uart_if_t const *dbg_uart = NULL; +static volatile uint32_t *pGpioData = (uint32_t*)SYS_GPIO_0_DATA; +static volatile uint32_t *pGpioDir = (uint32_t*)SYS_GPIO_0_DIR; +static uint32_t led_count = 0; + +extern int dbg_handler(struct xcptcontext * xcp); +extern void handle_exception (unsigned long *registers); + +int gdb_stub(struct xcptcontext * xcp) +{ +// handle_exception((unsigned long *)xcp); + return 0; +} + +void dbg_uart_isr(struct xcptcontext *xcp) +{ + if(SYS_UART_BIT_RX_AVAIL & *dbg_uart->pCTRL) + { + char c = *dbg_uart->pDATA; + if (c == 3) + { + DEBUGGER(xcp); + } + } +} + +void dbg_uart_setup() +{ + const int UART_INT = SYS_INT_UART1; + dbg_uart = (uart_if_t*)&uart_if[1]; + + *dbg_uart->pCTRL = SYS_UART_BIT_RX_INTEN; +} + +inline void _dbg_writechar(uart_if_t const *pUart, char c) +{ + while((SYS_UART_BIT_TX_HALFFULL & *pUart->pCTRL) != 0); + + *pUart->pDATA = (uint32_t)c; + +} + +inline char _dbg_readchar(uart_if_t const *pUart) +{ + // busy read + while(!(SYS_UART_BIT_RX_AVAIL & *pUart->pCTRL)) + { + (*pGpioData) = (led_count++) >> 16; + } + led_count = 0; + return (*pUart->pDATA & 0xFF); + +} + +void dbg_putchar(char c) +{ + if (c == 0x0A) + { + _dbg_writechar(dbg_uart, 0x0D); + } + _dbg_writechar(dbg_uart, c); +} + +char dbg_getchar() +{ + return (char)_dbg_readchar(dbg_uart); +} + +void board_init(void) +{ + +} diff --git a/src/bootloader/boards/ml402/board.c b/src/bootloader/boards/ml402/board.c new file mode 100644 index 0000000..1d9a039 --- /dev/null +++ b/src/bootloader/boards/ml402/board.c @@ -0,0 +1,89 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +#include +#include "../../../libsys/boards/ml402/board.h" +#include "../../../libsys/uart.h" +#include "../../../libsys/irq.h" + +#define DEBUGGER gdb_stub + +extern uart_if_t uart_if[]; + +#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0])) + +static uart_if_t const *dbg_uart = NULL; +static volatile uint32_t *pGpioData = (uint32_t*)SYS_GPIO_0_DATA; +static volatile uint32_t *pGpioDir = (uint32_t*)SYS_GPIO_0_DIR; +static uint32_t led_count = 0; + +extern int dbg_handler(struct xcptcontext * xcp); +extern void handle_exception (unsigned long *registers); + +int gdb_stub(struct xcptcontext * xcp) +{ +// handle_exception((unsigned long *)xcp); + return 0; +} + +void dbg_uart_isr(struct xcptcontext *xcp) +{ + if(SYS_UART_BIT_RX_AVAIL & *dbg_uart->pCTRL) + { + char c = *dbg_uart->pDATA; + if (c == 3) + { + DEBUGGER(xcp); + } + } +} + +void dbg_uart_setup() +{ + const int UART_INT = SYS_INT_UART; + dbg_uart = (uart_if_t*)&uart_if[1]; + + *dbg_uart->pCTRL = SYS_UART_BIT_RX_INTEN; +} + +inline void _dbg_writechar(uart_if_t const *pUart, char c) +{ + while((SYS_UART_BIT_TX_HALFFULL & *pUart->pCTRL) != 0); + + *pUart->pDATA = (uint32_t)c; + +} + +inline char _dbg_readchar(uart_if_t const *pUart) +{ + // busy read + while(!(SYS_UART_BIT_RX_AVAIL & *pUart->pCTRL)) + { + (*pGpioData) = (led_count++) >> 16; + } + led_count = 0; + return (*pUart->pDATA & 0xFF); + +} + +void dbg_putchar(char c) +{ + if (c == 0x0A) + { + _dbg_writechar(dbg_uart, 0x0D); + } + _dbg_writechar(dbg_uart, c); +} + +char dbg_getchar() +{ + return (char)_dbg_readchar(dbg_uart); +} + +void board_init(void) +{ + +} diff --git a/src/bootloader/bootloader.c b/src/bootloader/bootloader.c index 1003664..5af0b57 100644 --- a/src/bootloader/bootloader.c +++ b/src/bootloader/bootloader.c @@ -1,3 +1,4 @@ +#include #include "libsys.h" #define MAGIC_EB 0x4A464931 // "JFI1" in big-endian; diff --git a/src/bootloader/bootloader_with_flash.c b/src/bootloader/bootloader_with_flash.c index 3da6e81..28d80fe 100644 --- a/src/bootloader/bootloader_with_flash.c +++ b/src/bootloader/bootloader_with_flash.c @@ -1,5 +1,6 @@ +#include #include "libsys.h" -#include "cfiflash.h" +#include "../cfiflash.h" #define MAGIC_EB 0x4A464931 // "JFI1" in big-endian; #define MAGIC_EL 0x3149464A // "JFI1" in little-endian; @@ -235,7 +236,7 @@ int main(int argc, char *argv[]) *pGPIO_DIR = GPIO_0_DFLT_DIR; *pGPIO_DATA = GPIO_0_DFLT_DATA; haddr = 0; - block_sel = 0x7F & (uint32_t)((*pGPIO_DATA & GPIO_0_DIP) >> GPIO_0_ALIGN_DIP); + block_sel = 0x7F & (uint32_t)((*pGPIO_DATA & GPIO_0_MASK_DIP) >> GPIO_0_ALIGN_DIP); sputs("\nMIPS bootloader\n"); // ---------------------------------------------------------- @@ -251,7 +252,7 @@ int main(int argc, char *argv[]) ram32 = (uint32_t*)(SDRAM_BASE); pFlashIO = (uint32_t*)(SYS_FLASH_IO + flash_offset); - if (!(((*pGPIO_DATA & GPIO_0_BTN) >> GPIO_0_ALIGN_BTN) & 8)) + if (!(((*pGPIO_DATA & GPIO_0_MASK_BTN) >> GPIO_0_ALIGN_BTN) & 8)) { sputs("Loading image from flash at ");print_word(flash_offset);sputs("\n"); pImg_hdr = (flash_img_hdr_t*)pFlashIO; diff --git a/src/bootloader/libsys.c b/src/bootloader/libsys.c index 62f9c5a..f5d46fc 100644 --- a/src/bootloader/libsys.c +++ b/src/bootloader/libsys.c @@ -5,6 +5,9 @@ #include #include #include "libsys.h" +#include "../../uart.h" + +extern uart_if_t uart_if[]; // --------------------------------------------------------------------------------- void _exit(int reason) @@ -14,12 +17,6 @@ void _exit(int reason) while(1); } -void libsys_init() -{ - // Initialzie interrupt support -// interrupt_init(); -} - // MIPS specific uint32_t CP0_SR_read(void) { @@ -141,22 +138,21 @@ void DCACHE_invalidate_at(uint32_t* pPtr) // --------------------------------------------------------------------------------- char readchar(void) { - volatile uint32_t *pUART_stat = (uint32_t*)SYS_UART_STAT; - volatile uint32_t *pUART_data = (uint32_t*)SYS_UART_DATA; + int c; - while(!(0x10 & *pUART_stat)); - - return (char)*pUART_data; + // busy read + do + { + c = UART_readchar(&uart_if[0]); + + } while(c < 0); + + return (char)c; } void writechar(char c) { - 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); - - *pUART_data = (uint32_t)c; + UART_writechar(&uart_if[0], c); } void _putchar(char c) diff --git a/src/bootloader/libsys.h b/src/bootloader/libsys.h index cdeeeef..c423b4d 100644 --- a/src/bootloader/libsys.h +++ b/src/bootloader/libsys.h @@ -9,96 +9,6 @@ #define LSYS_ERR_BASE 0x80000000 #define IS_ERROR(e) ((e & LSYS_ERR_BASE) == LSYS_ERR_BASE) -#ifndef SYS_IO_BASE -#define SYS_IO_BASE 0xA0000000 -#endif -#ifndef SDRAM_BASE -#define SDRAM_BASE 0x40000000 -#endif -#ifndef FLASH_BASE_IO -#define FLASH_BASE_IO 0xA4000000 -#endif -#ifndef FLASH_BASE_MEM -#define FLASH_BASE_MEM 0x00000000 -#endif - - -#define SYS_GPIO_0_DATA (SYS_IO_BASE + 0x0) -#define SYS_GPIO_0_DIR (SYS_IO_BASE + 0x4) -#define GPIO_0_DFLT_DIR (GPIO_0_LED | GPIO_0_USB_RST | GPIO_0_USB_INTEN | GPIO_0_AC97_INTEN | GPIO_0_PHY_RST | GPIO_0_PHY_MDC) -#define GPIO_0_DFLT_DATA ((~GPIO_0_LED & GPIO_0_LED) | GPIO_0_USB_RST | (~GPIO_0_USB_INTEN & GPIO_0_USB_INTEN) | (~GPIO_0_AC97_INTEN & GPIO_0_AC97_INTEN) | GPIO_0_PHY_RST | (~GPIO_0_PHY_MDC & GPIO_0_PHY_MDC)) -#define GPIO_0_LED 0x000001FF -#define GPIO_0_BTN 0x1F000000 -#define GPIO_0_DIP 0x00FF0000 -#define GPIO_0_USB_RST 0x00001000 -#define GPIO_0_USB_INTEN 0x00002000 -#define GPIO_0_AC97_INTEN 0x00008000 -#define GPIO_0_PHY_RST 0x20000000 -#define GPIO_0_PHY_MDC 0x40000000 -#define GPIO_0_PHY_MDIO 0x80000000 -#define GPIO_0_ALIGN_LED 0 -#define GPIO_0_ALIGN_DIP 16 -#define GPIO_0_ALIGN_BTN 24 -#define GPIO_0_ALIGN_MDIO 31 - -#define SYS_TIMER_USEC (SYS_IO_BASE + 0x8) -#define SYS_TIMER_SEC (SYS_IO_BASE + 0xC) -#define SYS_ITIM_CTRL (SYS_IO_BASE + 0x18) -#define SYS_ITIM_STAT (SYS_IO_BASE + 0x1C) -#define SYS_ITIM0_CNT (SYS_IO_BASE + 0x20) -#define SYS_ITIM1_CNT (SYS_IO_BASE + 0x24) -#define SYS_ITIM2_CNT (SYS_IO_BASE + 0x28) -#define SYS_ITIM3_CNT (SYS_IO_BASE + 0x2C) -#define SYS_ITIM0_CMP (SYS_IO_BASE + 0x30) -#define SYS_ITIM1_CMP (SYS_IO_BASE + 0x34) -#define SYS_ITIM2_CMP (SYS_IO_BASE + 0x38) -#define SYS_ITIM3_CMP (SYS_IO_BASE + 0x3C) - -#define SYS_UART_DATA (SYS_IO_BASE + 0x10000) -#define SYS_UART_STAT (SYS_IO_BASE + 0x10004) -#define SYS_UART_BAUD (SYS_IO_BASE + 0x10008) - -#define SYS_SPI_STAT (SYS_IO_BASE + 0x20000) -// Read -#define SPI_STAT_CMDRDY (0x01) -#define SPI_STAT_DINRDY (0x02) -#define SPI_STAT_DOUTRDY (0x04) -#define SPI_STAT_CMD_FIFO_FULL (0x0100) -#define SPI_STAT_CMD_FIFO_EMPTY (0x0200) -#define SPI_STAT_WRITE_FIFO_FULL (0x0400) -#define SPI_STAT_WRITE_FIFO_EMPTY (0x0800) -#define SPI_STAT_READ_FIFO_FULL (0x1000) -#define SPI_STAT_READ_FIFO_EMPTY (0x2000) -#define SPI_STAT_RX_VALID (0x4000) -#define SPI_STAT_SPI_HOLD (0x8000) - -// Write -#define SPI_STAT_COMMIT (1) - -#define SYS_SPI_XFER_SIZE (SYS_IO_BASE + 0x20004) -#define SYS_SPI_DATA_SIZE (SYS_IO_BASE + 0x20008) -#define SYS_SPI_DATA (SYS_IO_BASE + 0x2000C) -#define SYS_SPI_CTRL (SYS_IO_BASE + 0x20010) - -#define SYS_FLASH_IO FLASH_BASE_IO -#define SYS_FLASH_MEM FLASH_BASE_MEM - -// RTC -#define SYS_TIMER_USEC (SYS_IO_BASE + 0x8) -#define SYS_TIMER_SEC (SYS_IO_BASE + 0xC) - -// TIMERs -#define SYS_ITIM_CTRL (SYS_IO_BASE + 0x18) -#define SYS_ITIM_STAT (SYS_IO_BASE + 0x1C) -#define SYS_ITIM0_CNT (SYS_IO_BASE + 0x20) -#define SYS_ITIM1_CNT (SYS_IO_BASE + 0x24) -#define SYS_ITIM2_CNT (SYS_IO_BASE + 0x28) -#define SYS_ITIM3_CNT (SYS_IO_BASE + 0x2C) -#define SYS_ITIM0_CMP (SYS_IO_BASE + 0x30) -#define SYS_ITIM1_CMP (SYS_IO_BASE + 0x34) -#define SYS_ITIM2_CMP (SYS_IO_BASE + 0x38) -#define SYS_ITIM3_CMP (SYS_IO_BASE + 0x3C) - // MIPS specific uint32_t CP0_SR_read(void); void CP0_SR_write(uint32_t val); diff --git a/src/bootloader/startup.S b/src/bootloader/startup.S index 67424f0..acb20cf 100644 --- a/src/bootloader/startup.S +++ b/src/bootloader/startup.S @@ -2,6 +2,7 @@ .text .section .init,"ax" + .extern board_init .align 2 _start: @@ -14,7 +15,7 @@ _start: # Kernel mode (SR[1]=0), Int disabled(SR[0]=0), after RFE into main li $26, 0x1040000C mtc0 $26, $12 - li $26, 0x00000000 + li $26, 0x00000000 mtc0 $26, $13 mfc0 $26, $15 @@ -36,14 +37,14 @@ $zeroise: addiu $8, 4 _init: - # Call libsys_init - la $k0, libsys_init + # Call board_init + la $k0, board_init jalr $k0 nop - la $26, main + la $k0, main - jalr $26 + jalr $k0 nop _terminate: nop diff --git a/src/cfiflash.c b/src/cfiflash.c index 8b5d913..2aa0757 100644 --- a/src/cfiflash.c +++ b/src/cfiflash.c @@ -1,5 +1,3 @@ -#include -#include #include "cfiflash.h" uint32_t cfi_get_status(flash_t *pObj) diff --git a/src/hpi.h b/src/hpi.h index fc4704b..e190145 100644 --- a/src/hpi.h +++ b/src/hpi.h @@ -1,6 +1,7 @@ #ifndef HPI_H #define HPI_H +#include // --------------------------------------------------------- // API related // --------------------------------------------------------- diff --git a/src/libsys/boards/denano/board.c b/src/libsys/boards/denano/board.c index 9bd8b0a..0478b3d 100644 --- a/src/libsys/boards/denano/board.c +++ b/src/libsys/boards/denano/board.c @@ -6,6 +6,9 @@ #include #include "board.h" +#include "../../irq.h" +#include "../../uart.h" +#include "../../console.h" #include "../../regdef.h" #define DEBUGGER gdb_stub @@ -23,7 +26,7 @@ const con_if_entry_t con_if_entry[] = {4, "UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar} }; -con_if_t con_if = +const con_if_t con_if = { con_if_entry, ARRAYSIZE(con_if_entry) }; diff --git a/src/libsys/boards/denano/board.h b/src/libsys/boards/denano/board.h index 66d562f..880318b 100644 --- a/src/libsys/boards/denano/board.h +++ b/src/libsys/boards/denano/board.h @@ -14,10 +14,6 @@ #ifndef BOARD_H #define BOARD_H -#include "../../irq.h" -#include "../../uart.h" -#include "../../console.h" - #define CPU_FREQ_HZ 50000000 // --------------------------------------------------------- @@ -61,6 +57,12 @@ #define GPIO_0_MASK_LED 0x000000FF #define GPIO_0_ALIGN_LED 0 +#define GPIO_0_MASK_DIP 0x000000FF +#define GPIO_0_ALIGN_DIP 16 + +#define GPIO_0_MASK_BTN 0x0000001F +#define GPIO_0_ALIGN_BTN 24 + // RTC #define SYS_TIMER_USEC (SYS_IO_BASE + 0x8) #define SYS_TIMER_SEC (SYS_IO_BASE + 0xC) diff --git a/src/libsys/boards/ml402/board.c b/src/libsys/boards/ml402/board.c index 051e598..1207936 100644 --- a/src/libsys/boards/ml402/board.c +++ b/src/libsys/boards/ml402/board.c @@ -6,10 +6,16 @@ #include +#include "../../irq.h" +#include "../../mips_ps2.h" +#include "../../mips_gfx.h" +#include "../../screen.h" +#include "../../uart.h" +#include "../../console.h" #include "board.h" -extern void dbg_init(); -extern void dbg_handler(struct xcptcontext * xcp); +extern int dbg_handler(struct xcptcontext * xcp); +#define DEBUGGER dbg_handler extern uart_if_t uart_if[]; extern ps2_if_t ps2_if[]; @@ -17,7 +23,7 @@ extern vga_if_t vga_if; #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0])) -static const con_if_entry_t con_if_entry[] = +const con_if_entry_t con_if_entry[] = { {0, "stdin", &uart_if[0], NULL, NULL, UART_readchar, NULL}, {1, "stdout", &uart_if[0], NULL, NULL, NULL, UART_writechar}, @@ -29,11 +35,28 @@ static const con_if_entry_t con_if_entry[] = {30, "VGA-0", &vga_if, cg_open, cg_close, NULL, cg_writechar} }; -con_if_t con_if = +const con_if_t con_if = { con_if_entry, ARRAYSIZE(con_if_entry) }; +void handle_debugger_int(struct xcptcontext * xcp) +{ + dbg_handler(xcp); +} + +void dbg_init() +{ + xcpt_register(EXC_ADEL, DEBUGGER); + xcpt_register(EXC_ADES, DEBUGGER); + xcpt_register(EXC_IBE, DEBUGGER); + xcpt_register(EXC_DBE, DEBUGGER); + xcpt_register(EXC_BP, DEBUGGER); + xcpt_register(EXC_RI, DEBUGGER); + xcpt_register(EXC_CPU, DEBUGGER); + xcpt_register(EXC_OV, DEBUGGER); +} + void board_init(void) { uint32_t volatile *pITIM_ctrl = (uint32_t*)SYS_ITIM_CTRL; @@ -54,7 +77,7 @@ void board_init(void) // Initalize debugger dbg_init(); - interrupt_register(2, dbg_handler); + interrupt_register(2, handle_debugger_int); interrupt_enable(2); // flush stdin diff --git a/src/libsys/boards/ml402/board.h b/src/libsys/boards/ml402/board.h index c86b06f..8cabe3a 100644 --- a/src/libsys/boards/ml402/board.h +++ b/src/libsys/boards/ml402/board.h @@ -14,13 +14,6 @@ #ifndef BOARD_H #define BOARD_H -#include "../../irq.h" -#include "../../mips_ps2.h" -#include "../../mips_gfx.h" -#include "../../screen.h" -#include "../../uart.h" -#include "../../console.h" - #define CPU_FREQ_HZ 100000000 // --------------------------------------------------------- diff --git a/src/libsys/mips_ps2.c b/src/libsys/mips_ps2.c index 71b27d6..c078188 100644 --- a/src/libsys/mips_ps2.c +++ b/src/libsys/mips_ps2.c @@ -5,9 +5,9 @@ #include "libsys.h" #include "mips_ps2.h" -uint32_t con_readchar(ps2_if_t *pIF); +uint32_t ps2_readchar(ps2_if_t *pIF); -ps2_if_t ps2_if[2] = +const ps2_if_t ps2_if[2] = { {ps2_type_unknown, (uint32_t*)SYS_PS2_0_STAT, (uint32_t*)SYS_PS2_0_DATA}, {ps2_type_unknown, (uint32_t*)SYS_PS2_1_STAT, (uint32_t*)SYS_PS2_1_DATA} @@ -23,7 +23,7 @@ int PS2_readchar(void const *pInst) assert(pInst); ps2_if_t *pIF = (ps2_if_t*)pInst; - return (int)con_readchar(pIF); + return (int)ps2_readchar(pIF); } void PS2_open(void const *pInst) @@ -396,7 +396,7 @@ static char __findkey(char scancode, int mode) #define ARROW_LEFT (SPECIALKEY|EXTENDED|0x6b) #define ARROW_RIGHT (SPECIALKEY|EXTENDED|0x74) -uint32_t con_readchar(ps2_if_t *pIF) +uint32_t ps2_readchar(ps2_if_t *pIF) { uint8_t c; static char mode = 0; diff --git a/src/libsys/screen.c b/src/libsys/screen.c index d24c607..2de688f 100755 --- a/src/libsys/screen.c +++ b/src/libsys/screen.c @@ -11,7 +11,7 @@ #include #include "screen.h" -vga_if_t vga_if = +const vga_if_t vga_if = { (uint32_t*)SYS_VGA_CTRL, (uint32_t*)SYS_VGA_ASCII, (uint32_t*)SYS_VGA_POSX, (uint32_t*)SYS_VGA_POSY }; diff --git a/src/libsys/uart.c b/src/libsys/uart.c index 656dd45..91c9ea4 100644 --- a/src/libsys/uart.c +++ b/src/libsys/uart.c @@ -4,14 +4,13 @@ * and open the template in the editor. */ -#include #include #include "uart.h" // --------------------------------------------------------------------------------- // Globals // --------------------------------------------------------------------------------- -uart_if_t uart_if[2] = +const uart_if_t uart_if[2] = { {(uint32_t*)SYS_UART0_STAT, (uint32_t*)SYS_UART0_DATA, (uint32_t*)SYS_UART0_BAUD}, {(uint32_t*)SYS_UART1_STAT, (uint32_t*)SYS_UART1_DATA, (uint32_t*)SYS_UART1_BAUD} @@ -21,12 +20,10 @@ uart_if_t uart_if[2] = // Low-level I/O // ------------------------------------ #define CALC_BAUD(b) \ - ((uint32_t)((float)CPU_FREQ_HZ/(16*b) + 0.5f) - 1); + (((10*CPU_FREQ_HZ)/((16*b) + 5))/10 - 1) void UART_setbaud(void const *pInst, uint32_t baudrate) { - assert(pInst); - uart_if_t *pReg = (uart_if_t*)pInst; *pReg->pBAUD = CALC_BAUD(baudrate); @@ -34,20 +31,18 @@ void UART_setbaud(void const *pInst, uint32_t baudrate) int UART_readchar(void const *pInst) { - assert(pInst); - uart_if_t *pReg = (uart_if_t*)pInst; if (SYS_UART_BIT_RX_AVAIL & *pReg->pCTRL) + { return (*pReg->pDATA & 0xFF); + } return -1; } void UART_writechar(void const *pInst, char c) { - assert(pInst); - uart_if_t *pReg = (uart_if_t*)pInst; while((SYS_UART_BIT_TX_HALFFULL & *pReg->pCTRL) != 0); diff --git a/src/test_hpi.c b/src/test_hpi.c index 6eb40fb..8032a65 100644 --- a/src/test_hpi.c +++ b/src/test_hpi.c @@ -3,10 +3,10 @@ #include #include -#include -#include - -#include "cfiflash.h" +#include +#include +#include +#include #include "hpi.h" static volatile uint32_t _g_uart_msg; diff --git a/src/test_irq.c b/src/test_irq.c index 618b7ce..ec27944 100644 --- a/src/test_irq.c +++ b/src/test_irq.c @@ -5,7 +5,10 @@ #include #include -#include "libsys.h" +#include +#include +#include +#include #define PS2_NUM_IF 2 char buffer[16384]; diff --git a/src/test_vga.c b/src/test_vga.c index a6f7c96..5860371 100644 --- a/src/test_vga.c +++ b/src/test_vga.c @@ -5,7 +5,11 @@ #include #include -#include "libsys.h" +#include +#include +#include +#include +#include #define PS2_NUM_IF 2 static volatile int32_t mouse_x; diff --git a/src/testbench.c b/src/testbench.c index 97c4c12..565c332 100644 --- a/src/testbench.c +++ b/src/testbench.c @@ -5,9 +5,11 @@ #include #include #include -#include "libsys.h" -#include "gpio.h" -#include "mips_gfx.h" +#include +#include +#include +#include +#include #define TEST10_ERROR (ERROR | 0x1000) #define TEST11_ERROR (ERROR | 0x1100)