Kernel - Added (completely untested) m68k port
authorJohn Hodge <[email protected]>
Wed, 30 Nov 2011 07:22:15 +0000 (15:22 +0800)
committerJohn Hodge <[email protected]>
Wed, 30 Nov 2011 07:22:15 +0000 (15:22 +0800)
14 files changed:
BuildConf/m68k/Makefile.cfg [new file with mode: 0644]
BuildConf/m68k/default.mk [new file with mode: 0644]
Kernel/arch/m68k/Makefile [new file with mode: 0644]
Kernel/arch/m68k/debug.c [new file with mode: 0644]
Kernel/arch/m68k/include/arch.h [new file with mode: 0644]
Kernel/arch/m68k/include/mm_virt.h [new file with mode: 0644]
Kernel/arch/m68k/include/proc.h [new file with mode: 0644]
Kernel/arch/m68k/lib.c [new file with mode: 0644]
Kernel/arch/m68k/link.ld [new file with mode: 0644]
Kernel/arch/m68k/main.c [new file with mode: 0644]
Kernel/arch/m68k/mm_phys.c [new file with mode: 0644]
Kernel/arch/m68k/mm_virt.c [new file with mode: 0644]
Kernel/arch/m68k/proc.c [new file with mode: 0644]
Kernel/arch/m68k/time.c [new file with mode: 0644]

diff --git a/BuildConf/m68k/Makefile.cfg b/BuildConf/m68k/Makefile.cfg
new file mode 100644 (file)
index 0000000..21f0efe
--- /dev/null
@@ -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 (file)
index 0000000..e69de29
diff --git a/Kernel/arch/m68k/Makefile b/Kernel/arch/m68k/Makefile
new file mode 100644 (file)
index 0000000..4caea1e
--- /dev/null
@@ -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 (file)
index 0000000..8c7de3b
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Acess2 M68K port
+ * - By John Hodge (thePowersGang)
+ *
+ * arch/m68k/debug.c
+ * - Debugging output
+ */
+#include <acess.h>
+
+// === 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 (file)
index 0000000..0b2dc5b
--- /dev/null
@@ -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 (file)
index 0000000..01480b9
--- /dev/null
@@ -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 (file)
index 0000000..8cf6aa0
--- /dev/null
@@ -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 (file)
index 0000000..2888a31
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * Acess2 M68K port
+ * - By John Hodge (thePowersGang)
+ *
+ * arch/m68k/lib.c
+ * - Library functions
+ */
+#include <acess.h>
+#include "../helpers.h"
+#include <drv_pci_int.h>
+
+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 (file)
index 0000000..c0b0c9d
--- /dev/null
@@ -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 (file)
index 0000000..3a270ad
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Acess2 M68K port
+ * - By John Hodge (thePowersGang)
+ *
+ * arch/m68k/main.c
+ * - C entrypoint
+ */
+#include <acess.h>
+#include <init.h>
+
+// === 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 (file)
index 0000000..24fd1f2
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Acess2 M68K port
+ * - By John Hodge (thePowersGang)
+ *
+ * arch/m68k/mm_phys.c
+ * - Stubbed physical memory management
+ */
+#include <acess.h>
+
+// === 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 (file)
index 0000000..88990a1
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Acess2 M68K port
+ * - By John Hodge (thePowersGang)
+ *
+ * arch/m68k/mm_virt.c
+ * - Stubbed virtual memory management (no MMU)
+ */
+#include <acess.h>
+#include <mm_virt.h>
+#include <hal_proc.h>
+
+// === 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 (file)
index 0000000..c148bff
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Acess2 M68K port
+ * - By John Hodge (thePowersGang)
+ *
+ * arch/m68k/proc.c
+ * - Multithreading
+ */
+#include <acess.h>
+#include <threads_int.h>
+#include <hal_proc.h>
+
+// === 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 (file)
index 0000000..0fffaf6
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * Acess2 M68K port
+ * - By John Hodge (thePowersGang)
+ *
+ * arch/m68k/time.c
+ * - Timekeeping
+ */
+#include <acess.h>
+
+// === CODE ===
+Sint64 now(void)
+{
+       return 0;
+}

UCC git Repository :: git.ucc.asn.au