| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * OpenSPARC T2 Processor File: parse.c |
| 5 | * Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved |
| 6 | * 4150 Network Circle, Santa Clara, California 95054, U.S.A. |
| 7 | * |
| 8 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; version 2 of the License. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | * |
| 23 | * For the avoidance of doubt, and except that if any non-GPL license |
| 24 | * choice is available it will apply instead, Sun elects to use only |
| 25 | * the General Public License version 2 (GPLv2) at this time for any |
| 26 | * software where a choice of GPL license versions is made |
| 27 | * available with the language indicating that GPLv2 or any later version |
| 28 | * may be used, or where a choice of which version of the GPL is applied is |
| 29 | * otherwise unspecified. |
| 30 | * |
| 31 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 32 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 33 | * have any questions. |
| 34 | * |
| 35 | * |
| 36 | * ========== Copyright Header End ============================================ |
| 37 | */ |
| 38 | #include "vcsuser.h" |
| 39 | #include "acc_user.h" |
| 40 | #include "malloc.h" |
| 41 | #include "string.h" |
| 42 | #include "ctype.h" /* for toupper */ |
| 43 | #include "stdio.h" /* for sscanf.h */ |
| 44 | |
| 45 | int parse_debug; |
| 46 | |
| 47 | /************************************************************************/ |
| 48 | /* parse check routine */ |
| 49 | /************************************************************************/ |
| 50 | void parse_check(int data, int reason) |
| 51 | { |
| 52 | parse_debug = 0; |
| 53 | return; |
| 54 | } /* value_check */ |
| 55 | |
| 56 | |
| 57 | |
| 58 | /************************************************************************/ |
| 59 | /* parese call routine */ |
| 60 | /************************************************************************/ |
| 61 | |
| 62 | void parse_call(int data, int reason) |
| 63 | { |
| 64 | char *ptr, *ptr_start; |
| 65 | float argf; |
| 66 | char *ptr_parse_str; |
| 67 | char *ptr_fmt_str; |
| 68 | char c, sep_c; |
| 69 | int arg_count; |
| 70 | int max_args; |
| 71 | int ret_null_str; |
| 72 | int i; |
| 73 | |
| 74 | static s_acc_value avalue = {accIntVal}; /* Holds argument value */ |
| 75 | static s_setval_delay delay_s = {{0}, accNoDelay}; |
| 76 | |
| 77 | max_args = tf_nump(); |
| 78 | |
| 79 | ptr_parse_str = tf_getcstringp(1); |
| 80 | ptr_fmt_str = tf_getcstringp(2); |
| 81 | ptr = tf_getcstringp(3); |
| 82 | ret_null_str = 0; |
| 83 | |
| 84 | if (*ptr_parse_str == 0) { |
| 85 | tf_putp(0, 0); |
| 86 | return; |
| 87 | } |
| 88 | if (parse_debug == 1) |
| 89 | io_printf ("parse_debug: parse-str=%s, fmt-str=%s, max-args=%d\n", ptr_parse_str, ptr_fmt_str, max_args); |
| 90 | arg_count = 3; |
| 91 | |
| 92 | c = *ptr_fmt_str++; // % |
| 93 | c = *ptr_fmt_str++; |
| 94 | |
| 95 | ptr_start = ptr_parse_str; |
| 96 | for (i = 3; i <= (max_args); i++) { |
| 97 | sep_c = *ptr_fmt_str++; |
| 98 | if (parse_debug == 1) |
| 99 | io_printf ("parse_debug: sep-char=%c\n", sep_c); |
| 100 | ptr = ptr_start; |
| 101 | while (ptr && *ptr && (*ptr != sep_c)) ptr++; |
| 102 | ret_null_str = *ptr; |
| 103 | *ptr = 0; |
| 104 | if (parse_debug == 1) |
| 105 | io_printf ("parse_debug: value-string=%s\n", ptr_start); |
| 106 | avalue.value.str = strdup (ptr_start); |
| 107 | ptr_start = ptr+1; |
| 108 | |
| 109 | switch (c) { |
| 110 | case 'b': { |
| 111 | /* Write the binary string into the register */ |
| 112 | avalue.format = accBinStrVal; |
| 113 | acc_set_value(acc_handle_tfarg(i), &avalue, &delay_s); |
| 114 | break; |
| 115 | } /* %b */ |
| 116 | |
| 117 | case 'd': { |
| 118 | /* Write the decimal string into the register */ |
| 119 | avalue.format = accDecStrVal; |
| 120 | acc_set_value(acc_handle_tfarg(i), &avalue, &delay_s); |
| 121 | break; |
| 122 | } /* %d */ |
| 123 | |
| 124 | case 'e': { |
| 125 | /* Write the floating string into the register */ |
| 126 | sscanf(ptr, "%e", &argf); |
| 127 | avalue.format = accRealVal; |
| 128 | avalue.value.real = argf; |
| 129 | acc_set_value(acc_handle_tfarg(i), &avalue, &delay_s); |
| 130 | break; |
| 131 | } /* %e */ |
| 132 | |
| 133 | case 'f': { |
| 134 | /* Write the floating string into the register */ |
| 135 | sscanf(ptr, "%f", &argf); |
| 136 | avalue.format = accRealVal; |
| 137 | avalue.value.real = argf; |
| 138 | acc_set_value(acc_handle_tfarg(i), &avalue, &delay_s); |
| 139 | break; |
| 140 | } /* %f */ |
| 141 | |
| 142 | case 'g': { |
| 143 | /* Write the floating string into the register */ |
| 144 | sscanf(ptr, "%g", &argf); |
| 145 | avalue.format = accRealVal; |
| 146 | avalue.value.real = argf; |
| 147 | acc_set_value(acc_handle_tfarg(i), &avalue, &delay_s); |
| 148 | break; |
| 149 | } /* %g */ |
| 150 | |
| 151 | case 'h': { |
| 152 | /* Write the hexadecimal string into the register */ |
| 153 | avalue.format = accHexStrVal; |
| 154 | acc_set_value(acc_handle_tfarg(i), &avalue, &delay_s); |
| 155 | break; |
| 156 | } /* %h */ |
| 157 | |
| 158 | case 'o': { |
| 159 | /* Write the octal string into the register */ |
| 160 | /* I'll give you a buck for anyone who still uses octal */ |
| 161 | avalue.format = accOctStrVal; |
| 162 | acc_set_value(acc_handle_tfarg(i), &avalue, &delay_s); |
| 163 | break; |
| 164 | } /* %o */ |
| 165 | |
| 166 | case 's': { |
| 167 | avalue.format = accStringVal; |
| 168 | acc_set_value(acc_handle_tfarg(i), &avalue, &delay_s); |
| 169 | break; |
| 170 | } /* %s */ |
| 171 | |
| 172 | default: { |
| 173 | tf_error("plus error in undefined format = %c", c); |
| 174 | tf_dofinish(); |
| 175 | } /* default */ |
| 176 | |
| 177 | } /* switch fmt->type */ |
| 178 | c = *ptr_fmt_str++; // % |
| 179 | if (parse_debug == 1) |
| 180 | io_printf ("parse_debug: format string= %c ", c); |
| 181 | c = *ptr_fmt_str++; |
| 182 | if (parse_debug == 1) |
| 183 | io_printf ("parse_debug: format char= %c\n", c); |
| 184 | |
| 185 | } |
| 186 | if (ret_null_str) |
| 187 | avalue.value.str = strdup (ptr_start); |
| 188 | else |
| 189 | *avalue.value.str = 0; |
| 190 | avalue.format = accStringVal; |
| 191 | acc_set_value(acc_handle_tfarg(1), &avalue, &delay_s); |
| 192 | tf_putp(0, 1); |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | |