Disassembler recommendations ...

A place to discuss everything Dragon related that doesn't fall into the other categories.
tjewell
Posts: 346
Joined: Mon Oct 19, 2009 4:58 pm
Location: Cambridge, England

Disassembler recommendations ...

Post 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.
User avatar
tormod
Posts: 416
Joined: Sat Apr 27, 2013 12:06 pm
Location: Switzerland
Contact:

Re: Disassembler recommendations ...

Post 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.
tjewell
Posts: 346
Joined: Mon Oct 19, 2009 4:58 pm
Location: Cambridge, England

Re: Disassembler recommendations ...

Post 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.
tjewell
Posts: 346
Joined: Mon Oct 19, 2009 4:58 pm
Location: Cambridge, England

Re: Disassembler recommendations ...

Post by tjewell »

Sorry, just spotted the entries in the Xroar manual - I'll RTFM and hopefully I'll make it all work.
tjewell
Posts: 346
Joined: Mon Oct 19, 2009 4:58 pm
Location: Cambridge, England

Re: Disassembler recommendations ...

Post 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.
User avatar
tormod
Posts: 416
Joined: Sat Apr 27, 2013 12:06 pm
Location: Switzerland
Contact:

Re: Disassembler recommendations ...

Post 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)
tjewell
Posts: 346
Joined: Mon Oct 19, 2009 4:58 pm
Location: Cambridge, England

Re: Disassembler recommendations ...

Post by tjewell »

Wonderful, thank you very much, I see disassembly! Right, next step is to actually understand it ...
tjewell
Posts: 346
Joined: Mon Oct 19, 2009 4:58 pm
Location: Cambridge, England

Re: Disassembler recommendations ...

Post 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!
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Disassembler recommendations ...

Post 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...
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
tormod
Posts: 416
Joined: Sat Apr 27, 2013 12:06 pm
Location: Switzerland
Contact:

Re: Disassembler recommendations ...

Post 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?
Post Reply