1 2/****************************************************************************** 3 * 4 * Module Name: exstorob - AML Interpreter object store support, store to object 5 * $Revision: 1.1.1.1 $ 6 * 7 *****************************************************************************/ 8 9/* 10 * Copyright (C) 2000, 2001 R. Byron Moore 11 * 12 * This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License as published by 14 * the Free Software Foundation; either version 2 of the License, or 15 * (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 */ 26 27 28#include "acpi.h" 29#include "acparser.h" 30#include "acdispat.h" 31#include "acinterp.h" 32#include "amlcode.h" 33#include "acnamesp.h" 34#include "actables.h" 35 36 37#define _COMPONENT ACPI_EXECUTER 38 MODULE_NAME ("exstorob") 39 40 41/******************************************************************************* 42 * 43 * FUNCTION: Acpi_ex_copy_buffer_to_buffer 44 * 45 * PARAMETERS: Source_desc - Source object to copy 46 * Target_desc - Destination object of the copy 47 * 48 * RETURN: Status 49 * 50 * DESCRIPTION: Copy a buffer object to another buffer object. 51 * 52 ******************************************************************************/ 53 54acpi_status 55acpi_ex_copy_buffer_to_buffer ( 56 acpi_operand_object *source_desc, 57 acpi_operand_object *target_desc) 58{ 59 u32 length; 60 u8 *buffer; 61 62 63 PROC_NAME ("Ex_copy_buffer_to_buffer"); 64 65 66 /* 67 * We know that Source_desc is a buffer by now 68 */ 69 buffer = (u8 *) source_desc->buffer.pointer; 70 length = source_desc->buffer.length; 71 72 /* 73 * If target is a buffer of length zero, allocate a new 74 * buffer of the proper length 75 */ 76 if (target_desc->buffer.length == 0) { 77 target_desc->buffer.pointer = ACPI_MEM_ALLOCATE (length); 78 if (!target_desc->buffer.pointer) { 79 return (AE_NO_MEMORY); 80 } 81 82 target_desc->buffer.length = length; 83 } 84 85 /* 86 * Buffer is a static allocation, 87 * only place what will fit in the buffer. 88 */ 89 if (length <= target_desc->buffer.length) { 90 /* Clear existing buffer and copy in the new one */ 91 92 MEMSET (target_desc->buffer.pointer, 0, target_desc->buffer.length); 93 MEMCPY (target_desc->buffer.pointer, buffer, length); 94 } 95 96 else { 97 /* 98 * Truncate the source, copy only what will fit 99 */ 100 MEMCPY (target_desc->buffer.pointer, buffer, target_desc->buffer.length); 101 102 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 103 "Truncating src buffer from %X to %X\n", 104 length, target_desc->buffer.length)); 105 } 106 107 return (AE_OK); 108} 109 110 111/******************************************************************************* 112 * 113 * FUNCTION: Acpi_ex_copy_string_to_string 114 * 115 * PARAMETERS: Source_desc - Source object to copy 116 * Target_desc - Destination object of the copy 117 * 118 * RETURN: Status 119 * 120 * DESCRIPTION: Copy a String object to another String object 121 * 122 ******************************************************************************/ 123 124acpi_status 125acpi_ex_copy_string_to_string ( 126 acpi_operand_object *source_desc, 127 acpi_operand_object *target_desc) 128{ 129 u32 length; 130 u8 *buffer; 131 132 133 FUNCTION_ENTRY (); 134 135 136 /* 137 * We know that Source_desc is a string by now. 138 */ 139 buffer = (u8 *) source_desc->string.pointer; 140 length = source_desc->string.length; 141 142 /* 143 * Setting a string value replaces the old string 144 */ 145 if (length < target_desc->string.length) { 146 /* Clear old string and copy in the new one */ 147 148 MEMSET (target_desc->string.pointer, 0, target_desc->string.length); 149 MEMCPY (target_desc->string.pointer, buffer, length); 150 } 151 152 else { 153 /* 154 * Free the current buffer, then allocate a buffer 155 * large enough to hold the value 156 */ 157 if (target_desc->string.pointer && 158 (!(target_desc->common.flags & AOPOBJ_STATIC_POINTER))) { 159 /* 160 * Only free if not a pointer into the DSDT 161 */ 162 ACPI_MEM_FREE (target_desc->string.pointer); 163 } 164 165 target_desc->string.pointer = ACPI_MEM_ALLOCATE (length + 1); 166 if (!target_desc->string.pointer) { 167 return (AE_NO_MEMORY); 168 } 169 170 target_desc->string.length = length; 171 MEMCPY (target_desc->string.pointer, buffer, length); 172 } 173 174 return (AE_OK); 175} 176 177 178