This is where the BIN Hackers and definition junkies discuss the inner workings of the EEC code and hardware. General tuning questions do not go here. Only technical/hardware-specific/code questions and discussions belong here.

Moderators: EDS50, cgrey8, 2Shaker, Jon 94GT

Post Reply
User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Why auto disassembly is tough

Post by tvrfan » Thu Feb 22, 2018 12:41 am

Hah !! I think I finally got the hang of using git and github commands instead of manually uploading the files....

V 3.04 on github - new layout with subdirectories.

Fixed subroutine size issue (jsa)
sorted JC and JNC and other conditional jumps for source printout (but I'm still not sure it's entirely right....)
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Thu Feb 22, 2018 3:06 am

github seems to be doing you a disservice.

The SAD.EXE windows executable is not 3.04, more like 3.03.

The source seems to be a version different to 3.03, but please check if it is the intended 3.04 update.

For a source build:
Had a quick look at conditionals, they are different. Not sure naming from SYM made it through the changes.

Sym naming of arguments to LU's appears to have gotten worse.

With SAD in general are you attempting disassembly of 72ef onwards for something like push(72ef)?
How about testing jumps and calls to see if the address is a valid code line entry or in the middle of some operands?
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Why auto disassembly is tough

Post by tvrfan » Thu Feb 22, 2018 1:59 pm

jsa - You're talking about CARD ?? I'll SAD it here and have a good look.

GitHub. Was messing about with structure to get git to push to github in single command (as it should).
I thought I had pushed latest version of everything, but it's possible I screwed up the Windows exe, as it's built in a VM (CodeBlocks) and copied back to Linux.
Will double check today....

3.04 concentrated on conditional jumps , JC/JNC and the size problem in command defined subroutines - didn't do anything else.
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Thu Feb 22, 2018 3:01 pm

Yes CARD.

The sad.exe is definitely out of step with the source.
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Why auto disassembly is tough

Post by tvrfan » Thu Feb 22, 2018 4:38 pm

After your post about names I thought (a bit annoyed) "What is this guy talking about....." And then I realised...... So.....

The subroutine size problem you reported (3.03) was actually twofold.
1) the size calculated by the dir command was not transferred correctly to the subroutine
2) the subroutine is marked as "by command" (correct), so then additional sigs or names should NOT added to it, but were, which means size could STILL be wrong.

So I fixed both these things for 3.04. BUT the autonaming (Funclu etc) is dependent on the signature, which should NOT be added if the subroutine
is defined by command, but then you need the F: option back to define this as subroutine as a 'special' e.g. a function or table LU subroutine.

If you just want to add a name then you should use a SYM command, BUT then I break my own rule in my generation of directives at the end of the msgs file as well ....

Therefore rules should be -

Any use of SUB 1234 DEFINES that subroutine, so signature scans/names will NOT happen for that subr, because a user command HAS to override any automatic detection (so errors can be sorted).

So I must put back a method to allow define of a special subroutine type (func lookup, tab lookup)
Subroutines which don't do anything special or don't have arguments should be listed as SYM only....

and discovered that 7333 in CARD is a separate little bug where an immediate value gets treated as a word address. (thanks for spotting that)

so 3.05 list is already here !

Hope this makes sense - Comments, Arguments ??? (are welcome - I want this to be right)
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Thu Feb 22, 2018 5:46 pm

LOL, probably wise to treat anything I say with suspicion :surprised:

Yes it makes sense to an extent.

Evidently funclu works for those bins that have two registers set preceding the call. CARD takes the two inputs after the call as arguments. So why not add a signature for that scenario? cbaza, cdan and likely newer are also LU with arguments. Of course named arguments to other user commanded sub's is desirable.

Against the backdrop of SAD overlooking fair amounts of code in CARD, it falls to the user to tease out that code.
scan 1234 5678 does not seem to find much of the overlooked code.
code 1234 5678 will just translate it all to code without checking validity so lots of !INV! output and general "that can't be right"
sub 1234 seemed the best solution, now I better reread the help file for sym......

I don't recall the V0.5 message file having a sym statement for every sub like V3. So when transferring msg content to dir, you're saying the matching SYM must tag along, otherwise names are lost?
After all putting the sub from msg into sym makes it a user command. Should the copy to dir section of msg exclude sub's?
So having the msg discovered subs in dir prevents any further discovery of related code or errors?


So I will try some SYM's in lieu of SUB's.

Damn addressing mode scourge, can't say I checked to see if it was the cause!

Will give 3.05 a run whet it shows on GIT.
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Why auto disassembly is tough

Post by tvrfan » Thu Feb 22, 2018 9:41 pm

subroutine args - from my memory so a bit hazy....

Funclu and tablu signatures are indeed supposed to be able to handle both preset registers AND inline arguments, and I agree they used to work....
but not for all the encoded address types - and I found that the old version did not handle the situation where the encoding was done by a separate subr (A9L does this as well as later bins) and so it got the wrong address for tabs. This eventually led me to rewrite some of the 'signature' part, so I could tag arguments which were then 'passed down' into another subroutine. So not that surprised it doesn't work anymore ....
A9L auto however now DOES sort out which args are encoded in a list.

And SAD still doesn't handle some of the later tricks, so back to my old favourite thread about emulation....

So for now, I'll get all the manual commands working, and then I'll look at emulating the stack properly for inline arguments....Version 4 ??

SYMs etc.
The idea was that a SYM prints out either as part of a command (e.g. sub 1234 "name" or struct 1234 1237 "xname", and then sym doesn't appear in sym list.. (in end printout in _msg.txt).

In dir file it's just as legal to do
sub 1234
sym 1234 "name"

but then the subroutine is defined as having no arguments or special purpose, which isn't always what's true...
I don't know what's best, frankly.... define subroutine with a way to say "Auto detect(s) can/can't change this" ??

I did also wonder whether to make this legal -

WORD 1234 1235 "myname"
BYTE 1234 1234 "newname"

which would answer your request about symbols and sizes, and also whether to allow second address to be optional (for 1 item, for everything ?) ....
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Thu Feb 22, 2018 11:35 pm

tvrfan wrote: ↑Thu Feb 22, 2018 9:41 pm

So for now, I'll get all the manual commands working, and then I'll look at emulating the stack properly for inline arguments....Version 4 ??
Yes I agree, get the manual commands so that user intervention can get to a point where output is correct and sym names are tied to correct address results.

As static is not enough to disassemble everything automatically, doing a recode with emulation certainly is V4 stuff. No doubt V4 will take some time to develop for release.
In dir file it's just as legal to do
sub 1234
sym 1234 "name"
OK, I need to give SYM a once over to see how it pans out.
I don't know what's best, frankly.... define subroutine with a way to say "Auto detect(s) can/can't change this" ??
I think the msg file needs a warning if SAD auto detects output that contradicts explicit user options. A note in the lst at the Subr address also. That could give the user the chance to adopt SAD's interpretation in the dir. Alternatively a switch option that fixes command options or allows auto override.

Most of the Sub 1234 "Sub1234_SomeName" I put in dir, because I think a Sub exists at an address, to see what SAD decodes. Sometimes just that sub is found, sometimes more than 1, and sometimes the result is partly plausible. It is the partly plausible ones that I want SAD to chase the rabbit hole and hopefully finds the arguments.

So my answer is allow the user flexibility.
I did also wonder whether to make this legal -

WORD 1234 1235 "myname"
BYTE 1234 1234 "newname"
I like it, as an addition, does away with the need for a SYM as well. Less typing, less clutter in dir.
I have this
vect 2DAC 2E0D : N
in V0.5 dir to get the Sub names beside the vector list. V3 is happy without it.
which would answer your request about symbols and sizes, and also whether to allow second address to be optional (for 1 item, for everything ?) ....
But I don't like the idea of editing over a thousand SYM's to Byte or Word commands.
Multiply that by the number of BINs/users, ouch.....

Really too much water under the bridge to throw out the current commands.
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Fri Feb 23, 2018 1:42 am

SYM alone does not give a good result.

The DIR entry

Code: Select all

SYM 582B "SUB582B"
The result

Code: Select all

  SUB582B:
582b: 71,bf,64,57,70,c9,00,4e ?? 
5833: df,1a,11,4f,fa,ff,38,0a ?? 
583b: 0e,45,03,00,06,0e,b3,4f ?? 
5843: 49,04,0d,fb,e0,4e,ed,fb ?? 
584b: c7,70,c9,4e,89,01,00,bc ?? 
5853: d1,18,05,bc,01,4c,3d,47 ?? 
585b: 02,05,4c,c3,01,56,04,4c ?? 
5863: c3,01,4e,09,4c,95,20,47 ?? 
586b: 20,04,a1,01,00,bc,32,0a ?? 
5873: 03,ef,a9,fd,11,4a,34,da ?? 
587b: 03,ef,34,1e,30,e7,02,28 ?? 
5883: df,32,0a,03,ef,96,fd,17 ?? 
588b: 65,30,65,03,e7,62,00,a1 ?? 
5893: 02,56,8c,32,0a,02,2d,85 ?? 
589b: 48,84,06,80,64,80,84,b4 ?? 
58a3: 00,86,89,16,56,8c,db,38 ?? 
58ab: a2,8d,88,57,88,01,00,8e ?? 
58b3: df,f0,a3,88,02,7c,b3,88 ?? 
58bb: 04,7e,68,84,7c,b8,86,7e ?? 
58c3: 3f,7e,08,d7,dd,89,83,06 ?? 
58cb: 7c,d9,d7,64,84,7c,b4,86 ?? 
58d3: 7e,b1,80,4a,11,8f,65,00 ?? 
58db: 54,8e,c9,96,58,ca,8e,f0 ?? 
58e3: 39,65,0c,ef,b5,fd,3a,65 ?? 
58eb: 06,3b,65,03,ef,8e,24,20 ?? 
58f3: 3b,b3,01,30,09,4d,19,02 ?? 
58fb: 4d,b0,03,4e,71,03,4e,90 ?? 
5903: 4e,4d,71,7f,4d,35,4d,03 ?? 
590b: 91,80,4d,b0,0b,4c,85,00 ?? 
5913: 20,4c,c8,4c,a3,6c,da,50 ?? 
591b: 84,50,4c,02,4c,a0,c8,4e ?? 
5923: 84,50,4e,60,4e,4c,84,4c ?? 
592b: c8,cf,6c,da,36,64,03,e7 ?? 
5933: f6,fe,fa,71,7f,64,b0,68 ?? 
593b: 08,31,09,03,b1,02,08,c3 ?? 
5943: 01,00,1f,00,c3,01,00,1f ?? 
594b: 00,f3,f0            ?? 


Sub 582B "SUB582B" disassembles the routine, discovers others and disassembles those as well.
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

motorhead1991
Regular
Posts: 238
Joined: Tue Nov 21, 2017 2:32 am

Re: Why auto disassembly is tough

Post by motorhead1991 » Fri Feb 23, 2018 5:16 pm

Hey tvrfan, here's a cool thing about git. You don't have to delete everything to update it. It tracks changes all on it's own. If you look at the tree in OpenEEC, you'll notice that the commits are much cleaner and more specific.

If you'd rather delete and readd to hide your methods, by all means carry on.

This works on executables and images too. You can even merge and copy commits from other trees.
1990 Ford Ranger FLH2 conversion. Ford forged/dished pistons, Total Seal file-fit rings, Clevite rod and main bearings, Clevite cam bearings, IHI turbo, Siemens Deka 60lb/hr injectors, Ford slot MAF in custom 3" housing. Moates Quarterhorse with Binary Editor, using the PAAD6 database.

OpenEEC Telegram Chat:
Telegram

User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Why auto disassembly is tough

Post by tvrfan » Fri Feb 23, 2018 6:20 pm

motorhead1991 wrote: ↑Fri Feb 23, 2018 5:16 pm Hey tvrfan, here's a cool thing about git. You don't have to delete everything to update it. It tracks changes all on it's own. If you look at the tree in OpenEEC, you'll notice that the commits are much cleaner and more specific. If you'd rather delete and readd to hide your methods, by all means carry on.
This works on executables and images too. You can even merge and copy commits from other trees.

Yeah, I couldn't get the 'push' to work to github and spent ages trying to work out why, fiddling around with branches etc. Answer was obvious (as these things often are). You must put the protocol at the front, as in https:// or ftp:// etc. It was right there in the examples and I missed it over and over .... (browsers fill this in for you, ....duh.....)

I had a mess on GitHub, So I restarted from scratch on my PC (deleted the .git), with a directory structure more to my liking, and pushed (with -force) the whole new tree, so it's clean. The source versions will go to their own subdirs from now on, more as per the classic layout (as far as I can tell, anyway), and git will track all the subdirs for me. Neat, now I got it to work !!

STILL not quite sure how branches are added to the MASTER, I'll get it - must read up some more.....so probably a 'testing' branch will pop up and disappear a few times !

Meanwhile I've been playing with FLTK library - it's a beautifully simple and straightforward lib for an old 'C' geek like me, and it's supposed to be Win and Linux IDENTICAL code, which many others are not, despite claiming portability (Yes, I was looking at you Wxwidgets, and you're a lot more complex to set up and use.)
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Why auto disassembly is tough

