flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > raspberry pi, arduino

Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 25 Oct 2018, 10:47
hello, i am trying to use assembly langage on rpi and arduino compatible boards (arm, avr, esp, stm) in order to understand their architectures.

it is very powerfull to use assembly langage to get the deep understanding of an architecture. then, i plan to do some stuff inside them, using fasm/fasmg of course.

and as i not really active here these times, i have two choices:

asking everybody.
searching in the exponential number of topics and search results.

and then, create the topic that will reference every pertinent ressources about this subject. cause i like a lot to create things.

[fasmarm] rpi lower16 upper16
Raspberry Pi
[AVR] fasmg assembles with error(s)
Post 25 Oct 2018, 10:47
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 25 Oct 2018, 22:13
Hi edfed.

What are you planning?
Post 25 Oct 2018, 22:13
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 29 Oct 2018, 12:19
hi revolution.

i am planning to program avr boards using assembly cause i meet lot of limitations using the "c++" arduino ide.

and i want to code avr in asm, just because it helps a lot to understand the core itself.

about the current projects:

for the raspberry pi, i need to just have a starfield on the hdmi screen at startup and use gpio to change some stuff.

on arduino, it is just in order to get more knowledge on the avr architecture, and be able to bypass the arduino ide and tools to upload binaries Smile

as arduino boards are seen as serial ports, it is very possible to code something in fasm to get it working directlly, and be able to do self modifiable code, in order to change functions and data at runtime, without flashing the entire binary.
Post 29 Oct 2018, 12:19
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 30 Oct 2018, 19:07
There is a good chance you can get help with the rPi code on this board.
Post 30 Oct 2018, 19:07
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 17 Nov 2018, 13:24
hurrah, i got the rasp working using ssh on my pc.

a friend installed it for me, and i got a cpp project running, with code edition with netbeans on the pc Crying or Very sad

let say, to display one pixel, i have approximatelly 4G raspbian on the SD, and 1.5G of tools on the PC...Embarassed here, assembler takes all it's sense.

it is very ugly, the rasp is using raspbian jessie distro on a 4G SD, and i don't have many more room for files cause linux... is linux, very frustrating when it comes to play with access rights, paths, and so on....

the startup is very slow, i get a 1 minute console scrolling, very annoying.
and linux file system is really not my taste.

now thenext goal is to get the minimal set of files on the sd to fit my needs, and after, run some fasmarm code.

see you in 2034 then Laughing
Post 17 Nov 2018, 13:24
View user's profile Send private message Visit poster's website Reply with quote
bzt



Joined: 09 Nov 2018
Posts: 79
bzt 17 Nov 2018, 14:53
Hi,

I've never used fasm with arduino, but I can help with Raspberry Pi. You create a raw AArch64 binary (not ELF) and save it on the first (fat) partition on the SD card as "kernel8.img". If you've an AArch32 binary, name it as "kernel7.img". (Where the number designates ARMv8 for AArch64 and ARMv7 for AArch32 respectively). You'll also need three firmware files (bootcode.bin, start.elf, fixup.dat) on that fat partition, from here. That's all, forget all the other rasbian files and partitions.

What's common: on a RaspberryPi3 board, your code will be executed in paralell by all 4 cores at once (in contrast to x86, where you have to send an interrupt from BP to start APs). You can distinguish by reading a system register (mpidr_el1). You have to set up a stack and clear the bss yourself. For both modes, you can use the Mailbox interface (an MMIO area) to communicate with the board (like reading board number, setting screen resolution and require framebuffer address, etc.). In both cases your code will be running at hypervisor level (EL2), unless you set "kernel_old=1" in the config.txt, which will load your code at address 0 and executes it at EL3 (!). Therefore you should write a trampoline code which switches to supervisor (EL1) or userspace (EL0). I think EL1 is what you're after at first.

What's different: kernel7.img is loaded at 0x8000 (note 3 zeros), and you'll get some system table pointers in registers. Kernel8.img is loaded at 0x80000 (note 4 zeros) and you can't rely on the registers (linux uses a different method in 64 bit mode to pass dtb). So it's better to use a Mailbox call to get the command line for example, as that works for both AArch32 and AArch64.

An example minimal C trampoline code is here. Throw rocks on me, but I've used GNU toolchain for that. Thankfully there are lots of pure fasmarm examples as well, I suggest to take a look at
Peter Lemon's tutorials,
which includes examples in AArch32 and AArch64 for all models (Rpi1, Rpi2, Rpi3). The main difference among board models is that 2 and 3 uses a different MMIO address than the original Pi, and only Rpi3 supports AArch64. Not a starfield, but Peter's graphic mode hello world example is here, illustrating core and Mailbox handling as well as writing to the framebuffer:
https://github.com/PeterLemon/RaspberryPi/blob/master/HelloWorld/CPU/kernel8.asm#L22

Oh, and very important. Don't believe the BCM2835/6/7 documentation! They are full of typos and bugs, always look for an errata!

Cheers,
bzt
Post 17 Nov 2018, 14:53
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 22 Nov 2018, 12:50
Post 22 Nov 2018, 12:50
View user's profile Send private message Yahoo Messenger Reply with quote
FlierMate11



Joined: 13 Oct 2022
Posts: 94
FlierMate11 26 Oct 2022, 05:46
What about RP2040 (a MCU from Raspberry Pi Foundation)? It uses ARM Cortex-M0.

The documentations say:
Quote:
The processor implements the ARMv6-M Thumb instruction set, including a number of 32-bit instructions that use Thumb-2 technology. The ARMv6-M instruction set comprises:

*all of the 16-bit Thumb instructions from ARMv7-M excluding CBZ, CBNZ and IT

*the 32-bit Thumb instructions BL, DMB, DSB, ISB, MRS and MSR.

Table 3.1 shows the Cortex-M0 instructions and their cycle counts.

Source: https://developer.arm.com/documentation/ddi0432/c/programmers-model/instruction-set-summary?lang=en

Is the above supported in FASM ARM? I am new to everything revolving around ARM and MCU. RP2040 can be programmed in MicroPython, but like what edfed was saying, I want to get a deeper understanding about MCU by writing program in Assembly language.
BTW, bzt came up with useful information.
Post 26 Oct 2022, 05:46
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 26 Oct 2022, 05:48
FlierMate11 wrote:
Is the above supported in [FASMARM]?
Yes.

BTW: fasmarm is one word.
Post 26 Oct 2022, 05:48
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.