;----------------------------------------------------------------------------
;   Linux/Root + Linux/Cell on DRA821
; 13 Jul 20 - Richard Woodruff - DRA829 to DRA821
; 24 Aug 21 - Richard Woodruff - use OS.PPD() for demo
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
; Ability to debug dra821 Root Cell + Hypervisor 
 ; Add Linux or Windows paths to component symbols
 &opath="d:"
;&opath="/opt"
 &SYMS="&opath/syms/dra821/hypervisor" 
 &JH="&opath/ti/ti-jailhouse"
 IF VERSION.BUILD()>13839.
   &demo=OS.PDD()
 ELSE   
   &demo="~~/demo/arm64"

 RESet
 SYStem.RESet
 SYStem.CPU dra821
 SYStem.CONFIG CORE 1. 1. 
 CORE.ASSIGN 1.                      ; assign physical CPUs                        

 &GTCSPEED="200MHz"  ; 250MHz Default, SDK now sets down to 200MHz

 IF !INTERCOM.PING(INMATE)
   TargetSystem.NewInstance INMATE /ARCHitecture ARM64

 TITLE "TRACE32 for ARM64 - DRA821-A72-JH:RootCell - MASTER"
 IC INMATE TITLE "TRACE32 for ARM64 - dra821=A72x1-JH:InmateCell - SLAVE"

 IC INMATE RESet
 IC INMATE SYStem.RESet
 IC INMATE SYStem.CPU DRA821
 IC INMATE SYStem.CONFIG CORE 2. 1. 
 IC INMATE CORE.ASSIGN 2.                  ; assign physical CPU 
 IC ALL SYStem.memaccess dap               ; allow dap memory accesses
 IC ALL SYStem.JtagClock CTCK 25MHz        ; Choose compensated clock (can be sped up)
 IC ALL SYStem.Option ResBreak OFF         ; hardware dependent (see manual)
 IC ALL SYStem.Option WaitReset ON         ; hardware dependent (see manual)
 IC ALL SYStem.Option IMASKASM ON          ; lock interrupts while single stepping assembly
 IC ALL SYStem.Option IMASKHLL ON          ; lock interrupts while single stepping assembly
 IC ALL SYStem.Option ZONESPACES ON        ; separate NS/H/ZS zones - in all sessions
 IC ALL SYStem.Option MMUSPACES ON         ; separate TASK SPACES in Linux Session

 IC ALL Trace.DISable

 IC ALL CTS.UseConst OFF
 IC ALL CTS.UseMemory OFF
 IC ALL CTS.UseRegister OFF

 System.Mode Attach     ; q1-2019 builds need separate attach
 IC INMATE System.Mode Attach
 IC ALL Break

; -----------------------------------------------------------------------------
; Trace
(    
  IC ALL TPIU.PortMode Continuous
  IF Analyzer()
    IC ALL Trace.METHOD Analyzer
  ELSE
    IC ALL Trace.METHOD onchip
  IC ALL ETM.ContextID 32
  IC ALL ETM.Trace ON
  IC ALL ETM.ON
  IC ALL ETM.TimeStampCLOCK &GTCSPEED
  IC ALL ETM.TIMEMODE ASYNCTIMESTAMPS    ; add timestamps to ptm trace
  IC ALL Trace.clock 2000.MHz
  IC ALL ETM.VMID ON

  DO ~~~~/../dra821_tracemux.cmm 
)

; In hypervised system, we need to disable the reverse translation
  IC ALL SYStem.Option.MMUPhysLogMemaccess OFF

(
  PRINT "loading hypervisor symbols..."
  IC ALL data.load.elf "&SYMS/hypervisor.o" H:0x0  /nocode /plusvm
  IC ALL symbol.sourcepath.setrecursedir &JH

  PRINT "loading Linux symbols..."
  IC ALL data.load.elf "&SYMS/vmlinux" NS:0x0 /nocode /noclear /plusvm ; load up elf symbols
  print "initializing debugger MMU..."
  ; If in doubt, run linux\board\template CMM to determine.  ARM64 has a few layout possibilities
  MMU.FORMAT LINUXSWAP3 \\vmlinux\\swapper_pg_dir NS:0xffff0000110c5000++0xfff 0x00000000810c5000
  IC INMATE MMU.FORMAT LINUXSWAP3 \\vmlinux\\swapper_pg_dir NS:0xffff0000110c5000++0xfff 0x00000008e12c5000
  IC ALL TRANSlation.COMMON NS:0xf000000000000000--0xffffffffffffffff
  IC ALL TRANSlation.TableWalk ON
  IC ALL TRANSlation.ON
  IC ALL TASK.CONFIG "&demo/kernel/linux/awareness/linux.t32" /ACCESS NS:
  IC ALL MENU.ReProgram "&demo/kernel/linux/awareness/linux.men"

  PRINT "loading jailhouse symbols..."
  data.load.elf "&SYMS/jailhouse.ko" N:0x0  /nocode /noclear /plusvm /reloctype 3
  symbol.sourcepath.setrecursedir &JH
  EXTension.LOAD "&demo/kernel/jailhouse/jailhouse.t32" /ACCESS H:
  MENU.ReProgram "&demo/kernel/jailhouse/jailhouse.men"
  TRANSlation.COMMON H:0x0--0xffffffffffffffff
  ; Configure dtb access from hypervisor awareness
  &dtbphysical=address.offset(mmu.physical(N:v.value(initial_boot_params)))
  EXTension.jailhouse.Option DTB &dtbphysical

  IC ALL GROUP.Create "hypervisor" H:0x0--HX:0x0000ffffffffffff /BLUE
)

 IC ALL SYnch.CONNECT OTHERS
 IC ALL SYnch.MasterBreak ON
 IC ALL SYnch.MasterGo ON
 IC ALL SYnch.SlaveGo.on
 IC ALL SYnch.SlaveBreak.ON
 IC ALL SYnch.ON
 IC ALL SYnch.Xtrack others

 ; Open up trace Analysis windows
 ;Trace.STATistic.TASK                ; display per thread stats
 ;a.stat.Y /t /SORT RATIO             ; display per symbol stats (kernel)
 ;a.chart.Y /t /SORT RATIO            ; show timeline
 ;trace.chart.task
 ;trace.profilechart.task

ENDDO
