📄 heap_2.lst
字号:
##############################################################################
# #
# IAR ARM ANSI C/C++ Compiler V4.30A/W32 KICKSTART 14/Dec/2005 14:41:45 #
# Copyright 1999-2005 IAR Systems. All rights reserved. #
# #
# Cpu mode = interwork #
# Endian = little #
# Stack alignment = 4 #
# Source file = D:\board\FreeRTOSV3.2.3\FreeRTOS\Source\portable\Mem #
# Mang\heap_2.c #
# Command line = D:\board\FreeRTOSV3.2.3\FreeRTOS\Source\portable\Mem #
# Mang\heap_2.c -D _NDEBUG -D STR71X_IAR -lC #
# D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\binary\List\ --diag_suppress pe191,pa082 -o #
# D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\binary\Obj\ -s9 --no_clustering --cpu_mode thumb #
# --endian little --cpu ARM7TDMI --stack_align 4 #
# --interwork -e --require_prototypes --fpu None #
# --dlib_config "C:\Program Files\IAR #
# Systems\Embedded Workbench 4.0 #
# Kickstart\arm\LIB\dl4tptinl8n.h" -I #
# D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\ -I D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR #
# 71x_IAR\library\include\ -I #
# D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\..\common\include\ -I D:\board\FreeRTOSV3.2.3\Free #
# RTOS\Demo\ARM7_STR71x_IAR\..\..\source\include\ -I #
# "C:\Program Files\IAR Systems\Embedded Workbench #
# 4.0 Kickstart\arm\INC\" #
# List file = D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\binary\List\heap_2.lst #
# Object file = D:\board\FreeRTOSV3.2.3\FreeRTOS\Demo\ARM7_STR71x_IA #
# R\binary\Obj\heap_2.r79 #
# #
# #
##############################################################################
D:\board\FreeRTOSV3.2.3\FreeRTOS\Source\portable\MemMang\heap_2.c
1 /*
2 FreeRTOS V3.2.3 - Copyright (C) 2003-2005 Richard Barry.
3
4 This file is part of the FreeRTOS distribution.
5
6 FreeRTOS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 FreeRTOS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with FreeRTOS; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 A special exception to the GPL can be applied should you wish to distribute
21 a combined work that includes FreeRTOS, without being obliged to provide
22 the source code for any proprietary components. See the licensing section
23 of http://www.FreeRTOS.org for full details of how and when the exception
24 can be applied.
25
26 ***************************************************************************
27 See http://www.FreeRTOS.org for documentation, latest information, license
28 and contact details. Please ensure to read the configuration and relevant
29 port sections of the online documentation.
30 ***************************************************************************
31 */
32
33 /*
34 * A sample implementation of pvPortMalloc() and vPortFree() that permits
35 * allocated blocks to be freed, but does not combine adjacent free blocks
36 * into a single larger block.
37 *
38 * See heap_1.c and heap_3.c for alternative implementations, and the memory
39 * management pages of http://www.FreeRTOS.org for more information.
40 */
41 #include <stdlib.h>
42
43 #include "FreeRTOS.h"
44 #include "task.h"
45
46 /* Setup the correct byte alignment mask for the defined byte alignment. */
47 #if portBYTE_ALIGNMENT == 4
48 #define heapBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0003 )
49 #endif
50
51 #if portBYTE_ALIGNMENT == 2
52 #define heapBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0001 )
53 #endif
54
55 #if portBYTE_ALIGNMENT == 1
56 #define heapBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0000 )
57 #endif
58
59 #ifndef heapBYTE_ALIGNMENT_MASK
60 #error "Invalid portBYTE_ALIGNMENT definition"
61 #endif
62
63 /* Allocate the memory for the heap. The struct is used to force byte
64 alignment without using any non-portable code. */
65 static struct xRTOS_HEAP
66 {
67 unsigned portLONG ulDummy;
68 unsigned portCHAR ucHeap[ configTOTAL_HEAP_SIZE ];
\ In segment DATA_Z, align 4, align-sorted
69 } xHeap;
\ ??xHeap:
\ 00000000 DS8 20484
70
71 /* Define the linked list structure. This is used to link free blocks in order
72 of their size. */
73 typedef struct A_BLOCK_LINK
74 {
75 struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */
76 size_t xBlockSize; /*<< The size of the free block. */
77 } xBlockLink;
78
79
80 static const unsigned portSHORT heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + ( sizeof( xBlockLink ) % portBYTE_ALIGNMENT ) );
81 #define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) )
82
83 /* Create a couple of list links to mark the start and end of the list. */
\ In segment DATA_Z, align 4, align-sorted
84 static xBlockLink xStart, xEnd;
\ ??xStart:
\ 00000000 DS8 8
\ In segment DATA_Z, align 4, align-sorted
\ ??xEnd:
\ 00000000 DS8 8
85
86 /* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */
87
88 /*
89 * Insert a block into the list of free blocks - which is ordered by size of
90 * the block. Small blocks at the start of the list and large blocks at the end
91 * of the list.
92 */
93 #define prvInsertBlockIntoFreeList( pxBlockToInsert ) \
94 { \
95 xBlockLink *pxIterator; \
96 size_t xBlockSize; \
97 \
98 xBlockSize = pxBlockToInsert->xBlockSize; \
99 \
100 /* Iterate through the list until a block is found that has a larger size */ \
101 /* than the block we are inserting. */ \
102 for( pxIterator = &xStart; pxIterator->pxNextFreeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextFreeBlock ) \
103 { \
104 /* There is nothing to do here - just iterate to the correct position. */ \
105 } \
106 \
107 /* Update the list to include the block being inserted in the correct */ \
108 /* position. */ \
109 pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; \
110 pxIterator->pxNextFreeBlock = pxBlockToInsert; \
111 }
112 /*-----------------------------------------------------------*/
113
114 #define prvHeapInit() \
115 { \
116 xBlockLink *pxFirstFreeBlock; \
117 \
118 /* xStart is used to hold a pointer to the first item in the list of free */ \
119 /* blocks. The void cast is used to prevent compiler warnings. */ \
120 xStart.pxNextFreeBlock = ( void * ) xHeap.ucHeap; \
121 xStart.xBlockSize = ( size_t ) 0; \
122 \
123 /* xEnd is used to mark the end of the list of free blocks. */ \
124 xEnd.xBlockSize = configTOTAL_HEAP_SIZE; \
125 xEnd.pxNextFreeBlock = NULL; \
126 \
127 /* To start with there is a single free block that is sized to take up the \
128 entire heap space. */ \
129 pxFirstFreeBlock = ( void * ) xHeap.ucHeap; \
130 pxFirstFreeBlock->xBlockSize = configTOTAL_HEAP_SIZE; \
131 pxFirstFreeBlock->pxNextFreeBlock = &xEnd; \
132 }
133 /*-----------------------------------------------------------*/
134
\ In segment CODE, align 4, keep-with-next
135 void *pvPortMalloc( size_t xWantedSize )
136 {
\ pvPortMalloc:
\ 00000000 F0B5 PUSH {R4-R7,LR}
\ 00000002 051C MOV R5,R0
137 xBlockLink *pxBlock, *pxPreviousBlock, *pxNewBlockLink;
138 static portBASE_TYPE xHeapHasBeenInitialised = pdFALSE;
139 void *pvReturn = NULL;
\ 00000004 0024 MOV R4,#+0
140
141 vTaskSuspendAll();
\ 00000006 ........ _BLF vTaskSuspendAll,vTaskSuspendAll??rT
142 {
143 /* If this is the first call to malloc then the heap will require
144 initialisation to setup the list of free blocks. */
145 if( xHeapHasBeenInitialised == pdFALSE )
\ 0000000A 2649 LDR R1,??pvPortMalloc_0 ;; ??xEnd
\ 0000000C A022 MOV R2,#+0xA0
\ 0000000E D201 LSL R2,R2,#+0x7 ;; #+0x5000
\ 00000010 .... LDR R0,??DataTable1 ;; ??xStart
\ 00000012 254B LDR R3,??pvPortMalloc_0+0x4 ;; ??xHeapHasBeenInitialised
\ 00000014 1E68 LDR R6,[R3, #+0]
\ 00000016 002E CMP R6,#+0
\ 00000018 09D1 BNE ??pvPortMalloc_1
146 {
147 prvHeapInit();
\ 0000001A 244E LDR R6,??pvPortMalloc_0+0x8 ;; ??xHeap
\ 0000001C 371D ADD R7,R6,#+0x4
\ 0000001E 0760 STR R7,[R0, #+0]
\ 00000020 4460 STR R4,[R0, #+0x4]
\ 00000022 4A60 STR R2,[R1, #+0x4]
\ 00000024 0C60 STR R4,[R1, #+0]
\ 00000026 B260 STR R2,[R6, #+0x8]
\ 00000028 7160 STR R1,[R6, #+0x4]
148 xHeapHasBeenInitialised = pdTRUE;
\ 0000002A 0126 MOV R6,#+0x1
\ 0000002C 1E60 STR R6,[R3, #+0]
149 }
150
151 /* The wanted size is increased so it can contain a xBlockLink
152 structure in addition to the requested amount of bytes. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -