]> git.buserror.net Git - polintos/scott/priv.git/blobdiff - kernel/arch/x86/misc.cc
Regs struct, int98/99
[polintos/scott/priv.git] / kernel / arch / x86 / misc.cc
index a747fb881b3ce9f7ddc6f588aa447667889a937e..a1b6e18b2dc2fb5d2171a05ac8fb9eac1da7bc6f 100644 (file)
@@ -2,23 +2,15 @@
 //
 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
 // 
-// Permission is hereby granted, free of charge, to any person obtaining a copy of
-// this software and associated documentation files (the "Software"), to deal with
-// the Software without restriction, including without limitation the rights to
-// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-// of the Software, and to permit persons to whom the Software is furnished to do
-// so, subject to the following condition:
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors or contributors be held liable for any damages
+// arising from the use of this software.
 // 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-// CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-// SOFTWARE.
+// Permission is hereby granted to everyone, free of charge, to use, copy,
+// modify, prepare derivative works of, publish, distribute, perform,
+// sublicense, and/or sell copies of the Software, provided that the above
+// copyright notice and disclaimer of warranty be included in all copies or
+// substantial portions of this software.
 
 #include <kern/types.h>
 #include <kern/libc.h>
 #include <kern/time.h>
 #include <kern/thread.h>
 #include <kern/mem.h>
+#include <kern/process.h>
+#include <kern/orb.h>
 
 #include <arch/addrs.h>
 #include <arch/multiboot.h>
+#include <arch/regs.h>
 
 extern u32 x86_init_ptbl_l2[1024];
 
