Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3423 → Rev 3424

/branches/tracing/uspace/lib/libfs/libfs.c
160,7 → 160,7
len = 0;
while ((next <= last) && (ops->plb_get_char(next) != '/')) {
if (len + 1 == NAME_MAX) {
/* comopnent length overflow */
/* component length overflow */
ipc_answer_0(rid, ENAMETOOLONG);
goto out;
}
/branches/tracing/uspace/lib/libc/include/stdio.h
49,7 → 49,7
int n; \
n = snprintf(buf, sizeof(buf), fmt, ##__VA_ARGS__); \
if (n > 0) \
(void) __SYSCALL3(SYS_IO, 1, (sysarg_t) buf, strlen(buf)); \
(void) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, strlen(buf)); \
}
 
extern int getchar(void);
/branches/tracing/uspace/lib/libc/include/task.h
40,6 → 40,7
typedef uint64_t task_id_t;
 
extern task_id_t task_get_id(void);
extern int task_spawn(void *image, size_t size);
 
#endif
 
/branches/tracing/uspace/lib/libc/include/libc.h
49,7 → 49,6
__syscall(p1, p2, p3, p4, p5, p6,id)
 
extern void __main(void);
extern void __io_init(void);
extern void __exit(void);
 
#endif
/branches/tracing/uspace/lib/libc/include/io/stream.h
39,8 → 39,8
 
#define EMFILE -17
 
extern void open_stdin(void);
extern void open_stdout(void);
extern void open_console(void);
extern void klog_update(void);
 
extern ssize_t read_stdin(void *, size_t);
extern ssize_t write_stdout(const void *, size_t);
/branches/tracing/uspace/lib/libc/include/ipc/devmap.h
0,0 → 1,99
/*
* Copyright (c) 2007 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.
*/
 
/** @addtogroup devmap
* @{
*/
 
#ifndef DEVMAP_DEVMAP_H_
#define DEVMAP_DEVMAP_H_
 
#include <ipc/ipc.h>
#include <libadt/list.h>
 
#define DEVMAP_NAME_MAXLEN 512
 
typedef enum {
DEVMAP_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
DEVMAP_DRIVER_UNREGISTER,
DEVMAP_DEVICE_REGISTER,
DEVMAP_DEVICE_UNREGISTER,
DEVMAP_DEVICE_GET_NAME,
DEVMAP_DEVICE_GET_HANDLE
} devmap_request_t;
 
/** Representation of device driver.
* Each driver is responsible for a set of devices.
*/
typedef struct {
/** Pointers to previous and next drivers in linked list */
link_t drivers;
/** Pointer to the linked list of devices controlled by
* this driver */
link_t devices;
/** Phone asociated with this driver */
ipcarg_t phone;
/** Device driver name */
char *name;
/** Futex for list of devices owned by this driver */
atomic_t devices_futex;
} devmap_driver_t;
 
/** Info about registered device
*
*/
typedef struct {
/** Pointer to the previous and next device in the list of all devices */
link_t devices;
/** Pointer to the previous and next device in the list of devices
owned by one driver */
link_t driver_devices;
/** Unique device identifier */
int handle;
/** Device name */
char *name;
/** Device driver handling this device */
devmap_driver_t *driver;
} devmap_device_t;
 
/** Interface provided by devmap.
* Every process that connects to devmap must ask one of following
* interfaces otherwise connection will be refused.
*/
typedef enum {
/** Connect as device driver */
DEVMAP_DRIVER = 1,
/** Connect as client */
DEVMAP_CLIENT,
/** Create new connection to instance of device that
* is specified by second argument of call. */
DEVMAP_CONNECT_TO_DEVICE
} devmap_interface_t;
 
#endif
 
/branches/tracing/uspace/lib/libc/include/ipc/services.h
42,7 → 42,6
SERVICE_KEYBOARD,
SERVICE_VIDEO,
SERVICE_CONSOLE,
SERVICE_RD,
SERVICE_VFS,
SERVICE_DEVMAP
} services_t;
/branches/tracing/uspace/lib/libc/generic/task.c
44,5 → 44,10
return task_id;
}
 
int task_spawn(void *image, size_t size)
{
return __SYSCALL2(SYS_TASK_SPAWN, (sysarg_t) image, (sysarg_t) size);
}
 
/** @}
*/
/branches/tracing/uspace/lib/libc/generic/fibril.c
342,4 → 342,3
 
/** @}
*/
 
/branches/tracing/uspace/lib/libc/generic/libc.c
64,14 → 64,10
_async_init();
f = fibril_setup();
__tcb_set(f->tcb);
open_console();
}
 
void __io_init(void)
{
open_stdin();
open_stdout();
}
 
void __exit(void)
{
fibril_teardown(__tcb_get()->fibril_data);
/branches/tracing/uspace/lib/libc/generic/async.c
1012,4 → 1012,3
 
/** @}
*/
 
/branches/tracing/uspace/lib/libc/generic/vfs/vfs.c
48,6 → 48,7
#include <futex.h>
#include <errno.h>
#include <string.h>
#include <ipc/devmap.h>
#include "../../srv/vfs/vfs.h"
 
int vfs_phone = -1;
102,14 → 103,49
return vfs_phone;
}
 
static int device_get_handle(char *name, dev_handle_t *handle)
{
int phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0);
if (phone < 0)
return phone;
ipc_call_t answer;
aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0,
&answer);
ipcarg_t retval = ipc_data_write_start(phone, name, strlen(name) + 1);
 
if (retval != EOK) {
async_wait_for(req, NULL);
ipc_hangup(phone);
return retval;
}
 
async_wait_for(req, &retval);
 
if (handle != NULL)
*handle = -1;
if (retval == EOK) {
if (handle != NULL)
*handle = (dev_handle_t) IPC_GET_ARG1(answer);
}
ipc_hangup(phone);
return retval;
}
 
int mount(const char *fs_name, const char *mp, const char *dev)
{
int res;
ipcarg_t rc;
aid_t req;
 
dev_handle_t dev_handle = 0; /* TODO */
 
dev_handle_t dev_handle;
res = device_get_handle(dev, &dev_handle);
if (res != EOK)
return res;
size_t mpa_len;
char *mpa = absolutize(mp, &mpa_len);
if (!mpa)
/branches/tracing/uspace/lib/libc/generic/io/stream.c
56,52 → 56,54
 
ssize_t read_stdin(void *buf, size_t count)
{
ipcarg_t r0, r1;
size_t i = 0;
 
while (i < count) {
if (async_req_0_2(console_phone, CONSOLE_GETCHAR, &r0,
&r1) < 0) {
return -1;
open_console();
if (console_phone >= 0) {
ipcarg_t r0, r1;
size_t i = 0;
while (i < count) {
if (async_req_0_2(console_phone, CONSOLE_GETCHAR, &r0, &r1) < 0)
return -1;
((char *) buf)[i++] = r0;
}
((char *) buf)[i++] = r0;
return i;
} else {
return -1;
}
return i;
}
 
ssize_t write_stdout(const void *buf, size_t count)
{
int i;
 
for (i = 0; i < count; i++)
async_msg_1(console_phone, CONSOLE_PUTCHAR,
((const char *) buf)[i]);
open_console();
if (console_phone >= 0) {
int i;
return count;
for (i = 0; i < count; i++)
async_msg_1(console_phone, CONSOLE_PUTCHAR,
((const char *) buf)[i]);
return count;
} else
return __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, count);
}
 
void open_stdin(void)
void open_console(void)
{
if (console_phone < 0) {
while ((console_phone = ipc_connect_me_to(PHONE_NS,
SERVICE_CONSOLE, 0, 0)) < 0) {
usleep(10000);
}
int phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0, 0);
if (phone >= 0)
console_phone = phone;
}
}
 
void open_stdout(void)
void klog_update(void)
{
if (console_phone < 0) {
while ((console_phone = ipc_connect_me_to(PHONE_NS,
SERVICE_CONSOLE, 0, 0)) < 0) {
usleep(10000);
}
}
(void) __SYSCALL3(SYS_KLOG, 1, NULL, 0);
}
 
int get_cons_phone(void)
{
open_console();
return console_phone;
}
 
/branches/tracing/uspace/lib/libc/arch/sparc64/src/entry.s
31,7 → 31,6
.org 0
 
.globl __entry
.globl __entry_driver
 
## User-space task entry point
#
40,18 → 39,7
sethi %hi(_gp), %l7
call __main
or %l7, %lo(_gp), %l7
call __io_init
nop
call main
nop
call __exit
nop
 
__entry_driver:
sethi %hi(_gp), %l7
call __main
or %l7, %lo(_gp), %l7
call main
nop
call __exit
nop
/branches/tracing/uspace/lib/libc/arch/ia64/src/entry.s
31,7 → 31,6
.org 0
 
.globl __entry
.globl __entry_driver
 
## User-space task entry point
#
41,17 → 40,6
mov r1 = _gp
br.call.sptk.many b0 = __main
0:
br.call.sptk.many b0 = __io_init
1:
br.call.sptk.many b0 = main
2:
br.call.sptk.many b0 = __exit
 
__entry_driver:
alloc loc0 = ar.pfs, 0, 1, 2, 0
mov r1 = _gp
br.call.sptk.many b0 = __main
0:
br.call.sptk.many b0 = main
1:
br.call.sptk.many b0 = __exit
/branches/tracing/uspace/lib/libc/arch/arm32/src/entry.s
31,7 → 31,6
.org 0
 
.global __entry
.global __entry_driver
 
## User-space task entry point
#
38,12 → 37,5
#
__entry:
bl __main
bl __io_init
bl main
bl __exit
 
__entry_driver:
bl __main
bl main
bl __exit
 
/branches/tracing/uspace/lib/libc/arch/ppc32/src/entry.s
31,7 → 31,6
.org 0
 
.globl __entry
.globl __entry_driver
 
## User-space task entry point
#
38,11 → 37,5
#
__entry:
bl __main
bl __io_init
bl main
bl __exit
 
__entry_driver:
bl __main
bl main
bl __exit
/branches/tracing/uspace/lib/libc/arch/amd64/include/atomic.h
38,11 → 38,11
#define LIBC_amd64_ATOMIC_H_
 
static inline void atomic_inc(atomic_t *val) {
asm volatile ("lock incq %0\n" : "=m" (val->count));
asm volatile ("lock incq %0\n" : "+m" (val->count));
}
 
static inline void atomic_dec(atomic_t *val) {
asm volatile ("lock decq %0\n" : "=m" (val->count));
asm volatile ("lock decq %0\n" : "+m" (val->count));
}
 
static inline long atomic_postinc(atomic_t *val)
52,7 → 52,7
asm volatile (
"movq $1, %0\n"
"lock xaddq %0, %1\n"
: "=r" (r), "=m" (val->count)
: "=r" (r), "+m" (val->count)
);
 
return r;
65,14 → 65,14
asm volatile (
"movq $-1, %0\n"
"lock xaddq %0, %1\n"
: "=r" (r), "=m" (val->count)
: "=r" (r), "+m" (val->count)
);
return r;
}
 
#define atomic_preinc(val) (atomic_postinc(val)+1)
#define atomic_predec(val) (atomic_postdec(val)-1)
#define atomic_preinc(val) (atomic_postinc(val) + 1)
#define atomic_predec(val) (atomic_postdec(val) - 1)
 
#endif
 
/branches/tracing/uspace/lib/libc/arch/amd64/src/entry.s
31,7 → 31,6
.org 0
 
.globl __entry
.globl __entry_driver
 
## User-space task entry point
#
38,11 → 37,5
#
__entry:
call __main
call __io_init
call main
call __exit
 
__entry_driver:
call __main
call main
call __exit
/branches/tracing/uspace/lib/libc/arch/mips32/include/atomic.h
64,7 → 64,7
" sc %0, %1\n"
" beq %0, %4, 1b\n" /* if the atomic operation failed, try again */
/* nop */ /* nop is inserted automatically by compiler */
: "=&r" (tmp), "=m" (val->count), "=&r" (v)
: "=&r" (tmp), "+m" (val->count), "=&r" (v)
: "i" (i), "i" (0)
);
 
/branches/tracing/uspace/lib/libc/arch/mips32/src/entry.s
52,9 → 52,6
jal __main
nop
jal __io_init
nop
jal main
nop
62,28 → 59,6
nop
.end
 
.ent __entry_driver
__entry_driver:
.frame $sp, 32, $31
.cpload $25
# Mips o32 may store its arguments on stack, make space (16 bytes),
# so that it could work with -O0
# Make space additional 16 bytes for the stack frame
 
addiu $sp, -32
.cprestore 16 # Allow PIC code
jal __main
nop
jal main
nop
jal __exit
nop
.end
# Alignment of output section data to 0x4000
.section .data
.align 14
/branches/tracing/uspace/lib/libc/arch/ia32/include/atomic.h
36,11 → 36,11
#define LIBC_ia32_ATOMIC_H_
 
static inline void atomic_inc(atomic_t *val) {
asm volatile ("lock incl %0\n" : "=m" (val->count));
asm volatile ("lock incl %0\n" : "+m" (val->count));
}
 
static inline void atomic_dec(atomic_t *val) {
asm volatile ("lock decl %0\n" : "=m" (val->count));
asm volatile ("lock decl %0\n" : "+m" (val->count));
}
 
static inline long atomic_postinc(atomic_t *val)
50,7 → 50,7
asm volatile (
"movl $1, %0\n"
"lock xaddl %0, %1\n"
: "=r" (r), "=m" (val->count)
: "=r" (r), "+m" (val->count)
);
 
return r;
63,14 → 63,14
asm volatile (
"movl $-1, %0\n"
"lock xaddl %0, %1\n"
: "=r" (r), "=m" (val->count)
: "=r" (r), "+m" (val->count)
);
return r;
}
 
#define atomic_preinc(val) (atomic_postinc(val)+1)
#define atomic_predec(val) (atomic_postdec(val)-1)
#define atomic_preinc(val) (atomic_postinc(val) + 1)
#define atomic_predec(val) (atomic_postdec(val) - 1)
 
#endif
 
/branches/tracing/uspace/lib/libc/arch/ia32/include/config.h
36,7 → 36,7
#define LIBC_ia32_CONFIG_H_
 
#define PAGE_WIDTH 12
#define PAGE_SIZE (1<<PAGE_WIDTH)
#define PAGE_SIZE (1 << PAGE_WIDTH)
#define PAGE_COLOR_BITS 0 /* dummy */
 
#endif
/branches/tracing/uspace/lib/libc/arch/ia32/src/entry.s
31,7 → 31,6
.org 0
 
.globl __entry
.globl __entry_driver
 
## User-space task entry point
#
44,17 → 43,5
# Do not set %gs, it contains descriptor that can see TLS
call __main
call __io_init
call main
call __exit
__entry_driver:
mov %ss, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
# Do not set %gs, it contains descriptor that can see TLS
call __main
call main
call __exit
/branches/tracing/uspace/lib/libc/arch/ia32/src/syscall.S
53,4 → 53,3
popl %esi
popl %ebx
ret