Skip to content

Commit

Permalink
Merge branch 'devel1'
Browse files Browse the repository at this point in the history
  • Loading branch information
fautomat committed Jun 11, 2024
2 parents d5739a0 + e2fd343 commit 3623b1c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 28 deletions.
56 changes: 46 additions & 10 deletions mkstub
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ dir=$out-support
shift

if [[ "$1" == "" ]] || [[ "$out" == "" ]]; then
echo "USAGE mkstub <libname> <def file>"
echo "USAGE mkstub <libname> <def file> <object files...>"
echo "USAGE mkstub <libname> <object files...>"
exit 1
fi

if [[ "${1%%.def}" != "$1" ]]; then
if [ -f "$1" ]; then
echo "Using DEF file $1"
deffile=$1
shift
else
echo "$1 not found"
exit 1
Expand All @@ -39,12 +41,20 @@ static long __so_${out}_start[1] = {0};
void __so_${out}_open() {
${out}Base = OldOpenLibrary(\"$out.library\");
if (!${out}Base) {
FPuts(Output(), \"failed to load $out.library\n\");
FPuts(Output(), \"failed to load $out.library\\n\");
exit(10);
}
register long * a0 asm(\"a0\") = &__so_${out}_start[1];
register void * a6 asm(\"a6\") = ${out}Base;
asm volatile(\"jsr (-30,a6)\"::\"r\"(a0), \"r\"(a6));
register long d0 asm(\"d0\");
asm volatile(\"jsr (-30,a6)\": \"=r\"(d0): \"r\"(a0), \"r\"(a6));
if (d0) {
BPTR out = Output();
FPuts(out, \"can't resolve \");
FPuts(out, (char const *)d0);
FPuts(out, \"\\n\");
exit(10);
}
}
void __so_${out}_close() {
Expand All @@ -56,8 +66,16 @@ ADD2INIT(__so_${out}_open, -78); // priority one less than __initlibraries
ADD2EXIT(__so_${out}_close, -78);
"

echo >$dir/export-$out.c "
__attribute__((section(\".data.export~\")))
short __export_stubs_end = -1;
__attribute__((section(\".data.export@\")))
short __export_stubs_start = -1;
"

# get last word = var name of exported functions
(if [[ "${1%%.def}" != "$1" ]]; then cat $1; else m68k-amigaos-objdump -t $* | grep "0000 01 "; fi) | while read line; do
(if [[ "${1%%.def}" != "$deffile" ]]; then cat $deffile; else m68k-amigaos-objdump -t $* | grep "0000 01 "; fi) | while read line; do

n=$(echo $line | awk '{ print $NF }' | grep -v "___")
n=${n:1}
Expand All @@ -67,8 +85,11 @@ if [[ "${n}" == "" ]]; then
fi

text=${line##*.text}
direct=${line##*.direct}
# text segment -> function with stub
if [[ "$text" != "$line" ]]; then
if [[ "$text" != "$line" ]] || [[ "$direct" != "$line" ]] ; then

if [[ "$text" != "$line" ]] ; then

echo "create export function for ${n}"
echo >>$dir/export-$out.c "
Expand All @@ -86,15 +107,26 @@ fi
\" move.l (___save_sp:W,a4),-(sp) \n\"
\" move.l (___save_a4:W,a4),a4 \n\"
\" rts \n\");
extern void * __export_${n};
__attribute__((section(\".dlist_so_export_${n}\")))
char const * __name_${n} = \"${n}\";
__attribute__((section(\".dlist_so_export_${n}\")))
void ** __ptr_to_${n} = &__export_${n};
"


else

echo >>$dir/export-$out.c "
__attribute__((section(\".dlist_so_export_${n}\")))
char const * __name_${n} = \"${n}\";
__attribute__((section(\".dlist_so_export_${n}\")))
void ** __ptr_to_${n} = &${n};
"

fi


echo creating $dir/stub-${n}.s
echo >$dir/stub-${n}.s "| stub for ${n}
Expand All @@ -119,11 +151,11 @@ else
echo "create export variable for ${n}"
echo >>$dir/export-$out.c "
extern void * ${n};
extern void * ${n}__data;
__attribute__((section(\".dlist_so_export_${n}\")))
char const * __name_${n} = \"${n}\";
__attribute__((section(\".dlist_so_export_${n}\")))
void ** __ptr_to_${n} = (void**)&${n};
void ** __ptr_to_${n} = (void**)&${n}__data;
"

echo creating $dir/stub-${n}.s
Expand All @@ -145,8 +177,10 @@ fi

done


pushd $dir >/dev/null
echo compiling stubs

echo m68k-amigaos-gcc ${LIB_MODE} -Os -fomit-frame-pointer *stub*.s *stub*.c -c
m68k-amigaos-gcc ${LIB_MODE} -Os -fomit-frame-pointer *stub*.s *stub*.c -c

Expand All @@ -160,4 +194,6 @@ m68k-amigaos-gcc -resident -Os -fomit-frame-pointer export*.c -c

popd >/dev/null


if [[ "$*" != "" ]]; then
m68k-amigaos-gcc -shared -noixemul $* $dir/export-$out.o -o ${out}.library
fi
40 changes: 22 additions & 18 deletions sources/startup/init_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,12 @@ __LibOpen(struct Library *_masterlib asm("a6")) {
// apply datadata relocs
long *p;
asm volatile("lea ___datadata_relocs,%0" : "=r"(p));
asm volatile("lea __etext,%0" : "=r"(a4));
if (p < a4) {
long count = *p++;
long diff = (char*) &__lib - to;
while (count > 0) {
long *t = (long*) *p++;
*t -= diff;
--count;
}
long count = *p++;
long diff = (char*) &__lib - to;
while (count > 0) {
long t = (long) *p++;
*(long*)(t + to) -= diff;
--count;
}

// reload a4 for the child library
Expand Down Expand Up @@ -255,8 +252,12 @@ long __LibClose(struct Library *childLib asm("a6")) {
return r;
}


extern char __export_stubs_start;
extern char __export_stubs_end;

__regargs
void __so_xlib_init(char const *name, void **to) {
char const * __so_xlib_init(char const *name, void **to) {
long *p = &__so_xlib_export[1];
while (*p) {
char const *oname = (char const*) *p++;
Expand All @@ -269,25 +270,28 @@ void __so_xlib_init(char const *name, void **to) {
void *v = (void*) *p++;
if (0 == strcmp(name, oname)) {
*to = v;
register long * l asm("a2") = (long *)v - 1;
asm volatile("move.l a4,(%0)" :: "r"(l));
break;
if ((char *)v > &__export_stubs_start && (char *)v < &__export_stubs_end) {
register long * l asm("a2") = (long *)v - 1;
asm volatile("move.l a4,(%0)" :: "r"(l));
}
return 0;
}
}
if (!*to)
exit(10);
return name;
}

void __ResolveSymbols(long *p asm("a0"), struct Library *childLib asm("a6")) {
char const * __ResolveSymbols(long *p asm("a0"), struct Library *childLib asm("a6")) {
register long *a4 asm("a4");
asm volatile("move.l a4,-(a7)" :: "r"(a4));
asm volatile("lea 32766(a6),%0;\n" : "=r"(a4));
while (*p) {
char const * r = 0;
while (!r && *p) {
char const *name = (char const*) *p++;
void **to = (void**) *p++;
__so_xlib_init(name, to);
r = __so_xlib_init(name, to);
}
asm volatile("move.l (a7)+,a4" : "=r"(a4));
return r;
}

extern void __initlibraries();
Expand Down

0 comments on commit 3623b1c

Please sign in to comment.