Back to index

lightning-sunbird  0.9+nobinonly
xptcstubs_asm_shle.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 # Script for generating the assembler code requried for virtual function
00003 # stubs for SuperH processor in little-endian mode (perhaps it works big-endian
00004 # too, I haven't checked). 
00005 
00006 f = open("xptcstubs_asm_shle.s", 'w')
00007 
00008 prefix = "_ZN14nsXPTCStubBase"
00009 minStub = 3
00010 maxStub = 250
00011 
00012 # Frequency with which we store the address of the function to branch to
00013 # If too high, we'll get errors from the assembler.
00014 jumpRepeat = 20
00015 jumpCount = 0
00016 labelIndex = 2
00017 
00018 f.write("""
00019        /* Automatically generated by xptcstubs_asm_shle.py */
00020        .text
00021        .little
00022        .section      .rodata
00023 
00024        .globl SharedStub
00025        .type  SharedStub, @function
00026 SharedStub:
00027        mov       r15, r1
00028        mov.l  r14,@-r15     
00029        sts.l  pr,@-r15
00030        mov           r15, r14
00031 
00032        /* Some parameters might have been passed in registers, so push them
00033         * all onto the stack, PrepareAndDispatch can then work out whats what
00034         * given method type information.
00035         */
00036        mov.l r7, @-r15
00037        mov.l r6, @-r15
00038        mov.l r5, @-r15
00039        mov      r15, r7            /* r7 = PrepareAndDispatch intRegParams param    */
00040 
00041        fmov.s fr10, @-r15
00042        fmov.s fr11, @-r15
00043        fmov.s fr8, @-r15
00044        fmov.s fr9, @-r15
00045        fmov.s fr6, @-r15
00046        fmov.s fr7, @-r15
00047        fmov.s fr4, @-r15
00048        fmov.s fr5, @-r15
00049        mov.l  r15, @-r15    /* PrepareAndDispatch floatRegParams param              */
00050 
00051        mov       r1, r6            /* r6 = PrepareAndDispatch data param                   */
00052 
00053        mov.l  .L1, r1
00054        jsr       @r1               /* Note, following instruction is executed first*/
00055        mov       r2, r5            /* r5 = PrepareAndDispatch methodIndex param     */
00056 
00057        mov           r14,r15
00058        lds.l  @r15+,pr
00059        mov.l  @r15+,r14
00060        rts
00061        nop
00062        .align 2
00063 .L1:
00064        .long  PrepareAndDispatch
00065 
00066        /* Stubs.  Each stub simply saves the method number in r1 and jumps
00067         * to SharedStub which does all the processing common to all stubs.
00068         */
00069 """)
00070 
00071 for i in range(minStub,maxStub):
00072        jumpCount = jumpCount + 1
00073        if  jumpCount == jumpRepeat:
00074               f.write( '\t.align 2\n')
00075               f.write( '.L' + str(labelIndex) + ':\n')
00076               f.write( '\t.long\tSharedStub\n\n')
00077               jumpCount = 0
00078               labelIndex = labelIndex + 1
00079        funcName = 'Stub' + str(i)
00080        name = prefix + str(len(funcName)) + funcName +  'Ev'
00081        f.write( '\t.globl ' + name + '\n')
00082        f.write( '\t.type ' + name + '  @function\n')
00083        f.write( '\t.align 1\n')
00084        f.write( name + ':\n')
00085        f.write( '\tmov.l\t.L' + str(labelIndex) + ', r1\n')
00086        f.write( '\tjmp\t@r1\n')
00087        f.write( '\tmov\t#'  + str(i) + ', r2            /* Executed before jmp */\n\n')
00088 
00089 f.write( '\t.align 2\n')
00090 f.write( '.L' + str(labelIndex) + ':\n')
00091 f.write( '\t.long\tSharedStub\n')