Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[i386] Simplify linker script and standardise linker-defined symbol n…
…ames

Reduce the number of sections within the linker script to match the
number of practical sections within the output file.

Define _section, _msection, _esection, _section_filesz, _section_memsz,
and _section_lma for each section, replacing the mixture of symbols that
previously existed.

In particular, replace _text and _end with _textdata and _etextdata, to
make it explicit within code that uses these symbols that the .text and
.data sections are always treated as a single contiguous block.
  • Loading branch information
Michael Brown committed Oct 10, 2008
1 parent 3029eb0 commit 13d09e6
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 236 deletions.
8 changes: 4 additions & 4 deletions src/arch/i386/core/relocate.c
Expand Up @@ -18,8 +18,8 @@ extern char _max_align[];
#define max_align ( ( unsigned int ) _max_align )

/* Linker symbols */
extern char _text[];
extern char _end[];
extern char _textdata[];
extern char _etextdata[];

/* within 1MB of 4GB is too close.
* MAX_ADDR is the maximum address we can easily do DMA to.
Expand Down Expand Up @@ -47,8 +47,8 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {

/* Get memory map and current location */
get_memmap ( &memmap );
start = virt_to_phys ( _text );
end = virt_to_phys ( _end );
start = virt_to_phys ( _textdata );
end = virt_to_phys ( _etextdata );
size = ( end - start );
padded_size = ( size + max_align - 1 );

Expand Down
4 changes: 2 additions & 2 deletions src/arch/i386/firmware/pcbios/e820mangler.S
Expand Up @@ -66,7 +66,7 @@
.align 16
.globl hidemem_base
.globl hidemem_umalloc
.globl hidemem_text
.globl hidemem_textdata
memory_windows:
base_memory_window: .long 0x00000000, 0x00000000 /* Start of memory */

Expand All @@ -76,7 +76,7 @@ ext_memory_window: .long 0x000a0000, 0x00000000 /* 640kB mark */
hidemem_umalloc: .long 0xffffffff, 0xffffffff /* Changes at runtime */
.long 0xffffffff, 0xffffffff /* Changes at runtime */

hidemem_text: .long 0xffffffff, 0xffffffff /* Changes at runtime */
hidemem_textdata: .long 0xffffffff, 0xffffffff /* Changes at runtime */
.long 0xffffffff, 0xffffffff /* Changes at runtime */

.long 0xffffffff, 0xffffffff /* End of memory */
Expand Down
32 changes: 16 additions & 16 deletions src/arch/i386/firmware/pcbios/hidemem.c
Expand Up @@ -55,8 +55,8 @@ extern struct hidden_region __data16 ( hidemem_umalloc );
#define hidemem_umalloc __use_data16 ( hidemem_umalloc )

/** Hidden text memory */
extern struct hidden_region __data16 ( hidemem_text );
#define hidemem_text __use_data16 ( hidemem_text )
extern struct hidden_region __data16 ( hidemem_textdata );
#define hidemem_textdata __use_data16 ( hidemem_textdata )

/** Assembly routine in e820mangler.S */
extern void int15();
Expand All @@ -66,12 +66,12 @@ extern struct segoff __text16 ( int15_vector );
#define int15_vector __use_text16 ( int15_vector )

/* The linker defines these symbols for us */
extern char _text[];
extern char _end[];
extern char _text16_size[];
#define _text16_size ( ( unsigned int ) _text16_size )
extern char _data16_size[];
#define _data16_size ( ( unsigned int ) _data16_size )
extern char _textdata[];
extern char _etextdata[];
extern char _text16_memsz[];
#define _text16_memsz ( ( unsigned int ) _text16_memsz )
extern char _data16_memsz[];
#define _data16_memsz ( ( unsigned int ) _data16_memsz )

/**
* Hide region of memory from system memory map
Expand Down Expand Up @@ -110,17 +110,17 @@ void hide_basemem ( void ) {
*
*/
void hide_umalloc ( physaddr_t start, physaddr_t end ) {
assert ( end <= virt_to_phys ( _text ) );
assert ( end <= virt_to_phys ( _textdata ) );
hide_region ( &hidemem_umalloc, start, end );
}

