shithub: riscv

Download patch

ref: f48f1a324aaad4616b93ec595d5e0f2e22d12bc4
parent: c9570c14af7780384df818c94700dc8a18a29423
author: cinap_lenrek <[email protected]>
date: Wed Dec 4 17:02:51 EST 2019

bcm: use extended small pages so XN bit can work

the change to support no-execute bits broke the original
raspberry pi1, as it uses backwards compatible page table
format.

to use the XN bit, subpage AP bits have to be disabled
using the XP bit in CP15 Control Register c1 Bit 23.

--- a/sys/src/9/bcm/archbcm.c
+++ b/sys/src/9/bcm/archbcm.c
@@ -116,12 +116,6 @@
 }
 
 int
-l2ap(int ap)
-{
-	return (AP(3, (ap))|AP(2, (ap))|AP(1, (ap))|AP(0, (ap)));
-}
-
-int
 cmpswap(long *addr, long old, long new)
 {
 	return cas32(addr, old, new);
--- a/sys/src/9/bcm/archbcm2.c
+++ b/sys/src/9/bcm/archbcm2.c
@@ -221,12 +221,6 @@
 	addclock0link(wdogfeed, HZ);
 }
 
-int
-l2ap(int ap)
-{
-	return (AP(0, (ap)));
-}
-
 void
 cpustart(int cpu)
 {
--- a/sys/src/9/bcm/arm.h
+++ b/sys/src/9/bcm/arm.h
@@ -123,6 +123,7 @@
 #define CpCha		(1<<17)		/* HA: hw access flag enable */
 #define CpCdz		(1<<19)		/* DZ: divide by zero fault enable */
 #define CpCfi		(1<<21)		/* FI: fast intrs */
+#define CpCxp		(1<<23)		/* XP: subpage AP bits disabled */
 #define CpCve		(1<<24)		/* VE: intr vectors enable */
 #define CpCee		(1<<25)		/* EE: exception endianness */
 #define CpCnmfi		(1<<27)		/* NMFI: non-maskable fast intrs. */
@@ -309,8 +310,8 @@
 
 #define F(v, o, w)	(((v) & ((1<<(w))-1))<<(o))
 #define AP(n, v)	F((v), ((n)*2)+4, 2)
-#define L1AP(ap)	(AP(3, (ap)))
-/* L2AP differs between armv6 and armv7 -- see l2ap in arch*.c */
+#define L1AP(ap)	AP(3, (ap))
+#define L2AP(ap)	AP(0, (ap))
 #define DAC(n, v)	F((v), (n)*2, 2)
 
 #define HVECTORS	0xffff0000
--- a/sys/src/9/bcm/armv6.s
+++ b/sys/src/9/bcm/armv6.s
@@ -57,7 +57,7 @@
 	 * enable caches, mmu, and high vectors
 	 */
 	MRC	CpSC, 0, R0, C(CpCONTROL), C(0), CpMainctl
-	ORR	$(CpChv|CpCdcache|CpCicache|CpCpredict|CpCmmu), R0
+	ORR	$(CpCxp|CpChv|CpCdcache|CpCicache|CpCpredict|CpCmmu), R0
 	MCR	CpSC, 0, R0, C(CpCONTROL), C(0), CpMainctl
 	ISB
 
--- a/sys/src/9/bcm/fns.h
+++ b/sys/src/9/bcm/fns.h
@@ -99,7 +99,6 @@
 extern void wdogfeed(void);
 extern void writeconf(void);
 extern void vtable(void);
-extern int l2ap(int);
 extern uint getcputemp(void);
 extern char *cputype2name(char *buf, int size);
 extern uint getboardrev(void);
--- a/sys/src/9/bcm/mkfile
+++ b/sys/src/9/bcm/mkfile
@@ -112,6 +112,7 @@
 main.$O: errstr.h init.h reboot.h
 devmouse.$O mouse.$O screen.$O: screen.h
 usbdwc.$O: dwcotg.h ../port/usb.h
+arch.$O archbcm.$O archbcm2.$O clock.$O coproc.$O fpiarn.$O mmu.$O trap.$O vfp3.$O: arm.h mem.h
 
 init.h:D:	../port/initcode.c init9.s
 	$CC ../port/initcode.c
--- a/sys/src/9/bcm/mmu.c
+++ b/sys/src/9/bcm/mmu.c
@@ -9,7 +9,6 @@
 #define FEXT(d, o, w)	(((d)>>(o)) & ((1<<(w))-1))
 #define L1X(va)		FEXT((va), 20, 12)
 #define L2X(va)		FEXT((va), 12, 8)
-#define L2AP(ap)	l2ap(ap)
 #define L1ptedramattrs	soc.l1ptedramattrs
 #define L2ptedramattrs	soc.l2ptedramattrs
 #define PTEDRAM		(PHYSDRAM|Dom0|L1AP(Krw)|Section|L1ptedramattrs)