Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4346 → Rev 4347

/branches/dynload/uspace/lib/libc/include/ddi.h
37,6 → 37,7
 
#include <task.h>
 
extern int device_assign_devno(void);
extern int physmem_map(void *, void *, unsigned long, int);
extern int iospace_enable(task_id_t, void *, unsigned long);
extern int preemption_control(int);
/branches/dynload/uspace/lib/libc/include/console.h
37,10 → 37,21
 
#include <console/style.h>
#include <console/color.h>
#include <bool.h>
 
extern void console_open(bool);
extern void console_close(void);
 
extern int console_phone_get(bool);
extern void console_wait(void);
 
extern void console_clear(void);
extern void console_goto(int, int);
extern void console_putchar(int);
extern ssize_t console_write(const char *buf, size_t nbyte);
extern void console_putstr(const char *s);
extern void console_flush(void);
 
extern int console_get_size(int *, int *);
extern void console_set_style(int);
extern void console_set_color(int, int, int);
47,6 → 58,8
extern void console_set_rgb_color(int, int);
extern void console_cursor_visibility(int);
 
extern void console_kcon_enable(void);
 
#endif
/** @}
/branches/dynload/uspace/lib/libc/include/stdio.h
69,6 → 69,7
 
extern int puts(const char *);
extern int putchar(int);
extern int fflush(FILE *);
 
extern int printf(const char *, ...);
extern int asprintf(char **, const char *, ...);
/branches/dynload/uspace/lib/libc/include/io/stream.h
39,17 → 39,13
 
#define EMFILE -17
 
extern void open_console(void);
extern void close_console(void);
extern void klog_update(void);
 
extern ssize_t read_stdin(void *, size_t);
extern ssize_t write_stdout(const void *, size_t);
extern ssize_t write_stderr(const void *, size_t);
extern int flush_stdout(void);
 
extern int get_console_phone(void);
extern void console_wait(void);
 
#endif
 
/** @}
/branches/dynload/uspace/lib/libc/include/event.h
0,0 → 1,46
/*
* Copyright (c) 2009 Jakub Jermar
* 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.
*/
 
/** @addtogroup libc
* @{
*/
/** @file
*/
 
#ifndef LIBC_EVENT_H_
#define LIBC_EVENT_H_
 
#include <kernel/event/event_types.h>
#include <ipc/ipc.h>
 
extern int event_subscribe(event_type_t, ipcarg_t);
 
#endif
 
/** @}
*/
/branches/dynload/uspace/lib/libc/include/ipc/console.h
40,6 → 40,7
typedef enum {
CONSOLE_GETKEY = IPC_FIRST_USER_METHOD,
CONSOLE_PUTCHAR,
CONSOLE_WRITE,
CONSOLE_CLEAR,
CONSOLE_GOTO,
CONSOLE_GETSIZE,
47,7 → 48,8
CONSOLE_SET_STYLE,
CONSOLE_SET_COLOR,
CONSOLE_SET_RGB_COLOR,
CONSOLE_CURSOR_VISIBILITY
CONSOLE_CURSOR_VISIBILITY,
CONSOLE_KCON_ENABLE
} console_request_t;
 
#endif
/branches/dynload/uspace/lib/libc/generic/ddi.c
41,6 → 41,16
#include <libarch/config.h>
#include <kernel/ddi/ddi_arg.h>
 
/** Return unique device number.
*
* @return New unique device number.
*
*/
int device_assign_devno(void)
{
return __SYSCALL0(SYS_DEVICE_ASSIGN_DEVNO);
}
 
