Exemple #1
0
static int do_open(void *msg, anvil_msginfo_t *msg_info) {

    struct anvil_open_msg   *openmsg;
    char                    name[1024];
    file_struct             *pfile;
    int                     found;
    fcb_t                   *fcb;
#if 0
    openmsg = (struct anvil_open_msg *)msg;

    if (openmsg->pathlen > 1023) {
        msg_reply(msg_info->pid, msg_info->tid, ENAMETOOLONG, NULL, 0);
        return -1;
    }

    msg_peek(msg_info->pid, msg_info->tid, name, openmsg->pathlen, sizeof(struct anvil_open_msg));
    name[openmsg->pathlen] = 0;
    anvil_syslog(0, "INITRD: do_open file <%s>\n", name);

    pfile = (file_struct *)dlist_peek_head(&filelist);
    found = 0;
    while (pfile) {
        if (!strcmp(pfile->filename, name)) {
            anvil_syslog(0, "*** INITRD: Found file %s\n", pfile->filename);
            found = 1;
            break; /* Break so that pfile is valid */
        }
        pfile = (file_struct *)dlist_peek_next(&filelist, (dlist_item_t *)pfile);
    }

    if (!found) {
        anvil_syslog(0, "INITRD: do_open couldn't find %s\n", name);
        msg_reply(msg_info->pid, msg_info->tid, ENOENT, NULL, 0);
        return -1;
    }

    fcb = (fcb_t *)malloc(sizeof(fcb_t));
    fcb->fs = pfile;
    fcb->pos = 0;
    fcb->data = pfile->addr;

    //anvil_syslog(0, "INITRD: do_open file <%s> fcb=%016lx\n", name, fcb);

    msg_port_allow(msg_info->pid, msg_info->tid, (void *)fcb, NULL);

    msg_reply(msg_info->pid, msg_info->tid, 0, NULL, 0);
#endif
    return 0;
}
Exemple #2
0
pid_t setsid(void)
{
    anvil_procinfo_t    info;
    int                 err;
    anvil_syslog(0, "%s\n", __FUNCTION__);
    memset(&info, 0, sizeof(info));
    if ((err = anvil_procinfo(0, &info, _ANVIL_SETSID)) < 0)
    {
        anvil_syslog(0, "%s returning %d\n", __FUNCTION__, err);
        errno = -err;
        return -1;
    }
    anvil_syslog(0, "%s returning %d\n", __FUNCTION__, info.sid);
    return info.sid;
}
Exemple #3
0
int fexecve(int fd, char *const argv[], char *const envp[])
{
    anvil_syslog(0, "%s unimplemented\n", __FUNCTION__);
    while (1);

    return 0;
}
Exemple #4
0
PageCache::PageCache()
{
    // Create a whole bunch of pages to be in the page cache
    m_page_array = new Page[num_pages];
    anvil_syslog(0, "PageCache::PageCache: %016lx\n", m_page_array);
    m_page_data = (char *)::mmap(0, num_pages * __PAGESIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
    anvil_syslog(0, "PageCache::PageCache: %016lx %016lx\n", m_page_data, num_pages * __PAGESIZE);
    
    int i;
    for (i=0; i<num_pages; ++i)
    {
        m_page_array[i].SetAddr(&m_page_data[__PAGESIZE * i]);
        m_freelist.push_back(&m_page_array[i]);
    }
    anvil_syslog(0, "PageCache::PageCache: last %016lx\n", &m_page_data[__PAGESIZE * i]);
}
Exemple #5
0
Aw::Widget *Aw::Grid1d::DeliverEvent(const Point& point, const Event &ev) {

    grid_debug(0, "Click in gridh at %d %d\n", point.m_x, point.m_y);

    int clicked_row, clicked_column;

    // Work out whether the pointer is on a widget
    int x_pos, y_pos;

    for (auto it=m_children.begin(); it!=m_children.end(); ++it)
    {
        Point child_pos = (*it).pos;
        Size child_size = (*it).widget->getDrawSize();
        if (    child_pos.m_x + m_gap_left <= point.m_x
                && point.m_x < child_pos.m_x + child_size.m_width - m_gap_right
                && child_pos.m_y + m_gap_left <= point.m_y
                && point.m_y < child_pos.m_y + child_size.m_height - m_gap_bottom
           )
        {
            // We're in the child - translate the point to child co-ordinates
            const Point child_point(point.m_x - child_pos.m_x - m_gap_left, point.m_y - child_pos.m_y - m_gap_top);
            Widget *handled_by = (*it).widget->DeliverEvent(child_point, ev);
            if (handled_by)
            {
                return handled_by;
            }
        }
    }

    anvil_syslog(0, "No child wants the event\n");

    // Let the derived class peek at the event if it wants to - this is here
    // mainly for buttons and the like that might want to animate
    return eventHandle(point, ev);
}
Exemple #6
0
int fcntl(int fildes, int cmd, ...) {

    va_list             ap;
    int                 int_arg;
    int                 ret;

    va_start(ap, cmd);
    switch (cmd) {

        case F_DUPFD:
            int_arg = va_arg(ap, int);
            if ((ret = _Dup(0, fildes, int_arg)) < 0) {
                errno = -ret;
                ret = -1;
            }
            break;

        case F_GETFD:
        case F_SETFD:
        case F_GETOWN:
        case F_SETOWN:
        case F_GETLK:
        case F_SETLK:
        case F_SETLKW:
            anvil_syslog(0, "fcntl - NOT IMPLEMENTED fd=%d cmd=%d\n", fildes, cmd);
            ret = O_ACCMODE | O_DIRECTORY;
            break;
        case F_GETFL:
            //anvil_syslog(0, "fcntl - F_GETFL fd=%d\n", fildes);
            ret = O_ACCMODE | O_DIRECTORY;
            break;
        case F_SETFL:
            int_arg = va_arg(ap, int);
            anvil_syslog(0, "fcntl - F_SETFL fd=%d arg=%x\n", fildes, int_arg);
            ret = 0;
            break;
        default:
            ret = EINVAL;
            break;
    }
    va_end(ap);

    return ret;
}
Exemple #7
0
bool Ata::Ata::WriteSynch(int d, int64_t lba, int nblks, char *buf)
{
    if (d > m_drive_list.size())
    {
        anvil_syslog(0, "Ata::Ata::ReadSynch bad drive num %d\n", d);
        return false;
    }
    if (lba > m_drive_list[d].GetMaxLba())
    {
        anvil_syslog(0, "Ata::Ata::ReadSynch bad lba num %ld\n", lba);
        return false;
    }
    int c_num = m_drive_list[d].GetController();
    int d_num = m_drive_list[d].GetDrive();

    m_controller[c_num]->WriteSynch(d_num, lba, nblks, buf);

    return true;
}
Exemple #8
0
int closedir(DIR *dirp) {

    anvil_syslog(0, "%s %d\n", __FUNCTION__, dirp->dd_fd);

    close(dirp->dd_fd);

    free(dirp);

    return 0;
}
Exemple #9
0
void rewinddir(DIR *dirp)
{
    int ret;

    anvil_syslog(0, "%s %d\n", __FUNCTION__, dirp->dd_fd);

    if ((ret = lseek(dirp->dd_fd, 0, SEEK_SET)) < 0) {
        return;
    }
    dirp->dd_loc = dirp->dd_seek = 0;
}
Exemple #10
0
void TermBox::process_esc_seq(std::string& buf)
{
    // Look at the final char
    switch (buf[buf.size()-1])
    {
        case '[':
            anvil_syslog(0, "SWITCH TO CSI\n");
            m_state = State::csi;
            m_buf.clear();
            return;

    }
    m_state = State::norm;
}
Exemple #11
0
Inode *Ext2Inode::CreateFile(const std::string name, mode_t mode)
{
    anvil_syslog(0, "Ext2Inode::CreateFile\n");

    // Call the Filesystem to find an unused inode in the inode bitmap
    Ext2filesystem *pfs = static_cast<Ext2filesystem *>(m_fs);
    ino_t inum = pfs->AllocInode(false);

    struct ext2_inode *ext2inode = pfs->inodeGet(inum);
    ext2inode->i_links_count = 1;
    ext2inode->i_mode = (mode & ~S_IFMT) | S_IFREG;
    ext2inode->i_ctime =
    ext2inode->i_atime =
    ext2inode->i_mtime = time(NULL);

    pfs->inodePut(inum);

    anvil_syslog(0, "Inode %d allocated\n", inum);

    // Now we search the directory to see if we can find it
    Inode *new_child = SearchDirAndAct(name.c_str(), Inode::action::create, inum);

    return new_child;
}
Exemple #12
0
int do_close(void *msg, anvil_msginfo_t *msg_info) {

    fcb_t                   *fcb;
    int                     fd_ret;
    int                     pid;

    anvil_syslog(0, "do_close pid=%d fd=%d FCB=%016lx\n", msg_info->pid, fcb);

    fcb = (fcb_t *)msg_info->cookie;

    //++fcb->ref_cnt;

    msg_reply(msg_info->pid, msg_info->tid, 0, NULL, 0);

    return 0;
}
Exemple #13
0
void TermBox::writech(unsigned char ch)
{
    int pid, tid;
    getWaiter(pid, tid);
    if (pid)
    {
        char buf[100];
        memcpy(buf, m_fcb->line_disc.getKeyBuf(), m_fcb->line_disc.getKeyCnt());
        buf[m_fcb->line_disc.getKeyCnt()] = 0;
        anvil_syslog(0, "TERM-SVR: do_read un-blocking %d keys\n", m_fcb->line_disc.getKeyCnt());
        //anvil_syslog(0, "TERM-SVR: REPLYING %s\n", buf);
        msg_reply(pid, tid, 1, m_fcb->line_disc.getKeyBuf(), 1);
        m_fcb->line_disc.clearBuf(1);
        setWaiter(0, 0);
    }
}
Exemple #14
0
bool msg_callback(void *buf, anvil_msginfo_t *msg_info)
{
    // Assume that we'll handle the msg
    bool handled = true;

    //anvil_syslog(0, "msg_callback\n");

    switch (msg_info->type & ~ANVIL_NAME_LOOKUP)
    {
        case ANVIL_OPEN:
            do_open(buf, msg_info);
            break;
        case ANVIL_CLOSE:
            do_close(buf, msg_info);
            break;
        case ANVIL_DUP:
            do_dup(buf, msg_info);
            break;
        case ANVIL_READ:
            do_read(buf, msg_info);
            break;
        case ANVIL_WRITE:
            do_write(buf, msg_info);
            break;
        case ANVIL_STAT:
            do_stat(buf, msg_info);
            break;
        case ANVIL_GETATTR:
            do_getattr(buf, msg_info);
            break;
        case ANVIL_SETATTR:
            do_setattr(buf, msg_info);
            break;
        case ANVIL_GETWINSZ:
            do_getwinsz(buf, msg_info);
            break;

        default:
            handled = false;
            anvil_syslog(0, "term-svr GOT UNKNOWN MSG %d\n", msg_info->type);
            break;
    }
    return handled;
}
Exemple #15
0
int ungetc(int c, FILE *stream) {

    if (c < 0 || c > 255) {
        anvil_syslog(0, "ungetc bad char\n");
        return EOF;
    }

    /* Check that reading is allowed */
    if ((stream->__status & (_IO_READABLE | _IO_RDWRABLE)) == 0) {
        anvil_syslog(0, "ungetc not readable\n");
        stream->__status |= _IO_STATUS_ERR;
        errno = EBADF;
        return EOF;
    }

    /* There are a bunch of things that prevent writing */
    if (stream->__status & (_IO_STATUS_ERR | _IO_WIDE)) {
        anvil_syslog(0, "ungetc error or wide\n");
        stream->__status |= _IO_STATUS_ERR;
        errno = EBADF;
        return EOF;
    }

    /* Set/clear these flags just in case it's the first time through */
    stream->__status |= (_IO_READABLE | _IO_CHAR);
    stream->__status &= ~(_IO_STATUS_EOF | _IO_WRITEABLE);

    if (stream->__buf == NULL) {
        _Setbuf(stream);
    }

    /* See whether we are already using the ungetc buffer */
    if (stream->__curp_saved == NULL) {
        /* Save the current pointer */
        anvil_syslog(0, "ungetc setting buffer\n");
        stream->__curp_saved = stream->__curp;
        stream->__rdend_saved = stream->__rdend;
        stream->__curp = stream->__ungetc_buf + UNGETC_BUFSIZ;
        stream->__rdend = stream->__curp;
    }

    if (stream->__curp <= stream->__ungetc_buf) {
        anvil_syslog(0, "ungetc buffer full\n");
        return EOF;
    }

    anvil_syslog(0, "ungetc storing %c\n", (unsigned char)c);
    return *--stream->__curp = (unsigned char)c;
}
Exemple #16
0
Aw::Widget *TaskbarButton::eventHandle(const Aw::Point& point, const Aw::Event& ev)
{
    anvil_syslog(0, "Button::eventHandle()\n");

    switch (ev.getType())
    {
        case Aw::Event::Type::ButtonPress:
            //m_pressed = true;
            // todo: send draw event
            break;
        case Aw::Event::Type::ButtonRelease:
            m_pressed = !m_pressed;//false;
            // todo: send draw event
            click_callback(this, ev);
            // We handled the event
            return this;
            break;
    }
    return nullptr;
}
Exemple #17
0
static int do_stat(void *msg, anvil_msginfo_t *msg_info) {

    anvil_iovec_t           rmsg[2];
    struct anvil_stat_msg   *statmsg;
    int                     leng;
    int                     remaining;
    char                    *pdata;
    fcb_t                   *fcb;
    int64_t                 new_pos;
    struct stat             stat;

    statmsg = (struct anvil_stat_msg *)msg;

    fcb = (fcb_t *)msg_info->cookie;

    anvil_syslog(0, "do_stat FCB=%016lx\n", fcb);

    stat.st_dev = 0;
    stat.st_ino = 0;
    stat.st_mode = 0100777;
    stat.st_nlink = 1;
    stat.st_uid = 1;
    stat.st_gid = 1;
    stat.st_rdev = 0;
    stat.st_size = 100;//fcb->fs->size;
    stat.st_atime = 0;
    //stat.st_spare1;
    stat.st_mtime = 0;
    //stat.st_spare2;
    stat.st_ctime = 0;
    //stat.st_spare3;
    stat.st_blksize = 512;
    stat.st_blocks = 1;//fcb->fs->size/512+1;
    //stat.st_spare4[2];

    msg_reply(msg_info->pid, msg_info->tid, 0, &stat, sizeof(stat));

    return 0;
}
Exemple #18
0
Ata::Ata::Ata()
{
    m_controller[0] = new Controller(Controller::ATA_PORT0);
    m_controller[1] = new Controller(Controller::ATA_PORT1);

    /* Now check that the controllers are okay */
    for (int i=0; i<Controller::ATA_MAX_CONTROLLERS; ++i)
    {
        if (m_controller[i]->Probe() == false)
        {
            m_controller[i]->SetOkay(false);
        }
        else
        {
            m_controller[i]->SetOkay(true);
        }
    }

    // We now have some number of hard disks - let's enumerate them
    for (int c=0; c<2; ++c)
    {
        for (int d=0; d<2; ++d)
        {
            if (m_controller[c]->m_drivetype[d] == Controller::DriveType::ata)
            {
                int64_t nsecs;
                bool dma;
                if (m_controller[c]->Identify(d, nsecs, dma))
                {
                    Drive drive(c, d, nsecs, dma);
                    anvil_syslog(0, "<%d %d %ld %d>\n", c, d, nsecs, dma);
                    m_drive_list.push_back(drive);
                }
            }
        }
    }
}
Exemple #19
0
void Taskbar::m_OnClick(Aw::Widget *sender, Aw::Event e)
{
    std::vector<std::string> menu_items;

    for (int i=0; i<sizeof(anvil_menu_items)/sizeof(anvil_menu_items[0]); ++i)
    {
        menu_items.push_back(anvil_menu_items[i]);
    }

    anvil_syslog(0, "Taskbar::m_OnClick\n");
    if (m_menu_window == nullptr)
    {
        m_menu_window = new Aw::MenuWindow(menu_items);
        m_menu_window->show();
        m_menu_window->winFlags(0, ACE_WIN_RESIZABLE | ACE_WIN_MOVEABLE);
        m_menu_window->attach(0, 1, 22);
        //ace_win_attach()
    }
    else
    {
        delete m_menu_window;
        m_menu_window = 0;
    }
}
Exemple #20
0
Aw::Widget *TermBox::eventHandle(const Aw::Point& point, const Aw::Event& ev)
{
    //anvil_syslog(0, "TermBox::eventHandle()\n");

    if (ev.getType() != Aw::Event::Type::KeyPress)
    {
        return NULL;
    }

    int shift_nums[] = { ')', '!', '@', '#', '$', '%', '^', '&', '*', '(' };
    int keycode = ev.getKey().keycode;
    int shift_state = ev.getKey().shift_state;
    int charcode = -1;

    //anvil_syslog(0, "TermBox::eventHandle() %x %x\n", keycode, shift_state);

    if (keycode >= 'A' && keycode <= 'Z')
    {
        charcode = keycode;
        if ((shift_state & ACE_SHIFTSTATE_CTRL) == ACE_SHIFTSTATE_CTRL)
        {
            charcode = charcode - 'A' + 1;
            anvil_syslog(0, "Control %d\n", charcode);
        }
        else if ((shift_state & ACE_SHIFTSTATE_SHIFT) == 0)
        {
            charcode = charcode - 'A' + 'a';
        }
    }
    else if (keycode >= '0' && keycode <= '9')
    {
        charcode = keycode;
        if ((shift_state & ACE_SHIFTSTATE_SHIFT))
        {
            charcode = shift_nums[keycode - '0'];
        }
    }
    else if (keycode == ACE_KEY_SPACE)
    {
        charcode = ' ';
    }
    else if (keycode == ACE_KEY_ESC)
    {
        charcode = 0x1b;
    }
    else if (keycode == ACE_KEY_ENTER)
    {
        charcode = '\r';
    }
    else
    {
        if ((shift_state & ACE_SHIFTSTATE_SHIFT) == 0)
        {
            switch (keycode) {
            case ACE_KEY_LEFT:
                m_fcb->line_disc.addChar(0x1b);
                m_fcb->line_disc.addChar('[');
                m_fcb->line_disc.addChar('D');
                charcode = -1;
                break;
            case ACE_KEY_RIGHT:
                m_fcb->line_disc.addChar(0x1b);
                m_fcb->line_disc.addChar('[');
                m_fcb->line_disc.addChar('C');
                charcode = -1;
                break;
            case ACE_KEY_UP:
                m_fcb->line_disc.addChar(0x1b);
                m_fcb->line_disc.addChar('[');
                m_fcb->line_disc.addChar('A');
                charcode = -1;
                break;
            case ACE_KEY_DOWN:
                m_fcb->line_disc.addChar(0x1b);
                m_fcb->line_disc.addChar('[');
                m_fcb->line_disc.addChar('B');
                charcode = -1;
                break;
            case ACE_KEY_BACK:
                charcode = 8;
                break;
            case ACE_BACK_QUOTE:
                charcode = '`';
                break;
            case ACE_KEY_TAB:
                charcode = '\t';
                break;
            case ACE_KEY_COMMA:
                charcode = ',';
                break;
            case ACE_KEY_DOT:
                charcode = '.';
                break;
            case ACE_KEY_MINUS:
                charcode = '-';
                break;
            case ACE_KEY_QUOTE:
                charcode = '\'';
                break;
            case ACE_KEY_EQUAL:
                charcode = '=';
                break;
            case ACE_KEY_ENTER:
                charcode = '\r';
                break;
            case ACE_KEY_SLASH:
                charcode = '/';
                break;
            case ACE_KEY_BACKSLASH:
                charcode = '\\';
                break;
            case ACE_KEY_SEMICOLON:
                charcode = ';';
                break;
            case ACE_KEY_LBRACKET:
                charcode = '[';
                break;
            case ACE_KEY_RBRACKET:
                charcode = ']';
                break;
            }
        }
        else if ((shift_state & ACE_SHIFTSTATE_SHIFT) == ACE_SHIFTSTATE_SHIFT)
        {
            switch (keycode) {
            case ACE_BACK_QUOTE:
                charcode = '~';
                break;
            case ACE_KEY_TAB:
                //charcode = '\t';
                break;
            case ACE_KEY_COMMA:
                charcode = '<';
                break;
            case ACE_KEY_DOT:
                charcode = '>';
                break;
            case ACE_KEY_MINUS:
                charcode = '_';
                break;
            case ACE_KEY_QUOTE:
                charcode = '"';
                break;
            case ACE_KEY_EQUAL:
                charcode = '+';
                break;
            case ACE_KEY_ENTER:
                //charcode = '\n';
                break;
            case ACE_KEY_SLASH:
                charcode = '?';
                break;
            case ACE_KEY_BACKSLASH:
                charcode = '|';
                break;
            case ACE_KEY_SEMICOLON:
                charcode = ':';
                break;
            case ACE_KEY_LBRACKET:
                charcode = '{';
                break;
            case ACE_KEY_RBRACKET:
                charcode = '}';
                break;
            }
        }

        //anvil_syslog(0, "TERM-SVR: PRESS %d %08x\n", getevent_rpy.key.keycode, getevent_rpy.key.shift_state);
    }

    if (charcode == 5)
    {
        // Dump the line buffers
        m_screen->Dump();
    }
    else if (charcode == 12)
    {
        // Clear the entire screen
        m_screen->ClearAll();
    }
    else if (charcode != -1)
    {
        m_fcb->line_disc.addChar(charcode);
    }

    return this;
}
Exemple #21
0
void TermBox::putChar(unsigned char byte)
{
    anvil_syslog(0, "TERMCHAR %c (%02x)\n", byte, byte);
    wchar_t ch;

    if (mbrtowc(&ch, (char *)&byte, 1, &m_mbstate) >= (size_t)-2)
    {
        // @todo: Handle UTF-8 errors
        return;
    }

    // Process control chars up front
    if (ch <= 0x1f || ch == 0x7f)
    {
        // It's a control char
        switch (ch)
        {
            case 0:
                break;

            case 0x7:
                // @todo: ring bell
                break;

            case 0x1b:
                m_state = State::esc;
                m_buf.clear();
                break;

            case '\r':
                m_screen->set_curx(0);
                break;

            case '\b':
                m_screen->set_curx(m_screen->get_curx()-1);
                break;

            case '\t':
                {
                    anvil_syslog(0, "TAB\n");
                    int x = m_screen->get_curx();
                    x += 8;
                    x &= ~7;
                    m_screen->set_curx(x);
                }
                break;

            case '\n':
                if (m_screen->get_cury() >= m_screen->get_rows() - 1)
                {
                    m_screen->scroll();
                }
                else
                {
                    m_screen->set_cury(m_screen->get_cury()+1);
                }
                m_screen->set_curx(0);
                break;

            default:
                break;
        }
        return;
    }

    switch (m_state)
    {
        case State::norm:
            // Just print 'normal' chars
            m_lastchar = ch;
            m_screen->PutChar(ch);
            break;

        case State::esc:
            // Collect escaped chars until we get a final char
            if (ch >= 0x20 && ch <= 0x2f)
            {
                // It's an intermediate char
                // Just accumulate the character
                m_buf.push_back(ch);
            }
            else if (ch >= 0x30 && ch <= 0x7e)
            {
                // It's a final char we can process the sequence
                m_buf.push_back(ch);
                process_esc_seq(m_buf);
            }
            break;

        case State::csi:
            anvil_syslog(0, "IN CSI ch=%x\n", ch);
            if (ch >= 0x20 && ch <= 0x3f)
            {
                // Just accumulate the character
                anvil_syslog(0, "IN CSI acc ch=%x\n", ch);
                m_buf.push_back(ch);
            }
            else if (ch >= 0x40 && ch <= 0x7e)
            {
                anvil_syslog(0, "IN CSI process ch=%x\n", ch);
                m_buf.push_back(ch);
                process_ctrl_seq(m_buf);
            }
            break;
    }
}
Exemple #22
0
void TermBox::process_ctrl_seq(std::string& buf)
{
    if (buf.size() < 1)
    {
        return;
    }
    int cmd = buf[buf.size()-1];
    buf.pop_back();
    anvil_syslog(0, "Got cmd %c (%s)\n", cmd, buf.c_str());
    bool VT;
    std::vector<std::string> argv = getArgs(buf, VT);
    anvil_syslog(0, "argc=%d ", argv.size());
    for (int i=0; i<argv.size(); ++i)
    {
        anvil_syslog(0, "argv%d=%s ", i, argv[i].c_str());
    }
    anvil_syslog(0, "\n");

    // Look at the final char
    switch (cmd)
    {
        case 'A':
        {
            int x = 1;
            if (argv.size() == 1)
            {
                x = strtol(argv[0].c_str(), NULL, 10);
            }
            m_screen->set_cury(m_screen->get_cury()-x);
            break;
        }
        case 'B':
        {
            int x = 1;
            if (argv.size() == 1)
            {
                x = strtol(argv[0].c_str(), NULL, 10);
            }
            m_screen->set_cury(m_screen->get_cury()+x);
            break;
        }
        case 'C':
        {
            int x = 1;
            if (argv.size() == 1)
            {
                x = strtol(argv[0].c_str(), NULL, 10);
            }
            m_screen->set_curx(m_screen->get_curx()+x);
            break;
        }
        case 'D':
        {
            int x = 1;
            if (argv.size() == 1)
            {
                x = strtol(argv[0].c_str(), NULL, 10);
            }
            m_screen->set_curx(m_screen->get_curx()-x);
            break;
        }
        case 'G':
        {
            int x = 1;
            if (argv.size() == 1)
            {
                x = strtol(argv[0].c_str(), NULL, 10);
            }
            m_screen->set_curx(x-1);
            break;
        }
        case 'H':
        {
            int x = 1, y = 1;
            if (argv.size() == 2)
            {
                y = strtol(argv[0].c_str(), NULL, 10);
                x = strtol(argv[1].c_str(), NULL, 10);
            }
            m_screen->set_curx(x-1);
            m_screen->set_cury(y-1);
            break;
        }
        case 'K': // EL - erase in line
        {
            int x = 0;
            if (argv.size() == 1)
            {
                x = strtol(argv[0].c_str(), NULL, 10);
            }
            switch (x)
            {
            case 0:
                for (int i=0; i<m_screen->get_curx(); ++i)
                {

                }
                break;
            case 1:
                for (int i=0; i<m_screen->get_curx(); ++i)
                {

                }
                break;
            case 2:
                for (int i=0; i<m_screen->get_curx(); ++i)
                {

                }
                break;
            }
            break;
        }
        case 'J':
            // Erase
            m_screen->ClearAll();
            break;
        case 'b':
            if (argv.size() == 1)
            {
                int num = strtol(argv[0].c_str(), NULL, 10);
                for (int i=0; i<num; ++i)
                {
                    m_screen->PutChar(m_lastchar);
                }
            }
            break;
        case 'd':
        {
            int x=1, y=1;
            if (argv.size() == 1)
            {
                y = strtol(argv[0].c_str(), NULL, 10);
            }
            if (argv.size() == 2)
            {
                y = strtol(argv[0].c_str(), NULL, 10);
                x = strtol(argv[1].c_str(), NULL, 10);
            }
            m_screen->set_curx(x-1);
            m_screen->set_cury(y-1);
            break;
        }
        case 'h':
            if (VT)
            {
                int x = strtol(argv[0].c_str(), NULL, 10);
                if (x == 1)
                {
                    anvil_syslog(0, "APPLICATION CURSOR KEYS\n");
                }
                else if (x == 1049)
                {
                    m_screen = m_alternate_screen;
                    m_screen->set_size(m_cols, m_rows);
                    anvil_syslog(0, "ALTERNATE SCREEN\n");
                }
            }
            else
            {

            }
            break;
        case 'l':
            break;

        case 'm':
            for (int i=0; i<argv.size(); ++i)
            {
                int arg = strtol(argv[i].c_str(), NULL, 10);

                switch(arg)
                {
                    case 0:
                        m_screen->sgr_normal();
                        break;
                    case 7:
                        m_screen->sgr_inverse();
                        break;
                    case 10:
                        //m_screen->Normal();
                        break;
                }
            }
            break;
        case 'r':
            break;

        default:
            anvil_syslog(0, "UNHANDLED ANSIESCAPE %c\n", cmd);
            break;
    }
    m_state = State::norm;
}
Exemple #23
0
int cfsetospeed(struct termios *termios_p, speed_t speed)
{
    anvil_syslog(0, "%s\n", __FUNCTION__);
    termios_p->c_ospeed = speed;
    return 0;
}
Exemple #24
0
int chown(const char *path, uid_t owner, gid_t group) {

    anvil_syslog(0, "%s unimplemented\n", __FUNCTION__);
    while (1);
    return 0;
}
Exemple #25
0
int main(int argc, char *argv[]) {

    int             ret;
    int             cnt;
    struct timespec tsp;
    long            next_frame;


    gl_ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);

    ace_connection = ace_connect("GlxGears");
    width = 400;
    height = 300;
    gl_win = ace_win_create(ace_connection, 1, 0, 0);
    ace_buffer = ace_buffer_create(ace_connection, 1024 * 768 * sizeof(uint32_t));
    //ace_win_clear(gl_win, 0x000000);
    //ace_buffer_damage(gl_win, ace_buffer, -1, -1, -1, -1, -1);

    ace_win_update(gl_win, ace_buffer, width, height, width*4);
    ace_win_show(gl_win);

    ret = OSMesaMakeCurrent(gl_ctx, ace_buffer->pixel_buf, GL_UNSIGNED_BYTE, width, height);
    OSMesaPixelStore( OSMESA_Y_UP , GL_FALSE );
    reshape(width, height);

    init();

    clock_gettime(CLOCK_REALTIME, &tsp);
    next_frame = TIMESPEC_TO_TICK(&tsp);
    while (1) {
        //ace_win_clear(gl_win, 0x80000000);
        memset(ace_buffer->pixel_buf, 0, 1024 * 768 * sizeof(uint32_t));
        draw();
        /* Now wait for the next frame time */
        while (1) {
            long    curr_time;
            clock_gettime(CLOCK_REALTIME, &tsp);
            curr_time = TIMESPEC_TO_TICK(&tsp);
            if (curr_time > next_frame)
                break;
            switch (get_event()) {
                case ACE_KEY_RIGHT:
                    view_roty += 0.5;
                    break;
                case ACE_KEY_LEFT:
                    view_roty -= 0.5;
                    break;
                case ACE_KEY_UP:
                    view_rotx += 0.5;
                    break;
                case ACE_KEY_DOWN:
                    view_rotx -= 0.5;
                    break;
                default:
                    break;
            }
        }
        ace_win_update(gl_win, ace_buffer, width, height, width);
//        ace_win_damage(gl_win, -1, -1, -1, -1);
        next_frame += 40000000;
        angle += 1;
        clock_gettime(CLOCK_REALTIME, &tsp);
        if (++cnt == 1000) {
            anvil_syslog(0, "TIME %ld %ld\n", tsp.tv_sec, tsp.tv_nsec);
            cnt = 0;
        }
//        usleep(40000);
    }
    anvil_syslog(0, "All done\n");

    while (1)
        sleep(1);
}
Exemple #26
0
void *elf_file_load(int pid, int fd) {

    elf64_hdr       elf_header;
    elf64_hdr       *pelf_header;
    elf64_phdr      *pprog_hdr;
    void            *seg_addr;
    void            *elf_offset;
    int             ph;
    uintptr_t       start, end;
    int             sizeof_phdrs;
    int             err;
    char            *p;
    char            *interp_name;
    elf64_dyn       *dyn_seg;
    int             ndyn_items;
    int             interp_fd;
    uintptr_t       entry_offs;
    int             prot;


    interp_name = NULL;
    dyn_seg     = NULL;
    entry_offs  = 0;

    if (read(fd, &elf_header, sizeof(elf_header)) != sizeof(elf_header)) {
        anvil_syslog(0, "Bad ELF header\n");
        while (1);
    }

    pelf_header = &elf_header;

    if (strncmp((const char *)pelf_header->e_ident, "\x7f" "ELF", 4)) {
        anvil_syslog(0, "Incorrect ELF identifier\n");
        return NULL;
    }

    if (pelf_header->e_ident[4] != 2) {
        anvil_syslog(0, "Elf file is not 64 bit\n");
        return NULL;
    }

    if (pelf_header->e_type != 2) {
        anvil_syslog(0, "Elf file is not executable\n");
        return NULL;
    }

//    if (pelf_header->e_phnum > 3) {
//        anvil_syslog(0, "Elf file has too many segments\n");
//        return NULL;
//    }

    //anvil_syslog(0, "Elf OK\n");

    sizeof_phdrs = pelf_header->e_phentsize * pelf_header->e_phnum;

    pprog_hdr = (elf64_phdr *)alloca(sizeof_phdrs);
    memset(pprog_hdr, 0, sizeof_phdrs);

    if (pread(fd, pprog_hdr, sizeof_phdrs, elf_header.e_phoff) == -1) {
        anvil_syslog(0, "Bad prog_hdr header\n");
        while (1);
    }

    for (ph=0; ph<pelf_header->e_phnum; ++ph) {

        switch (pprog_hdr->p_type) {

            case PT_LOAD:
                if (pprog_hdr->p_type != 1) {
                    anvil_syslog(0, "Elf file segment is not loadable\n");
                    return NULL;
                }

                prot = get_prot(pprog_hdr->p_flags);

                /* We found a loadable segment so create a mapping */
                start = pprog_hdr->p_vaddr;
                end = start + pprog_hdr->p_memsz;

                start &= ~0xfff;
                end = __PAGEROUND(end);

                //anvil_syslog(0, "\nstart=%016lx end=%016lx\n", start, end);

                /* Make a mapping in the address of the exec-svr */
                if (_Mmap(0, 0, end - start, PROT_READ,
                            MAP_ANON, -1, 0, &seg_addr) != 0) {
                    anvil_syslog(0, "Out of memory\n");
                    return NULL;
                }

                /*
                 * seg_addr (from the mmap call) is the address in the
                 * exec-svr where we will load the section
                 */

                /* Load the segment from the file */
                //anvil_syslog(0, "pread to %016lx %016lx\n", pprog_hdr->p_filesz, pprog_hdr->p_offset);
                if (pread(fd, seg_addr + pprog_hdr->p_vaddr - start, pprog_hdr->p_filesz, pprog_hdr->p_offset) == -1) {
                    anvil_syslog(0, "Bad load of segment\n");
                    while (1);
                }

                /* Send it to the new process space */
                //anvil_syslog(0, "_Vmm_send: %d %016lx %016lx %018x\n",
                //        pid, start, seg_addr, end - start);
                _Vmm_send(pid, (void *)start, seg_addr, end - start, prot);

            break;

            case PT_INTERP:
                /*
                 * Just record the name of the interpreter. We'll load it in
                 * a minute
                 */
                //anvil_syslog(0, "PT_INTERP %d\n", pprog_hdr->p_filesz);
                interp_name = alloca(pprog_hdr->p_filesz + 1);
                if (pread(fd, interp_name, pprog_hdr->p_filesz, pprog_hdr->p_offset) == -1) {
                    anvil_syslog(0, "Bad load of interp\n");
                    while (1);
                }
                interp_name[pprog_hdr->p_filesz] = 0;
                //anvil_syslog(0, "PT_INTERP is %s\n", interp_name);
                break;

            case PT_DYNAMIC:
                /*
                 */
                //anvil_syslog(0, "PT_DYNAMIC\n");
                dyn_seg = alloca(pprog_hdr->p_filesz);
                if (pread(fd, dyn_seg, pprog_hdr->p_filesz, pprog_hdr->p_offset) == -1) {
                    anvil_syslog(0, "Bad load of dyn_seg\n");
                    while (1);
                }
                ndyn_items = pprog_hdr->p_filesz / sizeof(elf64_dyn);
                //anvil_syslog(0, "PT_DYNAMIC %d items\n", ndyn_items);
                /* Now parse the dyn seg */
                while (ndyn_items) {
                    //anvil_syslog(0, " items %d %016lx\n", dyn_seg->d_tag, dyn_seg->d_un.d_ptr);
                    ++dyn_seg;
                    --ndyn_items;
                }
                break;

            case PT_TLS:
//                anvil_syslog(0, "PT_TLS\n");
//                anvil_syslog(0, "p_type %016lx\n",pprog_hdr->p_type);
//                anvil_syslog(0, "p_flags %016lx\n",pprog_hdr->p_flags);
//                anvil_syslog(0, "p_offset %016lx\n",pprog_hdr->p_offset);
//                anvil_syslog(0, "p_vaddr %016lx\n",pprog_hdr->p_vaddr);
//                anvil_syslog(0, "p_paddr %016lx\n",pprog_hdr->p_paddr);
//                anvil_syslog(0, "p_filesz %016lx\n",pprog_hdr->p_filesz);
//                anvil_syslog(0, "p_memsz %016lx\n",pprog_hdr->p_memsz);
//                anvil_syslog(0, "p_align %016lx\n",pprog_hdr->p_align);
                //*ptls_bss_len += pprog_hdr->p_memsz;
                break;

            default:
                anvil_syslog(0, "Unknown Load type %d\n", pprog_hdr->p_type);
            break;
        }

        pprog_hdr = (elf64_phdr *)
                ((uint64_t)pprog_hdr + pelf_header->e_phentsize);
    }

    if (interp_name != NULL) {
        interp_name = "/lib/libc.so";
        //anvil_syslog(0, "Loading interpreter %s\n", interp_name);
        if ((interp_fd = open(interp_name, 0, 0)) == -1) {
            anvil_syslog(0, "Couldn't open interpreter %s\n", interp_name);
            return NULL;
        }

        /*
         * Now load the interpreter into memory. The interpreter should be
         * entirely PIC so we can load it anywhere.
         */

        if (read(interp_fd, &elf_header, sizeof(elf_header)) != sizeof(elf_header)) {
            anvil_syslog(0, "Bad ELF header\n");
            while (1);
        }

        pelf_header = &elf_header;

        if (strncmp((const char *)pelf_header->e_ident, "\x7f" "ELF", 4)) {
            anvil_syslog(0, "Interp: Incorrect ELF identifier\n");
            return NULL;
        }

        if (pelf_header->e_ident[4] != 2) {
            anvil_syslog(0, "Interp: Elf file is not 64 bit\n");
            return NULL;
        }

        if (pelf_header->e_type != 3) {
            anvil_syslog(0, "Interp: Elf file is not a so\n");
            return NULL;
        }

        anvil_syslog(0, "Interp OK\n");

        sizeof_phdrs = pelf_header->e_phentsize * pelf_header->e_phnum;

        pprog_hdr = (elf64_phdr *)alloca(sizeof_phdrs);
        memset(pprog_hdr, 0, sizeof_phdrs);

        if (pread(interp_fd, pprog_hdr, sizeof_phdrs, elf_header.e_phoff) == -1) {
            anvil_syslog(0, "Interp: Bad prog_hdr header\n");
            while (1);
        }

        for (ph=0; ph<pelf_header->e_phnum; ++ph) {

            switch (pprog_hdr->p_type) {

                case PT_LOAD:
                    if (pprog_hdr->p_type != 1) {
                        anvil_syslog(0, "Interp: Elf file segment is not loadable\n");
                        return NULL;
                    }

                    prot = get_prot(pprog_hdr->p_flags);

                    /* We found a loadable segment so create a mapping */
                    start = pprog_hdr->p_vaddr;
                    end = start + pprog_hdr->p_memsz;

                    start &= ~0xfff;
                    end = __PAGEROUND(end);

                    //anvil_syslog(0, "\nstart=%016lx end=%016lx\n", start, end);

                    /* Make a mapping in the address of the exec-svr */
                    if (_Mmap(0, 0, end - start, PROT_EXEC|PROT_READ|PROT_WRITE,
                                MAP_ANON, -1, 0, &seg_addr) != 0) {
                        anvil_syslog(0, "Interp: Out of memory\n");
                        return NULL;
                    }

                    /*
                     * seg_addr (from the mmap call) is the address in the
                     * exec-svr where we will load the section
                     */

                    /* Load the segment from the file */
                    //anvil_syslog(0, "pread to %016lx %016lx\n", pprog_hdr->p_filesz, pprog_hdr->p_offset);
                    if (pread(interp_fd, seg_addr + pprog_hdr->p_vaddr - start, pprog_hdr->p_filesz, pprog_hdr->p_offset) == -1) {
                        anvil_syslog(0, "Interp: Bad load of segment\n");
                        while (1);
                    }

                    /* Send it to the new process space */
                    //anvil_syslog(0, "_Vmm_send: %d %016lx %016lx %018x\n",
                    //        pid, start, seg_addr, end - start);
                    _Vmm_send(pid, (void *)start+0x100000000, seg_addr, end - start, prot);

                break;

                default:
                    anvil_syslog(0, "Unknown Load type %d\n", pprog_hdr->p_type);
                break;
            }

            pprog_hdr = (elf64_phdr *)
                    ((uint64_t)pprog_hdr + pelf_header->e_phentsize);
        }
        entry_offs += 0x100000000;
        close(interp_fd);
    }

    //anvil_syslog(0, "Start address at %016lx\n", elf_header.e_entry+entry_offs);

    return (void *)elf_header.e_entry + entry_offs;
}
Exemple #27
0
void *elf_file_load_ram(int pid, char *pfile) {

    elf64_hdr       *pelf_header;
    elf64_phdr      *prog_hdr;
    void            *seg_addr;
    void            *elf_offset;
    int             ph;
    uintptr_t       start, end;
    int             sizeof_phdrs;
    int             err;

    pelf_header = (elf64_hdr *)pfile;

    if (strncmp((const char *)pelf_header->e_ident, "\x7f" "ELF", 4)) {
        anvil_syslog(0, "Incorrect ELF identifier\n");
        return NULL;
    }

    if (pelf_header->e_ident[4] != 2) {
        anvil_syslog(0, "Elf file is not 64 bit\n");
        return NULL;
    }

    if (pelf_header->e_type != 2) {
        anvil_syslog(0, "Elf file is not executable\n");
        return NULL;
    }

    if (pelf_header->e_phnum > 3) {
        anvil_syslog(0, "Elf file has too many segments\n");
        return NULL;
    }

    //anvil_syslog(0, "Elf OK\n");

    sizeof_phdrs = pelf_header->e_phentsize * pelf_header->e_phnum;

    prog_hdr = (elf64_phdr *)((char *)pelf_header + pelf_header->e_phoff);

    for (ph=0; ph<pelf_header->e_phnum; ++ph) {

        int prot;

        if (prog_hdr->p_type != 1) {
            anvil_syslog(0, "Elf file segment is not loadable\n");
            return NULL;
        }

        prot = get_prot(prog_hdr->p_flags);

        /* We found a loadable segment so create a mapping */
        start = prog_hdr->p_vaddr;
        end = start + prog_hdr->p_memsz;

        start &= ~0xfff;
        end = __PAGEROUND(end);

        if (_Mmap(0, 0, end - start, PROT_READ,
                    MAP_ANON, -1, 0, &seg_addr) != 0) {
            anvil_syslog(0, "Out of memory\n");
            return NULL;
        }

        //anvil_syslog(0, "seg_addr = %016lx\n", seg_addr);

        /* Find where, in the elf image the section is */
        elf_offset = (void *)(pfile + prog_hdr->p_offset);
        //anvil_syslog(0, "File image addr = %08x\n", elf_offset);

        /* The segment is zero filled by the _Mmap system call */
        //anvil_syslog(0, "%016lx %016lx %016lx\n",
        //                seg_addr + prog_hdr->p_vaddr - start,
        //                elf_offset,
        //                prog_hdr->p_filesz);

        memcpy(seg_addr + prog_hdr->p_vaddr - start,
                                elf_offset, prog_hdr->p_filesz);

        //anvil_syslog(0, "_Vmm_send: %d %016lx %016lx %018x\n",
        //        pid, start, seg_addr, end - start);
        _Vmm_send(pid, (void *)start, seg_addr, end - start, prot);

        prog_hdr = (elf64_phdr *)
                ((uint64_t)prog_hdr + pelf_header->e_phentsize);
    }

    return (void *)pelf_header->e_entry;
}
Exemple #28
0
int _Wprintf(int (*nputs)(void *, const wchar_t *, int ), void *arg, const wchar_t *fmt, va_list ap) {

    anvil_syslog(0, "%s unimplemented\n", __FUNCTION__);
    while (1);
    return 0;
}
Exemple #29
0
pid_t waitpid(pid_t pid, int *stat_loc, int options) {

    anvil_syslog(0, "Calling waitpid()\n");
    return wait4(pid, stat_loc, options, NULL);
}
Exemple #30
0
void freeaddrinfo(struct addrinfo *ai)
{
    anvil_syslog(0, "%s unimplemented\n", __FUNCTION__);
    while (1);
}