mips conversion started

This commit is contained in:
László Molnár
2006-07-05 18:32:52 +02:00
parent b38cd0a48d
commit ee0c87f7b1
5 changed files with 240 additions and 188 deletions
+8 -2
View File
@@ -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.app-asm5900 = perl -w $(srcdir)/src/arch/mips/mipsel.r3000/app-asm5900.pl
tc.mipsel.r3000-ps1.asm5900 = asm5900 tc.mipsel.r3000-ps1.asm5900 = asm5900
tc.mipsel.r3000-ps1.gas = asm5900
mipsel.r3000-ps1-%.h : $(srcdir)/src/mipsel.r3000-ps1.asm mipsel.r3000-ps1-%.h : $(srcdir)/src/mipsel.r3000-ps1.asm
# call gpp_inc to generate .d file # call gpp_inc to generate .d file
$(call tc,gpp_inc) --mode=c --MMD=$@ --MF=tmp/$T.tmp1.d $< -o /dev/null $(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,pp-asm) $(PP_FLAGS) $< -o tmp/$T.tmp1
$(call tc,app-asm5900) tmp/$T.tmp1 tmp/$T.tmp2 #$(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,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 $@ $(call tc,bin2h) --ident=$(IDENT_NAME) tmp/$T.bin $@
mipsel.r3000-ps1-boot.h: PP_FLAGS += -DCDBOOT mipsel.r3000-ps1-boot.h: PP_FLAGS += -DCDBOOT
+63 -52
View File
@@ -1,3 +1,4 @@
/*
; bits.ash -- bit access for decompression ; bits.ash -- bit access for decompression
; ;
; This file is part of the UCL data compression library. ; This file is part of the UCL data compression library.
@@ -24,14 +25,15 @@
; <markus@oberhumer.com> <jssg@users.sourceforge.net> ; <markus@oberhumer.com> <jssg@users.sourceforge.net>
; http://www.oberhumer.com/opensource/ucl/ ; http://www.oberhumer.com/opensource/ucl/
; ;
*/
#ifndef _MR3K_STD_CONF_ #ifndef _MR3K_STD_CONF_
#define _MR3K_STD_CONF_ #define _MR3K_STD_CONF_
;////////////////////////////////////// //////////////////////////////////////
;// register defines // register defines
;////////////////////////////////////// //////////////////////////////////////
#define src a0 #define src a0
#define dst a2 #define dst a2
@@ -48,40 +50,41 @@
#define m_pos v1 #define m_pos v1
;////////////////////////////////////// //////////////////////////////////////
;// optimized branch macros // optimized branch macros
;////////////////////////////////////// //////////////////////////////////////
beqz2gb MACRO reg,label,nrv_bb .macro beqz2gb reg,label,nrv_bb
IF (!small) && (nrv_bb == 8) IF (!small) && (\nrv_bb == 8)
beqz reg,label+4 beqz \reg,\label+4
andi var,bb,0x007F andi var,bb,0x007F
ELSE ELSE
beqz reg,label beqz \reg,\label
nop nop
ENDIF ENDIF
beqz2gb ENDM .endm
b2gb MACRO label,nrv_bb .macro b2gb label,nrv_bb
IF (!small) IF (!small)
b label+4 b \label+4
IF (nrv_bb == 8) IF (\nrv_bb == 8)
andi var,bb,0x007F andi var,bb,0x007F
ELSE ;(nrv_bb == 32) ELSE // ;(nrv_bb == 32)
addiu bc,-1 addiu bc,-1
ENDIF ENDIF
ELSE ELSE
b label b \label
nop nop
ENDIF ENDIF
b2gb ENDM .endm
;////////////////////////////////////// //////////////////////////////////////
;// ucl memcpy // ucl memcpy
;////////////////////////////////////// //////////////////////////////////////
uclmcpy MACRO retoffset,nrv_bb .macro uclmcpy retoffset,nrv_bb
local wordchk, prepbytecpy, bytecopy
# ifdef FAST # ifdef FAST
slti var,m_off,4 slti var,m_off,4
bnez var,prepbytecpy bnez var,prepbytecpy
@@ -98,7 +101,7 @@ wordchk:
addiu m_pos,4 addiu m_pos,4
bnez m_len,wordchk bnez m_len,wordchk
addiu dst,4 addiu dst,4
b2gb retoffset,nrv_bb b2gb \retoffset,\nrv_bb
prepbytecpy: prepbytecpy:
# else # else
addiu m_len,1 addiu m_len,1
@@ -111,82 +114,90 @@ bytecopy:
addiu m_pos,1 addiu m_pos,1
bnez m_len,bytecopy bnez m_len,bytecopy
addiu dst,1 addiu dst,1
b2gb retoffset,nrv_bb b2gb \retoffset,\nrv_bb
uclmcpy ENDM .endm
;////////////////////////////////////// //////////////////////////////////////
;// init decompressor // init decompressor
;////////////////////////////////////// //////////////////////////////////////
init MACRO nrv_bb .macro init nrv_bb
move bb,zero move bb,zero
IF (nrv_bb == 32) IF (\nrv_bb == 32)
move bc,bb move bc,bb
ENDIF ENDIF
li last_m_off,1 li last_m_off,1
move src_ilen,src 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) IF (!small)
addiu bc,-1 addiu bc,-1
ENDIF ENDIF
bgez bc,\@z bgez bc,.L1
srlv var,bb,bc srlv var,bb,bc
li bc,31 li bc,31
lwr bb,0(src_ilen) lwr bb,0(src_ilen)
lwl bb,3(src_ilen) lwl bb,3(src_ilen)
addiu src_ilen,4 addiu src_ilen,4
srlv var,bb,bc srlv var,bb,bc
\@z: .L1:
IF (small) IF (small)
jr ra jr ra
ENDIF ENDIF
andi var,0x0001 andi var,0x0001
gbit_le32 ENDM .endm
;////////////////////////////////////// //////////////////////////////////////
;// 8bit getbit macro // 8bit getbit macro
;////////////////////////////////////// //////////////////////////////////////
gbit_8 MACRO .macro gbit_8
local .L2
IF (!small) IF (!small)
andi var,bb,0x007F andi var,bb,0x007F
ENDIF ENDIF
bnez var,\@x bnez var,.L2
sll bb,1 sll bb,1
lbu var,0(src_ilen) lbu var,0(src_ilen)
addiu src_ilen,1 addiu src_ilen,1
sll var,1 sll var,1
addiu bb,var,1 addiu bb,var,1
\@x: .L2:
srl var,bb,8 srl var,bb,8
IF (small) IF (small)
jr ra jr ra
ENDIF ENDIF
andi var,0x0001 andi var,0x0001
gbit_8 ENDM .endm
//////////////////////////////////////
// getbit call macro for small version
//////////////////////////////////////
;////////////////////////////////////// .macro gbit_call subroutine,nrv_bb
;// getbit call macro for small version bal \subroutine
;////////////////////////////////////// IF (\nrv_bb == 8)
gbit_call MACRO subroutine,nrv_bb
bal subroutine
IF (nrv_bb == 8)
andi var,bb,0x007F andi var,bb,0x007F
ELSE ELSE
addiu bc,-1 addiu bc,-1
ENDIF ENDIF
gbit_call ENDM .endm
#endif //_MR3K_STD_CONF_ #endif //_MR3K_STD_CONF_
+62 -16
View File
@@ -1,3 +1,4 @@
/*
; macros.ash -- macros ; macros.ash -- macros
; ;
; This file is part of the UCL data compression library. ; This file is part of the UCL data compression library.
@@ -24,29 +25,74 @@
; <markus@oberhumer.com> <jssg@users.sourceforge.net> ; <markus@oberhumer.com> <jssg@users.sourceforge.net>
; http://www.oberhumer.com/opensource/ucl/ ; http://www.oberhumer.com/opensource/ucl/
; ;
*/
; Load Address macro .macro section name
.section \name
.endm
la MACRO reg,addr .set noat
lui reg,(addr >> 16)+((addr >> 15)&1) .altmacro
addiu reg,reg,((addr & 0FFFFh))
la ENDM
; 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 #define IF .if
IF (imm == -1) #define ELSE .else
addiu reg, zero, -1 #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 ELSE
IF ((imm>>16)!=0) IF ((\imm>>16)!=0)
lui reg,imm >> 16 lui \reg,\imm >> 16
ori reg,reg,(imm & 0FFFFh) ori \reg,\reg,(\imm & 0xFFFF)
ELSE ELSE
IF ((imm&0xffff)>0x8000) IF ((\imm&0xffff)>0x8000)
ori reg,zero,(imm & 0FFFFh) ori \reg,zero,(\imm & 0xFFFF)
ELSE ELSE
addiu reg,zero,(imm & 0FFFFh) addiu \reg,zero,(\imm & 0xFFFF)
ENDIF ENDIF
ENDIF ENDIF
ENDIF ENDIF
li ENDM .endm
#endif
.macro subiu reg, p1, p2
.if p2
addiu \reg, p1, -p2
.else
addiu \reg, -p1
.endif
.endm
@@ -1,3 +1,4 @@
/*
; n2e_d.ash -- NRV2E decompressor in Mips R3000 assembly ; n2e_d.ash -- NRV2E decompressor in Mips R3000 assembly
; ;
; This file is part of the UCL data compression library. ; This file is part of the UCL data compression library.
@@ -24,11 +25,13 @@
; <markus@oberhumer.com> <jssg@users.sourceforge.net> ; <markus@oberhumer.com> <jssg@users.sourceforge.net>
; http://www.oberhumer.com/opensource/ucl/ ; http://www.oberhumer.com/opensource/ucl/
; ;
*/
small = 0
#if (NRV_BB==8) #if (NRV_BB==8)
# ifdef SMALL # ifdef SMALL
IF (!small) IF (!small)
DEFINE small small = 1
ENDIF ENDIF
# define UCL_DECOMPRESSOR ucl_nrv2e_decompress_8_small # define UCL_DECOMPRESSOR ucl_nrv2e_decompress_8_small
# define GETBIT gbit_call gbit_sub,NRV_BB # define GETBIT gbit_call gbit_sub,NRV_BB
@@ -42,7 +45,7 @@
# define GETBIT gbit_call gbit_sub,NRV_BB # define GETBIT gbit_call gbit_sub,NRV_BB
# else # else
IF (small) IF (small)
UNDEF small small = 0
ENDIF ENDIF
# define UCL_DECOMPRESSOR ucl_nrv2e_decompress_32 # define UCL_DECOMPRESSOR ucl_nrv2e_decompress_32
# define GETBIT gbit_le32 # define GETBIT gbit_le32
@@ -51,20 +54,23 @@
# error "define NRV_BB first!" # error "define NRV_BB first!"
#endif #endif
#include "bits.ash" #include "bits.ash"
/*
; ------------- DECOMPRESSION ------------- ; ------------- DECOMPRESSION -------------
; On entry: ; On entry:
; a0 src pointer ; a0 src pointer
; a2 dest 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 init NRV_BB
n2e_18: n2e_18:
GETBIT GETBIT
beqz var,n2e_4C beqz var, n2e_4C
li m_off,1 li m_off,1
lbu var,0(src_ilen) lbu var,0(src_ilen)
addiu src_ilen,1 addiu src_ilen,1
@@ -139,7 +145,8 @@ gbit_sub:
#endif #endif
n2e_decomp_done: n2e_decomp_done:
UCL_DECOMPRESSOR ENDP .endm
UCL_DECOMPRESSOR
#undef UCL_DECOMPRESSOR #undef UCL_DECOMPRESSOR
#undef GETBIT #undef GETBIT
+94 -112
View File
@@ -1,3 +1,4 @@
/*
; l_ps1.asm -- ps1/exe program entry & decompressor ; l_ps1.asm -- ps1/exe program entry & decompressor
; ;
; This file is part of the UPX executable compressor. ; This file is part of the UPX executable compressor.
@@ -28,6 +29,7 @@
; Jens Medoch ; Jens Medoch
; <jssg@users.sourceforge.net> ; <jssg@users.sourceforge.net>
; ;
*/
#include "arch/mips/mipsel.r3000/macros.ash" #include "arch/mips/mipsel.r3000/macros.ash"
@@ -38,105 +40,103 @@
#define SZ_REG 4 #define SZ_REG 4
#if CDBOOT #if CDBOOT
regs MACRO _w, marker .macro regs _w, marker
_w a0,SZ_REG*0(sp) \_w a0,SZ_REG*0(sp)
_w a1,SZ_REG*1(sp) \_w a1,SZ_REG*1(sp)
_w a2,SZ_REG*2(sp) \_w a2,SZ_REG*2(sp)
_w a3,SZ_REG*3(sp) \_w a3,SZ_REG*3(sp)
_w v0,SZ_REG*4(sp) \_w v0,SZ_REG*4(sp)
_w v1,SZ_REG*5(sp) \_w v1,SZ_REG*5(sp)
IF (marker != 0) IF (\marker != 0)
DW marker DW \marker
ENDIF ENDIF
_w ra,SZ_REG*6(sp) \_w ra,SZ_REG*6(sp)
regs ENDM .endm
#define REG_SZ (7*SZ_REG) #define REG_SZ (7*SZ_REG)
#else //console #else //console
regs MACRO _w, marker .macro regs _w, marker
_w at,SZ_REG*0(sp) \_w at,SZ_REG*0(sp)
_w a0,SZ_REG*1(sp) \_w a0,SZ_REG*1(sp)
_w a1,SZ_REG*2(sp) \_w a1,SZ_REG*2(sp)
_w a2,SZ_REG*3(sp) \_w a2,SZ_REG*3(sp)
_w a3,SZ_REG*4(sp) \_w a3,SZ_REG*4(sp)
_w v0,SZ_REG*5(sp) \_w v0,SZ_REG*5(sp)
_w v1,SZ_REG*6(sp) \_w v1,SZ_REG*6(sp)
_w ra,SZ_REG*7(sp) \_w ra,SZ_REG*7(sp)
IF (marker != 0) IF (\marker != 0)
DW marker DW \marker
addu sp,at addu sp,at
ENDIF ENDIF
regs ENDM .endm
#define REG_SZ (8*SZ_REG) #define REG_SZ (8*SZ_REG)
#endif //CDBOOT #endif //CDBOOT
ORG 0
start:
#if CDBOOT #if CDBOOT
; ============= // =============
; ============= ENTRY POINT // ============= ENTRY POINT
; ============= // =============
; for cd-boot only // for cd-boot only
; __PS1START__ section PS1START
li t0,'PSVR' ; prepare to compute value li t0, PSVR // prepare to compute value
subu t0,s0,t0 ; get stored header offset in mem subu t0,s0,t0 // get stored header offset in mem
jr t0 jr t0
subiu sp,REG_SZ ; adjust stack subiu sp, REG_SZ // adjust stack
cutpoint: cutpoint:
; __PS1ENTRY__ section PS1ENTRY
regs sw,0 ; push used regs regs sw,0 // push used regs
li a0,'CPDO' ; load COMPDATA offset li a0, CPDO // load COMPDATA offset
; li a1,'CDSZ' ; compressed data size - disabled! // li a1,'CDSZ' // compressed data size - disabled!
; __PS1CONHL__ section PS1CONHL
li a2,'DECO' li a2, DECO
; __PS1CONHI__ section PS1CONHI
lui a2,HI('DECO') lui a2,HI( DECO)
#else //CONSOLE #else //CONSOLE
; ============= // =============
; ============= ENTRY POINT // ============= ENTRY POINT
; ============= // =============
; for console- / cd-boot // for console- / cd-boot
; __PS1START__ section PS1START
addiu at,zero,'LS' ; size of decomp. routine addiu at,zero, LS // size of decomp. routine
subu sp,at ; adjust the stack with this size subu sp,at // adjust the stack with this size
regs sw,0 ; push used regs regs sw,0 // push used regs
subiu a2,at,REG_SZ ; a2 = counter copyloop subiu a2,at,REG_SZ // a2 = counter copyloop
addiu a3,sp,REG_SZ ; get offset for decomp. routine addiu a3,sp,REG_SZ // get offset for decomp. routine
move a1,a3 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: copyloop:
lw at,0(a0) ; memcpy *a0 -> at -> *a1 lw at,0(a0) // memcpy *a0 -> at -> *a1
addiu a2,-4 addiu a2,-4
sw at,0(a1) sw at,0(a1)
addiu a0,4 addiu a0,4
bnez a2,copyloop bnez a2,copyloop
addiu a1,4 addiu a1,4
; __PS1PADCD__ section PS1PADCD
addiu a0,'PC' ; a0 = pointer compressed data addiu a0, PC // a0 = pointer compressed data
; __PS1CONHL__ section PS1CONHL
lui a2,HI('DECO') ; load DECOMPDATA HI offset lui a2,HI( DECO) // load DECOMPDATA HI offset
jr a3 jr a3
ori a2,LO('DECO') ; load DECOMPDATA LO offset ori a2,LO( DECO) // load DECOMPDATA LO offset
; __PS1CONHI__ section PS1CONHI
jr a3 jr a3
lui a2,HI('DECO') ; same for HI only !(offset&0xffff) lui a2,HI( DECO) // same for HI only !(offset&0xffff)
cutpoint: cutpoint:
; __PS1ENTRY__ section PS1ENTRY
#endif //CDBOOT #endif //CDBOOT
; ============= // =============
; ============= DECOMPRESSION // ============= DECOMPRESSION
; ============= // =============
#ifndef FAST #ifndef FAST
# define FAST # define FAST
@@ -157,11 +157,11 @@ cutpoint:
#endif #endif
#define NRV_BB 8 #define NRV_BB 8
; __PS1N2B08__ section PS1N2B08
#include "arch/mips/mipsel.r3000/nrv2b_d.ash" //#include "arch/mips/mipsel.r3000/nrv2b_d.ash"
; __PS1N2D08__ section PS1N2D08
#include "arch/mips/mipsel.r3000/nrv2d_d.ash" //#include "arch/mips/mipsel.r3000/nrv2d_d.ash"
; __PS1N2E08__ section PS1N2E08
#include "arch/mips/mipsel.r3000/nrv2e_d.ash" #include "arch/mips/mipsel.r3000/nrv2e_d.ash"
#ifdef NRV_BB #ifdef NRV_BB
@@ -169,28 +169,28 @@ cutpoint:
#endif #endif
#define NRV_BB 32 #define NRV_BB 32
; __PS1N2B32__ section PS1N2B32
#include "arch/mips/mipsel.r3000/nrv2b_d.ash" //#include "arch/mips/mipsel.r3000/nrv2b_d.ash"
; __PS1N2D32__ section PS1N2D32
#include "arch/mips/mipsel.r3000/nrv2d_d.ash" //#include "arch/mips/mipsel.r3000/nrv2d_d.ash"
; __PS1N2E32__ section PS1N2E32
#include "arch/mips/mipsel.r3000/nrv2e_d.ash" #include "arch/mips/mipsel.r3000/nrv2e_d.ash"
; ============= // =============
; __PS1MSETS__ section PS1MSETS
ori a0,zero,'SC' ; amount of removed zeros at eof ori a0,zero, SC // amount of removed zeros at eof
; __PS1MSETB__ section PS1MSETB
ori a0,zero,'SC' ; amount of removed zeros at eof ori a0,zero, SC // amount of removed zeros at eof
sll a0,3 ; (cd mode 2 data sector alignment) sll a0,3 // (cd mode 2 data sector alignment)
; __PS1MSETA__ section PS1MSETA
memset_aligned: memset_aligned:
sw zero,0(a2) sw zero,0(a2)
addiu a0,-1 addiu a0,-1
bnez a0,memset_aligned bnez a0,memset_aligned
addiu a2,4 addiu a2,4
; __PS1MSETU__ section PS1MSETU
memset_unaligned: memset_unaligned:
swl zero,3(a2) swl zero,3(a2)
swr zero,0(a2) swr zero,0(a2)
@@ -198,41 +198,23 @@ memset_unaligned:
bnez a0,memset_unaligned bnez a0,memset_unaligned
addiu a2,4 addiu a2,4
; ============= // =============
; __PS1EXITC__ section PS1EXITC
li t2,160 ; flushes li t2,160 // flushes
jalr ra,t2 ; instruction jalr ra,t2 // instruction
li t1,68 ; cache li t1,68 // cache
regs lw, 'JPEP' ; marker for the entry jump regs lw, JPEP // marker for the entry jump
; ============= // =============
; __PS1PAHDR__ #include "include/header2.ash"
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
; ============= // =============
#if !CDBOOT #if !CDBOOT
; __PS1SREGS__ section PS1SREGS
DW REG_SZ DW REG_SZ
#endif //CDBOOT #endif //CDBOOT
; __PS1EOASM__ // vi:ts=8:et:nowrap
eof:
; section .data
DW_UNALIGNED -1
DH_UNALIGNED eof
; vi:ts=8:et:nowrap