From: John Hodge Date: Fri, 23 Sep 2011 05:47:37 +0000 (+0800) Subject: Kernel/arm7 - Fixing, manages to start pmm init X-Git-Tag: rel0.11~84 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=2337aa1fb9c4289294e1e4f23d0318faac5450ce;p=tpg%2Facess2.git Kernel/arm7 - Fixing, manages to start pmm init - VMM broken, doesn't map correctly --- diff --git a/Kernel/arch/arm7/Makefile b/Kernel/arch/arm7/Makefile index e479ed21..4d1aa049 100644 --- a/Kernel/arch/arm7/Makefile +++ b/Kernel/arch/arm7/Makefile @@ -22,3 +22,6 @@ LDFLAGS += `$(CC) --print-libgcc-file-name` A_OBJ = start.ao main.o lib.o time.o pci.o debug.o A_OBJ += mm_phys.o mm_virt.o proc.o + +main.c: Makefile.BuildNum.$(ARCH) + diff --git a/Kernel/arch/arm7/debug.c b/Kernel/arch/arm7/debug.c index 02a17be1..6d0232f2 100644 --- a/Kernel/arch/arm7/debug.c +++ b/Kernel/arch/arm7/debug.c @@ -1,10 +1,16 @@ /** + * Acess2 + * - By John Hodge (thePowersGang) + * + * arch/arm7/debug.c + * - ARM7 Debug output + * NOTE: Currently designed for the realview-pb-a8 emulated by Qemu */ #include // === CONSTANTS === //#define UART0_BASE 0x10009000 -#define UART0_BASE 0xF0000000 +#define UART0_BASE 0xF0000000 // Boot time mapped // === PROTOTYPES === void KernelPanic_SetMode(void); diff --git a/Kernel/arch/arm7/lib.c b/Kernel/arch/arm7/lib.c index bfcfeb63..6f11f012 100644 --- a/Kernel/arch/arm7/lib.c +++ b/Kernel/arch/arm7/lib.c @@ -112,13 +112,62 @@ void *memset(void *_dest, int _value, size_t _length) return _dest; } +Uint64 DivMod64U(Uint64 Num, Uint64 Den, Uint64 *Rem) +{ + Uint64 ret; + if(Den == 0) return 0; // TODO: #div0 + if(Num == 0) { + if(Rem) *Rem = 0; + return 0; + } + if(Den == 1) { + if(Rem) *Rem = 0; + return Num; + } + if(Den == 2) { + if(Rem) *Rem = Num & 1; + return Num >> 1; + } + if(Den == 16) { + if(Rem) *Rem = Num & 0xF; + return Num >> 4; + } + if(Den == 0x1000) { + if(Rem) *Rem = Num & 0xFFF; + return Num >> 12; + } + + #if 0 + { + // http://www.tofla.iconbar.com/tofla/arm/arm02/index.htm + Uint64 tmp = 1; + __asm__ __volatile__( + "1:" + "cmpl %2,%1" + "movls %2,%2,lsl#1" + "movls %3,%3,lsl#1" + "bls 1b" + "2:" + "cmpl %" + while(Num > Den) { + Den <<= 1; + tmp <<= 1; + } + Den >>= 1; tmp >>= 1; + while( + } + #else + for( ret = 0; Num > Den; ret ++, Num -= Den) ; + #endif + if(Rem) *Rem = Num; + return ret; +} + // Unsigned Divide 64-bit Integer Uint64 __udivdi3(Uint64 Num, Uint64 Den) { - if( Num == 0 ) return 0; - if( Den == 0 ) return 5 / (Uint32)Den; // Force a #DIV0 - if( Den == 1 ) return Num; - if( Den == 2 ) return Num >> 1; + return DivMod64U(Num, Den, NULL); +// if( Den == 0 ) return 5 / (Uint32)Den; // Force a #DIV0 if( Den == 16 ) return Num >> 4; if( Den == 256 ) return Num >> 8; if( Den == 512 ) return Num >> 9; @@ -142,8 +191,8 @@ Uint64 __udivdi3(Uint64 Num, Uint64 Den) // Unsigned Modulus 64-bit Integer Uint64 __umoddi3(Uint64 Num, Uint64 Den) { - if( Num == 0 ) return 0; if( Den == 0 ) return 5 / (Uint32)Den; // Force a #DIV0 + if( Num < Den ) return Num; if( Den == 1 ) return 0; if( Den == 2 ) return Num & 1; if( Den == 16 ) return Num & 3; @@ -152,9 +201,8 @@ Uint64 __umoddi3(Uint64 Num, Uint64 Den) if( Den == 1024 ) return Num & 0x3FF; if( Den == 2048 ) return Num & 0x7FF; if( Den == 4096 ) return Num & 0xFFF; - if( Num < Den ) return 0; - if( Num <= 0xFFFFFFFF && Den <= 0xFFFFFFFF ) - return (Uint32)Num % (Uint32)Den; +// if( Num <= 0xFFFFFFFF && Den <= 0xFFFFFFFF ) +// return (Uint32)Num % (Uint32)Den; #if 0 if( Den <= 0xFFFFFFFF ) { diff --git a/Kernel/arch/arm7/main.c b/Kernel/arch/arm7/main.c index 4520b80f..455fe839 100644 --- a/Kernel/arch/arm7/main.c +++ b/Kernel/arch/arm7/main.c @@ -16,12 +16,14 @@ extern void Arch_LoadBootModules(void); // === CODE === int kmain(void) { - LogF("Booting...\n"); + LogF("Acess2 ARMv7 v"EXPAND_STR(KERNEL_VERSION)"\n", BUILD_NUM); + LogF(" Build %i\n", BUILD_NUM); // Interrupts_Setup(); MM_SetupPhys(); //TODO: + LogF("End of kmain(), for(;;);\n"); for(;;); } diff --git a/Kernel/arch/arm7/mm_phys.c b/Kernel/arch/arm7/mm_phys.c index d91f889f..cc16463e 100644 --- a/Kernel/arch/arm7/mm_phys.c +++ b/Kernel/arch/arm7/mm_phys.c @@ -14,10 +14,10 @@ char gStaticAllocPages[NUM_STATIC_ALLOC][PAGE_SIZE] __attribute__ ((section(".padata"))); tPAddr gaiStaticAllocPages[NUM_STATIC_ALLOC] = { - (tPAddr)(&gStaticAllocPages[0] - KERNEL_BASE), - (tPAddr)(&gStaticAllocPages[1] - KERNEL_BASE), - (tPAddr)(&gStaticAllocPages[2] - KERNEL_BASE), - (tPAddr)(&gStaticAllocPages[3] - KERNEL_BASE) + (tPAddr)(&gStaticAllocPages[0]) - KERNEL_BASE, + (tPAddr)(&gStaticAllocPages[1]) - KERNEL_BASE, + (tPAddr)(&gStaticAllocPages[2]) - KERNEL_BASE, + (tPAddr)(&gStaticAllocPages[3]) - KERNEL_BASE }; extern char gKernelEnd[]; diff --git a/Kernel/arch/arm7/mm_virt.c b/Kernel/arch/arm7/mm_virt.c index 7b11237b..3dca8ac6 100644 --- a/Kernel/arch/arm7/mm_virt.c +++ b/Kernel/arch/arm7/mm_virt.c @@ -25,6 +25,10 @@ typedef struct int AP; } tMM_PageInfo; +//#define FRACTAL(table1, addr) ((table1)[ (0xFF8/4*1024) + ((addr)>>20)]) +#define FRACTAL(table1, addr) ((table1)[ (0xFF8/4*1024) + ((addr)>>22)]) +#define TLBIALL() __asm__ __volatile__ ("mcr p15, 0, %0, c8, c7, 0" : : "r" (0)) + // === PROTOTYPES === void MM_int_GetTables(tVAddr VAddr, Uint32 **Table0, Uint32 **Table1); int MM_int_AllocateCoarse(tVAddr VAddr, int Domain); @@ -82,7 +86,11 @@ int MM_int_AllocateCoarse(tVAddr VAddr, int Domain) desc[2] = desc[0] + 0x800; desc[3] = desc[0] + 0xC00; - table1[(VAddr>>20)*256] = paddr | 3; + Log("FRACTAL(%p, %p) = %p", table1, VAddr, &FRACTAL(table1, VAddr)); + FRACTAL(table1, VAddr) = paddr | 3; + + // TLBIALL + TLBIALL(); return 0; } diff --git a/Kernel/arch/arm7/start.s b/Kernel/arch/arm7/start.s index abfbb59b..83b2d1b6 100644 --- a/Kernel/arch/arm7/start.s +++ b/Kernel/arch/arm7/start.s @@ -1,15 +1,17 @@ KERNEL_BASE = 0x80000000 - +@ +@ Exception defs taken from ARM DDI 0406B +@ .section .init interrupt_vector_table: b _start @ Reset - b . @ ? - b SyscallHandler @ SWI instruction - b . - b . - b . - b . - b . + 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: @@ -43,7 +45,7 @@ SyscallHandler: .globl kernel_table0 kernel_table0: - .long 0x00000002 @ Identity map the first 4 MiB + .long 0x00000002 @ Identity map the first 1 MiB .rept 0x800 - 1 .long 0 .endr @@ -71,7 +73,7 @@ kernel_table0: .endr .globl kernel_table1_map -kernel_table1_map: +kernel_table1_map: @ Size = 4KiB .rept 0xF00/4 .long 0 .endr