Fixed compatibility of output.
[AROS.git] / arch / all-pc / acpica / source / compiler / aslnamesp.c
blob3fc5f397a726d0ca211021e4bb1092ea3b0d8812
1 /******************************************************************************
3 * Module Name: aslnamesp - Namespace output file generation
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include "aslcompiler.h"
46 #include "aslcompiler.y.h"
47 #include "acnamesp.h"
50 #define _COMPONENT ACPI_COMPILER
51 ACPI_MODULE_NAME ("aslnamesp")
53 /* Local prototypes */
55 static ACPI_STATUS
56 NsDoOneNamespaceObject (
57 ACPI_HANDLE ObjHandle,
58 UINT32 Level,
59 void *Context,
60 void **ReturnValue);
62 static ACPI_STATUS
63 NsDoOnePathname (
64 ACPI_HANDLE ObjHandle,
65 UINT32 Level,
66 void *Context,
67 void **ReturnValue);
70 /*******************************************************************************
72 * FUNCTION: NsSetupNamespaceListing
74 * PARAMETERS: Handle - local file handle
76 * RETURN: None
78 * DESCRIPTION: Set the namespace output file to the input handle
80 ******************************************************************************/
82 void
83 NsSetupNamespaceListing (
84 void *Handle)
87 Gbl_NsOutputFlag = TRUE;
88 Gbl_Files[ASL_FILE_NAMESPACE_OUTPUT].Handle = Handle;
92 /*******************************************************************************
94 * FUNCTION: NsDisplayNamespace
96 * PARAMETERS: None
98 * RETURN: Status
100 * DESCRIPTION: Walk the namespace an display information about each node
101 * in the tree. Information is written to the optional
102 * namespace output file.
104 ******************************************************************************/
106 ACPI_STATUS
107 NsDisplayNamespace (
108 void)
110 ACPI_STATUS Status;
113 if (!Gbl_NsOutputFlag)
115 return (AE_OK);
118 Gbl_NumNamespaceObjects = 0;
120 /* File header */
122 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Contents of ACPI Namespace\n\n");
123 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Count Depth Name - Type\n\n");
125 /* Walk entire namespace from the root */
127 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
128 ACPI_UINT32_MAX, FALSE, NsDoOneNamespaceObject, NULL,
129 NULL, NULL);
131 /* Print the full pathname for each namespace node */
133 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\nNamespace pathnames\n\n");
135 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
136 ACPI_UINT32_MAX, FALSE, NsDoOnePathname, NULL,
137 NULL, NULL);
139 return (Status);
143 /*******************************************************************************
145 * FUNCTION: NsDoOneNamespaceObject
147 * PARAMETERS: ACPI_WALK_CALLBACK
149 * RETURN: Status
151 * DESCRIPTION: Dump a namespace object to the namespace output file.
152 * Called during the walk of the namespace to dump all objects.
154 ******************************************************************************/
156 static ACPI_STATUS
157 NsDoOneNamespaceObject (
158 ACPI_HANDLE ObjHandle,
159 UINT32 Level,
160 void *Context,
161 void **ReturnValue)
163 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
164 ACPI_OPERAND_OBJECT *ObjDesc;
165 ACPI_PARSE_OBJECT *Op;
168 Gbl_NumNamespaceObjects++;
170 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u [%u] %*s %4.4s - %s",
171 Gbl_NumNamespaceObjects, Level, (Level * 3), " ",
172 &Node->Name,
173 AcpiUtGetTypeName (Node->Type));
175 Op = Node->Op;
176 ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node->Object);
178 if (!Op)
180 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
181 return (AE_OK);
185 if ((ObjDesc) &&
186 (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND))
188 switch (Node->Type)
190 case ACPI_TYPE_INTEGER:
192 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
193 " [Initial Value 0x%8.8X%8.8X]",
194 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
195 break;
197 case ACPI_TYPE_STRING:
199 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
200 " [Initial Value \"%s\"]",
201 ObjDesc->String.Pointer);
202 break;
204 default:
206 /* Nothing to do for other types */
208 break;
212 else
214 switch (Node->Type)
216 case ACPI_TYPE_INTEGER:
218 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
220 Op = Op->Asl.Child;
222 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
223 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
225 Op = Op->Asl.Next;
227 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
228 " [Initial Value 0x%8.8X%8.8X]",
229 ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer));
230 break;
232 case ACPI_TYPE_STRING:
234 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
236 Op = Op->Asl.Child;
238 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
239 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
241 Op = Op->Asl.Next;
243 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
244 " [Initial Value \"%s\"]",
245 Op->Asl.Value.String);
246 break;
248 case ACPI_TYPE_LOCAL_REGION_FIELD:
250 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
251 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
253 Op = Op->Asl.Child;
255 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
256 " [Offset 0x%04X Length 0x%04X bits]",
257 Op->Asl.Parent->Asl.ExtraValue, (UINT32) Op->Asl.Value.Integer);
258 break;
260 case ACPI_TYPE_BUFFER_FIELD:
262 switch (Op->Asl.ParseOpcode)
264 case PARSEOP_CREATEBYTEFIELD:
266 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BYTE ( 8 bit)]");
267 break;
269 case PARSEOP_CREATEDWORDFIELD:
271 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [DWORD (32 bit)]");
272 break;
274 case PARSEOP_CREATEQWORDFIELD:
276 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [QWORD (64 bit)]");
277 break;
279 case PARSEOP_CREATEWORDFIELD:
281 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [WORD (16 bit)]");
282 break;
284 case PARSEOP_CREATEBITFIELD:
286 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BIT ( 1 bit)]");
287 break;
289 case PARSEOP_CREATEFIELD:
291 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [Arbitrary Bit Field]");
292 break;
294 default:
296 break;
299 break;
301 case ACPI_TYPE_PACKAGE:
303 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
305 Op = Op->Asl.Child;
307 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
308 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
310 Op = Op->Asl.Next;
312 Op = Op->Asl.Child;
314 if ((Op->Asl.ParseOpcode == PARSEOP_BYTECONST) ||
315 (Op->Asl.ParseOpcode == PARSEOP_RAW_DATA))
317 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
318 " [Initial Length 0x%.2X elements]",
319 Op->Asl.Value.Integer);
321 break;
323 case ACPI_TYPE_BUFFER:
325 if (Op->Asl.ParseOpcode == PARSEOP_NAME)
327 Op = Op->Asl.Child;
329 if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) ||
330 (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING))
332 Op = Op->Asl.Next;
334 Op = Op->Asl.Child;
336 if (Op && (Op->Asl.ParseOpcode == PARSEOP_INTEGER))
338 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
339 " [Initial Length 0x%.2X bytes]",
340 Op->Asl.Value.Integer);
342 break;
344 case ACPI_TYPE_METHOD:
346 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
347 " [Code Length 0x%.4X bytes]",
348 Op->Asl.AmlSubtreeLength);
349 break;
351 case ACPI_TYPE_LOCAL_RESOURCE:
353 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
354 " [Desc Offset 0x%.4X Bytes]", Node->Value);
355 break;
357 case ACPI_TYPE_LOCAL_RESOURCE_FIELD:
359 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
360 " [Field Offset 0x%.4X Bits 0x%.4X Bytes] ",
361 Node->Value, Node->Value / 8);
363 if (Node->Flags & ANOBJ_IS_REFERENCED)
365 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
366 "Referenced");
368 else
370 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT,
371 "Name not referenced");
373 break;
375 default:
377 /* Nothing to do for other types */
379 break;
383 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n");
384 return (AE_OK);
388 /*******************************************************************************
390 * FUNCTION: NsDoOnePathname
392 * PARAMETERS: ACPI_WALK_CALLBACK
394 * RETURN: Status
396 * DESCRIPTION: Print the full pathname for a namespace node.
398 ******************************************************************************/
400 static ACPI_STATUS
401 NsDoOnePathname (
402 ACPI_HANDLE ObjHandle,
403 UINT32 Level,
404 void *Context,
405 void **ReturnValue)
407 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
408 ACPI_STATUS Status;
409 ACPI_BUFFER TargetPath;
412 TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
413 Status = AcpiNsHandleToPathname (Node, &TargetPath);
414 if (ACPI_FAILURE (Status))
416 return (Status);
419 FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%s\n", TargetPath.Pointer);
420 ACPI_FREE (TargetPath.Pointer);
422 return (AE_OK);