From 28eafc7611ec3d3f840845ec2b54025affd7bc1e Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 22 Aug 2011 12:20:36 +0800 Subject: [PATCH] Kernel/arm7 - Stubbing functions, now compiles and links --- Kernel/arch/arm7/Makefile | 2 +- Kernel/arch/arm7/debug.c | 46 +++++++++++++++ Kernel/arch/arm7/include/mm_virt.h | 7 ++- Kernel/arch/arm7/include/proc.h | 2 - Kernel/arch/arm7/link.ld | 13 +++- Kernel/arch/arm7/main.c | 9 ++- Kernel/arch/arm7/mm_virt.c | 95 ++++++++++++++++++++++-------- Kernel/arch/arm7/proc.c | 35 +++++++++++ Kernel/arch/arm7/start.s | 48 ++++++++++++++- Kernel/binary.c | 6 +- Kernel/include/hal_proc.h | 25 ++++++++ Kernel/syscalls.c | 3 +- Kernel/threads.c | 5 +- 13 files changed, 256 insertions(+), 40 deletions(-) create mode 100644 Kernel/arch/arm7/debug.c create mode 100644 Kernel/include/hal_proc.h diff --git a/Kernel/arch/arm7/Makefile b/Kernel/arch/arm7/Makefile index ff9532df..e479ed21 100644 --- a/Kernel/arch/arm7/Makefile +++ b/Kernel/arch/arm7/Makefile @@ -20,5 +20,5 @@ endif CPPFLAGS += -DMMU_PRESENT=$(MMU_PRESENT) -DPCI_ADDRESS=$(PCI_ADDRESS) LDFLAGS += `$(CC) --print-libgcc-file-name` -A_OBJ = start.ao main.o lib.o time.o pci.o +A_OBJ = start.ao main.o lib.o time.o pci.o debug.o A_OBJ += mm_phys.o mm_virt.o proc.o diff --git a/Kernel/arch/arm7/debug.c b/Kernel/arch/arm7/debug.c new file mode 100644 index 00000000..ba64ba0f --- /dev/null +++ b/Kernel/arch/arm7/debug.c @@ -0,0 +1,46 @@ +/** + */ +#include + +// === CONSTANTS === +#define SERIAL_BASE 0x16000000 +#define SERIAL_REG_DATA 0x0 +#define SERIAL_REG_FLAG 0x18 +#define SERIAL_FLAG_FULL 0x20 + +// === PROTOTYPES === +void KernelPanic_SetMode(void); +void KernelPanic_PutChar(char Ch); +void StartupPrint(const char *str); + +// === GLOBALS === + int giDebug_SerialInitialised = 0; + +// === CODE === +void Debug_PutCharDebug(char ch) +{ + while( *(volatile Uint32*)(SERIAL_BASE + SERIAL_REG_FLAG) & SERIAL_FLAG_FULL ) + ; + + *(volatile Uint32*)(SERIAL_BASE + SERIAL_REG_DATA) = ch; +} + +void Debug_PutStringDebug(const char *str) +{ + for( ; *str; str++ ) + Debug_PutCharDebug( *str ); +} + +void KernelPanic_SetMode(void) +{ +} + +void KernelPanic_PutChar(char ch) +{ + Debug_PutCharDebug(ch); +} + +void StartupPrint(const char *str) +{ +} + diff --git a/Kernel/arch/arm7/include/mm_virt.h b/Kernel/arch/arm7/include/mm_virt.h index 872258be..bbbe4ce9 100644 --- a/Kernel/arch/arm7/include/mm_virt.h +++ b/Kernel/arch/arm7/include/mm_virt.h @@ -26,7 +26,7 @@ #define MM_MODULE_MIN 0xC0000000 // - 0xD0000000 #define MM_MODULE_MAX 0xD0000000 -// PMM Data, giving it 128MiB is overkill, but it's unused atm +// PMM Data, giving it 256MiB is overkill, but it's unused atm #define MM_MAXPHYSPAGE (1024*1024) // 2^(32-12) max pages // 8.125 bytes per page (for bitmap allocation) @@ -34,6 +34,11 @@ #define MM_PMM_BASE 0xE0000000 #define MM_PMM_END 0xF0000000 +#define MM_HWMAP_BASE 0xF0000000 // Ent 0xF00 +#define MM_HWMAP_END 0xFE000000 +#define MM_TMPMAP_BASE 0xFE000000 +#define MM_TMPMAP_END 0xFF000000 + #define MM_KERNEL_VFS 0xFF000000 // #define MM_TABLE1KERN 0xFF800000 // - 0x???????? 4MiB #define MM_TABLE0KERN 0xFFC00000 // - 0xFFE04000 16KiB diff --git a/Kernel/arch/arm7/include/proc.h b/Kernel/arch/arm7/include/proc.h index 507b8791..e2063597 100644 --- a/Kernel/arch/arm7/include/proc.h +++ b/Kernel/arch/arm7/include/proc.h @@ -46,8 +46,6 @@ typedef struct { #define HALT() do{}while(0) // === PROTOTYPES === -extern void Proc_Start(void); -extern tTID Proc_Clone(Uint *Errno, int Flags); #endif diff --git a/Kernel/arch/arm7/link.ld b/Kernel/arch/arm7/link.ld index b16e7f63..b17677bb 100644 --- a/Kernel/arch/arm7/link.ld +++ b/Kernel/arch/arm7/link.ld @@ -11,14 +11,23 @@ SECTIONS *(.text*) *(.rodata*) } - .data : AT( ADDR(.text) - _kernel_base ) + .data ALIGN(0x1000) : AT( ADDR(.data) - _kernel_base ) { *(.padata) *(.data*) + + gKernelSymbols = .; + *(KEXPORT) + gKernelSymbolsEnd = .; + + gKernelModules = .; + *(KMODULES) + gKernelModulesEnd = .; } - .bss : AT( ADDR(.text) - _kernel_base ) + .bss : AT( ADDR(.bss) - _kernel_base ) { *(.bss*) *(COMMON*) } + gKernelEnd = .; } diff --git a/Kernel/arch/arm7/main.c b/Kernel/arch/arm7/main.c index 1e35c0ef..4520b80f 100644 --- a/Kernel/arch/arm7/main.c +++ b/Kernel/arch/arm7/main.c @@ -8,6 +8,7 @@ // === IMPORTS === extern void Interrupts_Setup(void); +extern void Arch_LoadBootModules(void); // === PROTOTYPES === int kmain(void); @@ -15,10 +16,16 @@ extern void Interrupts_Setup(void); // === CODE === int kmain(void) { - Interrupts_Setup(); + LogF("Booting...\n"); +// Interrupts_Setup(); MM_SetupPhys(); //TODO: for(;;); } + +void Arch_LoadBootModules(void) +{ +} + diff --git a/Kernel/arch/arm7/mm_virt.c b/Kernel/arch/arm7/mm_virt.c index 78f05c62..4d453f44 100644 --- a/Kernel/arch/arm7/mm_virt.c +++ b/Kernel/arch/arm7/mm_virt.c @@ -6,6 +6,7 @@ */ #include #include +#include #define AP_KRW_ONLY 0x1 #define AP_KRO_ONLY 0x5 @@ -25,6 +26,8 @@ typedef struct } tMM_PageInfo; // === PROTOTYPES === +void MM_int_GetTables(tVAddr VAddr, Uint32 **Table0, Uint32 **Table1); + int MM_int_AllocateCoarse(tVAddr VAddr, int Domain); int MM_int_SetPageInfo(tVAddr VAddr, tMM_PageInfo *pi); int MM_int_GetPageInfo(tVAddr VAddr, tMM_PageInfo *pi); @@ -36,20 +39,60 @@ int MM_InitialiseVirtual(void) return 0; } -int MM_int_SetPageInfo(tVAddr VAddr, tMM_PageInfo *pi) +void MM_int_GetTables(tVAddr VAddr, Uint32 **Table0, Uint32 **Table1) +{ + if(VAddr & 0x80000000) { + *Table0 = (void*)MM_TABLE0KERN; // Level 0 + *Table1 = (void*)MM_TABLE1KERN; // Level 1 + } + else { + *Table0 = (void*)MM_TABLE0USER; + *Table1 = (void*)MM_TABLE1USER; + } +} + +int MM_int_AllocateCoarse(tVAddr VAddr, int Domain) { Uint32 *table0, *table1; Uint32 *desc; + tPAddr paddr; + + MM_int_GetTables(VAddr, &table0, &table1); + + VAddr &= ~(0x400000-1); // 4MiB per "block", 1 Page - if(VAddr & 0x80000000 ) { - table0 = (void*)MM_TABLE0KERN; // Level 0 - table1 = (void*)MM_TABLE1KERN; // Level 1 + desc = &table0[VAddr>>20]; + + if( (desc[0] & 3) != 0 || (desc[1] & 3) != 0 + || (desc[2] & 3) != 0 || (desc[3] & 3) != 0 ) + { + // Error? + return 1; } - else { - table0 = (void*)MM_TABLE0USER; - table1 = (void*)MM_TABLE1USER; + + paddr = MM_AllocPhys(); + if( !paddr ) + { + // Error + return 2; } - VAddr &= 0x7FFFFFFF; + + *desc = paddr | (Domain << 5) | 1; + desc[1] = desc[0] + 0x400; + desc[2] = desc[0] + 0x800; + desc[3] = desc[0] + 0xC00; + + table1[(VAddr>>20)*256] = paddr | 3; + + return 0; +} + +int MM_int_SetPageInfo(tVAddr VAddr, tMM_PageInfo *pi) +{ + Uint32 *table0, *table1; + Uint32 *desc; + + MM_int_GetTables(VAddr, &table0, &table1); desc = &table0[ VAddr >> 20 ]; @@ -58,11 +101,7 @@ int MM_int_SetPageInfo(tVAddr VAddr, tMM_PageInfo *pi) case 12: // Small Page case 16: // Large Page if( (*desc & 3) == 0 ) { - if( pi->PhysAddr == 0 ) return 0; - // Allocate - *desc = MM_AllocPhys(); - *desc |= pi->Domain << 5; - *desc |= 1; + MM_int_AllocateCoarse( VAddr, pi->Domain ); } desc = &table1[ VAddr >> 12 ]; if( pi->Size == 12 ) @@ -121,16 +160,8 @@ int MM_int_GetPageInfo(tVAddr VAddr, tMM_PageInfo *pi) { Uint32 *table0, *table1; Uint32 desc; - - if(VAddr & 0x80000000 ) { - table0 = (void*)MM_TABLE0KERN; // Level 0 - table1 = (void*)MM_TABLE1KERN; // Level 1 - } - else { - table0 = (void*)MM_TABLE0USER; - table1 = (void*)MM_TABLE1USER; - } - VAddr &= 0x7FFFFFFF; + + MM_int_GetTables(VAddr, &table0, &table1); desc = table0[ VAddr >> 20 ]; @@ -296,3 +327,21 @@ void MM_Deallocate(tVAddr VAddr) pi.bExecutable = 0; MM_int_SetPageInfo(VAddr, &pi); } + +tPAddr MM_ClearUser(void) +{ + // TODO: Implement ClearUser + return 0; +} + +tVAddr MM_MapTemp(tPAddr PAddr) +{ + // TODO: Implement MapTemp + return 0; +} + +void MM_FreeTemp(tVAddr VAddr) +{ + // TODO: Implement FreeTemp +} + diff --git a/Kernel/arch/arm7/proc.c b/Kernel/arch/arm7/proc.c index d7775eec..07c823eb 100644 --- a/Kernel/arch/arm7/proc.c +++ b/Kernel/arch/arm7/proc.c @@ -7,6 +7,7 @@ */ #include #include +#include // === PROTOTYPES === @@ -14,11 +15,45 @@ tThread *gpCurrentThread; // === CODE === +void ArchThreads_Init(void) +{ +} + void Proc_Start(void) { } +int GetCPUNum(void) +{ + return 0; +} + tThread *Proc_GetCurThread(void) { return gpCurrentThread; } + +tTID Proc_Clone(Uint Flags) +{ + return -1; +} + +void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize) +{ +} + +tTID Proc_SpawnWorker(void) +{ + return 0; +} + +void Proc_CallFaultHandler(tThread *Thread) +{ + +} + +void Proc_DumpThreadCPUState(tThread *Thread) +{ + +} + diff --git a/Kernel/arch/arm7/start.s b/Kernel/arch/arm7/start.s index 4fb371b4..1897ecd6 100644 --- a/Kernel/arch/arm7/start.s +++ b/Kernel/arch/arm7/start.s @@ -1,3 +1,5 @@ +KERNEL_BASE = 0x80000000 + interrupt_vector_table: b . @ Reset b . @@ -13,12 +15,56 @@ interrupt_vector_table: .globl _start _start: ldr sp, =stack+0x10000 @ Set up stack - bl main + bl kmain 1: b 1b @ Infinite loop SyscallHandler: .section .padata .globl kernel_table0 +kernel_table0: + .rept 0x800 + .long 0 + .endr + .long 0x00000002 @ Identity map the first 4 MiB + .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 + .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 + .long kernel_table0 - KERNEL_BASE + 2 @ Sure it maps too much, but fuck that + .rept 0x1000 - 0xFF8 - 5 + .long 0 + .endr +.globl kernel_table1_map +kernel_table1_map: + .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 +.globl hwmap_table_0 +hwmap_table_0: + .long 0x16000000 + (1 << 4) + 3 @ Serial Port + .rept 1024 - 1 + .long 0 + .endr + diff --git a/Kernel/binary.c b/Kernel/binary.c index 76f84ed8..1276f722 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -6,6 +6,7 @@ #include #include #include +#include // === CONSTANTS === #define BIN_LOWEST MM_USER_MIN // 1MiB @@ -23,10 +24,7 @@ typedef struct sKernelBin { } tKernelBin; // === IMPORTS === -extern int Proc_Clone(Uint *Err, Uint Flags); extern char *Threads_GetName(int ID); -extern Uint MM_ClearUser(void); -extern void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize); extern tKernelSymbol gKernelSymbols[]; extern tKernelSymbol gKernelSymbolsEnd[]; extern tBinaryType gELF_Info; @@ -79,7 +77,7 @@ int Proc_Spawn(const char *Path) LOG("stackPath = '%s'\n", stackPath); - if(Proc_Clone(NULL, CLONE_VM) == 0) + if(Proc_Clone(CLONE_VM) == 0) { // CHILD const char *args[2] = {stackPath, NULL}; diff --git a/Kernel/include/hal_proc.h b/Kernel/include/hal_proc.h new file mode 100644 index 00000000..8a4e052d --- /dev/null +++ b/Kernel/include/hal_proc.h @@ -0,0 +1,25 @@ +/** + * Acess2 + * - By John Hodge (thePowersGang) + * + * include/hal_proc.h + * - HAL Process management functions + * + */ +#ifndef _HAL_PROC_H_ +#define _HAL_PROC_H_ + +#include + +extern void ArchThreads_Init(void); +extern void Proc_Start(void); +extern int GetCPUNum(void); +extern tTID Proc_Clone(Uint Flags); +extern void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize); +extern void Proc_CallFaultHandler(tThread *Thread); +extern void Proc_DumpThreadCPUState(tThread *Thread); + + +extern tPAddr MM_ClearUser(void); + +#endif diff --git a/Kernel/syscalls.c b/Kernel/syscalls.c index 1294b214..00f031fe 100644 --- a/Kernel/syscalls.c +++ b/Kernel/syscalls.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -66,7 +67,7 @@ void SyscallHandler(tSyscallRegs *Regs) // -- Clone the current thread case SYS_CLONE: // Call clone system call - ret = Proc_Clone(&err, Regs->Arg1); + ret = Proc_Clone(Regs->Arg1); // Change user stack if a new stack address is passed if(ret == 0 && Regs->Arg2) Regs->StackPointer = Regs->Arg2; diff --git a/Kernel/threads.c b/Kernel/threads.c index fa6f6e0f..7114745a 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -9,6 +9,7 @@ #include #include #include +#include // Configuration #define DEBUG_TRACE_TICKETS 0 // Trace ticket counts @@ -34,10 +35,6 @@ const enum eConfigTypes cCONFIG_TYPES[] = { }; // === IMPORTS === -extern void ArchThreads_Init(void); -extern void Proc_CallFaultHandler(tThread *Thread); -extern void Proc_DumpThreadCPUState(tThread *Thread); -extern int GetCPUNum(void); // === PROTOTYPES === void Threads_Init(void); -- 2.20.1