dynld-386.c 595 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "lib9.h"
  2. #include <a.out.h>
  3. #include <dynld.h>
  4. #define CHK(i,ntab) if((unsigned)(i)>=(ntab))return "bad relocation index"
  5. long
  6. dynmagic(void)
  7. {
  8. return DYN_MAGIC | I_MAGIC;
  9. }
  10. char*
  11. dynreloc(uchar *b, ulong p, int m, Dynsym **tab, int ntab)
  12. {
  13. int i;
  14. ulong v, *pp;
  15. p += (ulong)b;
  16. pp = (ulong*)p;
  17. v = *pp;
  18. switch(m){
  19. case 0:
  20. v += (ulong)b;
  21. break;
  22. case 1:
  23. i = v>>22;
  24. v &= 0x3fffff;
  25. CHK(i, ntab);
  26. v += tab[i]->addr;
  27. break;
  28. case 2:
  29. i = v>>22;
  30. CHK(i, ntab);
  31. v = tab[i]->addr -p-4;
  32. break;
  33. default:
  34. return "bad relocation mode";
  35. }
  36. *pp = v;
  37. return nil;
  38. }