]> rtime.felk.cvut.cz Git - l4.git/blobdiff - kernel/fiasco/src/kern/ux/usermode.cpp
update
[l4.git] / kernel / fiasco / src / kern / ux / usermode.cpp
index 254c0542986dca9cd712c8c31a74477bb652f59d..b19ac6a8021f413b37cf2769856753c3901105fd 100644 (file)
@@ -181,16 +181,16 @@ Usermode::write_debug_register (pid_t pid, Mword reg, Mword value)
  */
 PRIVATE static
 void
-Usermode::kernel_entry (unsigned _cpu,
-                        struct ucontext *context,
-                        Mword trap,
-                        Mword xss,
-                        Mword esp,
-                        Mword efl,
-                        Mword xcs,
-                        Mword eip,
-                        Mword err,
-                        Mword cr2)
+Usermode::kernel_entry(Cpu_number _cpu,
+                       struct ucontext *context,
+                       Mword trap,
+                       Mword xss,
+                       Mword esp,
+                       Mword efl,
+                       Mword xcs,
+                       Mword eip,
+                       Mword err,
+                       Mword cr2)
 {
   Mword *kesp = (xcs & 3) == 3
               ? (Mword *) Cpu::cpus.cpu(_cpu).kernel_sp() - 5
@@ -212,7 +212,7 @@ Usermode::kernel_entry (unsigned _cpu,
   if ((Mword) kesp % THREAD_BLOCK_SIZE <= 512)
     {
       printf("KERNEL BUG: Kernel stack of thread ");
-      printf("DBGID=%lx\n", static_cast<Thread*>(context_of(kesp))->dbg_id());
+      printf("DBGID=%lx\n", static_cast<Thread*>(context_of(kesp))->dbg_info()->dbg_id());
       panic(" exceeded (%p, %c). \n"
             "            As a workaround, please make sure that you built \n"
             "            Fiasco-UX with enabled CONTEXT_4K.",
@@ -263,7 +263,6 @@ Usermode::kip_syscall (Address eip)
     return 0;
 
   Mword trap = 0x30 + (eip - Mem_layout::Syscalls >> 8);
-  if (trap == 0x38) trap = 0x39;
 
   return Emulation::idt_vector (trap, true) ? trap : 0;
 }
@@ -282,8 +281,8 @@ Usermode::l4_syscall (Mword opcode)
 
 PRIVATE static inline NOEXPORT NEEDS["thread_state.h"]
 bool
-Usermode::user_exception (unsigned _cpu, pid_t pid, struct ucontext *context,
-                          struct user_regs_struct *regs)
+Usermode::user_exception(Cpu_number _cpu, pid_t pid, struct ucontext *context,
+                         struct user_regs_struct *regs)
 {
   Mword trap, error = 0, addr = 0;
 
@@ -304,7 +303,7 @@ Usermode::user_exception (unsigned _cpu, pid_t pid, struct ucontext *context,
        * instructions in the syscall page.
        */
       if (EXPECT_FALSE((t->state() & (Thread_alien | Thread_dis_alien))
-                       == Thread_alien))
+                       == Thread_alien || t->space_ref()->user_mode()))
         regs->eip += 2;
       else
         {
@@ -383,9 +382,9 @@ Usermode::user_exception (unsigned _cpu, pid_t pid, struct ucontext *context,
 
 PRIVATE static inline NOEXPORT
 bool
-Usermode::user_emulation (unsigned _cpu, int stop, pid_t pid,
-                          struct ucontext *context,
-                          struct user_regs_struct *regs)
+Usermode::user_emulation(Cpu_number _cpu, int stop, pid_t pid,
+                         struct ucontext *context,
+                         struct user_regs_struct *regs)
 {
   Mword trap, error = 0;
 
@@ -452,11 +451,11 @@ Usermode::user_emulation (unsigned _cpu, int stop, pid_t pid,
  */
 PRIVATE static inline NOEXPORT
 void
-Usermode::iret_to_user_mode (unsigned _cpu,
-                             struct ucontext *context, Mword *kesp)
+Usermode::iret_to_user_mode(Cpu_number _cpu,
+                            struct ucontext *context, Mword *kesp)
 {
   struct user_regs_struct regs;
-  int stop, irq_pend;
+  int irq_pend;
   Context *t = context_of (kesp);
   pid_t pid = t->vcpu_aware_space()->pid();
 
@@ -502,7 +501,7 @@ Usermode::iret_to_user_mode (unsigned _cpu,
   regs.ebp    = context->uc_mcontext.gregs[REG_EBP];
   regs.xds    = context->uc_mcontext.gregs[REG_DS];
   regs.xes    = context->uc_mcontext.gregs[REG_ES];
-  regs.xfs    = context->uc_mcontext.gregs[REG_FS];
+  regs.xfs    = Cpu::get_fs();
   regs.xgs    = Cpu::get_gs();
 
   // ptrace will return with an error if we try to load invalid values to
@@ -514,7 +513,7 @@ Usermode::iret_to_user_mode (unsigned _cpu,
            "        Fixing up!\n");
       regs.xds = Cpu::kern_ds();
       regs.xes = Cpu::kern_es();
-      regs.xfs = 0;
+      regs.xgs = 0;
       check(ptrace (PTRACE_SETREGS, pid, NULL, &regs));
     }
   else
@@ -526,7 +525,7 @@ Usermode::iret_to_user_mode (unsigned _cpu,
     {
       ptrace (t->is_native() ? PTRACE_CONT :  PTRACE_SYSCALL, pid, NULL, NULL);
 
-      stop = wait_for_stop (pid);
+      int stop = wait_for_stop (pid);
 
       if (EXPECT_FALSE (stop == SIGWINCH || stop == SIGTERM || stop == SIGINT))
         continue;
@@ -551,7 +550,7 @@ Usermode::iret_to_user_mode (unsigned _cpu,
   context->uc_mcontext.gregs[REG_EBP] = regs.ebp;
   context->uc_mcontext.gregs[REG_DS]  = regs.xds;
   context->uc_mcontext.gregs[REG_ES]  = regs.xes;
-  context->uc_mcontext.gregs[REG_FS]  = regs.xfs;
+  Cpu::set_fs(regs.xfs);
   Cpu::set_gs(regs.xgs);
 
   Fpu::save_state (t->fpu_state());
@@ -582,7 +581,7 @@ Usermode::iret_to_kern_mode (struct ucontext *context, Mword *kesp)
  */
 PRIVATE static inline NOEXPORT
 void
-Usermode::iret (unsigned _cpu, struct ucontext *context)
+Usermode::iret(Cpu_number _cpu, struct ucontext *context)
 {
   Mword *kesp = (Mword *) context->uc_mcontext.gregs[REG_ESP];
 
@@ -610,7 +609,7 @@ Usermode::emu_handler (int, siginfo_t *, void *ctx)
   struct ucontext *context = reinterpret_cast<struct ucontext *>(ctx);
   unsigned int trap = context->uc_mcontext.gregs[REG_TRAPNO];
 
-  unsigned _cpu = Cpu::p2l(Cpu::phys_id_direct());
+  Cpu_number _cpu = Cpu::cpus.find_cpu(Cpu::By_phys_id(Cpu::phys_id_direct()));
 
   if (trap == 0xd)     /* General protection fault */
     {
@@ -665,7 +664,7 @@ Usermode::int_handler (int, siginfo_t *, void *ctx)
 
   Pic::eat (irq);
 
-  kernel_entry (Cpu::p2l(Cpu::phys_id_direct()),
+  kernel_entry (Cpu::cpus.find_cpu(Cpu::By_phys_id(Cpu::phys_id_direct())),
                 context,
                 gate,
                 context->uc_mcontext.gregs[REG_SS],     /* XSS */
@@ -697,7 +696,7 @@ Usermode::jdb_handler (int sig, siginfo_t *, void *ctx)
   signal (SIGSEGV, SIG_IGN);    // Cancel signal
   set_signal (SIGSEGV);         // Reinstall handler
 
-  kernel_entry (Cpu::p2l(Cpu::phys_id_direct()),
+  kernel_entry (Cpu::cpus.find_cpu(Cpu::By_phys_id(Cpu::phys_id_direct())),
                 context, sig == SIGTRAP ? 3 : 1,
                 context->uc_mcontext.gregs[REG_SS],     /* XSS */
                 context->uc_mcontext.gregs[REG_ESP],   /* ESP */
@@ -731,16 +730,16 @@ Usermode::set_signal (int sig)
 
 PUBLIC static FIASCO_INIT_CPU
 void
-Usermode::init(unsigned cpu)
+Usermode::init(Cpu_number cpu)
 {
   stack_t stack;
 
   /* We want signals, aka interrupts to be delivered on an alternate stack */
-  if (cpu == 0)
+  if (cpu == Cpu_number::boot_cpu())
     stack.ss_sp  = (void *) Mem_layout::phys_to_pmem
                                 (Mem_layout::Sigstack_cpu0_start_frame);
   else
-    stack.ss_sp = Mapped_allocator::allocator()->alloc(Mem_layout::Sigstack_log2_size);
+    stack.ss_sp = Kmem_alloc::allocator()->alloc(Mem_layout::Sigstack_log2_size);
   stack.ss_size  =  Mem_layout::Sigstack_size;
   stack.ss_flags = 0;
 
@@ -754,7 +753,7 @@ Usermode::init(unsigned cpu)
 
   set_signal (SIGSEGV);
   set_signal (SIGIO);
-  if (cpu == 0)
+  if (cpu == Cpu_number::boot_cpu())
     set_signal (SIGINT);
   else
     signal (SIGINT, SIG_IGN);