Subversion Repositories Kolibri OS

Rev

Rev 1498 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1498 serge 1
 
2
 *
3
 * Module Name: aslcodegen - AML code generation
4
 *
5
 *****************************************************************************/
6
7
 
8
 *
9
 * 1. Copyright Notice
10
 *
11
 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
2216 Serge 12
 * All rights reserved.
1498 serge 13
 *
14
 * 2. License
15
 *
16
 * 2.1. This is your license from Intel Corp. under its intellectual property
17
 * rights.  You may have additional license terms from the party that provided
18
 * you this software, covering your right to use that party's intellectual
19
 * property rights.
20
 *
21
 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22
 * copy of the source code appearing in this file ("Covered Code") an
23
 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24
 * base code distributed originally by Intel ("Original Intel Code") to copy,
25
 * make derivatives, distribute, use and display any portion of the Covered
26
 * Code in any form, with the right to sublicense such rights; and
27
 *
28
 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29
 * license (with the right to sublicense), under only those claims of Intel
30
 * patents that are infringed by the Original Intel Code, to make, use, sell,
31
 * offer to sell, and import the Covered Code and derivative works thereof
32
 * solely to the minimum extent necessary to exercise the above copyright
33
 * license, and in no event shall the patent license extend to any additions
34
 * to or modifications of the Original Intel Code.  No other license or right
35
 * is granted directly or by implication, estoppel or otherwise;
36
 *
37
 * The above copyright and patent license is granted only if the following
38
 * conditions are met:
39
 *
40
 * 3. Conditions
41
 *
42
 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43
 * Redistribution of source code of any substantial portion of the Covered
44
 * Code or modification with rights to further distribute source must include
45
 * the above Copyright Notice, the above License, this list of Conditions,
46
 * and the following Disclaimer and Export Compliance provision.  In addition,
47
 * Licensee must cause all Covered Code to which Licensee contributes to
48
 * contain a file documenting the changes Licensee made to create that Covered
49
 * Code and the date of any change.  Licensee must include in that file the
50
 * documentation of any changes made by any predecessor Licensee.  Licensee
51
 * must include a prominent statement that the modification is derived,
52
 * directly or indirectly, from Original Intel Code.
53
 *
54
 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55
 * Redistribution of source code of any substantial portion of the Covered
56
 * Code or modification without rights to further distribute source must
57
 * include the following Disclaimer and Export Compliance provision in the
58
 * documentation and/or other materials provided with distribution.  In
59
 * addition, Licensee may not authorize further sublicense of source of any
60
 * portion of the Covered Code, and must include terms to the effect that the
61
 * license from Licensee to its licensee is limited to the intellectual
62
 * property embodied in the software Licensee provides to its licensee, and
63
 * not to intellectual property embodied in modifications its licensee may
64
 * make.
65
 *
66
 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67
 * substantial portion of the Covered Code or modification must reproduce the
68
 * above Copyright Notice, and the following Disclaimer and Export Compliance
69
 * provision in the documentation and/or other materials provided with the
70
 * distribution.
71
 *
72
 * 3.4. Intel retains all right, title, and interest in and to the Original
73
 * Intel Code.
74
 *
75
 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76
 * Intel shall be used in advertising or otherwise to promote the sale, use or
77
 * other dealings in products derived from or relating to the Covered Code
78
 * without prior written authorization from Intel.
79
 *
80
 * 4. Disclaimer and Export Compliance
81
 *
82
 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83
 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84
 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85
 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86
 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87
 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88
 * PARTICULAR PURPOSE.
89
 *
90
 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91
 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92
 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93
 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94
 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95
 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96
 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97
 * LIMITED REMEDY.
98
 *
99
 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100
 * software or system incorporating such software without first obtaining any
101
 * required license or other approval from the U. S. Department of Commerce or
102
 * any other agency or department of the United States Government.  In the
103
 * event Licensee exports any such software from the United States or
104
 * re-exports any such software from a foreign destination, Licensee shall
105
 * ensure that the distribution and export/re-export of the software is in
106
 * compliance with all laws, regulations, orders, or other restrictions of the
107
 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108
 * any of its subsidiaries will export/re-export any technical data, process,
109
 * software, or service, directly or indirectly, to any country for which the
110
 * United States government or any agency thereof requires an export license,
