]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/console/ppc/serial_console.c
xnu-792.21.3.tar.gz
[apple/xnu.git] / osfmk / console / ppc / serial_console.c
index bb5e7f87a3a9c9a444d946ac5ade4565fe7cf4cd..3488e109318364e4dbcc724161049a62bc9d99fa 100644 (file)
@@ -1,23 +1,29 @@
 /*
  * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  * @OSF_COPYRIGHT@
@@ -34,7 +40,6 @@
 #include <machine/machparam.h>         /* spl definitions */
 #include <types.h>
 #include <console/video_console.h>
-#include <console/serial_protos.h>
 #include <kern/kalloc.h>
 #include <kern/thread.h>
 #include <ppc/misc_protos.h>
  */
 
 const int console_unit = 0;
-const uint32_t console_chan_default = CONSOLE_PORT;
+const int console_chan_default = CONSOLE_PORT;
 #define console_chan (console_chan_default) /* ^ cpu_number()) */
 
+#define OPS(putc, getc, nosplputc, nosplgetc) putc, getc
+
+const struct console_ops {
+       int     (*putc)(int, int, int);
+       int     (*getc)(int, int, boolean_t, boolean_t);
+} cons_ops[] = {
+#define SCC_CONS_OPS 0
+       {OPS(scc_putc, scc_getc, no_spl_scputc, no_spl_scgetc)},
+#define VC_CONS_OPS 1
+       {OPS(vcputc, vcgetc, no_spl_vcputc, no_spl_vcgetc)},
+};
+#define NCONSOPS (sizeof cons_ops / sizeof cons_ops[0])
+
+#if SERIAL_CONSOLE_DEFAULT
+#define CONS_OPS SCC_CONS_OPS
+#define CONS_NAME "com"
+#else
+#define CONS_OPS VC_CONS_OPS
+#define CONS_NAME "vc"
+#endif
 
 #define MP_SAFE_CONSOLE 1      /* Set this to 1 to allow more than 1 processor to print at once */
 #if MP_SAFE_CONSOLE
@@ -78,17 +103,8 @@ volatile unsigned int sconowner=-1;                                                         /* Mark who's actually writing */
 
 #endif
 
-#define OPS(putc, getc, nosplputc, nosplgetc) putc, getc
-
-console_ops_t cons_ops[] = {
-       {OPS(scc_putc, scc_getc, no_spl_scputc, no_spl_scgetc)},
-       {OPS(vcputc, vcgetc, no_spl_vcputc, no_spl_vcgetc)},
-};
-
-uint32_t nconsops = (sizeof cons_ops / sizeof cons_ops[0]);
-
-uint32_t cons_ops_index = VC_CONS_OPS;
 
+unsigned int cons_ops_index = CONS_OPS;
 unsigned int killprint = 0;
 unsigned int debcnputc = 0;
 extern unsigned int    mappingdeb0;
@@ -303,6 +319,43 @@ cnmaygetc()
                                             FALSE, FALSE);
 }
 
+boolean_t console_is_serial()
+{
+       return cons_ops_index == SCC_CONS_OPS;
+}
+
+int
+switch_to_video_console()
+{
+       int old_cons_ops = cons_ops_index;
+       cons_ops_index = VC_CONS_OPS;
+       return old_cons_ops;
+}
+
+int
+switch_to_serial_console()
+{
+       int old_cons_ops = cons_ops_index;
+       cons_ops_index = SCC_CONS_OPS;
+       return old_cons_ops;
+}
+
+/* The switch_to_{video,serial,kgdb}_console functions return a cookie that
+   can be used to restore the console to whatever it was before, in the
+   same way that splwhatever() and splx() work.  */
+void
+switch_to_old_console(int old_console)
+{
+       static boolean_t squawked;
+       unsigned int ops = old_console;
+
+       if (ops >= NCONSOPS && !squawked) {
+               squawked = TRUE;
+               printf("switch_to_old_console: unknown ops %d\n", ops);
+       } else
+               cons_ops_index = ops;
+}
+
 
 int
 vcgetc(__unused int l,