This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


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

Re: FWIW: VAX fix backport and gcc built on 4.3BSD first time ever!


>> Marc Espie <espie@quatramaran.ens.fr> wrote:
>> 
>> > The gcc used in OpenBSD does have additions to vax.md for precisely that
>> > problem. Namely, it defines call_pop and call_value_pop (I think... I'm
>> > not too familiar with that).
>> >
>> > This might not be the cleanest solution, but I can vouch that 
>> > vax-unknown-openbsd28 is a reality.
>> 
>> Hmm, vax.md is definitely the wrong place to fix this. vax.md is correct.

Unfortunately, recent changes to the mainline CVS source have broken
the vax machine definition again.  The call_pop and call_value_pop insns
have holes in their operand list that need fixing.  Also, there are
two unamed patterns intended to handle the zero argument case that
appear unnecessary.  These are essentially call and call_value.  After
reviewing this, I believe the current machine definition can be simplified.

>> VAX was among the ports of the very first original gcc, and gcc has
>> accommodated this from the beginning. A port doesn't have to have call and
>> call_value patterns, and can have call_pop and call_value_pop instead. It's
>> just that somewhere along the way calls.c got broken, and John David Anglin's
>> patch is the correct fix for it. In fact, this is not even VAX-specific.
>> calls.c simply had a bug in it that made it violate one of gcc's internal rules
>> as to what patterns a port must define. It broke every port that chose to
>> define call_pop and call_value_pop, but not call and call_value.

Correct.

>> As for OpenBSD, if as you say you hack vax.md to work around this bug in
>> calls.c, I guess what you are doing is defining call and call_value patterns
>> that emulate the behavior of lesser architectures on the VAX. I guess you emit
>> a calls $0, right? If so, please be advised that this violates the VAX
>> Architecture Reference Manual. While in ANSI/ISO C a function can't determine
>> how many arguments it was called with, on a VAX it can. 4.3BSD, for example,
>> being a true VAX OS, makes use of this feature in a few places, as any VARM-
>> compliant software can legitimately do. Calling functions with calls $0 tells
>> them that they have no arguments, and thus breaks VARM-compliant software.

No.  Defining call and call_value is OK because RETURN_POPS_ARGS is
defined.  The call and call_value forms will only be used when there
are no arguments to pop.  Thus, defining them shouldn't break the ARM.
The `calls $0' form is also used when the number of arguments exceeds 255.

>> No, Dave's patch is the right fix, and has been in the mainline gcc since
>> August 1999. According to Dave, the current mainline gcc bootstraps and works
>> correctly on VAX Ultrix. I'm now working on getting it to build on 4.3BSD.

Although I originally submitted the patch for the 2.95 branch, I am not
pushing to have it installed in that branch.  I don't think that it is
the only patch needed to get the 2.95 branch working on the vax.  I would
rather spend my time getting 3.0 (aka 2.97) working right.  I currently
use a snapshot of 2.97 for most of my builds on the vax.

I have enclosed a patch to vax.md that I am currently testing to fix
the new requirement for contiguous operands.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)

2000-12-20  John David Anglin  <dave@hiauly1.hia.nrc.ca>

        * vax.md (call_pop, call_value_pop): Change to define_expand.
	(call_pop_internal, call, call_value): Define.
	(casesi1 + 1): Make operands contiguous.

--- vax.md.orig	Tue Sep 12 10:58:47 2000
+++ vax.md	Tue Dec 19 14:20:35 2000
@@ -1818,46 +1818,47 @@
   ""
   "decl %0\;jgequ %l1")
 
-;; Note that operand 1 is total size of args, in bytes,
-;; and what the call insn wants is the number of words.
-;; It is used in the call instruction as a byte, but in the addl2 as
-;; a word.  Since the only time we actually use it in the call instruction
-;; is when it is a constant, SImode (for addl2) is the proper mode.
-(define_insn "call_pop"
+;; Call instructions.
+
+;; Call subroutine returning no value.
+;; Operand 2 is not used on the vax.
+
+(define_expand "call_pop"
   [(call (match_operand:QI 0 "memory_operand" "m")
 	 (match_operand:SI 1 "const_int_operand" "n"))
    (set (reg:SI 14) (plus:SI (reg:SI 14)
 			     (match_operand:SI 3 "immediate_operand" "i")))]
   ""
-  "*
-  if (INTVAL (operands[1]) > 255 * 4)
-    /* Vax `calls' really uses only one byte of #args, so pop explicitly.  */
-    return \"calls $0,%0\;addl2 %1,sp\";
-  operands[1] = GEN_INT ((INTVAL (operands[1]) + 3)/ 4);
-  return \"calls %1,%0\";
-")
+  "
+{
+  emit_insn (gen_call_pop_internal (operands[0], operands[1]));
+  DONE;
+}")
+
+;; Call subroutine returning a value in operand 0.
+;; Operand 3 is not used on the vax.
 
