[BACK]Return to db_memrw.c CVS log [TXT][DIR] Up to [local] / sys / arch / hp300 / hp300

Annotation of sys/arch/hp300/hp300/db_memrw.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: db_memrw.c,v 1.9 2002/03/14 03:15:52 millert Exp $    */
                      2: /*     $NetBSD: db_memrw.c,v 1.5 1997/06/10 18:48:47 veego Exp $       */
                      3:
                      4: /*-
                      5:  * Copyright (c) 1996 The NetBSD Foundation, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * This code is derived from software contributed to The NetBSD Foundation
                      9:  * by Gordon W. Ross and Jason R. Thorpe.
                     10:  *
                     11:  * Redistribution and use in source and binary forms, with or without
                     12:  * modification, are permitted provided that the following conditions
                     13:  * are met:
                     14:  * 1. Redistributions of source code must retain the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer.
                     16:  * 2. Redistributions in binary form must reproduce the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer in the
                     18:  *    documentation and/or other materials provided with the distribution.
                     19:  * 3. All advertising materials mentioning features or use of this software
                     20:  *    must display the following acknowledgement:
                     21:  *        This product includes software developed by the NetBSD
                     22:  *        Foundation, Inc. and its contributors.
                     23:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     24:  *    contributors may be used to endorse or promote products derived
                     25:  *    from this software without specific prior written permission.
                     26:  *
                     27:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     28:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     29:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     30:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
                     31:  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     32:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     33:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     34:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     35:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     36:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     37:  * POSSIBILITY OF SUCH DAMAGE.
                     38:  */
                     39:
                     40: /*
                     41:  * Interface to the debugger for virtual memory read/write.
                     42:  * This file is shared by DDB and KGDB, and must work even
                     43:  * when only KGDB is included (thus no db_printf calls).
                     44:  *
                     45:  * To write in the text segment, we have to first make
                     46:  * the page writable, do the write, then restore the PTE.
                     47:  * For writes outside the text segment, and all reads,
                     48:  * just do the access -- if it causes a fault, the debugger
                     49:  * will recover with a longjmp to an appropriate place.
                     50:  *
                     51:  * ALERT!  If you want to access device registers with a
                     52:  * specific size, then the read/write functions have to
                     53:  * make sure to do the correct sized pointer access.
                     54:  *
                     55:  * Modified from sun3 version for hp300 (and probably other m68ks, too)
                     56:  * by Jason R. Thorpe <thorpej@NetBSD.ORG>.
                     57:  */
                     58:
                     59: #include <sys/param.h>
                     60: #include <sys/systm.h>
                     61: #include <sys/proc.h>
                     62:
                     63: #include <uvm/uvm_extern.h>
                     64:
                     65: #include <machine/pte.h>
                     66: #include <machine/db_machdep.h>
                     67: #include <machine/cpu.h>
                     68:
                     69: #include <ddb/db_access.h>
                     70:
                     71: static void    db_write_text(db_addr_t, size_t, char *);
                     72:
                     73: /*
                     74:  * Read bytes from kernel address space for debugger.
                     75:  * This used to check for valid PTEs, but now that
                     76:  * traps in DDB work correctly, "Just Do It!"
                     77:  */
                     78: void
                     79: db_read_bytes(addr, size, data)
                     80:        db_addr_t       addr;
                     81:        size_t          size;
                     82:        char            *data;
                     83: {
                     84:        char    *src = (char *)addr;
                     85:
                     86:        if (size == 4) {
                     87:                *((int *)data) = *((int *)src);
                     88:                return;
                     89:        }
                     90:
                     91:        if (size == 2) {
                     92:                *((short *)data) = *((short *)src);
                     93:                return;
                     94:        }
                     95:
                     96:        while (size > 0) {
                     97:                --size;
                     98:                *data++ = *src++;
                     99:        }
                    100: }
                    101:
                    102: /*
                    103:  * Write bytes somewhere in kernel text.
                    104:  * Makes text page writable temporarily.
                    105:  * We're probably a little to cache-paranoid.
                    106:  */
                    107: static void
                    108: db_write_text(addr, size, data)
                    109:        db_addr_t addr;
                    110:        size_t size;
                    111:        char *data;
                    112: {
                    113:        char *dst, *odst;
                    114:        pt_entry_t *pte, oldpte, tmppte;
                    115:        vaddr_t pgva;
                    116:        int limit;
                    117:
                    118:        if (size == 0)
                    119:                return;
                    120:
                    121:        dst = (char *)addr;
                    122:
                    123:        do {
                    124:                /*
                    125:                 * Get the VA for the page.
                    126:                 */
                    127:                pgva = trunc_page((vaddr_t)dst);
                    128:
                    129:                /*
                    130:                 * Save this destination address, for TLB
                    131:                 * flush.
                    132:                 */
                    133:                odst = dst;
                    134:
                    135:                /*
                    136:                 * Compute number of bytes that can be written
                    137:                 * with this mapping and subtract it from the
                    138:                 * total size.
                    139:                 */
                    140:                limit = NBPG - ((u_long)dst & PGOFSET);
                    141:                if (limit > size)
                    142:                        limit = size;
                    143:                size -= limit;
                    144:
                    145: #ifdef M68K_MMU_HP
                    146:                /*
                    147:                 * Flush the supervisor side of the VAC to
                    148:                 * prevent a cache hit on the old, read-only PTE.
                    149:                 * XXX Is this really necessary, or am I just
                    150:                 * paranoid?
                    151:                 */
                    152:                if (ectype == EC_VIRT)
                    153:                        DCIS();
                    154: #endif
                    155:
                    156:                /*
                    157:                 * Make the page writable.  Note the mapping is
                    158:                 * cache-inhibited to save hair.
                    159:                 */
                    160:                pte = kvtopte(pgva);
                    161:                oldpte = *pte;
                    162:
                    163:                if ((oldpte & PG_V) == 0) {
                    164:                        printf(" address %p not a valid page\n", dst);
                    165:                        return;
                    166:                }
                    167:
                    168:                tmppte = (oldpte & ~PG_RO) | PG_RW | PG_CI;
                    169:                *pte = tmppte;
                    170:                TBIS((vaddr_t)odst);
                    171:
                    172:                /*
                    173:                 * Page is now writable.  Do as much access as we
                    174:                 * can in this page.
                    175:                 */
                    176:                for (; limit > 0; limit--)
                    177:                        *dst++ = *data++;
                    178:
                    179:                /*
                    180:                 * Restore the old PTE.
                    181:                 */
                    182:                *pte = oldpte;
                    183:                TBIS((vaddr_t)odst);
                    184:        } while (size != 0);
                    185:
                    186:        /*
                    187:         * Invalidate the instruction cache so our changes
                    188:         * take effect.
                    189:         */
                    190:        ICIA();
                    191: }
                    192:
                    193: /*
                    194:  * Write bytes to kernel address space for debugger.
                    195:  */
                    196: extern char    kernel_text[], etext[];
                    197: void
                    198: db_write_bytes(addr, size, data)
                    199:        db_addr_t       addr;
                    200:        size_t  size;
                    201:        char    *data;
                    202: {
                    203:        char    *dst = (char *)addr;
                    204:
                    205:        /* If any part is in kernel text, use db_write_text() */
                    206:        if ((dst < etext) && ((dst + size) > kernel_text)) {
                    207:                db_write_text(addr, size, data);
                    208:                return;
                    209:        }
                    210:
                    211:        if (size == 4) {
                    212:                *((int *)dst) = *((int *)data);
                    213:                return;
                    214:        }
                    215:
                    216:        if (size == 2) {
                    217:                *((short *)dst) = *((short *)data);
                    218:                return;
                    219:        }
                    220:
                    221:        while (size > 0) {
                    222:                --size;
                    223:                *dst++ = *data++;
                    224:        }
                    225: }

CVSweb