summaryrefslogtreecommitdiff
path: root/lib/libc/arch/powerpc/sys/brk.S
blob: df371c2d9eba8b44a66c9760b7016685d1895ae7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "SYS.h"

	.extern _ASM_LABEL(__curbrk)
	.extern _C_LABEL(end)

PREFIX2(brk,break)
	
	/* check >= _end, if not make the call for _end */
#ifndef PIC
	addis 5,0,_C_LABEL(end)@h
	ori  5,5,_C_LABEL(end)@l		/* # 5 = &_end */
#else
	mflr	10
	bl	_GLOBAL_OFFSET_TABLE_@local-4
	mflr	9
	mtlr	10
	lwz	5,_C_LABEL(end)@got(9)
#endif
	cmpw	3,5
	bge+	.L_brk_call
	mr	3, 5

.L_brk_call:
	mr	7, 3
	/* call break(size) */
#ifndef PIC
	addis	6, 0, _ASM_LABEL(__curbrk)@H
	ori	6, 6, _ASM_LABEL(__curbrk)@L	/* # 6 = &__curbrk */
#else
	lwz	6,_ASM_LABEL(__curbrk)@got(9)
#endif

	sc

	/* check for error */
	cmpwi	0, 0
	beq+	.L_brk_ok	/* OK so this is stupid but I haven't read b */
	b	PIC_PLT(_ASM_LABEL(__cerror))

	/* update, __curbrk and return */
.L_brk_ok:
	stw	7, 0(6)		/* # remember, 6=&__curbrk, 3= new value */
	mr	3, 0		/* # return 0 */
	blr