VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/acpi/acpi-ast.cpp@ 108029

Last change on this file since 108029 was 108029, checked in by vboxsync, 3 weeks ago

Runtime/RTAcpi: Some more work on the ASL -> AML compiler, can process our vbox-standard.dsl now, bugref:10733

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: acpi-ast.cpp 108029 2025-02-03 15:58:01Z vboxsync $ */
2/** @file
3 * IPRT - Advanced Configuration and Power Interface (ACPI) AST handling.
4 */
5
6/*
7 * Copyright (C) 2025 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * 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, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#define LOG_GROUP RTLOGGROUP_ACPI
42#include <iprt/assert.h>
43#include <iprt/errcore.h>
44#include <iprt/list.h>
45#include <iprt/mem.h>
46
47#include <iprt/formats/acpi-aml.h>
48
49#include "internal/acpi.h"
50
51
52/*********************************************************************************************************************************
53* Defined Constants And Macros *
54*********************************************************************************************************************************/
55
56
57/*********************************************************************************************************************************
58* Structures and Typedefs *
59*********************************************************************************************************************************/
60
61
62/*********************************************************************************************************************************
63* Global Variables *
64*********************************************************************************************************************************/
65
66
67/*********************************************************************************************************************************
68* Internal Functions *
69*********************************************************************************************************************************/
70
71DECLHIDDEN(PRTACPIASTNODE) rtAcpiAstNodeAlloc(uint8_t bOpc, uint32_t fFlags, uint8_t cArgs)
72{
73 PRTACPIASTNODE pAstNd = (PRTACPIASTNODE)RTMemAllocZ(RT_UOFFSETOF_DYN(RTACPIASTNODE, aArgs[cArgs]));
74 if (pAstNd)
75 {
76 pAstNd->bOpc = bOpc;
77 pAstNd->fFlags = fFlags;
78 pAstNd->cArgs = cArgs;
79 RTListInit(&pAstNd->LstScopeNodes);
80 }
81
82 return pAstNd;
83}
84
85
86DECLHIDDEN(void) rtAcpiAstNodeFree(PRTACPIASTNODE pAstNd)
87{
88 /** @todo */
89 RTMemFree(pAstNd);
90}
91
92
93static int rtAcpiAstDumpAstList(PCRTLISTANCHOR pLst, RTACPITBL hAcpiTbl)
94{
95 PCRTACPIASTNODE pIt;
96 RTListForEach(pLst, pIt, RTACPIASTNODE, NdAst)
97 {
98 int rc = rtAcpiAstDumpToTbl(pIt, hAcpiTbl);
99 if (RT_FAILURE(rc))
100 return rc;
101 }
102
103 return VINF_SUCCESS;
104}
105
106
107static int rtAcpiAstDumpExtOpc(PCRTACPIASTNODE pAstNd, RTACPITBL hAcpiTbl)
108{
109 int rc;
110
111 switch (pAstNd->bOpc)
112 {
113 case ACPI_AML_BYTE_CODE_EXT_OP_PROCESSOR:
114 {
115 AssertBreakStmt( pAstNd->cArgs == 4
116 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_NameString
117 && pAstNd->aArgs[1].enmType == kAcpiAstArgType_U8
118 && pAstNd->aArgs[2].enmType == kAcpiAstArgType_U32
119 && pAstNd->aArgs[3].enmType == kAcpiAstArgType_U8,
120 rc = VERR_INTERNAL_ERROR);
121 rc = RTAcpiTblProcessorStart(hAcpiTbl,
122 pAstNd->aArgs[0].u.pszNameString,
123 pAstNd->aArgs[1].u.u8,
124 pAstNd->aArgs[2].u.u32,
125 pAstNd->aArgs[3].u.u8);
126 if (RT_SUCCESS(rc))
127 {
128 /* Walk all the other AST nodes. */
129 rc = rtAcpiAstDumpAstList(&pAstNd->LstScopeNodes, hAcpiTbl);
130 if (RT_SUCCESS(rc))
131 rc = RTAcpiTblProcessorFinalize(hAcpiTbl);
132 }
133 break;
134 }
135 default:
136 AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED);
137 }
138
139 return rc;
140}
141
142
143static int rtAcpiAstDumpOpc(PCRTACPIASTNODE pAstNd, RTACPITBL hAcpiTbl)
144{
145 int rc;
146
147 switch (pAstNd->bOpc)
148 {
149 case ACPI_AML_BYTE_CODE_OP_SCOPE:
150 {
151 AssertBreakStmt( pAstNd->cArgs == 1
152 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_NameString,
153 rc = VERR_INTERNAL_ERROR);
154 rc = RTAcpiTblScopeStart(hAcpiTbl, pAstNd->aArgs[0].u.pszNameString);
155 if (RT_SUCCESS(rc))
156 {
157 /* Walk all the other AST nodes. */
158 rc = rtAcpiAstDumpAstList(&pAstNd->LstScopeNodes, hAcpiTbl);
159 if (RT_SUCCESS(rc))
160 rc = RTAcpiTblScopeFinalize(hAcpiTbl);
161 }
162 break;
163 }
164 default:
165 AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED);
166 }
167
168 return rc;
169}
170
171
172DECLHIDDEN(int) rtAcpiAstDumpToTbl(PCRTACPIASTNODE pAstNd, RTACPITBL hAcpiTbl)
173{
174 if (pAstNd->fFlags & RTACPI_AST_NODE_F_EXT_OPC)
175 return rtAcpiAstDumpExtOpc(pAstNd, hAcpiTbl);
176 else
177 return rtAcpiAstDumpOpc(pAstNd, hAcpiTbl);
178}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette