| @@ -1,16 +1,16 @@ | | | @@ -1,16 +1,16 @@ |
1 | /* $NetBSD: machdep.c,v 1.260 2017/07/25 17:43:44 maxv Exp $ */ | | 1 | /* $NetBSD: machdep.c,v 1.261 2017/09/28 17:35:08 maxv Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /* |
4 | * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 | | 4 | * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 |
5 | * The NetBSD Foundation, Inc. | | 5 | * The NetBSD Foundation, Inc. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * This code is derived from software contributed to The NetBSD Foundation | | 8 | * This code is derived from software contributed to The NetBSD Foundation |
9 | * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace | | 9 | * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace |
10 | * Simulation Facility, NASA Ames Research Center. | | 10 | * Simulation Facility, NASA Ames Research Center. |
11 | * | | 11 | * |
12 | * This code is derived from software contributed to The NetBSD Foundation | | 12 | * This code is derived from software contributed to The NetBSD Foundation |
13 | * by Coyote Point Systems, Inc. which was written under contract to Coyote | | 13 | * by Coyote Point Systems, Inc. which was written under contract to Coyote |
14 | * Point by Jed Davis and Devon O'Dell. | | 14 | * Point by Jed Davis and Devon O'Dell. |
15 | * | | 15 | * |
16 | * Redistribution and use in source and binary forms, with or without | | 16 | * Redistribution and use in source and binary forms, with or without |
| @@ -63,30 +63,29 @@ | | | @@ -63,30 +63,29 @@ |
63 | * notice, this list of conditions and the following disclaimer in the | | 63 | * notice, this list of conditions and the following disclaimer in the |
64 | * documentation and/or other materials provided with the distribution. | | 64 | * documentation and/or other materials provided with the distribution. |
65 | * | | 65 | * |
66 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 66 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
67 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 67 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
68 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 68 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
69 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 69 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
70 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 70 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
71 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 71 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
72 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 72 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
73 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 73 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
74 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 74 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
75 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 75 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
76 | * | | | |
77 | */ | | 76 | */ |
78 | | | 77 | |
79 | /*- | | 78 | /* |
80 | * Copyright (c) 1982, 1987, 1990 The Regents of the University of California. | | 79 | * Copyright (c) 1982, 1987, 1990 The Regents of the University of California. |
81 | * All rights reserved. | | 80 | * All rights reserved. |
82 | * | | 81 | * |
83 | * This code is derived from software contributed to Berkeley by | | 82 | * This code is derived from software contributed to Berkeley by |
84 | * William Jolitz. | | 83 | * William Jolitz. |
85 | * | | 84 | * |
86 | * Redistribution and use in source and binary forms, with or without | | 85 | * Redistribution and use in source and binary forms, with or without |
87 | * modification, are permitted provided that the following conditions | | 86 | * modification, are permitted provided that the following conditions |
88 | * are met: | | 87 | * are met: |
89 | * 1. Redistributions of source code must retain the above copyright | | 88 | * 1. Redistributions of source code must retain the above copyright |
90 | * notice, this list of conditions and the following disclaimer. | | 89 | * notice, this list of conditions and the following disclaimer. |
91 | * 2. Redistributions in binary form must reproduce the above copyright | | 90 | * 2. Redistributions in binary form must reproduce the above copyright |
92 | * notice, this list of conditions and the following disclaimer in the | | 91 | * notice, this list of conditions and the following disclaimer in the |
| @@ -101,27 +100,27 @@ | | | @@ -101,27 +100,27 @@ |
101 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 100 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
102 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 101 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
103 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 102 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
104 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 103 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
105 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 104 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
106 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 105 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
107 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 106 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
108 | * SUCH DAMAGE. | | 107 | * SUCH DAMAGE. |
109 | * | | 108 | * |
110 | * @(#)machdep.c 7.4 (Berkeley) 6/3/91 | | 109 | * @(#)machdep.c 7.4 (Berkeley) 6/3/91 |
111 | */ | | 110 | */ |
112 | | | 111 | |
113 | #include <sys/cdefs.h> | | 112 | #include <sys/cdefs.h> |
114 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.260 2017/07/25 17:43:44 maxv Exp $"); | | 113 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.261 2017/09/28 17:35:08 maxv Exp $"); |
115 | | | 114 | |
116 | /* #define XENDEBUG_LOW */ | | 115 | /* #define XENDEBUG_LOW */ |
117 | | | 116 | |
118 | #include "opt_modular.h" | | 117 | #include "opt_modular.h" |
119 | #include "opt_user_ldt.h" | | 118 | #include "opt_user_ldt.h" |
120 | #include "opt_ddb.h" | | 119 | #include "opt_ddb.h" |
121 | #include "opt_kgdb.h" | | 120 | #include "opt_kgdb.h" |
122 | #include "opt_cpureset_delay.h" | | 121 | #include "opt_cpureset_delay.h" |
123 | #include "opt_mtrr.h" | | 122 | #include "opt_mtrr.h" |
124 | #include "opt_realmem.h" | | 123 | #include "opt_realmem.h" |
125 | #include "opt_xen.h" | | 124 | #include "opt_xen.h" |
126 | #ifndef XEN | | 125 | #ifndef XEN |
127 | #include "opt_physmem.h" | | 126 | #include "opt_physmem.h" |
| @@ -1429,27 +1428,27 @@ set_sys_segment(struct sys_segment_descr | | | @@ -1429,27 +1428,27 @@ set_sys_segment(struct sys_segment_descr |
1429 | sd->sd_p = 1; | | 1428 | sd->sd_p = 1; |
1430 | sd->sd_hilimit = (unsigned)limit >> 16; | | 1429 | sd->sd_hilimit = (unsigned)limit >> 16; |
1431 | sd->sd_gran = gran; | | 1430 | sd->sd_gran = gran; |
1432 | sd->sd_hibase = (uint64_t)base >> 24; | | 1431 | sd->sd_hibase = (uint64_t)base >> 24; |
1433 | } | | 1432 | } |
1434 | | | 1433 | |
1435 | void | | 1434 | void |
1436 | cpu_init_idt(void) | | 1435 | cpu_init_idt(void) |
1437 | { | | 1436 | { |
1438 | #ifndef XEN | | 1437 | #ifndef XEN |
1439 | struct region_descriptor region; | | 1438 | struct region_descriptor region; |
1440 | | | 1439 | |
1441 | setregion(®ion, idt, NIDT * sizeof(idt[0]) - 1); | | 1440 | setregion(®ion, idt, NIDT * sizeof(idt[0]) - 1); |
1442 | lidt(®ion); | | 1441 | lidt(®ion); |
1443 | #else | | 1442 | #else |
1444 | if (HYPERVISOR_set_trap_table(xen_idt)) | | 1443 | if (HYPERVISOR_set_trap_table(xen_idt)) |
1445 | panic("HYPERVISOR_set_trap_table() failed"); | | 1444 | panic("HYPERVISOR_set_trap_table() failed"); |
1446 | #endif | | 1445 | #endif |
1447 | } | | 1446 | } |
1448 | | | 1447 | |
1449 | #define IDTVEC(name) __CONCAT(X, name) | | 1448 | #define IDTVEC(name) __CONCAT(X, name) |
1450 | typedef void (vector)(void); | | 1449 | typedef void (vector)(void); |
1451 | extern vector IDTVEC(syscall); | | 1450 | extern vector IDTVEC(syscall); |
1452 | extern vector IDTVEC(syscall32); | | 1451 | extern vector IDTVEC(syscall32); |
1453 | extern vector IDTVEC(osyscall); | | 1452 | extern vector IDTVEC(osyscall); |
1454 | extern vector *IDTVEC(exceptions)[]; | | 1453 | extern vector *IDTVEC(exceptions)[]; |
1455 | | | 1454 | |
| @@ -1485,50 +1484,52 @@ init_x86_64_ksyms(void) | | | @@ -1485,50 +1484,52 @@ init_x86_64_ksyms(void) |
1485 | ((int *)(void *)&end) + 1, esym); | | 1484 | ((int *)(void *)&end) + 1, esym); |
1486 | #endif /* XEN */ | | 1485 | #endif /* XEN */ |
1487 | #endif | | 1486 | #endif |
1488 | } | | 1487 | } |
1489 | | | 1488 | |
1490 | void | | 1489 | void |
1491 | init_x86_64(paddr_t first_avail) | | 1490 | init_x86_64(paddr_t first_avail) |
1492 | { | | 1491 | { |
1493 | extern void consinit(void); | | 1492 | extern void consinit(void); |
1494 | struct region_descriptor region; | | 1493 | struct region_descriptor region; |
1495 | struct mem_segment_descriptor *ldt_segp; | | 1494 | struct mem_segment_descriptor *ldt_segp; |
1496 | int x; | | 1495 | int x; |
1497 | struct pcb *pcb; | | 1496 | struct pcb *pcb; |
| | | 1497 | extern vaddr_t lwp0uarea; |
1498 | #ifndef XEN | | 1498 | #ifndef XEN |
1499 | extern paddr_t local_apic_pa; | | 1499 | extern paddr_t local_apic_pa; |
1500 | int ist; | | 1500 | int ist; |
1501 | #endif | | 1501 | #endif |
1502 | | | 1502 | |
1503 | KASSERT(first_avail % PAGE_SIZE == 0); | | 1503 | KASSERT(first_avail % PAGE_SIZE == 0); |
1504 | | | 1504 | |
1505 | #ifdef XEN | | 1505 | #ifdef XEN |
1506 | KASSERT(HYPERVISOR_shared_info != NULL); | | 1506 | KASSERT(HYPERVISOR_shared_info != NULL); |
1507 | cpu_info_primary.ci_vcpu = &HYPERVISOR_shared_info->vcpu_info[0]; | | 1507 | cpu_info_primary.ci_vcpu = &HYPERVISOR_shared_info->vcpu_info[0]; |
| | | 1508 | #endif |
1508 | | | 1509 | |
1509 | __PRINTK(("init_x86_64(0x%lx)\n", first_avail)); | | 1510 | uvm_lwp_setuarea(&lwp0, lwp0uarea); |
1510 | #endif /* XEN */ | | | |
1511 | | | 1511 | |
1512 | cpu_probe(&cpu_info_primary); | | 1512 | cpu_probe(&cpu_info_primary); |
1513 | cpu_init_msrs(&cpu_info_primary, true); | | 1513 | cpu_init_msrs(&cpu_info_primary, true); |
1514 | | | 1514 | |
1515 | use_pae = 1; /* PAE always enabled in long mode */ | | 1515 | use_pae = 1; /* PAE always enabled in long mode */ |
1516 | | | 1516 | |
1517 | pcb = lwp_getpcb(&lwp0); | | 1517 | pcb = lwp_getpcb(&lwp0); |
1518 | #ifdef XEN | | 1518 | #ifdef XEN |
1519 | mutex_init(&pte_lock, MUTEX_DEFAULT, IPL_VM); | | 1519 | mutex_init(&pte_lock, MUTEX_DEFAULT, IPL_VM); |
1520 | pcb->pcb_cr3 = xen_start_info.pt_base - KERNBASE; | | 1520 | pcb->pcb_cr3 = xen_start_info.pt_base - KERNBASE; |
1521 | __PRINTK(("pcb_cr3 0x%lx\n", xen_start_info.pt_base - KERNBASE)); | | 1521 | #else |
| | | 1522 | pcb->pcb_cr3 = PDPpaddr; |
1522 | #endif | | 1523 | #endif |
1523 | | | 1524 | |
1524 | #if NISA > 0 || NPCI > 0 | | 1525 | #if NISA > 0 || NPCI > 0 |
1525 | x86_bus_space_init(); | | 1526 | x86_bus_space_init(); |
1526 | #endif | | 1527 | #endif |
1527 | | | 1528 | |
1528 | consinit(); /* XXX SHOULD NOT BE DONE HERE */ | | 1529 | consinit(); /* XXX SHOULD NOT BE DONE HERE */ |
1529 | | | 1530 | |
1530 | /* | | 1531 | /* |
1531 | * Initialize PAGE_SIZE-dependent variables. | | 1532 | * Initialize PAGE_SIZE-dependent variables. |
1532 | */ | | 1533 | */ |
1533 | uvm_md_init(); | | 1534 | uvm_md_init(); |
1534 | | | 1535 | |
| @@ -1780,38 +1781,38 @@ cpu_reset(void) | | | @@ -1780,38 +1781,38 @@ cpu_reset(void) |
1780 | x86_disable_intr(); | | 1781 | x86_disable_intr(); |
1781 | | | 1782 | |
1782 | #ifdef XEN | | 1783 | #ifdef XEN |
1783 | HYPERVISOR_reboot(); | | 1784 | HYPERVISOR_reboot(); |
1784 | #else | | 1785 | #else |
1785 | | | 1786 | |
1786 | x86_reset(); | | 1787 | x86_reset(); |
1787 | | | 1788 | |
1788 | /* | | 1789 | /* |
1789 | * Try to cause a triple fault and watchdog reset by making the IDT | | 1790 | * Try to cause a triple fault and watchdog reset by making the IDT |
1790 | * invalid and causing a fault. | | 1791 | * invalid and causing a fault. |
1791 | */ | | 1792 | */ |
1792 | kpreempt_disable(); | | 1793 | kpreempt_disable(); |
1793 | pmap_changeprot_local(idt_vaddr, VM_PROT_READ|VM_PROT_WRITE); | | 1794 | pmap_changeprot_local(idt_vaddr, VM_PROT_READ|VM_PROT_WRITE); |
1794 | memset((void *)idt, 0, NIDT * sizeof(idt[0])); | | 1795 | memset((void *)idt, 0, NIDT * sizeof(idt[0])); |
1795 | kpreempt_enable(); | | 1796 | kpreempt_enable(); |
1796 | breakpoint(); | | 1797 | breakpoint(); |
1797 | | | 1798 | |
1798 | #if 0 | | 1799 | #if 0 |
1799 | /* | | 1800 | /* |
1800 | * Try to cause a triple fault and watchdog reset by unmapping the | | 1801 | * Try to cause a triple fault and watchdog reset by unmapping the |
1801 | * entire address space and doing a TLB flush. | | 1802 | * entire address space and doing a TLB flush. |
1802 | */ | | 1803 | */ |
1803 | memset((void *)PTD, 0, PAGE_SIZE); | | 1804 | memset((void *)PTD, 0, PAGE_SIZE); |
1804 | tlbflush(); | | 1805 | tlbflush(); |
1805 | #endif | | 1806 | #endif |
1806 | #endif /* XEN */ | | 1807 | #endif /* XEN */ |
1807 | | | 1808 | |
1808 | for (;;); | | 1809 | for (;;); |
1809 | } | | 1810 | } |
1810 | | | 1811 | |
1811 | void | | 1812 | void |
1812 | cpu_getmcontext(struct lwp *l, mcontext_t *mcp, unsigned int *flags) | | 1813 | cpu_getmcontext(struct lwp *l, mcontext_t *mcp, unsigned int *flags) |
1813 | { | | 1814 | { |
1814 | const struct trapframe *tf = l->l_md.md_regs; | | 1815 | const struct trapframe *tf = l->l_md.md_regs; |
1815 | __greg_t ras_rip; | | 1816 | __greg_t ras_rip; |
1816 | | | 1817 | |
1817 | /* Copy general registers member by member */ | | 1818 | /* Copy general registers member by member */ |
| @@ -2031,27 +2032,26 @@ cpu_fsgs_reload(struct lwp *l, int fssel | | | @@ -2031,27 +2032,26 @@ cpu_fsgs_reload(struct lwp *l, int fssel |
2031 | update_descriptor(&curcpu()->ci_gdt[GUFS_SEL], &pcb->pcb_fs); | | 2032 | update_descriptor(&curcpu()->ci_gdt[GUFS_SEL], &pcb->pcb_fs); |
2032 | update_descriptor(&curcpu()->ci_gdt[GUGS_SEL], &pcb->pcb_gs); | | 2033 | update_descriptor(&curcpu()->ci_gdt[GUGS_SEL], &pcb->pcb_gs); |
2033 | setfs(fssel); | | 2034 | setfs(fssel); |
2034 | #ifndef XEN | | 2035 | #ifndef XEN |
2035 | setusergs(gssel); | | 2036 | setusergs(gssel); |
2036 | #else | | 2037 | #else |
2037 | HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, gssel); | | 2038 | HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, gssel); |
2038 | #endif | | 2039 | #endif |
2039 | tf->tf_fs = fssel; | | 2040 | tf->tf_fs = fssel; |
2040 | tf->tf_gs = gssel; | | 2041 | tf->tf_gs = gssel; |
2041 | kpreempt_enable(); | | 2042 | kpreempt_enable(); |
2042 | } | | 2043 | } |
2043 | | | 2044 | |
2044 | | | | |
2045 | #ifdef __HAVE_DIRECT_MAP | | 2045 | #ifdef __HAVE_DIRECT_MAP |
2046 | bool | | 2046 | bool |
2047 | mm_md_direct_mapped_io(void *addr, paddr_t *paddr) | | 2047 | mm_md_direct_mapped_io(void *addr, paddr_t *paddr) |
2048 | { | | 2048 | { |
2049 | vaddr_t va = (vaddr_t)addr; | | 2049 | vaddr_t va = (vaddr_t)addr; |
2050 | | | 2050 | |
2051 | if (va >= PMAP_DIRECT_BASE && va < PMAP_DIRECT_END) { | | 2051 | if (va >= PMAP_DIRECT_BASE && va < PMAP_DIRECT_END) { |
2052 | *paddr = PMAP_DIRECT_UNMAP(va); | | 2052 | *paddr = PMAP_DIRECT_UNMAP(va); |
2053 | return true; | | 2053 | return true; |
2054 | } | | 2054 | } |
2055 | return false; | | 2055 | return false; |
2056 | } | | 2056 | } |
2057 | | | 2057 | |