root/loader/sx210is/resetcode/main.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. copy_and_restart

   1 
   2 /*
   3  * Operating system has died. Known functions will be killed
   4  * after memmove.
   5  *
   6  * Make sure stack is not used.
   7  */
   8 
   9 
  10 void __attribute__((noreturn)) copy_and_restart(void *dst_void, const void *src_void, long length) {
  11 
  12         {
  13                 char *dst = dst_void;
  14                 const char *src = src_void;
  15 
  16                 if (src < dst && dst < src + length)
  17                 {
  18                         /* Have to copy backwards */
  19                         src += length;
  20                         dst += length;
  21                         while (length--)
  22                         {
  23                                 *--dst = *--src;
  24                         }
  25                 }
  26                 else
  27                 {
  28                         while (length--)
  29                         {
  30                                 *dst++ = *src++;
  31                         }
  32                 }
  33         }
  34 
  35         asm volatile (
  36                  "MRS     R0, CPSR\n"
  37                  "BIC     R0, R0, #0x3F\n"
  38                  "ORR     R0, R0, #0xD3\n"
  39                  "MSR     CPSR, R0\n"
  40                  "LDR     R1, =0xC0200000\n"
  41                  "MVN     R0, #0\n"
  42                  "STR     R0, [R1,#0x10C]\n"
  43                  "STR     R0, [R1,#0xC]\n"
  44                  "STR     R0, [R1,#0x1C]\n"
  45                  "STR     R0, [R1,#0x2C]\n"
  46                  "STR     R0, [R1,#0x3C]\n"
  47                  "STR     R0, [R1,#0x4C]\n"
  48                  "STR     R0, [R1,#0x5C]\n"
  49                  "STR     R0, [R1,#0x6C]\n"
  50                  "STR     R0, [R1,#0x7C]\n"
  51                  "STR     R0, [R1,#0x8C]\n"
  52                  "STR     R0, [R1,#0x9C]\n"
  53                  "STR     R0, [R1,#0xAC]\n"
  54                  "STR     R0, [R1,#0xBC]\n"
  55                  "STR     R0, [R1,#0xCC]\n"
  56                  "STR     R0, [R1,#0xDC]\n"
  57                  "STR     R0, [R1,#0xEC]\n"
  58                  "CMP     R4, #7\n"
  59                  "STR     R0, [R1,#0xFC]\n"
  60                  "LDMEQFD SP!, {R4,PC}\n"
  61                  "MOV     R0, #0x78\n"
  62                  "MCR     p15, 0, R0,c1,c0\n"
  63                  "MOV     R0, #0\n"
  64                  "MCR     p15, 0, R0,c7,c10, 4\n"
  65                  "MCR     p15, 0, R0,c7,c5\n"
  66                  "MCR     p15, 0, R0,c7,c6\n"
  67                  "MOV     R0, #0x80000006\n"
  68                  "MCR     p15, 0, R0,c9,c1\n"
  69                  "MCR     p15, 0, R0,c9,c1, 1\n"
  70                  "MRC     p15, 0, R0,c1,c0\n"
  71                  "ORR     R0, R0, #0x50000\n"
  72                  "MCR     p15, 0, R0,c1,c0\n"
  73                  "LDR     R0, =0x12345678\n"
  74                  "MOV     R1, #0x80000000\n"
  75                  "STR     R0, [R1,#0xFFC]\n"
  76               // "LDR     R0, =loc_FF810000\n"
  77                  "MOV     R0, %0\n"              // new jump-vector
  78                  "LDMFD   SP!, {R4,LR}\n"
  79                  "BX      R0\n"
  80                  : : "r"(dst_void) : "memory","r0","r1","r2","r3","r4");
  81 
  82         while(1);
  83 }

/* [<][>][^][v][top][bottom][index][help] */