mirror of
https://github.com/vivier/EMILE.git
synced 2025-02-07 14:30:34 +00:00
Allocate and relocate section BSS
This commit is contained in:
parent
cf8d13a76f
commit
8b4036e0f5
@ -4,6 +4,10 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
.macro NewPtr
|
||||||
|
.short 0xA11E
|
||||||
|
.endm
|
||||||
|
|
||||||
.equ cmdline_length, 256 /* see CL_SIZE in bootinfo.c */
|
.equ cmdline_length, 256 /* see CL_SIZE in bootinfo.c */
|
||||||
|
|
||||||
.global _start
|
.global _start
|
||||||
@ -18,10 +22,14 @@ _command_line:
|
|||||||
|
|
||||||
.align 4
|
.align 4
|
||||||
setup:
|
setup:
|
||||||
/* relocate C code, need to be compile with -fpic */
|
/* relocate C code, need to be compiled with -fpic */
|
||||||
|
|
||||||
bsr relocate
|
bsr relocate
|
||||||
|
|
||||||
|
/* memory map */
|
||||||
|
|
||||||
|
bsr init_memory_map@PLTPC
|
||||||
|
|
||||||
/* identify system */
|
/* identify system */
|
||||||
|
|
||||||
bsr arch_init@PLTPC
|
bsr arch_init@PLTPC
|
||||||
@ -30,21 +38,10 @@ setup:
|
|||||||
|
|
||||||
bsr console_init@PLTPC
|
bsr console_init@PLTPC
|
||||||
|
|
||||||
/* initialize memory, so we can work */
|
|
||||||
|
|
||||||
bsr memory_init@PLTPC
|
|
||||||
|
|
||||||
/* retrieve machine info */
|
/* retrieve machine info */
|
||||||
|
|
||||||
bsr bootinfo_init@PLTPC
|
bsr bootinfo_init@PLTPC
|
||||||
|
|
||||||
/* allocate stack, so we can jump */
|
|
||||||
|
|
||||||
pea 0x2000
|
|
||||||
bsr malloc@PLTPC
|
|
||||||
add.l #0x2000 - 16, %d0
|
|
||||||
move.l %d0, %sp
|
|
||||||
|
|
||||||
/* begin to work */
|
/* begin to work */
|
||||||
|
|
||||||
bsr main@PLTPC
|
bsr main@PLTPC
|
||||||
@ -54,6 +51,14 @@ loop:
|
|||||||
bra loop
|
bra loop
|
||||||
|
|
||||||
relocate:
|
relocate:
|
||||||
|
/* Allocate BSS section */
|
||||||
|
|
||||||
|
move.l #__bss_size, %d0 /* size */
|
||||||
|
NewPtr /* result in %a0 */
|
||||||
|
move.l %a0,%d3
|
||||||
|
move.l #__bss_start, %d0
|
||||||
|
sub.l %d0,%d3 /* %d3 is the offset to add for BSS */
|
||||||
|
|
||||||
/* real address of GOT */
|
/* real address of GOT */
|
||||||
|
|
||||||
lea (%pc, _GLOBAL_OFFSET_TABLE_@GOTPC), %a0
|
lea (%pc, _GLOBAL_OFFSET_TABLE_@GOTPC), %a0
|
||||||
@ -62,19 +67,35 @@ relocate:
|
|||||||
|
|
||||||
move.l #_GLOBAL_OFFSET_TABLE_, %d0
|
move.l #_GLOBAL_OFFSET_TABLE_, %d0
|
||||||
|
|
||||||
/* offset to add to GOT items */
|
/* %d2 is the offset to add for all other sections */
|
||||||
|
|
||||||
move.l %a0,%d2
|
move.l %a0,%d2
|
||||||
sub.l %d0,%d2
|
sub.l %d0,%d2
|
||||||
beq exit_relocate
|
|
||||||
|
|
||||||
move.l #_GOT_SIZE, %d0
|
/* relocate BSS section */
|
||||||
|
|
||||||
|
move.l #__got_size, %d0
|
||||||
beq exit_relocate
|
beq exit_relocate
|
||||||
|
|
||||||
got_loop:
|
got_loop:
|
||||||
move.l (%a0), %d1
|
move.l (%a0), %d1
|
||||||
|
|
||||||
|
cmp.l #__bss_start, %d1
|
||||||
|
blt other_section
|
||||||
|
cmp.l #_end, %d1
|
||||||
|
bgt other_section
|
||||||
|
|
||||||
|
/* symbol in section BSS */
|
||||||
|
|
||||||
|
add.l %d3, %d1
|
||||||
|
bra got_store
|
||||||
|
|
||||||
|
other_section:
|
||||||
add.l %d2, %d1
|
add.l %d2, %d1
|
||||||
|
|
||||||
|
got_store:
|
||||||
move.l %d1, (%a0)+
|
move.l %d1, (%a0)+
|
||||||
|
|
||||||
subq.l #4, %d0
|
subq.l #4, %d0
|
||||||
bgt got_loop
|
bgt got_loop
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ SECTIONS
|
|||||||
.gcc_except_table : { *(.gcc_except_table) }
|
.gcc_except_table : { *(.gcc_except_table) }
|
||||||
.dynamic : { *(.dynamic) }
|
.dynamic : { *(.dynamic) }
|
||||||
.got : { *(.got.plt) *(.got) }
|
.got : { *(.got.plt) *(.got) }
|
||||||
_GOT_SIZE = . - _GLOBAL_OFFSET_TABLE_;
|
__got_size = . - _GLOBAL_OFFSET_TABLE_;
|
||||||
_edata = .;
|
_edata = .;
|
||||||
PROVIDE (edata = .);
|
PROVIDE (edata = .);
|
||||||
__bss_start = .;
|
__bss_start = .;
|
||||||
@ -94,6 +94,7 @@ SECTIONS
|
|||||||
. = ALIGN(32 / 8);
|
. = ALIGN(32 / 8);
|
||||||
}
|
}
|
||||||
. = ALIGN(32 / 8);
|
. = ALIGN(32 / 8);
|
||||||
|
__bss_size = . - __bss_start;
|
||||||
_end = .;
|
_end = .;
|
||||||
__bootloader_end = .;
|
__bootloader_end = .;
|
||||||
PROVIDE (end = .);
|
PROVIDE (end = .);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user