[NTLK] ROM Disassembly online?

Mark Crutch mark.crutch at gmail.com
Thu Apr 2 11:24:52 EDT 2015


I've done a little testing on my sed script idea, based on Matthias's
previous emails.

Given a file called "rom.asm" that contains this:

Init__10TIdleTimerFUl9TimeUnitsN21:             @ 0x00025464:
TIdleTimer::Init(unsigned long, TimeUnits, unsigned long, unsigned long)
        @ label = 'Init__10TIdleTimerFUl9TimeUnitsN21'
        @ ARM R0 = type: 'unsigned long'
        @ ARM R1 = type: 'TimeUnits'
        @ ARM R2 = type: 'unsigned long'
        @ ARM R3 = type: 'unsigned long'
        @ name = 'Init'
        @ class = 'TIdleTimer'
        mov     pc, lr                          @ 0x00025464 0xE1A0F00E


and a sed script called "comments.sed" that contains this:

/^Init__10TIdleTimerFUl9TimeUnitsN21/,+8{
1 i \
@@@ \\brief Initialize the idle timer\
@@@ Actually, the real timer is a derived class, so there is no code needed
here\
@@@ \\param a  whatever\
@@@ \\param b  I don't know\
@@@ \\return nothing at all


3 s/$/ @@ actually, the disassembler is wrong: R0 is 'this'/


8 a \\t@@ the following line simply returns without a return value
}


The command "sed -f comments.sed rom.asm > commented_rom.asm" produces a
file called "commented_rom.asm" that looks like this:

@@@ \brief Initialize the idle timer
@@@ Actually, the real timer is a derived class, so there is no code needed
here
@@@ \param a  whatever
@@@ \param b  I don't know
@@@ \return nothing at all
Init__10TIdleTimerFUl9TimeUnitsN21:             @ 0x00025464:
TIdleTimer::Init(unsigned long, TimeUnits, unsigned long, unsigned long)
        @ label = 'Init__10TIdleTimerFUl9TimeUnitsN21'
        @ ARM R0 = type: 'unsigned long' @@ actually, the disassembler is
wrong: R0 is 'this'
        @ ARM R1 = type: 'TimeUnits'
        @ ARM R2 = type: 'unsigned long'
        @ ARM R3 = type: 'unsigned long'
        @ name = 'Init'
        @ class = 'TIdleTimer'
        @@ the following line simply returns without a return value
        mov     pc, lr                          @ 0x00025464 0xE1A0F00E




I believe sed is present on OSX via the terminal. It's certainly present on
Linux, and can be added to Windows via Cygwin or similar.

The sed script above works something like this:

1) Find a line matching the regex "^Init__10TIdleTimerFUl9TimeUnitsN21",
where "^" represents the start of the line, stopping it also matching
against line 2.
2) Select this line, and the following 8, to perform the operations within
the braces on.
3) "1 i \" means "insert the following text before line 1. Each line to be
inserted is terminated by a backslash, except the last. Literal backslashes
are escaped with another backslash.
4) "3 s/regex/replacement/" replaces text in line 3. In this particular
case it replaces "$", the end of line marker in a regex, with the comment,
effectively appending it to the end of line 3.
5) "8 a TEXT STRING" appends the specified text after line 8. The "\\t"
inserts a tab in this case.
6) Inserts ("i") can be performed on a single line, much like the append,
for simple comments. Appends ("a") can be multi-line, much like the insert,
for complex ones.
7) The next chunk of comments would follow in another brace-delimited
block. There are various ways to define the extent of a block, other than
just "regex plus n lines", so you could match between two regexs for
example, to get everything from a label to the next label or blank line.


The advantage of this, I think, is that the syntax isn't *too* obscure, so
it should be fairly easy for anyone who's technically minded to correct
typos or make other edits. The downside is that it would require a fair bit
of manual labour to get the initial file(s) created, rather than Matthias's
proposal of a tool that takes a commented asm file and produces the desired
result.


Mark


-- 
*The Greys*, *Elvie* and *Monsters, Inked* webcomics

Website      http://www.peppertop.com/
Facebook   http://facebook.com/TheGreysComic
Twitter        https://twitter.com/TheGreysComic



More information about the NewtonTalk mailing list