Sat Jun 1 12:42:28 2019 UTC ()
Misc changes in RISC-V. Start changing the memory layout, too.


(maxv)
diff -r1.3 -r1.4 src/common/lib/libc/arch/riscv/atomic/Makefile.inc
diff -r0 -r1.1 src/sys/arch/riscv/compile/Makefile
diff -r1.9 -r1.10 src/sys/arch/riscv/conf/GENERIC
diff -r1.3 -r1.4 src/sys/arch/riscv/conf/Makefile.riscv
diff -r1.1 -r1.2 src/sys/arch/riscv/conf/files.riscv
diff -r1.4 -r1.5 src/sys/arch/riscv/include/cpu.h
diff -r1.4 -r1.5 src/sys/arch/riscv/include/vmparam.h
diff -r1.6 -r1.7 src/sys/arch/riscv/include/elf_machdep.h
diff -r1.1 -r1.2 src/sys/arch/riscv/include/mutex.h
diff -r1.1 -r1.2 src/sys/arch/riscv/include/pmap.h
diff -r1.1 -r1.2 src/sys/arch/riscv/include/pte.h
diff -r1.2 -r1.3 src/sys/arch/riscv/include/param.h
diff -r1.1 -r1.2 src/sys/arch/riscv/riscv/core_machdep.c
diff -r1.3 -r1.4 src/sys/arch/riscv/riscv/genassym.cf
diff -r1.7 -r1.8 src/sys/arch/riscv/riscv/locore.S
diff -r1.2 -r1.3 src/sys/arch/riscv/riscv/pmap_machdep.c
diff -r1.11 -r1.12 src/sys/uvm/pmap/pmap.h

cvs diff -r1.3 -r1.4 src/common/lib/libc/arch/riscv/atomic/Makefile.inc (expand / switch to unified diff)

--- src/common/lib/libc/arch/riscv/atomic/Makefile.inc 2019/04/17 07:40:34 1.3
+++ src/common/lib/libc/arch/riscv/atomic/Makefile.inc 2019/06/01 12:42:27 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: Makefile.inc,v 1.3 2019/04/17 07:40:34 mrg Exp $ 1# $NetBSD: Makefile.inc,v 1.4 2019/06/01 12:42:27 maxv Exp $
2 2
3.for op in add and cas nand or sub swap xor 3.for op in add and cas nand or sub swap xor
4sizes=32 4sizes=32
5.if "${MLIBDIR}" != "" 5.if "${MLIBDIR}" != ""
6.if ${COMMON_MACHINE_ARCH} == "riscv64" 6.if ${COMMON_MACHINE_ARCH} == "riscv64"
7sizes+=64 7sizes+=64
8.endif 8.endif
9.elif ${MACHINE_ARCH} == "riscv64" 9.elif ${MACHINE_ARCH} == "riscv64"
10sizes+=64 10sizes+=64
11.endif 11.endif
12.for sz in ${sizes} 12.for sz in ${sizes}
13SRCS.atomic+= atomic_${op}_${sz}.S 13SRCS.atomic+= atomic_${op}_${sz}.S
14.endfor 14.endfor
@@ -17,18 +17,18 @@ SRCS.atomic+= atomic_${op}_${sz}_cas.c @@ -17,18 +17,18 @@ SRCS.atomic+= atomic_${op}_${sz}_cas.c
17.endfor 17.endfor
18.endfor 18.endfor
19SRCS.atomic+= membar_ops.S 19SRCS.atomic+= membar_ops.S
20SRCS.atomic+= atomic_cas_by_cas32.c 20SRCS.atomic+= atomic_cas_by_cas32.c
21 21
22.if defined(LIB) && (${LIB} != "kern" && ${LIB} != "rump") 22.if defined(LIB) && (${LIB} != "kern" && ${LIB} != "rump")
23 23
24SRCS.atomic+= atomic_init_cas.c \ 24SRCS.atomic+= atomic_init_cas.c \
25 atomic_c11_compare_exchange_cas_16.c \ 25 atomic_c11_compare_exchange_cas_16.c \
26 atomic_c11_compare_exchange_cas_8.c 26 atomic_c11_compare_exchange_cas_8.c
27 27
28.endif #LIB 28.endif #LIB
29 29
30.if ${LIB} == "c" 30.if defined(LIB) && ${LIB} == "c"
31SRCS.atomic+= atomic_and_16_nv_cas.c atomic_and_8_nv_cas.c 31SRCS.atomic+= atomic_and_16_nv_cas.c atomic_and_8_nv_cas.c
32.endif 32.endif
33 33
34SRCS+= ${SRCS.atomic} 34SRCS+= ${SRCS.atomic}

File Added: src/sys/arch/riscv/compile/Makefile
#	$NetBSD: Makefile,v 1.1 2019/06/01 12:42:27 maxv Exp $

.include <bsd.prog.mk>

cvs diff -r1.9 -r1.10 src/sys/arch/riscv/conf/GENERIC (expand / switch to unified diff)

--- src/sys/arch/riscv/conf/GENERIC 2018/08/01 20:04:13 1.9
+++ src/sys/arch/riscv/conf/GENERIC 2019/06/01 12:42:27 1.10
@@ -1,38 +1,38 @@ @@ -1,38 +1,38 @@
1# $NetBSD: GENERIC,v 1.9 2018/08/01 20:04:13 maxv Exp $ 1# $NetBSD: GENERIC,v 1.10 2019/06/01 12:42:27 maxv Exp $
2# 2#
3# GENERIC machine description file 3# GENERIC machine description file
4# 4#
5# This machine description file is used to generate the default NetBSD 5# This machine description file is used to generate the default NetBSD
6# kernel. The generic kernel does not include all options, subsystems 6# kernel. The generic kernel does not include all options, subsystems
7# and device drivers, but should be useful for most applications. 7# and device drivers, but should be useful for most applications.
8# 8#
9# The machine description file can be customised for your specific 9# The machine description file can be customised for your specific
10# machine to reduce the kernel size and improve its performance. 10# machine to reduce the kernel size and improve its performance.
11# 11#
12# For further information on compiling NetBSD kernels, see the config(8) 12# For further information on compiling NetBSD kernels, see the config(8)
13# man page. 13# man page.
14# 14#
15# For further information on hardware support for this architecture, see 15# For further information on hardware support for this architecture, see
16# the intro(4) man page. For further information about kernel options 16# the intro(4) man page. For further information about kernel options
17# for this architecture, see the options(4) man page. For an explanation 17# for this architecture, see the options(4) man page. For an explanation
18# of each device driver in this file see the section 4 man page for the 18# of each device driver in this file see the section 4 man page for the
19# device. 19# device.
20 20
21include "arch/riscv/conf/std.riscv64" 21include "arch/riscv/conf/std.riscv64"
22 22
23options INCLUDE_CONFIG_FILE # embed config file in kernel binary 23options INCLUDE_CONFIG_FILE # embed config file in kernel binary
24 24
25#ident "GENERIC-$Revision: 1.9 $" 25#ident "GENERIC-$Revision: 1.10 $"
26 26
27maxusers 64 # estimated number of users 27maxusers 64 # estimated number of users
28 28
29# Standard system options 29# Standard system options
30 30
31options NTP # NTP phase/frequency locked loop 31options NTP # NTP phase/frequency locked loop
32 32
33options KTRACE # system call tracing via ktrace(1) 33options KTRACE # system call tracing via ktrace(1)
34 34
35# Note: SysV IPC parameters could be changed dynamically, see sysctl(8). 35# Note: SysV IPC parameters could be changed dynamically, see sysctl(8).
36options SYSVMSG # System V-like message queues 36options SYSVMSG # System V-like message queues
37options SYSVSEM # System V-like semaphores 37options SYSVSEM # System V-like semaphores
38options SYSVSHM # System V-like memory sharing 38options SYSVSHM # System V-like memory sharing
@@ -64,29 +64,27 @@ options DDB # in-kernel debugger @@ -64,29 +64,27 @@ options DDB # in-kernel debugger
64#options DDB_COMMANDONENTER="bt" # execute command when ddb is entered 64#options DDB_COMMANDONENTER="bt" # execute command when ddb is entered
65#options DDB_ONPANIC=1 # see also sysctl(7): `ddb.onpanic' 65#options DDB_ONPANIC=1 # see also sysctl(7): `ddb.onpanic'
66options DDB_HISTORY_SIZE=512 # enable history editing in DDB 66options DDB_HISTORY_SIZE=512 # enable history editing in DDB
67#options KGDB # remote debugger 67#options KGDB # remote debugger
68#options KGDB_DEVNAME="\"com\"",KGDB_DEVADDR=0x3f8,KGDB_DEVRATE=9600 68#options KGDB_DEVNAME="\"com\"",KGDB_DEVADDR=0x3f8,KGDB_DEVRATE=9600
69#options SYSCALL_STATS # per syscall counts 69#options SYSCALL_STATS # per syscall counts
70#options SYSCALL_TIMES # per syscall times 70#options SYSCALL_TIMES # per syscall times
71#options SYSCALL_TIMES_HASCOUNTER # use 'broken' rdtsc (soekris) 71#options SYSCALL_TIMES_HASCOUNTER # use 'broken' rdtsc (soekris)
72 72
73# Compatibility options 73# Compatibility options
74include "conf/compat_netbsd70.config" 74include "conf/compat_netbsd70.config"
75 75
76options COMPAT_OSSAUDIO 76options COMPAT_OSSAUDIO
77options COMPAT_NETBSD32 77#options COMPAT_NETBSD32
78#options COMPAT_LINUX 
79#options COMPAT_LINUX32 # req. COMPAT_LINUX and COMPAT_NETBSD32 
80#options EXEC_ELF32 78#options EXEC_ELF32
81 79
82# Wedge support 80# Wedge support
83options DKWEDGE_AUTODISCOVER # Automatically add dk(4) instances 81options DKWEDGE_AUTODISCOVER # Automatically add dk(4) instances
84options DKWEDGE_METHOD_GPT # Supports GPT partitions as wedges 82options DKWEDGE_METHOD_GPT # Supports GPT partitions as wedges
85options DKWEDGE_METHOD_BSDLABEL # Support disklabel entries as wedges 83options DKWEDGE_METHOD_BSDLABEL # Support disklabel entries as wedges
86options DKWEDGE_METHOD_MBR # Support MBR partitions as wedges 84options DKWEDGE_METHOD_MBR # Support MBR partitions as wedges
87options DKWEDGE_METHOD_APPLE # Support Apple partitions as wedges 85options DKWEDGE_METHOD_APPLE # Support Apple partitions as wedges
88#options DKWEDGE_METHOD_RDB # Support RDB partitions as wedges 86#options DKWEDGE_METHOD_RDB # Support RDB partitions as wedges
89 87
90include "conf/filesystems.config" 88include "conf/filesystems.config"
91 89
92# File system options 90# File system options

