code_junkie

Is GCC broken when taking the address of an argument on ARM7TDMI?

Nov 10th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. void foo(unsigned int x) {
  2. *(volatile unsigned int*)(0x4000000 + 0xd4) = (unsigned int)(&x);
  3. }
  4.  
  5. int main() {
  6. foo(1);
  7. while(1);
  8. }
  9.  
  10. .align 2
  11. .global foo
  12. .type foo, %function
  13. foo:
  14. @ Function supports interworking.
  15. @ args = 0, pretend = 0, frame = 8
  16. @ frame_needed = 0, uses_anonymous_args = 0
  17. @ link register save eliminated.
  18. sub sp, sp, #8
  19. str r0, [sp, #4] @ 3. Store the argument on the stack
  20. mov r3, #67108864
  21. add r3, r3, #212
  22. add r2, sp, #4 @ 4. Address of the stack variable
  23. str r2, [r3, #0] @ 5. Store the address at 0x40000d4
  24. add sp, sp, #8
  25. bx lr
  26. .size foo, .-foo
  27. .align 2
  28. .global main
  29. .type main, %function
  30. main:
  31. @ Function supports interworking.
  32. @ args = 0, pretend = 0, frame = 0
  33. @ frame_needed = 0, uses_anonymous_args = 0
  34. stmfd sp!, {r4, lr}
  35. mov r0, #1 @ 1. Pass the argument in register 0
  36. bl foo @ 2. Call function foo
  37. .L4:
  38. b .L4
  39. .size main, .-main
  40. .ident "GCC: (GNU) 4.4.0 20080820 (experimental)"
  41.  
  42. .align 2
  43. .global foo
  44. .type foo, %function
  45. foo:
  46. @ Function supports interworking.
  47. @ args = 0, pretend = 0, frame = 8
  48. @ frame_needed = 0, uses_anonymous_args = 0
  49. @ link register save eliminated.
  50. sub sp, sp, #8
  51. mov r2, #67108864
  52. add r3, sp, #4 @ 3. Address of *something* on the stack
  53. str r3, [r2, #212] @ 4. Store the address at 0x40000d4
  54. add sp, sp, #8
  55. bx lr
  56. .size foo, .-foo
  57. .align 2
  58. .global main
  59. .type main, %function
  60. main:
  61. @ Function supports interworking.
  62. @ args = 0, pretend = 0, frame = 0
  63. @ frame_needed = 0, uses_anonymous_args = 0
  64. stmfd sp!, {r4, lr}
  65. mov r0, #1 @ 1. Pass the argument in register 0
  66. bl foo @ 2. Call function foo
  67. .L4:
  68. b .L4
  69. .size main, .-main
  70. .ident "GCC: (GNU) 4.4.0 20080820 (experimental)"
  71.  
  72. void foo(unsigned int x) {
  73. volatile unsigned int* ptr = (unsigned int*)(0x4000000 + 0xd4);
  74. *ptr = (unsigned int)(&x);
  75. }
  76.  
  77. int main() {
  78. foo(1);
  79. while(1);
  80. }
  81.  
  82. void foo(unsigned int *x) {
  83. volatile unsigned int* ptr = (unsigned int*)(0x4000000 + 0xd4);
  84. *ptr = (unsigned int)(x);
  85. }
  86.  
  87. int main() {
  88. int x = 1;
  89. foo(&x);
  90. while(1);
  91. }
  92.  
  93. void foo(unsigned int x) {
  94. volatile int y = x;
  95. *(volatile unsigned int*)(0x4000000 + 0xd4) = (unsigned int)(&y);
  96. }
  97.  
  98. void foo(unsigned int x)
  99. {
  100. volatile unsigned int* pArg = &x;
  101. *(volatile unsigned int*)(0x4000000 + 0xd4) = (unsigned int)pArg;
  102. }
  103.  
  104. void foo(unsigned int x)
  105. {
  106. volatile unsigned int* pArg = &x;
  107. *(volatile unsigned int*)(0x4000000 + 0xd4) = (unsigned int)pArg;
  108. }
  109.  
  110. *(volatile unsigned int *)0x12345 = someuintvariable;
  111.  
  112. *(volatile unsigned int *)0x12345 = 0x12;
  113.  
  114. .globl PUT32
  115. PUT32:
  116. str r1,[r0]
  117. bx lr
  118.  
  119.  
  120.  
  121.  
  122.  
  123. PUT32(0x12345,0x12);
  124.  
  125. // Warning: untested code.
  126. void foo(unsigned int x) {
  127. static volatile unsigned int color = x; // "static" so it's not on the stack
  128. volatile unsigned int** dma_register =
  129. (volatile unsigned int**)(0x4000000 + 0xd4);
  130. *dma_register = &color;
  131. }
  132.  
  133. int main() {
  134. foo(1);
  135. while(1);
  136. }
Add Comment
Please, Sign In to add comment