Updated chapter 1 to be more fleshed out.
This commit is contained in:
+12
-45
@@ -1,47 +1,14 @@
|
||||
\chapter{Overview}
|
||||
This is an attempt to distill what I know about how computers work into some kind of emulator / simulator. I'm curious to see if what I know at the moment is enough to allow me to emulate a general purpose computer. A computer that will be big-endian, using 8-bit bytes for its char type. The memory is a 32 bit linear address space allowing for a maximum of 2\textsuperscript{32} bytes to be addressable.
|
||||
\chapter{Introduction}
|
||||
This is an attempt to distill what I know about how computers work into some kind of emulator / simulator. I'm curious to see if what I know at the moment is enough to allow me to emulate a general purpose computer. It turns out that it take quite a different skillset compared to writing web applications or desktop applications. But I realize that, while I understand the concepts that underpin what I do day to day, I don't have an intuitive understanding of the hardware. This has become painfully evident pretty much immediately after I started this project. An ISA should be simple, add, subtract, copy, etc., but the you have to consider the state the processor will be in after each instruction.
|
||||
\section{Registers}
|
||||
Eight 32-bit general purpose registers are available for holding operands and memory addresses along with a Flags Register. The Flags Register is a 32-bit register allowing for 32 flags. Currently there are only arithmetic flags which are Overflow (OF), Underflow (UF), and a Zero Flag (ZF). The overflow flag is set if there is a carry. A base pointer register contains a 32 bit address that points to the start of the current stack frame, which is the first opcode of the stack frame. Therefore the first argument would be addressed as such:
|
||||
\begin{verbatim}
|
||||
mov r1, bp - sizeof(void *)
|
||||
\end{verbatim}
|
||||
Finally we have the Program Counter which contains a 32 bit address that points to the next instruction to execute.
|
||||
Thirty-two general purpose registers are available for program code to use however it wishes. The base name for the general purpose registers is \quotes{r} follows by an unpadded number, such as \quotes{r28}. These numbers do not follow a zero-based index scheme, \quotes{r29} is the twenty-ninth register. Using the base name implies full width, a \quotes{word}, when reading or writing from or to the register respectively. In addition to the general purpose registers there is also a base pointer (bp), stack pointer (sp) and an instruction pointer (ip). The base pointer and the stack pointer may be set directly using the \hyperref[sec:mov]{mov} instruction, which allows the programmer to set up a stack frame. The instruction pointer can only be set with a branching operation like \hyperref[sec:jmp]{jmp} or a call to a subroutine with the \hyperref[sec:call]{call} instruction.
|
||||
|
||||
\def\minY{-5} \def\maxY{5}
|
||||
\def\minX{-5} \def\maxX{5}
|
||||
\begin{figure}[ht]
|
||||
\centering
|
||||
\begin{tikzpicture}[node distance=0cm]
|
||||
\node [draw, fit={(\minX, 1.0) (0, 1.5)}, label=center:Program Counter] (pc) {};
|
||||
\node [draw, fit={(\minX, 0) (0, 0.5)}, label=center:Flags] (flags) {};
|
||||
\node [draw, fit={(\minX, -1) (0, -1.5)}, label=center:r1] (r1) {};
|
||||
\node [draw, fit={(\maxX / 2, 0) (\maxX, \minY)}, label=center:Memory] (memory) {};
|
||||
|
||||
\draw (pc);
|
||||
\node[above =of pc] {Status Registers};
|
||||
\node[above left =of pc] {31};
|
||||
\node[above right =of pc] {0};
|
||||
|
||||
\draw (flags);
|
||||
|
||||
\draw (r1);
|
||||
\node[above =of r1] {General Purpose Registers};
|
||||
\node[above left =of r1] {31};
|
||||
\node[above right =of r1] {0};
|
||||
|
||||
\foreach \pos in {2,...,8} {
|
||||
\node [draw, fit={(\minX, -\pos) (0, -\pos - 0.5)}, label=center:r\pos] (r\pos) {};
|
||||
\draw (r\pos);
|
||||
}
|
||||
|
||||
\draw (memory);
|
||||
\node [above =of memory] {Linear Memory (2\textsuperscript{32} Bytes)};
|
||||
\node [above right =of memory, yshift=-1em] {0};
|
||||
\node [below right =of memory, yshift=1em] {2\textsuperscript{32 - 1}};
|
||||
|
||||
%\draw (memory.north east) -- (memory.south west);
|
||||
%\node at (memory.south east) {test};
|
||||
\end{tikzpicture}
|
||||
\caption{Register Bit Layout}
|
||||
\end{figure}
|
||||
\section{Memory Layout}
|
||||
\begin{description}
|
||||
\item In summary, the available registers are as follows:
|
||||
\item[General Purpose] Thirty-two general purpose registers that are the width of a \textit{word} and numbered \quotes{r1} through \quotes{r32}
|
||||
\item[Base Pointer (bp)] Points to the call location when a function call is made
|
||||
\item[Stack Pointer (sp)] points to the end of the last argument after a function call is executed, which may be the return address of the stack
|
||||
\item[Instruction Pointer (ip)] Points to the next instruction to execute and advanced by the width of an instruction. Set by jump or call instructions to the location specified by the instruction.
|
||||
\end{description}
|
||||
|
||||
\section{Memory}
|
||||
Reference in New Issue
Block a user