Add the nonfunctional boilerplate for the MSDOS 386 port.

This commit is contained in:
David Given 2022-08-03 20:41:06 +02:00
parent a45f1cdd33
commit 6d9ac0b182
32 changed files with 454 additions and 17 deletions

View file

@ -12,6 +12,7 @@ vars.plats = {
"linuxppc", "linuxppc",
"linuxmips", "linuxmips",
"msdos86", "msdos86",
"msdos386",
"osx386", "osx386",
"osxppc", "osxppc",
"pc86", "pc86",

View file

@ -0,0 +1,11 @@
/* $Source$
* $State$
* $Revision$
*/
#ifndef _ACK_PLAT_H
#define _ACK_PLAT_H
#define ACKCONF_WANT_O_TEXT_O_BINARY 1
#endif

View file

@ -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
}

View file

@ -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

View file

@ -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"
}
}

170
plat/msdos386/boot.s Normal file
View file

@ -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

View file

@ -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",
}
}

View file

@ -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",
}
}

77
plat/msdos386/descr Normal file
View file

@ -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

View file

@ -0,0 +1,6 @@
#ifndef _ACK_PLAT_H
#define _ACK_PLAT_H
#define ACKCONF_WANT_O_TEXT_O_BINARY 1
#endif

View file

@ -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
}

View file

@ -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

View file

@ -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"
}
}

View file

@ -1,43 +1,28 @@
acklibrary { acklibrary {
name = "lib", name = "lib",
srcs = { srcs = {
"./brk.c",
"./close.s", "./close.s",
"./creat.c",
"./errno.s", "./errno.s",
"./getpid.s", "./getpid.s",
"./gettimeofday.c",
"./_hol0.s", "./_hol0.s",
"./isatty.s", "./isatty.s",
"./kill.c",
"./lseek.c",
"./open.c",
"./read.c",
"./setmode.c",
"./signal.c",
"./sys_exists.s", "./sys_exists.s",
"./sys_fdmodes.c",
"./sys_getdate.s", "./sys_getdate.s",
"./sys_getmode.c",
"./sys_gettime.s", "./sys_gettime.s",
"./sys_initmain.c",
"./sys_iseof.c",
"./sys_isopen.s", "./sys_isopen.s",
"./sys_isreadyr.s", "./sys_isreadyr.s",
"./sys_rawcreat.s", "./sys_rawcreat.s",
"./sys_rawlseek.s", "./sys_rawlseek.s",
"./sys_rawopen.s", "./sys_rawopen.s",
"./sys_rawrw.s", "./sys_rawrw.s",
"./sys_seteof.c",
"./sys_seterrno.c",
"./sys_setmode.c",
"./sys_xret.s", "./sys_xret.s",
"./unlink.s", "./unlink.s",
"./write.c", "plat/msdos/libsys+srcs",
}, },
deps = { deps = {
"lang/cem/libcc.ansi/headers+headers", "lang/cem/libcc.ansi/headers+headers",
"plat/msdos86/include+headers", "plat/msdos86/include+headers",
"plat/msdos/libsys+headers",
}, },
vars = { vars = {
plat = "msdos86" plat = "msdos86"