| 1 | /* |
| 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
| 3 | * |
| 4 | * @APPLE_LICENSE_HEADER_START@ |
| 5 | * |
| 6 | * The contents of this file constitute Original Code as defined in and |
| 7 | * are subject to the Apple Public Source License Version 1.1 (the |
| 8 | * "License"). You may not use this file except in compliance with the |
| 9 | * License. Please obtain a copy of the License at |
| 10 | * http://www.apple.com/publicsource and read it before using this file. |
| 11 | * |
| 12 | * This Original Code and all software distributed under the License are |
| 13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
| 14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
| 15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
| 17 | * License for the specific language governing rights and limitations |
| 18 | * under the License. |
| 19 | * |
| 20 | * @APPLE_LICENSE_HEADER_END@ |
| 21 | */ |
| 22 | /* |
| 23 | * @OSF_COPYRIGHT@ |
| 24 | */ |
| 25 | /* |
| 26 | * Mach Operating System |
| 27 | * Copyright (c) 1991,1990 Carnegie Mellon University |
| 28 | * All Rights Reserved. |
| 29 | * |
| 30 | * Permission to use, copy, modify and distribute this software and its |
| 31 | * documentation is hereby granted, provided that both the copyright |
| 32 | * notice and this permission notice appear in all copies of the |
| 33 | * software, derivative works or modified versions, and any portions |
| 34 | * thereof, and that both notices appear in supporting documentation. |
| 35 | * |
| 36 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
| 37 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR |
| 38 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. |
| 39 | * |
| 40 | * Carnegie Mellon requests users of this software to return to |
| 41 | * |
| 42 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
| 43 | * School of Computer Science |
| 44 | * Carnegie Mellon University |
| 45 | * Pittsburgh PA 15213-3890 |
| 46 | * |
| 47 | * any improvements or extensions that they make and grant Carnegie Mellon |
| 48 | * the rights to redistribute these changes. |
| 49 | */ |
| 50 | /* |
| 51 | */ |
| 52 | /* |
| 53 | * Author: David B. Golub, Carnegie Mellon University |
| 54 | * Date: 7/90 |
| 55 | */ |
| 56 | #include <mach/boolean.h> |
| 57 | #include <machine/db_machdep.h> /* type definitions */ |
| 58 | #include <machine/setjmp.h> |
| 59 | #include <machine/endian.h> |
| 60 | #include <kern/task.h> |
| 61 | #include <ddb/db_access.h> |
| 62 | |
| 63 | |
| 64 | |
| 65 | /* |
| 66 | * Access unaligned data items on aligned (longword) |
| 67 | * boundaries. |
| 68 | */ |
| 69 | |
| 70 | int db_access_level = DB_ACCESS_LEVEL; |
| 71 | |
| 72 | db_expr_t |
| 73 | db_get_task_value( |
| 74 | db_addr_t addr, |
| 75 | register int size, |
| 76 | boolean_t is_signed, |
| 77 | task_t task) |
| 78 | { |
| 79 | char data[sizeof(db_expr_t)]; |
| 80 | register db_expr_t value; |
| 81 | register int i; |
| 82 | uint64_t signx; |
| 83 | |
| 84 | if(size == 0) return 0; |
| 85 | |
| 86 | db_read_bytes((vm_offset_t)addr, size, data, task); |
| 87 | |
| 88 | value = 0; |
| 89 | #if BYTE_MSF |
| 90 | for (i = 0; i < size; i++) |
| 91 | #else /* BYTE_LSF */ |
| 92 | for (i = size - 1; i >= 0; i--) |
| 93 | #endif |
| 94 | { |
| 95 | value = (value << 8) + (data[i] & 0xFF); |
| 96 | } |
| 97 | |
| 98 | if(!is_signed) return value; |
| 99 | |
| 100 | signx = 0xFFFFFFFFFFFFFFFFULL << ((size << 3) - 1); |
| 101 | |
| 102 | if(value & signx) value |= signx; /* Add 1s to front if sign bit is on */ |
| 103 | |
| 104 | return (value); |
| 105 | } |
| 106 | |
| 107 | void |
| 108 | db_put_task_value( |
| 109 | db_addr_t addr, |
| 110 | register int size, |
| 111 | register db_expr_t value, |
| 112 | task_t task) |
| 113 | { |
| 114 | char data[sizeof(db_expr_t)]; |
| 115 | register int i; |
| 116 | |
| 117 | #if BYTE_MSF |
| 118 | for (i = size - 1; i >= 0; i--) |
| 119 | #else /* BYTE_LSF */ |
| 120 | for (i = 0; i < size; i++) |
| 121 | #endif |
| 122 | { |
| 123 | data[i] = value & 0xFF; |
| 124 | value >>= 8; |
| 125 | } |
| 126 | |
| 127 | db_write_bytes((vm_offset_t)addr, size, data, task); |
| 128 | } |
| 129 | |
| 130 | db_expr_t |
| 131 | db_get_value( |
| 132 | db_addr_t addr, |
| 133 | int size, |
| 134 | boolean_t is_signed) |
| 135 | { |
| 136 | return(db_get_task_value(addr, size, is_signed, TASK_NULL)); |
| 137 | } |
| 138 | |
| 139 | void |
| 140 | db_put_value( |
| 141 | db_addr_t addr, |
| 142 | int size, |
| 143 | db_expr_t value) |
| 144 | { |
| 145 | db_put_task_value(addr, size, value, TASK_NULL); |
| 146 | } |