summaryrefslogtreecommitdiffstats
path: root/main/common/cstart.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/common/cstart.c')
-rw-r--r--main/common/cstart.c163
1 files changed, 82 insertions, 81 deletions
diff --git a/main/common/cstart.c b/main/common/cstart.c
index 260c9b3..2a986eb 100644
--- a/main/common/cstart.c
+++ b/main/common/cstart.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
* Copyright (c) 2013 Alcatel-Lucent
- *
+ *
* Alcatel Lucent licenses this file to You under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. A copy of the License is contained the
@@ -21,7 +21,7 @@
* cstart.c:
* This is the first 'C' code exececuted by the processor after a reset if
* the monitor is built to boot and copy itself into RAM.
- *
+ *
* This 2-stage monitor is done with two distinct images.
* The first image (the real "boot" image) includes this cstart() code
* in place of normal start(). The make process generates the umon.c file
@@ -50,99 +50,100 @@ ulong MonStack[ROM_MONSTACKSIZE/4];
char *
memcpy(char *to,char *from,int count)
{
- char *to_copy, *end;
+ char *to_copy, *end;
- to_copy = to;
+ to_copy = to;
- /* If count is greater than 8, get fancy, else just do byte-copy... */
- if (count > 8) {
- /* Attempt to optimize the transfer here... */
- if (((int)to & 3) && ((int)from & 3)) {
- /* If from and to pointers are both unaligned to the
- * same degree then we can do a few char copies to get them
- * 4-byte aligned and then do a lot of 4-byte aligned copies.
- */
- if (((int)to & 3) == ((int)from & 3)) {
- while((int)to & 3) {
- *to++ = *from++;
- count--;
- }
- }
- /* If from and to pointers are both odd, but different, then
- * we can increment them both by 1 and do a bunch of 2-byte
- * aligned copies...
- */
- else if (((int)to & 1) && ((int)from & 1)) {
- *to++ = *from++;
- count--;
- }
- }
-
- /* If both pointers are now 4-byte aligned or 2-byte aligned,
- * take advantage of that here...
- */
- if (!((int)to & 3) && !((int)from & 3)) {
- end = to + (count & ~3);
- count = count & 3;
- while(to < end) {
- *(ulong *)to = *(ulong *)from;
- from += 4;
- to += 4;
- }
- }
- else if (!((int)to & 1) && !((int)from & 1)) {
- end = to + (count & ~1);
- count = count & 1;
- while(to < end) {
- *(ushort *)to = *(ushort *)from;
- from += 2;
- to += 2;
- }
- }
- }
+ /* If count is greater than 8, get fancy, else just do byte-copy... */
+ if(count > 8) {
+ /* Attempt to optimize the transfer here... */
+ if(((int)to & 3) && ((int)from & 3)) {
+ /* If from and to pointers are both unaligned to the
+ * same degree then we can do a few char copies to get them
+ * 4-byte aligned and then do a lot of 4-byte aligned copies.
+ */
+ if(((int)to & 3) == ((int)from & 3)) {
+ while((int)to & 3) {
+ *to++ = *from++;
+ count--;
+ }
+ }
+ /* If from and to pointers are both odd, but different, then
+ * we can increment them both by 1 and do a bunch of 2-byte
+ * aligned copies...
+ */
+ else if(((int)to & 1) && ((int)from & 1)) {
+ *to++ = *from++;
+ count--;
+ }
+ }
- if (count) {
- end = to + count;
- while(to < end)
- *to++ = *from++;
- }
- return(to_copy);
+ /* If both pointers are now 4-byte aligned or 2-byte aligned,
+ * take advantage of that here...
+ */
+ if(!((int)to & 3) && !((int)from & 3)) {
+ end = to + (count & ~3);
+ count = count & 3;
+ while(to < end) {
+ *(ulong *)to = *(ulong *)from;
+ from += 4;
+ to += 4;
+ }
+ } else if(!((int)to & 1) && !((int)from & 1)) {
+ end = to + (count & ~1);
+ count = count & 1;
+ while(to < end) {
+ *(ushort *)to = *(ushort *)from;
+ from += 2;
+ to += 2;
+ }
+ }
+ }
+
+ if(count) {
+ end = to + count;
+ while(to < end) {
+ *to++ = *from++;
+ }
+ }
+ return(to_copy);
}
void
cstart(void)
{
- register long *lp1, *lp2, *end2;
- void (*entry)();
-
- entry = (void(*)())UMON_START;
+ register long *lp1, *lp2, *end2;
+ void (*entry)();
+
+ entry = (void(*)())UMON_START;
- /* Copy image from boot flash to RAM, then verify the copy.
- * If it worked, then jump into that space; else reset and start
- * over (not much else can be done!).
- */
- memcpy((char *)UMON_RAMBASE,(char *)umon,(int)sizeof(umon));
+ /* Copy image from boot flash to RAM, then verify the copy.
+ * If it worked, then jump into that space; else reset and start
+ * over (not much else can be done!).
+ */
+ memcpy((char *)UMON_RAMBASE,(char *)umon,(int)sizeof(umon));
- /* Verify the copy...
- */
- lp1 = (long *)UMON_RAMBASE;
- lp2 = (long *)umon;
- end2 = lp2 + (int)sizeof(umon)/sizeof(long);
- while(lp2 < end2) {
- if (*lp1 != *lp2) {
+ /* Verify the copy...
+ */
+ lp1 = (long *)UMON_RAMBASE;
+ lp2 = (long *)umon;
+ end2 = lp2 + (int)sizeof(umon)/sizeof(long);
+ while(lp2 < end2) {
+ if(*lp1 != *lp2) {
#ifdef CSTART_ERROR_FUNCTION
- extern void CSTART_ERROR_FUNCTION();
+ extern void CSTART_ERROR_FUNCTION();
- CSTART_ERROR_FUNCTION(lp1,*lp1,*lp2);
+ CSTART_ERROR_FUNCTION(lp1,*lp1,*lp2);
#endif
#ifdef INLINE_RESETFUNC
- INLINE_RESETFUNC();
+ INLINE_RESETFUNC();
#else
- entry = RESETFUNC();
+ entry = RESETFUNC();
#endif
- break;
- }
- lp1++; lp2++;
- }
- entry();
+ break;
+ }
+ lp1++;
+ lp2++;
+ }
+ entry();
}