diff --git a/20210607/rtech-20210607.tex b/20210607/rtech-20210607.tex index 56b7d392521787771c2058bd060480f726683766..af8429b35780ac4ae7c55daa4b02beaf25d32209 100644 --- a/20210607/rtech-20210607.tex +++ b/20210607/rtech-20210607.tex @@ -20,7 +20,7 @@ % Attribution-ShareAlike 3.0 Unported License along with this % document. If not, see <http://creativecommons.org/licenses/>. -% README: Architekturmerkmale von Prozessoren +% README: CPU-Stack, Anwender-Software \documentclass[10pt,t]{beamer} diff --git a/20210608/hello-1.c b/20210608/hello-1.c new file mode 100644 index 0000000000000000000000000000000000000000..95066d98a9b3e6713957e0bc8ba4a34569596600 --- /dev/null +++ b/20210608/hello-1.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main (void) +{ + char *s = "Hello, world!"; + printf ("%s\n", s); + return 0; +} diff --git a/20210608/hello-2.cpp b/20210608/hello-2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2ec9589ba98d1a4146aa419c7ba3a1106b0d3f11 --- /dev/null +++ b/20210608/hello-2.cpp @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main () +{ + char *s = "Hello, world!"; + printf ("%s\n", s); + return 0; +} diff --git a/20210608/hello-3.cpp b/20210608/hello-3.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c3ba0001dfbfe82610a9260a6418d70d5f7947c --- /dev/null +++ b/20210608/hello-3.cpp @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main () +{ + const char *s = "Hello, world!"; + printf ("%s\n", s); + return 0; +} diff --git a/20210608/hello-4.cpp b/20210608/hello-4.cpp new file mode 100644 index 0000000000000000000000000000000000000000..646bbb19440a353ce75eb918a78189b5d1d9f256 --- /dev/null +++ b/20210608/hello-4.cpp @@ -0,0 +1,9 @@ +#include <iostream> +#include <string> + +int main () +{ + std::string s = "Hello, world!"; + std::cout << s << std::endl; + return 0; +} diff --git a/20210608/logo-hochschule-bochum-cvh-text-v2.pdf b/20210608/logo-hochschule-bochum-cvh-text-v2.pdf new file mode 100644 index 0000000000000000000000000000000000000000..3725a72c764b4d9ab200553474e4262161f7a5b5 Binary files /dev/null and b/20210608/logo-hochschule-bochum-cvh-text-v2.pdf differ diff --git a/20210608/logo-hochschule-bochum.pdf b/20210608/logo-hochschule-bochum.pdf new file mode 100644 index 0000000000000000000000000000000000000000..8cad73dbb48a2b550bf29355b5a6ec895ce091f8 Binary files /dev/null and b/20210608/logo-hochschule-bochum.pdf differ diff --git a/20210608/main-program-1.c b/20210608/main-program-1.c new file mode 100644 index 0000000000000000000000000000000000000000..59ea0c0028cbb0885f60b9520010beb9102ae9a6 --- /dev/null +++ b/20210608/main-program-1.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +void print (char *s) +{ + printf ("%s\n", s); +} + +int main (void) +{ + print ("Hello, world!"); + return 0; +} diff --git a/20210608/main-program-2.c b/20210608/main-program-2.c new file mode 100644 index 0000000000000000000000000000000000000000..3fa68b1e00cad4bf51c915d16ef1273375358d76 --- /dev/null +++ b/20210608/main-program-2.c @@ -0,0 +1,7 @@ +extern void print (char *s); + +int main (void) +{ + print ("Hello, world!"); + return 0; +} diff --git a/20210608/module-2.c b/20210608/module-2.c new file mode 100644 index 0000000000000000000000000000000000000000..1e4e6f7cc61aabe0c26fb797306bab75039f873b --- /dev/null +++ b/20210608/module-2.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +void print (char *s) +{ + printf ("%s\n", s); +} diff --git a/20210608/modules-1.txt b/20210608/modules-1.txt new file mode 100644 index 0000000000000000000000000000000000000000..ab5cce983cdbbe7f984a7b943e6606337acb5608 --- /dev/null +++ b/20210608/modules-1.txt @@ -0,0 +1,22 @@ +cassini/home/peter/bo/2021ss/rtech/20210608> cat main-program-2.c +extern void print (char *s); + +int main (void) +{ + print ("Hello, world!"); + return 0; +} +cassini/home/peter/bo/2021ss/rtech/20210608> cat module-2.c +#include <stdio.h> + +void print (char *s) +{ + printf ("%s\n", s); +} +cassini/home/peter/bo/2021ss/rtech/20210608> gcc -Wall -O main-program-2.c module-2.c -o main-program-2 +cassini/home/peter/bo/2021ss/rtech/20210608> ./main-program-2 +Hello, world! +cassini/home/peter/bo/2021ss/rtech/20210608> gcc -Wall -O main-program-2.c -o main-program-2 /usr/bin/ld: /tmp/ccUY2lSw.o: in function `main': +main-program-2.c:(.text+0xc): undefined reference to `print' +collect2: error: ld returned 1 exit status +cassini/home/peter/bo/2021ss/rtech/20210608> diff --git a/20210608/modules-2.txt b/20210608/modules-2.txt new file mode 100644 index 0000000000000000000000000000000000000000..40b98cc75241797784fbe75e0a4caec52f10a395 --- /dev/null +++ b/20210608/modules-2.txt @@ -0,0 +1,24 @@ +cassini/home/peter/bo/2021ss/rtech/20210608> gcc -Wall -O main-program-2.c -o main-program-2 +/usr/bin/ld: /tmp/ccHKsgcU.o: in function `main': +main-program-2.c:(.text+0xc): undefined reference to `print' +collect2: error: ld returned 1 exit status +cassini/home/peter/bo/2021ss/rtech/20210608> ls -l main-program-2* +-rw-r--r-- 1 peter peter 89 Jun 8 11:24 main-program-2.c +cassini/home/peter/bo/2021ss/rtech/20210608> gcc -Wall -O main-program-2.c -c +cassini/home/peter/bo/2021ss/rtech/20210608> ls -l main-program-2* +-rw-r--r-- 1 peter peter 89 Jun 8 11:24 main-program-2.c +-rw-r--r-- 1 peter peter 1560 Jun 8 11:27 main-program-2.o +cassini/home/peter/bo/2021ss/rtech/20210608> file main-program-2.o +main-program-2.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped +cassini/home/peter/bo/2021ss/rtech/20210608> gcc main-program-2.o -o main-program-2 +/usr/bin/ld: main-program-2.o: in function `main': +main-program-2.c:(.text+0xc): undefined reference to `print' +collect2: error: ld returned 1 exit status +cassini/home/peter/bo/2021ss/rtech/20210608> gcc -Wall -O module-2.c -c +cassini/home/peter/bo/2021ss/rtech/20210608> ls -l module-2* +-rw-r--r-- 1 peter peter 67 Jun 8 11:24 module-2.c +-rw-r--r-- 1 peter peter 1384 Jun 8 11:29 module-2.o +cassini/home/peter/bo/2021ss/rtech/20210608> gcc main-program-2.o module-2.o -o main-program-2 +cassini/home/peter/bo/2021ss/rtech/20210608> ./main-program-2 +Hello, world! +cassini/home/peter/bo/2021ss/rtech/20210608> diff --git a/20210608/modules-3.txt b/20210608/modules-3.txt new file mode 100644 index 0000000000000000000000000000000000000000..2d0b64b775277b8354cd3ee81e68da5691c88aed --- /dev/null +++ b/20210608/modules-3.txt @@ -0,0 +1,10 @@ +cassini/home/peter/bo/2021ss/rtech/20210608> nm main-program-2.o + U _GLOBAL_OFFSET_TABLE_ +0000000000000000 r .LC0 +0000000000000000 T main + U print +cassini/home/peter/bo/2021ss/rtech/20210608> nm module-2.o + U _GLOBAL_OFFSET_TABLE_ +0000000000000000 T print + U puts +cassini/home/peter/bo/2021ss/rtech/20210608> diff --git a/20210608/modules-4.txt b/20210608/modules-4.txt new file mode 100644 index 0000000000000000000000000000000000000000..c87ac747ae7471d3ce41d30313017a57602ac378 --- /dev/null +++ b/20210608/modules-4.txt @@ -0,0 +1,15 @@ +cassini/home/peter/bo/2021ss/rtech/20210608> nm main-program-2.o + U _GLOBAL_OFFSET_TABLE_ +0000000000000000 r .LC0 +0000000000000000 T main + U print +cassini/home/peter/bo/2021ss/rtech/20210608> nm module-2.o + U _GLOBAL_OFFSET_TABLE_ +0000000000000000 T print + U puts +cassini/home/peter/bo/2021ss/rtech/20210608> gcc main-program-2.o module-2.o -o main-program-2 +cassini/home/peter/bo/2021ss/rtech/20210608> ldd main-program-2 + linux-vdso.so.1 (0x00007ffc9d1e1000) + libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f73a5a8b000) + /lib64/ld-linux-x86-64.so.2 (0x00007f73a5c95000) +cassini/home/peter/bo/2021ss/rtech/20210608> diff --git a/20210608/pgslides.sty b/20210608/pgslides.sty new file mode 100644 index 0000000000000000000000000000000000000000..9a019ce99f03d27a17942facc56fe2145f46b6a6 --- /dev/null +++ b/20210608/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/20210608/rtech-20210608.pdf b/20210608/rtech-20210608.pdf new file mode 100644 index 0000000000000000000000000000000000000000..322cf721cf0e83d6832fadd16f8725b1860f8ac5 Binary files /dev/null and b/20210608/rtech-20210608.pdf differ diff --git a/20210608/rtech-20210608.tex b/20210608/rtech-20210608.tex new file mode 100644 index 0000000000000000000000000000000000000000..220bfc8d0444c8872803fdd6c93d12e208706a6a --- /dev/null +++ b/20210608/rtech-20210608.tex @@ -0,0 +1,609 @@ +% rtech-20210608.pdf - Lecture Slides on Computer Technology +% Copyright (C) 2012, 2013, 2014, 2021 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 + +\documentclass[10pt,t]{beamer} + +\usepackage{pgslides} +\usepackage{rotating} + +\lstdefinestyle{asm}{basicstyle=\color{structure}, + language={}, + gobble=4} + +\title{Rechnertechnik} +\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} +\date{8.\ Juni 2021} + +\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} + \item[\textbf{4}] \textbf{Der CPU-Stack} + \begin{itemize} + \color{medgreen} + \item[4.1] Implementation + \item[4.2] Unterprogramme + \item[4.3] Register sichern + \item[4.4] Stack-Überläufe + \color{red} + \item[4.5] Puffer-Überläufe + \end{itemize} + \color{gray} +% \item[\textbf{5}] \textbf{Hardwarenahe Programmierung} + \item[\textbf{5}] \textbf{Anwender-Software} + \begin{itemize} + \color{medgreen} + \item[5.1] Relokation und Linken + \item[5.2] Dateiformate + \item[5.3] Die Toolchain + \item[5.4] Besonderheiten von Mikrocontrollern + \end{itemize} +% \item[\textbf{7}] \textbf{Bus-Systeme} +% \item[\textbf{8}] \textbf{Pipelining} + \item[\textbf{\dots\hspace{-0.75em}}] +% \item[\textbf{9}] \textbf{Ausblick} + \end{itemize} + +\end{frame} + +\setcounter{section}{4} + +\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} + +\setcounter{section}{3} +\section{Der CPU-Stack\label{CPU-Stack}} +\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{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} + +\subsection{Puffer-Überläufe} + +\begin{frame}[fragile] + + \showsection + \showsubsection + + \begin{lstlisting} + #include <stdio.h> + + int main (void) + { + int ID; + char buffer[20]; + printf ("Your ID, please: "); + gets (buffer); + sscanf (buffer, "%d", &ID); + printf ("Your name, please: "); + gets (buffer); + printf ("Hello, %s!\nYour ID is %d.\n", buffer, ID); + return 0; + } + \end{lstlisting} + +\end{frame} + +\end{document} diff --git a/20210608/server-0.c b/20210608/server-0.c new file mode 100644 index 0000000000000000000000000000000000000000..d9eaf86fe7ad4ac05a647825bcd95d88f62436fd --- /dev/null +++ b/20210608/server-0.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +int main (void) +{ + int ID; + char buffer[20]; + printf ("Your ID, please: "); + gets (buffer); + sscanf (buffer, "%d", &ID); + printf ("Your name, please: "); + gets (buffer); + printf ("Hello, %s!\nYour ID is %d.\n", buffer, ID); + return 0; +}