; --------------------------------------------------------------------------------
; @Title: Linux Demo for TRACE32 OS Awareness for the OMAP H4 Board
; @Description: 
;   This script is supposed to attach to a running Linux on TI OMAP H4 board. 
;   The Task Awareness + Debugger Address Translation are prepared as for the 
;   GSRD. After execution of this script the debugger is ready for Process, 
;   Kernel, optional Module and optional Library debugging.
;   It will NOT run on any other board, but may be used as a template
;   for others.
; @Keywords: awareness, OMAP24*, omaph4
; @Board: OMAP-H4
; @Chip: OMAP2420
; @Copyright: (C) 1989-2019 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: omap_h4_linux_attach.cmm 16133 2020-06-01 11:09:18Z mcharfi $


; Starting Linux example with TRACE32:
; - Connect NULL modem cable to J9/serial connector on debug board
; - Open terminal: 115200 baud, 8/N/1, no(!) handshake
; - Start TRACE32
; - Power on H4 board
; - TRACE32: do omap_h4_linux_attach


LOCAL &ka_path &awareness

 SCREEN.ON


; Debugger Reset

  WinPAGE.RESet
  AREA.RESet
  WinPOS 0. 26. 75. 8. 0. 0. W000
  AREA.view
 
  PRINT "resetting..."

  SYStem.Down
  TASK.RESet
  Break.Delete
  MAP.RESet
  sYmbol.RESet
  TRANSlation.RESet


; Initializing Debugger
 
  PRINT "initializing..."
  SYStem.CPU OMAP2420
  SYStem.Option DACR ON          ; give Debugger global write permissions
  TrOnchip.Set DABORT OFF        ; used by Linux for page miss!
  TrOnchip.Set PABORT OFF        ; used by Linux for page miss!
  TrOnchip.Set UNDEF OFF         ; used by Linux for detecting not existent units
  SYStem.Option MMUSPACES ON     ; enable space ids to virtual addresses
  SYStem.Option ResBreak OFF
  SYStem.Option EnReset OFF
  SYStem.JtagClock RTCK 20MHz    ; use adaptive clocking for most speed
  SETUP.IMASKASM ON              ; lock interrupts while single stepping
 
; declare read-only memory
  MAP.BOnchip 0x00000000--0x401fffff

  SYStem.Attach
  Break.direct
  WAIT !STATE.RUN()
  
; Load the Linux kernel symbols into the debugger
 ; use /strippart and /path to map source paths, if necessary
 
  PRINT "loading Linux kernel symbols..."
  Data.LOAD.Elf vmlinux /gnu /NoCODE
 

; Open a Code Window -- we like to see something

  WinPOS 0. 0. 75. 20.
  List.auto
  SCREEN.display
 
 
; Declare the MMU format to the debugger
 ; - table format is "LINUX"
 ; - table base address is at label "swapper_pg_dir"
 ; - kernel address translation
 ; Map the virtual kernel symbols to physical addresses to give 
 ; the debugger access to it before CPU MMU is initialized

  PRINT "initializing debugger MMU..."
  MMU.FORMAT LINUX swapper_pg_dir 0xc0000000--0xc3ffffff 0x80000000
  TRNASlation.COMMON 0xc0000000--0xffffffff            ; common area for kernel and processes
  TRNASlation.TableWalk ON   ; debugger uses a table walk to decode virtual addresses
  TRNASlation.ON             ; switch on debugger(!) address translation 
 
 ; Initialize Linux Awareness
  ; Note that the Linux awareness needs the kernel symbols to work 
  PRINT "initializing RTOS support..."
  ; Choose the correct Linux major version below
  ;TASK.CONFIG ~~/demo/arm/kernel/linux/linux-2.x/linux.t32     ; loads Linux awareness for linux-2.x
  ;MENU.ReProgram ~~/demo/arm/kernel/linux/linux-2.x/linux.men  ; loads Linux menu  for linux-2.x
  TASK.CONFIG ~~/demo/arm/kernel/linux/linux-3.x/linux3.t32     ; loads Linux awareness for linux-3.x
  MENU.ReProgram ~~/demo/arm/kernel/linux/linux-3.x/linux.men  ; loads Linux menu  for linux-3.x
  
  Go.direct

  Mode.Hll

  ENDDO