blocks.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. /* B L O C K S T O R I N G A N D L O A D I N G */
  7. #include "lint.h"
  8. #ifndef LINT
  9. #include <em.h>
  10. #include <em_reg.h>
  11. #include "arith.h"
  12. #include "sizes.h"
  13. #include "atw.h"
  14. #include "align.h"
  15. #ifndef STB
  16. #include "label.h"
  17. #include "stack.h"
  18. #include "Lpars.h"
  19. extern arith NewLocal();
  20. #define LocalPtrVar() NewLocal(pointer_size, pointer_align, reg_pointer, REGISTER)
  21. #define LocalIntVar() NewLocal(int_size, int_align, reg_any, REGISTER)
  22. #endif /* STB */
  23. /* Because EM does not support the loading and storing of
  24. objects having other sizes than word fragment and multiple,
  25. we need to have a way of transferring these objects, whereby
  26. we simulate "loi" and "sti": the address of the source resp.
  27. destination is located on top of stack and a call is done
  28. to load_block() resp. store_block().
  29. ===============================================================
  30. # Loadblock() works on the stack as follows: ([ ] indicates the
  31. # position of the stackpointer)
  32. # lower address--->
  33. # 1) | &object
  34. # 2) | ... ATW(sz) bytes ... | sz | &stack_block | &object
  35. # 3) | ... ATW(sz) bytes ...
  36. ===============================================================
  37. Loadblock() pushes ATW(sz) bytes directly onto the stack!
  38. Store_block() works on the stack as follows:
  39. lower address--->
  40. 1) | ... ATW(sz) bytes ... | &object
  41. 2) | ... ATW(sz) bytes ... | &object | &stack_block | sz
  42. 3) <empty>
  43. If sz is a legal argument for "loi" or "sti", just one EM
  44. instruction is generated.
  45. In the other cases, the notion of alignment is taken into account:
  46. we only push an object of the size accepted by EM onto the stack,
  47. while we need a loop to store the stack block into a memory object.
  48. */
  49. suitable_sz(sz, al)
  50. arith sz;
  51. int al;
  52. {
  53. return ((int)sz % (int)word_size == 0 && al % word_align == 0) ||
  54. (
  55. word_size % sz == 0 &&
  56. (al >= (int)sz || al >= word_align)
  57. /* Lots of Irritating Stupid Parentheses */
  58. );
  59. }
  60. store_block(sz, al)
  61. arith sz;
  62. int al;
  63. {
  64. if (suitable_sz(sz, al))
  65. C_sti(sz);
  66. else {
  67. #ifndef STB
  68. arith src, dst;
  69. /* allocate two pointer temporaries */
  70. src = LocalPtrVar();
  71. dst = LocalPtrVar();
  72. /* load the addresses */
  73. StoreLocal(dst, pointer_size);
  74. C_lor((arith)1); /* push current sp */
  75. StoreLocal(src, pointer_size);
  76. copy_loop(sz, src, dst);
  77. C_asp(ATW(sz));
  78. FreeLocal(dst);
  79. FreeLocal(src);
  80. #else /* STB */
  81. /* address of destination lies on the stack */
  82. /* push address of first byte of block on stack onto
  83. the stack by computing it from the current stack
  84. pointer position
  85. */
  86. C_lor((arith)1); /* push current sp */
  87. C_adp(pointer_size); /* set & to 1st byte of block */
  88. C_loc(sz); /* number of bytes to transfer */
  89. C_cal("__stb"); /* call transfer routine */
  90. C_asp(pointer_size + pointer_size + int_size + ATW(sz));
  91. #endif /* STB */
  92. }
  93. }
  94. load_block(sz, al)
  95. arith sz;
  96. int al;
  97. {
  98. if (suitable_sz(sz, al))
  99. C_loi(sz);
  100. else {
  101. #ifndef STB
  102. arith src, dst;
  103. /* allocate two pointer temporaries */
  104. src = LocalPtrVar();
  105. dst = LocalPtrVar();
  106. StoreLocal(src, pointer_size);
  107. C_asp(-ATW(sz)); /* allocate stack block */
  108. C_lor((arith)1); /* push & of stack block as dst */
  109. StoreLocal(dst, pointer_size);
  110. copy_loop(sz, src, dst);
  111. FreeLocal(dst);
  112. FreeLocal(src);
  113. #else /* STB */
  114. arith esz = ATW(sz) - pointer_size;
  115. C_asp(-esz); /* allocate stack block */
  116. C_lor((arith)1); /* push & of stack block as dst */
  117. C_dup(pointer_size); /* fetch source address */
  118. C_adp(esz);
  119. C_loi(pointer_size);
  120. C_loc(sz); /* # bytes to copy */
  121. C_cal("__stb"); /* library copy routine */
  122. C_asp(int_size + pointer_size + pointer_size);
  123. #endif /* STB */
  124. }
  125. }
  126. copy_block(sz, al)
  127. arith sz;
  128. int al;
  129. {
  130. if (suitable_sz(sz, al))
  131. C_blm(sz);
  132. else {
  133. #ifndef STB
  134. arith src, dst;
  135. /* allocate two pointer temporaries */
  136. src = LocalPtrVar();
  137. dst = LocalPtrVar();
  138. StoreLocal(dst, pointer_size);
  139. StoreLocal(src, pointer_size);
  140. copy_loop(sz, src, dst);
  141. FreeLocal(dst);
  142. FreeLocal(src);
  143. #else /* STB */
  144. C_loc(sz); /* # bytes to copy */
  145. C_cal("__stb"); /* library copy routine */
  146. C_asp(int_size + pointer_size + pointer_size);
  147. #endif /* STB */
  148. }
  149. }
  150. #ifndef STB
  151. copy_loop(sz, src, dst)
  152. arith sz, src, dst;
  153. {
  154. /* generate inline byte-copy loop */
  155. label l_cont = text_label(), l_stop = text_label();
  156. arith tmp_sz = LocalIntVar();
  157. C_loc(sz); /* amount of bytes */
  158. StoreLocal(tmp_sz, int_size);
  159. C_df_ilb(l_cont);
  160. LoadLocal(tmp_sz, int_size);
  161. C_zle(l_stop);
  162. C_del(tmp_sz);
  163. LoadLocal(src, pointer_size);
  164. C_dup(pointer_size);
  165. C_adp((arith)1);
  166. StoreLocal(src, pointer_size);
  167. C_loi((arith)1);
  168. LoadLocal(dst, pointer_size);
  169. C_dup(pointer_size);
  170. C_adp((arith)1);
  171. StoreLocal(dst, pointer_size);
  172. C_sti((arith)1);
  173. C_bra(l_cont);
  174. C_df_ilb(l_stop);
  175. FreeLocal(tmp_sz);
  176. }
  177. #endif /* STB */
  178. #endif /* LINT */