2004-02-15 20:46:45 +00:00
|
|
|
/*
|
|
|
|
*
|
2006-09-15 14:55:39 +00:00
|
|
|
* (c) 2004, 2005 Laurent Vivier <Laurent@lvivier.info>
|
2004-02-15 20:46:45 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-03-22 15:36:39 +00:00
|
|
|
.cpu 68000
|
2005-05-17 23:36:26 +00:00
|
|
|
|
2004-08-18 23:14:55 +00:00
|
|
|
.macro SysError
|
|
|
|
.short 0xA9C9
|
|
|
|
.endm
|
|
|
|
|
2005-06-06 19:33:40 +00:00
|
|
|
.macro NewPtrClear
|
|
|
|
.short 0xA31E
|
2004-05-25 20:12:52 +00:00
|
|
|
.endm
|
|
|
|
|
2005-11-27 22:31:07 +00:00
|
|
|
.equ paramstring_length, 1024
|
2004-05-19 00:09:58 +00:00
|
|
|
|
2004-05-26 23:05:35 +00:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* second level arguments
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
|
|
|
|
2004-06-22 21:24:54 +00:00
|
|
|
_start: bra setup
|
2007-05-12 19:33:25 +00:00
|
|
|
_signature: .dc.b 'E','M','0','7'
|
2004-12-03 00:21:25 +00:00
|
|
|
|
2005-11-27 22:31:07 +00:00
|
|
|
/* EM06 */
|
2004-12-03 00:21:25 +00:00
|
|
|
|
2005-11-27 22:31:07 +00:00
|
|
|
_conf_size: .dc.w paramstring_length
|
|
|
|
_configuration: .skip paramstring_length, 0
|
2004-05-19 00:09:58 +00:00
|
|
|
|
|
|
|
.align 4
|
|
|
|
setup:
|
2004-05-25 20:12:52 +00:00
|
|
|
/* relocate C code, need to be compiled with -fpic */
|
2004-05-24 23:59:13 +00:00
|
|
|
|
|
|
|
bsr relocate
|
|
|
|
|
2004-02-15 20:46:45 +00:00
|
|
|
/* begin to work */
|
|
|
|
|
2004-06-22 21:24:54 +00:00
|
|
|
lea _start(%pc), %a0
|
2004-06-03 19:30:26 +00:00
|
|
|
move.l %a0, -(%sp)
|
|
|
|
bsr start@PLTPC
|
2004-02-15 20:46:45 +00:00
|
|
|
|
|
|
|
/* We guess to never come here */
|
|
|
|
loop:
|
|
|
|
bra loop
|
2004-05-24 23:59:13 +00:00
|
|
|
|
|
|
|
relocate:
|
2004-05-25 20:12:52 +00:00
|
|
|
/* Allocate BSS section */
|
|
|
|
|
|
|
|
move.l #__bss_size, %d0 /* size */
|
2005-06-06 19:33:40 +00:00
|
|
|
/* Alloc and clear memory (needed by GCC 3) */
|
|
|
|
NewPtrClear /* result in %a0 */
|
2004-08-18 23:14:55 +00:00
|
|
|
move.l %a0, %d0
|
|
|
|
bne malloc_ok
|
|
|
|
SysError
|
|
|
|
malloc_ok:
|
2004-05-25 20:12:52 +00:00
|
|
|
move.l %a0,%d3
|
|
|
|
move.l #__bss_start, %d0
|
|
|
|
sub.l %d0,%d3 /* %d3 is the offset to add for BSS */
|
|
|
|
|
2004-05-24 23:59:13 +00:00
|
|
|
/* real address of GOT */
|
|
|
|
|
2005-06-10 20:53:14 +00:00
|
|
|
lea _GLOBAL_OFFSET_TABLE_-.-8,%a0
|
|
|
|
lea (%pc, %a0), %a0
|
2004-05-24 23:59:13 +00:00
|
|
|
|
|
|
|
/* linked address of GOT */
|
|
|
|
|
|
|
|
move.l #_GLOBAL_OFFSET_TABLE_, %d0
|
|
|
|
|
2004-05-25 20:12:52 +00:00
|
|
|
/* %d2 is the offset to add for all other sections */
|
2004-05-24 23:59:13 +00:00
|
|
|
|
|
|
|
move.l %a0,%d2
|
|
|
|
sub.l %d0,%d2
|
|
|
|
|
2004-05-25 20:12:52 +00:00
|
|
|
/* relocate BSS section */
|
|
|
|
|
|
|
|
move.l #__got_size, %d0
|
2004-05-24 23:59:13 +00:00
|
|
|
beq exit_relocate
|
|
|
|
|
|
|
|
got_loop:
|
|
|
|
move.l (%a0), %d1
|
2004-05-25 20:12:52 +00:00
|
|
|
|
2004-05-25 23:16:56 +00:00
|
|
|
cmp.l #__bss_start.l, %d1
|
2004-05-25 20:12:52 +00:00
|
|
|
blt other_section
|
2004-05-25 23:16:56 +00:00
|
|
|
cmp.l #_end.l, %d1
|
2004-05-25 20:12:52 +00:00
|
|
|
bgt other_section
|
|
|
|
|
|
|
|
/* symbol in section BSS */
|
|
|
|
|
|
|
|
add.l %d3, %d1
|
|
|
|
bra got_store
|
|
|
|
|
|
|
|
other_section:
|
2004-05-24 23:59:13 +00:00
|
|
|
add.l %d2, %d1
|
2004-05-25 20:12:52 +00:00
|
|
|
|
|
|
|
got_store:
|
2004-05-24 23:59:13 +00:00
|
|
|
move.l %d1, (%a0)+
|
2004-05-25 20:12:52 +00:00
|
|
|
|
2004-05-24 23:59:13 +00:00
|
|
|
subq.l #4, %d0
|
|
|
|
bgt got_loop
|
|
|
|
|
|
|
|
exit_relocate:
|
|
|
|
rts
|