From c827b513ac5cd7e974975044496b4ef7efad5e50 Mon Sep 17 00:00:00 2001 From: scottr Date: Sat, 6 Nov 1999 23:50:29 +0000 Subject: [PATCH] Convert buffer copies to memcpy(). --- sys/arch/mac68k/dev/adb_direct.c | 88 ++++++++++++++------------------ 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/sys/arch/mac68k/dev/adb_direct.c b/sys/arch/mac68k/dev/adb_direct.c index fdd0d0e10b68..6804306c22fb 100644 --- a/sys/arch/mac68k/dev/adb_direct.c +++ b/sys/arch/mac68k/dev/adb_direct.c @@ -1,4 +1,4 @@ -/* $NetBSD: adb_direct.c,v 1.27 1999/11/06 23:44:32 scottr Exp $ */ +/* $NetBSD: adb_direct.c,v 1.28 1999/11/06 23:50:29 scottr Exp $ */ /* From: adb_direct.c 2.02 4/18/97 jpw */ @@ -443,8 +443,7 @@ switch_start: * [4], even for RTC/PRAM commands. */ /* set up data for adb_pass_up */ - for (i = 0; i <= adbInputBuffer[0]; i++) - packet.data[i] = adbInputBuffer[i]; + memcpy(packet.data, adbInputBuffer, adbInputBuffer[0] + 1); if ((adbWaiting == 1) && (adbInputBuffer[4] == adbWaitingCmd) && @@ -548,8 +547,7 @@ switch_start: adbWaitingCmd = adbOutputBuffer[2]; /* save waiting command */ } else { /* no talk, so done */ /* set up stuff for adb_pass_up */ - for (i = 0; i <= adbInputBuffer[0]; i++) - packet.data[i] = adbInputBuffer[i]; + memcpy(packet.data, adbInputBuffer, adbInputBuffer[0] + 1); packet.saveBuf = adbBuffer; packet.compRout = adbCompRout; packet.compData = adbCompData; @@ -610,7 +608,7 @@ int send_adb_cuda(u_char * in, u_char * buffer, void *compRout, void *data, int command) { - int i, s, len; + int s, len; #ifdef ADB_DEBUG if (adb_debug) @@ -655,12 +653,11 @@ send_adb_cuda(u_char * in, u_char * buffer, void *compRout, void *data, int adbOutputBuffer[1] = 0x00; /* mark as an ADB command */ adbOutputBuffer[2] = (u_char)command; /* load command */ - for (i = 1; i <= len; i++) /* copy additional output - * data, if any */ - adbOutputBuffer[2 + i] = buffer[i]; + /* copy additional output data, if any */ + memcpy(adbOutputBuffer + 3, buffer + 1, len); } else - for (i = 0; i <= (in[0] + 1); i++) - adbOutputBuffer[i] = in[i]; + /* if data ready, just copy over */ + memcpy(adbOutputBuffer, in, in[0] + 2); adbSentChars = 0; /* nothing sent yet */ adbBuffer = buffer; /* save buffer to know where to save result */ @@ -729,11 +726,13 @@ switch_start: if (adb_debug & 0x80) printf_intr("POLL-doing-out-queue. "); #endif - /* copy over data */ ADB_SET_STATE_IDLE_II(); delay(ADB_DELAY); - for (i = 0; i <= (adbOutQueue.outBuf[0] + 1); i++) - adbOutputBuffer[i] = adbOutQueue.outBuf[i]; + + /* copy over data */ + memcpy(adbOutputBuffer, adbOutQueue.outBuf, + adbOutQueue.outBuf[0] + 2); + adbBuffer = adbOutQueue.saveBuf; /* user data area */ adbCompRout = adbOutQueue.compRout; /* completion routine */ adbCompData = adbOutQueue.data; /* comp. rout. data */ @@ -744,8 +743,7 @@ switch_start: ADB_SET_SR_OUTPUT(); /* set shift register for OUT */ ADB_SR() = adbOutputBuffer[1]; /* load byte for output */ adbBusState = ADB_BUS_CMD; /* set bus to cmd state */ - ADB_SET_STATE_CMD(); /* tell ADB that we want to - * send */ + ADB_SET_STATE_CMD(); /* tell ADB that we want to send */ break; } else { #ifdef ADB_DEBUG @@ -839,8 +837,7 @@ switch_start: } /* set up data for adb_pass_up */ - for (i = 0; i <= adbInputBuffer[0]; i++) - packet.data[i] = adbInputBuffer[i]; + memcpy(packet.data, adbInputBuffer, adbInputBuffer[0] + 1); if (!adbWaiting && (adbInputBuffer[0] != 0)) { packet.unsol = 1; @@ -870,8 +867,8 @@ switch_start: printf_intr("XXX: DOING OUT QUEUE\n"); #endif /* copy over data */ - for (i = 0; i <= (adbOutQueue.outBuf[0] + 1); i++) - adbOutputBuffer[i] = adbOutQueue.outBuf[i]; + memcpy(adbOutputBuffer, adbOutQueue.outBuf, + adbOutQueue.outBuf[0] + 2); adbBuffer = adbOutQueue.saveBuf; /* user data area */ adbCompRout = adbOutQueue.compRout; /* completion routine */ adbCompData = adbOutQueue.data; /* comp. rout. data */ @@ -967,8 +964,7 @@ switch_start: printf_intr("done \n"); #endif /* set up stuff for adb_pass_up */ - for (i = 0; i <= adbOutputBuffer[0]; i++) - packet.data[i] = adbOutputBuffer[i]; + memcpy(packet.data, adbOutputBuffer, adbOutputBuffer[0] + 1); packet.saveBuf = adbBuffer; packet.compRout = adbCompRout; packet.compData = adbCompData; @@ -983,8 +979,8 @@ switch_start: adbCompData = (long)0; if (adbOutQueueHasData == 1) { /* copy over data */ - for (i = 0; i <= (adbOutQueue.outBuf[0] + 1); i++) - adbOutputBuffer[i] = adbOutQueue.outBuf[i]; + memcpy(adbOutputBuffer, adbOutQueue.outBuf, + adbOutQueue.outBuf[0] + 2); adbBuffer = adbOutQueue.saveBuf; /* user data area */ adbCompRout = adbOutQueue.compRout; /* completion routine */ adbCompData = adbOutQueue.data; /* comp. rout. data */ @@ -1058,7 +1054,7 @@ switch_start: int send_adb_II(u_char * in, u_char * buffer, void *compRout, void *data, int command) { - int i, s, len; + int s, len; if (adbActionState == ADB_ACTION_NOTREADY) /* return if ADB not * available */ @@ -1086,13 +1082,11 @@ send_adb_II(u_char * in, u_char * buffer, void *compRout, void *data, int comman adbOutQueue.outBuf[0] = 1 + len; /* command + addl. data */ adbOutQueue.outBuf[1] = (u_char)command; /* load command */ - for (i = 1; i <= len; i++) /* copy additional output - * data, if any */ - adbOutQueue.outBuf[1 + i] = buffer[i]; + /* copy additional output data, if any */ + memcpy(adbOutQueue.outBuf + 2, buffer + 1, len); } else /* if data ready, just copy over */ - for (i = 0; i <= (in[0] + 1); i++) - adbOutQueue.outBuf[i] = in[i]; + memcpy(adbOutQueue.outBuf, in, in[0] + 2); adbOutQueue.saveBuf = buffer; /* save buffer to know where to save * result */ @@ -1103,8 +1097,8 @@ send_adb_II(u_char * in, u_char * buffer, void *compRout, void *data, int comman if ((adbActionState == ADB_ACTION_IDLE) && /* is ADB available? */ (ADB_INTR_IS_OFF)) { /* and no incoming interrupts? */ /* then start command now */ - for (i = 0; i <= (adbOutQueue.outBuf[0] + 1); i++) /* copy over data */ - adbOutputBuffer[i] = adbOutQueue.outBuf[i]; + memcpy(adbOutputBuffer, adbOutQueue.outBuf, + adbOutQueue.outBuf[0] + 2); /* copy over data */ adbBuffer = adbOutQueue.saveBuf; /* pointer to user data * area */ @@ -1284,8 +1278,7 @@ switch_start: * commands */ /* set up data for adb_pass_up */ - for (i = 0; i <= adbInputBuffer[0]; i++) - packet.data[i] = adbInputBuffer[i]; + memcpy(packet.data, adbInputBuffer, adbInputBuffer[0] + 1); if ((adbWaiting == 1) && /* are we waiting AND */ (adbInputBuffer[4] == adbWaitingCmd) && /* the cmd we sent AND */ @@ -1377,8 +1370,8 @@ switch_start: adbWaitingCmd = adbOutputBuffer[2]; /* save waiting command */ } else {/* no talk, so done */ /* set up stuff for adb_pass_up */ - for (i = 0; i <= adbInputBuffer[0]; i++) - packet.data[i] = adbInputBuffer[i]; + memcpy(packet.data, adbInputBuffer, + adbInputBuffer[0] + 1); packet.saveBuf = adbBuffer; packet.compRout = adbCompRout; packet.compData = adbCompData; @@ -1444,7 +1437,7 @@ int send_adb_IIsi(u_char * in, u_char * buffer, void *compRout, void *data, int command) { - int i, s, len; + int s, len; if (adbActionState == ADB_ACTION_NOTREADY) return 1; @@ -1481,12 +1474,11 @@ send_adb_IIsi(u_char * in, u_char * buffer, void *compRout, void *data, int adbOutputBuffer[1] = 0x00; /* mark as an ADB command */ adbOutputBuffer[2] = (u_char)command; /* load command */ - for (i = 1; i <= len; i++) /* copy additional output - * data, if any */ - adbOutputBuffer[2 + i] = buffer[i]; + /* copy additional output data, if any */ + memcpy(adbOutputBuffer + 3, buffer + 1, len); } else - for (i = 0; i <= (in[0] + 1); i++) - adbOutputBuffer[i] = in[i]; + /* if data ready, just copy over */ + memcpy(adbOutputBuffer, in, in[0] + 2); adbSentChars = 0; /* nothing sent yet */ adbBuffer = buffer; /* save buffer to know where to save result */ @@ -1615,7 +1607,7 @@ send_adb_iop(int cmd, u_char * buffer, void *compRout, void *data) void adb_pass_up(struct adbCommand *in) { - int i, start = 0, len = 0, cmd = 0; + int start = 0, len = 0, cmd = 0; ADBDataBlock block; /* temp for testing */ @@ -1712,9 +1704,7 @@ adb_pass_up(struct adbCommand *in) * directly into an adbCommand struct, which is passed to * this routine, then we could eliminate this copy. */ - for (i = 1; i <= len; i++) - adbInbound[adbInTail].data[i] = in->data[start+i]; - + memcpy(adbInbound[adbInTail].data + 1, in->data + start + 1, len); adbInbound[adbInTail].data[0] = len; adbInbound[adbInTail].cmd = cmd; @@ -1743,7 +1733,7 @@ adb_pass_up(struct adbCommand *in) void adb_soft_intr(void) { - int s, i; + int s; int cmd = 0; u_char *buffer = 0; u_char *comprout = 0; @@ -1776,8 +1766,8 @@ adb_soft_intr(void) * For ack_only buffer was set to 0, so don't copy. */ if (buffer) - for (i = 0; i <= adbInbound[adbInHead].data[0]; i++) - *(buffer+i) = adbInbound[adbInHead].data[i]; + memcpy(buffer, adbInbound[adbInHead].data, + adbInbound[adbInHead].data[0] + 1); #ifdef ADB_DEBUG if (adb_debug & 0x80) {