This is the mail archive of the cgen@sources.redhat.com mailing list for the CGEN project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Generating CPU family headers for multiple isas


Time to get serious with questions backed with real information now.
Attached are the changes I have made to the sim*.scm files to support
multiple isas.  I expect that the changes should cause cgen to emit:

	* one hardware struct for hardware elements that apply to more than
	  one isa (ie. are generally applicable).

	* one hardware struct for hardware elements that only apply to each
	  of the _selected_ isas -- named <isa>_hardware.

I am invoking the sim application via the sim/common/cgen.sh script like so:

$ make stamp-cpu
make cgen-cpu CGEN=`if [ -f ../../guile/libguile/guile ]; then echo
../../guile/libguile/guile; else echo guile ; fi` CGENFLAGS="-v" \
  cpu=foocpu mach=foomach isa=bar,baz FLAGS="with-multiple-isa with-scache with-profile=fn"
make[1]: Entering directory `/u5/build/sim/foo'
/bin/sh /home/bje/devo/sim/foo/../common/cgen.sh cpu /home/bje/devo/sim/foo \
guile /home/bje/devo/sim/foo/../../cgen "-v" \
        fooarch "with-multiple-isa with-scache with-profile=fn" foocpu
"bar,baz" foomach "" ""
Skipping slib/sort, already loaded.
cgen -s /home/bje/devo/sim/foo/../../cgen/cgen-sim.scm -s /home/bje/devo/sim/foo/../../cgen -v -f "with-multiple-isa with-scache with-profile=fn" -m foomach -a fooarch -i bar,baz -C tmp-cpu.h1 -U tmp-cpu.c1 -M tmp-mod.c1
Setting option `with-multiple-isa' to "".
Setting option `with-scache' to "".
Setting option `with-profile' to "fn".
Loading cpu file /home/bje/devo/sim/foo/../../cgen/foo.cpu ...
Including file simplify.inc ...
Processing cpu file /home/bje/devo/sim/foo/../../cgen/foo.cpu ...
Generating foocpu cpu.h ...
Analyzing instruction set ...
Done analysis.
Computing sformat argument buffers ...
ERROR: multiple isas selected (bar baz)
No backtrace available.

What's the right way to proceed here?  I think wanting the hardware elements
for all selected isas in the nominated cpu family listed in cpu.h is a
reasonable thing.

The patch also shows some (gen-cpu-ref) function applications where I am
passing an empty list.  Given the scope of these invocations, I'm not sure
how to pass the (hw-isas).  Help!

Thanks, Ben


