]>
Commit | Line | Data |
---|---|---|
0c530ab8 | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2005-2006 Apple Computer, Inc. All rights reserved. |
0c530ab8 | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0c530ab8 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0c530ab8 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
0c530ab8 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0c530ab8 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
0c530ab8 A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * @APPLE_FREE_COPYRIGHT@ | |
33 | */ | |
34 | ||
0c530ab8 A |
35 | #include <kern/spl.h> |
36 | #include <mach/std_types.h> | |
37 | #include <types.h> | |
38 | #include <kern/thread.h> | |
39 | #include <console/serial_protos.h> | |
40 | ||
0c530ab8 A |
41 | extern void cons_cinput(char ch); /* The BSD routine that gets characters */ |
42 | ||
43 | unsigned int serialmode; /* Serial mode keyboard and console control */ | |
44 | ||
45 | /* | |
46 | * This routine will start a thread that polls the serial port, listening for | |
47 | * characters that have been typed. | |
48 | */ | |
49 | ||
50 | void | |
51 | serial_keyboard_init(void) | |
52 | { | |
53 | kern_return_t result; | |
54 | thread_t thread; | |
55 | ||
2d21ac55 A |
56 | if(!(serialmode & 2)) /* Leave if we do not want a serial console */ |
57 | return; | |
0c530ab8 A |
58 | |
59 | kprintf("Serial keyboard started\n"); | |
60 | result = kernel_thread_start_priority((thread_continue_t)serial_keyboard_start, NULL, MAXPRI_KERNEL, &thread); | |
61 | if (result != KERN_SUCCESS) | |
62 | panic("serial_keyboard_init"); | |
63 | ||
64 | thread_deallocate(thread); | |
65 | } | |
66 | ||
67 | void | |
68 | serial_keyboard_start(void) | |
69 | { | |
2d21ac55 A |
70 | /* Go see if there are any characters pending now */ |
71 | serial_keyboard_poll(); | |
0c530ab8 | 72 | panic("serial_keyboard_start: we can't get back here\n"); |
0c530ab8 A |
73 | } |
74 | ||
75 | void | |
76 | serial_keyboard_poll(void) | |
77 | { | |
78 | int chr; | |
79 | uint64_t next; | |
80 | ||
2d21ac55 | 81 | while(1) { |
0c530ab8 | 82 | chr = _serial_getc(0, 1, 0, 1); /* Get a character if there is one */ |
2d21ac55 A |
83 | if(chr < 0) /* The serial buffer is empty */ |
84 | break; | |
0c530ab8 A |
85 | cons_cinput((char)chr); /* Buffer up the character */ |
86 | } | |
87 | ||
88 | clock_interval_to_deadline(16, 1000000, &next); /* Get time of pop */ | |
89 | ||
90 | assert_wait_deadline((event_t)serial_keyboard_poll, THREAD_UNINT, next); /* Show we are "waiting" */ | |
91 | thread_block((thread_continue_t)serial_keyboard_poll); /* Wait for it */ | |
92 | panic("serial_keyboard_poll: Shouldn't never ever get here...\n"); | |
93 | } | |
94 | ||
2d21ac55 A |
95 | boolean_t |
96 | console_is_serial(void) | |
0c530ab8 | 97 | { |
2d21ac55 | 98 | return (cons_ops_index == SERIAL_CONS_OPS); |
0c530ab8 A |
99 | } |
100 | ||
101 | int | |
2d21ac55 | 102 | switch_to_video_console(void) |
0c530ab8 A |
103 | { |
104 | int old_cons_ops = cons_ops_index; | |
105 | cons_ops_index = VC_CONS_OPS; | |
106 | return old_cons_ops; | |
107 | } | |
108 | ||
109 | int | |
2d21ac55 | 110 | switch_to_serial_console(void) |
0c530ab8 A |
111 | { |
112 | int old_cons_ops = cons_ops_index; | |
113 | cons_ops_index = SERIAL_CONS_OPS; | |
114 | return old_cons_ops; | |
115 | } | |
116 | ||
117 | /* The switch_to_{video,serial,kgdb}_console functions return a cookie that | |
118 | can be used to restore the console to whatever it was before, in the | |
119 | same way that splwhatever() and splx() work. */ | |
120 | void | |
121 | switch_to_old_console(int old_console) | |
122 | { | |
123 | static boolean_t squawked; | |
124 | uint32_t ops = old_console; | |
125 | ||
126 | if ((ops >= nconsops) && !squawked) { | |
127 | squawked = TRUE; | |
128 | printf("switch_to_old_console: unknown ops %d\n", ops); | |
129 | } else | |
130 | cons_ops_index = ops; | |
131 | } |