GithubHelp home page GithubHelp logo

arm_lab's Introduction

ARM_lab

This repository contains assembly code and scripts used in the lab classes of the course "Architettura degli Elaboratori" of the Department of Computer Science of the University of Catania.

Emulate Raspberry Pi OS on QEMU

In order to emulate Raspberry Pi OS on Ubuntu you need:

  • qemu-system
  • Latest qemu kernel
  • Raspberry Pi OS image

Download quemu-system using apt-get

sudo apt-get install qemu-system

Get the latest qemu kernel

This git repository contains the latest qemu-rpi kernel. I added a copy of the repository here in the folder qemu-rpi-kernel

Download Raspberry Pi OS image

You can find the image of the last Rspberry Pi OS in this link. Follow the istructions and save the .img file in the main folder of this repository

Run Raspberry Pi OS image on QEMU

First change the name of the image inside the start.sh script with the name of the image you downloaded (-hda argument):

#!/bin/bash

qemu-system-arm \
  -M versatilepb \
  -cpu arm1176 \
  -m 256 \
  -hda YOUR_IMAGE_NAME.img \
  -net nic -net user,hostfwd=tcp::5022-:22 \
  -dtb qemu-rpi-kernel/versatile-pb-buster.dtb \
  -kernel qemu-rpi-kernel/kernel-qemu-4.19.50-buster \
  -append 'root=/dev/sda2 panic=1' \
  -no-reboot 

Now you can simply run the script and qemu will start:

./start.sh

The default username and password for the Raspberry Pi OS are:

  • User: pi
  • Password: raspberry

Connect via ssh to the Raspberry Pi OS

In order to connect via ssh to the Raspberry Pi OS running on qemu, open a terminal in Raspberry Pi OS and start the ssh service:

sudo service ssh start

You can now connect to the Raspberry Pi OS from your host system:

ssh [email protected] -p 5022 -X

And send files to the Raspberry Pi OS using scp:

scp -P 5022 -r PATH_OF_THE_FOLDER_IN_THE_HOST_SYSTEM [email protected]:PATH_OF_THE_DESTINATION_FOLDER_IN_RASPBERRY_PI_OS

If SSH doesn’t start in your emulator at startup by default, you can change that inside your Pi terminal with:

sudo update-rc.d ssh enable

Assembly code

Inside the assembly directory there are 2 programs written in assembly:

  • prodottoMain.s: Simple program that calculates the product of 2 integers. The input numbers are read using the clib functions printf and scanf. The function that actually calculates the product is stored in a different source file (prodottoFunc.s)
  • ledon.s: Simple program that uses some GPIO pins to control 3 leds pressing a button. This code will only run on a real raspberry hardware since the GPIO pins are not emulated in the kernel used here

Assembling and running prodottoMain

In order to assemble prodottoMain in the raspberry Pi OS we can use gcc:

gcc -g -o prodotto prodottoFunc.s prodottoMain.s

After running gcc the executable is saved in the file prodotto. To run the program we can simply execute the following command:

./prodotto

If we want to run it in debug mode we can use gdb:

gdb ./prodotto

Please refer to this tutorial to learn how to use the basic functions of gdb debugger

Assembling and running ledon

In order to run this code you need a raspberry Pi 2/3 board. The program is expecting to have 3 leds connected to the pins GPIO 5, 6 and 26, and a button connected to the pin GPIO 22. The following schematic shows a possible way to connect the components to the board.

Schematic needed for ledon.s code

The led connected to GPIO26 will turn on everytime the button is pressed, the led on GPIO5 will switch its state whenever the button transits from not-pressed to pressed, and the led on GPIO6 will switch its state whenever the button transits from pressed to not-pressed.

In order to assemble ledon.s in the raspberry Pi OS use gcc:

gcc -g -o ledon ledon.s

To run the program execute the following command:

./ledon

If we want to run it in debug mode use this command:

gdb ./ledon

Useful links

arm_lab's People

Contributors

nigno17 avatar

Stargazers

Flavio Bellomo avatar Giuseppe Tomarchio avatar Alessandro Tomarchio avatar Paride Giunta avatar Gaetano Smario avatar Francisco Pablo Russo avatar

Watchers

James Cloos avatar  avatar Francisco Pablo Russo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.