The Relogix translation
Note: This is a 100% automatic translation, with no human intervention or cleaning-up of the code. Relogix has automatically chosen the function prototype, has detected the use of structures and pointers, has chosen the variable names itself, and has placed the assembler comments in the translated source allowing for the re-arrangement of the code flow. Note that parameters passed to other subroutines either in registers (eg oscall_seteve) or on the stack (eg oscall_blkmove) are correctly handled.
In a real translation project, the translation could be further improved by providing user-defined header files to tune the names and types of variables, and the function prototypes. If you download the full sample translation you can see examples of this and read about the translation in detail.
/*
*************************************************************************
* echo_reply *
*************************************************************************
*
*
* ECHO_REPLY - Echo Reply received
*
* Entry : A0 -> ICMP Echo Reply message
* D1 = Length of complete datagram + header (bytes)
* D2 = Internet address of sender
*
* Parameters:
*
* unsigned long the_ping_len1 [Originally in d1; In]
* unsigned long internet_addr_sender [Originally in d2; In]
* struct icm *icmp_echo_reply_msg [Originally in a0; In]
*/
static void echo_reply (unsigned long the_ping_len1, unsigned long internet_addr_sender, struct icm *icmp_echo_reply_msg)
{
Boolean exec_no_check;
short i; /* [Originally in d3] */
Boolean is_equal; /* [Originally condition EQ] */
struct ping *next_table_entry; /* [Originally in a3] */
short packet_length; /* [Originally in d0] */
char *ping_reply; /* [Originally in a1] */
unsigned long temp_copy; /* [Originally d1 pushed on stack] */
char *the_ping_buf; /* [Originally in a2] */
unsigned long the_ping_len2; /* [Originally in d0] */
long the_ping_tim; /* [Originally in d4] */
the_ping_tim = oscall_millmid (); /* Get time reply was received
Save it in D4 */
icmp_ping_replies++;
next_table_entry = (struct ping *) &ping_table [-(long) sizeof(struct ping)];
for (i = 0; i < PINGTAB_ENTS; i++) {
temp_copy = the_ping_len1;
next_table_entry++; /* A3 -> next table entry */
/* Echo reply satisfies this request ?
Check TID of waiting task */
if (internet_addr_sender == next_table_entry->ping_tpa && next_table_entry->ping_tid != 0) {
next_table_entry->ping_tim = the_ping_tim;
/* Plug time packet was received */
the_ping_len1 -= ICM_IPH; /* Calculate length of packet data */
/* Correct length ? */
if (the_ping_len1 != next_table_entry->ping_len) {
/* Room for whole packet ? */
if (the_ping_len1 > next_table_entry->ping_len) {
the_ping_len2 = next_table_entry->ping_len;
/* No, only copy upto buffer size */
next_table_entry->ping_len = the_ping_len1;
/* Plug bad packet length */
the_ping_len1 = the_ping_len2;
/* D1 = length to copy/verify */
}
next_table_entry->ping_err |= PE_LEN;
/* Flag task that length was bad */
}
/* Check the reply packet, or maybe
copy the data ? */
if (next_table_entry->ping_flg & (PNG_CHK + PNG_COPY)) {
exec_no_check = True;
/* Verify it then ? */
if (next_table_entry->ping_flg & PNG_CHK) {
packet_length = the_ping_len1 - 1;
/* D0 = packet length
Adjust for DBRA */
the_ping_buf = next_table_entry->ping_buf;
/* A2 -> user's ping packet */
ping_reply = (char *) icmp_echo_reply_msg + ICM_IPH;
/* A1 -> ping reply */
do {
is_equal = *the_ping_buf++ == *ping_reply++;
/* Packets the same ? */
} while (is_equal && packet_length-- != 0);
if (is_equal)
exec_no_check = False;
else
next_table_entry->ping_err |= PE_CKS;
/* No ! */
}
if (exec_no_check) {
/* Copy it ? */
if (next_table_entry->ping_flg & PNG_COPY) {
the_ping_buf = next_table_entry->ping_buf;
/* A2 -> user's ping packet */
oscall_psched ();
/* Woken up with timeout since we
started processing reply ? */
if (next_table_entry->ping_tid != 0)
oscall_blkmove ((long) the_ping_len1, (char *) icmp_echo_reply_msg + ICM_IPH, the_ping_buf);
/* D0 = packet length
A1 -> ping reply
Copy the received packet */
oscall_asched ();
}
}
}
oscall_seteve (next_table_entry->ping_tid, JE_DEV);
/* Get TID of waiting task
Wake task up */
}
the_ping_len1 = temp_copy;
}
}