PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/microcode/cmpintmd/alpha.h

#
C Header | 717 lines | 331 code | 96 blank | 290 comment | 21 complexity | 20053391b40320e18176113991f1ba9c MD5 | raw file
Possible License(s): GPL-2.0
  1. /* -*- C -*-
  2. Copyright (C) 1992, 1993 Digital Equipment Corporation (D.E.C.)
  3. Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
  4. 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
  5. 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Massachusetts
  6. Institute of Technology
  7. This software was developed at the Digital Equipment Corporation
  8. Cambridge Research Laboratory. Permission to copy this software, to
  9. redistribute it, and to use it for any purpose is granted, subject to
  10. the following restrictions and understandings.
  11. 1. Any copy made of this software must include this copyright notice
  12. in full.
  13. 2. Users of this software agree to make their best efforts (a) to
  14. return to both the Digital Equipment Corporation Cambridge Research
  15. Lab (CRL) and the MIT Scheme project any improvements or extensions
  16. that they make, so that these may be included in future releases; and
  17. (b) to inform CRL and MIT of noteworthy uses of this software.
  18. 3. All materials developed as a consequence of the use of this
  19. software shall duly acknowledge such use, in accordance with the usual
  20. standards of acknowledging credit in academic research.
  21. 4. D.E.C. has made no warrantee or representation that the operation
  22. of this software will be error-free, and D.E.C. is under no obligation
  23. to provide any services, by way of maintenance, update, or otherwise.
  24. 5. In conjunction with products arising from the use of this material,
  25. there shall be no use of the name of the Digital Equipment Corporation
  26. nor of any adaptation thereof in any advertising, promotional, or
  27. sales literature without prior written consent from D.E.C. in each
  28. case. */
  29. /*
  30. *
  31. * Compiled code interface macros.
  32. *
  33. * See cmpint.txt for a description of these fields.
  34. *
  35. * Specialized for the Alpha
  36. */
  37. #ifndef SCM_CMPINTMD_H_INCLUDED
  38. #define SCM_CMPINTMD_H_INCLUDED
  39. /* Machine parameters to be set by the user. */
  40. /* Until cmpaux-alpha.m4 is updated. */
  41. #define CMPINT_USE_STRUCS
  42. #define PAGE_SIZE (8 * 1024)
  43. /* Processor type. Choose a number from the above list, or allocate your own.
  44. */
  45. #define COMPILER_PROCESSOR_TYPE COMPILER_ALPHA_TYPE
  46. /* Size (in long words) of the contents of a floating point register if
  47. different from a double. For example, an MC68881 saves registers
  48. in 96 bit (3 longword) blocks.
  49. #define COMPILER_TEMP_SIZE 1
  50. */
  51. /* Descriptor size.
  52. This is the size of the offset field, and of the format field.
  53. This definition probably does not need to be changed.
  54. */
  55. typedef unsigned short format_word; /* 16 bits */
  56. /* Utilities for manipulating absolute subroutine calls.
  57. On the ALPHA this is done with either
  58. BR rtarget, displacement
  59. <absolute address of destination>
  60. or
  61. JMP rtarget, closure_hook
  62. <absolute address of destination>
  63. The latter form is installed by the out-of-line code that allocates
  64. and initializes closures and execute caches. The former is
  65. generated by the GC when the closure is close enough to the
  66. destination address to fit in a branch displacement (4 megabytes).
  67. Why does EXTRACT_ABSOLUTE_ADDRESS store into the execute cache or
  68. closure? Because the GC (which calls it) assumes that if the
  69. destination is in constant space there will be no need to modify the
  70. cell, since the destination won't move. Since the Alpha uses
  71. PC-relative addressing, though, the cell needs to be updated if the
  72. cell has moved even if the destination hasn't.
  73. */
  74. #define EXTRACT_ABSOLUTE_ADDRESS(target, address) \
  75. (target) = (* ((SCHEME_OBJECT *) (((int *) address) + 1))); \
  76. /* The +1 skips over the instruction to the absolute address */ \
  77. alpha_store_absolute_address(((void *) target), ((void *) address))
  78. #define STORE_ABSOLUTE_ADDRESS(entry_point, address) \
  79. alpha_store_absolute_address (((void *) entry_point), ((void *) address))
  80. extern void alpha_store_absolute_address(void *, void *);
  81. #define opJMP 0x1A
  82. #define fnJMP 0x00
  83. #define JMP(linkage, dest, displacement) \
  84. ((opJMP << 26) | ((linkage) << 21) | \
  85. ((dest) << 16) | (fnJMP << 14) | \
  86. (((displacement)>>2) & ((1<<14)-1)))
  87. /* Compiled Code Register Conventions */
  88. /* This must match the compiler and cmpaux-alpha.m4 */
  89. #define COMP_REG_UTILITY_CODE 1
  90. #define COMP_REG_TRAMP_INDEX COMP_REG_UTILITY_CODE
  91. #define COMP_REG_STACK_POINTER 2
  92. #define COMP_REG_MEMTOP 3
  93. #define COMP_REG_FREE 4
  94. #define COMP_REG_REGISTERS 9
  95. #define COMP_REG_SCHEME_INTERFACE 10
  96. #define COMP_REG_CLOSURE_HOOK 11
  97. #define COMP_REG_LONGJUMP COMP_REG_CLOSURE_HOOK
  98. #define COMP_REG_FIRST_ARGUMENT 17
  99. #define COMP_REG_LINKAGE 26
  100. #define COMP_REG_TEMPORARY 28
  101. #define COMP_REG_ZERO 31
  102. #ifdef IN_CMPINT_C
  103. #define PC_FIELD_SIZE 21
  104. #define MAX_PC_DISPLACEMENT (1<<22)
  105. #define MIN_PC_DISPLACEMENT (-MAX_PC_DISPLACEMENT)
  106. #define opBR 0x30
  107. void
  108. alpha_store_absolute_address (void *entry_point, void *address)
  109. {
  110. extern void scheme_closure_hook (void);
  111. int *Instruction_Address = (int *) address;
  112. SCHEME_OBJECT *Addr = (SCHEME_OBJECT *) (Instruction_Address + 1);
  113. SCHEME_OBJECT *Entry_Point = (SCHEME_OBJECT *) entry_point;
  114. long offset = ((char *) Entry_Point) - ((char *) Addr);
  115. *Addr = (SCHEME_OBJECT) Entry_Point;
  116. if ((offset < MAX_PC_DISPLACEMENT) &&
  117. (offset >= MIN_PC_DISPLACEMENT))
  118. *Instruction_Address =
  119. (opBR << 26) | (COMP_REG_LINKAGE << 21) |
  120. ((offset>>2) & ((1L<<PC_FIELD_SIZE)-1));
  121. else
  122. *Instruction_Address =
  123. JMP(COMP_REG_LINKAGE, COMP_REG_LONGJUMP,
  124. (((char *) scheme_closure_hook) - ((char *) Addr)));
  125. return;
  126. }
  127. #endif
  128. /* Interrupt/GC polling. */
  129. /* Procedure entry points look like:
  130. CONTINUATIONS AND ORDINARY PROCEDURES
  131. GC_Handler: <code sequence 1> -- call interrupt handler
  132. <entry descriptor> (32 bits)
  133. label: <code sequence 2> -- test for interrupts
  134. <code for procedure>
  135. Interrupt: BR GC_Handler -- to help branch predictor in
  136. code sequences 2
  137. It is a good idea to align the GC_Handler (hence the label) so that
  138. we dual issue nicely.
  139. Code sequence 1 (call interrupt handler):
  140. LDA UTILITY_CODE,#code(ZERO)
  141. JMP LINKAGE,(SCHEME-TO-INTERFACE-JSR)
  142. Code sequence 2 (test for interrupts):
  143. CMPLT FREE,MEMTOP,temp
  144. LDQ MEMTOP, 0(BLOCK)
  145. BEQ temp,Interrupt
  146. CLOSURES
  147. <entry descriptor> (32 bits)
  148. label: <code sequence 3> -- test for interrupts
  149. merge: <code for procedure>
  150. Internal-Label:
  151. <code sequence 4> -- test for interrupts, and
  152. branch to merge: if none
  153. Interrupt: <code sequence 5> -- call interrupt handler
  154. to help branch predictor in
  155. code sequence 3
  156. Code sequence 3 (test for interrupts):
  157. ...SUBQ SP,#8,SP -- in closure object before entry
  158. SUBQ LINKAGE,#8,temp -- bump ret. addr. back to entry point
  159. CMPLT FREE,MEMTOP,temp2 -- interrupt/gc check
  160. LDQ MEMTOP,0(BLOCK) -- Fill MemTop register
  161. BIS CC_ENTRY_TYPE,temp,temp -- put tag on closure object
  162. STQ temp,0(SP) -- save closure on top of stack
  163. BEQ temp2,Interrupt -- possible interrupt ...
  164. Code sequence 4 (test for interrupts):
  165. *Note*: In most machines code sequence 3 and 4 are the same and are
  166. shared. We've carefully optimized sequence 3 for dual issue, so it
  167. differs from sequence 4. Time over space ...
  168. CMPLT FREE,MEMTOP,temp -- interrupt/gc check
  169. LDQ MEMTOP,0(BLOCK) -- Fill MemTop register
  170. BNE temp,Merge -- branch back if no interrupt
  171. Code sequence 5 (call interrupt handler):
  172. LDA UTILITY_CODE,#code(ZERO)
  173. JMP LINKAGE,(SCHEME-TO-INTERFACE)
  174. */
  175. #define INSTRUCTIONS *4 /* bytes/instruction */
  176. /* The length of code sequence 1, above */
  177. #define ENTRY_PREFIX_LENGTH (2 INSTRUCTIONS)
  178. /* Compiled closures */
  179. /* On the Alpha (byte offsets from start of closure):
  180. -16: TC_MANIFEST_CLOSURE || length of object
  181. -8 : count of entry points
  182. -4 : Format word and GC offset
  183. 0 : SUBQ SP,#8,SP
  184. +4 : BR or JMP instruction
  185. +8 : absolute target address
  186. +16: more entry points (i.e. repetitions from -8 through +8)
  187. and/or closed variables
  188. ...
  189. Note: On other machines, there is a different format used for one
  190. entry point closures and closures with more than one entry point.
  191. This is not needed on the Alpha, because we have a "wasted" 32 bit
  192. pad area in all closures.
  193. */
  194. #define CLOSURE_OFFSET_OF_FIRST_ENTRY_POINT 16
  195. /* Bytes from manifest header to SUBQ in first entry point code */
  196. /* A NOP on machines where closure entry points are aligned at object */
  197. /* boundaries, as on the Alpha. */
  198. #define ADJUST_CLOSURE_AT_CALL(entry_point, location) \
  199. do { \
  200. } while (0)
  201. /* Manifest closure entry block size.
  202. Size in bytes of a compiled closure's header excluding the
  203. TC_MANIFEST_CLOSURE header.
  204. On the Alpha this is 32 bits (one instruction) of padding, 16 bits
  205. of format_word, 16 bits of GC offset word, 2 32-bit instructions
  206. (SUBQ and JMP or BR), and a 64-bit absolute address.
  207. */
  208. #define COMPILED_CLOSURE_ENTRY_SIZE \
  209. ((1 INSTRUCTIONS) + (2*(sizeof(format_word)) + \
  210. (2 INSTRUCTIONS) + (sizeof(SCHEME_OBJECT *))))
  211. /* Override the default definition of MANIFEST_CLOSURE_END in cmpgc.h */
  212. #define MANIFEST_CLOSURE_END(start, count) \
  213. (((SCHEME_OBJECT *) (start)) \
  214. + (CHAR_TO_SCHEME_OBJECT (((count) * COMPILED_CLOSURE_ENTRY_SIZE))))
  215. /* Manifest closure entry destructuring.
  216. Given the entry point of a closure, extract the `real entry point'
  217. (the address of the real code of the procedure, ie. one indirection)
  218. from the closure.
  219. */
  220. #define EXTRACT_CLOSURE_ENTRY_ADDRESS(returned_address, entry_point) \
  221. { EXTRACT_ABSOLUTE_ADDRESS (returned_address, \
  222. (((unsigned int *) entry_point) + 1)); \
  223. }
  224. /* This is the inverse of EXTRACT_CLOSURE_ENTRY_ADDRESS.
  225. Given a closure's entry point and a code entry point, store the
  226. code entry point in the closure.
  227. */
  228. #define STORE_CLOSURE_ENTRY_ADDRESS(address_to_store, entry_point) \
  229. { STORE_ABSOLUTE_ADDRESS (address_to_store, \
  230. (((unsigned int *) entry_point) + 1)); \
  231. }
  232. /* Trampolines
  233. On the Alpha, here's a picture of a trampoline (offset in bytes
  234. from entry point)
  235. -24: MANIFEST vector header
  236. -16: NON_MARKED header
  237. - 8: 0
  238. - 4: Format word
  239. - 2: 0xC (GC Offset to start of block from .+2)
  240. Note the encoding -- divided by 2, low bit for
  241. extended distances (see OFFSET_WORD_TO_BYTE_OFFSET)
  242. 0: BIS ZERO, #index, TRAMP_INDEX
  243. 4: JMP Utility_Argument_1, (SCHEME_TO_INTERFACE)
  244. 8: trampoline dependent storage (0 - 3 objects)
  245. TRAMPOLINE_ENTRY_SIZE is the size in longwords of the machine
  246. dependent portion of a trampoline, including the GC and format
  247. headers. The code in the trampoline must store an index (used to
  248. determine which C SCHEME_UTILITY procedure to invoke) in a
  249. register, jump to "scheme_to_interface" and leave the address of
  250. the storage following the code in a standard location.
  251. TRAMPOLINE_ENTRY_POINT takes the address of the manifest vector
  252. header of a trampoline and returns the address of its first
  253. instruction.
  254. TRAMPOLINE_STORAGE takes the address of the first instruction in a
  255. trampoline (not the start of the trampoline block) and returns the
  256. address of the first storage word in the trampoline.
  257. STORE_TRAMPOLINE_ENTRY gets the address of the first instruction in
  258. the trampoline and stores the instructions. It also receives the
  259. index of the C SCHEME_UTILITY to be invoked.
  260. */
  261. #define TRAMPOLINE_ENTRY_SIZE 2
  262. #define TRAMPOLINE_ENTRY_POINT(tramp) \
  263. ((void *) (((SCHEME_OBJECT *) (tramp)) + 3))
  264. #define TRAMPOLINE_STORAGE(tramp_entry) \
  265. ((SCHEME_OBJECT *) (((char *) (tramp_entry)) + (2 INSTRUCTIONS)))
  266. #define opBIS 0x11
  267. #define opSUBQ 0x10
  268. #define funcBIS 0x20
  269. #define funcSUBQ 0x29
  270. #define constantBIS(source, constant, target) \
  271. ((opBIS << 26) | ((source) << 21) | \
  272. ((constant) << 13) | (1 << 12) | (funcBIS << 5) | (target))
  273. #define constantSUBQ(source, constant, target) \
  274. ((opSUBQ << 26) | ((source) << 21) | \
  275. ((constant) << 13) | (1 << 12) | (funcSUBQ << 5) | (target))
  276. #define STORE_TRAMPOLINE_ENTRY(entry_address, index) \
  277. { unsigned int *PC; \
  278. extern void scheme_to_interface(void); \
  279. PC = ((unsigned int *) (entry_address)); \
  280. *PC++ = constantBIS(COMP_REG_ZERO, index, COMP_REG_TRAMP_INDEX);\
  281. *PC = JMP(COMP_REG_FIRST_ARGUMENT, \
  282. COMP_REG_SCHEME_INTERFACE, \
  283. (((char *) scheme_to_interface) - \
  284. ((char *) (PC+1)))); \
  285. PC += 1; \
  286. }
  287. /* Execute cache entries.
  288. Execute cache entry size in longwords. The cache itself
  289. contains both the number of arguments provided by the caller and
  290. code to jump to the destination address. Before linkage, the cache
  291. contains the callee's name instead of the jump code.
  292. On Alpha: 2 machine words (64 bits each).
  293. */
  294. #define EXECUTE_CACHE_ENTRY_SIZE 2
  295. /* Execute cache destructuring. */
  296. /* Given a target location and the address of the first word of an
  297. execute cache entry, extract from the cache cell the number of
  298. arguments supplied by the caller and store it in target. */
  299. /* For the Alpha, addresses in bytes from the start of the cache:
  300. Before linking
  301. +0: number of supplied arguments, +1
  302. +4: TC_FIXNUM | 0
  303. +8: TC_SYMBOL || symbol address
  304. After linking
  305. +0: number of supplied arguments, +1
  306. +4: BR or JMP instruction
  307. +8: absolute target address
  308. */
  309. #define EXTRACT_EXECUTE_CACHE_ARITY(target, address) \
  310. (target) = ((long) (((unsigned int *) (address)) [0]))
  311. #define EXTRACT_EXECUTE_CACHE_SYMBOL(target, address) \
  312. (target) = ((SCHEME_OBJECT *) (address))[1]
  313. /* Extract the target address (not the code to get there) from an
  314. execute cache cell.
  315. */
  316. #define EXTRACT_EXECUTE_CACHE_ADDRESS(target, address) \
  317. { \
  318. EXTRACT_ABSOLUTE_ADDRESS (target, (((unsigned int *)address)+1)); \
  319. }
  320. /* This is the inverse of EXTRACT_EXECUTE_CACHE_ADDRESS.
  321. */
  322. #define STORE_EXECUTE_CACHE_ADDRESS(address, entry) \
  323. { \
  324. STORE_ABSOLUTE_ADDRESS (entry, (((unsigned int *)address)+1)); \
  325. }
  326. /* This stores the fixed part of the instructions leaving the
  327. destination address and the number of arguments intact. These are
  328. split apart so the GC can call EXTRACT/STORE...ADDRESS but it does
  329. NOT need to store the instructions back. On this architecture the
  330. instructions may change due to GC and thus STORE_EXECUTE_CACHE_CODE
  331. is a no-op; all of the work is done by STORE_EXECUTE_CACHE_ADDRESS
  332. instead.
  333. */
  334. #define STORE_EXECUTE_CACHE_CODE(address) { }
  335. /* This flushes the Scheme portion of the I-cache.
  336. It is used after a GC or disk-restore.
  337. It's needed because the GC has moved code around, and closures
  338. and execute cache cells have absolute addresses that the
  339. processor might have old copies of.
  340. */
  341. extern long Synchronize_Caches(void);
  342. extern void Flush_I_Cache(void);
  343. #if 1
  344. #define FLUSH_I_CACHE() ((void) Synchronize_Caches())
  345. #else
  346. #define FLUSH_I_CACHE() (Flush_I_Cache())
  347. #endif
  348. /* This flushes a region of the I-cache.
  349. It is used after updating an execute cache while running.
  350. Not needed during GC because FLUSH_I_CACHE will be used.
  351. */
  352. #define FLUSH_I_CACHE_REGION(address, nwords) FLUSH_I_CACHE()
  353. #define PUSH_D_CACHE_REGION(address, nwords) FLUSH_I_CACHE()
  354. #define SPLIT_CACHES
  355. #ifdef IN_CMPINT_C
  356. #include <sys/mman.h>
  357. #include <sys/types.h>
  358. #define VM_PROT_SCHEME (PROT_READ | PROT_WRITE | PROT_EXEC)
  359. #define ASM_RESET_HOOK() interface_initialize((void *) &utility_table[0])
  360. #define REGBLOCK_EXTRA_SIZE 8 /* See lapgen.scm */
  361. #define COMPILER_REGBLOCK_N_FIXED 16
  362. #define REGBLOCK_FIRST_EXTRA COMPILER_REGBLOCK_N_FIXED
  363. #define REGBLOCK_ADDRESS_OF_STACK_POINTER REGBLOCK_FIRST_EXTRA
  364. #define REGBLOCK_ADDRESS_OF_FREE REGBLOCK_FIRST_EXTRA+1
  365. #define REGBLOCK_ADDRESS_OF_UTILITY_TABLE REGBLOCK_FIRST_EXTRA+2
  366. #define REGBLOCK_ALLOCATE_CLOSURE REGBLOCK_FIRST_EXTRA+3
  367. #define REGBLOCK_DIVQ REGBLOCK_FIRST_EXTRA+4
  368. #define REGBLOCK_REMQ REGBLOCK_FIRST_EXTRA+5
  369. #define COMPILER_REGBLOCK_N_TEMPS 256
  370. void *
  371. alpha_heap_malloc (long Size)
  372. { int pagesize;
  373. caddr_t Heap_Start_Page;
  374. void *Area;
  375. pagesize = getpagesize();
  376. Area = (void *) malloc(Size+pagesize);
  377. if (Area==NULL) return Area;
  378. Heap_Start_Page =
  379. ((caddr_t) (((((long) Area)+(pagesize-1)) /
  380. pagesize) *
  381. pagesize));
  382. if (mprotect (Heap_Start_Page, Size, VM_PROT_SCHEME) == -1)
  383. { perror("compiler_reset: unable to change protection for Heap");
  384. fprintf(stderr, "mprotect(0x%lx, %d (0x%lx), 0x%lx)\n",
  385. Heap_Start_Page, Size, Size, VM_PROT_SCHEME);
  386. Microcode_Termination (TERM_EXIT);
  387. /*NOTREACHED*/
  388. }
  389. return (void *) Heap_Start_Page;
  390. }
  391. /* ASSUMPTION: Direct mapped first level cache, with
  392. shared secondary caches. Sizes in bytes.
  393. */
  394. #define DCACHE_SIZE (8*1024)
  395. #define DCACHE_LINE_SIZE 32
  396. #define WRITE_BUFFER_SIZE (4*DCACHE_LINE_SIZE)
  397. long
  398. Synchronize_Caches (void)
  399. { long Foo=0;
  400. Flush_I_Cache();
  401. { static volatile long Fake_Out[WRITE_BUFFER_SIZE/(sizeof (long))];
  402. volatile long *Ptr, *End, i=0;
  403. for (End = &(Fake_Out[WRITE_BUFFER_SIZE/(sizeof (long))]),
  404. Ptr = &(Fake_Out[0]);
  405. Ptr < End;
  406. Ptr += DCACHE_LINE_SIZE/(sizeof (long)))
  407. { Foo += *Ptr;
  408. *Ptr = Foo;
  409. i += 1;
  410. }
  411. }
  412. #if 0
  413. { static volatile long Fake_Out[DCACHE_SIZE/(sizeof (long))];
  414. volatile long *Ptr, *End;
  415. for (End = &(Fake_Out[DCACHE_SIZE/(sizeof (long))]),
  416. Ptr = &(Fake_Out[0]);
  417. Ptr < End;
  418. Ptr += DCACHE_LINE_SIZE/(sizeof (long)))
  419. Foo += *Ptr;
  420. }
  421. #endif
  422. return Foo;
  423. }
  424. extern char *allocate_closure(long, char *);
  425. static void
  426. interface_initialize (void * table)
  427. { extern void __divq();
  428. extern void __remq();
  429. Registers[REGBLOCK_ADDRESS_OF_STACK_POINTER] =
  430. ((SCHEME_OBJECT) &stack_pointer);
  431. Registers[REGBLOCK_ADDRESS_OF_FREE] =
  432. ((SCHEME_OBJECT) &Free);
  433. Registers[REGBLOCK_ADDRESS_OF_UTILITY_TABLE] =
  434. ((SCHEME_OBJECT) table);
  435. Registers[REGBLOCK_ALLOCATE_CLOSURE] =
  436. ((SCHEME_OBJECT) allocate_closure);
  437. Registers[REGBLOCK_DIVQ] = ((SCHEME_OBJECT) __divq);
  438. Registers[REGBLOCK_REMQ] = ((SCHEME_OBJECT) __remq);
  439. return;
  440. }
  441. #define CLOSURE_ENTRY_WORDS \
  442. (COMPILED_CLOSURE_ENTRY_SIZE / (sizeof (SCHEME_OBJECT)))
  443. static long closure_chunk = (1024 * CLOSURE_ENTRY_WORDS);
  444. static long last_chunk_size;
  445. char *
  446. allocate_closure (long size, char *this_block)
  447. /* size in Scheme objects of the block we need to allocate.
  448. this_block is a pointer to the first entry point in the block we
  449. didn't manage to allocate.
  450. */
  451. { long space;
  452. SCHEME_OBJECT *free_closure, *limit;
  453. free_closure = (SCHEME_OBJECT *)
  454. (this_block-CLOSURE_OFFSET_OF_FIRST_ENTRY_POINT);
  455. limit = GET_CLOSURE_SPACE;
  456. space = limit - free_closure;
  457. if (size > space)
  458. { SCHEME_OBJECT *ptr;
  459. unsigned int *wptr;
  460. /* Clear remaining words from last chunk so that the heap can be scanned
  461. forward.
  462. */
  463. if (space > 0)
  464. { for (ptr = free_closure; ptr < limit; ptr++) *ptr = SHARP_F;
  465. /* We can reformat the closures (from JMPs to BRs) using
  466. last_chunk_size. The start of the area is
  467. (limit - last_chunk_size), and all closures are contiguous
  468. and have appropriate headers.
  469. */
  470. }
  471. free_closure = Free;
  472. if ((size <= closure_chunk) && (!GC_NEEDED_P (closure_chunk)))
  473. { limit = (free_closure + closure_chunk);
  474. }
  475. else
  476. { if (GC_NEEDED_P (size))
  477. { if ((heap_end - Free) < size)
  478. { /* No way to back out -- die. */
  479. fprintf (stderr, "\nC_allocate_closure (%d): No space.\n", size);
  480. Microcode_Termination (TERM_NO_SPACE);
  481. /* NOTREACHED */
  482. }
  483. REQUEST_GC (0);
  484. }
  485. else if (size <= closure_chunk)
  486. { REQUEST_GC (0);
  487. }
  488. limit = (free_closure + size);
  489. }
  490. Free = limit;
  491. last_chunk_size = limit-free_closure; /* For next time, maybe. */
  492. for (wptr = (unsigned int *) free_closure;
  493. wptr < (unsigned int *) limit;)
  494. { extern void scheme_closure_hook (void);
  495. *wptr++ = constantSUBQ (COMP_REG_STACK_POINTER,
  496. 8,
  497. COMP_REG_STACK_POINTER);
  498. *wptr = JMP(COMP_REG_LINKAGE, COMP_REG_LONGJUMP,
  499. (((char *) scheme_closure_hook) -
  500. ((char *) (wptr + 1))));
  501. wptr += 1;
  502. }
  503. PUSH_D_CACHE_REGION (free_closure, last_chunk_size);
  504. SET_CLOSURE_SPACE (limit);
  505. }
  506. SET_CLOSURE_FREE (free_closure + size);
  507. return (((char *) free_closure)+CLOSURE_OFFSET_OF_FIRST_ENTRY_POINT);
  508. }
  509. #endif /* IN_CMPINT_C */
  510. /* Derived parameters and macros.
  511. These macros expect the above definitions to be meaningful.
  512. If they are not, the macros below may have to be changed as well.
  513. */
  514. #define COMPILED_ENTRY_OFFSET_WORD(entry) (((format_word *) (entry)) [-1])
  515. #define COMPILED_ENTRY_FORMAT_WORD(entry) (((format_word *) (entry)) [-2])
  516. /* The next one assumes 2's complement integers....*/
  517. #define CLEAR_LOW_BIT(word) ((word) & ((unsigned long) -2))
  518. #define OFFSET_WORD_CONTINUATION_P(word) (((word) & 1) != 0)
  519. #define BYTE_OFFSET_TO_OFFSET_WORD(offset) ((offset) >> 1)
  520. #define OFFSET_WORD_TO_BYTE_OFFSET(word) ((CLEAR_LOW_BIT (word)) << 1)
  521. #define MAKE_OFFSET_WORD(entry, block, continue) \
  522. ((BYTE_OFFSET_TO_OFFSET_WORD(((char *) (entry)) - \
  523. ((char *) (block)))) | \
  524. ((continue) ? 1 : 0))
  525. #if (EXECUTE_CACHE_ENTRY_SIZE == 2)
  526. #define EXECUTE_CACHE_COUNT_TO_ENTRIES(count) \
  527. ((count) >> 1)
  528. #define EXECUTE_CACHE_ENTRIES_TO_COUNT(entries) \
  529. ((entries) << 1)
  530. #endif
  531. #if (EXECUTE_CACHE_ENTRY_SIZE == 4)
  532. #define EXECUTE_CACHE_COUNT_TO_ENTRIES(count) \
  533. ((count) >> 2)
  534. #define EXECUTE_CACHE_ENTRIES_TO_COUNT(entries) \
  535. ((entries) << 2)
  536. #endif
  537. #if (!defined(EXECUTE_CACHE_COUNT_TO_ENTRIES))
  538. #define EXECUTE_CACHE_COUNT_TO_ENTRIES(count) \
  539. ((count) / EXECUTE_CACHE_ENTRY_SIZE)
  540. #define EXECUTE_CACHE_ENTRIES_TO_COUNT(entries) \
  541. ((entries) * EXECUTE_CACHE_ENTRY_SIZE)
  542. #endif
  543. /* The first entry in a cc block is preceeded by 2 headers (block and nmv),
  544. a format word and a gc offset word. See the early part of the
  545. TRAMPOLINE picture, above.
  546. */
  547. #define CC_BLOCK_FIRST_ENTRY_OFFSET \
  548. (2 * ((sizeof(SCHEME_OBJECT)) + (sizeof(format_word))))
  549. /* Format words */
  550. #define FORMAT_BYTE_EXPR 0xFF
  551. #define FORMAT_BYTE_COMPLR 0xFE
  552. #define FORMAT_BYTE_CMPINT 0xFD
  553. #define FORMAT_BYTE_DLINK 0xFC
  554. #define FORMAT_BYTE_RETURN 0xFB
  555. #define FORMAT_WORD_EXPR (MAKE_FORMAT_WORD(0xFF, FORMAT_BYTE_EXPR))
  556. #define FORMAT_WORD_CMPINT (MAKE_FORMAT_WORD(0xFF, FORMAT_BYTE_CMPINT))
  557. #define FORMAT_WORD_RETURN (MAKE_FORMAT_WORD(0xFF, FORMAT_BYTE_RETURN))
  558. /* This assumes that a format word is at least 16 bits,
  559. and the low order field is always 8 bits.
  560. */
  561. #define MAKE_FORMAT_WORD(field1, field2) \
  562. (((field1) << 8) | ((field2) & 0xff))
  563. #define SIGN_EXTEND_FIELD(field, size) \
  564. (((field) & ((1 << (size)) - 1)) | \
  565. ((((field) & (1 << ((size) - 1))) == 0) ? 0 : \
  566. ((-1) << (size))))
  567. #define FORMAT_WORD_LOW_BYTE(word) \
  568. (SIGN_EXTEND_FIELD ((((unsigned long) (word)) & 0xff), 8))
  569. #define FORMAT_WORD_HIGH_BYTE(word) \
  570. (SIGN_EXTEND_FIELD \
  571. ((((unsigned long) (word)) >> 8), \
  572. (((sizeof (format_word)) * CHAR_BIT) - 8)))
  573. #define COMPILED_ENTRY_FORMAT_HIGH(addr) \
  574. (FORMAT_WORD_HIGH_BYTE (COMPILED_ENTRY_FORMAT_WORD (addr)))
  575. #define COMPILED_ENTRY_FORMAT_LOW(addr) \
  576. (FORMAT_WORD_LOW_BYTE (COMPILED_ENTRY_FORMAT_WORD (addr)))
  577. #define FORMAT_BYTE_FRAMEMAX 0x7f
  578. #define COMPILED_ENTRY_MAXIMUM_ARITY COMPILED_ENTRY_FORMAT_LOW
  579. #define COMPILED_ENTRY_MINIMUM_ARITY COMPILED_ENTRY_FORMAT_HIGH
  580. #endif /* !SCM_CMPINTMD_H_INCLUDED */