From 1919553cf0f4605491a44f3a458aa31fd81580fc Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 4 Apr 2020 17:39:30 +0200 Subject: pmap: Fix boot with kvm+PAE on some systems It seems some systems refuse the W bit in the pdp. Only enable it for Xen PV tables which do require it. * i386/intel/pmap.c (pmap_bootstrap, pmap_create) [!MACH_PV_PAGETABLES]: Do not set INTEL_PTE_WRITE in pdpbase entries. --- i386/intel/pmap.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/i386/intel/pmap.c b/i386/intel/pmap.c index 108ea048..ac0e3865 100644 --- a/i386/intel/pmap.c +++ b/i386/intel/pmap.c @@ -649,7 +649,11 @@ void pmap_bootstrap(void) WRITE_PTE(&kernel_pmap->pdpbase[i], pa_to_pte(_kvtophys((void *) kernel_page_dir + i * INTEL_PGBYTES)) - | INTEL_PTE_VALID | INTEL_PTE_WRITE); + | INTEL_PTE_VALID +#ifdef MACH_PV_PAGETABLES + | INTEL_PTE_WRITE +#endif + ); } #ifdef __x86_64__ #ifdef MACH_HYP @@ -1289,7 +1293,11 @@ pmap_t pmap_create(vm_size_t size) for (i = 0; i < PDPNUM; i++) WRITE_PTE(&p->pdpbase[i], pa_to_pte(kvtophys((vm_offset_t) page_dir[i])) - | INTEL_PTE_VALID | INTEL_PTE_WRITE); + | INTEL_PTE_VALID +#ifdef MACH_PV_PAGETABLES + | INTEL_PTE_WRITE +#endif + ); } #ifdef __x86_64__ // FIXME: use kmem_cache_alloc instead -- cgit v1.2.3 From 03b05ed702de248d308bb42348754ad19643d502 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 5 Apr 2020 20:47:55 +0200 Subject: Fix xen build * xen/grant.c: Include instead of . --- xen/grant.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/grant.c b/xen/grant.c index 6715a374..1d6e607b 100644 --- a/xen/grant.c +++ b/xen/grant.c @@ -16,7 +16,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include +#include #include #include #include -- cgit v1.2.3 From b4ee23b7445a74c06dd5a2368f78250f5ca57548 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 5 Apr 2020 21:50:29 +0200 Subject: Fix warning * xen/net.c (hyp_net_intr): Cast WINDOW to long. --- xen/net.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/net.c b/xen/net.c index 4507ead3..ac8c9b1f 100644 --- a/xen/net.c +++ b/xen/net.c @@ -184,7 +184,7 @@ static void hyp_net_intr(int unit) { simple_lock(&nd->lock); if ((nd->rx.sring->rsp_prod - nd->rx.rsp_cons) >= (WINDOW*3)/4) - printf("window %ld a bit small!\n", WINDOW); + printf("window %ld a bit small!\n", (long) WINDOW); more = RING_HAS_UNCONSUMED_RESPONSES(&nd->rx); while (more) { -- cgit v1.2.3 From c41d54362d15d0c0c2a049c384c134134a3415f0 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 5 Apr 2020 23:02:13 +0200 Subject: Xen x86_64: Fix getting page table base * i386/intel/pmap.c (pmap_bootstrap): Reload base from boot_info at each loop. --- i386/intel/pmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i386/intel/pmap.c b/i386/intel/pmap.c index ac0e3865..d67d39d1 100644 --- a/i386/intel/pmap.c +++ b/i386/intel/pmap.c @@ -693,10 +693,10 @@ void pmap_bootstrap(void) #endif pt_entry_t *l1_map[NSUP_L1]; { - pt_entry_t *base = (pt_entry_t*) boot_info.pt_base; vm_offset_t la; int n_l1map; for (n_l1map = 0, la = VM_MIN_KERNEL_ADDRESS; la >= VM_MIN_KERNEL_ADDRESS; la += NPTES * PAGE_SIZE) { + pt_entry_t *base = (pt_entry_t*) boot_info.pt_base; #ifdef PAE #ifdef __x86_64__ base = (pt_entry_t*) ptetokv(base[0]); -- cgit v1.2.3 From ad71f1f742661863e0de59a94746f5d01e80b346 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 5 Apr 2020 23:16:42 +0200 Subject: xen: Fix rdtsc call for x86_64 * i386/i386/xen.h (hyp_cpu_clock): Replace "=A" register constraint with separate "=a" and "=d". --- i386/i386/xen.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/i386/i386/xen.h b/i386/i386/xen.h index 49564ebb..8a17748a 100644 --- a/i386/i386/xen.h +++ b/i386/i386/xen.h @@ -396,9 +396,9 @@ _hypcall1(unsigned long, get_debugreg, int, reg); /* x86-specific */ MACH_INLINE uint64_t hyp_cpu_clock(void) { - uint64_t tsc; - asm volatile("rdtsc":"=A"(tsc)); - return tsc; + uint32_t hi, lo; + asm volatile("rdtsc" : "=d"(hi), "=a"(lo)); + return (((uint64_t) hi) << 32) | lo; } #else /* __ASSEMBLER__ */ -- cgit v1.2.3 From 1e901a41a81bdbd00961959da1939dc6e42994aa Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 5 Apr 2020 23:18:39 +0200 Subject: xen: Fix vm_page layout for x86_64 * i386/i386/vm_param.h [MACH_XEN && __LP64__] (VM_PAGE_MAX_SEGS): Set to 4. (VM_PAGE_DMA32_LIMIT): Define. (VM_PAGE_DIRECTMAP_LIMIT): Set to 0x400000000000. (VM_PAGE_HIGHMEM_LIMIT): Set to 0x10000000000000. --- i386/i386/vm_param.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/i386/i386/vm_param.h b/i386/i386/vm_param.h index 1ca6b22c..edd9522c 100644 --- a/i386/i386/vm_param.h +++ b/i386/i386/vm_param.h @@ -122,11 +122,18 @@ #ifdef MACH_XEN /* TODO Completely check Xen physical/virtual layout */ +#ifdef __LP64__ +#define VM_PAGE_MAX_SEGS 4 +#define VM_PAGE_DMA32_LIMIT DECL_CONST(0x100000000, UL) +#define VM_PAGE_DIRECTMAP_LIMIT DECL_CONST(0x400000000000, UL) +#define VM_PAGE_HIGHMEM_LIMIT DECL_CONST(0x10000000000000, ULL) +#else #define VM_PAGE_MAX_SEGS 3 #define VM_PAGE_DIRECTMAP_LIMIT (VM_MAX_KERNEL_ADDRESS \ - VM_MIN_KERNEL_ADDRESS \ - VM_KERNEL_MAP_SIZE) #define VM_PAGE_HIGHMEM_LIMIT DECL_CONST(0x10000000000000, ULL) +#endif #else /* MACH_XEN */ #ifdef __LP64__ #define VM_PAGE_MAX_SEGS 4 -- cgit v1.2.3 From b3d8176955e9c4646f08ab47cb45acdaf869cd0b Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 5 Apr 2020 23:37:44 +0200 Subject: x86_64: Fix passing argument * kern/boot_script.c (add_arg): Make val parameter long. --- kern/boot_script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kern/boot_script.c b/kern/boot_script.c index b2ae901c..d937a26f 100644 --- a/kern/boot_script.c +++ b/kern/boot_script.c @@ -172,7 +172,7 @@ add_list (void *ptr, void ***ptr_list, int *alloc, int *index, int incr) /* Create an argument with TEXT, value type TYPE, and value VAL. Add the argument to the argument list of CMD. */ static struct arg * -add_arg (struct cmd *cmd, char *text, int type, int val) +add_arg (struct cmd *cmd, char *text, int type, long val) { struct arg *arg; -- cgit v1.2.3 From 803e1543c774763e92f14016f3d306aabf657153 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 6 Apr 2020 00:02:49 +0200 Subject: x86_64: Fix userland max address * i386/include/mach/i386/vm_param.h (VM_MAX_ADDRESS) [__x86_64__]: Set to 0x40000000UL. --- i386/include/mach/i386/vm_param.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/i386/include/mach/i386/vm_param.h b/i386/include/mach/i386/vm_param.h index 3a209b83..a684ed97 100644 --- a/i386/include/mach/i386/vm_param.h +++ b/i386/include/mach/i386/vm_param.h @@ -73,6 +73,10 @@ with that. */ #define VM_MIN_ADDRESS (0) +#ifdef __x86_64__ +#define VM_MAX_ADDRESS (0x40000000UL) +#else #define VM_MAX_ADDRESS (0xc0000000UL) +#endif #endif /* _MACH_I386_VM_PARAM_H_ */ -- cgit v1.2.3 From da8c9a7e035df0ad9e748caacc654b23a5901af9 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 6 Apr 2020 02:32:08 +0200 Subject: boot_script: Explicit missing symbol name * kern/boot_script.c: Include . (boot_script_exec): Print missing symbol name on symbol lookup error. --- kern/boot_script.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kern/boot_script.c b/kern/boot_script.c index d937a26f..9e8f60a7 100644 --- a/kern/boot_script.c +++ b/kern/boot_script.c @@ -4,6 +4,7 @@ #include #include +#include #include "boot_script.h" @@ -558,6 +559,7 @@ boot_script_exec (void) if (sym->type == VAL_NONE) { error = BOOT_SCRIPT_UNDEF_SYM; + printf("bootstrap script missing symbol '%s'\n", sym->name); goto done; } arg->type = sym->type; -- cgit v1.2.3 From 899d69cc267b3d07ea3eeea91cf10a5a32dac985 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 6 Apr 2020 02:38:23 +0200 Subject: bootstrap: Add missing reference to send port between tasks When giving the port to a bootstrap task to another bootstrap task, we need to add a reference. This shows up on error-cleanup (e.g. when forgetting to define the root). * kern/bootstrap.c (boot_script_insert_task_port): Call ipc_port_make_send on `task''s itk_sself. --- kern/bootstrap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kern/bootstrap.c b/kern/bootstrap.c index c7b18b1d..00064cef 100644 --- a/kern/bootstrap.c +++ b/kern/bootstrap.c @@ -898,6 +898,7 @@ boot_script_insert_right (struct cmd *cmd, mach_port_t port, mach_port_t *name) int boot_script_insert_task_port (struct cmd *cmd, task_t task, mach_port_t *name) { - *name = task_insert_send_right (cmd->task, task->itk_sself); + *name = task_insert_send_right (cmd->task, + ipc_port_make_send(task->itk_sself)); return 0; } -- cgit v1.2.3 From 34e83eab4497bfbe8da0cbb7bd4f59c0021bf285 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 6 Apr 2020 22:13:15 +0200 Subject: ddb: Add 64bit support to memory examination * ddb/db_examine.c(db_examine): Add q modifier to examine 64bit values. * doc/mach.texi (examine): Document q modifier. --- ddb/db_examine.c | 12 ++++++++---- doc/mach.texi | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ddb/db_examine.c b/ddb/db_examine.c index 6f94b686..6509a538 100644 --- a/ddb/db_examine.c +++ b/ddb/db_examine.c @@ -130,20 +130,24 @@ db_examine(addr, fmt, count, task) db_examine_prev_addr = addr; while (--count >= 0) { fp = fmt; - size = sizeof(int); + size = 4; width = 4*size; while ((c = *fp++) != 0) { switch (c) { case 'b': - size = sizeof(char); + size = 1; width = 4*size; break; case 'h': - size = sizeof(short); + size = 2; width = 4*size; break; case 'l': - size = sizeof(long); + size = 4; + width = 4*size; + break; + case 'q': + size = 8; width = 4*size; break; case 'a': /* address */ diff --git a/doc/mach.texi b/doc/mach.texi index dd1e5edd..07cb0ad1 100644 --- a/doc/mach.texi +++ b/doc/mach.texi @@ -6793,6 +6793,9 @@ look at by half words(16 bits) @item l look at by long words(32 bits) +@item q +look at by quad words(64 bits) + @item a print the location being displayed -- cgit v1.2.3 From 71f4f63143d2ab0987d3315cdcd5d20e233d68d7 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 6 Apr 2020 22:15:36 +0200 Subject: Add warning about one of the next 64bit fixes to make --- i386/intel/pmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/i386/intel/pmap.c b/i386/intel/pmap.c index d67d39d1..0f650f2a 100644 --- a/i386/intel/pmap.c +++ b/i386/intel/pmap.c @@ -1396,6 +1396,9 @@ void pmap_destroy(pmap_t p) page_dir = p->dirbase; #endif +#ifdef __x86_64__ +#warning FIXME 64bit need to free l3 +#endif /* * Free the memory maps, then the * pmap structure. -- cgit v1.2.3 From 8872f037708d83d8b71de6747be499066d287455 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 6 Apr 2020 22:16:05 +0200 Subject: mach_trap_table: Fix 64bit version The addition of the mach_trap_name field made the 64bit unused field spurious. * kern/syscall_sw.h (mach_trap_t): Remove `unused' field. --- i386/i386/locore.S | 2 +- kern/syscall_sw.h | 5 ++--- x86_64/locore.S | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/i386/i386/locore.S b/i386/i386/locore.S index ddba2245..a0960a26 100644 --- a/i386/i386/locore.S +++ b/i386/i386/locore.S @@ -1075,7 +1075,7 @@ syscall_native: movb $0xf,%dh movw %dx,0xb800c #endif - shll $4,%eax /* manual indexing */ + shll $4,%eax /* manual indexing of mach_trap_t */ movl EXT(mach_trap_table)(%eax),%ecx /* get number of arguments */ jecxz mach_call_call /* skip argument copy if none */ diff --git a/kern/syscall_sw.h b/kern/syscall_sw.h index 9d28281a..80b1810b 100644 --- a/kern/syscall_sw.h +++ b/kern/syscall_sw.h @@ -31,6 +31,8 @@ * mach_trap_stack indicates the trap may discard * its kernel stack. Some architectures may need * to save more state in the pcb for these traps. + * + * Note: this is indexed manually by locore.S! */ typedef struct { @@ -38,9 +40,6 @@ typedef struct { int (*mach_trap_function)(); boolean_t mach_trap_stack; const char *mach_trap_name; -#ifdef __x86_64__ - long unused; -#endif } mach_trap_t; extern mach_trap_t mach_trap_table[]; diff --git a/x86_64/locore.S b/x86_64/locore.S index 3a2b3963..fd3617c5 100644 --- a/x86_64/locore.S +++ b/x86_64/locore.S @@ -1134,7 +1134,7 @@ syscall_native: movb $0xf,%dh movw %dx,0xb800c #endif - shll $5,%eax /* manual indexing */ + shll $5,%eax /* manual indexing of mach_trap_t */ xorq %r10,%r10 movl EXT(mach_trap_table)(%eax),%r10d /* get number of arguments */ -- cgit v1.2.3