Rev 3467 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3467 | Rev 3477 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2006 Pavel Rimsky |
2 | * Copyright (c) 2006 Pavel Rimsky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup sparc64 |
29 | /** @addtogroup sparc64 |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** |
32 | /** |
33 | * @file |
33 | * @file |
34 | * @brief Routines for writing characters directly to Simics CLI. |
34 | * @brief Routines for writing characters directly to Simics CLI. |
35 | * |
35 | * |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <console/chardev.h> |
38 | #include <console/chardev.h> |
39 | #include <console/console.h> |
39 | #include <console/console.h> |
40 | #include <synch/spinlock.h> |
40 | #include <synch/spinlock.h> |
41 | #include <arch/drivers/simics_output.h> |
41 | #include <arch/drivers/simics_output.h> |
42 | 42 | ||
43 | /** maximum number of characters stored before printed */ |
43 | /** maximum number of characters stored before printed */ |
44 | #define BUFSIZE 512 |
44 | #define BUFSIZE 512 |
45 | 45 | ||
46 | /* %g2 will store a magic value used during initialization */ |
46 | /* %g2 will store a magic value used during initialization */ |
47 | asm (".register %g2, #scratch"); |
47 | asm (".register %g2, #scratch"); |
48 | 48 | ||
49 | /* %g3 will store the address (to be passed to Simics) of the buffer */ |
49 | /* %g3 will store the address (to be passed to Simics) of the buffer */ |
50 | asm (".register %g3, #scratch"); |
50 | asm (".register %g3, #scratch"); |
51 | 51 | ||
52 | /* lock protecting the character buffer */ |
52 | /* lock protecting the character buffer */ |
53 | SPINLOCK_INITIALIZE(simics_buf_lock); |
53 | SPINLOCK_INITIALIZE(simics_buf_lock); |
54 | 54 | ||
55 | static void simics_putchar(struct chardev * cd, char c); |
55 | static void simics_putchar(struct chardev * cd, char c); |
56 | 56 | ||
57 | /** character device operations - only writing will be supported */ |
57 | /** character device operations - only writing will be supported */ |
58 | static chardev_operations_t simics_stdout_ops = { |
58 | static chardev_operations_t simics_stdout_ops = { |
59 | .suspend = NULL, |
59 | .suspend = NULL, |
60 | .resume = NULL, |
60 | .resume = NULL, |
61 | .write = simics_putchar, |
61 | .write = simics_putchar, |
62 | .read = NULL |
62 | .read = NULL |
63 | }; |
63 | }; |
64 | 64 | ||
65 | /** Simics character device */ |
65 | /** Simics character device */ |
66 | chardev_t simics_stdout; |
66 | chardev_t simics_stdout; |
67 | 67 | ||
68 | /** |
68 | /** |
69 | * buffer to which output characters are stored before they're printed by Simics |
69 | * buffer to which output characters are stored before they're printed by Simics |
70 | */ |
70 | */ |
71 | static volatile char buffer[BUFSIZE]; |
71 | static volatile char buffer[BUFSIZE]; |
72 | 72 | ||
73 | /** Writes a single character to the Simics CLI. |
73 | /** Writes a single character to the Simics CLI. |
74 | * |
74 | * |
75 | * The character is not written immediately, but it is stored to the first free |
75 | * The character is not written immediately, but it is stored to the first free |
76 | * position in the buffer, waiting for Simics' Python routine to hang it up |
76 | * position in the buffer, waiting for Simics' Python routine to read it |
77 | * and print it. |
77 | * and print it. |
78 | */ |
78 | */ |
79 | static void simics_putchar(struct chardev * cd, char c) |
79 | static void simics_putchar(struct chardev * cd, char c) |
80 | { |
80 | { |
81 | /* the first free position in the buffer */ |
81 | /* the first free position in the buffer */ |
82 | static uint16_t current = 0; |
82 | static uint16_t current = 0; |
83 | 83 | ||
84 | /* '\0' terminates a contiguous block of characters to be printed! */ |
84 | /* '\0' terminates a contiguous block of characters to be printed! */ |
85 | if (c == '\0') |
85 | if (c == '\0') |
86 | return; |
86 | return; |
87 | 87 | ||
88 | /* wait till buffer is non-full and other processors aren't writing to it */ |
88 | /* wait till buffer is non-full and other processors aren't writing to it */ |
89 | while (1) { |
89 | while (1) { |
90 | while (buffer[current] != 0) |
90 | while (buffer[current] != 0) |
91 | ; |
91 | ; |
92 | if (spinlock_trylock(&simics_buf_lock)) |
92 | if (spinlock_trylock(&simics_buf_lock)) |
93 | break; |
93 | break; |
94 | } |
94 | } |
95 | 95 | ||
96 | buffer[current] = c; |
96 | buffer[current] = c; |
97 | 97 | ||
98 | current = (current + 1) % BUFSIZE; |
98 | current = (current + 1) % BUFSIZE; |
99 | membar(); |
99 | membar(); |
100 | 100 | ||
101 | spinlock_unlock(&simics_buf_lock); |
101 | spinlock_unlock(&simics_buf_lock); |
102 | } |
102 | } |
103 | 103 | ||
104 | /** Initializes the Simics output. |
104 | /** Initializes the Simics output. |
105 | * |
105 | * |
106 | * Passes the address of the buffer to the Simics' Python script and |
106 | * Passes the address of the buffer to the Simics' Python script and |
107 | * redirects kernel output to the Simics CLI. |
107 | * redirects kernel output to the Simics CLI. |
108 | */ |
108 | */ |
109 | void simics_output_init(void) |
109 | void simics_output_init(void) |
110 | { |
110 | { |
111 | /* all buffer positions are free at the beginning */ |
111 | /* all buffer positions are free at the beginning */ |
112 | uint16_t i; |
112 | uint16_t i; |
113 | for (i = 0; i < BUFSIZE; i++) { |
113 | for (i = 0; i < BUFSIZE; i++) { |
114 | buffer[i] = '\0'; |
114 | buffer[i] = '\0'; |
115 | } |
115 | } |
116 | 116 | ||
117 | /* |
117 | /* |
118 | * pass the address of the buffer to the Simics' Python script |
118 | * pass the address of the buffer to the Simics' Python script |
119 | * - write it to the %g3 register |
119 | * - write it to the %g3 register |
120 | * - write the magic value to the %g2 register |
120 | * - write the magic value to the %g2 register |
121 | * (so that the script knows that the value in %g3 is valid) |
121 | * (so that the script knows that the value in %g3 is valid) |
122 | * - loop until the value is read |
122 | * - loop until the value is read |
123 | * (the script notifies us by setting %g2 to 0) |
123 | * (the script notifies us by setting %g2 to 0) |
124 | */ |
124 | */ |
125 | asm volatile ( |
125 | asm volatile ( |
126 | "or %0, 0, %%g3\n" |
126 | "or %0, 0, %%g3\n" |
127 | 127 | ||
128 | "set 0x18273645, %%g2\n" |
128 | "set 0x18273645, %%g2\n" |
129 | 129 | ||
130 | "0: cmp %%g2, 0\n" |
130 | "0: cmp %%g2, 0\n" |
131 | "bnz 0b\n" |
131 | "bnz 0b\n" |
132 | "nop" |
132 | "nop" |
133 | :: "r" (buffer) |
133 | :: "r" (buffer) |
134 | ); |
134 | ); |
135 | 135 | ||
136 | /* redirect kernel output */ |
136 | /* redirect kernel output */ |
137 | chardev_initialize("simics_output", &simics_stdout, &simics_stdout_ops); |
137 | chardev_initialize("simics_output", &simics_stdout, &simics_stdout_ops); |
138 | stdout = &simics_stdout; |
138 | stdout = &simics_stdout; |
139 | } |
139 | } |
140 | 140 | ||
141 | /** @} |
141 | /** @} |
142 | */ |
142 | */ |
143 | 143 |