brk.S 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <features.h>
  16. #include "ppc_asm.h"
  17. #define _ERRNO_H 1
  18. #include <bits/errno.h>
  19. #include <sys/syscall.h>
  20. #ifdef __NR_brk
  21. #ifdef __PIC__
  22. .section .bss
  23. .align 4
  24. .globl __curbrk
  25. .hidden __curbrk
  26. __curbrk: .skip 4
  27. .type __curbrk,@object
  28. .size __curbrk,4
  29. #else
  30. .comm __curbrk, 4,4
  31. #endif
  32. .text
  33. .globl brk
  34. .type brk,@function
  35. .align 2
  36. brk:
  37. stwu r1,-16(r1)
  38. stw r3,8(r1)
  39. li 0, __NR_brk;
  40. sc
  41. lwz r6,8(r1)
  42. #ifdef __PIC__
  43. mflr r4
  44. # ifdef HAVE_ASM_PPC_REL16
  45. bcl 20,31,1f
  46. 1: mflr r5
  47. addis r5,r5,_GLOBAL_OFFSET_TABLE_-1b@ha
  48. addi r5,r5,_GLOBAL_OFFSET_TABLE_-1b@l
  49. # else
  50. bl _GLOBAL_OFFSET_TABLE_@local-4
  51. mflr r5
  52. # endif
  53. lwz r5,__curbrk@got(r5)
  54. mtlr r4
  55. stw r3,0(r5)
  56. #else
  57. lis r4,__curbrk@ha
  58. stw r3,__curbrk@l(r4)
  59. #endif
  60. cmplw r6,r3
  61. addi r1,r1,16
  62. li r3,0
  63. blelr+
  64. li r3,ENOMEM
  65. b __syscall_error
  66. .size brk,.-brk
  67. libc_hidden_def(brk)
  68. #endif