xref: /netbsd-src/sys/external/bsd/acpica/dist/tests/misc/badcode.asl (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
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 */
13DefinitionBlock ("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    // Method MTH4 does not explicitly return a value
120
121    Method (MTH4) {Return}
122    Method (MTH5) {Store (MTH4(), Local0)}
123
124    // Invalid _HID values
125
126    Device (H1)
127    {
128        Name (_HID, "*PNP0C0A")     // Illegal leading asterisk
129    }
130    Device (H2)
131    {
132        Name (_HID, "PNP")          // Too short, must be 7 or 8 chars
133    }
134    Device (H3)
135    {
136        Name (_HID, "MYDEVICE01")   // Too long, must be 7 or 8 chars
137    }
138    Device (H4)
139    {
140        Name (_HID, "acpi0001")     // non-hex chars must be uppercase
141    }
142    Device (H5)
143    {
144        Name (_HID, "PNP-123")      // HID must be alphanumeric
145    }
146    Device (H6)
147    {
148        Name (_HID, "")             // Illegal Null HID
149        Name (_CID, "")             // Illegal Null CID
150    }
151
152    // Predefined Name typechecking
153
154    Name (_PRW, 4)
155    Name (_FDI, Buffer () {0})
156
157    // Predefined Name argument count validation
158    // and return value validation
159
160    Method (_OSC, 5)
161    {
162    }
163
164    // Predefined Names that must be implemented as control methods
165
166    Name (_L01, 1)
167    Name (_E02, 2)
168    Name (_Q03, 3)
169    Name (_ON,  0)
170    Name (_INI, 1)
171    Name (_PTP, 2)
172
173    // GPE methods that cause type collision (L vs. E)
174
175    Scope (\_GPE)
176    {
177        Method (_L1D)
178        {
179        }
180        Method (_E1D)
181        {
182        }
183    }
184
185    // Predefined names that should not have a return value
186
187    Method (_FDM, 1)
188    {
189        Return (Buffer(1){0x33})
190    }
191    Method (_Q22)
192    {
193        Return ("Unexpected Return Value")
194    }
195
196    // _REG must have a corresponding Operation Region declaration
197    // within the same scope
198
199    Device (EC)
200    {
201        Method (_REG, 2)
202        {
203        }
204    }
205
206    /*
207     * Resource Descriptor error checking
208     */
209    Name (RSC1, ResourceTemplate ()
210    {
211        // Illegal nested StartDependent macros
212
213        StartDependentFn (0, 0)
214        {
215            StartDependentFn (0, 0)
216            {
217            }
218        }
219
220        // Missing EndDependentFn macro
221    })
222
223    Name (RSC2, ResourceTemplate ()
224    {
225        // AddressMin is larger than AddressMax
226        IO (Decode16,
227            0x07D0,             // Range Minimum
228            0x03E8,             // Range Maximum
229            0x01,               // Alignment
230            0x20,               // Length
231            )
232
233        // Length larger than Min/Max window size
234        Memory32 (ReadOnly,
235            0x00001000,         // Range Minimum
236            0x00002000,         // Range Maximum
237            0x00000004,         // Alignment
238            0x00002000,         // Length
239            )
240
241        // Min and Max not multiples of alignment value
242        Memory32 (ReadOnly,
243            0x00001001,         // Range Minimum
244            0x00002002,         // Range Maximum
245            0x00000004,         // Alignment
246            0x00000200,         // Length
247            )
248
249        // 10-bit ISA I/O address has a max of 0x3FF
250        FixedIO (
251            0xFFFF,             // Address
252            0x20,               // Length
253            )
254
255        // Invalid AccessSize parameter
256        Register (SystemIO,
257            0x08,               // Bit Width
258            0x00,               // Bit Offset
259            0x0000000000000100, // Address
260            0x05                // Access Size
261            )
262
263        // Invalid ResourceType (0xB0)
264        QWordSpace (0xB0, ResourceConsumer, PosDecode, MinFixed, MaxFixed, 0xA5,
265            0x0000,             // Granularity
266            0xA000,             // Range Minimum
267            0xBFFF,             // Range Maximum
268            0x0000,             // Translation Offset
269            0x2000,             // Length
270            ,, )
271
272        // AddressMin is larger than AddressMax
273        WordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
274            0x0000,             // Granularity
275            0x0200,             // Range Minimum
276            0x0100,             // Range Maximum
277            0x0000,             // Translation Offset
278            0x0100,             // Length
279            ,, , TypeStatic)
280
281        // Length larger than Min/Max window size
282        DWordSpace (0xC3, ResourceConsumer, PosDecode, MinFixed, MaxFixed, 0xA5,
283            0x00000000,         // Granularity
284            0x000C8000,         // Range Minimum
285            0x000C9000,         // Range Maximum
286            0x00000000,         // Translation Offset
287            0x00001002,         // Length
288            ,, )
289
290        // Granularity must be (power-of-two -1)
291        DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxNotFixed, NonCacheable, ReadWrite,
292            0x00000010,
293            0x40000000,
294            0xFED9FFFF,
295            0x00000000,
296            0xBECA0000)
297
298        // Address Min (with zero length) not on granularity boundary
299        QWordIO (ResourceProducer, MinFixed, MaxNotFixed, PosDecode, EntireRange,
300            0x0000000000000003, // Granularity
301            0x0000000000000B02, // Range Minimum
302            0x0000000000000C00, // Range Maximum
303            0x0000000000000000, // Translation Offset
304            0x0000000000000000, // Length
305            ,, , TypeStatic)
306
307        // Address Max (with zero length) not on (granularity boundary -1)
308        QWordMemory (ResourceProducer, PosDecode, MinNotFixed, MaxFixed, Cacheable, ReadWrite,
309            0x0000000000000001, // Granularity
310            0x0000000000100000, // Range Minimum
311            0x00000000002FFFFE, // Range Maximum
312            0x0000000000000000, // Translation Offset
313            0x0000000000000000, // Length
314            ,, , AddressRangeMemory, TypeStatic)
315
316        // Invalid combination: zero length, both Min and Max are fixed
317        DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
318            0x00000000,         // Granularity
319            0x000C8000,         // Range Minimum
320            0x000C8FFF,         // Range Maximum
321            0x00000000,         // Translation Offset
322            0x00000000,         // Length
323            ,, )
324
325        // Invalid combination: non-zero length, Min Fixed, Max not fixed
326        DWordIO (ResourceProducer, MinFixed, MaxNotFixed, PosDecode, EntireRange,
327            0x00000001,         // Granularity
328            0x000C8000,         // Range Minimum
329            0x000C8FFF,         // Range Maximum
330            0x00000000,         // Translation Offset
331            0x00000100,         // Length
332            ,, )
333
334        // Invalid combination: non-zero length, Min not Fixed, Max fixed
335        DWordIO (ResourceProducer, MinNotFixed, MaxFixed, PosDecode, EntireRange,
336            0x00000001,         // Granularity
337            0x000C8000,         // Range Minimum
338            0x000C8FFF,         // Range Maximum
339            0x00000000,         // Translation Offset
340            0x00000200,         // Length
341            ,, )
342
343        // Granularity must be zero if non-zero length, min/max fixed
344        DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
345            0x0000000F,         // Granularity
346            0x000C8000,         // Range Minimum
347            0x000C8FFF,         // Range Maximum
348            0x00000000,         // Translation Offset
349            0x00001000,         // Length
350            ,, )
351
352        // Null descriptor (intended to be modified at runtime) must
353        // have a resource tag (to allow it to be modified at runtime)
354        DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
355            0x00000000,         // Granularity
356            0x00000000,         // Range Minimum
357            0x00000000,         // Range Maximum
358            0x00000000,         // Translation Offset
359            0x00000000,         // Length
360            ,, )
361
362        // Missing StartDependentFn macro
363
364        EndDependentFn ()
365    })
366}
367
368