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
--- /dev/null
+/**
+ */
+#include <acess.h>
+
+// === 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)
+{
+}
+
#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)
#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
#define HALT() do{}while(0)
// === PROTOTYPES ===
-extern void Proc_Start(void);
-extern tTID Proc_Clone(Uint *Errno, int Flags);
#endif
*(.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 = .;
}
// === IMPORTS ===
extern void Interrupts_Setup(void);
+extern void Arch_LoadBootModules(void);
// === PROTOTYPES ===
int kmain(void);
// === CODE ===
int kmain(void)
{
- Interrupts_Setup();
+ LogF("Booting...\n");
+// Interrupts_Setup();
MM_SetupPhys();
//TODO:
for(;;);
}
+
+void Arch_LoadBootModules(void)
+{
+}
+
*/
#include <acess.h>
#include <mm_virt.h>
+#include <hal_proc.h>
#define AP_KRW_ONLY 0x1
#define AP_KRO_ONLY 0x5
} 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);
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 ];
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 )
{
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 ];
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
+}
+
*/
#include <acess.h>
#include <threads_int.h>
+#include <hal_proc.h>
// === PROTOTYPES ===
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)
+{
+
+}
+
+KERNEL_BASE = 0x80000000
+
interrupt_vector_table:
b . @ Reset
b .
.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
+
#include <acess.h>
#include <binary.h>
#include <mm_virt.h>
+#include <hal_proc.h>
// === CONSTANTS ===
#define BIN_LOWEST MM_USER_MIN // 1MiB
} 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;
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};
--- /dev/null
+/**
+ * Acess2
+ * - By John Hodge (thePowersGang)
+ *
+ * include/hal_proc.h
+ * - HAL Process management functions
+ *
+ */
+#ifndef _HAL_PROC_H_
+#define _HAL_PROC_H_
+
+#include <threads_int.h>
+
+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
#include <acess.h>
#include <syscalls.h>
#include <proc.h>
+#include <hal_proc.h>
#include <errno.h>
#include <threads.h>
// -- 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;
#include <errno.h>
#include <mutex.h>
#include <semaphore.h>
+#include <hal_proc.h>
// Configuration
#define DEBUG_TRACE_TICKETS 0 // Trace ticket counts
};
// === 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);