star/star.c
/*
** This is the function that generates a base for a given 68K PC.
**
**  Entry: 68K PC in ESI
**  Exit:  Newly calculated base in EBP
**
** Sounds like a simple lookup into the __fetch array, and in the case of
** 32-bit addresses, it is.  But for anything less, we'll need to compensate
** for potential garbage in the unused address bits, by subtracting the value
** of these unused bits from the base.  This way the full 32 bits of the PC
** are preserved, even if they're not used.
**
** The only registers which need to be "live" here are ESI and EBP.  The
** fetch region cache is updated, and bit 1 of __execinfo is set if the base
** couldn't be calculated.
*/
This is the function that generates a base for a given 68K PC.
Entry: 68K PC in ESI
Exit:  Newly calculated base in EBP

Sounds like a simple lookup into the __fetch array, and in the case of
32-bit addresses, it is.  But for anything less, we'll need to compensate
for potential garbage in the unused address bits, by subtracting the value
of these unused bits from the base.  This way the full 32 bits of the PC
are preserved, even if they're not used.

The only registers which need to be "live" here are ESI and EBP.  The
fetch region cache is updated, and bit 1 of __execinfo is set if the base
couldn't be calculated.
This is the function that generates a base for a given 68K PC . Entry : 68K PC in ESI Exit : Newly calculated base in EBP Sounds like a simple lookup into the __fetch array and in the case of 32 - bit addresses it is . But for anything less we ' ll need to compensate for potential garbage in the unused address bits by subtracting the value of these unused bits from the base . This way the full 32 bits of the PC are preserved even if they ' re not used . The only registers which need to be " live " here are ESI and EBP . The fetch region cache is updated and bit 1 of __execinfo is set if the base couldn ' t be calculated .
static void gen_basefunction(void) {
	align(16);
	emit("basefunction:\n");
	if(addressbits < 32) {
		emit("push esi\n");
		maskaddress("esi");
	}
	emit("mov ebp,[__fetch]\n");
	emit(".check:\n");
	emit("db 3Eh\n");
	emit("cmp esi,[ebp]\n");           
	emit("jb short .next\n");          
	emit("db 3Eh\n");
	emit("cmp esi,[ebp+4]\n");         
	emit("jbe short .base\n");
	emit(".next:\n");
	emit("db 3Eh\n");
	emit("cmp dword [ebp],byte -1\n"); 
	emit("je short .outofrange\n");
	emit("add ebp,byte 12\n");         
	emit("jmp short .check\n");
	emit(".outofrange:\n");
	if(addressbits < 32) emit("pop esi\n");
	emit("xor ebp,ebp\n");
	emit("mov dword[__fetch_region_start],-1\n");
	emit("mov dword[__fetch_region_end],ebp\n");
	force_context_switch();
	emit("or byte[__execinfo],2\n");
	emit("ret\n");
	emit(".base:\n");
	if(addressbits < 32) {
		emit("mov esi,[esp]\n");
		emit("and esi,%d\n", 0xFFFFFFFF << addressbits);
	}
	emit("push edx\n");
	emit("mov edx,ebp\n");
	emit("mov ebp,[edx]\n");
	if(addressbits < 32) emit("or ebp,esi\n");
	emit("mov [__fetch_region_start],ebp\n");
	emit("mov ebp,[edx+4]\n");
	if(addressbits < 32) emit("or ebp,esi\n");
	emit("mov [__fetch_region_end],ebp\n");
	emit("mov ebp,[edx+8]\n");
	emit("pop edx\n");
	if(addressbits < 32) {
		emit("sub ebp,esi\n");
		emit("pop esi\n");
	}
	emit("ret\n");
}
static void gen_basefunction ( void ) { align ( 16 ) ; emit ( " \n " ) ; if ( addressbits < 32 ) { emit ( " \n " ) ; maskaddress ( " " ) ; } emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; if ( addressbits < 32 ) emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; force_context_switch ( ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; if ( addressbits < 32 ) { emit ( " \n " ) ; emit ( " \n " , 0xFFFFFFFF << addressbits ) ; } emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; if ( addressbits < 32 ) emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; if ( addressbits < 32 ) emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; emit ( " \n " ) ; if ( addressbits < 32 ) { emit ( " \n " ) ; emit ( " \n " ) ; } emit ( " \n " ) ; }
This is the function that generates a base for a given 68K PC.
This is the function that generates a base for a given 68K PC .
/*
	** Prepare ESI by masking off unused address bits (but save it
	** first).
	*/ /* Are we smaller? */ /* Yes, go to next address */ /* Are we bigger? */ /* End of list? */ /* To the next structure */ /* Bad news... we jumped out into the weeds. */ /*
	** Dealing with addressbits < 32 again... if the unused PC bits are
	** anything but zero, then we'll need to adjust the base to
	** compensate.
	*/ /*
	** Update the fetch region cache, adding in the garbage bits where
	** applicable.
	*/ /*
		** Subtract garbage bits from the base, and restore the
		** original 32-bit PC value.
		*/