mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 21:22:39 -05:00
rbutil: Merge rbutil with utils folder.
rbutil uses several components from the utils folder, and can be considered part of utils too. Having it in a separate folder is an arbitrary split that doesn't help anymore these days, so merge them. This also allows other utils to easily use libtools.make without the need to navigate to a different folder. Change-Id: I3fc2f4de19e3e776553efb5dea5f779dfec0dc21
This commit is contained in:
parent
6c6f0757d7
commit
c876d3bbef
494 changed files with 13 additions and 13 deletions
3
utils/mkamsboot/dualboot/.gitignore
vendored
Normal file
3
utils/mkamsboot/dualboot/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
*.arm-bin
|
||||
*.o
|
||||
bin2c
|
||||
61
utils/mkamsboot/dualboot/Makefile
Normal file
61
utils/mkamsboot/dualboot/Makefile
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
CC=gcc
|
||||
CROSS_PREFIX?=arm-elf-eabi
|
||||
# Edit the following variables (plus copy/paste another set of rules) when
|
||||
# adding a new target. mkamsboot.c also needs to be edited to refer to these
|
||||
# new images.
|
||||
|
||||
BOOTOBJS = nrv2e_d8.o dualboot_clip.o dualboot_e200v2.o dualboot_c200v2.o dualboot_m200v4.o dualboot_fuze.o dualboot_clipv2.o dualboot_clipplus.o dualboot_fuzev2.o dualboot_clipzip.o
|
||||
BOOTBINS = nrv2e_d8.arm-bin dualboot_clip.arm-bin dualboot_e200v2.arm-bin dualboot_c200v2.arm-bin dualboot_m200v4.arm-bin dualboot_fuze.arm-bin dualboot_clipv2.arm-bin dualboot_clipplus.arm-bin dualboot_fuzev2.arm-bin dualboot_clipzip.arm-bin
|
||||
|
||||
all: ../dualboot.h ../dualboot.c
|
||||
|
||||
# Dualboot bootloaders
|
||||
|
||||
dualboot_clip.o: dualboot.S
|
||||
$(CROSS_PREFIX)-$(CC) -DSANSA_CLIP -c -o dualboot_clip.o dualboot.S
|
||||
|
||||
dualboot_fuze.o: dualboot.S
|
||||
$(CROSS_PREFIX)-$(CC) -DSANSA_FUZE -c -o dualboot_fuze.o dualboot.S
|
||||
|
||||
dualboot_e200v2.o: dualboot.S
|
||||
$(CROSS_PREFIX)-$(CC) -DSANSA_E200V2 -c -o dualboot_e200v2.o dualboot.S
|
||||
|
||||
dualboot_m200v4.o: dualboot.S
|
||||
$(CROSS_PREFIX)-$(CC) -DSANSA_M200V4 -c -o dualboot_m200v4.o dualboot.S
|
||||
|
||||
dualboot_c200v2.o: dualboot.S
|
||||
$(CROSS_PREFIX)-$(CC) -DSANSA_C200V2 -c -o dualboot_c200v2.o dualboot.S
|
||||
|
||||
dualboot_clipv2.o: dualboot.S
|
||||
$(CROSS_PREFIX)-$(CC) -DSANSA_CLIPV2 -c -o dualboot_clipv2.o dualboot.S
|
||||
|
||||
dualboot_clipplus.o: dualboot.S
|
||||
$(CROSS_PREFIX)-$(CC) -DSANSA_CLIPPLUS -c -o dualboot_clipplus.o dualboot.S
|
||||
|
||||
dualboot_fuzev2.o: dualboot.S
|
||||
$(CROSS_PREFIX)-$(CC) -DSANSA_FUZEV2 -c -o dualboot_fuzev2.o dualboot.S
|
||||
|
||||
dualboot_clipzip.o: dualboot.S
|
||||
$(CROSS_PREFIX)-$(CC) -DSANSA_CLIPZIP -c -o dualboot_clipzip.o dualboot.S
|
||||
|
||||
# Rules for the ucl unpack function
|
||||
nrv2e_d8.o: nrv2e_d8.S
|
||||
$(CROSS_PREFIX)-$(CC) -DPURE_THUMB -c -o nrv2e_d8.o nrv2e_d8.S
|
||||
|
||||
# Rules for the ARM code embedded in mkamsboot - assemble, link, then extract
|
||||
# the binary code and finally convert to .h for building in mkamsboot
|
||||
|
||||
%.arm-elf: %.o
|
||||
$(CROSS_PREFIX)-ld -e 0 -Ttext=0 -o $@ $<
|
||||
|
||||
%.arm-bin: %.arm-elf
|
||||
$(CROSS_PREFIX)-objcopy -O binary $< $@
|
||||
|
||||
../dualboot.c ../dualboot.h: $(BOOTBINS) bin2c
|
||||
./bin2c ../dualboot $(BOOTBINS)
|
||||
|
||||
bin2c: bin2c.c
|
||||
$(CC) -o bin2c bin2c.c
|
||||
|
||||
clean:
|
||||
rm -f *~ bin2c $(BOOTBINS) $(BOOTOBJS)
|
||||
140
utils/mkamsboot/dualboot/bin2c.c
Normal file
140
utils/mkamsboot/dualboot/bin2c.c
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2007 Dave Chapman
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
static off_t filesize(int fd)
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
fstat(fd,&buf);
|
||||
return buf.st_size;
|
||||
}
|
||||
|
||||
static void write_cfile(const unsigned char* buf, off_t len, FILE* fp, const char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
fprintf(fp,"unsigned char %s[%ld] = {",name,len);
|
||||
|
||||
for (i=0;i<len;i++) {
|
||||
if ((i % 16) == 0) {
|
||||
fprintf(fp,"\n ");
|
||||
}
|
||||
if (i == (len-1)) {
|
||||
fprintf(fp,"0x%02x",buf[i]);
|
||||
} else if ((i % 16) == 15) {
|
||||
fprintf(fp,"0x%02x,",buf[i]);
|
||||
} else {
|
||||
fprintf(fp,"0x%02x, ",buf[i]);
|
||||
}
|
||||
}
|
||||
fprintf(fp,"\n};\n");
|
||||
}
|
||||
|
||||
int main (int argc, char* argv[])
|
||||
{
|
||||
char* cname;
|
||||
int i;
|
||||
FILE *cfile, *hfile;
|
||||
char cfilename[256], hfilename[256];
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf(stderr,"Usage: bin2c cname file1 [file2 [file3 ...]]\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
cname=argv[1];
|
||||
|
||||
snprintf(cfilename,256,"%s.c",cname);
|
||||
cfile = fopen(cfilename,"w+");
|
||||
if (cfile == NULL) {
|
||||
fprintf(stderr,"Couldn't open %s\n",cfilename);
|
||||
return 2;
|
||||
}
|
||||
|
||||
snprintf(hfilename,256,"%s.h",cname);
|
||||
hfile = fopen(hfilename,"w+");
|
||||
if (hfile == NULL) {
|
||||
fprintf(stderr,"Couldn't open %s\n",hfilename);
|
||||
fclose(cfile);
|
||||
return 3;
|
||||
}
|
||||
|
||||
fprintf(cfile,"/* Generated by bin2c */\n\n");
|
||||
fprintf(cfile,"#include \"%s\"\n\n", basename(hfilename));
|
||||
fprintf(hfile,"/* Generated by bin2c */\n\n");
|
||||
|
||||
for(i=0; i < argc - 2; i++) {
|
||||
unsigned char* buf;
|
||||
off_t len;
|
||||
off_t orig_len;
|
||||
char *ext;
|
||||
char *array = argv[2+i];
|
||||
|
||||
int fd = open(array,O_RDONLY|O_BINARY);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr,"Can not open %s\n",argv[2+i]);
|
||||
fclose(cfile);
|
||||
fclose(hfile);
|
||||
return 4;
|
||||
}
|
||||
|
||||
orig_len = filesize(fd);
|
||||
/* pad to 32bit */
|
||||
len = (orig_len + 3) & ~3;
|
||||
|
||||
buf = malloc(len);
|
||||
if (read(fd,buf,orig_len) < orig_len) {
|
||||
fprintf(stderr,"Short read, aborting\n");
|
||||
return 5;
|
||||
}
|
||||
|
||||
/* pad to 32bit with zeros */
|
||||
if (len > orig_len)
|
||||
memset(buf+orig_len, 0, len-orig_len);
|
||||
|
||||
/* remove file extension */
|
||||
ext = strchr (array, '.');
|
||||
if (ext != NULL)
|
||||
*ext = '\0';
|
||||
write_cfile (buf, len, cfile, array);
|
||||
fprintf(hfile,"extern unsigned char %s[%ld];\n",array,len);
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
fclose(cfile);
|
||||
fclose(hfile);
|
||||
|
||||
return 0;
|
||||
}
|
||||
307
utils/mkamsboot/dualboot/dualboot.S
Normal file
307
utils/mkamsboot/dualboot/dualboot.S
Normal file
|
|
@ -0,0 +1,307 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2008 Rafaël Carré
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
.text
|
||||
|
||||
/* AS3525 hardware registers */
|
||||
.set GPIOA, 0xC80B0000
|
||||
.set GPIOB, 0xC80C0000
|
||||
.set GPIOC, 0xC80D0000
|
||||
.set GPIOD, 0xC80E0000
|
||||
.set CGU_PROC, 0xC80F0010
|
||||
.set CGU_PERI, 0xC80F0014
|
||||
.set CGU_DBOP, 0xC80F0038
|
||||
.set CCU_IO, 0xC810000C
|
||||
.set DBOP, 0xC8120000
|
||||
.set I2C_BASE, 0xC8070000
|
||||
.set I2C_DATA, 0x00
|
||||
.set I2C_SLAD0, 0x04
|
||||
.set I2C_CNTRL, 0x0c
|
||||
.set I2C_DACNT, 0x10
|
||||
.set I2C_CPSR0, 0x1c
|
||||
.set I2C_CPSR1, 0x20
|
||||
.set I2C_IMR, 0x24
|
||||
.set I2C_SR, 0x30
|
||||
.set I2C_SADDR, 0x44
|
||||
.set AS3514_I2C_ADDR, 0x46
|
||||
.set AS3514_IRQ_ENRD0, 0x25
|
||||
.set PCLK, 24000000
|
||||
.set I2C_CLK, 400000
|
||||
.set I2C_PRESCALER, ((PCLK + I2C_CLK -1) / I2C_CLK)
|
||||
.set I2C_PRESCALER_LOW, (I2C_PRESCALER & 0xff)
|
||||
.set I2C_PRESCALER_HIGH, (I2C_PRESCALER >> 8)
|
||||
#if I2C_PRESCALER_HIGH > 3
|
||||
#error i2c prescaler too big!
|
||||
#endif
|
||||
|
||||
b start @ skip our data
|
||||
|
||||
/* These values are filled in by mkamsboot - don't move them from offset 0x4 */
|
||||
|
||||
uclunpack_end: .word 0 /* End of the ucl_unpack function */
|
||||
uclunpack_size: .word 0 /* Size in bytes of the ucl_unpack function */
|
||||
|
||||
ucl_of_end: .word 0 /* End of the ucl-compressed OF image */
|
||||
ucl_of_size: .word 0 /* Size in bytes of the compressed OF image */
|
||||
|
||||
ucl_rb_end: .word 0 /* End of the ucl-compressed RB image */
|
||||
ucl_rb_size: .word 0 /* Size in bytes of the compressed RB image */
|
||||
|
||||
ucl_dest: .word 0 /* End of our destination buffer (end of memory) */
|
||||
|
||||
start:
|
||||
/* First copy the UCL unpack function to the end of RAM */
|
||||
ldr r0, uclunpack_end /* Source */
|
||||
ldr r1, uclunpack_size /* Source length */
|
||||
sub r2, r0, r1 /* Source start - 1*/
|
||||
|
||||
ldr r3, ucl_dest /* Destination end */
|
||||
|
||||
uclcopy:
|
||||
ldrb r4, [r0], #-1
|
||||
strb r4, [r3], #-1
|
||||
cmp r2, r0
|
||||
bne uclcopy
|
||||
|
||||
/* store the new destination buffer */
|
||||
str r3, ucl_dest
|
||||
|
||||
/* enable gpio clock */
|
||||
ldr r0, =CGU_PERI
|
||||
ldr r1, [r0]
|
||||
orr r1, r1, #(1<<16)
|
||||
str r1, [r0]
|
||||
|
||||
/* Here are model specific tests for dual boot (test left button) */
|
||||
|
||||
#ifdef SANSA_CLIP
|
||||
.set row, (1<<5) /* enable output on C5 */
|
||||
.set col, (1<<0) /* read keyscan column B0 */
|
||||
|
||||
ldr r0, =GPIOC
|
||||
mov r1, #row
|
||||
str r1, [r0, #0x400]
|
||||
str r1, [r0, #(4*row)]
|
||||
|
||||
ldr r0, =GPIOB
|
||||
mov r1, #0
|
||||
str r1, [r0, #0x400]
|
||||
ldr r1, [r0, #(4*col)]
|
||||
|
||||
cmp r1, #0
|
||||
bne boot_of
|
||||
#elif defined(SANSA_CLIPV2)
|
||||
.set row, (1<<4) /* enable output on D4 */
|
||||
.set col, (1<<0) /* read keyscan column D0 */
|
||||
|
||||
ldr r0, =CCU_IO
|
||||
ldr r1, [r0]
|
||||
bic r1, r1, #(3<<2) @ XPD works as general purpose IO
|
||||
str r1, [r0]
|
||||
|
||||
ldr r0, =GPIOD
|
||||
mov r1, #((1<<5)|(1<<4)|(1<<3)) /* all rows as output */
|
||||
str r1, [r0, #0x400]
|
||||
|
||||
/* all rows high */
|
||||
mov r1, #(1<<3)
|
||||
str r1, [r0, #(4*(1<<3))]
|
||||
mov r1, #(1<<4)
|
||||
str r1, [r0, #(4*(1<<4))]
|
||||
mov r1, #(1<<5)
|
||||
str r1, [r0, #(4*(1<<5))]
|
||||
|
||||
mov r1, #0 /* button row low */
|
||||
str r1, [r0, #(4*row)]
|
||||
|
||||
mov r1, #5 /* small delay */
|
||||
1: subs r1, r1, #1
|
||||
bne 1b
|
||||
|
||||
ldr r1, [r0, #(4*col)]
|
||||
|
||||
cmp r1, #0
|
||||
beq boot_of
|
||||
#elif defined(SANSA_E200V2) || defined(SANSA_FUZE)
|
||||
ldr r0, =GPIOC
|
||||
mov r1, #0
|
||||
str r1, [r0, #0x400]
|
||||
ldr r1, [r0, #0x20] /* read pin C3 */
|
||||
|
||||
cmp r1, #0 /* C3 = #0 means button pressed */
|
||||
beq boot_of
|
||||
|
||||
#elif defined(SANSA_FUZEV2)
|
||||
ldr r0, =GPIOC
|
||||
mov r1, #0
|
||||
str r1, [r0, #0x400]
|
||||
ldr r1, [r0, #0x20] /* read pin C3 */
|
||||
|
||||
cmp r1, #0 /* C3 != #0 means button pressed */
|
||||
bne boot_of
|
||||
|
||||
#elif defined(SANSA_CLIPPLUS)
|
||||
@ read pins
|
||||
ldr r0, =GPIOC
|
||||
ldr r1, [r0, #4*(1<<3)] @ read pin C3 "|<<"
|
||||
|
||||
ldr r0, =GPIOA
|
||||
ldr r2, [r0, #4*(1<<1)] @ read pin A1 "Home"
|
||||
|
||||
orr r2, r2, r1 @ c3 || A1
|
||||
|
||||
cmp r2, #0 @ test input from pins
|
||||
bne boot_of @ branch directly to OF if either pin high
|
||||
|
||||
#elif defined(SANSA_CLIPZIP)
|
||||
@ read pins
|
||||
ldr r0, =GPIOA
|
||||
ldr r1, [r0, #4*(1<<6)] @ read GPIO A6 "vol-"
|
||||
|
||||
cmp r1, #0 @ test input from pins
|
||||
bne boot_of @ branch directly to OF if either pin high
|
||||
|
||||
ldr r0, =GPIOC
|
||||
|
||||
ldr r1, [r0, #0x400]
|
||||
orr r1, r1, #((1<<1)|(1<<2)) @ output
|
||||
bic r1, r1, #(1<<5) @ input
|
||||
str r1, [r0, #0x400]
|
||||
|
||||
mov r1, #0
|
||||
str r1, [r0, #4*(1<<1)] @ zero C1
|
||||
mov r1, #(1<<2)
|
||||
str r1, [r0, #4*(1<<2)] @ set C2
|
||||
|
||||
mov r1, #50 /* small delay */
|
||||
1: subs r1, r1, #1
|
||||
bne 1b
|
||||
|
||||
ldr r1, [r0, #4*(1<<5)] @ read C5 = left
|
||||
|
||||
cmp r1, #0
|
||||
bne boot_of
|
||||
|
||||
#elif defined(SANSA_C200V2)
|
||||
.set BUTTON_LEFT, (1<< 2)
|
||||
.set BUTTON_DOWN, (1<< 3)
|
||||
.set BUTTON_SELECT, (1<< 4)
|
||||
.set BUTTON_UP, (1<< 5)
|
||||
.set BUTTON_RIGHT, (1<< 6)
|
||||
.set BUTTON_HOLD, (1<<12)
|
||||
|
||||
ldr r0, =CGU_DBOP
|
||||
mov r1, #(1<<3) @ DBOP freq = PCLK, clock enabled
|
||||
str r1, [r0]
|
||||
|
||||
@ AFSEL needs to be set for this to work
|
||||
ldr r2, =GPIOB
|
||||
mov r1, #0xc
|
||||
str r1, [r2, #0x420] @ GPIOB_AFSEL
|
||||
ldr r2, =GPIOC
|
||||
mov r1, #0xff
|
||||
str r1, [r2, #0x420] @ GPIOC_AFSEL
|
||||
|
||||
ldr r0, =DBOP
|
||||
@ TIMPOL doesn't matter here since we don't need
|
||||
@ the control signals.
|
||||
|
||||
@ 16 bit data width
|
||||
@ enable write
|
||||
@ tri-state output
|
||||
ldr r1, =0x00091000
|
||||
str r1, [r0, #8] @ DBOP_CTRL
|
||||
|
||||
ldr r1, =0xf0ff @ precharge
|
||||
str r1, [r0, #0x10] @ DBOP_DOUT
|
||||
|
||||
2: ldr r1, [r0, #0xc] @ DOBP_STAT
|
||||
ands r1, r1, #(1<<10)
|
||||
beq 2b @ make sure fifo is empty
|
||||
|
||||
@ 16 bit data width
|
||||
@ start read
|
||||
@ tri-state output
|
||||
@ strobe time 31
|
||||
ldr r1, =0x0008901f
|
||||
str r1, [r0, #8] @ DBOP_CTRL
|
||||
|
||||
3: ldr r1, [r0, #0xc] @ DOBP_STAT
|
||||
ands r1, r1, #(1<<16)
|
||||
beq 3b @ wait for valid data
|
||||
|
||||
ldrh r1, [r0, #0x14] @ DBOP_DIN
|
||||
|
||||
tst r1, #BUTTON_LEFT @ boot of?
|
||||
beq boot_of
|
||||
#elif defined(SANSA_M200V4)
|
||||
.set row, (1<<5) /* enable output on A5 */
|
||||
.set col, (1<<0) /* read keyscan column A0 */
|
||||
|
||||
ldr r0, =GPIOA
|
||||
mov r1, #row
|
||||
str r1, [r0, #0x400]
|
||||
str r1, [r0, #(4*row)]
|
||||
|
||||
ldr r2, [r0, #(4*col)]
|
||||
|
||||
/* check value read (1 means button pressed) */
|
||||
cmp r2, #0
|
||||
bne boot_of
|
||||
#else
|
||||
#error No target-specific key check defined!
|
||||
#endif
|
||||
|
||||
/* The dualboot button was not held, so we boot rockbox */
|
||||
ldr r0, ucl_rb_end /* Address of compressed image */
|
||||
ldr r1, ucl_rb_size /* Compressed size */
|
||||
b decompress
|
||||
|
||||
boot_of:
|
||||
ldr r0, ucl_of_end /* Address of compressed image */
|
||||
ldr r1, ucl_of_size /* Compressed size */
|
||||
|
||||
|
||||
decompress:
|
||||
/* At this point: */
|
||||
/* r0 = source_end for UCL image to copy */
|
||||
/* r1 = size of UCL image to copy */
|
||||
|
||||
ldr r3, ucl_dest
|
||||
add r5, r3, #2 /* r5 is entry point of copy of uclunpack */
|
||||
/* function, plus one (for thumb mode */
|
||||
|
||||
sub r4, r3, r1 /* r4 := destination_start - 1 */
|
||||
|
||||
fw_copy:
|
||||
ldrb r2, [r0], #-1
|
||||
strb r2, [r3], #-1
|
||||
cmp r3, r4 /* Stop when we reached dest_start-1 */
|
||||
bne fw_copy
|
||||
|
||||
/* Call the ucl decompress function, which will branch to 0x0 */
|
||||
/* on completion */
|
||||
add r0, r3, #1 /* r0 := Start of compressed image */
|
||||
/* r1 already contains compressed size */
|
||||
mov r2, #0 /* r2 := Destination for unpacking */
|
||||
bx r5 /* Branch to uclunpack, switching to thumb */
|
||||
|
||||
/* never reached : uclunpack will branch to the reset vector (0x0) */
|
||||
198
utils/mkamsboot/dualboot/nrv2e_d8.S
Normal file
198
utils/mkamsboot/dualboot/nrv2e_d8.S
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
/* arm_nrv2e_d8.S -- ARM decompressor for NRV2E
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996-2008 Laszlo Molnar
|
||||
Copyright (C) 2000-2008 John F. Reiser
|
||||
All Rights Reserved.
|
||||
|
||||
UPX and the UCL library are free software; you can redistribute them
|
||||
and/or modify them under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer Laszlo Molnar
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
|
||||
John F. Reiser
|
||||
<jreiser@users.sourceforge.net>
|
||||
*/
|
||||
#define SAFE 0 /* 1 for src+dst bounds checking: cost 40 bytes */
|
||||
|
||||
#define src r0
|
||||
#define len r1 /* overlaps 'cnt' */
|
||||
#define dst r2
|
||||
#define tmp r3
|
||||
#define bits r4
|
||||
#define off r5
|
||||
#define wrnk r6 /* 0x500 M2_MAX_OFFSET before "wrinkle" */
|
||||
#define srclim r7
|
||||
#if 1==SAFE /*{*/
|
||||
#define dstlim r12
|
||||
#endif /*}*/
|
||||
|
||||
#define cnt r1 /* overlaps 'len' while reading an offset */
|
||||
|
||||
#if 1==SAFE /*{*/
|
||||
#define CHECK_SRC cmp src,srclim; bhs bad_src_n2e
|
||||
#define CHECK_DST cmp dst,dstlim; bhs bad_dst_n2e
|
||||
#else /*}{*/
|
||||
#define CHECK_SRC /*empty*/
|
||||
#define CHECK_DST /*empty*/
|
||||
#endif /*}*/
|
||||
|
||||
#if 0 /*{ DEBUG only: check newly-decompressed against original dst */
|
||||
#define CHECK_BYTE \
|
||||
push {wrnk}; \
|
||||
ldrb wrnk,[dst]; \
|
||||
cmp wrnk,tmp; beq 0f; bkpt; \
|
||||
0: pop {wrnk}
|
||||
#else /*}{*/
|
||||
#define CHECK_BYTE /*empty*/
|
||||
#endif /*}*/
|
||||
|
||||
/* "mov lr,pc; bxx ..." implements conditional subroutine call
|
||||
*
|
||||
* NOTE: the lsb will not be set, so you MUST NOT use 'bx lr' to return,
|
||||
* else the T bit will be cleared and processor will go in ARM state */
|
||||
#define GETBIT add bits,bits; mov lr,pc; beq get1_n2e
|
||||
|
||||
#define getnextb(reg) GETBIT; adc reg,reg
|
||||
#define jnextb0 GETBIT; bcc
|
||||
#define jnextb1 GETBIT; bcs
|
||||
|
||||
#ifndef PURE_THUMB
|
||||
ucl_nrv2e_decompress_8: .globl ucl_nrv2e_decompress_8 @ ARM mode
|
||||
.type ucl_nrv2e_decompress_8, %function
|
||||
/* error = (*)(char const *src, int len_src, char *dst, int *plen_dst)
|
||||
Actual decompressed length is stored through plen_dst.
|
||||
For SAFE mode: at call, *plen_dst must be allowed length of output buffer.
|
||||
*/
|
||||
adr r12,1+.thumb_nrv2e_d8; bx r12 @ enter THUMB mode
|
||||
#endif
|
||||
.code 16 @ THUMB mode
|
||||
.thumb_func
|
||||
|
||||
.thumb_nrv2e_d8:
|
||||
#if 0
|
||||
push {r2,r3, r4,r5,r6,r7, lr}
|
||||
#define sp_DST0 0 /* stack offset of original dst */
|
||||
#endif
|
||||
add srclim,len,src @ srclim= eof_src;
|
||||
#if 1==SAFE /*{*/
|
||||
ldr tmp,[r3] @ len_dst
|
||||
add tmp,dst
|
||||
mov dstlim,tmp
|
||||
#endif /*}*/
|
||||
mov bits,#1; neg off,bits @ off= -1 initial condition
|
||||
lsl bits,#31 @ 1<<31: refill next time
|
||||
mov wrnk,#5
|
||||
lsl wrnk,#8 @ 0x500 @ nrv2e M2_MAX_OFFSET
|
||||
b top_n2e
|
||||
|
||||
#if 1==SAFE /*{*/
|
||||
bad_dst_n2e: # return value will be 2
|
||||
add src,srclim,#1
|
||||
bad_src_n2e: # return value will be 1
|
||||
add src,#1
|
||||
#endif /*}*/
|
||||
eof_n2e:
|
||||
#if 0
|
||||
pop {r3,r4} @ r3= orig_dst; r4= plen_dst
|
||||
sub src,srclim @ 0 if actual src length equals expected length
|
||||
sub dst,r3 @ actual dst length
|
||||
str dst,[r4]
|
||||
pop {r4,r5,r6,r7 /*,pc*/}
|
||||
pop {r1}; bx r1 @ "pop {,pc}" fails return to ARM mode on ARMv4T
|
||||
#else
|
||||
mov r0, #0
|
||||
bx r0 /* Branch to 0x0, switch to ARM mode */
|
||||
#endif
|
||||
|
||||
get1_n2e: @ In: Carry set [from adding 0x80000000 (1<<31) to itself]
|
||||
ldrb bits,[src] @ zero-extend next byte
|
||||
adc bits,bits @ double and insert CarryIn as low bit
|
||||
CHECK_SRC
|
||||
add src,#1
|
||||
lsl bits,#24 @ move to top byte, and set CarryOut from old bit 8
|
||||
/* NOTE: the following instruction will not work on ARMv7+, because
|
||||
* it will update the T bit and return into ARM state */
|
||||
mov pc,lr @ return, stay in current (THUMB) mode
|
||||
|
||||
lit_n2e:
|
||||
CHECK_SRC; ldrb tmp,[src]; add src,#1
|
||||
CHECK_BYTE
|
||||
CHECK_DST; strb tmp,[dst]; add dst,#1
|
||||
top_n2e:
|
||||
jnextb1 lit_n2e
|
||||
mov cnt,#1; b getoff_n2e
|
||||
|
||||
off_n2e:
|
||||
sub cnt,#1
|
||||
getnextb(cnt)
|
||||
getoff_n2e:
|
||||
getnextb(cnt)
|
||||
jnextb0 off_n2e
|
||||
|
||||
sub tmp,cnt,#3 @ set Carry
|
||||
mov len,#0 @ Carry unaffected
|
||||
blo offprev_n2e @ cnt was 2; tests Carry only
|
||||
lsl tmp,#8
|
||||
CHECK_SRC; ldrb off,[src]; add src,#1 @ low 7+1 bits
|
||||
orr off,tmp
|
||||
mvn off,off; beq eof_n2e @ off= ~off
|
||||
asr off,#1; bcs lenlast_n2e
|
||||
b lenmore_n2e
|
||||
|
||||
offprev_n2e:
|
||||
jnextb1 lenlast_n2e
|
||||
lenmore_n2e:
|
||||
mov len,#1
|
||||
jnextb1 lenlast_n2e
|
||||
len_n2e:
|
||||
getnextb(len)
|
||||
jnextb0 len_n2e
|
||||
add len,#6-2
|
||||
b gotlen_n2e
|
||||
|
||||
lenlast_n2e:
|
||||
getnextb(len) @ 0,1,2,3
|
||||
add len,#2
|
||||
gotlen_n2e: @ 'cmn': add the inputs, set condition codes, discard the sum
|
||||
cmn wrnk,off; bcs near_n2e @ within M2_MAX_OFFSET
|
||||
add len,#1 @ too far away, so minimum match length is 3
|
||||
near_n2e:
|
||||
#if 1==SAFE /*{*/
|
||||
ldr tmp,[sp,#sp_DST0]
|
||||
sub tmp,dst
|
||||
sub tmp,off; bhi bad_dst_n2e @ reaching back too far
|
||||
|
||||
add tmp,dst,cnt
|
||||
cmp tmp,dstlim; bhi bad_dst_n2e @ too much output
|
||||
#endif /*}*/
|
||||
ldrb tmp,[dst] @ force cacheline allocate
|
||||
copy_n2e:
|
||||
ldrb tmp,[dst,off]
|
||||
CHECK_BYTE
|
||||
strb tmp,[dst]; add dst,#1
|
||||
sub len,#1; bne copy_n2e
|
||||
b top_n2e
|
||||
|
||||
#ifndef PURE_THUMB
|
||||
.size ucl_nrv2e_decompress_8, .-ucl_nrv2e_decompress_8
|
||||
#endif
|
||||
|
||||
/*
|
||||
vi:ts=8:et:nowrap
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue