/*-1* SPDX-License-Identifier: MIT-CMU2*3* Mach Operating System4* Copyright (c) 1991,1990 Carnegie Mellon University5* All Rights Reserved.6*7* Permission to use, copy, modify and distribute this software and its8* documentation is hereby granted, provided that both the copyright9* notice and this permission notice appear in all copies of the10* software, derivative works or modified versions, and any portions11* thereof, and that both notices appear in supporting documentation.12*13* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS14* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR15* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.16*17* Carnegie Mellon requests users of this software to return to18*19* Software Distribution Coordinator or [email protected]20* School of Computer Science21* Carnegie Mellon University22* Pittsburgh PA 15213-389023*24* any improvements or extensions that they make and grant Carnegie the25* rights to redistribute these changes.26*/27/*28* Author: David B. Golub, Carnegie Mellon University29* Date: 7/9030*/3132#include <sys/param.h>33#include <sys/kdb.h>34#include <sys/endian.h>3536#include <ddb/ddb.h>37#include <ddb/db_access.h>3839/*40* Access unaligned data items on aligned (longword)41* boundaries.42*/4344static unsigned db_extend[] = { /* table for sign-extending */450,460xFFFFFF80U,470xFFFF8000U,480xFF800000U49};5051db_expr_t52db_get_value(db_addr_t addr, int size, bool is_signed)53{54char data[sizeof(uint64_t)];55db_expr_t value;56int i;5758if (db_read_bytes(addr, size, data) != 0) {59db_printf("*** error reading from address %llx ***\n",60(long long)addr);61kdb_reenter();62}6364value = 0;65#if _BYTE_ORDER == _BIG_ENDIAN66for (i = 0; i < size; i++)67#else /* _LITTLE_ENDIAN */68for (i = size - 1; i >= 0; i--)69#endif70{71value = (value << 8) + (data[i] & 0xFF);72}7374if (size < 4) {75if (is_signed && (value & db_extend[size]) != 0)76value |= db_extend[size];77}78return (value);79}8081void82db_put_value(db_addr_t addr, int size, db_expr_t value)83{84char data[sizeof(int)];85int i;8687#if _BYTE_ORDER == _BIG_ENDIAN88for (i = size - 1; i >= 0; i--)89#else /* _LITTLE_ENDIAN */90for (i = 0; i < size; i++)91#endif92{93data[i] = value & 0xFF;94value >>= 8;95}9697if (db_write_bytes(addr, size, data) != 0) {98db_printf("*** error writing to address %llx ***\n",99(long long)addr);100kdb_reenter();101}102}103104105