The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/ddb/db_access.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: db_access.c,v 1.26 2019/09/12 17:09:00 ryo Exp $       */
    2 
    3 /*
    4  * Mach Operating System
    5  * Copyright (c) 1991,1990 Carnegie Mellon University
    6  * All Rights Reserved.
    7  *
    8  * Permission to use, copy, modify and distribute this software and its
    9  * documentation is hereby granted, provided that both the copyright
   10  * notice and this permission notice appear in all copies of the
   11  * software, derivative works or modified versions, and any portions
   12  * thereof, and that both notices appear in supporting documentation.
   13  *
   14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   16  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   17  *
   18  * Carnegie Mellon requests users of this software to return to
   19  *
   20  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   21  *  School of Computer Science
   22  *  Carnegie Mellon University
   23  *  Pittsburgh PA 15213-3890
   24  *
   25  * any improvements or extensions that they make and grant Carnegie the
   26  * rights to redistribute these changes.
   27  *
   28  *      Author: David B. Golub, Carnegie Mellon University
   29  *      Date:   7/90
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __KERNEL_RCSID(0, "$NetBSD: db_access.c,v 1.26 2019/09/12 17:09:00 ryo Exp $");
   34 
   35 #if defined(_KERNEL_OPT)
   36 #include "opt_kgdb.h"
   37 #endif
   38 
   39 #include <sys/param.h>
   40 #include <sys/proc.h>
   41 #include <sys/endian.h>
   42 
   43 #include <ddb/ddb.h>
   44 
   45 /*
   46  * Access unaligned data items on aligned (longword)
   47  * boundaries.
   48  *
   49  * This file is shared by ddb, kgdb and crash(8).
   50  */
   51 
   52 #if defined(DDB) || !defined(DDB) && !defined(KGDB)
   53 #define _COMPILE_THIS
   54 #endif
   55 
   56 #if defined(_COMPILE_THIS) || defined(KGDB) && defined(SOFTWARE_SSTEP)
   57 
   58 db_expr_t
   59 db_get_value(db_addr_t addr, size_t size, bool is_signed)
   60 {
   61         char data[sizeof(db_expr_t)] __aligned(sizeof(db_expr_t));
   62         uintmax_t uvalue;
   63         db_expr_t value;
   64         size_t i;
   65 
   66         db_read_bytes(addr, size, data);
   67 
   68         uvalue = 0;
   69 #if BYTE_ORDER == LITTLE_ENDIAN
   70         for (i = size; i-- > 0;)
   71 #else /* BYTE_ORDER == BIG_ENDIAN */
   72         for (i = 0; i < size; i++)
   73 #endif /* BYTE_ORDER */
   74                 uvalue = (uvalue << 8) + (data[i] & 0xFF);
   75 
   76         value = (db_expr_t)uvalue;
   77 
   78         if (size < sizeof(db_expr_t) && is_signed
   79             && (value & ((db_expr_t)1 << (8*size - 1)))) {
   80                 value |= (unsigned long)~(db_expr_t)0 << (8*size - 1);
   81         }
   82         return (value);
   83 }
   84 
   85 quad_t
   86 db_get_qvalue(db_addr_t addr, size_t size, bool is_signed)
   87 {
   88         uint64_t data;
   89 
   90         if (size < sizeof(uint64_t)) {
   91                 if (is_signed)
   92                         return db_get_value(addr, size, true);
   93                 return (uint32_t)db_get_value(addr, size, false);
   94         }
   95 
   96         if (size != sizeof(data)) {
   97                 db_error("unnsupported size\n");
   98                 /*NOTREACHED*/
   99         }
  100 
  101         db_read_bytes(addr, sizeof(data), (char *)&data);
  102         return data;
  103 }
  104 
  105 void
  106 db_put_value(db_addr_t addr, size_t size, db_expr_t value)
  107 {
  108         char data[sizeof(db_expr_t)] __aligned(sizeof(db_expr_t));
  109         size_t i;
  110 
  111 #if BYTE_ORDER == LITTLE_ENDIAN
  112         for (i = 0; i < size; i++)
  113 #else /* BYTE_ORDER == BIG_ENDIAN */
  114         for (i = size; i-- > 0;)
  115 #endif /* BYTE_ORDER */
  116         {
  117                 data[i] = value & 0xFF;
  118                 value >>= 8;
  119         }
  120 
  121         db_write_bytes(addr, size, data);
  122 }
  123 
  124 #endif  /* _COMPILE_THIS || KGDB && SOFTWARE_SSTEP */
  125 
  126 #ifdef  _COMPILE_THIS
  127 
  128 void *
  129 db_read_ptr(const char *name)
  130 {
  131         db_expr_t val;
  132         void *p;
  133 
  134         if (!db_value_of_name(name, &val)) {
  135                 db_printf("db_read_ptr: cannot find `%s'\n", name);
  136                 db_error(NULL);
  137                 /* NOTREACHED */
  138         }
  139         db_read_bytes((db_addr_t)val, sizeof(p), (char *)&p);
  140         return p;
  141 }
  142 
  143 int
  144 db_read_int(const char *name)
  145 {
  146         db_expr_t val;
  147         int p;
  148 
  149         if (!db_value_of_name(name, &val)) {
  150                 db_printf("db_read_int: cannot find `%s'\n", name);
  151                 db_error(NULL);
  152                 /* NOTREACHED */
  153         }
  154         db_read_bytes((db_addr_t)val, sizeof(p), (char *)&p);
  155         return p;
  156 }
  157 
  158 #endif  /* _COMPILE_THIS */

Cache object: 8cc53d9a76b020110fd0981f4e4be20c


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.