Advertisement
Guest User

Linker Policies in the Toolchain (again)

a guest
Nov 5th, 2012
1,051
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1.  
  2.  
  3. <<------------------------->>
  4. << so we assemble our file >>
  5. <<------------------------->>
  6.  
  7.  
  8. james@server:~/0x10c-build> cat kcall.dasm16
  9. ; random stuff here
  10. SET J, 7
  11. ADD I, 3
  12.  
  13. SET A, 0x1000
  14. SET B, 0x1001
  15. SET C, 0x1002
  16. SET PUSH, 0x1004
  17. SET PUSH, 0x1005
  18. SET PUSH, 0x1006
  19.  
  20. ; do a kernel call
  21. .CALL _stubapi_malloc
  22.  
  23. ; more user code
  24. SET [A+0], 0x1
  25. SET [A+1], 0x2
  26. SET [A+2], 0x3
  27. SET [A+3], 0x4
  28. SET [A+4], 0x5
  29. SET [A+5], 0x6
  30. SET [A+6], 0x7
  31. SET [A+7], 0x8
  32. james@server:~/0x10c-build> dtasm/dtasm -o kcall.dobj16 kcall.dasm16
  33. warning: expressions will not be adjusted at link or relocation time. ensure labels are not used as part of expressions.
  34.  
  35.  
  36. <<------------------------------------------->>
  37. << now we have a policy that uses stack-call >>
  38. <<------------------------------------------->>
  39.  
  40.  
  41. james@server:~/0x10c-build> cat policy
  42. defaults
  43. {
  44. kernel=/home/james/0x10c-build/kernel/stubsys.dkrn16
  45. symbols=/home/james/0x10c-build/kernel/stubsys.dsym16
  46. direct=false
  47. # use pure stack calling conventioncat
  48. interrupt-call=stack-call
  49. # interrupt call mappings
  50. interrupt-call(_stubapi_malloc)=0x4001
  51. interrupt-call(_stubapi_free)=0x4002
  52. interrupt-call(_stubapi_errno)=0x4003
  53. interrupt-call(_stubapi_exit)=0x4004
  54. interrupt-size(_stubapi_malloc)=6
  55. interrupt-size(_stubapi_free)=1
  56. interrupt-size(_stubapi_errno)=0
  57. interrupt-size(_stubapi_exit)=1
  58. }
  59.  
  60. format(image):
  61. offset 0x1000
  62. chain image-direct
  63.  
  64. format(image-direct):
  65. write code
  66.  
  67.  
  68. <<--------------------------->>
  69. << and this is the result... >>
  70. <<--------------------------->>
  71.  
  72.  
  73. james@server:~/0x10c-build> dtld/dtld -p policy -o kcall.dcpu16 kcall.dobj16
  74. linker: saved 10 words during optimization.
  75. james@server:~/0x10c-build> DISPLAY= dtdb/dtdb kcall.dcpu16 -c "disasm 0x0 0x30"
  76. Created VM.
  77. Loaded 0x002D words from kcall.dcpu16.
  78. Flashed memory.
  79. 0x0000 (0xA0E1): >>> SET J, 0x0007
  80. 0x0001 (0x90C2): ADD I, 0x0003
  81. 0x0002 (0x7C01): SET A, 0x1000
  82. 0x0004 (0x7C21): SET B, 0x1001
  83. 0x0006 (0x7C41): SET C, 0x1002
  84. 0x0008 (0x7F01): SET PUSH, 0x1004
  85. 0x000A (0x7F01): SET PUSH, 0x1005
  86. 0x000C (0x7F01): SET PUSH, 0x1006
  87. 0x000E (0x0301): SET PUSH, A
  88. 0x000F (0x0701): SET PUSH, B
  89. 0x0010 (0x0B01): SET PUSH, C
  90. 0x0011 (0x6B01): SET PUSH, [SP+0xFFFA]
  91. 0x0013 (0x6B01): SET PUSH, [SP+0xFFFA]
  92. 0x0015 (0x6B01): SET PUSH, [SP+0xFFFA]
  93. 0x0017 (0x7D00): INT [A], 0x4001
  94. 0x0019 (0x6401): SET A, [SP]
  95. 0x001A (0x7F62): ADD SP, 0x0009
  96. 0x001C (0x8A01): SET [A+0x0000], 0x0001
  97. 0x001E (0x8E01): SET [A+0x0001], 0x0002
  98. 0x0020 (0x9201): SET [A+0x0002], 0x0003
  99. 0x0022 (0x9601): SET [A+0x0003], 0x0004
  100. 0x0024 (0x9A01): SET [A+0x0004], 0x0005
  101. 0x0026 (0x9E01): SET [A+0x0005], 0x0006
  102. 0x0028 (0xA201): SET [A+0x0006], 0x0007
  103. 0x002A (0xA601): SET [A+0x0007], 0x0008
  104.  
  105.  
  106. <<---------------------------------------------------->>
  107. << let's change the policy to a register call instead >>
  108. <<---------------------------------------------------->>
  109.  
  110.  
  111. james@server:~/0x10c-build> vi policy
  112. james@server:~/0x10c-build> cat policy
  113. defaults
  114. {
  115. kernel=/home/james/0x10c-build/kernel/stubsys.dkrn16
  116. symbols=/home/james/0x10c-build/kernel/stubsys.dsym16
  117. direct=false
  118. # use pure stack calling convention
  119. interrupt-call=register-call
  120. # interrupt call mappings
  121. interrupt-call(_stubapi_malloc)=0x4001
  122. interrupt-call(_stubapi_free)=0x4002
  123. interrupt-call(_stubapi_errno)=0x4003
  124. interrupt-call(_stubapi_exit)=0x4004
  125. interrupt-size(_stubapi_malloc)=6
  126. interrupt-size(_stubapi_free)=1
  127. interrupt-size(_stubapi_errno)=0
  128. interrupt-size(_stubapi_exit)=1
  129. }
  130.  
  131. format(image):
  132. offset 0x1000
  133. chain image-direct
  134.  
  135. format(image-direct):
  136. write code
  137.  
  138.  
  139. <<----------------------------------------------------->>
  140. << now **WITHOUT RE-ASSEMBLING**, let's see the result >>
  141. <<----------------------------------------------------->>
  142.  
  143.  
  144. james@server:~/0x10c-build> dtld/dtld -p policy -o kcall.dcpu16 kcall.dobj16
  145. linker: saved 10 words during optimization.
  146. james@server:~/0x10c-build> DISPLAY= dtdb/dtdb kcall.dcpu16 -c "disasm 0x0 0x30"
  147. Created VM.
  148. Loaded 0x0024 words from kcall.dcpu16.
  149. Flashed memory.
  150. 0x0000 (0xA0E1): >>> SET J, 0x0007
  151. 0x0001 (0x90C2): ADD I, 0x0003
  152. 0x0002 (0x7C01): SET A, 0x1000
  153. 0x0004 (0x7C21): SET B, 0x1001
  154. 0x0006 (0x7C41): SET C, 0x1002
  155. 0x0008 (0x7F01): SET PUSH, 0x1004
  156. 0x000A (0x7F01): SET PUSH, 0x1005
  157. 0x000C (0x7F01): SET PUSH, 0x1006
  158. 0x000E (0x7D00): INT [A], 0x4001
  159. 0x0010 (0x6401): SET A, [SP]
  160. 0x0011 (0x7F62): ADD SP, 0x0003
  161. 0x0013 (0x8A01): SET [A+0x0000], 0x0001
  162. 0x0015 (0x8E01): SET [A+0x0001], 0x0002
  163. 0x0017 (0x9201): SET [A+0x0002], 0x0003
  164. 0x0019 (0x9601): SET [A+0x0003], 0x0004
  165. 0x001B (0x9A01): SET [A+0x0004], 0x0005
  166. 0x001D (0x9E01): SET [A+0x0005], 0x0006
  167. 0x001F (0xA201): SET [A+0x0006], 0x0007
  168. 0x0021 (0xA601): SET [A+0x0007], 0x0008
  169.  
  170.  
  171. <<------------------------------------------>>
  172. << verdict: linker policies == fucking cool >>
  173. <<------------------------------------------>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement