Jump to content



Photo
- - - - -

Building a simple addin binary with assembly


  • Please log in to reply
5 replies to this topic

#1 hejsotnoss

hejsotnoss

    Casio Fan

  • Members
  • PipPip
  • 31 posts
  • Gender:Male
  • Interests:programming
    mathematics
    piano
    reading

  • Calculators:
    fx-9750GII
    fx-9860GII

Posted 14 March 2020 - 11:59 PM

Hello. this is a simple tutorial that intends to help people who are wanting to get started programming casio fx-9860GII-2 with assembly on a linux machine.

The first step which I will be going over(to an extent) is compiling binutils which is compatible with the superH architecture. This is mostly derived from https://www.planet-c...riels.php?id=61

First we will set up our environment and download the binutils archive:

cd /tmp
wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.34.tar.xz
tar xJf binutils-2.34.tar.xz -C $HOME/.local/src/
mkdir build-binutils tmp-binutilscd build-binutils$HOME/.local/src/binutils-2.34/configure --prefix=/tmp/tmp-binutils --target=sh3eb-elf --disable-nls --program-prefix=sh-elf- 

Now compile and install our binutils under sh-elf-

# -j depend on your system, 24 for me
make -j24 MAKEINFO=true
make install MAKEINFO=true
cp /tmp/tmp-binutils/bin/* $HOME/bin/

Now we can begin fun part:

Go to a directory where your code will go and download this which contains important initialization code

wget https://www.planet-casio.com/storage/forums/bin-12970.zip
unzip bin-12970.zip 

For this example we will have following code in addin.s:

.section .text 	
.global _main
_main: 	
rts 	
mov #1, r0
.end

Now we will use binutils to assemble and link everything together:

sh-elf-as --big --renesas --isa=sh4a-nofpu -o main.o addin.s
sh-elf-as --big --renesas --isa=sh4a-nofpu -o crt0.o crt0.s
sh-elf-ld -T addin.ld -EB --oformat=binary -o addin.elf main.o crt0.o

And you are done!
Now you can wrap the binary file using the fxg1a tool by Lephenixnoir of planet-casio.com

Somethings to keep in mind:
Addin in example will do nothing because it only returns to main menu.
Binary size needs to be at least 272 byte long for g1a checksum so you will need to the fill rest with 0xFF if the size is smaller.

Thanks for reading,

hejsotnoss


Edited by hejsotnoss, 22 April 2020 - 06:01 PM.

  • TBit likes this

#2 TBit

TBit

    Newbie

  • Members
  • Pip
  • 26 posts
  • Gender:Male
  • Location:Germany
  • Interests:C/C++, Assembly, Demoscene

  • Calculators:
    FX-9860 GII
    FX-9750 GII
    ClassPad 330 PLUS

Posted 15 March 2020 - 02:19 AM

Very nice post, I think I'll actually switch to GNU binutils now :)


  • hejsotnoss likes this

#3 hejsotnoss

hejsotnoss

    Casio Fan

  • Members
  • PipPip
  • 31 posts
  • Gender:Male
  • Interests:programming
    mathematics
    piano
    reading

  • Calculators:
    fx-9750GII
    fx-9860GII

Posted 15 March 2020 - 05:05 PM

I'm glad you found it useful :) Let me know if you have any problems setting up the GNU binutils

Regards,

hejsotnoss

#4 hejsotnoss

hejsotnoss

    Casio Fan

  • Members
  • PipPip
  • 31 posts
  • Gender:Male
  • Interests:programming
    mathematics
    piano
    reading

  • Calculators:
    fx-9750GII
    fx-9860GII

Posted 16 March 2020 - 07:53 AM

As a continuation, here is a simple hello world program I wrote using syscalls:

	.section .text
	.global _main

_main:
	mov.l r8, @-r15
	mov #1, r4
	mov #1, r5
	mov.l locate, r1
	sts.l pr, @-r15

	jsr @r1
	add #-4, r15

	mov.l print, r1
	mov.l getkey, r8
	mov.l hello_world, r4
	
	jsr @r1
	nop
loop:
	jsr @r8
	mov r15, r4
	bra loop
	nop

locate: .long _locate
print: .long _print
getkey: .long _getkey
hello_world: .long _hello_world

_locate:
	mov.l syscall, r2
	mov.l 1f, r0
	jmp @r2
	nop
1: .long 0x807
_print:
	mov.l syscall, r2
	mov.l 1f, r0
	jmp @r2
	nop
1: .long 0x808
_getkey:
	mov.l syscall, r2
	mov.l 1f, r0
	jmp @r2
	nop
1: .long 0x90f

syscall: .long 0x80010070

_hello_world: .asciz "Hello, world!"

  • TBit likes this

#5 TBit

TBit

    Newbie

  • Members
  • Pip
  • 26 posts
  • Gender:Male
  • Location:Germany
  • Interests:C/C++, Assembly, Demoscene

  • Calculators:
    FX-9860 GII
    FX-9750 GII
    ClassPad 330 PLUS

Posted 16 March 2020 - 01:17 PM

One small suggestion: I think you can omit the 

sh-elf-objcopy -O binary addin.elf addin.bin

step and just add

--oformat=binary

to the linker flags.


  • hejsotnoss likes this

#6 hejsotnoss

hejsotnoss

    Casio Fan

  • Members
  • PipPip
  • 31 posts
  • Gender:Male
  • Interests:programming
    mathematics
    piano
    reading

  • Calculators:
    fx-9750GII
    fx-9860GII

Posted 16 March 2020 - 04:38 PM

One small suggestion: I think you can omit the 

sh-elf-objcopy -O binary addin.elf addin.bin

step and just add

--oformat=binary

to the linker flags.

Thank you, it seems like a better option :), I'll add that to the tutorial




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users