Index: sim-cpu.scm
===================================================================
RCS file: /cvs/cvsfiles/devo/cgen/sim-cpu.scm,v
retrieving revision 1.58
diff -u -r1.58 sim-cpu.scm
--- sim-cpu.scm	2000/11/20 19:03:16	1.58
+++ sim-cpu.scm	2000/11/22 06:13:14
@@ -40,6 +40,34 @@
   (and (register? hw) (not (obj-has-attr? hw 'VIRTUAL)))
 )

+; Subroutine of -gen-hardware-types to generate the struct containing
+; hardware elements of one isa.
+
+(define (-gen-hardware-struct prefix hw-list)
+  (if (null? hw-list)
+      ; If struct is empty, leave it out to simplify generated code.
+      ""
+      (string-list
+       (if prefix
+	   (string-append "  /* Hardware elements for " prefix " isa.  */\n")
+	   "  /* Hardware elements.  */\n")
+       "  struct {\n"
+       (string-list-map (lambda (hw)
+			  (string-list
+			   (gen-decl hw)
+			   (gen-obj-sanitize hw
+					     (string-list
+					      (send hw 'gen-get-macro)
+					      (send hw 'gen-set-macro)))))
+			(find hw-need-storage? hw-list))
+       "  } "
+       (if prefix
+	   (string-append prefix "_")
+	   "")
+       "hardware;\n"
+       ))
+)
+
 ; Return C type declarations of all of the hardware elements.
 ; The name of the type is prepended with the cpu family name.

@@ -47,19 +75,37 @@
   (string-list
    "/* CPU state information.  */\n"
    "typedef struct {\n"
-   "  /* Hardware elements.  */\n"
-   "  struct {\n"
-   (string-list-map (lambda (hw)
-		      (string-list
-		       (gen-decl hw)
-		       (gen-obj-sanitize hw
-					 (string-list
-					  (send hw 'gen-get-macro)
-					  (send hw 'gen-set-macro)))
-		       ))
-		    (find hw-need-storage? (current-hw-list)))
-   "  } hardware;\n"
+   (if (with-multiple-isa?)
+       (let ((keep-isas (current-keep-isa-name-list))
+	     (candidates (find hw-need-storage? (current-hw-list))))
+	 (string-list
+	  (-gen-hardware-struct #f
+				(find (lambda (hw)
+					(> (count-common
+					    keep-isas
+					    (bitset-attr->list
+					     (obj-attr-value hw 'ISA)))
+					   1))
+				      candidates))
+
+	  ; Now emit structs for each isa.  These contain entries for
+	  ; elements supported by exactly one isa.
+	  (string-list-map (lambda (isa)
+			     (-gen-hardware-struct
+			      isa
+			      (find (lambda (hw)
+				      (= (count-common
+					  keep-isas
+					  (bitset-attr->list
+					   (obj-attr-value hw 'ISA)))
+					 1))
+				    candidates))) keep-isas)
+	  ))
+       (-gen-hardware-struct #f (find hw-need-storage? (current-hw-list)))
+       )
+
    "#define CPU_CGEN_HW(cpu) (& (cpu)->cpu_data.hardware)\n"
+   "#define CPU_CGEN_HW_ISA(cpu, isa) &( (cpu)->cpu_data.isa ## _hardware)\n"
    ;"  /* CPU profiling state information.  */\n"
    ;"  struct {\n"
    ;(string-list-map (lambda (hw) (send hw 'gen-profile-decl))
Index: sim.scm
===================================================================
RCS file: /cvs/cvsfiles/devo/cgen/sim.scm,v
retrieving revision 1.89
diff -u -r1.89 sim.scm
--- sim.scm	2000/10/13 12:06:55	1.89
+++ sim.scm	2000/11/22 06:13:15
@@ -42,6 +42,8 @@
 ;	and doing a post-semantics writeback pass.
 ; with-parallel-only
 ;	Only generate parallel versions of each insn.
+; with-multiple-isa
+;	Enable multiple-isa support (eg. arm+thumb).
 ; copyright fsf|cygnus
 ;	emit an FSF or Cygnus copyright (temporary, pending decision)
 ; package gnusim|cygsim
@@ -61,6 +63,10 @@
 (define (with-profile?) -with-profile?)
 (define (with-any-profile?) (or -with-profile-fn? -with-profile-sw?))

+; #t if multiple isa support is enabled
+(define -with-multiple-isa? #f)
+(define (with-multiple-isa?) -with-multiple-isa?)
+
 ; Handle parallel execution with generic writeback pass.
 (define -with-generic-write? #f)
 (define (with-generic-write?) -with-generic-write?)
@@ -81,6 +87,7 @@
   (set! -with-scache? #f)
   (set! -with-profile-fn? #f)
   (set! -with-profile-sw? #f)
+  (set! -with-multiple-isa? #f)
   (set! -with-generic-write? #f)
   (set! -with-parallel-only? #f)
   (set! CURRENT-COPYRIGHT copyright-fsf)
@@ -98,6 +105,7 @@
 			  ((equal? value '("sw"))
 			   (set! -with-profile-sw? #t))
 			  (else (error "invalid with-profile value" value))))
+    ((with-multiple-isa) (set! -with-multiple-isa? #t))
     ((with-generic-write) (set! -with-generic-write? #t))
     ((with-parallel-only) (set! -with-parallel-only? #t))
     ((copyright) (cond ((equal?  value '("fsf"))
@@ -148,8 +156,11 @@

 (define c-cpu-macro "CPU")

-(define (gen-cpu-ref sym)
-  (string-append c-cpu-macro " (" sym ")")
+(define (gen-cpu-ref isas sym)
+  (if (and (with-multiple-isa?)
+	   (= (length isas) 1))
+      (string-append "CPU_CGEN_HW_ISA (current_cpu, @isa@)->" sym)
+      (string-append c-cpu-macro " (" sym ")"))
 )


@@ -211,14 +222,14 @@
  <scalar> 'gen-sym-get-macro
  (lambda (self sym comment)
    (let ((sym (gen-c-symbol sym)))
-     (gen-get-macro sym "" (gen-cpu-ref sym))))
+     (gen-get-macro sym "" (gen-cpu-ref () sym))))
 )

 (method-make!
  <scalar> 'gen-sym-set-macro
  (lambda (self sym comment)
    (let ((sym (gen-c-symbol sym)))
-     (gen-set-macro sym "" (gen-cpu-ref sym))))
+     (gen-set-macro sym "" (gen-cpu-ref () sym))))
 )

 (method-make! <scalar> 'gen-ref (lambda (self sym index estate) sym))
@@ -250,7 +261,7 @@
      (string-append
       "#define GET_" (string-upcase sym)
       "(" (string-drop 2 (gen-macro-args rank)) ") "
-      (gen-cpu-ref sym) (gen-array-ref (macro-args rank)) "\n"
+      (gen-cpu-ref () sym) (gen-array-ref (macro-args rank)) "\n"
       )))
 )

@@ -262,7 +273,7 @@
      (string-append
       "#define SET_" (string-upcase sym)
       "(" (string-drop 2 (gen-macro-args rank)) ", x) "
-      "(" (gen-cpu-ref sym) (gen-array-ref (macro-args rank))
+      "(" (gen-cpu-ref () sym) (gen-array-ref (macro-args rank))
       " = (x))\n"
       )))
 )
@@ -573,7 +584,7 @@
 		     (if (with-scache?)
 			 (gen-hw-index-argbuf-ref index)
 			 (gen-hw-index-argbuf-name index))))
-		   (else (gen-cpu-ref (send hw 'gen-ref
+		   (else (gen-cpu-ref (hw-isas hw) (send hw 'gen-ref
 					    (gen-sym hw) index estate))))))
 )

@@ -588,7 +599,7 @@
   (let ((mode (if (mode:eq? 'DFLT mode)
 		  (send self 'get-mode)
 		  mode)))
-    (cx:make mode (gen-cpu-ref (send self 'gen-ref
+    (cx:make mode (gen-cpu-ref (hw-isas self) (send self 'gen-ref
 				     (gen-sym self) index estate)))))
 )

@@ -612,7 +623,7 @@
 			      (gen-hw-index-argbuf-ref index)
 			      (gen-hw-index-argbuf-name index))
 			  " = " (cx:c newval) ";\n"))
-	  (else (string-append (gen-cpu-ref (send hw 'gen-ref
+	  (else (string-append (gen-cpu-ref (hw-isas hw) (send hw 'gen-ref
 						  (gen-sym hw) index estate))
 			       " = " (cx:c newval) ";\n"))))
 )
@@ -625,7 +636,7 @@
 (method-make!
  <hw-register> 'gen-set-quiet-raw
  (lambda (self estate mode index selector newval)
-   (string-append (gen-cpu-ref (send self 'gen-ref
+   (string-append (gen-cpu-ref (hw-isas self) (send self 'gen-ref
 				     (gen-sym self) index estate))
 		  " = " (cx:c newval) ";\n"))
 )
@@ -633,11 +644,21 @@
 ; Return name of C access function for getting/setting a register.

 (define (gen-reg-getter-fn hw prefix)
-  (string-append prefix "_" (gen-sym hw) "_get")
-)
+  (string-append (if (and (with-multiple-isa?)
+			  (= (length (hw-isas hw)) 1))
+		     (string-append (gen-sym (car (hw-isas hw))) "_")
+		     "")
+		 (gen-sym hw)
+		 "_get")
+  )

 (define (gen-reg-setter-fn hw prefix)
-  (string-append prefix "_" (gen-sym hw) "_set")
+  (string-append (if (and (with-multiple-isa?)
+			  (= (length (hw-isas hw)) 1))
+		     (string-append (gen-sym (car (hw-isas hw))) "_")
+		     "")
+		 (gen-sym hw)
+		 "_set")
 )

 ; Generate decls for access fns of register HW, beginning with
@@ -909,7 +930,7 @@
 	       (gen-hw-index-argbuf-name index)))
 	  (else
 	   (string-append "& "
-			  (gen-cpu-ref (send hw 'gen-ref
+			  (gen-cpu-ref (hw-isas hw) (send hw 'gen-ref
 					     (gen-sym hw) index estate))))))
 )





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]