From 7634bf8d41ed9946056cb4527dfc6e5e49285102 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Tue, 6 Apr 2021 13:41:03 +0000 Subject: [PATCH] - refactored git-svn-id: http://moon:8086/svn/mips@149 a8ebac50-d88d-4704-bea3-6648445a41b3 --- make/compile.mk | 39 +++++++++ make/mips_app.mk | 40 ++------- make/mips_lib.mk | 35 ++------ src/Makefile | 2 +- src/hello.c | 2 +- src/libsys/Makefile | 8 +- src/libsys/{ => asm}/kernel.S | 4 +- src/libsys/{ => asm}/regdef.h | 0 src/libsys/{ => asm}/startup.S | 12 +-- src/libsys/{ => asm}/xcpt_asm.h | 0 src/libsys/boards/denano/board.c | 2 +- src/libsys/boards/ml402/board.c | 2 +- src/libsys/boards/sim/board.c | 49 +++++++++++ src/libsys/boards/sim/board.h | 139 +++++++++++++++++++++++++++++++ src/libsys/irq.c | 2 +- src/libsys/libsys.c | 2 +- toolchain/make.sh | 4 +- 17 files changed, 256 insertions(+), 86 deletions(-) create mode 100644 make/compile.mk rename src/libsys/{ => asm}/kernel.S (94%) rename src/libsys/{ => asm}/regdef.h (100%) rename src/libsys/{ => asm}/startup.S (75%) rename src/libsys/{ => asm}/xcpt_asm.h (100%) create mode 100644 src/libsys/boards/sim/board.c create mode 100644 src/libsys/boards/sim/board.h diff --git a/make/compile.mk b/make/compile.mk new file mode 100644 index 0000000..564e193 --- /dev/null +++ b/make/compile.mk @@ -0,0 +1,39 @@ +# environment vaiables read: +# BOARD = {ml402, denano, sim} +# WITH_TLB = {n, y} +# ENDIANESS = {eb, el} +# DEBUGGER = {gdb, mips, rom} + +BOARD ?= ml402 +WITH_TLB ?= n +ENDIANESS ?= eb +DEBUGGER ?= mips + +DEFINES := -DBOARD_$(BOARD) +CCFLAGS := -fno-rtti -fno-use-cxa-atexit -fno-threadsafe-statics +CFLAGS := -fno-exceptions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostartfiles -Os + +CFLAGS_TLB-y := -DSYS_IO_BASE=0xAC000000 -DSDRAM_BASE=0x80000000 -DFLASH_BASE_IO=0xA4000000 -DFLASH_BASE_MEM=0x88000000 +CFLAGS_TLB-n := -DSYS_IO_BASE=0xA0000000 -DSDRAM_BASE=0x40000000 -DFLASH_BASE_IO=0xA4000000 -DFLASH_BASE_MEM=0x00000000 + +CFLAGS-eb =-EB +CFLAGS-el =-EL + +CFLAGS += $(CFLAGS_TLB-$(WITH_TLB)) +CFLAGS += $(CFLAGS-$(ENDIANESS)) +CFLAGS += -msoft-float -march=r3000 +CFLAGS += $(CFLAGS-$(BOARD)) + +FLASHGEN_TLB-y := flashgen_tlb +FLASHGEN_TLB-n := flashgen +PACKHEX := packhex + +AS=mips-elf-as +AR=mips-elf-ar +CC=mips-elf-gcc +LD=mips-elf-gcc +OBJDUMP=mips-elf-objdump +OBJCOPY=mips-elf-objcopy +FLASHGEN=$(FLASHGEN_TLB-$(WITH_TLB)) + + diff --git a/make/mips_app.mk b/make/mips_app.mk index 74d93b9..a75518c 100644 --- a/make/mips_app.mk +++ b/make/mips_app.mk @@ -1,8 +1,8 @@ -# environment vaiables read: -# BOARD = {ml402, denano} -# TLB = {no, yes} -# ENDIANESS = {eb, el} -# DEBUGGER = {gdb, mips, rom} +include $(MIPS_HOME)/make/compile.mk + +CFLAGS-sim := -Os +CFLAGS-ml402 := -g -O2 +CFLAGS-denano := -g -O2 ifeq ($(TLB),yes) SPECNAME=specs_tlb @@ -10,35 +10,11 @@ else SPECNAME=specs endif -ifeq ($(ENDIANESS),eb) - ENDIAN_FLAGS=-EB -else - ENDIAN_FLAGS=-EL -endif - BUILD_DIR=build/$(BOARD)/$(ENDIANESS) LSYS_BUILD_DIR=libsys/build/$(BOARD)/$(ENDIANESS) -CFLAGS :=$(ENDIAN_FLAGS) -ffunction-sections -fdata-sections -Wl,--gc-sections -G 0 -T $(MIPS_HOME)/link/ram.ld -g -msoft-float -O2 -march=r3000 -I. -Ilibsys -Ilibsys/boards/$(BOARD) -L$(LSYS_BUILD_DIR) -Wl,-M -ifeq ($(TLB),yes) - CFLAGS+=-DSYS_IO_BASE=0xAC000000 -DSDRAM_BASE=0x80000000 -DFLASH_BASE_IO=0xA4000000 -DFLASH_BASE_MEM=0x88000000 -else - CFLAGS+=-DSYS_IO_BASE=0xA0000000 -DSDRAM_BASE=0x40000000 -DFLASH_BASE_IO=0xA4000000 -DFLASH_BASE_MEM=0x00000000 -endif +CFLAGS += -Wl,--gc-sections -G 0 -T $(MIPS_HOME)/link/ram.ld +CFLAGS += -I. -Ilibsys -Ilibsys/boards/$(BOARD) -L$(LSYS_BUILD_DIR) $(DEFINES) -ifeq ($(TLB),yes) - FLASHGEN=flashgen_tlb -else - FLASHGEN=flashgen -endif -PACKHEX=packhex - -LIBS=-lm -lc -lsys -lc - -AS=mips-elf-as -AR=mips-elf-ar -CC=mips-elf-gcc -LD=mips-elf-ld -OBJDUMP=mips-elf-objdump -OBJCOPY=mips-elf-objcopy +LIBS=-lsys -lm -lc diff --git a/make/mips_lib.mk b/make/mips_lib.mk index 0ff6833..e3b58ed 100644 --- a/make/mips_lib.mk +++ b/make/mips_lib.mk @@ -1,20 +1,8 @@ -# environment vaiables read: -# BOARD = {ml402, denano} -# TLB = {no, yes} -# ENDIANESS = {eb, el} -# DEBUGGER = {gdb, mips, rom} +include $(MIPS_HOME)/make/compile.mk -BOARD ?= ml402 -TLB ?= no -ENDIANESS ?= eb -DEBUGGER ?= mips - - -ifeq ($(ENDIANESS),el) - ENDIAN_FLAGS=-EL -else - ENDIAN_FLAGS=-EB -endif +CFLAGS-sim := -Os +CFLAGS-ml402 := -g -O2 +CFLAGS-denano := -g -O2 ifeq ($(DEBUGGER),gdb) DBG_FLAGS := -DWITH_GDB_STUB @@ -29,21 +17,8 @@ ifeq ($(DEBUGGER),rom) endif -CFLAGS=$(ENDIAN_FLAGS) -ffunction-sections -fdata-sections -g -msoft-float -O2 -march=r3000 -I. -Iboards/$(BOARD) -D$(BOARD) $(DBG_FLAGS) - -ifeq ($(TLB),yes) - CFLAGS+=-DSYS_IO_BASE=0xAC000000 -DSDRAM_BASE=0x80000000 -DFLASH_BASE_IO=0xA4000000 -DFLASH_BASE_MEM=0x88000000 -else - CFLAGS+=-DSYS_IO_BASE=0xA0000000 -DSDRAM_BASE=0x40000000 -DFLASH_BASE_IO=0xA4000000 -DFLASH_BASE_MEM=0x00000000 -endif +CFLAGS += -I. -Iboards/$(BOARD) $(DBG_FLAGS) $(DEFINES) BUILD_DIR=./build/$(BOARD)/$(ENDIANESS) -AS=mips-elf-as -AR=mips-elf-ar -CC=mips-elf-gcc -LD=mips-elf-ld -OBJDUMP=mips-elf-objdump -OBJCOPY=mips-elf-objcopy -FLASHGEN=flashgen diff --git a/src/Makefile b/src/Makefile index 39b8376..fc7481c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,7 +5,7 @@ include ../make/mips_app.mk PROG-ml402 = $(addprefix $(BUILD_DIR)/, hello.elf testbench.elf test_irq.elf dhry.elf queens.elf stanford.elf paranoia.elf rmd160_test.elf Bessel.elf whet.elf phrasen.elf dttl.elf richards_benchmark.elf test_exception.elf life.elf r3.elf gunzip.elf basic_math.elf jman_patches.elf jman_patchmeshes.elf jman_polys.elf test_hpi.elf test_vga.elf test_fft.elf) PROG-denano = $(addprefix $(BUILD_DIR)/, hello.elf dhry.elf queens.elf stanford.elf paranoia.elf rmd160_test.elf Bessel.elf whet.elf phrasen.elf dttl.elf richards_benchmark.elf test_exception.elf testbench_denano.elf) -PROG-sim = $(addprefix $(BUILD_DIR)/, hello.elf ICacheTest.elf) +PROG-sim = $(addprefix $(BUILD_DIR)/, hello.elf) CFLAGS-sim := -O0 CFLAGS += $(CFLAGS-$(BOARD)) diff --git a/src/hello.c b/src/hello.c index c63b27f..9243811 100644 --- a/src/hello.c +++ b/src/hello.c @@ -2,5 +2,5 @@ int main() { - printf("Hello, world!\n"); + printf("Hello, MIPS-world!\n"); } diff --git a/src/libsys/Makefile b/src/libsys/Makefile index 416f306..b271cf8 100644 --- a/src/libsys/Makefile +++ b/src/libsys/Makefile @@ -1,5 +1,5 @@ # environment vaiables read: -# BOARD = {ml402, denano} +# BOARD = {ml402, denano, sim} # TLB = {no, yes} # ENDIANESS = {eb, el} # DEBUGGER = {gdb, mips, rom} @@ -13,7 +13,7 @@ include ../../make/mips_lib.mk OBJS-ml402=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o cop0.o irq.o $(DBG_OBJ) console.o uart.o board.o gpio.o mips_ps2.o mips_gfx.o screen.o) OBJS-denano=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o cop0.o irq.o $(DBG_OBJ) console.o uart.o board.o gpio.o) -OBJS-sim=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o cop0.o irq.o $(DBG_OBJ) console.o uart.o board.o gpio.o) +OBJS-sim=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o cop0.o irq.o console.o uart.o board.o gpio.o) all: $(BUILD_DIR) $(BUILD_DIR)/libsys.a @@ -28,8 +28,8 @@ $(BUILD_DIR)/board.o : boards/$(BOARD)/board.c $(BUILD_DIR)/libsys.a: $(OBJS-$(BOARD)) $(AR) -r $(BUILD_DIR)/libsys.a $(OBJS-$(BOARD)) - $(CC) $(CFLAGS) -G 0 -c -o $(BUILD_DIR)/startup.o startup.S - $(CC) $(CFLAGS) -G 0 -c -o $(BUILD_DIR)/kernel.o kernel.S + $(CC) $(CFLAGS) -G 0 -c -o $(BUILD_DIR)/startup.o asm/startup.S + $(CC) $(CFLAGS) -G 0 -c -o $(BUILD_DIR)/kernel.o asm/kernel.S $(BUILD_DIR): mkdir -p $(BUILD_DIR) diff --git a/src/libsys/kernel.S b/src/libsys/asm/kernel.S similarity index 94% rename from src/libsys/kernel.S rename to src/libsys/asm/kernel.S index ef08cb4..c8c17da 100644 --- a/src/libsys/kernel.S +++ b/src/libsys/asm/kernel.S @@ -1,5 +1,5 @@ -#include -#include +#include "regdef.h" +#include "xcpt_asm.h" .text .section .exc_vect, "ax" diff --git a/src/libsys/regdef.h b/src/libsys/asm/regdef.h similarity index 100% rename from src/libsys/regdef.h rename to src/libsys/asm/regdef.h diff --git a/src/libsys/startup.S b/src/libsys/asm/startup.S similarity index 75% rename from src/libsys/startup.S rename to src/libsys/asm/startup.S index 832e9e8..e716ce9 100644 --- a/src/libsys/startup.S +++ b/src/libsys/asm/startup.S @@ -1,4 +1,4 @@ -#include +#include "regdef.h" .file "startup.S" .section .rodata @@ -8,23 +8,15 @@ argv: .word argv0 .text .section .start, "ax" - .extern _init + .extern board_init .align 2 .set noreorder _start: la sp, stack_ptr la gp, _gp - la ra, _zero_bss - j _init nop - .text - .globl _zero_bss - .extern board_init - .align 2 - .set noreorder - _zero_bss: # zero bss la $8, __bss_start diff --git a/src/libsys/xcpt_asm.h b/src/libsys/asm/xcpt_asm.h similarity index 100% rename from src/libsys/xcpt_asm.h rename to src/libsys/asm/xcpt_asm.h diff --git a/src/libsys/boards/denano/board.c b/src/libsys/boards/denano/board.c index 47fdc88..7df36b7 100644 --- a/src/libsys/boards/denano/board.c +++ b/src/libsys/boards/denano/board.c @@ -9,7 +9,7 @@ #include "../../irq.h" #include "../../uart.h" #include "../../console.h" -#include "../../regdef.h" +#include "../../asm/regdef.h" extern uart_if_t uart_if[]; diff --git a/src/libsys/boards/ml402/board.c b/src/libsys/boards/ml402/board.c index b6b4c20..0e6569c 100644 --- a/src/libsys/boards/ml402/board.c +++ b/src/libsys/boards/ml402/board.c @@ -9,7 +9,7 @@ #include "../../irq.h" #include "../../uart.h" #include "../../console.h" -#include "../../regdef.h" +#include "../../asm/regdef.h" extern uart_if_t uart_if[]; #ifdef WITH_ROM_DEBUGGER diff --git a/src/libsys/boards/sim/board.c b/src/libsys/boards/sim/board.c new file mode 100644 index 0000000..74722f5 --- /dev/null +++ b/src/libsys/boards/sim/board.c @@ -0,0 +1,49 @@ +/* + * 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 "board.h" +#include "../../irq.h" +#include "../../uart.h" +#include "../../console.h" +#include "../../asm/regdef.h" + +extern uart_if_t uart_if[]; + +#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0])) + +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}, + {2, "stderr", &uart_if[0], NULL, NULL, NULL, UART_writechar}, + {3, "UART-0", &uart_if[0], NULL, NULL, UART_readchar, UART_writechar}, + {4, "UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar} +}; + +const con_if_t con_if = +{ + con_if_entry, ARRAYSIZE(con_if_entry) +}; + + +void board_init(void) +{ + uint32_t volatile *pITIM_ctrl = (uint32_t*)SYS_ITIM_CTRL; + + // Disable timers + *pITIM_ctrl = 0; + + // Setup syscall support + syscalls_init(); + + // Setup interrupt support + interrupt_init(); + interrupt_global_enable(); + + // Do some initializations here +} + diff --git a/src/libsys/boards/sim/board.h b/src/libsys/boards/sim/board.h new file mode 100644 index 0000000..674a752 --- /dev/null +++ b/src/libsys/boards/sim/board.h @@ -0,0 +1,139 @@ +/* + * 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. + */ + +/* + * File: board.h + * Author: jens + * + * Created on 8. Januar 2017, 11:33 + */ + +#ifndef BOARD_H +#define BOARD_H + +#define CPU_FREQ_HZ 100000000 +#define UART_STDIO 0 +#define UART_DEBUGGER 1 + +// --------------------------------------------------------- +// IRQs +// --------------------------------------------------------- +#define SYS_INT_SOFT_0 0 +#define SYS_INT_SOFT_1 1 +#define SYS_INT_TIMER 2 +#define SYS_INT_UART0 3 +#define SYS_INT_UART1 4 +#define SYS_INT_FLASH 5 + +// --------------------------------------------------------- +// Memory-mapped registers +// --------------------------------------------------------- +#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 + +// Backwards compatibility +#define SYS_FLASH_IO FLASH_BASE_IO +#define SYS_FLASH_MEM FLASH_BASE_MEM + +// GPIO +#define SYS_GPIO_0_BASE (SYS_IO_BASE + 0) +#define SYS_GPIO_0_DATA (SYS_GPIO_0_BASE + 0) +#define SYS_GPIO_0_DIR (SYS_GPIO_0_BASE + 4) + +#define GPIO_0_DFLT_DIR 0x00000000 // Inputs +#define GPIO_0_DFLT_DATA 0x00000000 + +#define GPIO_0_MASK_LED 0x000000FF +#define GPIO_0_ALIGN_LED 0 + +#define GPIO_0_MASK_DIP 0x0000000F +#define GPIO_0_ALIGN_DIP 8 + +#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) + +// 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) + +// UARTs +#define SYS_UART_BIT_TX_HALFFULL 0x00000001 +#define SYS_UART_BIT_TX_FULL 0x00000002 +#define SYS_UART_BIT_RX_HALFFULL 0x00000004 +#define SYS_UART_BIT_RX_FULL 0x00000008 +#define SYS_UART_BIT_RX_AVAIL 0x00000010 +#define SYS_UART_BIT_TX_INTEN 0x00000020 +#define SYS_UART_BIT_RX_INTEN 0x00000040 +#define SYS_UART_BIT_TX_IRQ 0x00000100 +#define SYS_UART_BIT_RX_IRQ 0x00000200 +#define SYS_UART_DATA SYS_UART0_DATA +#define SYS_UART_STAT SYS_UART0_STAT +#define SYS_UART_BAUD SYS_UART0_BAUD +#define SYS_UART0_DATA (SYS_IO_BASE + 0x10000) +#define SYS_UART0_STAT (SYS_IO_BASE + 0x10004) +#define SYS_UART0_BAUD (SYS_IO_BASE + 0x10008) +#define SYS_UART1_DATA (SYS_IO_BASE + 0x30000) +#define SYS_UART1_STAT (SYS_IO_BASE + 0x30004) +#define SYS_UART1_BAUD (SYS_IO_BASE + 0x30008) + +// SPI +#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) + +#ifdef __cplusplus +extern "C" { +#endif + + + + +#ifdef __cplusplus +} +#endif + +#endif /* BOARD_H */ + diff --git a/src/libsys/irq.c b/src/libsys/irq.c index 18937c5..ebe2ea5 100644 --- a/src/libsys/irq.c +++ b/src/libsys/irq.c @@ -1,6 +1,6 @@ #include #include -#include "regdef.h" +#include "asm/regdef.h" #include "xcpt.h" #include "irq.h" diff --git a/src/libsys/libsys.c b/src/libsys/libsys.c index 1500857..e9fb48f 100644 --- a/src/libsys/libsys.c +++ b/src/libsys/libsys.c @@ -6,7 +6,7 @@ #include #include #include "libsys.h" -#include "regdef.h" +#include "asm/regdef.h" static uint32_t critical_nesting_counter = 0; diff --git a/toolchain/make.sh b/toolchain/make.sh index 4438e7b..46a7b25 100644 --- a/toolchain/make.sh +++ b/toolchain/make.sh @@ -32,7 +32,7 @@ if [ ! -e ./$SRC_BINUTILS-build ]; then echo Building $SRC_BINUTILS mkdir -p $SRC_BINUTILS-build cd $SRC_BINUTILS-build - ../$SRC_BINUTILS/configure --target=$TARGET --prefix=$PREFIX || exit 1 + ../$SRC_BINUTILS/configure --target=$TARGET --prefix=$PREFIX --disable-nls --disable-werror || exit 1 make -j4 || exit 1 make install || exit 1 cd .. @@ -177,7 +177,7 @@ if [ ! -e ./$SRC_GCC-build ]; then echo Building $SRC_GCC mkdir -p $SRC_GCC-build cd $SRC_GCC-build - ../$SRC_GCC/configure --target=$TARGET --prefix=$PREFIX --with-gmp=$PREFIX --with-mpfr=$PREFIX --with-mpc=$PREFIX --with-float=soft --with-newlib --verbose --enable-languages="c,c++" --with-gnu-as --with-gnu-ld || exit 1 + ../$SRC_GCC/configure --target=$TARGET --prefix=$PREFIX --with-gmp=$PREFIX --with-mpfr=$PREFIX --with-mpc=$PREFIX --with-float=soft --with-newlib --verbose --enable-languages="c,c++" --with-gnu-as --with-gnu-ld --disable-nls --disable-threads --disable-multilib --without-headers --disable-shared --enable-lto -disable-werror || exit 1 make -j4 all || exit 1 make info || exit 1 make install || exit 1