From: John Hodge Date: Sun, 25 Sep 2011 09:14:07 +0000 (+0800) Subject: Kernel/arm7 - Fiddling with PCI etc X-Git-Tag: rel0.11~62 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=5e9042e320d0a24d1691bcd6845936879238e812;p=tpg%2Facess2.git Kernel/arm7 - Fiddling with PCI etc - PCI is currently disabled because -pb boards don't implement it --- diff --git a/Kernel/Makefile b/Kernel/Makefile index 3ae93776..14bae507 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -30,9 +30,12 @@ ifeq ($(DEBUG_BUILD),yes) endif ifeq ($(AS_SUFFIX),) - AS_SUFFIX = s + AS_SUFFIX = S endif +BUILDINFO_OBJ := $(OBJDIR)buildinfo.o$(OBJSUFFIX) +BUILDINFO_SRC := $(OBJDIR)buildinfo.c$(OBJSUFFIX) + OBJ := $(addprefix arch/$(ARCHDIR)/,$(A_OBJ)) OBJ += heap.o drvutil.o logging.o debug.o lib.o adt.o time.o OBJ += messages.o modules.o syscalls.o system.o threads.o @@ -58,13 +61,15 @@ DEPFILES := $(DEPFILES:%.o$(OBJSUFFIX)=%.dep$(OBJSUFFIX)) SRCFILES = $(OBJ:$(OBJDIR)%.o$(OBJSUFFIX)=%.c) SRCFILES := $(SRCFILES:$(OBJDIR)%.ao$(OBJSUFFIX)=%.$(AS_SUFFIX)) +OBJ += $(BUILDINFO_OBJ) + .PHONY: all clean install apidoc all: $(BIN) clean: # $(RM) $(BIN) ../Acess2.$(ARCH).gz $(BIN).dsm ../Map.$(ARCH).txt LineCounts.$(ARCH).txt $(OBJ) $(DEPFILES) - @$(RM) $(BIN) ../Acess2.$(ARCH).gz $(BIN).dsm ../Map.$(ARCH).txt LineCounts.$(ARCH).txt -r $(OBJDIR) $(OBJ) $(DEPFILES) + @$(RM) $(BIN) ../Acess2.$(ARCH).gz $(BIN).dsm ../Map.$(ARCH).txt LineCounts.$(ARCH).txt -r $(OBJDIR) $(OBJ) $(DEPFILES) $(BUILDINFO_SRC) install: $(BIN) cp $(BIN) $(BIN)_ @@ -107,8 +112,12 @@ include/syscalls.h include/syscalls.inc.asm: syscalls.lst Makefile GenSyscalls.p Makefile: ../Makefile.cfg arch/$(ARCHDIR)/Makefile -# HACK - Rebuild proc when the buildnum changes -#$(OBJDIR)drv/proc.o$(OBJSUFFIX): Makefile.BuildNum.$(ARCH) +.PHONY: $(BUILDINFO_SRC) +$(BUILDINFO_SRC): + @echo "const char * const gsGitHash = \""`git log -n 1 | head -n 1 | awk '{print $$1}'`"\";" > $@ + @echo "const int giBuildNumber = $(BUILD_NUM);" >> $@ +$(BUILDINFO_OBJ): $(BUILDINFO_SRC) + @$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< # Dependency Files -include $(DEPFILES) diff --git a/Kernel/arch/arm7/debug.c b/Kernel/arch/arm7/debug.c index 12794983..d75048ed 100644 --- a/Kernel/arch/arm7/debug.c +++ b/Kernel/arch/arm7/debug.c @@ -10,7 +10,7 @@ // === CONSTANTS === //#define UART0_BASE 0x10009000 -#define UART0_BASE 0xF0000000 // Boot time mapped +#define UART0_BASE 0xF1000000 // Boot time mapped // === PROTOTYPES === void KernelPanic_SetMode(void); diff --git a/Kernel/arch/arm7/pci.c b/Kernel/arch/arm7/pci.c index 62b7deaf..0d25049f 100644 --- a/Kernel/arch/arm7/pci.c +++ b/Kernel/arch/arm7/pci.c @@ -3,6 +3,12 @@ */ #include +// Realview +//#define PCI_BASE 0x60000000 + +//#define PCI_BASE 0xF0400000 // VMM Mapping +#define PCI_BASE 0 + // === PROTOTYPES === #if 1 void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data); @@ -14,13 +20,21 @@ Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset); // === CODE === void PCI_CfgWriteDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset, Uint32 data) { - // TODO: Use PCI_ADDRESS constant + #if PCI_BASE + Uint32 address = PCI_BASE | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC); + *(Uint32*)(address) = data; + #else + #endif } Uint32 PCI_CfgReadDWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) { - // TODO: Locate PCI base and read/write data + #if PCI_BASE + Uint32 address = PCI_BASE | ((Uint)bus<<16) | ((Uint)dev<<11) | ((Uint)func<<8) | (offset&0xFC); + return *(Uint32*)address; + #else return 0xFFFFFFFF; + #endif } Uint16 PCI_CfgReadWord(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset) diff --git a/Kernel/arch/arm7/start.S b/Kernel/arch/arm7/start.S new file mode 100644 index 00000000..d93033ea --- /dev/null +++ b/Kernel/arch/arm7/start.S @@ -0,0 +1,120 @@ +KERNEL_BASE = 0x80000000 +PCI_PADDR = 0x60000000 @ Realview +UART0_PADDR = 0x10009000 @ Realview +@ +@ Exception defs taken from ARM DDI 0406B +@ +.section .init +interrupt_vector_table: + b _start @ Reset + b . @ #UD + b SyscallHandler @ SVC (SWI assume) + b . @ Prefetch abort + b . @ Data abort + b . @ Not Used + b IRQHandler @ IRQ + b . @ FIQ (Fast interrupt) + +.globl _start +_start: + ldr r0, =kernel_table0-KERNEL_BASE + mcr p15, 0, r0, c2, c0, 1 @ Set TTBR1 to r0 + mcr p15, 0, r0, c2, c0, 0 @ Set TTBR0 to r0 too (for identity) + + mov r0, #1 + mcr p15, 0, r0, c2, c0, 2 @ Set TTCR to 1 (50/50 split) + + mov r0, #3 + mcr p15, 0, r0, c3, c0, 0 @ Set Domain 0 to Manager + + mrc p15, 0, r0, c1, c0, 0 + orr r0, r0, #1 + orr r0, r0, #1 << 23 + mcr p15, 0, r0, c1, c0, 0 + + ldr sp, =stack+0x10000 @ Set up stack + ldr r0, =kmain + mov pc, r0 +1: b 1b @ Infinite loop +_ptr_kmain: + .long kmain + +.comm stack, 0x10000 @ ; 64KiB Stack + +SyscallHandler: + b . +.section .padata +.globl kernel_table0 + +kernel_table0: + .long 0x00000002 @ Identity map the first 1 MiB + .rept 0x800 - 1 + .long 0 + .endr + .long 0x00000002 @ Map first 4 MiB to 2GiB + .long 0x00100002 @ + .long 0x00200002 @ + .long 0x00300002 @ + .rept 0xF00 - 0x800 - 4 + .long 0 + .endr +#if PCI_PADDR + .long PCI_PADDR + 0*(1 << 20) + 2 @ Map PCI config space + .long PCI_PADDR + 1*(1 << 20) + 2 + .long PCI_PADDR + 2*(1 << 20) + 2 + .long PCI_PADDR + 3*(1 << 20) + 2 + .long PCI_PADDR + 4*(1 << 20) + 2 + .long PCI_PADDR + 5*(1 << 20) + 2 + .long PCI_PADDR + 6*(1 << 20) + 2 + .long PCI_PADDR + 7*(1 << 20) + 2 + .long PCI_PADDR + 8*(1 << 20) + 2 + .long PCI_PADDR + 9*(1 << 20) + 2 + .long PCI_PADDR + 10*(1 << 20) + 2 + .long PCI_PADDR + 11*(1 << 20) + 2 + .long PCI_PADDR + 12*(1 << 20) + 2 + .long PCI_PADDR + 13*(1 << 20) + 2 + .long PCI_PADDR + 14*(1 << 20) + 2 + .long PCI_PADDR + 15*(1 << 20) + 2 +#else + .rept 16 + .long 0 + .endr +#endif + .long hwmap_table_0 + 0x000 - KERNEL_BASE + 1 + .long hwmap_table_0 + 0x400 - KERNEL_BASE + 1 + .long hwmap_table_0 + 0x800 - KERNEL_BASE + 1 + .long hwmap_table_0 + 0xC00 - KERNEL_BASE + 1 + .rept 0xFF8 - 0xF00 - 16 - 4 + .long 0 + .endr + @ Page fractals + .long kernel_table1_map + 0x000 - KERNEL_BASE + 1 + .long kernel_table1_map + 0x400 - KERNEL_BASE + 1 + .long kernel_table1_map + 0x800 - KERNEL_BASE + 1 + .long kernel_table1_map + 0xC00 - KERNEL_BASE + 1 + @ Top level fractals + .long 0 @ removed for alignment constraints, using the KERNEL_BASE identity mapping instead + .rept 0x1000 - 0xFF8 - 5 + .long 0 + .endr + +.globl kernel_table1_map +kernel_table1_map: @ Size = 4KiB + .rept 0xF00/4 + .long 0 + .endr + .long hwmap_table_0 - KERNEL_BASE + (1 << 4) + 3 + .rept 0xFF8/4 - 0xF00/4 - 1 + .long 0 + .endr + .long kernel_table1_map - KERNEL_BASE + (1 << 4) + 3 + .long 0 + +@ Hardware mappings +.globl hwmap_table_0 +hwmap_table_0: + .long UART0_PADDR + (1 << 4) + 3 @ UART0 + .rept 1024 - 1 + .long 0 + .endr + diff --git a/Kernel/arch/arm7/start.s b/Kernel/arch/arm7/start.s deleted file mode 100644 index 606dbb73..00000000 --- a/Kernel/arch/arm7/start.s +++ /dev/null @@ -1,97 +0,0 @@ -KERNEL_BASE = 0x80000000 -@ -@ Exception defs taken from ARM DDI 0406B -@ -.section .init -interrupt_vector_table: - b _start @ Reset - b . @ #UD - b SyscallHandler @ SVC (SWI assume) - b . @ Prefetch abort - b . @ Data abort - b . @ Not Used - b . @ IRQ - b . @ FIQ (Fast interrupt) - -.globl _start -_start: - ldr r0, =kernel_table0-KERNEL_BASE - mcr p15, 0, r0, c2, c0, 1 @ Set TTBR1 to r0 - mcr p15, 0, r0, c2, c0, 0 @ Set TTBR0 to r0 too (for identity) - - mov r0, #1 - mcr p15, 0, r0, c2, c0, 2 @ Set TTCR to 1 (50/50 split) - - mov r0, #3 - mcr p15, 0, r0, c3, c0, 0 @ Set Domain 0 to Manager - - mrc p15, 0, r0, c1, c0, 0 - orr r0, r0, #1 - orr r0, r0, #1 << 23 - mcr p15, 0, r0, c1, c0, 0 - - ldr sp, =stack+0x10000 @ Set up stack - ldr r0, =kmain - mov pc, r0 -1: b 1b @ Infinite loop -_ptr_kmain: - .long kmain - -.comm stack, 0x10000 @ ; 64KiB Stack - -SyscallHandler: - b . -.section .padata -.globl kernel_table0 - -kernel_table0: - .long 0x00000002 @ Identity map the first 1 MiB - .rept 0x800 - 1 - .long 0 - .endr - .long 0x00000002 @ Map first 4 MiB to 2GiB - .long 0x00100002 @ - .long 0x00200002 @ - .long 0x00300002 @ - .rept 0xF00 - 0x800 - 4 - .long 0 - .endr - .long hwmap_table_0 + 0x000 - KERNEL_BASE + 1 - .long hwmap_table_0 + 0x400 - KERNEL_BASE + 1 - .long hwmap_table_0 + 0x800 - KERNEL_BASE + 1 - .long hwmap_table_0 + 0xC00 - KERNEL_BASE + 1 - .rept 0xFF8 - 0xF00 - 4 - .long 0 - .endr - @ Page fractals - .long kernel_table1_map + 0x000 - KERNEL_BASE + 1 - .long kernel_table1_map + 0x400 - KERNEL_BASE + 1 - .long kernel_table1_map + 0x800 - KERNEL_BASE + 1 - .long kernel_table1_map + 0xC00 - KERNEL_BASE + 1 - @ Top level fractals - @.long kernel_table0 - KERNEL_BASE + 2 @ Only need 16KiB, but this maps 1MiB - .long 0 @ removed for alignment constraints, using the KERNEL_BASE ident mapping instead - .rept 0x1000 - 0xFF8 - 5 - .long 0 - .endr - -.globl kernel_table1_map -kernel_table1_map: @ Size = 4KiB - .rept 0xF00/4 - .long 0 - .endr - .long hwmap_table_0 - KERNEL_BASE + (1 << 4) + 3 - .rept 0xFF8/4 - 0xF00/4 - 1 - .long 0 - .endr - .long kernel_table1_map - KERNEL_BASE + (1 << 4) + 3 - .long 0 - -@ Hardware mappings -.globl hwmap_table_0 -hwmap_table_0: - .long 0x10009000 + (1 << 4) + 3 @ UART0 - .rept 1024 - 1 - .long 0 - .endr - diff --git a/Makefile.arm7.cfg b/Makefile.arm7.cfg index c1b454e4..992a88c3 100644 --- a/Makefile.arm7.cfg +++ b/Makefile.arm7.cfg @@ -1,6 +1,6 @@ CC = arm-elf-gcc -AS = arm-elf-as +AS = arm-elf-gcc -c LD = arm-elf-ld OBJDUMP = arm-elf-objdump DISASM = $(OBJDUMP) -d -S