diff --git a/20220607/calls-03.s b/20220607/calls-03.s new file mode 100644 index 0000000000000000000000000000000000000000..2f76456f9ad0223da209c34783b76ed9d5e83bf2 --- /dev/null +++ b/20220607/calls-03.s @@ -0,0 +1,40 @@ + .file "calls-03.c" + .text + .section .rodata.str1.1,"aMS",@progbits,1 +.LC0: + .string "Ihr Name: " +.LC1: + .string "Hallo, %s! :-)\n" + .text + .globl main + .type main, @function +main: +.LFB11: + .cfi_startproc + pushq %rbx + .cfi_def_cfa_offset 16 + .cfi_offset 3, -16 + subq $16, %rsp + .cfi_def_cfa_offset 32 + leaq .LC0(%rip), %rdi + movl $0, %eax + call printf@PLT + leaq 6(%rsp), %rbx + movq %rbx, %rdi + movl $0, %eax + call gets@PLT + movq %rbx, %rsi + leaq .LC1(%rip), %rdi + movl $0, %eax + call printf@PLT + movl $0, %eax + addq $16, %rsp + .cfi_def_cfa_offset 16 + popq %rbx + .cfi_def_cfa_offset 8 + ret + .cfi_endproc +.LFE11: + .size main, .-main + .ident "GCC: (Debian 8.3.0-6) 8.3.0" + .section .note.GNU-stack,"",@progbits diff --git a/20220614/Buegeln.pdf b/20220614/Buegeln.pdf new file mode 120000 index 0000000000000000000000000000000000000000..2815ea3ab388d141c6e5f73cd46739f223db8dfc --- /dev/null +++ b/20220614/Buegeln.pdf @@ -0,0 +1 @@ +../common/Buegeln.pdf \ No newline at end of file diff --git a/20220614/Trommeltrocknen.pdf b/20220614/Trommeltrocknen.pdf new file mode 120000 index 0000000000000000000000000000000000000000..93e2ad1f81820d422de2faf653a919dcdb99ca82 --- /dev/null +++ b/20220614/Trommeltrocknen.pdf @@ -0,0 +1 @@ +../common/Trommeltrocknen.pdf \ No newline at end of file diff --git a/20220614/Waschen_30.pdf b/20220614/Waschen_30.pdf new file mode 120000 index 0000000000000000000000000000000000000000..ca128204612c7f88c965b7ee5a0aae68075b9ebf --- /dev/null +++ b/20220614/Waschen_30.pdf @@ -0,0 +1 @@ +../common/Waschen_30.pdf \ No newline at end of file diff --git a/20220614/fak-01.c b/20220614/fak-01.c new file mode 100644 index 0000000000000000000000000000000000000000..05b2244928a5befeb11e5067cf5af5f1321b4bd7 --- /dev/null +++ b/20220614/fak-01.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int fak (int n) +{ + if (n <= 1) + return 1; + else + return n * fak (n - 1); +} + +int main (void) +{ + printf ("%d! = %d\n", 6, fak (6)); + return 0; +} diff --git a/20220614/fak-02.c b/20220614/fak-02.c new file mode 100644 index 0000000000000000000000000000000000000000..1b6b3b85e19eda191d6795513e7d30c52563fa63 --- /dev/null +++ b/20220614/fak-02.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int fak (int n) +{ + if (n <= 1) + return 1; + else + return n * fak (n); +} + +int main (void) +{ + printf ("%d! = %d\n", 6, fak (6)); + return 0; +} diff --git a/20220614/logo-hochschule-bochum-cvh-text-v2.pdf b/20220614/logo-hochschule-bochum-cvh-text-v2.pdf new file mode 100644 index 0000000000000000000000000000000000000000..3725a72c764b4d9ab200553474e4262161f7a5b5 Binary files /dev/null and b/20220614/logo-hochschule-bochum-cvh-text-v2.pdf differ diff --git a/20220614/logo-hochschule-bochum.pdf b/20220614/logo-hochschule-bochum.pdf new file mode 100644 index 0000000000000000000000000000000000000000..8cad73dbb48a2b550bf29355b5a6ec895ce091f8 Binary files /dev/null and b/20220614/logo-hochschule-bochum.pdf differ diff --git a/20220614/pgslides.sty b/20220614/pgslides.sty new file mode 100644 index 0000000000000000000000000000000000000000..9a019ce99f03d27a17942facc56fe2145f46b6a6 --- /dev/null +++ b/20220614/pgslides.sty @@ -0,0 +1,233 @@ +% pgslides.sty - LaTeX Settings for Lecture Slides +% Copyright (C) 2012, 2013 Peter Gerwinski +% +% This document is free software: you can redistribute it and/or +% modify it either under the terms of the Creative Commons +% Attribution-ShareAlike 3.0 License, or under the terms of the +% GNU General Public License as published by the Free Software +% Foundation, either version 3 of the License, or (at your option) +% any later version. +% +% This document is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this document. If not, see <http://www.gnu.org/licenses/>. +% +% You should have received a copy of the Creative Commons +% Attribution-ShareAlike 3.0 Unported License along with this +% document. If not, see <http://creativecommons.org/licenses/>. + +\usepackage{amsfonts} +\usepackage[british,german]{babel} % Yes, really "german" and not "ngerman". +\usepackage[utf8]{luainputenc} % Without this, umlauts are broken. Weird. +\usepackage{microtype} +\usepackage[T1]{fontenc} +\usepackage{times} +\usepackage{helvet} +\renewcommand*\familydefault{\sfdefault} +\usepackage{graphicx} +\usepackage{pstricks} + +\hypersetup{colorlinks,allcolors=blue} + +%% @@@ Not necessary for slides. Why??? +%% Repair kerning: Automatically insert "\kern{-0.15em}" between "//" % (in URLs). +%\directlua{ +% local glyph = node.id ("glyph") +% local function my_kerning (head) +% for t in node.traverse (head) do +% if t.id == glyph and t.char == 47 then +% if t.next +% and t.next.next +% and t.next.next.id == glyph +% and t.next.next.char == 47 then +% local k = node.new ("kern") +% k.kern = tex.sp ("-0.15em") +% k.next = t.next +% k.prev = t +% t.next.prev = k +% t.next = k +% end +% end +% end +% node.kerning (head) +% end +% luatexbase.add_to_callback ("kerning", my_kerning, "URL kerning") +%} + +\usetheme{default} +\usefonttheme{structurebold} +\setbeamertemplate{navigation symbols}{} +\setbeamersize{text margin left = 0.3cm, text margin right = 0.2cm} +\setbeamertemplate{itemize item}{$\bullet$} +\setbeamertemplate{itemize subitem}{--} +\setbeamerfont{itemize/enumerate subbody}{size=\normalsize} +\setbeamerfont{itemize/enumerate subsubbody}{size=\normalsize} +\setbeamercolor{footline}{fg=gray} + +\newcommand{\sep}{~$\cdot$~} + +\newif\ifminimalistic +\minimalistictrue + +\institute[Hochschule Bochum\sep CVH]{% + \makebox(0,0.005)[tl]{\includegraphics[scale=0.72]{logo-hochschule-bochum-cvh-text-v2.pdf}}\hfill + \makebox(0,0)[tr]{\includegraphics[scale=0.5]{logo-hochschule-bochum.pdf}}% +} + +\setbeamertemplate{headline}{% + \leavevmode + \hbox to \textwidth{% + \ifminimalistic + \strut\hfill + \else + \rule{0pt}{5.7pt}% + \hspace*{8.55pt}\insertinstitute\hspace*{5.7pt}% + \raisebox{-30pt}{\rule{0pt}{1pt}}% + \fi + }% + \vskip0pt% +} + +\iffalse + \setbeamertemplate{footline}{} +\else + \setbeamertemplate{footline}{% + \leavevmode + \hbox to \textwidth{% + \usebeamercolor{footline}% + \usebeamerfont{footline}% + \ifminimalistic + \strut\hfill + \else + \,\insertshorttitle\sep + \insertshortauthor\sep + \insertshortinstitute\sep + \insertshortdate\hfill + \fi + \insertframenumber/\inserttotalframenumber + %Folie\,\insertframenumber\sep Seite\,\insertpagenumber\, + }% + \vskip0pt% + } +\fi + +\newcommand{\maketitleframe}{% + \ifminimalistic + \begin{frame}[t,plain] + \insertinstitute + \par\vfill + \begin{center} + {\LARGE\color{structure}\inserttitle\par}\bigskip\bigskip + {\large \insertauthor\par}\bigskip\medskip + \insertdate + \end{center} + \end{frame} + \else + \begin{frame} + \vfill + \begin{center} + {\LARGE\color{structure}\inserttitle\par}\bigskip\bigskip + {\large \insertauthor\par}\bigskip\medskip + \insertdate + \end{center} + \vfill + \end{frame} + \fi +} + +\definecolor{medgreen}{rgb}{0.0,0.5,0.0} +\definecolor{darkgreen}{rgb}{0.0,0.3,0.0} +\definecolor{lightred}{rgb}{1.0,0.7,0.7} +\definecolor{medred}{rgb}{0.5,0.0,0.0} +\definecolor{bored}{rgb}{0.89,0.0,0.098} +\definecolor{lightgray}{rgb}{0.85,0.85,0.85} +\definecolor{orange}{rgb}{1.0,0.5,0.0} +\definecolor{darkgray}{rgb}{0.4,0.4,0.4} + +\newenvironment{experts}{\color{darkgray}}{} + +\usepackage{listings} +\lstset{basicstyle=\color{structure}, + language=C, + captionpos=b, + gobble=4, + columns=fullflexible, + aboveskip=0pt, + belowskip=0pt, + moredelim=**[is][\color{structure}]{¡}{¿}, + moredelim=**[is][\only<2->{\color{structure}}]{²}{¿}, + moredelim=**[is][\only<3->{\color{structure}}]{³}{¿}, + moredelim=**[is][\only<4->{\color{structure}}]{°}{¿}, + moredelim=**[is][\only<5->{\color{structure}}]{¤}{¿}, + moredelim=**[is][\only<6->{\color{structure}}]{¢}{¿}, + moredelim=**[is][\only<7->{\color{structure}}]{æ}{¿}, + moredelim=**[is][\only<8->{\color{structure}}]{ø}{¿}} +\lstdefinestyle{terminal}{basicstyle=\ttfamily\color{darkgreen}, + language={}, + columns=fixed, + moredelim=**[is][\color{red}]{¡}{¿}, + moredelim=**[is][\color{blendedblue}]{°}{¿}, + moredelim=**[is][\sffamily\it\lstset{columns=fullflexible}]{²}{¿}} +\lstdefinestyle{cmd}{basicstyle=\ttfamily\color{red}, + language={}, + gobble=2, + columns=fixed, + moredelim=**[is][\color{darkgreen}]{¡}{¿}, + moredelim=**[is][\color{structure}]{°}{¿}, + moredelim=**[is][\sffamily\it\lstset{columns=fullflexible}]{²}{¿}} +\lstdefinestyle{shy}{basicstyle=\color{lightgray}} + +\setcounter{topnumber}{3} +\renewcommand\topfraction{0.7} +\setcounter{bottomnumber}{3} +\renewcommand\bottomfraction{0.7} +\setcounter{totalnumber}{5} +\renewcommand\textfraction{0.1} +\renewcommand\floatpagefraction{0.9} + +\setlength{\unitlength}{1cm} + +\newcommand{\protectfile}[1]{#1} +\urlstyle{sf} +\newcommand{\file}[1]{{\color{structure}\protectfile{#1}}} +\newcommand{\textarrow}{{\boldmath $\longrightarrow$}} +\newcommand{\arrowitem}{\item[\textarrow]} +\newcommand{\newterm}[1]{\emph{\color{darkgreen}#1}} +\newcommand{\BIGskip}{\vspace{1cm}} +\newcommand{\shy}{\color{lightgray}} +\newcommand{\hot}{\color{red}} +\newcommand{\shyhot}{\color{lightred}} + +\newcommand{\sectionnonumber}[1]{\section{#1}\addtocounter{section}{-1}} + +\def\showsectionnonumber{\hbox{\Large\color{structure}\bf + \vtop{\secname}\par}\bigskip} + +\newcommand{\nosectionnonumber}[1]{\gdef\nosectionnonumbername{#1}} + +\def\shownosectionnonumber{\hbox{\Large\color{structure}\bf + \vtop{\nosectionnonumbername}\par}\bigskip} + +\def\showsection{\hbox{\Large\color{structure}\bf + \vtop{\hbox{\arabic{section}}}\kern1em% + \vtop{\secname}\par}\bigskip} + +\newcommand{\subsectionnonumber}[1]{\subsection{#1}\addtocounter{subsection}{-1}} + +\def\showsubsectionnonumber{{\large\color{structure}\bf\subsecname\par}\bigskip} + +\def\showsubsection{\hbox{\large\color{structure}\bf + \vtop{\hbox{\arabic{section}.\arabic{subsection}}}\kern1em% + \vtop{\subsecname}\par}\bigskip} + +\newcommand{\subsubsectionnonumber}[1]{\subsubsection{#1}\addtocounter{subsubsection}{-1}} + +\def\showsubsubsectionnonumber{{\normalsize\color{structure}\bf\subsubsecname\par}\bigskip} + +\def\showsubsubsection{\hbox{\normalsize\color{structure}\bf + \vtop{\hbox{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}}\kern1em% + \vtop{\subsubsecname}\par}\bigskip} diff --git a/20220614/rtech-20220614.pdf b/20220614/rtech-20220614.pdf new file mode 100644 index 0000000000000000000000000000000000000000..376990642d52a3ca4fc3151596d5527277c36176 Binary files /dev/null and b/20220614/rtech-20220614.pdf differ diff --git a/20220614/rtech-20220614.tex b/20220614/rtech-20220614.tex new file mode 100644 index 0000000000000000000000000000000000000000..ee8c8fa4b1c290600b016698c1108144bd8add15 --- /dev/null +++ b/20220614/rtech-20220614.tex @@ -0,0 +1,1482 @@ +% rtech-20220614.pdf - Lecture Slides on Computer Technology +% Copyright (C) 2012, 2013, 2014, 2021, 2022 Peter Gerwinski +% +% This document is free software: you can redistribute it and/or +% modify it either under the terms of the Creative Commons +% Attribution-ShareAlike 3.0 License, or under the terms of the +% GNU General Public License as published by the Free Software +% Foundation, either version 3 of the License, or (at your option) +% any later version. +% +% This document is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this document. If not, see <http://www.gnu.org/licenses/>. +% +% You should have received a copy of the Creative Commons +% Attribution-ShareAlike 3.0 Unported License along with this +% document. If not, see <http://creativecommons.org/licenses/>. + +% README: CPU-Stack, Anwender-Software, Pipelining + +\documentclass[10pt,t]{beamer} + +\usepackage{pgslides} +\usepackage{tikz} +\usepackage{rotating} + +\lstdefinestyle{asm}{basicstyle=\color{structure}, + language={}, + gobble=4} + +\title{Rechnertechnik} +\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} +\date{14.\ Juni 2022} + +\begin{document} + +\maketitleframe + +\sectionnonumber{\inserttitle} + +\begin{frame} + + \showsectionnonumber + + \begin{itemize} + \item[\textbf{1}] \textbf{Einführung} + \item[\textbf{2}] \textbf{Vom Schaltkreis zum Computer} + \item[\textbf{3}] \textbf{Architekturmerkmale von Prozessoren} + \begin{itemize} + \color{medgreen} + \item[3.1] Speicherarchitekturen + \item[3.2] Registerarchitekturen + \item[3.3] Befehlssätze + \end{itemize} + \item[\textbf{4}] \textbf{Der CPU-Stack} + \begin{itemize} + \color{medgreen} + \item[4.0] Was ist ein Stack? + \item[4.1] Implementation + \item[4.2] Unterprogramm + \item[4.3] Register sichern + \item[4.4] Puffer-Überläufe + \color{red} + \item[4.5] Stack-Überläufe + \end{itemize} +% \item[\textbf{5}] \textbf{Hardwarenahe Programmierung} + \item[\textbf{5}] \textbf{Anwender-Software} +% \item[\textbf{6}] \textbf{Bus-Systeme} + \item[\textbf{6}] \textbf{Pipelining} +% \item[\textbf{\dots\hspace{-0.75em}}] +% \item[\textbf{9}] \textbf{Ausblick} + \end{itemize} + +\end{frame} + +\setcounter{section}{2} +\section{Architekturmerkmale von Prozessoren} +\subsection{Speicherarchitekturen} + +\begin{frame} + + \showsection + \showsubsection + + Bezeichnungen + \begin{itemize} + \item + \newterm{Bit\/} = 0 oder 1 -- kleinste Einheit an Information + \item + \newterm{Byte\/} = Zusammenfassung mehrerer \newterm{Bits}\\ + zu einer Binärzahl, die ein Zeichen (\newterm{Character\/}) darstellen kann,\\ + häufig 8 Bits (\newterm{Oktett\/}) + \item + \newterm{Speicherwort\/} = Zusammenfassung mehrerer Bits\\ + zu der kleinsten adressierbaren Einheit, häufig 1 Byte + \item + \newterm{RAM\/} = \newterm{Random Access Memory\/} = Hauptspeicher + \item + \newterm{ROM\/} = \newterm{Read Only Memory\/} = nur lesbarer Speicher + \end{itemize} + +\end{frame} + +\begin{frame} + + \showsubsection + + Verschiedene Arten von Speicher + \begin{itemize} + \item + \newterm{Prozessor-Register}\\ + können direkt mit ALU verbunden werden,\\ + besonders schnell (Flipflops),\\ + überschaubare Anzahl von Registern + \item + \newterm{Hauptspeicher}\\ + kann direkt adressisert und mit Prozessor-Registern abgeglichen werden,\\ + heute i.\,d.\,R.\ dynamischer Speicher (Kondensatoren) + \item + \newterm{I/O-Ports}\\ + sind spezielle Speicheradressen, über die\\ + mit externen Geräten kommuniziert wird + \item + \newterm{Massenspeicher}\\ + liegt auf externem Gerät, wird über I/O-Ports angesprochen,\\ + Festplatte, Flash-Speicher, \dots + \end{itemize} + +\end{frame} + +\begin{frame} + + \showsubsection + + \begin{itemize} + \item + \newterm{Von-Neumann-Architektur}\\ + Es gibt nur 1 Hauptspeicher, in dem sich sowohl die Befehle\\ + als auch die Daten befinden. + + \begin{onlyenv}<1> + Vorteil: Flexibilität in der Speichernutzung + + Nachteil: Befehle können überschrieben werden.\\ + $\longrightarrow$ Abstürze und Malware möglich + \end{onlyenv} + + \pause + \item + \newterm{Harvard-Architektur}\\ + Es gibt 2 Hauptspeicher. In einem befinden sich die Befehle,\\ + im anderen die Daten. + + \begin{onlyenv}<2> + Vorteil: Befehle können nicht überschrieben werden\\ + $\longrightarrow$ sicherer als Von-Neumann-Architektur + + Nachteile: Leitungen zum Speicher (Bus) müssen doppelt vorhanden sein,\\ + freier Befehlsspeicher kann nicht für Daten genutzt werden. + \end{onlyenv} + + \pause + \item + Weitere Kombinationen\\ + Hauptspeicher und I/O-Ports gemeinsam oder getrennt,\\ + Hauptspeicher und Prozessorregister gemeinsam oder getrennt + \end{itemize} + +\end{frame} + +\begin{frame} + + \showsubsection + + Beispiele: + \begin{itemize} + \item + Intel IA-32 (i386, Nachfolger und Kompatible):\\ + Von-Neumann-Architektur (plus Speicherschutzmechanismen),\\ + Prozessorregister und I/O-Ports vom Hauptspeicher getrennt + \item + Atmel AVR (z.\,B.\ ATmega):\\ + Harvard-Architektur (Befehlsspeicher als Flash-Speicher grundsätzlich auch schreibbar),\\ + Prozessorregister und I/O-Ports in gemeinsamem Adressbereich mit Hauptspeicher + \item + 6502, Renesas-Mikro-Controller:\\ + Von-Neumann-Architektur,\\ + I/O-Ports in gemeinsamem Adressbereich mit Hauptspeicher,\\ + Prozessorregister und Hauptspeicher getrennt + \end{itemize} + +\end{frame} + +\subsection{Registerarchitekturen} + +\begin{frame}[fragile] + + \showsubsection + + \vspace*{-\medskipamount} + + \begin{itemize} + \item + Mehrere Register, einzeln ansprechbar + \item + \newterm{Akkumulator\/}: Nur 1 Register kann rechnen. + \item + \newterm{Stack-Architektur\/}: Stapel, "`umgekehrte Polnische Notation"' + \end{itemize} + + \pause + + Operationen: typischerweise nur + \lstinline{=}, \lstinline{+=}, \lstinline{-=}, \lstinline{*=}, \lstinline{/=}, \dots + + \pause + \medskip + + Beispiel: \lstinline{c = a + 2 * b;} + + \pause + \medskip + + \begin{minipage}[t]{2cm} + C:\smallskip\par + \begin{lstlisting}[gobble=6] + R = b; + R *= 2; + R += a; + c = R; + \end{lstlisting} + \end{minipage}\pause + \begin{minipage}[t]{4cm} + Mehrere Register:\smallskip\par + \begin{lstlisting}[style=asm,gobble=6] + movl (b), %eax + imull $2, %eax, %eax + addl (a), %eax + movl %eax, (c) + \end{lstlisting} + \smallskip\par + (IA-32-Assembler) + \end{minipage}\pause + \begin{minipage}[t]{3cm} + Akkumulator:\smallskip\par + \begin{lstlisting}[style=asm,gobble=6] + load (b) + mul $2 + add (a) + store (c) + \end{lstlisting} + \smallskip\par + (Pseudo-Assembler) + \end{minipage}\pause + \begin{minipage}[t]{3cm} + Register-Stack:\smallskip\par + \begin{lstlisting}[style=asm,gobble=6] + push (a) + push (b) + push $2 + mul + add + pop (c) + \end{lstlisting} + \end{minipage} + +\end{frame} + +\begin{frame} + + \showsubsection + + Beispiele: + \begin{itemize} + \item + Intel IA-32 (i386, Nachfolger und Kompatible):\\ + Mehrere Register, für verschiedene Zwecke spezialisiert (unübersichtlich),\\[\smallskipamount] + Fließkommaregister: Stack-Architektur + \item + Atmel AVR (z.\,B.\ ATmega):\\ + 32 Register + \item + 6502, Renesas-Mikro-Controller:\\ + 3 Register: A, X, Y. Nur A kann rechnen $\longrightarrow$ Akkumulator + \item + Java Virtual Machine (JVM):\\ + Stack-Architektur + \item + Redcode:\\ + Jede Speicherzelle fungiert als Register + \end{itemize} + +\end{frame} + +\subsection{Befehlssätze} + +\begin{frame} + + \showsubsection + + \begin{itemize} + \item + \newterm{Complex Instruction Set Computer (CISC)} + + \smallskip + + Umfangreiche Befehlssätze, mächtige Befehle + + \begin{onlyenv}<1> + \textarrow\ komfortable manuelle Programmierung in Assembler\\ + \textarrow\ längere Abarbeitungszeit der einzelnen Befehle + + \smallskip + + Realisierung: "`Prozessor im Prozessor"' -- \newterm{Mikroprogramme} + + \smallskip + + Beispiele: IA-32, AMD-64 + \end{onlyenv} + + \medskip + \pause + \item + \newterm{Reduced Instruction Set Computer (RISC)} + + \smallskip + + wenige, wenig mächtige Befehle + + \begin{onlyenv}<2> + \textarrow\ Programmierung in Assembler für Menschen unkomfortabel\\ + \textarrow\ schnelle Abarbeitung der Befehle + + \smallskip + + Beispiele: Atmel AVR, Redcode + \end{onlyenv} + + \pause + \medskip + \item + \newterm{Very Long Instruction Word (VLIW)\/} und\\ + \newterm{Explicitly Parallel Instruction Computing (EPIC)} + + \smallskip + + mehrere Befehle gleichzeitig ausführbar + + \begin{onlyenv}<3> + \textarrow\ mehr Rechenleistung möglich\\ + \textarrow\ Programmierung sehr aufwendig + + \smallskip + + Beispiel: IA-64 + \end{onlyenv} + + \pause + \medskip + \item + \newterm{Orthogonaler Befehlssatz} + + \smallskip + + jeder Befehl mit jeder Adressierungsart kombinierbar + \end{itemize} + +\end{frame} + +\section{Der CPU-Stack\label{CPU-Stack}} +\addtocounter{subsection}{-1} +\subsection{Was ist ein Stack?} + +\begin{frame}[fragile] + + \showsection + \showsubsection + + \bigskip + +\iffalse + + \begin{minipage}[b]{6cm} + \begin{center} + "`First In -- First Out"' + + \bigskip + + \begin{picture}(6,4) + \thicklines + \color{structure} + \put(0.5,0){\line(1,0){5}} + + \put(3.5,0){\only<1-5>{\line(0,1){1}}} + \put(4.5,0){\only<1-4>{\line(0,1){1}}} + \put(3.5,1){\only<1-4>{\line(1,0){1}}} + \put(4.0,0.5){\only<1-4>{\makebox(0,0){\lstinline{3}}}} + \put(3.0,1.5){\only<1>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} + \put(3.0,1.5){\only<1>{\makebox(0,0)[b]{\lstinline{push (3)}}}} + + \put(2.5,0){\only<2-6>{\line(0,1){1}}} + \put(2.5,1){\only<2-5>{\line(1,0){1}}} + \put(3.0,0.5){\only<2-5>{\makebox(0,0){\lstinline{7}}}} + \put(2.0,1.5){\only<2>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} + \put(2.0,1.5){\only<2>{\makebox(0,0)[b]{\lstinline{push (7)}}}} + + \put(1.5,0){\only<3-6>{\line(0,1){1}}} + \put(1.5,1){\only<3-6>{\line(1,0){1}}} + \put(2.0,0.5){\only<3-6>{\makebox(0,0){\lstinline{137}}}} + \put(1.0,1.5){\only<3>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} + \put(1.0,1.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}} + + \put(4.55,1.05){\only<4>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} + \put(5.00,1.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 3}}} + + \put(3.55,1.05){\only<5>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} + \put(4.00,1.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}} + + \put(2.55,1.05){\only<6>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} + \put(3.00,1.60){\only<6>{\makebox(0,0)[b]{\lstinline{pop ()}: 137}}} + \end{picture} + + \bigskip + + FIFO = Queue = Reihe + \end{center} + \end{minipage}\hfill + +\fi + + \begin{minipage}[b]{6cm} + \begin{center} + "`Last In -- First Out"' + + \bigskip + + \begin{picture}(6,4) + \thicklines + \color{structure} + \put(1.5,0){\line(1,0){3}} + + \put(2.5,0){\line(0,1){1}} + \put(3.5,0){\line(0,1){1}} + \put(2.5,1){\line(1,0){1}} + \put(3.0,0.5){\makebox(0,0){\lstinline{3}}} + \put(2.0,1.5){\only<1>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} + \put(2.0,1.5){\only<1>{\makebox(0,0)[b]{\lstinline{push (3)}}}} + + \put(2.5,1){\only<2-5>{\line(0,1){1}}} + \put(3.5,1){\only<2-5>{\line(0,1){1}}} + \put(2.5,2){\only<2-5>{\line(1,0){1}}} + \put(3.0,1.5){\only<2-5>{\makebox(0,0){\lstinline{7}}}} + \put(2.0,2.5){\only<2>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} + \put(2.0,2.5){\only<2>{\makebox(0,0)[b]{\lstinline{push (7)}}}} + + \put(2.5,2){\only<3-4>{\line(0,1){1}}} + \put(3.5,2){\only<3-4>{\line(0,1){1}}} + \put(2.5,3){\only<3-4>{\line(1,0){1}}} + \put(3.0,2.5){\only<3-4>{\makebox(0,0){\lstinline{137}}}} + \put(2.0,3.5){\only<3>{\makebox(0,0)[tl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,-0.45);}}}} + \put(2.0,3.5){\only<3>{\makebox(0,0)[b]{\lstinline{push (137)}}}} + + \put(3.55,3.05){\only<4>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} + \put(4.00,3.60){\only<4>{\makebox(0,0)[b]{\lstinline{pop ()}: 137}}} + + \put(3.55,2.05){\only<5>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} + \put(4.00,2.60){\only<5>{\makebox(0,0)[b]{\lstinline{pop ()}: 7}}} + + \put(3.55,1.05){\only<6>{\makebox(0,0)[bl]{\tikz{\draw[-latex, line width=1pt](0,0)--(0.45,0.45);}}}} + \put(4.00,1.60){\only<6>{\makebox(0,0)[b]{\lstinline{pop ()}: 3}}} + \end{picture} + + \bigskip + + LIFO = Stack = Stapel + \end{center} + \end{minipage} + +% +% \dots + +\end{frame} +\subsection{Implementation} + +\begin{frame} + + \showsection + \showsubsection + + Speicher, in dem Werte "`gestapelt"' werden: \newterm{Stack} + + \begin{itemize} + \item + Speicherbereich (ein array) reservieren + \item + Variable (typischerweise: Prozessorregister) als + \newterm{Stack Pointer\/} reservieren \textarrow\ \lstinline{SP} + \item + Assembler-Befehl \lstinline[style=asm]{push foo}: \quad + \lstinline{*SP++ = foo;} + \item + Assembler-Befehl \lstinline[style=asm]{pop bar}: \quad + \lstinline{bar = *--SP;} + \end{itemize} + + \pause + \medskip + Speziell: Unterprogramme + +\end{frame} + +\subsection{Unterprogramme} + +\begin{frame}[fragile] + + \showsection + \showsubsection + + \begin{minipage}[t]{4.5cm} + Parameter: + \begin{itemize} + \item + Prozessorregister + \item + CPU-Stack + \end{itemize} + + \smallskip + + Rückgabewert: + \begin{itemize} + \item + Prozessorregister + \end{itemize} + \end{minipage}% + \begin{minipage}[t]{5cm} + Aufruf: + \begin{itemize} + \item + \lstinline[style=asm]{push IP}\\ + \lstinline[style=asm]{jmp foo} + {\color{red}\boldmath $\longleftarrow$ mov \#foo IP}\\ + \textarrow\ \lstinline[style=asm]{call foo} + \end{itemize} + Rücksprung: + \begin{itemize} + \item + \lstinline[style=asm]{pop IP}\\ + \textarrow\ \lstinline[style=asm]{ret} + \end{itemize} + \end{minipage} + +\end{frame} + +\subsection{Register sichern} + +\begin{frame} + + \showsection + \showsubsection + + Ein Unterprogramm verändert Registerinhalte. + \begin{itemize} + \item + im Hauptprogramm nötigenfalls vor Aufruf sichern + \item + im Unterprogramm vor Benutzung sichern + \item + Kombinationen (manche Register so, manche so) + \end{itemize} + +\end{frame} + +\subsection{Puffer-Überläufe} + +\begin{frame}[fragile] + + \showsection + \showsubsection + + \begin{lstlisting} + #include <stdio.h> + + int main (void) + { + char name[10]; + printf ("Ihr Name: "); + gets (name); + printf ("Hallo, %s! :-)\n", name); + return 0; + } + \end{lstlisting} + +\end{frame} + +\subsection{Stack-Überläufe} + +\begin{frame}[fragile] + + \showsection + \showsubsection + + Unendliche Rekursion + + \begin{lstlisting} + #include <stdio.h> + + int fak (int n) + { + if (n <= 1) + return 1; + else + return n * fak (n); + } + + int main (void) + { + printf ("%d! = %d\n", 6, fak (6)); + return 0; + } + \end{lstlisting} + \begin{picture}(0,0) + \put(5,6){\makebox(0,0)[tl]{\begin{minipage}{6cm} + Bei jedem Aufruf wird die Rücksprungadresse auf den Stack gelegt + und die Variable \lstinline{n} auf dem Stack gesichert. + \end{minipage}}} + \put(3.7,3.5){\makebox(0,0)[l]{\color{red}$\longleftarrow$ Fehler!}} + \end{picture} + \vspace*{-1cm} + +\end{frame} + +\section{Anwender-Software} +\subsection{Relokation und Linken} + +\begin{frame}[fragile] + + \showsection + \vspace*{-\smallskipamount} + \showsubsection + + Software im Speicher + + \begin{center} + \setlength{\unitlength}{0.8cm} + \begin{picture}(15,3)(2,-1.25) + \footnotesize + + \put(2,1.0){\line(1,0){15}} + \multiput(2,1)(0.1,0){151}{\line(0,1){0.1}} + \put(2,1.1){\line(1,0){15}} + \put(3.5,1.2){$\overbrace{\rule{10\unitlength}{0pt}}$} + \only<2->{% + \put(3.5,-0.05){\vector(0,1){1}} + \put(2.5,-0.05){\line(1,0){1}} + \put(2.4,-0.05){\makebox(0,0)[r]{\lstinline|CS|}}} + + \put(4.95,0.7){\line(0,1){0.25}} + \put(4.95,0.7){\line(1,0){0.5}} + \put(5.45,0.7){\vector(0,1){0.25}} + \put(6.65,0.7){\line(0,1){0.25}} + \put(6.65,0.7){\line(1,0){0.8}} + \put(7.45,0.7){\vector(0,1){0.25}} + \put(9.55,0.6){\line(0,1){0.35}} + \put(9.55,0.6){\line(-1,0){3.2}} + \put(6.35,0.6){\vector(0,1){0.35}} + \put(7.25,0.4){\makebox(0,0)[t]{Sprünge innerhalb des Programms}} + + \put(8.50,1.55){\makebox(0,0)[b]{Programm}} + \end{picture} +% \pause + \begin{picture}(15,3)(0,-1.25) + \footnotesize + + \put(0,1.0){\line(1,0){15}} + \multiput(0,1)(0.1,0){151}{\line(0,1){0.1}} + \put(0,1.1){\line(1,0){15}} + \put(3.5,1.2){$\overbrace{\rule{10\unitlength}{0pt}}$} + \only<2->{% + \put(3.5,-0.05){\vector(0,1){1}} + \put(2.5,-0.05){\line(1,0){1}} + \put(2.4,-0.05){\makebox(0,0)[r]{\lstinline|CS|}}} + + \put(4.95,0.7){\line(0,1){0.25}} + \put(4.95,0.7){\line(1,0){0.5}} + \put(5.45,0.7){\vector(0,1){0.25}} + \put(6.65,0.7){\line(0,1){0.25}} + \put(6.65,0.7){\line(1,0){0.8}} + \put(7.45,0.7){\vector(0,1){0.25}} + \put(9.55,0.6){\line(0,1){0.35}} + \put(9.55,0.6){\line(-1,0){3.2}} + \put(6.35,0.6){\vector(0,1){0.35}} + \put(7.25,0.4){\makebox(0,0)[t]{Sprünge innerhalb des Programms}} + + \put(8.50,1.55){\makebox(0,0)[b]{Programm}} + \end{picture} + \end{center} +% \pause + \vspace*{-0.8cm} + Sprünge anpassen: Relokation + + \pause + \smallskip + + Hardware-Unterstützung (z.\,B.\ Intel): Speichersegmentierung + + \lstinline{CS} = Code-Segment: Segment-Register oder Selektor + +\end{frame} + +\begin{frame}[fragile] + + \showsubsection + \vspace*{-0.8cm} + + \begin{center} + \setlength{\unitlength}{0.8cm} + \begin{picture}(15,4.2)(2,-1.25) + \footnotesize + + \put(2,1.0){\line(1,0){15}} + \multiput(2,1)(0.1,0){151}{\line(0,1){0.1}} + \put(2,1.1){\line(1,0){15}} + \put(3.5,1.2){$\overbrace{\rule{8.0\unitlength}{0pt}}$} + \put(7.50,1.55){\makebox(0,0)[b]{Programm}} + \put(12.2,2.2){$\overbrace{\rule{3.0\unitlength}{0pt}}$} + \put(13.7,2.55){\makebox(0,0)[b]{Bibliothek}} + + \put(8.45,0.95){\line(0,-1){1}} + \put(8.45,-0.05){\line(1,0){5.5}} + \put(13.95,-0.05){\vector(0,1){1}} + \put(13.95,1.25){\begin{rotate}{45}\normalsize\lstinline{scanf}\end{rotate}} + \put(10.15,0.95){\line(0,-1){0.8}} + \put(10.15,0.15){\line(1,0){2.5}} + \put(12.65,0.15){\vector(0,1){0.8}} + \put(12.65,1.25){\begin{rotate}{45}\normalsize\lstinline{printf}\end{rotate}} + \put(11.20,-0.25){\makebox(0,0)[t]{Sprünge aus dem Programm heraus}} + \end{picture} +% \pause + \begin{picture}(15,4.2)(2,-1.25) + \footnotesize + + \put(2,1.0){\line(1,0){15}} + \multiput(2,1)(0.1,0){151}{\line(0,1){0.1}} + \put(2,1.1){\line(1,0){15}} + \put(3.5,1.2){$\overbrace{\rule{8.0\unitlength}{0pt}}$} + \put(7.50,1.55){\makebox(0,0)[b]{Programm}} + \put(13.2,2.2){$\overbrace{\rule{3.0\unitlength}{0pt}}$} + \put(14.7,2.55){\makebox(0,0)[b]{Bibliothek}} + + \put(8.45,0.95){\line(0,-1){1}} + \put(8.45,-0.05){\line(1,0){6.5}} + \put(14.95,-0.05){\vector(0,1){1}} + \put(14.95,1.25){\begin{rotate}{45}\normalsize\lstinline{scanf}\end{rotate}} + \put(10.15,0.95){\line(0,-1){0.8}} + \put(10.15,0.15){\line(1,0){3.5}} + \put(13.65,0.15){\vector(0,1){0.8}} + \put(13.65,1.25){\begin{rotate}{45}\normalsize\lstinline{printf}\end{rotate}} + \put(12.20,-0.25){\makebox(0,0)[t]{Sprünge aus dem Programm heraus}} + \end{picture} + \end{center} +% \pause + \vspace*{-0.8cm} + Sprünge anpassen: Linken + +% \pause + \smallskip + + Beim Erzeugen der Datei: statisches Linken\\ + Beim Laden: dynamisches Linken + +\end{frame} + +\subsection{Dateiformate} + +\begin{frame} + + \visible<1->{\showsubsection} + + Man kann Maschinenprogramme nicht "`einfach so"' in den Speicher laden. + +% \pause + \bigskip + + Sprünge anpassen + \begin{itemize} + \item + Relokation: Relokationstabelle + \item + Linken: Symboltabelle + \end{itemize} + +\end{frame} + +\begin{frame} + + \showsubsection + + \vspace*{-0.5cm} + + \begin{center} + \setlength{\unitlength}{0.8cm} + \begin{picture}(15,6)(0,-1.25) + \footnotesize + + \put(0,1.0){\line(1,0){15}} + \multiput(0,1)(0.1,0){151}{\line(0,1){0.1}} + \put(0,1.1){\line(1,0){15}} + \put(0,0.8){\makebox(0,0)[tl]{Ausführbare Binärdatei}} + \put(0.5,1.2){$\overbrace{\rule{1.0\unitlength}{0pt}}$} + \put(2.0,1.2){$\overbrace{\rule{1.0\unitlength}{0pt}}$} + \put(3.5,1.2){$\overbrace{\rule{11.5\unitlength}{0pt}}$} + + \put(0,4.0){\line(1,0){5}} + \multiput(0,3.5)(0.5,0){11}{\line(0,1){0.5}} + \put(0,3.5){\line(1,0){5}} + \put(0,4.2){\makebox(0,0)[bl]{Relokationstabelle}} + \put(1.0,3.4){\line(0,-1){1.9}} + \put(3.75,3.4){\vector(1,-2){1.2}} + \put(4.25,3.4){\vector(1,-1){2.4}} + \put(4.75,3.4){\vector(2,-1){4.8}} + + \put(4.95,0.7){\line(0,1){0.25}} + \put(4.95,0.7){\line(1,0){0.5}} + \put(5.45,0.7){\vector(0,1){0.25}} + \put(6.65,0.7){\line(0,1){0.25}} + \put(6.65,0.7){\line(1,0){0.8}} + \put(7.45,0.7){\vector(0,1){0.25}} + \put(9.55,0.6){\line(0,1){0.35}} + \put(9.55,0.6){\line(-1,0){3.2}} + \put(6.35,0.6){\vector(0,1){0.35}} + \put(7.25,0.4){\makebox(0,0)[t]{Sprünge innerhalb des Programms}} + + \put(6,4.0){\line(1,0){5}} + \multiput(6,3.5)(0.5,0){11}{\line(0,1){0.5}} + \put(6,3.5){\line(1,0){5}} + \put(6,4.2){\makebox(0,0)[bl]{Symboltabelle}} + \put(6.4,3.4){\line(-2,-1){3.8}} + \put(10.25,3.4){\vector(1,-2){1.2}} + \put(10.75,3.4){\vector(1,-1){2.4}} + + \put(9.25,1.55){\line(0,1){1}} + \put(8.50,2.60){\makebox(0,0)[b]{Maschinenprogramm}} + + \put(11.45,0.95){\vector(0,-1){1}} + \put(11.45,-0.10){\makebox(0,0)[t]{\lstinline{scanf}}} + \put(13.15,0.95){\vector(0,-1){1}} + \put(13.15,-0.10){\makebox(0,0)[t]{\lstinline{printf}}} + \put(12.30,-0.50){\makebox(0,0)[t]{Sprünge aus dem Programm heraus}} + + \end{picture} + \end{center} + + \vspace*{-1.2cm} + + \begin{onlyenv}<2> + + Ausführbare Binärdatei: + + \smallskip + + Relokationstabelle,\\ + Symboltabelle für dynamischen Linker + + \smallskip + + Formate: a.out, COFF, ELF, \dots\\ + Dateiendungen: (keine), .elf, .com, .exe, .scr + + \end{onlyenv} + + \begin{onlyenv}<3> + + Objektdatei: + + \smallskip + + Relokationstabelle,\\ + Symboltabellen für statischen und dynamischen Linker + + \smallskip + + Formate: a.out, COFF, ELF, \dots\\ + Dateiendungen: .o, .obj + + \end{onlyenv} + + \begin{onlyenv}<4-> + + \strut\\ + Bibliothek: + + \smallskip + + Zusammenfassung mehrerer Objekt-Dateien + + \smallskip + + Statische Bibliotheken: .a, .lib\\ + Dynamische Bibliotheken: .so, .dll + + \end{onlyenv} + +\end{frame} + +\subsection{Die Toolchain} + +\begin{frame}[fragile] + + \showsubsection + + \vspace*{-0.8cm} + \begin{center} + \addtolength{\leftskip}{4cm} + \small + \newcommand{\vtextarrow}[1]{% + \begin{picture}(0,0.8) + \put(0,0.8){\vector(0,-1){0.8}} + \put(0.125,0.4){\makebox(0,0)[l]{#1}} + \end{picture}} + + \framebox{\shortstack{\strut menschliche Gedanken}} + + \vtextarrow{Texteditor} + + \framebox{\shortstack{\strut C-Quelltext}} % (z.\,B.\ hello.c)}} + + \vtextarrow{Compiler} + + \framebox{\shortstack{\strut Assembler-Quelltext}} % (z.\,B.\ hello.s, hello.asm)}} + + \vtextarrow{Assembler} + + \framebox{\shortstack{\strut Objekt- und Bibliothek-Dateien}} % (z.\,B.\ hello.o, hello.obj)}} + + \vtextarrow{Linker} + + \framebox{\shortstack{\strut ausführbare Binärdatei}} % (z.\,B.\ hello, hello.exe)}} + + \vtextarrow{Loader} + + \framebox{\shortstack{\strut Programm im Speicher bereit zur Ausführung}} + \end{center} + +% \pause + \vspace*{-7cm} + Automatischer Aufruf: + \begin{itemize} + \item + Entwicklungsumgebungen\\ + (z.\,B.\ Eclipse, Code::Blocks, \dots) + \medskip + \item + \file{gcc} = Compiler\\ + \hspace*{3em}+ Assembler\\ + \hspace*{3em}+ Linker\\ + \hspace*{3em}+ \dots + \medskip + \item + \file{make} kann \emph{alles} aufrufen + \end{itemize} + +\end{frame} + +\subsection{Besonderheiten von Mikro-Controllern} + +\begin{frame} + + \showsubsection + + Kein Betriebssystem\\ % \pause\\ + \textarrow\ kein Relocator, kein dynamischer Linker\\ % \pause\\ + \textarrow\ Wir müssen dem Mikro-Controller alles "`mundgerecht"' servieren. + +% \pause + \smallskip + + \begin{itemize} + \item + fertiges ROM: Hersteller + \item + Flash-Speicher und In-System Programmer (ISP) + \item + Flash-Speicher und Boot-Loader + \end{itemize} + + \smallskip + + In jedem Fall: statisch linken, Relokation vorher + \begin{picture}(0,0) + \color{red} + \put(0.1,0.1){\line(1,0){1.2}} + \put(1.3,0.1){\vector(0,1){2.2}} + \end{picture}\\ + \textarrow\ ELF-Datei in HEX-Datei umwandeln + + \smallskip + + Format: Intel-Hex-Format\\ + Dateiendung: .hex + +\end{frame} + +\section{Pipelining} +\subsection{Konzept} + +\newcommand{\wm}{\raisebox{-0.3cm}{\includegraphics[width=1.0cm]{Waschen_30.pdf}}} +\newcommand{\wt}{\raisebox{-0.3cm}{\includegraphics[width=1.0cm]{Trommeltrocknen.pdf}}} +\newcommand{\be}{\raisebox{-0.3cm}{\includegraphics[width=1.0cm]{Buegeln.pdf}}} + +\begin{frame} + \showsection + + \pause + \showsubsection + \begin{itemize} + \item + Aufgabe in Teilaufgaben zerlegen + \item + Teilaufgaben parallel ausführen + \end{itemize} + + \pause + \bigskip + Beispiel: Wäsche waschen + \pause + \begin{itemize} + \item + Teilaufgaben: \wm, \wt, \be + \pause + \item + müssen nacheinander ausgeführt werden\pause: Datenfluß + \pause + \item + belegen jeweils 1 Ressource + \end{itemize} + +\end{frame} + +\begin{frame} + + 3 Ladungen Wäsche + \begin{center} + \begin{onlyenv}<1-2> + \begin{picture}(12,3.5) + \thicklines + \put(1,1){\wm} + \put(2,1){\wt} + \put(3,1){\be} + \put(4,2){\wm} + \put(5,2){\wt} + \put(6,2){\be} + \put(7,3){\wm} + \put(8,3){\wt} + \put(9,3){\be} + \put(-0.1,0.5){\vector(1,0){11.1}} + \put(11.5,0.5){\makebox(0,0){$t$}} + \put(10.5,1.0){\makebox(0,0)[r]{ineffizient}} + \end{picture}\\[\medskipamount] + \end{onlyenv} + \begin{onlyenv}<2-4> + \begin{picture}(12,3.5) + \thicklines + \put(1,1){\wm} + \put(2,1){\wt} + \put(3,1){\be} + \put(2,2){\wm} + \put(3,2){\wt} + \put(4,2){\be} + \put(3,3){\wm} + \put(4,3){\wt} + \put(5,3){\be} + \put(-0.1,0.5){\vector(1,0){11.1}} + \put(11.5,0.5){\makebox(0,0){$t$}} + \put(10.5,1.0){\makebox(0,0)[r]{effizient}} + \end{picture}\\[\medskipamount] + \end{onlyenv} + \begin{onlyenv}<3-> + \begin{picture}(12,3.5) + \thicklines + \put(1,1){\wm} + \put(2,1){\wt} + \put(3,1){\be} + \put(1,2){\wm} + \put(2,2){\wt} + \put(3,2){\be} + \put(1,3){\wm} + \put(2,3){\wt} + \put(3,3){\be} + \put(-0.1,0.5){\vector(1,0){11.1}} + \put(11.5,0.5){\makebox(0,0){$t$}} + \put(10.5,1.0){\makebox(0,0)[r]{noch effizienter}} + \color{red} + \thicklines + \put(0.5,0.8){\only<4->{\line(4,1){10}}} + \put(0.5,3.3){\only<4->{\line(4,-1){10}}} + \put(7.5,1.7){\only<4->{\mbox{\shortstack{Ressourcen-\\konflikt}}}} + \end{picture}\\[\medskipamount] + \end{onlyenv} + \begin{onlyenv}<5-> + \begin{picture}(12,3.5) + \thicklines + \put(1,1){\wm} + \put(2,1){\wt} + \put(3,1){\be} + \put(1,2){\wt} + \put(2,2){\be} + \put(3,2){\wm} + \put(1,3){\be} + \put(2,3){\wm} + \put(3,3){\wt} + \put(-0.1,0.5){\vector(1,0){11.1}} + \put(11.5,0.5){\makebox(0,0){$t$}} + \put(10.5,1.0){\makebox(0,0)[r]{noch effizienter}} + \color{red} + \thicklines + \put(0.5,0.8){\only<6->{\line(4,1){10}}} + \put(0.5,3.3){\only<6->{\line(4,-1){10}}} + \put(7.5,1.7){\only<6->{\mbox{\shortstack{Daten-\\konflikt}}}} + \end{picture}% + \end{onlyenv} + \end{center} + +\end{frame} + +\subsection{Arithmetik-Pipelines} + +\newcommand{\insns}[1]{% + \begin{picture}(0,0) + \put(0,0){\line(1,0){2}} + \put(2,0){\line(0,-1){#1}} + \put(2,-#1){\vector(-1,0){2}} + \end{picture}} + +\newcommand{\insnsup}[1]{% + \begin{picture}(0,0) + \put(0,0){\line(1,0){2}} + \put(2,0){\line(0,1){#1}} + \put(2,#1){\vector(-1,0){2}} + \end{picture}} + +\begin{frame} + + \showsubsection + "`Register-FIFO"' + + \pause + \smallskip + + Pseudo-Code: Berechnung von + \begin{displaymath} + S = \left(\begin{array}{c}a_1\\a_2\\a_3\end{array}\right) + \cdot\left(\begin{array}{c}b_1\\b_2\\b_3\end{array}\right) + = a_1 \cdot b_1 + + a_2 \cdot b_2 + + a_3 \cdot b_3 + \end{displaymath} + mit einer Pipeline der Länge 3 + + \pause + \medskip + + \begingroup + \setlength{\unitlength}{\baselineskip}% + \begin{picture}(0,0)(-5.0,-0.25) + \color{red} + \put(0,0.0){\only<4->{\insns{3}}} + \put(0.5,-1){\only<5->{\insns{2.9}}} + \put(1.0,-2){\only<6->{\insns{3}}} + \put(0.5,-4.1){\only<8->{\insns{2.8}}} + \put(0.5,-7.1){\only<11->{\insns{2.9}}} + \put(-1.5,-9.25){\only<15->{\shortstack{Daten-\\konflikt}}} + \end{picture}% + \color{structure} + push $a_1 \cdot b_1$\\ + \pause + \pause + push $a_2 \cdot b_2$\\ + \pause + push $a_3 \cdot b_3$\\ + \pause + $s_1$ = pop\\ + \pause + push $s_1 + \mbox{pop}$\\ + \pause + $s_3$ = pop\\ + \pause + nop\\ + \pause + push $s_3 + \mbox{pop}$\\ + \pause + nop\\ + \pause + nop\\ + \pause + $S$ = pop\\ + \endgroup + \pause + \pause + \begin{picture}(0,0) + \color{red} + \put(5,3.8){\makebox(0,0)[l]{$\left.\rule{0pt}{1.2cm}\right\}$ effizient: Pipeline gefüllt}} + \put(5,1.4){\makebox(0,0)[l]{$\left.\rule{0pt}{1.2cm}\right\}$ ineffizient: "`Blasen"'}} + \end{picture} + \pause + \vspace*{-1.25cm} + \begin{flushright} + \dots\ aber immer noch effizienter als\\ + 3 Schritte für jede Operation + \end{flushright} + +\end{frame} + +\subsectionnonumber{Reales Beispiel: \break Vektor-Addition auf i860} + +\begin{frame}[fragile] + + \begin{minipage}[t]{5cm} + \raggedright + \showsubsectionnonumber + \begin{lstlisting} + .align 8 + .globl _vadd + nop + _vadd: + shr 1,r19,r19 + bte r19,r0,exitadd + addu 0x000F,r16,r16 + andnot 0x000F,r16,r16 + adds -16,r16,r16 + addu 0x000F,r17,r17 + andnot 0x000F,r17,r17 + adds -16,r17,r17 + addu 0x000F,r18,r18 + andnot 0x000F,r18,r18 + adds -16,r18,r18 + mov -1,r20 + \end{lstlisting} + \end{minipage} + \begin{minipage}[t]{5cm} + \begin{lstlisting} + fld.q 16(r16)++,f16 + fld.q 16(r17)++,f20 + pfadd.dd f16,f20,f0 + bla r20,r19,loopadd + pfadd.dd f18,f22,f0 + loopadd: + d.pfadd.dd f0,f0,f0 + fld.q 16(r16)++,f16 + d.pfadd.dd f0,f0,f24 + fld.q 16(r17)++,f20 + d.pfadd.dd f16,f20,f26 + bla r20,r19,loopadd + d.pfadd.dd f18,f22,f0 + fst.q f24,16(r18)++ + nop + nop + nop + exitadd: + bri r1 + nop + \end{lstlisting} + \end{minipage} + +\end{frame} + +\lstdefinestyle{shybubble}{basicstyle=\color{lightgray}, + moredelim=**[is][\color{structure}]{¡}{¿}, + moredelim=**[is][\only<7->{\color{red}}]{°}{¿}} + +\begin{frame}[fragile] + + \begin{minipage}[t]{5cm} + \raggedright + \showsubsectionnonumber + \begin{lstlisting}[style=shybubble] + .align 8 + .globl _vadd + nop + _vadd: + shr 1,r19,r19 + bte r19,r0,exitadd + addu 0x000F,r16,r16 + andnot 0x000F,r16,r16 + adds -16,r16,r16 + addu 0x000F,r17,r17 + andnot 0x000F,r17,r17 + adds -16,r17,r17 + addu 0x000F,r18,r18 + andnot 0x000F,r18,r18 + adds -16,r18,r18 + mov -1,r20 + \end{lstlisting} + \end{minipage} + \begin{minipage}[t]{5cm} + \begin{lstlisting}[style=shybubble] + ¡fld.q 16(r16)++,f16 + fld.q 16(r17)++,f20 + pfadd.dd f16,f20,f0 + bla r20,r19,loopadd + pfadd.dd f18,f22,f0 + loopadd: + d.pfadd.dd °f0,f0,f0¿ + fld.q 16(r16)++,f16 + d.pfadd.dd °f0,f0¿,f24 + fld.q 16(r17)++,f20 + d.pfadd.dd f16,f20,f26 + bla r20,r19,loopadd + d.pfadd.dd f18,f22,°f0¿ + fst.q f24,16(r18)++¿ + nop + nop + nop + exitadd: + bri r1 + nop + \end{lstlisting} + \end{minipage} + + \pause + \begingroup + \setlength{\unitlength}{\baselineskip}% + \begin{picture}(0,0)(-21.0,-17.6) + \color{red} + \put(0,0){\only<2->{\insns{5.9}}} + \put(1.0,-2){\only<3->{\insns{6.0}}} + \put(-7,-9){\only<4->{\line(-1,0){1}}} + \put(-8,-9){\only<4->{\line(0,-1){2}}} + \put(-8,-11){\only<4->{\line(-1,0){1}}} + \put(-9,-11){\only<4->{\line(0,1){8}}} + \put(-9,-3){\only<4->{\vector(1,0){0.7}}} + \put(0.8,-7.8){\only<5->{\insnsup{1.7}}} + \put(0.8,-10){\only<6->{\insnsup{1.8}}} + \put(-0.5,-12.5){\only<7->{\mbox{6mal f0 = 2 Blasen}}} + \end{picture}% + \endgroup + + \vspace{-2cm} + \begin{flushright} + \only<8->{Immerhin: 2 Additionen in 4 Taktzyklen} + + \medskip + + \only<9->{Dies ist ein \emph{einfaches} Beispiel.} + \end{flushright} + +\end{frame} + +\subsection{Instruktions-Pipelines} + +\begin{frame}[fragile] + + \showsubsection + + Ein Prozessor benötigt Zeit, um einen Befehl zu verstehen. + + \textarrow\ Während Befehlsausführung nächste Befehle vorauslesen + + \medskip + + \begin{lstlisting}[style=shy] + ².L3: + movw r30,r20¿ + ³add r30,r18¿ + °adc r31,r19¿ + ¤mov r24,r18 + subi r24,lo8(-(1)) + st Z,r24 + subi r18,lo8(-(1)) + sbci r19,hi8(-(1)) + cp r22,r18 + cpc r23,r19¿ + ¢brge .L3¿ + æret¿ + \end{lstlisting} + + \begin{picture}(0,0) + \color{red} + \put(0.5,1.00){\only<8->{\line(-1,0){0.4}}} + \put(0.1,1.00){\only<8->{\line(0,1){4.15}}} + \put(0.1,5.15){\only<8->{\vector(1,0){0.4}}} + \put(0.5,0.90){\only<9->{\line(-1,0){0.4}}} + \put(0.1,0.90){\only<9->{\line(0,-1){0.35}}} + \put(0.1,0.55){\only<9->{\vector(1,0){0.4}}} + \put(2.5,0.825){\only<10->{\begin{minipage}[t]{8cm} + bedingter Sprung: + Welche Befehle vorauslesen?\\[\smallskipamount] + \only<11->{Kontrollflußkonflikt} + \end{minipage}}} + \end{picture} + + \begin{flushright} + \vspace*{-0.5cm} + \only<12->{Lösungsansatz: Zweigvorhersage} + \vspace*{-1cm} + \end{flushright} + +\end{frame} + +\subsubsectionnonumber{Zweigvorhersage -- Branch Prediction} + +\begin{frame}[fragile] + + \showsubsection + \showsubsubsectionnonumber + + \begin{itemize} + \setlength{\unitlength}{\baselineskip}% + \pause + \item + Sprünge nach oben sind Schleifen: "`Ja"'\\ + Sprünge nach unten sind Auswahl-Verzweigungen: "`Nein"' + \pause + \item + Delayed Branches: Sprungbefehl verspätet ausführen\\ + \textarrow\ Optimierung manuell oder durch Compiler + \pause + \medskip + \begin{lstlisting} + loopadd: + d.pfadd.dd f0,f0,f0 + fld.q 16(r16)++,f16 + d.pfadd.dd f0,f0,f24 + fld.q 16(r17)++,f20 + d.pfadd.dd f16,f20,f26 + bla r20,r19,loopadd + d.pfadd.dd f18,f22,f0 + fst.q f24,16(r18)++ + \end{lstlisting} + \begin{picture}(0,0)(-9.6,-12.2) + \color{red} + \put(-7,-9){\line(-1,0){1}} + \put(-8,-9){\line(0,-1){2}} + \put(-8,-11){\line(-1,0){1}} + \put(-9,-11){\line(0,1){8}} + \put(-9,-3){\vector(1,0){0.7}} + \end{picture} + \pause + \item + Branch History Table: Sprünge merken + \pause + \item + \dots + \end{itemize} + +\end{frame} + +\subsectionnonumber{Zusammenfassung} + +\begin{frame} + + \showsection + \showsubsectionnonumber + + \begin{itemize} + \item + Teilaufgaben parallel ausführen + \item + Arithmetik-Pipelines führen Berechnungen parallel aus,\\ + Instruktions-Pipelines lesen Befehle voraus + \item + Ressourcen-, Daten- und Kontrollflußkonflikte führen zu "`Blasen"' + \item + Zweigvorhersage reduziert Kontrollflußkonflikte in Instruktions-Pipelines + \begin{itemize} + \item + nach oben / nach unten + \item + Delayed Branches: manuell optimieren + \item + Branch History Table: Sprünge merken + \end{itemize} + \end{itemize} + +\end{frame} + +\end{document} diff --git a/20220614/rtech-20220614.txt b/20220614/rtech-20220614.txt new file mode 100644 index 0000000000000000000000000000000000000000..9e79e9449f4036d1f71b109a2a0e7310ac1ab492 --- /dev/null +++ b/20220614/rtech-20220614.txt @@ -0,0 +1,26 @@ +Die Meltdown-Sicherheitslücke, 14.06.2022, 14:30:35 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +https://de.wikipedia.org/wiki/Meltdown_(Sicherheitsl%C3%BCcke) + +Ursache: Fehler in der Instruktions-Pipeline + +Wirkung: Programme können Speicher auslesen (z.B. aus dem Kernel), + auf den sie eigentlich keinen Zugriff haben. + +Vorgehensweise: + 1. Lies die Speicherzelle. Dies führt zu einem Absturz. + 2. Nimm den gelesenen Wert als Index für ein Array, + dessen Elemente jeweils 4096 Bytes groß sind. + 3. Lies eine Zahl aus dem Array. + +Während 1. abstürzt, wurden bereits 2. und 3. vorausgelesen. +Wegen 3. hat der Prozessor bereits den virtuellen Speicher an +der Stelle des Arrays in reellen Speicher umgewandelt. + +Danach greift ein anderer Thread auf das Array zu. +Der Index, bei dem dies schneller erfolgt, ist der +gesuchte Wert der unzugänglichen Speicherzelle. + +Dies ist ein Fehler im Prozessor. +Der Absturz hätte eigentlich das Einlagern des virtuellen Speichers +verhindern müssen.