brk.S 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* brk system call for Linux/ppc.
  2. Copyright (C) 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <features.h>
  17. #include "ppc_asm.h"
  18. #define _ERRNO_H 1
  19. #include <bits/errno.h>
  20. #include <sys/syscall.h>
  21. #ifdef __NR_brk
  22. #ifdef __PIC__
  23. .section .bss
  24. .align 4
  25. .globl __curbrk
  26. .hidden __curbrk
  27. __curbrk: .skip 4
  28. .type __curbrk,@object
  29. .size __curbrk,4
  30. #else
  31. .comm __curbrk, 4,4
  32. #endif
  33. .text
  34. .globl brk
  35. .type brk,@function
  36. .align 2
  37. brk:
  38. stwu r1,-16(r1)
  39. stw r3,8(r1)
  40. li 0, __NR_brk;
  41. sc
  42. lwz r6,8(r1)
  43. #ifdef __PIC__
  44. mflr r4
  45. # ifdef HAVE_ASM_PPC_REL16
  46. bcl 20,31,1f
  47. 1: mflr r5
  48. addis r5,r5,_GLOBAL_OFFSET_TABLE_-1b@ha
  49. addi r5,r5,_GLOBAL_OFFSET_TABLE_-1b@l
  50. # else
  51. bl _GLOBAL_OFFSET_TABLE_@local-4
  52. mflr r5
  53. # endif
  54. lwz r5,__curbrk@got(r5)
  55. mtlr r4
  56. stw r3,0(r5)
  57. #else
  58. lis r4,__curbrk@ha
  59. stw r3,__curbrk@l(r4)
  60. #endif
  61. cmplw r6,r3
  62. addi r1,r1,16
  63. li r3,0
  64. blelr+
  65. li r3,ENOMEM
  66. b __syscall_error
  67. .size brk,.-brk
  68. libc_hidden_def(brk)
  69. #endif