/** Map piece of physical memory to task.
*
* Caller of this function must have the CAP_MEM_MANAGER capability.
/branches/dynload/uspace/lib/libc/generic/kbd.c
37,15 → 37,16
#include <kbd/kbd.h>
#include <ipc/ipc.h>
#include <ipc/console.h>
#include <console.h>
#include <async.h>
 
int kbd_get_event(kbd_event_t *ev)
{
int console_phone = get_console_phone();
int cons_phone = console_phone_get(true);
ipcarg_t r0, r1, r2, r3;
int rc;
 
rc = async_req_0_4(console_phone, CONSOLE_GETKEY, &r0, &r1, &r2, &r3);
rc = async_req_0_4(cons_phone, CONSOLE_GETKEY, &r0, &r1, &r2, &r3);
if (rc < 0)
return -1;
 
/branches/dynload/uspace/lib/libc/generic/console.c
1,4 → 1,6
/*
* Copyright (c) 2006 Josef Cejka
* Copyright (c) 2006 Jakub Vana
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
35,29 → 37,208
#include <async.h>
#include <io/stream.h>
#include <ipc/console.h>
#include <ipc/services.h>
#include <errno.h>
#include <string.h>
#include <console.h>
 
static int console_phone = -1;
 
/** Size of cbuffer. */
#define CBUFFER_SIZE 256
 
/** Buffer for writing characters to the console. */
static char cbuffer[CBUFFER_SIZE];
 
/** Pointer to end of cbuffer. */
static char *cbuffer_end = cbuffer + CBUFFER_SIZE;
 
/** Pointer to first available field in cbuffer. */
static char *cbp = cbuffer;
 
static ssize_t cons_write(const char *buf, size_t nbyte);
static void cons_putchar(int c);
 
static void cbuffer_flush(void);
static void cbuffer_drain(void);
static void cbuffer_putc(int c);
 
 
void console_open(bool blocking)
{
if (console_phone < 0) {
int phone;
if (blocking) {
phone = ipc_connect_me_to_blocking(PHONE_NS,
SERVICE_CONSOLE, 0, 0);
} else {
phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0,
0);
}
if (phone >= 0)
console_phone = phone;
}
}
 
void console_close(void)
{
if (console_phone >= 0) {
if (ipc_hangup(console_phone) == 0) {
console_phone = -1;
}
}
}
 
int console_phone_get(bool blocking)
{
if (console_phone < 0)
console_open(blocking);
return console_phone;
}
 
void console_wait(void)
{
while (console_phone < 0)
console_open(true);
}
 
void console_clear(void)
{
int cons_phone = get_console_phone();
int cons_phone = console_phone_get(true);
 
cbuffer_drain();
async_msg_0(cons_phone, CONSOLE_CLEAR);
}
 
void console_goto(int row, int col)
{
int cons_phone = get_console_phone();
int cons_phone = console_phone_get(true);
 
cbuffer_flush();
async_msg_2(cons_phone, CONSOLE_GOTO, row, col);
}
 
void console_putchar(int c)
{
cbuffer_putc(c);
}
 
/** Write all data from output buffer to the console. */
static void cbuffer_flush(void)
{
int rc;
int len;
 
len = cbp - cbuffer;
 
while (len > 0) {
rc = cons_write(cbuffer, cbp - cbuffer);
if (rc < 0)
return;
 
len -= rc;
}
 
cbp = cbuffer;
}
 
/** Drop all data in console output buffer. */
static void cbuffer_drain(void)
{
cbp = cbuffer;
}
 
/** Write one character to the output buffer. */
static inline void cbuffer_putc(int c)
{
if (cbp == cbuffer_end)
cbuffer_flush();
 
*cbp++ = c;
 
if (c == '\n')
cbuffer_flush();
}
 
/** Write one character to the console via IPC. */
static void cons_putchar(int c)
{
int cons_phone = console_phone_get(true);
async_msg_1(cons_phone, CONSOLE_PUTCHAR, c);
}
 
/** Write characters to the console via IPC. */
static ssize_t cons_write(const char *buf, size_t nbyte)
{
int cons_phone = console_phone_get(true);
ipcarg_t rc;
ipc_call_t answer;
aid_t req;
 
async_serialize_start();
req = async_send_0(cons_phone, CONSOLE_WRITE, &answer);
rc = ipc_data_write_start(cons_phone, (void *) buf, nbyte);
 
if (rc != EOK) {
async_wait_for(req, NULL);
async_serialize_end();
return (ssize_t) rc;
}
 
async_wait_for(req, &rc);
async_serialize_end();
 
if (rc == EOK)
return (ssize_t) IPC_GET_ARG1(answer);
else
return -1;
}
 
/** Write characters to the console. */
ssize_t console_write(const char *buf, size_t nbyte)
{
size_t left;
 
left = nbyte;
 
while (left > 0) {
cbuffer_putc(*buf++);
--left;
}
 
return nbyte;
}
 
/** Write a NULL-terminated string to the console. */
void console_putstr(const char *s)
{
size_t len;
ssize_t rc;
 
len = strlen(s);
while (len > 0) {
rc = console_write(s, len);
if (rc < 0)
return; /* Error */
s += rc;
len -= rc;
}
}
 
/** Flush all output to the console. */
void console_flush(void)
{
int cons_phone = get_console_phone();
int cons_phone = console_phone_get(false);
 
cbuffer_flush();
async_msg_0(cons_phone, CONSOLE_FLUSH);
}
 
int console_get_size(int *rows, int *cols)
{
int cons_phone = get_console_phone();
int cons_phone = console_phone_get(true);
ipcarg_t r, c;
int rc;
 
71,27 → 252,43
 
void console_set_style(int style)
{
int cons_phone = get_console_phone();
int cons_phone = console_phone_get(true);
 
cbuffer_flush();
async_msg_1(cons_phone, CONSOLE_SET_STYLE, style);
}
 
void console_set_color(int fg_color, int bg_color, int flags)
{
int cons_phone = get_console_phone();
int cons_phone = console_phone_get(true);
 
cbuffer_flush();
async_msg_3(cons_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
}
 
void console_set_rgb_color(int fg_color, int bg_color)
{
int cons_phone = get_console_phone();
int cons_phone = console_phone_get(true);
 
cbuffer_flush();
async_msg_2(cons_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
}
 
void console_cursor_visibility(int show)
{
int cons_phone = get_console_phone();
int cons_phone = console_phone_get(true);
 
cbuffer_flush();
async_msg_1(cons_phone, CONSOLE_CURSOR_VISIBILITY, show != 0);
}
 
void console_kcon_enable(void)
{
int cons_phone = console_phone_get(true);
 
cbuffer_flush();
async_msg_0(cons_phone, CONSOLE_KCON_ENABLE);
}
 
/** @}
*/
/branches/dynload/uspace/lib/libc/generic/event.c
0,0 → 1,57
/*
* Copyright (c) 2009 Jakub Jermar
* 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.
*/
 
/** @addtogroup libc
* @{
* @}
*/
 
/** @addtogroup libc
*/
/** @file
*/
 
#include <libc.h>
#include <event.h>
#include <kernel/event/event_types.h>
#include <ipc/ipc.h>
 
/** Subscribe for event notifications.
*
* @param e Event number.
* @param method Use this method for notifying me.
*
* @return Value returned by the kernel.
*/
int event_subscribe(event_type_t e, ipcarg_t method)
{
return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) e, (sysarg_t) method);
}
 
/** @}
*/
/branches/dynload/uspace/lib/libc/generic/io/io.c
97,6 → 97,8
int getchar(void)
{
unsigned char c;
 
flush_stdout();
if (read_stdin((void *) &c, 1) == 1)
return c;
103,5 → 105,11
return EOF;
}
 
int fflush(FILE *f)
{
(void) f;
return flush_stdout();
}
 
/** @}
*/
/branches/dynload/uspace/lib/libc/generic/io/stream.c
43,13 → 43,12
#include <ipc/fb.h>
#include <ipc/services.h>
#include <ipc/console.h>
#include <console.h>
#include <kbd/kbd.h>
#include <unistd.h>
#include <async.h>
#include <sys/types.h>
 
static int console_phone = -1;
 
ssize_t write_stderr(const void *buf, size_t count)
{
return count;
57,8 → 56,9
 
ssize_t read_stdin(void *buf, size_t count)
{
open_console();
if (console_phone >= 0) {
int cons_phone = console_phone_get(false);
 
if (cons_phone >= 0) {
kbd_event_t ev;
int rc;
size_t i = 0;
79,55 → 79,36
 
ssize_t write_stdout(const void *buf, size_t count)
{
open_console();
if (console_phone >= 0) {
int cons_phone = console_phone_get(false);
int left, rc;
 
if (cons_phone >= 0) {
int i;
for (i = 0; i < count; i++)
async_msg_1(console_phone, CONSOLE_PUTCHAR,
((const char *) buf)[i]);
 
left = count;
while (left > 0) {
rc = console_write(buf, left);
if (rc < 0)
break;
buf += rc;
left -= rc;
}
 
return count;
} else
return __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, count);
}
 
void open_console(void)
int flush_stdout(void)
{
if (console_phone < 0) {
int phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0, 0);
if (phone >= 0)
console_phone = phone;
}
console_flush();
return 0;
}
 
void close_console(void)
{
if (console_phone >= 0) {
if (ipc_hangup(console_phone) == 0) {
console_phone = -1;
}
}
}
 
void klog_update(void)
{
(void) __SYSCALL3(SYS_KLOG, 1, NULL, 0);
}
 
int get_console_phone(void)
{
if (console_phone < 0)
console_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_CONSOLE, 0, 0);
return console_phone;
}
 
void console_wait(void)
{
while (console_phone < 0)
get_console_phone();
}
 
/** @}
*/
/branches/dynload/uspace/lib/libc/Makefile
51,6 → 51,7
generic/as.c \
generic/cap.c \
generic/console.c \
generic/event.c \
generic/mem.c \
generic/string.c \
generic/fibril.c \
/branches/dynload/uspace/lib/libc/arch/sparc64/_link.ld.in
31,13 → 31,11
_tdata_start = .;
*(.tdata);
_tdata_end = .;
} :data
.tbss : {
_tbss_start = .;
*(.tbss);
_tbss_end = .;
} :data
_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
_tls_alignment = ALIGNOF(.tdata);
.bss : {
*(.sbss);
*(COMMON);
/branches/dynload/uspace/lib/libc/arch/ia64/_link.ld.in
32,13 → 32,11
_tdata_start = .;
*(.tdata);
_tdata_end = .;
} :data
.tbss : {
_tbss_start = .;
*(.tbss);
_tbss_end = .;
} :data
_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
_tls_alignment = ALIGNOF(.tdata);
.bss : {
*(.sbss);
*(.scommon);
/branches/dynload/uspace/lib/libc/arch/arm32/_link.ld.in
28,13 → 28,11
_tdata_start = .;
*(.tdata);
_tdata_end = .;
} :data
.tbss : {
_tbss_start = .;
*(.tbss);
_tbss_end = .;
} :data
_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
_tls_alignment = ALIGNOF(.tdata);
.bss : {
*(.sbss);
*(.scommon);
/branches/dynload/uspace/lib/libc/arch/ppc32/_link.ld.in
27,13 → 27,11
_tdata_start = .;
*(.tdata);
_tdata_end = .;
} :data
.tbss : {
_tbss_start = .;
*(.tbss);
_tbss_end = .;
} :data
_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
_tls_alignment = ALIGNOF(.tdata);
.bss : {
*(.sbss);
*(COMMON);
/branches/dynload/uspace/lib/libc/arch/amd64/_link.ld.in
26,13 → 26,11
_tdata_start = .;
*(.tdata);
_tdata_end = .;
} :data
.tbss : {
_tbss_start = .;
*(.tbss);
_tbss_end = .;
} :data
_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
_tls_alignment = ALIGNOF(.tdata);
.bss : {
*(COMMON);
*(.bss);
/branches/dynload/uspace/lib/libc/arch/mips32/_link.ld.in
33,13 → 33,11
_tdata_start = .;
*(.tdata);
_tdata_end = .;
} :data
.tbss : {
_tbss_start = .;
*(.tbss);
_tbss_end = .;
} :data
_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
_tls_alignment = ALIGNOF(.tdata);
 
.sbss : {
*(.scommon);
/branches/dynload/uspace/lib/libc/arch/ia32/_link.ld.in
26,13 → 26,11
_tdata_start = .;
*(.tdata);
_tdata_end = .;
} :data
.tbss : {
_tbss_start = .;
*(.tbss);
_tbss_end = .;
} :data
_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
_tls_alignment = ALIGNOF(.tdata);
.bss : {
*(COMMON);
*(.bss);