Add access?
* libc/mlibc.c (access): New function. * module/mes/libc-i386.mes (i386:access): New function. (i386:libc): Add it. * src/posix.c (access_p): New function. * module/mes/posix.mes: New file. * module/mes/base-0.mes (mes): Include it. * module/mes/read-0-32.mo: Regenerate.
This commit is contained in:
parent
133772d992
commit
9918ffab92
69
libc/mlibc.c
69
libc/mlibc.c
|
@ -78,27 +78,6 @@ read (int fd, void* buf, size_t n)
|
|||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
open (char const *s, int mode)
|
||||
{
|
||||
int r;
|
||||
//syscall (SYS_open, mode));
|
||||
asm (
|
||||
"mov %1,%%ebx\n\t"
|
||||
"mov %2,%%ecx\n\t"
|
||||
"mov $0x5,%%eax\n\t"
|
||||
"int $0x80\n\t"
|
||||
"mov %%eax,%0\n\t"
|
||||
: "=r" (r)
|
||||
: "" (s), "" (mode)
|
||||
: "eax", "ebx", "ecx"
|
||||
);
|
||||
return r;
|
||||
}
|
||||
|
||||
int puts (char const*);
|
||||
char const* itoa (int);
|
||||
|
||||
int
|
||||
write (int fd, char const* s, int n)
|
||||
{
|
||||
|
@ -120,19 +99,37 @@ write (int fd, char const* s, int n)
|
|||
}
|
||||
|
||||
int
|
||||
fsync (int fd)
|
||||
open (char const *s, int mode)
|
||||
{
|
||||
int r;
|
||||
//syscall (SYS_fsync, fd));
|
||||
//syscall (SYS_open, mode));
|
||||
asm (
|
||||
"mov %1,%%ebx\n\t"
|
||||
|
||||
"mov $0x76, %%eax\n\t"
|
||||
"mov %2,%%ecx\n\t"
|
||||
"mov $0x5,%%eax\n\t"
|
||||
"int $0x80\n\t"
|
||||
"mov %%eax,%0\n\t"
|
||||
: "=r" (r)
|
||||
: "" (fd)
|
||||
: "eax", "ebx"
|
||||
: "" (s), "" (mode)
|
||||
: "eax", "ebx", "ecx"
|
||||
);
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
access (char const *s, int mode)
|
||||
{
|
||||
int r;
|
||||
//syscall (SYS_access, mode));
|
||||
asm (
|
||||
"mov %1,%%ebx\n\t"
|
||||
"mov %2,%%ecx\n\t"
|
||||
"mov $0x21,%%eax\n\t"
|
||||
"int $0x80\n\t"
|
||||
"mov %%eax,%0\n\t"
|
||||
: "=r" (r)
|
||||
: "" (s), "" (mode)
|
||||
: "eax", "ebx", "ecx"
|
||||
);
|
||||
return r;
|
||||
}
|
||||
|
@ -155,6 +152,24 @@ brk (void *p)
|
|||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
fsync (int fd)
|
||||
{
|
||||
int r;
|
||||
//syscall (SYS_fsync, fd));
|
||||
asm (
|
||||
"mov %1,%%ebx\n\t"
|
||||
|
||||
"mov $0x76, %%eax\n\t"
|
||||
"int $0x80\n\t"
|
||||
"mov %%eax,%0\n\t"
|
||||
: "=r" (r)
|
||||
: "" (fd)
|
||||
: "eax", "ebx"
|
||||
);
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
fputc (int c, int fd)
|
||||
{
|
||||
|
|
|
@ -173,3 +173,4 @@
|
|||
(mes-use-module (srfi srfi-13))
|
||||
(mes-use-module (mes display))
|
||||
(mes-use-module (mes catch))
|
||||
(mes-use-module (mes posix))
|
||||
|
|
|
@ -124,6 +124,3 @@
|
|||
((eq? c #\*eof*) s)
|
||||
(#t (read-string (read-char) (peek-char) (append-char s c)))))
|
||||
(list->string (read-string (read-char) (peek-char) (list))))
|
||||
|
||||
(define (access? file-name how) #t)
|
||||
(define R_OK 0)
|
||||
|
|
|
@ -32,21 +32,6 @@
|
|||
#xcd #x80 ; int $0x80
|
||||
))
|
||||
|
||||
(define (i386:open f g ta t d)
|
||||
'(
|
||||
#x55 ; push %ebp
|
||||
#x89 #xe5 ; mov %esp,%ebp
|
||||
|
||||
#x8b #x5d #x08 ; mov 0x8(%ebp),%ebx
|
||||
#x8b #x4d #x0c ; mov 0xc(%ebp),%ecx
|
||||
|
||||
#xb8 #x05 #x00 #x00 #x00 ; mov $0x5,%eax
|
||||
#xcd #x80 ; int $0x80
|
||||
|
||||
#xc9 ; leave
|
||||
#xc3 ; ret
|
||||
))
|
||||
|
||||
(define (i386:read f g ta t d)
|
||||
'(
|
||||
#x55 ; push %ebp
|
||||
|
@ -79,6 +64,36 @@
|
|||
#xc3 ; ret
|
||||
))
|
||||
|
||||
(define (i386:open f g ta t d)
|
||||
'(
|
||||
#x55 ; push %ebp
|
||||
#x89 #xe5 ; mov %esp,%ebp
|
||||
|
||||
#x8b #x5d #x08 ; mov 0x8(%ebp),%ebx
|
||||
#x8b #x4d #x0c ; mov 0xc(%ebp),%ecx
|
||||
|
||||
#xb8 #x05 #x00 #x00 #x00 ; mov $0x5,%eax
|
||||
#xcd #x80 ; int $0x80
|
||||
|
||||
#xc9 ; leave
|
||||
#xc3 ; ret
|
||||
))
|
||||
|
||||
(define (i386:access f g ta t d)
|
||||
'(
|
||||
#x55 ; push %ebp
|
||||
#x89 #xe5 ; mov %esp,%ebp
|
||||
|
||||
#x8b #x5d #x08 ; mov 0x8(%ebp),%ebx
|
||||
#x8b #x4d #x0c ; mov 0xc(%ebp),%ecx
|
||||
|
||||
#xb8 #x21 #x00 #x00 #x00 ; mov $0x21,%eax
|
||||
#xcd #x80 ; int $0x80
|
||||
|
||||
#xc9 ; leave
|
||||
#xc3 ; ret
|
||||
))
|
||||
|
||||
(define (i386:brk f g ta t d)
|
||||
'(
|
||||
#x55 ; push %ebp
|
||||
|
@ -119,8 +134,9 @@
|
|||
(define i386:libc
|
||||
(list
|
||||
(cons "exit" (list i386:exit))
|
||||
(cons "open" (list i386:open))
|
||||
(cons "read" (list i386:read))
|
||||
(cons "write" (list i386:write))
|
||||
(cons "fsync" (list i386:fsync))
|
||||
(cons "brk" (list i386:brk))))
|
||||
(cons "open" (list i386:open))
|
||||
(cons "access" (list i386:access))
|
||||
(cons "brk" (list i386:brk))
|
||||
(cons "fsync" (list i386:fsync))))
|
||||
|
|
25
module/mes/posix.mes
Normal file
25
module/mes/posix.mes
Normal file
|
@ -0,0 +1,25 @@
|
|||
;;; -*-scheme-*-
|
||||
|
||||
;;; Mes --- Maxwell Equations of Software
|
||||
;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||
;;;
|
||||
;;; 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; Code:
|
||||
|
||||
(define R_OK 0)
|
Binary file not shown.
|
@ -101,6 +101,12 @@ open_input_file (SCM file_name)
|
|||
return MAKE_NUMBER (open (string_to_cstring (file_name), O_RDONLY));
|
||||
}
|
||||
|
||||
SCM
|
||||
access_p (SCM file_name, SCM mode)
|
||||
{
|
||||
return access (string_to_cstring (file_name), VALUE (mode)) == 0 ? cell_t : cell_f;
|
||||
}
|
||||
|
||||
SCM
|
||||
current_input_port ()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue