;------------------------------------------------------------------------------------
;   1 May 20 - Richard Woodruff - Create for quick checkout
;------------------------------------------------------------------------------------
; VBAR for CSL is 0000000070010800
;

 LOCAL &emulation
 &emulation="no"

 RESet
 SYStem.RESet
 SYStem.CPU AM625X

 SYStem.Option RESBREAK OFF
 SYStem.Option EnReset OFF
 IF "&emulation"=="yes"
 (
  System.Option MemStatusCheck ON
  System.CONFIG DEBUGTIMESCALE 32.
  SYStem.POLLING OFF
  setup.urate 2500.ms           ; slow window updates, this can be bigger
  system.polling slow           ; sparse pinging
  system.JTAGCLOCK rtck 100Khz
 )
 ELSE
 (
  system.JTAGCLOCK CTCK 25MHz
 )

 core.assign 1.
 system.Option.IMASKASM.on
 system.Option.IMASKHLL.on
 system.MemAccess.DAP
 core.assign 1

 IF SIMULATOR()
   SIM.CACHE.ON
 ELSE
   trace.METHOD.Onchip

 trace.off

 stm.TimeStampCLOCK 250Mhz

 SYStem.Mode Up
 break

; Clear/setup system regs from AARCH64-EL3 
 R.S M 0x0d
 PER.Set.simple SPR:0x34200 %Quad 0x0
 PER.Set.simple SPR:0x36200 %Quad 0x0
 PER.Set.simple SPR:0x34210 %Quad 0x0
 PER.Set.simple SPR:0x34212 %Long 0x0
 PER.Set.simple SPR:0x30201 %Quad 0x0
 PER.Set.simple SPR:0x30200 %Quad 0x0
 PER.Set.simple SPR:0x36112 %Quad.Long 0x0   ; CPU quirk, clear CPTR_EL3.TFP, don't trap FPEN for ASMD!
 PER.Set.simple C15:0x6 %Long 0x0
 PER.Set.simple SPR:0x30C00 %Quad 0x701F0000
 PER.Set.simple SPR:0x34C00 %Quad 0x701F0000
 PER.Set.simple SPR:0x36C00 %Quad 0x701F0000
 PER.Set.simple SPR:0x30600 %Quad 0x0
 PER.Set.simple SPR:0x34600 %Quad 0x0
 R.S R13_USR 0x44051000
 R.S R13_SVC 0x44051000
 R.S R13_UND 0x44051000
 R.S R13_IRQ 0x44051000
 R.S R13_ABT 0x44051000
 R.S R13_HYP 0x44051000
 R.S R13_FIQ 0x44051000
 R.S SP_EL0 0x44051000
 R.S SP_EL1 0x44051000
 R.S SP_EL3 0x44051000
 R.S SP_EL2 0x44051000
 PER.Set.simple SPR:0x30520 %Long 0x0
 PER.Set.simple SPR:0x34520 %Long 0x0
 PER.Set.simple SPR:0x36520 %Long 0x0
 PER.Set.simple SPR:0x34604 %Quad 0x0
 PER.Set.simple SPR:0x31F21 %Quad 0x40

; Now got to AARCH32 and get ready for legacy TI-CC binary
 R.S M 0x13   ; go to svc
 PER.Set.simple C15:0x1 %Long 0x00C50838        ; cache and mmu off
 PER.Set.simple C15:0x5 %Long 0x0
 PER.Set.simple C15:0x206 %Long 0x0
 PER.Set.simple C15:0x105 %Long 0x0
 R.S NS 1
 PER.Set.simple C15:0x101 %Long 0x3
 PER.Set.simple C15:0x1 %Long 0x00C50838        ; cache and mmu off
 R.S T 0                                        ; arm mode (not thumb2)
 R.S I 1                                        ; no irq
 R.S F 1                                        ; no fiq
; R.S A 1			 		; maybe should enable... to catch error
 R.S E 0                                        ; little endian data only
 PER.Set.simple C15:0x0C %Long 0x701F0000       ; VBAR or no SVC semi-host (TBD relocate) 
 PER.Set.simple C15:0x102 %Long 0x0             ; clean up any old ttbr1 (reset would be better)
 PER.Set.simple C15:0x202 %Long 0x0

; setup some dummy globals in ocmc
;; data.set asd:0x701F0000++0x4fff 0x0            ; clear part of ocmc for vects
;; D.A NSR:0x701F0000 b 0x701F0000                 ; setup some dummy vectors
;; D.A NSR:0x701F0004 b 0x701F0004
;; D.A NSR:0x701F0008 b 0x701F0008
;; D.A NSR:0x701F000c b 0x701F000c
;; D.A NSR:0x701F0010 b 0x701F0010
;; D.A NSR:0x701F0014 b 0x701F0014
;; D.A NSR:0x701F0018 b 0x701F0018

; configure and open semihosting channel for IO (GCC)
 b.s 0x70010800 /onchip                          ; set breakpoint to SVC (SWI) vector
 TERM.reset
 TERM.HEAPINFO 0x701F1000 0x701F2000 0x701F4000 0x701F3000   ; these are not right for HW
 TERM.METHOD armswi
 TERM.Mode STRING                        ; allow for ascii escape code usage
; TERM.mode ascii
 TERM.size 80. 50. 200.
 WinPOS 120.71 0.083333 89. 36. 0. 0. W001
 TERM.GATE

; go to EL3 to get going
 R.S M 0x0d

 data.load.elf ~~~~/AM62x_LINUX_MEMTESTER_A53.out

; patch method two: break point and change registers before go
; b memtester
; go
; screen.wait !state.run()         ; wait for break to complete
; Register.Set X1 0x400            ; change input parameters
; Register.Set X2 0x10

 b.s avv_done /onchip              ; stop when done

; Open and place a few windows for checkout
 WinPOS 2.5714 0.0 124. 26. 24. 1. W003
 WinTABS 10. 10. 25.
 ws.LIST /markPC

 WinPOS 132.43 28.833 53. 35. 0. 0. W002
 ws.register.view /sl

 WinPOS 1.7143 28.5 125. 28. 25. 2. W004
 Trace.Chart.sYmbol

 WinPOS 2.2857 63.417 186. 16. 42. 1. W005
 WinTABS 42. 8. 10. 39. 10. 33.
 ; mmu.list pagetable

 go

ENDDO