Module Name:    src
Committed By:   jmcneill
Date:           Fri Sep  7 17:30:32 UTC 2018

Modified Files:
        src/sys/stand/efiboot: efiboot_machdep.h
        src/sys/stand/efiboot/bootaa64: cache.S efibootaa64.c

Log Message:
Disable MMU and dcache before jumping to the kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/efiboot_machdep.h
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/bootaa64/cache.S \
    src/sys/stand/efiboot/bootaa64/efibootaa64.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/stand/efiboot/efiboot_machdep.h
diff -u src/sys/stand/efiboot/efiboot_machdep.h:1.1 src/sys/stand/efiboot/efiboot_machdep.h:1.2
--- src/sys/stand/efiboot/efiboot_machdep.h:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/efiboot_machdep.h	Fri Sep  7 17:30:32 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot_machdep.h,v 1.1 2018/08/24 02:01:06 jmcneill Exp $ */
+/* $NetBSD: efiboot_machdep.h,v 1.2 2018/09/07 17:30:32 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca>
@@ -30,4 +30,5 @@
 #define	EFIBOOT_ALIGN 0
 #endif
 
+void efi_dcache_flush(u_long, u_long);
 void efi_boot_kernel(u_long[]);

Index: src/sys/stand/efiboot/bootaa64/cache.S
diff -u src/sys/stand/efiboot/bootaa64/cache.S:1.1 src/sys/stand/efiboot/bootaa64/cache.S:1.2
--- src/sys/stand/efiboot/bootaa64/cache.S:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/bootaa64/cache.S	Fri Sep  7 17:30:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cache.S,v 1.1 2018/08/24 02:01:06 jmcneill Exp $	*/
+/*	$NetBSD: cache.S,v 1.2 2018/09/07 17:30:32 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2014 Robin Randhawa
@@ -34,6 +34,9 @@
 
 #include <aarch64/asm.h>
 
+#define	SCTLR_M	(1<<0)
+#define	SCTLR_C	(1<<2)
+
 	.text
 	.align	2
 
@@ -96,3 +99,40 @@ ENTRY(aarch64_icache_inv_all)
 	isb
 	ret
 END(aarch64_icache_inv_all)
+
+/*
+ * void aarch64_exec_kernel(paddr_t entry, paddr_t dtb)
+ */
+ENTRY(aarch64_exec_kernel)
+	mov	x20, x0	/* kernel entry point */
+	mov	x21, x1	/* dtb address */
+
+	mrs	x0, CurrentEL
+	lsr	x0, x0, #2
+	cmp	x0, #0x2
+	b.eq	1f
+
+	/* Disable MMU and dcache, CurrentEL = EL1 */
+	mrs	x0, sctlr_el1
+	bic	x0, x0, #SCTLR_M
+	bic	x0, x0, #SCTLR_C
+	msr	sctlr_el1, x0
+	isb
+	b	2f
+1:
+	/* Disable MMU and dcache, CurrentEL = EL2 */
+	mrs	x0, sctlr_el2
+	bic	x0, x0, #SCTLR_M
+	bic	x0, x0, #SCTLR_C
+	msr	sctlr_el2, x0
+	isb
+2:
+
+	/* Jump to kernel */
+	mov	x0, x21
+	mov	x1, xzr
+	mov	x2, xzr
+	mov	x3, xzr
+	br	x20
+
+END(aarch64_exec_kernel)
Index: src/sys/stand/efiboot/bootaa64/efibootaa64.c
diff -u src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.1 src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.2
--- src/sys/stand/efiboot/bootaa64/efibootaa64.c:1.1	Fri Aug 24 02:01:06 2018
+++ src/sys/stand/efiboot/bootaa64/efibootaa64.c	Fri Sep  7 17:30:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efibootaa64.c,v 1.1 2018/08/24 02:01:06 jmcneill Exp $	*/
+/*	$NetBSD: efibootaa64.c,v 1.2 2018/09/07 17:30:32 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -36,6 +36,13 @@
 /* cache.S */
 void aarch64_dcache_wbinv_range(vaddr_t, vsize_t);
 void aarch64_icache_inv_all(void);
+void aarch64_exec_kernel(paddr_t, paddr_t);
+
+void
+efi_dcache_flush(u_long start, u_long size)
+{
+	aarch64_dcache_wbinv_range(start, size);
+}
 
 void
 efi_boot_kernel(u_long marks[MARK_MAX])
@@ -51,5 +58,5 @@ efi_boot_kernel(u_long marks[MARK_MAX])
 		aarch64_dcache_wbinv_range((u_long)efi_fdt_data(), efi_fdt_size());
 	aarch64_icache_inv_all();
 
-	kernel_entry((register_t)efi_fdt_data(), 0, 0, 0);
+	aarch64_exec_kernel((paddr_t)marks[MARK_ENTRY], (paddr_t)efi_fdt_data());
 }

Reply via email to