It is currently Mon Oct 20, 2014 4:48 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Thu Mar 28, 2013 3:42 pm 
Offline
 Profile

Joined: Thu Nov 06, 2008 1:13 am
Posts: 14
Been working on this the past few days, thought it had reached the point where it might be useful to people so I'm going to release it.

So hear it is BeebDis, a disassembler that outputs BeebAsm compatible code.

Attachment:
File comment: BeebDis 0.90
BeebDis.zip [147.5 KiB]
Downloaded 39 times


There is a pdf / word file in the archive with some basic instructions. Also included is the Delphi 7 & Lazarus source for the project, along with the windows executable.

The source should be able to be compiled on any platform that Lazarus is available for I have tried it on Windows and Linux (x86).

I welcome constructive comments.

Cheers.

Phill.


Top
 
PostPosted: Thu Mar 28, 2013 9:42 pm 
Offline
 Profile

Joined: Sat Mar 10, 2012 10:27 pm
Posts: 41
"string address <length>
Defines a string ...length of the string by probing ahead from the start address until it finds a character not in the range $20-$7F."

Maybe also a zstring option? Searches until NUL? 'Cos many many print routines do "print until NUL"
eg
JSR printmsg
EQUS "hello there"
equb 13
equb 10
BRK
MORE_CODE

Hmm, bug? If no "entry" value set then it seems to just do a dump of EQUBs and not do any disassembly

Always seems to generate a L000 = $0000 ?

Heheheh, silly... may be worth adding BeebDisStartAddr to your pre-defined list of labels
eg
Code:
L0000   = $0000

        org     $2000
.BeebDisStartAddr
.L2000
        LDA     #$41
        JSR     LFFEE

        JSR     L2000

        RTS

.BeebDisEndAddr
SAVE "y.bin",BeebDisStartAddr,BeebDisEndAddr

L2000 probably isn't needed :-)
(why all the extra blank lines?)


Top
 
PostPosted: Fri Mar 29, 2013 1:21 am 
Offline
 Profile

Joined: Sat Mar 10, 2012 10:27 pm
Posts: 41
Compiled using lazarus on Ubuntu 12.04LTS and it returned lots of warnings, but appears to work.

Resulting file is a weird combo of Unix and DOS end-of-lines
eg
Code:
        org     $2000
.BeebDisStartAddr
        LDA     #$41
        JSR     LFFEE^M

        JSR     L2009^M

        RTS^M


No errors if file isn't loaded?
Code:
$ grep label c
symbols labels.txt
$ ls
LABELS.txt  a  c
$ BeebDis c
BeebDis V0.90 2013-03, PhillHarvey-Smith.
$ grep FFEE r
LFFEE   = $FFEE
        JSR     LFFEE
        JSR     LFFEE
$ mv LABELS.txt labels.txt
$ BeebDis c               
BeebDis V0.90 2013-03, PhillHarvey-Smith.
$ grep FFEE r
OSWRCH  = $FFEE
$ grep JSR r
        JSR     OSWRCH
        JSR     L2009
        JSR     OSWRCH
$

So the misnamed file wasn't loaded but no error or warning reported.


Top
 
PostPosted: Fri Mar 29, 2013 1:32 am 
Offline
 Profile

Joined: Sat Mar 10, 2012 10:27 pm
Posts: 41
Silly thought; would it be possible to also output a separate "new label" file?

As part of the recursive process if I take this file:
Code:
00000000  A9 41 20 EE FF 20 09 20   .A .. .
00000008  60 20 EE FF 60            ` ..`

Then the resulting file is:
Code:
$ cat r
L0000   = $0000
OSWRCH  = $FFEE

        org     $2000
.BeebDisStartAddr
        LDA     #$41
        JSR     OSWRCH

        JSR     L2009

        RTS

.L2009
        JSR     OSWRCH

        RTS

.BeebDisEndAddr
SAVE "r.bin",BeebDisStartAddr,BeebDisEndAddr

Now if I add "GLUB $2009" to the labels.txt file the relevant section becomes
Code:
        JSR     GLUB

        RTS

.GLUB
        JSR     OSWRCH

Which is _NICE_. So what would be nice would be a "output label file" which contains commented lines such as "# L2009 $2009" so we can see what labels your code has created for us. Then we can edit this file and put in names as we like and rerun your program. Maybe I'm overcomplicating things :-)


Top
 
PostPosted: Fri Mar 29, 2013 2:19 am 
Offline
 Profile

Joined: Sat Mar 10, 2012 10:27 pm
Posts: 41
(and a final "PS" for today..., anyway!) Hope you take those messages in the manner that they were meant; not attacking, but pointing out areas of potential improvement.


Top
 
PostPosted: Fri Mar 29, 2013 10:31 pm 
Offline
 Profile

Joined: Sat Aug 22, 2009 7:45 pm
Posts: 34
To do the same thing on a platform that you can run BBC BASIC on (eg BBC, Master, CPM, Unix, Windows, DOS, Spectrum, Amstrad), disassembly programs, including the MkSrc* programs that create text or BASIC source code that can be re-assembled with the BBC BASIC assembler.


Top
 
PostPosted: Sat Mar 30, 2013 5:56 am 
Offline
 Profile

Joined: Thu Nov 06, 2008 1:13 am
Posts: 14
sweh wrote:
(and a final "PS" for today..., anyway!) Hope you take those messages in the manner that they were meant; not attacking, but pointing out areas of potential improvement.


Indeed, one of the reasons I released it was to see if anyone else had any suggestions :) Sometimes you think you've got something working nicely, and then someone comes along and says it would be good if it did X, which you never thought about but is indeed useful.

Will prolly implement some of this when I've finished up with the RCM meeting tomorrow :)

Cheers.

Phill.


Top
 
PostPosted: Wed Apr 17, 2013 3:41 pm 
Offline
 Profile

Joined: Sat Mar 10, 2012 10:27 pm
Posts: 41
Another, more difficult, idea..

Handling of comments.

For example, I was disassembling Solidisk E1770 ROM and quite early on I came to
Code:
.ServEntry
        PHA
        LDA     #$0F
        STA     LFE62
        LDA     L00F4
        STA     LFE60
        PLA

Now that tells me that this ROM was written for the original Solidisk SWR that used the user-port to switch writeable banks; clearly this code ensured the current ROM was set writeable. I'd love to comment that, but next time I run the disassembler my comments would be lost.

Not sure how to do this in a clean manner :-)


Top
 
PostPosted: Sun Apr 21, 2013 4:35 pm 
Offline
 Profile

Joined: Sat Aug 22, 2009 7:45 pm
Posts: 34
sweh wrote:
I'd love to comment that, but next time I run the disassembler my comments would be lost.
Not sure how to do this in a clean manner :-)
You could either have a seperate file of comments indexed by the disassembly address, and the generated disassembly merges in the comments from the comments file; or the disassembly process could take a previously-generated disassembly as an input file as well as the code file, and it extracts the comments from it and re-adds them back into the output file.


Top
 
PostPosted: Sun Apr 21, 2013 8:58 pm 
Offline
 Profile

Joined: Sat Mar 10, 2012 10:27 pm
Posts: 41
jgharston wrote:
sweh wrote:
I'd love to comment that, but next time I run the disassembler my comments would be lost.
Not sure how to do this in a clean manner :-)
You could either have a seperate file of comments indexed by the disassembly address, and the generated disassembly merges in the comments from the comments file

Yeah, it's the "clean" part that I was having trouble with. Comments might be multi-line (eg describing a whole subroutine) or associated with a command (eg STA to a hardware register). The best I thought of was having "+ADDR" or "+LABEL" (or some other indicator) to indicate start of comment and then read the next line(s) until the next address/label and then sticking the comment in just before that point. Hmm...
Quote:
or the disassembly process could take a previously-generated disassembly as an input file as well as the code file, and it extracts the comments from it and re-adds them back into the output file.

Since BeebDis seems to ignore fail-to-open this might work (else we get a boot-strap type issue) but then there's a risk of losing comments if the disassembly or re-parsing fails. I didn't like this option when I was going through it in my mind; struck me as too complicated and prone to failure.

Ultimately I didn't try to "solution" the requirement because nothing felt clean enough. I'd leave it to Phill, if he decided to implement :-)


Top
 
PostPosted: Mon Apr 22, 2013 1:42 am 
Offline
 Profile

Joined: Sat Aug 22, 2009 7:45 pm
Posts: 34
sweh wrote:
Yeah, it's the "clean" part that I was having trouble with. Comments might be multi-line (eg describing a whole subroutine) or associated with a command (eg STA to a hardware register). The best I thought of was having "+ADDR" or "+LABEL" (or some other indicator) to indicate start of comment and then read the next line(s) until the next address/label and then sticking the comment in just before that point. Hmm...
Comments would normally start with a comment character, either ; or \, so that would be the normal thing to insert in the output and check for in the input.
I usually use (TABs or SPCs to column);(SPC) or (TABs or SPCs to column):\(SPC) as a comment marker, eg:
Code:
FFE0   JMP (&0210) ; OSRDCH get a byte from current input stream
FFE3   CMP #&0D    ; OSASCI output a byte to VDU stream expanding
FFE5   BNE &FFEE   ; carriage returns (&0D) to LF/CR (&0A,&0D)
FFE7   LDA #&0A    ; OSNEWL output a CR/LF to VDU stream
FFE9   JSR OSWRCH  ; Outputs A followed by CR to VDU stream
 ... or (more detailed example) ...
FFEC   LDA #&0D    :\ OSWRCR output a CR to VDU stream
FFEE   JMP (&020E) :\ OSWRCH output a character to the VDU stream
FFF1   JMP (&020C) :\ OSWORD perform operation using parameter table
\ On entry, A =function
\           XY=>control block
\ On exit, OSWORD 0,   CC=Ok, CS=Escape
\                      Y=length of returned line
\          OSWORD <>0, A,X,Y,P irrelevant, likely to be corrupted
\                      All data returned in control block
\
FFF4   JMP (&020A) :\ OSBYTE perform operation with single bytes
\ On entry, A=function
\           X=first byte parameter
\           Y=second byte parameter if A>&7F
\ On exit,  A=preserved
\           X=first byte result
\           Y=second byte result if A>&7F
\           CC/CS returned for some if A>&7F
\
FFF7   JMP (&0208) :\ OSCLI  pass string to command line interpreter
\ On entry, XY=>command string
\ On exit,  all registers irrelevant
\           Some systems return A=return result

