; --------------------------------------------------------------------------------
; @Title: Load an example APU for a simulated coprocessor and an example program.
; @Description:
;   This script loads the APU library, which first has to be compiled by the
;   user, for example by using the provided Makefiles.
;
;   See the comments in example_address_translation.c for further information.
;
;   Example:
;   CD ~~/demo/apu/example_address_translation
;   OS.Area make
;   DO example_address_translation.cmm
; @Author: MPL
; @Copyright: (C) 1989-2016 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id$

; The simulated APU has the following memories:
;
;  - Program memory:
;     - Mapped at main core address D:0x20000000
;     - memory access unit 4 bytes
;  - Data memory:
;     - Mapped at main core address D:0x10000000
;     - memory access unit 2 bytes
;
; Note that symbols always live in the main core's address space and that
; TRACE32 makes no distinction between main core and APU symbols.
;
; APU addresses in the command line are in words (so in APU commands, the range
; P:0x0++3. is 16 bytes long. If a symbol is used on the APU command line, it
; is converted to an APU address.

PRIVATE &ppd &name &architecture &extension

IF !SIMULATOR()
(
	PRINT %WARNING "This demo is intended to be used in simulator mode. For a real target. you most likely need to adjust MEMORY_BASE_ADDRESS_DATA and MEMORY_BASE_ADDRESS_PROGRAM in example_address_translation.c"
)
ELSE
(
	SYStem.Up
)

&ppd=OS.PPD()
&name="example_address_translation"

IF OS.NAME()=="Linux"
(
  &extension="so"
)
ELSE IF OS.NAME()=="Windows"
(
  &extension="dll"
)
ELSE
(
  PRINT %ERROR "Unsupported OS"
  ENDDO FALSE()
)

&architecture=""
IF SOFTWARE.64BIT()
(
  &architecture="64"
)

APU.LOAD &ppd/&name&architecture.&extension

APU.Data.Set P:0x00000000 %Long %LE 0x00000000 ; NOP
APU.Data.Set P:0x00000001 %Long %LE 0x02000010 ; INC [0x00000010]
APU.Data.Set P:0x00000002 %Long %LE 0x00000000 ; NOP
APU.Data.Set P:0x00000003 %Long %LE 0x00000000 ; NOP
APU.Data.Set P:0x00000004 %Long %LE 0x02000020 ; INC [0x00000020]
APU.Data.Set P:0x00000005 %Long %LE 0x00000000 ; NOP
APU.Data.Set P:0x00000006 %Long %LE 0x01000000 ; JMP 0x00000000

; load symbols for some random program to get a uint16_t type
Data.LOAD.Elf ~~/demo/arm/compiler/gnu-pic/sieve_arm.elf 0 /NoCODE

sYmbol.CREATE.Label    inc1 P:0x20000004
sYmbol.CREATE.Label    inc2 P:0x20000010
sYmbol.CREATE.Function main P:0x20000000++0x1B
sYmbol.CREATE.Var      val1 D:0x10000020 uint16_t
sYmbol.CREATE.Var      val2 D:0x10000040 uint16_t
sYmbol.CREATE.Done

; get rid of the symbols loaded above
sYmbol.Delete \\sieve_arm

APU.Data.List P:0x00000000
APU.Data.dump P:0x00000000 /NoAscii /SpotLight
APU.Data.dump D:0x00000000 /NoAscii /SpotLight
APU.Break.List
AREA.view

PRINT "Virtual APU example with address translation loaded."

ENDDO TRUE()
