Notice: We have migrated to GitLab launching 2024-05-01 see here:

Version 23 (modified by Gedare Bloom, on 11/09/15 at 17:41:33) (diff)

add cmdline for qemu leon3


This BSP is for the LEON3/4 SPARC V8 processor developed by Cobham Gaisler. LEON3/4 is available as a synthesizable VHDL model, allowing custom implementations on FPGA and/or ASIC. The LEON3/4 BSP probes AMBA Plug&Play information for basic peripherals such as interrupt controller, timer, and UART. Probing the Plug&Play makes it possible for the BSP to supports many LEON3/4 based controllers and boards. The BSP supports both SMP and AMP configurations.

The basic peripherals supported:


The BSP supports three network interfaces: the GRETH 10/100/1000, the Opencores Ethernet MAC and the LAN91C111 i/f.

  • Ethernet (GRETH 10/100/1000)
  • CAN, OC_CAN (Opencores CAN GRLIB wrapper)
  • 1553, 1553BRM
  • SpaceWire, GRSPW
  • PCI drivers to RASTA, Companion Chip

System Console

The LEON3/4 BSP has support for the RTEMS console interface and the debug UART interface (printk). The first UART found is by default selected as debug and system console. However, it is possible to override the default settings by declaring an integer named debug_uart_index and/or syscon_uart_index. Setting the variable to N will select the Nth UART for either debug UART or system console. Note that on a AMP system (RTEMS MP) the default is to use APBUART[0] for CPU0, APBUART[1] for CPU1 and so on.

/dev/console_a is by default renamed /dev/console and assigned minor=0, but the user can select /dev/console_['a'+N] to be renamed to /dev/console by setting syscon_uart_index=N. See table below.

0 /dev/console Default APBUART[0], user selectable through syscon_uart_index
1 /dev/console_a APBUART[0] (missing by default)
2 /dev/console_b APBUART[1]

On a MP system the console renamed to /dev/console is selected by CPU index (LEON3_Cpu_Index). /dev/console_['a' + LEON3_Cpu_Index] is renamed unless overridden. Resource sharing is performed by the user, one should not open/access a console that another OS instance uses.

The console driver can operate in polling mode or interrupt mode. Which mode is used is selected at compile time using the CONSOLE_USE_INTERRUPT configuration option. All UARTs operate in the same mode.

SMP Support

The interrupt controller, timer, and UART drivers are all SMP safe. For other drivers one need to ensure that all communication with the driver is done on the same CPU that handles interrupts for the driver. Any driver helper task need to have its affinity set to the same CPU. For the network driver tasks this can be done by setting the default network task CPU affinity in the rtems_bsdnet_config struct.

Static Interrupt Affinity

CPU affinity can be assigned to individual interrupts. By default interrupts are processed by the boot CPU, but this can be changed by defining the weakly linked table const unsigned char LEON3_irq_to_cpu[32] in the user program. This makes it possible to specify which CPU a specific interrupt should be routed to. The array index is the interrupt to be rerouted and the array[INTERRUPT] content is the CPU number relative to the boot CPU index that will be servicing the interrupts from the IRQ source.

Selecting IRQ for Inter-processor Interrupts

Inter-processor interrupts are used in the communication between CPUs. By default IRQ 14 is used, but on some systems this can conflict with an IP core using the same IRQ. Defining the weakly linked variable const unsigned char LEON3_mp_irq in the user program makes it possible to decide which IRQ should be used instead, allowing the conflict to be avoided.

The GR712 uses IRQ 14 for the GRETH Ethernet controller and needs the inter-processor IRQ to be changed for the network driver to work properly.


GRMON is a general debug monitor for the LEON processor. It is used to download, execute, and debug applications for LEON-based systems. This section gives a quick overview of some basic operations. For more information, see the GRMON manual.

Loading an RTEMS Application

Start GRMON with the flag corresponding to debug link you want to use (for example -usb). To tunnel console output (see below), use the -u flag.

  GRMON2 LEON debug monitor
  Copyright (C) Aeroflex Gaisler - All rights reserved.
  For latest updates, go to
  Comments or bug-reports to

Parsing -usb
Parsing -u

  Device ID:           0x281
  GRLIB build version: 4114
  Detected system:     NGMP FP
  Detected frequency:  150 MHz
  Component                            Vendor
  JTAG Debug Link                      Aeroflex Gaisler
  GRSPW2 SpaceWire Serial Link         Aeroflex Gaisler
  EDCL master interface                Aeroflex Gaisler
  EDCL master interface                Aeroflex Gaisler
  USB Debug Communication Link         Aeroflex Gaisler
  LEON4 SPARC V8 Processor             Aeroflex Gaisler
  LEON4 SPARC V8 Processor             Aeroflex Gaisler
  LEON4 SPARC V8 Processor             Aeroflex Gaisler
  LEON4 SPARC V8 Processor             Aeroflex Gaisler
  General Purpose Register Bank        Aeroflex Gaisler
  Use command 'info sys' to print a detailed report of attached cores


