17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5fea9cb91Slq150181 * Common Development and Distribution License (the "License"). 6fea9cb91Slq150181 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21fea9cb91Slq150181 227c478bd9Sstevel@tonic-gate /* 232d7b546fSlq150181 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24fa9e4066Sahrens * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/promif.h> 307c478bd9Sstevel@tonic-gate #include <sys/promimpl.h> 317c478bd9Sstevel@tonic-gate 322d7b546fSlq150181 /* 332d7b546fSlq150181 * Because kmdb links prom_stdout_is_framebuffer into its own 342d7b546fSlq150181 * module and coherent console adds "device-type=console" for 352d7b546fSlq150181 * /os-io node, we also check if the device-type is "console", 362d7b546fSlq150181 * (if not "display"), so that prom_stdout_is_framebuffer still 372d7b546fSlq150181 * works corrrectly after /os-io node is registered into OBP. 382d7b546fSlq150181 */ 397c478bd9Sstevel@tonic-gate int 407c478bd9Sstevel@tonic-gate prom_stdout_is_framebuffer(void) 417c478bd9Sstevel@tonic-gate { 427c478bd9Sstevel@tonic-gate static int remember = -1; 437c478bd9Sstevel@tonic-gate 442d7b546fSlq150181 if (remember != -1) 452d7b546fSlq150181 return (remember); 462d7b546fSlq150181 47fa9e4066Sahrens remember = prom_devicetype((pnode_t)prom_stdout_node(), 487c478bd9Sstevel@tonic-gate OBP_DISPLAY); 492d7b546fSlq150181 502d7b546fSlq150181 if (remember == 0) 512d7b546fSlq150181 remember = prom_devicetype((pnode_t)prom_stdout_node(), 522d7b546fSlq150181 OBP_DISPLAY_CONSOLE); 532d7b546fSlq150181 547c478bd9Sstevel@tonic-gate return (remember); 557c478bd9Sstevel@tonic-gate } 56fea9cb91Slq150181 57fea9cb91Slq150181 /* 58*c9503a49Slq150181 * get inverse? and inverse-screen? property, 59*c9503a49Slq150181 * -1 is returned if true, 0 is returned if false. 60*c9503a49Slq150181 */ 61*c9503a49Slq150181 void 62*c9503a49Slq150181 prom_get_tem_inverses(int *inverse, int *inverse_screen) 63*c9503a49Slq150181 { 64*c9503a49Slq150181 prom_interpret( 65*c9503a49Slq150181 "my-self >r stdout @ is my-self " 66*c9503a49Slq150181 "inverse? swap l! inverse-screen? swap l! " 67*c9503a49Slq150181 "r> is my-self", 68*c9503a49Slq150181 (uintptr_t)inverse, (uintptr_t)inverse_screen, 0, 0, 0); 69*c9503a49Slq150181 } 70*c9503a49Slq150181 71*c9503a49Slq150181 /* 72fea9cb91Slq150181 * get current cursor position from the stdout handle, which 73fea9cb91Slq150181 * containing the instance handle of the OBP console output device. 74fea9cb91Slq150181 */ 75fea9cb91Slq150181 void 76fea9cb91Slq150181 prom_get_tem_pos(uint32_t *row, uint32_t *col) 77fea9cb91Slq150181 { 78fea9cb91Slq150181 prom_interpret( 79fea9cb91Slq150181 "my-self >r stdout @ is my-self " 80fea9cb91Slq150181 "line# swap l! column# swap l! " 81fea9cb91Slq150181 "r> is my-self", 82fea9cb91Slq150181 (uintptr_t)row, (uintptr_t)col, 0, 0, 0); 83fea9cb91Slq150181 } 84fea9cb91Slq150181 85fea9cb91Slq150181 86fea9cb91Slq150181 /* 87fea9cb91Slq150181 * get the font size and the start window top of 88fea9cb91Slq150181 * OBP terminal emulator 89fea9cb91Slq150181 */ 90fea9cb91Slq150181 void 91fea9cb91Slq150181 prom_get_term_font_size(int *charheight, int *window_top) 92fea9cb91Slq150181 { 93fea9cb91Slq150181 prom_interpret( 94fea9cb91Slq150181 "my-self >r stdout @ is my-self " 95fea9cb91Slq150181 "char-height swap l! window-top swap l! " 96fea9cb91Slq150181 "r> is my-self", 97fea9cb91Slq150181 (uintptr_t)charheight, (uintptr_t)window_top, 0, 0, 0); 98fea9cb91Slq150181 99fea9cb91Slq150181 } 100fea9cb91Slq150181 101fea9cb91Slq150181 /* Clear the spining "|" character and hide the PROM cursor. */ 102fea9cb91Slq150181 void 103fea9cb91Slq150181 prom_hide_cursor(void) 104fea9cb91Slq150181 { 105fea9cb91Slq150181 prom_interpret( 106fea9cb91Slq150181 "my-self >r stdout @ is my-self " 107fea9cb91Slq150181 "toggle-cursor " 108fea9cb91Slq150181 "1 delete-characters " 109fea9cb91Slq150181 "r> is my-self", 110fea9cb91Slq150181 0, 0, 0, 0, 0); 111fea9cb91Slq150181 } 112fea9cb91Slq150181 113fea9cb91Slq150181 static size_t 114fea9cb91Slq150181 prom_atol(const char *str, int len) 115fea9cb91Slq150181 { 116fea9cb91Slq150181 size_t n = 0; 117fea9cb91Slq150181 118fea9cb91Slq150181 while (len-- && (*str != '\0')) { 119fea9cb91Slq150181 n = n * 10 + (*str - '0'); 120fea9cb91Slq150181 str++; 121fea9cb91Slq150181 } 122fea9cb91Slq150181 123fea9cb91Slq150181 return (n); 124fea9cb91Slq150181 } 125fea9cb91Slq150181 126fea9cb91Slq150181 /* 127fea9cb91Slq150181 * Here we use the "screen-#columns" and "screen-#rows" settings of 128fea9cb91Slq150181 * PROM to help us decide the console size and cursor position. The 129fea9cb91Slq150181 * actual sizes of PROM's TEM and the console might be different with 130fea9cb91Slq150181 * those "screen-#.." settings, in cases that they are too big to 131fea9cb91Slq150181 * accommodate. 132fea9cb91Slq150181 */ 133fea9cb91Slq150181 void 134fea9cb91Slq150181 prom_get_tem_size(size_t *height, size_t *width) 135fea9cb91Slq150181 { 136fea9cb91Slq150181 char buf[MAXPATHLEN]; 137fea9cb91Slq150181 char name[16]; 138fea9cb91Slq150181 pnode_t node; 139fea9cb91Slq150181 int len; 140fea9cb91Slq150181 141fea9cb91Slq150181 if ((node = prom_optionsnode()) == OBP_BADNODE) 142fea9cb91Slq150181 return; 143fea9cb91Slq150181 144fea9cb91Slq150181 (void) prom_strcpy(name, "screen-#rows"); 145fea9cb91Slq150181 if ((len = prom_getproplen(node, (caddr_t)name)) > 0) { 146fea9cb91Slq150181 (void) prom_getprop(node, (caddr_t)name, (caddr_t)buf); 147fea9cb91Slq150181 *height = prom_atol(buf, len); 148fea9cb91Slq150181 } 149fea9cb91Slq150181 150fea9cb91Slq150181 (void) prom_strcpy(name, "screen-#columns"); 151fea9cb91Slq150181 if ((len = prom_getproplen(node, (caddr_t)name)) > 0) { 152fea9cb91Slq150181 (void) prom_getprop(node, (caddr_t)name, (caddr_t)buf); 153fea9cb91Slq150181 *width = prom_atol(buf, len); 154fea9cb91Slq150181 } 155fea9cb91Slq150181 } 156