A_OBJ := start32.ao start64.ao desctab.ao proc.ao
A_OBJ += main.o lib.o proc.o mm_virt.o mm_phys.o
A_OBJ += kernelpanic.o errors.o time.o pci.o
-A_OBJ += vm8086.o
+A_OBJ += vm8086.o vpci.o
A_OBJ += ../x86/mboot.o
# rme.o
[BITS 64]
[extern Log]
+[extern Log_Debug]
[extern gGDTPtr]
[extern gGDT]
push rax
push rdx
sub rsp, 8
- mov rcx, rdi ; IRQ Number
- mov rdx, rsi ; Callback
- mov rsi, rax ; Pointer
- mov rdi, csIRQ_Assigned
- call Log
+ mov rcx, rsi ; IRQ Number
+ mov rdx, rdi ; Callback
+ mov rsi, csIRQ_Assigned
+ mov rdi, csIRQ_Tag
+ call Log_Debug
add rsp, 8
pop rdx
pop rax
[section .rodata]
csIRQ_Assigned:
- db "IRQ %p := %p (IRQ %i)",0
+ db "IRQ %i .= %p",0
csIRQ_Fired:
db "IRQ %i fired",0
+csIRQ_Tag:
+ db "IRQ",0
[section .text]
%macro ISR_NOERRNO 1
return ret;
}
+EXPORT(memcpy);
+EXPORT(memset);
+
// === CONSTANTS ===
#define KERNEL_LOAD 0x100000
#define MAX_PMEMMAP_ENTS 16
+#define MAX_ARGSTR_POS (0x200000-0x2000)
// === IMPORTS ===
extern void Desctab_Init(void);
// === GLOBALS ==
char *gsBootCmdLine = NULL;
+tBootModule *gaArch_BootModules;
+ int giArch_NumBootModules = 0;
// === CODE ===
void kmain(Uint MbMagic, void *MbInfoPtr)
// Adjust Multiboot structure address
mbInfo = (void*)( (Uint)MbInfoPtr + KERNEL_BASE );
gsBootCmdLine = (char*)( (Uint)mbInfo->CommandLine + KERNEL_BASE);
+ // TODO: ref above?
nPMemMapEnts = Multiboot_LoadMemoryMap(mbInfo, KERNEL_BASE, pmemmap, MAX_PMEMMAP_ENTS,
KERNEL_LOAD, (tVAddr)&gKernelEnd - KERNEL_BASE
);
MM_InitPhys( nPMemMapEnts, pmemmap ); // Set up physical memory manager
Log("gsBootCmdLine = '%s'", gsBootCmdLine);
+ switch(MbMagic)
+ {
+ case MULTIBOOT_MAGIC:
+ MM_RefPhys( mbInfo->CommandLine );
+ break;
+ }
+
*(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'D';
Heap_Install();
Log_Log("Arch", "Starting VFS...");
VFS_Init();
+ gaArch_BootModules = Multiboot_LoadModules(mbInfo, KERNEL_BASE, &giArch_NumBootModules);
+
*(Uint16*)(KERNEL_BASE|0xB8000) = 0x1F00|'Z';
// Pass on to Independent Loader
void Arch_LoadBootModules(void)
{
-
+ int i, j, numPages;
+ Log("gsBootCmdLine = '%s'", gsBootCmdLine);
+ for( i = 0; i < giArch_NumBootModules; i ++ )
+ {
+ Log_Log("Arch", "Loading '%s'", gaArch_BootModules[i].ArgString);
+
+ if( !Module_LoadMem( gaArch_BootModules[i].Base,
+ gaArch_BootModules[i].Size, gaArch_BootModules[i].ArgString
+ ) )
+ {
+ Log_Warning("Arch", "Unable to load module");
+ }
+
+ // Unmap and free
+ numPages = (gaArch_BootModules[i].Size + ((Uint)gaArch_BootModules[i].Base&0xFFF) + 0xFFF) >> 12;
+ MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].Base, numPages );
+
+ for( j = 0; j < numPages; j++ )
+ MM_DerefPhys( gaArch_BootModules[i].PBase + (j << 12) );
+
+ if( (tVAddr) gaArch_BootModules[i].ArgString < KERNEL_BASE )
+ MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].ArgString, 2 );
+ }
+ Log_Log("Arch", "Boot modules loaded");
+ if( gaArch_BootModules )
+ free( gaArch_BootModules );
}
void StartupPrint(const char *String)
expected |= expected_pml4 & PF_NX;
expected |= expected_pdp & PF_NX;
expected |= expected_pd & PF_NX;
- Log("expected (pml4 = %x, pdp = %x, pd = %x)",
- expected_pml4, expected_pdp, expected_pd);
+// Log("expected (pml4 = %x, pdp = %x, pd = %x)",
+// expected_pml4, expected_pdp, expected_pd);
// Dump
MM_int_DumpTablesEnt( rangeStart, curPos - rangeStart, expected );
expected = CHANGEABLE_BITS;
tmp_addr = MM_MapTemp(phys);
dest = (char*)tmp_addr + (0x1000 - StackSize);
memcpy( dest, StackData, StackSize );
- Log_Debug("MM", "MM_NewWorkerStack: %p->%p %i bytes (i=%i)", StackData, dest, StackSize, i);
- Log_Debug("MM", "MM_NewWorkerStack: ret = %p", ret);
MM_FreeTemp(tmp_addr);
}
\r
#define _COMMON_H\r
#define SysDebug(v...) LOG(v)\r
-#define DISABLE_ELF64\r
+#if BITS <= 32\r
+# define DISABLE_ELF64\r
+#endif\r
void *GetSymbol(const char *Name, size_t *Size);\r
void *GetSymbol(const char *Name, size_t *Size) { Uint val; Binary_GetSymbol(Name, &val); if(Size)*Size=0; return (void*)val; };\r
#define AddLoaded(a,b) do{}while(0)\r
\r
int Elf_Relocate(void *Base)\r
{\r
- return ElfRelocate(Base, (char**){NULL}, "") != NULL;\r
+ return ElfRelocate(Base, (char**){NULL}, "") != NULL;\r
}\r
int Elf_GetSymbol(void *Base, const char *Name, Uint *ret)\r
{\r
tKernelBin *pKBin;
int numKSyms = ((Uint)&gKernelSymbolsEnd-(Uint)&gKernelSymbols)/sizeof(tKernelSymbol);
+ LOG("numKSyms = %i", numKSyms);
+
// Scan Kernel
for( i = 0; i < numKSyms; i++ )
{
+ LOG("KSym %s = %p", gKernelSymbols[i].Name, gKernelSymbols[i].Value);
if(strcmp(Name, gKernelSymbols[i].Name) == 0) {
*Value = gKernelSymbols[i].Value;
return 1;
// TODO: I need a way of relocating the dependencies before everything else, so
// they can be resolved before any other link errors
if( !Binary_Relocate(base) ) {
- Log_Warning("Relocation of module %s failed", Path);
+ Log_Warning("Module", "Relocation of module %s failed", Path);
Binary_Unload(base);
return 0;
}
}
if( !Module_int_ResolveDeps(info) ) {
- Log_Warning("Dependencies not met for '%s'", Path);
+ Log_Warning("Module", "Dependencies not met for '%s'", Path);
Binary_Unload(base);
return 0;
}
* system.c
* - Architecture Independent System Init
*/
-#define DEBUG 0
+#define DEBUG 1
#include <acess.h>
#include <hal_proc.h>
int i;
Elf64_Ehdr *hdr = Base;
Elf64_Phdr *phtab;
- Elf64_Dyn *dyntab;
+ Elf64_Dyn *dyntab = NULL;
Elf64_Addr compiledBase = -1, baseDiff;
Elf64_Sym *symtab = NULL;
char *strtab = NULL;
DEBUGS("Elf64Relocate: e_phnum = %i", hdr->e_phnum);
// Scan for the dynamic table (and find the compiled base)
- phtab = Base + hdr->e_phoff;
+ phtab = (void*)((uintptr_t)Base + hdr->e_phoff);
for( i = 0; i < hdr->e_phnum; i ++ )
{
if(phtab[i].p_type == PT_DYNAMIC)
break;
case R_X86_64_COPY: {
size_t size;
- void *sym = GetSymbol(symname, &size);
- memcpy(ptr, sym, size);
+ void *symptr = GetSymbol(symname, &size);
+ memcpy(ptr, symptr, size);
} break;
case R_X86_64_GLOB_DAT:
*(uint64_t*)ptr = (uintptr_t)GetSymbol(symname, NULL);