Skip to content

Commit

Permalink
Same same but based on libc implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
atraber authored and gautschimi committed Jul 21, 2016
1 parent eca214b commit 07bced5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
21 changes: 8 additions & 13 deletions sw/ref/crt0.riscv.S
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,8 @@ zero_loop:
ble x26, x27, zero_loop
zero_loop_end:

/* call C++ constructors */
la x26, __init_array_start
la x27, __init_array_end

bge x26, x27, init_array_loop_end

init_array_loop:
lw x10, 0(x26)
jalr x1, x10
addi x26, x26, 4
ble x26, x27, init_array_loop
init_array_loop_end:

/* Run global initialization functions */
call __libc_init_array

main_entry:
addi x10, x0, 0
Expand Down Expand Up @@ -184,6 +173,12 @@ end_except:
addi x2, x2, EXCEPTION_STACK_SIZE
eret

.global _init
.global _fini
_init:
_fini:
# These don't have to do anything since we use init_array/fini_array.
ret

/* =================================================== [ exceptions ] === */
/* This section has to be down here, since we have to disable rvc for it */
Expand Down
34 changes: 26 additions & 8 deletions sw/ref/link.common.ld
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,32 @@ SECTIONS
_endtext = .;
} > instrram

.init_array : {
. = ALIGN(4);
__init_array_start = .;
*(.init_array)
*(.init_array.*)
__init_array_end = .;
KEEP(*(.init_array))
} > instrram
/*--------------------------------------------------------------------*/
/* Global constructor/destructor segement */
/*--------------------------------------------------------------------*/

.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
} > dataram

.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array ))
PROVIDE_HIDDEN (__init_array_end = .);
} > dataram

.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array ))
PROVIDE_HIDDEN (__fini_array_end = .);
} > dataram

.rodata : {
. = ALIGN(4);
Expand Down

0 comments on commit 07bced5

Please sign in to comment.