Giter VIP home page Giter VIP logo

qemu-semihost's Introduction

ReadCounter โ€“ a trivial device for QEMU

This example demonstrates how to implement a simple virtual device for QEMU and access this device from a program compiled for ARM Cortex-M3 architecture.

The device is visible to the user program as a 32-bit memory-mmapped register that returns the number of times this register has been read.

The primary sources to look at are hw/arm/read_counter.c (device) and main.c (example usage).

To run the example, do the following:

git clone https://github.com/krasin/qemu-counter-hello.git
cd qemu-counter-hello
./test.sh

This script will ensure you have ARM EABI GCC toolchain (and download it, if missing), will build a modified QEMU from https://github.com/krasin/qemu-counter, build hello.c and run it under QEMU.

If not working, you might need to sudo apt-get install cmake gcc-multilib make glib2.0-dev libsdl1.2-dev dh-autoreconf

If working, after a few minutes of waiting, which will take to download all the dependencies and to build QEMU, you will hopefully see the following:

=============================================
Running QEMU w/o read_counter device
=============================================
This is a test program for QEMU counter device
See http://github.com/krasin/qemu-counter for more details

Let's check if the Read Counter device presented
The device has been accessed for 0 times!
The device has been accessed for 0 times!
The device has been accessed for 0 times!
The device has been accessed for 0 times!
The device has been accessed for 0 times!
The device has been accessed for 0 times!
The device has been accessed for 0 times!
The device has been accessed for 0 times!
The device has been accessed for 0 times!
The device has been accessed for 0 times!
ERROR - No Read Counter detected

=============================================
Running QEMU with read_counter device
=============================================
This is a test program for QEMU counter device
See http://github.com/krasin/qemu-counter for more details

Let's check if the Read Counter device presented
The device has been accessed for 1 times!
The device has been accessed for 2 times!
The device has been accessed for 3 times!
The device has been accessed for 4 times!
The device has been accessed for 5 times!
The device has been accessed for 6 times!
The device has been accessed for 7 times!
The device has been accessed for 8 times!
The device has been accessed for 9 times!
The device has been accessed for 10 times!
OK - Read Counter works as intended

After that you will be able to run it by hand as well:

$ ./qemu/build/arm-softmmu/qemu-system-arm -cpu cortex-m3 -nographic -monitor null \
-serial null -semihosting -device read_counter -kernel hello.elf
This is a test program for QEMU counter device
See http://github.com/krasin/qemu-counter for more details

Let's check if the Read Counter device presented
The device has been accessed for 1 times!
The device has been accessed for 2 times!The device has been accessed for 3 times!
The device has been accessed for 4 times!
The device has been accessed for 5 times!
The device has been accessed for 6 times!
The device has been accessed for 7 times!
The device has been accessed for 8 times!
The device has been accessed for 9 times!
The device has been accessed for 10 times!
OK - Read Counter works as intended

Happy QEMU hacking!

qemu-semihost's People

Contributors

jserv avatar krasin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.