]>
Commit | Line | Data |
---|---|---|
ce823bab JJ |
1 | /* cfe.c -- I/O code for the MIPS boards running CFE. */ |
2 | ||
3 | /* | |
4 | * Copyright 2001, 2002 | |
5 | * Broadcom Corporation. All rights reserved. | |
6 | * | |
7 | * This software is furnished under license and may be used and copied only | |
8 | * in accordance with the following terms and conditions. Subject to these | |
9 | * conditions, you may download, copy, install, use, modify and distribute | |
10 | * modified or unmodified copies of this software in source and/or binary | |
11 | * form. No title or ownership is transferred hereby. | |
12 | * | |
13 | * 1) Any source code used, modified or distributed must reproduce and | |
14 | * retain this copyright notice and list of conditions as they appear in | |
15 | * the source file. | |
16 | * | |
17 | * 2) No right is granted to use any trade name, trademark, or logo of | |
18 | * Broadcom Corporation. The "Broadcom Corporation" name may not be | |
19 | * used to endorse or promote products derived from this software | |
20 | * without the prior written permission of Broadcom Corporation. | |
21 | * | |
22 | * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED | |
23 | * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF | |
24 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR | |
25 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE | |
26 | * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE | |
27 | * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | |
30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
31 | */ | |
32 | ||
33 | #include "cfe_api.h" | |
34 | ||
35 | char inbyte (void); | |
36 | int outbyte (char c); | |
37 | ||
38 | /* Make sure cfe_prestart is used. It doesn't look like setting the | |
39 | entry symbol in the linker script to a symbol from that fiel will do | |
40 | this! */ | |
41 | extern int _prestart; | |
42 | static void *force_prestart = &_prestart; | |
43 | ||
44 | /* The following variables are initialized to non-zero so that they'll be | |
45 | in data, rather than BSS. Used to be that you could init variables to | |
46 | any value to put them into initialized data sections rather than BSS, | |
47 | but that decades-old idiom went out the window with gcc 3.2. Now, | |
48 | either you compile specially (with -fno-zero-initialized-in-bss), or | |
49 | you init to non-zero. In this case, initting to non-zero is OK (and | |
50 | even beneficial; alignment fault via jump to odd if not properly | |
f8054a38 JJ |
51 | set up by _prestart()), so we do the latter. |
52 | ||
53 | These variables are 'int's so they can be reliably stored w/ "sw". | |
54 | (longs fall victim to -mlong64.) They are signed so that they remain | |
55 | valid pointers when extended to cfe_xuint_t in the call to cfe_init(). | |
56 | This assumes that they are compatibility-space pointers. */ | |
57 | int __cfe_handle = 0xdeadbeef; | |
58 | int __cfe_entrypt = 0xdeadbeef; | |
ce823bab JJ |
59 | |
60 | /* Echo input characters? */ | |
61 | int __cfe_echo_input = 0; | |
62 | ||
63 | /* CFE handle used to access console device. */ | |
64 | static int cfe_conshandle; | |
65 | ||
66 | char | |
67 | inbyte (void) | |
68 | { | |
69 | unsigned char c; | |
70 | int rv; | |
71 | ||
72 | while (cfe_read (cfe_conshandle, &c, 1) != 1) | |
73 | ; | |
74 | if (c == '\r') | |
75 | c = '\n'; | |
76 | if (__cfe_echo_input) | |
77 | outbyte (c); | |
78 | return c; | |
79 | } | |
80 | ||
81 | int | |
82 | outbyte (char c) | |
83 | { | |
84 | int res; | |
85 | ||
86 | do | |
87 | { | |
88 | res = cfe_write (cfe_conshandle, &c, 1); | |
89 | } | |
90 | while (res == 0); | |
91 | if (c == '\n') | |
92 | outbyte ('\r'); | |
93 | return 0; | |
94 | } | |
95 | ||
96 | /* Initialize hardware. Called from crt0. */ | |
97 | void | |
98 | hardware_init_hook(void) | |
99 | { | |
100 | cfe_init (__cfe_handle, __cfe_entrypt); | |
101 | cfe_conshandle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE); | |
102 | } | |
103 | ||
ce823bab JJ |
104 | /* Exit back to monitor, with the given status code. */ |
105 | void | |
106 | hardware_exit_hook (int status) | |
107 | { | |
108 | outbyte ('\r'); | |
109 | outbyte ('\n'); | |
110 | cfe_exit (CFE_FLG_WARMSTART, status); | |
111 | } | |
112 | ||
113 | /* Structure filled in by get_mem_info. Only the size field is | |
114 | actually used (by sbrk), so the others aren't even filled in. */ | |
115 | struct s_mem | |
116 | { | |
117 | unsigned int size; | |
118 | unsigned int icsize; | |
119 | unsigned int dcsize; | |
120 | }; | |
121 | ||
122 | void | |
123 | get_mem_info (mem) | |
124 | struct s_mem *mem; | |
125 | { | |
126 | /* XXX FIXME: Fake this for now. Should invoke cfe_enummem, but we | |
127 | don't have enough stack to do that (yet). */ | |
128 | mem->size = 0x4000000; /* Assume 64 MB of RAM */ | |
129 | } |