Subversion Repositories HelenOS

Compare Revisions

No changes between revisions

Ignore whitespace Rev 4580 → Rev 4581

/branches/network/uspace/srv/console/nameic.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/anim_4.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/anim_3.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/anim_2.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/anim_1.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/helenos.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/cons_selected.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/cons_idle.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/cons_kernel.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/cons_has_data.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Deleted: svn:mime-type
-application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/gcons.h
27,25 → 27,30
*/
 
/** @addtogroup console
* @{
* @{
*/
/** @file
*/
 
#ifndef _GCONS_H_
#define _GCONS_H_
#ifndef GCONS_H_
#define GCONS_H_
 
#include <sys/types.h>
 
void gcons_init(int phone);
 
void gcons_redraw_console(void);
void gcons_change_console(int consnum);
void gcons_notify_char(int consnum);
void gcons_change_console(size_t index);
void gcons_notify_char(size_t index);
void gcons_in_kernel(void);
void gcons_notify_connect(int consnum);
void gcons_notify_disconnect(int consnum);
void gcons_mouse_move(int dx, int dy);
int gcons_mouse_btn(int state);
 
void gcons_notify_connect(size_t index);
void gcons_notify_disconnect(size_t index);
 
void gcons_mouse_move(ssize_t dx, ssize_t dy);
int gcons_mouse_btn(bool state);
 
#endif
 
/** @}
*/
/branches/network/uspace/srv/console/screenbuffer.h
27,19 → 27,20
*/
 
/** @addtogroup console
* @{
* @{
*/
/** @file
*/
 
#ifndef __SCREENBUFFER_H__
#define __SCREENBUFFER_H__
#ifndef SCREENBUFFER_H__
#define SCREENBUFFER_H__
 
#include <stdint.h>
#include <sys/types.h>
#include <bool.h>
 
#define DEFAULT_FOREGROUND 0x0 /**< default console foreground color */
#define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */
#define DEFAULT_FOREGROUND 0x0 /**< default console foreground color */
#define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */
 
typedef struct {
uint8_t style;
52,8 → 53,8
} attr_idx_t;
 
typedef struct {
uint32_t bg_color; /**< background color */
uint32_t fg_color; /**< foreground color */
uint32_t bg_color; /**< background color */
uint32_t fg_color; /**< foreground color */
} attr_rgb_t;
 
typedef struct {
66,73 → 67,91
attr_style_t s;
attr_idx_t i;
attr_rgb_t r;
} a;
} a;
} attrs_t;
 
/** One field on screen. It contain one character and its attributes. */
typedef struct {
wchar_t character; /**< Character itself */
attrs_t attrs; /**< Character`s attributes */
wchar_t character; /**< Character itself */
attrs_t attrs; /**< Character attributes */
} keyfield_t;
 
/** Structure for buffering state of one virtual console.
*/
typedef struct {
keyfield_t *buffer; /**< Screen content - characters and their attributes. Used as a circular buffer. */
unsigned int size_x, size_y; /**< Number of columns and rows */
unsigned int position_x, position_y; /**< Coordinates of last printed character for determining cursor position */
attrs_t attrs; /**< Current attributes. */
unsigned int top_line; /**< Points to buffer[][] line that will be printed at screen as the first line */
unsigned char is_cursor_visible; /**< Cursor state - default is visible */
keyfield_t *buffer; /**< Screen content - characters and
their attributes (used as a circular buffer) */
size_t size_x; /**< Number of columns */
size_t size_y; /**< Number of rows */
/** Coordinates of last printed character for determining cursor position */
size_t position_x;
size_t position_y;
attrs_t attrs; /**< Current attributes. */
size_t top_line; /**< Points to buffer[][] line that will
be printed at screen as the first line */
bool is_cursor_visible; /**< Cursor state - default is visible */
} screenbuffer_t;
 
/** Returns keyfield for position on screen. Screenbuffer->buffer is cyclic buffer so we must couted in index of the topmost line.
* @param scr screenbuffer
* @param x position on screen
* @param y position on screen
* @return keyfield structure with character and its attributes on x,y
/** Returns keyfield for position on screen
*
* Screenbuffer->buffer is cyclic buffer so we
* must couted in index of the topmost line.
*
* @param scr Screenbuffer
* @param x Position on screen
* @param y Position on screen
*
* @return Keyfield structure with character and its attributes on x, y
*
*/
static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y)
static inline keyfield_t *get_field_at(screenbuffer_t *scr, size_t x, size_t y)
{
return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x;
}
 
/** Compares two sets of attributes.
* @param s1 first style
* @param s2 second style
* @return nonzero on equality
*
* @param s1 First style
* @param s2 Second style
*
* @return Nonzero on equality
*
*/
static inline int attrs_same(attrs_t a1, attrs_t a2)
{
if (a1.t != a2.t) return 0;
 
if (a1.t != a2.t)
return 0;
switch (a1.t) {
case at_style: return a1.a.s.style == a2.a.s.style;
case at_idx: return a1.a.i.fg_color == a2.a.i.fg_color &&
a1.a.i.bg_color == a2.a.i.bg_color &&
a1.a.i.flags == a2.a.i.flags;
case at_rgb: return a1.a.r.fg_color == a2.a.r.fg_color &&
a1.a.r.bg_color == a2.a.r.bg_color;
case at_style:
return (a1.a.s.style == a2.a.s.style);
case at_idx:
return (a1.a.i.fg_color == a2.a.i.fg_color)
&& (a1.a.i.bg_color == a2.a.i.bg_color)
&& (a1.a.i.flags == a2.a.i.flags);
case at_rgb:
return (a1.a.r.fg_color == a2.a.r.fg_color)
&& (a1.a.r.bg_color == a2.a.r.bg_color);
}
}
 
 
void screenbuffer_putchar(screenbuffer_t *scr, wchar_t c);
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y);
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y);
 
void screenbuffer_clear(screenbuffer_t *scr);
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line);
void screenbuffer_clear_line(screenbuffer_t *scr, size_t line);
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest);
void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y);
void screenbuffer_set_style(screenbuffer_t *scr, int style);
void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color,
unsigned int bg_color, unsigned int attr);
void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color,
unsigned int bg_color);
void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y);
void screenbuffer_set_style(screenbuffer_t *scr, uint8_t style);
void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color,
uint8_t bg_color, uint8_t attr);
void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color,
uint32_t bg_color);
 
#endif
 
/** @}
*/
 
/branches/network/uspace/srv/console/console.c
27,7 → 27,7
*/
 
/** @addtogroup console
* @{
* @{
*/
/** @file
*/
36,96 → 36,71
#include <fb.h>
#include <ipc/ipc.h>
#include <kbd.h>
#include <kbd/keycode.h>
#include <io/keycode.h>
#include <ipc/fb.h>
#include <ipc/services.h>
#include <errno.h>
#include <key_buffer.h>
#include <keybuffer.h>
#include <ipc/console.h>
#include <unistd.h>
#include <async.h>
#include <libadt/fifo.h>
#include <screenbuffer.h>
#include <adt/fifo.h>
#include <sys/mman.h>
#include <stdio.h>
#include <string.h>
#include <sysinfo.h>
#include <event.h>
#include <devmap.h>
#include <fibril_sync.h>
 
#include "console.h"
#include "gcons.h"
#include "screenbuffer.h"
 
#define MAX_KEYREQUESTS_BUFFERED 32
#define NAME "console"
 
#define NAME "console"
#define MAX_DEVICE_NAME 32
 
/** Index of currently used virtual console.
*/
int active_console = 0;
int prev_console = 0;
/** Phone to the keyboard driver. */
static int kbd_phone;
 
/** Information about framebuffer */
struct {
int phone; /**< Framebuffer phone */
ipcarg_t rows; /**< Framebuffer rows */
ipcarg_t cols; /**< Framebuffer columns */
int phone; /**< Framebuffer phone */
ipcarg_t cols; /**< Framebuffer columns */
ipcarg_t rows; /**< Framebuffer rows */
} fb_info;
 
typedef struct {
keybuffer_t keybuffer; /**< Buffer for incoming keys. */
/** Buffer for unsatisfied request for keys. */
FIFO_CREATE_STATIC(keyrequests, ipc_callid_t,
MAX_KEYREQUESTS_BUFFERED);
int keyrequest_counter; /**< Number of requests in buffer. */
int client_phone; /**< Phone to connected client. */
int used; /**< 1 if this virtual console is
* connected to some client.*/
screenbuffer_t screenbuffer; /**< Screenbuffer for saving screen
* contents and related settings. */
} connection_t;
size_t index; /**< Console index */
size_t refcount; /**< Connection reference count */
dev_handle_t dev_handle; /**< Device handle */
keybuffer_t keybuffer; /**< Buffer for incoming keys. */
screenbuffer_t scr; /**< Screenbuffer for saving screen
contents and related settings. */
} console_t;
 
static connection_t connections[CONSOLE_COUNT]; /**< Array of data for virtual
* consoles */
static keyfield_t *interbuffer = NULL; /**< Pointer to memory shared
* with framebufer used for
* faster virtual console
* switching */
/** Array of data for virtual consoles */
static console_t consoles[CONSOLE_COUNT];
 
static console_t *active_console = &consoles[0];
static console_t *prev_console = &consoles[0];
static console_t *kernel_console = &consoles[KERNEL_CONSOLE];
 
/** Pointer to memory shared with framebufer used for
faster virtual console switching */
static keyfield_t *interbuffer = NULL;
 
/** Information on row-span yet unsent to FB driver. */
struct {
int row; /**< Row where the span lies. */
int col; /**< Leftmost column of the span. */
int n; /**< Width of the span. */
size_t col; /**< Leftmost column of the span. */
size_t row; /**< Row where the span lies. */
size_t cnt; /**< Width of the span. */
} fb_pending;
 
/** Size of cwrite_buf. */
#define CWRITE_BUF_SIZE 256
static FIBRIL_MUTEX_INITIALIZE(input_mutex);
static FIBRIL_CONDVAR_INITIALIZE(input_cv);
 
/** Buffer for receiving data via the CONSOLE_WRITE call from the client. */
static char cwrite_buf[CWRITE_BUF_SIZE];
 
static void fb_putchar(wchar_t c, int row, int col);
 
 
/** Find unused virtual console.
*
*/
static int find_free_connection(void)
{
int i;
for (i = 0; i < CONSOLE_COUNT; i++) {
if (!connections[i].used)
return i;
}
return -1;
}
 
static void clrscr(void)
{
async_msg_0(fb_info.phone, FB_CLEAR);
}
 
static void curs_visibility(bool visible)
{
async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible);
136,11 → 111,16
ipc_call_sync_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);
}
 
static void curs_goto(int row, int col)
static void curs_goto(size_t x, size_t y)
{
async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col);
async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);
}
 
static void screen_clear(void)
{
async_msg_0(fb_info.phone, FB_CLEAR);
}
 
static void screen_yield(void)
{
ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_YIELD);
151,9 → 131,19
ipc_call_sync_0_0(fb_info.phone, FB_SCREEN_RECLAIM);
}
 
static void kbd_yield(void)
{
ipc_call_sync_0_0(kbd_phone, KBD_YIELD);
}
 
static void kbd_reclaim(void)
{
ipc_call_sync_0_0(kbd_phone, KBD_RECLAIM);
}
 
static void set_style(int style)
{
async_msg_1(fb_info.phone, FB_SET_STYLE, style);
async_msg_1(fb_info.phone, FB_SET_STYLE, style);
}
 
static void set_color(int fgcolor, int bgcolor, int flags)
172,12 → 162,10
case at_style:
set_style(attrs->a.s.style);
break;
 
case at_idx:
set_color(attrs->a.i.fg_color, attrs->a.i.bg_color,
attrs->a.i.flags);
break;
 
case at_rgb:
set_rgb_color(attrs->a.r.fg_color, attrs->a.r.bg_color);
break;
185,57 → 173,31
}
 
/** Send an area of screenbuffer to the FB driver. */
static void fb_update_area(connection_t *conn, int x, int y, int w, int h)
static void fb_update_area(console_t *cons, ipcarg_t x0, ipcarg_t y0, ipcarg_t width, ipcarg_t height)
{
int i, j;
int rc;
attrs_t *attrs;
keyfield_t *field;
 
if (interbuffer) {
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
interbuffer[i + j * w] =
*get_field_at(&conn->screenbuffer,
x + i, y + j);
ipcarg_t x;
ipcarg_t y;
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
interbuffer[y * width + x] =
*get_field_at(&cons->scr, x0 + x, y0 + y);
}
}
 
rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
x, y, w, h);
} else {
rc = ENOTSUP;
async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
x0, y0, width, height);
}
 
if (rc != 0) {
/*
attrs = &conn->screenbuffer.attrs;
 
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
field = get_field_at(&conn->screenbuffer,
x + i, y + j);
if (!attrs_same(*attrs, field->attrs))
set_attrs(&field->attrs);
attrs = &field->attrs;
 
fb_putchar(field->character, y + j, x + i);
}
}*/
}
}
 
/** Flush pending cells to FB. */
static void fb_pending_flush(void)
{
screenbuffer_t *scr;
 
scr = &(connections[active_console].screenbuffer);
 
if (fb_pending.n > 0) {
fb_update_area(&connections[active_console], fb_pending.col,
fb_pending.row, fb_pending.n, 1);
fb_pending.n = 0;
if (fb_pending.cnt > 0) {
fb_update_area(active_console, fb_pending.col,
fb_pending.row, fb_pending.cnt, 1);
fb_pending.cnt = 0;
}
}
 
243,167 → 205,162
*
* This adds the cell to the pending rowspan if possible. Otherwise
* the old span is flushed first.
*
*/
static void cell_mark_changed(int row, int col)
static void cell_mark_changed(size_t col, size_t row)
{
if (fb_pending.n != 0) {
if (row != fb_pending.row ||
col != fb_pending.col + fb_pending.n) {
if (fb_pending.cnt != 0) {
if ((col != fb_pending.col + fb_pending.cnt)
|| (row != fb_pending.row)) {
fb_pending_flush();
}
}
 
if (fb_pending.n == 0) {
if (fb_pending.cnt == 0) {
fb_pending.col = col;
fb_pending.row = row;
fb_pending.col = col;
}
 
++fb_pending.n;
fb_pending.cnt++;
}
 
 
/** Print a character to the active VC with buffering. */
static void fb_putchar(wchar_t c, int row, int col)
static void fb_putchar(wchar_t c, ipcarg_t col, ipcarg_t row)
{
async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col);
async_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row);
}
 
/** Process a character from the client (TTY emulation). */
static void write_char(int console, wchar_t ch)
static void write_char(console_t *cons, wchar_t ch)
{
bool flush_cursor = false;
screenbuffer_t *scr = &(connections[console].screenbuffer);
 
switch (ch) {
case '\n':
fb_pending_flush();
flush_cursor = true;
scr->position_y++;
scr->position_x = 0;
cons->scr.position_y++;
cons->scr.position_x = 0;
break;
case '\r':
break;
case '\t':
scr->position_x += 8;
scr->position_x -= scr->position_x % 8;
cons->scr.position_x += 8;
cons->scr.position_x -= cons->scr.position_x % 8;
break;
case '\b':
if (scr->position_x == 0)
if (cons->scr.position_x == 0)
break;
scr->position_x--;
if (console == active_console)
cell_mark_changed(scr->position_y, scr->position_x);
screenbuffer_putchar(scr, ' ');
cons->scr.position_x--;
if (cons == active_console)
cell_mark_changed(cons->scr.position_x, cons->scr.position_y);
screenbuffer_putchar(&cons->scr, ' ');
break;
default:
if (console == active_console)
cell_mark_changed(scr->position_y, scr->position_x);
 
screenbuffer_putchar(scr, ch);
scr->position_x++;
default:
if (cons == active_console)
cell_mark_changed(cons->scr.position_x, cons->scr.position_y);
screenbuffer_putchar(&cons->scr, ch);
cons->scr.position_x++;
}
 
if (scr->position_x >= scr->size_x) {
if (cons->scr.position_x >= cons->scr.size_x) {
flush_cursor = true;
scr->position_y++;
cons->scr.position_y++;
}
if (scr->position_y >= scr->size_y) {
if (cons->scr.position_y >= cons->scr.size_y) {
fb_pending_flush();
scr->position_y = scr->size_y - 1;
screenbuffer_clear_line(scr, scr->top_line);
scr->top_line = (scr->top_line + 1) % scr->size_y;
if (console == active_console)
cons->scr.position_y = cons->scr.size_y - 1;
screenbuffer_clear_line(&cons->scr, cons->scr.top_line);
cons->scr.top_line = (cons->scr.top_line + 1) % cons->scr.size_y;
if (cons == active_console)
async_msg_1(fb_info.phone, FB_SCROLL, 1);
}
 
scr->position_x = scr->position_x % scr->size_x;
 
if (console == active_console && flush_cursor)
curs_goto(scr->position_y, scr->position_x);
if (cons == active_console && flush_cursor)
curs_goto(cons->scr.position_x, cons->scr.position_y);
cons->scr.position_x = cons->scr.position_x % cons->scr.size_x;
}
 
/** Switch to new console */
static void change_console(int newcons)
static void change_console(console_t *cons)
{
connection_t *conn;
int i, j, rc;
keyfield_t *field;
attrs_t *attrs;
if (cons == active_console)
return;
if (newcons == active_console)
return;
 
fb_pending_flush();
 
if (newcons == KERNEL_CONSOLE) {
if (cons == kernel_console) {
async_serialize_start();
curs_hide_sync();
gcons_in_kernel();
screen_yield();
kbd_yield();
async_serialize_end();
 
if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
prev_console = active_console;
active_console = KERNEL_CONSOLE;
active_console = kernel_console;
} else
newcons = active_console;
cons = active_console;
}
if (newcons != KERNEL_CONSOLE) {
if (cons != kernel_console) {
size_t x;
size_t y;
int rc = 0;
async_serialize_start();
if (active_console == KERNEL_CONSOLE) {
if (active_console == kernel_console) {
screen_reclaim();
kbd_reclaim();
gcons_redraw_console();
}
active_console = newcons;
gcons_change_console(newcons);
conn = &connections[active_console];
active_console = cons;
gcons_change_console(cons->index);
set_attrs(&conn->screenbuffer.attrs);
set_attrs(&cons->scr.attrs);
curs_visibility(false);
if (interbuffer) {
for (j = 0; j < conn->screenbuffer.size_y; j++) {
for (i = 0; i < conn->screenbuffer.size_x; i++) {
unsigned int size_x;
size_x = conn->screenbuffer.size_x;
interbuffer[j * size_x + i] =
*get_field_at(&conn->screenbuffer, i, j);
for (y = 0; y < cons->scr.size_y; y++) {
for (x = 0; x < cons->scr.size_x; x++) {
interbuffer[y * cons->scr.size_x + x] =
*get_field_at(&cons->scr, x, y);
}
}
/* This call can preempt, but we are already at the end */
rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
0, 0, conn->screenbuffer.size_x,
conn->screenbuffer.size_y);
0, 0, cons->scr.size_x,
cons->scr.size_y);
}
if ((!interbuffer) || (rc != 0)) {
set_attrs(&conn->screenbuffer.attrs);
clrscr();
attrs = &conn->screenbuffer.attrs;
set_attrs(&cons->scr.attrs);
screen_clear();
for (j = 0; j < conn->screenbuffer.size_y; j++)
for (i = 0; i < conn->screenbuffer.size_x; i++) {
field = get_field_at(&conn->screenbuffer, i, j);
if (!attrs_same(*attrs, field->attrs))
for (y = 0; y < cons->scr.size_y; y++)
for (x = 0; x < cons->scr.size_x; x++) {
keyfield_t *field = get_field_at(&cons->scr, x, y);
if (!attrs_same(cons->scr.attrs, field->attrs))
set_attrs(&field->attrs);
attrs = &field->attrs;
cons->scr.attrs = field->attrs;
if ((field->character == ' ') &&
(attrs_same(field->attrs,
conn->screenbuffer.attrs)))
(attrs_same(field->attrs, cons->scr.attrs)))
continue;
 
fb_putchar(field->character, j, i);
fb_putchar(field->character, x, y);
}
}
curs_goto(conn->screenbuffer.position_y,
conn->screenbuffer.position_x);
curs_visibility(conn->screenbuffer.is_cursor_visible);
curs_goto(cons->scr.position_x, cons->scr.position_y);
curs_visibility(cons->scr.is_cursor_visible);
async_serialize_end();
}
412,31 → 369,19
/** Handler for keyboard */
static void keyboard_events(ipc_callid_t iid, ipc_call_t *icall)
{
ipc_callid_t callid;
ipc_call_t call;
int retval;
kbd_event_t ev;
connection_t *conn;
int newcon;
/* Ignore parameters, the connection is alread opened */
while (1) {
callid = async_get_call(&call);
/* Ignore parameters, the connection is already opened */
while (true) {
ipc_call_t call;
ipc_callid_t callid = async_get_call(&call);
int retval;
console_event_t ev;
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
/* TODO: Handle hangup */
return;
case KBD_MS_LEFT:
newcon = gcons_mouse_btn(IPC_GET_ARG1(call));
if (newcon != -1)
change_console(newcon);
retval = 0;
break;
case KBD_MS_MOVE:
gcons_mouse_move(IPC_GET_ARG1(call),
IPC_GET_ARG2(call));
retval = 0;
break;
case KBD_EVENT:
/* Got event from keyboard driver. */
retval = 0;
445,30 → 390,19
ev.mods = IPC_GET_ARG3(call);
ev.c = IPC_GET_ARG4(call);
/* switch to another virtual console */
conn = &connections[active_console];
 
if ((ev.key >= KC_F1) && (ev.key < KC_F1 +
CONSOLE_COUNT) && ((ev.mods & KM_CTRL) == 0)) {
if (ev.key == KC_F12)
change_console(KERNEL_CONSOLE);
if (ev.key == KC_F1 + KERNEL_CONSOLE)
change_console(kernel_console);
else
change_console(ev.key - KC_F1);
change_console(&consoles[ev.key - KC_F1]);
break;
}
/* if client is awaiting key, send it */
if (conn->keyrequest_counter > 0) {
conn->keyrequest_counter--;
ipc_answer_4(fifo_pop(conn->keyrequests), EOK,
ev.type, ev.key, ev.mods, ev.c);
break;
}
 
keybuffer_push(&conn->keybuffer, &ev);
retval = 0;
 
fibril_mutex_lock(&input_mutex);
keybuffer_push(&active_console->keybuffer, &ev);
fibril_condvar_broadcast(&input_cv);
fibril_mutex_unlock(&input_mutex);
break;
default:
retval = ENOENT;
477,62 → 411,132
}
}
 
/** Handle CONSOLE_WRITE call. */
static void cons_write(int consnum, ipc_callid_t rid, ipc_call_t *request)
static void cons_write(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
{
ipc_callid_t callid;
size_t size;
wchar_t ch;
size_t off;
 
if (!ipc_data_write_receive(&callid, &size)) {
ipc_answer_0(callid, EINVAL);
ipc_answer_0(rid, EINVAL);
return;
}
char *buf = (char *) malloc(size);
if (buf == NULL) {
ipc_answer_0(callid, ENOMEM);
ipc_answer_0(rid, ENOMEM);
return;
}
(void) ipc_data_write_finalize(callid, buf, size);
async_serialize_start();
size_t off = 0;
while (off < size) {
wchar_t ch = str_decode(buf, &off, size);
write_char(cons, ch);
}
async_serialize_end();
gcons_notify_char(cons->index);
ipc_answer_1(rid, EOK, size);
free(buf);
}
 
if (size > CWRITE_BUF_SIZE)
size = CWRITE_BUF_SIZE;
static void cons_read(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
{
ipc_callid_t callid;
size_t size;
if (!ipc_data_read_receive(&callid, &size)) {
ipc_answer_0(callid, EINVAL);
ipc_answer_0(rid, EINVAL);
return;
}
char *buf = (char *) malloc(size);
if (buf == NULL) {
ipc_answer_0(callid, ENOMEM);
ipc_answer_0(rid, ENOMEM);
return;
}
size_t pos = 0;
console_event_t ev;
fibril_mutex_lock(&input_mutex);
recheck:
while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) {
if (ev.type == KEY_PRESS) {
buf[pos] = ev.c;
pos++;
}
}
if (pos == size) {
(void) ipc_data_read_finalize(callid, buf, size);
ipc_answer_1(rid, EOK, size);
free(buf);
} else {
fibril_condvar_wait(&input_cv, &input_mutex);
goto recheck;
}
fibril_mutex_unlock(&input_mutex);
}
 
(void) ipc_data_write_finalize(callid, cwrite_buf, size);
static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
{
console_event_t ev;
 
off = 0;
while (off < size) {
ch = str_decode(cwrite_buf, &off, size);
write_char(consnum, ch);
fibril_mutex_lock(&input_mutex);
recheck:
if (keybuffer_pop(&cons->keybuffer, &ev)) {
ipc_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c);
} else {
fibril_condvar_wait(&input_cv, &input_mutex);
goto recheck;
}
 
gcons_notify_char(consnum);
ipc_answer_1(rid, EOK, size);
fibril_mutex_unlock(&input_mutex);
}
 
/** Default thread for new connections */
static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
{
ipc_callid_t callid;
ipc_call_t call;
int consnum;
ipcarg_t arg1, arg2, arg3, arg4;
connection_t *conn;
screenbuffer_t *scr;
console_t *cons = NULL;
if ((consnum = find_free_connection()) == -1) {
ipc_answer_0(iid, ELIMIT);
size_t i;
for (i = 0; i < CONSOLE_COUNT; i++) {
if (i == KERNEL_CONSOLE)
continue;
if (consoles[i].dev_handle == (dev_handle_t) IPC_GET_ARG1(*icall)) {
cons = &consoles[i];
break;
}
}
if (cons == NULL) {
ipc_answer_0(iid, ENOENT);
return;
}
conn = &connections[consnum];
conn->used = 1;
ipc_callid_t callid;
ipc_call_t call;
ipcarg_t arg1;
ipcarg_t arg2;
ipcarg_t arg3;
async_serialize_start();
gcons_notify_connect(consnum);
conn->client_phone = IPC_GET_ARG5(*icall);
screenbuffer_clear(&conn->screenbuffer);
if (consnum == active_console)
clrscr();
if (cons->refcount == 0)
gcons_notify_connect(cons->index);
cons->refcount++;
/* Accept the connection */
ipc_answer_0(iid, EOK);
while (1) {
while (true) {
async_serialize_end();
callid = async_get_call(&call);
async_serialize_start();
540,62 → 544,55
arg1 = 0;
arg2 = 0;
arg3 = 0;
arg4 = 0;
 
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
gcons_notify_disconnect(consnum);
/* Answer all pending requests */
while (conn->keyrequest_counter > 0) {
conn->keyrequest_counter--;
ipc_answer_0(fifo_pop(conn->keyrequests),
ENOENT);
break;
cons->refcount--;
if (cons->refcount == 0)
gcons_notify_disconnect(cons->index);
return;
case VFS_READ:
async_serialize_end();
cons_read(cons, callid, &call);
async_serialize_start();
continue;
case VFS_WRITE:
async_serialize_end();
cons_write(cons, callid, &call);
async_serialize_start();
continue;
case VFS_SYNC:
fb_pending_flush();
if (cons == active_console) {
async_req_0_0(fb_info.phone, FB_FLUSH);
curs_goto(cons->scr.position_x, cons->scr.position_y);
}
conn->used = 0;
return;
case CONSOLE_PUTCHAR:
write_char(consnum, IPC_GET_ARG1(call));
gcons_notify_char(consnum);
break;
case CONSOLE_WRITE:
cons_write(consnum, callid, &call);
continue;
case CONSOLE_CLEAR:
/* Send message to fb */
if (consnum == active_console) {
async_msg_0(fb_info.phone, FB_CLEAR);
}
if (cons == active_console)
async_msg_0(fb_info.phone, FB_CLEAR);
screenbuffer_clear(&conn->screenbuffer);
screenbuffer_clear(&cons->scr);
break;
case CONSOLE_GOTO:
screenbuffer_goto(&conn->screenbuffer,
IPC_GET_ARG2(call), IPC_GET_ARG1(call));
if (consnum == active_console)
screenbuffer_goto(&cons->scr,
IPC_GET_ARG1(call), IPC_GET_ARG2(call));
if (cons == active_console)
curs_goto(IPC_GET_ARG1(call),
IPC_GET_ARG2(call));
break;
case CONSOLE_GETSIZE:
arg1 = fb_info.rows;
arg2 = fb_info.cols;
case CONSOLE_GET_SIZE:
arg1 = fb_info.cols;
arg2 = fb_info.rows;
break;
case CONSOLE_FLUSH:
fb_pending_flush();
if (consnum == active_console) {
async_req_0_0(fb_info.phone, FB_FLUSH);
 
scr = &(connections[consnum].screenbuffer);
curs_goto(scr->position_y, scr->position_x);
}
break;
case CONSOLE_SET_STYLE:
fb_pending_flush();
arg1 = IPC_GET_ARG1(call);
screenbuffer_set_style(&conn->screenbuffer, arg1);
if (consnum == active_console)
screenbuffer_set_style(&cons->scr, arg1);
if (cons == active_console)
set_style(arg1);
break;
case CONSOLE_SET_COLOR:
603,9 → 600,8
arg1 = IPC_GET_ARG1(call);
arg2 = IPC_GET_ARG2(call);
arg3 = IPC_GET_ARG3(call);
screenbuffer_set_color(&conn->screenbuffer, arg1,
arg2, arg3);
if (consnum == active_console)
screenbuffer_set_color(&cons->scr, arg1, arg2, arg3);
if (cons == active_console)
set_color(arg1, arg2, arg3);
break;
case CONSOLE_SET_RGB_COLOR:
612,46 → 608,27
fb_pending_flush();
arg1 = IPC_GET_ARG1(call);
arg2 = IPC_GET_ARG2(call);
screenbuffer_set_rgb_color(&conn->screenbuffer, arg1,
arg2);
if (consnum == active_console)
screenbuffer_set_rgb_color(&cons->scr, arg1, arg2);
if (cons == active_console)
set_rgb_color(arg1, arg2);
break;
case CONSOLE_CURSOR_VISIBILITY:
fb_pending_flush();
arg1 = IPC_GET_ARG1(call);
conn->screenbuffer.is_cursor_visible = arg1;
if (consnum == active_console)
cons->scr.is_cursor_visible = arg1;
if (cons == active_console)
curs_visibility(arg1);
break;
case CONSOLE_GETKEY:
if (keybuffer_empty(&conn->keybuffer)) {
/* buffer is empty -> store request */
if (conn->keyrequest_counter <
MAX_KEYREQUESTS_BUFFERED) {
fifo_push(conn->keyrequests, callid);
conn->keyrequest_counter++;
} else {
/*
* No key available and too many
* requests => fail.
*/
ipc_answer_0(callid, ELIMIT);
}
continue;
}
kbd_event_t ev;
keybuffer_pop(&conn->keybuffer, &ev);
arg1 = ev.type;
arg2 = ev.key;
arg3 = ev.mods;
arg4 = ev.c;
break;
case CONSOLE_GET_EVENT:
async_serialize_end();
cons_get_event(cons, callid, &call);
async_serialize_start();
continue;
case CONSOLE_KCON_ENABLE:
change_console(KERNEL_CONSOLE);
change_console(kernel_console);
break;
}
ipc_answer_4(callid, EOK, arg1, arg2, arg3, arg4);
ipc_answer_3(callid, EOK, arg1, arg2, arg3);
}
}
 
660,31 → 637,23
change_console(prev_console);
}
 
int main(int argc, char *argv[])
static bool console_init(void)
{
printf(NAME ": HelenOS Console service\n");
ipcarg_t phonehash;
int kbd_phone;
size_t ib_size;
int i;
async_set_client_connection(client_connection);
/* Connect to keyboard driver */
kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
if (kbd_phone < 0) {
printf(NAME ": Failed to connect to keyboard service\n");
return -1;
return false;
}
ipcarg_t phonehash;
if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
printf(NAME ": Failed to create callback from keyboard service\n");
return -1;
return false;
}
async_new_connection(phonehash, 0, NULL, keyboard_events);
 
/* Connect to framebuffer driver */
fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
if (fb_info.phone < 0) {
692,48 → 661,28
return -1;
}
/* Disable kernel output to the console */
__SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE);
/* Register driver */
int rc = devmap_driver_register(NAME, client_connection);
if (rc < 0) {
printf(NAME ": Unable to register driver (%d)\n", rc);
return false;
}
/* Initialize gcons */
gcons_init(fb_info.phone);
/* Synchronize, the gcons can have something in queue */
/* Synchronize, the gcons could put something in queue */
async_req_0_0(fb_info.phone, FB_FLUSH);
async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.rows,
&fb_info.cols);
set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
clrscr();
/* Init virtual consoles */
for (i = 0; i < CONSOLE_COUNT; i++) {
connections[i].used = 0;
keybuffer_init(&connections[i].keybuffer);
connections[i].keyrequests.head = 0;
connections[i].keyrequests.tail = 0;
connections[i].keyrequests.items = MAX_KEYREQUESTS_BUFFERED;
connections[i].keyrequest_counter = 0;
if (screenbuffer_init(&connections[i].screenbuffer,
fb_info.cols, fb_info.rows) == NULL) {
/* FIXME: handle error */
return -1;
}
}
connections[KERNEL_CONSOLE].used = 1;
 
/* Set up shared memory buffer. */
ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
size_t ib_size = sizeof(keyfield_t) * fb_info.cols * fb_info.rows;
interbuffer = as_get_mappable_page(ib_size);
 
fb_pending.n = 0;
 
if (as_area_create(interbuffer, ib_size, AS_AREA_READ |
AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer) {
AS_AREA_WRITE | AS_AREA_CACHEABLE) != interbuffer)
interbuffer = NULL;
}
 
if (interbuffer) {
if (ipc_share_out_start(fb_info.phone, interbuffer,
AS_AREA_READ) != EOK) {
742,22 → 691,62
}
}
fb_pending.cnt = 0;
/* Inititalize consoles */
size_t i;
for (i = 0; i < CONSOLE_COUNT; i++) {
if (i != KERNEL_CONSOLE) {
if (screenbuffer_init(&consoles[i].scr,
fb_info.cols, fb_info.rows) == NULL) {
printf(NAME ": Unable to allocate screen buffer %u\n", i);
return false;
}
screenbuffer_clear(&consoles[i].scr);
keybuffer_init(&consoles[i].keybuffer);
consoles[i].index = i;
consoles[i].refcount = 0;
char vc[MAX_DEVICE_NAME];
snprintf(vc, MAX_DEVICE_NAME, "vc%u", i);
if (devmap_device_register(vc, &consoles[i].dev_handle) != EOK) {
devmap_hangup_phone(DEVMAP_DRIVER);
printf(NAME ": Unable to register device %s\n", vc);
return false;
}
}
}
/* Disable kernel output to the console */
__SYSCALL0(SYS_DEBUG_DISABLE_CONSOLE);
/* Initialize the screen */
async_serialize_start();
gcons_redraw_console();
set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
screen_clear();
curs_goto(0, 0);
curs_visibility(
connections[active_console].screenbuffer.is_cursor_visible);
curs_visibility(active_console->scr.is_cursor_visible);
async_serialize_end();
/* Register at NS */
if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, 0, &phonehash) != 0)
return -1;
/* Receive kernel notifications */
if (event_subscribe(EVENT_KCONSOLE, 0) != EOK)
printf(NAME ": Error registering kconsole notifications\n");
async_set_interrupt_received(interrupt_received);
// FIXME: avoid connectiong to itself, keep using klog
// printf(NAME ": Accepting connections\n");
return true;
}
 
int main(int argc, char *argv[])
{
printf(NAME ": HelenOS Console service\n");
if (!console_init())
return -1;
printf(NAME ": Accepting connections\n");
async_manager();
return 0;
/branches/network/uspace/srv/console/gfx/anim_1.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/gfx/anim_2.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/gfx/anim_3.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/gfx/cons_has_data.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/gfx/anim_4.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/gfx/cons_selected.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/gfx/nameic.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/gfx/helenos.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/gfx/cons_idle.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/gfx/cons_kernel.ppm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/branches/network/uspace/srv/console/console.h
27,7 → 27,7
*/
 
/** @addtogroup console
* @{
* @{
*/
/** @file
*/
35,11 → 35,10
#ifndef __CONSOLE_H__
#define __CONSOLE_H__
 
#define KERNEL_CONSOLE 11
#define CONSOLE_COUNT 12
#define KERNEL_CONSOLE 11
 
#define CONSOLE_COUNT 12
#endif
 
#endif
/** @}
*/
/branches/network/uspace/srv/console/screenbuffer.c
27,44 → 27,50
*/
 
/** @addtogroup console
* @{
* @{
*/
/** @file
*/
 
#include <screenbuffer.h>
#include <console/style.h>
#include <io/style.h>
#include <malloc.h>
#include <unistd.h>
 
/** Store one character to screenbuffer. Its position is determined by
* scr->position_x and scr->position_y.
/** Store one character to screenbuffer.
*
* @param scr screenbuffer
* @param c stored character
* Its position is determined by scr->position_x
* and scr->position_y.
*
* @param scr Screenbuffer
* @param c Stored character
*
*/
void screenbuffer_putchar(screenbuffer_t *scr, wchar_t ch)
{
keyfield_t *field;
 
field = get_field_at(scr, scr->position_x, scr->position_y);
 
keyfield_t *field =
get_field_at(scr, scr->position_x, scr->position_y);
field->character = ch;
field->attrs = scr->attrs;
}
 
/** Initilize screenbuffer. Allocate space for screen content in accordance to given size.
* @param scr initialized screenbuffer
* @param size_x width in characters
* @param size_y height in characters
* @return pointer to screenbuffer (same as scr parameter) or NULL
/** Initilize screenbuffer.
*
* Allocate space for screen content in accordance to given size.
*
* @param scr Initialized screenbuffer
* @param size_x Width in characters
* @param size_y Height in characters
*
* @return Pointer to screenbuffer (same as scr parameter) or NULL
*
*/
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y)
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y)
{
scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
if (!scr->buffer) {
if (!scr->buffer)
return NULL;
}
scr->size_x = size_x;
scr->size_y = size_y;
77,56 → 83,63
return scr;
}
 
/** Clear screenbuffer.
* @param scr screenbuffer
/** Clear screenbuffer.
*
* @param scr Screenbuffer
*
*/
void screenbuffer_clear(screenbuffer_t *scr)
{
unsigned int i;
size_t i;
for (i = 0; i < (scr->size_x * scr->size_y); i++) {
scr->buffer[i].character = ' ';
scr->buffer[i].attrs = scr->attrs;
}
 
scr->top_line = 0;
scr->position_x = 0;
scr->position_y = 0;
scr->position_x = 0;
}
 
/** Clear one buffer line.
*
* @param scr
* @param line One buffer line (not a screen line!)
*
*/
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line)
void screenbuffer_clear_line(screenbuffer_t *scr, size_t line)
{
unsigned int i;
size_t x;
for (i = 0; i < scr->size_x; i++) {
scr->buffer[i + line * scr->size_x].character = ' ';
scr->buffer[i + line * scr->size_x].attrs = scr->attrs;
for (x = 0; x < scr->size_x; x++) {
scr->buffer[x + line * scr->size_x].character = ' ';
scr->buffer[x + line * scr->size_x].attrs = scr->attrs;
}
}
 
/** Copy content buffer from screenbuffer to given memory.
* @param scr source screenbuffer
* @param dest destination
*
* @param scr Source screenbuffer
* @param dest Destination
*
*/
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
{
unsigned int i;
size_t i;
for (i = 0; i < scr->size_x * scr->size_y; i++) {
for (i = 0; i < (scr->size_x * scr->size_y); i++)
dest[i] = scr->buffer[i];
}
}
 
/** Set new cursor position in screenbuffer.
*
* @param scr
* @param x
* @param y
*
*/
void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y)
void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y)
{
scr->position_x = x % scr->size_x;
scr->position_y = y % scr->size_y;
133,11 → 146,13
}
 
/** Set new style.
*
* @param scr
* @param fg_color
* @param bg_color
*
*/
void screenbuffer_set_style(screenbuffer_t *scr, int style)
void screenbuffer_set_style(screenbuffer_t *scr, uint8_t style)
{
scr->attrs.t = at_style;
scr->attrs.a.s.style = style;
144,11 → 159,13
}
 
/** Set new color.
*
* @param scr
* @param fg_color
* @param bg_color
*
*/
void screenbuffer_set_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color, unsigned int flags)
void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color, uint8_t bg_color, uint8_t flags)
{
scr->attrs.t = at_idx;
scr->attrs.a.i.fg_color = fg_color;
157,11 → 174,13
}
 
/** Set new RGB color.
*
* @param scr
* @param fg_color
* @param bg_color
*
*/
void screenbuffer_set_rgb_color(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color)
void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color, uint32_t bg_color)
{
scr->attrs.t = at_rgb;
scr->attrs.a.r.fg_color = fg_color;
168,6 → 187,5
scr->attrs.a.r.bg_color = bg_color;
}
 
/** @}
*/
/branches/network/uspace/srv/console/gcons.c
27,7 → 27,7
*/
 
/** @addtogroup console
* @{
* @{
*/
/** @file
*/
39,23 → 39,25
#include <sys/mman.h>
#include <string.h>
#include <align.h>
#include <bool.h>
 
#include "console.h"
#include "gcons.h"
 
#define CONSOLE_TOP 66
#define CONSOLE_MARGIN 6
#define CONSOLE_TOP 66
#define CONSOLE_MARGIN 6
 
#define STATUS_START 110
#define STATUS_TOP 8
#define STATUS_SPACE 4
#define STATUS_WIDTH 48
#define STATUS_HEIGHT 48
#define STATUS_START 110
#define STATUS_TOP 8
#define STATUS_SPACE 4
#define STATUS_WIDTH 48
#define STATUS_HEIGHT 48
 
#define MAIN_COLOR 0xffffff
#define MAIN_COLOR 0xffffff
 
static int use_gcons = 0;
static ipcarg_t xres,yres;
static bool use_gcons = false;
static ipcarg_t xres;
static ipcarg_t yres;
 
enum butstate {
CONS_DISCONNECTED = 0,
77,8 → 79,15
static int ic_pixmaps[CONS_LAST] = {-1, -1, -1, -1, -1, -1};
static int animation = -1;
 
static int active_console = 0;
static size_t active_console = 0;
 
size_t mouse_x;
size_t mouse_y;
 
bool btn_pressed;
size_t btn_x;
size_t btn_y;
 
static void vp_switch(int vp)
{
async_msg_1(fbphone, FB_VIEWPORT_SWITCH, vp);
85,8 → 94,7
}
 
/** Create view port */
static int vp_create(unsigned int x, unsigned int y, unsigned int width,
unsigned int height)
static int vp_create(size_t x, size_t y, size_t width, size_t height)
{
return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
(width << 16) | height);
97,48 → 105,52
async_msg_0(fbphone, FB_CLEAR);
}
 
static void set_rgb_color(int fgcolor, int bgcolor)
static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
{
async_msg_2(fbphone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
}
 
/** Transparent putchar */
static void tran_putch(char c, int row, int col)
static void tran_putch(wchar_t ch, size_t col, size_t row)
{
async_msg_3(fbphone, FB_PUTCHAR, c, row, col);
async_msg_3(fbphone, FB_PUTCHAR, ch, col, row);
}
 
/** Redraw the button showing state of a given console */
static void redraw_state(int consnum)
static void redraw_state(size_t index)
{
char data[5];
int i;
enum butstate state = console_state[consnum];
 
vp_switch(cstatus_vp[consnum]);
vp_switch(cstatus_vp[index]);
enum butstate state = console_state[index];
if (ic_pixmaps[state] != -1)
async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum],
async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[index],
ic_pixmaps[state]);
 
if (state != CONS_DISCONNECTED && state != CONS_KERNEL &&
state != CONS_DISCONNECTED_SEL) {
snprintf(data, 5, "%d", consnum + 1);
for (i = 0; data[i]; i++)
tran_putch(data[i], 1, 2 + i);
}
if ((state != CONS_DISCONNECTED) && (state != CONS_KERNEL)
&& (state != CONS_DISCONNECTED_SEL)) {
char data[5];
snprintf(data, 5, "%u", index + 1);
size_t i;
for (i = 0; data[i] != 0; i++)
tran_putch(data[i], 2 + i, 1);
}
}
 
/** Notification run on changing console (except kernel console) */
void gcons_change_console(int consnum)
void gcons_change_console(size_t index)
{
int i;
 
if (!use_gcons)
return;
 
if (active_console == KERNEL_CONSOLE) {
size_t i;
for (i = 0; i < CONSOLE_COUNT; i++)
redraw_state(i);
if (animation != -1)
async_msg_1(fbphone, FB_ANIM_START, animation);
} else {
146,71 → 158,74
console_state[active_console] = CONS_DISCONNECTED;
else
console_state[active_console] = CONS_IDLE;
redraw_state(active_console);
}
active_console = consnum;
 
if (console_state[consnum] == CONS_DISCONNECTED) {
console_state[consnum] = CONS_DISCONNECTED_SEL;
redraw_state(consnum);
} else
console_state[consnum] = CONS_SELECTED;
redraw_state(consnum);
 
active_console = index;
if ((console_state[index] == CONS_DISCONNECTED)
|| (console_state[index] == CONS_DISCONNECTED_SEL))
console_state[index] = CONS_DISCONNECTED_SEL;
else
console_state[index] = CONS_SELECTED;
redraw_state(index);
vp_switch(console_vp);
}
 
/** Notification function that gets called on new output to virtual console */
void gcons_notify_char(int consnum)
void gcons_notify_char(size_t index)
{
if (!use_gcons)
return;
 
if (consnum == active_console ||
console_state[consnum] == CONS_HAS_DATA)
if ((index == active_console)
|| (console_state[index] == CONS_HAS_DATA))
return;
 
console_state[consnum] = CONS_HAS_DATA;
 
console_state[index] = CONS_HAS_DATA;
if (active_console == KERNEL_CONSOLE)
return;
 
redraw_state(consnum);
redraw_state(index);
vp_switch(console_vp);
}
 
/** Notification function called on service disconnect from console */
void gcons_notify_disconnect(int consnum)
void gcons_notify_disconnect(size_t index)
{
if (!use_gcons)
return;
if (active_console == consnum)
console_state[consnum] = CONS_DISCONNECTED_SEL;
if (index == active_console)
console_state[index] = CONS_DISCONNECTED_SEL;
else
console_state[consnum] = CONS_DISCONNECTED;
console_state[index] = CONS_DISCONNECTED;
if (active_console == KERNEL_CONSOLE)
return;
redraw_state(consnum);
redraw_state(index);
vp_switch(console_vp);
}
 
/** Notification function called on console connect */
void gcons_notify_connect(int consnum)
void gcons_notify_connect(size_t index)
{
if (!use_gcons)
return;
if (active_console == consnum)
console_state[consnum] = CONS_SELECTED;
if (index == active_console)
console_state[index] = CONS_SELECTED;
else
console_state[consnum] = CONS_IDLE;
 
console_state[index] = CONS_IDLE;
if (active_console == KERNEL_CONSOLE)
return;
 
redraw_state(consnum);
redraw_state(index);
vp_switch(console_vp);
}
 
224,29 → 239,28
vp_switch(0);
}
 
/** Return x, where left <= x <= right && |a-x|==min(|a-x|) is smallest */
static inline int limit(int a,int left, int right)
/** Return x, where left <= x <= right && |a-x| == min(|a-x|) is smallest */
static inline int limit(size_t a, size_t left, size_t right)
{
if (a < left)
a = left;
if (a >= right)
a = right - 1;
return a;
}
 
int mouse_x, mouse_y;
int btn_pressed, btn_x, btn_y;
 
/** Handle mouse move
*
* @param dx Delta X of mouse move
* @param dy Delta Y of mouse move
*/
void gcons_mouse_move(int dx, int dy)
void gcons_mouse_move(ssize_t dx, ssize_t dy)
{
mouse_x = limit(mouse_x + dx, 0, xres);
mouse_y = limit(mouse_y + dy, 0, yres);
 
async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
}
 
253,8 → 267,8
static int gcons_find_conbut(int x, int y)
{
int status_start = STATUS_START + (xres - 800) / 2;
 
if (y < STATUS_TOP || y >= STATUS_TOP + STATUS_HEIGHT)
if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT))
return -1;
if (x < status_start)
270,28 → 284,31
 
/** Handle mouse click
*
* @param state New state (1-pressed, 0-depressed)
* @param state New state (true - pressed, false - depressed)
*/
int gcons_mouse_btn(int state)
int gcons_mouse_btn(bool state)
{
int conbut;
 
if (state) {
conbut = gcons_find_conbut(mouse_x, mouse_y);
if (conbut != -1) {
btn_pressed = 1;
btn_pressed = true;
btn_x = mouse_x;
btn_y = mouse_y;
}
return -1;
}
if (!state && !btn_pressed)
}
if ((!state) && (!btn_pressed))
return -1;
btn_pressed = 0;
 
btn_pressed = false;
conbut = gcons_find_conbut(mouse_x, mouse_y);
if (conbut == gcons_find_conbut(btn_x, btn_y))
return conbut;
return -1;
}
 
307,35 → 324,40
{
char *shm;
int rc;
 
/* Create area */
shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
MAP_ANONYMOUS, 0, 0);
if (shm == MAP_FAILED)
return;
 
memcpy(shm, logo, size);
/* Send area */
rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
if (rc)
goto exit;
rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
if (rc)
goto drop;
/* Draw logo */
async_msg_2(fbphone, FB_DRAW_PPM, x, y);
drop:
/* Drop area */
async_msg_0(fbphone, FB_DROP_SHM);
exit:
exit:
/* Remove area */
munmap(shm, size);
}
 
extern char _binary_helenos_ppm_start[0];
extern int _binary_helenos_ppm_size;
extern char _binary_nameic_ppm_start[0];
extern int _binary_nameic_ppm_size;
extern char _binary_gfx_helenos_ppm_start[0];
extern int _binary_gfx_helenos_ppm_size;
extern char _binary_gfx_nameic_ppm_start[0];
extern int _binary_gfx_nameic_ppm_size;
 
/** Redraws console graphics */
void gcons_redraw_console(void)
348,13 → 370,14
vp_switch(0);
set_rgb_color(MAIN_COLOR, MAIN_COLOR);
clear();
draw_pixmap(_binary_helenos_ppm_start,
(size_t) &_binary_helenos_ppm_size, xres - 66, 2);
draw_pixmap(_binary_nameic_ppm_start,
(size_t) &_binary_nameic_ppm_size, 5, 17);
draw_pixmap(_binary_gfx_helenos_ppm_start,
(size_t) &_binary_gfx_helenos_ppm_size, xres - 66, 2);
draw_pixmap(_binary_gfx_nameic_ppm_start,
(size_t) &_binary_gfx_nameic_ppm_size, 5, 17);
for (i = 0; i < CONSOLE_COUNT; i++)
redraw_state(i);
vp_switch(console_vp);
}
 
362,102 → 385,102
*
* @param data PPM data
* @param size PPM data size
*
* @return Pixmap identification
*
*/
static int make_pixmap(char *data, int size)
static int make_pixmap(char *data, size_t size)
{
char *shm;
int rc;
int pxid = -1;
 
/* Create area */
shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
MAP_ANONYMOUS, 0, 0);
if (shm == MAP_FAILED)
return -1;
 
memcpy(shm, data, size);
/* Send area */
rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
if (rc)
goto exit;
rc = ipc_share_out_start(fbphone, shm, PROTO_READ);
if (rc)
goto drop;
 
/* Obtain pixmap */
rc = async_req_0_0(fbphone, FB_SHM2PIXMAP);
if (rc < 0)
goto drop;
pxid = rc;
drop:
/* Drop area */
async_msg_0(fbphone, FB_DROP_SHM);
exit:
exit:
/* Remove area */
munmap(shm, size);
 
return pxid;
}
 
extern char _binary_anim_1_ppm_start[0];
extern int _binary_anim_1_ppm_size;
extern char _binary_anim_2_ppm_start[0];
extern int _binary_anim_2_ppm_size;
extern char _binary_anim_3_ppm_start[0];
extern int _binary_anim_3_ppm_size;
extern char _binary_anim_4_ppm_start[0];
extern int _binary_anim_4_ppm_size;
extern char _binary_gfx_anim_1_ppm_start[0];
extern int _binary_gfx_anim_1_ppm_size;
extern char _binary_gfx_anim_2_ppm_start[0];
extern int _binary_gfx_anim_2_ppm_size;
extern char _binary_gfx_anim_3_ppm_start[0];
extern int _binary_gfx_anim_3_ppm_size;
extern char _binary_gfx_anim_4_ppm_start[0];
extern int _binary_gfx_anim_4_ppm_size;
 
static void make_anim(void)
{
int an;
int pm;
 
an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
int an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
if (an < 0)
return;
 
pm = make_pixmap(_binary_anim_1_ppm_start,
(int) &_binary_anim_1_ppm_size);
int pm = make_pixmap(_binary_gfx_anim_1_ppm_start,
(int) &_binary_gfx_anim_1_ppm_size);
async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
 
pm = make_pixmap(_binary_anim_2_ppm_start,
(int) &_binary_anim_2_ppm_size);
pm = make_pixmap(_binary_gfx_anim_2_ppm_start,
(int) &_binary_gfx_anim_2_ppm_size);
async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
 
pm = make_pixmap(_binary_anim_3_ppm_start,
(int) &_binary_anim_3_ppm_size);
pm = make_pixmap(_binary_gfx_anim_3_ppm_start,
(int) &_binary_gfx_anim_3_ppm_size);
async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
 
pm = make_pixmap(_binary_anim_4_ppm_start,
(int) &_binary_anim_4_ppm_size);
pm = make_pixmap(_binary_gfx_anim_4_ppm_start,
(int) &_binary_gfx_anim_4_ppm_size);
async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
 
async_msg_1(fbphone, FB_ANIM_START, an);
 
animation = an;
}
 
extern char _binary_cons_selected_ppm_start[0];
extern int _binary_cons_selected_ppm_size;
extern char _binary_cons_idle_ppm_start[0];
extern int _binary_cons_idle_ppm_size;
extern char _binary_cons_has_data_ppm_start[0];
extern int _binary_cons_has_data_ppm_size;
extern char _binary_cons_kernel_ppm_start[0];
extern int _binary_cons_kernel_ppm_size;
extern char _binary_gfx_cons_selected_ppm_start[0];
extern int _binary_gfx_cons_selected_ppm_size;
extern char _binary_gfx_cons_idle_ppm_start[0];
extern int _binary_gfx_cons_idle_ppm_size;
extern char _binary_gfx_cons_has_data_ppm_start[0];
extern int _binary_gfx_cons_has_data_ppm_size;
extern char _binary_gfx_cons_kernel_ppm_start[0];
extern int _binary_gfx_cons_kernel_ppm_size;
 
/** Initialize nice graphical console environment */
void gcons_init(int phone)
{
int rc;
int i;
int status_start = STATUS_START;
fbphone = phone;
rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
int rc = async_req_0_2(phone, FB_GET_RESOLUTION, &xres, &yres);
if (rc)
return;
464,22 → 487,27
if ((xres < 800) || (yres < 600))
return;
/* create console viewport */
/* Create console viewport */
/* Align width & height to character size */
console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP,
ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8),
ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16));
if (console_vp < 0)
return;
/* Create status buttons */
status_start += (xres - 800) / 2;
size_t status_start = STATUS_START + (xres - 800) / 2;
size_t i;
for (i = 0; i < CONSOLE_COUNT; i++) {
cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN +
i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
STATUS_WIDTH, STATUS_HEIGHT);
if (cstatus_vp[i] < 0)
return;
vp_switch(cstatus_vp[i]);
set_rgb_color(0x202020, 0xffffff);
}
486,26 → 514,29
/* Initialize icons */
ic_pixmaps[CONS_SELECTED] =
make_pixmap(_binary_cons_selected_ppm_start,
(int) &_binary_cons_selected_ppm_size);
ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start,
(int) &_binary_cons_idle_ppm_size);
make_pixmap(_binary_gfx_cons_selected_ppm_start,
(size_t) &_binary_gfx_cons_selected_ppm_size);
ic_pixmaps[CONS_IDLE] =
make_pixmap(_binary_gfx_cons_idle_ppm_start,
(size_t) &_binary_gfx_cons_idle_ppm_size);
ic_pixmaps[CONS_HAS_DATA] =
make_pixmap(_binary_cons_has_data_ppm_start,
(int) &_binary_cons_has_data_ppm_size);
make_pixmap(_binary_gfx_cons_has_data_ppm_start,
(size_t) &_binary_gfx_cons_has_data_ppm_size);
ic_pixmaps[CONS_DISCONNECTED] =
make_pixmap(_binary_cons_idle_ppm_start,
(int) &_binary_cons_idle_ppm_size);
ic_pixmaps[CONS_KERNEL] = make_pixmap(_binary_cons_kernel_ppm_start,
(int) &_binary_cons_kernel_ppm_size);
make_pixmap(_binary_gfx_cons_idle_ppm_start,
(size_t) &_binary_gfx_cons_idle_ppm_size);
ic_pixmaps[CONS_KERNEL] =
make_pixmap(_binary_gfx_cons_kernel_ppm_start,
(size_t) &_binary_gfx_cons_kernel_ppm_size);
ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
make_anim();
use_gcons = 1;
use_gcons = true;
console_state[0] = CONS_DISCONNECTED_SEL;
console_state[KERNEL_CONSOLE] = CONS_KERNEL;
gcons_redraw_console();
vp_switch(console_vp);
}
 
/** @}
/branches/network/uspace/srv/console/Makefile
42,23 → 42,29
#
 
OUTPUT = console
 
GENERIC_SOURCES = \
console.c \
screenbuffer.c \
../kbd/generic/key_buffer.c \
../kbd/generic/keybuffer.c \
gcons.c
 
IMAGES = helenos.ppm nameic.ppm cons_selected.ppm cons_idle.ppm \
cons_has_data.ppm cons_kernel.ppm anim_1.ppm anim_2.ppm anim_3.ppm \
anim_4.ppm
IMAGES = \
gfx/helenos.ppm \
gfx/nameic.ppm \
gfx/cons_selected.ppm \
gfx/cons_idle.ppm \
gfx/cons_has_data.ppm \
gfx/cons_kernel.ppm \
gfx/anim_1.ppm \
gfx/anim_2.ppm \
gfx/anim_3.ppm \
gfx/anim_4.ppm
 
ARCH_SOURCES =
 
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES))) \
$(addsuffix .o,$(basename $(IMAGES)))
ARCH_OBJECTS := $(addsuffix .o,$(basename $(ARCH_SOURCES)))
$(addsuffix .o,$(basename $(IMAGES)))
 
OBJECTS := $(GENERIC_OBJECTS) $(ARCH_OBJECTS)
OBJECTS := $(GENERIC_OBJECTS)
 
.PHONY: all clean depend disasm
 
78,7 → 84,7
disasm: $(OUTPUT).disasm
 
$(OUTPUT).disasm: $(OUTPUT)
$(OBJDUMP) -d $< >$@
$(OBJDUMP) -d $< > $@
 
%.o: %.S
$(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@