Create a basic and probably wrong common unistd.h, which replaces the plat one.

Made this work with cpm (but nothing else yet).
This commit is contained in:
David Given 2018-06-23 11:46:55 +02:00
parent dd0f959245
commit 32c881474e
8 changed files with 83 additions and 58 deletions

View file

@ -7,23 +7,23 @@ vars.ackcflags = {
vars.ackldflags = {} vars.ackldflags = {}
vars.plats = { vars.plats = {
"cpm", "cpm",
"linux386", -- "linux386",
"linux68k", -- "linux68k",
"linuxppc", -- "linuxppc",
"osx386", -- "osx386",
"osxppc", -- "osxppc",
--"qemuppc", -- --"qemuppc",
"pc86", -- "pc86",
"rpi", -- "rpi",
"pdpv7", -- "pdpv7",
"em22", -- "em22",
} }
vars.plats_with_tests = { vars.plats_with_tests = {
"linux68k", -- "linux68k",
"linux386", -- "linux386",
"linuxppc", -- "linuxppc",
--"qemuppc", -- --"qemuppc",
"pc86", -- "pc86",
} }
local plat_packages = {} local plat_packages = {}

View file

@ -11,4 +11,12 @@
#define ACKCONF_WANT_STDIO_FLOAT ACKCONF_WANT_FLOAT #define ACKCONF_WANT_STDIO_FLOAT ACKCONF_WANT_FLOAT
#endif #endif
#ifndef ACKCONF_WANT_STANDARD_O
#define ACKCONF_WANT_STANDARD_O 1
#endif
#ifndef ACKCONF_WANT_STANDARD_SIGNALS
#define ACKCONF_WANT_STANDARD_SIGNALS 1
#endif
#endif #endif

View file

@ -58,6 +58,7 @@ typedef int16_t intptr_t;
typedef uint16_t uintptr_t; typedef uint16_t uintptr_t;
typedef int16_t ptrdiff_t; typedef int16_t ptrdiff_t;
typedef uint16_t size_t; typedef uint16_t size_t;
typedef int16_t ssize_t;
#define INTPTR_MAX 32767 #define INTPTR_MAX 32767
#define INTPTR_MIN (-32768) #define INTPTR_MIN (-32768)
#define UINTPTR_MAX 65535 #define UINTPTR_MAX 65535
@ -66,6 +67,7 @@ typedef int32_t intptr_t;
typedef uint32_t uintptr_t; typedef uint32_t uintptr_t;
typedef int32_t ptrdiff_t; typedef int32_t ptrdiff_t;
typedef uint32_t size_t; typedef uint32_t size_t;
typedef int32_t ssize_t;
#define INTPTR_MAX 2147483647 #define INTPTR_MAX 2147483647
#define INTPTR_MIN (-2147483647) #define INTPTR_MIN (-2147483647)
#define UINTPTR_MAX 4294967295 #define UINTPTR_MAX 4294967295

View file

@ -1,19 +1,20 @@
/*
* unistd.h - standard system calls
*/
/* $Id$ */
#ifndef _UNISTD_H #ifndef _UNISTD_H
#define _UNISTD_H #define _UNISTD_H
/*
* Generic Posix prototypes used by the rest of the libc. Plats don't have to
* implement these if they don't care about the functionality, but if they do,
* they must conform to these prototypes.
*/
#include <ack/config.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
/* Types */ #if ACKCONF_WANT_STANDARD_O
/* A standard set of flags for read/write/creat and friends for platforms
typedef int pid_t; * where these aren't determined by the operating system. */
typedef int mode_t;
/* Constants for file access (open and friends) */
enum enum
{ {
@ -28,31 +29,11 @@ enum
O_APPEND = 02000, O_APPEND = 02000,
O_NONBLOCK = 04000 O_NONBLOCK = 04000
}; };
#endif
/* Special variables */ #if ACKCONF_WANT_STANDARD_SIGNALS
/* A standard set of definitions for signal handling for platforms where these
extern char** environ; * aren't determined by the operating system. */
/* Implemented system calls */
extern void _exit(int);
extern pid_t getpid(void);
extern void* sbrk(int increment);
extern int isatty(int d);
extern off_t lseek(int fildes, off_t offset, int whence);
extern int close(int d);
extern int open(const char* path, int access, ...);
extern int creat(const char* path, mode_t mode);
extern int read(int fd, void* buffer, size_t count);
extern int write(int fd, void* buffer, size_t count);
extern int unlink(const char* path);
/* Unimplemented system calls (these are just prototypes to let the library
* compile). */
extern int fcntl(int fd, int op, ...);
/* Signal handling */
typedef int sig_atomic_t; typedef int sig_atomic_t;
@ -63,10 +44,37 @@ typedef int sig_atomic_t;
#define SIGABRT 6 /* Abort (ANSI) */ #define SIGABRT 6 /* Abort (ANSI) */
#define SIGILL 11 /* Illegal instruction */ #define SIGILL 11 /* Illegal instruction */
#define _NSIG 32 /* Biggest signal number + 1 #define _NSIG 16 /* Biggest signal number + 1
(not including real-time signals). */ (not including real-time signals). */
typedef void (*sighandler_t)(int); typedef void (*sighandler_t)(int);
extern sighandler_t signal(int signum, sighandler_t handler); typedef uint16_t sigset_t;
extern int raise(int signum);
#endif
/* Special variables */
extern char** environ;
/* Implemented system calls */
extern int brk(void* ptr);
extern int close(int d);
extern int creat(const char* path, mode_t mode);
extern int execve(const char *path, char *const argv[], char *const envp[]);
extern int isatty(int d);
extern int isatty(int d);
extern int kill(pid_t old, int sig);
extern int open(const char* path, int access, ...);
extern int raise(int signum);
extern int sigprocmask(int, const sigset_t *, sigset_t *);
extern int unlink(const char* path);
extern off_t lseek(int fildes, off_t offset, int whence);
extern pid_t getpid(void);
extern sighandler_t signal(int signum, sighandler_t handler);
extern ssize_t read(int fd, void* buffer, size_t count);
extern ssize_t write(int fd, void* buffer, size_t count);
extern void _exit(int);
extern void* sbrk(int increment);
extern int fcntl(int fd, int op, ...);
#endif #endif

View file

@ -9,8 +9,8 @@ local function addheader(h)
end end
addheader("ack/plat.h") addheader("ack/plat.h")
addheader("sys/types.h")
addheader("cpm.h") addheader("cpm.h")
addheader("unistd.h")
acklibrary { acklibrary {
name = "headers", name = "headers",

View file

@ -0,0 +1,7 @@
#ifndef _SYS_TYPES_H
#define _SYS_TYPES_H
typedef int pid_t;
typedef int mode_t;
#endif

View file

@ -8,7 +8,7 @@
#include <unistd.h> #include <unistd.h>
#include <cpm.h> #include <cpm.h>
int read(int fd, void* buffer, size_t count) ssize_t read(int fd, void* buffer, size_t count)
{ {
short save; short save;
unsigned char before_n; unsigned char before_n;
@ -37,7 +37,7 @@ int read(int fd, void* buffer, size_t count)
/* Read one line from the console. */ /* Read one line from the console. */
((unsigned char*)buffer)[-2] = before_n; ((unsigned char*)buffer)[-2] = before_n;
cpm_bc_register = CPM_BDOS_READ_CONSOLE_BUFFER; cpm_bc_register = CPM_BDOS_READ_CONSOLE_BUFFER;
cpm_de_register = (char*)buffer - 2; cpm_de_register = (uint16_t)(char*)buffer - 2;
cpm_bdos(); cpm_bdos();
before_n = ((unsigned char*)buffer)[-1]; before_n = ((unsigned char*)buffer)[-1];
@ -46,7 +46,7 @@ int read(int fd, void* buffer, size_t count)
/* Echo '\n' to console. */ /* Echo '\n' to console. */
cpm_bc_register = CPM_BDOS_PRINT_STRING; cpm_bc_register = CPM_BDOS_PRINT_STRING;
cpm_de_register = "\r\n$"; cpm_de_register = (uint16_t)"\r\n$";
cpm_bdos(); cpm_bdos();
return (int)before_n + 1; return (int)before_n + 1;

View file

@ -22,7 +22,7 @@ void _sys_write_tty(char c)
} }
} }
int write(int fd, void* buffer, size_t count) ssize_t write(int fd, void* buffer, size_t count)
{ {
int i; int i;
char* p = buffer; char* p = buffer;