From 6d9ac0b182fad0946f46031ce354ee322a6ad60b Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 3 Aug 2022 20:41:06 +0200 Subject: [PATCH] Add the nonfunctional boilerplate for the MSDOS 386 port. --- build.lua | 1 + plat/msdos/include/ack/plat.h | 11 ++ plat/msdos/include/build.lua | 24 +++ plat/msdos/include/sys/types.h | 9 + plat/{msdos86 => msdos}/libsys/brk.c | 0 plat/msdos/libsys/build.lua | 28 +++ plat/{msdos86 => msdos}/libsys/creat.c | 0 plat/{msdos86 => msdos}/libsys/gettimeofday.c | 0 plat/{msdos86 => msdos}/libsys/kill.c | 0 plat/{msdos86 => msdos}/libsys/libsys.h | 0 plat/{msdos86 => msdos}/libsys/lseek.c | 0 plat/{msdos86 => msdos}/libsys/open.c | 0 plat/{msdos86 => msdos}/libsys/read.c | 0 plat/{msdos86 => msdos}/libsys/setmode.c | 0 plat/{msdos86 => msdos}/libsys/signal.c | 0 plat/{msdos86 => msdos}/libsys/sys_fdmodes.c | 0 plat/{msdos86 => msdos}/libsys/sys_getmode.c | 0 plat/{msdos86 => msdos}/libsys/sys_initmain.c | 0 plat/{msdos86 => msdos}/libsys/sys_iseof.c | 0 plat/{msdos86 => msdos}/libsys/sys_seteof.c | 0 plat/{msdos86 => msdos}/libsys/sys_seterrno.c | 0 plat/{msdos86 => msdos}/libsys/sys_setmode.c | 0 plat/{msdos86 => msdos}/libsys/write.c | 0 plat/msdos386/boot.s | 170 ++++++++++++++++++ plat/msdos386/build-pkg.lua | 25 +++ plat/msdos386/build-tools.lua | 21 +++ plat/msdos386/descr | 77 ++++++++ plat/msdos386/include/ack/plat.h | 6 + plat/msdos386/include/build.lua | 24 +++ plat/msdos386/include/sys/types.h | 9 + plat/msdos386/libsys/build.lua | 47 +++++ plat/msdos86/libsys/build.lua | 19 +- 32 files changed, 454 insertions(+), 17 deletions(-) create mode 100644 plat/msdos/include/ack/plat.h create mode 100644 plat/msdos/include/build.lua create mode 100644 plat/msdos/include/sys/types.h rename plat/{msdos86 => msdos}/libsys/brk.c (100%) create mode 100644 plat/msdos/libsys/build.lua rename plat/{msdos86 => msdos}/libsys/creat.c (100%) rename plat/{msdos86 => msdos}/libsys/gettimeofday.c (100%) rename plat/{msdos86 => msdos}/libsys/kill.c (100%) rename plat/{msdos86 => msdos}/libsys/libsys.h (100%) rename plat/{msdos86 => msdos}/libsys/lseek.c (100%) rename plat/{msdos86 => msdos}/libsys/open.c (100%) rename plat/{msdos86 => msdos}/libsys/read.c (100%) rename plat/{msdos86 => msdos}/libsys/setmode.c (100%) rename plat/{msdos86 => msdos}/libsys/signal.c (100%) rename plat/{msdos86 => msdos}/libsys/sys_fdmodes.c (100%) rename plat/{msdos86 => msdos}/libsys/sys_getmode.c (100%) rename plat/{msdos86 => msdos}/libsys/sys_initmain.c (100%) rename plat/{msdos86 => msdos}/libsys/sys_iseof.c (100%) rename plat/{msdos86 => msdos}/libsys/sys_seteof.c (100%) rename plat/{msdos86 => msdos}/libsys/sys_seterrno.c (100%) rename plat/{msdos86 => msdos}/libsys/sys_setmode.c (100%) rename plat/{msdos86 => msdos}/libsys/write.c (100%) create mode 100644 plat/msdos386/boot.s create mode 100644 plat/msdos386/build-pkg.lua create mode 100644 plat/msdos386/build-tools.lua create mode 100644 plat/msdos386/descr create mode 100644 plat/msdos386/include/ack/plat.h create mode 100644 plat/msdos386/include/build.lua create mode 100644 plat/msdos386/include/sys/types.h create mode 100644 plat/msdos386/libsys/build.lua diff --git a/build.lua b/build.lua index 319571d8a..b0c2beebd 100644 --- a/build.lua +++ b/build.lua @@ -12,6 +12,7 @@ vars.plats = { "linuxppc", "linuxmips", "msdos86", + "msdos386", "osx386", "osxppc", "pc86", diff --git a/plat/msdos/include/ack/plat.h b/plat/msdos/include/ack/plat.h new file mode 100644 index 000000000..4343f1cf8 --- /dev/null +++ b/plat/msdos/include/ack/plat.h @@ -0,0 +1,11 @@ +/* $Source$ + * $State$ + * $Revision$ + */ + +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H + +#define ACKCONF_WANT_O_TEXT_O_BINARY 1 + +#endif diff --git a/plat/msdos/include/build.lua b/plat/msdos/include/build.lua new file mode 100644 index 000000000..6ae480041 --- /dev/null +++ b/plat/msdos/include/build.lua @@ -0,0 +1,24 @@ +include("plat/build.lua") + +headermap = {} +packagemap = {} + +local function addheader(h) + headermap[h] = "./"..h + packagemap["$(PLATIND)/msdos86/include/"..h] = "./"..h +end + +addheader("ack/plat.h") +addheader("sys/types.h") + +acklibrary { + name = "headers", + hdrs = headermap +} + +installable { + name = "pkg", + map = packagemap +} + + diff --git a/plat/msdos/include/sys/types.h b/plat/msdos/include/sys/types.h new file mode 100644 index 000000000..005f48eb0 --- /dev/null +++ b/plat/msdos/include/sys/types.h @@ -0,0 +1,9 @@ +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H + +typedef long pid_t; +typedef int mode_t; +typedef long time_t; +typedef long suseconds_t; + +#endif diff --git a/plat/msdos86/libsys/brk.c b/plat/msdos/libsys/brk.c similarity index 100% rename from plat/msdos86/libsys/brk.c rename to plat/msdos/libsys/brk.c diff --git a/plat/msdos/libsys/build.lua b/plat/msdos/libsys/build.lua new file mode 100644 index 000000000..d808fe894 --- /dev/null +++ b/plat/msdos/libsys/build.lua @@ -0,0 +1,28 @@ +bundle { + name = "srcs", + srcs = { + "./creat.c", + "./gettimeofday.c", + "./kill.c", + "./lseek.c", + "./open.c", + "./read.c", + "./setmode.c", + "./signal.c", + "./sys_fdmodes.c", + "./sys_getmode.c", + "./sys_initmain.c", + "./sys_iseof.c", + "./sys_seteof.c", + "./sys_seterrno.c", + "./sys_setmode.c", + "./write.c", + } +} + +bundle { + name = "headers", + srcs = { + "./libsys.h" + } +} diff --git a/plat/msdos86/libsys/creat.c b/plat/msdos/libsys/creat.c similarity index 100% rename from plat/msdos86/libsys/creat.c rename to plat/msdos/libsys/creat.c diff --git a/plat/msdos86/libsys/gettimeofday.c b/plat/msdos/libsys/gettimeofday.c similarity index 100% rename from plat/msdos86/libsys/gettimeofday.c rename to plat/msdos/libsys/gettimeofday.c diff --git a/plat/msdos86/libsys/kill.c b/plat/msdos/libsys/kill.c similarity index 100% rename from plat/msdos86/libsys/kill.c rename to plat/msdos/libsys/kill.c diff --git a/plat/msdos86/libsys/libsys.h b/plat/msdos/libsys/libsys.h similarity index 100% rename from plat/msdos86/libsys/libsys.h rename to plat/msdos/libsys/libsys.h diff --git a/plat/msdos86/libsys/lseek.c b/plat/msdos/libsys/lseek.c similarity index 100% rename from plat/msdos86/libsys/lseek.c rename to plat/msdos/libsys/lseek.c diff --git a/plat/msdos86/libsys/open.c b/plat/msdos/libsys/open.c similarity index 100% rename from plat/msdos86/libsys/open.c rename to plat/msdos/libsys/open.c diff --git a/plat/msdos86/libsys/read.c b/plat/msdos/libsys/read.c similarity index 100% rename from plat/msdos86/libsys/read.c rename to plat/msdos/libsys/read.c diff --git a/plat/msdos86/libsys/setmode.c b/plat/msdos/libsys/setmode.c similarity index 100% rename from plat/msdos86/libsys/setmode.c rename to plat/msdos/libsys/setmode.c diff --git a/plat/msdos86/libsys/signal.c b/plat/msdos/libsys/signal.c similarity index 100% rename from plat/msdos86/libsys/signal.c rename to plat/msdos/libsys/signal.c diff --git a/plat/msdos86/libsys/sys_fdmodes.c b/plat/msdos/libsys/sys_fdmodes.c similarity index 100% rename from plat/msdos86/libsys/sys_fdmodes.c rename to plat/msdos/libsys/sys_fdmodes.c diff --git a/plat/msdos86/libsys/sys_getmode.c b/plat/msdos/libsys/sys_getmode.c similarity index 100% rename from plat/msdos86/libsys/sys_getmode.c rename to plat/msdos/libsys/sys_getmode.c diff --git a/plat/msdos86/libsys/sys_initmain.c b/plat/msdos/libsys/sys_initmain.c similarity index 100% rename from plat/msdos86/libsys/sys_initmain.c rename to plat/msdos/libsys/sys_initmain.c diff --git a/plat/msdos86/libsys/sys_iseof.c b/plat/msdos/libsys/sys_iseof.c similarity index 100% rename from plat/msdos86/libsys/sys_iseof.c rename to plat/msdos/libsys/sys_iseof.c diff --git a/plat/msdos86/libsys/sys_seteof.c b/plat/msdos/libsys/sys_seteof.c similarity index 100% rename from plat/msdos86/libsys/sys_seteof.c rename to plat/msdos/libsys/sys_seteof.c diff --git a/plat/msdos86/libsys/sys_seterrno.c b/plat/msdos/libsys/sys_seterrno.c similarity index 100% rename from plat/msdos86/libsys/sys_seterrno.c rename to plat/msdos/libsys/sys_seterrno.c diff --git a/plat/msdos86/libsys/sys_setmode.c b/plat/msdos/libsys/sys_setmode.c similarity index 100% rename from plat/msdos86/libsys/sys_setmode.c rename to plat/msdos/libsys/sys_setmode.c diff --git a/plat/msdos86/libsys/write.c b/plat/msdos/libsys/write.c similarity index 100% rename from plat/msdos86/libsys/write.c rename to plat/msdos/libsys/write.c diff --git a/plat/msdos386/boot.s b/plat/msdos386/boot.s new file mode 100644 index 000000000..451291b13 --- /dev/null +++ b/plat/msdos386/boot.s @@ -0,0 +1,170 @@ +# +! $Source$ +! $State$ +! $Revision$ + +! Declare segments (the order is important). + +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text +.use16 + +#define STACK_BUFFER 128 /* number of bytes to leave for stack */ + +begtext: + ! Make sure we are running under MS-DOS 2 or above. + ! + ! While at it, also remember the actual DOS version, so that we know + ! whether DOS gives us the program's name in the environment + ! segment. (DOS 3+ does; DOS 2.x does not.) + movb ah, 0x30 + int 0x21 + cbw + cmpb al, 2 + xchg bp, ax + jnc ok_sys + + mov dx, bad_sys_msg +dos_msg: + movb ah, 9 + int 0x21 + ret + +ok_sys: + ! Resize the program's memory control block (MCB) to cover only the + ! program's near code and data space. Use the starting sp value as + ! a guide to how much memory we can grab. Abort on any failure. + ! + ! As a side effect, this also frees up any memory allocated to our + ! program beyond 64 KiB. (The freed memory can possibly be used by + ! e.g. child processes, in the future.) + ! + ! Also check that we have some space between the BSS end and the + ! starting sp. + cmp sp, endbss+STACK_BUFFER + jb no_room + + movb ah, 0x4a + mov bx, sp + movb cl, 4 + shr bx, cl + inc bx + int 0x21 + jc no_room + + ! Clear BSS. + mov di, begbss + mov cx, endbss+1 + sub cx, di + shr cx, 1 + xor ax, ax + cld + rep stosw + + ! Get the size of the environment variables plus (if present) the + ! program name. Also count the number of environment variables. + xor di, di + mov es, 0x002C(di) + ! ax = 0 from above + cwd ! dx = count of env. vars. + ! cx = 0 from above + dec cx ! cx = max. str. bytes to scan + scasb ! handle special case of empty env. + jz is_empty_env +size_env: + inc dx + repnz scasb + scasb + jnz size_env +is_empty_env: + cmp bp, 2 + jz no_argv0 + scasw + repnz scasb +no_argv0: + + ! Copy out the environment variables and (possibly) program name + ! onto the stack. + mov si, di + dec si + std +copy_env: + and si, -2 + eseg lodsw + push ax + jnz copy_env + mov cx, sp + + ! Reset DF and es properly. + cld + push ss + pop es + + ! Reserve space for argc and the argv and envp pointers on the + ! stack. These will be passed to __m_a_i_n later. + sub sp, 6 + mov ax, sp + + ! Build up argc, argv[], and envp[]. + push ax ! output buffer for argc, argv, envp + push bp ! MS-DOS version + push cx ! env. string data + push dx ! count of env. vars. + mov ax, 0x0080 + push ax ! raw command line + call __sys_initmain + add sp, 10 + + ! Bail out if something went wrong. + test ax, ax + jnz no_room + + ! argc, argv, and envp are now at the stack top. Now go. + call __m_a_i_n + add sp, 6 + push ax + call _exit + +no_room: + mov dx, no_room_msg + call dos_msg + movb al, -1 + jmp al_exit + + ! Exit. +.define __exit +.extern __exit +.define EXIT +.extern EXIT +__exit: +EXIT: + pop bx + pop ax +al_exit: + movb ah, 0x4c + int 0x21 + +! Define symbols at the beginning of our various segments, so that we can find +! them. (Except .text, which has already been done.) + +.define begtext, begdata, begbss +.sect .data; begdata: +.sect .rom; begrom: +.sect .bss; begbss: + +.sect .rom + +! Some text messages. +bad_sys_msg: .ascii 'Bad DOS$' +no_room_msg: .ascii 'No room$' + +! Some magic data. All EM systems need these. + +.define .trppc, .ignmask, _errno +.comm .trppc, 4 +.comm .ignmask, 4 +.comm _errno, 4 diff --git a/plat/msdos386/build-pkg.lua b/plat/msdos386/build-pkg.lua new file mode 100644 index 000000000..98cce47cc --- /dev/null +++ b/plat/msdos386/build-pkg.lua @@ -0,0 +1,25 @@ +include("plat/build.lua") + +ackfile { + name = "boot", + srcs = { "./boot.s" }, + vars = { plat = "msdos386" } +} + +build_plat_libs { + name = "libs", + arch = "i386", + plat = "msdos386", +} + +installable { + name = "pkg", + map = { + "+tools", + "+libs", + "./include+pkg", + ["$(PLATIND)/msdos386/boot.o"] = "+boot", + ["$(PLATIND)/msdos386/libsys.a"] = "./libsys+lib", + } +} + diff --git a/plat/msdos386/build-tools.lua b/plat/msdos386/build-tools.lua new file mode 100644 index 000000000..d28aee904 --- /dev/null +++ b/plat/msdos386/build-tools.lua @@ -0,0 +1,21 @@ +include("plat/build.lua") + +build_as { + name = "as", + arch = "i386", +} + +build_ncg { + name = "ncg", + arch = "i386", +} + +return installable { + name = "tools", + map = { + ["$(PLATDEP)/msdos386/as"] = "+as", + ["$(PLATDEP)/msdos386/ncg"] = "+ncg", + ["$(PLATIND)/descr/msdos386"] = "./descr", + "util/opt+pkg", + } +} diff --git a/plat/msdos386/descr b/plat/msdos386/descr new file mode 100644 index 000000000..f6559471e --- /dev/null +++ b/plat/msdos386/descr @@ -0,0 +1,77 @@ +var w=4 +var wa=2 +var p=4 +var pa=2 +var s=2 +var sa=2 +var l=4 +var la=2 +var f=4 +var fa=2 +var d=8 +var da=2 +var x=8 +var xa=2 +var ARCH=i386 +var PLATFORM=msdos386 +var PLATFORMDIR={EM}/share/ack/{PLATFORM} +var CPP_F=-D__MSDOS__ -D__DOS__ -D_DOS +var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 +var MACHOPT_F=-m8 +var EGO_PLAT_FLAGS=-M{EM}/share/ack/ego/{ARCH}.descr + +# Override the setting in fe so that files compiled for this platform can see +# the platform-specific headers. + +var C_INCLUDES=-I{PLATFORMDIR}/include -I{EM}/share/ack/include/ansi + +name be + from .m.g + to .s + program {EM}/lib/ack/{PLATFORM}/ncg + args < + stdout + need .e +end +name as + from .s.so + to .o + program {EM}/lib/ack/{PLATFORM}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/ack/em_led + mapflag -l* LNAME={PLATFORMDIR}/lib* + mapflag -fp FLOATS={EM}/{ILIB}fp + args {ALIGN} {SEPID} \ + ({RTS}:.b=-u _i_main) \ + (.e:{HEAD}={PLATFORMDIR}/boot.o) \ + ({RTS}:.ocm.bas.b={PLATFORMDIR}/c-ansi.o) \ + ({RTS}:.c={PLATFORMDIR}/c-ansi.o) \ + ({RTS}:.mod={PLATFORMDIR}/modula2.o) \ + ({RTS}:.p={PLATFORMDIR}/pascal.o) \ + -o > < \ + (.p:{TAIL}={PLATFORMDIR}/libpascal.a) \ + (.b:{TAIL}={PLATFORMDIR}/libb.a) \ + (.bas:{TAIL}={PLATFORMDIR}/libbasic.a) \ + (.mod:{TAIL}={PLATFORMDIR}/libmodula2.a) \ + (.ocm:{TAIL}={PLATFORMDIR}/liboccam.a) \ + (.ocm.bas.mod.b.c.p:{TAIL}={PLATFORMDIR}/libc.a) \ + {FLOATS?} \ + (.e:{TAIL}={PLATFORMDIR}/libem.a \ + {PLATFORMDIR}/libsys.a \ + {PLATFORMDIR}/libc.a \ + {PLATFORMDIR}/libem.a \ + {PLATFORMDIR}/libend.a) + linker +end +name cv + from .out + to .exe + program {EM}/bin/aslod + args < > + outfile msdos386.exe +end diff --git a/plat/msdos386/include/ack/plat.h b/plat/msdos386/include/ack/plat.h new file mode 100644 index 000000000..c0d1b9fff --- /dev/null +++ b/plat/msdos386/include/ack/plat.h @@ -0,0 +1,6 @@ +#ifndef _ACK_PLAT_H +#define _ACK_PLAT_H + +#define ACKCONF_WANT_O_TEXT_O_BINARY 1 + +#endif diff --git a/plat/msdos386/include/build.lua b/plat/msdos386/include/build.lua new file mode 100644 index 000000000..693abd0c1 --- /dev/null +++ b/plat/msdos386/include/build.lua @@ -0,0 +1,24 @@ +include("plat/build.lua") + +headermap = {} +packagemap = {} + +local function addheader(h) + headermap[h] = "./"..h + packagemap["$(PLATIND)/msdos386/include/"..h] = "./"..h +end + +addheader("ack/plat.h") +addheader("sys/types.h") + +acklibrary { + name = "headers", + hdrs = headermap +} + +installable { + name = "pkg", + map = packagemap +} + + diff --git a/plat/msdos386/include/sys/types.h b/plat/msdos386/include/sys/types.h new file mode 100644 index 000000000..005f48eb0 --- /dev/null +++ b/plat/msdos386/include/sys/types.h @@ -0,0 +1,9 @@ +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H + +typedef long pid_t; +typedef int mode_t; +typedef long time_t; +typedef long suseconds_t; + +#endif diff --git a/plat/msdos386/libsys/build.lua b/plat/msdos386/libsys/build.lua new file mode 100644 index 000000000..c2ae13f52 --- /dev/null +++ b/plat/msdos386/libsys/build.lua @@ -0,0 +1,47 @@ +acklibrary { + name = "lib", + srcs = { +-- "./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", + "plat/msdos/libsys+srcs", + }, + deps = { + "lang/cem/libcc.ansi/headers+headers", + "plat/msdos386/include+headers", + "plat/msdos/libsys+headers", + }, + vars = { + plat = "msdos386" + } +} + diff --git a/plat/msdos86/libsys/build.lua b/plat/msdos86/libsys/build.lua index eddbbf262..e7d9b8fc7 100644 --- a/plat/msdos86/libsys/build.lua +++ b/plat/msdos86/libsys/build.lua @@ -1,43 +1,28 @@ acklibrary { name = "lib", srcs = { - "./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", - "./write.c", + "plat/msdos/libsys+srcs", }, deps = { "lang/cem/libcc.ansi/headers+headers", "plat/msdos86/include+headers", + "plat/msdos/libsys+headers", }, vars = { plat = "msdos86"