DC-SWAT Forum

Полная версия: how to use sh4dis.exe
Вы просматриваете yпpощеннyю веpсию форума. Пеpейти к полной веpсии.
Hello, everyone. Recently, I found a program written by SWAT in the hard disk

I checked the help file:

SH4 Disassembler v1.0 by SWAT
Usage: sh4dis [flags] filename
Flags:
-b<address> Binary file, text start
-o<filename> File to write output to (default: stdout)
-d Standard displacement


But I can't output bin file. Is my TXT file wrong?Blush


Txt:
Example

L8c010000:
nop
nop
nop
nop
nop
nop
mov.l #H'ff00001c,r0
mov.l @r0,r1
mov.l #H'000089af,r2
and r2,r1
mov.w #H'0800,r2
or r2,r1
mov.l r1,@r0
mov.l #H'8c05e760,r0
jmp @r0
nop
Disassembler - binary to assembler conversion
input bin file, output text

for asemblity use

Код:
sh-elf-as --little -o obj.o input.s
sh-elf-objcopy -R .stack -O binary obj.o output.bin
thank you~



So this can't be converted from txt to bin?


input txt file, output bin file?
no, sh4dis.exe only for convert from bin to txt

for convert txt to bin use sh-elf compiler
Thank you. I saw two programs sh4dis.exe and sh4disasm.exe.

I thought they could be used to convert ASM to elf
Sorry, I'll reply to the post again

I've learned to use sh elf as and sh elf objcopy, but I'd like to ask about the writing method

There is no problem in the compilation of general assembly instructions, but writing instructions containing addresses either prompts an error or compiles an error. Can you tell me how to write?

For example, there are no problems with the following
mov.b @r2+, r0
mov.b r0, @r3
Add #1, R3
TST R0, R0
BF loc_C
Mov R3, R0
And #3, R0
Mov #0, R2
cmp/eq #0, r0
BT loc_38
cmp/eq #1, r0
BT loc_2C
cmp/eq #2, r0
BT loc_30
cmp/eq #3, r0
BT loc_34

is ok~


But I don't know how to write The following

