Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1450 → Rev 1451

/uspace/trunk/kbd/include/kbd.h
31,5 → 31,18
 
#define KBD_PUSHCHAR 1024
 
#define KBD_KEY_F1 0x3b
#define KBD_KEY_F2 0x3c
#define KBD_KEY_F3 0x3d
#define KBD_KEY_F4 0x3e
#define KBD_KEY_F5 0x3f
#define KBD_KEY_F6 0x40
#define KBD_KEY_F7 0x41
#define KBD_KEY_F8 0x42
#define KBD_KEY_F9 0x43
#define KBD_KEY_F10 0x44
#define KBD_KEY_F11 0x45
#define KBD_KEY_F12 0x46
 
#endif
 
/uspace/trunk/kbd/include/key_buffer.h
31,12 → 31,21
 
#include <types.h>
 
void key_buffer_free(void);
void key_buffer_init(void);
int key_buffer_available(void);
int key_buffer_empty(void);
void key_buffer_push(char key);
int key_buffer_pop(char *c);
#define KEYBUFFER_SIZE 128 /**< Size of buffer for pressed keys */
 
typedef struct {
char fifo[KEYBUFFER_SIZE];
unsigned long head;
unsigned long tail;
unsigned long items;
} keybuffer_t;
 
void keybuffer_free(keybuffer_t *keybuffer);
void keybuffer_init(keybuffer_t *keybuffer);
int keybuffer_available(keybuffer_t *keybuffer);
int keybuffer_empty(keybuffer_t *keybuffer);
void keybuffer_push(keybuffer_t *keybuffer, char key);
int keybuffer_pop(keybuffer_t *keybuffer, char *c);
 
#endif
 
/uspace/trunk/kbd/generic/kbd.c
48,25 → 48,25
ipcarg_t phonead;
int phoneid;
char connected = 0;
keybuffer_t keybuffer;
ipcarg_t retval, arg1, arg2;
 
printf("Uspace kbd service started.\n");
// printf("Uspace kbd service started.\n");
 
/* Initialize arch dependent parts */
if (!(res = kbd_arch_init())) {
printf("Kbd registration failed with retval %d.\n", res);
// printf("Kbd registration failed with retval %d.\n", res);
return -1;
};
/* Initialize key buffer */
key_buffer_init();
keybuffer_init(&keybuffer);
/* Register service at nameserver */
printf("%s: Registering at naming service.\n", NAME);
// printf("%s: Registering at naming service.\n", NAME);
 
if ((res = ipc_connect_to_me(PHONE_NS, SERVICE_KEYBOARD, 0, &phonead)) != 0) {
printf("%s: Error: Registering at naming service failed.\n", NAME);
// printf("%s: Error: Registering at naming service failed.\n", NAME);
return -1;
};
75,7 → 75,7
// printf("%s:Call phone=%lX..", NAME, call.in_phone_hash);
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
printf("%s: Phone hung up.\n", NAME);
// printf("%s: Phone hung up.\n", NAME);
connected = 0;
retval = 0;
break;
97,7 → 97,7
case IPC_M_INTERRUPT:
if (connected) {
/* recode to ASCII - one interrupt can produce more than one code so result is stored in fifo */
kbd_arch_process(IPC_GET_ARG2(call));
kbd_arch_process(&keybuffer, IPC_GET_ARG2(call));
 
//printf("%s: GOT INTERRUPT: %c\n", NAME, key);
 
106,20 → 106,20
retval = 0;
 
while (!key_buffer_empty()) {
if (!key_buffer_pop((char *)&arg1)) {
printf("%s: KeyBuffer is empty but it should not be.\n");
while (!keybuffer_empty(&keybuffer)) {
if (!keybuffer_pop(&keybuffer, (char *)&arg1)) {
// printf("%s: KeyBuffer is empty but it should not be.\n");
break;
}
/*FIXME: detection of closed connection */
ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, 0, NULL);
ipc_call_async(phoneid, KBD_PUSHCHAR, arg1, NULL, NULL);
}
 
}
printf("%s: Interrupt processed.\n", NAME);
// printf("%s: Interrupt processed.\n", NAME);
break;
default:
printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
// printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
retval = ENOENT;
break;
}
/uspace/trunk/kbd/generic/key_buffer.c
27,27 → 27,22
*/
 
#include <key_buffer.h>
#include <libadt/fifo.h>
 
#define KBD_BUFFER_SIZE 128 /**< Size of buffer for pressed keys */
 
FIFO_INITIALIZE_STATIC(buffer, char, KBD_BUFFER_SIZE); /**< Fifo for storing pressed keys */
fifo_count_t buffer_items; /**< Counter of used items for prevent fifo overflow */
 
/** Clear key buffer.
*/
void key_buffer_free(void)
void keybuffer_free(keybuffer_t *keybuffer)
{
buffer_items = 0;
buffer.head = buffer.tail = 0;
 
keybuffer->items = 0;
keybuffer->head = keybuffer->tail = keybuffer->items = 0;
}
 
/** Key buffer initialization.
*
*/
void key_buffer_init(void)
void keybuffer_init(keybuffer_t *keybuffer)
{
key_buffer_free();
keybuffer_free(keybuffer);
}
 
/** Get free space in buffer.
55,17 → 50,17
* to more than one character.
* @return empty buffer space
*/
int key_buffer_available(void)
int keybuffer_available(keybuffer_t *keybuffer)
{
return KBD_BUFFER_SIZE - buffer_items;
return KEYBUFFER_SIZE - keybuffer->items;
}
 
/**
* @return nonzero, if buffer is not empty.
*/
int key_buffer_empty(void)
int keybuffer_empty(keybuffer_t *keybuffer)
{
return (buffer_items == 0);
return (keybuffer->items == 0);
}
 
/** Push key to key buffer.
72,11 → 67,11
* If buffer is full, character is ignored.
* @param key code of stored key
*/
void key_buffer_push(char key)
void keybuffer_push(keybuffer_t *keybuffer, char key)
{
if (buffer_items < KBD_BUFFER_SIZE) {
fifo_push(buffer, key);
buffer_items++;
if (keybuffer->items < KEYBUFFER_SIZE) {
keybuffer->fifo[keybuffer->tail = (keybuffer->tail + 1) < keybuffer->items ? (keybuffer->tail + 1) : 0] = (key);
keybuffer->items++;
}
}
 
84,11 → 79,11
* @param c pointer to space where to store character from buffer.
* @return zero on empty buffer, nonzero else
*/
int key_buffer_pop(char *c)
int keybuffer_pop(keybuffer_t *keybuffer, char *c)
{
if (buffer_items > 0) {
buffer_items--;
*c = fifo_pop(buffer);
if (keybuffer->items > 0) {
keybuffer->items--;
*c = keybuffer->fifo[keybuffer->head = (keybuffer->head + 1) < keybuffer->items ? (keybuffer->head + 1) : 0];
return 1;
}
return 0;
/uspace/trunk/kbd/Makefile
67,7 → 67,7
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
 
$(OUTPUT): $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(LIBS)
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld -e __entry_driver $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
 
disasm:
$(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm
/uspace/trunk/kbd/arch/mips32/include/kbd.h
29,8 → 29,10
#ifndef __mips32_KBD_H__
#define __mips32_KBD_H__
 
#include <key_buffer.h>
 
int kbd_arch_init(void);
int kbd_arch_process(int scan_code);
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code);
 
#endif
 
/uspace/trunk/kbd/arch/mips32/src/kbd.c
28,7 → 28,6
 
#include <arch/kbd.h>
#include <ipc/ipc.h>
#include <key_buffer.h>
 
irq_cmd_t msim_cmds[1] = {
{ CMD_MEM_READ_1, (void *)0xB0000000, 0 }
45,8 → 44,8
return 1;
}
 
int kbd_arch_process(int scan_code)
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code)
{
key_buffer_push(scan_code);
keybuffer_push(keybuffer, scan_code);
return 1;
}
/uspace/trunk/kbd/arch/ia32/include/kbd.h
29,7 → 29,9
#ifndef __ia32_KBD_H__
#define __ia32_KBD_H__
 
#include <key_buffer.h>
 
int kbd_arch_init(void);
int kbd_arch_process(int scan_code);
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code);
 
#endif
/uspace/trunk/kbd/arch/ia32/src/kbd.c
28,7 → 28,6
*/
 
#include <arch/kbd.h>
#include <key_buffer.h>
#include <ipc/ipc.h>
 
#define SPECIAL '?'
79,16 → 78,26
SPECIAL, /* 0x38 - LAlt */
' ',
SPECIAL, /* 0x3a - CapsLock */
SPECIAL, /* 0x3b - F1 */
SPECIAL, /* 0x3c - F2 */
SPECIAL, /* 0x3d - F3 */
SPECIAL, /* 0x3e - F4 */
SPECIAL, /* 0x3f - F5 */
SPECIAL, /* 0x40 - F6 */
SPECIAL, /* 0x41 - F7 */
SPECIAL, /* 0x42 - F8 */
SPECIAL, /* 0x43 - F9 */
SPECIAL, /* 0x44 - F10 */
0x3b, /* 0x3b - F1 */
// SPECIAL, /* 0x3b - F1 */
0x3c, /* 0x3c - F2 */
// SPECIAL, /* 0x3c - F2 */
0x3d, /* 0x3d - F3 */
// SPECIAL, /* 0x3d - F3 */
0x3e, /* 0x3e - F4 */
// SPECIAL, /* 0x3e - F4 */
// SPECIAL, /* 0x3f - F5 */
0x3f, /* 0x3f - F5 */
// SPECIAL, /* 0x40 - F6 */
0x40, /* 0x40 - F6 */
// SPECIAL, /* 0x41 - F7 */
0x41, /* 0x41 - F7 */
// SPECIAL, /* 0x42 - F8 */
0x42, /* 0x42 - F8 */
// SPECIAL, /* 0x43 - F9 */
0x43, /* 0x43 - F9 */
// SPECIAL, /* 0x44 - F10 */
0x44, /* 0x44 - F10 */
SPECIAL, /* 0x45 - NumLock */
SPECIAL, /* 0x46 - ScrollLock */
'7', '8', '9', '-',
159,16 → 168,26
SPECIAL, /* 0x38 - LAlt */
' ',
SPECIAL, /* 0x3a - CapsLock */
SPECIAL, /* 0x3b - F1 */
SPECIAL, /* 0x3c - F2 */
SPECIAL, /* 0x3d - F3 */
SPECIAL, /* 0x3e - F4 */
SPECIAL, /* 0x3f - F5 */
SPECIAL, /* 0x40 - F6 */
SPECIAL, /* 0x41 - F7 */
SPECIAL, /* 0x42 - F8 */
SPECIAL, /* 0x43 - F9 */
SPECIAL, /* 0x44 - F10 */
0x3b, /* 0x3b - F1 */
0x3c, /* 0x3c - F2 */
0x3d, /* 0x3d - F3 */
0x3e, /* 0x3e - F4 */
0x3f, /* 0x3f - F5 */
0x40, /* 0x40 - F6 */
0x41, /* 0x41 - F7 */
0x42, /* 0x42 - F8 */
0x43, /* 0x43 - F9 */
0x44, /* 0x44 - F10 */
// SPECIAL, /* 0x3b - F1 */
// SPECIAL, /* 0x3c - F2 */
// SPECIAL, /* 0x3d - F3 */
// SPECIAL, /* 0x3e - F4 */
// SPECIAL, /* 0x3f - F5 */
// SPECIAL, /* 0x40 - F6 */
// SPECIAL, /* 0x41 - F7 */
// SPECIAL, /* 0x42 - F8 */
// SPECIAL, /* 0x43 - F9 */
// SPECIAL, /* 0x44 - F10 */
SPECIAL, /* 0x45 - NumLock */
SPECIAL, /* 0x46 - ScrollLock */
'7', '8', '9', '-',
230,7 → 249,7
i8042_cmds
};
 
static int key_released(unsigned char key)
static int key_released(keybuffer_t *keybuffer, unsigned char key)
{
switch (key) {
case SC_LSHIFT:
249,7 → 268,7
}
}
 
static int key_pressed(unsigned char key)
static int key_pressed(keybuffer_t *keybuffer, unsigned char key)
{
char *map = sc_primary_map;
char ascii = sc_primary_map[key];
267,53 → 286,53
case SC_SPEC_ESCAPE:
break;
case SC_LEFTARR:
if (key_buffer_available() >= 3) {
key_buffer_push(0x1b);
key_buffer_push(0x5b);
key_buffer_push(0x44);
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x5b);
keybuffer_push(keybuffer, 0x44);
}
break;
case SC_RIGHTARR:
if (key_buffer_available() >= 3) {
key_buffer_push(0x1b);
key_buffer_push(0x5b);
key_buffer_push(0x43);
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x5b);
keybuffer_push(keybuffer, 0x43);
}
break;
case SC_UPARR:
if (key_buffer_available() >= 3) {
key_buffer_push(0x1b);
key_buffer_push(0x5b);
key_buffer_push(0x41);
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x5b);
keybuffer_push(keybuffer, 0x41);
}
break;
case SC_DOWNARR:
if (key_buffer_available() >= 3) {
key_buffer_push(0x1b);
key_buffer_push(0x5b);
key_buffer_push(0x42);
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x5b);
keybuffer_push(keybuffer, 0x42);
}
break;
case SC_HOME:
if (key_buffer_available() >= 3) {
key_buffer_push(0x1b);
key_buffer_push(0x4f);
key_buffer_push(0x48);
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x4f);
keybuffer_push(keybuffer, 0x48);
}
break;
case SC_END:
if (key_buffer_available() >= 3) {
key_buffer_push(0x1b);
key_buffer_push(0x4f);
key_buffer_push(0x46);
if (keybuffer_available(keybuffer) >= 3) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x4f);
keybuffer_push(keybuffer, 0x46);
}
break;
case SC_DELETE:
if (key_buffer_available() >= 4) {
key_buffer_push(0x1b);
key_buffer_push(0x5b);
key_buffer_push(0x33);
key_buffer_push(0x7e);
if (keybuffer_available(keybuffer) >= 4) {
keybuffer_push(keybuffer, 0x1b);
keybuffer_push(keybuffer, 0x5b);
keybuffer_push(keybuffer, 0x33);
keybuffer_push(keybuffer, 0x7e);
}
break;
default:
324,7 → 343,7
shift = !shift;
if (shift)
map = sc_secondary_map;
key_buffer_push(map[key]);
keybuffer_push(keybuffer, map[key]);
break;
}
}
337,13 → 356,13
return !(ipc_register_irq(1, &i8042_kbd));
}
 
int kbd_arch_process(int scan_code)
int kbd_arch_process(keybuffer_t *keybuffer, int scan_code)
{
if (scan_code != IGNORE_CODE) {
if (scan_code & KEY_RELEASE)
key_released(scan_code ^ KEY_RELEASE);
key_released(keybuffer, scan_code ^ KEY_RELEASE);
else
key_pressed(scan_code);
key_pressed(keybuffer, scan_code);
}
return 1;
}
/uspace/trunk/console/console.c
28,45 → 28,88
 
 
#include <kbd.h>
#include <fb.h>
#include <ipc/ipc.h>
#include <ipc/fb.h>
#include <ipc/services.h>
#include <stdio.h>
#include <errno.h>
#include <key_buffer.h>
#include <console.h>
 
//#define CONSOLE_COUNT VFB_CONNECTIONS
#define CONSOLE_COUNT 6
 
#define NAME "CONSOLE"
 
typedef struct {
keybuffer_t keybuffer;
int client_phone;
int vfb_number; /* Not used */
int vfb_phone;
int used;
} connection_t;
 
connection_t connections[CONSOLE_COUNT];
 
static int find_free_connection()
{
int i = 0;
while (i < CONSOLE_COUNT) {
if (connections[i].used == 0)
return i;
++i;
}
return CONSOLE_COUNT;
}
 
 
static int find_connection(int client_phone)
{
int i = 0;
while (i < CONSOLE_COUNT) {
if (connections[i].client_phone == client_phone)
return i;
++i;
}
return CONSOLE_COUNT;
}
 
int main(int argc, char *argv[])
{
ipcarg_t phonead;
ipc_call_t call;
ipc_callid_t callid;
int phone_kbd, phone_fb;
int kbd_phone, fb_phone;
ipcarg_t retval, arg1 = 0xdead, arg2 = 0xbeef;
int i;
int active_client = 0;
printf("Uspace console service started.\n");
/* Connect to keyboard driver */
 
while ((phone_kbd = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
while ((kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0)) < 0) {
};
if (ipc_connect_to_me(phone_kbd, SERVICE_CONSOLE, 0, &phonead) != 0) {
printf("%s: Error: Registering at naming service failed.\n", NAME);
if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, &phonead) != 0) {
return -1;
};
 
/* Connect to framebuffer driver */
while ((phone_fb = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
};
for (i = 0; i < CONSOLE_COUNT; i++) {
connections[i].used = 0;
keybuffer_init(&(connections[i].keybuffer));
/* TODO: init key_buffer */
while ((connections[i].vfb_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
ipc_call_async_2(connections[i].vfb_phone, FB_PUTCHAR, 'a', 'b', NULL, (void *)NULL);
}
}
 
/* Register service at nameserver */
printf("%s: Registering at naming service.\n", NAME);
 
if (ipc_connect_to_me(PHONE_NS, SERVICE_CONSOLE, 0, &phonead) != 0) {
printf("%s: Error: Registering at naming service failed.\n", NAME);
return -1;
};
74,20 → 117,71
callid = ipc_wait_for_call(&call);
switch (IPC_GET_METHOD(call)) {
case IPC_M_PHONE_HUNGUP:
printf("%s: Phone hung up.\n", NAME);
retval = 0;
/*FIXME: if its fb or kbd then panic! */
/* free connection */
if (i = find_connection(IPC_GET_ARG3(call)) < CONSOLE_COUNT) {
connections[i].used = 0;
/*TODO: free connection[i].key_buffer; */
/* FIXME: active_connection hungup */
retval = 0;
} else {
/*FIXME: No such connection */
}
break;
case IPC_M_CONNECT_ME_TO:
printf("%s: Connect me (%P) to: %zd\n",NAME, IPC_GET_ARG3(call), IPC_GET_ARG1(call));
/* find first free connection */
if ((i = find_free_connection()) == CONSOLE_COUNT) {
retval = ELIMIT;
break;
}
connections[i].used = 1;
connections[i].client_phone = IPC_GET_ARG3(call);
retval = 0;
break;
case KBD_PUSHCHAR:
printf("%s: Push char '%c'.\n", NAME, IPC_GET_ARG1(call));
/* got key from keyboard driver */
/* find active console */
/* if client is awaiting key, send it */
/*FIXME: else store key to its buffer */
retval = 0;
i = IPC_GET_ARG1(call) & 0xff;
/* switch to another virtual console */
if ((i >= KBD_KEY_F1) && (i < KBD_KEY_F1 + CONSOLE_COUNT)) {
active_client = i - KBD_KEY_F1;
break;
}
keybuffer_push(&(connections[active_client].keybuffer), i);
break;
case CONSOLE_PUTCHAR:
/* find sender client */
/* ???
* if its active client, send it to vfb
**/
/*FIXME: check, if its from active client, .... */
 
if ((i = find_connection(IPC_GET_ARG3(call))) == CONSOLE_COUNT) {
break;
};
/* TODO: send message to fb */
ipc_call_async_2(connections[i].vfb_phone, FB_PUTCHAR, IPC_GET_ARG1(call), IPC_GET_ARG2(call), NULL, NULL);
break;
case CONSOLE_GETCHAR:
/* FIXME: */
if (!keybuffer_pop(&(connections[active_client].keybuffer), (char *)&arg1)) {
/* FIXME: buffer empty -> store request */
arg1 = 'X'; /* Only temporary */
};
//ipc_call_async_2(connections[active_client].vfb_phone, FB_PUTCHAR, ' ', arg1, NULL, (void *)NULL);
break;
default:
printf("%s: Unknown method: %zd\n", NAME, IPC_GET_METHOD(call));
retval = ENOENT;
break;
}
/uspace/trunk/console/console.h
0,0 → 1,36
/*
* Copyright (C) 2006 Josef Cejka
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __CONSOLE_H__
#define __CONSOLE_H__
 
#define CONSOLE_GETCHAR 1025
#define CONSOLE_PUTCHAR 1027
 
#endif
 
/uspace/trunk/console/Makefile
33,7 → 33,7
SOFTINT_PREFIX = ../softint
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS += -Iinclude -I../kbd/include ../fb
CFLAGS += -I. -I../kbd/include -I../fb
 
LIBS = $(LIBC_PREFIX)/libc.a
 
42,7 → 42,8
 
OUTPUT = console
GENERIC_SOURCES = \
console.c
console.c \
../kbd/generic/key_buffer.c
 
ARCH_SOURCES =
 
62,7 → 63,7
$(CC) $(DEFS) $(CFLAGS) -M $(SOURCES) > Makefile.depend
 
$(OUTPUT): $(ARCH_OBJECTS) $(GENERIC_OBJECTS) $(LIBS)
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
$(LD) -T $(LIBC_PREFIX)/arch/$(ARCH)/_link.ld -e __entry_driver $(GENERIC_OBJECTS) $(ARCH_OBJECTS) $(LIBS) $(LFLAGS) -o $@ -Map $(OUTPUT).map
 
disasm:
$(OBJDUMP) -d $(OUTPUT) >$(OUTPUT).disasm
/uspace/trunk/fb/fb.c
126,7 → 126,7
ipc_call_t call;
int vfb = vfb_no++;
 
if (vfb > 9) {
if (vfb > VFB_CONNECTIONS) {
ipc_answer_fast(iid, ELIMIT, 0,0);
return;
}
535,7 → 535,7
if(EFB==(item_new=get_free_item()))return EFB;
if( (graphics_items[item_new]=malloc(sizeof(framebuffer_descriptor_t))) ==NULL)
if( (graphics_items[item_new]=malloc(sizeof(framebuffer_descriptor_t))) == NULL)
{
return EFB;
}
/uspace/trunk/fb/fb.h
32,6 → 32,8
#include <types.h>
#include <arch/types.h>
 
#define VFB_CONNECTIONS 9
 
//void fb_init(int item,__address addr, unsigned int x, unsigned int y, unsigned int bpp, unsigned int scan);
 
#endif
/uspace/trunk/libc/include/io/stream.h
7,6 → 7,6
 
 
typedef ssize_t (*pwritefn_t)(void *, const void *, size_t);
typedef ssize_t (*preadfn_t)(void);
typedef char (*preadfn_t)(void);
 
fd_t open(const char *fname, int flags);
/uspace/trunk/libc/generic/io/stream.c
7,6 → 7,7
#include <ipc/ns.h>
#include <ipc/fb.h>
#include <ipc/services.h>
#include <console.h>
 
#define FDS 32
 
16,13 → 17,8
void * param;
} stream_t;
 
int console_phone = -1;
 
typedef struct vfb_descriptor_t {
int phone;
int vfb;
} vfb_descriptor_t;
 
 
stream_t streams[FDS] = {{0, 0, 0}};
 
/*
32,17 → 28,27
return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}*/
 
static void vfb_send_char(vfb_descriptor_t *d, char c)
static ssize_t write_stderr(void *param, const void *buf, size_t count)
{
return count;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}
 
static char read_stdin(void)
{
ipcarg_t r0,r1;
ipc_call_sync_2(d->phone, FB_PUTCHAR, d->vfb, c, &r0, &r1);
ipc_call_sync_2(console_phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1);
return r0;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}
static ssize_t write_vfb(void *param, const void *buf, size_t count)
static ssize_t write_stdout(void *param, const void *buf, size_t count)
{
int i;
ipcarg_t r0,r1;
 
for (i = 0; i < count; i++)
vfb_send_char((vfb_descriptor_t *) param, ((char *) buf)[i]);
ipc_call_sync_2(console_phone, CONSOLE_PUTCHAR, 0, ((const char *)buf)[i], &r0, &r1);
return count;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
49,39 → 55,42
}
 
 
static ssize_t write_stderr(void *param, const void *buf, size_t count)
{
return count;
//return (ssize_t) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, (sysarg_t) count);
}
 
 
stream_t open_vfb(void)
static stream_t open_stdin(void)
{
stream_t stream;
vfb_descriptor_t *vfb;
int phoneid;
int res;
ipcarg_t vfb_no;
while ((phoneid = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0)) < 0) {
volatile int a;
for (a = 0; a < 1048576; a++);
if (console_phone < 0) {
while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
volatile int a;
for (a = 0; a < 1048576; a++);
}
}
ipc_call_sync(phoneid, FB_GET_VFB, 0, &vfb_no);
vfb = malloc(sizeof(vfb_descriptor_t));
stream.r = read_stdin;
stream.param = 0;
return stream;
}
 
static stream_t open_stdout(void)
{
stream_t stream;
int res;
vfb->phone = phoneid;
vfb->vfb = vfb_no;
if (console_phone < 0) {
while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) {
volatile int a;
for (a = 0; a < 1048576; a++);
}
}
stream.w = write_vfb;
stream.param = vfb;
stream.w = write_stdout;
stream.param = 0;
return stream;
}
 
 
fd_t open(const char *fname, int flags)
{
int c = 0;
92,7 → 101,7
return EMFILE;
if (!strcmp(fname, "stdin")) {
streams[c].r = (preadfn_t)1;
streams[c] = open_stdin();
return c;
}
99,7 → 108,7
if (!strcmp(fname, "stdout")) {
//streams[c].w = write_stdout;
//return c;
streams[c] = open_vfb();
streams[c] = open_stdout();
return c;
}
/uspace/trunk/libc/Makefile
31,6 → 31,7
 
LIBC_PREFIX = .
SOFTINT_PREFIX = ../softint
CONSOLE_PREFIX = ../console
 
## Setup toolchain
#
37,6 → 38,8
 
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS += -I$(CONSOLE_PREFIX)
 
## Sources
#