; --------------------------------------------------------------------------------
; @Title: NetBSD Demo for TRACE32 OS Awareness
; @Description: 
;   
;   This batchfile demonstrates the use of the OS Awareness for NetBSD
;   
;   The example is generated for an IBM Walnut 405GP board using an ICD.
;   It will NOT run on any other board, but may be used as a template
;   for others.
;   
;   NetBSD will be downloaded via ICD.
;   
; @Keywords: awareness, netbsd, RTOS, walnut
; @Author: DIE
; @Board: IBM-Walnut-405GP
; @Chip: PPC405GP
; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: netbsd.cmm 13125 2018-09-11 14:03:01Z rdienstbeck $


; IMPORTANT NOTE !!!
; --------------------------------------------------------------------------------

; sys\arch\evbppc\walnut\macdep.c, initppc():
;   Don't handle the trap instruction inside the target.
;   TRACE32 needs it, so comment this out.

; Starting NetBSD example with TRACE32 and Terminal:
; - Connect NULL modem cable to J11/RS232-1 (lower jack)
; - Start TRACE32
; - Open Terminal: 9600 baud, 8/N/1, no(!) handshake
; - TRACE32: do netbsd
; - Terminal: open a shell and start "/uname"


 ;screen.on
 SCREEN.ALways      ; to update terminal window permanently


; Debugger Reset

 WinPAGE.RESet
 AREA.RESet
 WinPOS 0. 21. 70. 9. 0. 0. W000
 AREA.view
 
 PRINT "resetting..."

 sYmbol.RESet
 SYStem.RESet
 TASK.RESet
 Break.RESet
 MAP.RESet
 TRANSlation.RESet

 
; Open terminal window
 TERM.METHOD COM COM1 9600.
 WinPOS 20. 3. ,,,,, TERM.view 
 TERM.view
 

; Initializing Debugger

 PRINT "initializing..."
 SYStem.CPU PPC405GP
 SYStem.BdmClock 10.0MHz
 SYStem.Option MMUSPACES ON     ; enable space ids to virtual addresses
 SYStem.Up
 Register.RESet
 

; Target Setup

 PRINT "target setup..."

; if you want to load the image via ICD

 IF !SIMULATOR()
 ( 
   ; let the boot monitor setup the board
   Go.direct
   WAIT 3.s
   Break.direct
 )


; Load the NetBSD image
   
 ; Use the next lines only to load the NetBSD image into
 ; RAM using the debugger.
   
 PRINT "loading NetBSD image..."
 Register.RESet
 Data.LOAD.Elf netbsd-Lauterbach_install


; Load the NetBSD kernel symbols into the debugger

 PRINT "loading NetBSD kernel symbols..."
 Data.LOAD.Elf netbsd.gdb /StripPART "/mnt/develop" /PATH "S:\" /NoCODE
   

; Initializing Debugger MMU

 TRANSlation.RESet
 TRANSlation.Create 0x0--0x017FFFFF 0x0     // map kernel pages manually
 TRANSlation.COMMON 0x0--0x017FFFFF         // valid for all space ids
 TRANSlation.ON
   
 WinPOS 0. 0. 75. 18.
 List.auto
 
 wintop TERM.view

; Initialize RTOS Support

 ; Note that the NetBSD awareness needs the kernel symbols to work
 
 PRINT "initializing NetBSD support..."
 TASK.CONFIG ../netbsd       ; loads NetBSD awareness (netbsd.t32)
 MENU.ReProgram ../netbsd    ; loads NetBSD menu (netbsd.men)
 HELP.FILTER.Add rtosnetbsd  ; add NetBSD awareness manual to help filter

 ; switch on autoloader
 
 sYmbol.AutoLOAD.CHECKLINUX "do "+OS.PPD()+"/../autoload "

; Group kernel area to be displayed with red bar

 GROUP.Create "kernel" 0x0--0x017FFFFF /RED


; Starting NetBSD

 Go.direct start_init
 PRINT "trapping NetBSD..."
 WAIT !run()

 Go.direct
 PRINT "booting NetBSD..."
 WAIT 2.s
 Break.direct
 
 PRINT "scanning swapper..."
 TASK.MMU.SCAN proc0
 
 Go.direct
 
 PRINT "starting shell..."
 WAIT 1.s
 TERM.Out 0x0d      // Terminal type? [vt100]
 WAIT 2.s
 TERM.Out "S" 0x0d    // (S)hell
 
 PRINT "done."     ; done with loading and starting Linux
 

; --------------------------------------------------------------------------------
; Application Debugging
; e.g. "uname"

 DO ../app_debug uname

 ENDDO
 
