1dd3cb568SWarner Losh /*- 2*796df753SPedro F. Giffuni * SPDX-License-Identifier: MIT-CMU 3*796df753SPedro F. Giffuni * 45b81b6b3SRodney W. Grimes * Mach Operating System 55b81b6b3SRodney W. Grimes * Copyright (c) 1991,1990 Carnegie Mellon University 65b81b6b3SRodney W. Grimes * All Rights Reserved. 75b81b6b3SRodney W. Grimes * 85b81b6b3SRodney W. Grimes * Permission to use, copy, modify and distribute this software and its 95b81b6b3SRodney W. Grimes * documentation is hereby granted, provided that both the copyright 105b81b6b3SRodney W. Grimes * notice and this permission notice appear in all copies of the 115b81b6b3SRodney W. Grimes * software, derivative works or modified versions, and any portions 125b81b6b3SRodney W. Grimes * thereof, and that both notices appear in supporting documentation. 135b81b6b3SRodney W. Grimes * 145b81b6b3SRodney W. Grimes * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 155b81b6b3SRodney W. Grimes * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 165b81b6b3SRodney W. Grimes * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 175b81b6b3SRodney W. Grimes * 185b81b6b3SRodney W. Grimes * Carnegie Mellon requests users of this software to return to 195b81b6b3SRodney W. Grimes * 205b81b6b3SRodney W. Grimes * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 215b81b6b3SRodney W. Grimes * School of Computer Science 225b81b6b3SRodney W. Grimes * Carnegie Mellon University 235b81b6b3SRodney W. Grimes * Pittsburgh PA 15213-3890 245b81b6b3SRodney W. Grimes * 255b81b6b3SRodney W. Grimes * any improvements or extensions that they make and grant Carnegie the 265b81b6b3SRodney W. Grimes * rights to redistribute these changes. 275b81b6b3SRodney W. Grimes */ 285b81b6b3SRodney W. Grimes /* 295b81b6b3SRodney W. Grimes * Author: David B. Golub, Carnegie Mellon University 305b81b6b3SRodney W. Grimes * Date: 7/90 315b81b6b3SRodney W. Grimes */ 32753960f7SDavid E. O'Brien 33753960f7SDavid E. O'Brien #include <sys/cdefs.h> 34753960f7SDavid E. O'Brien __FBSDID("$FreeBSD$"); 35753960f7SDavid E. O'Brien 36f540b106SGarrett Wollman #include <sys/param.h> 3737224cd3SMarcel Moolenaar #include <sys/kdb.h> 385ccbc3ccSBruce Evans 39f540b106SGarrett Wollman #include <ddb/ddb.h> 40058284fcSBruce Evans #include <ddb/db_access.h> 415b81b6b3SRodney W. Grimes 425b81b6b3SRodney W. Grimes /* 435b81b6b3SRodney W. Grimes * Access unaligned data items on aligned (longword) 445b81b6b3SRodney W. Grimes * boundaries. 455b81b6b3SRodney W. Grimes */ 465b81b6b3SRodney W. Grimes 47f73a856dSPoul-Henning Kamp static unsigned db_extend[] = { /* table for sign-extending */ 485b81b6b3SRodney W. Grimes 0, 49381fe1aaSGarrett Wollman 0xFFFFFF80U, 50381fe1aaSGarrett Wollman 0xFFFF8000U, 51381fe1aaSGarrett Wollman 0xFF800000U 525b81b6b3SRodney W. Grimes }; 535b81b6b3SRodney W. Grimes 54f4e98881SRuslan Ermilov #ifndef BYTE_MSF 55f4e98881SRuslan Ermilov #define BYTE_MSF 0 56f4e98881SRuslan Ermilov #endif 57f4e98881SRuslan Ermilov 585b81b6b3SRodney W. Grimes db_expr_t 59cd508278SPedro F. Giffuni db_get_value(db_addr_t addr, int size, bool is_signed) 605b81b6b3SRodney W. Grimes { 610ddc915cSHartmut Brandt char data[sizeof(u_int64_t)]; 623e85b721SEd Maste db_expr_t value; 633e85b721SEd Maste int i; 645b81b6b3SRodney W. Grimes 6537224cd3SMarcel Moolenaar if (db_read_bytes(addr, size, data) != 0) { 6637224cd3SMarcel Moolenaar db_printf("*** error reading from address %llx ***\n", 6737224cd3SMarcel Moolenaar (long long)addr); 6837224cd3SMarcel Moolenaar kdb_reenter(); 6937224cd3SMarcel Moolenaar } 705b81b6b3SRodney W. Grimes 715b81b6b3SRodney W. Grimes value = 0; 725b81b6b3SRodney W. Grimes #if BYTE_MSF 735b81b6b3SRodney W. Grimes for (i = 0; i < size; i++) 745b81b6b3SRodney W. Grimes #else /* BYTE_LSF */ 755b81b6b3SRodney W. Grimes for (i = size - 1; i >= 0; i--) 765b81b6b3SRodney W. Grimes #endif 775b81b6b3SRodney W. Grimes { 785b81b6b3SRodney W. Grimes value = (value << 8) + (data[i] & 0xFF); 795b81b6b3SRodney W. Grimes } 805b81b6b3SRodney W. Grimes 815b81b6b3SRodney W. Grimes if (size < 4) { 825b81b6b3SRodney W. Grimes if (is_signed && (value & db_extend[size]) != 0) 835b81b6b3SRodney W. Grimes value |= db_extend[size]; 845b81b6b3SRodney W. Grimes } 855b81b6b3SRodney W. Grimes return (value); 865b81b6b3SRodney W. Grimes } 875b81b6b3SRodney W. Grimes 885b81b6b3SRodney W. Grimes void 89a41dd031SPedro F. Giffuni db_put_value(db_addr_t addr, int size, db_expr_t value) 905b81b6b3SRodney W. Grimes { 915b81b6b3SRodney W. Grimes char data[sizeof(int)]; 923e85b721SEd Maste int i; 935b81b6b3SRodney W. Grimes 945b81b6b3SRodney W. Grimes #if BYTE_MSF 955b81b6b3SRodney W. Grimes for (i = size - 1; i >= 0; i--) 965b81b6b3SRodney W. Grimes #else /* BYTE_LSF */ 975b81b6b3SRodney W. Grimes for (i = 0; i < size; i++) 985b81b6b3SRodney W. Grimes #endif 995b81b6b3SRodney W. Grimes { 1005b81b6b3SRodney W. Grimes data[i] = value & 0xFF; 1015b81b6b3SRodney W. Grimes value >>= 8; 1025b81b6b3SRodney W. Grimes } 1035b81b6b3SRodney W. Grimes 10437224cd3SMarcel Moolenaar if (db_write_bytes(addr, size, data) != 0) { 10537224cd3SMarcel Moolenaar db_printf("*** error writing to address %llx ***\n", 10637224cd3SMarcel Moolenaar (long long)addr); 10737224cd3SMarcel Moolenaar kdb_reenter(); 1085b81b6b3SRodney W. Grimes } 10937224cd3SMarcel Moolenaar } 110