-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
cspec.xml
1967 lines (1966 loc) · 65.7 KB
/
cspec.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<article>
<info>
<title>Compiler Specification</title>
</info>
<sect1>
<title>Overview</title>
<para>
The <emphasis>compiler specification</emphasis> is a required part of
a Ghidra language module for supporting disassembly and analysis of a
particular processor. Its purpose is to encode information about a
target binary which is specific to the compiler that generated that
binary. Within Ghidra, the SLEIGH specification allows the decoding of
machine instructions for a particular processor, like Intel x86, but
more than one compiler can produce those instructions. For a
particular target binary, understanding details about the specific
compiler used to build it is important to the reverse engineering
process. The compiler specification fills this need, allowing concepts like parameter
passing conventions and stack mechanisms to be formally described.
</para>
<para>
A compiler specification is a single file contained in a
module's <computeroutput>data/languages</computeroutput> directory
with a ".cspec" suffix. There may be more than one ".cspec" file in
the directory, if Ghidra supports multiple compilers for the same processor. The
compiler specification is identified by the 5th field of
Ghidra's <emphasis>processor id</emphasis>. The id is explicitly
linked with the ".cspec" by adding a tag in the root ".ldefs" file for
the processor, also in the same directory.
<example>
Defining the processor id <code>x86:LE:32:default:gcc</code>
and associating it with the file <code>x86gcc.cspec</code>
<programlisting>
<language_definitions>
...
<language processor="x86"
endian="little"
size="32"
variant="default"
version="2.3"
slafile="x86.sla"
processorspec="x86.pspec"
manualindexfile="../manuals/x86.idx"
id="x86:LE:32:default">
<description>Intel/AMD 32-bit x86</description>
<compiler name="Visual Studio" spec="x86win.cspec" id="windows"/>
<emphasis role="bold"><compiler name="gcc" spec="x86gcc.cspec" id="gcc"/></emphasis>
<compiler name="Borland" spec="x86borland.cspec" id="borland"/>
</language>
...
</language_definitions>
</programlisting>
</example>
</para>
<para>
A compiler specification is just an XML file, so it needs to start
with the usual XML directive and it always
has <code><compiler_spec></code> as the root XML tag. All
specific compiler features are described using subtags to this tag. In
principle, all the subtags are optional except
the <code><default_prototype></code> tag, but there is generally a
minimum set of tags that are needed to create a useful specification
(See ???). In general, the subtags can appear in any order. The only
exceptions are that tags which define names,
like <code><prototype></code>, must appear before other tags
which use that name.
</para>
<para>
The rest of this document is broken up into sections that roughly correspond with aspects of
compiler design, and then subsections within these address particular tags.
</para>
<sect2 id="varnode_tag">
<title>Varnode Tags</title>
<para>Many parts of the compiler specification use tags that describe a single varnode. Since architectures
frequently name many of their registers or special memory locations, it is convenient for the specification
designer to be able to use these names. But in some cases there is no name and the designer must fall
back on the defining triple for a varnode: an <emphasis>address space</emphasis>, an
<emphasis>offset</emphasis> and a <emphasis>size</emphasis>. Hence there are really two different
XML tags that are used to describe varnodes and both are referred to as a
<emphasis role="bold">varnode tag</emphasis>.
</para>
<para>
The <code><register></code> tag is used to specify formally named registers, usually defined by
the SLEIGH specification for the processor. The name must be given in a <emphasis>name</emphasis> attribute
for the tag.
</para>
<para>
The <code><varnode></code> tag is used to generically describe any varnode. It must take
three attributes:
<emphasis>space</emphasis> is a formal name of the address space containing the varnode,
<emphasis>offset</emphasis> is an unsigned integer specifying the byte offset of the varnode
within the space, and <emphasis>size</emphasis> is an integer specifying the size of the varnode in bytes.
The <code><varnode></code> tag can be used to describe any varnode, including named registers, global
RAM locations, and stack locations. For stack locations, the offset is interpreted relative to the
function that is being decompiled or is otherwise in scope. An offset of 0, for instance typically refers
to the memory location on the stack being pointed to by the formal stack pointer register, upon entry
to the function being analyzed.
</para>
<example>
<programlisting>
<register name="EAX"/>
<register name="r1"/>
<varnode space="ram" offset="0x1020" size="4"/>
<varnode space="stack" offset="8" size="8"/>
<varnode space="stack" offset="0xfffffff8" size="2"/>
<varnode space="register" offset="0" size="1"/>
</programlisting>
</example>
</sect2>
</sect1>
<sect1 id="cspec_pcodeinterp">
<title>Compiler Specific P-code Interpretation</title>
<sect2>
<title><context_data></title>
<para>
<table xml:id="context_data.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code><context_set></code></td>
<td/>
<td>(0 or more) Set a context variable across a region of memory</td>
</tr>
<tr>
<td align='right'><code><tracked_set></code></td>
<td/>
<td>(0 or more) Set default value of register</td>
</tr>
</tbody>
</table>
</para>
<para>
A <code><context_data></code> tag consists of zero or more <code><context_set></code>
and <code><tracked_set></code> subtags, which allow certain values to be assumed by analysis.
</para>
<sect3>
<title><context_set></title>
<para>
<table xml:id="context_set.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code>space</code></td>
<td></td>
<td>Name of address space</td>
</tr>
<tr>
<td align='right'><code>first</code></td>
<td></td>
<td>(Optional) Starting offset of range</td>
</tr>
<tr>
<td align='right'><code>last</code></td>
<td></td>
<td>(Optional) Ending offset of range</td>
</tr>
</tbody>
<tbody>
<tr>
<td align='right'><code><set></code></td>
<td/>
<td>Specify the context variable and the new value</td>
</tr>
<tr>
<td/>
<td><code>name</code></td>
<td>Name of the context variable</td>
</tr>
<tr>
<td/>
<td><code>val</code></td>
<td>Integer value being set</td>
</tr>
<tr>
<td/>
<td><code>description</code></td>
<td>(Optional) Description of what is set</td>
</tr>
</tbody>
</table>
</para>
<para>
A <code><context_set></code> tag sets a SLEIGH context variable over a specified address range.
This potentially affects how instructions are disassembled within that range. This is more
commonly used in the <emphasis>processor specification</emphasis> file but can also be used
here for specific compilers.
The attributes <code>space</code>, <code>first</code>, and <code>last</code> describe the range.
Omitting <code>first</code> and/or <code>last</code> causes the range to start at the beginning
and/or run to the end of the address space respectively.
The <code><set></code> subtag describes the variable and its setting.
</para>
<example>
<programlisting>
<context_data>
<context_set space="ram">
<set name="mode16" val="1" description="Set 16-bit mode across all of ram"/>
</context_set>
</contextdata>
</programlisting>
</example>
</sect3>
<sect3>
<title><tracked_set></title>
<para>
<table xml:id="tracked_set.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code>space</code></td>
<td></td>
<td>Name of address space</td>
</tr>
<tr>
<td align='right'><code>first</code></td>
<td></td>
<td>(Optional) Starting offset of range</td>
</tr>
<tr>
<td align='right'><code>last</code></td>
<td></td>
<td>(Optional) Ending offset of range</td>
</tr>
</tbody>
<tbody>
<tr>
<td align='right'><code><set></code></td>
<td/>
<td>Specify the register and the new value</td>
</tr>
<tr>
<td/>
<td><code>name</code></td>
<td>Name of the register</td>
</tr>
<tr>
<td/>
<td><code>val</code></td>
<td>Integer value being set</td>
</tr>
<tr>
<td/>
<td><code>description</code></td>
<td>(Optional) Description of what is set</td>
</tr>
</tbody>
</table>
</para>
<para>
A <code><tracked_set></code> tag informs the decompiler that a register takes a specific value
for any function whose entry point is in the indicated range. Compilers sometimes know or assume that
registers have specific values coming into a function it produces. This tag allows the decompiler to
make the same assumption and possibly use constant propagation to make further simplifications.
</para>
<example>
<programlisting>
<context_data>
<tracked_set space="ram">
<set name="spsr" val="0"/>
</tracked_set>
</context_data>
</programlisting>
</example>
</sect3>
</sect2>
<sect2>
<title><callfixup></title>
<para>
<table xml:id="callfixup.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code>name</code></td>
<td></td>
<td>The identifier for this callfixup</td>
</tr>
</tbody>
<tbody>
<tr>
<td align='right'><code><target></code></td>
<td/>
<td>(0 or more) Map this callfixup to a specific symbol</td>
</tr>
<tr>
<td></td>
<td><code>name</code></td>
<td>The specific symbol name</td>
</tr>
<tr>
<td align='right'><code><pcode></code></td>
<td/>
<td>Description of p-code to inject.</td>
</tr>
</tbody>
</table>
</para>
<sect3>
<title><pcode></title>
<para>
<table xml:id="pcode.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code>paramshift</code></td>
<td></td>
<td>(Optional) Integer for shifting parameters at the callpoint.</td>
</tr>
</tbody>
<tbody>
<tr>
<td align='right'><code><body></code></td>
<td/>
<td>P-code to inject.</td>
</tr>
<tr>
<td></td>
<td><code><emphasis>text</emphasis></code></td>
<td></td>
</tr>
</tbody>
</table>
</para>
</sect3>
<para>
Compilers frequently make use of special bookkeeping functions that are really internal to the
compiler and not a direct reflection of functions in the original source code. During analysis
it can be helpful to replace a call to such a function with a snippet of p-code
that inlines the behavior, or a portion of the behavior, so that the decompiler can use it
during its simplification rather than displaying it as an opaque call.
A typical use is to inline <emphasis>prologue</emphasis> functions that help set up a stack frame.
</para>
<para>
The <code>name</code> attribute can be used to identify the callfixup
within the Ghidra CodeBrowser and manually force certain functions to
be replaced. The <code>name</code> attribute of
the <code><callfixup></code> tag and any
optional <code><target></code> subtags identify function names
which will <emphasis>automatically</emphasis> be replaced.
</para>
<para>
The text of the <code><body></code> subtag is fed directly to
the SLEIGH semantic expression parser to create the p-code snippet.
Identifiers are interpreted as formal registers, if the register exists,
but are otherwise interpreted as temporary registers in the <emphasis>unique</emphasis> space
of the processor. Its usually best to surround text with the XML <![CDATA[ construct.
</para>
<example>
<programlisting>
<callfixup name="get_pc_thunk_bx">
<target name="__i686.get_pc_thunk.bx"/>
<pcode>
<body><![CDATA[
EBX = * ESP;
ESP = ESP + 4;
]]></body>
</pcode>
</callfixup>
</programlisting>
</example>
</sect2>
<sect2>
<title><callotherfixup></title>
<para>
<table xml:id="callotherfixup.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code>targetop</code></td>
<td></td>
<td>Name of the <emphasis>CALLOTHER</emphasis> operator to inject.</td>
</tr>
</tbody>
<tbody>
<tr>
<td align='right'><code><pcode></code></td>
<td/>
<td>Description of p-code to inject.</td>
</tr>
</tbody>
</table>
</para>
<sect3>
<title><pcode></title>
<para>
<table xml:id="pcodeother.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code><input></code></td>
<td/>
<td>(0 or more) Description of formal input parameter.</td>
</tr>
<tr>
<td/>
<td><code>name</code></td>
<td>Name of the specific input symbol.</td>
</tr>
<tr>
<td/>
<td><code>size</code></td>
<td>Expected size of the parameter in bytes.</td>
</tr>
<tr>
<td align='right'><code><output></code></td>
<td/>
<td>(0 or more) Description of formal output parameter.</td>
</tr>
<tr>
<td/>
<td><code>name</code></td>
<td>Name of the specific output symbol.</td>
</tr>
<tr>
<td/>
<td><code>size</code></td>
<td>Expected size of output in bytes.</td>
</tr>
<tr>
<td align='right'><code><body></code></td>
<td/>
<td>P-code to inject.</td>
</tr>
<tr>
<td></td>
<td><code><emphasis>text</emphasis></code></td>
<td></td>
</tr>
</tbody>
</table>
</para>
</sect3>
<para>
The <code><callotherfixup></code> is similar to a <code><callfixup></code> tag but is used to describe
injections that replace user-defined p-code operations, rather than <code>CALL</code> operations. User-defined
p-code operations, referred to generically as <code>CALLOTHER</code> operations, are <emphasis>black-box</emphasis>
operations that a SLEIGH specification can define to encapsulate complicated (or esoteric) actions performed
by the processor. The specification must define a unique name for each such operation. The <code>targetop</code>
attribute links the p-code described here to the specific operation via this name.
</para>
<para>
As with any p-code operation,
the <code>CALLOTHER</code> takes formal varnodes as inputs and/or outputs. These varnodes can be referred to
in the injection <code><body></code> by predefining them using <code><input></code> or
<code><output></code> tags. The sequence of <code><input></code> tags correspond in order to the
input parameters of the <code>CALLOTHER</code>, and a <code><output></code> tag corresponds to output varnode
if present. The tags listed here <emphasis role="bold">must</emphasis> match the number of input and output
parameters in the actual p-code operation, or an exception will be thrown during p-code generation. The optional
<code>size</code> attribute in each tag will, if present, impose a size restriction on the parameter as well.
</para>
<para>
As with a <code><callfixup></code>, the <code><body></code> tag is fed straight to the SLEIGH semantic
parser. It can refer to registers via their symbolic name defined in SLEIGH, it can refer to the operator parameters
via their <code><input></code> or <code><output></code> names, and it can also refer to
<code>inst_start</code>, <code>inst_next</code> and <code>inst_next2</code> as addresses describing the instruction
containing the <code>CALLOTHER</code>.
</para>
<example>
<programlisting>
<callotherfixup targetop="saturate">
<pcode>
<input name="in1" size="4"/>
<input name="in2" size="4"/>
<body><![CDATA[
in1 = in1 + in2;
if (in1 < 0x10000) goto <end>;
in1 = 0xffff;
<end>
]]></body>
</pcode>
</callotherfixup>
</programlisting>
</example>
</sect2>
<sect2>
<title><prefersplit></title>
<para>
<table xml:id="prefersplit.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'>style</td>
<td></td>
<td>Strategy for splitting: <emphasis>inhalf</emphasis></td>
</tr>
</tbody>
<tbody>
<tr>
<td align='right'><emphasis><register> or <varnode></emphasis></td>
<td></td>
<td>(1 or more) <emphasis>varnode</emphasis> tags</td>
</tr>
</tbody>
</table>
</para>
<para>
This tag is designed to mark specific registers as <emphasis>packed</emphasis>,
containing multiple logical values that need to be split. The decompiler attempts
to split up any operator that reads or writes the register into multiple
p-code operations that operate on each logical value individually.
</para>
<para>
The tag lists one or more <emphasis role="bold">varnode tags</emphasis> describing the
registers or other storage locations that need to be split. The <emphasis>style</emphasis>
attribute indicates how the storage locations should be split. Currently the only accepted
style value is "inhalf", which means that each varnode should be split into two equal pieces.
</para>
<para>
Splitting a varnode is only possible if the all p-code operations it is involved in don't
mix their action across the logical pieces. If this is not possible, the p-code will
not be altered for that particular varnode.
</para>
<example>
<programlisting>
<prefersplit style="inhalf">
<register name="xr0"/>
<register name="xr1"/>
<register name="xr2"/>
<prefersplit>
</programlisting>
</example>
</sect2>
<sect2>
<title><aggressivetrim></title>
<para>
<table xml:id="aggressive.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'>signext</td>
<td></td>
<td>(Optional) <emphasis>true</emphasis> if sign-extension should be aggressively trimmed</td>
</tr>
</tbody>
</table>
</para>
<para>
This tag tells the decompiler that p-code extension operations are likely to be a side-effect
of the processor and are obscuring what is just the manipulation of the smaller logical value.
The decompiler normally trims extensions and other operations where it can prove that the
most significant bytes of the result are unused. This tag lets the decompiler be more
aggressive when use of the extended bytes is more indeterminate. It can assume that extensions into
sub-function parameters and into the return value are extraneous.
</para>
<para>
The <emphasis>signext</emphasis> attribute turns the behavior on specifically for the sign-extension
operation. Currently there is no toggle for zero-extensions.
</para>
<example>
<programlisting>
<aggressivetrim signext="true"/>
</programlisting>
</example>
</sect2>
</sect1>
<sect1 id="cspec_dataorg">
<title>Compiler Datatype Organization</title>
<sect2>
<title><data_organization></title>
<para>
<table xml:id="data_org.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code><absolute_max_alignment></code></td>
<td/>
<td>(Optional) Maximum alignment possible across all datatypes (0 indicates no maximum)</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><machine_alignment></code></td>
<td/>
<td>(Optional) Maximum useful alignment for the underlying architecture</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><default_alignment></code></td>
<td/>
<td>(Optional) Default alignment for any datatype that isn't structure, union, array, or pointer and whose
size isn't in the size/alignment map</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><default_pointer_alignment></code></td>
<td/>
<td>(Optional) Default alignment for a pointer that doesn't have a size</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><pointer_size></code></td>
<td/>
<td>(Optional) Size of a pointer</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><pointer_shift></code></td>
<td/>
<td>(Optional) Left-shift amount, in bits, for shifted pointer datatypes</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><wchar_size></code></td>
<td/>
<td>(Optional) Size of "wchar", the wide character datatype</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><short_size></code></td>
<td/>
<td>(Optional) Size of "short" and other short integer datatypes</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><integer_size></code></td>
<td/>
<td>(Optional) Size of "int" and other integer datatypes</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><long_size></code></td>
<td/>
<td>(Optional) Size of "long" and other long integer datatypes</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><long_long_size></code></td>
<td/>
<td>(Optional) Size of "longlong" integer datatypes</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><float_size></code></td>
<td/>
<td>(Optional) Size of "float" and other floating-point datatypes</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><double_size></code></td>
<td/>
<td>(Optional) Size of "double" and other double precision floating-point datatypes</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><long_double_size></code></td>
<td/>
<td>(Optional) Size of "longdouble" floating-point datatypes</td>
</tr>
<tr>
<td></td>
<td><code>value</code></td>
<td></td>
</tr>
<tr>
<td align='right'><code><size_alignment_map></code></td>
<td/>
<td>(Optional) Size to alignment map</td>
</tr>
</tbody>
</table>
</para>
<para>
The <code><data_organization></code> tag provides information
about the sizes of core datatypes and how the compiler typically
aligns datatypes. These are required so analysis can determine the
proper in-memory layout of datatypes, such as those described by C/C++
style header files. Both sizes and alignments are specified
in bytes by using the integer <code>value</code> attribute in the
corresponding tag. An alignment value indicates that the compiler
chooses a byte address that is a multiple of that value as the start
of that datatype. A value of 1 indicates <emphasis>no
alignment</emphasis>. Most atomic datatypes get their alignment
information from the
<code><size_alignment_map></code>. If the size of a particular datatype
isn't listed in the map, the <code><default_alignment></code> value
will be used.
</para>
<sect3>
<title><size_alignment_map></title>
<para>
<table xml:id="size_align.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code><entry></code></td>
<td/>
<td>(0 or more) Alignment information for a particular size</td>
</tr>
<tr>
<td></td>
<td><code>size</code></td>
<td>Size of datatype in bytes</td>
</tr>
<tr>
<td></td>
<td><code>alignment</code></td>
<td>The alignment value</td>
</tr>
</tbody>
</table>
</para>
<para>
Each <code><entry></code> maps a specific size to a specific alignment. Ghidra satisfies requests
for the alignment of all atomic datatypes (except pointers) by consulting this map. If it doesn't
contain the particular size, Ghidra reverts to the <code><default_alignment></code> subtag
in the parent <code><data_organization></code> tag. Its typical to only provide alignments
for sizes which are a power of 2.
</para>
</sect3>
<example>
<programlisting>
<data_organization>
<absolute_max_alignment value="0" />
<machine_alignment value="2" />
<default_alignment value="1" />
<default_pointer_alignment value="4" />
<pointer_size value="4" />
<wchar_size value="4" />
<short_size value="2" />
<integer_size value="4" />
<long_size value="4" />
<long_long_size value="8" />
<float_size value="4" />
<double_size value="8" />
<long_double_size value="12" />
<size_alignment_map>
<entry size="1" alignment="1" />
<entry size="2" alignment="2" />
<entry size="4" alignment="4" />
<entry size="8" alignment="4" />
</size_alignment_map>
</data_organization>
</programlisting>
</example>
</sect2>
<sect2>
<title><enum></title>
<para>
<table xml:id="enum.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code>size</code></td>
<td/>
<td>Default size of an enumerated datatype</td>
</tr>
<tr>
<td align='right'><code>signed</code></td>
<td/>
<td>(Optional) <emphasis>true</emphasis> or <emphasis>false</emphasis> : Is an enumeration viewed as a signed integer</td>
</tr>
</tbody>
</table>
</para>
<para>
This is a <emphasis role="bold">deprecated</emphasis> tag.
</para>
</sect2>
<sect2>
<title><funcptr></title>
<para>
<table xml:id="funcptr.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code>align</code></td>
<td/>
<td>Number of alignment bytes for functions</td>
</tr>
</tbody>
</table>
</para>
<para>
Some compilers rely on the alignment of code addresses to provide extra bits of space
in function pointers where extra internal information can be stored. On ARM chips in particular,
the processor itself supports an ARM/THUMB transition bit in code addresses, which are always at
least 2 byte aligned. This tag informs the decompiler of this region of encoding in function pointers
so that it can filter it out, allowing it to find the correct address in various situations. The
<code>align</code> attribute should always be a power of 2 corresponding to the number of bits
a compiler might use for additional storage.
</para>
<example>
<programlisting>
<funcptr align="2"/>
</programlisting>
</example>
</sect2>
</sect1>
<sect1 id="cspec_scopememory">
<title>Compiler Scoping and Memory Access</title>
<sect2>
<title><global></title>
<para>
<table xml:id="global.htmltable" frame="above" width="80%" rules="groups">
<col width="23%"/>
<col width="15%"/>
<col width="61%"/>
<thead>
<tr>
<td align='center' colspan='2'><emphasis role="bold">Attributes and Children</emphasis></td>
<td/>
</tr>
</thead>
<tbody>
<tr>
<td align='right'><code><register></code></td>
<td/>
<td>(0 or more) Specific register to be marked as global</td>
</tr>
<tr>
<td/>
<td><code>name</code></td>
<td>Name of register</td>
</tr>
<tr>
<td align='right'><code><range></code></td>
<td/>
<td>(0 or more) Range of addresses to be marked as global</td>
</tr>
<tr>
<td/>
<td><code>space</code></td>
<td>Address space of the global region</td>
</tr>
<tr>
<td/>
<td><code>first</code></td>
<td>(Optional) Starting offset of the region</td>
</tr>
<tr>
<td/>
<td><code>last</code></td>
<td>(Optional) Ending offset of the region</td>
</tr>
</tbody>
</table>
</para>
<para>
The <code><global></code> tag marks specific memory regions as
storage locations for the compiler's global variables. The
word <emphasis>global</emphasis> here refers to the standard scoping
concept for variables in high-level source code, meaning that the
variable or memory location is being used as permanent interfunction
storage. This tag informs the decompiler's <emphasis>discovery</emphasis>
of the scope of particular memory locations. Any location not marked as global
in this way is assumed to be local/temporary storage.
</para>