111
 * other governmental approval, or letter of assurance, without first obtaining
112
 * such license, approval or letter.
113
 *
114
 *****************************************************************************/
115
116
 
117
 
118
#include "aslcompiler.y.h"
119
#include "amlcode.h"
120
121
 
122
        ACPI_MODULE_NAME    ("aslcodegen")
123
124
 
125
126
 
127
CgAmlWriteWalk (
128
    ACPI_PARSE_OBJECT       *Op,
129
    UINT32                  Level,
130
    void                    *Context);
131
132
 
133
CgLocalWriteAmlData (
134
    ACPI_PARSE_OBJECT       *Op,
135
    void                    *Buffer,
136
    UINT32                  Length);
137
138
 
139
CgWriteAmlOpcode (
140
    ACPI_PARSE_OBJECT       *Op);
141
142
 
143
CgWriteTableHeader (
144
    ACPI_PARSE_OBJECT       *Op);
145
146
 
147
CgCloseTable (
148
    void);
149
150
 
151
CgWriteNode (
152
    ACPI_PARSE_OBJECT       *Op);
153
154
 
155
 
156
 *
157
 * FUNCTION:    CgGenerateAmlOutput
158
 *
159
 * PARAMETERS:  None.
160
 *
161
 * RETURN:      None
162
 *
163
 * DESCRIPTION: Generate AML code.  Currently generates the listing file
164
 *              simultaneously.
165
 *
166
 ******************************************************************************/
167
168
 
169
CgGenerateAmlOutput (
170
    void)
171
{
172
173
 
174
175
 
176
177
 
178
    Gbl_SourceLine = 0;
179
    Gbl_NextError = Gbl_ErrorLog;
180
181
 
182
        CgAmlWriteWalk, NULL, NULL);
183
    CgCloseTable ();
184
}
185
186
 
187
 
188
 *
189
 * FUNCTION:    CgAmlWriteWalk
190
 *
191
 * PARAMETERS:  ASL_WALK_CALLBACK
192
 *
193
 * RETURN:      Status
194
 *
195
 * DESCRIPTION: Parse tree walk to generate the AML code.
196
 *
197
 ******************************************************************************/
198
199
 
200
CgAmlWriteWalk (
201
    ACPI_PARSE_OBJECT       *Op,
202
    UINT32                  Level,
203
    void                    *Context)
204
{
205
206
 
207
     * Print header at level 0. Alignment assumes 32-bit pointers
208
     */
209
    if (!Level)
210
    {
211
        DbgPrint (ASL_TREE_OUTPUT,
212
            "Final parse tree used for AML output:\n");
213
        DbgPrint (ASL_TREE_OUTPUT,
214
            "%*s Value    P_Op A_Op OpLen PByts Len  SubLen PSubLen OpPtr    Child    Parent   Flags    AcTyp    Final Col L\n",
215
            76, " ");
216
    }
217
218
 
219
220
 
221
        "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
222
    UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
223
224
 
225
        Op->Asl.ParseOpcode == PARSEOP_NAMESTRING ||
226
        Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
227
    {
228
        DbgPrint (ASL_TREE_OUTPUT,
229
            "%10.32s      ", Op->Asl.ExternalName);
230
    }
231
    else
232
    {
233
        DbgPrint (ASL_TREE_OUTPUT, "                ");
234
    }
235
236
 
237
    "%08X %04X %04X %01X     %04X  %04X %04X   %04X    %08X %08X %08X %08X %08X %04X  %02d  %02d\n",
238
            /* 1  */ (UINT32) Op->Asl.Value.Integer,
239
            /* 2  */ Op->Asl.ParseOpcode,
240
            /* 3  */ Op->Asl.AmlOpcode,
241
            /* 4  */ Op->Asl.AmlOpcodeLength,
242
            /* 5  */ Op->Asl.AmlPkgLenBytes,
243
            /* 6  */ Op->Asl.AmlLength,
244
            /* 7  */ Op->Asl.AmlSubtreeLength,
245
            /* 8  */ Op->Asl.Parent ? Op->Asl.Parent->Asl.AmlSubtreeLength : 0,
246
            /* 9  */ Op,
247
            /* 10 */ Op->Asl.Child,
248
            /* 11 */ Op->Asl.Parent,
249
            /* 12 */ Op->Asl.CompileFlags,
250
            /* 13 */ Op->Asl.AcpiBtype,
251
            /* 14 */ Op->Asl.FinalAmlLength,
252
            /* 15 */ Op->Asl.Column,
253
            /* 16 */ Op->Asl.LineNumber);
254
255
 
256
257
 
258
    return (AE_OK);
259
}
260
261
 
262
 
263
 *
264
 * FUNCTION:    CgLocalWriteAmlData
265
 *
266
 * PARAMETERS:  Op              - Current parse op
267
 *              Buffer          - Buffer to write
268
 *              Length          - Size of data in buffer
269
 *
270
 * RETURN:      None
271
 *
272
 * DESCRIPTION: Write a buffer of AML data to the AML output file.
273
 *
274
 ******************************************************************************/
275
276
 
277
CgLocalWriteAmlData (
278
    ACPI_PARSE_OBJECT       *Op,
279
    void                    *Buffer,
280
    UINT32                  Length)
281
{
282
283
 
284
285
 
286
287
 
288
289
 
290
    {
291
        Op->Asl.FinalAmlLength += Length;
292
    }
293
}
294
295
 
296
 
297
 *
298
 * FUNCTION:    CgWriteAmlOpcode
299
 *
300
 * PARAMETERS:  Op            - Parse node with an AML opcode
301
 *
302
 * RETURN:      None.
303
 *
304
 * DESCRIPTION: Write the AML opcode corresponding to a parse node.
305
 *
306
 ******************************************************************************/
307
308
 
309
CgWriteAmlOpcode (
310
    ACPI_PARSE_OBJECT       *Op)
311
{
312
    UINT8                   PkgLenFirstByte;
313
    UINT32                  i;
314
    union {
315
        UINT16                  Opcode;
316
        UINT8                   OpcodeBytes[2];
317
    } Aml;
318
    union {
319
        UINT32                  Len;
320
        UINT8                   LenBytes[4];
321
    } PkgLen;
322
323
 
324
 
325
326
 
327
    {
328
        return;
329
    }
330
331
 
332
    {
333
    case AML_UNASSIGNED_OPCODE:
334
335
 
336
337
 
338
        fprintf (stderr, "Found a node with an unassigned AML opcode\n");
339
        return;
340
341
 
342
343
 
344
345
 
346
        break;
347
348
 
349
350
 
351
        break;
352
353
 
354
        Aml.Opcode = Op->Asl.AmlOpcode;
355
        break;
356
    }
357
358
 
359
 
360
    {
361
    case AML_PACKAGE_LENGTH:
362
363
 
364
365
 
366
        break;
367
368
 
369
370
 
371
372
 
373
        {
374
            /* Write the high byte first */
375
376
 
377
        }
378
379
 
380
381
 
382
383
 
384
        break;
385
    }
386
387
 
388
389
 
390
    {
391
        if (Op->Asl.AmlPkgLenBytes == 1)
392
        {
393
            /* Simplest case -- no bytes to follow, just write the count */
394
395
 
396
        }
397
        else if (Op->Asl.AmlPkgLenBytes != 0)
398
        {
399
            /*
400
             * Encode the "bytes to follow" in the first byte, top two bits.
401
             * The low-order nybble of the length is in the bottom 4 bits
402
             */
403
            PkgLenFirstByte = (UINT8)
404
                (((UINT32) (Op->Asl.AmlPkgLenBytes - 1) << 6) |
405
                (PkgLen.LenBytes[0] & 0x0F));
406
407
 
408
409
 
410
             * Shift the length over by the 4 bits we just stuffed
411
             * in the first byte
412
             */
413
            PkgLen.Len >>= 4;
414
415
 
416
417
 
418
            {
419
                CgLocalWriteAmlData (Op, &PkgLen.LenBytes[i], 1);
420
            }
421
        }
422
    }
423
424
 
425
    {
426
    case AML_BYTE_OP:
427
428
 
429
        break;
430
431
 
432
433
 
434
       break;
435
436
 
437
438
 
439
        break;
440
441
 
442
443
 
444
        break;
445
446
 
447
448
 
449
        break;
450
451
 
452
        /* All data opcodes must appear above */
453
        break;
454
    }
455
}
456
457
 