cvs diff -r1.3 -r1.4 src/sys/arch/riscv/conf/Makefile.riscv (expand / switch to unified diff)

--- src/sys/arch/riscv/conf/Makefile.riscv 2018/09/22 12:24:03 1.3
+++ src/sys/arch/riscv/conf/Makefile.riscv 2019/06/01 12:42:27 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: Makefile.riscv,v 1.3 2018/09/22 12:24:03 rin Exp $ 1# $NetBSD: Makefile.riscv,v 1.4 2019/06/01 12:42:27 maxv Exp $
2 2
3# Makefile for NetBSD 3# Makefile for NetBSD
4# 4#
5# This makefile is constructed from a machine description: 5# This makefile is constructed from a machine description:
6# config machineid 6# config machineid
7# Most changes should be made in the machine description 7# Most changes should be made in the machine description
8# /sys/arch/<machine>/conf/``machineid'' 8# /sys/arch/<machine>/conf/``machineid''
9# after which you should do 9# after which you should do
10# config machineid 10# config machineid
11# Machine generic makefile changes should be made in 11# Machine generic makefile changes should be made in
12# /sys/arch/riscv/conf/Makefile.riscv 12# /sys/arch/riscv/conf/Makefile.riscv
13# after which config should be rerun for all machines of that type. 13# after which config should be rerun for all machines of that type.
14# 14#
@@ -29,27 +29,26 @@ S= ../../../.. @@ -29,27 +29,26 @@ S= ../../../..
29.endif 29.endif
30THISRISCV= $S/arch/${MACHINE} 30THISRISCV= $S/arch/${MACHINE}
31RISCV= $S/arch/riscv 31RISCV= $S/arch/riscv
32GENASSYM_CONF= ${RISCV}/riscv/genassym.cf 32GENASSYM_CONF= ${RISCV}/riscv/genassym.cf
33.-include "${THISRISCV}/conf/Makefile.${MACHINE}.inc" 33.-include "${THISRISCV}/conf/Makefile.${MACHINE}.inc"
34 34
35## 35##
36## (2) compile settings 36## (2) compile settings
37## 37##
38## Note: -ffixed-?? must be kept in sync with cpu.h. 38## Note: -ffixed-?? must be kept in sync with cpu.h.
39## 39##
40CPPFLAGS+= -D${MACHINE} 40CPPFLAGS+= -D${MACHINE}
41CFLAGS+= -mcmodel=medany 41CFLAGS+= -mcmodel=medany
42CFLAGS+= -msoft-float 
43.if !defined(LP64) || ${LP64} == "no" 42.if !defined(LP64) || ${LP64} == "no"
44CFLAGS+= -m32 43CFLAGS+= -m32
45AFLAGS+= -m32 44AFLAGS+= -m32
46LDFLAGS+= -m elf32lriscv 45LDFLAGS+= -m elf32lriscv
47LINKFORMAT+= -m elf32lriscv 46LINKFORMAT+= -m elf32lriscv
48SYSTEM_LD_TAIL_EXTRA+= \ 47SYSTEM_LD_TAIL_EXTRA+= \
49 ;echo ${OBJCOPY} -O elf32-littleriscv $@ $@.elf32; \ 48 ;echo ${OBJCOPY} -O elf32-littleriscv $@ $@.elf32; \
50 ${OBJCOPY} -O elf32-littleriscv $@ $@.elf32 49 ${OBJCOPY} -O elf32-littleriscv $@ $@.elf32
51.endif # LP64=no 50.endif # LP64=no
52AFLAGS+= -x assembler-with-cpp ${AOPTS} 51AFLAGS+= -x assembler-with-cpp ${AOPTS}
53 52
54## 53##
55## (3) libkern and compat 54## (3) libkern and compat
@@ -60,27 +59,27 @@ OPT_MODULAR= %MODULAR% @@ -60,27 +59,27 @@ OPT_MODULAR= %MODULAR%
60## (4) local objects, compile rules, and dependencies 59## (4) local objects, compile rules, and dependencies
61## 60##
62MD_OBJS= locore.o 61MD_OBJS= locore.o
63MD_CFILES= 62MD_CFILES=
64MD_SFILES= ${RISCV}/riscv/locore.S 63MD_SFILES= ${RISCV}/riscv/locore.S
65 64
66locore.o: ${RISCV}/riscv/locore.S assym.h 65locore.o: ${RISCV}/riscv/locore.S assym.h
67 ${NORMAL_S} 66 ${NORMAL_S}
68 67
69## 68##
70## (5) link settings 69## (5) link settings
71## 70##
72.if ${MACHINE_ARCH} == "riscv64" && ${LP64:Uyes} == "yes" 71.if ${MACHINE_ARCH} == "riscv64" && ${LP64:Uyes} == "yes"
73TEXTADDR?= 0xFFFFFFFF80002000 72TEXTADDR?= 0xFFFFFFC000000000
74.else  73.else
75TEXTADDR?= 0xC0001000 74TEXTADDR?= 0xC0001000
76.endif 75.endif
77KERNLDSCRIPT?= ${RISCV}/conf/kern.ldscript 76KERNLDSCRIPT?= ${RISCV}/conf/kern.ldscript
78LINKFORMAT+= -T ${KERNLDSCRIPT} 77LINKFORMAT+= -T ${KERNLDSCRIPT}
79EXTRA_LINKFLAGS= ${LDOPTS} --relax 78EXTRA_LINKFLAGS= ${LDOPTS} --relax
80LINKFLAGS_NORMAL= -X 79LINKFLAGS_NORMAL= -X
81STRIPFLAGS= -g -X 80STRIPFLAGS= -g -X
82 81
83## 82##
84## (6) port specific target dependencies 83## (6) port specific target dependencies
85## 84##
86 85

cvs diff -r1.1 -r1.2 src/sys/arch/riscv/conf/files.riscv (expand / switch to unified diff)

