Skip to content

Commit

Permalink
wip: clean up, athena is now a 64bits architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
d0p1s4m4 committed Dec 3, 2023
1 parent fbc6b81 commit d892c8f
Show file tree
Hide file tree
Showing 37 changed files with 204 additions and 126 deletions.
29 changes: 27 additions & 2 deletions base/basic.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ \chapter{Basic Architecture}

\section{Addressing}

The basic addressable unit is the 8-bit byte.
The basic addressable unit is the 8-bit byte. Virtual addresses are 64bits long.

\section{Data Type}

Expand All @@ -29,6 +29,14 @@ \subsubsection{Word}
\bitbox{32}{}
\end{bytefield}

\subsection{Quadword}

\begin{bytefield}[%
bitformatting=\fakesfbits,
endianness=big]{16}
\bitheader{0-15} \\
\bitbox{16}{}
\end{bytefield}

\subsection{Signed Integer}

Expand All @@ -53,6 +61,17 @@ \subsubsection{Signed word}
\bitbox{31}{}
\end{bytefield}

\subsubsection{Signed quadword}

\begin{bytefield}[%
bitwidth=\widthof{\tiny ~Sign~},
bitformatting=\fakesfbits,
endianness=big]{16}
\bitheader{0-15} \\
\bitbox{1}{Sign} & \bitbox{15}{}
\end{bytefield}


\section{CPU Registers}

An Athena processor includes two types of registers: general purpose registers (GPR) and control/status registers (CRS).
Expand Down Expand Up @@ -109,6 +128,13 @@ \subsection{Control and Status Registers}
\hline
N° & name & read & write & Description \\
\hline
\multicolumn{5}{|c|}{Unprivileged Registers} \\
\hline
\multicolumn{5}{|c|}{Supervisor Registers} \\
\hline
\hline
\multicolumn{5}{|c|}{Machine Registers} \\
\hline
0 & isa & \ok & \no & Machine ISA Register \\
1 & status & \ok & \ok & Status Register \\
2 & cause & \ok & \no & Cause Register \\
Expand Down Expand Up @@ -161,7 +187,6 @@ \subsubsection{Trap Vector Base Address Regiter}

\subsection{Processor Id}


\begin{bytefield}{32}
\bitheader[endianness=big]{31,1,0} \\
\bitbox{31}{base}
Expand Down
3 changes: 3 additions & 0 deletions base/examples.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\chapter{Examples}

\input{base/examples/basic}
5 changes: 5 additions & 0 deletions base/examples/basic.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
\section{Basic operations}

\subsection{Simple loop}

\lstinputlisting[language={[Athena]Assembler}]{base/examples/loop.S}
4 changes: 4 additions & 0 deletions base/examples/loop.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
li r1, loop_count
loop:
subi r1, r1, 1
bnez r1, loop
24 changes: 14 additions & 10 deletions base/instr.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ \chapter{The Athena Instruction Set}

\section{Instruction Format}

There are 4 basic Athena instruction formats:
\begin{itemize}
\item R-Format
\item I-Format
\item J-Format
\item LS-Format
\end{itemize}

\subsection{R-Format}

\Rinstr{opcode}{ra}{rb}{rc}{shmat}{func}
Expand All @@ -23,20 +31,15 @@ \section{Alphabetical List of Instruction}
\input{base/instructions/add}
\input{base/instructions/addi}
\input{base/instructions/addiu}
\input{base/instructions/addu}
\input{base/instructions/addw}
\input{base/instructions/and}
\input{base/instructions/andi}
\input{base/instructions/b}
\input{base/instructions/beq}
\input{base/instructions/beqz}
\input{base/instructions/bge}
\input{base/instructions/bgeu}
\input{base/instructions/bgez}
\input{base/instructions/blt}
\input{base/instructions/bltu}
\input{base/instructions/bltz}
\input{base/instructions/bne}
\input{base/instructions/bnez}
\input{base/instructions/call}
\input{base/instructions/div}
\input{base/instructions/divu}
Expand All @@ -46,14 +49,13 @@ \section{Alphabetical List of Instruction}
\input{base/instructions/lh}
\input{base/instructions/lhu}
\input{base/instructions/lih}
\input{base/instructions/lq}
\input{base/instructions/lw}
\input{base/instructions/mod}
\input{base/instructions/modu}
\input{base/instructions/lwu}
\input{base/instructions/mult}
\input{base/instructions/multu}
\input{base/instructions/mvsrr}
\input{base/instructions/mvsrw}
\input{base/instructions/nop}
\input{base/instructions/nor}
\input{base/instructions/or}
\input{base/instructions/ori}
Expand All @@ -68,8 +70,10 @@ \section{Alphabetical List of Instruction}
\input{base/instructions/sub}
\input{base/instructions/subi}
\input{base/instructions/subiu}
\input{base/instructions/subu}
\input{base/instructions/subw}
\input{base/instructions/sq}
\input{base/instructions/sw}
\input{base/instructions/swu}
\input{base/instructions/trap}
\input{base/instructions/xor}
\input{base/instructions/xori}
Expand Down
2 changes: 1 addition & 1 deletion base/instructions/add.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ \subsection{ADD}

\paragraph{Format} ADD ra, rb, rc

\paragraph{Purpose} Add word, Trap on Overflow
\paragraph{Purpose} Add quadword, Trap on Overflow

\begin{lstlisting}[language=C]
GPR[ra] = GPR[rb] + GPR[rc];
Expand Down
4 changes: 2 additions & 2 deletions base/instructions/addi.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ \subsection{ADDI}

\paragraph{Format} ADDI ra, rb, imm

\paragraph{Purpose} Add immediate word, Trap on Overflow
\paragraph{Purpose} Add immediate sign extended, Trap on Overflow

\begin{lstlisting}[language=C]
GPR[ra] = GPR[rb] + (int32_t)(imm);
GPR[ra] = GPR[rb] + SEXT(imm);
\end{lstlisting}

\paragraph{Exceptions:} Integer Overflow
4 changes: 2 additions & 2 deletions base/instructions/addiu.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ \subsection{ADDIU}

\paragraph{Format} ADDIU ra, rb, imm

\paragraph{Purpose} Add immediate word
\paragraph{Purpose} Add immediate zero extended

\begin{lstlisting}[language=C]
GPR[ra] = GPR[rb] + (int32_t)(imm);
GPR[ra] = GPR[rb] + ZEXT(imm);
\end{lstlisting}
6 changes: 3 additions & 3 deletions base/instructions/addu.tex → base/instructions/addw.tex
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
\subsection{ADDU}
\subsection{ADDW}

\Rinstr{000000}{ra}{rb}{rc}{00000}{000010}

\paragraph{Format} ADDU ra, rb, rc
\paragraph{Format} ADDW ra, rb, rc

\paragraph{Purpose} Add word

\begin{lstlisting}[language=c]
GPR[ra] = GPR[rb] + GPR[rc];
GPR[ra] = SEXT((GPR[rb] + GPR[rc])<31:0>);
\end{lstlisting}
2 changes: 2 additions & 0 deletions base/instructions/and.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ \subsection{AND}
\begin{lstlisting}[language=c]
GPR[ra] = GPR[rb] & GPR[rc];
\end{lstlisting}

\paragraph{Exceptions:} None
4 changes: 3 additions & 1 deletion base/instructions/andi.tex
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ \subsection{ANDI}

\paragraph{Purpose} Logical and
\begin{lstlisting}[language=c]
GPR[ra] = GPR[rb] & (uint32_t)(imm);
GPR[ra] = GPR[rb] & ZEXT(imm);
\end{lstlisting}

\paragraph{Exceptions:} None
11 changes: 0 additions & 11 deletions base/instructions/b.tex

This file was deleted.

2 changes: 1 addition & 1 deletion base/instructions/beq.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ \subsection{BEQ}
\begin{lstlisting}[language=c]
if (GPR[ra] == GPR[rb])
{
PC += (int32_t)offset * 4;
PC += SEXT(offset) * 4;
}
\end{lstlisting}
14 changes: 0 additions & 14 deletions base/instructions/beqz.tex

This file was deleted.

12 changes: 0 additions & 12 deletions base/instructions/bgez.tex

This file was deleted.

12 changes: 0 additions & 12 deletions base/instructions/bltz.tex

This file was deleted.

12 changes: 0 additions & 12 deletions base/instructions/bnez.tex

This file was deleted.

2 changes: 1 addition & 1 deletion base/instructions/lh.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ \subsection{LH}

\paragraph{Format} LH ra, offset(rb)

\paragraph{Purpose} Loads a 16bit value from memory then sign extended to 32bit before storing to `ra`
\paragraph{Purpose} Loads a 16bit value from memory then sign extended to 64bit before storing to `ra`

\begin{lstlisting}[language=C]
GPR[ra] = *(int16_t)(GPR[rb] + offset);
Expand Down
11 changes: 11 additions & 0 deletions base/instructions/lq.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\subsection{LQ}

\LSinstr{001001}{ra}{rb}{11}{offset}

\paragraph{Format} LQ ra, offset(rb)

\paragraph{Purpose} Loads a 64bit value from memory then store to `ra`

\begin{lstlisting}[language=C]
GPR[ra] = *(int32_t)(GPR[rb] + offset);
\end{lstlisting}
3 changes: 2 additions & 1 deletion base/instructions/lw.tex
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ \subsection{LW}
\paragraph{Purpose} Loads a 32bit value from memory then store to `ra`

\begin{lstlisting}[language=C]
GPR[ra] = *(int32_t)(GPR[rb] + offset);
vaddr = GPR[rb] + SEXT(offset);
GPR[ra] = SEXT(*vaddr<31:0>);
\end{lstlisting}
12 changes: 12 additions & 0 deletions base/instructions/lwu.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\subsection{LW}

\LSinstr{001001}{ra}{rb}{10}{offset}

\paragraph{Format} LW ra, offset(rb)

\paragraph{Purpose} Loads a 32bit value from memory then store to `ra`

\begin{lstlisting}[language=C]
vaddr = GPR[rb] + SEXT(offset);
GPR[ra] = ZEXT(*vaddr<31:0>);
\end{lstlisting}
11 changes: 0 additions & 11 deletions base/instructions/mod.tex

This file was deleted.

12 changes: 0 additions & 12 deletions base/instructions/modu.tex

This file was deleted.

7 changes: 0 additions & 7 deletions base/instructions/nop.tex

This file was deleted.

2 changes: 1 addition & 1 deletion base/instructions/ori.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ \subsection{ORI}
\paragraph{Format} ORI ra, rb, imm

\begin{lstlisting}[language=C]
GPR[ra] = GPR[rb] | imm;
GPR[ra] = GPR[rb] | ZEXT(imm);
\end{lstlisting}
12 changes: 12 additions & 0 deletions base/instructions/sq.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\subsection{SQ}

\LSinstr{001000}{ra}{rb}{11}{offset}

\paragraph{Format} SQ offset(ra), rb

\paragraph{Purpose} Store the 64bit value from the low bits of register `rb` into memory

\begin{lstlisting}[language=C]
vaddr = GPR[ra] + SEXT(offset);
*vaddr = rb;
\end{lstlisting}
4 changes: 4 additions & 0 deletions base/instructions/sub.tex
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ \subsection{SUB}
\paragraph{Purpose} SUB ra, rb, rc

\paragraph{Exceptions:} Integer Overflow

\begin{lstlisting}[language=C]
GPR[ra] = GPR[rb] - GPR[rc];
\end{lstlisting}
Loading

0 comments on commit d892c8f

Please sign in to comment.