Commit | Line | Data |
---|---|---|
8477437c MM |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au> | |
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 2 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, write to the Free Software | |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | ||
19 | */ | |
20 | ||
21 | ||
22 | #ifndef _HW_REGISTER_C_ | |
23 | #define _HW_REGISTER_C_ | |
24 | ||
25 | #include "device_table.h" | |
26 | #include <stdlib.h> | |
27 | #include "psim.h" | |
28 | ||
29 | /* DEVICE | |
30 | ||
31 | register - dummy device to initialize processor registers | |
32 | ||
33 | DESCRIPTION | |
34 | ||
35 | The properties of this device are used, during initialization, to | |
36 | specify the initial value of various processor registers. The | |
37 | property name specifying the register to be initialized with the | |
38 | special form <cpu-nr>.<register> being used to initialize a | |
39 | specific processor's register (eg 0.pc). | |
40 | ||
41 | Because, when the device tree is created, overriding properties are | |
42 | entered into the tree before any default values, this device must | |
43 | initialize registers in newest (default) to oldest (overriding) | |
44 | property order. | |
45 | ||
46 | The actual registers (for a given target) are defined in the file | |
47 | registers.c. | |
48 | ||
49 | This device is normally a child of the /openprom/init node. | |
50 | ||
51 | EXAMPLE | |
52 | ||
53 | Given a device tree containing the entry: | |
54 | ||
55 | | /openprom/init/register/pc 0xfff00cf0 | |
56 | ||
57 | then specifying the command line option: | |
58 | ||
59 | | -o '/openprom/init/register/pc 0x0' | |
60 | ||
61 | would override the initial value of processor zero's program | |
62 | counter. The resultant device tree tree containing: | |
63 | ||
64 | | /openprom/init/register/0.pc 0x0 | |
65 | | /openprom/init/register/pc 0xfff00cf0 | |
66 | ||
67 | and would be processed last to first resulting in the sequence: set | |
68 | all program counters to 0xfff00cf0; set processor zero's program | |
69 | counter to zero. */ | |
70 | ||
71 | static void | |
72 | do_register_init(device *me, | |
73 | const device_property *prop) | |
74 | { | |
75 | psim *system = device_system(me); | |
76 | if (prop != NULL) { | |
77 | const char *name = prop->name; | |
78 | unsigned32 value = device_find_integer_property(me, name); | |
79 | int processor; | |
80 | ||
81 | do_register_init(me, device_next_property(prop)); | |
82 | ||
83 | if (strchr(name, '.') == NULL) { | |
84 | processor = -1; | |
85 | DTRACE(register, ("%s=0x%lx\n", name, (unsigned long)value)); | |
86 | } | |
87 | else { | |
88 | char *end; | |
89 | processor = strtoul(name, &end, 0); | |
90 | ASSERT(end[0] == '.'); | |
91 | name = end+1; | |
92 | DTRACE(register, ("%d.%s=0x%lx\n", processor, name, | |
93 | (unsigned long)value)); | |
94 | } | |
95 | psim_write_register(system, processor, /* all processors */ | |
96 | &value, | |
97 | name, | |
98 | cooked_transfer); | |
99 | } | |
100 | } | |
101 | ||
102 | ||
103 | static void | |
104 | register_init_data_callback(device *me) | |
105 | { | |
106 | const device_property *prop = device_find_property(me, NULL); | |
107 | do_register_init(me, prop); | |
108 | } | |
109 | ||
110 | ||
111 | static device_callbacks const register_callbacks = { | |
112 | { NULL, register_init_data_callback, }, | |
113 | { NULL, }, /* address */ | |
114 | { NULL, }, /* IO */ | |
115 | { NULL, }, /* DMA */ | |
116 | { NULL, }, /* interrupt */ | |
117 | { NULL, }, /* unit */ | |
118 | }; | |
119 | ||
120 | const device_descriptor hw_register_device_descriptor[] = { | |
121 | { "register", NULL, ®ister_callbacks }, | |
122 | { NULL }, | |
123 | }; | |
124 | ||
125 | #endif _HW_REGISTER_C_ |