Tue May 12 07:07:16 2015 UTC ()
Add some KASSERTs to catch similar bugs to the cnptes/nptes one


(skrll)
diff -r1.138 -r1.139 src/sys/arch/arm/include/arm32/pmap.h

cvs diff -r1.138 -r1.139 src/sys/arch/arm/include/arm32/pmap.h (expand / switch to unified diff)

--- src/sys/arch/arm/include/arm32/pmap.h 2015/02/25 13:52:42 1.138
+++ src/sys/arch/arm/include/arm32/pmap.h 2015/05/12 07:07:16 1.139
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.h,v 1.138 2015/02/25 13:52:42 joerg Exp $ */ 1/* $NetBSD: pmap.h,v 1.139 2015/05/12 07:07:16 skrll Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2002, 2003 Wasabi Systems, Inc. 4 * Copyright (c) 2002, 2003 Wasabi Systems, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Jason R. Thorpe & Steve C. Woodford for Wasabi Systems, Inc. 7 * Written by Jason R. Thorpe & Steve C. Woodford for Wasabi Systems, Inc.
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
@@ -557,43 +557,46 @@ l1pte_set(pt_entry_t *pdep, pt_entry_t p @@ -557,43 +557,46 @@ l1pte_set(pt_entry_t *pdep, pt_entry_t p
557 557
558#define l2pte_index(v) ((((v) & L2_ADDR_BITS) >> PGSHIFT) << (PGSHIFT-L2_S_SHIFT)) 558#define l2pte_index(v) ((((v) & L2_ADDR_BITS) >> PGSHIFT) << (PGSHIFT-L2_S_SHIFT))
559#define l2pte_valid_p(pte) (((pte) & L2_TYPE_MASK) != L2_TYPE_INV) 559#define l2pte_valid_p(pte) (((pte) & L2_TYPE_MASK) != L2_TYPE_INV)
560#define l2pte_pa(pte) ((pte) & L2_S_FRAME) 560#define l2pte_pa(pte) ((pte) & L2_S_FRAME)
561#define l1pte_lpage_p(pte) (((pte) & L2_TYPE_MASK) == L2_TYPE_L) 561#define l1pte_lpage_p(pte) (((pte) & L2_TYPE_MASK) == L2_TYPE_L)
562#define l2pte_minidata_p(pte) (((pte) & \ 562#define l2pte_minidata_p(pte) (((pte) & \
563 (L2_B | L2_C | L2_XS_T_TEX(TEX_XSCALE_X)))\ 563 (L2_B | L2_C | L2_XS_T_TEX(TEX_XSCALE_X)))\
564 == (L2_C | L2_XS_T_TEX(TEX_XSCALE_X))) 564 == (L2_C | L2_XS_T_TEX(TEX_XSCALE_X)))
565 565
566static inline void 566static inline void
567l2pte_set(pt_entry_t *ptep, pt_entry_t pte, pt_entry_t opte) 567l2pte_set(pt_entry_t *ptep, pt_entry_t pte, pt_entry_t opte)
568{ 568{
569 if (l1pte_lpage_p(pte)) { 569 if (l1pte_lpage_p(pte)) {
 570 KASSERTMSG((((uintptr_t)ptep / sizeof(pte)) & (L2_L_SIZE / L2_S_SIZE - 1)) == 0, "%p", ptep);
570 for (size_t k = 0; k < L2_L_SIZE / L2_S_SIZE; k++) { 571 for (size_t k = 0; k < L2_L_SIZE / L2_S_SIZE; k++) {
571 *ptep++ = pte; 572 *ptep++ = pte;
572 } 573 }
573 } else { 574 } else {
 575 KASSERTMSG((((uintptr_t)ptep / sizeof(pte)) & (PAGE_SIZE / L2_S_SIZE - 1)) == 0, "%p", ptep);
574 for (size_t k = 0; k < PAGE_SIZE / L2_S_SIZE; k++) { 576 for (size_t k = 0; k < PAGE_SIZE / L2_S_SIZE; k++) {
575 KASSERTMSG(*ptep == opte, "%#x [*%p] != %#x", *ptep, ptep, opte); 577 KASSERTMSG(*ptep == opte, "%#x [*%p] != %#x", *ptep, ptep, opte);
576 *ptep++ = pte; 578 *ptep++ = pte;
577 pte += L2_S_SIZE; 579 pte += L2_S_SIZE;
578 if (opte) 580 if (opte)
579 opte += L2_S_SIZE; 581 opte += L2_S_SIZE;
580 } 582 }
581 } 583 }
582} 584}
583 585
584static inline void 586static inline void
585l2pte_reset(pt_entry_t *ptep) 587l2pte_reset(pt_entry_t *ptep)
586{ 588{
 589 KASSERTMSG((((uintptr_t)ptep / sizeof(*ptep)) & (PAGE_SIZE / L2_S_SIZE - 1)) == 0, "%p", ptep);
587 *ptep = 0; 590 *ptep = 0;
588 for (vsize_t k = 1; k < PAGE_SIZE / L2_S_SIZE; k++) { 591 for (vsize_t k = 1; k < PAGE_SIZE / L2_S_SIZE; k++) {
589 ptep[k] = 0; 592 ptep[k] = 0;
590 } 593 }
591} 594}
592 595
593/* L1 and L2 page table macros */ 596/* L1 and L2 page table macros */
594#define pmap_pde_v(pde) l1pte_valid(*(pde)) 597#define pmap_pde_v(pde) l1pte_valid(*(pde))
595#define pmap_pde_section(pde) l1pte_section_p(*(pde)) 598#define pmap_pde_section(pde) l1pte_section_p(*(pde))
596#define pmap_pde_supersection(pde) l1pte_supersection_p(*(pde)) 599#define pmap_pde_supersection(pde) l1pte_supersection_p(*(pde))
597#define pmap_pde_page(pde) l1pte_page_p(*(pde)) 600#define pmap_pde_page(pde) l1pte_page_p(*(pde))
598#define pmap_pde_fpage(pde) l1pte_fpage_p(*(pde)) 601#define pmap_pde_fpage(pde) l1pte_fpage_p(*(pde))
599 602