1
0
mirror of synced 2024-11-25 14:34:22 +01:00

binary: added support for compiling and loading C code

This commit is contained in:
Christian Dietrich 2014-09-26 19:42:18 +02:00
parent 0dee263e00
commit b76e301213
4 changed files with 121 additions and 0 deletions

72
avr.binary.tex Normal file
View File

@ -0,0 +1,72 @@
\def\avr@ihex@parse@line:#1#2#3#4#5#6#7#8#9;{%
\avr@hex@tobin{#1#2}{\avr@ihex@bytes}%
\avr@hex@tobin{#3#4#5#6}{\avr@ihex@address}%
\def\avr@ihex@type{#7#8}%
\def\avr@ihex@data{#9}%
}
\def\avr@ihex@readop#1#2#3{%
\def\avr@ihex@readop@helper##1##2##3##4##5\@nnil{%
\avr@hex@tobin{##3##4##1##2}{#2}%
\xdef#3{##5}%
}%
\edef\@tempa{#1}%
\expandafter\avr@ihex@readop@helper\@tempa\@nnil%
}
\newcount\avr@ihex@addr
\newcount\avr@ihex@count
\newcount\avr@ihex@instrs
\def\avr@ihex@load#1{%
\newread\avr@input%
\avr@ihex@instrs=0\relax%
\openin\avr@input=#1\relax%
\@whilesw\unless\ifeof\avr@input\fi{%
\endlinechar59% 59==;
\readline\avr@input to \avr@line \relax%
\endlinechar=-1%
\expandafter\ifstrequal\expandafter{\avr@line}{;}{}{%
\expandafter\avr@ihex@parse@line \avr@line%
\ifdefstring{\avr@ihex@type}{00}{%
\avr@bin@tocount{\avr@ihex@bytes}{\avr@ihex@count}%
\avr@bin@tocount{\avr@ihex@address}{\avr@ihex@addr}%
\divide\avr@ihex@addr by 2\relax%
\divide\avr@ihex@count by 2\relax%
\loop \ifnum \avr@ihex@count > 0%
\avr@ihex@readop{\avr@ihex@data}{\avr@ihex@opcode}{\avr@ihex@data}%
\avr@code@set{\avr@ihex@opcode}{\the\avr@ihex@addr}%
%\avr@debug{=\avr@ihex@opcode}%
\advance \avr@ihex@count by -1\relax%
\advance \avr@ihex@addr by 1\relax%
\repeat
}{}%
}%
}%
\closein\avr@input%
}
\def\avr@compile#1#2{%
\ifnum\pdfshellescape=1%
\immediate\write18{avr-gcc -o #1.elf #1 #2}%
\immediate\write18{avr-objcopy -O ihex -R .eeprom #1.elf #1.hex}%
\else%
\typeout{avr@compile: --shell-escape is disabled}%
\fi%
}
\newcommand{\avrloadc}[2][-Os -mmcu=atmega8]{%
\avr@compile{#2}{#1}%
\avr@ihex@load{#2.hex}%
}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

View File

@ -319,6 +319,43 @@
\fi%
}
\csdef{avr@hex@0}{0000}
\csdef{avr@hex@1}{0001}
\csdef{avr@hex@2}{0010}
\csdef{avr@hex@3}{0011}
\csdef{avr@hex@4}{0100}
\csdef{avr@hex@5}{0101}
\csdef{avr@hex@6}{0110}
\csdef{avr@hex@7}{0111}
\csdef{avr@hex@8}{1000}
\csdef{avr@hex@9}{1001}
\csdef{avr@hex@A}{1010}
\csdef{avr@hex@B}{1011}
\csdef{avr@hex@C}{1100}
\csdef{avr@hex@D}{1101}
\csdef{avr@hex@E}{1110}
\csdef{avr@hex@F}{1111}
\csdef{avr@hex@a}{1010}
\csdef{avr@hex@b}{1011}
\csdef{avr@hex@c}{1100}
\csdef{avr@hex@d}{1101}
\csdef{avr@hex@e}{1110}
\csdef{avr@hex@f}{1111}
% Hexstring to Bitstring: hexstring, \result macro
\def\avr@hex@tobin#1#2{%
\def\avr@hex@helper##1##2\@nnil{%
\xdef#2{#2\csuse{avr@hex@##1}}%
\ifx&##2&\else%
\avr@hex@helper ##2\@nnil%
\fi%
}%
\def#2{}%
\edef\@tempa{#1}\relax%
\expandafter \avr@hex@helper \@tempa \@nnil%
}
\def\avr@count@overflow#1{%
\def\avr@count@overflow@flag{0}%
\ifnum #1 < 0%

View File

@ -380,6 +380,17 @@
}
\preto\avr@test{\avr@test@ROR}
\begin{filecontents*}{empty-main.c}
int main() { }
\end{filecontents*}
\def\avr@test@emptymain{%
\avrloadc{empty-main.c}
\avr@instr@stepn{3}
}
\preto\avr@test{\avr@test@emptymain}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "avr.tex"

View File

@ -11,6 +11,7 @@
\errorcontextlines=23
\input{avr.numbers}
\input{avr.binary}
\input{avr.bitops}
\input{avr.memory}
\input{avr.instr}