Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Modify the layout of the bootspace structure, in su...
details: https://anonhg.NetBSD.org/src/rev/74123e81d12c
branches: trunk
changeset: 357448:74123e81d12c
user: maxv <maxv%NetBSD.org@localhost>
date: Sat Nov 11 12:51:05 2017 +0000
description:
Modify the layout of the bootspace structure, in such a way that it can
contain several kernel segments of the same type (eg several .text
segments). Some parts are still a bit messy but will be cleaned up soon.
I cannot compile-test this change on i386, but it seems fine enough.
NOTE: you need to rebuild and reinstall a new prekern after this change.
diffstat:
sys/arch/amd64/amd64/machdep.c | 60 ++++++++----------
sys/arch/amd64/stand/prekern/mm.c | 73 +++++++++++++++++-----
sys/arch/amd64/stand/prekern/prekern.h | 20 ++---
sys/arch/i386/i386/machdep.c | 29 +++++---
sys/arch/x86/include/pmap.h | 21 ++---
sys/arch/x86/x86/db_memrw.c | 24 ++++---
sys/arch/x86/x86/pmap.c | 106 +++++++++++++++++---------------
7 files changed, 185 insertions(+), 148 deletions(-)
diffs (truncated from 582 to 300 lines):
diff -r 4be391629ee4 -r 74123e81d12c sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c Sat Nov 11 11:00:46 2017 +0000
+++ b/sys/arch/amd64/amd64/machdep.c Sat Nov 11 12:51:05 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.275 2017/11/04 08:50:47 cherry Exp $ */
+/* $NetBSD: machdep.c,v 1.276 2017/11/11 12:51:06 maxv Exp $ */
/*
* Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.275 2017/11/04 08:50:47 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.276 2017/11/11 12:51:06 maxv Exp $");
/* #define XENDEBUG_LOW */
@@ -1507,6 +1507,7 @@
extern char __rodata_start;
extern char __data_start;
extern char __kernel_end;
+ size_t i = 0;
memset(&bootspace, 0, sizeof(bootspace));
@@ -1514,17 +1515,23 @@
bootspace.head.pa = KERNTEXTOFF - KERNBASE;
bootspace.head.sz = 0;
- bootspace.text.va = KERNTEXTOFF;
- bootspace.text.pa = KERNTEXTOFF - KERNBASE;
- bootspace.text.sz = (size_t)&__rodata_start - KERNTEXTOFF;
+ bootspace.segs[i].type = BTSEG_TEXT;
+ bootspace.segs[i].va = KERNTEXTOFF;
+ bootspace.segs[i].pa = KERNTEXTOFF - KERNBASE;
+ bootspace.segs[i].sz = (size_t)&__rodata_start - KERNTEXTOFF;
+ i++;
- bootspace.rodata.va = (vaddr_t)&__rodata_start;
- bootspace.rodata.pa = (paddr_t)&__rodata_start - KERNBASE;
- bootspace.rodata.sz = (size_t)&__data_start - (size_t)&__rodata_start;
+ bootspace.segs[i].type = BTSEG_RODATA;
+ bootspace.segs[i].va = (vaddr_t)&__rodata_start;
+ bootspace.segs[i].pa = (paddr_t)&__rodata_start - KERNBASE;
+ bootspace.segs[i].sz = (size_t)&__data_start - (size_t)&__rodata_start;
+ i++;
- bootspace.data.va = (vaddr_t)&__data_start;
- bootspace.data.pa = (paddr_t)&__data_start - KERNBASE;
- bootspace.data.sz = (size_t)&__kernel_end - (size_t)&__data_start;
+ bootspace.segs[i].type = BTSEG_DATA;
+ bootspace.segs[i].va = (vaddr_t)&__data_start;
+ bootspace.segs[i].pa = (paddr_t)&__data_start - KERNBASE;
+ bootspace.segs[i].sz = (size_t)&__kernel_end - (size_t)&__data_start;
+ i++;
bootspace.boot.va = (vaddr_t)&__kernel_end;
bootspace.boot.pa = (paddr_t)&__kernel_end - KERNBASE;
@@ -2009,6 +2016,7 @@
{
const vaddr_t v = (vaddr_t)ptr;
vaddr_t kva, kva_end;
+ size_t i;
kva = bootspace.head.va;
kva_end = kva + bootspace.head.sz;
@@ -2017,33 +2025,19 @@
return 0;
}
- kva = bootspace.text.va;
- kva_end = kva + bootspace.text.sz;
- if (v >= kva && v < kva_end) {
+ for (i = 0; i < BTSPACE_NSEGS; i++) {
+ kva = bootspace.segs[i].va;
+ kva_end = kva + bootspace.segs[i].sz;
*handled = true;
- if (prot & VM_PROT_WRITE) {
- return EFAULT;
+ if (bootspace.segs[i].type == BTSEG_TEXT ||
+ bootspace.segs[i].type == BTSEG_RODATA) {
+ if (prot & VM_PROT_WRITE) {
+ return EFAULT;
+ }
}
return 0;
}
- kva = bootspace.rodata.va;
- kva_end = kva + bootspace.rodata.sz;
- if (v >= kva && v < kva_end) {
- *handled = true;
- if (prot & VM_PROT_WRITE) {
- return EFAULT;
- }
- return 0;
- }
-
- kva = bootspace.data.va;
- kva_end = kva + bootspace.data.sz;
- if (v >= kva && v < kva_end) {
- *handled = true;
- return 0;
- }
-
kva = bootspace.boot.va;
kva_end = kva + bootspace.boot.sz;
if (v >= kva && v < kva_end) {
diff -r 4be391629ee4 -r 74123e81d12c sys/arch/amd64/stand/prekern/mm.c
--- a/sys/arch/amd64/stand/prekern/mm.c Sat Nov 11 11:00:46 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/mm.c Sat Nov 11 12:51:05 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mm.c,v 1.9 2017/11/09 15:24:39 maxv Exp $ */
+/* $NetBSD: mm.c,v 1.10 2017/11/11 12:51:06 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -121,13 +121,20 @@
void
mm_bootspace_mprotect()
{
- /*
- * Remap the kernel segments with proper permissions.
- */
- mm_mprotect(bootspace.text.va, bootspace.text.sz,
- MM_PROT_READ|MM_PROT_EXECUTE);
- mm_mprotect(bootspace.rodata.va, bootspace.rodata.sz,
- MM_PROT_READ);
+ int prot;
+ size_t i;
+
+ /* Remap the kernel segments with proper permissions. */
+ for (i = 0; i < BTSPACE_NSEGS; i++) {
+ if (bootspace.segs[i].type == BTSEG_TEXT) {
+ prot = MM_PROT_READ|MM_PROT_EXECUTE;
+ } else if (bootspace.segs[i].type == BTSEG_RODATA) {
+ prot = MM_PROT_READ;
+ } else {
+ continue;
+ }
+ mm_mprotect(bootspace.segs[i].va, bootspace.segs[i].sz, prot);
+ }
print_state(true, "Segments protection updated");
}
@@ -276,6 +283,42 @@
return randva;
}
+static paddr_t
+bootspace_getend()
+{
+ paddr_t pa, max = 0;
+ size_t i;
+
+ for (i = 0; i < BTSPACE_NSEGS; i++) {
+ if (bootspace.segs[i].type == BTSEG_NONE) {
+ continue;
+ }
+ pa = bootspace.segs[i].pa + bootspace.segs[i].sz;
+ if (pa > max)
+ max = pa;
+ }
+
+ return max;
+}
+
+static void
+bootspace_addseg(int type, vaddr_t va, paddr_t pa, size_t sz)
+{
+ size_t i;
+
+ for (i = 0; i < BTSPACE_NSEGS; i++) {
+ if (bootspace.segs[i].type == BTSEG_NONE) {
+ bootspace.segs[i].type = type;
+ bootspace.segs[i].va = va;
+ bootspace.segs[i].pa = pa;
+ bootspace.segs[i].sz = sz;
+ return;
+ }
+ }
+
+ fatal("bootspace_addseg: segments full");
+}
+
static void
mm_map_segments()
{
@@ -302,9 +345,7 @@
memset((void *)(randva + elfsz), PAD_TEXT, size - elfsz);
/* Register the values in bootspace */
- bootspace.text.va = randva;
- bootspace.text.pa = pa;
- bootspace.text.sz = size;
+ bootspace_addseg(BTSEG_TEXT, randva, pa, size);
/*
* Kernel rodata segment.
@@ -325,9 +366,7 @@
memset((void *)(randva + elfsz), PAD_RODATA, size - elfsz);
/* Register the values in bootspace */
- bootspace.rodata.va = randva;
- bootspace.rodata.pa = pa;
- bootspace.rodata.sz = size;
+ bootspace_addseg(BTSEG_RODATA, randva, pa, size);
/*
* Kernel data segment.
@@ -348,9 +387,7 @@
memset((void *)(randva + elfsz), PAD_DATA, size - elfsz);
/* Register the values in bootspace */
- bootspace.data.va = randva;
- bootspace.data.pa = pa;
- bootspace.data.sz = size;
+ bootspace_addseg(BTSEG_DATA, randva, pa, size);
}
static void
@@ -370,7 +407,7 @@
randva = mm_randva_kregion(size);
/* Enter the area and build the ELF info */
- bootpa = bootspace.data.pa + bootspace.data.sz;
+ bootpa = bootspace_getend();
size = (pa_avail - bootpa);
npages = size / PAGE_SIZE;
for (i = 0; i < npages; i++) {
diff -r 4be391629ee4 -r 74123e81d12c sys/arch/amd64/stand/prekern/prekern.h
--- a/sys/arch/amd64/stand/prekern/prekern.h Sat Nov 11 11:00:46 2017 +0000
+++ b/sys/arch/amd64/stand/prekern/prekern.h Sat Nov 11 12:51:05 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: prekern.h,v 1.8 2017/11/10 08:52:57 maxv Exp $ */
+/* $NetBSD: prekern.h,v 1.9 2017/11/11 12:51:06 maxv Exp $ */
/*
* Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -102,6 +102,11 @@
/* -------------------------------------------------------------------------- */
+#define BTSEG_NONE 0
+#define BTSEG_TEXT 1
+#define BTSEG_RODATA 2
+#define BTSEG_DATA 3
+#define BTSPACE_NSEGS 64
struct bootspace {
struct {
vaddr_t va;
@@ -109,20 +114,11 @@
size_t sz;
} head;
struct {
+ int type;
vaddr_t va;
paddr_t pa;
size_t sz;
- } text;
- struct {
- vaddr_t va;
- paddr_t pa;
- size_t sz;
- } rodata;
- struct {
- vaddr_t va;
- paddr_t pa;
- size_t sz;
- } data;
+ } segs[BTSPACE_NSEGS];
struct {
vaddr_t va;
paddr_t pa;
diff -r 4be391629ee4 -r 74123e81d12c sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c Sat Nov 11 11:00:46 2017 +0000
+++ b/sys/arch/i386/i386/machdep.c Sat Nov 11 12:51:05 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.798 2017/11/04 08:50:47 cherry Exp $ */
+/* $NetBSD: machdep.c,v 1.799 2017/11/11 12:51:06 maxv Exp $ */
/*
* Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.798 2017/11/04 08:50:47 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.799 2017/11/11 12:51:06 maxv Exp $");
#include "opt_beep.h"
#include "opt_compat_freebsd.h"
@@ -1102,6 +1102,7 @@
extern char __rodata_start;
extern char __data_start;
extern char __kernel_end;
+ size_t i = 0;
memset(&bootspace, 0, sizeof(bootspace));
Home |
Main Index |
Thread Index |
Old Index