\documentclass[twoside,11pt,openany]{book}
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}

% Fix copy/pasting of ligatures in Acrobat
\input{glyphtounicode.tex}
\pdfgentounicode=1 %

\usepackage{etoolbox}

\input{preamble}

% All registers are named here. That way when we rename one we'll get errors if
% there are still references to the old name.

\usepackage{makeidx}
\makeindex

\usepackage{xspace}
\newcommand{\inst}[1]{{\tt #1}\xspace}
\newcommand{\reg}[1]{{\tt #1}\xspace}
\newcommand{\field}[1]{{$|#1|$}\xspace}
\newcommand{\defregname}[2]{\providecommand{#1}{\reg{#2}}}
\newcommand{\deffieldname}[2]{\providecommand{#1}{\field{#2}}}
\deffieldname{\FcsrMstatusMprv}{MPRV}
\deffieldname{\FcsrMstatusMie}{MIE}
\deffieldname{\FcsrSstatusSie}{SIE}
\deffieldname{\Fmxl}{MXL}
\defregname{\Rmisa}{misa}
\defregname{\Rmtime}{mtime}
\defregname{\Rtime}{time}
\defregname{\Rmstatus}{mstatus}
\defregname{\Rsstatus}{sstatus}
\defregname{\Rvsstatus}{vsstatus}
\defregname{\Rmcause}{mcause}
\defregname{\Rmie}{mie}
\defregname{\Rxepc}{xepc}
\defregname{\Rmepc}{mepc}
\defregname{\Rmedeleg}{medeleg}
\defregname{\Rhedeleg}{hedeleg}
\defregname{\Rmstateenzero}{mstateen0}
\defregname{\Rhstateenzero}{hstateen0}

\deffieldname{\Fasid}{ASID}
\defregname{\Rsatp}{satp}
\defregname{\Rvsatp}{vsatp}

\defregname{\Azero}{a0}
\defregname{\Aone}{a1}

\defregname{\Rzero}{zero}
\defregname{\Szero}{s0}
\defregname{\Sone}{s1}

\defregname{\Tzero}{t0}

\defregname{\Xzero}{x0}
\defregname{\Xone}{x1}
\defregname{\Xeight}{x8}
\defregname{\Xnine}{x9}
\defregname{\Xten}{x10}
\defregname{\Xeleven}{x11}
\defregname{\Xthirtyone}{x31}
\defregname{\Fone}{f1}
\defregname{\Rpc}{pc}
\defregname{\Rmhartid}{mhartid}
\defregname{\Rdataone}{data1}

\input{hwbp_registers.tex.inc}
\input{core_registers.tex.inc}
\input{jtag_registers.tex.inc}
\input{dm_registers.tex.inc}
\input{sample_registers.tex.inc}
\input{abstract_commands.tex.inc}
\input{sw_registers.tex.inc}

\deffieldname{\Fhartsel}{\hyperref[hartsel]{hartsel}}
\deffieldname{\Fsize}{\hyperref[sizelo]{size}}
\deffieldname{\Faction}{action}
\deffieldname{\Fresethaltreq}{\hyperref[resethaltreq]{resethaltreq}}
\deffieldname{\Fkeepalive}{\hyperref[keepalive]{keepalive}}

\input{vc.tex}

\begin{document}

\title{RISC-V Debug Specification\\
Version \versionnum\\
\GITHash
}
\author{Editors: \\
Paul Donahue \textless pdonahue@ventanamicro.com\textgreater, Ventana Micro Systems \\
Tim Newsome \textless tim@casualhacker.net\textgreater}
\date{\GITAuthorDate}
\maketitle

\markboth{RISC-V Debug Specification Version \versionnum}
{RISC-V Debug Specification Version \versionnum}
\thispagestyle{empty}

\frontmatter

\input{preface.tex}

\tableofcontents
\listoffigures
\listoftables

\mainmatter

\newpage

\input{introduction}
\input{overview}
\input{debug_module}
\input{Sdext}
\input{Sdtrig}
\input{dtm}

\newpage
\appendix

\include{implementations}
\include{debugger_implementation}

\clearpage
\addcontentsline{toc}{chapter}{Index}
\label{index}
\printindex

\ifrelease
\else
\ifdefstring{\releasename}{Frozen}{}{
    \chapter{Change Log}

    \begin{versionhistory}
        \input{changelog.tex}
    \end{versionhistory}
}
\fi

\end{document}
