view src/impl/ReadSyscallImpl.cbc @ 379:a0d6f7124b9b

add ReadSyscall interface
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 13 Jul 2020 16:10:06 +0900
parents
children 8f2bc03fcbb2
line wrap: on
line source

#include "../context.h"
#interface "ReadSyscall.h"

// ----
// typedef struct ReadSyscallImpl <Type, Isa> impl ReadSyscall {
//   __code next(....);
// } ReadSyscallImpl;
// ----

ReadSyscall* createReadSyscallImpl(struct Context* cbc_context) {
    struct ReadSyscall* read_syscall  = new ReadSyscall();
    struct ReadSyscallImpl* read_syscall_impl = new ReadSyscallImpl();
    read_syscall->read_syscall = (union Data*)read_syscall_impl;
    read_syscall->consoleread = C_consolereadReadSyscallImpl;
    read_syscall->consoleread1 = C_consoleread1ReadSyscallImpl;
    read_syscall->consoleread2 = C_consoleread2ReadSyscallImpl;
    read_syscall->piperead = C_pipereadReadSyscallImpl;
    read_syscall->piperead1 = C_piperead1ReadSyscallImpl;
    read_syscall->piperead2 = C_piperead2ReadSyscallImpl;
    read_syscall->piperead3 = C_piperead3ReadSyscallImpl;
    read_syscall->fileread = C_filereadReadSyscallImpl;
    read_syscall->fileread1 = C_fileread1ReadSyscallImpl;
    return read_syscall;
}
__code consolereadReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct inode* ip, char* dst, int n, __code next(int ret, ...)) {

    goto next(ret, ...);
}

__code consoleread1ReadSyscallImpl(struct ReadSyscallImpl* read_syscall,int n, int target, char* dst, struct inode* ip,  __code next(...)) {

    goto next(...);
}

__code consoleread2ReadSyscallImpl(struct ReadSyscallImpl* read_syscall,struct inode* ip, __code next(...)) {

    goto next(...);
}

__code pipereadReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct pipe* p,char* addr, int n,  __code next(int ret,...)) {

    goto next(ret,...);
}

__code piperead1ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct pipe* p, __code next(int ret,...)) {

    goto next(ret,...);
}

__code piperead2ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, int i, int n, struct pipe* p, char* addr, __code next(int ret,...)) {

    goto next(ret,...);
}

__code piperead3ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct pipe* p, int i, __code next(int ret,...)) {

    goto next(ret,...);
}

__code filereadReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct file* f, char* addr, int n, __code next(int ret, ...)) {
    if (f->readable == 0) {
        ret = -1;
        goto next(ret);
    }

    if (f->type == FD_PIPE) {
        goto read_syscall->piperead(f->pipe, addr, n, next);
    }

    if (f->type == FD_INODE) {
        ilock(f->ip);
        goto read_syscall->cbc_readi(f->ip, addr, f->off, n, readsys_call->fileread1);
    }

    goto cbc_panic("fileread");
}

__code fileread1ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct file* f, int ret, __code next(ret, ...)) {
    if (ret > 0)
        f->off += ret;
    iunlock(f->ip);
    goto next(ret);
}