1 ;-------------------------------------------------------- 2 ; File Created by SDCC : free open source ANSI-C Compiler 3 ; Version 3.9.3 #11345 (Linux) 4 ;-------------------------------------------------------- 5 .module malloc 6 .optsdcc -mstm8 7 8 ;-------------------------------------------------------- 9 ; Public variables in this module 10 ;-------------------------------------------------------- 11 .globl ___sdcc_heap_init 12 .globl ___sdcc_heap_free 13 .globl _malloc 14 ;-------------------------------------------------------- 15 ; ram data 16 ;-------------------------------------------------------- 17 .area DATA 000000 18 ___sdcc_heap_free:: 000000 19 .ds 2 20 ;-------------------------------------------------------- 21 ; ram data 22 ;-------------------------------------------------------- 23 .area INITIALIZED 24 ;-------------------------------------------------------- 25 ; absolute external ram data 26 ;-------------------------------------------------------- 27 .area DABS (ABS) 28 29 ; default segment ordering for linker 30 .area HOME 31 .area GSINIT 32 .area GSFINAL 33 .area CONST 34 .area INITIALIZER 35 .area CODE 36 37 ;-------------------------------------------------------- 38 ; global & static initialisations 39 ;-------------------------------------------------------- 40 .area HOME 41 .area GSINIT 42 .area GSFINAL 43 .area GSINIT 44 ;-------------------------------------------------------- 45 ; Home 46 ;-------------------------------------------------------- 47 .area HOME 48 .area HOME 49 ;-------------------------------------------------------- 50 ; code 51 ;-------------------------------------------------------- 52 .area CODE 53 ; ../malloc.c: 65: void __sdcc_heap_init(void) 54 ; ----------------------------------------- 55 ; function __sdcc_heap_init 56 ; ----------------------------------------- 000000 57 ___sdcc_heap_init: 58 ; ../malloc.c: 67: __sdcc_heap_free = HEAP_START; 000000 AEr00r00 [ 2] 59 ldw x, #(___sdcc_heap + 0) 000003 CFu00u00 [ 2] 60 ldw ___sdcc_heap_free+0, x 61 ; ../malloc.c: 68: __sdcc_heap_free->next = HEAP_END; 000006 AEr00r00 [ 2] 62 ldw x, #___sdcc_heap_end+0 000009 72 CFu00u00 [ 5] 63 ldw [___sdcc_heap_free+0], x 64 ; ../malloc.c: 69: __sdcc_heap_free->next_free = 0; 00000D CEu00u00 [ 2] 65 ldw x, ___sdcc_heap_free+0 000010 5C [ 1] 66 incw x 000011 5C [ 1] 67 incw x 000012 6F 01 [ 1] 68 clr (0x1, x) 000014 7F [ 1] 69 clr (x) 70 ; ../malloc.c: 70: } 000015 87 [ 5] 71 retf 72 ; ../malloc.c: 75: void *malloc(size_t size) 73 ; ----------------------------------------- 74 ; function malloc 75 ; ----------------------------------------- 000016 76 _malloc: 000016 52 0C [ 2] 77 sub sp, #12 78 ; ../malloc.c: 86: if(!size || size + offsetof(struct header, next_free) < size) 000018 1E 10 [ 2] 79 ldw x, (0x10, sp) 00001A 27 06 [ 1] 80 jreq 00101$ 00001C 5C [ 1] 81 incw x 00001D 5C [ 1] 82 incw x 00001E 13 10 [ 2] 83 cpw x, (0x10, sp) 000020 24 03 [ 1] 84 jrnc 00102$ 000022 85 00101$: 86 ; ../malloc.c: 87: return(0); 000022 5F [ 1] 87 clrw x 000023 20 74 [ 2] 88 jra 00115$ 000025 89 00102$: 90 ; ../malloc.c: 88: size += offsetof(struct header, next_free); 91 ; ../malloc.c: 89: if(size < sizeof(struct header)) // Requiring a minimum size makes it easier to implement free(), and avoid memory leaks. 000025 1F 10 [ 2] 92 ldw (0x10, sp), x 000027 A3 00 04 [ 2] 93 cpw x, #0x0004 00002A 24 05 [ 1] 94 jrnc 00105$ 95 ; ../malloc.c: 90: size = sizeof(struct header); 00002C AE 00 04 [ 2] 96 ldw x, #0x0004 00002F 1F 10 [ 2] 97 ldw (0x10, sp), x 000031 98 00105$: 99 ; ../malloc.c: 92: for(h = __sdcc_heap_free, f = &__sdcc_heap_free; h; f = &(h->next_free), h = h->next_free) 000031 CEu00u00 [ 2] 100 ldw x, ___sdcc_heap_free+0 000034 1F 01 [ 2] 101 ldw (0x01, sp), x 000036 AEr00r00 [ 2] 102 ldw x, #(___sdcc_heap_free + 0) 000039 1F 03 [ 2] 103 ldw (0x03, sp), x 00003B 104 00113$: 105 ; ../malloc.c: 94: size_t blocksize = (char HEAPSPACE *)(h->next) - (char HEAPSPACE *)h; 00003B 1E 01 [ 2] 106 ldw x, (0x01, sp) 00003D 27 59 [ 1] 107 jreq 00111$ 00003F FE [ 2] 108 ldw x, (x) 000040 1F 05 [ 2] 109 ldw (0x05, sp), x 000042 90 93 [ 1] 110 ldw y, x 000044 1E 01 [ 2] 111 ldw x, (0x01, sp) 000046 1F 07 [ 2] 112 ldw (0x07, sp), x 000048 72 F2 07 [ 2] 113 subw y, (0x07, sp) 114 ; ../malloc.c: 101: newheader->next_free = h->next_free; 00004B 1E 01 [ 2] 115 ldw x, (0x01, sp) 00004D 5C [ 1] 116 incw x 00004E 5C [ 1] 117 incw x 00004F 1F 09 [ 2] 118 ldw (0x09, sp), x 119 ; ../malloc.c: 95: if(blocksize >= size) // Found free block of sufficient size. 000051 51 [ 1] 120 exgw x, y 000052 13 10 [ 2] 121 cpw x, (0x10, sp) 000054 51 [ 1] 122 exgw x, y 000055 25 36 [ 1] 123 jrc 00114$ 124 ; ../malloc.c: 97: if(blocksize >= size + sizeof(struct header)) // It is worth creating a new free block 000057 1E 10 [ 2] 125 ldw x, (0x10, sp) 000059 1C 00 04 [ 2] 126 addw x, #0x0004 00005C 1F 0B [ 2] 127 ldw (0x0b, sp), x 00005E 93 [ 1] 128 ldw x, y 00005F 13 0B [ 2] 129 cpw x, (0x0b, sp) 000061 25 1F [ 1] 130 jrc 00107$ 131 ; ../malloc.c: 99: header_t *const newheader = (header_t *const)((char HEAPSPACE *)h + size); 000063 1E 07 [ 2] 132 ldw x, (0x07, sp) 000065 72 FB 10 [ 2] 133 addw x, (0x10, sp) 134 ; ../malloc.c: 100: newheader->next = h->next; 000068 1F 0B [ 2] 135 ldw (0x0b, sp), x 00006A 16 05 [ 2] 136 ldw y, (0x05, sp) 00006C FF [ 2] 137 ldw (x), y 138 ; ../malloc.c: 101: newheader->next_free = h->next_free; 00006D 1E 0B [ 2] 139 ldw x, (0x0b, sp) 00006F 5C [ 1] 140 incw x 000070 5C [ 1] 141 incw x 000071 16 09 [ 2] 142 ldw y, (0x09, sp) 000073 90 FE [ 2] 143 ldw y, (y) 000075 FF [ 2] 144 ldw (x), y 145 ; ../malloc.c: 102: *f = newheader; 000076 1E 03 [ 2] 146 ldw x, (0x03, sp) 000078 16 0B [ 2] 147 ldw y, (0x0b, sp) 00007A FF [ 2] 148 ldw (x), y 149 ; ../malloc.c: 103: h->next = newheader; 00007B 1E 01 [ 2] 150 ldw x, (0x01, sp) 00007D 16 0B [ 2] 151 ldw y, (0x0b, sp) 00007F FF [ 2] 152 ldw (x), y 000080 20 07 [ 2] 153 jra 00108$ 000082 154 00107$: 155 ; ../malloc.c: 106: *f = h->next_free; 000082 1E 09 [ 2] 156 ldw x, (0x09, sp) 000084 FE [ 2] 157 ldw x, (x) 000085 16 03 [ 2] 158 ldw y, (0x03, sp) 000087 90 FF [ 2] 159 ldw (y), x 000089 160 00108$: 161 ; ../malloc.c: 108: return(&(h->next_free)); 000089 1E 09 [ 2] 162 ldw x, (0x09, sp) 00008B 20 0C [ 2] 163 jra 00115$ 00008D 164 00114$: 165 ; ../malloc.c: 92: for(h = __sdcc_heap_free, f = &__sdcc_heap_free; h; f = &(h->next_free), h = h->next_free) 00008D 16 09 [ 2] 166 ldw y, (0x09, sp) 00008F 17 03 [ 2] 167 ldw (0x03, sp), y 000091 1E 09 [ 2] 168 ldw x, (0x09, sp) 000093 FE [ 2] 169 ldw x, (x) 000094 1F 01 [ 2] 170 ldw (0x01, sp), x 000096 20 A3 [ 2] 171 jra 00113$ 000098 172 00111$: 173 ; ../malloc.c: 112: return(0); 000098 5F [ 1] 174 clrw x 000099 175 00115$: 176 ; ../malloc.c: 113: } 000099 5B 0C [ 2] 177 addw sp, #12 00009B 87 [ 5] 178 retf 179 .area CODE 180 .area CONST 181 .area INITIALIZER 182 .area CABS (ABS)