Changeset 6d9c49a in mainline


Ignore:
Timestamp:
2006-03-13T19:39:30Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45d6add
Parents:
78a95d6f
Message:

Added kernel IPC functionality.

Files:
3 added
17 edited

Legend:

Unmodified
Added
Removed
  • Makefile

    r78a95d6f r6d9c49a  
    4545#
    4646
    47 DEFS = -D$(ARCH) -DARCH=\"$(ARCH)\" -DRELEASE=\"$(RELEASE)\" "-DNAME=\"$(NAME)\""
     47DEFS = -D$(ARCH) -DARCH=\"$(ARCH)\" -DRELEASE=\"$(RELEASE)\" "-DNAME=\"$(NAME)\"" -DKERNEL
    4848CFLAGS = -fno-builtin -fomit-frame-pointer -Wall -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -nostdlib -nostdinc -Igeneric/include/
    4949LFLAGS = -M
     
    134134        generic/src/synch/semaphore.c \
    135135        generic/src/synch/waitq.c \
    136         generic/src/smp/ipi.c
     136        generic/src/smp/ipi.c \
     137        generic/src/ipc/ipc.c
    137138
    138139## Test sources
  • arch/amd64/include/types.h

    r78a95d6f r6d9c49a  
    4949
    5050typedef __u64 __native;
     51typedef __s64 __snative;
    5152
    5253typedef struct page_specifier pte_t;
  • arch/amd64/src/asm_utils.S

    r78a95d6f r6d9c49a  
    208208        swapgs
    209209
     210        sti
    210211        movq %r9, %rcx      # Exchange last parameter as a third
    211212        call syscall_handler
    212        
     213        cli                 # We will be touching stack pointer
     214               
    213215        popq %r11
    214216        popq %rcx
  • arch/amd64/src/syscall.c

    r78a95d6f r6d9c49a  
    6363
    6464/** Dispatch system call */
    65 __native syscall_handler(__native id, __native a1, __native a2, __native a3)
     65__native syscall_handler(__native a1, __native a2, __native a3,
     66                         __native id)
    6667{
    67         interrupts_enable();
    6868        if (id < SYSCALL_END)
    6969                return syscall_table[id](a1,a2,a3);
    7070        else
    7171                panic("Undefined syscall %d", id);
    72         interrupts_disable();
    7372}
  • arch/ia32/include/types.h

    r78a95d6f r6d9c49a  
    4848
    4949typedef __u32 __native;
     50typedef __s32 __native;
    5051
    5152typedef struct page_specifier pte_t;
  • arch/ia32/src/interrupt.c

    r78a95d6f r6d9c49a  
    115115{
    116116        __native *stack = (__native *) st;
    117        
     117
     118        interrupts_enable();
    118119        if (stack[-2] < SYSCALL_END)
    119120                stack[-2] = syscall_table[stack[-2]](stack[-5], stack[-3], stack[-4]);
    120121        else
    121122                panic("Undefined syscall %d", stack[-2]);
     123        interrupts_disable();
    122124}
    123125
  • arch/ia64/include/types.h

    r78a95d6f r6d9c49a  
    1 /*
     1
    22 * Copyright (C) 2005 Jakub Jermar
    33 * All rights reserved.
     
    4848
    4949typedef __u64 __native;
     50typedef __s64 __native;
    5051
    5152typedef struct pte pte_t;
  • arch/mips32/include/types.h

    r78a95d6f r6d9c49a  
    4949
    5050typedef __u32 __native;
     51typedef __s32 __snative;
    5152
    5253typedef struct pte pte_t;
  • arch/mips32/src/exception.c

    r78a95d6f r6d9c49a  
    134134static void syscall_exception(int n, struct exception_regdump *pstate)
    135135{
     136        interrupts_enable();
    136137        if (pstate->a3 < SYSCALL_END)
    137138                pstate->v0 = syscall_table[pstate->a3](pstate->a0,
     
    140141        else
    141142                panic("Undefined syscall %d", pstate->a3);
     143        interrupts_disable();
    142144        pstate->epc += 4;
    143145}
  • arch/sparc64/include/types.h

    r78a95d6f r6d9c49a  
    4848
    4949typedef __u64 __native;
     50typedef __s64 __native;
    5051
    5152typedef struct pte pte_t;
  • generic/include/mm/page.h

    r78a95d6f r6d9c49a  
    3333#include <arch/types.h>
    3434#include <typedefs.h>
     35#include <memstr.h>
    3536
    3637#define PAGE_CACHEABLE_SHIFT            0
     
    6061#define PAGE_GLOBAL             (1<<PAGE_GLOBAL_SHIFT)
    6162
     63
     64/* TODO - check that userspace is OK, platform specific functions etc */
     65static inline void copy_to_uspace(void *dst, void *src, count_t cnt)
     66{
     67        memcpy(dst, src, cnt);
     68}
     69
     70static inline void copy_to_kernel(void *dst, void *src, count_t cnt)
     71{
     72        memcpy(dst, src, cnt);
     73}
     74
    6275/** Operations to manipulate page mappings. */
    6376struct page_mapping_operations {
  • generic/include/proc/task.h

    r78a95d6f r6d9c49a  
    3333#include <synch/spinlock.h>
    3434#include <adt/list.h>
     35#include <ipc/ipc.h>
    3536
    3637/** Task structure. */
     
    4041        link_t tasks_link;      /**< Link to other tasks within the system. */
    4142        as_t *as;               /**< Address space. */
     43        answerbox_t answerbox;  /**< Communication endpoint */
     44        phone_t phones[IPC_MAX_PHONES];
    4245};
    4346
  • generic/include/syscall/syscall.h

    r78a95d6f r6d9c49a  
    3030#define __SYSCALL_H__
    3131
    32 #include <typedefs.h>
    33 
    3432typedef enum {
    3533        SYS_CTL = 0,
    3634        SYS_IO  = 1,
     35        SYS_IPC_CALL = 2,
     36        SYS_IPC_ANSWER = 3,
     37        SYS_IPC_WAIT = 4,
    3738        SYSCALL_END
    3839} syscall_t;
    3940
    40 typedef int (*syshandler_t)();
     41#ifdef KERNEL
    4142
    42 extern int sys_ctl(void);
    43 extern int sys_io(int fd, const void *buf, size_t count);
     43#include <arch/types.h>
     44#include <typedefs.h>
     45
     46typedef __native (*syshandler_t)();
    4447
    4548extern syshandler_t syscall_table[SYSCALL_END];
    4649
    4750#endif
     51
     52#endif
  • generic/src/main/kinit.c

    r78a95d6f r6d9c49a  
    139139        interrupts_enable();
    140140
     141        ipc_create_phonecompany();
     142
    141143        if (config.init_size > 0) {
    142144                /*
  • generic/src/main/main.c

    r78a95d6f r6d9c49a  
    5555#include <arch/faddr.h>
    5656#include <typedefs.h>
     57#include <ipc/ipc.h>
    5758
    5859#ifdef CONFIG_SMP
     
    191192        if (config.init_size > 0)
    192193                printf("config.init_addr=%P, config.init_size=%d\n", config.init_addr, config.init_size);
    193 
     194       
     195        ipc_init();
    194196        /*
    195197         * Create kernel task.
  • generic/src/proc/task.c

    r78a95d6f r6d9c49a  
    3636#include <panic.h>
    3737#include <adt/list.h>
     38#include <ipc/ipc.h>
     39#include <memstr.h>
    3840
    3941SPINLOCK_INITIALIZE(tasks_lock);
     
    7173        list_initialize(&ta->tasks_link);
    7274        ta->as = as;
     75
     76        ipc_answerbox_init(&ta->answerbox);
     77        memsetb((__address)&ta->phones, sizeof(ta->phones[0])*IPC_MAX_PHONES, 0);
     78        if (ipc_central_box)
     79                ipc_phone_init(&ta->phones[0], ipc_central_box);
    7380       
    7481        ipl = interrupts_disable();
  • generic/src/syscall/syscall.c

    r78a95d6f r6d9c49a  
    3131#include <print.h>
    3232#include <putchar.h>
     33#include <ipc/ipc.h>
     34#include <errno.h>
     35#include <proc/task.h>
     36#include <arch.h>
     37#include <debug.h>
    3338
    34 int sys_ctl(void) {
     39static __native sys_ctl(void) {
    3540        printf("Thread finished\n");
    3641        thread_exit();
     
    3944}
    4045
    41 int sys_io(int fd, const void * buf, size_t count) {
     46static __native sys_io(int fd, const void * buf, size_t count) {
    4247       
    4348        // TODO: buf sanity checks and a lot of other stuff ...
     
    5156}
    5257
     58/** Send a call over syscall
     59 *
     60 * @return Call identification, returns -1 on fatal error,
     61           -2 on 'Too many async request, handle answers first
     62 */
     63static __native sys_ipc_call(__native phoneid, __native arg1, __native arg2)
     64{
     65        call_t *call;
     66        phone_t *phone;
     67
     68        if (phoneid >= IPC_MAX_PHONES)
     69                return -ENOENT;
     70
     71        phone = &TASK->phones[phoneid];
     72        if (!phone->callee)
     73                return -ENOENT;
     74
     75
     76        /* TODO: Check that we did not exceed system imposed maximum
     77         * of asynchrnously sent messages
     78         * - the userspace should be able to handle it correctly
     79         */
     80        call = ipc_call_alloc();
     81        call->data[0] = arg1;
     82        call->data[1] = arg2;
     83        ipc_call(phone, call);
     84
     85        return (__native) call;
     86}
     87
     88/** Send IPC answer */
     89static __native sys_ipc_answer(__native callid, __native arg1, __native arg2)
     90{
     91        call_t *call;
     92
     93        /* Check that the user is not sending us answer callid */
     94        ASSERT(! (callid & 1));
     95        /* TODO: Check that the callid is in the dispatch table */
     96        call = (call_t *) callid;
     97
     98        call->data[0] = arg1;
     99        call->data[1] = arg2;
     100
     101        ipc_answer(&TASK->answerbox, call);
     102        return 0;
     103}
     104
     105/** Wait for incoming ipc call or answer
     106 *
     107 * @param result
     108 * @param flags
     109 * @return Callid, if callid & 1, then the call is answer
     110 */
     111static __native sys_ipc_wait_for_call(__native *calldata, __native flags)
     112{
     113        call_t *call;
     114       
     115        call = ipc_wait_for_call(&TASK->answerbox, flags);
     116        copy_to_uspace(calldata, &call->data, sizeof(__native) * IPC_CALL_LEN);
     117
     118        if (call->flags & IPC_CALL_ANSWERED)
     119                return ((__native)call) | 1;
     120        return (__native)call;
     121}
     122
     123
    53124syshandler_t syscall_table[SYSCALL_END] = {
    54125        sys_ctl,
    55         sys_io
     126        sys_io,
     127        sys_ipc_call,
     128        sys_ipc_answer,
     129        sys_ipc_wait_for_call
    56130};
Note: See TracChangeset for help on using the changeset viewer.