From 9391e0cd3443adc0c39d93cac34889f289109506 Mon Sep 17 00:00:00 2001 From: DizzyOfCRN Date: Sun, 16 Mar 2014 09:19:25 +0000 Subject: [PATCH] - More sunifigations and hardware definitions - (0xffff 0000 - 0xffff ffff) contains the BROM code. Preserve memory at top of the DRAM just before kernel for vector table, MMU can then map the vector table at 0xffff 0000 to point at the DRAM location. Not sure if some linker script magic would be better suited for creating the actual vector table, now assuming it will be created with pc-relative loads. - End of DRAM (free space up until the vector table) could be the early stack pointer. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@48851 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- arch/arm-sun4i/boot/boot.c | 14 ++++++-- arch/arm-sun4i/boot/elf.c | 32 +++++++---------- arch/arm-sun4i/boot/ldscript.lds | 5 ++- arch/arm-sun4i/boot/mmakefile.src | 4 +-- arch/arm-sun4i/boot/serialdebug.c | 6 ++-- arch/arm-sun4i/boot/uEnv.txt | 2 +- arch/arm-sun4i/include/hardware/tmr.h | 63 ++++++++++++++++++++++++++++++++++ arch/arm-sun4i/include/hardware/uart.h | 40 ++++++++++----------- arch/arm-sun4i/kernel/kernel_arch.h | 2 +- arch/arm-sun4i/kernel/kernel_debug.c | 6 ++-- 10 files changed, 117 insertions(+), 57 deletions(-) create mode 100644 arch/arm-sun4i/include/hardware/tmr.h diff --git a/arch/arm-sun4i/boot/boot.c b/arch/arm-sun4i/boot/boot.c index 83702a6eae..dafd6fc751 100644 --- a/arch/arm-sun4i/boot/boot.c +++ b/arch/arm-sun4i/boot/boot.c @@ -194,11 +194,21 @@ void boot(uintptr_t dummy, uintptr_t arch, struct tag * atags) { kprintf("[BOOT] Bootstrap @ %08x-%08x\n", &__bootstrap_start, &__bootstrap_end); kprintf("[BOOT] Topmost address for kernel: %p\n", *mem_upper); + if(*mem_upper){ + if((*mem_upper &0x0000ffff)==0x0000ffff) { + *mem_upper = (*mem_upper & 0xffff0000); + }else{ + *mem_upper = (*mem_upper & 0xffff0000) - 0x10000; + } + } + + kprintf("[BOOT] Topmost address for kernel: %p\n", *mem_upper); + + if (*mem_upper) { *mem_upper = *mem_upper & ~4095; unsigned long kernel_phys = *mem_upper; -// unsigned long kernel_phys = *mem_lower; unsigned long kernel_virt = kernel_phys; unsigned long total_size_ro, total_size_rw; @@ -259,12 +269,10 @@ void boot(uintptr_t dummy, uintptr_t arch, struct tag * atags) { } kernel_phys = *mem_upper - total_size_ro - total_size_rw; -// kernel_phys = *mem_lower; kernel_virt = 0xffff0000 - total_size_ro - total_size_rw; /* Adjust "top of memory" pointer */ *mem_upper = kernel_phys; -// *mem_lower = kernel_phys + total_size_ro + total_size_rw; kprintf("[BOOT] Physical address of kernel: %p\n", kernel_phys); kprintf("[BOOT] Virtual address of kernel: %p\n", kernel_virt); diff --git a/arch/arm-sun4i/boot/elf.c b/arch/arm-sun4i/boot/elf.c index 8ab8b20c82..9cdb8d7bb6 100644 --- a/arch/arm-sun4i/boot/elf.c +++ b/arch/arm-sun4i/boot/elf.c @@ -176,16 +176,11 @@ static int load_hunk(void *file, struct sheader *sh) sh->addr = ptr; /* copy block of memory from ELF file if it exists */ - if (sh->type != SHT_NOBITS) - { - read_block(file, sh->offset, (void *)((unsigned long)sh->addr), - sh->size); - } - else - { + if (sh->type != SHT_NOBITS) { + read_block(file, sh->offset, (void *)((unsigned long)sh->addr), sh->size); + } else { bzero(ptr, sh->size); - bss_tracker->addr = - (void *)((unsigned long)ptr + virtoffset); + bss_tracker->addr = (void *)((unsigned long)ptr + virtoffset); bss_tracker->length = sh->size; bss_tracker++; /* @@ -358,18 +353,15 @@ int loadElf(void *elf_file) else if (sh[i].flags & SHF_ALLOC) { /* Yup, it does. Load the hunk */ - if (!load_hunk(elf_file, &sh[i])) - { + if (!load_hunk(elf_file, &sh[i])) { return 0; - } - else - { - if (sh[i].size) - { - kprintf("[BOOT] ELF: %s section loaded at %p (Virtual addr: %p)\n", - sh[i].flags & SHF_WRITE ? "RW":"RO", - sh[i].addr, - sh[i].addr + virtoffset); + } else { + if (sh[i].size) { + kprintf("[BOOT] ELF: %s section loaded at %p (Virtual addr: %p-%p)\n", + sh[i].flags & SHF_WRITE ? "RW":"RO", + sh[i].addr, + sh[i].addr + virtoffset, + sh[i].addr + sh[i].size + virtoffset); } } } diff --git a/arch/arm-sun4i/boot/ldscript.lds b/arch/arm-sun4i/boot/ldscript.lds index 4a2d33d4a0..c70b8e288c 100644 --- a/arch/arm-sun4i/boot/ldscript.lds +++ b/arch/arm-sun4i/boot/ldscript.lds @@ -1,9 +1,8 @@ FORCE_COMMON_ALLOCATION - +ENTRY(bootstrap) SECTIONS { - . = 0x75f00000; - + . = 0x40010000; __bootstrap_start = . ; .text ALIGN(4096) : diff --git a/arch/arm-sun4i/boot/mmakefile.src b/arch/arm-sun4i/boot/mmakefile.src index b01401f48c..1cedf5a453 100644 --- a/arch/arm-sun4i/boot/mmakefile.src +++ b/arch/arm-sun4i/boot/mmakefile.src @@ -35,11 +35,11 @@ kernel-image-sun4i-arm: sun4i-bootfiles: $(AROSDIR)/boot/arosboot $(AROSDIR)/boot/arosboot: $(foreach f, $(FILES), $(TARGETDIR)/$(f).o $(TARGETDIR)/$(f).d) $(TARGETDIR)/kernel.bin.o - $(KERNEL_LD) -s --entry=bootstrap --script=$(SRCDIR)/$(CURDIR)/ldscript.lds $(foreach f, $(FILES), $(TARGETDIR)/$(f).o) $(TARGETDIR)/kernel.bin.o -L$(AROS_LIB) -lstdc.static -laeabi -o $@ + $(KERNEL_LD) -s --entry=bootstrap --script=$(SRCDIR)/$(CURDIR)/ldscript.lds $(foreach f, $(FILES), $(TARGETDIR)/$(f).o) $(TARGETDIR)/kernel.bin.o -Map=$(AROSDIR)/kernel.map -L$(AROS_LIB) -lstdc.static -laeabi -o $@ $(OBJCOPY) -O binary $@ $@.bin gzip $@.bin mv $@.bin.gz $@.bin - mkimage -A arm -O linux -T kernel -C gzip -a 0x75f00000 -e 0x75f00000 -n "AROS Boot" -d $@.bin $(AROSDIR)/boot/uImage-aros + mkimage -A arm -O linux -T kernel -C gzip -a 0x40010000 -n "AROS Boot" -d $@.bin $(AROSDIR)/boot/uImage-aros $(TARGETDIR)/kernel.bin.o: $(AROSDIR)/boot/aros-sun4i cp $(AROSDIR)/boot/aros-sun4i $(TARGETDIR)/kernel.bin diff --git a/arch/arm-sun4i/boot/serialdebug.c b/arch/arm-sun4i/boot/serialdebug.c index 6f58d86fe5..1caccea649 100644 --- a/arch/arm-sun4i/boot/serialdebug.c +++ b/arch/arm-sun4i/boot/serialdebug.c @@ -16,16 +16,16 @@ static inline void waitBusy() { volatile struct UART *UARTDEBUG; UARTDEBUG = SUN4I_UARTDEBUG_BASE; - while ((UARTDEBUG->lsr & LSR_THRE) == 0); + while ((UARTDEBUG->LSR & LSR_THRE) == 0); } static inline void putByte(uint8_t chr) { volatile struct UART *UARTDEBUG; UARTDEBUG = SUN4I_UARTDEBUG_BASE; - UARTDEBUG->thr = (uint32_t) chr; + UARTDEBUG->THR = (uint32_t) chr; // if (chr == '\n') { -// UARTDEBUG->thr = (uint32_t) '\r'; +// UARTDEBUG->THR = (uint32_t) '\r'; // } } void putBytes(const char *str) { diff --git a/arch/arm-sun4i/boot/uEnv.txt b/arch/arm-sun4i/boot/uEnv.txt index 84bb9fb998..5cb9065d28 100644 --- a/arch/arm-sun4i/boot/uEnv.txt +++ b/arch/arm-sun4i/boot/uEnv.txt @@ -1,4 +1,4 @@ bootargs=console=ttyO0,115200n8 root=/dev/mmcblk0p0 rootwait -bootcmd=mmc rescan; fatload mmc 0 0x40000000 boot/uImage-aros; fatload mmc 0 0x41000000 boot/uInitrd-aros; bootm 0x40000000 0x41000000 +bootcmd=mmc rescan; fatload mmc 0 0x48000000 boot/uImage-aros; fatload mmc 0 0x49000000 boot/uInitrd-aros; bootm 0x48000000 0x49000000 uenvcmd=boot diff --git a/arch/arm-sun4i/include/hardware/tmr.h b/arch/arm-sun4i/include/hardware/tmr.h new file mode 100644 index 0000000000..50372c86f4 --- /dev/null +++ b/arch/arm-sun4i/include/hardware/tmr.h @@ -0,0 +1,63 @@ +/* + Copyright © 2014, The AROS Development Team. All rights reserved. + $Id$ + + Desc: sun4i timer registers + Lang: english +*/ + +#ifndef +#define + +#ifndef _INTTYPES_H +#include +#endif + +#define SUN4I_TMR_BASE 0x01c20c00 + +struct TMR { + uint32_t IRQ_EN; + uint32_t IRQ_STA; + uint32_t 0_CTRL; + uint32_t 0_INTR_VAL; + uint32_t 0_CUR_VAL; + uint32_t 1_CTRL; + uint32_t 1_INTR_VAL; + uint32_t 1_CUR_VAL; + uint32_t 2_CTRL; + uint32_t 2_INTR_VAL; + uint32_t 2_CUR_VAL; + uint32_t 3_CTRL; + uint32_t 3_INTR_VAL; + uint32_t 3_CUR_VAL; + uint32_t 4_CTRL; + uint32_t 4_INTR_VAL; + uint32_t 4_CUR_VAL; + uint32_t 5_CTRL; + uint32_t 5_INTR_VAL; + uint32_t 5_CUR_VAL; + uint32_t AVS_CTRL; + uint32_t AVS0; + uint32_t AVS1; + uint32_t AVS_DIV; + uint32_t WDT_CTRL; + uint32_t WDT_MODE; + uint32_t CNT64_CTRL; + uint32_t CNT64_LO; + uint32_t CNT64_HI; + uint32_t 32KHZ_OSC_CTRL; + uint32_t RTC_DATE; + uint32_t RTC_TIME; + uint32_t ALARM_CNT; + uint32_t ALARM_WK; + uint32_t ALARM_EN; + uint32_t ALARM_IRQ_EN; + uint32_t ALARM_IRQ_STA; + uint32_t GP0; + uint32_t GP1; + uint32_t GP2; + uint32_t GP3; + uint32_t CPU_CFG; +}__attribute__((__packed__)); + +#endif diff --git a/arch/arm-sun4i/include/hardware/uart.h b/arch/arm-sun4i/include/hardware/uart.h index f87f3d2afc..634aaad0cb 100644 --- a/arch/arm-sun4i/include/hardware/uart.h +++ b/arch/arm-sun4i/include/hardware/uart.h @@ -21,31 +21,29 @@ #define SUN4I_UART5_BASE 0x01c29400 #define SUN4I_UART6_BASE 0x01c29800 #define SUN4I_UART7_BASE 0x01c29c00 -#define SUN4I_PS2_0_BASE 0x01c2a000 -#define SUN4I_PS2_1_BASE 0x01c2a400 struct UART { - uint32_t rbrthrdlb; - uint32_t ierdmb; - uint32_t iirfcrafr; - uint32_t lcr; - uint32_t mcr; - uint32_t lsr; - uint32_t msr; - uint32_t scr; - uint32_t reserved[2]; - uint32_t dsr; - uint32_t dcr; + uint32_t RBRTHRDLB; + uint32_t IERDMB; + uint32_t IIRFCRAFR; + uint32_t LCR; + uint32_t MCR; + uint32_t LSR; + uint32_t MSR; + uint32_t SCR; + uint32_t UART_RESERVED_1[2]; + uint32_t DSR; + uint32_t DCR; }__attribute__((__packed__)); -#define rbr rbrthrdlb -#define thr rbrthrdlb -#define dll rbrthrdlb -#define ier ierdmb -#define dlm ierdmb -#define iir iirfcrafr -#define fcr iirfcrafr -#define afr iirfcrafr +#define RBR RBRTHRDLB +#define THR RBRTHRDLB +#define DLL RBRTHRDLB +#define IER IERDMB +#define DLM IERDMB +#define IIR IIRFCRAFR +#define FCR IIRFCRAFR +#define AFR IIRFCRAFR #define LSR_DR 0x01 #define LSR_OE 0x02 diff --git a/arch/arm-sun4i/kernel/kernel_arch.h b/arch/arm-sun4i/kernel/kernel_arch.h index f943b528bb..abbfecb273 100644 --- a/arch/arm-sun4i/kernel/kernel_arch.h +++ b/arch/arm-sun4i/kernel/kernel_arch.h @@ -9,6 +9,6 @@ #ifndef KERNEL_ARCH_H_ #define KERNEL_ARCH_H_ -#define IRQ_COUNT 120 +#define IRQ_COUNT 95 #endif /* KERNEL_ARCH_H_ */ diff --git a/arch/arm-sun4i/kernel/kernel_debug.c b/arch/arm-sun4i/kernel/kernel_debug.c index 23feecde4b..de2a670611 100644 --- a/arch/arm-sun4i/kernel/kernel_debug.c +++ b/arch/arm-sun4i/kernel/kernel_debug.c @@ -20,16 +20,16 @@ static inline void waitBusy() { volatile struct UART *UARTDEBUG; UARTDEBUG = SUN4I_UARTDEBUG_BASE; - while ((UARTDEBUG->lsr & LSR_THRE) == 0); + while ((UARTDEBUG->LSR & LSR_THRE) == 0); } static inline void putByte(uint8_t chr) { volatile struct UART *UARTDEBUG; UARTDEBUG = SUN4I_UARTDEBUG_BASE; - UARTDEBUG->thr = (uint32_t) chr; + UARTDEBUG->THR = (uint32_t) chr; // if (chr == '\n') { -// UARTDEBUG->thr = (uint32_t) '\r'; +// UARTDEBUG->THR = (uint32_t) '\r'; // } } -- 2.11.4.GIT