@@ -42,22 +37,18 @@ namespace Arch {
        namespace Priv {
                void set_idt();
                
-               void show_regs(u32 *stack) {
+               void show_regs(Regs *regs)
+               {
                        printf("eax: 0x%08x   ecx: 0x%08x   edx: 0x%08x   ebx: 0x%08x\n"
                               "esp: 0x%08x   ebp: 0x%08x   esi: 0x%08x   edi: 0x%08x\n"
-                              "eflags: 0x%08x\n",
-                              stack[0],
-                              stack[1],
-                              stack[2],
-                              stack[3],
-                              stack[9] & 3 ? stack[11] : (u32)stack + 11 * 4,
-                              stack[5],
-                              stack[6],
-                              stack[7],
-                              stack[10]);
+                              "eflags: 0x%08x ds: %04x es: %04x ss: %04x\n",
+                              regs->eax, regs->ecx, regs->edx, regs->ebx,
+                              regs->cs & 3 ? regs->user_esp : (u32)regs + (u32)sizeof(regs),
+                              regs->ebp, regs->esi, regs->edi, regs->eflags,
+                              regs->ds, regs->es, regs->cs & 3 ? regs->user_ss : regs->ds);
                        
                        printf("Stack trace:          ");
-                       u32 *frame = (u32 *)stack[5];
+                       u32 *frame = (u32 *)regs->ebp;
                        
                        for (int i = 2; i < 32; i++) {
                                u32 stackptr = frame[1];
@@ -102,7 +93,7 @@ namespace Arch {
                
                Priv::tss.ss0 = 8;
                asm volatile("ltr %w0" : : "r" (0x18) : "memory");
-               init_thread->addr_space = new Mem::AddrSpace(x86_init_ptbl_l2);
+               init_thread->addr_space = new Mem::ProcAddrSpace(x86_init_ptbl_l2);
                init_thread->active_addr_space = init_thread->addr_space;
        }
 
@@ -126,36 +117,37 @@ namespace Arch {
 }
 
 using Arch::Priv::show_regs;
+using Arch::Priv::Regs;
 
-extern "C" void x86_do_diverr(u32 *stack)
+extern "C" void x86_do_diverr(Regs *regs)
 {
-       printf("Division error at 0x%04x:0x%08x\n", stack[9], stack[8]);
-       show_regs(stack);
+       printf("Division error at 0x%04x:0x%08x\n", regs->cs, regs->eip);
+       show_regs(regs);
        for(;;);
 }
 
-extern "C" void x86_do_debug(u32 *stack)
+extern "C" void x86_do_debug(Regs *regs)
 {
-       printf("Debug exception at 0x%04x:0x%08x\n", stack[9], stack[8]);
-       show_regs(stack);
+       printf("Debug exception at 0x%04x:0x%08x\n", regs->cs, regs->eip);
+       show_regs(regs);
        for(;;);
 }
 
-extern "C" void x86_do_breakpoint(u32 *stack)
+extern "C" void x86_do_breakpoint(Regs *regs)
 {
-       printf("Breakpoint at 0x%04x:0x%08x\n", stack[9], stack[8]);
-       show_regs(stack);
+       printf("Breakpoint at 0x%04x:0x%08x\n", regs->cs, regs->eip);
+       show_regs(regs);
        for(;;);
 }
 
-extern "C" void x86_do_invalid_insn(u32 *stack)
+extern "C" void x86_do_invalid_insn(Regs *regs)
 {
-       printf("Invalid instruction at 0x%04x:0x%08x\n", stack[9], stack[8]);
-       show_regs(stack);
+       printf("Invalid instruction at 0x%04x:0x%08x\n", regs->cs, regs->eip);
+       show_regs(regs);
        for(;;);
 }
 
-extern "C" void x86_do_page_fault(u32 *stack, u32 fault_addr, u32 error_code)
+extern "C" void x86_do_page_fault(Regs *regs, u32 fault_addr, u32 error_code)
 {
        Mem::AddrSpace *as;
 
@@ -174,7 +166,7 @@ extern "C" void x86_do_page_fault(u32 *stack, u32 fault_addr, u32 error_code)
        // accomplish much other than decreasing the odds that the fault message
        // gets out.
        
-       if (!(stack[10] & 0x200))
+       if (!(regs->eflags & 0x200))
                goto bad_fault;
        
        // Don't allow fault-ins using a borrowed addr-space.
@@ -197,14 +189,14 @@ bad_fault:
        in_fault++;
        
        printf("Page fault at 0x%04x:0x%08x for 0x%08x, error code: 0x%04x\n",
-              stack[9], stack[8], fault_addr, error_code);
+              regs->cs, regs->eip, fault_addr, error_code);
        
-       show_regs(stack);
+       show_regs(regs);
 
        for(;;);
 }
 
-extern "C" void x86_do_gpf(u32 *stack, u32 error_code)
+extern "C" void x86_do_gpf(Regs *regs, u32 error_code)
 {
        if (in_fault)
                for(;;);
@@ -212,9 +204,9 @@ extern "C" void x86_do_gpf(u32 *stack, u32 error_code)
        in_fault++;
 
        printf("General protection fault at 0x%04x:0x%08x, error code: 0x%04x\n",
-              stack[9], stack[8], error_code);
+              regs->cs, regs->eip, error_code);
 
-       show_regs(stack);
+       show_regs(regs);
        
        for(;;);
 }
@@ -223,3 +215,32 @@ extern "C" void x86_do_irq(int irq)
 {
        IRQ::i8259.handle_irq(irq - 0x20);
 }
+
+namespace Arch {
+namespace Priv {
+       struct OrbRegs {
+               union {
+                       System::RunTime::ParamInfoBlock *pib;
+                       ulong exptr;
+               };
+               
+               union {
+                       ulong caller;
+                       ulong exlen;
+               };
+               
+               ulong eip, cs, eflags, user_esp, user_ss;
+       };
+}}
+
+extern "C" void x86_invoke_method(Arch::Priv::OrbRegs *regs)
+{
+       assert(regs->cs & 3);
+       ORB::invoke_method(regs->pib, regs->user_esp);
+}
+
+extern "C" void x86_return_from_method(Arch::Priv::OrbRegs *regs)
+{
+       assert(regs->cs & 3);
+       regs->user_esp = ORB::return_from_method(regs->exptr, regs->exlen);
+}