If I'm creating a disassembly to then use as source code, I put the addresses in the comments. Short version:
Code:
.OSWORD :JMP (&020C)  :\ &FFF1 - Perform operation using parameter table
.OSBYTE :JMP (&020A)  :\ &FFF4 - Perform operation with single bytes
.OS_CLI :JMP (&0208)  :\ &FFF7 - Pass string to command line interpreter

Detailed version:
Code:
\ ========================================================
\ OSWORD - &FFF1 - Perform operation using parameter table
\ --------------------------------------------------------
\ On entry, A =function
\           XY=>control block
\ On exit, OSWORD 0,   CC=Ok, CS=Escape
\                      Y=length of returned line
\          OSWORD <>0, A,X,Y,P irrelevant, likely to be corrupted
\                      All data returned in control block
\
.OSWORD :JMP (&020C)
\
\ ====================================================
\ OSBYTE - &FFF4 - Perform operation with single bytes
\ ----------------------------------------------------
\ On entry, A=function
\           X=first byte parameter
\           Y=second byte parameter if A>&7F
\ On exit,  A=preserved (exceptions with &82/&83/&84)
\           X=first byte result
\           Y=second byte result if A>&7F
\           CC/CS returned for some if A>&7F
\
.OSBYTE :JMP (&020A)
\
\ =======================================================
\ OSCLI - &FFF7 - Pass string to command line interpreter
\ -------------------------------------------------------
\ On entry, XY=>command string
\ On exit,  all registers irrelevant
\           Some systems return A=return result
\
.OS_CLI :JMP (&0208)
\

As an example see the DNFS disassembly.


Top
 
PostPosted: Tue Apr 23, 2013 10:44 am 
Offline
 Profile

Joined: Thu Nov 06, 2008 1:13 am
Posts: 14
Ok here's the latest version.

Attachment:
File comment: BeebDis 0.91
BeebDis0.91-2013-04-23.zip [123.4 KiB]
Downloaded 26 times


I've added a load of stuff and hopefully squashed some of the bugs (without introducing new ones!).

Cheers.

Phill.


Top
 
PostPosted: Sun Apr 28, 2013 7:15 pm 
Offline
 Profile

Joined: Sat Mar 10, 2012 10:27 pm
Posts: 41
Hmm, this _seems_ to be a step backwards...

Here's the beginning of a ROM
Code:
0000000  00 00 00 4C 2B 80 82 14   ...L+...
00000008  00 4D 41 4E 41 47 45 52   .MANAGER
00000010  20 31 32 38 00 28 43 29    128.(C)
00000018  20 53 4F 4C 49 44 49 53    SOLIDIS
00000020  4B 20 30 36 2E 30 34 2E   K 06.04.
00000028  38 37 00 C9 01 D0 36 AD   87....6.
00000030  8D 02 F0 05 A9 FF 8D A3   ........
00000038  03 AD A3 03 C9 03 D0 1D   ........
00000040  AD FF 10 C9 08 B0 16 A9   ........
00000048  00 8D A5 02 8D A6 02 8D   ........


Code:
$ cat control
load $8000 MANAGER
entry $8000
symbols symbols
save output
$ cat symbols
OSCLI  $FFF7
OSBYTE $FFF4
$ BeebDis control
BeebDis V0.91 2013-03, PhillHarvey-Smith.
EntryPoints:Label L8000 Address 8000
SymbolList:Label OSCLI Address FFF7
SymbolList:Label OSBYTE Address FFF4
SymbolList:Label BeebDisStartAddr Address 8000
Disassembling 8000
SymbolList:Label L8001 Address 8001
SymbolList:Label L8003 Address 8003
SymbolList:Label L8009 Address 8009
SymbolList:Label L004E Address 004E

and lots lots more output

Then the result is (skipping down to the org)
Code:
        org     $8000
.BeebDisStartAddr
        BRK
.L8001
        EQUB    $00

        BRK
.L8003
        EQUB    $4C

; PC=8004 INVALID opcode 2B
; PC=8005 INVALID opcode 80


With 0.90 we don't get the tonnes of screen output, and the result looks more sane:
Code:
        org     $8000
.BeebDisStartAddr
.L8000
        BRK
        BRK
        BRK
        JMP     L802B


Although 0.90 doesn't seem to recover from string calls properly; later on I have
Code:
byte $808B
string $808C

And the resulting code says
Code:
        EQUB    $0C
        EQUS    "Shadow"
        EQUB    $00
        EQUB    $A6

I can't force it to start disassembly again, even if I give a length to the string. I have to specify a 'entry' value after the string to get it to continue properly.


Top
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron