diff --git a/src/stub/Makefile b/src/stub/Makefile index 01608172..3ae7032e 100644 --- a/src/stub/Makefile +++ b/src/stub/Makefile @@ -637,13 +637,19 @@ mipsel.r3000-ps1-%.h : tc_list = mipsel.r3000-ps1 default tc.mipsel.r3000-ps1.app-asm5900 = perl -w $(srcdir)/src/arch/mips/mipsel.r3000/app-asm5900.pl tc.mipsel.r3000-ps1.asm5900 = asm5900 +tc.mipsel.r3000-ps1.gas = asm5900 mipsel.r3000-ps1-%.h : $(srcdir)/src/mipsel.r3000-ps1.asm # call gpp_inc to generate .d file $(call tc,gpp_inc) --mode=c --MMD=$@ --MF=tmp/$T.tmp1.d $< -o /dev/null $(call tc,pp-asm) $(PP_FLAGS) $< -o tmp/$T.tmp1 - $(call tc,app-asm5900) tmp/$T.tmp1 tmp/$T.tmp2 - $(call tc,asm5900) --nologo -q -ltmp/$T.bin.lst tmp/$T.tmp2 -otmp/$T.bin + #$(call tc,app-asm5900) tmp/$T.tmp1 tmp/$T.tmp2 + #$(call tc,asm5900) --nologo -q -ltmp/$T.bin.lst tmp/$T.tmp2 -otmp/$T.bin + + $(call tc,m-objcopy) --strip-unneeded tmp/$T.bin + $(call tc,m-objcopy) -R .text -R .data -R .bss tmp/$T.bin + $(call tc,m-objcopy) -R .note -R .comment tmp/$T.bin + $(call tc,m-objdump) -trwh tmp/$T.bin >> tmp/$T.bin $(call tc,bin2h) --ident=$(IDENT_NAME) tmp/$T.bin $@ mipsel.r3000-ps1-boot.h: PP_FLAGS += -DCDBOOT diff --git a/src/stub/src/arch/mips/mipsel.r3000/bits.ash b/src/stub/src/arch/mips/mipsel.r3000/bits.ash index 22a4b089..299eb2d7 100644 --- a/src/stub/src/arch/mips/mipsel.r3000/bits.ash +++ b/src/stub/src/arch/mips/mipsel.r3000/bits.ash @@ -1,3 +1,4 @@ +/* ; bits.ash -- bit access for decompression ; ; This file is part of the UCL data compression library. @@ -24,14 +25,15 @@ ; ; http://www.oberhumer.com/opensource/ucl/ ; +*/ #ifndef _MR3K_STD_CONF_ #define _MR3K_STD_CONF_ -;////////////////////////////////////// -;// register defines -;////////////////////////////////////// +////////////////////////////////////// +// register defines +////////////////////////////////////// #define src a0 #define dst a2 @@ -48,40 +50,41 @@ #define m_pos v1 -;////////////////////////////////////// -;// optimized branch macros -;////////////////////////////////////// +////////////////////////////////////// +// optimized branch macros +////////////////////////////////////// -beqz2gb MACRO reg,label,nrv_bb - IF (!small) && (nrv_bb == 8) - beqz reg,label+4 +.macro beqz2gb reg,label,nrv_bb + IF (!small) && (\nrv_bb == 8) + beqz \reg,\label+4 andi var,bb,0x007F ELSE - beqz reg,label + beqz \reg,\label nop ENDIF -beqz2gb ENDM +.endm -b2gb MACRO label,nrv_bb +.macro b2gb label,nrv_bb IF (!small) - b label+4 - IF (nrv_bb == 8) + b \label+4 + IF (\nrv_bb == 8) andi var,bb,0x007F - ELSE ;(nrv_bb == 32) + ELSE // ;(nrv_bb == 32) addiu bc,-1 ENDIF ELSE - b label + b \label nop ENDIF -b2gb ENDM +.endm -;////////////////////////////////////// -;// ucl memcpy -;////////////////////////////////////// +////////////////////////////////////// +// ucl memcpy +////////////////////////////////////// -uclmcpy MACRO retoffset,nrv_bb +.macro uclmcpy retoffset,nrv_bb + local wordchk, prepbytecpy, bytecopy # ifdef FAST slti var,m_off,4 bnez var,prepbytecpy @@ -98,7 +101,7 @@ wordchk: addiu m_pos,4 bnez m_len,wordchk addiu dst,4 - b2gb retoffset,nrv_bb + b2gb \retoffset,\nrv_bb prepbytecpy: # else addiu m_len,1 @@ -111,82 +114,90 @@ bytecopy: addiu m_pos,1 bnez m_len,bytecopy addiu dst,1 - b2gb retoffset,nrv_bb -uclmcpy ENDM + b2gb \retoffset,\nrv_bb +.endm -;////////////////////////////////////// -;// init decompressor -;////////////////////////////////////// +////////////////////////////////////// +// init decompressor +////////////////////////////////////// -init MACRO nrv_bb +.macro init nrv_bb move bb,zero - IF (nrv_bb == 32) + IF (\nrv_bb == 32) move bc,bb ENDIF li last_m_off,1 move src_ilen,src -init ENDM +.endm + +#ifndef LOCLABELHACK +# define LOCLABELHACK 0 +#else +# undef __LL +# +#endif -;////////////////////////////////////// -;// 32bit getbit macro -;////////////////////////////////////// +////////////////////////////////////// +// 32bit getbit macro +////////////////////////////////////// -gbit_le32 MACRO +.macro gbit_le32 +local .L1 IF (!small) addiu bc,-1 ENDIF - bgez bc,\@z + bgez bc,.L1 srlv var,bb,bc li bc,31 lwr bb,0(src_ilen) lwl bb,3(src_ilen) addiu src_ilen,4 srlv var,bb,bc -\@z: +.L1: IF (small) jr ra ENDIF andi var,0x0001 -gbit_le32 ENDM +.endm -;////////////////////////////////////// -;// 8bit getbit macro -;////////////////////////////////////// +////////////////////////////////////// +// 8bit getbit macro +////////////////////////////////////// -gbit_8 MACRO +.macro gbit_8 +local .L2 IF (!small) andi var,bb,0x007F ENDIF - bnez var,\@x + bnez var,.L2 sll bb,1 lbu var,0(src_ilen) addiu src_ilen,1 sll var,1 addiu bb,var,1 -\@x: +.L2: srl var,bb,8 IF (small) jr ra ENDIF andi var,0x0001 -gbit_8 ENDM +.endm +////////////////////////////////////// +// getbit call macro for small version +////////////////////////////////////// -;////////////////////////////////////// -;// getbit call macro for small version -;////////////////////////////////////// - -gbit_call MACRO subroutine,nrv_bb - bal subroutine - IF (nrv_bb == 8) +.macro gbit_call subroutine,nrv_bb + bal \subroutine + IF (\nrv_bb == 8) andi var,bb,0x007F ELSE addiu bc,-1 ENDIF -gbit_call ENDM +.endm #endif //_MR3K_STD_CONF_ diff --git a/src/stub/src/arch/mips/mipsel.r3000/macros.ash b/src/stub/src/arch/mips/mipsel.r3000/macros.ash index 65528389..fa9b06f5 100644 --- a/src/stub/src/arch/mips/mipsel.r3000/macros.ash +++ b/src/stub/src/arch/mips/mipsel.r3000/macros.ash @@ -1,3 +1,4 @@ +/* ; macros.ash -- macros ; ; This file is part of the UCL data compression library. @@ -24,29 +25,74 @@ ; ; http://www.oberhumer.com/opensource/ucl/ ; +*/ -; Load Address macro +.macro section name + .section \name +.endm -la MACRO reg,addr - lui reg,(addr >> 16)+((addr >> 15)&1) - addiu reg,reg,((addr & 0FFFFh)) -la ENDM +.set noat +.altmacro -; Load Immidiate macro +#define zero $0 +#define at $1 +#define v0 $2 +#define v1 $3 +#define a0 $4 +#define a1 $5 +#define a2 $6 +#define a3 $7 +#define t0 $8 +#define t1 $9 +#define t2 $10 +#define t3 $11 +#define t4 $12 +#define t5 $13 +#define t6 $14 +#define t7 $15 +#define sp $29 +#define ra $31 -li MACRO reg,imm -IF (imm == -1) - addiu reg, zero, -1 +#define IF .if +#define ELSE .else +#define ENDIF .endif + +#define DW .long +#define DB .byte + +// Load Address macro + +.macro la reg,addr + lui \reg,(\addr >> 16)+((\addr >> 15)&1) + addiu \reg,\reg,((\addr & 0xFFFF)) +.endm + +// Load Immidiate macro + +#if 0 +.macro li reg,imm +IF (\imm == -1) + addiu \reg, zero, -1 ELSE - IF ((imm>>16)!=0) - lui reg,imm >> 16 - ori reg,reg,(imm & 0FFFFh) + IF ((\imm>>16)!=0) + lui \reg,\imm >> 16 + ori \reg,\reg,(\imm & 0xFFFF) ELSE - IF ((imm&0xffff)>0x8000) - ori reg,zero,(imm & 0FFFFh) + IF ((\imm&0xffff)>0x8000) + ori \reg,zero,(\imm & 0xFFFF) ELSE - addiu reg,zero,(imm & 0FFFFh) + addiu \reg,zero,(\imm & 0xFFFF) ENDIF ENDIF ENDIF -li ENDM +.endm +#endif + +.macro subiu reg, p1, p2 + .if p2 + addiu \reg, p1, -p2 + .else + addiu \reg, -p1 + .endif +.endm + diff --git a/src/stub/src/arch/mips/mipsel.r3000/nrv2e_d.ash b/src/stub/src/arch/mips/mipsel.r3000/nrv2e_d.ash index 2f62cad7..db6cc617 100644 --- a/src/stub/src/arch/mips/mipsel.r3000/nrv2e_d.ash +++ b/src/stub/src/arch/mips/mipsel.r3000/nrv2e_d.ash @@ -1,3 +1,4 @@ +/* ; n2e_d.ash -- NRV2E decompressor in Mips R3000 assembly ; ; This file is part of the UCL data compression library. @@ -24,11 +25,13 @@ ; ; http://www.oberhumer.com/opensource/ucl/ ; +*/ +small = 0 #if (NRV_BB==8) # ifdef SMALL IF (!small) - DEFINE small + small = 1 ENDIF # define UCL_DECOMPRESSOR ucl_nrv2e_decompress_8_small # define GETBIT gbit_call gbit_sub,NRV_BB @@ -42,7 +45,7 @@ # define GETBIT gbit_call gbit_sub,NRV_BB # else IF (small) - UNDEF small + small = 0 ENDIF # define UCL_DECOMPRESSOR ucl_nrv2e_decompress_32 # define GETBIT gbit_le32 @@ -51,20 +54,23 @@ # error "define NRV_BB first!" #endif - #include "bits.ash" +/* ; ------------- DECOMPRESSION ------------- ; On entry: ; a0 src pointer ; a2 dest pointer +*/ -UCL_DECOMPRESSOR PROC +.macro UCL_DECOMPRESSOR + local n2e_18, n2e_4C, n2e_E4, n2e_124, n2e_150, n2e_184 + local n2e_1E0, n2e_244, gbit_sub, n2e_decomp_done init NRV_BB n2e_18: GETBIT - beqz var,n2e_4C + beqz var, n2e_4C li m_off,1 lbu var,0(src_ilen) addiu src_ilen,1 @@ -139,7 +145,8 @@ gbit_sub: #endif n2e_decomp_done: -UCL_DECOMPRESSOR ENDP +.endm + UCL_DECOMPRESSOR #undef UCL_DECOMPRESSOR #undef GETBIT diff --git a/src/stub/src/mipsel.r3000-ps1.asm b/src/stub/src/mipsel.r3000-ps1.asm index 0d60c9c9..29acd6fc 100644 --- a/src/stub/src/mipsel.r3000-ps1.asm +++ b/src/stub/src/mipsel.r3000-ps1.asm @@ -1,3 +1,4 @@ +/* ; l_ps1.asm -- ps1/exe program entry & decompressor ; ; This file is part of the UPX executable compressor. @@ -28,6 +29,7 @@ ; Jens Medoch ; ; +*/ #include "arch/mips/mipsel.r3000/macros.ash" @@ -38,105 +40,103 @@ #define SZ_REG 4 #if CDBOOT -regs MACRO _w, marker - _w a0,SZ_REG*0(sp) - _w a1,SZ_REG*1(sp) - _w a2,SZ_REG*2(sp) - _w a3,SZ_REG*3(sp) - _w v0,SZ_REG*4(sp) - _w v1,SZ_REG*5(sp) -IF (marker != 0) - DW marker +.macro regs _w, marker + \_w a0,SZ_REG*0(sp) + \_w a1,SZ_REG*1(sp) + \_w a2,SZ_REG*2(sp) + \_w a3,SZ_REG*3(sp) + \_w v0,SZ_REG*4(sp) + \_w v1,SZ_REG*5(sp) +IF (\marker != 0) + DW \marker ENDIF - _w ra,SZ_REG*6(sp) -regs ENDM + \_w ra,SZ_REG*6(sp) +.endm #define REG_SZ (7*SZ_REG) #else //console -regs MACRO _w, marker - _w at,SZ_REG*0(sp) - _w a0,SZ_REG*1(sp) - _w a1,SZ_REG*2(sp) - _w a2,SZ_REG*3(sp) - _w a3,SZ_REG*4(sp) - _w v0,SZ_REG*5(sp) - _w v1,SZ_REG*6(sp) - _w ra,SZ_REG*7(sp) -IF (marker != 0) - DW marker +.macro regs _w, marker + \_w at,SZ_REG*0(sp) + \_w a0,SZ_REG*1(sp) + \_w a1,SZ_REG*2(sp) + \_w a2,SZ_REG*3(sp) + \_w a3,SZ_REG*4(sp) + \_w v0,SZ_REG*5(sp) + \_w v1,SZ_REG*6(sp) + \_w ra,SZ_REG*7(sp) +IF (\marker != 0) + DW \marker addu sp,at ENDIF -regs ENDM +.endm #define REG_SZ (8*SZ_REG) #endif //CDBOOT - ORG 0 -start: - #if CDBOOT -; ============= -; ============= ENTRY POINT -; ============= -; for cd-boot only +// ============= +// ============= ENTRY POINT +// ============= +// for cd-boot only -; __PS1START__ - li t0,'PSVR' ; prepare to compute value - subu t0,s0,t0 ; get stored header offset in mem +section PS1START + li t0, PSVR // prepare to compute value + subu t0,s0,t0 // get stored header offset in mem jr t0 - subiu sp,REG_SZ ; adjust stack + subiu sp, REG_SZ // adjust stack cutpoint: -; __PS1ENTRY__ - regs sw,0 ; push used regs - li a0,'CPDO' ; load COMPDATA offset -; li a1,'CDSZ' ; compressed data size - disabled! -; __PS1CONHL__ - li a2,'DECO' -; __PS1CONHI__ - lui a2,HI('DECO') +section PS1ENTRY + regs sw,0 // push used regs + li a0, CPDO // load COMPDATA offset +// li a1,'CDSZ' // compressed data size - disabled! +section PS1CONHL + li a2, DECO +section PS1CONHI + lui a2,HI( DECO) #else //CONSOLE -; ============= -; ============= ENTRY POINT -; ============= -; for console- / cd-boot +// ============= +// ============= ENTRY POINT +// ============= +// for console- / cd-boot -; __PS1START__ - addiu at,zero,'LS' ; size of decomp. routine - subu sp,at ; adjust the stack with this size - regs sw,0 ; push used regs - subiu a2,at,REG_SZ ; a2 = counter copyloop - addiu a3,sp,REG_SZ ; get offset for decomp. routine +section PS1START + addiu at,zero, LS // size of decomp. routine + subu sp,at // adjust the stack with this size + regs sw,0 // push used regs + subiu a2,at,REG_SZ // a2 = counter copyloop + addiu a3,sp,REG_SZ // get offset for decomp. routine move a1,a3 - li a0,'DCRT' ; load decompression routine's offset + lui a0, DCRT // load decompression routine's offset +// ori a0, LO(DCRT) // load decompression routine's offset copyloop: - lw at,0(a0) ; memcpy *a0 -> at -> *a1 + lw at,0(a0) // memcpy *a0 -> at -> *a1 addiu a2,-4 sw at,0(a1) addiu a0,4 bnez a2,copyloop addiu a1,4 -; __PS1PADCD__ - addiu a0,'PC' ; a0 = pointer compressed data -; __PS1CONHL__ - lui a2,HI('DECO') ; load DECOMPDATA HI offset +section PS1PADCD + addiu a0, PC // a0 = pointer compressed data +section PS1CONHL + lui a2,HI( DECO) // load DECOMPDATA HI offset jr a3 - ori a2,LO('DECO') ; load DECOMPDATA LO offset -; __PS1CONHI__ + ori a2,LO( DECO) // load DECOMPDATA LO offset +section PS1CONHI jr a3 - lui a2,HI('DECO') ; same for HI only !(offset&0xffff) + lui a2,HI( DECO) // same for HI only !(offset&0xffff) cutpoint: -; __PS1ENTRY__ +section PS1ENTRY #endif //CDBOOT -; ============= -; ============= DECOMPRESSION -; ============= +// ============= +// ============= DECOMPRESSION +// ============= #ifndef FAST # define FAST @@ -157,11 +157,11 @@ cutpoint: #endif #define NRV_BB 8 -; __PS1N2B08__ -#include "arch/mips/mipsel.r3000/nrv2b_d.ash" -; __PS1N2D08__ -#include "arch/mips/mipsel.r3000/nrv2d_d.ash" -; __PS1N2E08__ +section PS1N2B08 +//#include "arch/mips/mipsel.r3000/nrv2b_d.ash" +section PS1N2D08 +//#include "arch/mips/mipsel.r3000/nrv2d_d.ash" +section PS1N2E08 #include "arch/mips/mipsel.r3000/nrv2e_d.ash" #ifdef NRV_BB @@ -169,28 +169,28 @@ cutpoint: #endif #define NRV_BB 32 -; __PS1N2B32__ -#include "arch/mips/mipsel.r3000/nrv2b_d.ash" -; __PS1N2D32__ -#include "arch/mips/mipsel.r3000/nrv2d_d.ash" -; __PS1N2E32__ +section PS1N2B32 +//#include "arch/mips/mipsel.r3000/nrv2b_d.ash" +section PS1N2D32 +//#include "arch/mips/mipsel.r3000/nrv2d_d.ash" +section PS1N2E32 #include "arch/mips/mipsel.r3000/nrv2e_d.ash" -; ============= +// ============= -; __PS1MSETS__ - ori a0,zero,'SC' ; amount of removed zeros at eof -; __PS1MSETB__ - ori a0,zero,'SC' ; amount of removed zeros at eof - sll a0,3 ; (cd mode 2 data sector alignment) -; __PS1MSETA__ +section PS1MSETS + ori a0,zero, SC // amount of removed zeros at eof +section PS1MSETB + ori a0,zero, SC // amount of removed zeros at eof + sll a0,3 // (cd mode 2 data sector alignment) +section PS1MSETA memset_aligned: sw zero,0(a2) addiu a0,-1 bnez a0,memset_aligned addiu a2,4 -; __PS1MSETU__ +section PS1MSETU memset_unaligned: swl zero,3(a2) swr zero,0(a2) @@ -198,41 +198,23 @@ memset_unaligned: bnez a0,memset_unaligned addiu a2,4 -; ============= +// ============= -; __PS1EXITC__ - li t2,160 ; flushes - jalr ra,t2 ; instruction - li t1,68 ; cache - regs lw, 'JPEP' ; marker for the entry jump +section PS1EXITC + li t2,160 // flushes + jalr ra,t2 // instruction + li t1,68 // cache + regs lw, JPEP // marker for the entry jump -; ============= +// ============= -; __PS1PAHDR__ - DB 85,80,88,33 ; 0 UPX_MAGIC_LE32 - ; another magic for PackHeader::putPackHeader - DB 161,216,208,213 ; UPX_MAGIC2_LE32 - DW 0 ; 8 uncompressed adler32 - DW 0 ; 12 compressed adler32 - DW 0 ; 16 uncompressed len - DW 0 ; 20 compressed len - DW 0 ; 24 original file size - DB 0 ; 28 filter id - DB 0 ; 29 filter cto - DB 0 ; unsused - DB 45 ; 31 header checksum +#include "include/header2.ash" -; ============= +// ============= #if !CDBOOT -; __PS1SREGS__ +section PS1SREGS DW REG_SZ #endif //CDBOOT -; __PS1EOASM__ -eof: -; section .data - DW_UNALIGNED -1 - DH_UNALIGNED eof - -; vi:ts=8:et:nowrap +// vi:ts=8:et:nowrap