The application can then be loaded onto the LEON system by using the load command.

grmon2> load testsuites/smptests/smp01/smp01.exe
  00000000 .text                    132.8kB / 132.8kB   [===============>] 100%
  00021320 .data                      1.5kB /   1.5kB   [===============>] 100%
  Total size: 134.25kB (24.99Mbit/s)
  Entry point 0x0
  Image testsuites/smptests/smp01/smp01.exe loaded

Execute the application with the run command.

grmon2> run

 CPU 3 start task TA0
 CPU 2 running Task TA0 
 CPU 3 start task TA1
 CPU 1 running Task TA1 
 CPU 3 start task TA2
 CPU 0 running Task TA2 
*** END OF TEST SMP 1 ***
  CPU 0:  Power down mode
  CPU 1:  Power down mode
  CPU 2:  Power down mode
  CPU 3:  Program exited normally.

Information about available RTEMS tasks can be listed using the thread info command.

grmon2> thread info
    NAME  TYPE      ID          CPU  PRIO  TIME (h:m:s)     ENTRY POINT              PC                                            STATE
    IDLE  internal  0x09010001    -   255  0:0:0.000000000  pwdloop                  0x0000197c <pwdloop+0x0>                      READY
    IDLE  internal  0x09010002    -   255  0:0:0.000000000  pwdloop                  0x0000197c <pwdloop+0x0>                      READY
    IDLE  internal  0x09010003    -   255  0:0:0.000000000  pwdloop                  0x0000197c <pwdloop+0x0>                      READY
    IDLE  internal  0x09010004    -   255  0:0:0.000000000  pwdloop                  0x0000197c <pwdloop+0x0>                      READY
    UI1   classic   0x0a010001    3     1  0:0:0.000000000  Init                     0x00002ca0 <syscall+0x0>                      READY
    TA0   classic   0x0a010002    2     1  0:0:0.000000000  Test_task                0x0000197c <pwdloop+0x0>                      READY
    TA1   classic   0x0a010003    1     1  0:0:0.000000000  Test_task                0x0000197c <pwdloop+0x0>                      READY
  * TA2   classic   0x0a010004    0     1  0:0:0.000000000  Test_task                0x0000197c <pwdloop+0x0>                      READY

Connecting GDB to GRMON

GRMON can act as a remote target for GDB. To enable the GDB support, start GRMON with the -gdb flag or use the gdb start command inside GRMON.

grmon2> gdb start
  Started GDB service on port 2222.

Connect to the GDB service of GRMON by entering the following commands in GDB:

(gdb) target extended-remote :2222
(gdb) symbol-file testsuites/smptests/smp01/smp01.exe
(gdb) set remote exec-file testsuites/smptests/smp01/smp01.exe

GRMON commands can be entered in GDB by prepending them with monitor. For example:

(gdb) monitor info reg greth0
GR Ethernet MAC
    0xff940000  Control register                        0x9e000000
    0xff940004  Status register                         0x00000000
    0xff940008  MAC address MSB                         0x00006010
    0xff94000c  MAC address LSB                         0x00000081
    0xff940010  MDIO register                           0x7949084a
    0xff940014  Tx descriptor register                  0x4de06000
    0xff940018  Rx descriptor register                  0x00000000
    0xff94001c  EDCL IP register                        0xc0a8001f

Console forwarding to GRMON

Starting GRMON with the -u flag will set one UART in "debug-mode" or loop-back (older hardware) mode. UART output/input is then tunneled over the debug-link to the PC, instead of at the physical UART connector of the PCB, and presented in GRMON.

Note that it is not possible to use the interrupt mode of the driver together with the "old" APBUART and -u to GRMON. However the new APBUART core (from GRLIB 1.0.17-b2710) has the GRMON debug bit and can handle interrupts. Please see the GRMON manual.



  • patched Qemu is able to run LEON3 BSP. If you build Qemu with RSB it should just work. Use qemu-system-sparc -no-reboot -nographic -M leon3_generic -m 64M -kernel app.exe
  • RTEMS Tools GDB is also able to run LEON2/3 BSP

The startup procedure for LEON BSPs is explained in SparcBSPStartup.

Test Reports

4.6.4: Jiri reports that it runs fine on the TSIM simulator, and boards from Pender Jiri reports that it runs fine on the simulator, and on boards from Pender runs on GR-XC3S-1500 board - tested with networking (greth) Daniel Sep 5 2007, Tested GRETH 10/100, B1553BRM(on RASTA over PCI, on Companion Chip over PCI, direct), GRCAN(on RASTA over PCI), OC_CAN(on Companion Chip over PCI, direct) Tested on GR712RC and GR-CPCI-LEON4-N2X