Cut-and-paste the msdos86 libsys so the msdos386 stuff now at least builds.

This commit is contained in:
David Given 2022-08-07 22:10:08 +02:00
parent 00c722d2ef
commit b81ac5e2c3
21 changed files with 555 additions and 32 deletions

View file

@ -0,0 +1,19 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .bss
! This data block is used to store information about the current line number
! and file.
.define hol0
.comm hol0, 8

View file

@ -1,39 +1,24 @@
acklibrary {
name = "lib",
srcs = {
"./brk.c",
"./close.s",
"./errno.s",
"./getpid.s",
"./_hol0.s",
"./isatty.s",
"./rename.s",
-- "./brk.c",
-- "./close.s",
-- "./creat.c",
-- "./errno.s",
-- "./getpid.s",
-- "./gettimeofday.c",
-- "./_hol0.s",
-- "./isatty.s",
-- "./kill.c",
-- "./lseek.c",
-- "./open.c",
-- "./read.c",
-- "./setmode.c",
-- "./signal.c",
-- "./sys_exists.s",
-- "./sys_fdmodes.c",
-- "./sys_getdate.s",
-- "./sys_getmode.c",
-- "./sys_gettime.s",
-- "./sys_initmain.c",
-- "./sys_iseof.c",
-- "./sys_isopen.s",
-- "./sys_isreadyr.s",
-- "./sys_rawcreat.s",
-- "./sys_rawlseek.s",
-- "./sys_rawopen.s",
-- "./sys_rawrw.s",
-- "./sys_seteof.c",
-- "./sys_seterrno.c",
-- "./sys_setmode.c",
-- "./sys_xret.s",
-- "./unlink.s",
"./sys_exists.s",
"./sys_getdate.s",
"./sys_gettime.s",
"./sys_isopen.s",
"./sys_isreadyr.s",
"./sys_rawcreat.s",
"./sys_rawlseek.s",
"./sys_rawopen.s",
"./sys_rawrw.s",
"./sys_xret.s",
"./unlink.s",
"plat/msdos/libsys+srcs",
},
deps = {

View file

@ -0,0 +1,23 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Close a file.
.define _close
_close:
mov bx, sp
mov bx, 2(bx)
movb ah, 0x3E
int 0x21
jmp .sys_zret

View file

@ -0,0 +1,28 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
#define D(e) .define e; e
.sect .data
! Define various ACK error numbers. Note that these are *not* ANSI C
! errnos, and are used for different purposes.
D(ERANGE) = 1
D(ESET) = 2
D(EIDIVZ) = 6
D(EHEAP) = 17
D(EILLINS) = 18
D(EODDZ) = 19
D(ECASE) = 20
D(EBADMON) = 25

View file

@ -0,0 +1,45 @@
#
! $Source$
! $State$
! $Revision$
! Copyright (c) 2021--2022 TK Chia
!
! The authors hereby grant permission to use, copy, modify, distribute,
! and license this software and its documentation for any purpose, provided
! that existing copyright notices are retained in all copies and that this
! notice is included verbatim in any distributions. No written agreement,
! license, or royalty fee is required for any of the authorized uses.
! Modifications to this software may be copyrighted by their authors
! and need not follow the licensing terms described here, provided that
! the new terms are clearly indicated on the first page of each file where
! they apply.
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Get the current process identifier. For MS-DOS, use the Program Segment
! Prefix (PSP) segment as the PID, unless the system supports an actual
! `getpid' syscall, e.g. European MS-DOS 4.0.
!
! (Note that pid_t is a 32-bit type. This is to allow for PSP segments and
! MS-DOS PIDs above 0x7FFF.)
.define _getpid
_getpid:
movb ah, 0x87
stc
int 0x21
jnc .eur_dos
movb ah, 0x51
int 0x21
xchg bx, ax
.eur_dos:
xor dx, dx
ret

View file

@ -0,0 +1,37 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Say whether a given file descriptor number refers to a terminal.
.define _isatty
_isatty:
mov bx, sp
mov bx, 2(bx)
mov ax, 0x4400
int 0x21
jc error
testb dl, dl
jz not_tty
mov ax, 1
ret
not_tty:
mov (_errno), 25 ! ENOTTY
not_tty_2:
xor ax, ax
ret
error:
push ax
call __sys_seterrno
pop cx
jmp not_tty_2

View file

@ -0,0 +1,26 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Rename a file.
.define _rename
_rename:
mov bx, sp
push di
mov dx, 2(bx)
mov di, 4(bx)
movb ah, 0x56
int 0x21
pop di
jmp .sys_zret

View file

@ -0,0 +1,25 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Say whether a file exists with the given name.
.define __sys_exists
__sys_exists:
mov bx, sp
mov dx, 2(bx)
mov ax, 0x4300
int 0x21
sbb ax, ax
inc ax
ret

View file

@ -0,0 +1,25 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Get the current system date from MS-DOS.
.define __sys_getdate
__sys_getdate:
movb ah, 0x2a
int 0x21
mov bx, sp
mov bx, 2(bx)
mov (bx), dx
mov 2(bx), cx
ret

View file

@ -0,0 +1,25 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Get the current system time from MS-DOS.
.define __sys_gettime
__sys_gettime:
movb ah, 0x2c
int 0x21
mov bx, sp
mov bx, 2(bx)
mov (bx), cx
mov 2(bx), dx
ret

View file

@ -0,0 +1,26 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Say whether a given file descriptor number refers to a valid open file
! descriptor.
.define __sys_isopen
__sys_isopen:
mov bx, sp
mov bx, 2(bx)
mov ax, 0x4400
int 0x21
sbb ax, ax
inc ax
ret

View file

@ -0,0 +1,28 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Say whether a file descriptor is ready for input, i.e. reading from the
! fd will immediately return something.
.define __sys_isreadyr
__sys_isreadyr:
mov bx, sp
mov ax, 0x4406
mov bx, 2(bx)
int 0x21
jnc ok
movb al, 0
ok:
cbw
ret

View file

@ -0,0 +1,24 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Create or truncate a file.
.define __sys_rawcreat
__sys_rawcreat:
movb ah, 0x3c
mov bx, sp
mov dx, 2(bx)
mov cx, 4(bx)
int 0x21
jmp .sys_axret

View file

@ -0,0 +1,26 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Move the current file position for a file descriptor.
.define __sys_rawlseek
__sys_rawlseek:
movb ah, 0x42
mov bx, sp
mov dx, 4(bx)
mov cx, 6(bx)
movb al, 8(bx)
mov bx, 2(bx)
int 0x21
jmp .sys_dxaxret

View file

@ -0,0 +1,24 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Open an existing file.
.define __sys_rawopen
__sys_rawopen:
movb ah, 0x3d
mov bx, sp
mov dx, 2(bx)
movb al, 4(bx)
int 0x21
jmp .sys_axret

View file

@ -0,0 +1,33 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Read/write bytes to/to a file descriptor. These routines do not do any
! translation between CRLF and LF line endings.
!
! Note that, for MS-DOS, a raw "write" request of zero bytes will truncate
! (or extend) the file to the current file position.
.define __sys_rawread
__sys_rawread:
movb ah, 0x3f
.data1 0x3d ! eat up the next instruction
.define __sys_rawwrite
__sys_rawwrite:
movb ah, 0x40
mov bx, sp
mov dx, 4(bx)
mov cx, 6(bx)
mov bx, 2(bx)
int 0x21
jmp .sys_axret

View file

@ -0,0 +1,41 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! .sys_zret: if the carry flag is set, then set `errno' from the DOS error
! code in ax, and return a shortword -1. If the carry flag is clear, just
! return a shortword zero.
!
! .sys_axret: if the carry flag is set, then set `errno' from the DOS error
! code in ax, and return a shortword -1. If the carry flag is clear, just
! return ax as a return value.
!
! .sys_dxaxret: same as .sys_axret, but return a longword -1 or dx:ax as a
! return value.
.extern .sys_zret
.extern .sys_axret
.extern .sys_dxaxret
.sys_zret:
jc error
xor ax, ax
no_error:
ret
.sys_axret:
.sys_dxaxret:
jnc no_error
error:
push ax
call __sys_seterrno
pop cx
ret

View file

@ -0,0 +1,23 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Remove a file.
.define _unlink
_unlink:
mov bx, sp
mov dx, 2(bx)
movb ah, 0x41
int 0x21
jmp .sys_zret

59
plat/msdos86/libsys/brk.c Normal file
View file

@ -0,0 +1,59 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include "libsys.h"
#define STACK_BUFFER 128 /* number of bytes to leave for stack */
extern char _end[1];
static char* current = _end;
int brk(void* newend)
{
/* This variable is used to figure out the current stack pointer,
* by taking its address. */
char dummy;
char* p = newend;
if ((p > (&dummy - STACK_BUFFER)) ||
(p < _end))
{
errno = ENOMEM;
return -1;
}
current = p;
return 0;
}
void* sbrk(int increment)
{
char* old;
char* new;
if (increment == 0)
return current;
old = current;
new = old + increment;
if ((increment > 0) && (new <= old))
goto out_of_memory;
else if ((increment < 0) && (new >= old))
goto out_of_memory;
if (brk(new) < 0)
goto out_of_memory;
return old;
out_of_memory:
errno = ENOMEM;
return OUT_OF_MEMORY;
}

View file

@ -1,6 +1,7 @@
acklibrary {
name = "lib",
srcs = {
"./brk.c",
"./close.s",
"./errno.s",
"./getpid.s",