diff --git a/sys/arch/amd64/amd64/locore.S b/sys/arch/amd64/amd64/locore.S index ac02991c9b19..54f9f17deba4 100644 --- a/sys/arch/amd64/amd64/locore.S +++ b/sys/arch/amd64/amd64/locore.S @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.87 2016/05/12 06:45:16 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.88 2016/05/12 07:21:18 maxv Exp $ */ /* * Copyright-o-rama! @@ -564,6 +564,8 @@ no_NOX: * * (PROC0 STK + L4 + L3 + L2 + L1) is later referred to as BOOTSTRAP TABLES. * + * Important note: the kernel segments are properly 4k-aligned + * (see kern.ldscript), so there's no need to enforce alignment. */ /* Find end of kernel image; brings us on (1). */ @@ -616,16 +618,16 @@ no_NOX: shrl $(PGSHIFT-3),%ecx /* ((n >> PGSHIFT) << 3) for # PDEs */ addl %ecx,%ebx - /* - * Compute &__rodata_start - KERNBASE. This can't be > 4G, or we can't - * deal with it anyway, since we can't load it in 32 bit mode. So use - * the bottom 32 bits. - */ - movl $RELOC(__rodata_start),%edx - andl $~PGOFSET,%edx + /* Map the kernel text RX. */ + movl $RELOC(__rodata_start),%ecx + subl %eax,%ecx + shrl $PGSHIFT,%ecx + orl $(PG_V|PG_KR),%eax + fillkpt - /* Map the kernel text read-only. */ - movl %edx,%ecx + /* Map the kernel rodata ROX. */ + movl $RELOC(__rodata_start),%eax + movl $RELOC(__data_start),%ecx subl %eax,%ecx shrl $PGSHIFT,%ecx orl $(PG_V|PG_KR),%eax @@ -639,11 +641,12 @@ no_NOX: * +--------+----------+-------------------+------------------+ * We just map everything from < to > with RWX rights. */ - leal (PG_V|PG_KW)(%edx),%eax - movl $TABLESIZE,%ecx - addl %esi,%ecx /* end of tables */ - subl %edx,%ecx /* subtract end of text */ + movl $RELOC(__data_start),%eax + movl %esi,%ecx /* start of BOOTSTRAP TABLES */ + addl $TABLESIZE,%ecx /* end of BOOTSTRAP TABLES */ + subl %eax,%ecx /* subtract start of DATA */ shrl $PGSHIFT,%ecx + orl $(PG_V|PG_KW),%eax fillkpt /* We are on (4). Map ISA I/O mem (later atdevbase) RWX. */ diff --git a/sys/arch/amd64/conf/kern.ldscript b/sys/arch/amd64/conf/kern.ldscript index b2c11a4e19f5..59c95426fac2 100644 --- a/sys/arch/amd64/conf/kern.ldscript +++ b/sys/arch/amd64/conf/kern.ldscript @@ -1,4 +1,4 @@ -/* $NetBSD: kern.ldscript,v 1.19 2016/05/12 06:45:16 maxv Exp $ */ +/* $NetBSD: kern.ldscript,v 1.20 2016/05/12 07:21:18 maxv Exp $ */ #include "assym.h" @@ -36,6 +36,8 @@ SECTIONS *(.rodata.*) } + . = ALIGN(__PAGE_SIZE); + __data_start = . ; .data : {