lib_mem_a.asm
上传用户:yj_qqy
上传日期:2017-01-28
资源大小:2911k
文件大小:12k
源码类别:

uCOS

开发平台:

C/C++

  1. ;******************************************************************************************************** ;                                               uC/LIB ;                                       CUSTOM LIBRARY MODULES ; ;                          (c) Copyright 2004-2008; Micrium, Inc.; Weston, FL ; ;               All rights reserved.  Protected by international copyright laws. ; ;               uC/LIB is provided in source form for FREE evaluation, for educational ;               use or peaceful research.  If you plan on using uC/LIB in a commercial ;               product you need to contact Micrium to properly license its use in your ;               product.  We provide ALL the source code for your convenience and to ;               help you experience uC/LIB.  The fact that the source code is provided ;               does NOT mean that you can use it without paying a licensing fee. ; ;               Knowledge of the source code may NOT be used to develop a similar product. ; ;               Please help us continue to provide the Embedded community with the finest ;               software available.  Your honesty is greatly appreciated. ;******************************************************************************************************** ;******************************************************************************************************** ; ;                                     STANDARD MEMORY OPERATIONS ; ;                                           ARM-Cortex-M3 ;                                     RealView Development Suite ;                            RealView Microcontroller Development Kit (MDK) ;                                      ARM Developer Suite (ADS) ;                                           Keil uVision ; ; Filename      : lib_mem_a.asm ; Version       : V1.25 ; Programmer(s) : JDH ;                 BAN ;******************************************************************************************************** ; Note(s)       : (1) NO compiler-supplied standard library functions are used in library or product software. ; ;                     (a) ALL standard library functions are implemented in the custom library modules : ; ;                         (1) <Custom Library Directory>lib*.* ; ;                         (2) <Custom Library Directory>Ports<cpu><compiler>lib*_a.* ; ;                               where ;                                       <Custom Library Directory>      directory path for custom library software ;                                       <cpu>                           directory name for specific processor (CPU) ;                                       <compiler>                      directory name for specific compiler ; ;                     (b) Product-specific library functions are implemented in individual products. ; ;                 (2) Assumes ARM CPU mode configured for Little Endian. ;******************************************************************************************************** ;******************************************************************************************************** ;                                           PUBLIC FUNCTIONS ;********************************************************************************************************         EXPORT  Mem_Copy ;******************************************************************************************************** ;                                      CODE GENERATION DIRECTIVES ;********************************************************************************************************         AREA |.text|, CODE, READONLY, ALIGN=2 THUMB REQUIRE8 PRESERVE8 ;$PAGE ;******************************************************************************************************** ;                                             Mem_Copy() ; ; Description : Copy data octets from one buffer to another buffer. ; ; Argument(s) : pdest       Pointer to destination memory buffer. ; ;               psrc        Pointer to source      memory buffer. ; ;               size        Number of data buffer octets to copy. ; ; Return(s)   : none. ; ; Caller(s)   : Application. ; ; Note(s)     : (1) Null copies allowed (i.e. 0-octet size). ; ;               (2) Memory buffers NOT checked for overlapping. ; ;               (3) Modulo arithmetic is used to determine whether a memory buffer starts on a 'CPU_ALIGN' ;                   address boundary. ; ;               (4) ARM Cortex-M3 processors use a subset of the ARM Thumb-2 instruction set which does ;                   NOT support 16-bit conditional branch instructions but ONLY supports 8-bit conditional  ;                   branch instructions. ; ;                   Therefore, branches exceeding 8-bit, signed, relative offsets : ; ;                   (a) CANNOT be implemented with     conditional branches; but ... ;                   (b) MUST   be implemented with non-conditional branches. ;******************************************************************************************************** ; void  Mem_Copy (void        *pdest,       ;  ==>  R0 ;                 void        *psrc,        ;  ==>  R1 ;                 CPU_SIZE_T   size)        ;  ==>  R2 Mem_Copy
  2.         CMP         R0, #0
  3.         BNE         Mem_Copy_1
  4.         BX          LR                      ; return if pdest == NULL
  5. Mem_Copy_1
  6.         CMP         R1, #0
  7.         BNE         Mem_Copy_2
  8.         BX          LR                      ; return if psrc  == NULL
  9. Mem_Copy_2
  10.         CMP         R2, #0
  11.         BNE         Mem_Copy_3
  12.         BX          LR                      ; return if size  == 0
  13. Mem_Copy_3
  14.         STMFD       SP!, {R3-R12}           ; save registers on stack
  15. ;$PAGE Chk_Align_32                                ; check if both dest & src 32-bit aligned
  16.         AND         R3, R0, #0x03
  17.         AND         R4, R1, #0x03
  18.         CMP         R3, R4
  19.         BNE         Chk_Align_16            ; not 32-bit aligned, check for 16-bit alignment
  20.         RSB         R3, R3, #0x04           ; compute 1-2-3 pre-copy bytes (to align to the next 32-bit boundary)
  21.         AND         R3, R3, #0x03
  22. Pre_Copy_1
  23.         CMP         R3, #1                  ; copy 1-2-3 bytes (to align to the next 32-bit boundary)
  24.         BCC         Copy_32_1               ; start real 32-bit copy
  25.         CMP         R2, #1                  ; check if any more data to copy         BCS         Pre_Copy_1_Cont         B           Mem_Copy_END            ;           no more data to copy (see Note #4b)
  26. Pre_Copy_1_Cont
  27.         LDRB        R4, [R1], #1
  28.         STRB        R4, [R0], #1
  29.         SUB         R3, R3, #1
  30.         SUB         R2, R2, #1
  31.         B           Pre_Copy_1
  32. Chk_Align_16                                ; check if both dest & src 16-bit aligned
  33.         AND         R3, R0, #0x01
  34.         AND         R4, R1, #0x01
  35.         CMP         R3, R4
  36.         BEQ         Pre_Copy_2
  37.         B           Copy_08_1               ; not 16-bit aligned, start 8-bit copy (see Note #4b)
  38. Pre_Copy_2
  39.         CMP         R3, #1                  ; copy 1 byte (to align to the next 16-bit boundary)
  40.         BCC         Copy_16_1               ; start real 16-bit copy
  41.         LDRB        R4, [R1], #1
  42.         STRB        R4, [R0], #1
  43.         SUB         R3, R3, #1
  44.         SUB         R2, R2, #1
  45.         B           Pre_Copy_2
  46. Copy_32_1
  47.         CMP         R2, #(04*10*09)         ; Copy 9 chunks of 10 32-bit words (360 octets per loop)
  48.         BCC         Copy_32_2
  49.         LDMIA       R1!, {R3-R12}
  50.         STMIA       R0!, {R3-R12}
  51.         LDMIA       R1!, {R3-R12}
  52.         STMIA       R0!, {R3-R12}
  53.         LDMIA       R1!, {R3-R12}
  54.         STMIA       R0!, {R3-R12}
  55.         LDMIA       R1!, {R3-R12}
  56.         STMIA       R0!, {R3-R12}
  57.         LDMIA       R1!, {R3-R12}
  58.         STMIA       R0!, {R3-R12}
  59.         LDMIA       R1!, {R3-R12}
  60.         STMIA       R0!, {R3-R12}
  61.         LDMIA       R1!, {R3-R12}
  62.         STMIA       R0!, {R3-R12}
  63.         LDMIA       R1!, {R3-R12}
  64.         STMIA       R0!, {R3-R12}
  65.         LDMIA       R1!, {R3-R12}
  66.         STMIA       R0!, {R3-R12}
  67.         SUB         R2, R2, #(04*10*09)
  68.         B           Copy_32_1
  69. Copy_32_2
  70.         CMP         R2, #(04*10*01)         ; Copy chunks of 10 32-bit words (40 octets per loop)
  71.         BCC         Copy_32_3
  72.         LDMIA       R1!, {R3-R12}
  73.         STMIA       R0!, {R3-R12}
  74.         SUB         R2, R2, #(04*10*01)
  75.         B           Copy_32_2
  76. Copy_32_3
  77.         CMP         R2, #(04*01*01)         ; Copy remaining 32-bit words
  78.         BCC         Copy_16_1
  79.         LDR         R3, [R1], #4
  80.         STR         R3, [R0], #4
  81.         SUB         R2, R2, #(04*01*01)
  82.         B           Copy_32_3
  83. ;$PAGE Copy_16_1
  84.         CMP         R2, #(02*01*16)         ; Copy chunks of 16 16-bit words (32 bytes per loop)
  85.         BCC         Copy_16_2
  86.         LDRH        R3, [R1], #2
  87.         STRH        R3, [R0], #2
  88.         LDRH        R3, [R1], #2
  89.         STRH        R3, [R0], #2
  90.         LDRH        R3, [R1], #2
  91.         STRH        R3, [R0], #2
  92.         LDRH        R3, [R1], #2
  93.         STRH        R3, [R0], #2
  94.         LDRH        R3, [R1], #2
  95.         STRH        R3, [R0], #2
  96.         LDRH        R3, [R1], #2
  97.         STRH        R3, [R0], #2
  98.         LDRH        R3, [R1], #2
  99.         STRH        R3, [R0], #2
  100.         LDRH        R3, [R1], #2
  101.         STRH        R3, [R0], #2
  102.         LDRH        R3, [R1], #2
  103.         STRH        R3, [R0], #2
  104.         LDRH        R3, [R1], #2
  105.         STRH        R3, [R0], #2
  106.         LDRH        R3, [R1], #2
  107.         STRH        R3, [R0], #2
  108.         LDRH        R3, [R1], #2
  109.         STRH        R3, [R0], #2
  110.         LDRH        R3, [R1], #2
  111.         STRH        R3, [R0], #2
  112.         LDRH        R3, [R1], #2
  113.         STRH        R3, [R0], #2
  114.         LDRH        R3, [R1], #2
  115.         STRH        R3, [R0], #2
  116.         LDRH        R3, [R1], #2
  117.         STRH        R3, [R0], #2
  118.         SUB         R2, R2, #(02*01*16)
  119.         B           Copy_16_1
  120. Copy_16_2
  121.         CMP         R2, #(02*01*01)         ; Copy remaining 16-bit words
  122.         BCC         Copy_08_1
  123.         LDRH        R3, [R1], #2
  124.         STRH        R3, [R0], #2
  125.         SUB         R2, R2, #(02*01*01)
  126.         B           Copy_16_2
  127. ;$PAGE Copy_08_1
  128.         CMP         R2, #(01*01*16)         ; Copy chunks of 16 8-bit words (16 bytes per loop)
  129.         BCC         Copy_08_2
  130.         LDRB        R3, [R1], #1
  131.         STRB        R3, [R0], #1
  132.         LDRB        R3, [R1], #1
  133.         STRB        R3, [R0], #1
  134.         LDRB        R3, [R1], #1
  135.         STRB        R3, [R0], #1
  136.         LDRB        R3, [R1], #1
  137.         STRB        R3, [R0], #1
  138.         LDRB        R3, [R1], #1
  139.         STRB        R3, [R0], #1
  140.         LDRB        R3, [R1], #1
  141.         STRB        R3, [R0], #1
  142.         LDRB        R3, [R1], #1
  143.         STRB        R3, [R0], #1
  144.         LDRB        R3, [R1], #1
  145.         STRB        R3, [R0], #1
  146.         LDRB        R3, [R1], #1
  147.         STRB        R3, [R0], #1
  148.         LDRB        R3, [R1], #1
  149.         STRB        R3, [R0], #1
  150.         LDRB        R3, [R1], #1
  151.         STRB        R3, [R0], #1
  152.         LDRB        R3, [R1], #1
  153.         STRB        R3, [R0], #1
  154.         LDRB        R3, [R1], #1
  155.         STRB        R3, [R0], #1
  156.         LDRB        R3, [R1], #1
  157.         STRB        R3, [R0], #1
  158.         LDRB        R3, [R1], #1
  159.         STRB        R3, [R0], #1
  160.         LDRB        R3, [R1], #1
  161.         STRB        R3, [R0], #1
  162.         SUB         R2, R2, #(01*01*16)
  163.         B           Copy_08_1
  164. Copy_08_2
  165.         CMP         R2, #(01*01*01)         ; Copy remaining 8-bit words
  166.         BCC         Mem_Copy_END
  167.         LDRB        R3, [R1], #1
  168.         STRB        R3, [R0], #1
  169.         SUB         R2, R2, #(01*01*01)
  170.         B           Copy_08_2
  171. Mem_Copy_END
  172.         LDMFD       SP!, {R3-R12}           ; restore registers from stack
  173.         BX          LR                      ; return
  174.         END