From 4bc2841ef0c262d5724da569156e7ef475d3c894 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Thu, 8 Sep 2011 21:09:14 +0200 Subject: [PATCH] Restored the partial support for x64. --- sortix/keyboard.cpp | 2 ++ sortix/memorymanagement.cpp | 14 +++++++++++++- sortix/memorymanagement.h | 6 ++++++ sortix/process.cpp | 2 ++ sortix/scheduler.cpp | 17 +++++++++++------ sortix/sound.cpp | 2 ++ sortix/vga.cpp | 8 +++++++- sortix/x64/memorymanagement-asm.s | 14 +++++++------- 8 files changed, 50 insertions(+), 15 deletions(-) diff --git a/sortix/keyboard.cpp b/sortix/keyboard.cpp index 7fbbc34d..6fe4e51a 100644 --- a/sortix/keyboard.cpp +++ b/sortix/keyboard.cpp @@ -715,6 +715,7 @@ namespace Sortix void SysReceieveKeystroke(CPU::InterruptRegisters* R) { +#ifdef PLATFORM_X86 uint32_t codepoint; if ( keystrokeQueueUsed == 0 ) { @@ -728,6 +729,7 @@ namespace Sortix keystrokeQueueUsed--; } R->eax = codepoint; +#endif } } } diff --git a/sortix/memorymanagement.cpp b/sortix/memorymanagement.cpp index bc4e381f..68569fd3 100644 --- a/sortix/memorymanagement.cpp +++ b/sortix/memorymanagement.cpp @@ -131,6 +131,8 @@ namespace Sortix #ifdef PLATFORM_X64 Log::Print("Halt: CPU X64 cannot continue as the virtual memory isn't disabled (kernel bug) and the code is about to access non-mapped memory.\n"); + Log::Print("Sorry, it simply isn't possible to fully boot Sortix in x64 mode yet.\n"); + Log::Print("X64 may be working when Sortix 0.5 comes out, or try the git master.\n"); while(true); #endif @@ -627,11 +629,21 @@ namespace Sortix #warning "Virtual Memory is not available on this arch" + addr_t Lookup(addr_t where) { while(true); return 0; } void Flush() { while(true); } - void SwitchDirectory(addr_t dir) { while(true); } + addr_t CreateAddressSpace() { while(true); return 0; } + addr_t SwitchAddressSpace(addr_t addrspace) { while(true); return 0; } + addr_t SwitchDirectory(addr_t dir) { while(true); return 0; } addr_t CreateDirectory() { while(true); return 0; } + void MapKernel(addr_t where, addr_t physical) { while(true); } addr_t UnmapKernel(addr_t where) { while(true); return 0; } + Table* CreateUserTable(addr_t where, bool maycreate) { while(true); return NULL; } + bool MapUser(addr_t where, addr_t physical) { while(true); return false; } addr_t UnmapUser(addr_t where) { while(true); return 0; } + bool MapRangeKernel(addr_t where, size_t bytes) { while(true); return false; } + void UnmapRangeKernel(addr_t where, size_t bytes) { while(true); } + bool MapRangeUser(addr_t where, size_t bytes) { while(true); return false; } + void UnmapRangeUser(addr_t where, size_t bytes) { while(true); } #endif } diff --git a/sortix/memorymanagement.h b/sortix/memorymanagement.h index 3f3ed79b..693fc66e 100644 --- a/sortix/memorymanagement.h +++ b/sortix/memorymanagement.h @@ -344,6 +344,12 @@ namespace Sortix // good dozen of pages onwards. Beware that this is only meant to be // a temporary place to put memory. const addr_t tempaddr = 0xFF800000UL; + +#elif defined(PLATFORM_X64) + // This isn't supported yet, so just use random values. + const addr_t heapLower = 0x80000000UL; + const addr_t heapUpper = 0xFF800000UL; + const addr_t tempaddr = 0xFF800000UL; #endif } diff --git a/sortix/process.cpp b/sortix/process.cpp index 407c2744..b58dee65 100644 --- a/sortix/process.cpp +++ b/sortix/process.cpp @@ -81,6 +81,7 @@ namespace Sortix void SysExecute(CPU::InterruptRegisters* R) { +#ifdef PLATFORM_X86 const char* programname = (const char*) R->ebx; size_t programsize = 0; @@ -96,5 +97,6 @@ namespace Sortix R->eip = entry; R->useresp = 0x80000000UL; R->ebp = 0x80000000UL; +#endif } } diff --git a/sortix/scheduler.cpp b/sortix/scheduler.cpp index cfa54a39..b41fc78f 100644 --- a/sortix/scheduler.cpp +++ b/sortix/scheduler.cpp @@ -261,6 +261,11 @@ namespace Sortix // Create a new thread data structure. Thread* thread = new Thread(Process, AllocatedThreadId++, PhysStack, StackLength); +#ifndef PLATFORM_X86 + #warning "No threads are available on this arch" + while(true); +#endif + #ifdef PLATFORM_X86 uintptr_t StackPos = 0x80000000UL; @@ -271,7 +276,6 @@ namespace Sortix VirtualMemory::MapUser(MapTo, PhysStack); size_t* Stack = (size_t*) StackPos; -#ifdef PLATFORM_X86 // Prepare the parameters for the entry function (C calling convention). //Stack[StackLength - 1] = (size_t) 0xFACE; // Parameter2 Stack[-1] = (size_t) Parameter2; // Parameter2 @@ -280,12 +284,7 @@ namespace Sortix Stack[-4] = (size_t) 0x0; // Eip thread->_registers.ebp = thread->_registers.useresp = (uint32_t) (StackPos - 4*sizeof(size_t)); // Point to the last word used on the stack. thread->_registers.eip = (uint32_t) Start; // Point to our entry function. -#endif -#else - #warning "No threads are available on this arch" - while(true); -#endif // Mark the thread as running, which adds it to the scheduler's linked list. thread->SetState(Thread::State::RUNNABLE); @@ -293,6 +292,8 @@ namespace Sortix // Avoid side effects by restoring the old address space. VirtualMemory::SwitchAddressSpace(OldAddrSpace); +#endif + return thread; } @@ -319,12 +320,16 @@ namespace Sortix if ( currentThread != NoopThread && currentThread->GetProcess() && sigintpending ) { +#ifdef PLATFORM_X86 Sound::Mute(); const char* programname = "sh"; R->ebx = (uint32_t) programname; SysExecute(R); sigintpending = false; Log::Print("^C\n"); +#else +#warning "Sigint is not available on this arch" +#endif } WakeSleeping(TimePassed); diff --git a/sortix/sound.cpp b/sortix/sound.cpp index 3a75ae21..fef4ccae 100644 --- a/sortix/sound.cpp +++ b/sortix/sound.cpp @@ -55,8 +55,10 @@ namespace Sortix void SysSetFrequency(CPU::InterruptRegisters* R) { +#ifdef PLATFORM_X86 unsigned frequency = R->ebx; if ( frequency == 0 ) { Mute(); } else { Play(frequency); } +#endif } } } diff --git a/sortix/vga.cpp b/sortix/vga.cpp index 6a46e779..332dbd7c 100644 --- a/sortix/vga.cpp +++ b/sortix/vga.cpp @@ -62,6 +62,7 @@ namespace Sortix void SysCreateFrame(CPU::InterruptRegisters* R) { +#ifdef PLATFORM_X86 addr_t page = Page::Get(); if ( page == NULL ) { R->eax = 0; return; } @@ -102,10 +103,12 @@ namespace Sortix process->_endcodesection = mapto + 0x1000UL; R->eax = mapto; +#endif } void SysChangeFrame(CPU::InterruptRegisters* R) { +#ifdef PLATFORM_X86 int fd = (int) R->ebx; Process* process = CurrentProcess(); @@ -167,11 +170,13 @@ namespace Sortix frame->onscreen = true; currentframe = frame; - SetCursor(width, height-1); + SetCursor(width, height-1); +#endif } void SysDeleteFrame(CPU::InterruptRegisters* R) { +#ifdef PLATFORM_X86 int fd = (int) R->ebx; Process* process = CurrentProcess(); @@ -181,6 +186,7 @@ namespace Sortix if ( device == NULL ) { R->eax = -1; return; } if ( !device->Close() ) { R->eax = -1; return; } R->eax = 0; +#endif } } diff --git a/sortix/x64/memorymanagement-asm.s b/sortix/x64/memorymanagement-asm.s index 223d1c01..178c6a1d 100644 --- a/sortix/x64/memorymanagement-asm.s +++ b/sortix/x64/memorymanagement-asm.s @@ -18,7 +18,7 @@ with Sortix. If not, see . memorymanagement-asm.s - Handles memory for the x86 architecture. + Handles memory for the x64 architecture. ******************************************************************************/ @@ -80,9 +80,9 @@ FragNext: FragDone: ret -.globl _ZN6Sortix4Page3GetEv -.type _ZN6Sortix4Page3GetEv, @function # namespace Sortix { void Paging::Allocate(); } -_ZN6Sortix4Page3GetEv: +.globl _ZN6Sortix4Page10GetPrivateEv +.type _ZN6Sortix4Page10GetPrivateEv, @function # namespace Sortix { void Paging::Allocate(); } +_ZN6Sortix4Page10GetPrivateEv: # Load the front of our linked list. movq _ZN6Sortix4Page15UnallocatedPageE, %rax # Load UnallocPage* Sortix::Page::UnallocatedPage @@ -135,9 +135,9 @@ OutOfMem: movq $0, %rax ret -.globl _ZN6Sortix4Page3PutEPv -.type _ZN6Sortix4Page3PutEPv, @function # namespace Sortix { void Paging::Free(void* Page); } -_ZN6Sortix4Page3PutEPv: +.globl _ZN6Sortix4Page10PutPrivateEm +.type _ZN6Sortix4Page10PutPrivateEm, @function # namespace Sortix { void Paging::Free(void* Page); } +_ZN6Sortix4Page10PutPrivateEm: movq _ZN6Sortix4Page15UnallocatedPageE, %rax # Load UnallocPage* Sortix::Page::UnallocatedPage # Disable virtual memory