$NetBSD: patch-ah,v 1.3 2003/07/11 07:47:44 jtb Exp $

--- asmcomp/power/emit.mlp.orig
+++ asmcomp/power/emit.mlp
@@ -65,7 +65,7 @@
 
 let emit_symbol =
   match Config.system with
-    "aix" | "elf" -> (fun s -> Emitaux.emit_symbol '.' s)
+    "aix" | "elf" | "bsd" -> (fun s -> Emitaux.emit_symbol '.' s)
   | "rhapsody"    -> (fun s -> emit_char '_'; Emitaux.emit_symbol '$' s)
   | _ -> assert false
 
@@ -78,7 +78,7 @@
 let label_prefix =
   match Config.system with
     "aix" -> "L.."
-  | "elf" -> ".L"
+  | "elf" | "bsd" -> ".L"
   | "rhapsody" -> "L"
   | _ -> assert false
 
@@ -90,21 +90,21 @@
 let data_space =
   match Config.system with
     "aix" -> "	.csect  .data[RW]\n"
-  | "elf" -> "	.section \".data\"\n"
+  | "elf" | "bsd" -> "	.section \".data\"\n"
   | "rhapsody" -> "	.data\n"
   | _ -> assert false
 
 let code_space =
   match Config.system with
     "aix" -> "	.csect  .text[PR]\n"
-  | "elf" -> "	.section \".text\"\n"
+  | "elf" | "bsd" -> "	.section \".text\"\n"
   | "rhapsody" -> "	.text\n"
   | _ -> assert false
 
 let rodata_space =
   match Config.system with
     "aix" -> "	.csect  .data[RW]\n" (* ?? *)
-  | "elf" -> "	.section \".rodata\"\n"
+  | "elf" | "bsd" -> "	.section \".rodata\"\n"
   | "rhapsody" -> "	.const\n"
   | _ -> assert false
 
@@ -157,7 +157,7 @@
 
 let emit_upper emit_fun arg =
   match Config.system with
-    "elf" ->
+    "elf" | "bsd" ->
       emit_fun arg; emit_string "@ha"
   | "rhapsody" ->
       emit_string "ha16("; emit_fun arg; emit_string ")"
@@ -165,7 +165,7 @@
 
 let emit_lower emit_fun arg =
   match Config.system with
-    "elf" ->
+    "elf" | "bsd" ->
       emit_fun arg; emit_string "@l"
   | "rhapsody" ->
       emit_string "lo16("; emit_fun arg; emit_string ")"
@@ -935,6 +935,30 @@
       emit_instr i None;
       emit_all i.next
 
+(* Emission of the profiling prelude *)
+
+let emit_profile () =
+  match Config.system with
+    "bsd" ->
+      `	stwu 1, -32(1)\n`;
+      `	mflr 0\n`;
+      `	stw 0, 4(1)\n`;
+      `	stw 2, 8(1)\n`;
+      `	stw 3, 12(1)\n`;
+      `	stw 4, 16(1)\n`;
+      `	stw 5, 20(1)\n`;
+      `	stw 6, 24(1)\n`;
+      `	stw 7, 28(1)\n`;
+      `	bl {emit_symbol "_mcount"}\n`;
+      `	lwz 2, 8(1)\n`;
+      `	lwz 3, 12(1)\n`;
+      `	lwz 4, 16(1)\n`;
+      `	lwz 5, 20(1)\n`;
+      `	lwz 6, 24(1)\n`;
+      `	lwz 7, 28(1)\n`;
+      `	addic 1, 1, 32\n`;
+  | _ -> () (*unsupported yet*)
+
 (* Emission of a function declaration *)
 
 let fundecl fundecl =
@@ -951,10 +975,11 @@
       `	.csect	{emit_symbol fundecl.fun_name}[DS]\n`;
       `{emit_symbol fundecl.fun_name}:\n`;
       `	.long	.{emit_symbol fundecl.fun_name}, TOC[tc0], 0\n`
-  | "elf" ->
+  | "elf" | "bsd" ->
       `	.type	{emit_symbol fundecl.fun_name}, @function\n`
   | _ -> ()
   end;
+  if !Clflags.gprofile then emit_profile();
   emit_string code_space;
   `	.align	2\n`;
   `{emit_codesymbol fundecl.fun_name}:\n`;
@@ -996,7 +1021,7 @@
 
 let declare_global_data s =
   `	.globl	{emit_symbol s}\n`;
-  if Config.system = "elf" then
+  if Config.system = "elf" || Config.system = "bsd" then
     `	.type	{emit_symbol s}, @object\n`
 
 let emit_item = function