/**
* Hide .text and .data
*
*/
void hide_text ( void ) {
hide_region ( &hidemem_text, virt_to_phys ( _text ),
virt_to_phys ( _end ) );
void hide_textdata ( void ) {
hide_region ( &hidemem_textdata, virt_to_phys ( _textdata ),
virt_to_phys ( _etextdata ) );
}

/**
Expand Down Expand Up @@ -148,8 +148,8 @@ static void hide_etherboot ( void ) {

/* Initialise the hidden regions */
hide_basemem();
hide_umalloc ( virt_to_phys ( _text ), virt_to_phys ( _text ) );
hide_text();
hide_umalloc ( virt_to_phys ( _textdata ), virt_to_phys ( _textdata ) );
hide_textdata();

/* Some really moronic BIOSes bring up the PXE stack via the
* UNDI loader entry point and then don't bother to unload it
Expand All @@ -161,8 +161,8 @@ static void hide_etherboot ( void ) {
* We use a heuristic to guess whether or not we are being
* loaded sensibly.
*/
rm_cs_top = ( ( ( rm_cs << 4 ) + _text16_size + 1024 - 1 ) >> 10 );
rm_ds_top = ( ( ( rm_ds << 4 ) + _data16_size + 1024 - 1 ) >> 10 );
rm_cs_top = ( ( ( rm_cs << 4 ) + _text16_memsz + 1024 - 1 ) >> 10 );
rm_ds_top = ( ( ( rm_ds << 4 ) + _data16_memsz + 1024 - 1 ) >> 10 );
fbms = get_fbms();
if ( ( rm_cs_top < fbms ) && ( rm_ds_top < fbms ) ) {
DBG ( "Detected potentially unsafe UNDI load at CS=%04x "
Expand Down
14 changes: 7 additions & 7 deletions src/arch/i386/interface/pxe/pxe_entry.S
Expand Up @@ -44,10 +44,10 @@ ppxe:
.byte SegDescCnt /* SegDescCnt */
.word 0 /* FirstSelector */
pxe_segments:
.word 0, 0, 0, _data16_size /* Stack */
.word 0, 0, 0, _data16_size /* UNDIData */
.word 0, 0, 0, _text16_size /* UNDICode */
.word 0, 0, 0, _text16_size /* UNDICodeWrite */
.word 0, 0, 0, _data16_memsz /* Stack */
.word 0, 0, 0, _data16_memsz /* UNDIData */
.word 0, 0, 0, _text16_memsz /* UNDICode */
.word 0, 0, 0, _text16_memsz /* UNDICodeWrite */
.word 0, 0, 0, 0 /* BC_Data */
.word 0, 0, 0, 0 /* BC_Code */
.word 0, 0, 0, 0 /* BC_CodeWrite */
Expand Down Expand Up @@ -76,15 +76,15 @@ pxenv:
.long 0 /* PMEntry */
.word 0 /* PMSelector */
.word 0 /* StackSeg */
.word _data16_size /* StackSize */
.word _data16_memsz /* StackSize */
.word 0 /* BC_CodeSeg */
.word 0 /* BC_CodeSize */
.word 0 /* BC_DataSeg */
.word 0 /* BC_DataSize */
.word 0 /* UNDIDataSeg */
.word _data16_size /* UNDIDataSize */
.word _data16_memsz /* UNDIDataSize */
.word 0 /* UNDICodeSeg */
.word _text16_size /* UNDICodeSize */
.word _text16_memsz /* UNDICodeSize */
.word ppxe, 0 /* PXEPtr */
.equ pxenv_length, . - pxenv
.size pxenv, . - pxenv
Expand Down
2 changes: 1 addition & 1 deletion src/arch/i386/prefix/dskprefix.S
Expand Up @@ -144,7 +144,7 @@ got_sectors:
/* Jump to loaded copy */
ljmp $SYSSEG, $start_runtime

endseg: .word SYSSEG + _load_size_pgh
endseg: .word SYSSEG + _filesz_pgh
.section ".zinfo.fixup", "a" /* Compressor fixup information */
.ascii "SUBW"
.long endseg
Expand Down
2 changes: 1 addition & 1 deletion src/arch/i386/prefix/hdprefix.S
Expand Up @@ -63,7 +63,7 @@ max_sector:
max_head:
.byte 0
load_length:
.long _load_size_sect
.long _filesz_sect

.section ".zinfo.fixup", "a" /* Compressor fixup information */
.ascii "SUBL"
Expand Down
36 changes: 18 additions & 18 deletions src/arch/i386/prefix/libprefix.S
Expand Up @@ -511,11 +511,11 @@ alloc_basemem:
shlw $6, %ax

/* .data16 segment address */
subw $_data16_size_pgh, %ax
subw $_data16_memsz_pgh, %ax
pushw %ax

/* .text16 segment address */
subw $_text16_size_pgh, %ax
subw $_text16_memsz_pgh, %ax
pushw %ax

/* Update FBMS */
Expand Down Expand Up @@ -594,19 +594,19 @@ install_prealloc:
jnz 1f
movw %cs, %si
shll $4, %esi
1: addl $_payload_offset, %esi
1: addl $_payload_lma, %esi

/* Install .text16 and .data16 */
pushl %edi
movzwl %ax, %edi
shll $4, %edi
movl $_text16_size, %ecx
movl $_text16_memsz, %ecx
movl %ecx, %edx
call install_block /* .text16 */
movzwl %bx, %edi
shll $4, %edi
movl $_data16_progbits_size, %ecx
movl $_data16_size, %edx
movl $_data16_filesz, %ecx
movl $_data16_memsz, %edx
call install_block /* .data16 */
popl %edi

Expand All @@ -622,8 +622,8 @@ install_prealloc:
* prior to reading the E820 memory map and relocating
* properly.
*/
movl $_textdata_progbits_size, %ecx
movl $_textdata_size, %edx
movl $_textdata_filesz, %ecx
movl $_textdata_memsz, %edx
call install_block

/* Initialise librm at current location */
Expand Down Expand Up @@ -681,25 +681,25 @@ prot_call_vector:
#if COMPRESS
.section ".zinfo", "a"
.ascii "COPY"
.long _prefix_load_offset
.long _prefix_progbits_size
.long _prefix_lma
.long _prefix_filesz
.long _max_align
.ascii "PACK"
.long _text16_load_offset
.long _text16_progbits_size
.long _text16_lma
.long _text16_filesz
.long _max_align
.ascii "PACK"
.long _data16_load_offset
.long _data16_progbits_size
.long _data16_lma
.long _data16_filesz
.long _max_align
.ascii "PACK"
.long _textdata_load_offset
.long _textdata_progbits_size
.long _textdata_lma
.long _textdata_filesz
.long _max_align
#else /* COMPRESS */
.section ".zinfo", "a"
.ascii "COPY"
.long _prefix_load_offset
.long _load_size
.long _prefix_lma
.long _filesz
.long _max_align
#endif /* COMPRESS */
2 changes: 1 addition & 1 deletion src/arch/i386/prefix/lkrnprefix.S
Expand Up @@ -92,7 +92,7 @@ setup_sects:
root_flags:
.word 0
syssize:
.long _load_size_pgh - PREFIXPGH
.long _filesz_pgh - PREFIXPGH

.section ".zinfo.fixup", "a" /* Compressor fixup information */
.ascii "SUBL"
Expand Down
4 changes: 2 additions & 2 deletions src/arch/i386/prefix/nbiprefix.S
Expand Up @@ -32,8 +32,8 @@ segment_header:
.byte 0
.byte 0x04 /* Last segment */
.long 0x00007e00
imglen: .long _load_size - 512
memlen: .long _load_size - 512
imglen: .long _filesz - 512
memlen: .long _filesz - 512
.size segment_header, . - segment_header

.section ".zinfo.fixup", "a" /* Compressor fixup information */
Expand Down
14 changes: 7 additions & 7 deletions src/arch/i386/prefix/romprefix.S
Expand Up @@ -30,7 +30,7 @@
.org 0x00
romheader:
.word 0xAA55 /* BIOS extension signature */
romheader_size: .byte _load_size_sect /* Size in 512-byte blocks */
romheader_size: .byte _filesz_sect /* Size in 512-byte blocks */
jmp init /* Initialisation vector */
checksum:
.byte 0
Expand Down Expand Up @@ -58,12 +58,12 @@ pciheader:
.byte 0x03 /* PCI data structure revision */
.byte 0x02, 0x00, 0x00 /* Class code */
pciheader_image_length:
.word _load_size_sect /* Image length */
.word _filesz_sect /* Image length */
.word 0x0001 /* Revision level */
.byte 0x00 /* Code type */
.byte 0x80 /* Last image indicator */
pciheader_runtime_length:
.word _load_size_sect /* Maximum run-time image length */
.word _filesz_sect /* Maximum run-time image length */
.word 0x0000 /* Configuration utility code header */
.word 0x0000 /* DMTF CLP entry point */
.equ pciheader_len, . - pciheader
Expand Down Expand Up @@ -130,9 +130,9 @@ undiheader:
.byte 0 /* Structure revision */
.byte 0,1,2 /* PXE version: 2.1.0 */
.word undiloader /* Offset to loader routine */
.word _data16_size /* Stack segment size */
.word _data16_size /* Data segment size */
.word _text16_size /* Code segment size */
.word _data16_memsz /* Stack segment size */
.word _data16_memsz /* Data segment size */
.word _text16_memsz /* Code segment size */
.ascii "PCIR" /* Bus type */
.equ undiheader_len, . - undiheader
.size undiheader, . - undiheader
Expand Down Expand Up @@ -294,7 +294,7 @@ pmm_scan:
/* Shrink ROM and update checksum */
xorw %bx, %bx
xorw %si, %si
movw $_prefix_size_sect, %cx
movw $_prefix_memsz_sect, %cx
movb %cl, romheader_size
shlw $9, %cx
1: lodsb
Expand Down

0 comments on commit 13d09e6

Please sign in to comment.