asm-glue.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <stdio.h>
  2. #include "scheme48.h"
  3. static s48_value s48_provide_asm_values(s48_value asm_vector);
  4. static s48_value s48_malloc_byte_vector(s48_value length);
  5. static s48_value s48_stob_start_address(s48_value stob);
  6. static s48_value s48_free_byte_vector(s48_value byte_vector);
  7. void
  8. s48_init_asm_glue(void)
  9. {
  10. S48_EXPORT_FUNCTION(s48_provide_asm_values);
  11. S48_EXPORT_FUNCTION(s48_malloc_byte_vector);
  12. S48_EXPORT_FUNCTION(s48_stob_start_address);
  13. S48_EXPORT_FUNCTION(s48_free_byte_vector);
  14. }
  15. static s48_value
  16. s48_provide_asm_values(s48_value asm_vector)
  17. {
  18. extern void s48_stack_gc();
  19. extern long s48_unknown_call();
  20. extern long s48_unknown_return();
  21. extern long s48_interrupt_handler();
  22. extern long s48_exception_handler();
  23. extern long s48_restart_vm();
  24. extern long s48_Sstack_limitS;
  25. /* 0 *val* */
  26. /* 1 *cont* */
  27. /* 2 *stack* */
  28. S48_VECTOR_SET(asm_vector, 3, s48_enter_fixnum((long) &s48_Sstack_limitS));
  29. S48_VECTOR_SET(asm_vector, 4, s48_enter_fixnum((long) &s48_stack_gc));
  30. /* 5 *hp* */
  31. /* 6 *heap-limit* */
  32. S48_VECTOR_SET(asm_vector, 7, s48_enter_fixnum((long) &s48_unknown_call));
  33. S48_VECTOR_SET(asm_vector, 8, s48_enter_fixnum((long) &s48_unknown_return));
  34. S48_VECTOR_SET(asm_vector, 9, s48_enter_fixnum((long) &s48_interrupt_handler));
  35. S48_VECTOR_SET(asm_vector, 10, s48_enter_fixnum((long) &s48_exception_handler));
  36. S48_VECTOR_SET(asm_vector, 11, s48_enter_fixnum((long) &s48_restart_vm));
  37. return S48_UNSPECIFIC;
  38. }
  39. /*
  40. * Make a byte-vector that is outside the heap (and thus won't be moved (or
  41. * freed) by the GC).
  42. */
  43. static s48_value
  44. s48_malloc_byte_vector(s48_value length)
  45. {
  46. int c_length = s48_extract_fixnum(length);
  47. int bytes = (c_length + 4 + 3) & -4; /* space for header + round up */
  48. char *bv = (char *)malloc(bytes);
  49. if (bv == NULL)
  50. s48_raise_out_of_memory_error();
  51. *((long *) bv) = (c_length << 8)
  52. | (S48_STOBTYPE_BYTE_VECTOR << 2)
  53. | S48_HEADER_TAG;
  54. return (s48_value) ((((long) bv) + 4) | S48_STOB_TAG);
  55. }
  56. /*
  57. * Free up a malloc'ed byte vector.
  58. */
  59. static s48_value
  60. s48_free_byte_vector(s48_value byte_vector)
  61. {
  62. if (!S48_BYTE_VECTOR_P(byte_vector))
  63. s48_raise_argument_type_error(byte_vector);
  64. free((void *) ((byte_vector & -4)- 4));
  65. return S48_UNSPECIFIC;
  66. }
  67. /*
  68. * The assembler needs to be able to get the start address of a stored
  69. * object.
  70. */
  71. static s48_value
  72. s48_stob_start_address(s48_value stob)
  73. {
  74. if (!S48_STOB_P(stob))
  75. s48_raise_argument_type_error(stob);
  76. return s48_enter_integer((long) S48_ADDRESS_AFTER_HEADER(stob, void));
  77. }