-(define_insn "call_value_pop"
+(define_expand "call_value_pop"
   [(set (match_operand 0 "" "=g")
 	(call (match_operand:QI 1 "memory_operand" "m")
 	      (match_operand:SI 2 "const_int_operand" "n")))
    (set (reg:SI 14) (plus:SI (reg:SI 14)
 			     (match_operand:SI 4 "immediate_operand" "i")))]
   ""
-  "*
-  if (INTVAL (operands[2]) > 255 * 4)
-    /* Vax `calls' really uses only one byte of #args, so pop explicitly.  */
-    return \"calls $0,%1\;addl2 %2,sp\";
-  operands[2] = GEN_INT ((INTVAL (operands[2]) + 3)/ 4);
-  return \"calls %2,%1\";
-")
+  "
+{
+  emit_insn (gen_call_pop_internal (operands[1], operands[2]));
+  DONE;
+}")
 
-;; Define another set of these for the case of functions with no
-;; operands.  In that case, combine may simplify the adjustment of sp.
-(define_insn ""
-  [(call (match_operand:QI 0 "memory_operand" "m")
-	 (match_operand:SI 1 "const_int_operand" "n"))
-   (set (reg:SI 14) (reg:SI 14))]
+;; Note that operand 1 is total size of args, in bytes,
+;; and what the call insn wants is the number of words.
+;; It is used in the call instruction as a byte, but in the addl2 as
+;; a word.  Since the only time we actually use it in the call instruction
+;; is when it is a constant, SImode (for addl2) is the proper mode.
+(define_insn "call_pop_internal"
+  [(call (match_operand:QI 0 "" "")
+	 (match_operand:SI 1 "" ""))]
   ""
   "*
   if (INTVAL (operands[1]) > 255 * 4)
@@ -1867,19 +1868,20 @@
   return \"calls %1,%0\";
 ")
 
-(define_insn ""
+(define_insn "call"
+  [(call (match_operand:QI 0 "memory_operand" "m")
+	 (match_operand:SI 1 "const_int_operand" "n"))]
+  ;; Operand 1 not used on the vax.
+  ""
+  "calls $0,%0")
+
+(define_insn "call_value"
   [(set (match_operand 0 "" "=g")
 	(call (match_operand:QI 1 "memory_operand" "m")
-	      (match_operand:SI 2 "const_int_operand" "n")))
-   (set (reg:SI 14) (reg:SI 14))]
+	      (match_operand:SI 2 "const_int_operand" "n")))]
+  ;; Operand 2 not used on the vax.
   ""
-  "*
-  if (INTVAL (operands[2]) > 255 * 4)
-    /* Vax `calls' really uses only one byte of #args, so pop explicitly.  */
-    return \"calls $0,%1\;addl2 %2,sp\";
-  operands[2] = GEN_INT ((INTVAL (operands[2]) + 3)/ 4);
-  return \"calls %2,%1\";
-")
+  "calls $0,%0")
 
 ;; Call subroutine returning any type.
 
@@ -1986,7 +1988,7 @@
 					  (mult:SI (minus:SI (match_dup 0)
 							     (const_int 0))
 						   (const_int 2)))))
-			       (label_ref:SI (match_operand 3 "" "")))
+			       (label_ref:SI (match_operand 2 "" "")))
 		      (pc)))]
   ""
   "casel %0,$0,%1")

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