1!
2! CDDL HEADER START
3!
4! The contents of this file are subject to the terms of the
5! Common Development and Distribution License, Version 1.0 only
6! (the "License").  You may not use this file except in compliance
7! with the License.
8!
9! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10! or http://www.opensolaris.org/os/licensing.
11! See the License for the specific language governing permissions
12! and limitations under the License.
13!
14! When distributing Covered Code, include this CDDL HEADER in each
15! file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16! If applicable, add the following below this CDDL HEADER, with the
17! fields enclosed by brackets "[]" replaced with your own identifying
18! information: Portions Copyright [yyyy] [name of copyright owner]
19!
20! CDDL HEADER END
21!
22!	"%Z%%M%	%I%	%E% SMI"
23!	Copyright (c) 1986 by Sun Microsystems, Inc.
24!
25!	.seg	"text"
26
27	.file	"sbrk.s"
28
29#include "SYS.h"
30#include <sys/syscall.h>
31
32#define ALIGNSIZE	8
33
34	.global	.curbrk
35	.type   .curbrk,#object
36	.size	.curbrk,4
37
38	.global end
39	.section ".data"
40	.align	4
41.curbrk:
42	.word	end
43
44	ENTRY(sbrk)
45	add	%o0, (ALIGNSIZE-1), %o0	! round up request to align size
46	andn	%o0, (ALIGNSIZE-1), %o0
47#ifdef PIC
48	PIC_SETUP(o5)
49	ld	[%o5 + .curbrk], %g1
50	ld	[%g1], %o3
51#else
52	sethi	%hi(.curbrk), %o2
53	ld	[%o2 + %lo(.curbrk)], %o3
54#endif
55	add	%o3, (ALIGNSIZE-1), %o3	! round up .curbrk to align size
56	andn	%o3, (ALIGNSIZE-1), %o3
57	add	%o3, %o0, %o0		! new break setting = request + .curbrk
58	mov	%o0, %o4		! save it
59	mov	SYS_brk, %g1
60	t	8
61	CERROR(o5)
62#ifdef PIC
63	PIC_SETUP(o5)
64	ld	[%o5 + .curbrk], %g1
65	st	%o4, [%g1]
66#else
67	st	%o4, [%o2 + %lo(.curbrk)] ! store new break in .curbrk
68#endif
69	retl
70	mov	%o3, %o0		! return old break
71	SET_SIZE(sbrk)
72