## Here is a sample .gdbinit file for use with the gdb debugger.  If
## you run gdb and select the target 'sim', you can run the program in
## the simulator without having any actual ARM hardware.  As it is,
## this file is set up to run the riscy.asm (riscy.s) (riscy.elf)
## program on an LPC2378 board via a JTAG cable and openOCD.

## from within Emacs, try starting gdb with
##   M-x gdb RET gdb-arm -nx -x /home/frank/riscy/p2378/.gdbinit --annotate=3 riscy.elf
## or
##   M-x gdb RET gdb-arm -nx -x /home/frank/riscy/p2378/.gdbinit --annotate=3 

## above says to ignore the .gdbinit file in ~/ but load the one in .../p2378

set complaints 1
set output-radix 0x10
set input-radix 0x10

# LPC ARM chips are *always* little endian
set endian little

dir
#cd /home/frank/riscy/p2378
dir /home/frank/riscy/p2378
set prompt (arm-gdb-riscy) 

file
file riscy.elf

# connect to the simulator
#target sim

# connect to openocd running on gdb port 3333
# (you must have started openocd first)
target remote localhost:3333

#sleep 2
# This is needed so we can debug in flash memory
monitor arm7_9 force_hw_bkpts enable

# Load the program executable.  
#load riscy.elf
# It is already loaded into flash.  However, if not, it can
# be done with monitor commands such as 
#     monitor flash erase 0 0 3
#     monitor flash write 0 riscy.bin 0

# Reset the chip to get to a known state.
#monitor reset
#monitor halt

# LPC Init Values
# Disable IRQ & FIRQ, set SVC mode
#set $cpsr = 0xd3

# Increase the packet size to improve download speed.
# Wish this didn't cause an "Are you sure?" popup.
# At least with small programs, they aren't needed.
#set remote memory-write-packet-size 1024
#set remote memory-write-packet-size fixed


# make it easy to turn on hardware breakpoints
define hw
  monitor arm7_9 force_hw_bkpts enable
end
document hw
  Enable hardware breakpoints
end

# reload our program into flash
define reload
  monitor flash erase 0 0 1
  #monitor flash write 0 /home/frank/riscy/p2378/riscy.bin 0
  monitor flash write 0 /home/frank/riscy/p2378/combo.bin 0
end
document reload
  Burn the flash with latest riscy.bin
end


# Set a breakpoint
#b _start

# Run to the breakpoint.
#c


echo ~/riscy/p2378/.gdbinit loaded sucessfully\n





