(Category) CGEN Faq-O-Matic
Please add any questions/answers about CGEN here and/or on the cgen@sources.redhat.com mailing list.
(Answer) How does one build and run cgen?
(Answer) How does one regenerate the CGEN-related parts of a toolchain?

(Category) To-do items
(Answer) I can't load "dev.scm" into guile
(Answer) Does CGEN run on guile 1.6?
(Answer) Using CGEN with cygwin
(Answer) dni format description

[New Answer in "CGEN Faq-O-Matic"]
(Answer) (Category) CGEN Faq-O-Matic :
How does one build and run cgen?
Quick answer: one doesn't.

CGEN is written in Scheme, and is usually run via a Scheme interpreter such as Guile. Therefore, no explicit configure/compile step is required for cgen itself.
Normally, the interpreted cgen sources, as well as files generated by cgen, all sit within in a common source tree that also includes the cgen-generated tools (the opcodes library and the various simulators). In a build tree configured from such a source tree, cgen rarely needs to be run: only when its inputs (.cpu/.opc description files, or .scm cgen sources) are changed. Even in such cases, cgen is rarely run by hand: instead, cgen is invoked via the make program in the generated tools directories.

See also:

    http://www.airs.com/ian/configure
    http://www.fsf.org/software/guile
    http://sources.redhat.com/fom/cgen?file=7

fche@redhat.com
I am currently trying to install CGEN. However, after running the ./configure in the top-directory I try to run make and basically nothing happens (no compilation or anything - it just says 'nothing to do'). A following make install command doesn't (of course) result in anything. I have looked in the generated Makefile and can see nothing wrong (but I am not a Makefile expert). I am very anxious to get CGEN up running since I am currently working with the design of our next generation Ultra-low power DSP and need a tool like CGEN to describe/verify it. I use Caldera open Linux v2.3, kernel 2.2.13.
 
Thanks.
 
Jakob Nielsen
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  Jakob Nielsen                 jakob.nielsen@dspfactory.com
  Senior DSP Engineer
  Dspfactory Ltd.                Tel: +1-519-884-9696 x252
  80 King Street S., Suite 206   Fax: +1-519-884-0228
  Waterloo, ONT, CANADA          http://www.dspfactory.com/
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

jakob.nielsen@dspfactory.com
cgen manual in cgen doc area explains how to debug using dev.scm.
But for the impatient beginner, here are some hints to get started quick.
If you want to run cgen scripts in a different directory other than binutils/opcodes (GNU binutils),
copy binutils/opcodes/cgen.sh to the new directory, and create a makefile (Makefile) as follows:
####### Makefile begin srcdir=. cgendir = ./cgen/src/cgen CGEN = "guile -L $(cgendir) -l ${cgendir}/guile.scm -s" # directory where all cgen .scm files are CGENDIR = `pwd`/cgen/src/cgen CGENFLAGS = -v arch=tp01 prefix = tp01 archfile = `pwd`/tp01.cpu opcfile = `pwd`/tp01.opc extrafiles = options =
# remember to use use tab where necessary run-cgen:
       $(SHELL) $(srcdir)/cgen.sh opcodes $(srcdir) $(CGEN) \
         $(CGENDIR) "$(CGENFLAGS)" $(arch) $(prefix) $(archfile) $(opcfile) \
         "$(options)" "$(extrafiles)"
         touch stamp-${prefix} 
###### Makefile end
and run make. This example assumes that your cgen inputs are tp01.cpu, and tp01.opc.
Following text shows how cgen is called from binutils.
If you have gnu binutils downloaded and configured, cd to opcodes directory run
make -n stamp-m32r or make stamp-m32r
to see how m32r related files are generated using cgen.
opcodes directory contains a shell script "cgen.sh". If you insert set -x in this file, at the top, and run "make stamp-m32r", you will see how cgen guile scripts are called.
v2george@gmail.com
From George Varughese:

If you want to run cgen scripts in a different directory other than
binutils/opcodes (GNU binutils),

copy binutils/opcodes/cgen.sh to the new directory, and create a makefile
(Makefile) as follows:

####### Makefile begin
srcdir=.
cgendir = ./cgen/src/cgen
CGEN = "guile -L $(cgendir) -l ${cgendir}/guile.scm -s"
# directory where all cgen .scm files are
CGENDIR = `pwd`/cgen/src/cgen
CGENFLAGS = -v
arch=tp01
prefix = tp01
archfile = `pwd`/tp01.cpu
opcfile = `pwd`/tp01.opc
extrafiles =
options =

# remember to use use tab where necessary
run-cgen:
       $(SHELL) $(srcdir)/cgen.sh opcodes $(srcdir) $(CGEN) \
         $(CGENDIR) "$(CGENFLAGS)" $(arch) $(prefix) $(archfile) $(opcfile) \
         "$(options)" "$(extrafiles)"
         touch stamp-${prefix}

###### Makefile end

and run make. This example assumes that your cgen inputs are tp01.cpu, and
tp01.opc.

Following text shows how cgen is called from binutils.
   
If you have gnu binutils downloaded and configured, cd to opcodes directory
run
   
make -n stamp-m32r
or
make stamp-m32r
   
to see how m32r related files  are generated using cgen.

opcodes directory contains a shell script "cgen.sh". If you insert
set -x
in this file, at the top, and run "make stamp-m32r", you will see how cgen guile
scripts are called.
fche@redhat.com
[Append to This Answer]
(Answer) (Category) CGEN Faq-O-Matic :
How does one regenerate the CGEN-related parts of a toolchain?
When a target needs a change applied to its .cpu or .opc files, or cgen's
own .scm files, cgen must be rerun in order to propagate the changes to the
generated files elsewhere.

While some dependencies are recorded in the Makefiles, most or all are
approximate and incomplete (e.g., including only the .cpu file but not .opc;
including some .scm files of cgen itself but not all).  The safest way is to
regenerate cgen stuff by hand.  The problem is remembering what each build
directory's regeneration make target is:

opcodes:                         make stamp-TARGET
sim/TARGET:                      make stamp-arch stamp-cpu stamp-desc
sid/component/cgen-cpu/TARGET:   make cgen-all   

cgen puts the modified files back in the source tree.  When committing a
change to cgen inputs, one should commit the changes to regenerated files also.
fche@redhat.com
Before you execute these 'make ...' commands your build tree
has to be built. Otherwise you'll get errors like:

make: *** No rule to make target `../cgen/stamp-cgen', needed by `stamp-vpe4k'.
pbaranov@ubicom.com
[Append to This Answer]
(Category) (Category) CGEN Faq-O-Matic :
To-do items
Until a formal system like GNATS is required for tracking CGEN issues, please add Faq-O-Matic Answer objects for each item of interest.
fche@redhat.com
Known problems:
(Answer) Current CGEN bugs

Future enhancements:
(Answer) dummy ER

[New Answer in "To-do items"]
(Answer) (Category) CGEN Faq-O-Matic : (Category) To-do items :
Current CGEN bugs
I have two bugs that need attention when we have a moment:
1. When multiple ISAs are defined, only the base instruction size
   associated with the first encountered/described ISA is used.  This
   causes problems when ISAs of different base instruction size are
   defined in the same cpu file. 
The base instruction size of the ISA associated with the instruction in question should be used. File: cgen/mach.scm Routine: state_base_insn_bitsize + feeder routines

2. When rereading a little endian instruction with a base instruction

   size of 16 bits plus a 16 bit immediate, the byte ordering gets
   hosed.  The problem occurs due to the 32 bits being interpreted as
   one little endian int not two 16 bit, little endian shorts.    
File: opcodes/cgen-dis.in Routine: print_insn()