mova @(h'44,pc), r0 ; [0000004C] = h'8Cf14000


mov.l @(h'44,pc), r0 ; [8C0B757C] = sub_8C08D100


mov.l #h'41474553, r5

thank you for your reply~
(18.03.2020 17:27)kof888 писал(а): [ -> ]But I don't know how to write The following

mova @(h'44,pc), r0 ; [0000004C] = h'8Cf14000


mov.l @(h'44,pc), r0 ; [8C0B757C] = sub_8C08D100


mov.l #h'41474553, r5

Код:
    mova @(0x44,pc), r0
    nop
    mov.l @(0x44,pc), r0
    mov.l .value, r5

.align 2
.value:
    .long    0x41474553

example:

Код:
    mova .value, r0        ! r0 = adress of value
    mov.l @r0, r0        ! r0 = 0x41474553

.align 2
.value:
    .long    0x41474553

Код:
    mov.l .value, r0    ! r0 = 0x41474553

.align 2
.value:
    .long    0x41474553
thank you~

How to write if it is several consecutive?

mov.l @(h'44,pc), r0 ; [8C0B757C] = sub_8C08D100

mov.l @(h'44,pc), r1 ; [8C0B757C] = sub_8C08D104

mov.l @(h'44,pc), r2 ; [8C0B757C] = sub_8C08D108

Is it read in order?



mov.l .value, r0
mov.l .value, r1
mov.l .value, r2
mov.l .value, r3

.value:
.long 0x41474553
.long 0x8c010000
.long 0x8c010004
.long 0x8c010008






anf Warning: misaligned data,
How to fill the alignment if there is no 4-byte alignment at the end?
Do you need to add a NOP manually?
(18.03.2020 18:08)kof888 писал(а): [ -> ]Is it read in order?



mov.l .value, r0
mov.l .value, r1
mov.l .value, r2
mov.l .value, r3

.value:
.long 0x41474553
.long 0x8c010000
.long 0x8c010004
.long 0x8c010008

no

Код:
    mov.l .value1, r0
    mov.l .value2, r1
    mov.l .value3, r2
    mov.l .value4, r3
    
.align 2
.value1:
    .long 0x41474553
.value2:
    .long 0x8c010000
.value3:
    .long 0x8c010004
.value4:
    .long 0x8c010008

Цитата:MOV.L @(disp, PC), Rn
Description
This instruction loads a signed long-word from memory using PC-relative with displacement addressing.
The effective address is formed by calculating PC+4, clearing the lowest 2 bits, and adding the zero-extended 8-bit immediate i multiplied by 4.
This address calculation ensures that the effective address is correctly aligned for a long-word access regardless of the PC alignment.
The long-word is loaded from the effective address and placed in R n .
Thanks for your reply.

I used to play the machine code by hand


about MOV.L @(disp, PC), Rn,I know what it means


I KONW,NOP will be added automatically. Thank you for your answer
Код:
    mova  .value, r0
    mov.l @r0+, r4        ! r4 = 0x41474553
    mov.l @r0+, r5        ! r5 = 0x8c010000
    mov.l @r0+, r6        ! r6 = 0x8c010004
    mov.l @r0,  r7        ! r7 = 0x8c010008

.align 2
.value:
    .long 0x41474553
    .long 0x8c010000
    .long 0x8c010004
    .long 0x8c010008
Thank you very much, I love this program so much, I love you too ^6^
I found a problem. I don't know if it's a bug or a mistake
mov.w .value1, r2
cmp/eq r2, r6
add #-0xA, r0
mov #0x1F, r2
and r2, r6
add #0xD, r6
mov #0xA, r2
shld r2, r1
mov #-0xE, r2
mov r1, r6
shld r2, r6
mov.l .value2, r2
lds.l @r15+, pr
rts
nop

.align 2
.value1:
.short 0x3FF
.value2:
.long 0x3FFFF
.end ;

mov.l .value2, r2 This one will go wrong


Код:
0E922036F6701FE229260D760AE22D41F2E213662D46 02D2 264F 0B00 0900 0900 FF03 0000  FFFF0300
                                             ↑02 is wrong



If this instruction is swapped forward or backward, there will be no error

Did I write it wrong?
value2 not aligned to 32 bits

you set .align 2 and put short
short is 2 bytes, after short you place long

8c010000 FF 03 ! value1
8c010002 FF FF ! value2
8c010004 03 00

if you read long from 8c010002 it's generate exception
long can be read only from 8c01000x, where x is 0, 4, 8 or C

Код:
mov.w .value1, r2
cmp/eq r2, r6
add #-0xA, r0
mov #0x1F, r2
and r2, r6
add #0xD, r6
mov #0xA, r2
shld r2, r1
mov #-0xE, r2
mov r1, r6
shld r2, r6
mov.l .value2, r2
lds.l @r15+, pr
rts
nop

.value1:
.short 0x3FF
.align 2
.value2:
.long 0x3FFFF
.end ;
Thanks for the reply,I konw ~

Does the software help explain the problem of writing grammar?
Sorry, I encountered new problems with this program
I would like to ask in this case, can that address be calculated automatically in .value0

mov r4, r3
mov #0, r0
cmp/eq r0, r6
bt loc_60330BA
mov #0xC, r0
cmp/gt r0, r6
bf loc_60330B0
neg r5, r0
add #4, r0
and #3, r0
tst r0, r0
bt loc_603304C
mov r0, r1

loc_6033040:
mov.b @r5+, r0
dt r1
mov.b r0, @r4
add #-1, r6
add #1, r4
bf loc_6033040

loc_603304C:
mov r6, r2
shlr2 r2
tst r2, r2
bt loc_60330A4
mov r4, r0
and #3, r0
mov r0, r1
mova .value0, r0
mov.b @(r0,r1), r1
add r1, r0
jmp @r0
nop

! ---------------------------------------------------------------------------
! ---------------------------------------------------------------------------

.value0: !!!!!!!! Is there a way to calculate these few bytes automatically?
.byte 0x04
.byte 0x24
.byte 0x12
.byte 0x24

! ---------------------------------------------------------------------------
! ---------------------------------------------------------------------------


loc_6033068: ! CODE XREF: sub_6033024+4Cj
mov.l @r5+, r0
dt r2
mov.l r0, @r4
add #4, r4
bf loc_6033068
bra loc_60330A4
nop

loc_6033078:
mov.l @r5+, r0
dt r2
mov.w r0, @(2,r4)
shlr16 r0
mov.w r0, @r4
add #4, r4
bf loc_6033078
bra loc_60330A4
nop

loc_603308C:
mov.l @r5+, r0
dt r2
mov.b r0, @(3,r4)
shlr8 r0
mov.b r0, @(2,r4)
shlr8 r0
mov.b r0, @(1,r4)
shlr8 r0
mov.b r0, @r4
add #4, r4
bf loc_603308C
loc_60330A4:
mov r6, r0
and #03, r0
tst r0, r0
bt loc_60330BA
mov r0, r6

loc_60330B0:

mov.b @r5+, r0
dt r6
mov.b r0, @r4
add #1, r4
bf loc_60330B0

loc_60330BA:
rts
mov r3, r0
Код:
    mov r4, r3
    mov #0, r0
    cmp/eq r0, r6
    bt loc_60330BA
    mov #0xC, r0
    cmp/gt r0, r6
    bf loc_60330B0
    neg r5, r0
    add #4, r0
    and #3, r0
    tst r0, r0
    bt loc_603304C
    mov r0, r1

loc_6033040:
    mov.b @r5+, r0
    dt r1
    mov.b r0, @r4
    add #-1, r6
    add #1, r4
    bf loc_6033040

loc_603304C:
    mov r6, r2
    shlr2 r2
    tst r2, r2
    bt loc_60330A4
    mov r4, r0
    and #3, r0
    mov r0, r1
    mova .value0, r0
    mov.b @(r0,r1), r1
    add r1, r0
    jmp @r0
    nop

! ---------------------------------------------------------------------------
! ---------------------------------------------------------------------------
! value0 placed in address 0x6033064
.value0:
.byte loc_6033068 - .value0
.byte loc_6033088 - .value0
.byte loc_6033076 - .value0
.byte loc_6033088 - .value0

! ---------------------------------------------------------------------------
! ---------------------------------------------------------------------------


loc_6033068:    ! 0x6033064 + 0x04
    mov.l @r5+, r0
    dt r2
    mov.l r0, @r4
    add #4, r4
    bf loc_6033068
    bra loc_60330A4
loc_6033076:    ! 0x6033064 + 0x12
    nop

loc_6033078:
    mov.l @r5+, r0
    dt r2
    mov.w r0, @(2,r4)
    shlr16 r0
    mov.w r0, @r4
    add #4, r4
    bf loc_6033078
    bra loc_60330A4
loc_6033088:    ! 0x6033064 + 0x24
    nop

loc_603308C:
    mov.l @r5+, r0
    dt r2
    mov.b r0, @(3,r4)
    shlr8 r0
    mov.b r0, @(2,r4)
    shlr8 r0
    mov.b r0, @(1,r4)
    shlr8 r0
    mov.b r0, @r4
    add #4, r4
    bf loc_603308C
    loc_60330A4:
    mov r6, r0
    and #03, r0
    tst r0, r0
    bt loc_60330BA
    mov r0, r6

loc_60330B0:
    mov.b @r5+, r0
    dt r6
    mov.b r0, @r4
    add #1, r4
    bf loc_60330B0

loc_60330BA:
    rts
    mov r3, r0

if it's alrady edited code then calculate offset before you edit code
Thanks for your reply, every time you can reply me at the first time
now,Finally no need to calculate manually

thank you very much!
URL ссылки