-
Notifications
You must be signed in to change notification settings - Fork 0
/
simics.tex
1360 lines (1150 loc) · 47.8 KB
/
simics.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
\ifdefined\cheatsheetCompact
\documentclass[8pt]{extarticle}
\usepackage[a4paper,xetex,landscape,left=1cm,right=1cm,
top=0.7cm,bottom=0.7cm]{geometry}
\else
\documentclass[12pt]{extarticle}
\usepackage[a4paper,xetex,left=3cm,right=3cm,
top=1.5cm,bottom=2cm]{geometry}
\fi
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\sffamily\large\bfseries\color{blue}}
{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\sffamily\bfseries\color{blue}}
{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\sffamily\small\bfseries\color{blue}}
{\thesubsubsection}{1em}{}
\usepackage{calc}
\usepackage{enumitem}
\ifdefined\cheatsheetCompact
\usepackage{multicol}
% Compact titles %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\titlespacing*{\section}
{-1.2ex}{0ex}{0ex}
\titlespacing*{\subsection}
{-1.2ex}{0ex}{0ex}
\titlespacing*{\subsubsection}
{-1.2ex}{0ex}{0ex}
\raggedcolumns
% Don't print section numbers
\setcounter{secnumdepth}{1}
% no space before new paragraph
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}
% less spacing between items
\setlist[enumerate]{
labelindent=25pt,
leftmargin=*,
itemsep=-0.2em
}
\setlist[itemize]{
labelindent=25pt,
leftmargin=*,
itemsep=-0.2em
}
% Turn off header and footer
\pagestyle{empty}
\newcommand{\vshort}[1]{%
\vspace{-0.6em}%
#1%
\vspace{0.0em}}
\else
\newcommand{\vshort}[1]{%
#1%
}
%\newcommand{\sectionbreak}{}
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tabulary}
% make tabulary prevent overflows (https://tex.stackexchange.com/a/195088)
\tymin=60pt
\tymax=\maxdimen
\usepackage[table,usenames,dvipsnames]{xcolor}
\usepackage{adjustbox}
\usepackage[most]{tcolorbox}
\usepackage{fontspec}
\usepackage[urlbordercolor=blue,linkbordercolor=cyan,
pdfborderstyle={/S/U/W 1}]{hyperref}
% declare font faces for Nunito font https://fonts.google.com/specimen/Nunito
% I don't use package `nunito` since it's not present in older Linux boxes,
% but instead download directly. Also in my installation presence of
% Nunito-VariableFont_wght.ttf/Nunito-Italic-VariableFont_wght.ttf broke
% some font shapes finding so I deleted it leaving only "static" ttf fonts.
\usepackage{fourier} % for \warning
\newcommand{\mywarning}{{\huge \warning}}
\setmainfont{Nunito}[
FontFace={el}{n}{Font=* ExtraLight},
FontFace={l}{n}{Font=* Light},
FontFace={r}{n}{Font=*},
FontFace={m}{n}{Font=* Medium},
FontFace={sb}{n}{Font=* SemiBold},
FontFace={b}{n}{Font=* Bold},
FontFace={eb}{n}{Font=* ExtraBold},
FontFace={xb}{n}{Font=* Black},
FontFace={eli}{i}{Font=* ExtraLight Italic},
FontFace={i}{i}{Font=* Italic},
FontFace={mi}{i}{Font=* Medium Italic},
FontFace={sbi}{i}{Font=* SemiBold Italic},
FontFace={bi}{i}{Font=* Bold Italic},
FontFace={ebi}{i}{Font=* ExtraBold Italic},
FontFace={xbi}{i}{Font=* Black Italic},
]
\DeclareRobustCommand{\elseries}{\fontseries{el}\selectfont}
\DeclareRobustCommand{\lseries}{\fontseries{l}\selectfont}
\DeclareRobustCommand{\rseries}{\fontseries{r}\selectfont}
\DeclareRobustCommand{\mseries}{\fontseries{m}\selectfont}
\DeclareRobustCommand{\sbseries}{\fontseries{sb}\selectfont}
\DeclareRobustCommand{\bseries}{\fontseries{b}\selectfont}
\DeclareRobustCommand{\ebseries}{\fontseries{eb}\selectfont}
\DeclareRobustCommand{\xbseries}{\fontseries{xb}\selectfont}
\DeclareRobustCommand{\eliseries}{\fontseries{eli}\fontshape{i}\selectfont}
\DeclareRobustCommand{\liseries}{\fontseries{li}\fontshape{i}\selectfont}
\DeclareRobustCommand{\iseries}{\fontseries{i}\fontshape{i}\selectfont}
\DeclareRobustCommand{\miseries}{\fontseries{mi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\sbiseries}{\fontseries{sbi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\biseries}{\fontseries{bi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\ebiseries}{\fontseries{ebi}\fontshape{i}\selectfont}
\DeclareRobustCommand{\xbiseries}{\fontseries{xbi}\fontshape{i}\selectfont}
% redefine default bold to extra bold
\DeclareRobustCommand{\bfseries}{\fontseries{eb}\fontshape{n}\selectfont}
% fix \textit
\DeclareTextFontCommand{\textit}{\iseries}
% font for headings
\setsansfont{Open Sans}
% some bolder font
\usepackage{unicode-math}
\setmathfont[Scale=1.0]{TeX Gyre Schola Math}
\usepackage{circledsteps} % for \Circled
\pgfkeys{/csteps/inner color=white}
\pgfkeys{/csteps/outer color=black}
\pgfkeys{/csteps/fill color=black}
\newcommand{\circled}[1]{\Circled{\textbf{#1}}}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc,fit}
\tikzset{
block/.style = {draw, fill=white, rectangle, minimum height=3em, minimum width=3em},
line/.style={-latex},
}
% definition for drawing arrow
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawBottomReverse}[4]{%
\begin{tikzpicture}[overlay,remember picture,-latex,shorten >=5pt,shorten
<=5pt,out=225,in=315]
\draw[distance=0.45cm,#1] (#2.south) to node[right,xshift=1.1cm]{#4}
(#3.south);
\end{tikzpicture}
}
\newcommand{\DrawTopBottom}[4]{%
\begin{tikzpicture}[overlay,remember picture,-latex,shorten >=5pt,shorten
<=5pt,out=340,in=20]
\draw[distance=0.45cm,#1] (#2.east) to node[right,xshift=0.1cm]{#4}
(#3.east);
\end{tikzpicture}
}
\newtcolorbox{prebox}[1][]{
left=0.5mm, right=0.5mm, top=0mm, bottom=0mm,
before skip=3pt, after skip=3pt,
frame hidden, boxrule=0.05em,
colback=green!10, #1}
% colored box around code
\newenvironment{code}[1][]{%
\begin{prebox}[#1]\obeylines%
\fontdimen2\font=0.9ex% inter word space
}{%
\end{prebox}%
\fontdimen2\font=0.6ex% inter word space
}
% box with modifiable size
\newenvironment{codem}[2][\linewidth]{%
\begin{minipage}{#1}%
\begin{prebox}[colback=#2]\obeylines}{%
\end{prebox}%
\end{minipage}}
% box with size 90%
\newenvironment{code9}{%
\begin{codem}[0.9\linewidth]{green!10}}{\end{codem}}
% inline color box for code
\newcommand{\cod}[2][green!10]{\tcbox[
size=fbox,
on line,
colback=#1,
colframe=black,
arc=0.3em % rounded corners
]{#2}}
% Syntax highlighting for code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\ind}{\hphantom{~~~}}
% shell and other prompts
\newcommand{\prompt}{\textcolor{red}{\textbf{\$}\ }}
% target prompt:
\newcommand{\tprompt}{\textcolor{brown}{\textbf{target\$}\ }}
\newcommand{\sprompt}{\textcolor{blue}{\textbf{>}\ }}
% Syntax:
\newcommand{\kw}[1]{\textcolor{magenta}{\textbf{#1}}}
\definecolor{myOrange}{rgb}{0.7,0.25,0}
\definecolor{lightBrown}{HTML}{ffcc99}
\definecolor{lightCyan}{HTML}{00ffff}
\newcommand{\ty}[1]{\textcolor{myOrange}{\textbf{#1}}}
% Misc highlighting:
\newcommand{\hl}[1]{\textcolor{blue}{\textbf{#1}}}
% shell/simics script/python comment
\newcommand{\cmtcommon}[1]{\textcolor{Sepia}{\textbf{#1}}}
\newcommand{\cmt}[1]{\cmtcommon{\#\ #1}}
% DML/C comment:
\newcommand{\cmtd}[1]{\cmtcommon{/\,/\ #1}}
\newcommand{\p}[1]{\textit{\large#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fontdimen2\font=0.6ex% inter word space
% fancy line breaks
\newcommand{\lbreak}{\hfill\textcolor{red}{\Large \raisebox{-0.2em}{$↩$}}\\\ind}
\ifdefined\cheatsheetCompact
\newcommand{\condbreak}{\lbreak}
\else
\newcommand{\condbreak}{}
\fi
% This document specific declarations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\local}{\kw{local} }
\newcommand{\class}{\kw{class} }
\usepackage{underscore} % underscore is often used in code here
\newcommand{\Simics}{\textcolor{cyan}{\textbf{Simics}}}
\newlength{\MyLen}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
% Never allow text overflow to margin:
\setlength\emergencystretch{\hsize}\hbadness=10000
\ifdefined\cheatsheetCompact
\begin{multicols*}{3}
\fi
{\Large\centering \Simics{} Cheatsheet\par}
%\section*{Simics cheatsheet}
%\begin{center} \textbf{\Large \Simics{} Cheat Sheet} \end{center}
\ifdefined\cheatsheetCompact
\vspace{0.1cm}
\fi
\section{\Simics{} Usage (command line)}
\subsection{Glossary \& Documentation}
\settowidth{\MyLen}{\textit{[simics]-script.}}
\rowcolors{1}{gray!15}{white}
\noindent\begin{tabular}{p{\the\MyLen}p{\linewidth-\the\MyLen-0.8cm}}
\textit{\Simics{} Base} & \cod{simics} executable + the set of
supporting shared libraries (DLLs) + tools
\\
\textit{simulation} & running of code (target) on
a model/platform (target) with advancement of time
\\
\textit{host} & a computer where simulation runs
\\
\textit{target} & a simulated
code running in its isolated memory region, e.g. Linux or
Windows guest
\\
\textit{platform} & a complete runnable model:
full set-up of devices
with CPU or with at least a clock provider
\\
\textit{package} & a set of devices, oftentimes constituting
1 platform, distributed as a whole in an archive and unpacked
into 1 directory
\\
\textit{[\Simics] Script} & simple Unix-shell-like language (a wrapper
over Python) used for connecting devices and command line
automation
\\
\textit{Simics User’s Guide} & documentation on \Simics{}
usage — both command line and Eclipse
\end{tabular}
Below \prompt stands for Unix shell prompt, \sprompt for \Simics{} prompt.
\p{Big_italic} text means user-supplied arguments for commands/functions.
\subsection{Set up a workspace with platform package}
\begin{code}
\prompt \p{path/to/simics-base}/bin/project-setup\ \ .
\prompt bin/addon-manager -c \cmt{remove default package associations}
\cmt{Allow scripts \& shared libraries be found:}
\prompt bin/addon-manager -s \p{/path/to/platform-package}
\prompt bin/addon-manager -s \p{/path/to/additional/package}
\end{code}
\subsection{Start up}
\begin{code}
\prompt ./simics targets/\p{platform/platform.simics}
\end{code}
%\begin{tabular}{|p{6cm}| p{10cm} |}
Shell command line arguments $\longrightarrow$ \Simics{} command line
correspondence:
\noindent\begin{tabular}{p{0.05\linewidth}p{0.85\linewidth}}
&
\begin{code9}
\prompt ./simics start.simics
\end{code9}
\vspace{0.05cm}
\\
$\longrightarrow$ &
\begin{code9}
\prompt ./simics
\sprompt run-command-file start.simics
\end{code9}
\vspace{0.2cm}
\\
& \begin{code9}
\prompt ./simics script.py
\end{code9}
\vspace{0.05cm}
\\
$\longrightarrow$ &
\begin{code9}
\prompt ./simics
\sprompt run-python-file script.py
\end{code9}
\vspace{0.2cm}
\\
& \begin{code9}
\prompt ./simics -e ‘\$config_variable1=value; \$config_var2=value’ start.simics
\cmt{\mywarning NOT ./simics start.simics -e \$varibables ...}
\end{code9}
\vspace{0.05cm}
\\
$\longrightarrow$ &
\begin{code9}
\prompt ./simics
\sprompt \$config_variable=value
\sprompt \$config_var2=value
\sprompt run-command-file start.simics
\end{code9}
\end{tabular}
\subsection{Environment \& Packages}
\begin{code}
\sprompt version \cmt{list of installed packages}
\prompt ./simics -v \cmt{the same}
\sprompt pwd \cmt{current directory where simics is running}
\sprompt list-directories \cmt{where \Simics{} searches files}
\end{code}
To debug chain of called auxiliary scripts \cod{include}s:
\begin{code}
\prompt ./simics -script-trace targets/\p{platform/platform.simics}
\end{code}
\subsection{Commands for running simulation}
\begin{code}
\sprompt c[ontinue]
\sprompt r[un] 100 cycles \ind \cmt{or 10 steps or 0.1 seconds}
\sprompt ptime [-all] \ind \cmt{to show target's time}
\sprompt print-event-queue \ind \cmt{show all pending events (e.g. timers)}
\cmt{To know CPU/clock which advances time for the device (and executes events):}
\sprompt \p{platform.myDevice}->queue
\end{code}
\subsection{Printing device structure}
To find devices by name/class or interface name:
\begin{code}
\sprompt list-objects -all \p{name} \ind \cmt{searches also for the class}
\sprompt list-objects -all substr = \p{mem} \cmt{object names containing \p{mem}}
\sprompt list-objects -all iface = \p{my_interface} \cmt{by interface name}
\end{code}
To examine device structure (\Simics{} \textit{components}
and \textit{devices}) of a given component \p{myPlatform}:
\begin{code}
\cmt{1-level representation: immediate children \p{myPlatform}:}
\sprompt list-objects namespace = \p{myPlatform}
\cmt{Multi-level one: all children of \p{myPlatform} with all hierarchy:}
\sprompt list-objects namespace = \p{myPlatform} -tree
\end{code}
To find all objects with the same class as given device:
\begin{code}
\begin{code}
\sprompt \p{platform.myDevice}->classname
\textbf{myClass}
\end{code}
\sprompt list-objects -all \p{myClass}
\sprompt list-objects -all class = \p{myClass}
\end{code}
\subsection{Registers}
\begin{code}
\cmt{Print all registers:}
\sprompt print-device-regs \p{platform.myDevice}
\cmt{Print fields of register \p{myRegister}:}
\sprompt print-device-reg-info \condbreak \p{platform.myDevice.myBank.myRegister}
\end{code}
\subsubsection{Writing/reading with side effects}
\begin{code}
\sprompt write-device-reg \lbreak \p{platform.myDevice}.bank.\p{Bank.Group.myRegister} 0x1
\cmt{(register groups like \p{myGrp} may be omitted in devices)}
\sprompt read-device-reg \condbreak \p{platform.myDevice}.bank.\p{Bank.Group.myRegister}
\end{code}
%\subsubsection{Writing/reading \textbf{without} side effects (aka set/get)}
\subsubsection{Writing/reading {\bseries without} side effects (aka set/get)}
\begin{code}
\cmt{You can use set-device-reg / get-device-reg...}
\cmt{...or do it through attributes, e.g. to set to value 0x1:}
\p{platform.myDevice}->\p{Bank_Group_register} = 0x1
\cmt{To get the value:}
\p{platform.myDevice}->\p{Bank_Group_register}
\end{code}
\subsection{Connects — attributes that point to other devices}
\begin{code}
\cmt{To set a connect attribute:}
\sprompt \p{platform.myDevice}->\p{myConnect} = \p{"platform.Device2"}
\cmt{To zero connect attribute:}
\sprompt \p{platform.myDevice}->\p{myConnect} = FALSE \ind\cmt{obvious ;-)}
\end{code}
\subsection{Device information: static}
\begin{code}
\cmt{To find info about class/module/package for your device:}
\begin{code}
\sprompt help \p{platform.myDevice}
\ind Class \textbf{myClass}
\vspace{0.3em} \ind Provided By
\ind \ind \textbf{myModule} (from \textbf{myPackage})
\vspace{0.2em}
\ind \cmt{...then documentation about the device is printed.}
\end{code}
\vspace{0.3em}
\cmt{To list all classes provided by a module:}
\sprompt list-classes -m \p{myModule}
\cmt{Configuration information:}
\sprompt \p{platform.myDevice}.info
\end{code}
\subsection{Device information: dynamic}
\begin{code}
\cmt{Runtime information:}
\sprompt \p{platform.myDevice}.status
\cmt{pretty-print device attributes with values:}
\sprompt list-attributes \p{platform.myDevice}
\cmt{to search all attributes/registers containing \p{mem}:}
list-attributes \p{platform.myDevice} substr = \p{mem}
\end{code}
\subsection{Memory spaces}
All target software runs on CPU and can access devices only through
hierarchy of memory spaces:
\noindent\includegraphics[width=\linewidth]{diagrams/mem_spaces.pdf}
\begin{code}
\cmt{To find memory spaces the device is mapped in:}
\sprompt devs \p{platform.myDevice}
\end{code}
\subsection{Getting help}
\begin{code}
\cmt{Get help on some command:}
\sprompt{help \p{instantiate-components}}
\cmt{Finding sections of documentation mentioning it:}
\sprompt{apropos \p{instantiate-components}}
\cmt{To open Simics Documentation in browser run from workspace:}
\prompt ./documentation \ind \cmt{or .\textbackslash{}documentation.bat on Windows}
\end{code}
\subsection{Debugger commands}
To use \Simics{} to debug target:
\begin{code}
dis[assemble] \cmt{show assembler commands at current address}
\cmt{Set break point on physical memory access from current CPU:}
break \p{address} [-r] [-w] [-x] \cmt{-rw by default}
\cmt{To break from specific CPU:}
\p{cpu.phys_mem}.break \p{address} [-r] [-w] [-x]
\cmt{To break on access from any memory space to \p{myDevice}:}
break-io \p{myDevice} \p{Bank} \p{Offset} \p{Length}
\cmt{To break on specific conditions, "HAP"s:}
break-hap Core-Magic-Instruction \cmt{run \cod{list-haps} for options}
\end{code}
\subsection{Examining current state}
\noindent\begin{tabular}{ll}
pselect & show currently running CPU \\
memory-map & print all mapped devices \\
pregs & print all CPU registers \\
probe-address \p{addr} & path to target \p{addr}
\end{tabular}
\subsection{x86-specific and platform-specific commands}
\noindent\begin{tabular}{ll}
memory-trace \p{addr} & path to target \p{addr} \\
pregs & to know x86 mode (16/32/64-bit), 1st line \\
reset-button-press & to reboot the target \\
power-button-press & to press power button \\
\end{tabular}
\subsection{Moving files target \texorpdfstring{$\longleftrightarrow$}{<->} host}
%\subsection{Moving files target $\longleftrightarrow$ host}
%\subsection{Moving files target <-> host}
\begin{code}
\sprompt start-simicsfs-server
\end{code}
\begin{code}[colback=blue!15]
\tprompt mkdir a
\tprompt simicsfs-client a
\end{code}
\subsection{Saving info}
Save logs from current point
\begin{code}
\sprompt start-command-line-capture \p{filename}
\end{code}
To save simics variables to a file:
\begin{code}
\sprompt start-command-line-capture \p{filename}
\sprompt list-variables
\sprompt stop-command-line-capture
\end{code}
\subsection{Check points}
\noindent\begin{tabular}{ll}
\cod{write-configuration \p{"checkpoint_name"}} & — save
checkpoint \\
\cod{read-configuration \p{"checkpoint_name"}} & — restore it back
\end{tabular}
%\subsection{Making images}
\subsection{Creating components dynamically (for hot plug)}
\begin{code}
\sprompt create-myDevice-comp "\p{platform.myDeviceComp}"
\sprompt connect \p{platform.myDeviceComp.connectorName} \lbreak \p{platform.Device2.connectorName}
\sprompt instantiate-components
\end{code}
\subsection{Miscellaneous}
\begin{code}
\cmt{To dump network packages (for analysis with Wireshark):}
\sprompt pcap-dump link=\p{ethernet_switch0} filename=\p{myFile}
\end{code}
\begin{code}
\cmt{Treat all input as Python code:}
\sprompt python-mode
\sprompt \sprompt \sprompt \p{Enter your Python code}
\end{code}
\ifdefined\cheatsheetCompact
% \newpage
\vspace{0.4cm}
\fi
\section{\Simics{} DML 1.4 Programming \& C/DML API}
\subsection{Glossary \& Documentation}
\settowidth{\MyLen}{\texttt{dml-1.4-reference-man}}
%\begin{tabulary}{\linewidth}{p{4cm}L}
\noindent\begin{tabular}{p{\the\MyLen}p{\linewidth-\the\MyLen-0.8cm}}
\textit{DML} & Device Modelling Language is a
wrapper over C for writing (fast) devices.
Its compiler is included into \Simics{} Base.
\\
\kw{device} & any \Simics{} class for modelling real
devices. Different \Simics{} devices communicate via \textit{interfaces}.
\\
\textit{Model Builder User’s Guide} & overview of \Simics{}/DML
programming \\
\textit{DML 1.4 Reference Manual} & language specification \\
\textit{API Reference Manual} & API function list for DML \& C,
describes ownership rules\\
\textit{model writers} & those who write \Simics{} devices\\
\textit{users} & those who use \Simics{} devices:
device driver writers, firmware/UEFI writers,
validators/testers, etc
\end{tabular}
\subsection{Getting help}
\begin{code}
\cmt{Print explanation of C/Python/DML API functions:}
\sprompt api-help \p{SIM_add_configuration}
\end{code}
\subsection{Create stub device}
\begin{code}
\prompt bin/project-setup -{}-device \p{example-dev}
\prompt ls modules/\p{example-dev}
test/ \p{example-dev}.dml Makefile module_load.py
\end{code}
The header of \p{example-dev}.dml is then:
\begin{code}
%\begin{tabulary}{\linewidth}{p{4cm}L}
%\begin{tabular}{p{3cm}p{\linewidth-3.8cm}}
\rowcolors{1}{}{}
\noindent\begin{tabular}{ll}
dml 1.4; & \cmtd{obligatory .dml header} \\
\kw{device} \p{example_dev}; & \cmtd{class name.} \\
& \cmtd{Note: \cod{-} changed to underscore \cod{_}}
\end{tabular}
\end{code}
\subsection{Create stub interface with Python wrapper}
\begin{code}
\prompt bin/project-setup -{}-interface \p{sample}
\prompt ls modules/\p{sample}-interface
Makefile \p{sample}-interface.dml \p{sample}-interface.h
\end{code}
Python support is enabled by \cod{IFACE_FILES} in the Makefile.
The generated C \kw{struct} name is \cod{\ty{\p{sample}_interface_t}}.
\subsection{Arithmetics}
\subsubsection{RHS is int64, LHS truncates}
Assignments are equivalent to casts and hence can truncate:
\begin{code}
\local \ty{uint8} x = 0xffff \cmtd{results in x == 0xff}
\end{code}
All aritmetic operators like $+$, $*$ convert its operands to int64:
\begin{code}
\local \ty{uint16} $i$ = 0x7fff; \local \ty{int8} $j$ = 2; \cmtd{Let us sum them:}
\vspace{0.1cm}
\local \ty{int16} \tikzmark{b} $x$ = $\overbrace{\ind i + j; \ind }^{\text{calculates as \ty{int64} $\rightarrow$ 0x8001} \tikzmark{a}}$ \DrawBottomReverse{black}{a}{b}{truncates to \ty{int16}}
\vspace{0.3cm}
\cmtd{finally results in $x == 1$.}
\end{code}
\subsubsection{Comparisons act as uint64 or int64: $==$, $<$, $<=$}
Comparisons on only \ty{uint64} act as proper \ty{uint64}, however
in comparisons \ty{int64} vs. \ty{uint64} the operands are converted to \ty{int64}!
\begin{code}
\local \ty{uint64} u;
u = -1; \ind \cmtd{equivalent to u = cast(-1, uint64) $\mathbf{= 2^{64}-1}$, all ones}
\rowcolors{1}{}{}
\noindent\begin{tabular}{@{}ll}
u == -1 & \cmtd{FALSE! Equivalent to int64(u) == int64(-1),} \\
& \cmtd{where upper bit is cropped: int64(u) == ($\mathbf{2^{63}-1}$).}
\end{tabular}
u == cast(-1, \ty{uint64}) \cmtd{true. As comparison is b/w two uint64}
u > -1 \ind \cmtd{true, but unlike C! it's int64(u) > int64(-1): $\mathbf{2^{63}-1>1}$}
\end{code}
\subsection{Syntax}
\subsubsection{Statements}
\begin{code}
\cmtd{Printing through \kw{log} statements:}
\kw{log} \p{log-type}, $\underbrace{level}_{\makebox[0pt]{\text{default 1\hspace{0.5cm}}}}$, $\underbrace{groups}_{\makebox[0pt]{\hspace{1.7cm}\text{default 0 (no group)}}}$: \p{"format-string"}, $arg_1$, ..., $arg_N$;
\cmtd{(the "format-string" is the same as in C, see `man 3 printf')}
\end{code}
\global\rownum=0\relax
\noindent\begin{tabulary}{\linewidth}{|LL|}
\hline
\p{log-level} & usage rule \\
\hline
1 & most important messages (for both users and model writers),
typically \texttt{error}\\
2 & crucial events for boards/devices, e.g. their resets \\
3 & any other messages (for users) \\
4 & internal device debug messages (for model writers)\\
\hline
\end{tabulary}
\noindent\begin{tabulary}{\linewidth}{|LL|}
\hline
\p{log-type} & usage rule \\
\hline
\texttt{info} & informational message \\
\texttt{spec_viol} & specification violation by target software (for users) \\
\texttt{unimpl} & attempt to use not implemented functionality (for users) \\
\texttt{error} & internal device error (for model writers).
\mywarning There is a limit (default 10_000) after
which simulation stops!\\
\texttt{critical} & like \texttt{spec_viol} or error, but \mywarning
stops simulation \\
\hline
\end{tabulary}
\begin{code}
\cmtd{Dynamic allocation (like malloc() in C):}
\local \ty{$type$ *} x = \kw{new} \ty{$type$};
\cmtd{E.g. for int array:}
\local \ty{int *} x = \kw{new} \ty{int[100]};
\kw{delete} x; \cmtd{deallocation like free() in C}
\cmtd{Raising/catching exceptions:}
\kw{try} \{
\ind \kw{throw;} \cmtd{YES, no data can be carried by exception}
\} catch \{
\vshort{\ind ...}
\}
\end{code}
\subsubsection{Expressions}
\begin{code}
sizeof $value$ \cmtd{: int — get byte size of the value}
sizeoftype \ty{$type$} \cmtd{: int — get byte size of the type}
x[10:8] \cmtd{get bits 10—8 of integer $x$:}
x[8] \cmtd{get bit 8 of integer $x$:}
\end{code}
\subsubsection{Scalar types}
DML-specific: \ty{uint1}...\ty{uint64} and \ty{int1}...\ty{int64} (+ aliases:
\ty{int} $→$ \ty{int32}, \ty{char} $→$ \ty{int8}),
\ty{uint8_be/le_t} ... \ty{uint64_be/le_t}.
\\
C-like types: \ty{size_t}, \ty{uintptr_t}, \ty{double}, \ty{bool}.
\subsubsection{Derived types}
\begin{code}
\kw{typedef} \underline{\kw{struct} \{ \p{member declarations;} \}} \p{typeName};
\cmtd{Layout members can be only whole-byte (\ty{int8}, \ty{int16}, ...):}
\kw{typedef} \underline{\kw{layout} "big-endian" \{ \p{member declarations;} \}} \p{typeName};
\cmtd{Bitfield size \p{sizeBits} can be 1 ... 64 and field size arbitrary:}
\kw{typedef} \underline{\kw{bitfields} \p{sizeBits} \{}
\ind \underline{\ty{uint3} a @ [31:29];} \ind \cmtd{just an example}
\ind ...
\underline{\}} \p{typeName};
\cmtd{All the types can be used for variable definitions inline, e.g.:}
\{
\ind \kw{local} \underline{\kw{struct} \{ uint8 \p{field}; \}} \p{variableName};
\ind \p{variableName.field} = 255;
\end{code}
\subsubsection{Methods}
They are called \textit{methods}, not functions, because
they accept \textbf{implicit} 1st argument — object (current
device), like C++ methods. Thus multiple instances of each device are allowed.
\begin{code}
\kw{method} \p{name}(\ty{$inputType_1$} $arg_1$) -> (\ty{$outputType_1$}, \ty{$outputType_2$}) \{
\vshort{\ind ...}
\ind \kw{local} \ty{$outputType_1$} $var_1$ = ...; \kw{local} \ty{$outputType_2$} $var_2$ = ...;
\ind return $(var_1, var_2)$;
\}
\cmtd{Calling this method:}
\kw{local} \ty{$inputType_1$} val = ...;
\kw{local} \ty{$outputType_1$} x; \kw{local} \ty{$outputType_2$} y;
(x, y) = \p{name}(val);
\end{code}
\subsubsection{Bitfields}
\begin{code}
bitfields 32 \{
\ind \ty{uint3} \p{upper_bits} @ [31:29];
\vshort{\ind ...}
\}
\end{code}
\subsubsection{Object declarations}
\begin{code}
\p{objectType} \p{objectName} \{
\ind \kw{method} \p{methodName} \{
\ind \vshort{\ind \ind ...}
\ind \}
\}
register \p{regName} @ \p{offset} is ($template_1$, ...);
\cmtd{@ \p{offset} is a syntax for "\kw{param} offset = \p{offset};"}
\end{code}
\subsubsection{Module variables and other data objects}
\global\rownum=1\relax
\noindent\begin{tabulary}{\linewidth}{|LLLLL|}
\hline
DML construct & checkpointed & fields & address-mapped & arbitrary data\\
\hline
\kw{session} & - & - & - & + \\
\kw{saved} & + & - & - & - \\
attribute & + & - & - & + \\
unmapped register & + & + & - & - \\
{[}normal{]} register & + & + & + & - \\
\hline
\end{tabulary}
\subsubsection{Interfaces}
Definition in \cod{.dml}:
\begin{code}
\kw{extern typedef struct} \{
\ind \kw{method} \p{name}(\ty{conf_object_t *}\hl{obj}, \p{\ty{$type_1$} $value_1$})
\ind \ind \ind -> \p{\ty{out_type}};
\} \ty{\p{sample}_interface_t};
\end{code}
Obligatory definition in C \cod{.h} file \textbf{for using the interface from Python}:
\begin{code}
SIM_INTERFACE(\p{sample}) \{ \cmtd{essentially '\kw{typedef struct}' also}
\ind \ty{\p{out_type}} (*\p{name})(\ty{conf_object_t *}\hl{obj}, \ty{\p{$type_1$}} \p{$value_1$});
\}
\kw{\#define} \p{SAMPLE}_INTERFACE "\p{sample}" \ind \cmtd{necessary!}
\end{code}
Then it is called \textbf{without} \cod{\hl{obj}}: just \cod{\p{name}(\p{$value_1$})}.
\subsubsection{Explaining \cod{connect}s and \cod[magenta!35]{implement}s}
\begin{itemize}
\item \cod{connect}s are for \textbf{out}bound calls
\item \cod[magenta!35]{implement}s are for \textbf{in}bound calls
\end{itemize}
\noindent\includegraphics[width=\linewidth]{diagrams/connect_implement.pdf}
\newlength{\connectwidth}
\newlength{\implementwidth}
\ifdefined\cheatsheetCompact
\setlength{\connectwidth}{3.4cm}
\setlength{\implementwidth}{2.5cm}
\else
\setlength{\connectwidth}{6.2cm}
\setlength{\implementwidth}{5cm}
\fi
\global\rownum=1\relax
%\begin{tabulary}{\linewidth}{|LCC|}
%\begin{tabular}{|lp{2.5cm}c|}
\noindent\begin{tabular}{|lp{\implementwidth}p{\connectwidth}|}
\hline
%co & \begin{minipage}{2.5cm}unnamed (whole-device)\end{minipage} &
& unnamed (whole-device) & named (wrapped in attribute) \\
\hline
\cod{connect} & - &
\begin{codem}[\connectwidth]{green!10}
connect \p{C_a} \{ \circled{1}
\ind interface $I_1$ \{ \circled{2}
\vshort{\ind\ind ...}
\ind \}
\ind interface $I_2$ \{ \circled{2}
\vshort{\ind\ind ...}
\ind \}
\}
connect \p{C_b} \{ \circled{1}
\ind interface $I_2$ \{ \circled{2}
\vshort{\ind\ind ...}
% \vspace{-0.6em}
%\ind\ind ...
\end{codem}
\\[1.4cm] % selected by trial
\cod[magenta!35]{implement} &
%\begin{codem}[2.5cm]{magenta!35}
\begin{codem}[\implementwidth]{magenta!35}
implement $I_1$ \{
\ind ...
\}
implement $I_2$ \{
\ind ...
\}
\end{codem}
\underline{as in picture above}
&
\begin{codem}[\connectwidth]{magenta!35}
port $P_A$ \{
\ind implement $I_1$ \{
\vshort{\ind\ind ...}
\ind\}
\ind implement $I_2$ \{
\ind\ind \emph{... 1st way of $I_2$ ...}
\vspace{-0.3em}
\ind\}
\}
port $P_B$ \{
\ind implement $I_2$ \{
\ind\ind \emph{... 2nd way of $I_2$ ...}
\end{codem}
\\
\hline
\end{tabular}
%\end{tabulary}
\noindent\begin{tabulary}{\linewidth}{LL}
\circled{1} &
\begin{minipage}{\linewidth}
To make the whole \cod{connect} required:
\begin{code}
\kw{param} configuration = "required";\\
\cmtd{other variants: "optional" (default), "pseudo", "none"}
\end{code}
\end{minipage}
\\
\circled{2} &
Individual interfaces are already \textbf{required} by default, to make them optional:
\begin{code}
\kw{param} required = false;
\end{code}
\end{tabulary}
\mywarning \cod[magenta!35]{implement \{\}} does NOT check that all (or any!) methods
of an interface are really provided, defaulting to \kw{NULL}.
\subsection{Calling device code from Python}
If \p{device} \cod{implement}s interface $iface_1$ then its methouds
can be invoked from \Simics{} command line via Python:
\begin{code}
@conf.\p{platform.device}.iface.$iface_1$.$method_1$(\textit{argument_1}, ...)
\end{code}
\subsection{Debugging with Gdb}
To debug simics and its modules itself:
%\cmt{Terminal \#1:}
\begin{code}
%\begin{center}Terminal \#1:\end{center}
{\large\centering Terminal \#1:\par}
\cmt{Recompile your module with debugging support:}
\prompt make clobber-\p{my-module}
\prompt make D=1 \p{my-module}
\prompt ./simics
\sprompt pid
\p{12345}
\end{code}
\begin{code}[colback=blue!15]
{\large\centering Terminal \#2:\par}
\prompt bin/gdb
>\,>\,> attach \p{12345}
>\,>\,> br \p{file.dml:100} \ind \cmt{set break point on line 100 of file.dml}
>\,>\,> continue
\end{code}
\begin{code}
{\large\centering Back to terminal \#1:\par}
\sprompt run-command-file targets/\p{platform/platform.simics}
\end{code}
\subsubsection{Using gdb for debugging target}
\begin{code}
load-module gdb-remote
new-gdb-remote \p{50000} \ind \cmt{open port \p{50000}}
\end{code}
\subsection{Attribute values}
\cod{\ty{attr_value_t}} is a C union that can hold one of a
few predefined types.
Attributes values are allocated/packed by:\\
\cod{\ty{attr_value_t} x = \textbf{SIM_make_attr_\p{T}}(\ty{\p{cType}} val)},
and extracted by:\\
\cod{\ty{\p{cType}} \ind \ind val = \textbf{SIM_attr_\p{T}}(x)}, where