--- src/sys/arch/riscv/conf/files.riscv 2015/03/28 16:13:56 1.1
+++ src/sys/arch/riscv/conf/files.riscv 2019/06/01 12:42:27 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: files.riscv,v 1.1 2015/03/28 16:13:56 matt Exp $ 1# $NetBSD: files.riscv,v 1.2 2019/06/01 12:42:27 maxv Exp $
2# 2#
3 3
4maxpartitions 16 4maxpartitions 16
5maxusers 8 32 64 5maxusers 8 32 64
6 6
7defflag opt_ddb.h DDB_TRACE 7defflag opt_ddb.h DDB_TRACE
8 8
9#file arch/riscv/riscv/locore.S 9#file arch/riscv/riscv/locore.S
10file arch/riscv/riscv/spl.S 10file arch/riscv/riscv/spl.S
11 11
12file arch/riscv/riscv/autoconf.c 12file arch/riscv/riscv/autoconf.c
13file arch/riscv/riscv/cpu_subr.c 13file arch/riscv/riscv/cpu_subr.c
14file arch/riscv/riscv/db_disasm.c ddb 14file arch/riscv/riscv/db_disasm.c ddb
@@ -31,43 +31,36 @@ file arch/riscv/riscv/process_machdep.c @@ -31,43 +31,36 @@ file arch/riscv/riscv/process_machdep.c
31file arch/riscv/riscv/procfs_machdep.c procfs 31file arch/riscv/riscv/procfs_machdep.c procfs
32file arch/riscv/riscv/riscv_machdep.c 32file arch/riscv/riscv/riscv_machdep.c
33file arch/riscv/riscv/sig_machdep.c # signal delivery 33file arch/riscv/riscv/sig_machdep.c # signal delivery
34file arch/riscv/riscv/softint_machdep.c 34file arch/riscv/riscv/softint_machdep.c
35file arch/riscv/riscv/sys_machdep.c 35file arch/riscv/riscv/sys_machdep.c
36file arch/riscv/riscv/vm_machdep.c 36file arch/riscv/riscv/vm_machdep.c
37 37
38file dev/cons.c 38file dev/cons.c
39file dev/md_root.c memory_disk_hooks 39file dev/md_root.c memory_disk_hooks
40 40
41file kern/subr_disk_mbr.c disk 41file kern/subr_disk_mbr.c disk
42 42
43file uvm/pmap/pmap.c 43file uvm/pmap/pmap.c
44file uvm/pmap/pmap_pv.c 44file uvm/pmap/pmap_pvt.c
45file uvm/pmap/pmap_segtab.c 45file uvm/pmap/pmap_segtab.c
46file uvm/pmap/pmap_tlb.c 46file uvm/pmap/pmap_tlb.c
47 47
48# Binary compatibility with 32bit NetBSD (COMPAT_NETBSD32) 48# Binary compatibility with 32bit NetBSD (COMPAT_NETBSD32)
49file arch/riscv/riscv/core32_machdep.c compat_netbsd32 & coredump 49file arch/riscv/riscv/core32_machdep.c compat_netbsd32 & coredump
50file arch/riscv/riscv/netbsd32_machdep.c compat_netbsd32 50file arch/riscv/riscv/netbsd32_machdep.c compat_netbsd32
51file arch/riscv/riscv/sig32_machdep.c compat_netbsd32 51file arch/riscv/riscv/sig32_machdep.c compat_netbsd32
52include "compat/netbsd32/files.netbsd32" 52include "compat/netbsd32/files.netbsd32"
53 53
54# Linux compatibility (COMPAT_LINUX) XXX Highly experimental 
55#include "compat/ossaudio/files.ossaudio" 
56#include "compat/linux/files.linux" 
57#include "compat/linux/arch/riscv/files.linux_riscv" 
58#file arch/riscv/riscv/linux_trap.c compat_linux 
59#file arch/riscv/riscv/linux_syscall.c compat_linux 
60 
61device mainbus { [instance=-1] } 54device mainbus { [instance=-1] }
62attach mainbus at root 55attach mainbus at root
63file arch/riscv/riscv/mainbus.c mainbus 56file arch/riscv/riscv/mainbus.c mainbus
64 57
65device cpu 58device cpu
66attach cpu at mainbus with cpu_mainbus 59attach cpu at mainbus with cpu_mainbus
67file arch/riscv/riscv/cpu_mainbus.c cpu_mainbus 60file arch/riscv/riscv/cpu_mainbus.c cpu_mainbus
68 61
69device htif { } 62device htif { }
70attach htif at mainbus with htif_mainbus 63attach htif at mainbus with htif_mainbus
71file arch/riscv/htif/htif.c htif_mainbus 64file arch/riscv/htif/htif.c htif_mainbus
72 65
73device htifcons { } : tty 66device htifcons { } : tty

cvs diff -r1.4 -r1.5 src/sys/arch/riscv/include/cpu.h (expand / switch to unified diff)

--- src/sys/arch/riscv/include/cpu.h 2015/04/01 21:55:03 1.4
+++ src/sys/arch/riscv/include/cpu.h 2019/06/01 12:42:28 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cpu.h,v 1.4 2015/04/01 21:55:03 matt Exp $ */ 1/* $NetBSD: cpu.h,v 1.5 2019/06/01 12:42:28 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry. 8 * by Matt Thomas of 3am Software Foundry.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -58,31 +58,30 @@ struct cpu_info { @@ -58,31 +58,30 @@ struct cpu_info {
58 struct trapframe *ci_ddb_regs; 58 struct trapframe *ci_ddb_regs;
59 59
60 uint64_t ci_lastintr; 60 uint64_t ci_lastintr;
61 61
62 int ci_mtx_oldspl; 62 int ci_mtx_oldspl;
63 int ci_mtx_count; 63 int ci_mtx_count;
64 64
65 int ci_want_resched; 65 int ci_want_resched;
66 int ci_cpl; 66 int ci_cpl;
67 u_int ci_softints; 67 u_int ci_softints;
68 volatile u_int ci_intr_depth; 68 volatile u_int ci_intr_depth;
69 69
70 tlb_asid_t ci_pmap_asid_cur; 70 tlb_asid_t ci_pmap_asid_cur;
71#if 0 71
72 union pmap_pdetab *ci_pmap_user_pdetab; 72 union pmap_segtab *ci_pmap_user_segtab;
73#ifdef _LP64 73#ifdef _LP64
74 union pmap_pdetab *ci_pmap_user_pde0tab; 74 union pmap_segtab *ci_pmap_user_seg0tab;
75#endif 
76#endif 75#endif
77 76
78 struct evcnt ci_ev_fpu_saves; 77 struct evcnt ci_ev_fpu_saves;
79 struct evcnt ci_ev_fpu_loads; 78 struct evcnt ci_ev_fpu_loads;
80 struct evcnt ci_ev_fpu_reenables; 79 struct evcnt ci_ev_fpu_reenables;
81}; 80};
82 81
83#endif /* _KERNEL || _KMEMUSER */ 82#endif /* _KERNEL || _KMEMUSER */
84 83
85#ifdef _KERNEL 84#ifdef _KERNEL
86 85
87extern struct cpu_info cpu_info_store; 86extern struct cpu_info cpu_info_store;
88 87

cvs diff -r1.4 -r1.5 src/sys/arch/riscv/include/vmparam.h (expand / switch to unified diff)

--- src/sys/arch/riscv/include/vmparam.h 2018/05/31 22:26:36 1.4
+++ src/sys/arch/riscv/include/vmparam.h 2019/06/01 12:42:28 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vmparam.h,v 1.4 2018/05/31 22:26:36 mrg Exp $ */ 1/* $NetBSD: vmparam.h,v 1.5 2019/06/01 12:42:28 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry. 8 * by Matt Thomas of 3am Software Foundry.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -32,30 +32,26 @@ @@ -32,30 +32,26 @@
32#ifndef _RISCV_VMPARAM_H_ 32#ifndef _RISCV_VMPARAM_H_
33#define _RISCV_VMPARAM_H_ 33#define _RISCV_VMPARAM_H_
34 34
35#include <riscv/param.h> 35#include <riscv/param.h>
36 36
37#ifdef _KERNEL_OPT 37#ifdef _KERNEL_OPT
38#include "opt_multiprocessor.h" 38#include "opt_multiprocessor.h"
39#endif 39#endif
40 40
41/* 41/*
42 * Machine dependent VM constants for RISCV. 42 * Machine dependent VM constants for RISCV.
43 */ 43 */
44 44
45/* 
46 * We use a 8K page on RV64 and 4K on RV32 systems. 
47 * Override PAGE_* definitions to compile-time constants. 
48 */ 
49#define PAGE_SHIFT PGSHIFT 45#define PAGE_SHIFT PGSHIFT
50#define PAGE_SIZE (1 << PAGE_SHIFT) 46#define PAGE_SIZE (1 << PAGE_SHIFT)
51#define PAGE_MASK (PAGE_SIZE - 1) 47#define PAGE_MASK (PAGE_SIZE - 1)
52 48
53/* 49/*
54 * USRSTACK is the top (end) of the user stack. 50 * USRSTACK is the top (end) of the user stack.
55 * 51 *
56 * USRSTACK needs to start a page below the maxuser address so that a memory 52 * USRSTACK needs to start a page below the maxuser address so that a memory
57 * access with a maximum displacement (0x7ff) won't cross into the kernel's 53 * access with a maximum displacement (0x7ff) won't cross into the kernel's
58 * address space. We use PAGE_SIZE instead of 0x800 since these need to be 54 * address space. We use PAGE_SIZE instead of 0x800 since these need to be
59 * page-aligned. 55 * page-aligned.
60 */ 56 */
61#define USRSTACK (VM_MAXUSER_ADDRESS-PAGE_SIZE) /* Start of user stack */ 57#define USRSTACK (VM_MAXUSER_ADDRESS-PAGE_SIZE) /* Start of user stack */
@@ -97,44 +93,36 @@ @@ -97,44 +93,36 @@
97#endif 93#endif
98#ifndef MAXSSIZ32 94#ifndef MAXSSIZ32
99#define MAXSSIZ32 MAXSSIZ /* max stack size */ 95#define MAXSSIZ32 MAXSSIZ /* max stack size */
100#endif 96#endif
101 97
102/* 98/*
103 * PTEs for mapping user space into the kernel for phyio operations. 99 * PTEs for mapping user space into the kernel for phyio operations.
104 * The default PTE number is enough to cover 8 disks * MAXBSIZE. 100 * The default PTE number is enough to cover 8 disks * MAXBSIZE.
105 */ 101 */
106#ifndef USRIOSIZE 102#ifndef USRIOSIZE
107#define USRIOSIZE (MAXBSIZE/PAGE_SIZE * 8) 103#define USRIOSIZE (MAXBSIZE/PAGE_SIZE * 8)
108#endif 104#endif
109 105
110// user/kernel map constants 106/*
111// These use negative addresses since RISCV addresses are signed. 107 * User/kernel map constants.
 108 */
112#define VM_MIN_ADDRESS ((vaddr_t)0x00000000) 109#define VM_MIN_ADDRESS ((vaddr_t)0x00000000)
113#ifdef _LP64 110#ifdef _LP64 /* Sv39 */
114#define VM_MAXUSER_ADDRESS ((vaddr_t) 1L << 42) /* 0x0000040000000000 */ 111#define VM_MAXUSER_ADDRESS ((vaddr_t)0x0000004000000000 - 16 * PAGE_SIZE)
115// For 64-bit kernels, we could, in theory, have 8TB (42 (13+29) bits worth) 112#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)0xFFFFFFC000000000)
116// of KVA space. We need to divide that between KVA for direct-mapped memory, 113#define VM_MAX_KERNEL_ADDRESS ((vaddr_t)0xFFFFFFD000000000) /* MIN + 64GB */
117// space for I/O devices (someday), the kernel's mapped space. For now, we are 114#else /* Sv32 */
118// going to restrict ourselves to use highest 8GB of KVA. The highest 2GB of 
119// that KVA will be used to direct map memory. 
120#define VM_MAX_KERNEL_ADDRESS ((vaddr_t) -PAGE_SIZE << 18) 
121 /* 0xFFFFFFFF80000000 */ 
122#define VM_MIN_KERNEL_ADDRESS ((vaddr_t) -PAGE_SIZE << 20) 
123 /* 0xFFFFFFFE00000000 */ 
124#else 
125#define VM_MAXUSER_ADDRESS ((vaddr_t)-0x7fffffff-1)/* 0xFFFFFFFF80000000 */ 115#define VM_MAXUSER_ADDRESS ((vaddr_t)-0x7fffffff-1)/* 0xFFFFFFFF80000000 */
126// We reserve the bottom (nonnegative) address for user, then split the upper 
127// 2GB into two 1GB, the lower for mapped KVA and the upper for direct-mapped. 
128#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)-0x7fffffff-1)/* 0xFFFFFFFF80000000 */ 116#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)-0x7fffffff-1)/* 0xFFFFFFFF80000000 */
129#define VM_MAX_KERNEL_ADDRESS ((vaddr_t)-0x40000000) /* 0xFFFFFFFFC0000000 */ 117#define VM_MAX_KERNEL_ADDRESS ((vaddr_t)-0x40000000) /* 0xFFFFFFFFC0000000 */
130#endif 118#endif
131#define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS 119#define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS
132#define VM_MAXUSER_ADDRESS32 ((vaddr_t)(1UL << 31))/* 0x0000000080000000 */ 120#define VM_MAXUSER_ADDRESS32 ((vaddr_t)(1UL << 31))/* 0x0000000080000000 */
133 121
134/* 122/*
135 * The address to which unspecified mapping requests default 123 * The address to which unspecified mapping requests default
136 */ 124 */
137#define __USE_TOPDOWN_VM 125#define __USE_TOPDOWN_VM
138 126
139#define VM_DEFAULT_ADDRESS_TOPDOWN(da, sz) \ 127#define VM_DEFAULT_ADDRESS_TOPDOWN(da, sz) \
140 trunc_page(USRSTACK - MAXSSIZ - (sz) - user_stack_guard_size) 128 trunc_page(USRSTACK - MAXSSIZ - (sz) - user_stack_guard_size)

cvs diff -r1.6 -r1.7 src/sys/arch/riscv/include/elf_machdep.h (expand / switch to unified diff)

--- src/sys/arch/riscv/include/elf_machdep.h 2017/11/06 03:47:48 1.6
+++ src/sys/arch/riscv/include/elf_machdep.h 2019/06/01 12:42:28 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: elf_machdep.h,v 1.6 2017/11/06 03:47:48 christos Exp $ */ 1/* $NetBSD: elf_machdep.h,v 1.7 2019/06/01 12:42:28 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry. 8 * by Matt Thomas of 3am Software Foundry.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -36,30 +36,31 @@ @@ -36,30 +36,31 @@
36#define ELF64_MACHDEP_ID EM_RISCV 36#define ELF64_MACHDEP_ID EM_RISCV
37 37
38#define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB 38#define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB
39#define ELF64_MACHDEP_ENDIANNESS ELFDATA2LSB 39#define ELF64_MACHDEP_ENDIANNESS ELFDATA2LSB
40 40
41#define ELF32_MACHDEP_ID_CASES \ 41#define ELF32_MACHDEP_ID_CASES \
42 case EM_RISCV: \ 42 case EM_RISCV: \
43 break; 43 break;
44 44
45#define ELF64_MACHDEP_ID_CASES \ 45#define ELF64_MACHDEP_ID_CASES \
46 case EM_RISCV: \ 46 case EM_RISCV: \
47 break; 47 break;
48 48
49#define KERN_ELFSIZE 32 
50#ifdef _LP64 49#ifdef _LP64
 50#define KERN_ELFSIZE 64
51#define ARCH_ELFSIZE 64 /* MD native binary size */ 51#define ARCH_ELFSIZE 64 /* MD native binary size */
52#else 52#else
 53#define KERN_ELFSIZE 32
53#define ARCH_ELFSIZE 32 /* MD native binary size */ 54#define ARCH_ELFSIZE 32 /* MD native binary size */
54#endif 55#endif
55 56
56/* Processor specific flags for the ELF header e_flags field. */ 57/* Processor specific flags for the ELF header e_flags field. */
57 58
58/* Processor specific relocation types */ 59/* Processor specific relocation types */
59 60
60#define R_RISCV_NONE 0 61#define R_RISCV_NONE 0
61#define R_RISCV_32 1 // A 62#define R_RISCV_32 1 // A
62#define R_RISCV_64 2 63#define R_RISCV_64 2
63#define R_RISCV_RELATIVE 3 64#define R_RISCV_RELATIVE 3
64#define R_RISCV_COPY 4 65#define R_RISCV_COPY 4
65#define R_RISCV_JMP_SLOT 5 66#define R_RISCV_JMP_SLOT 5

cvs diff -r1.1 -r1.2 src/sys/arch/riscv/include/mutex.h (expand / switch to unified diff)

--- src/sys/arch/riscv/include/mutex.h 2014/09/19 17:36:26 1.1
+++ src/sys/arch/riscv/include/mutex.h 2019/06/01 12:42:28 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mutex.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */ 1/* $NetBSD: mutex.h,v 1.2 2019/06/01 12:42:28 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe and Andrew Doran. 8 * by Jason R. Thorpe and Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -73,27 +73,27 @@ static inline void @@ -73,27 +73,27 @@ static inline void
73riscv_mutex_initialize_spin_ipl(kmutex_t *__mtx, int ipl) 73riscv_mutex_initialize_spin_ipl(kmutex_t *__mtx, int ipl)
74{ 74{
75 __mtx->mtx_owner = (__mtx->mtx_owner & ~MTX_IPL) 75 __mtx->mtx_owner = (__mtx->mtx_owner & ~MTX_IPL)
76 | __SHIFTIN(ipl, MTX_IPL); 76 | __SHIFTIN(ipl, MTX_IPL);
77} 77}
78 78
79static inline void 79static inline void
80riscv_mutex_spinbit_lock_init(kmutex_t *__mtx) 80riscv_mutex_spinbit_lock_init(kmutex_t *__mtx)
81{ 81{
82 __mtx->mtx_owner &= ~MTX_LOCK; 82 __mtx->mtx_owner &= ~MTX_LOCK;
83} 83}
84 84
85static inline bool 85static inline bool
86riscv_mutex_spinbit_locked_p(kmutex_t *__mtx) 86riscv_mutex_spinbit_locked_p(const kmutex_t *__mtx)
87{ 87{
88 return (__mtx->mtx_owner & MTX_LOCK) != 0; 88 return (__mtx->mtx_owner & MTX_LOCK) != 0;
89} 89}
90 90
91static inline bool 91static inline bool
92riscv_mutex_spinbit_lock_try(kmutex_t *__mtx) 92riscv_mutex_spinbit_lock_try(kmutex_t *__mtx)
93{ 93{
94 uintptr_t __old; 94 uintptr_t __old;
95 __asm __volatile( 95 __asm __volatile(
96 "amoor" MTX_ASMOP_SFX ".aq\t%0, %1, (%2)" 96 "amoor" MTX_ASMOP_SFX ".aq\t%0, %1, (%2)"
97 : "=r"(__old) 97 : "=r"(__old)
98 : "r"(MTX_LOCK), "r"(__mtx)); 98 : "r"(MTX_LOCK), "r"(__mtx));
99 return (__old & MTX_LOCK) == 0; 99 return (__old & MTX_LOCK) == 0;

cvs diff -r1.1 -r1.2 src/sys/arch/riscv/include/pmap.h (expand / switch to unified diff)

--- src/sys/arch/riscv/include/pmap.h 2014/09/19 17:36:26 1.1
+++ src/sys/arch/riscv/include/pmap.h 2019/06/01 12:42:28 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */ 1/* $NetBSD: pmap.h,v 1.2 2019/06/01 12:42:28 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry. 8 * by Matt Thomas of 3am Software Foundry.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -32,32 +32,32 @@ @@ -32,32 +32,32 @@
32#ifndef _RISCV_PMAP_H_ 32#ifndef _RISCV_PMAP_H_
33#define _RISCV_PMAP_H_ 33#define _RISCV_PMAP_H_
34 34
35#ifdef _KERNEL_OPT 35#ifdef _KERNEL_OPT
36#include "opt_modular.h" 36#include "opt_modular.h"
37#endif 37#endif
38 38
39#if !defined(_MODULE) 39#if !defined(_MODULE)
40 40
41#include <sys/types.h> 41#include <sys/types.h>
42#include <sys/pool.h> 42#include <sys/pool.h>
43#include <sys/evcnt.h> 43#include <sys/evcnt.h>
44 44
 45#include <uvm/uvm_physseg.h>
45#include <uvm/pmap/vmpagemd.h> 46#include <uvm/pmap/vmpagemd.h>
46 47
47#include <riscv/pte.h> 48#include <riscv/pte.h>
48 49
49#define PMAP_SEGTABSIZE (__SHIFTOUT(PTE_PPN0, PTE_PPN0) + 1) 50#define PMAP_SEGTABSIZE NPTEPG
50#define PMAP_PDETABSIZE (__SHIFTOUT(PTE_PPN0, PTE_PPN0) + 1) 
51 51
52#define NBSEG (NBPG*NPTEPG) 52#define NBSEG (NBPG*NPTEPG)
53#ifdef _LP64 53#ifdef _LP64
54#define NBXSEG (NBSEG*NSEGPG) 54#define NBXSEG (NBSEG*NSEGPG)
55#define XSEGSHIFT (SEGSHIFT + PGSHIFT - 3) 55#define XSEGSHIFT (SEGSHIFT + PGSHIFT - 3)
56#define XSEGOFSET (PTE_PPN1|SEGOFSET) 56#define XSEGOFSET (PTE_PPN1|SEGOFSET)
57#define SEGSHIFT (PGSHIFT + PGSHIFT - 3) 57#define SEGSHIFT (PGSHIFT + PGSHIFT - 3)
58#else 58#else
59#define SEGSHIFT (PGSHIFT + PGSHIFT - 2) 59#define SEGSHIFT (PGSHIFT + PGSHIFT - 2)
60#endif 60#endif
61#define SEGOFSET (PTE_PPN0|PAGE_MASK) 61#define SEGOFSET (PTE_PPN0|PAGE_MASK)
62 62
63#define KERNEL_PID 0 63#define KERNEL_PID 0
@@ -66,62 +66,73 @@ @@ -66,62 +66,73 @@
66#define PMAP_TLB_NUM_PIDS 256 66#define PMAP_TLB_NUM_PIDS 256
67#define PMAP_TLB_MAX 1 67#define PMAP_TLB_MAX 1
68#ifdef _LP64 68#ifdef _LP64
69#define PMAP_INVALID_PDETAB_ADDRESS ((pmap_pdetab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE)) 69#define PMAP_INVALID_PDETAB_ADDRESS ((pmap_pdetab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE))
70#define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE)) 70#define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE))
71#else 71#else
72#define PMAP_INVALID_PDETAB_ADDRESS ((pmap_pdetab_t *)0xdeadbeef) 72#define PMAP_INVALID_PDETAB_ADDRESS ((pmap_pdetab_t *)0xdeadbeef)
73#define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)0xdeadbeef) 73#define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)0xdeadbeef)
74#endif 74#endif
75#define PMAP_TLB_FLUSH_ASID_ON_RESET false 75#define PMAP_TLB_FLUSH_ASID_ON_RESET false
76 76
77#define pmap_phys_address(x) (x) 77#define pmap_phys_address(x) (x)
78 78
 79#ifndef __BSD_PTENTRY_T__
 80#define __BSD_PTENTRY_T__
 81#ifdef _LP64
 82#define PRIxPTE PRIx64
 83#else
 84#define PRIxPTE PRIx32
 85#endif
 86#endif /* __BSD_PTENTRY_T__ */
 87
79#define PMAP_NEED_PROCWR 88#define PMAP_NEED_PROCWR
80static inline void 89static inline void
81pmap_procwr(struct proc *p, vaddr_t va, vsize_t len) 90pmap_procwr(struct proc *p, vaddr_t va, vsize_t len)
82{ 91{
83 __asm __volatile("fence\trw,rw; fence.i"); 92 __asm __volatile("fence\trw,rw; fence.i");
84} 93}
85 94
86 95
87#include <uvm/pmap/tlb.h> 96#include <uvm/pmap/tlb.h>
88 97
89#include <uvm/pmap/pmap_tlb.h> 98#include <uvm/pmap/pmap_tlb.h>
90 99
91#define PMAP_GROWKERNEL 100#define PMAP_GROWKERNEL
92#define PMAP_STEAL_MEMORY 101#define PMAP_STEAL_MEMORY
93 102
94#ifdef _KERNEL 103#ifdef _KERNEL
95 104
96#define __HAVE_PMAP_MD 105#define __HAVE_PMAP_MD
97struct pmap_md { 106struct pmap_md {
98 paddr_t md_ptbr; 107 paddr_t md_ptbr;
 108 pd_entry_t *md_pdetab;
99}; 109};
100 110
101struct vm_page * 111struct vm_page *
102 pmap_md_alloc_poolpage(int flags); 112 pmap_md_alloc_poolpage(int flags);
103vaddr_t pmap_md_map_poolpage(paddr_t, vsize_t); 113vaddr_t pmap_md_map_poolpage(paddr_t, vsize_t);
104void pmap_md_unmap_poolpage(vaddr_t, vsize_t); 114void pmap_md_unmap_poolpage(vaddr_t, vsize_t);
105bool pmap_md_direct_mapped_vaddr_p(vaddr_t); 115bool pmap_md_direct_mapped_vaddr_p(vaddr_t);
106bool pmap_md_io_vaddr_p(vaddr_t); 116bool pmap_md_io_vaddr_p(vaddr_t);
107paddr_t pmap_md_direct_mapped_vaddr_to_paddr(vaddr_t); 117paddr_t pmap_md_direct_mapped_vaddr_to_paddr(vaddr_t);
108vaddr_t pmap_md_direct_map_paddr(paddr_t); 118vaddr_t pmap_md_direct_map_paddr(paddr_t);
109void pmap_md_init(void); 119void pmap_md_init(void);
110bool pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t); 120bool pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t);
111//void pmap_md_page_syncicache(struct vm_page *, const kcpuset_t *); 121//void pmap_md_page_syncicache(struct vm_page *, const kcpuset_t *);
112 122
113void pmap_md_pdetab_activate(struct pmap *); 123void pmap_md_pdetab_activate(struct pmap *);
114void pmap_md_pdetab_init(struct pmap *); 124void pmap_md_pdetab_init(struct pmap *);
 125bool pmap_md_ok_to_steal_p(const uvm_physseg_t, size_t);
115 126
116#ifdef __PMAP_PRIVATE 127#ifdef __PMAP_PRIVATE
117static inline void 128static inline void
118pmap_md_page_syncicache(struct vm_page *pg, const kcpuset_t *kc) 129pmap_md_page_syncicache(struct vm_page *pg, const kcpuset_t *kc)
119{ 130{
120 __asm __volatile("fence\trw,rw; fence.i"); 131 __asm __volatile("fence\trw,rw; fence.i");
121} 132}
122 133
123/* 134/*
124 * Virtual Cache Alias helper routines. Not a problem for RISCV CPUs. 135 * Virtual Cache Alias helper routines. Not a problem for RISCV CPUs.
125 */ 136 */
126static inline bool 137static inline bool
127pmap_md_vca_add(struct vm_page *pg, vaddr_t va, pt_entry_t *nptep) 138pmap_md_vca_add(struct vm_page *pg, vaddr_t va, pt_entry_t *nptep)
@@ -156,20 +167,20 @@ pmap_md_tlb_asid_max(void) @@ -156,20 +167,20 @@ pmap_md_tlb_asid_max(void)
156#endif /* !_MODULE */ 167#endif /* !_MODULE */
157 168
158#if defined(MODULAR) || defined(_MODULE) 169#if defined(MODULAR) || defined(_MODULE)
159/* 170/*
160 * Define a compatible vm_page_md so that struct vm_page is the same size 171 * Define a compatible vm_page_md so that struct vm_page is the same size
161 * whether we are using modules or not. 172 * whether we are using modules or not.
162 */ 173 */
163#ifndef __HAVE_VM_PAGE_MD 174#ifndef __HAVE_VM_PAGE_MD
164#define __HAVE_VM_PAGE_MD 175#define __HAVE_VM_PAGE_MD
165 176
166struct vm_page_md { 177struct vm_page_md {
167 uintptr_t mdpg_dummy[3]; 178 uintptr_t mdpg_dummy[3];
168}; 179};
169#endif /* !__HVE_VM_PAGE_MD */ 
170 
171__CTASSERT(sizeof(struct vm_page_md) == sizeof(uintptr_t)*3); 180__CTASSERT(sizeof(struct vm_page_md) == sizeof(uintptr_t)*3);
172 181
 182#endif /* !__HAVE_VM_PAGE_MD */
 183
173#endif /* MODULAR || _MODULE */ 184#endif /* MODULAR || _MODULE */
174 185
175#endif /* !_RISCV_PMAP_H_ */ 186#endif /* !_RISCV_PMAP_H_ */

cvs diff -r1.1 -r1.2 src/sys/arch/riscv/include/pte.h (expand / switch to unified diff)

--- src/sys/arch/riscv/include/pte.h 2014/09/19 17:36:26 1.1
+++ src/sys/arch/riscv/include/pte.h 2019/06/01 12:42:28 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pte.h,v 1.1 2014/09/19 17:36:26 matt Exp $ */ 1/* $NetBSD: pte.h,v 1.2 2019/06/01 12:42:28 maxv Exp $ */
2/*- 2/*-
3 * Copyright (c) 2014 The NetBSD Foundation, Inc. 3 * Copyright (c) 2014 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Matt Thomas of 3am Software Foundry. 7 * by Matt Thomas of 3am Software Foundry.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -229,58 +229,41 @@ pte_make_kenter_pa(paddr_t pa, struct vm @@ -229,58 +229,41 @@ pte_make_kenter_pa(paddr_t pa, struct vm
229 pte |= PTE_WIRED | PTE_V; 229 pte |= PTE_WIRED | PTE_V;
230 pte |= pte_flag_bits(NULL, flags, true); 230 pte |= pte_flag_bits(NULL, flags, true);
231 pte |= pte_prot_bits(NULL, prot, true); /* pretend unmanaged */ 231 pte |= pte_prot_bits(NULL, prot, true); /* pretend unmanaged */
232 232
233 return pte; 233 return pte;
234} 234}
235 235
236static inline void 236static inline void
237pte_set(pt_entry_t *ptep, pt_entry_t pte) 237pte_set(pt_entry_t *ptep, pt_entry_t pte)
238{ 238{
239 *ptep = pte; 239 *ptep = pte;
240} 240}
241 241
242static inline pd_entry_t 
243pte_invalid_pde(void) 
244{ 
245 return 0; 
246} 
247 
248static inline pd_entry_t 
249pte_pde_pdetab(paddr_t pa) 
250{ 
251 return PTE_V | PTE_G | PTE_T | pa; 
252} 
253 
254static inline pd_entry_t 
255pte_pde_ptpage(paddr_t pa) 
256{ 
257 return PTE_V | PTE_G | PTE_T | pa; 
258} 
259 
260static inline bool 
261pte_pde_valid_p(pd_entry_t pde) 
262{ 
263 return (pde & (PTE_V|PTE_T)) == (PTE_V|PTE_T); 
264} 
265 
266static inline paddr_t 242static inline paddr_t
267pte_pde_to_paddr(pd_entry_t pde) 243pte_pde_to_paddr(pd_entry_t pde)
268{ 244{
269 return pde & ~PAGE_MASK; 245 return pde & ~PAGE_MASK;
270} 246}
271 247
272static inline pd_entry_t 248static inline pd_entry_t
273pte_pde_cas(pd_entry_t *pdep, pd_entry_t opde, pt_entry_t npde) 249pte_pde_cas(pd_entry_t *pdep, pd_entry_t opde, pt_entry_t npde)
274{ 250{
275#ifdef MULTIPROCESSOR 251#ifdef MULTIPROCESSOR
276#ifdef _LP64 252#ifdef _LP64
277 return atomic_cas_64(pdep, opde, npde); 253 return atomic_cas_64(pdep, opde, npde);
278#else 254#else
279 return atomic_cas_32(pdep, opde, npde); 255 return atomic_cas_32(pdep, opde, npde);
280#endif 256#endif
281#else 257#else
282 *pdep = npde; 258 *pdep = npde;
283 return 0; 259 return 0;
284#endif 260#endif
285} 261}
 262
 263static inline pt_entry_t
 264pte_value(pt_entry_t pte)
 265{
 266 return pte;
 267}
 268
286#endif /* _RISCV_PTE_H_ */ 269#endif /* _RISCV_PTE_H_ */

cvs diff -r1.2 -r1.3 src/sys/arch/riscv/include/param.h (expand / switch to unified diff)

--- src/sys/arch/riscv/include/param.h 2019/01/07 22:00:32 1.2
+++ src/sys/arch/riscv/include/param.h 2019/06/01 12:42:28 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: param.h,v 1.2 2019/01/07 22:00:32 jdolecek Exp $ */ 1/* $NetBSD: param.h,v 1.3 2019/06/01 12:42:28 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry. 8 * by Matt Thomas of 3am Software Foundry.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -56,31 +56,27 @@ @@ -56,31 +56,27 @@
56#endif 56#endif
57#define _MACHINE riscv 57#define _MACHINE riscv
58#define MACHINE "riscv" 58#define MACHINE "riscv"
59 59
60#define MID_MACHINE MID_RISCV 60#define MID_MACHINE MID_RISCV
61 61
62/* RISCV-specific macro to align a stack pointer (downwards). */ 62/* RISCV-specific macro to align a stack pointer (downwards). */
63#define STACK_ALIGNBYTES (__BIGGEST_ALIGNMENT__ - 1) 63#define STACK_ALIGNBYTES (__BIGGEST_ALIGNMENT__ - 1)
64#define ALIGNBYTES32 __BIGGEST_ALIGNMENT__ 64#define ALIGNBYTES32 __BIGGEST_ALIGNMENT__
65 65
66#define NKMEMPAGES_MAX_DEFAULT (2048UL * 1024 * 1024) 66#define NKMEMPAGES_MAX_DEFAULT (2048UL * 1024 * 1024)
67#define NKMEMPAGES_MIN_DEFAULT (128UL * 1024 * 1024) 67#define NKMEMPAGES_MIN_DEFAULT (128UL * 1024 * 1024)
68 68
69#ifdef _LP64 
70#define PGSHIFT 13 
71#else 
72#define PGSHIFT 12 69#define PGSHIFT 12
73#endif 
74#define NBPG (1 << PGSHIFT) 70#define NBPG (1 << PGSHIFT)
75#define PGOFSET (NBPG - 1) 71#define PGOFSET (NBPG - 1)
76 72
77#define UPAGES 2 73#define UPAGES 2
78#define USPACE (UPAGES << PGSHIFT) 74#define USPACE (UPAGES << PGSHIFT)
79#define USPACE_ALIGN NBPG 75#define USPACE_ALIGN NBPG
80 76
81/* 77/*
82 * Constants related to network buffer management. 78 * Constants related to network buffer management.
83 * MCLBYTES must be no larger than NBPG (the software page size), and 79 * MCLBYTES must be no larger than NBPG (the software page size), and
84 * NBPG % MCLBYTES must be zero. 80 * NBPG % MCLBYTES must be zero.
85 */ 81 */
86#define MSIZE 512 /* size of an mbuf */ 82#define MSIZE 512 /* size of an mbuf */

cvs diff -r1.1 -r1.2 src/sys/arch/riscv/riscv/core_machdep.c (expand / switch to unified diff)

--- src/sys/arch/riscv/riscv/core_machdep.c 2015/03/28 16:13:56 1.1
+++ src/sys/arch/riscv/riscv/core_machdep.c 2019/06/01 12:42:28 1.2
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE. 27 * POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31 31
32#ifndef CORENAME 32#ifndef CORENAME
33__RCSID("$NetBSD: core_machdep.c,v 1.1 2015/03/28 16:13:56 matt Exp $"); 33__RCSID("$NetBSD: core_machdep.c,v 1.2 2019/06/01 12:42:28 maxv Exp $");
34#endif 34#endif
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/proc.h> 38#include <sys/proc.h>
39#include <sys/core.h> 39#include <sys/core.h>
40#include <sys/exec.h> 40#include <sys/exec.h>
41#include <sys/cpu.h> 41#include <sys/cpu.h>
42 42
43#include <riscv/locore.h> 43#include <riscv/locore.h>
44 44
45#ifndef CORENAME 45#ifndef CORENAME
46#define CORENAME(n) n 46#define CORENAME(n) n
@@ -73,27 +73,27 @@ CORENAME(cpu_coredump)(struct lwp *l, st @@ -73,27 +73,27 @@ CORENAME(cpu_coredump)(struct lwp *l, st
73 } 73 }
74 74
75 pcu_save_all(l); 75 pcu_save_all(l);
76 76
77 // Can't use structure assignment if this is doing COMPAT_NETBSD32 77 // Can't use structure assignment if this is doing COMPAT_NETBSD32
78 const struct trapframe * const tf = l->l_md.md_utf; 78 const struct trapframe * const tf = l->l_md.md_utf;
79 for (size_t i = _X_RA; i <= _X_GP; i++) { 79 for (size_t i = _X_RA; i <= _X_GP; i++) {
80 cpustate.tf.tf_reg[i] = tf->tf_reg[i]; 80 cpustate.tf.tf_reg[i] = tf->tf_reg[i];
81 } 81 }
82 cpustate.tf.tf_pc = tf->tf_pc; 82 cpustate.tf.tf_pc = tf->tf_pc;
83 cpustate.tf.tf_badaddr = tf->tf_badaddr; 83 cpustate.tf.tf_badaddr = tf->tf_badaddr;
84 cpustate.tf.tf_cause = tf->tf_cause; 84 cpustate.tf.tf_cause = tf->tf_cause;
85 cpustate.tf.tf_sr = tf->tf_sr; 85 cpustate.tf.tf_sr = tf->tf_sr;
86 if (fpu_valid_p()) { 86 if (fpu_valid_p(l)) {
87 cpustate.fpregs = ((struct pcb *)lwp_getpcb(l))->pcb_fpregs; 87 cpustate.fpregs = ((struct pcb *)lwp_getpcb(l))->pcb_fpregs;
88 } else { 88 } else {
89 memset(&cpustate.fpregs, 0, sizeof(cpustate.fpregs)); 89 memset(&cpustate.fpregs, 0, sizeof(cpustate.fpregs));
90 } 90 }
91 CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU); 91 CORE_SETMAGIC(cseg, CORESEGMAGIC, MID_MACHINE, CORE_CPU);
92 cseg.c_addr = 0; 92 cseg.c_addr = 0;
93 cseg.c_size = chdr->c_cpusize; 93 cseg.c_size = chdr->c_cpusize;
94 94
95 error = coredump_write(iocookie, UIO_SYSSPACE, &cseg, 95 error = coredump_write(iocookie, UIO_SYSSPACE, &cseg,
96 chdr->c_seghdrsize); 96 chdr->c_seghdrsize);
97 if (error) 97 if (error)
98 return error; 98 return error;
99 99

cvs diff -r1.3 -r1.4 src/sys/arch/riscv/riscv/genassym.cf (expand / switch to unified diff)

--- src/sys/arch/riscv/riscv/genassym.cf 2015/03/31 06:47:47 1.3
+++ src/sys/arch/riscv/riscv/genassym.cf 2019/06/01 12:42:28 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: genassym.cf,v 1.3 2015/03/31 06:47:47 matt Exp $ 1# $NetBSD: genassym.cf,v 1.4 2019/06/01 12:42:28 maxv Exp $
2#- 2#-
3# Copyright (c) 2014 The NetBSD Foundation, Inc. 3# Copyright (c) 2014 The NetBSD Foundation, Inc.
4# All rights reserved. 4# All rights reserved.
5# 5#
6# This code is derived from software contributed to The NetBSD Foundation 6# This code is derived from software contributed to The NetBSD Foundation
7# by Matt Thomas of 3am Software Foundry. 7# by Matt Thomas of 3am Software Foundry.
8# 8#
9# Redistribution and use in source and binary forms, with or without 9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions 10# modification, are permitted provided that the following conditions
11# are met: 11# are met:
12# 1. Redistributions of source code must retain the above copyright 12# 1. Redistributions of source code must retain the above copyright
13# notice, this list of conditions and the following disclaimer. 13# notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright 14# 2. Redistributions in binary form must reproduce the above copyright
@@ -184,15 +184,15 @@ define XSEGSHIFT XSEGSHIFT @@ -184,15 +184,15 @@ define XSEGSHIFT XSEGSHIFT
184endif 184endif
185define SEGSHIFT SEGSHIFT 185define SEGSHIFT SEGSHIFT
186define PGSHIFT PGSHIFT 186define PGSHIFT PGSHIFT
187define NPDEPG NPDEPG 187define NPDEPG NPDEPG
188define NBSEG NBSEG 188define NBSEG NBSEG
189 189
190define PTE_T PTE_T 190define PTE_T PTE_T
191define PTE_V PTE_V 191define PTE_V PTE_V
192define PTE_G PTE_G 192define PTE_G PTE_G
193define PTE_SX PTE_SX 193define PTE_SX PTE_SX
194define PTE_SW PTE_SW 194define PTE_SW PTE_SW
195define PTE_SR PTE_SR 195define PTE_SR PTE_SR
196 196
197define PM_PDETAB offsetof(struct pmap, pm_pdetab) 197define PM_MD_PDETAB offsetof(struct pmap, pm_md.md_pdetab)
198define PM_MD_PTBR offsetof(struct pmap, pm_md.md_ptbr) 198define PM_MD_PTBR offsetof(struct pmap, pm_md.md_ptbr)

cvs diff -r1.7 -r1.8 src/sys/arch/riscv/riscv/locore.S (expand / switch to unified diff)

--- src/sys/arch/riscv/riscv/locore.S 2018/02/05 10:41:12 1.7
+++ src/sys/arch/riscv/riscv/locore.S 2019/06/01 12:42:28 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: locore.S,v 1.7 2018/02/05 10:41:12 maya Exp $ */ 1/* $NetBSD: locore.S,v 1.8 2019/06/01 12:42:28 maxv Exp $ */
2/*- 2/*-
3 * Copyright (c) 2014 The NetBSD Foundation, Inc. 3 * Copyright (c) 2014 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Matt Thomas of 3am Software Foundry. 7 * by Matt Thomas of 3am Software Foundry.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -81,27 +81,31 @@ ENTRY_NP(start) @@ -81,27 +81,31 @@ ENTRY_NP(start)
81 INT_L a7, (zero) // load memory size 81 INT_L a7, (zero) // load memory size
82 slli a7, a7, (20-PGSHIFT) // convert MB to pages 82 slli a7, a7, (20-PGSHIFT) // convert MB to pages
83.L01: PTR_LA t0, physmem 83.L01: PTR_LA t0, physmem
84 INT_S a7, (t0) // store it in physmem 84 INT_S a7, (t0) // store it in physmem
85 85
86 li t4, PTE_V | PTE_SX | PTE_SW | PTE_SR | PTE_G 86 li t4, PTE_V | PTE_SX | PTE_SW | PTE_SR | PTE_G
87#ifdef _LP64 87#ifdef _LP64
88 REG_S t4, 0(s2) // keep a mapping for the first 8GB. 88 REG_S t4, 0(s2) // keep a mapping for the first 8GB.
89 or t0, s3, t4 // point to next page 89 or t0, s3, t4 // point to next page
90 or t0, t0, PTE_T // tranverse it. 90 or t0, t0, PTE_T // tranverse it.
91 REG_S t0, -SZREG(s3) // store in highest first level PDE 91 REG_S t0, -SZREG(s3) // store in highest first level PDE
92#endif 92#endif
93 93
94#if (VM_MIN_KERNEL_ADDRESS >> XSEGSHIFT) != (VM_MAX_KERNEL_ADDRESS >> XSEGSHIFT) 94 /*
 95 * XXX XXX XXX: This is completely broken and wrong, we should map only
 96 * the kernel sections, and the direct map should be mapped later in C.
 97 */
 98#if 0 && (VM_MIN_KERNEL_ADDRESS >> XSEGSHIFT) != (VM_MAX_KERNEL_ADDRESS >> XSEGSHIFT)
95#error VM_MIN_KERNEL_ADDRESS not in same first level PDE as VM_MAX_KERNEL_ADDRESS 99#error VM_MIN_KERNEL_ADDRESS not in same first level PDE as VM_MAX_KERNEL_ADDRESS
96#endif 100#endif
97 // We allocated the kernel first PTE page so let's insert in the 101 // We allocated the kernel first PTE page so let's insert in the
98 // page table. For now, we assume it's in the same PDE page as the 102 // page table. For now, we assume it's in the same PDE page as the
99 // direct-mapped memory. 103 // direct-mapped memory.
100 or t0, s4, t4 104 or t0, s4, t4
101 or t0, t0, PTE_T 105 or t0, t0, PTE_T
102#if ((VM_MIN_KERNEL_ADDRESS >> SEGSHIFT) & (NPDEPG-1)) * SZREG 106#if ((VM_MIN_KERNEL_ADDRESS >> SEGSHIFT) & (NPDEPG-1)) * SZREG
103 li t1, ((VM_MIN_KERNEL_ADDRESS >> SEGSHIFT) & (NPDEPG-1)) * SZREG 107 li t1, ((VM_MIN_KERNEL_ADDRESS >> SEGSHIFT) & (NPDEPG-1)) * SZREG
104 add t1, t1, s3 108 add t1, t1, s3
105 REG_S t0, 0(t1) 109 REG_S t0, 0(t1)
106#else 110#else
107 REG_S t0, 0(s3) 111 REG_S t0, 0(s3)
@@ -134,27 +138,27 @@ ENTRY_NP(start) @@ -134,27 +138,27 @@ ENTRY_NP(start)
134 csrw sscratch, zero // zero in sscratch to mark kernel 138 csrw sscratch, zero // zero in sscratch to mark kernel
135 139
136 PTR_LA tp, _C_LABEL(lwp0) // put curlwp in tp 140 PTR_LA tp, _C_LABEL(lwp0) // put curlwp in tp
137 141
138 PTR_LA a0, _C_LABEL(cpu_exception_handler) 142 PTR_LA a0, _C_LABEL(cpu_exception_handler)
139 csrw stvec, a0 143 csrw stvec, a0
140 144
141 PTR_S s1, L_PCB(tp) // set uarea of lwp (already zeroed) 145 PTR_S s1, L_PCB(tp) // set uarea of lwp (already zeroed)
142 addi sp, s2, -TF_LEN // switch to new stack 146 addi sp, s2, -TF_LEN // switch to new stack
143 PTR_S sp, L_MD_UTF(tp) // store pointer to empty trapframe 147 PTR_S sp, L_MD_UTF(tp) // store pointer to empty trapframe
144 148
145 PTR_LA t1, _C_LABEL(kernel_pmap_store) 149 PTR_LA t1, _C_LABEL(kernel_pmap_store)
146 add t2, s2, s11 // PA -> VA 150 add t2, s2, s11 // PA -> VA
147 PTR_S t2, PM_PDETAB(t1) // VA of kernel PDETAB 151 PTR_S t2, PM_MD_PDETAB(t1) // VA of kernel PDETAB
148 PTR_S s2, PM_MD_PTBR(t1) // PA of kernel PDETAB 152 PTR_S s2, PM_MD_PTBR(t1) // PA of kernel PDETAB
149 153
150 // Now we should ready to start initializing the kernel. 154 // Now we should ready to start initializing the kernel.
151 PTR_LA a0, _C_LABEL(start) // kernel_start 155 PTR_LA a0, _C_LABEL(start) // kernel_start
152 add a1, s5, s11 // kernel_end 156 add a1, s5, s11 // kernel_end
153 call _C_LABEL(init_riscv) // do MD startup 157 call _C_LABEL(init_riscv) // do MD startup
154 tail _C_LABEL(main) // and transfer to main 158 tail _C_LABEL(main) // and transfer to main
155 // not reached 159 // not reached
156END(start) 160END(start)
157 161
158// 162//
159// struct lwp *cpu_switchto(struct lwp *oldl, struct lwp *newl, bool returning); 163// struct lwp *cpu_switchto(struct lwp *oldl, struct lwp *newl, bool returning);
160// 164//

cvs diff -r1.2 -r1.3 src/sys/arch/riscv/riscv/pmap_machdep.c (expand / switch to unified diff)

