From 890a253c42f25337b4805a0ef4ea2c64b0e32cef Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 27 Jun 2022 22:21:28 +0200 Subject: [PATCH 1/6] Attempt to build the luaposix rock on Windows. --- .github/workflows/ccpp.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 9a6f73fba..268eddb82 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -39,19 +39,18 @@ jobs: install: >- make mingw-w64-i686-gcc - mingw-w64-i686-lua51 - mingw-w64-i686-lua-luarocks + mingw-w64-x86_64-lua51 + mingw-w64-x86_64-lua-luarocks ninja bison flex zip - git - name: luarocks run: | - /mingw32/bin/luarocks --lua-version 5.1 install luaposix 33.0.0-1 + git config --global url."https://".insteadOf git:// + /mingw64/bin/luarocks --lua-version 5.1 install luaposix 33.0.0-1 - uses: actions/checkout@v3 - name: build run: | - eval $(/mingw32/bin/luarocks --lua-version 5.1 path) - make LUA=/mingw32/bin/lua5.1 + make LUA=/mingw64/bin/lua5.1 From 1d3f0e2ee1757ba3f7fef52616481ee4154dfcd4 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 27 Jun 2022 22:25:10 +0200 Subject: [PATCH 2/6] I need to manually install git? --- .github/workflows/ccpp.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 268eddb82..edbb1ea41 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -45,6 +45,7 @@ jobs: bison flex zip + git - name: luarocks run: | git config --global url."https://".insteadOf git:// From eef2135e9f9284f71a86928cee93703dde2333c0 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 27 Jun 2022 22:32:12 +0200 Subject: [PATCH 3/6] Give up on Windows for now. --- .github/workflows/ccpp.yml | 58 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index edbb1ea41..0131ce13f 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -26,32 +26,32 @@ jobs: eval $(luarocks --lua-version 5.1 path) make LUA=/usr/local/bin/lua5.1 - build-windows: - runs-on: windows-latest - defaults: - run: - shell: msys2 {0} - steps: - - uses: msys2/setup-msys2@v2 - with: - update: true - msystem: MINGW32 - install: >- - make - mingw-w64-i686-gcc - mingw-w64-x86_64-lua51 - mingw-w64-x86_64-lua-luarocks - ninja - bison - flex - zip - git - - name: luarocks - run: | - git config --global url."https://".insteadOf git:// - /mingw64/bin/luarocks --lua-version 5.1 install luaposix 33.0.0-1 - - uses: actions/checkout@v3 - - name: build - run: | - make LUA=/mingw64/bin/lua5.1 - +# build-windows: +# runs-on: windows-latest +# defaults: +# run: +# shell: msys2 {0} +# steps: +# - uses: msys2/setup-msys2@v2 +# with: +# update: true +# msystem: MINGW32 +# install: >- +# make +# mingw-w64-i686-gcc +# mingw-w64-x86_64-lua51 +# mingw-w64-x86_64-lua-luarocks +# ninja +# bison +# flex +# zip +# git +# - name: luarocks +# run: | +# git config --global url."https://".insteadOf git:// +# /mingw64/bin/luarocks --lua-version 5.1 install luaposix 33.0.0-1 +# - uses: actions/checkout@v3 +# - name: build +# run: | +# make LUA=/mingw64/bin/lua5.1 +# From 1c71653d7f95da25291da24adabb0fd663d4d910 Mon Sep 17 00:00:00 2001 From: tkchia Date: Tue, 28 Jun 2022 20:13:16 +0000 Subject: [PATCH 4/6] plat/msdos86: free up program memory above 64 KiB; also check we have enough memory for BSS --- plat/msdos86/boot.s | 54 +++++++++++++++++++++--------- plat/msdos86/libsys/sys_initmain.c | 4 +-- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/plat/msdos86/boot.s b/plat/msdos86/boot.s index 56d424e1c..f542f1626 100644 --- a/plat/msdos86/boot.s +++ b/plat/msdos86/boot.s @@ -12,6 +12,8 @@ .sect .text +#define STACK_BUFFER 128 /* number of bytes to leave for stack */ + begtext: ! Make sure we are running under MS-DOS 2 or above. ! @@ -20,9 +22,38 @@ begtext: ! segment. (DOS 3+ does; DOS 2.x does not.) movb ah, 0x30 int 0x21 + cbw cmpb al, 2 - xchg bx, ax - jc bad_sys + 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 @@ -35,11 +66,12 @@ begtext: ! Get the size of the environment variables plus (if present) the ! program name. Also count the number of environment variables. - mov es, (0x002C) xor di, di + mov es, 0x002C(di) ! ax = 0 from above cwd ! dx = count of env. vars. - mov cx, -1 + ! 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: @@ -48,7 +80,7 @@ size_env: scasb jnz size_env is_empty_env: - cmpb bl, 2 + cmp bp, 2 jz no_argv0 scasw repnz scasb @@ -58,10 +90,9 @@ no_argv0: ! onto the stack. mov si, di dec si - and si, -2 std copy_env: - test si, si + and si, -2 eseg lodsw push ax jnz copy_env @@ -79,7 +110,7 @@ copy_env: ! Build up argc, argv[], and envp[]. push ax ! output buffer for argc, argv, envp - push bx ! MS-DOS version + push bp ! MS-DOS version push cx ! env. string data push dx ! count of env. vars. mov ax, 0x0080 @@ -97,13 +128,6 @@ copy_env: push ax call _exit -bad_sys: - mov dx, bad_sys_msg -dos_msg: - movb ah, 9 - int 0x21 - ret - no_room: mov dx, no_room_msg call dos_msg diff --git a/plat/msdos86/libsys/sys_initmain.c b/plat/msdos86/libsys/sys_initmain.c index 5530a0510..84b215511 100644 --- a/plat/msdos86/libsys/sys_initmain.c +++ b/plat/msdos86/libsys/sys_initmain.c @@ -22,7 +22,7 @@ struct for_main { * Return zero if everything went well, non-zero otherwise. */ int _sys_initmain(char *arg_data, size_t n_env_vars, char *env_data, - unsigned msdos_ver, struct for_main *out) + unsigned msdos_ver_major, struct for_main *out) { char **argv, **envp; char c, *p, **pp; @@ -100,7 +100,7 @@ int _sys_initmain(char *arg_data, size_t n_env_vars, char *env_data, * shortword) following the environment variables, so advance p by 3 * bytes to get at the program name. */ - if ((msdos_ver & 0x00ff) >= 3) + if (msdos_ver_major >= 3) { p += 3; argv[0] = p; From 0a38acecfdbcd43ca356e20228017049553de5cd Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 29 Jun 2022 12:56:34 +0200 Subject: [PATCH 5/6] Update README --- README | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README b/README index 53630e755..e0601efa4 100644 --- a/README +++ b/README @@ -56,6 +56,8 @@ Requirements: - GNU make. +- Lua (any version) with the lua-posix library installed. + - (optionally) ninja; if you've got this, this will be autodetected and give you faster builds. From 80d1932ff8f2149a35c2063f1d6d95b9c99c59a7 Mon Sep 17 00:00:00 2001 From: tkchia Date: Sat, 16 Jul 2022 07:27:46 +0000 Subject: [PATCH 6/6] libcc.ansi: make abort() try harder to abort the process --- lang/cem/libcc.ansi/core/misc/abort.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lang/cem/libcc.ansi/core/misc/abort.c b/lang/cem/libcc.ansi/core/misc/abort.c index d59624169..bcf0759c7 100644 --- a/lang/cem/libcc.ansi/core/misc/abort.c +++ b/lang/cem/libcc.ansi/core/misc/abort.c @@ -1,14 +1,31 @@ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". + * + * (c) copyright 2022 by TK Chia. */ /* $Id$ */ #include #include #include +#include void abort(void) { - raise(SIGABRT); + unsigned short count = 0; + int *bad_ptr = NULL; + while (--count != 0) + raise(SIGABRT); + /* + * If the target platform does not implement raise(.), or the + * SIGABRT signal turns out to be handled or ignored, then our + * process may still be running. Try harder to make the process + * crash or exit. -- tkchia + */ + while (--count != 0) + abs(*bad_ptr); + write(2, "abort!\n", 7); + for (;;) + _exit(128 + SIGABRT); }