-
Notifications
You must be signed in to change notification settings - Fork 2
/
lzsabi.tex
5183 lines (4834 loc) · 199 KB
/
lzsabi.tex
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
% © Copyright IBM Corporation 2001, 2024
% © Copyright Linux Foundation 2002
%
% SPDX-License-Identifier: GFDL-1.1-no-invariants-only
%
% s390/s390x ABI specification -- LaTeX source
%
% Permission is granted to copy, distribute and/or modify this document
% under the terms of the GNU Free Documentation License, Version 1.1; with
% no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
% Texts.
\documentclass[english,11pt,twoside,toc=bib,toc=idx]{scrreprt}
\usepackage{scrhack}
% --- Version ---
\newcommand{\Version}{1.6.1}
% --- Packages ---
\usepackage{babel}
\usepackage{graphicx}
\usepackage{array}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{threeparttable}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{makeidx}
% --- Indexing ---
\makeindex
% --- Fonts ---
\ifdefined\ifHtml\else
\usepackage{unicode-math}
\usepackage{fontspec}
\usepackage{microtype}
% Use the IBM Plex font family.
\setmainfont{IBMPlexSerif-Regular.otf}[
BoldFont = IBMPlexSerif-Bold.otf,
ItalicFont = IBMPlexSerif-Italic.otf,
BoldItalicFont = IBMPlexSerif-BoldItalic.otf]
\setsansfont{IBM Plex Sans}
\setmonofont{IBM Plex Mono}
\setkomafont{captionlabel}{%
\usekomafont{descriptionlabel}%
}
% The math font for Plex may not be packaged by all distributions (yet).
% It can be downloaded from https://github.com/IBM/plex/releases
\setmathfont{IBM Plex Math}
\fi
% --- Layout definitions ---
\KOMAoptions{paper=letter}
\KOMAoptions{DIV=13,BCOR=1cm}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\DeclareTOCStyleEntry[numwidth=2em]{default}{chapter}
\DeclareTOCStyleEntry[indent=2em,numwidth=3em]{default}{section}
\DeclareTOCStyleEntry[indent=5em,numwidth=3.5em]{default}{subsection}
\DeclareTOCStyleEntry[indent=8.5em,numwidth=4em]{default}{subsubsection}
\DeclareTOCStyleEntry[numwidth=3em]{default}{figure}
\DeclareTOCStyleEntry[numwidth=3em]{default}{table}
% --- Custom commands ---
\newcommand{\jumplabel}[1]{\textsf{‹#1›}}
\newcommand{\stackit}[2][l]{\setlength{\tabcolsep}{0mm}\begin{tabular}{#1}%
#2\end{tabular}}
\ifzseries
\newcommand{\NBITS}{64}
\newcommand{\ADDRBITS}{64}
\newcommand{\NBYTES}{8}
\newcommand{\STACKSIZE}{160}
\newcommand{\ABINAME}{s390x}
\newcommand{\ARCH}{z/\kern-1pt Ar\-chi\-tec\-ture}
\newcommand{\ARCHarch}{\ARCH}
\newcommand{\aARCH}{a \ARCH}
\newcommand{\theARCH}{the \ARCH}
\else
\newcommand{\NBITS}{32}
\newcommand{\ADDRBITS}{31}
\newcommand{\NBYTES}{4}
\newcommand{\STACKSIZE}{96}
\newcommand{\ABINAME}{s390}
\newcommand{\ARCH}{ESA/390}
\newcommand{\ARCHarch}{the \ARCH{} ar\-chi\-tec\-ture}
\newcommand{\aARCH}{an \ARCH}
\newcommand{\theARCH}{\ARCHarch}
\fi
\newenvironment{DIFnomarkup}{}{} % For latexdiff
% --- Listings ---
\usepackage{xcolor}
\definecolor{lstnumbers}{rgb}{0.5,0.5,0.5}
\usepackage{listings}
\lstset{%
basicstyle={\ttfamily\small},
numberstyle={\sffamily\footnotesize\color{lstnumbers}},
showstringspaces=false,
captionpos=b,
abovecaptionskip=2ex,
language=C}
\lstdefinestyle{float}{%
frame=single,
float=tbp}
\lstdefinestyle{embed}{%
frame=single}
\lstdefinestyle{long}{%
frame=single,
captionpos=t}
\lstdefinestyle{short}{%
aboveskip=-1.2ex,
belowskip=-\baselineskip}
\lstdefinelanguage{simpleasm}{%
comment=[l]\#,
string=[b]{"}}
% --- Hyperref ---
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=1,
breaklinks=true,pdfborder={0 0 0},backref=false,colorlinks=true]
{hyperref}
\hypersetup{linkcolor=black,pdfstartview={XYZ 0 0 1}}
\usepackage{cleveref}
% Fixed definition of \refstepcounter@noarg from cleveref.sty. This
% version fixes an endless loop with tex4ht when used together with
% listings and hyperref.
\makeatletter
\def\refstepcounter@noarg#1{%
\cref@old@refstepcounter{#1}%
\cref@constructprefix{#1}{\cref@result}%
\@ifundefined{cref@#1@alias}%
{\def\@tempa{#1}}%
{\def\@tempa{\csname cref@#1@alias\endcsname}}%
\protected@xdef\cref@currentlabel{% <-- xdef instead of edef
[\@tempa][\arabic{#1}][\cref@result]%
\csname p@#1\endcsname\csname the#1\endcsname}}%
\makeatother
% Call out figures with "figure" instead of "fig.".
\crefname{figure}{figure}{figures}
\Crefname{figure}{Figure}{Figures}
% --- TikZ support ---
\newif\ifSkipTikZ
\ifdefined\ifHtml
\SkipTikZtrue
\else
\SkipTikZfalse
\fi
\ifSkipTikZ\else % BEGIN skip TikZ
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{fit}
\usetikzlibrary{patterns}
\usetikzlibrary{positioning}
\usetikzlibrary{shadows}
\usetikzlibrary{shapes}
% --- PGF layer definitions ---
\pgfdeclarelayer{background}
% --- Misc PGF/TikZ style definitions ---
\tikzset{memory layout/.style={fill=yellow!10,draw}}
\tikzset{inactive layout/.style={text=black!60}}
% --- Style definitions for bit layout charts ---
\tikzset{bitnum/.style={text=black!60, font={\footnotesize\sffamily}}}
\tikzset{bytenum/.style={font={\footnotesize}}}
\tikzset{bitchart box/.style={fill=blue!7, draw}}
\tikzset{bitfield label/.style={}}
\tikzset{bitfield padding/.style={draw=black, very thick,
line cap=round, shorten <=0.5ex, shorten >=0.5ex,
dash pattern=on 0pt off 6pt, dash phase=3pt}}
\tikzset{>=latex}
% --- Helpers for bit layout charts ---
\newcommand{\bitchartsep} {
\draw (0, 0) -- (last SE);
}
\makeatletter
\def\one@bitchartfield#1#2{%
\pgfmathsetmacro{\xlow}{\xprev-\xfirst}
\pgfmathsetmacro{\xhigh}{#1-\xfirst}
\pgfmathtruncatemacro{\xhighminus}{#1-1}
\path (\xlow, 0) node [bitnum, above right] {\xprev};
\ifx\\#2\\
\path [bitfield padding] (\xlow, 0.5) -- (\xhigh, 0.5);
\else
\path (\xlow, 0) -- node [bitfield label,pos=0.5]
{\texttt{#2}} (\xhigh, 1);
\fi
\path (\xhigh, 0) coordinate (last SE) {}
node [bitnum, above left] {\xhighminus};
\edef\xprev{#1}}
\def\bitchartfield@n#1/#2/#3{%
\one@bitchartfield{#1}{#2}
\draw (\xlow, 0) -- (\xlow, 1);
\if,#3\let\next\bitchartfield@n\else\let\next\egroup\fi\next}
\def\bitchartfields#1 #2/#3/#4{%
\bgroup
\edef\xfirst{#1}
\let\xprev\xfirst
\one@bitchartfield{#2}{#3}
\if,#4\let\next\bitchartfield@n\else\let\next\egroup\fi\next}
\def\one@bytechartfield#1#2{%
\pgfmathsetmacro{\xlow}{8*(\prevbyte-\firstbyte)}
\pgfmathsetmacro{\xhigh}{8*(#1-\firstbyte)}
\path (\xlow, 1) node [bytenum, below right] (bnum) {\prevbyte};
\ifx\\#2\\
\path [bitfield padding] (\xhigh, 0.5) coordinate (m){} -- (bnum|-m);
\else
\path (\xlow, 0) -- node [bitfield label,pos=0.5]
{\texttt{#2}} (\xhigh, 1);
\fi
\path (\xhigh, 0) coordinate (last SE) {};
\edef\prevbyte{#1}}
\def\bytechartfield@n#1/#2/#3{%
\one@bytechartfield{#1}{#2}
\draw (\xlow, 1) -- (\xlow, 0);
\if,#3\let\next\bytechartfield@n\else\let\next\egroup\fi\next}
\def\bytechartfields#1 #2/#3/#4{%
\bgroup
\edef\firstbyte{#1}
\edef\prevbyte{#1}
\one@bytechartfield{#2}{#3}
\if,#4\let\next\bytechartfield@n\else\let\next\egroup\fi\next}
\newcommand{\bitchartbytes}[2]{%
\bgroup
\edef\first@byte{#1}
\foreach \b in {#2} {%
\pgfmathsetmacro{\bit@}{8*(\b-#1)}
\path (\bit@, 1) node [bytenum, below right] {\b};
\ifx\b\first@byte\else
\path (\bit@, 1) -- (\bit@, 0);
\fi
}
\egroup
}
\makeatother
\fi % END skip TikZ
% Hyphenation rules for compound words.
\hyphenation{big=endi-an}
\hyphenation{cia=rel-a-tive}
\hyphenation{float-ing=point}
\hyphenation{func-tion=call-ing}
\hyphenation{lit-tle=endi-an}
\hyphenation{non=ze-ro}
\hyphenation{pa-ram-e-ter=pass-ing}
\hyphenation{po-si-tion=inde-pen-dence}
\hyphenation{po-si-tion=inde-pen-dent}
\hyphenation{sig-nal=han-dling}
\hyphenation{sign=ex-tend-ed}
\hyphenation{sys-tem=sup-plied}
\hyphenation{two=el-e-ment}
\hyphenation{ze-ro=ex-tend-ed}
% ------------------------------------------------------------
\begin{document}
\newcommand{\myTitle}{ELF Application Binary Interface \ABINAME{}~Supplement}
\begin{DIFnomarkup}
\title{\myTitle}
\subtitle{Version \Version}
\author{Martin Schwidefsky\and Ulrich Weigand\and Andreas Arnez%
\and Andreas Krebbel}
\publishers{IBM\textregistered{} Corporation}
\lowertitleback{%
\noindent \textbf{\myTitle}
\noindent Version \Version
\noindent © Copyright IBM Corporation 2001, 2024
\noindent © Copyright Linux Foundation 2002
\medskip
\noindent Permission is granted to copy, distribute and/or modify
this document under the terms of the GNU Free Documentation License,
Version 1.1; with no Invariant Sections, with no Front-Cover Texts,
and with no Back-Cover Texts. A copy of the license is included in
the section entitled ``GNU Free Documentation License.''}
\maketitle
\end{DIFnomarkup}
\tableofcontents
\listoffigures
\listoftables
\lstlistoflistings
\chapter*{About This Book}
The \ABINAME{} supplement to the Executable and Linkage
Format Application Binary Interface (or ELF ABI) defines a system
interface for compiled application programs. Its purpose is to
establish a standard binary interface for application programs on
Linux\textregistered{} for \ARCH{}\textregistered{} systems.
This book is a supplement to the generic ``System V Application Binary
Interface'' and should be read in conjunction with it.
\section*{History}
\begin{description}
\item[1.6.1] Minor release to pick up a few fixes. Published at
\url{https://github.com/ibm/s390x-abi}, January 2024.
\item[1.6] Describe vector types and registers (based on input from
Andreas Krebbel); mention condition code and program mask; enhance
exception handling information. Published at
\url{https://github.com/ibm/s390x-abi}, November 2021.
\item[1.5] \emph{``ELF Application Binary Interface
\ABINAME{}~Supplement''} -- Conversion to \LaTeX{}; various
corrections to revision~1.02. Edited by Andreas Arnez. Published at
\url{https://github.com/ibm/s390x-abi}, January~2021.
\item[1.02] \emph{``{\ifzseries zSeries\else S/390\fi} ELF Application
Binary Interface Supplement''} -- Revised edition. Published under
the GNU Free Documentation License~1.1 by The Linux Foundation as a
``referenced specification'' at \url{http://refspecs.linuxbase.org/},
November 2002.
\item[1.0] \emph{``LINUX for {\ifzseries zSeries\else S/390\fi}: ELF
Application Binary Interface Supplement''} -- First edition.
Published by IBM as LNUX-1107-{\ifzseries 01\else 02\fi}, March 2001.
\end{description}
\chapter{Low-Level System Information}
\section{Machine Interface}
This section describes the processor-specific information for
\ARCH{} processors.
\subsection{Processor Architecture}
\index{processor architecture}
\index{instruction set}
{\ifzseries
\cite{sa22} (SA22-7832) defines \theARCH{}.
\else
\cite{sa22} (SA22-7201) defines \theARCH{}.
\fi}
% TODO: Explain micro-architecture levels
% - "based on editions of the z/Architecture"
Programs intended to execute directly on the processor use the
\ARCH{} instruction set and the
instruction encoding and semantics of the architecture.
An application program can assume that all instructions defined by the
architecture and that are neither privileged nor optional, exist and work
as documented.
To be ABI conforming, the processor must implement the instructions of
the architecture, perform the specified operations, and produce the
expected results. The ABI neither places performance constraints on
systems nor specifies what instructions must be implemented in
hardware. A software emulation of the architecture can conform to
the ABI\@.
{\ifzseries\else
There are some instructions in \ARCHarch{}
which are described as ``optional.'' This ABI
requires some of these to be available; in particular:
\begin{itemize}
\item additional floating-point facilities, % checksum instruction
\item compare and move extended,
\item immediate and relative instructions,
\item square root,
\item string instructions.
\end{itemize}
The ABI guarantees that these instructions are present. In order to
comply with the ABI the operating system must emulate these
instructions on machines which do not support them in the hardware.
Other instructions are not available in some current models; programs
using these instructions do not conform to the \ABINAME{} ABI and
executing them on machines without the extra capabilities will result
in undefined behavior. \fi}
In \ARCHarch{} a
processor runs in big-endian mode. (See \cref{byteordering}.)
\subsection{Data Representation}
\subsubsection{Byte Ordering}
\label{byteordering}
\index{byte ordering}
The architecture defines an 8-bit byte\index{byte},
a 16-bit halfword\index{halfword},
a 32-bit word\index{word},{\ifzseries\else{} and\fi}
a 64-bit doubleword\index{doubleword}{\ifzseries ,
and a 128-bit quadword\index{quadword}\fi}.
Byte ordering defines how the bytes that make up halfwords,
words,{\ifzseries\else{} and\fi} doublewords{\ifzseries , and
quadwords\fi} are ordered in memory. Most significant byte (MSB)
ordering, also called ``big-endian,''\index{big-endian} means that
the most significant byte
of a structure is located in the lowest addressed byte position in a
storage unit (byte 0). By contrast, least significant byte (LSB)
ordering, or ``little-endian,''\index{little-endian} refers to the
reverse byte order, where
the lowest addressed byte position holds the least significant byte.
\Crefrange{fig:halfword}{\ifzseries fig:quadwords\else
fig:doublewords\fi} illustrate the conventions for bit and byte
numbering within storage units of various widths. These conventions
apply to both integer data and floating-point data, where the most
significant byte of a floating-point value holds the sign and the
exponent (or at least the start of the exponent). The figures show
big-endian byte numbers in the upper left corners and bit numbers in
the lower corners.
\begin{figure}
\centering
\ifSkipTikZ
\begin{verbatim}
+-------------+-------------+
| 0 | 1 |
| msb | lsb |
| 0 7 | 8 15 |
+-------------+-------------+
\end{verbatim}
\else
\begin{tikzpicture}[x=1.3ex,y=3em]
\path [bitchart box] (0, 0) rectangle (16, 1);
\bitchartfields 0 8/\textrm{msb}/, 16/\textrm{lsb}/;
\bitchartbytes{0}{0,1}
\end{tikzpicture}
\fi
\caption{Bit and byte numbering in halfwords}
\label{fig:halfword}
\end{figure}
\begin{figure}
\centering
\ifSkipTikZ
\begin{verbatim}
+-------------+-------------+-------------+-------------+
| 0 | 1 | 2 | 3 |
| msb | | | lsb |
| 0 7 | 8 15 | 16 23 | 24 31 |
+-------------+-------------+-------------+-------------+
\end{verbatim}
\else
\begin{tikzpicture}[x=1.3ex,y=3em]
\path [bitchart box] (0, 0) rectangle (32, 1);
\bitchartfields 0 8/\textrm{msb}/, 16/~/, 24/~/, 32/\textrm{lsb}/;
\bitchartbytes{0}{0,...,3}
\end{tikzpicture}
\fi
\caption{Bit and byte numbering in words}
\label{fig:words}
\end{figure}
\begin{figure}
\centering
\ifSkipTikZ
\begin{verbatim}
+-------------+-------------+-------------+-------------+
| 0 | 1 | 2 | 3 |
| msb | | | |
| 0 7 | 8 15 | 16 23 | 24 31 |
+-------------+-------------+-------------+-------------+
| 4 | 5 | 6 | 7 |
| | | | lsb |
| 32 39 | 40 47 | 48 55 | 56 63 |
+-------------+-------------+-------------+-------------+
\end{verbatim}
\else
\begin{tikzpicture}[x=1.3ex,y=3em]
\path [bitchart box] (0, -1) rectangle (32, 1);
\bitchartfields 0 8/\textrm{msb}/, 16/~/, 24/~/, 32/~/;
\bitchartbytes{0}{0,...,3}
\bitchartsep
\begin{scope}[shift={(0,-1)}]
\bitchartfields 32 40/~/, 48/~/, 56/~/, 64/\textrm{lsb}/;
\bitchartbytes{4}{4,...,7}
\end{scope}
\end{tikzpicture}
\fi
\caption{Bit and byte numbering in doublewords}
\label{fig:doublewords}
\end{figure}
\ifzseries
\begin{figure}
\centering
\ifSkipTikZ
\begin{verbatim}
+-------------+-------------+-------------+-------------+
| 0 | 1 | 2 | 3 |
| msb | | | |
| 0 7 | 8 15 | 16 23 | 24 31 |
+-------------+-------------+-------------+-------------+
| 4 | 5 | 6 | 7 |
| | | | |
| 32 39 | 40 47 | 48 55 | 56 63 |
+-------------+-------------+-------------+-------------+
| 8 | 9 | 10 | 11 |
| | | | |
| 64 71 | 72 79 | 80 87 | 88 95 |
+-------------+-------------+-------------+-------------+
| 12 | 13 | 14 | 15 |
| | | | lsb |
| 96 103 | 104 111 | 112 119 | 120 127 |
+-------------+-------------+-------------+-------------+
\end{verbatim}
\else
\begin{tikzpicture}[x=1.3ex,y=3.2em]
\path [bitchart box] (0, -3) rectangle (32, 1);
\bitchartfields 0 8/\textrm{msb}/, 16/~/, 24/~/, 32/~/;
\bitchartbytes{0}{0,...,3}
\bitchartsep
\begin{scope}[shift={(0,-1)}]
\bitchartfields 32 40/~/, 48/~/, 56/~/, 64/~/;
\bitchartbytes{4}{4,...,7}
\bitchartsep
\end{scope}
\begin{scope}[shift={(0,-2)}]
\bitchartfields 64 72/~/, 80/~/, 88/~/, 96/~/;
\bitchartbytes{8}{8,...,11}
\bitchartsep
\end{scope}
\begin{scope}[shift={(0,-3)}]
\bitchartfields 96 104/~/, 112/~/, 120/~/, 128/\textrm{lsb}/;
\bitchartbytes{12}{12,...,15}
\end{scope}
\end{tikzpicture}
\fi
\caption{Bit and byte numbering in quadwords}
\label{fig:quadwords}
\end{figure}
\fi
\subsubsection{Fundamental Types}
\index{type!scalar}
\Cref{tab:scalar} shows how ISO C scalar types correspond to those of
\aARCH{} processor. To comply with this ABI, objects stored in memory
must be aligned\index{alignment!scalar} as indicated, even though the
architecture permits unaligned storage operands for most instructions.
For all types, a null pointer\index{null pointer} has the value zero (binary).
A Boolean\index{Boolean} object is represented in memory as a single byte
with a value of 0 or 1. If a byte with any other value is evaluated as a
Boolean, the behavior is undefined.
For each binary floating-point type, there is a corresponding complex
type\index{complex type}. It is represented as a two-element array with
the real part as its first and the imaginary part as its second element.
Some C dialects permit enumeration constants that exceed the range of an
\texttt{int}. Then the enumeration type\index{enumeration type} shall be
encoded as the smallest unsigned or signed C integer type that can
represent all of its enumeration constants and is not smaller than
\texttt{int}.
\begin{table}
\centering
\begin{DIFnomarkup}
\begin{threeparttable}
\begin{tabularx}{\textwidth}{XlrrX}
\toprule
\multirow{2}{*}{Type}
& \multirow{2}{*}{ISO C}
& Size in & Align- & \ARCH{} \\
&
& bytes & ment & type \\
\midrule
\multirow{8}{\hsize}{Unsigned integer}
& \texttt{\_Bool} & 1 & 1
& \multirow{8}{\hsize}{$n$-bit unsigned binary integer\tnote{\dagger}}
\\
& \texttt{unsigned char} & 1 & 1 \\
& \texttt{char} & 1 & 1 \\
& \texttt{unsigned short} & 2 & 2 \\
& \texttt{unsigned int} & 4 & 4 \\
& \texttt{unsigned long} & \NBYTES{} & \NBYTES{} \\
& \texttt{unsigned long long} & 8 & 8 \\
& \texttt{unsigned \_\_int128}\tnote{\dagger\dagger} & 16 & 8 \\
\midrule
\multirow{12}{\hsize}{Signed integer}
& \texttt{signed char} & 1 & 1
& \multirow{12}{\hsize}{$n$-bit signed binary integer\tnote{\dagger}}
\\
& \texttt{signed short} & 2 & 2 \\
& \texttt{short} & 2 & 2 \\
& \texttt{signed int} & 4 & 4 \\
& \texttt{int} & 4 & 4 \\
& \texttt{enum} & 4 & 4 \\
& \texttt{signed long} & \NBYTES{} & \NBYTES{} \\
& \texttt{long} & \NBYTES{} & \NBYTES{} \\
& \texttt{signed long long} & 8 & 8 \\
& \texttt{long long} & 8 & 8 \\
& \texttt{\_\_int128}\tnote{\dagger\dagger} & 16 & 8 \\
& \texttt{signed \_\_int128}\tnote{\dagger\dagger} & 16 & 8 \\
\midrule
\multirow{2}{\hsize}{Pointer}
& \textit{any-type}\texttt{ *} & \NBYTES{} & \NBYTES{}
& \multirow{2}{\hsize}{\ADDRBITS{}-bit address} \\
& \textit{any-type}\texttt{ (*) ()} & \NBYTES{} & \NBYTES{} \\
\midrule
\multirow{3}{\hsize}{Binary floating-point} &
\texttt{float} & 4 & 4 & short BFP \\
& \texttt{double} & 8 & 8 & long BFP \\
& \texttt{long double} & 16 & 8 & extended BFP \\
\midrule
\multirow{3}{\hsize}{Decimal floating-point} &
\texttt{\_Decimal32}\tnote{\dagger\dagger} & 4 & 4 & short DFP \\
& \texttt{\_Decimal64}\tnote{\dagger\dagger} & 8 & 8 & long DFP \\
& \texttt{\_Decimal128}\tnote{\dagger\dagger} & 16 & 8 & extended DFP \\
\bottomrule
\end{tabularx}
\medskip
\begin{tablenotes}
\item [\dagger] Here $n$ denotes the bit size, which equals the byte
size multiplied by 8.
\item [\dagger\dagger] These types are an extension to C (ISO/IEC
9899:2011).
\end{tablenotes}
\end{threeparttable}
\end{DIFnomarkup}
\caption{Scalar types}
\label{tab:scalar}
\end{table}
\subsubsection{Aggregates and Unions}
Aggregates\index{aggregate}\index{type!aggregate}
(structures\index{structure} and arrays\index{array}) and
unions\index{union}\index{type!union} assume the
alignment\index{alignment!aggregate or union} of their most strictly
aligned component---that is, the component with the largest alignment.
The size\index{size!aggregate or union} of any object, including
aggregates and unions, is always a multiple of the alignment of the
object. An array uses the same alignment as its elements. Structure and
union objects may require padding to meet these size and alignment
constraints:
\begin{itemize}
\item An entire structure or union object is aligned on the same
boundary as its most strictly aligned member.
\item Each member is assigned to the lowest available offset with the
appropriate alignment. This may require internal
padding\index{padding}, depending on the previous member.
\item If necessary, a structure's size is increased to make it a
multiple of the structure's alignment. This may require tail padding
if the last member does not end on the appropriate boundary.
\end{itemize}
In the examples shown in \crefrange{fig:struct1}{fig:struct5},
member byte offsets (for the big-endian implementation) appear in the
upper left corners.
\begin{figure}
\centering
\ifSkipTikZ
\begin{verbatim}
Byte aligned, sizeof is 1
+-------------+
struct { | 0 |
char c; | |
}; | c |
+-------------+
\end{verbatim}
\else
\begin{tabular}{>{\texttt\bgroup}l<{\texttt\egroup}}
struct \{\\
~~~~char c;\\
\};\\
\end{tabular}
\quad
\begin{tikzpicture}[baseline=(mid),x=1.3ex,y=3em]
\path [bitchart box] (0, 0) rectangle (8, 1);
\bytechartfields 0 1/c/;
\path (current bounding box.center) coordinate (mid) {};
\path (current bounding box.north)
node [above] {Byte aligned, \texttt{sizeof} is 1};
\end{tikzpicture}
\fi
\caption{Structure smaller than a word}
\label{fig:struct1}
\end{figure}
\begin{figure}
\centering
\ifSkipTikZ
\begin{verbatim}
Word aligned, sizeof is 8
+-------------+-------------+---------------------------+
struct { | 0 | 1 | 2 |
char c; | | | |
char d; | c | d | s |
short s; |-------------+-------------+---------------------------|
int n; | 4 |
}; | |
| n |
+-------------------------------------------------------+
\end{verbatim}
\else
\begin{tabular}{>{\texttt\bgroup}l<{\texttt\egroup}}
struct \{\\
~~~~char c;\\
~~~~char d;\\
~~~~short s;\\
~~~~{\ifzseries int\else long\fi} n;\\
\};\\
\end{tabular}
\quad
\begin{tikzpicture}[baseline=(mid),x=1.3ex,y=3em]
\path [bitchart box] (0, -1) rectangle (32, 1);
\bytechartfields 0 1/c/, 2/d/, 4/s/;
\bitchartsep
\begin{scope}[shift={(0,-1)}]
\bytechartfields 4 8/n/;
\end{scope}
\path (current bounding box.center) coordinate (mid) {};
\path (current bounding box.north)
node [above] {Word aligned, \texttt{sizeof} is 8};
\end{tikzpicture}
\fi
\caption{No padding}
\label{fig:struct2}
\end{figure}
\begin{figure}
\centering
\ifSkipTikZ
\begin{verbatim}
+-------------+-------------+---------------------------+
struct { | 0 | 1 | 2 |
char c; | | | |
short s; | c | pad | s |
}; +-------------+-------------+---------------------------+
\end{verbatim}
\else
\begin{tabular}{>{\texttt\bgroup}l<{\texttt\egroup}}
struct \{\\
~~~~char c;\\
~~~~short s;\\
\};\\
\end{tabular}
\quad
\begin{tikzpicture}[baseline=(mid),x=1.3ex,y=3em]
\path [bitchart box] (0, 0) rectangle (32, 1);
\bytechartfields 0 1/c/, 2//, 4/s/;
\path (current bounding box.center) coordinate (mid) {};
\path (current bounding box.north)
node [above] {Halfword aligned, \texttt{sizeof} is 4};
\end{tikzpicture}
\fi
\caption{Internal padding}
\label{fig:struct3}
\end{figure}
\begin{figure}
\centering
\ifSkipTikZ
\begin{verbatim}
Doubleword aligned, sizeof is 24
+-------------+-----------------------------------------+
| 0 | 1 |
| | |
| c | pad |
|-------------+-----------------------------------------|
| 4 |
| |
| pad |
|-------------------------------------------------------|
struct { | 8 |
char c; | |
double d; | d |
short s; |-------------------------------------------------------|
}; | 12 |
| |
| d |
|---------------------------+---------------------------|
| 16 | 18 |
| | |
| s | pad |
|---------------------------+---------------------------|
| 20 |
| |
| pad |
+-------------------------------------------------------+
\end{verbatim}
\else
\begin{tabular}{>{\texttt\bgroup}l<{\texttt\egroup}}
struct \{\\
~~~~char c;\\
~~~~double d;\\
~~~~short s;\\
\};\\
\end{tabular}
\quad
\begin{tikzpicture}[baseline=(mid),x=1.3ex,y=2.5em]
\path [bitchart box] (0, -5) rectangle (32, 1);
\bytechartfields 0 1/c/, 4//;
\bitchartsep
\begin{scope}[shift={(0,-1)}]
\bytechartfields 4 8//;
\bitchartsep
\end{scope}
\begin{scope}[shift={(0,-2)}]
\bytechartfields 8 12/d/;
\bitchartsep
\end{scope}
\begin{scope}[shift={(0,-3)}]
\bytechartfields 12 16/d/;
\bitchartsep
\end{scope}
\begin{scope}[shift={(0,-4)}]
\bytechartfields 16 18/s/, 20//;
\bitchartsep
\end{scope}
\begin{scope}[shift={(0,-5)}]
\bytechartfields 20 24//;
\bitchartsep
\end{scope}
\path (current bounding box.center) coordinate (mid) {};
\path (current bounding box.north)
node [above] {Doubleword aligned, \texttt{sizeof} is 24};
\end{tikzpicture}
\fi
\caption{Internal and tail padding}
\label{fig:struct4}
\end{figure}
\begin{figure}
\centering
\ifSkipTikZ
\begin{verbatim}
Word aligned, sizeof is 4
+-------------+-----------------------------------------+
| 0 | 1 |
| | |
| c | pad |
+-------------+-----------------------------------------+
union { +---------------------------+---------------------------+
char c; | 0 | 2 |
short s; | | |
int j; | s | pad |
}; +---------------------------+---------------------------+
+-------------------------------------------------------+
| 0 |
| |
| j |
+-------------------------------------------------------+
\end{verbatim}
\else
\begin{tabular}{>{\texttt\bgroup}l<{\texttt\egroup}}
union \{\\
~~~~char c;\\
~~~~short s;\\
~~~~int j;\\
\};\\
\end{tabular}
\quad
\begin{tikzpicture}[baseline=(mid),x=1.3ex,y=2.5em]
\path [bitchart box] (0, 0) rectangle (32, 1);
\bytechartfields 0 1/c/, 4//;
\begin{scope}[shift={(0,-1.2)}]
\path [bitchart box] (0, 0) rectangle (32, 1);
\bytechartfields 0 2/s/, 4//;
\end{scope}
\begin{scope}[shift={(0,-2.4)}]
\path [bitchart box] (0, 0) rectangle (32, 1);
\bytechartfields 0 4/j/;
\end{scope}
\path (current bounding box.south west) coordinate (sw) {}
(current bounding box.north west) coordinate (nw) {};
\path (current bounding box.center) coordinate (mid) {};
\path (current bounding box.north)
node [above] {Word aligned, \texttt{sizeof} is 4};
\path (nw) +(-1em,0) coordinate (nw) {};
\draw [decorate,decoration=brace, thick] (sw) + (-1em,0) -- (nw);
\end{tikzpicture}
\fi
\caption{Union padding}
\label{fig:struct5}
\end{figure}
\subsubsection{Bit-Fields}
C struct and union definitions may have ``bit-fields,'' defining
integral objects with a specified number of bits
(see \cref{tab:bitfields}).
\begin{table}
\centering
\begin{DIFnomarkup}
\begin{tabular}[t]{lcr@{~\ldots~}l}
\toprule
Bit-field type & Width $n$ & \multicolumn{2}{c}{Range} \\
\midrule
\texttt{signed char} & \multirow{3}{*}{1…8} & $-2^{n-1}$ & $2^{n-1}-1$ \\
\texttt{char} & & $0$ & $2^n-1$ \\
\texttt{unsigned char} & & $0$ & $2^n-1$ \\
\midrule
\texttt{signed short} & \multirow{3}{*}{1…16} & -$2^{n-1}$ & $2^{n-1}-1$ \\
\texttt{short} & & -$2^{n-1}$ & $2^{n-1}-1$ \\
\texttt{unsigned short} & & $0$ & $2^n-1$ \\
\midrule
\texttt{signed int} & \multirow{\ifzseries 3\else 6\fi}{*}{1…32} &
$-2^{n-1}$ & $2^{n-1}-1$ \\
\texttt{int} & & $-2^{n-1}$ & $2^{n-1}-1$ \\
\texttt{unsigned int} & & $0$ & $2^n-1$ \\
\ifzseries \midrule \fi
\texttt{signed long} & {\ifzseries\multirow{3}{*}{1…64}\fi} &
$-2^{n-1}$ & $2^{n-1}-1$ \\
\texttt{long} & & $-2^{n-1}$ & $2^{n-1}-1$ \\
\texttt{unsigned long} & & $0$ & 2$^n-1$ \\
\midrule
\texttt{signed long long} & \multirow{3}{*}{1…64} & $-2^{n-1}$ & $2^{n-1}-1$ \\
\texttt{long long} & & $-2^{n-1}$ & $2^{n-1}-1$ \\
\texttt{unsigned long long} & & $0$ & $2^n-1$ \\
\bottomrule
\end{tabular}
\end{DIFnomarkup}
\caption{Bit-fields}
\label{tab:bitfields}
\end{table}
Bit-fields\index{bit-field} have the signedness of their underlying type.
For example, a bit-field of type \texttt{long} is signed, whereas a
bit-field of type \texttt{char} is unsigned.
Bit-fields obey the same size and alignment rules as other structure and
union members, with the following additions:
\begin{itemize}
\item Bit-fields are allocated from left to right (most to least
significant).
\item A bit-field must entirely reside in a storage unit appropriate
for its declared type. Thus, a bit-field never crosses its unit
boundary.
\item Bit-fields must share a storage unit with other structure and
union members (either bit-field or non-bit-field) if and only if
there is sufficient space within the storage unit.
\item Unnamed bit-fields' types do not affect the alignment of a
structure or union, although an individual bit-field's member
offsets obey the alignment constraints. An unnamed, zero-width
bit-field shall prevent any further member, bit-field or other, from
residing in the storage unit corresponding to the type of the
zero-width bit-field.
\end{itemize}
The examples in \crefrange{fig:bitnum}{fig:unnbitf} show
structure and union member byte offsets in the upper left corners.
Bit numbers appear in the lower corners.
\begin{figure}
\centering
\ifSkipTikZ
\begin{verbatim}