--- src/sys/arch/riscv/riscv/pmap_machdep.c 2015/03/31 01:14:57 1.2
+++ src/sys/arch/riscv/riscv/pmap_machdep.c 2019/06/01 12:42:28 1.3
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE. 27 * POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#define __PMAP_PRIVATE 30#define __PMAP_PRIVATE
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33 33
34__RCSID("$NetBSD: pmap_machdep.c,v 1.2 2015/03/31 01:14:57 matt Exp $"); 34__RCSID("$NetBSD: pmap_machdep.c,v 1.3 2019/06/01 12:42:28 maxv Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37 37
38#include <uvm/uvm.h> 38#include <uvm/uvm.h>
39 39
40#include <riscv/locore.h> 40#include <riscv/locore.h>
41 41
42int riscv_poolpage_vmfreelist = VM_FREELIST_DEFAULT; 42int riscv_poolpage_vmfreelist = VM_FREELIST_DEFAULT;
43 43
44void 44void
45pmap_zero_page(paddr_t pa) 45pmap_zero_page(paddr_t pa)
46{ 46{
47#ifdef POOL_PHYSTOV 47#ifdef POOL_PHYSTOV
@@ -90,27 +90,27 @@ pmap_md_direct_mapped_vaddr_p(vaddr_t va @@ -90,27 +90,27 @@ pmap_md_direct_mapped_vaddr_p(vaddr_t va
90 return VM_MAX_KERNEL_ADDRESS <= va && (intptr_t) va < 0; 90 return VM_MAX_KERNEL_ADDRESS <= va && (intptr_t) va < 0;
91} 91}
92 92
93bool 93bool
94pmap_md_io_vaddr_p(vaddr_t va) 94pmap_md_io_vaddr_p(vaddr_t va)
95{ 95{
96 return false; 96 return false;
97} 97}
98 98
99paddr_t 99paddr_t
100pmap_md_direct_mapped_vaddr_to_paddr(vaddr_t va) 100pmap_md_direct_mapped_vaddr_to_paddr(vaddr_t va)
101{ 101{
102 KASSERT(VM_MAX_KERNEL_ADDRESS <= va && (intptr_t) va < 0); 102 KASSERT(VM_MAX_KERNEL_ADDRESS <= va && (intptr_t) va < 0);
103 const pmap_pdetab_t *ptb = pmap_kernel()->pm_pdetab; 103 const pmap_pdetab_t *ptb = pmap_kernel()->pm_md.md_pdetab;
104 pd_entry_t pde; 104 pd_entry_t pde;
105 105
106#ifdef _LP64 106#ifdef _LP64
107 pde = ptb->pde_pde[(va >> XSEGSHIFT) & (NPDEPG-1)]; 107 pde = ptb->pde_pde[(va >> XSEGSHIFT) & (NPDEPG-1)];
108 if ((pde & PTE_V) == 0) { 108 if ((pde & PTE_V) == 0) {
109 return -(paddr_t)1; 109 return -(paddr_t)1;
110 } 110 }
111 if ((pde & PTE_T) == 0) { 111 if ((pde & PTE_T) == 0) {
112 return pde & ~XSEGOFSET; 112 return pde & ~XSEGOFSET;
113 } 113 }
114 ptb = (const pmap_pdetab_t *)POOL_PHYSTOV(pte_pde_to_paddr(pde)); 114 ptb = (const pmap_pdetab_t *)POOL_PHYSTOV(pte_pde_to_paddr(pde));
115#endif 115#endif
116 pde = ptb->pde_pde[(va >> SEGSHIFT) & (NPDEPG-1)]; 116 pde = ptb->pde_pde[(va >> SEGSHIFT) & (NPDEPG-1)];
@@ -126,43 +126,49 @@ pmap_md_direct_mapped_vaddr_to_paddr(vad @@ -126,43 +126,49 @@ pmap_md_direct_mapped_vaddr_to_paddr(vad
126vaddr_t 126vaddr_t
127pmap_md_direct_map_paddr(paddr_t pa) 127pmap_md_direct_map_paddr(paddr_t pa)
128{ 128{
129 return POOL_PHYSTOV(pa); 129 return POOL_PHYSTOV(pa);
130} 130}
131 131
132void 132void
133pmap_md_init(void) 133pmap_md_init(void)
134{ 134{
135 pmap_tlb_info_evcnt_attach(&pmap_tlb0_info); 135 pmap_tlb_info_evcnt_attach(&pmap_tlb0_info);
136} 136}
137 137
138bool 138bool
 139pmap_md_ok_to_steal_p(const uvm_physseg_t bank, size_t npgs)
 140{
 141 return true;
 142}
 143
 144bool
139pmap_md_tlb_check_entry(void *ctx, vaddr_t va, tlb_asid_t asid, pt_entry_t pte) 145pmap_md_tlb_check_entry(void *ctx, vaddr_t va, tlb_asid_t asid, pt_entry_t pte)
140{ 146{
141 return false; 147 return false;
142} 148}
143  149
144void 150void
145pmap_md_pdetab_activate(struct pmap *pmap) 151pmap_md_pdetab_activate(struct pmap *pmap)
146{ 152{
147 __asm("csrw\tsptbr, %0" :: "r"(pmap->pm_md.md_ptbr)); 153 __asm("csrw\tsptbr, %0" :: "r"(pmap->pm_md.md_ptbr));
148} 154}
149 155
150void 156void
151pmap_md_pdetab_init(struct pmap *pmap) 157pmap_md_pdetab_init(struct pmap *pmap)
152{ 158{
153 pmap->pm_pdetab[NPDEPG-1] = pmap_kernel()->pm_pdetab[NPDEPG-1]; 159 pmap->pm_md.md_pdetab[NPDEPG-1] = pmap_kernel()->pm_md.md_pdetab[NPDEPG-1];
154 pmap->pm_md.md_ptbr = 160 pmap->pm_md.md_ptbr =
155 pmap_md_direct_mapped_vaddr_to_paddr((vaddr_t)pmap->pm_pdetab); 161 pmap_md_direct_mapped_vaddr_to_paddr((vaddr_t)pmap->pm_md.md_pdetab);
156} 162}
157 163
158// TLB mainenance routines 164// TLB mainenance routines
159 165
160tlb_asid_t 166tlb_asid_t
161tlb_get_asid(void) 167tlb_get_asid(void)
162{ 168{
163 return riscvreg_asid_read(); 169 return riscvreg_asid_read();
164} 170}
165 171
166void 172void
167tlb_set_asid(tlb_asid_t asid) 173tlb_set_asid(tlb_asid_t asid)
168{ 174{

cvs diff -r1.11 -r1.12 src/sys/uvm/pmap/pmap.h (expand / switch to unified diff)

--- src/sys/uvm/pmap/pmap.h 2019/05/20 17:00:57 1.11
+++ src/sys/uvm/pmap/pmap.h 2019/06/01 12:42:28 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.h,v 1.11 2019/05/20 17:00:57 skrll Exp $ */ 1/* $NetBSD: pmap.h,v 1.12 2019/06/01 12:42:28 maxv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Ralph Campbell. 8 * Ralph Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -124,26 +124,29 @@ extern kmutex_t pmap_segtab_lock; @@ -124,26 +124,29 @@ extern kmutex_t pmap_segtab_lock;
124struct pmap { 124struct pmap {
125#ifdef MULTIPROCESSOR 125#ifdef MULTIPROCESSOR
126 kcpuset_t *pm_active; /* pmap was active on ... */ 126 kcpuset_t *pm_active; /* pmap was active on ... */
127 kcpuset_t *pm_onproc; /* pmap is active on ... */ 127 kcpuset_t *pm_onproc; /* pmap is active on ... */
128 volatile u_int pm_shootdown_pending; 128 volatile u_int pm_shootdown_pending;
129#endif 129#endif
130 pmap_segtab_t * pm_segtab; /* pointers to pages of PTEs */ 130 pmap_segtab_t * pm_segtab; /* pointers to pages of PTEs */
131 u_int pm_count; /* pmap reference count */ 131 u_int pm_count; /* pmap reference count */
132 u_int pm_flags; 132 u_int pm_flags;
133#define PMAP_DEFERRED_ACTIVATE __BIT(0) 133#define PMAP_DEFERRED_ACTIVATE __BIT(0)
134 struct pmap_statistics pm_stats; /* pmap statistics */ 134 struct pmap_statistics pm_stats; /* pmap statistics */
135 vaddr_t pm_minaddr; 135 vaddr_t pm_minaddr;
136 vaddr_t pm_maxaddr; 136 vaddr_t pm_maxaddr;
 137#ifdef __HAVE_PMAP_MD
 138 struct pmap_md pm_md;
 139#endif
137 struct pmap_asid_info pm_pai[1]; 140 struct pmap_asid_info pm_pai[1];
138}; 141};
139 142
140#ifdef _KERNEL 143#ifdef _KERNEL
141struct pmap_kernel { 144struct pmap_kernel {
142 struct pmap kernel_pmap; 145 struct pmap kernel_pmap;
143#if defined(MULTIPROCESSOR) && PMAP_TLB_MAX > 1 146#if defined(MULTIPROCESSOR) && PMAP_TLB_MAX > 1
144 struct pmap_asid_info kernel_pai[PMAP_TLB_MAX-1]; 147 struct pmap_asid_info kernel_pai[PMAP_TLB_MAX-1];
145#endif 148#endif
146}; 149};
147 150
148struct pmap_limits { 151struct pmap_limits {
149 paddr_t avail_start; 152 paddr_t avail_start;