Module Name: src
Committed By: maxv
Date: Thu May 12 09:40:23 UTC 2016
Modified Files:
src/sys/arch/amd64/amd64: mptramp.S
src/sys/arch/i386/i386: mptramp.S
Log Message:
KNF, and reduce the diff between amd64 and i386.
To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/amd64/amd64/mptramp.S
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/i386/i386/mptramp.S
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/amd64/amd64/mptramp.S
diff -u src/sys/arch/amd64/amd64/mptramp.S:1.21 src/sys/arch/amd64/amd64/mptramp.S:1.22
--- src/sys/arch/amd64/amd64/mptramp.S:1.21 Wed May 11 19:35:08 2016
+++ src/sys/arch/amd64/amd64/mptramp.S Thu May 12 09:40:23 2016
@@ -1,6 +1,6 @@
-/* $NetBSD: mptramp.S,v 1.21 2016/05/11 19:35:08 maxv Exp $ */
+/* $NetBSD: mptramp.S,v 1.22 2016/05/12 09:40:23 maxv Exp $ */
-/*-
+/*
* Copyright (c) 2000, 2016 The NetBSD Foundation, Inc.
* All rights reserved.
*
@@ -71,7 +71,7 @@
* 1) Get the processors running kernel-code from a special
* page-table and stack page, do chip identification.
* 2) halt the processors waiting for them to be enabled
- * by a idle-thread
+ * by a idle-thread
*/
#include "opt_mpbios.h" /* for MPDEBUG */
@@ -84,10 +84,10 @@
#include <machine/i82489reg.h>
#include <machine/gdt.h>
-#define _RELOC(x) ((x) - KERNBASE)
-#define RELOC(x) _RELOC(_C_LABEL(x))
+#define _RELOC(x) ((x) - KERNBASE)
+#define RELOC(x) _RELOC(_C_LABEL(x))
-#define _TRMP_LABEL(a) a = . - _C_LABEL(cpu_spinup_trampoline) + MP_TRAMPOLINE
+#define _TRMP_LABEL(a) a = . - _C_LABEL(cpu_spinup_trampoline) + MP_TRAMPOLINE
#ifdef MPDEBUG
/*
@@ -131,10 +131,10 @@ LABEL(cpu_spinup_trampoline)
#ifdef __clang__
lgdt (mptramp_gdt32_desc) /* load flat descriptor table */
#else
- data32 addr32 lgdt (mptramp_gdt32_desc) /* load flat descriptor table */
+ data32 addr32 lgdt (mptramp_gdt32_desc) /* load flat descriptor table */
#endif
movl %cr0, %eax /* get cr0 */
- orl $0x1, %eax /* enable protected mode */
+ orl $CR0_PE, %eax /* enable protected mode */
movl %eax, %cr0 /* doit */
ljmpl $0x8, $mp_startup
@@ -149,7 +149,7 @@ _TRMP_LABEL(mp_startup)
movw %ax, %gs
/* bootstrap stack end, with scratch space.. */
- movl $(MP_TRAMPOLINE+NBPG-16),%esp
+ movl $(MP_TRAMPOLINE+PAGE_SIZE-16),%esp
#ifdef MPDEBUG
leal RELOC(cpu_trace),%edi
@@ -208,8 +208,8 @@ mptramp_compat:
ljmp *(%eax)
_TRMP_LABEL(mptramp_jmp64)
- .long mptramp_longmode
- .word GSEL(GCODE_SEL, SEL_KPL)
+ .long mptramp_longmode
+ .word GSEL(GCODE_SEL, SEL_KPL)
#define GDT_LIMIT 0x17 /* 23 = 3 * 8 - 1 */
_TRMP_LABEL(mptramp_gdt32)
@@ -237,8 +237,8 @@ _TRMP_LABEL(mptramp_longmode)
_C_LABEL(cpu_spinup_trampoline_end): /* end of code copied to MP_TRAMPOLINE */
-1:
/* Don't touch lapic until BP has done init sequence. */
+1:
movq _C_LABEL(cpu_starting),%rdi
pause
testq %rdi, %rdi
Index: src/sys/arch/i386/i386/mptramp.S
diff -u src/sys/arch/i386/i386/mptramp.S:1.27 src/sys/arch/i386/i386/mptramp.S:1.28
--- src/sys/arch/i386/i386/mptramp.S:1.27 Sun Feb 2 22:41:20 2014
+++ src/sys/arch/i386/i386/mptramp.S Thu May 12 09:40:23 2016
@@ -1,13 +1,11 @@
-/* $NetBSD: mptramp.S,v 1.27 2014/02/02 22:41:20 dsl Exp $ */
+/* $NetBSD: mptramp.S,v 1.28 2016/05/12 09:40:23 maxv Exp $ */
-/*-
- * Copyright (c) 2000 The NetBSD Foundation, Inc.
+/*
+ * Copyright (c) 2000, 2016 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
- * by RedBack Networks Inc.
- *
- * Author: Bill Sommerfeld
+ * by RedBack Networks Inc. (Author: Bill Sommerfeld), and Maxime Villard.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,7 +28,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-
+
/*
* Copyright (c) 1999 Stefan Grefen
*
@@ -62,24 +60,25 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
/*
* MP startup ...
- * the stuff from cpu_spinup_trampoline to mp_startup
- * is copied into the first 640 KB
+ * the stuff from cpu_spinup_trampoline to mp_startup is copied into the
+ * first 640 KB.
*
* We startup the processors now when the kthreads become ready.
* The steps are:
- * 1) Get the processors running kernel-code from a special
- * page-table and stack page, do chip identification.
- * 2) halt the processors waiting for them to be enabled
- * by a idle-thread
+ * 1) Get the processors running kernel-code from a special
+ * page-table and stack page, do chip identification.
+ * 2) halt the processors waiting for them to be enabled
+ * by a idle-thread
*/
#include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: mptramp.S,v 1.27 2014/02/02 22:41:20 dsl Exp $");
-
+__KERNEL_RCSID(0, "$NetBSD: mptramp.S,v 1.28 2016/05/12 09:40:23 maxv Exp $");
+
#include "opt_mpbios.h" /* for MPDEBUG */
-
+
#include "assym.h"
#include <machine/specialreg.h>
#include <machine/segments.h>
@@ -87,29 +86,34 @@ __KERNEL_RCSID(0, "$NetBSD: mptramp.S,v
#include <machine/i82489reg.h>
#include <machine/gdt.h>
-#define GDTE(a,b) .byte 0xff,0xff,0x0,0x0,0x0,a,b,0x0
-#define _RELOC(x) ((x) - KERNBASE)
-#define RELOC(x) _RELOC(_C_LABEL(x))
+#define GDTE(a,b) .byte 0xff,0xff,0x0,0x0,0x0,a,b,0x0
+#define _RELOC(x) ((x) - KERNBASE)
+#define RELOC(x) _RELOC(_C_LABEL(x))
-#define _TRMP_LABEL(a) a = . - _C_LABEL(cpu_spinup_trampoline) + MP_TRAMPOLINE
+#define _TRMP_LABEL(a) a = . - _C_LABEL(cpu_spinup_trampoline) + MP_TRAMPOLINE
#ifdef MPDEBUG
-
/*
* Debug code to stop aux. processors in various stages based on the
* value in cpu_trace.
*
- * %edi points at cpu_trace; cpu_trace[0] is the "hold point";
- * cpu_trace[1] is the point which the CPU has reached.
+ * %edi points at cpu_trace;
+ * cpu_trace[0] is the "hold point";
+ * cpu_trace[1] is the point which the CPU has reached;
* cpu_trace[2] is the last value stored by HALTT.
*/
-
-#define HALT(x) 1: movl (%edi),%ebx;cmpl $ x,%ebx ; jle 1b ; movl $x,4(%edi)
-#define HALTT(x,y) movl y,8(%edi); HALT(x)
+#define HALT(x) \
+1: movl (%edi),%ebx ; \
+ cmpl $x,%ebx ; \
+ jle 1b ; \
+ movl $x,4(%edi) ;
+#define HALTT(x,y) \
+ movl y,8(%edi) ; \
+ HALT(x) ;
#else
-#define HALT(x) /**/
-#define HALTT(x,y) /**/
-#endif
+#define HALT(x)
+#define HALTT(x,y)
+#endif /* MPDEBUG */
.global _C_LABEL(cpu_spinup_trampoline)
.global _C_LABEL(cpu_spinup_trampoline_end)
@@ -121,52 +125,53 @@ __KERNEL_RCSID(0, "$NetBSD: mptramp.S,v
/* XXX ENTRY() */
LABEL(cpu_spinup_trampoline)
cli
- xorw %ax,%ax
- movw %ax, %ds
- movw %ax, %es
- movw %ax, %ss
+ xorw %ax,%ax
+ movw %ax,%ds
+ movw %ax,%es
+ movw %ax,%ss
#ifdef __clang__
- lgdt (gdt_desc) # load flat descriptor table
+ lgdt (gdt_desc) /* load flat descriptor table */
#else
- data32 addr32 lgdt (gdt_desc) # load flat descriptor table
+ data32 addr32 lgdt (gdt_desc) /* load flat descriptor table */
#endif
- movl %cr0, %eax # get cr0
- orl $CR0_PE, %eax # enable protected mode
- movl %eax, %cr0 # doit
- ljmpl $0x8, $mp_startup
+ movl %cr0, %eax /* get cr0 */
+ orl $CR0_PE, %eax /* enable protected mode */
+ movl %eax, %cr0 /* doit */
+ ljmpl $0x8, $mp_startup
_TRMP_LABEL(mp_startup)
.code32
- movl $0x10, %eax # data segment
- movw %ax, %ds
- movw %ax, %ss
- movw %ax, %es
- movw %ax, %fs
- movw %ax, %gs
-
- movl $ (MP_TRAMPOLINE+PAGE_SIZE-16),%esp # bootstrap stack end,
- # with scratch space..
-
+ movl $0x10, %eax /* data segment */
+ movw %ax, %ds
+ movw %ax, %ss
+ movw %ax, %es
+ movw %ax, %fs
+ movw %ax, %gs
+
+ /* bootstrap stack end, with scratch space.. */
+ movl $(MP_TRAMPOLINE+PAGE_SIZE-16),%esp
+
#ifdef MPDEBUG
- leal RELOC(cpu_trace),%edi
+ leal RELOC(cpu_trace),%edi
#endif
HALT(0x1)
/* First, reset the PSL. */
- pushl $PSL_MBO
+ pushl $PSL_MBO
popfl
-
+
+ /* Enable PSE if available */
movl RELOC(pmap_largepages),%eax
orl %eax,%eax
- jz 1f
+ jz no_PSE
movl %cr4,%eax
orl $CR4_PSE,%eax
movl %eax,%cr4
+no_PSE:
-1:
-
-#ifdef PAE /* Enable PAE */
+#ifdef PAE
+ /* Enable PAE */
movl %cr4,%eax
or $CR4_PAE,%eax
movl %eax,%cr4
@@ -174,16 +179,15 @@ _TRMP_LABEL(mp_startup)
movl RELOC(mp_pdirpa),%ecx
HALTT(0x5,%ecx)
-
- /* Load base of page directory and enable mapping. */
- movl %ecx,%cr3 # load ptd addr into mmu
- movl %cr0,%eax # get control word
- # enable paging & the fpu
- orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM),%eax
- movl %eax,%cr0 # and page NOW!
+
+ /* Load base of page directory and enable mapping. */
+ movl %ecx,%cr3 /* load PTD addr into MMU */
+ movl %cr0,%eax
+ orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM),%eax
+ movl %eax,%cr0
#ifdef MPDEBUG
- leal _C_LABEL(cpu_trace),%edi
+ leal _C_LABEL(cpu_trace),%edi
#endif
HALT(0x6)
@@ -211,81 +215,83 @@ _TRMP_LABEL(mp_startup)
pause
testl %ecx, %ecx
jz 1b
-
+
HALTT(0x7, %ecx)
/* %ecx points at our cpu_info structure. */
- movw $((MAXGDTSIZ*8) - 1), 6(%esp) # prepare segment descriptor
- movl CPU_INFO_GDT(%ecx), %eax # for our real gdt
- movl %eax, 8(%esp)
+ movw $((MAXGDTSIZ*8) - 1), 6(%esp) /* prepare segment descriptor */
+ movl CPU_INFO_GDT(%ecx), %eax /* for our real gdt */
+ movl %eax, 8(%esp)
lgdt 6(%esp)
- HALT(0x8)
+ HALT(0x8)
jmp 1f
nop
-1:
+1:
HALT(0x12)
- movl $GSEL(GDATA_SEL, SEL_KPL),%eax #switch to new segment
- movl %eax,%ds
- movl %eax,%es
- movl %eax,%ss
+ movl $GSEL(GDATA_SEL, SEL_KPL),%eax /* switch to new segment */
+ movl %eax,%ds
+ movl %eax,%es
+ movl %eax,%ss
HALT(0x13)
- pushl $GSEL(GCODE_SEL, SEL_KPL)
+ pushl $GSEL(GCODE_SEL, SEL_KPL)
pushl $mp_cont
HALT(0x14)
lret
- .align 4,0x0
-_TRMP_LABEL(gdt_table)
- .word 0x0,0x0,0x0,0x0 # null gdte
- GDTE(0x9f,0xcf) # Kernel text
- GDTE(0x93,0xcf) # Kernel data
-_TRMP_LABEL(gdt_desc)
- .word 0x17 # limit 3 entries
- .long gdt_table # base of gdt
-
-_C_LABEL(cpu_spinup_trampoline_end): #end of code copied to MP_TRAMPOLINE
+ .align 4,0x0
+
+_TRMP_LABEL(gdt_table)
+ .word 0x0,0x0,0x0,0x0 /* null gdte */
+ GDTE(0x9f,0xcf) /* Kernel text */
+ GDTE(0x93,0xcf) /* Kernel data */
+_TRMP_LABEL(gdt_desc)
+ .word 0x17 /* limit 3 entries */
+ .long gdt_table /* base of gdt */
+
+_C_LABEL(cpu_spinup_trampoline_end): /* end of code copied to MP_TRAMPOLINE */
+
mp_cont:
HALT(0x15)
movl CPU_INFO_IDLELWP(%ecx),%esi
movl L_PCB(%esi),%esi
-
+
/* %esi now points at our PCB. */
-
+
HALTT(0x19, %esi)
-
+
movl PCB_ESP(%esi),%esp
movl PCB_EBP(%esi),%ebp
-
- HALT(0x20)
+
+ HALT(0x20)
/* Switch address space. */
movl PCB_CR3(%esi),%eax
- HALTT(0x22, %eax)
+ HALTT(0x22, %eax)
movl %eax,%cr3
HALT(0x25)
/* load segment registers. */
movl $GSEL(GCPU_SEL, SEL_KPL),%eax
- HALTT(0x26,%eax)
- movl %eax,%fs
+ HALTT(0x26,%eax)
+ movl %eax,%fs
xorl %eax,%eax
- HALTT(0x27,%eax)
+ HALTT(0x27,%eax)
movl %eax,%gs
- movl PCB_CR0(%esi),%eax
- HALTT(0x28,%eax)
- movl %eax,%cr0
- HALTT(0x30,%ecx)
+ movl PCB_CR0(%esi),%eax
+ HALTT(0x28,%eax)
+ movl %eax,%cr0
+ HALTT(0x30,%ecx)
pushl %ecx
call _C_LABEL(cpu_hatch)
END(cpu_spinup_trampoline)
-
+
.data
LABEL(mp_pdirpa)
.long 0
END(mp_pdirpa)
#ifdef MPDEBUG
LABEL(cpu_trace)
- .long 0x40
- .long 0xff
- .long 0xff
+ .long 0x40
+ .long 0xff
+ .long 0xff
END(cpu_trace)
#endif