Skip to content

Commit b7205b6

Browse files
bdgscotlandchrisbra
authored andcommitted
patch 9.2.0290: Amiga: no support for AmigaOS 3.x
Problem: Amiga: no support for AmigaOS 3.x Solution: Add support for building Vim on classic AmigaOS 3.x with the bebbo cross-compiler and libnix (-noixemul) runtime (Duncan Bowring). The existing Make_ami.mak targets AmigaOS 4 (clib2), AROS, and MorphOS. This patch adds a fourth target for classic 68k AmigaOS 3.x systems (A1200, A4000, accelerated A500/A2000) using: ``` make -f Make_ami.mak UNM=AmigaOS3 BUILD=normal ``` Changes: os_amiga.c: - Add 256 KiB __stack cookie for OS3 (conservative for limited RAM) - Add safe_Lock() wrapper to suppress "Please insert volume" system requesters during path probing (benefits all Amiga targets) - Suppress system requesters globally in mch_init() via pr_WindowPtr=-1 (Vim probes many paths at startup; Lock()/Open() on non-existent volume names triggers blocking system requesters) - Fix mch_get_host_name() for OS3 (libnix has no gethostname) - Fix Delay() prototype for non-LATTICE compilers - Fix nilfh file handle leak on error exit in mch_check_win() os_amiga.h: - Add fchown/fchmod/ftruncate no-op stubs for OS3/libnix os_amiga_stubs.c (new): - IM function stubs (referenced by optiondefs.h, no X11 on Amiga) - mch_rmdir() via AmigaDOS DeleteFile() - getpwuid()/getgrgid()/getuid() stubs (single-user system) Make_ami.mak: - Add AmigaOS3 target with -noixemul, -std=gnu99, -DWORDS_BIGENDIAN blowfish.c: - Accept WORDS_BIGENDIAN or AMIGA without requiring HAVE_CONFIG_H xdiff/xmacros.h: - Make SIZE_MAX fallback unconditional (not just hpux/VMS) All OS3-specific changes are guarded by: #if defined(__GNUC__) && defined(AMIGA) && !defined(__amigaos4__) Tested on FS-UAE with Workbench 3.1: 23 automated tests passing. Binary size: 2.2 MiB with -Os -m68020 -DFEAT_NORMAL. This is the first modern Vim build for classic 68k AmigaOS since Vim 5.8 circa 1998. Vim was originally released on the Amiga (Fred Fish Disk 591, 1991). closes: #19840 Signed-off-by: Duncan Bowring <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 23be188 commit b7205b6

8 files changed

Lines changed: 173 additions & 16 deletions

File tree

Filelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ SRC_AMI = \
678678
src/Make_ami.mak \
679679
src/os_amiga.c \
680680
src/os_amiga.h \
681+
src/os_amiga_stubs.c \
681682
src/proto/os_amiga.pro \
682683
src/testdir/Make_amiga.mak \
683684
src/testdir/util/amiga.vim \

src/Make_ami.mak

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Makefile for AROS, AmigaOS4 and MorphOS.
2+
# Makefile for AROS, AmigaOS 3.x, AmigaOS 4 and MorphOS.
33
#
44
BIN = vim
55
CC ?= gcc
@@ -52,6 +52,7 @@ endif
5252

5353
# OS specific compiler flags
5454
ifeq ($(UNM),AmigaOS)
55+
# AmigaOS 4 (PowerPC)
5556
LDFLAGS = -lauto
5657
CFLAGS += -DHAVE_FSYNC -D__USE_INLINE__
5758
else
@@ -61,6 +62,12 @@ else
6162
ifeq ($(UNM),MorphOS)
6263
CFLAGS += -noixemul
6364
LDFLAGS = -ldebug -lm -noixemul
65+
else
66+
# Classic AmigaOS 3.x (68k) with bebbo-gcc and libnix.
67+
# Build: make -f Make_ami.mak UNM=AmigaOS3 CC=m68k-amigaos-gcc BUILD=normal
68+
CFLAGS += -noixemul -std=gnu99 -DWORDS_BIGENDIAN -DHAVE_ERRNO_H
69+
LDFLAGS = -noixemul -lm
70+
endif
6471
endif
6572
endif
6673
endif
@@ -150,6 +157,7 @@ SRC += \
150157
option.c \
151158
optionstr.c \
152159
os_amiga.c \
160+
os_amiga_stubs.c \
153161
popupmenu.c \
154162
popupwin.c \
155163
quickfix.c \

