sovereignx/asm/malloc.s

340 lines
5.5 KiB
ArmAsm
Raw Normal View History

2015-10-06 13:46:30 +01:00
thumb_func_start malloc_header
2015-10-10 11:12:48 +01:00
; void malloc_header(struct memblk *blk, struct memblk *prev, struct memblk *next, u32 size)
malloc_header: ; 8000988
2015-10-06 13:46:30 +01:00
push {r4,lr}
movs r4, 0
strh r4, [r0]
ldr r4, =0x0000a3a3
strh r4, [r0, 0x2]
str r3, [r0, 0x4]
str r1, [r0, 0x8]
str r2, [r0, 0xC]
pop {r4}
pop {r0}
bx r0
.align 2, 0
.pool
thumb_func_end malloc_header
thumb_func_start malloc_unlinked_header
2015-10-10 11:12:48 +01:00
; void malloc_unlinked_header(struct memblk *blk, u32 size)
malloc_unlinked_header: ; 80009A4
2015-10-06 13:46:30 +01:00
push {lr}
adds r2, r0, 0
adds r3, r1, 0
subs r3, 0x10
adds r1, r2, 0
bl malloc_header
pop {r0}
bx r0
thumb_func_end malloc_unlinked_header
thumb_func_start malloc_core
2015-10-10 11:12:48 +01:00
; void *malloc_core(struct memblk *head, u32 size)
malloc_core: ; 80009B8
2015-10-06 13:46:30 +01:00
push {r4-r6,lr}
adds r4, r0, 0
adds r6, r4, 0
movs r0, 0x3
ands r0, r1
cmp r0, 0
2015-10-10 11:12:48 +01:00
beq @080009CC
2015-10-06 13:46:30 +01:00
lsrs r0, r1, 2
adds r0, 0x1
lsls r1, r0, 2
2015-10-10 11:12:48 +01:00
@080009CC:
2015-10-06 13:46:30 +01:00
movs r2, 0x1
2015-10-10 11:12:48 +01:00
@080009CE:
2015-10-06 13:46:30 +01:00
ldrh r0, [r4]
cmp r0, 0
2015-10-10 11:12:48 +01:00
bne @08000A0C
2015-10-06 13:46:30 +01:00
ldr r3, [r4, 0x4]
cmp r3, r1
2015-10-10 11:12:48 +01:00
bcc @08000A0C
2015-10-06 13:46:30 +01:00
subs r0, r3, r1
cmp r0, 0x1F
2015-10-10 11:12:48 +01:00
bhi @080009E4
2015-10-06 13:46:30 +01:00
strh r2, [r4]
2015-10-10 11:12:48 +01:00
b @08000A06
@080009E4:
2015-10-06 13:46:30 +01:00
subs r3, 0x10
subs r3, r1
adds r0, r1, 0
adds r0, 0x10
adds r5, r4, r0
strh r2, [r4]
str r1, [r4, 0x4]
ldr r2, [r4, 0xC]
adds r0, r5, 0
adds r1, r4, 0
bl malloc_header
str r5, [r4, 0xC]
ldr r0, [r5, 0xC]
cmp r0, r6
2015-10-10 11:12:48 +01:00
beq @08000A06
2015-10-06 13:46:30 +01:00
str r5, [r0, 0x8]
2015-10-10 11:12:48 +01:00
@08000A06:
2015-10-06 13:46:30 +01:00
adds r0, r4, 0
adds r0, 0x10
2015-10-10 11:12:48 +01:00
b @08000A18
@08000A0C:
2015-10-06 13:46:30 +01:00
ldr r0, [r4, 0xC]
cmp r0, r6
2015-10-10 11:12:48 +01:00
beq @08000A16
2015-10-06 13:46:30 +01:00
adds r4, r0, 0
2015-10-10 11:12:48 +01:00
b @080009CE
@08000A16:
2015-10-06 13:46:30 +01:00
movs r0, 0
2015-10-10 11:12:48 +01:00
@08000A18:
2015-10-06 13:46:30 +01:00
pop {r4-r6}
pop {r1}
bx r1
thumb_func_end malloc_core
thumb_func_start free_core
2015-10-10 11:12:48 +01:00
; void free_core(struct memblk *head, struct memblk *node)
free_core: ; 8000A20
2015-10-06 13:46:30 +01:00
push {r4,r5,lr}
cmp r1, 0
2015-10-10 11:12:48 +01:00
beq @08000A7C
2015-10-06 13:46:30 +01:00
adds r5, r0, 0
adds r2, r1, 0
subs r2, 0x10
movs r0, 0
strh r0, [r2]
ldr r3, [r2, 0xC]
cmp r3, r5
2015-10-10 11:12:48 +01:00
beq @08000A54
2015-10-06 13:46:30 +01:00
ldrh r4, [r3]
cmp r4, 0
2015-10-10 11:12:48 +01:00
bne @08000A54
2015-10-06 13:46:30 +01:00
ldr r0, [r2, 0x4]
adds r0, 0x10
ldr r1, [r3, 0x4]
adds r0, r1
str r0, [r2, 0x4]
strh r4, [r3, 0x2]
ldr r0, [r2, 0xC]
ldr r0, [r0, 0xC]
str r0, [r2, 0xC]
cmp r0, r5
2015-10-10 11:12:48 +01:00
beq @08000A54
2015-10-06 13:46:30 +01:00
str r2, [r0, 0x8]
2015-10-10 11:12:48 +01:00
@08000A54:
2015-10-06 13:46:30 +01:00
cmp r2, r5
2015-10-10 11:12:48 +01:00
beq @08000A7C
2015-10-06 13:46:30 +01:00
ldr r1, [r2, 0x8]
ldrh r3, [r1]
cmp r3, 0
2015-10-10 11:12:48 +01:00
bne @08000A7C
2015-10-06 13:46:30 +01:00
ldr r0, [r2, 0xC]
str r0, [r1, 0xC]
ldr r1, [r2, 0xC]
cmp r1, r5
2015-10-10 11:12:48 +01:00
beq @08000A6E
2015-10-06 13:46:30 +01:00
ldr r0, [r2, 0x8]
str r0, [r1, 0x8]
2015-10-10 11:12:48 +01:00
@08000A6E:
2015-10-06 13:46:30 +01:00
strh r3, [r2, 0x2]
ldr r0, [r2, 0x8]
ldr r1, [r0, 0x4]
adds r1, 0x10
ldr r2, [r2, 0x4]
adds r1, r2
str r1, [r0, 0x4]
2015-10-10 11:12:48 +01:00
@08000A7C:
2015-10-06 13:46:30 +01:00
pop {r4,r5}
pop {r0}
bx r0
thumb_func_end free_core
thumb_func_start malloc_core_and_clear
2015-10-10 11:12:48 +01:00
; void *malloc_core_and_clear(struct memblk *head, unsigned int size)
malloc_core_and_clear: ; 8000A84
2015-10-06 13:46:30 +01:00
push {r4,r5,lr}
sub sp, 0x4
adds r4, r1, 0
bl malloc_core
adds r5, r0, 0
cmp r5, 0
2015-10-10 11:12:48 +01:00
beq @08000AB8
2015-10-06 13:46:30 +01:00
movs r0, 0x3
ands r0, r4
cmp r0, 0
2015-10-10 11:12:48 +01:00
beq @08000AA2
2015-10-06 13:46:30 +01:00
lsrs r0, r4, 2
adds r0, 0x1
lsls r4, r0, 2
2015-10-10 11:12:48 +01:00
@08000AA2:
2015-10-06 13:46:30 +01:00
movs r0, 0
str r0, [sp]
lsls r2, r4, 9
lsrs r2, 11
movs r0, 0xA0
lsls r0, 19
orrs r2, r0
mov r0, sp
adds r1, r5, 0
bl CpuSet
2015-10-10 11:12:48 +01:00
@08000AB8:
2015-10-06 13:46:30 +01:00
adds r0, r5, 0
add sp, 0x4
pop {r4,r5}
pop {r1}
bx r1
thumb_func_end malloc_core_and_clear
thumb_func_start check_memblk_core
2015-10-10 11:12:48 +01:00
; _BOOL4 check_memblk_core(struct memblk *head, struct memblk *node)
check_memblk_core: ; 8000AC4
2015-10-06 13:46:30 +01:00
push {r4,r5,lr}
adds r5, r0, 0
adds r3, r1, 0
subs r3, 0x10
ldrh r2, [r3, 0x2]
ldr r0, =0x0000a3a3
cmp r2, r0
2015-10-10 11:12:48 +01:00
bne @08000B0A
2015-10-06 13:46:30 +01:00
ldr r0, [r3, 0xC]
ldrh r1, [r0, 0x2]
adds r4, r0, 0
cmp r1, r2
2015-10-10 11:12:48 +01:00
bne @08000B0A
2015-10-06 13:46:30 +01:00
cmp r4, r5
2015-10-10 11:12:48 +01:00
beq @08000AE8
2015-10-06 13:46:30 +01:00
ldr r0, [r4, 0x8]
cmp r0, r3
2015-10-10 11:12:48 +01:00
bne @08000B0A
@08000AE8:
2015-10-06 13:46:30 +01:00
ldr r2, [r3, 0x8]
ldrh r1, [r2, 0x2]
ldr r0, =0x0000a3a3
cmp r1, r0
2015-10-10 11:12:48 +01:00
bne @08000B0A
2015-10-06 13:46:30 +01:00
cmp r2, r5
2015-10-10 11:12:48 +01:00
beq @08000AFC
2015-10-06 13:46:30 +01:00
ldr r0, [r2, 0xC]
cmp r0, r3
2015-10-10 11:12:48 +01:00
bne @08000B0A
@08000AFC:
2015-10-06 13:46:30 +01:00
cmp r4, r5
2015-10-10 11:12:48 +01:00
beq @08000B14
2015-10-06 13:46:30 +01:00
ldr r0, [r3, 0x4]
adds r0, 0x10
adds r0, r3, r0
cmp r4, r0
2015-10-10 11:12:48 +01:00
beq @08000B14
@08000B0A:
2015-10-06 13:46:30 +01:00
movs r0, 0
2015-10-10 11:12:48 +01:00
b @08000B16
2015-10-06 13:46:30 +01:00
.align 2, 0
.pool
2015-10-10 11:12:48 +01:00
@08000B14:
2015-10-06 13:46:30 +01:00
movs r0, 0x1
2015-10-10 11:12:48 +01:00
@08000B16:
2015-10-06 13:46:30 +01:00
pop {r4,r5}
pop {r1}
bx r1
thumb_func_end check_memblk_core
thumb_func_start init_malloc
2015-10-10 11:12:48 +01:00
; void init_malloc(u32 heapStart, u32 heapSize)
init_malloc: ; 8000B1C
2015-10-06 13:46:30 +01:00
push {lr}
ldr r2, =0x03000004
str r0, [r2]
ldr r2, =0x03000008
str r1, [r2]
bl malloc_unlinked_header
pop {r0}
bx r0
.align 2, 0
.pool
thumb_func_end init_malloc
thumb_func_start malloc
2015-10-10 11:12:48 +01:00
; void *malloc(u32 size)
malloc: ; 8000B38
2015-10-06 13:46:30 +01:00
push {lr}
adds r1, r0, 0
ldr r0, =0x03000004
ldr r0, [r0]
bl malloc_core
pop {r1}
bx r1
.align 2, 0
.pool
thumb_func_end malloc
thumb_func_start malloc_and_clear
2015-10-10 11:12:48 +01:00
; void *malloc_and_clear(u32 size)
malloc_and_clear: ; 8000B4C
2015-10-06 13:46:30 +01:00
push {lr}
adds r1, r0, 0
ldr r0, =0x03000004
ldr r0, [r0]
bl malloc_core_and_clear
pop {r1}
bx r1
.align 2, 0
.pool
thumb_func_end malloc_and_clear
thumb_func_start free
2015-10-10 11:12:48 +01:00
; void free(void *ptr)
free: ; 8000B60
2015-10-06 13:46:30 +01:00
push {lr}
adds r1, r0, 0
ldr r0, =0x03000004
ldr r0, [r0]
bl free_core
pop {r0}
bx r0
.align 2, 0
.pool
thumb_func_end free
thumb_func_start check_memblk
2015-10-10 11:12:48 +01:00
; _BOOL4 check_memblk(struct memblk *node)
check_memblk: ; 8000B74
2015-10-06 13:46:30 +01:00
push {lr}
adds r1, r0, 0
ldr r0, =0x03000004
ldr r0, [r0]
bl check_memblk_core
pop {r1}
bx r1
.align 2, 0
.pool
thumb_func_end check_memblk
thumb_func_start check_all_memblks
2015-10-10 11:12:48 +01:00
; _BOOL4 check_all_memblks()
check_all_memblks: ; 8000B88
2015-10-06 13:46:30 +01:00
push {r4,r5,lr}
ldr r0, =0x03000004
ldr r4, [r0]
adds r5, r0, 0
2015-10-10 11:12:48 +01:00
@08000B90:
2015-10-06 13:46:30 +01:00
ldr r0, [r5]
adds r1, r4, 0
adds r1, 0x10
bl check_memblk_core
cmp r0, 0
2015-10-10 11:12:48 +01:00
beq @08000BB0
2015-10-06 13:46:30 +01:00
ldr r4, [r4, 0xC]
ldr r0, [r5]
cmp r4, r0
2015-10-10 11:12:48 +01:00
bne @08000B90
2015-10-06 13:46:30 +01:00
movs r0, 0x1
2015-10-10 11:12:48 +01:00
b @08000BB2
2015-10-06 13:46:30 +01:00
.align 2, 0
.pool
2015-10-10 11:12:48 +01:00
@08000BB0:
2015-10-06 13:46:30 +01:00
movs r0, 0
2015-10-10 11:12:48 +01:00
@08000BB2:
2015-10-06 13:46:30 +01:00
pop {r4,r5}
pop {r1}
bx r1
thumb_func_end check_all_memblks