Skip to content

Commit

Permalink
Compressed ROM images now work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brown committed Jul 16, 2007
1 parent 37fa9a8 commit 048bbee
Show file tree
Hide file tree
Showing 9 changed files with 439 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Makefile
Expand Up @@ -90,6 +90,7 @@ MKCONFIG ?= $(PERL) ./util/mkconfig.pl
SYMCHECK ?= $(PERL) ./util/symcheck.pl
SORTOBJDUMP ?= $(PERL) ./util/sortobjdump.pl
NRV2B ?= ./util/nrv2b
ZBIN ?= ./util/zbin
DOXYGEN ?= doxygen

# Location to place generated files
Expand Down
26 changes: 22 additions & 4 deletions src/Makefile.housekeeping
Expand Up @@ -307,11 +307,23 @@ $(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
$(BIN)/%.map : $(BIN)/%.tmp
@less $(BIN)/$*.tmp.map

# Extract compression information from intermediate object file
#
$(BIN)/%.zinfo : $(BIN)/%.tmp
$(QM)echo " [ZINFO] $@"
$(Q)$(OBJCOPY) -O binary -j .zinfo $< $@

# Build raw binary file from intermediate object file
#
$(BIN)/%.bin : $(BIN)/%.tmp
$(QM)echo " [BIN] $@"
$(Q)$(OBJCOPY) -O binary $< $@
$(Q)$(OBJCOPY) -O binary -R .zinfo $< $@

# Compress raw binary file
#
$(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
$(QM)echo " [ZBIN] $@"
$(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@

# Build bochs symbol table
$(BIN)/%.bxs : $(BIN)/%.tmp
Expand Down Expand Up @@ -356,7 +368,7 @@ define media_template
@$(MKDIR) -p $(dir $(2))
@$(RM) $(2)
@$(TOUCH) $(2)
@echo -e '$$(BIN)/%$(1) : $$(BIN)/%$(1).bin' \
@echo -e '$$(BIN)/%$(1) : $$(BIN)/%$(1).zbin' \
'\n\t$$(QM)echo " [FINISH] $$@"' \
'\n\t$$(Q)$$(CP) $$< $$@' \
'\n\t$$(Q)$$(FINALISE_$(1))' \
Expand All @@ -383,13 +395,19 @@ include $(MEDIA_DEPS)
allroms allzroms : all%s : $(foreach ROM,$(ROMS),$(BIN)/$(ROM).%)
all%s : $(foreach DRIVER,$(DRIVERS),$(BIN)/$(DRIVER).%)

# The compressor utility
# The compression utilities
#
$(NRV2B) : util/nrv2b.c $(MAKEDEPS)
$(HOST_CC) -O2 -DENCODE -DDECODE -DMAIN -DVERBOSE -DNDEBUG \
$(QM)echo " [HOSTCC] $@"
$(Q)$(HOST_CC) -O2 -DENCODE -DDECODE -DMAIN -DVERBOSE -DNDEBUG \
-DBITSIZE=32 -DENDIAN=0 -o $@ $<
CLEANUP += $(NRV2B)

$(ZBIN) : util/zbin.c util/nrv2b.c $(MAKEDEPS)
$(QM)echo " [HOSTCC] $@"
$(Q)$(HOST_CC) -O2 -o $@ $<
CLEANUP += $(ZBIN)

# Auto-incrementing build serial number. Append "bs" to your list of
# build targets to get a serial number printed at the end of the
# build. Enable -DBUILD_SERIAL in order to see it when the code runs.
Expand Down
9 changes: 8 additions & 1 deletion src/arch/i386/prefix/libprefix.S
Expand Up @@ -37,6 +37,9 @@
*/
#define HIGHMEM_LOADPOINT ( 4 << 20 )

/* Image compression enabled */
#define COMPRESS 1

#define CR0_PE 1

.arch i386
Expand Down Expand Up @@ -81,7 +84,11 @@ install_block:

/* Do the copy */
cld
rep addr32 movsb /* or "call decompress16" */
#if COMPRESS
call decompress16
#else
call nodecompress16
#endif

/* Zero remaining space */
movl %eax, %edi
Expand Down
18 changes: 18 additions & 0 deletions src/arch/i386/prefix/nonrv2b.S
@@ -0,0 +1,18 @@
/* Placeholder for decompress16 in non-compressed images */

.text
.arch i386
.section ".prefix.lib", "ax", @progbits

.code16
.globl nodecompress16
nodecompress16:
rep addr32 movsb
ret

/* File split information for the compressor */
.section ".zinfo", "a"
.ascii "COPY"
.long _prefix_load_offset
.long _load_size
.long _max_align
16 changes: 14 additions & 2 deletions src/arch/i386/prefix/romprefix.S
Expand Up @@ -14,7 +14,7 @@
.org 0x00
romheader:
.word 0xAA55 /* BIOS extension signature */
.byte _rom_size /* Size in 512-byte blocks */
romheader_size: .byte _rom_size /* Size in 512-byte blocks */
jmp init_vector /* Initialisation vector */
.org 0x16
.word undiheader
Expand All @@ -34,7 +34,7 @@ pciheader:
.byte 0x02 /* Device Base Type code */
.byte 0x00 /* Device Sub-Type code */
.byte 0x00 /* Device Interface Type code */
.word _rom_size /* Image length same as offset 02h */
pciheader_size: .word _rom_size /* Image length same as offset 02h */
.word 0x0001 /* revision level of code/data */
.byte 0x00 /* code type */
.byte 0x80 /* Flags (last PCI data structure) */
Expand Down Expand Up @@ -215,3 +215,15 @@ print_message:
popw %ax
ret
.size print_message, . - print_message


/* Data update information for the compressor */
.section ".zinfo.fixup", "a"
.ascii "SUBB"
.long romheader_size
.long 512
.long 0
.ascii "SUBW"
.long pciheader_size
.long 512
.long 0
29 changes: 25 additions & 4 deletions src/arch/i386/prefix/unnrv2b.S
Expand Up @@ -35,7 +35,7 @@

.text
.arch i386
.section ".prefix", "ax", @progbits
.section ".prefix.lib", "ax", @progbits

#ifdef CODE16
/****************************************************************************
Expand All @@ -54,6 +54,7 @@
* NOTE: It would be possible to build a smaller version of the
* decompression code for -DKEEP_IT_REAL by using
* #define REG(x) x
* #define MOVSB movsb
* to use 16-bit registers where possible. This would impose limits
* that the compressed data size must be in the range [1,65533-%si]
* and the uncompressed data size must be in the range [1,65536-%di]
Expand All @@ -66,6 +67,7 @@
*/

#define REG(x) e ## x
#define MOVSB addr32 movsb

.code16
.globl decompress16
Expand Down Expand Up @@ -109,11 +111,10 @@ decompress:
cld
xor %xBP, %xBP
dec %xBP /* last_m_off = -1 */
add $4, %xSI /* Skip "file length" field */
jmp dcl1_n2b

decompr_literals_n2b:
movsb
MOVSB
decompr_loop_n2b:
addl %ebx, %ebx
jnz dcl2_n2b
Expand Down Expand Up @@ -157,7 +158,7 @@ decompr_got_mlen_n2b:
push %xSI
lea (%xBP,%xDI), %xSI /* m_pos = dst + olen + -m_off */
rep
es movsb /* dst[olen++] = *m_pos++ while(m_len > 0) */
es MOVSB /* dst[olen++] = *m_pos++ while(m_len > 0) */
pop %xSI
jmp decompr_loop_n2b

Expand All @@ -179,3 +180,23 @@ decompr_end_n2b:
popl %ebx
pop %xAX
ret


/* File split information for the compressor */
.section ".zinfo", "a"
.ascii "COPY"
.long _prefix_load_offset
.long _prefix_progbits_size
.long _max_align
.ascii "PACK"
.long _text16_load_offset
.long _text16_progbits_size
.long _max_align
.ascii "PACK"
.long _data16_load_offset
.long _data16_progbits_size
.long _max_align
.ascii "PACK"
.long _textdata_load_offset
.long _textdata_progbits_size
.long _max_align
25 changes: 25 additions & 0 deletions src/arch/i386/scripts/i386.lds
Expand Up @@ -164,6 +164,24 @@ SECTIONS {

_end = .;

/*
* Compressor information block
*/

_zinfo_link_addr = 0;
. = _zinfo_link_addr;
_zinfo = .;

.zinfo : AT ( _zinfo_load_offset + __zinfo ) {
__zinfo = .;
_entry = .;
*(.zinfo)
*(.zinfo.*)
_ezinfo_progbits = .;
}

_ezinfo = .;

/*
* Dispose of the comment and note sections to make the link map
* easier to read
Expand Down Expand Up @@ -215,6 +233,13 @@ SECTIONS {

_load_size = . - _load_addr;

. -= _zinfo_link_addr;
_zinfo_load_offset = ALIGN ( _max_align );
_zinfo_load_addr = _zinfo_link_addr + _zinfo_load_offset;
_zinfo_size = _ezinfo - _zinfo;
_zinfo_progbits_size = _ezinfo_progbits - _zinfo;
. = _zinfo_load_addr + _zinfo_progbits_size;

_payload_offset = _text16_load_offset;

/*
Expand Down
1 change: 1 addition & 0 deletions src/util/.gitignore
@@ -1,3 +1,4 @@
nrv2b
zbin
hijack
prototester

0 comments on commit 048bbee

Please sign in to comment.