Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 680x0 line A instructions #140

Closed
p2mate opened this issue Mar 9, 2019 · 4 comments
Closed

Support 680x0 line A instructions #140

p2mate opened this issue Mar 9, 2019 · 4 comments
Labels
Feature: Processor/68000 Reason: Duplicate This issue or pull request already exists Type: Enhancement New feature or request

Comments

@p2mate
Copy link

p2mate commented Mar 9, 2019

MacOS classic uses line A instructions (instructions with the highest 4 bits set to 1010) as an interface to the OS and the toolbox. Ghidra however considers these illegal, making disassembly of MacOS classic code difficult. It would be useful if Ghidra disassembles those as LineA #0xyyy where yyy are the lower 12 bits of the instruction word.

@p2mate p2mate added the Type: Enhancement New feature or request label Mar 9, 2019
@mumbel
Copy link
Contributor

mumbel commented Mar 9, 2019

http://mirror.informatimago.com/next/developer.apple.com/documentation/mac/OSUtilities/OSUtilities-170.html#HEADING170-48

  • op11=0 - Operating System routine
    • push exception stack frame
    • op0910 = flags: routine dependent
    • op8 = return/save A0 bit: op8=0: A0 is returned from OS routine, op8=1: A0 is not returned
    • op7 = trap number
    • saves: D0,D1,D2,A1,(A2?),A0 if op8=0
    • low(D1)=$AXXX
    • may alter D0-D2, A0-A2; preserve D3-D7, A3-A6; may return in D0 (and A0 if op8=0)
    • restore D1,D2,A1,A2,A0 if op8=0
    • values in D0 and A0 if op8=1 are not restored
    • param: D0 data value and A0 for addresses (or parameter block when more than 2 params)
  • op11=1 - Toolbox routine
    • op10 = auto-pop bit: forces trap dispatcher to remove 4bytes of stack before dispatching, will return to glue routine was called
    • op9 = trap number
    • may alter D0-D2,A0,A1
    • parameters and return are stack based and passed as pointers to actual storage

No clue how to write sleigh, and more to it ^^^, but something like this in 68000.sinc for starters

   opbig  = (8,15)
   op02 = (0,2)
   op03 = (0,3)
+  op07 = (0,7)
   op08 = (0,8)
+  op09 = (0,9)
   op015 = (0,15)
   op34 = (3,4)
   op35 = (3,5)
@@ -94,6 +96,7 @@
   op8 = (8,8)
   quick = (9,11)
   op811 = (8,11)
+  op11 = (11,11)
   copcc1 = (0,5)
   d8base = (0,7) signed
 @ifdef COLDFIRE
@@ -300,6 +303,8 @@
 
 define pcodeop kfactor;
 define pcodeop ftrap;
+define pcodeop atrap;
+define pcodeop toolbox;
 define pcodeop trap;
 define pcodeop reset;
 define pcodeop saveFPUStateFrame;
@@ -741,6 +746,9 @@
 :asr.l cntreg,regdn		is op=14 & cntreg & op8=0 & op67=2 & op34=0 & regdn		{ getbit(CF,regdn,cntreg-1); regdn=regdn s>>cntreg; resflags(regdn); }
 :asr eaw			is (opbig=0xe0 & op67=3 & $(MEM_ALTER_ADDR_MODES))... & eaw				{ getbit(CF,eaw,0); eaw=eaw s>>1; resflags(eaw); }
 
+:atrap	"#"^op07    	  	is op=10 & op11=0 & op07  { tmp:4 = op07; atrap(tmp); }
+:toolbox "#"^op09    	  	is op=10 & op11=1 & op09  { tmp:4 = op09; toolbox(tmp); }
+
 :b^cc^".b" addr8		is op=6 & cc & addr8						{ if (cc) goto addr8; }
 :b^cc^".w" addr16		is op=6 & cc & d8base=0; addr16					{ if (cc) goto addr16; }
 :b^cc^".l": addr32		is op=6 & cc & d8base=255; addr32				{ if (cc) goto addr32; }

@p2mate
Copy link
Author

p2mate commented Mar 10, 2019

Thanks. That helps. Next thing to do is probably to write a script which tells Ghidra which registers have changed by the trap.

@ryanmkurtz ryanmkurtz added Reason: Duplicate This issue or pull request already exists Feature: Processor/68000 labels Sep 20, 2019
@ryanmkurtz
Copy link
Collaborator

Duplicate of #487

@ryanmkurtz ryanmkurtz marked this as a duplicate of #487 Sep 20, 2019
@hippietrail
Copy link
Contributor

I'm guessing there are typos in at least these two parts:

  • op7 = trap number

  • op9 = trap number

Those would mean single bit fields. I'm guessing it should be:

  • op07 = trap number

  • op09 = trap number

I'm not sure if there were other typos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Processor/68000 Reason: Duplicate This issue or pull request already exists Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants