LCOV - code coverage report
Current view: top level - ddb - db_access.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 21 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: db_access.c,v 1.15 2016/04/19 10:24:42 mpi Exp $      */
       2             : /*      $NetBSD: db_access.c,v 1.8 1994/10/09 08:37:35 mycroft Exp $    */
       3             : 
       4             : /*
       5             :  * Mach Operating System
       6             :  * Copyright (c) 1991,1990 Carnegie Mellon University
       7             :  * All Rights Reserved.
       8             :  *
       9             :  * Permission to use, copy, modify and distribute this software and its
      10             :  * documentation is hereby granted, provided that both the copyright
      11             :  * notice and this permission notice appear in all copies of the
      12             :  * software, derivative works or modified versions, and any portions
      13             :  * thereof, and that both notices appear in supporting documentation.
      14             :  *
      15             :  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
      16             :  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
      17             :  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
      18             :  *
      19             :  * Carnegie Mellon requests users of this software to return to
      20             :  *
      21             :  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
      22             :  *  School of Computer Science
      23             :  *  Carnegie Mellon University
      24             :  *  Pittsburgh PA 15213-3890
      25             :  *
      26             :  * any improvements or extensions that they make and grant Carnegie the
      27             :  * the rights to redistribute these changes.
      28             :  *
      29             :  *      Author: David B. Golub, Carnegie Mellon University
      30             :  *      Date:   7/90
      31             :  */
      32             : 
      33             : #include <sys/param.h>
      34             : #include <sys/endian.h>
      35             : 
      36             : #include <machine/db_machdep.h>           /* type definitions */
      37             : 
      38             : #include <ddb/db_access.h>
      39             : 
      40             : /*
      41             :  * Access unaligned data items on aligned (longword)
      42             :  * boundaries.
      43             :  */
      44             : db_expr_t
      45           0 : db_get_value(db_addr_t addr, size_t size, int is_signed)
      46             : {
      47           0 :         char data[sizeof(db_expr_t)];
      48             :         db_expr_t value, extend;
      49             :         int i;
      50             : 
      51             : #ifdef DIAGNOSTIC
      52           0 :         if (size > sizeof data)
      53           0 :                 size = sizeof data;
      54             : #endif
      55             : 
      56           0 :         db_read_bytes(addr, size, data);
      57             : 
      58             :         value = 0;
      59           0 :         extend = (~(db_expr_t)0) << (size * 8 - 1);
      60             : #if BYTE_ORDER == LITTLE_ENDIAN
      61           0 :         for (i = size - 1; i >= 0; i--)
      62             : #else /* BYTE_ORDER == BIG_ENDIAN */
      63             :         for (i = 0; i < size; i++)
      64             : #endif /* BYTE_ORDER */
      65           0 :                 value = (value << 8) + (data[i] & 0xFF);
      66             : 
      67           0 :         if (size < sizeof(db_expr_t) && is_signed && (value & extend))
      68           0 :                 value |= extend;
      69           0 :         return (value);
      70           0 : }
      71             : 
      72             : void
      73           0 : db_put_value(db_addr_t addr, size_t size, db_expr_t value)
      74             : {
      75           0 :         char data[sizeof(db_expr_t)];
      76             :         int i;
      77             : 
      78             : #ifdef DIAGNOSTIC
      79           0 :         if (size > sizeof data)
      80           0 :                 size = sizeof data;
      81             : #endif
      82             : 
      83             : #if BYTE_ORDER == LITTLE_ENDIAN
      84           0 :         for (i = 0; i < size; i++)
      85             : #else /* BYTE_ORDER == BIG_ENDIAN */
      86             :         for (i = size - 1; i >= 0; i--)
      87             : #endif /* BYTE_ORDER */
      88             :         {
      89           0 :                 data[i] = value & 0xff;
      90           0 :                 value >>= 8;
      91             :         }
      92             : 
      93           0 :         db_write_bytes(addr, size, data);
      94           0 : }

Generated by: LCOV version 1.13