Home | History | Annotate | Line # | Download | only in misc
badcode.asl revision 1.1.1.2
      1 /*
      2  * badcode.asl
      3  *
      4  * This file contains examples of the extended error checking and
      5  * typechecking capabilities of the iASL compiler. Other ASL compilers
      6  * may ignore these errors completely. Note - this is not an exhaustive
      7  * list of errors detected by iASL, it shows many of the errors that
      8  * are not detected by other ASL compilers.
      9  *
     10  * To compile, use:
     11  * iasl badcode.asl
     12  */
     13 DefinitionBlock ("badcode.aml", "DSDT", 1, "Intel", "Example", 0x00000001)
     14 {
     15     Name (INT1, 0)
     16     Name (BUF1, Buffer() {0,1,2,3})
     17     Event (EVT1)
     18 
     19     // Invalid SyncLevel in Mutex declaration
     20 
     21     Mutex (MTX1, 32)
     22 
     23     // Integer beyond the table integer size (32 bits)
     24 
     25     Name (BIG, 0x1234567887654321)
     26 
     27     // CPackage length does not match initializer list length
     28 
     29     Name (PKG1, Package(5) {0,1})
     30 
     31     // Inadvertent use of single backslash in a string
     32 
     33     Name (PATH, Buffer() {"\_SB_.PCI2._CRS"})
     34 
     35     // Invalid hex escape sequence
     36 
     37     Name (ESC1, "abcdefg\x00hijklmn")
     38 
     39     // Field access beyond region bounds
     40 
     41     OperationRegion (OPR1, SystemMemory, 0x2000, 6)
     42     Field (OPR1, DWordAcc, NoLock, Preserve)
     43     {
     44         Offset (4),
     45         FLD1, 8
     46     }
     47 
     48     // Some address spaces support only ByteAcc or BufferAcc
     49 
     50     OperationRegion (OPR2, EmbeddedControl, 0x4000, 8)
     51     Field (OPR2, DWordAcc, NoLock, Preserve)
     52     {
     53         FLD2, 8
     54     }
     55     OperationRegion (OPR3, SMBus, 0x8000, 16)
     56     Field (OPR3, WordAcc, NoLock, Preserve)
     57     {
     58         FLD3, 8
     59     }
     60 
     61     // Invalid SyncLevel in method declaration
     62 
     63     Method (MTH1, 0, NotSerialized, 32)
     64     {
     65         // Invalid arguments and uninitialized locals
     66 
     67         Store (Arg3, Local0)
     68         Store (Local1, Local2)
     69 
     70         // Parameter typechecking (MTX1 is invalid type)
     71 
     72         Subtract (MTX1, 4, Local3)
     73 
     74         // Various invalid parameters
     75 
     76         CreateField (BUF1, 0, Subtract (4, 4), FLD1)
     77 
     78         // Unchecked mutex and event timeouts
     79 
     80         Acquire (MTX1, 100)
     81         Wait (EVT1, 1)
     82 
     83         // Result from operation is not used - statement has no effect
     84 
     85         Add (INT1, 8)
     86 
     87         // Unreachable code
     88 
     89         Return (0)
     90         Store (5, INT1)
     91     }
     92 
     93     Method (MTH2)
     94     {
     95         // Switch with no Case statements
     96 
     97         Switch (ToInteger (INT1))
     98         {
     99             Default
    100             {
    101             }
    102         }
    103 
    104         if (LEqual (INT1, 0))
    105         {
    106             Return (INT1)
    107         }
    108 
    109         // Fallthrough exit path does not return a value
    110     }
    111 
    112     Method (MTH3)
    113     {
    114         // Method MTH2 above does not always return a value
    115 
    116         Store (MTH2 (), Local0)
    117     }
    118 
    119     // Invalid _HID values
    120 
    121     Device (H1)
    122     {
    123         Name (_HID, "*PNP0C0A")     // Illegal leading asterisk
    124     }
    125     Device (H2)
    126     {
    127         Name (_HID, "PNP")          // Too short, must be 7 or 8 chars
    128     }
    129     Device (H3)
    130     {
    131         Name (_HID, "MYDEVICE01")   // Too long, must be 7 or 8 chars
    132     }
    133     Device (H4)
    134     {
    135         Name (_HID, "acpi0001")     // non-hex chars must be uppercase
    136     }
    137     Device (H5)
    138     {
    139         Name (_HID, "PNP-123")      // HID must be alphanumeric
    140     }
    141     Device (H6)
    142     {
    143         Name (_HID, "")             // Illegal Null HID
    144         Name (_CID, "")             // Illegal Null CID
    145     }
    146 
    147     // Predefined Name typechecking
    148 
    149     Name (_PRW, 4)
    150     Name (_FDI, Buffer () {0})
    151 
    152     // Predefined Name argument count validation
    153     // and return value validation
    154 
    155     Method (_OSC, 5)
    156     {
    157     }
    158 
    159     // Predefined Names that must be implemented as control methods
    160 
    161     Name (_L01, 1)
    162     Name (_E02, 2)
    163     Name (_Q03, 3)
    164     Name (_ON,  0)
    165     Name (_INI, 1)
    166     Name (_PTP, 2)
    167 
    168     // GPE methods that cause type collision (L vs. E)
    169 
    170     Scope (\_GPE)
    171     {
    172         Method (_L1D)
    173         {
    174         }
    175         Method (_E1D)
    176         {
    177         }
    178     }
    179 
    180     // Predefined names that should not have a return value
    181 
    182     Method (_FDM, 1)
    183     {
    184         Return (Buffer(1){0x33})
    185     }
    186     Method (_Q22)
    187     {
    188         Return ("Unexpected Return Value")
    189     }
    190 
    191     /*
    192      * Resource Descriptor error checking
    193      */
    194     Name (RSC1, ResourceTemplate ()
    195     {
    196         // Illegal nested StartDependent macros
    197 
    198         StartDependentFn (0, 0)
    199         {
    200             StartDependentFn (0, 0)
    201             {
    202             }
    203         }
    204 
    205         // Missing EndDependentFn macro
    206     })
    207 
    208     Name (RSC2, ResourceTemplate ()
    209     {
    210         // AddressMin is larger than AddressMax
    211         IO (Decode16,
    212             0x07D0,             // Range Minimum
    213             0x03E8,             // Range Maximum
    214             0x01,               // Alignment
    215             0x20,               // Length
    216             )
    217 
    218         // Length larger than Min/Max window size
    219         Memory32 (ReadOnly,
    220             0x00001000,         // Range Minimum
    221             0x00002000,         // Range Maximum
    222             0x00000004,         // Alignment
    223             0x00002000,         // Length
    224             )
    225 
    226         // Min and Max not multiples of alignment value
    227         Memory32 (ReadOnly,
    228             0x00001001,         // Range Minimum
    229             0x00002002,         // Range Maximum
    230             0x00000004,         // Alignment
    231             0x00000200,         // Length
    232             )
    233 
    234         // 10-bit ISA I/O address has a max of 0x3FF
    235         FixedIO (
    236             0xFFFF,             // Address
    237             0x20,               // Length
    238             )
    239 
    240         // Invalid AccessSize parameter
    241         Register (SystemIO,
    242             0x08,               // Bit Width
    243             0x00,               // Bit Offset
    244             0x0000000000000100, // Address
    245             0x05                // Access Size
    246             )
    247 
    248         // Invalid ResourceType (0xB0)
    249         QWordSpace (0xB0, ResourceConsumer, PosDecode, MinFixed, MaxFixed, 0xA5,
    250             0x0000,             // Granularity
    251             0xA000,             // Range Minimum
    252             0xBFFF,             // Range Maximum
    253             0x0000,             // Translation Offset
    254             0x2000,             // Length
    255             ,, )
    256 
    257         // AddressMin is larger than AddressMax
    258         WordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
    259             0x0000,             // Granularity
    260             0x0200,             // Range Minimum
    261             0x0100,             // Range Maximum
    262             0x0000,             // Translation Offset
    263             0x0100,             // Length
    264             ,, , TypeStatic)
    265 
    266         // Length larger than Min/Max window size
    267         DWordSpace (0xC3, ResourceConsumer, PosDecode, MinFixed, MaxFixed, 0xA5,
    268             0x00000000,         // Granularity
    269             0x000C8000,         // Range Minimum
    270             0x000C9000,         // Range Maximum
    271             0x00000000,         // Translation Offset
    272             0x00001002,         // Length
    273             ,, )
    274 
    275         // Granularity must be (power-of-two -1)
    276         DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxNotFixed, NonCacheable, ReadWrite,
    277             0x00000010,
    278             0x40000000,
    279             0xFED9FFFF,
    280             0x00000000,
    281             0xBECA0000)
    282 
    283         // Address Min (with zero length) not on granularity boundary
    284         QWordIO (ResourceProducer, MinFixed, MaxNotFixed, PosDecode, EntireRange,
    285             0x0000000000000003, // Granularity
    286             0x0000000000000B02, // Range Minimum
    287             0x0000000000000C00, // Range Maximum
    288             0x0000000000000000, // Translation Offset
    289             0x0000000000000000, // Length
    290             ,, , TypeStatic)
    291 
    292         // Address Max (with zero length) not on (granularity boundary -1)
    293         QWordMemory (ResourceProducer, PosDecode, MinNotFixed, MaxFixed, Cacheable, ReadWrite,
    294             0x0000000000000001, // Granularity
    295             0x0000000000100000, // Range Minimum
    296             0x00000000002FFFFE, // Range Maximum
    297             0x0000000000000000, // Translation Offset
    298             0x0000000000000000, // Length
    299             ,, , AddressRangeMemory, TypeStatic)
    300 
    301         // Invalid combination: zero length, both Min and Max are fixed
    302         DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
    303             0x00000000,         // Granularity
    304             0x000C8000,         // Range Minimum
    305             0x000C8FFF,         // Range Maximum
    306             0x00000000,         // Translation Offset
    307             0x00000000,         // Length
    308             ,, )
    309 
    310         // Invalid combination: non-zero length, Min Fixed, Max not fixed
    311         DWordIO (ResourceProducer, MinFixed, MaxNotFixed, PosDecode, EntireRange,
    312             0x00000001,         // Granularity
    313             0x000C8000,         // Range Minimum
    314             0x000C8FFF,         // Range Maximum
    315             0x00000000,         // Translation Offset
    316             0x00000100,         // Length
    317             ,, )
    318 
    319         // Invalid combination: non-zero length, Min not Fixed, Max fixed
    320         DWordIO (ResourceProducer, MinNotFixed, MaxFixed, PosDecode, EntireRange,
    321             0x00000001,         // Granularity
    322             0x000C8000,         // Range Minimum
    323             0x000C8FFF,         // Range Maximum
    324             0x00000000,         // Translation Offset
    325             0x00000200,         // Length
    326             ,, )
    327 
    328         // Granularity must be zero if non-zero length, min/max fixed
    329         DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
    330             0x0000000F,         // Granularity
    331             0x000C8000,         // Range Minimum
    332             0x000C8FFF,         // Range Maximum
    333             0x00000000,         // Translation Offset
    334             0x00001000,         // Length
    335             ,, )
    336 
    337         // Null descriptor (intended to be modified at runtime) must
    338         // have a resource tag (to allow it to be modified at runtime)
    339         DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
    340             0x00000000,         // Granularity
    341             0x00000000,         // Range Minimum
    342             0x00000000,         // Range Maximum
    343             0x00000000,         // Translation Offset
    344             0x00000000,         // Length
    345             ,, )
    346 
    347         // Missing StartDependentFn macro
    348 
    349         EndDependentFn ()
    350     })
    351 }
    352 
    353