XO 4 Hardware peek and poke

From OLPC
Jump to: navigation, search

Remember the BASIC peek() and poke() commands ? Hardware debugging frequently needs such an interface, and one is built into the XO-4 laptop at many levels.

Introduction

While peek() and poke() exposed the raw machine, the rest of BASIC is best forgotten. The Forth language provides an ideal low-overhead interpreter for hardware debugging, and much of the XO hardware debugging involved working in the XO laptop's native Open Firmware, sometimes over a serial console. This page discusses a method for playing around with the bare metal in Forth on the XO-4 laptop while simultaneously running other applications in Linux.

sdkit

On OLPC OS builds, a Forth interpreter (sdkit) capable of accessing the hardware is available in /runin/sdkit-arm. It can be started from a Terminal:

$ su
# cd /runin/sdkit-arm
# RUNIN_PATH=/runin ./sdkit.sh
ok 

Much more information about using sdkit (including installing it on systems where it isn't already available) is found in Forth Lesson 22.

XO-4 HDMI Registers

In order to access hardware registers such as the HDMI controller, you first need to map a range of the physical address space into the virtual address space used within sdkit:

ok D420.B000 1000 mmap constant hdmi-base
ok hdmi-base c08 + l@ .   \ reads the 32b contents of HDMI_PHY_CFG0 at D420.BC08 and prints them

To modify a register, for example setting bit 1, simply:

ok hdmi-base c08 + dup l@ 2 or l!

New to Forth ?

You should spend ten minutes reading Forth Lesson 0 and Forth Lesson 1.