2 * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
4 * This software may be freely used, copied, modified, and distributed
5 * provided that the above copyright notice is preserved in all copies of the
17 * Title: Parameter negotiation utility functions
22 #include "angel_endian.h"
27 * Function: Angel_FindParam
28 * Purpose: find the value of a given parameter from a config.
30 * see params.h for details
32 bool Angel_FindParam( ADP_Parameter type
,
33 const ParameterConfig
*config
,
38 for ( i
= 0; i
< config
->num_parameters
; ++i
)
39 if ( config
->param
[i
].type
== type
)
41 *value
= config
->param
[i
].value
;
49 #if !defined(TARGET) || !defined(MINIMAL_ANGEL) || MINIMAL_ANGEL == 0
51 ParameterList
*Angel_FindParamList( const ParameterOptions
*options
,
56 for ( i
= 0; i
< options
->num_param_lists
; ++i
)
57 if ( options
->param_list
[i
].type
== type
)
58 return &options
->param_list
[i
];
64 #if defined(TARGET) || defined(TEST_PARAMS)
66 * Function: Angel_MatchParams
67 * Purpose: find a configuration from the requested options which is
68 * the best match from the supported options.
70 * see params.h for details
72 const ParameterConfig
*Angel_MatchParams( const ParameterOptions
*requested
,
73 const ParameterOptions
*supported
)
75 static Parameter chosen_params
[AP_NUM_PARAMS
];
76 static ParameterConfig chosen_config
= {
82 ASSERT( requested
!= NULL
, "requested is NULL" );
83 ASSERT( requested
!= NULL
, "requested is NULL" );
84 ASSERT( supported
->num_param_lists
<= AP_NUM_PARAMS
, "supp_num too big" );
86 if ( requested
->num_param_lists
> supported
->num_param_lists
)
88 WARN( "req_num exceeds supp_num" );
92 for ( i
= 0; i
< requested
->num_param_lists
; ++i
)
97 const ParameterList
*req_list
= &requested
->param_list
[i
];
98 ADP_Parameter req_type
= req_list
->type
;
99 const ParameterList
*sup_list
= Angel_FindParamList(
100 supported
, req_type
);
102 if ( sup_list
== NULL
)
104 #ifdef ASSERTIONS_ENABLED
105 __rt_warning( "option %x not supported\n", req_type
);
110 for ( j
= 0, match
= FALSE
;
111 (j
< req_list
->num_options
) && !match
;
118 (k
< sup_list
->num_options
) && !match
;
122 if ( req_list
->option
[j
] == sup_list
->option
[k
] )
125 __rt_info( "chose value %d for option %x\n",
126 req_list
->option
[j
], req_type
);
129 chosen_config
.param
[i
].type
= req_type
;
130 chosen_config
.param
[i
].value
= req_list
->option
[j
];
137 #ifdef ASSERTIONS_ENABLED
138 __rt_warning( "no match found for option %x\n", req_type
);
144 chosen_config
.num_parameters
= i
;
145 INFO( "match succeeded" );
146 return &chosen_config
;
148 #endif /* defined(TARGET) || defined(TEST_PARAMS) */
151 #if !defined(TARGET) || defined(TEST_PARAMS)
153 * Function: Angel_StoreParam
154 * Purpose: store the value of a given parameter to a config.
156 * see params.h for details
158 bool Angel_StoreParam( ParameterConfig
*config
,
164 for ( i
= 0; i
< config
->num_parameters
; ++i
)
165 if ( config
->param
[i
].type
== type
)
167 config
->param
[i
].value
= value
;
173 #endif /* !defined(TARGET) || defined(TEST_PARAMS) */
176 #if defined(TARGET) || defined(LINK_RECOVERY) || defined(TEST_PARAMS)
178 * Function: Angel_BuildParamConfigMessage
179 * Purpose: write a parameter config to a buffer in ADP format.
181 * see params.h for details
183 unsigned int Angel_BuildParamConfigMessage( unsigned char *buffer
,
184 const ParameterConfig
*config
)
186 unsigned char *start
= buffer
;
189 PUT32LE( buffer
, config
->num_parameters
);
190 buffer
+= sizeof( word
);
192 for ( i
= 0; i
< config
->num_parameters
; ++i
)
194 PUT32LE( buffer
, config
->param
[i
].type
);
195 buffer
+= sizeof( word
);
196 PUT32LE( buffer
, config
->param
[i
].value
);
197 buffer
+= sizeof( word
);
200 return (buffer
- start
);
202 #endif /* defined(TARGET) || defined(LINK_RECOVERY) || defined(TEST_PARAMS) */
205 #if !defined(TARGET) || defined(TEST_PARAMS)
207 * Function: Angel_BuildParamOptionsMessage
208 * Purpose: write a parameter Options to a buffer in ADP format.
210 * see params.h for details
212 unsigned int Angel_BuildParamOptionsMessage( unsigned char *buffer
,
213 const ParameterOptions
*options
)
215 unsigned char *start
= buffer
;
218 PUT32LE( buffer
, options
->num_param_lists
);
219 buffer
+= sizeof( word
);
221 for ( i
= 0; i
< options
->num_param_lists
; ++i
)
223 PUT32LE( buffer
, options
->param_list
[i
].type
);
224 buffer
+= sizeof( word
);
225 PUT32LE( buffer
, options
->param_list
[i
].num_options
);
226 buffer
+= sizeof( word
);
227 for ( j
= 0; j
< options
->param_list
[i
].num_options
; ++j
)
229 PUT32LE( buffer
, options
->param_list
[i
].option
[j
] );
230 buffer
+= sizeof( word
);
234 return (buffer
- start
);
236 #endif /* !defined(TARGET) || defined(TEST_PARAMS) */
239 #if !defined(TARGET) || defined(LINK_RECOVERY) || defined(TEST_PARAMS)
241 * Function: Angel_ReadParamConfigMessage
242 * Purpose: read a parameter config from a buffer where it is in ADP format.
244 * see params.h for details
246 bool Angel_ReadParamConfigMessage( const unsigned char *buffer
,
247 ParameterConfig
*config
)
252 word
= GET32LE( buffer
);
253 buffer
+= sizeof( word
);
254 if ( word
> config
->num_parameters
)
256 WARN( "not enough space" );
259 config
->num_parameters
= word
;
261 for ( i
= 0; i
< config
->num_parameters
; ++i
)
263 config
->param
[i
].type
= (ADP_Parameter
)GET32LE( buffer
);
264 buffer
+= sizeof( word
);
265 config
->param
[i
].value
= GET32LE( buffer
);
266 buffer
+= sizeof( word
);
271 #endif /* !defined(TARGET) || defined(LINK_RECOVERY) || defined(TEST_PARAMS) */
274 #if defined(TARGET) || defined(TEST_PARAMS)
276 * Function: Angel_ReadParamOptionsMessage
277 * Purpose: read a parameter options block from a buffer
278 * where it is in ADP format.
280 * see params.h for details
282 bool Angel_ReadParamOptionsMessage( const unsigned char *buffer
,
283 ParameterOptions
*options
)
288 word
= GET32LE( buffer
);
289 buffer
+= sizeof( word
);
290 if ( word
> options
->num_param_lists
)
292 WARN( "not enough space" );
295 options
->num_param_lists
= word
;
297 for ( i
= 0; i
< options
->num_param_lists
; ++i
)
299 ParameterList
*list
= &options
->param_list
[i
];
301 list
->type
= (ADP_Parameter
)GET32LE( buffer
);
302 buffer
+= sizeof( word
);
303 word
= GET32LE( buffer
);
304 buffer
+= sizeof( word
);
305 if ( word
> list
->num_options
)
307 WARN( "not enough list space" );
310 list
->num_options
= word
;
312 for ( j
= 0; j
< list
->num_options
; ++j
)
314 list
->option
[j
] = GET32LE( buffer
);
315 buffer
+= sizeof( word
);
321 #endif /* defined(TARGET) || defined(TEST_PARAMS) */
323 #endif /* !define(TARGET) || !defined(MINIMAL_ANGEL) || MINIMAL_ANGEL == 0 */