; --------------------------------------------------------------------------------
; @Title: Script to read the PPC860 UPM
; @Description: 
;   This script reads the UPM and creates another
;   script which can be used to load the UPM with
;   the read values.
; @Keywords: linux, tqm850
; @Author: DIE
; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: readupm.cmm 6910 2014-04-21 15:39:40Z kjmal $


LOCAL &base &upm &addr &data

 &base=Data.Long(spr:0x27e)	; read IMMR
 &base=&base&0xffff0000     ; mask IMM base
 &upm=0                     ; 0 for UPM A, 1 for UPM B
 &addr=(&upm<<23)           ; start address

 ; open file and create header
 OPEN #1 writeupm.cmm /Create
 WRITE #1 "local &" "base"
 WRITE #1 " &" "base=data.long(spr:0x27e) ; IMMR"
 WRITE #1 " &" "base=&" "base&0xffff0000"

 ; for all UPM entries
 RePeaT
 (
   Data.Set &base+0x168 %Long 0x40000000+&addr       ; set MCR to read UPM
   &data=Data.Long(c:&base+0x17c)            ; read MDR
   WRITE #1 " Data.Set &" "base+0x17c %l " &data  ; write data to file
   WRITE #1 " Data.Set &" "base+0x168 %l " &addr  ; write MCR "write" command to file
   &addr=&addr+1                             ; next UPM address
 )
 WHILE (&addr&0x3ff)<0x40

 CLOSE #1
  
