Sat Jan 3 07:11:02 2009 UTC ()
Sync with an update on amiga:
Rewrite a weird calculation marked "XXX fix calcurations XXX"
for an index value of lev2 segment table for the kernel Sysptmap
with more meaningful expressions and PAGE_SIZE independent macro.
Also use "~0" rather than "-1" for an unsigned bitmap value.

Should produce the same results and no functional change.

Tested on Falcon with 68060 by Tuomo Makinen.


(tsutsui)
diff -r1.70 -r1.71 src/sys/arch/atari/atari/atari_init.c

cvs diff -r1.70 -r1.71 src/sys/arch/atari/atari/atari_init.c (expand / switch to unified diff)

--- src/sys/arch/atari/atari/atari_init.c 2009/01/02 04:38:09 1.70
+++ src/sys/arch/atari/atari/atari_init.c 2009/01/03 07:11:02 1.71
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: atari_init.c,v 1.70 2009/01/02 04:38:09 tsutsui Exp $ */ 1/* $NetBSD: atari_init.c,v 1.71 2009/01/03 07:11:02 tsutsui Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1995 Leo Weppelman 4 * Copyright (c) 1995 Leo Weppelman
5 * Copyright (c) 1994 Michael L. Hitch 5 * Copyright (c) 1994 Michael L. Hitch
6 * Copyright (c) 1993 Markus Wild 6 * Copyright (c) 1993 Markus Wild
7 * All rights reserved. 7 * All rights reserved.
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
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: atari_init.c,v 1.70 2009/01/02 04:38:09 tsutsui Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: atari_init.c,v 1.71 2009/01/03 07:11:02 tsutsui Exp $");
37 37
38#include "opt_ddb.h" 38#include "opt_ddb.h"
39#include "opt_mbtype.h" 39#include "opt_mbtype.h"
40#include "opt_m060sp.h" 40#include "opt_m060sp.h"
41 41
42#include <sys/param.h> 42#include <sys/param.h>
43#include <sys/systm.h> 43#include <sys/systm.h>
44#include <sys/proc.h> 44#include <sys/proc.h>
45#include <sys/user.h> 45#include <sys/user.h>
46#include <sys/ioctl.h> 46#include <sys/ioctl.h>
47#include <sys/select.h> 47#include <sys/select.h>
48#include <sys/tty.h> 48#include <sys/tty.h>
49#include <sys/buf.h> 49#include <sys/buf.h>
@@ -971,94 +971,95 @@ mmu030_setup(sysseg_pa, kstsize, ptpa, p @@ -971,94 +971,95 @@ mmu030_setup(sysseg_pa, kstsize, ptpa, p
971 *pg = (sysptmap_pa + kbase) /* relocated PA */ | PG_RW | PG_CI | PG_V; 971 *pg = (sysptmap_pa + kbase) /* relocated PA */ | PG_RW | PG_CI | PG_V;
972} 972}
973 973
974#if defined(M68040) || defined(M68060) 974#if defined(M68040) || defined(M68060)
975void 975void
976mmu040_setup(sysseg_pa, kstsize, ptpa, ptsize, sysptmap_pa, kbase) 976mmu040_setup(sysseg_pa, kstsize, ptpa, ptsize, sysptmap_pa, kbase)
977 paddr_t sysseg_pa; /* System segment table */ 977 paddr_t sysseg_pa; /* System segment table */
978 u_int kstsize; /* size of 'sysseg' in pages */ 978 u_int kstsize; /* size of 'sysseg' in pages */
979 paddr_t ptpa; /* Kernel page table */ 979 paddr_t ptpa; /* Kernel page table */
980 psize_t ptsize; /* size of 'pt' in bytes */ 980 psize_t ptsize; /* size of 'pt' in bytes */
981 paddr_t sysptmap_pa; /* System page table */ 981 paddr_t sysptmap_pa; /* System page table */
982 paddr_t kbase; 982 paddr_t kbase;
983{ 983{
984 int i; 984 int nl1desc, nl2desc, i;
985 st_entry_t sg_proto, *sg, *esg; 985 st_entry_t sg_proto, *sg, *esg;
986 pt_entry_t pg_proto, *pg, *epg; 986 pt_entry_t pg_proto, *pg, *epg;
987 987
988 /* 988 /*
989 * First invalidate the entire "segment table" pages 989 * First invalidate the entire "segment table" pages
990 * (levels 1 and 2 have the same "invalid" values). 990 * (levels 1 and 2 have the same "invalid" values).
991 */ 991 */
992 sg = (st_entry_t *)sysseg_pa; 992 sg = (st_entry_t *)sysseg_pa;
993 esg = &sg[kstsize * NPTEPG]; 993 esg = &sg[kstsize * NPTEPG];
994 while (sg < esg) 994 while (sg < esg)
995 *sg++ = SG_NV; 995 *sg++ = SG_NV;
996 996
997 /* 997 /*
998 * Initialize level 2 descriptors (which immediately 998 * Initialize level 2 descriptors (which immediately
999 * follow the level 1 table). 999 * follow the level 1 table).
1000 * We need: 1000 * We need:
1001 * NPTEPG / SG4_LEV3SIZE 1001 * NPTEPG / SG4_LEV3SIZE
1002 * level 2 descriptors to map each of the nptpages 1002 * level 2 descriptors to map each of the nptpages
1003 * pages of PTEs. Note that we set the "used" bit 1003 * pages of PTEs. Note that we set the "used" bit
1004 * now to save the HW the expense of doing it. 1004 * now to save the HW the expense of doing it.
1005 */ 1005 */
1006 i = (ptsize >> PGSHIFT) * (NPTEPG / SG4_LEV3SIZE); 1006 nl2desc = (ptsize >> PGSHIFT) * (NPTEPG / SG4_LEV3SIZE);
1007 sg = (st_entry_t *)sysseg_pa; 1007 sg = (st_entry_t *)sysseg_pa;
1008 sg = &sg[SG4_LEV1SIZE]; 1008 sg = &sg[SG4_LEV1SIZE];
1009 esg = &sg[i]; 1009 esg = &sg[nl2desc];
1010 sg_proto = (ptpa + kbase) /* relocated PA */ | SG_U | SG_RW | SG_V; 1010 sg_proto = (ptpa + kbase) /* relocated PA */ | SG_U | SG_RW | SG_V;
1011 while (sg < esg) { 1011 while (sg < esg) {
1012 *sg++ = sg_proto; 1012 *sg++ = sg_proto;
1013 sg_proto += (SG4_LEV3SIZE * sizeof(st_entry_t)); 1013 sg_proto += (SG4_LEV3SIZE * sizeof(st_entry_t));
1014 } 1014 }
1015 1015
1016 /* 1016 /*
1017 * Initialize level 1 descriptors. We need: 1017 * Initialize level 1 descriptors. We need:
1018 * roundup(num, SG4_LEV2SIZE) / SG4_LEVEL2SIZE 1018 * roundup(nl2desc, SG4_LEV2SIZE) / SG4_LEVEL2SIZE
1019 * level 1 descriptors to map the 'num' level 2's. 1019 * level 1 descriptors to map the 'nl2desc' level 2's.
1020 */ 1020 */
1021 i = roundup(i, SG4_LEV2SIZE) / SG4_LEV2SIZE; 1021 nl1desc = roundup(nl2desc, SG4_LEV2SIZE) / SG4_LEV2SIZE;
1022 protostfree = (-1 << (i + 2)) /* & ~(-1 << MAXKL2SIZE) */; 
1023 sg = (st_entry_t *)sysseg_pa; 1022 sg = (st_entry_t *)sysseg_pa;
1024 esg = &sg[i]; 1023 esg = &sg[nl1desc];
1025 sg_proto = ((paddr_t)&sg[SG4_LEV1SIZE] + kbase) /* relocated PA */ 1024 sg_proto = ((paddr_t)&sg[SG4_LEV1SIZE] + kbase) /* relocated PA */
1026 | SG_U | SG_RW | SG_V; 1025 | SG_U | SG_RW | SG_V;
1027 while (sg < esg) { 1026 while (sg < esg) {
1028 *sg++ = sg_proto; 1027 *sg++ = sg_proto;
1029 sg_proto += (SG4_LEV2SIZE * sizeof(st_entry_t)); 1028 sg_proto += (SG4_LEV2SIZE * sizeof(st_entry_t));
1030 } 1029 }
1031 1030
1032 /* Sysmap is last entry in level 1 */ 1031 /* Sysmap is last entry in level 1 */
1033 sg = (st_entry_t *)sysseg_pa; 1032 sg = (st_entry_t *)sysseg_pa;
1034 sg = &sg[SG4_LEV1SIZE - 1]; 1033 sg = &sg[SG4_LEV1SIZE - 1];
1035 *sg = sg_proto; 1034 *sg = sg_proto;
1036 1035
1037 /* 1036 /*
1038 * Kernel segment table at end of next level 2 table 1037 * Kernel segment table at end of next level 2 table
1039 */ 1038 */
1040 /* XXX fix calculations XXX */ 1039 i = SG4_LEV1SIZE + (nl1desc * SG4_LEV2SIZE);
1041 i = ((((ptsize >> PGSHIFT) + 3) & -2) - 1) * (NPTEPG / SG4_LEV3SIZE); 
1042 sg = (st_entry_t *)sysseg_pa; 1040 sg = (st_entry_t *)sysseg_pa;
1043 sg = &sg[SG4_LEV1SIZE + i]; 1041 sg = &sg[i + SG4_LEV2SIZE - (NPTEPG / SG4_LEV3SIZE)];
1044 esg = &sg[NPTEPG / SG4_LEV3SIZE]; 1042 esg = &sg[NPTEPG / SG4_LEV3SIZE];
1045 sg_proto = (sysptmap_pa + kbase) /* relocated PA */ 1043 sg_proto = (sysptmap_pa + kbase) /* relocated PA */
1046 | SG_U | SG_RW | SG_V; 1044 | SG_U | SG_RW | SG_V;
1047 while (sg < esg) { 1045 while (sg < esg) {
1048 *sg++ = sg_proto; 1046 *sg++ = sg_proto;
1049 sg_proto += (SG4_LEV3SIZE * sizeof(st_entry_t)); 1047 sg_proto += (SG4_LEV3SIZE * sizeof(st_entry_t));
1050 } 1048 }
1051 1049
 1050 /* Include additional level 2 table for Sysmap in protostfree */
 1051 protostfree = (~0 << (1 + nl1desc + 1)) /* & ~(~0 << MAXKL2SIZE) */;
 1052
1052 /* 1053 /*
1053 * Initialize Sysptmap 1054 * Initialize Sysptmap
1054 */ 1055 */
1055 pg = (pt_entry_t *)sysptmap_pa; 1056 pg = (pt_entry_t *)sysptmap_pa;
1056 epg = &pg[ptsize >> PGSHIFT]; 1057 epg = &pg[ptsize >> PGSHIFT];
1057 pg_proto = (ptpa + kbase) /* relocated PA */ | PG_RW | PG_CI | PG_V; 1058 pg_proto = (ptpa + kbase) /* relocated PA */ | PG_RW | PG_CI | PG_V;
1058 while (pg < epg) { 1059 while (pg < epg) {
1059 *pg++ = pg_proto; 1060 *pg++ = pg_proto;
1060 pg_proto += PAGE_SIZE; 1061 pg_proto += PAGE_SIZE;
1061 } 1062 }
1062 1063
1063 /* 1064 /*
1064 * Invalidate rest of Sysptmap page. 1065 * Invalidate rest of Sysptmap page.