ppcasm.h
上传用户:zbbssh
上传日期:2007-01-08
资源大小:196k
文件大小:26k
源码类别:

CA认证

开发平台:

C/C++

  1. #ifndef PPCASM_H
  2. #define PPCASM_H
  3. /*
  4.  * A PowerPC assembler in the C preprocessor.
  5.  * This assumes that ints are 32 bits, and uses them for the values.
  6.  *
  7.  * An assembly-language routine is simply an array of unsigned ints,
  8.  * initialized with the macros defined here.
  9.  *
  10.  * In the PowerPC, a generic function pointer does *not* point to the
  11.  * first word of code, but to a two (or possibly more) word "transition
  12.  * vector."  The first word of the TV points to the function's code.
  13.  * The second word is the function's TOC (Table Of Contents) pointer,
  14.  * which is loaded into r2.  The function's global variables are
  15.  * accessed via the TOC pointed to by r2.  TOC pointers are changed,
  16.  * for example, when a dynamically linked library is called, so the
  17.  * library can have private global variables.
  18.  *
  19.  * Saving r2 and reloading r2 each function call is a hassle that
  20.  * I'd really rather avoid, since a lot of useful assembly language routines
  21.  * can be written without global variables at all, so they don't need a TOC
  22.  * pointer.  But I haven't figured out how to persuade CodeWarrior to
  23.  * generate an intra-TOC call to an array.
  24.  *
  25.  * The basic PowerPC calling conventions for integers are:
  26.  * r0  - scratch.  May be modified by function calls.
  27.  * r1  - stack pointer.  Must be preserved across function calls.
  28.  *       See IMPORTANT notes on stack frame format below.
  29.  *       This must *ALWAYS*, at every instruction boundary, be 16-byte
  30.  *       aligned and point to a valid stack frame.  If a procedure
  31.  *       needs to create a stack frame, the recommended way is to do:
  32.  *       stwu r1,-frame_size(r1)
  33.  *       and on exit, recover with one of:
  34.  *       addi r1,r1,frame_size,   OR
  35.  *       lwz r1,0(r1)
  36.  * r2  - TOC pointer.  Points to the current table of contents.
  37.  *       Must be preserved across function calls.
  38.  * r3  - First argument register and return value register.
  39.  *       Arguments are passed in r3 through r10, and values returned in
  40.  *       r3 through r6, as needed.  (Usually only r3 for single word.)
  41.  * r4-r10 - More argument registers
  42.  * r11 - Scratch, may be modified by function calls.
  43.  *       On entry to indirect function calls, this points to the
  44.  *       transition vector, and additional words may be loaded
  45.  *       at offsets from it.  Some conventions use r12 instead.
  46.  * r12 - Scratch, may be modified by function calls.
  47.  * r13-r31 - Callee-save registers, may not be modified by function
  48.  *       calls.
  49.  * The LR, CTR and XER may be modified by function calls, as may the MQ
  50.  * register, on those processors for which it is implemented.
  51.  * CR fields 0, 1, 5, 6 and 7 are scratch and may be modified by function
  52.  * calls.  CR fields 2, 3 and 4 must be preserved across function calls.
  53.  *
  54.  * Stack frame format - READ
  55.  *
  56.  * r1 points to a stack frame, which must *ALWAYS*, meaning after each and
  57.  * ever instruction, without excpetion, point to a valid 16-byte-aligned
  58.  * stack frame, defined as follows:
  59.  * - The 296 bytes below r1 (from -296(r1) to -1(r1)) are the so-called Red
  60.  *   Zone reserved for leaf procedures, which may use it without allocating
  61.  *   a stack frame and without decrementing it.  The size comes from the room
  62.  *   needed to store all the callee-save registers: 19 64-bit integer registers
  63.  *   and 18 64-bit floating-point registers. (18+19)*8 = 296.  So any
  64.  *   procedure can save all the registers it needs to save before creating
  65.  *   a stack frame and moving r1.
  66.  *   The bytes at -297(r1) and below may be used by interrupt and exception
  67.  *   handlers at any time.
  68.  *   The word at 0(r1) is the previous r1, and so on in a linked list.
  69.  *   This is the minimum needed to be a valid stack frame, but some other
  70.  *   offsets from r1 are preallocated by the calling procedure for the called
  71.  *   procedure's use.  These are:
  72.  *   Offset 0:  Link to previous stack frame - saved r1, if the called
  73.  *              procedure alters it.
  74.  *   Offset 4:  Saved CR, if the called procedure alters the callee-save
  75.  *              fields.  There's no important reason to save it here,
  76.  *              but the space is reserved and you might as well use it
  77.  *              for its intended purpose unless you have good reason to
  78.  *              do otherwise.  (This may help some debuggers.)
  79.  *   Offset 8:  Saved LR, if the called procedure needs to save it for
  80.  *              later function return.  Saving the LR here helps a debugger
  81.  *              track the chain of return addresses on the stack.
  82.  *              Note that a called procedure does not need to preserve the
  83.  *              LR for it's caller's sake, but it uually wants to preserve
  84.  *              the value for its own sake until it finishes and it's time
  85.  *              to return.  At that point, this is usually loaded back into
  86.  *              the LR and the branch accomplished with BLR.  However,
  87.  *              if you want to be preverse, you could load it into the CTR
  88.  *              and use BCTR instead.
  89.  *   Offset 12: Reserved to compiler.  I cant find what this is for.
  90.  *   Offset 16: Reserved to compiler.  I cant find what this is for.
  91.  *   Offset 20: Saved TOC pointer.  In a cross-TOC call, the old TOC (r2)
  92.  *              is saved here before r2 is loaded with the new TOC value.
  93.  *              Again, it's not important to use this slot for this, but
  94.  *              you might as well.
  95.  * Beginning at offset 24 is the argument area.  This area is at least 8 words
  96.  * (32 bytes; I don't know what happens with 64 bits) long, and may be longer,
  97.  * up to the length of the longest argument list in a function called by
  98.  * the function which allocated this stack frame.  Generally, arguments
  99.  * to functions are passed in registers, but if those functions notice
  100.  * the address of the arguments being taken, the registers are stored
  101.  * into the space reserved for them in this area and then used from memory.
  102.  * Additional arguments that will not fit into registers are also stored
  103.  * here.  Variadic functions (like printf) generally start by saving
  104.  * all the integer argument registers from the "..." onwards to this space.
  105.  * For that reason, the space must be large enough to store all the argument
  106.  * registers, even if they're never used.
  107.  * (It could probably be safely shrunk if you're not calling any variadic
  108.  * functions, but be careful!)
  109.  * 
  110.  
  111.  *               It isn't Reserved to compiler.  I cant find what this is for.
  112.  
  113.  * 19 callee-save between
  114.  * every single pair 
  115.  * The floating-point instruction set isn't implemented yet (I'm too
  116.  * lazy, as I don't need it yet), but for when it is, the register
  117.  * usage convention is:
  118.  * FPSCR - Scratch, except for floating point exception enable fields,
  119.  * which should only be modified by functions defined to do so.
  120.  * fr0  - scratch
  121.  * fr1  - first floating point parameter and return value, scratch
  122.  * fr2  - second floating point parameter and return value (if needed), scratch
  123.  * fr3  - third floating point parameter and return value (if needed), scratch
  124.  * fr4  - fourth floating point parameter and return value (if needed), scratch
  125.  * fr5-fr13 - More floating point argument registers, scratch
  126.  * fr14-fr31 - Callee-save registers, may not be modified across a function call
  127.  *
  128.  * Complex values store the real part in the lower-numberd register of a pair.
  129.  * When mixing floating-point and integer arguments, reserve space (one register
  130.  * for single-precision, two for double-precision values) in the integer
  131.  * argument list for the floating-point values.  Those integer registers
  132.  * generally have undefined values, UNLESS there is no prototype for the call,
  133.  * in which case they should contain a copy of the floating-point value's
  134.  * bit pattern to cope with wierd software.
  135.  * If the floating point arguments go past the end of the integer registers,
  136.  * they are stored in the argument area as well as being passed in here.
  137.  *
  138.  * After the argument area comes the calling function's private storage.
  139.  * Typically, there are locals, followed by saved GP rgisters, followed
  140.  * by saved FP registers.
  141.  *
  142.  * Suggested instruction for allocating a stack frame:
  143.  *        stwu r1,-frame_size(r1)
  144.  * Suggested instructions for deallocating a stack frame:
  145.  *        addi r1,r1,frame_size
  146.  * or
  147.  *        lwz r1,0(r1)
  148.  * If frame_size is too big, you'll have to do something with temp registers,
  149.  * but be sure that r1 is updated atomicly.
  150.  *
  151.  *
  152.  * Basic PowerPC instructions look like this:
  153.  *
  154.  *                      1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
  155.  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  156.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  157.  * |   Opcode  | | | | | | | | | | | | | | | | | | | | | | | | | | |
  158.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  159.  *
  160.  * Branch instructions look like this:
  161.  *
  162.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  163.  * |   Opcode  |             Branch offset                     |A|L|
  164.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  165.  *
  166.  * The L, or LK, or Link bit indicates that the return address for the
  167.  * branch should be copied to the link register (LR).
  168.  * The A, or AA, or absolute address bit, indicates that the address
  169.  * of the current instruction (NOTE: not next instruction!) should NOT
  170.  * be added to the branch offset; it is relative to address 0.
  171.  *
  172.  * Conditional branches looks like this:
  173.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  174.  * |   Opcode  |    BO   |   BI    |      Branch offset        |A|L|
  175.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  176.  *
  177.  * The BI field specifies the condition bit of interest.
  178.  * The BO field specifies what's interesting.  It is encoded as follows.
  179.  * y = branch prediction bit.  z = must be 0
  180.  * 0000y - branch if --crt != 0 && BI == 0
  181.  *         don't branch if --crt == 0 || BI != 0
  182.  * 0001y - branch if --crt == 0 && BI == 0
  183.  *         don't branch if --crt != 0 || BI != 0
  184.  * 001zy - branch if BI == 0
  185.  *         don't branch if BI != 0
  186.  * 0100y - branch if --crt != 0 && BI != 0
  187.  *         don't branch if --crt == 0 || BI == 0
  188.  * 0101y - branch if --crt == 0 && BI != 0
  189.  *         don't branch if --crt != 0 || BI == 0
  190.  * 011zy - branch if BI != 0
  191.  *         don't branch if BI == 0
  192.  * 1z00y - branch if --crt != 0
  193.  *         don't branch if --crt == 0
  194.  * 1z01y - branch if --crt == 0
  195.  *         don't branch if --crt != 0
  196.  * 1z1zz - branch always
  197.  * If y is 1, the usual branch prediction (usually not taken, taken for
  198.  * backwards branches with immediate offsets) is reversed.
  199.  *
  200.  * Instructions with 2 operands and a 16-bit immediate field look like this:
  201.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  202.  * |   Opcode  |     D   |    A    |    16-bit immediate value     |
  203.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  204.  *
  205.  * Now, there are three variations of note.  In some instructions, the 16-bit
  206.  * value is sign-extended.  In others, it's zero-extended.  These are noted
  207.  * below as "simm" (signed immediate) and "uimm", respectively.  Also, which
  208.  * field is the destination and which is the source sometimes switches.
  209.  * Sometimes it's d = a OP imm, and sometimes it's a = s OP imm.  In the
  210.  * latter cases, the "d" field is referred to as "s" ("source" instead of
  211.  * "destination".  These are logical and shift instructions.  (Store also
  212.  * refers to the s register, but that's the source of the value to be stored.)
  213.  * The assembly code, however, always lists the destination first, swapping
  214.  * the order in the instruction if necessary.
  215.  * Third, quite often, if r0 is specified for the source a, then the constant
  216.  * value 0 is used instead.  Thus, r0 is of limited use - it can be used for
  217.  * some things, but not all.
  218.  *
  219.  * Instructions with three register operands look like this:
  220.  * Instructions with 2 operands and a 16-bit immediate field look like this:
  221.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  222.  * |   Opcode  |     D   |    A    |    B    |     Subopcode     |C|
  223.  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  224.  *
  225.  * For most of the instructions of interest the Opcode is 31 and the subopcode
  226.  * determines what the instruction does.  For a few instructions (mostly loads
  227.  * and stores), if the A field is 0, the constant 0 is used.  The "C"
  228.  * bit (also known as the "RC" bit) controls whether or not the condition
  229.  * codes are updated.  If it is set (indicated by a "." suffix on the official
  230.  * PowerPC opcodes, and a "_" suffix on these macros), condition code register
  231.  * field 0 (for integer instructions; field 1 for floating point) is updated
  232.  * to reflect the result of the operation.
  233.  * Some arithmetic instructions use the most significant bit of the subopcode
  234.  * field as an overflow enable bit (o suffix).
  235.  *
  236.  * Then there are the rotate and mask instructions, which have 5 operands, and
  237.  * fill the subopcode field with 2 more 5-bit fields.  See below for them.
  238.  *
  239.  * NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
  240.  * These macros fully parenthesize their arguments, but are not themselves
  241.  * fully parenthesized.  They are intended to be used for initializer lists,
  242.  * and if you want to do tricks with their numeric values, wrap them in
  243.  * parentheses.
  244.  */
  245. #define PPC_MAJOR(x) ((x)<<26) /* Major opcode (0..63) */
  246. #define PPC_MINOR(x) ((x)<<1) /* Minor opcode (0..1023) */
  247. #define PPC_RC 1 /* Record carry (. suffix, represented as _) */
  248. #define PPC_OE 1024 /* Overflow enable (o suffix) */
  249. #define PPC_DEST(reg) ((reg)<<21) /* Dest register field */
  250. #define PPC_SRCA(reg) ((reg)<<16) /* First source register field */
  251. #define PPC_SRCB(reg) ((reg)<<11) /* Second source register field */
  252. #define PPC_AA 2 /* Branch is absolute, relative to address 0 */
  253. #define PPC_LK 1 /* Branch with link (L suffix) */
  254. /* Unconditional branch (dest is 26 bits, +/- 2^25 bytes) */
  255. #define PPC_B(dest) PPC_MAJOR(18)|(((dest)<<2) & 0x03fffffc)
  256. #define PPC_BA(dest) PPC_B(dest)|PPC_AA
  257. #define PPC_BL(dest) PPC_B(dest)|PPC_LK
  258. #define PPC_BLA(dest) PPC_B(dest)|PPC_AA|PPC_LK
  259. /* Three-operand instructions */
  260. #define PPC_TYPE31(minor,d,a,b)
  261. PPC_MAJOR(31)|PPC_DEST(d)|PPC_SRCA(a)|PPC_SRCB(b)|PPC_MINOR(minor)
  262. #define PPC_ADD(d,a,b)   PPC_TYPE31(266,d,a,b)
  263. #define PPC_ADD_(d,a,b)  PPC_TYPE31(266,d,a,b)|PPC_RC
  264. #define PPC_ADDO(d,a,b)  PPC_TYPE31(266,d,a,b)|PPC_OE
  265. #define PPC_ADDO_(d,a,b) PPC_TYPE31(266,d,a,b)|PPC_OE|PPC_RC
  266. #define PPC_ADDC(d,a,b)  PPC_TYPE31(10,d,a,b)
  267. #define PPC_ADDC_(d,a,b) PPC_TYPE31(10,d,a,b)|PPC_RC
  268. #define PPC_ADDCO(d,a,b) PPC_TYPE31(10,d,a,b)|PPC_OE
  269. #define PPC_ADDCO_(d,a,b) PPC_TYPE31(10,d,a,b)|PPC_OE|PPC_RC
  270. #define PPC_ADDE(d,a,b)  PPC_TYPE31(138,d,a,b)
  271. #define PPC_ADDE_(d,a,b) PPC_TYPE31(138,d,a,b)|PPC_RC
  272. #define PPC_ADDEO(d,a,b) PPC_TYPE31(138,d,a,b)|PPC_OE
  273. #define PPC_ADDEO_(d,a,b) PPC_TYPE31(138,d,a,b)|PPC_OE|PPC_RC
  274. #define PPC_ADDME(d,a)   PPC_TYPE31(234,d,a,0)
  275. #define PPC_ADDME_(d,a)  PPC_TYPE31(234,d,a,0)|PPC_RC
  276. #define PPC_ADDMEO(d,a)  PPC_TYPE31(234,d,a,0)|PPC_OE
  277. #define PPC_ADDMEO_(d,a) PPC_TYPE31(234,d,a,0)|PPC_OE|PPC_RC
  278. #define PPC_ADDZE(d,a)   PPC_TYPE31(202,d,a,0)
  279. #define PPC_ADDZE_(d,a)  PPC_TYPE31(202,d,a,0)|PPC_RC
  280. #define PPC_ADDZEO(d,a)  PPC_TYPE31(202,d,a,0)|PPC_OE
  281. #define PPC_ADDZEO_(d,a) PPC_TYPE31(202,d,a,0)|PPC_OE|PPC_RC
  282. #define PPC_AND(a,s,b)   PPC_TYPE31(28,s,a,b)
  283. #define PPC_AND_(a,s,b)  PPC_TYPE31(28,s,a,b)|PPC_RC
  284. #define PPC_ANDC(a,s,b)  PPC_TYPE31(60,s,a,b)
  285. #define PPC_ANDC_(a,s,b) PPC_TYPE31(60,s,a,b)|PPC_RC
  286. #define PPC_CMP(cr,a,b)  PPC_TYPE31(0,(cr)<<2,a,b)
  287. #define PPC_CMPL(cr,a,b) PPC_TYPE31(32,(cr)<<2,a,b)
  288. #define PPC_CNTLZW(a,s)  PPC_TYPE31(26,s,a,0)
  289. #define PPC_CNTLZW_(a,s) PPC_TYPE31(26,s,a,0)|PPC_RC
  290. #define PPC_DCBF(a,b)    PPC_TYPE31(86,0,a,b)
  291. #define PPC_DCBI(a,b)    PPC_TYPE31(470,0,a,b)
  292. #define PPC_DCBST(a,b)   PPC_TYPE31(54,0,a,b)
  293. #define PPC_DCBT(a,b)    PPC_TYPE31(278,0,a,b)
  294. #define PPC_DCBTST(a,b)  PPC_TYPE31(246,0,a,b)
  295. #define PPC_DCBZ(a,b)    PPC_TYPE31(1014,0,a,b)
  296. #define PPC_DIVW(d,a,b)  PPC_TYPE31(491,d,a,b)
  297. #define PPC_DIVW_(d,a,b) PPC_TYPE31(491,d,a,b)|PPC_RC
  298. #define PPC_DIVWO(d,a,b) PPC_TYPE31(491,d,a,b)|PPC_OE
  299. #define PPC_DIVWO_(d,a,b) PPC_TYPE31(491,d,a,b)|PPC_OE|PPC_RC
  300. #define PPC_DIVWU(d,a,b) PPC_TYPE31(459,d,a,b)
  301. #define PPC_DIVWU_(d,a,b) PPC_TYPE31(459,d,a,b)|PPC_RC
  302. #define PPC_DIVWUO(d,a,b) PPC_TYPE31(459,d,a,b)|PPC_OE
  303. #define PPC_DIVWUO_(d,a,b) PPC_TYPE31(459,d,a,b)|PPC_OE|PPC_RC
  304. #define PPC_EIEIO()      PPC_TYPE31(854,0,0,0)
  305. #define PPC_EQV(a,s,b)   PPC_TYPE31(284,s,a,b)
  306. #define PPC_EQV_(a,s,b)  PPC_TYPE31(284,s,a,b)|PPC_RC
  307. #define PPC_EXTSB(a,s,b) PPC_TYPE31(954,s,a,b)
  308. #define PPC_EXTSB_(a,s,b) PPC_TYPE31(954,s,a,b)|PPC_RC
  309. #define PPC_EXTSH(a,s,b) PPC_TYPE31(922,s,a,b)
  310. #define PPC_EXTSH_(a,s,b) PPC_TYPE31(922,s,a,b)|PPC_RC
  311. #define PPC_ICBI(a,b)    PPC_TYPE31(982,0,a,b)
  312. #define PPC_ISYNC()      PPC_TYPE31(150,0,0,0)
  313. #define PPC_LBZUX(d,a,b) PPC_TYPE31(119,d,a,b)
  314. #define PPC_LBZX(d,a,b)  PPC_TYPE31(87,d,a,b)
  315. #define PPC_LHAUX(d,a,b) PPC_TYPE31(375,d,a,b)
  316. #define PPC_LHAX(d,a,b)  PPC_TYPE31(343,d,a,b)
  317. #define PPC_LHBRX(d,a,b) PPC_TYPE31(790,d,a,b)
  318. #define PPC_LHZUX(d,a,b) PPC_TYPE31(311,d,a,b)
  319. #define PPC_LHZX(d,a,b)  PPC_TYPE31(279,d,a,b)
  320. #define PPC_LSWI(d,a,nb) PPC_TYPE31(597,d,a,nb)
  321. #define PPC_LSWX(d,a,b)  PPC_TYPE31(533,d,a,b)
  322. #define PPC_LSARX(d,a,b)  PPC_TYPE31(20,d,a,b)
  323. #define PPC_LSBRX(d,a,b)  PPC_TYPE31(534,d,a,b)
  324. #define PPC_MCRXR(crd)   PPC_TYPE31(512,(crd)<<2,0,0)
  325. #define PPC_MFCR(d)      PPC_TYPE31(19,d,0,0)
  326. #define PPC_MFSPR(d,spr)      PPC_TYPE31(339,d,(spr)&31,(spr)>>5)
  327. #define PPC_MFTB(d)      PPC_TYPE31(371,d,12,8)
  328. #define PPC_MFTBU(d)      PPC_TYPE31(371,d,13,8)
  329. #define PPC_MTCRF(mask,s)      PPC_TYPE31(144,s,0,(mask)&0xff)
  330. #define PPC_MTSPR(s,spr)      PPC_TYPE31(467,s,(spr)&31,(spr)>>5)
  331. #define PPC_MULHW(d,a,b)  PPC_TYPE31(75,d,a,b)
  332. #define PPC_MULHW_(d,a,b)  PPC_TYPE31(75,d,a,b)|PPC_RC
  333. #define PPC_MULHWU(d,a,b)  PPC_TYPE31(11,d,a,b)
  334. #define PPC_MULHWU_(d,a,b)  PPC_TYPE31(11,d,a,b)|PPC_RC
  335. #define PPC_MULLW(d,a,b)  PPC_TYPE31(235,d,a,b)
  336. #define PPC_MULLW_(d,a,b)  PPC_TYPE31(235,d,a,b)|PPC_RC
  337. #define PPC_MULLWO(d,a,b)  PPC_TYPE31(235,d,a,b)|PPC_OE
  338. #define PPC_MULLWO_(d,a,b)  PPC_TYPE31(235,d,a,b)|PPC_OE|PPC_RC
  339. #define PPC_NAND(a,s,b)   PPC_TYPE31(476,s,a,b)
  340. #define PPC_NAND_(a,s,b)  PPC_TYPE31(476,s,a,b)|PPC_RC
  341. #define PPC_NEG(d,a)     PPC_TYPE31(104,d,a,b)
  342. #define PPC_NEG_(d,a)     PPC_TYPE31(104,d,a,b)|PPC_RC
  343. #define PPC_NEGO(d,a)     PPC_TYPE31(104,d,a,b)|PPC_OE
  344. #define PPC_NEGO_(d,a)     PPC_TYPE31(104,d,a,b)|PPC_OE|PPC_RC
  345. #define PPC_NOR(a,s,b)   PPC_TYPE31(124,s,a,b)
  346. #define PPC_NOR_(a,s,b)  PPC_TYPE31(124,s,a,b)|PPC_RC
  347. #define PPC_OR(a,s,b)    PPC_TYPE31(444,s,a,b)
  348. #define PPC_OR_(a,s,b)   PPC_TYPE31(444,s,a,b)|PPC_RC
  349. #define PPC_ORC(a,s,b)    PPC_TYPE31(412,s,a,b)
  350. #define PPC_ORC_(a,s,b)   PPC_TYPE31(412,s,a,b)|PPC_RC
  351. #define PPC_SLW(a,s,b)    PPC_TYPE31(24,s,a,b)
  352. #define PPC_SLW_(a,s,b)   PPC_TYPE31(24,s,a,b)|PPC_RC
  353. #define PPC_SRAW(a,s,b)    PPC_TYPE31(792,s,a,b)
  354. #define PPC_SRAW_(a,s,b)   PPC_TYPE31(792,s,a,b)|PPC_RC
  355. #define PPC_SRAWI(a,s,sh)    PPC_TYPE31(824,s,a,sh)
  356. #define PPC_SRAWI_(a,s,sh)   PPC_TYPE31(824,s,a,sh)|PPC_RC
  357. #define PPC_SRW(a,s,b)    PPC_TYPE31(536,s,a,b)
  358. #define PPC_SRW_(a,s,b)   PPC_TYPE31(536,s,a,b)|PPC_RC
  359. #define PPC_STBUX(s,a,b)    PPC_TYPE31(247,s,a,b)
  360. #define PPC_STBX(s,a,b)    PPC_TYPE31(215,s,a,b)
  361. #define PPC_STHBRX(s,a,b)    PPC_TYPE31(918,s,a,b)
  362. #define PPC_STHUX(s,a,b)    PPC_TYPE31(439,s,a,b)
  363. #define PPC_STHX(s,a,b)    PPC_TYPE31(407,s,a,b)
  364. #define PPC_STSWI(s,a,nb)    PPC_TYPE31(725,s,a,nb)
  365. #define PPC_STSWX(s,a,b)    PPC_TYPE31(661,s,a,b)
  366. #define PPC_STWBRX(s,a,b)    PPC_TYPE31(662,s,a,b)
  367. #define PPC_STWCX_(s,a,b)    PPC_TYPE31(150,s,a,b)|PPC_RC
  368. #define PPC_STWUX(s,a,b)    PPC_TYPE31(183,s,a,b)
  369. #define PPC_STWX(s,a,b)    PPC_TYPE31(151,s,a,b)
  370. #define PPC_SUBF(d,a,b)  PPC_TYPE31(40,d,a,b)
  371. #define PPC_SUBF_(d,a,b)  PPC_TYPE31(40,d,a,b)|PPC_RC
  372. #define PPC_SUBFO(d,a,b)  PPC_TYPE31(40,d,a,b)|PPC_OE
  373. #define PPC_SUBFO_(d,a,b)  PPC_TYPE31(40,d,a,b)|PPC_OE|PPC_RC
  374. #define PPC_SUB(d,b,a) PPC_SUBF(d,a,b)
  375. #define PPC_SUB_(d,b,a) PPC_SUBF_(d,a,b)
  376. #define PPC_SUBO(d,b,a) PPC_SUBFO(d,a,b)
  377. #define PPC_SUBO_(d,b,a) PPC_SUBFO_(d,a,b)
  378. #define PPC_SUBFC(d,a,b)  PPC_TYPE31(8,d,a,b)
  379. #define PPC_SUBFC_(d,a,b)  PPC_TYPE31(8,d,a,b)|PPC_RC
  380. #define PPC_SUBFCO(d,a,b)  PPC_TYPE31(8,d,a,b)|PPC_OE
  381. #define PPC_SUBFCO_(d,a,b)  PPC_TYPE31(8,d,a,b)|PPC_OE|PPC_RC
  382. #define PPC_SUBFE(d,a,b)  PPC_TYPE31(136,d,a,b)
  383. #define PPC_SUBFE_(d,a,b)  PPC_TYPE31(136,d,a,b)|PPC_RC
  384. #define PPC_SUBFEO(d,a,b)  PPC_TYPE31(136,d,a,b)|PPC_OE
  385. #define PPC_SUBFEO_(d,a,b)  PPC_TYPE31(136,d,a,b)|PPC_OE|PPC_RC
  386. #define PPC_SUBFME(d,a)  PPC_TYPE31(232,d,a,0)
  387. #define PPC_SUBFME_(d,a)  PPC_TYPE31(232,d,a,0)|PPC_RC
  388. #define PPC_SUBFMEO(d,a)  PPC_TYPE31(232,d,a,0)|PPC_OE
  389. #define PPC_SUBFMEO_(d,a)  PPC_TYPE31(232,d,a,0)|PPC_OE|PPC_RC
  390. #define PPC_SUBFZE(d,a)  PPC_TYPE31(200,d,a,0)
  391. #define PPC_SUBFZE_(d,a)  PPC_TYPE31(200,d,a,0)|PPC_RC
  392. #define PPC_SUBFZEO(d,a)  PPC_TYPE31(200,d,a,0)|PPC_OE
  393. #define PPC_SUBFZEO_(d,a)  PPC_TYPE31(200,d,a,0)|PPC_OE|PPC_RC
  394. #define PPC_SYNC() PPC_TYPE31(598,0,0,0)
  395. #define PPC_TW(to,a,b)    PPC_TYPE31(4,to,a,b)
  396. #define PPC_XOR(a,s,b)    PPC_TYPE31(316,s,a,b)
  397. /* Immediate-operand instructions.  Take a 16-bit immediate operand */
  398. #define PPC_IMM(major,d,a,imm) 
  399. PPC_MAJOR(major)|PPC_DEST(d)|PPC_SRCA(a)|((imm)&0xffff)
  400. /* Trap word immediate */
  401. #define PPV_TWI(to,a,simm) PPC_IMM(3,to,a,simm)
  402. /* Integer arithmetic */
  403. #define PPC_MULLI(d,a,simm) PPC_IMM(7,d,a,simm)
  404. #define PPC_SUBFIC(s,a,simm) PPC_IMM(8,s,a,simm)
  405. #define PPC_CMPLI(cr,a,uimm) PPC_IMM(10,(cr)<<2,a,uimm)
  406. #define PPC_CMPI(cr,a,simm) PPC_IMM(11,(cr)<<2,a,simm)
  407. #define PPC_ADDIC(d,a,simm) PPC_IMM(12,d,a,simm)
  408. #define PPC_ADDIC_(d,a,simm) PPC_IMM(13,d,a,simm)
  409. #define PPC_ADDI(d,a,simm) PPC_IMM(14,d,a,simm)
  410. #define PPC_ADDIS(d,a,simm) PPC_IMM(15,d,a,simm)
  411. /* Conditional branch (dest is 16 bits, +/- 2^15 bytes) */
  412. #define PPC_BC(bo,bi,dest) PPC_IMM(16,bo,bi,((dest)<<2)&0xfffc)
  413. #define PPC_BCA(bo,bi,dest) PPC_BC(bo,bi,dest)|PPC_AA
  414. #define PPC_BCL(bo,bi,dest) PPC_BC(bo,bi,dest)|PPC_LK
  415. #define PPC_BCLA(bo,bi,dest) PPC_BC(bo,bi,dest)|PPC_AA|PPC_LK
  416. /* Logical operations */
  417. #define PPC_ORI(a,s,uimm) PPC_IMM(24,s,a,uimm)
  418. #define PPC_ORIS(a,s,uimm) PPC_IMM(25,s,a,uimm)
  419. #define PPC_XORI(a,s,uimm) PPC_IMM(26,s,a,uimm)
  420. #define PPC_XORIS(a,s,uimm) PPC_IMM(27,s,a,uimm)
  421. #define PPC_ANDI_(a,s,uimm) PPC_IMM(28,s,a,uimm)
  422. #define PPC_ANDIS(a,s,uimm) PPC_IMM(29,s,a,uimm)
  423. /* Load/store */
  424. #define PPC_LWZ(d,a,simm) PPC_IMM(32,d,a,simm)
  425. #define PPC_LWZU(d,a,simm) PPC_IMM(33,d,a,simm)
  426. #define PPC_LBZ(d,a,simm) PPC_IMM(34,d,a,simm)
  427. #define PPC_LBZU(d,a,simm) PPC_IMM(35,d,a,simm)
  428. #define PPC_STW(s,a,simm) PPC_IMM(36,s,a,simm)
  429. #define PPC_STWU(s,a,simm) PPC_IMM(37,s,a,simm)
  430. #define PPC_STB(s,a,simm) PPC_IMM(38,s,a,simm)
  431. #define PPC_STBU(s,a,simm) PPC_IMM(39,s,a,simm)
  432. #define PPC_LHZ(d,a,simm) PPC_IMM(40,d,a,simm)
  433. #define PPC_LHZU(d,a,simm) PPC_IMM(41,d,a,simm)
  434. #define PPC_LHA(d,a,simm) PPC_IMM(42,d,a,simm)
  435. #define PPC_STH(s,a,simm) PPC_IMM(44,s,a,simm)
  436. #define PPC_STHU(s,a,simm) PPC_IMM(45,s,a,simm)
  437. #define PPC_LHAU(d,a,simm) PPC_IMM(43,d,a,simm)
  438. #define PPC_LMW(d,a,simm) PPC_IMM(46,d,a,simm)
  439. #define PPC_STMW(s,a,simm) PPC_IMM(47,s,a,simm)
  440. /* Major number = 19 - condition register operations.  d, a and b are CR bits */
  441. #define PPC_TYPE19(minor,d,a,b) 
  442. PPC_MAJOR(19)|PPC_DEST(d)|PPC_SRCA(a)|PPC_SRCB(b)|PPC_MINOR(minor)
  443. #define PPC_MCRF(d,s)    PPC_TYPE19(0,(d)<<2,(s)<<2,0)
  444. #define PPC_CRNOR(d,a,b) PPC_TYPE19(33,d,a,b)
  445. #define PPC_CRANDC(d,a,b) PPC_TYPE19(129,d,a,b)
  446. #define PPC_CRXOR(d,a,b) PPC_TYPE19(193,d,a,b)
  447. #define PPC_CRNAND(d,a,b) PPC_TYPE19(225,d,a,b)
  448. #define PPC_CRAND(d,a,b) PPC_TYPE19(257,d,a,b)
  449. #define PPC_CREQV(d,a,b) PPC_TYPE19(289,d,a,b)
  450. #define PPC_CRORC(d,a,b) PPC_TYPE19(417,d,a,b)
  451. #define PPC_CROR(d,a,b)  PPC_TYPE19(449,d,a,b)
  452. /* Indirect conditional branch */
  453. #define PPC_BCLR(bo,bi)  PPC_TYPE19(16,bo,bi,0)
  454. #define PPC_BCLRL(bo,bi) PPC_TYPE19(16,bo,bi,0)|PPC_LK
  455. #define PPC_BCCTR(bo,bi) PPC_TYPE19(528,bo,bi,0)
  456. #define PPC_BCCTRL(bo,bi) PPC_TYPE19(528,bo,bi,0)|PPC_LK
  457. #define PPC_BLR()            PPC_BCLR(20,31)
  458. #define PPC_BCTR()            PPC_BCCTR(20,31)
  459. /* Other */
  460. #define  PPC_RLWIMI(a,s,sh,mb,me) 
  461. PPC_MAJOR(20)|PPC_DEST(s)|PPC_SRCA(A)|PPC_SRCB(sh)|(mb)<<6|(me)<<1 
  462. #define  PPC_RLWIMI_(a,s,sh,mb,me) PPC_RLWIMI(a,s,sh,mb,me)|PPC_RC
  463. #define  PPC_RLWINM(a,s,sh,mb,me) 
  464. PPC_MAJOR(21)|PPC_DEST(s)|PPC_SRCA(A)|PPC_SRCB(sh)|(mb)<<6|(me)<<1 
  465. #define  PPC_RLWINM_(a,s,sh,mb,me) PPC_RLWINM(a,s,sh,mb,me)|PPC_RC
  466. #define  PPC_RLWNM(a,s,b,mb,me) 
  467.   PPC_MAJOR(23)|PPC_DEST(s)|PPC_SRCA(A)|PPC_SRCB(b)|(mb)<<6|(me)<<1 
  468. #define  PPC_RLWNM_(a,s,b,mb,me) PPC_RLWNM(a,s,b,mb,me)|PPC_RC
  469. #define PPC_SC() PPC_MAJOR(17)|2
  470. /* Major number = 63 Floating-point operations (not implemented for now) */
  471. /* Simplified Mnemonics */
  472. /* Fabricate immediate subtract out of add negative */
  473. #define PPC_SUBI(d,a,simm) PPC_ADDI(d,a,-(simm))
  474. #define PPC_SUBIS(d,a,simm) PPC_ADDIS(d,a,-(simm))
  475. #define PPC_SUBIC(d,a,simm) PPC_ADDIC(d,a,-(simm))
  476. #define PPC_SUBIC_(d,a,simm) PPC_ADDIC_(d,a,-(simm))
  477. /* Fabricate subtract out of subtract from */
  478. #define PPC_SUBC(d,b,a) PPC_SUBFC(d,a,b)
  479. #define PPC_SUBC_(d,b,a) PPC_SUBFC_(d,a,b)
  480. #define PPC_SUBCO(d,b,a) PPC_SUBFCO(d,a,b)
  481. #define PPC_SUBCO_(d,b,a) PPC_SUBFCO_(d,a,b)
  482. /* Messy compare bits omitted */
  483. /* Shift and rotate omitted */
  484. /* Branch coding omitted */
  485. #define PPC_CRSET(d) PPC_CREQV(d,d,d)
  486. #define PPC_CRCLR(d) PPC_CRXOR(d,d,d)
  487. #define PPC_CRMOVE(d,s) PPC_CROR(d,s,s)
  488. #define PPC_CRNOT(d,s) PPC_CRNOR(d,s,s)
  489. /* Trap menmonics omitted */
  490. /* Menmonics for user-accessible SPRs */
  491. #define PPC_MFXER(d)     PPC_MFSPR(d,1)
  492. #define PPC_MFLR(d)      PPC_MFSPR(d,8)
  493. #define PPC_MFCTR(d)     PPC_MFSPR(d,9)
  494. #define PPC_MTXER(s)     PPC_MTSPR(s,1)
  495. #define PPC_MTLR(s)      PPC_MTSPR(s,8)
  496. #define PPC_MTCTR(s)     PPC_MTSPR(s,9)
  497. /* Recommended mnemonics */
  498. #define PPC_NOP() PPC_ORI(0,0,0)
  499. #define PPC_LI(d,simm) PPC_ADDI(d,0,simm)
  500. #define PPC_LIS(d,simm) PPC_ADDIS(d,0,simm)
  501. #define PPC_LA(d,a,simm) PPC_ADDI(d,a,simm)
  502. #define PPC_MR(d,s) PPC_OR(d,s,s)
  503. #define PPC_NOT(d,s) PPC_NOR(d,s,s)
  504. #define PPC_MTCR(s) PPC_MTCRF(0xff,s)
  505. #endif /* PPCASM_H */
  506. /* 45678901234567890123456789012345678901234567890123456789012345678901234567 */