| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | namespace factor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | enum relocation_type { | 
					
						
							| 
									
										
										
										
											2010-01-19 02:00:33 -05:00
										 |  |  | 	/* arg is a literal table index, holding a pair (symbol/dll) */ | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	RT_DLSYM, | 
					
						
							| 
									
										
										
										
											2009-05-06 20:22:22 -04:00
										 |  |  | 	/* a word or quotation's general entry point */ | 
					
						
							| 
									
										
										
										
											2010-01-18 02:51:27 -05:00
										 |  |  | 	RT_ENTRY_POINT, | 
					
						
							| 
									
										
										
										
											2009-05-06 20:22:22 -04:00
										 |  |  | 	/* a word's PIC entry point */ | 
					
						
							| 
									
										
										
										
											2010-01-18 02:51:27 -05:00
										 |  |  | 	RT_ENTRY_POINT_PIC, | 
					
						
							| 
									
										
										
										
											2009-05-06 20:22:22 -04:00
										 |  |  | 	/* a word's tail-call PIC entry point */ | 
					
						
							| 
									
										
										
										
											2010-01-18 02:51:27 -05:00
										 |  |  | 	RT_ENTRY_POINT_PIC_TAIL, | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	/* current offset */ | 
					
						
							|  |  |  | 	RT_HERE, | 
					
						
							|  |  |  | 	/* current code block */ | 
					
						
							|  |  |  | 	RT_THIS, | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 	/* data heap literal */ | 
					
						
							|  |  |  | 	RT_LITERAL, | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	/* untagged fixnum literal */ | 
					
						
							|  |  |  | 	RT_UNTAGGED, | 
					
						
							| 
									
										
										
										
											2009-05-07 15:26:08 -04:00
										 |  |  | 	/* address of megamorphic_cache_hits var */ | 
					
						
							|  |  |  | 	RT_MEGAMORPHIC_CACHE_HITS, | 
					
						
							| 
									
										
										
										
											2009-09-23 13:18:23 -04:00
										 |  |  | 	/* address of vm object */ | 
					
						
							| 
									
										
										
										
											2009-08-18 15:40:26 -04:00
										 |  |  | 	RT_VM, | 
					
						
							| 
									
										
										
										
											2009-10-14 03:06:01 -04:00
										 |  |  | 	/* value of vm->cards_offset */ | 
					
						
							|  |  |  | 	RT_CARDS_OFFSET, | 
					
						
							|  |  |  | 	/* value of vm->decks_offset */ | 
					
						
							|  |  |  | 	RT_DECKS_OFFSET, | 
					
						
							| 
									
										
										
										
											2010-04-03 20:24:33 -04:00
										 |  |  | 	/* address of exception_handler -- this exists as a separate relocation
 | 
					
						
							|  |  |  | 	type since its used in a situation where relocation arguments cannot | 
					
						
							|  |  |  | 	be passed in, and so RT_DLSYM is inappropriate (Windows only) */ | 
					
						
							|  |  |  | 	RT_EXCEPTION_HANDLER, | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | 	/* arg is a literal table index, holding a pair (symbol/dll) */ | 
					
						
							|  |  |  | 	RT_DLSYM_TOC, | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | enum relocation_class { | 
					
						
							| 
									
										
										
										
											2010-04-12 17:22:41 -04:00
										 |  |  | 	/* absolute address in a pointer-width location */ | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	RC_ABSOLUTE_CELL, | 
					
						
							| 
									
										
										
										
											2010-04-12 17:22:41 -04:00
										 |  |  | 	/* absolute address in a 4 byte location */ | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	RC_ABSOLUTE, | 
					
						
							| 
									
										
										
										
											2010-04-12 17:22:41 -04:00
										 |  |  | 	/* relative address in a 4 byte location */ | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	RC_RELATIVE, | 
					
						
							| 
									
										
										
										
											2009-05-05 21:56:23 -04:00
										 |  |  | 	/* absolute address in a PowerPC LIS/ORI sequence */ | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	RC_ABSOLUTE_PPC_2_2, | 
					
						
							| 
									
										
										
										
											2009-05-05 21:56:23 -04:00
										 |  |  | 	/* absolute address in a PowerPC LWZ instruction */ | 
					
						
							|  |  |  | 	RC_ABSOLUTE_PPC_2, | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	/* relative address in a PowerPC LWZ/STW/BC instruction */ | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | 	RC_RELATIVE_PPC_2_PC, | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	/* relative address in a PowerPC B/BL instruction */ | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | 	RC_RELATIVE_PPC_3_PC, | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 	/* relative address in an ARM B/BL instruction */ | 
					
						
							|  |  |  | 	RC_RELATIVE_ARM_3, | 
					
						
							|  |  |  | 	/* pointer to address in an ARM LDR/STR instruction */ | 
					
						
							|  |  |  | 	RC_INDIRECT_ARM, | 
					
						
							|  |  |  | 	/* pointer to address in an ARM LDR/STR instruction offset by 8 bytes */ | 
					
						
							| 
									
										
										
										
											2010-01-02 07:03:30 -05:00
										 |  |  | 	RC_INDIRECT_ARM_PC, | 
					
						
							| 
									
										
										
										
											2010-04-12 17:22:41 -04:00
										 |  |  | 	/* absolute address in a 2 byte location */ | 
					
						
							|  |  |  | 	RC_ABSOLUTE_2, | 
					
						
							|  |  |  | 	/* absolute address in a 1 byte location */ | 
					
						
							|  |  |  | 	RC_ABSOLUTE_1, | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | 	/* absolute address in a PowerPC LIS/ORI/SLDI/ORIS/ORI sequence */ | 
					
						
							|  |  |  | 	RC_ABSOLUTE_PPC_2_2_2_2, | 
					
						
							| 
									
										
										
										
											2009-05-04 05:50:24 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | static const cell rel_absolute_ppc_2_mask = 0x0000ffff; | 
					
						
							|  |  |  | static const cell rel_relative_ppc_2_mask = 0x0000fffc; | 
					
						
							|  |  |  | static const cell rel_relative_ppc_3_mask = 0x03fffffc; | 
					
						
							|  |  |  | static const cell rel_indirect_arm_mask   = 0x00000fff; | 
					
						
							|  |  |  | static const cell rel_relative_arm_3_mask = 0x00ffffff; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* code relocation table consists of a table of entries for each fixup */ | 
					
						
							| 
									
										
										
										
											2009-11-07 17:16:09 -05:00
										 |  |  | struct relocation_entry { | 
					
						
							|  |  |  | 	u32 value; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-02 01:48:41 -05:00
										 |  |  | 	explicit relocation_entry(u32 value_) : value(value_) {} | 
					
						
							| 
									
										
										
										
											2009-11-07 17:16:09 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	relocation_entry(relocation_type rel_type, | 
					
						
							|  |  |  | 		relocation_class rel_class, | 
					
						
							|  |  |  | 		cell offset) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-01-24 08:17:18 -05:00
										 |  |  | 		value = (u32)((rel_type << 28) | (rel_class << 24) | offset); | 
					
						
							| 
									
										
										
										
											2009-11-07 17:16:09 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	relocation_type rel_type() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return (relocation_type)((value & 0xf0000000) >> 28); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	relocation_class rel_class() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return (relocation_class)((value & 0x0f000000) >> 24); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cell rel_offset() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return (value & 0x00ffffff); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int number_of_parameters() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		switch(rel_type()) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		case RT_VM: | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 		case RT_DLSYM: | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | 		case RT_DLSYM_TOC: | 
					
						
							| 
									
										
										
										
											2009-11-07 17:16:09 -05:00
										 |  |  | 			return 2; | 
					
						
							| 
									
										
										
										
											2010-01-18 02:51:27 -05:00
										 |  |  | 		case RT_ENTRY_POINT: | 
					
						
							|  |  |  | 		case RT_ENTRY_POINT_PIC: | 
					
						
							|  |  |  | 		case RT_ENTRY_POINT_PIC_TAIL: | 
					
						
							| 
									
										
										
										
											2009-12-15 07:20:09 -05:00
										 |  |  | 		case RT_LITERAL: | 
					
						
							| 
									
										
										
										
											2009-12-02 05:55:48 -05:00
										 |  |  | 		case RT_HERE: | 
					
						
							| 
									
										
										
										
											2009-12-02 05:28:15 -05:00
										 |  |  | 		case RT_UNTAGGED: | 
					
						
							| 
									
										
										
										
											2009-11-07 17:16:09 -05:00
										 |  |  | 		case RT_THIS: | 
					
						
							|  |  |  | 		case RT_MEGAMORPHIC_CACHE_HITS: | 
					
						
							|  |  |  | 		case RT_CARDS_OFFSET: | 
					
						
							|  |  |  | 		case RT_DECKS_OFFSET: | 
					
						
							| 
									
										
										
										
											2010-04-03 20:24:33 -04:00
										 |  |  | 		case RT_EXCEPTION_HANDLER: | 
					
						
							| 
									
										
										
										
											2009-11-07 17:16:09 -05:00
										 |  |  | 			return 0; | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2010-04-30 21:33:42 -04:00
										 |  |  | 			critical_error("Bad rel type in number_of_parameters()",rel_type()); | 
					
						
							| 
									
										
										
										
											2009-11-07 17:16:09 -05:00
										 |  |  | 			return -1; /* Can't happen */ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-23 19:51:08 -05:00
										 |  |  | struct instruction_operand { | 
					
						
							| 
									
										
										
										
											2009-12-02 01:48:41 -05:00
										 |  |  | 	relocation_entry rel; | 
					
						
							|  |  |  | 	code_block *compiled; | 
					
						
							|  |  |  | 	cell index; | 
					
						
							| 
									
										
										
										
											2009-11-07 17:16:09 -05:00
										 |  |  | 	cell pointer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-02 01:48:41 -05:00
										 |  |  | 	instruction_operand(relocation_entry rel_, code_block *compiled_, cell index_); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	relocation_type rel_type() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return rel.rel_type(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cell rel_offset() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return rel.rel_offset(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-23 19:51:08 -05:00
										 |  |  | 	fixnum load_value_2_2(); | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | 	fixnum load_value_2_2_2_2(); | 
					
						
							| 
									
										
										
										
											2009-12-02 09:20:33 -05:00
										 |  |  | 	fixnum load_value_masked(cell mask, cell bits, cell shift); | 
					
						
							| 
									
										
										
										
											2009-11-24 20:29:59 -05:00
										 |  |  | 	fixnum load_value(cell relative_to); | 
					
						
							| 
									
										
										
										
											2009-11-23 19:51:08 -05:00
										 |  |  | 	fixnum load_value(); | 
					
						
							| 
									
										
										
										
											2009-11-27 18:05:08 -05:00
										 |  |  | 	code_block *load_code_block(cell relative_to); | 
					
						
							| 
									
										
										
										
											2009-11-25 18:20:48 -05:00
										 |  |  | 	code_block *load_code_block(); | 
					
						
							| 
									
										
										
										
											2009-11-07 17:16:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-23 19:51:08 -05:00
										 |  |  | 	void store_value_2_2(fixnum value); | 
					
						
							| 
									
										
										
										
											2011-05-20 18:11:50 -04:00
										 |  |  | 	void store_value_2_2_2_2(fixnum value); | 
					
						
							| 
									
										
										
										
											2009-12-02 09:20:33 -05:00
										 |  |  | 	void store_value_masked(fixnum value, cell mask, cell shift); | 
					
						
							| 
									
										
										
										
											2009-11-23 19:51:08 -05:00
										 |  |  | 	void store_value(fixnum value); | 
					
						
							| 
									
										
										
										
											2009-11-25 18:20:48 -05:00
										 |  |  | 	void store_code_block(code_block *compiled); | 
					
						
							| 
									
										
										
										
											2009-11-07 17:16:09 -05:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-05-02 05:04:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-04 02:46:13 -04:00
										 |  |  | } |