Page 1 of 2

Disassembler recommendations ...

Posted: Sun Aug 30, 2015 2:50 pm
by tjewell
Hi all,

I've got a basic program here that loads a little bit of machine code from a bunch of data statements, and I'd love to know how it does what it does. Ideally, my final output would be some machine code that I can then tinker with and recompile with Ciaran's assembler.

I've seen a couple mentioned here over the years - anyone use one in anger? I use Xroar, and I guess half the fun will be getting the disassembled code out of the emulator into a form I can edit.

Many thanks in advance, Tony.

Re: Disassembler recommendations ...

Posted: Sun Aug 30, 2015 3:05 pm
by tormod
There are disassembler programs that you can run on the Dragon, but I often use XRoar with gdb which has a simple built-in disassembler. For more elaborated disassembly I would export the emulated Dragon memory using the gdb command "dump binary memory" and then use Ciaran's 6809dasm.pl.

Re: Disassembler recommendations ...

Posted: Sun Aug 30, 2015 4:38 pm
by tjewell
Thanks Tormod. Now, please excuse my ignorance, but how would I use gdb with Xroar? I'm using a mac, which might complicate things a little, but I'm a unix hacker at heart so happy to get my hands dirty.

Re: Disassembler recommendations ...

Posted: Sun Aug 30, 2015 4:42 pm
by tjewell
Sorry, just spotted the entries in the Xroar manual - I'll RTFM and hopefully I'll make it all work.

Re: Disassembler recommendations ...

Posted: Sun Aug 30, 2015 4:57 pm
by tjewell
And apologies again, so near, yet so far. I'm running Xroar -gdb, I run gdb and do a 'target remote 127.0.0.1:65520' and everything looks good.

I can see gcc has a disassemble command ... but I don't know what to do next! Any pointers gratefully received.

Re: Disassembler recommendations ...

Posted: Sun Aug 30, 2015 5:18 pm
by tormod
For instance:

Code: Select all

disass 0x90e5,+20
The relevant gdb docs: https://sourceware.org/gdb/onlinedocs/g ... -Code.html

Ciaran also posted some example commands here: viewtopic.php?f=5&t=3145&p=7311

Note that while single-stepping through a program using "si", it will show the disassembly of the current code if you are in assembly display layout:

Code: Select all

layout asm
(or press ctrl-X ctrl-A to enter/leave assembly layout mode)

Re: Disassembler recommendations ...

Posted: Sun Aug 30, 2015 9:46 pm
by tjewell
Wonderful, thank you very much, I see disassembly! Right, next step is to actually understand it ...

Re: Disassembler recommendations ...

Posted: Mon Aug 31, 2015 12:40 pm
by tjewell
It's amazing how much you can forget in over 30 years. I notice my little program is making a lot of use of the area from 0x138 to 0x148 to store various scratch variables, and looking at the memory map, this is the 'USR' table. Is it safe for my code to do this? Does anything store info there? Oh, I am so rusty!

Re: Disassembler recommendations ...

Posted: Mon Aug 31, 2015 4:04 pm
by jedie
In my dreams: My DragonPy emulator has a nice GUI to insert/inject machine code and assembly/disassembly...

Maybe i will start with a simple hex-editor with copy&paste... If there is time...

Re: Disassembler recommendations ...

Posted: Tue Sep 01, 2015 5:28 pm
by tormod
Well, I am (still) more surprised how much I can forget in 30 days :o If you don't use the USR functions it should be safe... However there are other locations you can use for better compatibility, but it depends on the lifespan of your values and how your code gets called. If it is run from an interrupt or a BASIC hook you have to be careful, otherwise if it is run via EXEC you can use some of the scratch locations used by BASIC functions. If it is only exec'ed from the command line and not from a BASIC program you may use the input line buffer (and return by jumping to the BASIC command entry loop). Or the cassette buffer... If you need to store values between invocations and you don't want to reserve high memory there are a few unused spots in low RAM. I guess you know Graham's http://dragon32.info/info/memmap.html which is kind of a reference?