1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 2000 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <stdio.h> 30*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 31*7c478bd9Sstevel@tonic-gate #include <strings.h> 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include <fcode/private.h> 34*7c478bd9Sstevel@tonic-gate #include <fcode/log.h> 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <fcdriver/fcdriver.h> 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate static fc_cell_t 39*7c478bd9Sstevel@tonic-gate fc_reg_read(fcode_env_t *env, char *service, fstack_t virt, int *errp) 40*7c478bd9Sstevel@tonic-gate { 41*7c478bd9Sstevel@tonic-gate fc_cell_t virtaddr, data; 42*7c478bd9Sstevel@tonic-gate int error, nin; 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate if (!is_mcookie(virt)) 45*7c478bd9Sstevel@tonic-gate forth_abort(env, "fc_reg_read: bad mcookie: 0x%x\n", virt); 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate virtaddr = mcookie_to_addr(virt); 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate /* Supress fc_run_priv error msgs on peeks */ 50*7c478bd9Sstevel@tonic-gate nin = ((errp == NULL) ? 1 : (1 | FCRP_NOERROR)); 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate error = fc_run_priv(env->private, service, nin, 1, virtaddr, &data); 53*7c478bd9Sstevel@tonic-gate if (errp) 54*7c478bd9Sstevel@tonic-gate /* Don't report error on peeks */ 55*7c478bd9Sstevel@tonic-gate *errp = error; 56*7c478bd9Sstevel@tonic-gate else if (error) { 57*7c478bd9Sstevel@tonic-gate log_message(MSG_ERROR, "fc_read_reg: ERROR: cookie: %llx" 58*7c478bd9Sstevel@tonic-gate " virt: %llx\n", (uint64_t)virt, (uint64_t)virtaddr); 59*7c478bd9Sstevel@tonic-gate data = 0; 60*7c478bd9Sstevel@tonic-gate } 61*7c478bd9Sstevel@tonic-gate return (data); 62*7c478bd9Sstevel@tonic-gate } 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate static void 65*7c478bd9Sstevel@tonic-gate fc_reg_write(fcode_env_t *env, char *service, fstack_t virt, fc_cell_t data, 66*7c478bd9Sstevel@tonic-gate int *errp) 67*7c478bd9Sstevel@tonic-gate { 68*7c478bd9Sstevel@tonic-gate fc_cell_t virtaddr; 69*7c478bd9Sstevel@tonic-gate int error, nin; 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate if (!is_mcookie(virt)) 72*7c478bd9Sstevel@tonic-gate forth_abort(env, "fc_reg_write: bad mcookie: 0x%x\n", virt); 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate virtaddr = mcookie_to_addr(virt); 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate /* Supress fc_run_priv error msgs on pokes */ 77*7c478bd9Sstevel@tonic-gate nin = ((errp == NULL) ? 2 : (2 | FCRP_NOERROR)); 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate error = fc_run_priv(env->private, service, nin, 0, virtaddr, data); 80*7c478bd9Sstevel@tonic-gate if (errp) 81*7c478bd9Sstevel@tonic-gate /* Don't report error on pokes */ 82*7c478bd9Sstevel@tonic-gate *errp = error; 83*7c478bd9Sstevel@tonic-gate else if (error) { 84*7c478bd9Sstevel@tonic-gate log_message(MSG_ERROR, "fc_write_reg: ERROR: cookie: %llx" 85*7c478bd9Sstevel@tonic-gate " virt: %llx\n", (uint64_t)virt, (uint64_t)virtaddr); 86*7c478bd9Sstevel@tonic-gate } 87*7c478bd9Sstevel@tonic-gate } 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate static int 90*7c478bd9Sstevel@tonic-gate check_address_abuse(fcode_env_t *env, fstack_t addr, char *type, 91*7c478bd9Sstevel@tonic-gate int want_mcookie, void (*alt)(fcode_env_t *)) 92*7c478bd9Sstevel@tonic-gate { 93*7c478bd9Sstevel@tonic-gate if (is_mcookie(addr) != want_mcookie) { 94*7c478bd9Sstevel@tonic-gate debug_msg(DEBUG_ADDR_ABUSE, "Warning: %s to %s address: %llx\n", 95*7c478bd9Sstevel@tonic-gate type, want_mcookie ? "unmapped" : "mapped", 96*7c478bd9Sstevel@tonic-gate (uint64_t)addr); 97*7c478bd9Sstevel@tonic-gate (*alt)(env); 98*7c478bd9Sstevel@tonic-gate return (1); 99*7c478bd9Sstevel@tonic-gate } 100*7c478bd9Sstevel@tonic-gate return (0); 101*7c478bd9Sstevel@tonic-gate } 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate static void 104*7c478bd9Sstevel@tonic-gate rlfetch(fcode_env_t *env) 105*7c478bd9Sstevel@tonic-gate { 106*7c478bd9Sstevel@tonic-gate fstack_t p; 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "rl@"); 109*7c478bd9Sstevel@tonic-gate p = TOS; 110*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, p, "rl@", 1, lfetch)) 111*7c478bd9Sstevel@tonic-gate TOS = (lforth_t)fc_reg_read(env, "rl@", p, NULL); 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate static void 115*7c478bd9Sstevel@tonic-gate rlstore(fcode_env_t *env) 116*7c478bd9Sstevel@tonic-gate { 117*7c478bd9Sstevel@tonic-gate fstack_t p, d; 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "rl!"); 120*7c478bd9Sstevel@tonic-gate p = TOS; 121*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, p, "rl!", 1, lstore)) { 122*7c478bd9Sstevel@tonic-gate p = POP(DS); 123*7c478bd9Sstevel@tonic-gate d = POP(DS); 124*7c478bd9Sstevel@tonic-gate fc_reg_write(env, "rl!", p, d, NULL); 125*7c478bd9Sstevel@tonic-gate } 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate static void 129*7c478bd9Sstevel@tonic-gate rwfetch(fcode_env_t *env) 130*7c478bd9Sstevel@tonic-gate { 131*7c478bd9Sstevel@tonic-gate fstack_t p; 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "rw@"); 134*7c478bd9Sstevel@tonic-gate p = TOS; 135*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, p, "rw@", 1, wfetch)) 136*7c478bd9Sstevel@tonic-gate TOS = (wforth_t)fc_reg_read(env, "rw@", p, NULL); 137*7c478bd9Sstevel@tonic-gate } 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate static void 140*7c478bd9Sstevel@tonic-gate rwstore(fcode_env_t *env) 141*7c478bd9Sstevel@tonic-gate { 142*7c478bd9Sstevel@tonic-gate fstack_t p, d; 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "rw!"); 145*7c478bd9Sstevel@tonic-gate p = TOS; 146*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, p, "rw!", 1, wstore)) { 147*7c478bd9Sstevel@tonic-gate p = POP(DS); 148*7c478bd9Sstevel@tonic-gate d = POP(DS); 149*7c478bd9Sstevel@tonic-gate fc_reg_write(env, "rw!", p, d, NULL); 150*7c478bd9Sstevel@tonic-gate } 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate void 154*7c478bd9Sstevel@tonic-gate rbfetch(fcode_env_t *env) 155*7c478bd9Sstevel@tonic-gate { 156*7c478bd9Sstevel@tonic-gate fstack_t p; 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "rb@"); 159*7c478bd9Sstevel@tonic-gate p = TOS; 160*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, p, "rb@", 1, cfetch)) { 161*7c478bd9Sstevel@tonic-gate TOS = (uchar_t)fc_reg_read(env, "rb@", p, NULL); 162*7c478bd9Sstevel@tonic-gate } 163*7c478bd9Sstevel@tonic-gate } 164*7c478bd9Sstevel@tonic-gate 165*7c478bd9Sstevel@tonic-gate static void 166*7c478bd9Sstevel@tonic-gate rbstore(fcode_env_t *env) 167*7c478bd9Sstevel@tonic-gate { 168*7c478bd9Sstevel@tonic-gate fstack_t p, d; 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "rb!"); 171*7c478bd9Sstevel@tonic-gate p = TOS; 172*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, p, "rb!", 1, cstore)) { 173*7c478bd9Sstevel@tonic-gate p = POP(DS); 174*7c478bd9Sstevel@tonic-gate d = POP(DS); 175*7c478bd9Sstevel@tonic-gate fc_reg_write(env, "rb!", p, d, NULL); 176*7c478bd9Sstevel@tonic-gate } 177*7c478bd9Sstevel@tonic-gate } 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate /* 180*7c478bd9Sstevel@tonic-gate * rx@ ( xa -- xv ) 181*7c478bd9Sstevel@tonic-gate */ 182*7c478bd9Sstevel@tonic-gate static void 183*7c478bd9Sstevel@tonic-gate rxfetch(fcode_env_t *env) 184*7c478bd9Sstevel@tonic-gate { 185*7c478bd9Sstevel@tonic-gate fstack_t p; 186*7c478bd9Sstevel@tonic-gate xforth_t x; 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "rx@"); 189*7c478bd9Sstevel@tonic-gate p = TOS; 190*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, p, "rx@", 1, xfetch)) { 191*7c478bd9Sstevel@tonic-gate p = POP(DS); 192*7c478bd9Sstevel@tonic-gate push_xforth(env, (xforth_t)fc_reg_read(env, "rx@", p, NULL)); 193*7c478bd9Sstevel@tonic-gate } 194*7c478bd9Sstevel@tonic-gate } 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate /* 197*7c478bd9Sstevel@tonic-gate * rx! ( xv xa -- ) 198*7c478bd9Sstevel@tonic-gate */ 199*7c478bd9Sstevel@tonic-gate static void 200*7c478bd9Sstevel@tonic-gate rxstore(fcode_env_t *env) 201*7c478bd9Sstevel@tonic-gate { 202*7c478bd9Sstevel@tonic-gate fstack_t p; 203*7c478bd9Sstevel@tonic-gate xforth_t d; 204*7c478bd9Sstevel@tonic-gate 205*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "rx!"); 206*7c478bd9Sstevel@tonic-gate p = TOS; 207*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, p, "rx!", 1, xstore)) { 208*7c478bd9Sstevel@tonic-gate p = POP(DS); 209*7c478bd9Sstevel@tonic-gate d = pop_xforth(env); 210*7c478bd9Sstevel@tonic-gate fc_reg_write(env, "rx!", p, d, NULL); 211*7c478bd9Sstevel@tonic-gate } 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate static void 215*7c478bd9Sstevel@tonic-gate lpeek(fcode_env_t *env) 216*7c478bd9Sstevel@tonic-gate { 217*7c478bd9Sstevel@tonic-gate fstack_t p; 218*7c478bd9Sstevel@tonic-gate lforth_t r; 219*7c478bd9Sstevel@tonic-gate int error; 220*7c478bd9Sstevel@tonic-gate 221*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "lpeek"); 222*7c478bd9Sstevel@tonic-gate p = POP(DS); 223*7c478bd9Sstevel@tonic-gate r = (lforth_t)fc_reg_read(env, "rl@", p, &error); 224*7c478bd9Sstevel@tonic-gate if (error) 225*7c478bd9Sstevel@tonic-gate PUSH(DS, FALSE); 226*7c478bd9Sstevel@tonic-gate else { 227*7c478bd9Sstevel@tonic-gate PUSH(DS, r); 228*7c478bd9Sstevel@tonic-gate PUSH(DS, TRUE); 229*7c478bd9Sstevel@tonic-gate } 230*7c478bd9Sstevel@tonic-gate } 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate static void 233*7c478bd9Sstevel@tonic-gate lpoke(fcode_env_t *env) 234*7c478bd9Sstevel@tonic-gate { 235*7c478bd9Sstevel@tonic-gate fstack_t p, d; 236*7c478bd9Sstevel@tonic-gate int error; 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "lpoke"); 239*7c478bd9Sstevel@tonic-gate p = POP(DS); 240*7c478bd9Sstevel@tonic-gate d = POP(DS); 241*7c478bd9Sstevel@tonic-gate fc_reg_write(env, "rl!", p, d, &error); 242*7c478bd9Sstevel@tonic-gate PUSH(DS, error ? FALSE : TRUE); 243*7c478bd9Sstevel@tonic-gate } 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate static void 246*7c478bd9Sstevel@tonic-gate wpeek(fcode_env_t *env) 247*7c478bd9Sstevel@tonic-gate { 248*7c478bd9Sstevel@tonic-gate fstack_t p; 249*7c478bd9Sstevel@tonic-gate int error; 250*7c478bd9Sstevel@tonic-gate wforth_t r; 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "wpeek"); 253*7c478bd9Sstevel@tonic-gate p = POP(DS); 254*7c478bd9Sstevel@tonic-gate r = (wforth_t)fc_reg_read(env, "rw@", p, &error); 255*7c478bd9Sstevel@tonic-gate if (error) 256*7c478bd9Sstevel@tonic-gate PUSH(DS, FALSE); 257*7c478bd9Sstevel@tonic-gate else { 258*7c478bd9Sstevel@tonic-gate PUSH(DS, r); 259*7c478bd9Sstevel@tonic-gate PUSH(DS, TRUE); 260*7c478bd9Sstevel@tonic-gate } 261*7c478bd9Sstevel@tonic-gate } 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate static void 264*7c478bd9Sstevel@tonic-gate wpoke(fcode_env_t *env) 265*7c478bd9Sstevel@tonic-gate { 266*7c478bd9Sstevel@tonic-gate fstack_t p, d; 267*7c478bd9Sstevel@tonic-gate int error; 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "wpoke"); 270*7c478bd9Sstevel@tonic-gate p = POP(DS); 271*7c478bd9Sstevel@tonic-gate d = POP(DS); 272*7c478bd9Sstevel@tonic-gate fc_reg_write(env, "rw!", p, d, &error); 273*7c478bd9Sstevel@tonic-gate PUSH(DS, error ? FALSE : TRUE); 274*7c478bd9Sstevel@tonic-gate } 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate static void 277*7c478bd9Sstevel@tonic-gate cpeek(fcode_env_t *env) 278*7c478bd9Sstevel@tonic-gate { 279*7c478bd9Sstevel@tonic-gate fstack_t p; 280*7c478bd9Sstevel@tonic-gate uchar_t r; 281*7c478bd9Sstevel@tonic-gate int error; 282*7c478bd9Sstevel@tonic-gate 283*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "cpeek"); 284*7c478bd9Sstevel@tonic-gate p = POP(DS); 285*7c478bd9Sstevel@tonic-gate r = (uchar_t)fc_reg_read(env, "rb@", p, &error); 286*7c478bd9Sstevel@tonic-gate if (error) 287*7c478bd9Sstevel@tonic-gate PUSH(DS, FALSE); 288*7c478bd9Sstevel@tonic-gate else { 289*7c478bd9Sstevel@tonic-gate PUSH(DS, r); 290*7c478bd9Sstevel@tonic-gate PUSH(DS, TRUE); 291*7c478bd9Sstevel@tonic-gate } 292*7c478bd9Sstevel@tonic-gate } 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate static void 295*7c478bd9Sstevel@tonic-gate cpoke(fcode_env_t *env) 296*7c478bd9Sstevel@tonic-gate { 297*7c478bd9Sstevel@tonic-gate fstack_t p, d; 298*7c478bd9Sstevel@tonic-gate int error; 299*7c478bd9Sstevel@tonic-gate 300*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "cpoke"); 301*7c478bd9Sstevel@tonic-gate p = POP(DS); 302*7c478bd9Sstevel@tonic-gate d = POP(DS); 303*7c478bd9Sstevel@tonic-gate fc_reg_write(env, "rb!", p, d, &error); 304*7c478bd9Sstevel@tonic-gate PUSH(DS, error ? FALSE : TRUE); 305*7c478bd9Sstevel@tonic-gate } 306*7c478bd9Sstevel@tonic-gate 307*7c478bd9Sstevel@tonic-gate /* 308*7c478bd9Sstevel@tonic-gate * fcdriver version of cfetch, replaces base 'c@' 309*7c478bd9Sstevel@tonic-gate */ 310*7c478bd9Sstevel@tonic-gate static void 311*7c478bd9Sstevel@tonic-gate fcd_cfetch(fcode_env_t *env) 312*7c478bd9Sstevel@tonic-gate { 313*7c478bd9Sstevel@tonic-gate fstack_t addr = TOS; 314*7c478bd9Sstevel@tonic-gate 315*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "c@"); 316*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, addr, "c@", 0, rbfetch)) 317*7c478bd9Sstevel@tonic-gate cfetch(env); 318*7c478bd9Sstevel@tonic-gate } 319*7c478bd9Sstevel@tonic-gate 320*7c478bd9Sstevel@tonic-gate /* 321*7c478bd9Sstevel@tonic-gate * fcdriver version of cstore, replaces base 'c!' 322*7c478bd9Sstevel@tonic-gate */ 323*7c478bd9Sstevel@tonic-gate static void 324*7c478bd9Sstevel@tonic-gate fcd_cstore(fcode_env_t *env) 325*7c478bd9Sstevel@tonic-gate { 326*7c478bd9Sstevel@tonic-gate fstack_t addr = TOS; 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "c!"); 329*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, addr, "c!", 0, rbstore)) 330*7c478bd9Sstevel@tonic-gate cstore(env); 331*7c478bd9Sstevel@tonic-gate } 332*7c478bd9Sstevel@tonic-gate 333*7c478bd9Sstevel@tonic-gate /* 334*7c478bd9Sstevel@tonic-gate * fcdriver version of wfetch, replaces base 'w@' 335*7c478bd9Sstevel@tonic-gate */ 336*7c478bd9Sstevel@tonic-gate static void 337*7c478bd9Sstevel@tonic-gate fcd_wfetch(fcode_env_t *env) 338*7c478bd9Sstevel@tonic-gate { 339*7c478bd9Sstevel@tonic-gate fstack_t addr = TOS; 340*7c478bd9Sstevel@tonic-gate 341*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "w@"); 342*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, addr, "w@", 0, rwfetch)) 343*7c478bd9Sstevel@tonic-gate wfetch(env); 344*7c478bd9Sstevel@tonic-gate } 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate /* 347*7c478bd9Sstevel@tonic-gate * fcdriver version of wstore, replaces base 'w!' 348*7c478bd9Sstevel@tonic-gate */ 349*7c478bd9Sstevel@tonic-gate static void 350*7c478bd9Sstevel@tonic-gate fcd_wstore(fcode_env_t *env) 351*7c478bd9Sstevel@tonic-gate { 352*7c478bd9Sstevel@tonic-gate fstack_t addr = TOS; 353*7c478bd9Sstevel@tonic-gate 354*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "w!"); 355*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, addr, "w!", 0, rwstore)) 356*7c478bd9Sstevel@tonic-gate wstore(env); 357*7c478bd9Sstevel@tonic-gate } 358*7c478bd9Sstevel@tonic-gate 359*7c478bd9Sstevel@tonic-gate /* 360*7c478bd9Sstevel@tonic-gate * fcdriver version of lfetch, replaces base 'l@' 361*7c478bd9Sstevel@tonic-gate */ 362*7c478bd9Sstevel@tonic-gate static void 363*7c478bd9Sstevel@tonic-gate fcd_lfetch(fcode_env_t *env) 364*7c478bd9Sstevel@tonic-gate { 365*7c478bd9Sstevel@tonic-gate fstack_t addr = TOS; 366*7c478bd9Sstevel@tonic-gate 367*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "l@"); 368*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, addr, "l@", 0, rlfetch)) 369*7c478bd9Sstevel@tonic-gate lfetch(env); 370*7c478bd9Sstevel@tonic-gate } 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate /* 373*7c478bd9Sstevel@tonic-gate * fcdriver version of lstore, replaces base 'l!' 374*7c478bd9Sstevel@tonic-gate */ 375*7c478bd9Sstevel@tonic-gate static void 376*7c478bd9Sstevel@tonic-gate fcd_lstore(fcode_env_t *env) 377*7c478bd9Sstevel@tonic-gate { 378*7c478bd9Sstevel@tonic-gate fstack_t addr = TOS; 379*7c478bd9Sstevel@tonic-gate 380*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "l!"); 381*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, addr, "l!", 0, rlstore)) 382*7c478bd9Sstevel@tonic-gate lstore(env); 383*7c478bd9Sstevel@tonic-gate } 384*7c478bd9Sstevel@tonic-gate 385*7c478bd9Sstevel@tonic-gate /* 386*7c478bd9Sstevel@tonic-gate * fcdriver version of xfetch, replaces base 'x@' 387*7c478bd9Sstevel@tonic-gate */ 388*7c478bd9Sstevel@tonic-gate static void 389*7c478bd9Sstevel@tonic-gate fcd_xfetch(fcode_env_t *env) 390*7c478bd9Sstevel@tonic-gate { 391*7c478bd9Sstevel@tonic-gate fstack_t addr = TOS; 392*7c478bd9Sstevel@tonic-gate 393*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "x@"); 394*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, addr, "x@", 0, rxfetch)) 395*7c478bd9Sstevel@tonic-gate xfetch(env); 396*7c478bd9Sstevel@tonic-gate } 397*7c478bd9Sstevel@tonic-gate 398*7c478bd9Sstevel@tonic-gate /* 399*7c478bd9Sstevel@tonic-gate * fcdriver version of xstore, replaces base 'x!' 400*7c478bd9Sstevel@tonic-gate */ 401*7c478bd9Sstevel@tonic-gate static void 402*7c478bd9Sstevel@tonic-gate fcd_xstore(fcode_env_t *env) 403*7c478bd9Sstevel@tonic-gate { 404*7c478bd9Sstevel@tonic-gate fstack_t addr = TOS; 405*7c478bd9Sstevel@tonic-gate 406*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "x!"); 407*7c478bd9Sstevel@tonic-gate if (!check_address_abuse(env, addr, "x!", 0, rxstore)) 408*7c478bd9Sstevel@tonic-gate xstore(env); 409*7c478bd9Sstevel@tonic-gate } 410*7c478bd9Sstevel@tonic-gate 411*7c478bd9Sstevel@tonic-gate /* 412*7c478bd9Sstevel@tonic-gate * fcdriver version of move, replaces base 'move' 413*7c478bd9Sstevel@tonic-gate */ 414*7c478bd9Sstevel@tonic-gate static void 415*7c478bd9Sstevel@tonic-gate fcd_move(fcode_env_t *env) 416*7c478bd9Sstevel@tonic-gate { 417*7c478bd9Sstevel@tonic-gate size_t len; 418*7c478bd9Sstevel@tonic-gate uchar_t *destaddr, *srcaddr; 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 3, "move"); 421*7c478bd9Sstevel@tonic-gate len = POP(DS); 422*7c478bd9Sstevel@tonic-gate destaddr = ((uchar_t *)POP(DS)); 423*7c478bd9Sstevel@tonic-gate srcaddr = ((uchar_t *)POP(DS)); 424*7c478bd9Sstevel@tonic-gate for (; len > 0; len--, srcaddr++, destaddr++) { 425*7c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)srcaddr); 426*7c478bd9Sstevel@tonic-gate fcd_cfetch(env); 427*7c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)destaddr); 428*7c478bd9Sstevel@tonic-gate fcd_cstore(env); 429*7c478bd9Sstevel@tonic-gate } 430*7c478bd9Sstevel@tonic-gate } 431*7c478bd9Sstevel@tonic-gate 432*7c478bd9Sstevel@tonic-gate static void 433*7c478bd9Sstevel@tonic-gate fcd_comp(fcode_env_t *env) 434*7c478bd9Sstevel@tonic-gate { 435*7c478bd9Sstevel@tonic-gate char *str1, *str2, byte1, byte2; 436*7c478bd9Sstevel@tonic-gate size_t len; 437*7c478bd9Sstevel@tonic-gate 438*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 3, "comp"); 439*7c478bd9Sstevel@tonic-gate len = (size_t)POP(DS); 440*7c478bd9Sstevel@tonic-gate str1 = (char *)POP(DS); 441*7c478bd9Sstevel@tonic-gate str2 = (char *)POP(DS); 442*7c478bd9Sstevel@tonic-gate for (; len > 0; len--, str1++, str2++) { 443*7c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)str1); 444*7c478bd9Sstevel@tonic-gate fcd_cfetch(env); 445*7c478bd9Sstevel@tonic-gate byte1 = POP(DS); 446*7c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)str2); 447*7c478bd9Sstevel@tonic-gate fcd_cfetch(env); 448*7c478bd9Sstevel@tonic-gate byte2 = POP(DS); 449*7c478bd9Sstevel@tonic-gate if (byte1 > byte2) { 450*7c478bd9Sstevel@tonic-gate PUSH(DS, -1); 451*7c478bd9Sstevel@tonic-gate return; 452*7c478bd9Sstevel@tonic-gate } 453*7c478bd9Sstevel@tonic-gate if (byte1 < byte2) { 454*7c478bd9Sstevel@tonic-gate PUSH(DS, 1); 455*7c478bd9Sstevel@tonic-gate return; 456*7c478bd9Sstevel@tonic-gate } 457*7c478bd9Sstevel@tonic-gate } 458*7c478bd9Sstevel@tonic-gate PUSH(DS, 0); 459*7c478bd9Sstevel@tonic-gate } 460*7c478bd9Sstevel@tonic-gate 461*7c478bd9Sstevel@tonic-gate char * 462*7c478bd9Sstevel@tonic-gate get_eeprom_value(fcode_env_t *env, char *name) 463*7c478bd9Sstevel@tonic-gate { 464*7c478bd9Sstevel@tonic-gate FILE *fd; 465*7c478bd9Sstevel@tonic-gate char buf[80], *p; 466*7c478bd9Sstevel@tonic-gate 467*7c478bd9Sstevel@tonic-gate sprintf(buf, "eeprom '%s'", name); 468*7c478bd9Sstevel@tonic-gate if ((fd = popen(buf, "r")) == NULL) 469*7c478bd9Sstevel@tonic-gate return (NULL); 470*7c478bd9Sstevel@tonic-gate fgets(buf, sizeof (buf), fd); 471*7c478bd9Sstevel@tonic-gate pclose(fd); 472*7c478bd9Sstevel@tonic-gate if ((p = strchr(buf, '\n')) != NULL) 473*7c478bd9Sstevel@tonic-gate *p = '\0'; 474*7c478bd9Sstevel@tonic-gate if ((p = strchr(buf, '=')) != NULL) 475*7c478bd9Sstevel@tonic-gate return (p + 1); 476*7c478bd9Sstevel@tonic-gate return (NULL); 477*7c478bd9Sstevel@tonic-gate } 478*7c478bd9Sstevel@tonic-gate 479*7c478bd9Sstevel@tonic-gate static void 480*7c478bd9Sstevel@tonic-gate local_mac_address(fcode_env_t *env) 481*7c478bd9Sstevel@tonic-gate { 482*7c478bd9Sstevel@tonic-gate char *mac_str; 483*7c478bd9Sstevel@tonic-gate int mac_value; 484*7c478bd9Sstevel@tonic-gate 485*7c478bd9Sstevel@tonic-gate mac_str = get_eeprom_value(env, "local-mac-address?"); 486*7c478bd9Sstevel@tonic-gate if (mac_str != NULL && strcmp(mac_str, "true") == 0) 487*7c478bd9Sstevel@tonic-gate mac_value = TRUE; 488*7c478bd9Sstevel@tonic-gate else 489*7c478bd9Sstevel@tonic-gate mac_value = FALSE; 490*7c478bd9Sstevel@tonic-gate PUSH(DS, mac_value); 491*7c478bd9Sstevel@tonic-gate } 492*7c478bd9Sstevel@tonic-gate 493*7c478bd9Sstevel@tonic-gate /* 494*7c478bd9Sstevel@tonic-gate * Allow for programmatic over-ride of 'mac-address' 495*7c478bd9Sstevel@tonic-gate */ 496*7c478bd9Sstevel@tonic-gate #define MAC_ADDR_SIZE 6 497*7c478bd9Sstevel@tonic-gate static char *mac_addr; 498*7c478bd9Sstevel@tonic-gate static int mac_addr_is_valid; 499*7c478bd9Sstevel@tonic-gate 500*7c478bd9Sstevel@tonic-gate void 501*7c478bd9Sstevel@tonic-gate set_mac_address(char *macaddr) 502*7c478bd9Sstevel@tonic-gate { 503*7c478bd9Sstevel@tonic-gate mac_addr_is_valid = 1; 504*7c478bd9Sstevel@tonic-gate memcpy(mac_addr, macaddr, MAC_ADDR_SIZE); 505*7c478bd9Sstevel@tonic-gate } 506*7c478bd9Sstevel@tonic-gate 507*7c478bd9Sstevel@tonic-gate void 508*7c478bd9Sstevel@tonic-gate push_mac_address(fcode_env_t *env) 509*7c478bd9Sstevel@tonic-gate { 510*7c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)mac_addr); 511*7c478bd9Sstevel@tonic-gate PUSH(DS, MAC_ADDR_SIZE); 512*7c478bd9Sstevel@tonic-gate } 513*7c478bd9Sstevel@tonic-gate 514*7c478bd9Sstevel@tonic-gate /* 515*7c478bd9Sstevel@tonic-gate * Does driver call to get this. 516*7c478bd9Sstevel@tonic-gate */ 517*7c478bd9Sstevel@tonic-gate static void 518*7c478bd9Sstevel@tonic-gate local_ether_addr(fcode_env_t *env) 519*7c478bd9Sstevel@tonic-gate { 520*7c478bd9Sstevel@tonic-gate static fc_cell_t *mac_add; 521*7c478bd9Sstevel@tonic-gate int error; 522*7c478bd9Sstevel@tonic-gate 523*7c478bd9Sstevel@tonic-gate mac_add = MALLOC(sizeof (fc_cell_t) * 2); 524*7c478bd9Sstevel@tonic-gate error = fc_run_priv(env->private, "local-ether-addr", 0, 2, &mac_add[0], 525*7c478bd9Sstevel@tonic-gate &mac_add[1]); 526*7c478bd9Sstevel@tonic-gate if (error) { 527*7c478bd9Sstevel@tonic-gate bzero(mac_add, sizeof (mac_add)); 528*7c478bd9Sstevel@tonic-gate } 529*7c478bd9Sstevel@tonic-gate 530*7c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)&mac_add[0]); 531*7c478bd9Sstevel@tonic-gate PUSH(DS, 6); 532*7c478bd9Sstevel@tonic-gate } 533*7c478bd9Sstevel@tonic-gate 534*7c478bd9Sstevel@tonic-gate /* 535*7c478bd9Sstevel@tonic-gate * 'mac-address' - complicated by 'local-mac-address' stuff. 536*7c478bd9Sstevel@tonic-gate */ 537*7c478bd9Sstevel@tonic-gate static void 538*7c478bd9Sstevel@tonic-gate mac_address(fcode_env_t *env) 539*7c478bd9Sstevel@tonic-gate { 540*7c478bd9Sstevel@tonic-gate fstack_t d; 541*7c478bd9Sstevel@tonic-gate 542*7c478bd9Sstevel@tonic-gate if (mac_addr_is_valid) { 543*7c478bd9Sstevel@tonic-gate push_mac_address(env); 544*7c478bd9Sstevel@tonic-gate return; 545*7c478bd9Sstevel@tonic-gate } 546*7c478bd9Sstevel@tonic-gate 547*7c478bd9Sstevel@tonic-gate /* 548*7c478bd9Sstevel@tonic-gate * From here, we essentially re-implement OBP's 'mac-address' word. 549*7c478bd9Sstevel@tonic-gate * on some platforms, this may need to be re-implemented. 550*7c478bd9Sstevel@tonic-gate */ 551*7c478bd9Sstevel@tonic-gate local_mac_address(env); 552*7c478bd9Sstevel@tonic-gate d = POP(DS); 553*7c478bd9Sstevel@tonic-gate if (d) { 554*7c478bd9Sstevel@tonic-gate push_a_string(env, "local-mac-address"); 555*7c478bd9Sstevel@tonic-gate get_inherited_prop(env); 556*7c478bd9Sstevel@tonic-gate d = POP(DS); 557*7c478bd9Sstevel@tonic-gate if (d == FALSE && TOS == 6) 558*7c478bd9Sstevel@tonic-gate return; 559*7c478bd9Sstevel@tonic-gate two_drop(env); 560*7c478bd9Sstevel@tonic-gate } 561*7c478bd9Sstevel@tonic-gate local_ether_addr(env); 562*7c478bd9Sstevel@tonic-gate } 563*7c478bd9Sstevel@tonic-gate 564*7c478bd9Sstevel@tonic-gate /* 565*7c478bd9Sstevel@tonic-gate * Allow for the programmatic setting of diagnostic-mode? 566*7c478bd9Sstevel@tonic-gate */ 567*7c478bd9Sstevel@tonic-gate static int diag_mode_is_valid = 0; 568*7c478bd9Sstevel@tonic-gate static int diag_mode = 0; 569*7c478bd9Sstevel@tonic-gate 570*7c478bd9Sstevel@tonic-gate void 571*7c478bd9Sstevel@tonic-gate set_diagnostic_mode(fcode_env_t *env) 572*7c478bd9Sstevel@tonic-gate { 573*7c478bd9Sstevel@tonic-gate fstack_t d = POP(DS); 574*7c478bd9Sstevel@tonic-gate 575*7c478bd9Sstevel@tonic-gate diag_mode = d; 576*7c478bd9Sstevel@tonic-gate diag_mode_is_valid = 1; 577*7c478bd9Sstevel@tonic-gate } 578*7c478bd9Sstevel@tonic-gate 579*7c478bd9Sstevel@tonic-gate void 580*7c478bd9Sstevel@tonic-gate push_diagnostic_mode(fcode_env_t *env) 581*7c478bd9Sstevel@tonic-gate { 582*7c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)diag_mode); 583*7c478bd9Sstevel@tonic-gate } 584*7c478bd9Sstevel@tonic-gate 585*7c478bd9Sstevel@tonic-gate /* 586*7c478bd9Sstevel@tonic-gate * 'diagnostic-mode?' - diagnostic-mode? is equivalent to NVRAM 'diag-switch?' 587*7c478bd9Sstevel@tonic-gate */ 588*7c478bd9Sstevel@tonic-gate static void 589*7c478bd9Sstevel@tonic-gate diagnostic_mode(fcode_env_t *env) 590*7c478bd9Sstevel@tonic-gate { 591*7c478bd9Sstevel@tonic-gate char *diag_str; 592*7c478bd9Sstevel@tonic-gate int diag_value; 593*7c478bd9Sstevel@tonic-gate 594*7c478bd9Sstevel@tonic-gate if (!diag_mode_is_valid) { 595*7c478bd9Sstevel@tonic-gate diag_str = get_eeprom_value(env, "diag-switch?"); 596*7c478bd9Sstevel@tonic-gate if (diag_str != NULL && strcmp(diag_str, "false") == 0) 597*7c478bd9Sstevel@tonic-gate diag_value = FALSE; 598*7c478bd9Sstevel@tonic-gate else 599*7c478bd9Sstevel@tonic-gate diag_value = TRUE; 600*7c478bd9Sstevel@tonic-gate PUSH(DS, diag_value); 601*7c478bd9Sstevel@tonic-gate set_diagnostic_mode(env); 602*7c478bd9Sstevel@tonic-gate } 603*7c478bd9Sstevel@tonic-gate 604*7c478bd9Sstevel@tonic-gate push_diagnostic_mode(env); 605*7c478bd9Sstevel@tonic-gate } 606*7c478bd9Sstevel@tonic-gate 607*7c478bd9Sstevel@tonic-gate /* 608*7c478bd9Sstevel@tonic-gate * May need to implement other memory-access Fcodes here (depending upon 609*7c478bd9Sstevel@tonic-gate * abuse), like fill, comp, +!, etc., etc. 610*7c478bd9Sstevel@tonic-gate */ 611*7c478bd9Sstevel@tonic-gate 612*7c478bd9Sstevel@tonic-gate #pragma init(_init) 613*7c478bd9Sstevel@tonic-gate 614*7c478bd9Sstevel@tonic-gate static void 615*7c478bd9Sstevel@tonic-gate _init(void) 616*7c478bd9Sstevel@tonic-gate { 617*7c478bd9Sstevel@tonic-gate fcode_env_t *env = initial_env; 618*7c478bd9Sstevel@tonic-gate 619*7c478bd9Sstevel@tonic-gate mac_addr = MALLOC(MAC_ADDR_SIZE); 620*7c478bd9Sstevel@tonic-gate 621*7c478bd9Sstevel@tonic-gate ASSERT(env); 622*7c478bd9Sstevel@tonic-gate NOTICE; 623*7c478bd9Sstevel@tonic-gate 624*7c478bd9Sstevel@tonic-gate ANSI(0x06e, 0, "l@", fcd_lfetch); 625*7c478bd9Sstevel@tonic-gate ANSI(0x06f, 0, "w@", fcd_wfetch); 626*7c478bd9Sstevel@tonic-gate ANSI(0x071, 0, "c@", fcd_cfetch); 627*7c478bd9Sstevel@tonic-gate ANSI(0x073, 0, "l!", fcd_lstore); 628*7c478bd9Sstevel@tonic-gate ANSI(0x074, 0, "w!", fcd_wstore); 629*7c478bd9Sstevel@tonic-gate ANSI(0x075, 0, "c!", fcd_cstore); 630*7c478bd9Sstevel@tonic-gate ANSI(0x078, 0, "move", fcd_move); 631*7c478bd9Sstevel@tonic-gate ANSI(0x07a, 0, "comp", fcd_comp); 632*7c478bd9Sstevel@tonic-gate 633*7c478bd9Sstevel@tonic-gate ANSI(0x120, 0, "diagnostic-mode?", diagnostic_mode); 634*7c478bd9Sstevel@tonic-gate 635*7c478bd9Sstevel@tonic-gate ANSI(0x1a4, 0, "mac-address", mac_address); 636*7c478bd9Sstevel@tonic-gate 637*7c478bd9Sstevel@tonic-gate P1275(0x220, 0, "cpeek", cpeek); 638*7c478bd9Sstevel@tonic-gate P1275(0x221, 0, "wpeek", wpeek); 639*7c478bd9Sstevel@tonic-gate P1275(0x222, 0, "lpeek", lpeek); 640*7c478bd9Sstevel@tonic-gate P1275(0x223, 0, "cpoke", cpoke); 641*7c478bd9Sstevel@tonic-gate P1275(0x224, 0, "wpoke", wpoke); 642*7c478bd9Sstevel@tonic-gate P1275(0x225, 0, "lpoke", lpoke); 643*7c478bd9Sstevel@tonic-gate 644*7c478bd9Sstevel@tonic-gate P1275(0x230, 0, "rb@", rbfetch); 645*7c478bd9Sstevel@tonic-gate P1275(0x231, 0, "rb!", rbstore); 646*7c478bd9Sstevel@tonic-gate P1275(0x232, 0, "rw@", rwfetch); 647*7c478bd9Sstevel@tonic-gate P1275(0x233, 0, "rw!", rwstore); 648*7c478bd9Sstevel@tonic-gate P1275(0x234, 0, "rl@", rlfetch); 649*7c478bd9Sstevel@tonic-gate P1275(0x235, 0, "rl!", rlstore); 650*7c478bd9Sstevel@tonic-gate 651*7c478bd9Sstevel@tonic-gate P1275(0x246, 0, "x@", fcd_xfetch); 652*7c478bd9Sstevel@tonic-gate P1275(0x247, 0, "x!", fcd_xstore); 653*7c478bd9Sstevel@tonic-gate 654*7c478bd9Sstevel@tonic-gate P1275(0x22e, 0, "rx@", rxfetch); 655*7c478bd9Sstevel@tonic-gate P1275(0x22f, 0, "rx!", rxstore); 656*7c478bd9Sstevel@tonic-gate FORTH(0, "set-diagnostic-mode", set_diagnostic_mode); 657*7c478bd9Sstevel@tonic-gate FORTH(0, "local-mac-address?", local_mac_address); 658*7c478bd9Sstevel@tonic-gate FORTH(0, "local-ether-addr", local_ether_addr); 659*7c478bd9Sstevel@tonic-gate } 660