mirror of
https://github.com/johnwinans/rvalp.git
synced 2025-10-01 07:02:20 -04:00
Add discussion of ebreak w/examples
This commit is contained in:
parent
c0274e55cd
commit
59ed75aa89
@ -1,9 +1,11 @@
|
|||||||
|
SUBDIRS=
|
||||||
|
# programs/src
|
||||||
|
|
||||||
TOP=..
|
TOP=..
|
||||||
include $(TOP)/Make.rules
|
include $(TOP)/Make.rules
|
||||||
|
|
||||||
TEXPATH=./float:./intro:./rv32:./copyright:./license:./elements:binary
|
TEXPATH=float:intro:rv32:copyright:license:elements:binary:programs/src
|
||||||
|
|
||||||
SUBDIRS=
|
|
||||||
|
|
||||||
all:: book.pdf
|
all:: book.pdf
|
||||||
|
|
||||||
|
@ -1,9 +1,42 @@
|
|||||||
\chapter{Writing RISC-V Programs}
|
\chapter{Writing RISC-V Programs}
|
||||||
|
|
||||||
|
|
||||||
\enote{Introduce the register names and aliases here.
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
Should we use ISA names or actual names here?}
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
\section{Using {\tt ebreak} to Stop \rvddt{} Execution}
|
||||||
|
|
||||||
|
The \insn{ebreak} instruction exists for the sole purpose of transferring control back
|
||||||
|
to a debugging environment.\cite[p.~24]{rvismv1v22:2017}
|
||||||
|
|
||||||
|
When \rvddt{} executes an \insn{ebreak} instruction, it will immediately terminate any
|
||||||
|
executing {\em trace} or {\em go} command currently executing and return to the
|
||||||
|
command prompt without advancing the \reg{pc} register.
|
||||||
|
|
||||||
|
The machine language encoding shows that \insn{ebreak} has no operands.
|
||||||
|
|
||||||
|
\DrawInsnTypeEPicture{ebreak}{00000000000100000000000001110011}
|
||||||
|
|
||||||
|
\listingRef{ebreak/ebreak.out} demonstrates that since \rvddt{} does
|
||||||
|
not advance the \reg{pc} when it encounters an \insn{ebreak} instruction,
|
||||||
|
subsequent {\em trace} and/or {\em go} commands will re-execute the same \insn{ebreak}
|
||||||
|
and halt the simulation again (and again).
|
||||||
|
This feature is intended to help prevent overzealous users from accidently
|
||||||
|
running past the end of a code fragment.\footnote{This was one of the first {\em enhancements}
|
||||||
|
I needed for myself \tt:-)}
|
||||||
|
|
||||||
|
\listing{ebreak/ebreak.S}{A one-line \insn{ebreak} program.}
|
||||||
|
|
||||||
|
\listing{ebreak/ebreak.out}{\insn{ebreak} stopps \rvddt{} without advancing \reg{pc}.}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
\section{todo}
|
||||||
|
|
||||||
|
|
||||||
|
\enote{Introduce the register names and aliases here.
|
||||||
|
Should we use ISA names or actual names here?}%
|
||||||
Ideas for order of introducing operations and instructions.
|
Ideas for order of introducing operations and instructions.
|
||||||
|
|
||||||
\section{Using {\tt addi} to Set Register Values}
|
\section{Using {\tt addi} to Set Register Values}
|
||||||
@ -20,9 +53,6 @@ Ideas for order of introducing operations and instructions.
|
|||||||
|
|
||||||
Demonstrate various addi instructions.
|
Demonstrate various addi instructions.
|
||||||
|
|
||||||
\section{Using {\tt ebreak} to Stopping rvddt Execution}
|
|
||||||
|
|
||||||
Introduce ebreak \& demonstrate.
|
|
||||||
|
|
||||||
|
|
||||||
\section{Other Instructions With Immediate Operands}
|
\section{Other Instructions With Immediate Operands}
|
||||||
|
55
book/programs/src/Make.rules
Normal file
55
book/programs/src/Make.rules
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
|
||||||
|
ARCH=riscv32-unknown-elf
|
||||||
|
|
||||||
|
CC=$(ARCH)-gcc
|
||||||
|
AS=$(ARCH)-as
|
||||||
|
LD=$(ARCH)-ld
|
||||||
|
OBJCOPY=$(ARCH)-objcopy
|
||||||
|
OBJDUMP=$(ARCH)-objdump
|
||||||
|
SIZE=$(ARCH)-size
|
||||||
|
|
||||||
|
#LDFLAGS+=-nostdlib -Wl,-Ttext=0x0,-Tdata=0x8000
|
||||||
|
LDFLAGS+=-nostdlib -Wl,-Ttext=0x0
|
||||||
|
|
||||||
|
CFLAGS+=-ffreestanding -fno-pic
|
||||||
|
CFLAGS+=-march=rv32i -mabi=ilp32
|
||||||
|
CFLAGS+=-Wl,--no-relax # see: https://github.com/riscv/riscv-gcc/issues/120
|
||||||
|
|
||||||
|
ASFLAGS+=$(CFLAGS)
|
||||||
|
|
||||||
|
CLEAN_DIRS=$(SUBDIRS:%=clean-%)
|
||||||
|
ALL_DIRS=$(SUBDIRS:%=all-%)
|
||||||
|
|
||||||
|
.PHONY: all clean world $(CLEAN_DIRS) $(ALL_DIRS)
|
||||||
|
|
||||||
|
|
||||||
|
%.bin : %
|
||||||
|
$(OBJCOPY) $< -O binary $@
|
||||||
|
|
||||||
|
%.lst : %
|
||||||
|
$(OBJDUMP) -dr $< > $<.lst
|
||||||
|
|
||||||
|
% : %.o
|
||||||
|
$(LINK.c) $(LDFLAGS) -o $@ $^ $(LDLIBS)
|
||||||
|
$(SIZE) -x -A $@
|
||||||
|
|
||||||
|
%.s: %.c
|
||||||
|
$(COMPILE.c) -S -o $@ $<
|
||||||
|
|
||||||
|
%.srec: %
|
||||||
|
$(OBJCOPY) $< -O srec $@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
all:: $(ALL_DIRS)
|
||||||
|
|
||||||
|
clean:: $(CLEAN_DIRS)
|
||||||
|
|
||||||
|
$(ALL_DIRS)::
|
||||||
|
$(MAKE) -C $(@:all-%=%) all
|
||||||
|
|
||||||
|
$(CLEAN_DIRS)::
|
||||||
|
$(MAKE) -C $(@:clean-%=%) clean
|
||||||
|
|
||||||
|
world:: clean all
|
6
book/programs/src/Makefile
Normal file
6
book/programs/src/Makefile
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
SUBDIRS=\
|
||||||
|
ebreak
|
||||||
|
|
||||||
|
TOP=.
|
||||||
|
include $(TOP)/Make.rules
|
1
book/programs/src/ebreak/.gitignore
vendored
Normal file
1
book/programs/src/ebreak/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
load4regs
|
18
book/programs/src/ebreak/Makefile
Normal file
18
book/programs/src/ebreak/Makefile
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
PROG=ebreak
|
||||||
|
|
||||||
|
all:: $(PROG).out $(PROG).lst
|
||||||
|
|
||||||
|
$(PROG).out:: $(PROG).bin
|
||||||
|
./run.sh > $@ 2>&1
|
||||||
|
|
||||||
|
$(PROG).bin:: $(PROG)
|
||||||
|
|
||||||
|
clean::
|
||||||
|
rm -f $(PROG) *.o *.lst *.bin *.srec *.out
|
||||||
|
|
||||||
|
TOP=..
|
||||||
|
include $(TOP)/Make.rules
|
||||||
|
|
||||||
|
|
||||||
|
|
6
book/programs/src/ebreak/ebreak.S
Normal file
6
book/programs/src/ebreak/ebreak.S
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
.text # put this into the text section
|
||||||
|
.align 2 # align to a multiple of 4
|
||||||
|
.globl _start
|
||||||
|
|
||||||
|
_start:
|
||||||
|
ebreak
|
10
book/programs/src/ebreak/run.sh
Executable file
10
book/programs/src/ebreak/run.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
prompt="$"
|
||||||
|
cmd="rvddt -f ebreak.bin"
|
||||||
|
echo "$prompt $cmd"
|
||||||
|
$cmd <<!
|
||||||
|
d 0 16
|
||||||
|
t 0 1000
|
||||||
|
t
|
||||||
|
g 0
|
||||||
|
r
|
||||||
|
!
|
Loading…
x
Reference in New Issue
Block a user