Post by tvrfan » Fri Feb 23, 2018 7:56 pm

What I said was wrong..... a sub command is actually a SYM + SCAN command......

Right - I need to go back to some basic rules - Comments please...

BASE RULE - If a user specifies a command, it cannot be changed by SAD program. This so user can force what happens.

BUT - for SUB commands finer detail is required (as per jsa posts above).

SYM - if you specify a symbol directly then it cannot be changed. You can also override the SAD default names.

SUB - if you specify a name [ SUB 1234 "name" ] then the name cannot be changed (as SYM), but the subroutine specification CAN be changed .
SUB - if you only specify address [ SUB 1234 ] then SAD can change both its name and its specification.

also -

VECT sometimes in a pointer list, there are invalid pointers (A9L actually has data in its lists !!)
SAD will print "WORD 1234" for these, and otherwise ignore them.

BANK Not finalised yet, but if you specify a bank that's bigger than the file, or two overlap, or.... then SAD will fix it ??

Autonaming - many items are autonamed in same style, such as SUB123, TAB23, where end number simply increments.
The autonaming can be switched off with an OPT command.

NB. Should we have an option to change autoname to SUB12345 style, where 12345 is its call address ?
Seems a bit redundant to me as it's in the opcode operand, but I note jsa does it this way, and I'm a geek.....

NB sub specification = arguments, special Lookup type etc

Any other command related stuff, 'shortcuts' etc that make sense to anyone ?
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Fri Feb 23, 2018 9:51 pm

