Updated to work with the new libmon-less setup.
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
#
|
||||
! $Source$
|
||||
! $State$
|
||||
! $Revision$
|
||||
|
||||
! Declare segments (the order is important).
|
||||
|
||||
.sect .text
|
||||
.sect .rom
|
||||
.sect .data
|
||||
.sect .bss
|
||||
|
||||
! This file contains the code necessary to extend the ACK heap. This is called
|
||||
! by a i86/libem helper function called .strhp, which takes care of updating
|
||||
! some magic global variables --- defined here.
|
||||
|
||||
! Pointer to the current top of the heap.
|
||||
|
||||
.sect .data
|
||||
.define .reghp
|
||||
.reghp:
|
||||
.data2 endbss
|
||||
|
||||
! Pointer to the current top of memory.
|
||||
|
||||
.sect .data
|
||||
.define .limhp
|
||||
.limhp:
|
||||
.data2 endbss
|
||||
|
||||
! Claims more memory from the system, but does not actually change those
|
||||
! global variables (.strhp does that). This does not use the C calling
|
||||
! convention!
|
||||
!
|
||||
! Stack: ( desired_limhp : actual_limhp )
|
||||
! Also returns: ax = -1 on failure
|
||||
|
||||
.sect .text
|
||||
.define BRK
|
||||
BRK:
|
||||
pop bx ! holds return address
|
||||
pop ax ! holds desired limhp
|
||||
|
||||
cmp ax, sp ! compare sp with si
|
||||
jae fail ! si too big? (Overlaps stack?)
|
||||
cmp ax, endbss ! compare with bottom of heap
|
||||
jb fail ! si too small? (Overlaps bss?)
|
||||
|
||||
return:
|
||||
push ax ! success
|
||||
jmp bx
|
||||
|
||||
fail:
|
||||
mov ax, -1
|
||||
jmp return
|
||||
19
plat/pc86/libsys/_hol0.s
Normal file
19
plat/pc86/libsys/_hol0.s
Normal 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
|
||||
@@ -1,166 +0,0 @@
|
||||
#
|
||||
! $Source$
|
||||
! $State$
|
||||
! $Revision$
|
||||
|
||||
! Declare segments (the order is important).
|
||||
|
||||
.sect .text
|
||||
.sect .rom
|
||||
.sect .data
|
||||
.sect .bss
|
||||
|
||||
.sect .bss
|
||||
|
||||
.define __sys_params_in
|
||||
.comm __sys_params_in, 6
|
||||
|
||||
.define __sys_params_out
|
||||
.comm __sys_params_out, 2
|
||||
|
||||
.comm opcode, 2
|
||||
.comm returnto, 2
|
||||
|
||||
.sect .text
|
||||
|
||||
|
||||
! Called on system call. This does *not* use the C calling convention:
|
||||
! ax: syscall number
|
||||
! stack: ( param3 param2 param1 - result )
|
||||
|
||||
.define .mon
|
||||
.mon:
|
||||
mov (opcode), ax
|
||||
pop (returnto)
|
||||
|
||||
cmp ax, 1
|
||||
je exit
|
||||
cmp ax, 3
|
||||
je read
|
||||
cmp ax, 4
|
||||
je write
|
||||
cmp ax, 5
|
||||
je open
|
||||
cmp ax, 6
|
||||
je nop_1 ! close
|
||||
cmp ax, 20
|
||||
je nop_0 ! getpid
|
||||
cmp ax, 35
|
||||
je nop_1 ! time
|
||||
cmp ax, 48
|
||||
je sigtrp
|
||||
cmp ax, 54
|
||||
je ioctl
|
||||
|
||||
! Syscall not supported --- write out an error message and halt.
|
||||
|
||||
unsupported:
|
||||
mov si, msg
|
||||
1:
|
||||
lodsb
|
||||
andb al, al
|
||||
jz 2f
|
||||
movb ah, 0xE ! service
|
||||
mov bx, 0x0007 ! page 0, white
|
||||
int 0x10
|
||||
jmp 1b
|
||||
2:
|
||||
|
||||
! Write out the syscall number.
|
||||
|
||||
mov dx, (opcode)
|
||||
mov cx, 4 ! 4 hex digits
|
||||
1:
|
||||
rol dx, 1 ! rotate so that highest 4 bits are at the bottom
|
||||
rol dx, 1
|
||||
rol dx, 1
|
||||
rol dx, 1
|
||||
mov ax, 0xE0F ! ah = request, al = mask for nybble
|
||||
andb al, dl
|
||||
addb al, 0x90 ! convert al to ascii hex (four instructions)
|
||||
daa
|
||||
adcb al, 0x40
|
||||
daa
|
||||
int 0x10
|
||||
loop 1b
|
||||
|
||||
! Exit.
|
||||
|
||||
jmp EXIT
|
||||
|
||||
.sect .rom
|
||||
msg:
|
||||
.asciz 'NOSYS'
|
||||
|
||||
.sect .text
|
||||
|
||||
exit:
|
||||
jmp EXIT
|
||||
|
||||
read:
|
||||
mov ax, __sys_read
|
||||
jmp in_3_out_1
|
||||
|
||||
write:
|
||||
mov ax, __sys_write
|
||||
jmp in_3_out_1
|
||||
|
||||
open:
|
||||
add sp, 2*2
|
||||
jmp unimplemented
|
||||
|
||||
ioctl:
|
||||
mov ax, __sys_ioctl
|
||||
jmp in_3_out_0
|
||||
|
||||
sigtrp:
|
||||
add sp, 4
|
||||
jmp unimplemented
|
||||
|
||||
in_3_out_0:
|
||||
pop (__sys_params_in+0)
|
||||
pop (__sys_params_in+2)
|
||||
pop (__sys_params_in+4)
|
||||
call ax
|
||||
jmp out_0
|
||||
|
||||
in_3_out_1:
|
||||
pop (__sys_params_in+0)
|
||||
pop (__sys_params_in+2)
|
||||
pop (__sys_params_in+4)
|
||||
call ax
|
||||
jmp out_1
|
||||
|
||||
out_0:
|
||||
or ax, ax
|
||||
jnz failed
|
||||
push ax
|
||||
jmp return
|
||||
|
||||
out_1:
|
||||
or ax, ax
|
||||
jnz failed
|
||||
push (__sys_params_out)
|
||||
push ax
|
||||
jmp return
|
||||
|
||||
unimplemented:
|
||||
mov ax, EBADMON
|
||||
failed:
|
||||
push ax
|
||||
push ax
|
||||
jmp return
|
||||
|
||||
nop_1:
|
||||
add sp, 1*2
|
||||
jmp nop_0
|
||||
nop_3:
|
||||
add sp, 3*2
|
||||
nop_0:
|
||||
mov ax, 0
|
||||
push ax
|
||||
jmp return
|
||||
|
||||
return:
|
||||
jmp (returnto)
|
||||
|
||||
43
plat/pc86/libsys/brk.c
Normal file
43
plat/pc86/libsys/brk.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */
|
||||
#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))
|
||||
return -1;
|
||||
|
||||
current = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* sbrk(intptr_t increment)
|
||||
{
|
||||
char* old;
|
||||
|
||||
if (increment == 0)
|
||||
return current;
|
||||
|
||||
old = current;
|
||||
if (brk(old + increment) < 0)
|
||||
return OUT_OF_MEMORY;
|
||||
|
||||
return old;
|
||||
}
|
||||
14
plat/pc86/libsys/close.c
Normal file
14
plat/pc86/libsys/close.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
15
plat/pc86/libsys/creat.c
Normal file
15
plat/pc86/libsys/creat.c
Normal file
@@ -0,0 +1,15 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "libsys.h"
|
||||
|
||||
int open(const char* path, int access, ...)
|
||||
{
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
@@ -14,6 +14,9 @@
|
||||
|
||||
.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
|
||||
|
||||
13
plat/pc86/libsys/getpid.c
Normal file
13
plat/pc86/libsys/getpid.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
pid_t getpid(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
13
plat/pc86/libsys/isatty.c
Normal file
13
plat/pc86/libsys/isatty.c
Normal file
@@ -0,0 +1,13 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int isatty(int fd)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
14
plat/pc86/libsys/kill.c
Normal file
14
plat/pc86/libsys/kill.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int kill(pid_t pid, int sig)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
@@ -11,6 +11,6 @@ extern unsigned char _sys_rawread(void);
|
||||
|
||||
extern void _sys_write_tty(char c);
|
||||
|
||||
extern int _sys_ttyflags;
|
||||
/* extern int _sys_ttyflags; */
|
||||
|
||||
#endif
|
||||
|
||||
14
plat/pc86/libsys/lseek.c
Normal file
14
plat/pc86/libsys/lseek.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
14
plat/pc86/libsys/open.c
Normal file
14
plat/pc86/libsys/open.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "libsys.h"
|
||||
|
||||
int creat(const char* path, int mode)
|
||||
{
|
||||
return open(path, O_CREAT|O_WRONLY|O_TRUNC, mode);
|
||||
}
|
||||
@@ -9,13 +9,22 @@ libsys_pc86 = acklibrary {
|
||||
ACKINCLUDES = {"%BINDIR%include"},
|
||||
|
||||
ackfile (d.."errno.s"),
|
||||
ackfile (d.."_mon.s"),
|
||||
ackfile (d.."_brk.s"),
|
||||
ackfile (d.."_hol0.s"),
|
||||
ackfile (d.."_sys_rawread.s"),
|
||||
ackfile (d.."_sys_rawwrite.s"),
|
||||
ackfile (d.."_sys_read.c"),
|
||||
ackfile (d.."_sys_write.c"),
|
||||
ackfile (d.."_sys_ioctl.c"),
|
||||
ackfile (d.."open.c"),
|
||||
ackfile (d.."creat.c"),
|
||||
ackfile (d.."close.c"),
|
||||
ackfile (d.."read.c"),
|
||||
ackfile (d.."write.c"),
|
||||
-- ackfile (d.."_sys_ioctl.c"),
|
||||
ackfile (d.."brk.c"),
|
||||
ackfile (d.."getpid.c"),
|
||||
ackfile (d.."kill.c"),
|
||||
ackfile (d.."isatty.c"),
|
||||
ackfile (d.."lseek.c"),
|
||||
ackfile (d.."time.c"),
|
||||
ackfile (d.."signal.c"),
|
||||
|
||||
install = pm.install("%BINDIR%lib/%PLATFORM%/libsys.a"),
|
||||
}
|
||||
|
||||
@@ -5,50 +5,39 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sgtty.h>
|
||||
#include <unistd.h>
|
||||
#include "libsys.h"
|
||||
|
||||
extern struct
|
||||
{
|
||||
int fd;
|
||||
char* buffer;
|
||||
size_t count;
|
||||
} _sys_params_in;
|
||||
|
||||
extern struct
|
||||
{
|
||||
size_t bytesread;
|
||||
} _sys_params_out;
|
||||
|
||||
#define P _sys_params_in
|
||||
|
||||
int _sys_read(void)
|
||||
int read(int fd, void* buffer, size_t count)
|
||||
{
|
||||
char i;
|
||||
|
||||
/* We're only allowed to read from fd 0, 1 or 2. */
|
||||
|
||||
if ((P.fd < 0) || (P.fd > 2))
|
||||
return EBADF;
|
||||
if ((fd < 0) || (fd > 2))
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Empty buffer? */
|
||||
|
||||
if (P.count == 0)
|
||||
{
|
||||
_sys_params_out.bytesread = 0;
|
||||
if (count == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Read one byte. */
|
||||
|
||||
i = _sys_rawread();
|
||||
#if 0
|
||||
if ((i == '\r') && !(_sys_ttyflags & RAW))
|
||||
i = '\n';
|
||||
if (_sys_ttyflags & ECHO)
|
||||
_sys_write_tty(i);
|
||||
#endif
|
||||
if (i == '\r')
|
||||
i = '\n';
|
||||
_sys_write_tty(i);
|
||||
|
||||
*P.buffer = i;
|
||||
|
||||
_sys_params_out.bytesread = 1;
|
||||
return 0;
|
||||
*(char*)buffer = i;
|
||||
return 1;
|
||||
}
|
||||
15
plat/pc86/libsys/signal.c
Normal file
15
plat/pc86/libsys/signal.c
Normal file
@@ -0,0 +1,15 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include "libsys.h"
|
||||
|
||||
sighandler_t signal(int signum, sighandler_t handler)
|
||||
{
|
||||
return SIG_DFL;
|
||||
}
|
||||
17
plat/pc86/libsys/time.c
Normal file
17
plat/pc86/libsys/time.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $Source$
|
||||
* $State$
|
||||
* $Revision$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include "libsys.h"
|
||||
|
||||
time_t time(time_t* t)
|
||||
{
|
||||
if (t)
|
||||
*t = 0;
|
||||
return 0;
|
||||
}
|
||||
@@ -5,51 +5,44 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sgtty.h>
|
||||
#include <unistd.h>
|
||||
#include "libsys.h"
|
||||
|
||||
extern struct
|
||||
{
|
||||
int fd;
|
||||
const char* buffer;
|
||||
size_t count;
|
||||
} _sys_params_in;
|
||||
|
||||
extern struct
|
||||
{
|
||||
size_t byteswritten;
|
||||
} _sys_params_out;
|
||||
|
||||
#define P _sys_params_in
|
||||
|
||||
void _sys_write_tty(char c)
|
||||
{
|
||||
_sys_rawwrite(c);
|
||||
#if 0
|
||||
if ((c == '\n') && !(_sys_ttyflags & RAW))
|
||||
_sys_rawwrite('\r');
|
||||
#endif
|
||||
if (c == '\n')
|
||||
_sys_rawwrite('\r');
|
||||
}
|
||||
|
||||
int _sys_write(void)
|
||||
int write(int fd, void* buffer, size_t count)
|
||||
{
|
||||
int i;
|
||||
char* p = buffer;
|
||||
|
||||
/* We're only allowed to write to fd 0, 1 or 2. */
|
||||
|
||||
if ((P.fd < 0) || (P.fd > 2))
|
||||
return EBADF;
|
||||
if ((fd < 0) || (fd > 2))
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Write all data. */
|
||||
|
||||
i = 0;
|
||||
while (i < P.count)
|
||||
while (i < count)
|
||||
{
|
||||
_sys_write_tty(*P.buffer++);
|
||||
_sys_write_tty(*p++);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
/* No failures. */
|
||||
|
||||
_sys_params_out.byteswritten = P.count;
|
||||
return 0;
|
||||
return count;
|
||||
}
|
||||
Reference in New Issue
Block a user