From 07f9fb8350b7f90fe1942c80ef5003d068a7bf00 Mon Sep 17 00:00:00 2001 From: Abel Romero PĂ©rez Date: Thu, 28 Jun 2018 00:00:14 -0400 Subject: initial commit --- configfrag.ac | 2 +- i386/i386/cswitch.S | 7 ++++--- i386/i386/lock.h | 18 +++++++++--------- i386/i386/locore.S | 19 ++++++++++--------- kern/cpu_number.h | 6 +++++- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/configfrag.ac b/configfrag.ac index 3d7033ec..d1fe1018 100644 --- a/configfrag.ac +++ b/configfrag.ac @@ -32,7 +32,7 @@ AC_DEFINE([BOOTSTRAP_SYMBOLS], [0], [BOOTSTRAP_SYMBOLS]) # Multiprocessor support is still broken. AH_TEMPLATE([MULTIPROCESSOR], [set things up for a uniprocessor]) -mach_ncpus=1 +mach_ncpus=2 AC_DEFINE_UNQUOTED([NCPUS], [$mach_ncpus], [number of CPUs]) [if [ $mach_ncpus -gt 1 ]; then] AC_DEFINE([MULTIPROCESSOR], [1], [set things up for a multiprocessor]) diff --git a/i386/i386/cswitch.S b/i386/i386/cswitch.S index 718c8aac..970255a7 100644 --- a/i386/i386/cswitch.S +++ b/i386/i386/cswitch.S @@ -29,6 +29,7 @@ #include #include #include +.include "i386/cpu_number.S" /* * Context switch routines for i386. @@ -39,7 +40,7 @@ ENTRY(Load_context) movl TH_KERNEL_STACK(%ecx),%ecx /* get kernel stack */ lea KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%ecx),%edx /* point to stack top */ - CPU_NUMBER(%eax) + CPU_NUMBER %eax movl %ecx,CX(EXT(active_stacks),%eax) /* store stack address */ movl %edx,CX(EXT(kernel_stack),%eax) /* store stack top */ @@ -57,7 +58,7 @@ ENTRY(Load_context) */ ENTRY(Switch_context) - CPU_NUMBER(%edx) + CPU_NUMBER %edx movl CX(EXT(active_stacks),%edx),%ecx /* get old kernel stack */ movl %ebx,KSS_EBX(%ecx) /* save registers */ @@ -109,7 +110,7 @@ ENTRY(Thread_continue) * has no FPU state) */ ENTRY(switch_to_shutdown_context) - CPU_NUMBER(%edx) + CPU_NUMBER %edx movl EXT(active_stacks)(,%edx,4),%ecx /* get old kernel stack */ movl %ebx,KSS_EBX(%ecx) /* save registers */ movl %ebp,KSS_EBP(%ecx) diff --git a/i386/i386/lock.h b/i386/i386/lock.h index 8efa0ca0..29214538 100644 --- a/i386/i386/lock.h +++ b/i386/i386/lock.h @@ -43,15 +43,15 @@ * The code here depends on the GNU C compiler. */ -#define _simple_lock_xchg_(lock, new_val) \ - ({ int _old_val_; \ - asm volatile("xchgl %0, %2" \ - : "=r" (_old_val_) \ - : "0" (new_val), "m" (*(lock)) : "memory" \ - ); \ - _old_val_; \ - }) - +/*#define _simple_lock_xchg_(lock, new_val) \ + * ({ int _old_val_; \ + * asm volatile("xchgl %0, %2" \ + * : "=r" (_old_val_) \ + * : "0" (new_val), "m" (*(lock)) : "memory" \ + * ); \ + * _old_val_; \ + * }) +*/ #define simple_lock_init(l) \ ((l)->lock_data = 0) diff --git a/i386/i386/locore.S b/i386/i386/locore.S index ddba2245..265a5d1d 100644 --- a/i386/i386/locore.S +++ b/i386/i386/locore.S @@ -37,6 +37,7 @@ #include #include #include +.include "i386/cpu_number.S" /* * Fault recovery. @@ -243,7 +244,7 @@ timer_normalize: * Switch to a new timer. */ ENTRY(timer_switch) - CPU_NUMBER(%edx) /* get this CPU */ + CPU_NUMBER %edx /* get this CPU */ movl VA_ETC,%ecx /* get timer */ movl CX(EXT(current_tstamp),%edx),%eax /* get old time stamp */ movl %ecx,CX(EXT(current_tstamp),%edx) /* set new time stamp */ @@ -261,7 +262,7 @@ ENTRY(timer_switch) * Initialize the first timer for a CPU. */ ENTRY(start_timer) - CPU_NUMBER(%edx) /* get this CPU */ + CPU_NUMBER %edx /* get this CPU */ movl VA_ETC,%ecx /* get timer */ movl %ecx,CX(EXT(current_tstamp),%edx) /* set initial time stamp */ movl S_ARG0,%ecx /* get timer */ @@ -479,7 +480,7 @@ trap_set_segs: jz trap_from_kernel /* kernel trap if not */ trap_from_user: - CPU_NUMBER(%edx) + CPU_NUMBER %edx TIME_TRAP_UENTRY movl CX(EXT(kernel_stack),%edx),%ebx @@ -501,7 +502,7 @@ _take_trap: */ _return_from_trap: - CPU_NUMBER(%edx) + CPU_NUMBER %edx cmpl $0,CX(EXT(need_ast),%edx) jz _return_to_user /* if we need an AST: */ @@ -547,7 +548,7 @@ trap_from_kernel: cmpl EXT(int_stack_base),%edx je 1f /* OK if so */ - CPU_NUMBER(%edx) /* get CPU number */ + CPU_NUMBER %edx /* get CPU number */ cmpl CX(EXT(kernel_stack),%edx),%esp /* already on kernel stack? */ ja 0f @@ -664,7 +665,7 @@ ENTRY(all_intrs) mov %dx,%fs mov %dx,%gs - CPU_NUMBER(%edx) + CPU_NUMBER %edx movl CX(EXT(int_stack_top),%edx),%ecx xchgl %ecx,%esp /* switch to interrupt stack */ @@ -683,7 +684,7 @@ ENTRY(all_intrs) .globl EXT(return_to_iret) LEXT(return_to_iret) /* ( label for kdb_kintr and hardclock) */ - CPU_NUMBER(%edx) + CPU_NUMBER %edx #if STAT_TIME #else TIME_INT_EXIT /* do timing */ @@ -760,7 +761,7 @@ ast_from_interrupt: mov %dx,%fs mov %dx,%gs - CPU_NUMBER(%edx) + CPU_NUMBER %edx TIME_TRAP_UENTRY movl CX(EXT(kernel_stack),%edx),%esp @@ -1025,7 +1026,7 @@ syscall_entry_2: movl %edx,R_CS(%esp) /* fix cs */ movl %ebx,R_EFLAGS(%esp) /* fix eflags */ - CPU_NUMBER(%edx) + CPU_NUMBER %edx TIME_TRAP_SENTRY movl CX(EXT(kernel_stack),%edx),%ebx diff --git a/kern/cpu_number.h b/kern/cpu_number.h index 5d3e4bd1..2ea510e4 100644 --- a/kern/cpu_number.h +++ b/kern/cpu_number.h @@ -37,7 +37,11 @@ int master_cpu; /* 'master' processor - keeps time */ /* cpu number is always 0 on a single processor system */ #define cpu_number() (0) -#endif /* NCPUS == 1 */ +#else /* NCPUS == 1 */ + +extern int cpu_number(void); + +#endif /* NCPUS != 1 */ #define CPU_L1_SIZE (1 << CPU_L1_SHIFT) -- cgit v1.2.3