1 /*  This file is part of the program psim.
2 
3     Copyright 1994, 1995, 1996, 2003 Andrew Cagney
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, see <http://www.gnu.org/licenses/>.
17 
18     */
19 
20 
21 #ifndef _HW_REGISTER_C_
22 #define _HW_REGISTER_C_
23 
24 #include "device_table.h"
25 #include <stdlib.h>
26 #include "psim.h"
27 
28 /* DEVICE
29 
30 
31    register - dummy device to initialize processor registers
32 
33 
34    DESCRIPTION
35 
36    The properties of this device are used, during initialization, to
37    specify the initial value of various processor registers.  The
38    property name specifying the register to be initialized with the
39    special form <cpu-nr>.<register> being used to initialize a
40    specific processor's register (eg 0.pc).
41 
42    Because, when the device tree is created, overriding properties are
43    entered into the tree before any default values, this device must
44    initialize registers in newest (default) to oldest (overriding)
45    property order.
46 
47    The actual registers (for a given target) are defined in the file
48    registers.c.
49 
50    This device is normally a child of the /openprom/init node.
51 
52 
53    EXAMPLES
54 
55 
56    Given a device tree containing the entry:
57 
58    |	/openprom/init/register/pc 0xfff00cf0
59 
60    then specifying the command line option:
61 
62    |	-o '/openprom/init/register/pc 0x0'
63 
64    would override the initial value of processor zero's program
65    counter.  The resultant device tree tree containing:
66 
67    |	/openprom/init/register/0.pc 0x0
68    |	/openprom/init/register/pc 0xfff00cf0
69 
70    and would be processed last to first resulting in the sequence: set
71    all program counters to 0xfff00cf0; set processor zero's program
72    counter to zero.
73 
74    */
75 
76 static void
do_register_init(device * me,const device_property * prop)77 do_register_init(device *me,
78 		 const device_property *prop)
79 {
80   psim *system = device_system(me);
81   if (prop != NULL) {
82     const char *name = prop->name;
83     unsigned32 value = device_find_integer_property(me, name);
84     int processor;
85 
86     do_register_init(me, device_next_property(prop));
87 
88     if (strchr(name, '.') == NULL) {
89       processor = -1;
90       DTRACE(register, ("%s=0x%lx\n", name, (unsigned long)value));
91     }
92     else {
93       char *end;
94       processor = strtoul(name, &end, 0);
95       ASSERT(end[0] == '.');
96       name = end+1;
97       DTRACE(register, ("%d.%s=0x%lx\n", processor, name,
98 			(unsigned long)value));
99     }
100     if (psim_write_register(system, processor, /* all processors */
101 			    &value,
102 			    name,
103 			    cooked_transfer) <= 0)
104       error("Invalid register name %s\n", name);
105   }
106 }
107 
108 
109 static void
register_init_data_callback(device * me)110 register_init_data_callback(device *me)
111 {
112   const device_property *prop = device_find_property(me, NULL);
113   do_register_init(me, prop);
114 }
115 
116 
117 static device_callbacks const register_callbacks = {
118   { NULL, register_init_data_callback, },
119   { NULL, }, /* address */
120   { NULL, }, /* IO */
121   { NULL, }, /* DMA */
122   { NULL, }, /* interrupt */
123   { NULL, }, /* unit */
124 };
125 
126 const device_descriptor hw_register_device_descriptor[] = {
127   { "register", NULL, &register_callbacks },
128   { NULL },
129 };
130 
131 #endif /* _HW_REGISTER_C_ */
132