src/blowfish.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ typedef union {
3636
#if defined(MSWIN)
3737
// MS-Windows is always little endian
3838
#else
39-
# ifdef HAVE_CONFIG_H
40-
// in configure.ac AC_C_BIGENDIAN() defines WORDS_BIGENDIAN when needed
39+
# if defined(HAVE_CONFIG_H) || defined(WORDS_BIGENDIAN) || defined(AMIGA)
40+
// Endianness determined by configure, explicit define, or known platform.
41+
// Amiga (68k) is always big-endian.
4142
# else
4243
# error Please change this code to define WORDS_BIGENDIAN for big-endian machines.
4344
# endif

src/os_amiga.c

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@
5555
#endif
5656

5757
/*
58-
* Set stack size to 1 MiB on NG systems. This should be enough even for
59-
* hungry syntax HL / plugin combinations. Leave the stack alone on OS 3
60-
* and below, those systems might be low on memory.
58+
* Set stack size on startup. 1 MiB on NG systems (OS4, AROS, MorphOS)
59+
* which have plenty of RAM. 256 KiB on classic OS 3 -- enough for syntax
60+
* highlighting and Vim9 execution but conservative for systems with as
61+
* little as 2 MiB of Fast RAM.
6162
*/
6263
#if defined(__amigaos4__)
6364
static const char* __attribute__((used)) stackcookie = "$STACK: 1048576";
6465
#elif defined(__AROS__) || defined(__MORPHOS__)
6566
unsigned long __stack = 1048576;
67+
#elif defined(__GNUC__) && defined(AMIGA)
68+
unsigned long __stack = 262144;
6669
#endif
6770

6871
/*
@@ -83,6 +86,26 @@ static void out_num(long n);
8386
static struct FileInfoBlock *get_fib(char_u *);
8487
static int sortcmp(const void *a, const void *b);
8588

89+
/*
90+
* Lock() wrapper that suppresses "Please insert volume" system requesters.
91+
* AmigaDOS pops a requester when Lock() is called with a name that matches a
92+
* non-mounted volume (e.g., a bare name like "vim" becomes "vim:" -> volume
93+
* request). Setting pr_WindowPtr to -1 suppresses the requester and makes
94+
* Lock() return NULL immediately. See dos.library/ErrorReport.
95+
*/
96+
static BPTR
97+
safe_Lock(UBYTE *name, long mode)
98+
{
99+
struct Process *me = (struct Process *)FindTask(NULL);
100+
APTR oldwin = me->pr_WindowPtr;
101+
BPTR flock;
102+
103+
me->pr_WindowPtr = (APTR)-1L;
104+
flock = Lock(name, mode);
105+
me->pr_WindowPtr = oldwin;
106+
return flock;
107+
}
108+
86109
static BPTR raw_in = (BPTR)NULL;
87110
static BPTR raw_out = (BPTR)NULL;
88111
static int close_win = FALSE; // set if Vim opened the window
@@ -225,7 +248,9 @@ mch_avail_mem(int special)
225248
void
226249
mch_delay(long msec, int flags)
227250
{
228-
#ifndef LATTICE // SAS declares void Delay(ULONG)
251+
// Delay() is declared in <proto/dos.h> for GCC; the local prototype is
252+
// only needed for the LATTICE/SAS toolchains.
253+
#ifdef LATTICE
229254
void Delay(long);
230255
#endif
231256

@@ -261,6 +286,17 @@ mch_init(void)
261286
#ifdef AZTEC_C
262287
Enable_Abort = 0; // disallow vim to be aborted
263288
#endif
289+
290+
// Suppress "Please insert volume" system requesters. Vim probes many
291+
// paths at startup ($VIM, $VIMRUNTIME, defaults.vim, vimrc, etc.) and
292+
// Lock()/Open() calls on non-existent paths can trigger requesters from
293+
// AmigaDOS (and from the C runtime library which calls Lock() internally).
294+
// A CLI editor should handle missing files gracefully, not pop up dialogs.
295+
{
296+
struct Process *me = (struct Process *)FindTask(NULL);
297+
me->pr_WindowPtr = (APTR)-1L;
298+
}
299+
264300
Columns = 80;
265301
Rows = 24;
266302

@@ -536,6 +572,8 @@ mch_check_win(int argc, char **argv)
536572
exitval = 0; // The Execute succeeded: exit this program
537573

538574
exit:
575+
if (nilfh)
576+
Close(nilfh);
539577
#ifdef FEAT_ARP
540578
if (ArpBase)
541579
CloseLibrary((struct Library *) ArpBase);
@@ -605,7 +643,7 @@ get_fib(char_u *fname)
605643
if (fib == NULL)
606644
return;
607645

608-
flock = Lock((UBYTE *)fname, (long)ACCESS_READ);
646+
flock = safe_Lock((UBYTE *)fname, (long)ACCESS_READ);
609647
if (flock == (BPTR)NULL || !Examine(flock, fib))
610648
{
611649
free_fib(fib); // in case of an error the memory is freed here
@@ -684,10 +722,11 @@ mch_get_user_name(char_u *s, int len)
684722
void
685723
mch_get_host_name(char_u *s, int len)
686724
{
687-
#if !defined(__AROS__)
688-
gethostname(s, len);
725+
#if defined(__amigaos4__) || defined(__MORPHOS__)
726+
gethostname((char *)s, len);
689727
#else
690-
vim_strncpy(s, "Amiga", len - 1);
728+
// AROS and classic OS 3 (libnix) do not have gethostname().
729+
vim_strncpy(s, (char_u *)"amiga", len - 1);
691730
#endif
692731
}
693732

@@ -735,7 +774,7 @@ mch_FullName(
735774
int i;
736775

737776
// Lock the file. If it exists, we can get the exact name.
738-
if ((l = Lock((UBYTE *)fname, (long)ACCESS_READ)) != (BPTR)0)
777+
if ((l = safe_Lock((UBYTE *)fname, (long)ACCESS_READ)) != (BPTR)0)
739778
{
740779
retval = lock2name(l, buf, (long)len - 1);
741780
UnLock(l);

src/os_amiga.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ typedef long off_t;
9090
# include <dirent.h>
9191
#endif
9292

93+
// Classic AmigaOS 3.x with GCC/libnix does not provide fchown, fchmod, or
94+
// ftruncate. Stub them as no-ops. (OS4 has these via clib2; MorphOS and
95+
// AROS provide them in their respective C libraries.)
96+
#if defined(__GNUC__) && defined(AMIGA) && !defined(__amigaos4__) \
97+
&& !defined(__AROS__) && !defined(__MORPHOS__)
98+
# define fchown(fd, uid, gid) (0)
99+
# define fchmod(fd, mode) (0)
100+
# define ftruncate(fd, len) (0)
101+
#endif
102+
93103
#include <time.h> // for strftime() and others
94104

95105
/*

src/os_amiga_stubs.c

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/* vi:set ts=8 sts=4 sw=4 noet:
2+
*
3+
* VIM - Vi IMproved by Bram Moolenaar
4+
*
5+
* Do ":help uganda" in Vim to read copying and usage conditions.
6+
* Do ":help credits" in Vim to see a list of people who contributed.
7+
* See README.txt for an overview of the Vim source code.
8+
*/
9+
10+
/*
11+
* os_amiga_stubs.c
12+
*
13+
* Stubs for functions referenced by Vim but not available on AmigaOS.
14+
* Split into a separate file to keep os_amiga.c clean.
15+
*/
16+
17+
#include "vim.h"
18+
19+
#ifndef PROTO
20+
21+
#include <proto/dos.h>
22+
23+
/*
24+
* Input Method (IM) stubs.
25+
* These are referenced unconditionally from optiondefs.h function pointer
26+
* tables, but AmigaOS has no X11 input method framework.
27+
*/
28+
int
29+
im_get_status(void)
30+
{
31+
return FALSE;
32+
}
33+
34+
void
35+
im_set_active(int active UNUSED)
36+
{
37+
}
38+
39+
int
40+
set_ref_in_im_funcs(int copyID UNUSED)
41+
{
42+
return 0;
43+
}
44+
45+
char *
46+
did_set_imactivatefunc(optset_T *args UNUSED)
47+
{
48+
return NULL;
49+
}
50+
51+
char *
52+
did_set_imstatusfunc(optset_T *args UNUSED)
53+
{
54+
return NULL;
55+
}
56+
57+
/*
58+
* Remove a directory.
59+
* os_amiga.c provides most mch_* functions but mch_rmdir() was missing.
60+
* AmigaDOS DeleteFile() works for empty directories.
61+
*/
62+
int
63+
mch_rmdir(char_u *name)
64+
{
65+
if (DeleteFile((STRPTR)name))
66+
return 0;
67+
return -1;
68+
}
69+
70+
/*
71+
* POSIX user/group database stubs.
72+
* AmigaOS is a single-user system with no passwd/group database.
73+
* The struct declarations exist in the NDK headers but the functions
74+
* are not implemented in libnix.
75+
*/
76+
#include <pwd.h>
77+
#include <grp.h>
78+
79+
struct passwd *
80+
getpwuid(uid_t uid UNUSED)
81+
{
82+
return NULL;
83+
}
84+
85+
struct group *
86+
getgrgid(gid_t gid UNUSED)
87+
{
88+
return NULL;
89+
}
90+
91+
uid_t
92+
getuid(void)
93+
{
94+
return 0;
95+
}
96+
97+
#endif // PROTO

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
290,
737739
/**/
738740
289,
739741
/**/

src/xdiff/xmacros.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
#define XMACROS_H
2525

2626

27-
#if defined(__hpux) || defined(VMS)
28-
# ifndef SIZE_MAX
29-
# define SIZE_MAX ((size_t)(-1))
30-
# endif
27+
// SIZE_MAX may not be defined on older platforms without <stdint.h>.
28+
#ifndef SIZE_MAX
29+
# define SIZE_MAX ((size_t)(-1))
3130
#endif
3231

3332
#define XDL_MIN(a, b) ((a) < (b) ? (a): (b))

0 commit comments

Comments
 (0)