load.c 985 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /*
  6. Module: get value on stack, byte by byte
  7. Author: Ceriel J.H. Jacobs
  8. Version: $Id$
  9. */
  10. #include <m2_traps.h>
  11. #ifndef EM_WSIZE
  12. #define EM_WSIZE _EM_WSIZE
  13. #define EM_PSIZE _EM_PSIZE
  14. #endif
  15. #if EM_WSIZE==EM_PSIZE
  16. typedef unsigned pcnt;
  17. #else
  18. typedef long pcnt;
  19. #endif
  20. load(siz, addr, p)
  21. register char *addr;
  22. register pcnt siz;
  23. {
  24. /* Make sure, that a value with a size that could have been
  25. handled by the LOI instruction ends up at the same place,
  26. where it would, were the LOI instruction used.
  27. */
  28. register char *q = (char *) &p;
  29. char t[4];
  30. if (siz < EM_WSIZE && EM_WSIZE % siz == 0) {
  31. /* as long as EM_WSIZE <= 4 ... */
  32. if (siz != 2) TRP(M2_INTERNAL); /* internal error */
  33. q = &t[0];
  34. }
  35. while (siz--) *q++ = *addr++;
  36. if (q - t == 2) {
  37. *((unsigned *)(&p)) = *((unsigned short *) (&t[0]));
  38. }
  39. }