SYM + SCAN...will give it a whirl.....

'The Rules' sound good to me. Sounds like it is possible to get a balance between auto and user.
I wonder what everyone else thinks?

Yes Sub2345 is redundant, however I find it more productive while reading the pseudo code column.
It is also one less translation sub->address I'm using my numbskull :wink: for.

I see sad.exe 3.04 is now in step on git, thanks.

For 3.04 and CARD I have
DIR

Code: Select all

SYM DCEF "S.My_Scalar_name_No_Sw"
If I run sad.exe 3.04 without DIR to get a raw msg and lst I get

Code: Select all

262b: 34,9a,09            jnb   B4,R9a,2637      if (B4_R9a = 1)  {
262e: 9b,ff,9b,01,00      cmpb  R0,[Rfe+19b]     
2633: d7,02               jne   2637             if (0 = [dcef])  {
If I run sad.exe 3.04 with DIR I get

Code: Select all

262b: 34,9a,09            jnb   B4,R9a,2637      if (B4_R9a = 1)  {
262e: 9b,ff,9b,01,00      cmpb  R0,[Rfe+19b]     
2633: d7,02               jne   2637             if (0 = 0)  {
Indeed dcef contains 0, so job well done.


But I would like my SYM to show like this

Code: Select all

262b: 34,9a,09            jnb   B4,R9a,2637      if (B4_R9a = 1)  {
262e: 9b,ff,9b,01,00      cmpb  R0,[Rfe+19b]     
2633: d7,02               jne   2637             if (0 = S.My_Scalar_name_No_Sw)  {
Edit 1 (for the 2nd time. must have posted into Bermuda triangle :confused: )
Added previous line of code. Other occurrences' of this issue have JNB and CMPx nested.
See L2E36.

Edit 2 More unexpected behaviour when using DIR

raw output no DIR

Code: Select all

2ec0: 3b,2c,10            jb    B3,R2c,2ed3      if (B3_R2c = 0)  {
2ec3: 37,da,0d            jnb   B7,Rda,2ed3      if (B7_Rda = 1)  {
2ec6: c7,6c,90,00         stb   R0,[R6c+90]      [210] = 0;
2eca: c7,6e,38,00         stb   R0,[R6e+38]      [3b8] = 0;
2ece: c3,6e,36,00         stw   R0,[R6e+36]      [3b6] = 0;
2ed2: f0                  ret                    return; } }

2ed3: 71,7f,d6            an2b  Rd6,7f           Rd6 &= 7f;
output with dir, 2ed3 to 33ef is not decoded.
Note pseudo code has reversed bit value. I have no SYM's involved.

Code: Select all

2ec0: 3b,2c,10            jb    B3,R2c,2ed3      if (B3_R2c = 1) goto 2ed3;
2ec3: 37,da,0d            jnb   B7,Rda,2ed3      if (B7_Rda = 0) goto 2ed3;

2ec6: c7,6c,90,00         stb   R0,[R6c+90]      [210] = 0;
2eca: c7,6e,38,00         stb   R0,[R6e+38]      [3b8] = 0;
2ece: c3,6e,36,00         stw   R0,[R6e+36]      [3b6] = 0;
2ed2: f0                  ret                    return;


2ed3: 71,7f,d6,ef,80,15,3a,f0 ?? 
Last edited by jsa on Sat Feb 24, 2018 8:52 pm, edited 2 times in total.
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

motorhead1991
Regular
Posts: 238
Joined: Tue Nov 21, 2017 2:32 am

Re: Why auto disassembly is tough

Post by motorhead1991 » Fri Feb 23, 2018 10:17 pm

tvrfan wrote: ↑Fri Feb 23, 2018 6:20 pm
motorhead1991 wrote: ↑Fri Feb 23, 2018 5:16 pm Hey tvrfan, here's a cool thing about git. You don't have to delete everything to update it. It tracks changes all on it's own. If you look at the tree in OpenEEC, you'll notice that the commits are much cleaner and more specific. If you'd rather delete and readd to hide your methods, by all means carry on.
This works on executables and images too. You can even merge and copy commits from other trees.

Yeah, I couldn't get the 'push' to work to github and spent ages trying to work out why, fiddling around with branches etc. Answer was obvious (as these things often are). You must put the protocol at the front, as in https:// or ftp:// etc. It was right there in the examples and I missed it over and over .... (browsers fill this in for you, ....duh.....)

I had a mess on GitHub, So I restarted from scratch on my PC (deleted the .git), with a directory structure more to my liking, and pushed (with -force) the whole new tree, so it's clean. The source versions will go to their own subdirs from now on, more as per the classic layout (as far as I can tell, anyway), and git will track all the subdirs for me. Neat, now I got it to work !!

STILL not quite sure how branches are added to the MASTER, I'll get it - must read up some more.....so probably a 'testing' branch will pop up and disappear a few times !

Meanwhile I've been playing with FLTK library - it's a beautifully simple and straightforward lib for an old 'C' geek like me, and it's supposed to be Win and Linux IDENTICAL code, which many others are not, despite claiming portability (Yes, I was looking at you Wxwidgets, and you're a lot more complex to set up and use.)
branches and "master" will only merge if you tell them to. Git has a handy tool called "cherry-pick" which can cross branches and allow you to pick and choose what you want to pull in (you have to check out master first though).

If you guy join the Telegram chat I have set up, I can walk you through all this and more.
1990 Ford Ranger FLH2 conversion. Ford forged/dished pistons, Total Seal file-fit rings, Clevite rod and main bearings, Clevite cam bearings, IHI turbo, Siemens Deka 60lb/hr injectors, Ford slot MAF in custom 3" housing. Moates Quarterhorse with Binary Editor, using the PAAD6 database.

OpenEEC Telegram Chat:
Telegram

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Sat Feb 24, 2018 9:59 pm

On the good news front, FuncLu's are working with V3.04 command options, copied and tweaked from MSG.
Thanks tvrfan, well done.

Code: Select all

sub 7773 "Sub7773_BFuncLu4"   : E 4 f0 N : W N
sub 77db "Sub77db_WFuncLu1"   : E 4 f0 N : W N
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Sun Feb 25, 2018 12:47 am

tvrfan wrote: ↑Fri Feb 23, 2018 7:56 pm What I said was wrong..... a sub command is actually a SYM + SCAN command......
I have tried SYM and SCAN instead of Sub for Sub40DF.

To get disassembly I had to use SUB with arguments option.
Then use
code 342C 354B
to get sad to disassemble that range with DIR.
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Sun Feb 25, 2018 9:20 pm

tvrfan,

Damn, on the bad news front for V3.04 and CARD

Comparing a raw disassembly without DIR to a DIR with one active entry.

Any single one of these, uncommented out; will cause lots and lots of code disassembly failures mentioned in an earlier post.
The Automatically assigned Subxx numbers in the vector list starting at 21e6 are renumbered as well.

Code: Select all

sub 7768 "Sub7768_BFuncLu1"   : E 4 f0 N : W N
# sub 776d "Sub776d_BFuncLu2"   : E 4 f0 N : W N
# sub 7770 "Sub7770_BFuncLu3"   : E 4 f0 N : W N
# sub 7773 "Sub7773_BFuncLu4"   : E 4 f0 N : W N
# sub 77db "Sub77db_WFuncLu1"   : E 4 f0 N : W N
# sub 77e6 "Sub77e6_WFuncLu4"   : E 4 f0 N : W N
Any single one of these, uncommented out; will cause lots and lots of code disassembly failures.
the vector list Subxx number remain the same.

Code: Select all

# sub 77e0 "Sub77e0_WFuncLu2"   : E 4 f0 N : W N
# sub 77e3 "Sub77e3_WFuncLu3"   : E 4 f0 N : W N
Nothing else is required in the DIR.
Gut feel, rbase entries may increase the negative impact. rbase on their own are fine.

Hopefully you can nail this and release V3.05.
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Why auto disassembly is tough

Post by tvrfan » Tue Feb 27, 2018 5:51 pm

Thanks Motorhead, may take you up on that later....

I am adding the manual 'special function' back (the F: for lookups) and attempting to fix up the signed/unsigned again in a different way, so that SAD has user defined, signature detect, guess from data, options for functions and subroutines and the structures. Noted jsa feedback (thanks again) but ignoring them just now whilst I try out a more thorough test of what will be 3.05. Rolling in other things as I spot them (there was STILL another bug with JNC !), and I will then do a review of bugs/feedback to try to get a more professional result this time..... I know some stuff didn't quite work after changing code around to try to get more variable arguments and encoded addresses covered correctly. Later bins also have the function/table lookups with a separate subroutine to get their parameters, which messes up the naming, I'm looking at that as well.

So might be a week or more. Please continue to report an problems - I promise I will read them !
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Fri Mar 02, 2018 7:52 am

tvrfan wrote: ↑Tue Feb 27, 2018 5:51 pm I will then do a review of bugs/feedback
...
So might be a week or more. Please continue to report an problems - I promise I will read them !
Sounds like 3.05 will be a nice advance with all the revisions you are putting in to it.

Here are a few more, not all, CARD address locations where details change between no DIR and using a DIR.
3.04 required a lot of code commands in the dir to work around the overlooked code after subs with args calls, and I have not had a chance to investigate each of these.

After various cmpx;
2539, 2633, 36A5, 3A57, 3A8E, 3ACA, 3B18, 3B35, 3B4B, 3B54, 3B73, 3DB2, 3FBE, 3FEF, 401B, 4021, 403A, 4074, 4096, 4538, 4543, 4733, 49EC, 4A39, 4AD4, 4B78, 4C36, 4DFD, 6C5B, 7DB4, 936A, 93D2, 958B, 95A4, 961F, 9660, A908, AD0E, AD5D, AD68, AD86, AF51, B2FB, B304, B786, B809

after subxw;
45F8, 94FE, ACE5, AD53, B00A

after ad3x;
412E, 49C7, 9137

After shlx;
A66F, BC0D

There are many instances where a sub call is followed by a jump. What do you think of some manual dir entry to apply the subs cy setting code to the jump?
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Why auto disassembly is tough

Post by tvrfan » Fri Mar 02, 2018 2:11 pm

jsa wrote: ↑Fri Mar 02, 2018 7:52 am ...There are many instances where a sub call is followed by a jump. What do you think of some manual dir entry to apply the subs cy setting code to the jump?
What should happen at a cond. jump is that SAD goes back to the nearest previous opcode which sets the PSW. SAD then reuses the operands from that opcode, if it was a compare then SAD shows if ('a-b') style, but if it's an opcode which writes to a register (e.g. an ADD) then it shows 'if (a = 0)' style, where a is what gets written (e.g. a = b + c). There was a bug in carry where set carry wasn't marked as changing the PSW.... and set and clear carry need a third style of if (CY = 0) . Done in 3.05. SAD also still sometimes prints 'if (0=name)' from a compare, which I will have a look at swopping.

in AA code there is a case where a subroutine STARTS with a JNE !! I can't think of any way to handle this other than a special comment.

Yes, quite a lot of subroutines set register(s) with PSW, which could be used as a return/answer status. Some actually use carry directly.
So I have also changed JNC/JC show the 'if (CY = 0)' style after a subroutine call...not sure quite what to do if a CALL is followed by a JNE or similar..
And there may well be other occasions too...

At the moment, I am trying to tie up signed/unsigned func and tab lookups (done), and correct subroutine naming (not done yet), for user, detected and default conditions, not working right as yet. Got the F: working and made it more consistent with rest by allowing Y, W, S, U letters.
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Sat Mar 03, 2018 3:41 am

tvrfan wrote: ↑Fri Mar 02, 2018 2:11 pm SAD also still sometimes prints 'if (0=name)' from a compare, which I will have a look at swopping.
I prefer the SYM name or [Rf0+abcd] to be shown in output when using dir. It sounds like you are going away from this?
in AA code there is a case where a subroutine STARTS with a JNE !!

I have seen something like that in CARD. Really need to know what the previous subr did.
It goes to my idea of being able to assign that previous compare etc to the JNE etc.
Probably about the same to just add a comment to CMT as you suggest.
not sure quite what to do if a CALL is followed by a JNE or similar..
Really not much different than JNE at the start of a subr.

Another wish list item I have, is having the called/jumped/pushed from addresses adjacent the Sub names in the output file. Would save a bit of effort when backtracking through code.
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Why auto disassembly is tough

Post by tvrfan » Sat Mar 03, 2018 2:21 pm

jsa wrote: ↑Sat Mar 03, 2018 3:41 am I prefer the SYM name or [Rf0+abcd] to be shown in output when using dir. It sounds like you are going away from this?
SAD will print always SYM name if one defined for that address, or the correct operand form if not (i.e. 1234 for immediate, [R30] for indirect, etc)
it always uses operand form in the first opcode printout. Note that indexed form is SIGNED so [R30+fe] short indexed is actually [R30-2], as shown in source code part. Not planning to change any of this.

If/when I go to the emulated calls, then SAD will know where the subroutine is called from, but what if the last PSW opcodes are different before each call ?? How to handle that ?? I did consider a form of 'if(subr(args)) = 0) goto' for cond. after the call.....can go in the possible list.

Called addresses - hmm.... SAD does keep track of those now as it makes its 'call tree' . I'll have a think about that, perhaps put the list in comments column ? Or could tidy up the printout currently used for debug in the _wrn.txt file.
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Sat Mar 03, 2018 3:28 pm

Here's some possible examples for jump, push and call.



Most jumps are relatively local, so see the from addresses added to the end of relevant lines for jumps within a Subroutine

Code: Select all

Sub0007:
22fb: b3,6e,a8,42          ldb   R42,[R6e+a8]       R42 = [328];         
22ff: 9b,f8,48,42          cmpb  R42,[Rf8+48]                            
2303: db,05                jc    230a               if ((uns) R42 >= [Sc0404]) goto 230a;
2305: 91,10,4b             orrb  R4b,10             R4b |= 10;           
2308: 20,09                sjmp  2313               goto 2313;           

230a: 9b,f8,47,42          cmpb  R42,[Rf8+47]                            
230e: d3,03                jnc   2313               if ((uns) R42 < [Sc0403]) goto 2313;
2310: 71,ef,4b             an2b  R4b,ef             R4b &= ef;           
2313: a3,6e,9c,42          ldw   R42,[R6e+9c]       R42 = [[31c]]             from 2308;
2317: 8b,f8,4c,42          cmpw  R42,[Rf8+4c]                            
231b: d3,05                jnc   2322               if ((uns) R42 < [Sc0406]) goto 2322;
231d: 91,08,4b             orrb  R4b,8              R4b |= 8;            
2320: 20,09                sjmp  232b               goto 232b;                

2322: 8b,f8,4a,42          cmpw  R42,[Rf8+4a]                            
2326: db,03                jc    232b               if ((uns) R42 >= [Sc0405]) goto 232b;
2328: 71,f7,4b             an2b  R4b,f7             R4b &= f7;           
232b: 3f,ce,0b             jb    B7,Rce,2339        if (B7_Rce)      from 2320 goto 2339;
232e: 34,4b,08             jnb   B4,R4b,2339        if (!B4_R4b)               goto 2339;
2331: 33,4b,05             jnb   B3,R4b,2339        if (!B3_R4b)               goto 2339;
2334: 91,20,4b             orrb  R4b,20             R4b |= 20;           
2337: 20,03                sjmp  233c               goto 233c;           

2339: 71,df,4b             an2b  R4b,df             R4b &= df;      from 232b 232e 2331;    
233c: 3a,da,10             jb    B2,Rda,234f        if (B2_Rda)     from 233c goto 234f;
233f: 3d,4b,0d             jb    B5,R4b,234f        if (B5_R4b)               goto 234f;
2342: fa                   di                       disable ints;        
2343: 36,4b,06             jnb   B6,R4b,234c        if (!B6_R4b) goto 234c;
2346: 71,bf,4b             an2b  R4b,bf             R4b &= bf;           
2349: 91,80,4b             orrb  R4b,80             R4b |= 80;           
234c: fb                   ei                       enable ints               from 2343;         
234d: f8                   clc                      CY = 0;              
234e: f0                   ret                      return;              
Calls tend to be from other Subs, so an extra line for a sub to sub call.

Code: Select all

Sub0048:
Call    3980 Sub0047    3987 Sub0047    3991 Sub0047    3998 Sub0047

39f4: b3,6c,91,18          ldb   R18,[R6c+91]       R18 = [211];         
A possible (would need to follow all code branches to confirm) Push example
and Sjump from other Subs to Sub0057

Code: Select all

Sub0052:
.
.
4079: 20,7f                sjmp  40fa               goto Sub0057;        
.
.
.
Sub0057:
Jump   4079 Sub0052
Push   446a Sub0075

8 40fa: ae,19,14             ldzbw R14,[R18++]        R14 = (uns)[R18++];  


Sub0075:
.
.
446a: c9,fa,40             push  40fa               push(Sub0057);       
        

Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Sun Mar 04, 2018 2:13 am

% characters in a SYM name are not printed to the LST.
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Why auto disassembly is tough

Post by tvrfan » Mon Mar 05, 2018 2:47 pm

jsa wrote: ↑Sun Mar 04, 2018 2:13 am% characters in a SYM name are not printed to the LST.
Easy one. That's a 'classic' common bug in the way the standard IO library is called.... Found and fixed 4 calls.
The right name might actually crash SAD ! (try %d or %x somewhere in a name and see what happens )

I'm thinking about reusing the debug printouts in the _wrn file, and turning that into a 'call index' for subroutines and data structs.
I'm not a fan of putting the lists into the actual _lst file ....

Still doing the signed/unsigned and related stuff for tables and funcs - sorted basic commands and naming, but not finished yet.
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Why auto disassembly is tough

Post by jsa » Tue Mar 06, 2018 1:40 am

try %d or %x
Hmmm, may explain some previous weirdness.

Warnings elsewhere makes sense, but I am a fan of having relevant info all in one place like the LST.

You are probably all over this.
Line 207B should be R14>R16

Code: Select all

2068: 88,16,14            cmpw  R14,R16          
206b: db,0e               jc    207b             if ((uns) R14 < R16)  {
206d: b2,15,1a            ldb   R1a,[R14++]      R1a = [R14++];
2070: b2,1a,1c            ldb   R1c,[R1a]        R1c = [R1a];
2073: 92,15,1c            orb   R1c,[R14++]      R1c |= [R14++];
2076: c6,1a,1c            stb   R1c,[R1a]        [R1a] = R1c;
2079: 27,ed               sjmp  2068             goto 2068; }
207b: d9,b5               jgtu  2032             if ((uns) R1c > 0 ) goto Sub2032
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

To carry or borrow ... Opinions ?

Post by tvrfan » Thu Mar 08, 2018 11:28 pm

OK - with disassembler, I reckon there are different logic cases. Anyone have an opinion ?

8096 and 8061 docs imply that this CPU engine uses the BORROW strategy.
i.e CARRY is effectively reversed for subtracts.

So in SAD, I reckon this gives logic of -

Code: Select all

AD3W  R32, R34, R36             R36 = R34+R32;
JC  12345                       if (R36 > 0xffff)   goto 12345; (same as overflow)

CMPW  R32, R34                 # set PSW for R34-R32    
JC  12345                       if (unsigned) (R34 > R32)  (carry still set)

SB3W  R32, R34, R36             R36 = R34-R32;
JC 12345                        if (unsigned) (R36 > 0)            # same as  if (R34 > R32)

SHL R34, 8                      R34 * 256;
JC 12345                        if (R34 > 0xffff) ( last bit shifted out was a 1)

SHR R34, 8                      R34 / 256;
JC 12345                        # ??    Probably of no practical use ...
Anyone got anything here ??
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

sailorbob
BIN Hacker
Posts: 1779
Joined: Tue Jul 12, 2005 6:10 am

To carry or borrow ... Opinions ?

Post by sailorbob » Fri Mar 09, 2018 2:52 am

My observations on those examples:

Code: Select all

AD3W R32, R34, R36
JC   12345
The jump occurs if R32 > 0xFFFF (i.e. the operation is R32 = R34 + R36)

Code: Select all

CMPW R32, R34
JC   12345
The jump occurs if R32 >= R34 (i.e. set PSW for R32 - R34)

Code: Select all

SB3W R32, R34, R36
JC   12345
The jump occurs if R32 >= 0 (i.e. the operation is R32 = R34 - R36)

Code: Select all

SHLB R32, #3h
JC   12345
The jump occurs only if R32 bit 5 is set (i.e. the last bit shifted out is saved into the carry)

Code: Select all

SHRB R32, #3h
JC   12345
The jump occurs only if R32 bit 2 is set (i.e. the last bit shifted out is saved into the carry)

User avatar
tvrfan
Tuning Addict
Posts: 590
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: To carry or borrow ... Opinions ?

Post by tvrfan » Fri Mar 09, 2018 2:47 pm

sailorbob wrote: ↑Fri Mar 09, 2018 2:52 am

Code: Select all

CMPW R32, R34
JC   12345
The jump occurs if R32 >= R34 (i.e. set PSW for R32 - R34)

Code: Select all

SB3W R32, R34, R36
JC   12345
The jump occurs if R32 >= 0 (i.e. the operation is R32 = R34 - R36)
Many Thanks Bob.

Oops, I missed the logic swop !! ( > flips to <= of course ! and note to self to double check operand order....)
This confirms what I thought, and therefore I need to put in specific logic for correct pseudo source printout.

so for JC/JNC
1. search back to last PSW setter opcode (or should this be a specific CARRY flag setter/clearer ? Hmmm...)
2. if search finds a STC, CLC, CALL, then print equiv of "if (CY = 0) goto" END (too hard right now to handle subrs with return value !)
3. if search finds a CMP or a SUB (any others?) then use the 'borrow'
4. If search finds ADD (etc) then use 'carry'
5. If shift, then use shift out (top or bottom, I guess SHL could be 'if (B4_R32 = 1) style, but probably never used that way

other Conditonal jumps (JNE etc) just look for last PSW setter.... (which is what I do now....)
TVR, kit cars, classic cars. Ex IT geek, development and databases.
https://github.com/tvrfan/EEC-IV-disassembler

jsa
Tuning Addict
Posts: 1289
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: To carry or borrow ... Opinions ?

Post by jsa » Fri Mar 09, 2018 5:38 pm

Code: Select all

AD3W  R32, R34, R36             R36 = R34+R32;
JC  12345                       if (R36 > 0xffff)   goto 12345; (same as overflow)
Page C4 and C14 of the EEC Handbook says R36=R32+R34 which gives the same answer as your example.
This contradicts Sailorbob, though. :surprised:

Code: Select all

CMPW  R32, R34                 # set PSW for R34-R32    
JC  12345                       if (unsigned) (R34 > R32)  (carry still set)
From page C15 of the EEC Handbook, jump when R34>=R32 as C=1 for R34>R32 or R34=R32.

Code: Select all

SB3W  R32, R34, R36             R36 = R34-R32;
JC 12345                        if (unsigned) (R36 > 0)            # same as  if (R34 > R32)
From page C15 of the EEC Handbook, R36=R34-R32.
C=1 for R34>R32 or R34=R32 as per JC.

Code: Select all

SHL R34, 8                      R34 * 256;
JC 12345                        if (R34 > 0xffff) ( last bit shifted out was a 1)
From page C9 of the EEC Handbook, I'm seeing that as eight Bits being 15, 14, 13, 12, 11, 10, 9 & 8 shifted to Carry.
Bit 8 being the last into Carry has to be a value of 1 for the jump to occur.

Code: Select all

SHR R34, 8                      R34 / 256;
JC 12345                        # ??    Probably of no practical use ...
From page C9 of the EEC Handbook, I'm seeing that as eight Bits being 0, 1, 2, 3, 4, 5, 6 & 7 shifted to Carry.
Bit 7 being the last into Carry has to be a value of 1 for the jump to occur.
From page C12 of the EEC Handbook; "The sticky bit is set if the carry is set following a right shift"


So, is an extremely basic Test Binary and test definition required to test and log the contradictions?
Cheers

John

95 Escort RS Cosworth - CARD QUIK COSY ANTI / GHAJ0
Moates QH & BE
ForDiag

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests