Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <<------------------------->>
- << so we assemble our file >>
- <<------------------------->>
- james@server:~/0x10c-build> cat kcall.dasm16
- ; random stuff here
- SET J, 7
- ADD I, 3
- SET A, 0x1000
- SET B, 0x1001
- SET C, 0x1002
- SET PUSH, 0x1004
- SET PUSH, 0x1005
- SET PUSH, 0x1006
- ; do a kernel call
- .CALL _stubapi_malloc
- ; more user code
- SET [A+0], 0x1
- SET [A+1], 0x2
- SET [A+2], 0x3
- SET [A+3], 0x4
- SET [A+4], 0x5
- SET [A+5], 0x6
- SET [A+6], 0x7
- SET [A+7], 0x8
- james@server:~/0x10c-build> dtasm/dtasm -o kcall.dobj16 kcall.dasm16
- warning: expressions will not be adjusted at link or relocation time. ensure labels are not used as part of expressions.
- <<------------------------------------------->>
- << now we have a policy that uses stack-call >>
- <<------------------------------------------->>
- james@server:~/0x10c-build> cat policy
- defaults
- {
- kernel=/home/james/0x10c-build/kernel/stubsys.dkrn16
- symbols=/home/james/0x10c-build/kernel/stubsys.dsym16
- direct=false
- # use pure stack calling conventioncat
- interrupt-call=stack-call
- # interrupt call mappings
- interrupt-call(_stubapi_malloc)=0x4001
- interrupt-call(_stubapi_free)=0x4002
- interrupt-call(_stubapi_errno)=0x4003
- interrupt-call(_stubapi_exit)=0x4004
- interrupt-size(_stubapi_malloc)=6
- interrupt-size(_stubapi_free)=1
- interrupt-size(_stubapi_errno)=0
- interrupt-size(_stubapi_exit)=1
- }
- format(image):
- offset 0x1000
- chain image-direct
- format(image-direct):
- write code
- <<--------------------------->>
- << and this is the result... >>
- <<--------------------------->>
- james@server:~/0x10c-build> dtld/dtld -p policy -o kcall.dcpu16 kcall.dobj16
- linker: saved 10 words during optimization.
- james@server:~/0x10c-build> DISPLAY= dtdb/dtdb kcall.dcpu16 -c "disasm 0x0 0x30"
- Created VM.
- Loaded 0x002D words from kcall.dcpu16.
- Flashed memory.
- 0x0000 (0xA0E1): >>> SET J, 0x0007
- 0x0001 (0x90C2): ADD I, 0x0003
- 0x0002 (0x7C01): SET A, 0x1000
- 0x0004 (0x7C21): SET B, 0x1001
- 0x0006 (0x7C41): SET C, 0x1002
- 0x0008 (0x7F01): SET PUSH, 0x1004
- 0x000A (0x7F01): SET PUSH, 0x1005
- 0x000C (0x7F01): SET PUSH, 0x1006
- 0x000E (0x0301): SET PUSH, A
- 0x000F (0x0701): SET PUSH, B
- 0x0010 (0x0B01): SET PUSH, C
- 0x0011 (0x6B01): SET PUSH, [SP+0xFFFA]
- 0x0013 (0x6B01): SET PUSH, [SP+0xFFFA]
- 0x0015 (0x6B01): SET PUSH, [SP+0xFFFA]
- 0x0017 (0x7D00): INT [A], 0x4001
- 0x0019 (0x6401): SET A, [SP]
- 0x001A (0x7F62): ADD SP, 0x0009
- 0x001C (0x8A01): SET [A+0x0000], 0x0001
- 0x001E (0x8E01): SET [A+0x0001], 0x0002
- 0x0020 (0x9201): SET [A+0x0002], 0x0003
- 0x0022 (0x9601): SET [A+0x0003], 0x0004
- 0x0024 (0x9A01): SET [A+0x0004], 0x0005
- 0x0026 (0x9E01): SET [A+0x0005], 0x0006
- 0x0028 (0xA201): SET [A+0x0006], 0x0007
- 0x002A (0xA601): SET [A+0x0007], 0x0008
- <<---------------------------------------------------->>
- << let's change the policy to a register call instead >>
- <<---------------------------------------------------->>
- james@server:~/0x10c-build> vi policy
- james@server:~/0x10c-build> cat policy
- defaults
- {
- kernel=/home/james/0x10c-build/kernel/stubsys.dkrn16
- symbols=/home/james/0x10c-build/kernel/stubsys.dsym16
- direct=false
- # use pure stack calling convention
- interrupt-call=register-call
- # interrupt call mappings
- interrupt-call(_stubapi_malloc)=0x4001
- interrupt-call(_stubapi_free)=0x4002
- interrupt-call(_stubapi_errno)=0x4003
- interrupt-call(_stubapi_exit)=0x4004
- interrupt-size(_stubapi_malloc)=6
- interrupt-size(_stubapi_free)=1
- interrupt-size(_stubapi_errno)=0
- interrupt-size(_stubapi_exit)=1
- }
- format(image):
- offset 0x1000
- chain image-direct
- format(image-direct):
- write code
- <<----------------------------------------------------->>
- << now **WITHOUT RE-ASSEMBLING**, let's see the result >>
- <<----------------------------------------------------->>
- james@server:~/0x10c-build> dtld/dtld -p policy -o kcall.dcpu16 kcall.dobj16
- linker: saved 10 words during optimization.
- james@server:~/0x10c-build> DISPLAY= dtdb/dtdb kcall.dcpu16 -c "disasm 0x0 0x30"
- Created VM.
- Loaded 0x0024 words from kcall.dcpu16.
- Flashed memory.
- 0x0000 (0xA0E1): >>> SET J, 0x0007
- 0x0001 (0x90C2): ADD I, 0x0003
- 0x0002 (0x7C01): SET A, 0x1000
- 0x0004 (0x7C21): SET B, 0x1001
- 0x0006 (0x7C41): SET C, 0x1002
- 0x0008 (0x7F01): SET PUSH, 0x1004
- 0x000A (0x7F01): SET PUSH, 0x1005
- 0x000C (0x7F01): SET PUSH, 0x1006
- 0x000E (0x7D00): INT [A], 0x4001
- 0x0010 (0x6401): SET A, [SP]
- 0x0011 (0x7F62): ADD SP, 0x0003
- 0x0013 (0x8A01): SET [A+0x0000], 0x0001
- 0x0015 (0x8E01): SET [A+0x0001], 0x0002
- 0x0017 (0x9201): SET [A+0x0002], 0x0003
- 0x0019 (0x9601): SET [A+0x0003], 0x0004
- 0x001B (0x9A01): SET [A+0x0004], 0x0005
- 0x001D (0x9E01): SET [A+0x0005], 0x0006
- 0x001F (0xA201): SET [A+0x0006], 0x0007
- 0x0021 (0xA601): SET [A+0x0007], 0x0008
- <<------------------------------------------>>
- << verdict: linker policies == fucking cool >>
- <<------------------------------------------>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement