From 979406f3a617880cda8c063ee4297ebca097fab7 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 22 Apr 2018 11:42:47 +0200 Subject: [PATCH] mlibc: Add ioctl. * stage0/x86.M1 (SYS_ioctl): New define. * lib/linux-mes.c (ioctl): New syscall. * lib/linux-gcc.c (ioctl): New syscall. * include/sys/ioctl.h: New file. --- include/sys/ioctl.h | 36 ++++++++++++++++++++++++++++++++++++ lib/linux-gcc.c | 31 +++++++++++++++++++++++++++++++ lib/linux-mes.c | 11 +++++++++++ stage0/x86.M1 | 1 + 4 files changed, 79 insertions(+) create mode 100644 include/sys/ioctl.h diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h new file mode 100644 index 00000000..d24fd82b --- /dev/null +++ b/include/sys/ioctl.h @@ -0,0 +1,36 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of Mes. + * + * Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mes. If not, see . + */ +#ifndef __MES_SYS_IOCTL_H +#define __MES_SYS_IOCTL_H 1 + +#if __GNUC__ && POSIX +#undef __MES_SYS_IOCTL_H +#include_next + +#else // !(__GNUC__ && POSIX) + +#define TCGETS 0x5401 +#define TCGETA 0x5405 +int ioctl (int fd, unsigned long request, ...); + +#endif // !(__GNUC__ && POSIX) + +#endif // __MES_SYS_IOCTL_H + diff --git a/lib/linux-gcc.c b/lib/linux-gcc.c index ca942440..4f357b10 100644 --- a/lib/linux-gcc.c +++ b/lib/linux-gcc.c @@ -137,6 +137,37 @@ brk (void *p) #endif } +int +ioctl (int fd, unsigned long request, ...) +{ +#if !__TINYC__ + int p; + asm ( + "mov %%ebp,%%eax\n\t" + "add $0x10,%%eax\n\t" + "mov (%%eax),%%eax\n\t" + "mov %%eax,%0\n\t" + : "=p" (p) + : //no inputs "" + ); + int r; + //syscall (SYS_ioctl, fd)); + asm ( + "mov %1,%%ebx\n\t" + "mov %2,%%ecx\n\t" + "mov %3,%%edx\n\t" + + "mov $0x36, %%eax\n\t" + "int $0x80\n\t" + "mov %%eax,%0\n\t" + : "=r" (r) + : "" (fd), "" (request), "" (p) + : "eax", "ebx", "ecx", "edx" + ); + return r; +#endif +} + int fsync (int fd) { diff --git a/lib/linux-mes.c b/lib/linux-mes.c index 06f55a8e..75dee3a9 100644 --- a/lib/linux-mes.c +++ b/lib/linux-mes.c @@ -69,6 +69,17 @@ brk () asm ("int____$0x80"); } +void +ioctl () +{ + asm ("mov____0x8(%ebp),%ebx !8"); + asm ("mov____0x8(%ebp),%ecx !12"); + asm ("mov____0x8(%ebp),%edx !16"); + + asm ("mov____$i32,%eax SYS_ioctl"); + asm ("int____$0x80"); +} + void fsync () { diff --git a/stage0/x86.M1 b/stage0/x86.M1 index 85f9c3ad..80dadfcd 100644 --- a/stage0/x86.M1 +++ b/stage0/x86.M1 @@ -205,5 +205,6 @@ DEFINE SYS_chmod 0f000000 DEFINE SYS_lseek 13000000 DEFINE SYS_access 21000000 DEFINE SYS_brk 2d000000 +DEFINE SYS_ioctl 36000000 DEFINE SYS_fsync 76000000 DEFINE SYS_getcwd b7000000