patrickm@redhat.com
[Append to This Answer]
(Answer) (Category) CGEN Faq-O-Matic : (Category) To-do items :
dummy ER
(placeholder)
fche@redhat.com
[Append to This Answer]
(Answer) (Category) CGEN Faq-O-Matic :
I can't load "dev.scm" into guile
Trying to follow the basic steps to use guile development environment described in CGEN manual I get following error trying to load "dev.scm":
guile> (load "dev.scm") dev.scm:17:18: While evaluating arguments to cons in expression (cons srcdir %lo ad-path): dev.scm:17:18: Unbound variable: srcdir ABORT: (unbound-variable)
Type "(backtrace)" to get more information or "(debug)" to enter the debugger. guile> (backtrace)
Backtrace: 0* [primitive-load "dev.scm"] 1* (set! %load-path (cons srcdir %load-path)) 2* [cons ...
guile>

This error appears on both Solaris and Windows platforms.

This documented method of running cgen is actually a bit of a trap: it doesn't work, just wants to see whether you're reading it!
CGEN is best run using the batch methods encoded into the various makefiles that make up the binutils/sim/sid projects.
I load dev.scm a lot these days, so it's working now (aug/09) (for the things I've tried anyway).
[Append to This Answer]
pbaranov@ubicom.com, fche@redhat.com, dje@sebabeach.org
(Answer) (Category) CGEN Faq-O-Matic :
Does CGEN run on guile 1.6?
At this time (2002 fall), cgen does not run on guile 1.6. Error messages like the following are produced:
  dev.scm:176:30: In procedure getenv in expression (getenv (quote HOME)):
  dev.scm:176:30: Wrong type argument in position 1 (expecting STRINGP): HOME
  ABORT: (wrong-type-arg) guile>
Fixes/suggestions are welcome.
fche@redhat.com
That particular bug is now fixed, but others may remain.
fche@redhat.com
[Append to This Answer]
(Answer) (Category) CGEN Faq-O-Matic :
Using CGEN with cygwin
I tried the release version of CGEN 1.0 with the latest cygwin and got errors. Per your suggestion:
1) I have downloaded guile 1.3.4.tar.gz. I manually patched the aand-let*.scm file to and-lets.scm to get it to build per some instructions I found on the www. It built a monolithic guile.exe which I copied to my /usr/bin directory.
2) Now I can load and run the "m32r" sample interactively using "dev.scm" :-)
3) I tried the "make all-opcodes" but I can't get find the generated the files anywhere (from the documentation I expected them to get [re]built in the binutils/src folder). What am I doing wrong?
4) Also the "make gas-test" and "make sim-test" in the "porting" section of the HTML manual don't work. What am I doing wrong?
Lennie
laraki@indigosystems.com
[Append to This Answer]
(Answer) (Category) CGEN Faq-O-Matic :
dni format description
Hello,
My name is Petronela, i would like to get more info about the format field from pmacros. For example the following insn is used in m32r.cpu:
(dni addx "addx"
     ((PIPE OS) (IDOC ALU))
     "addx $dr,$sr"
     (+ OP1_0 OP2_9 dr sr)
     (parallel ()
               (set dr (addc dr sr condbit))
               (set condbit (add-cflag dr sr condbit)))
     ()
)
What (+ OP1_0 OP2_9 dr sr) means ? OP1_* and OP2_* are defined in the following way:
(define-normal-insn-enum insn-op1 "insn format enums" () OP1_ f-op1
  ("0" "1" "2" "3" "4" "5" "6" "7"
   "8" "9" "10" "11" "12" "13" "14" "15")
)
(define-normal-insn-enum insn-op2 "op2 enums" () OP2_ f-op2
  ("0" "1" "2" "3" "4" "5" "6" "7"
   "8" "9" "10" "11" "12" "13" "14" "15")
)
My understanding is that destination register is always R0 and source register is always R9 for this type of insn. Is this correct ? Does this not restrict the hardware usage ? Since this insn can be executed on all R* registers.
Thank you
petronela.silvia@gmail.com
[Append to This Answer]
This document is: http://sourceware.org/fom/cgen?file=1
[Search] [Appearance] [Show Top Category Only]
This is a Faq-O-Matic 2.719.
This FAQ administered by ...