458
 
459
 *
460
 * FUNCTION:    CgWriteTableHeader
461
 *
462
 * PARAMETERS:  Op        - The DEFINITIONBLOCK node
463
 *
464
 * RETURN:      None
465
 *
466
 * DESCRIPTION: Write a table header corresponding to the DEFINITIONBLOCK
467
 *
468
 ******************************************************************************/
469
470
 
471
CgWriteTableHeader (
472
    ACPI_PARSE_OBJECT       *Op)
473
{
474
    ACPI_PARSE_OBJECT       *Child;
475
476
 
477
 
478
479
 
480
481
 
482
483
 
484
    strncpy (TableHeader.Signature, Child->Asl.Value.String, 4);
485
486
 
487
488
 
489
    TableHeader.Revision = (UINT8) Child->Asl.Value.Integer;
490
491
 
492
493
 
494
    {
495
        TableHeader.Revision = Gbl_RevisionOverride;
496
    }
497
498
 
499
500
 
501
    strncpy (TableHeader.OemId, Child->Asl.Value.String, 6);
502
503
 
504
505
 
506
    strncpy (TableHeader.OemTableId, Child->Asl.Value.String, 8);
507
508
 
509
510
 
511
    TableHeader.OemRevision = (UINT32) Child->Asl.Value.Integer;
512
513
 
514
515
 
2216 Serge 516
1498 serge 517
 
518
519
 
2216 Serge 520
1498 serge 521
 
522
523
 
524
    TableHeader.Checksum = 0;
525
526
 
527
}
528
529
 
530
 
531
 *
532
 * FUNCTION:    CgCloseTable
533
 *
534
 * PARAMETERS:  None.
535
 *
536
 * RETURN:      None.
537
 *
538
 * DESCRIPTION: Complete the ACPI table by calculating the checksum and
539
 *              re-writing the header.
540
 *
541
 ******************************************************************************/
542
543
 
544
CgCloseTable (
545
    void)
546
{
547
    signed char         Sum;
548
    UINT8               FileByte;
549
550
 
551
 
552
    Sum = 0;
553
554
 
555
556
 
557
    {
558
        Sum = (signed char) (Sum + FileByte);
559
    }
560
561
 
562
563
 
564
565
 
566
    CgLocalWriteAmlData (NULL, &TableHeader, sizeof (ACPI_TABLE_HEADER));
567
}
568
569
 
570
 
571
 *
572
 * FUNCTION:    CgWriteNode
573
 *
574
 * PARAMETERS:  Op            - Parse node to write.
575
 *
576
 * RETURN:      None.
577
 *
578
 * DESCRIPTION: Write the AML that corresponds to a parse node.
579
 *
580
 ******************************************************************************/
581
582
 
583
CgWriteNode (
584
    ACPI_PARSE_OBJECT       *Op)
585
{
586
    ASL_RESOURCE_NODE       *Rnode;
587
588
 
589
 
590
    /* TBD: this may not be the best place for this check */
591
592
 
593
        (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)     ||
594
        (Op->Asl.ParseOpcode == PARSEOP_INCLUDE)      ||
595
        (Op->Asl.ParseOpcode == PARSEOP_INCLUDE_END))
596
    {
597
        return;
598
    }
599
600
 
601
602
 
603
    {
604
    case AML_RAW_DATA_BYTE:
605
    case AML_RAW_DATA_WORD:
606
    case AML_RAW_DATA_DWORD:
607
    case AML_RAW_DATA_QWORD:
608
609
 
610
        return;
611
612
 
613
 
614
615
 
616
        return;
617
618
 
619
 
620
621
 
622
        while (Rnode)
623
        {
624
            CgLocalWriteAmlData (Op, Rnode->Buffer, Rnode->BufferLength);
625
            Rnode = Rnode->Next;
626
        }
627
        return;
628
629
 
630
        /* Internal data opcodes must all appear above */
631
        break;
632
    }
633
634
 
635
    {
636
    case PARSEOP_DEFAULT_ARG:
637
638
 
639
640
 
641
642
 
643
        break;
644
645
 
646
    case PARSEOP_NAMESTRING:
647
    case PARSEOP_METHODCALL:
648
649
 
650
        break;
651
652
 
653
654
 
655
        break;
656
    }
657
}
658