; --------------------------------------------------------------------------------
; @Title: QNX Demo for TRACE32 OS Awareness
; @Description: 
;   
;   This batchfile demonstrates the use of
;   the RTOS-Debugger for QNX
;   
;   The example is generated for an IBM Walnut 504GP board using an ICD.
;   It will NOT run on any other board, but may be used as a template for
;   others.
;   QNX will be downloaded either via Boot Monitor using BOOTP, or via ICD.
;   start with "do qnx bootp" for BOOTP loading,
;   start with "do qnx icd"   for ICD loading (default).
;   
;   
; @Keywords: awareness, qnx, RTOS, walnut
; @Author: DIE
; @Chip: PPC405GP
; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: qnx.cmm 13125 2018-09-11 14:03:01Z rdienstbeck $

;   Created by Rudi Dienstbeck / Lauterbach GmbH at 21.06.2002

; For Walnut Boot Monitor settings, please refer to the QNX manual
; "Getting the QNX RTOS Running on Your Board"

; Starting QNX example with TRACE32 and Hyperterminal:
; - Start TRACE32
; - Open Hyperterminal, connected to RS232-1:
;   - 9600 baud, 8/N/1, no(!) handshake
; - (T32) do qnx
; - if bootp loading: (HT)  0
; - (HT)  helloloop

ENTRY &loadmode
IF "&loadmode"==""
  &loadmode="icd"
IF "&loadmode"=="BOOTP"
  &loadmode="bootp"

 SCREEN.ON

; Debugger Reset

 WinPAGE.RESet
 AREA.RESet
 WinPOS 0. 26. 75. 9. 0. 0. W000
 AREA.view
 
 PRINT "resetting..."

 SYStem.Down
 Break.RESet
 MAP.RESet
 sYmbol.RESet
 TRANSlation.RESet
 
; setup of ICD
 
 PRINT "initializing..."
 SYStem.CPU PPC405GP
 SYStem.Option MMU ON       ; enable space ids to virtual addresses
 SYStem.Up
 Register.RESet
 SETUP.IMASKASM ON      ; disable interrupts at assembler single step
 SCREEN.ALways
 
 ;Break.SELect Program Onchip

; We'd like to see something, open a code window.
 WinPOS 0. 0. 77. 22. 13. 1. W001
 List.auto
 
; Target Setup

 IF "&loadmode"=="bootp"
 (
   ; if you want to load the image via BOOTP (much faster):
 
   ; we wait for an input in the terminal until startup starts
 
   Data.LOAD.Elf startup-walnut /NoCODE /RELOC .text at 0x30100
   Break.Set main /Program /Onchip
   PRINT "please enter '0' in the terminal window..."
   Go.direct
   WAIT !run()
   Break.Delete main
 )
 ELSE
 (
   ; if you want to load the image via ICD
 
   ; let the boot monitor setup the board
   Go.direct
   WAIT 3.s
   Break.direct
   
   ; load the image to the load address
   ; image header size is 0x20
   ; load address can be found in the header at offset 0x04
   ; start address can be found in the header at offset 0x10
   Data.LOAD.Binary walnut.openbios 0x30000-0x20
   Data.LOAD.Elf startup-walnut /NoCODE /RELOC .text at 0x30100
   Register.Set PC _start
   Go.direct main /Onchip
 )
 
; Switch on debugger address translation
 TRANSlation.ON
 TRANSlation.COMMON 0--0xfffff  ; kernel area is common for all MMU space ids

; Load and Relocate Symbols of procnto
; Loadfile:
; The QNX Awareness needs the symbols contained in procnto!
; Use the procnto file, which you used to build your QNX 
; system; the procnto file can be found in the directory
; /ppc/boot/sys
; Relocation:
; use "dumpifs -vvv image procnto" to get the segment addresses
; of procnto out of your QNX image. 
; Segment 0: p_vaddr specifies the text segment address
; Segment 1: p_vaddr specifies the data segment address
; use the other segments as noted below

 PRINT "loading procnto..."
 Data.LOAD.Elf procnto-400 /NoCODE /RELOC .text at 0x3d000 /RELOC .text_kernel AFTER .text /RELOC .rodata AFTER .text_kernel /RELOC .data at 0x87000 /RELOC .got2 AFTER .data /RELOC .sdata AFTER .got2 /RELOC .bss AFTER .sdata
 
; Now let's boot and start QNX!
 
 PRINT "booting QNX..."
 Go.direct
 WAIT 3.s       ; let it run for 3 seconds
 Break.direct

; Initialize Mutitasking Support

 PRINT "initializing RTOS support..."
 TASK.CONFIG ../qnx       ; loads QNX awareness (qnx.t32)
 MENU.ReProgram ../qnx    ; loads QNX menu (qnx.men)
 
; --------------------------------------------------------------------------------
; Application Debugging
; e.g. "helloloop"

 DO ../app_debug helloloop

 ENDDO
 