From aa8af5fd9a5a3cb3563244ceb85b50e959a184bf Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 30 Nov 2011 15:22:15 +0800 Subject: [PATCH] Kernel - Added (completely untested) m68k port --- BuildConf/m68k/Makefile.cfg | 7 ++ BuildConf/m68k/default.mk | 0 Kernel/arch/m68k/Makefile | 11 +++ Kernel/arch/m68k/debug.c | 27 +++++++ Kernel/arch/m68k/include/arch.h | 53 ++++++++++++++ Kernel/arch/m68k/include/mm_virt.h | 23 ++++++ Kernel/arch/m68k/include/proc.h | 40 ++++++++++ Kernel/arch/m68k/lib.c | 114 +++++++++++++++++++++++++++++ Kernel/arch/m68k/link.ld | 40 ++++++++++ Kernel/arch/m68k/main.c | 24 ++++++ Kernel/arch/m68k/mm_phys.c | 22 ++++++ Kernel/arch/m68k/mm_virt.c | 54 ++++++++++++++ Kernel/arch/m68k/proc.c | 75 +++++++++++++++++++ Kernel/arch/m68k/time.c | 14 ++++ 14 files changed, 504 insertions(+) create mode 100644 BuildConf/m68k/Makefile.cfg create mode 100644 BuildConf/m68k/default.mk create mode 100644 Kernel/arch/m68k/Makefile create mode 100644 Kernel/arch/m68k/debug.c create mode 100644 Kernel/arch/m68k/include/arch.h create mode 100644 Kernel/arch/m68k/include/mm_virt.h create mode 100644 Kernel/arch/m68k/include/proc.h create mode 100644 Kernel/arch/m68k/lib.c create mode 100644 Kernel/arch/m68k/link.ld create mode 100644 Kernel/arch/m68k/main.c create mode 100644 Kernel/arch/m68k/mm_phys.c create mode 100644 Kernel/arch/m68k/mm_virt.c create mode 100644 Kernel/arch/m68k/proc.c create mode 100644 Kernel/arch/m68k/time.c diff --git a/BuildConf/m68k/Makefile.cfg b/BuildConf/m68k/Makefile.cfg new file mode 100644 index 00000000..21f0efe8 --- /dev/null +++ b/BuildConf/m68k/Makefile.cfg @@ -0,0 +1,7 @@ + +# BUILD_DIST=y - Install to ./Dist +ifneq ($(BUILD_DIST),) + DISTROOT := $(ACESSDIR)/Dist + xCP := cp + xMKDIR := mkdir -p +endif diff --git a/BuildConf/m68k/default.mk b/BuildConf/m68k/default.mk new file mode 100644 index 00000000..e69de29b diff --git a/Kernel/arch/m68k/Makefile b/Kernel/arch/m68k/Makefile new file mode 100644 index 00000000..4caea1e1 --- /dev/null +++ b/Kernel/arch/m68k/Makefile @@ -0,0 +1,11 @@ +# +# Acess2 Kernel +# m68k Architecture Makefile +# arch/m68k/Makefile + +CFLAGS = + +A_OBJ = main.o debug.o lib.o time.o proc.o mm_virt.o mm_phys.o + +LDFLAGS += `$(CC) --print-libgcc-file-name` + diff --git a/Kernel/arch/m68k/debug.c b/Kernel/arch/m68k/debug.c new file mode 100644 index 00000000..8c7de3b1 --- /dev/null +++ b/Kernel/arch/m68k/debug.c @@ -0,0 +1,27 @@ +/* + * Acess2 M68K port + * - By John Hodge (thePowersGang) + * + * arch/m68k/debug.c + * - Debugging output + */ +#include + +// === PROTOTYPES === +void StartupPrint(const char *Str); +void KernelPanic_SetMode(void); +void KernelPanic_PutChar(char ch); + +// === CODE === +void StartupPrint(const char *Str) +{ +} + +void KernelPanic_SetMode(void) +{ +} + +void KernelPanic_PutChar(char ch) +{ +} + diff --git a/Kernel/arch/m68k/include/arch.h b/Kernel/arch/m68k/include/arch.h new file mode 100644 index 00000000..0b2dc5b4 --- /dev/null +++ b/Kernel/arch/m68k/include/arch.h @@ -0,0 +1,53 @@ +/* + * Acess2 M68000 port + * - By John Hodge (thePowersGang) + * + * arch/m68k/include/arch.h + * - Architectre config + */ +#ifndef _M68K_ARCH_H_ +#define _M68K_ARCH_H_ + +#define INVLPTR ((void*)-1) +#define BITS 32 + +typedef unsigned long long Uint64; +typedef unsigned long Uint32; +typedef unsigned short Uint16; +typedef unsigned char Uint8; + +typedef signed long long Sint64; +typedef signed long Sint32; +typedef signed short Sint16; +typedef signed char Sint8; + +typedef unsigned int Uint; +typedef unsigned int size_t; + +typedef char BOOL; + +typedef Uint32 tVAddr; +typedef Uint32 tPAddr; + +struct sShortSpinlock +{ + int v; +}; + +// Non preemptive and no SMP, no need for these +#define SHORTLOCK(lock) do{}while(0) +#define SHORTREL(lock) do{}while(0) +#define IS_LOCKED(lock) (0) +#define CPU_HAS_LOCK(lock) (0) + +#define Debug_PutCharDebug(ch) do{}while(0) +#define Debug_PutStringDebug(ch) do{}while(0) + +#define HALT() do{}while(0) + +#define USER_MAX 0 + +#define PAGE_SIZE 0x1000 + +#endif + diff --git a/Kernel/arch/m68k/include/mm_virt.h b/Kernel/arch/m68k/include/mm_virt.h new file mode 100644 index 00000000..01480b9b --- /dev/null +++ b/Kernel/arch/m68k/include/mm_virt.h @@ -0,0 +1,23 @@ +/* + * Acess2 M68000 port + * - By John Hodge (thePowersGang) + * + * arch/m68k/include/mm_virt.h + * - Virtual memory addresses + */ +#ifndef _M68K_MM_VIRT_H_ +#define _M68K_MM_VIRT_H_ + +#define MM_KHEAP_BASE 0 +#define MM_KHEAP_MAX 0 + +#define MM_USER_MIN 0 +#define USER_LIB_MAX 0 +#define MM_MODULE_MIN 0 +#define MM_MODULE_MAX 0 + +#define MM_PPD_HANDLES 0 +#define MM_KERNEL_VFS 0 + +#endif + diff --git a/Kernel/arch/m68k/include/proc.h b/Kernel/arch/m68k/include/proc.h new file mode 100644 index 00000000..8cf6aa0c --- /dev/null +++ b/Kernel/arch/m68k/include/proc.h @@ -0,0 +1,40 @@ +/* + * Acess2 M68000 port + * - By John Hodge (thePowersGang) + * + * arch/m68k/include/proc.h + * - Task management defs + */ +#ifndef _M68K_PROC_H_ +#define _M68K_PROC_H_ + +#define MAX_CPUS 1 + +typedef int tMemoryState; // Unused + +typedef struct { + Uint32 IP; + Uint32 SP; +} tTaskState; + +typedef struct { + Uint32 Num; + union { + Uint32 Arg1; + Uint32 Return; + }; + union { + Uint32 Arg2; + Uint32 RetHi; + }; + union { + Uint32 Arg3; + Uint32 Error; + }; + Uint32 Arg4; + Uint32 Arg5; + Uint32 Arg6; +} tSyscallRegs; + +#endif + diff --git a/Kernel/arch/m68k/lib.c b/Kernel/arch/m68k/lib.c new file mode 100644 index 00000000..2888a318 --- /dev/null +++ b/Kernel/arch/m68k/lib.c @@ -0,0 +1,114 @@ +/* + * Acess2 M68K port + * - By John Hodge (thePowersGang) + * + * arch/m68k/lib.c + * - Library functions + */ +#include +#include "../helpers.h" +#include + +Uint64 __divmod64(Uint64 Num, Uint64 Den, Uint64 *Rem); +Uint64 __udivdi3(Uint64 Num, Uint64 Den); +Uint64 __umoddi3(Uint64 Num, Uint64 Den); + +// === CODE === +void *memcpy(void *__dest, const void *__src, size_t __len) +{ + register Uint8 *dest = __dest; + register const Uint8 *src = __src; + + while(__len --) + *dest++ = *src++; + + return __dest; +} + +void *memset(void *__dest, int __val, size_t __count) +{ + register Uint8 *dest = __dest; + + while(__count --) + *dest = __val; + + return __dest; +} + +int memcmp(const void *__p1, const void *__p2, size_t __maxlen) +{ + const char *m1 = __p1, *m2 = __p2; + while( __maxlen-- ) + { + if(*m1 != *m2) return *m1 - *m2; + } + return 0; +} + +DEF_DIVMOD(64) + +Uint64 DivMod64U(Uint64 Num, Uint64 Den, Uint64 *Rem) +{ + Uint64 ret; + if(Den == 0) return 0; // TODO: #div0 + if(Num < Den) { + if(Rem) *Rem = Num; + return 0; + } + 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 == 32) { + if(Rem) *Rem = Num & 0x1F; + return Num >> 5; + } + if(Den == 0x1000) { + if(Rem) *Rem = Num & 0xFFF; + return Num >> 12; + } + + if( !(Den >> 32) && !(Num >> 32) ) { + if(Rem) *Rem = (Uint32)Num % (Uint32)Den; // Clear high bits + return (Uint32)Num / (Uint32)Den; + } + + ret = __divmod64(Num, Den, Rem); + return ret; +} + +// Unsigned Divide 64-bit Integer +Uint64 __udivdi3(Uint64 Num, Uint64 Den) +{ + return DivMod64U(Num, Den, NULL); +} + +// Unsigned Modulus 64-bit Integer +Uint64 __umoddi3(Uint64 Num, Uint64 Den) +{ + Uint64 ret = 0; + DivMod64U(Num, Den, &ret); + return ret; +} + +// ---- PCI (stubbed) +Uint32 PCI_CfgReadDWord(Uint32 Addr) +{ + return 0xFFFFFFFF; +} +void PCI_CfgWriteDWord(Uint32 Addr, Uint32 Data) +{ +} + diff --git a/Kernel/arch/m68k/link.ld b/Kernel/arch/m68k/link.ld new file mode 100644 index 00000000..c0b0c9d4 --- /dev/null +++ b/Kernel/arch/m68k/link.ld @@ -0,0 +1,40 @@ +ENTRY (_start) + +_kernel_base = 0x0; + +SECTIONS +{ + . = 0; + .init : + { + *(.init) + } + . += _kernel_base; + .text : AT( ADDR(.text) - _kernel_base ) + { + *(.text*) + *(.rodata*) + } + /* 0x4000 (4 pages) alignment needed for root table */ + .data ALIGN(0x4000) : AT( ADDR(.data) - _kernel_base ) + { + *(.padata) + *(.data*) + + gKernelSymbols = .; + *(KEXPORT) + gKernelSymbolsEnd = .; + + gKernelModules = .; + *(KMODULES) + gKernelModulesEnd = .; + } + .bss : AT( ADDR(.bss) - _kernel_base ) + { + *(.bss*) + *(COMMON*) + . = ALIGN(0x1000); + *(.pabss) + } + gKernelEnd = .; +} diff --git a/Kernel/arch/m68k/main.c b/Kernel/arch/m68k/main.c new file mode 100644 index 00000000..3a270adf --- /dev/null +++ b/Kernel/arch/m68k/main.c @@ -0,0 +1,24 @@ +/* + * Acess2 M68K port + * - By John Hodge (thePowersGang) + * + * arch/m68k/main.c + * - C entrypoint + */ +#include +#include + +// === PROTOTYPES === +void kmain(void); + +// === CODE === +void kmain(void) +{ + +} + +void Arch_LoadBootModules(void) +{ + +} + diff --git a/Kernel/arch/m68k/mm_phys.c b/Kernel/arch/m68k/mm_phys.c new file mode 100644 index 00000000..24fd1f2c --- /dev/null +++ b/Kernel/arch/m68k/mm_phys.c @@ -0,0 +1,22 @@ +/* + * Acess2 M68K port + * - By John Hodge (thePowersGang) + * + * arch/m68k/mm_phys.c + * - Stubbed physical memory management + */ +#include + +// === CODE === +void MM_RefPhys(tPAddr Page) +{ + // TODO: Refcount pages + Log_Warning("MMPhys", "TODO: Implement MM_RefPhys"); +} + +int MM_SetPageNode(tPAddr Page, void *Node) +{ + Log_Warning("MMPhys", "TODO: Implement MM_SetPageNode"); + return -1; +} + diff --git a/Kernel/arch/m68k/mm_virt.c b/Kernel/arch/m68k/mm_virt.c new file mode 100644 index 00000000..88990a1e --- /dev/null +++ b/Kernel/arch/m68k/mm_virt.c @@ -0,0 +1,54 @@ +/* + * Acess2 M68K port + * - By John Hodge (thePowersGang) + * + * arch/m68k/mm_virt.c + * - Stubbed virtual memory management (no MMU) + */ +#include +#include +#include + +// === CODE === +tPAddr MM_GetPhysAddr(tVAddr Addr) +{ + return Addr; +} + +void MM_SetFlags(tVAddr Addr, Uint Val, Uint Mask) +{ + return ; +} + +Uint MM_GetFlags(tVAddr Addr) +{ + return 0; +} + +int MM_Map(tVAddr Dest, tPAddr Src) +{ + Dest &= (PAGE_SIZE-1); + Src &= (PAGE_SIZE-1); + if(Dest != Src) + memcpy((void*)Dest, (void*)Src, PAGE_SIZE); + return 0; +} + +tPAddr MM_Allocate(tVAddr Dest) +{ + return Dest; +} + +void MM_Deallocate(tVAddr Addr) +{ +} + +void MM_ClearUser(void) +{ +} + +void MM_DumpTables(tVAddr Start, tVAddr End) +{ + +} + diff --git a/Kernel/arch/m68k/proc.c b/Kernel/arch/m68k/proc.c new file mode 100644 index 00000000..c148bff7 --- /dev/null +++ b/Kernel/arch/m68k/proc.c @@ -0,0 +1,75 @@ +/* + * Acess2 M68K port + * - By John Hodge (thePowersGang) + * + * arch/m68k/proc.c + * - Multithreading + */ +#include +#include +#include + +// === IMPORTS === +extern tThread gThreadZero; + +// === GLOBALS === +tThread *gpCurrentThread = &gThreadZero; + +// === CODE === +void ArchThreads_Init(void) +{ +} + +void Proc_Start(void) +{ +} + +tThread *Proc_GetCurThread(void) +{ + return gpCurrentThread; +} + +int GetCPUNum(void) +{ + return 0; +} + +tTID Proc_Clone(Uint Flags) +{ + UNIMPLEMENTED(); + return -1; +} + +tTID Proc_NewKThread(tThreadFunction Fcn, void *Arg) +{ + UNIMPLEMENTED(); + return -1; +} + +tTID Proc_SpawnWorker(tThreadFunction Fcn, void *Arg) +{ + UNIMPLEMENTED(); + return -1; +} + +void Proc_StartUser(Uint Entrypoint, Uint Base, int ArgC, char **ArgV, int DataSize) +{ + Log_KernelPanic("Proc", "TODO: Implement Proc_StartUser"); + for(;;); +} + +void Proc_CallFaultHandler(tThread *Thread) +{ + +} + +void Proc_DumpThreadCPUState(tThread *Thread) +{ + +} + +void Proc_Reschedule(void) +{ + Log_Notice("Proc", "TODO: Implement Proc_Reschedule"); +} + diff --git a/Kernel/arch/m68k/time.c b/Kernel/arch/m68k/time.c new file mode 100644 index 00000000..0fffaf66 --- /dev/null +++ b/Kernel/arch/m68k/time.c @@ -0,0 +1,14 @@ +/* + * Acess2 M68K port + * - By John Hodge (thePowersGang) + * + * arch/m68k/time.c + * - Timekeeping + */ +#include + +// === CODE === +Sint64 now(void) +{ + return 0; +} -- 2.20.1