diff --git a/hdr/nls.h b/hdr/nls.h index 26779ff..845461d 100644 --- a/hdr/nls.h +++ b/hdr/nls.h @@ -403,7 +403,7 @@ struct nlsExtCntryInfo { 0: 12 hours (append AM/PM) 1: 24 houres */ - VOID(FAR * upCaseFct) (VOID); /* far call to a function upcasing the + intvec upCaseFct; /* far call to a function upcasing the character in register AL */ char dataSep[2]; /* ASCIZ of separator in data records */ }; @@ -474,9 +474,19 @@ struct nlsInfoBlock { /* This block contains all information maybe tweaked by NLSFUNC */ UWORD sysCodePage; /* system code page */ unsigned flags; /* implementation flags */ +#ifdef __GNUC__ + /* need to initialize using explicit segment/offset */ + union { + struct { struct nlsPackage *off; char *seg; }; + struct nlsPackage FAR *p; + } actPkg, chain; + #define actPkg actPkg.p + #define chain chain.p +#else struct nlsPackage FAR *actPkg; /* current NLS package */ struct nlsPackage FAR *chain; /* first item of info chain -- hardcoded U.S.A./CP437 */ +#endif }; extern struct nlsInfoBlock ASM nlsInfo; diff --git a/hdr/portab.h b/hdr/portab.h index 25cb76b..0351322 100644 --- a/hdr/portab.h +++ b/hdr/portab.h @@ -140,8 +140,34 @@ unsigned short getSS(void); #define MC68K #elif defined(__GNUC__) + +#ifdef __FAR +#define I86 +#define far __far +#define CDECL +#define VA_CDECL +#define PASCAL + +#define _CS getCS() +static inline unsigned short getCS(void) +{ + unsigned short ret; + asm volatile("mov %%cs, %0" : "=r"(ret)); + return ret; +} + +#define _SS getSS() +static inline unsigned short getSS(void) +{ + unsigned short ret; + asm volatile("mov %%ss, %0" : "=r"(ret)); + return ret; +} +extern char DosDataSeg[]; +#else /* for warnings only ! */ #define MC68K +#endif #else #error Unknown compiler @@ -313,7 +339,11 @@ typedef signed long LONG; #define FP_OFF(fp) ((size_t)(fp)) #endif +#if defined(__GNUC__) && defined(__FAR) +typedef VOID FAR *intvec; +#else typedef VOID (FAR ASMCFUNC * intvec) (void); +#endif #define MK_PTR(type,seg,ofs) ((type FAR*) MK_FP (seg, ofs)) #if __TURBOC__ > 0x202 diff --git a/hdr/process.h b/hdr/process.h index a336631..d569921 100644 --- a/hdr/process.h +++ b/hdr/process.h @@ -67,7 +67,7 @@ typedef struct { for compatiblity with CP/M apps that do a near call to psp:5 and expect size (KB) of allocated segment in word at offset 6 */ UBYTE ps_farcall; /* 05 far call opcode */ - VOID(FAR ASMCFUNC * ps_reentry) (void); /* 06 re-entry point */ + intvec ps_reentry; /* 06 re-entry point */ intvec ps_isv22, /* 0a terminate address */ ps_isv23, /* 0e ctrl-break address */ diff --git a/kernel/chario.c b/kernel/chario.c index eb95803..3f3d1c2 100644 --- a/kernel/chario.c +++ b/kernel/chario.c @@ -149,6 +149,8 @@ STATIC void fast_put_char(unsigned char chr) #if defined(__TURBOC__) _AL = chr; __int__(0x29); +#elif defined(__GNUC__) + asm volatile("int $0x29":: "a"(chr):"bx"); #elif defined(I86) asm { diff --git a/kernel/fattab.c b/kernel/fattab.c index 0088a4a..12e1a2b 100644 --- a/kernel/fattab.c +++ b/kernel/fattab.c @@ -226,7 +226,7 @@ CLUSTER link_fat(struct dpb FAR * dpbp, CLUSTER Cluster1, if (ISFAT12(dpbp)) { - REG UBYTE FAR *fbp0, FAR * fbp1; + REG UBYTE FAR *fbp0; REG UBYTE FAR * fbp1; struct buffer FAR * bp1; unsigned cluster, cluster2; diff --git a/kernel/globals.h b/kernel/globals.h index 549043f..9c877cd 100644 --- a/kernel/globals.h +++ b/kernel/globals.h @@ -156,18 +156,17 @@ typedef BYTE *UPMAP; /* */ /* External Assembly variables */ /* */ -extern struct dhdr -FAR ASM clk_dev, /* Clock device driver */ - FAR ASM con_dev, /* Console device driver */ - FAR ASM prn_dev, /* Generic printer device driver */ - FAR ASM aux_dev, /* Generic aux device driver */ - FAR ASM blk_dev; /* Block device (Disk) driver */ +extern struct dhdr FAR ASM clk_dev; /* Clock device driver */ +extern struct dhdr FAR ASM con_dev; /* Console device driver */ +extern struct dhdr FAR ASM prn_dev; /* Generic printer device driver */ +extern struct dhdr FAR ASM aux_dev; /* Generic aux device driver */ +extern struct dhdr FAR ASM blk_dev; /* Block device (Disk) driver */ extern COUNT *error_tos, /* error stack */ disk_api_tos, /* API handler stack - disk fns */ char_api_tos; /* API handler stack - char fns */ -extern BYTE FAR _HMATextAvailable, /* first byte of available CODE area */ - FAR _HMATextStart[], /* first byte of HMAable CODE area */ - FAR _HMATextEnd[]; /* and the last byte of it */ +extern BYTE FAR _HMATextAvailable; /* first byte of available CODE area */ +extern BYTE FAR _HMATextStart[]; /* first byte of HMAable CODE area */ +extern BYTE FAR _HMATextEnd[]; /* and the last byte of it */ extern BYTE DosLoadedInHMA; /* if InitHMA has moved DOS up */ @@ -236,9 +235,8 @@ extern UWORD ASM first_mcb, /* Start of user memory */ ASM uppermem_root; /* Start of umb chain (usually 9fff) */ extern char * ASM inputptr; /* pointer to unread CON input */ extern sfttbl FAR * ASM sfthead; /* System File Table head */ -extern struct dhdr -FAR * ASM clock, /* CLOCK$ device */ - FAR * ASM syscon; /* console device */ +extern struct dhdr FAR * ASM clock; /* CLOCK$ device */ +extern struct dhdr FAR * ASM syscon;/* console device */ extern WORD ASM maxsecsize; /* largest sector size in use (can use) */ extern struct buffer FAR *ASM firstbuf; /* head of buffers linked list */ diff --git a/kernel/init-dat.h b/kernel/init-dat.h index 1e4960b..9cf3919 100644 --- a/kernel/init-dat.h +++ b/kernel/init-dat.h @@ -23,7 +23,7 @@ extern __segment DosTextSeg; #define DOSFAR FAR #define DOSTEXTFAR FAR -#elif !defined(I86) +#elif !defined(I86) || defined(__GNUC__) #define DOSFAR #define DOSTEXTFAR diff --git a/kernel/init-mod.h b/kernel/init-mod.h index 20f37dc..363225a 100644 --- a/kernel/init-mod.h +++ b/kernel/init-mod.h @@ -242,7 +242,11 @@ extern void Init_clk_driver(void); extern UWORD HMAFree; /* first byte in HMA not yet used */ extern unsigned CurrentKernelSegment; +#ifdef __GNUC__ +extern struct _KernelConfig ASM LowKernelConfig; +#else extern struct _KernelConfig FAR ASM LowKernelConfig; +#endif extern WORD days[2][13]; extern BYTE FAR *lpTop; extern BYTE ASM _ib_start[], ASM _ib_end[], ASM _init_end[]; @@ -256,11 +260,21 @@ extern struct lol FAR *LoL; extern struct dhdr DOSTEXTFAR ASM blk_dev; /* Block device (Disk) driver */ extern struct buffer FAR *DOSFAR firstAvailableBuf; /* first 'available' buffer */ +#ifdef __GNUC__ +extern struct lol ASM DATASTART; +#else extern struct lol ASM FAR DATASTART; +#endif -extern BYTE DOSFAR ASM _HMATextAvailable, /* first byte of available CODE area */ - FAR ASM _HMATextStart[], /* first byte of HMAable CODE area */ - FAR ASM _HMATextEnd[], DOSFAR ASM break_ena; /* break enabled flag */ +extern BYTE DOSFAR ASM _HMATextAvailable; /* first byte of available CODE area */ +#ifdef __GNUC__ +extern BYTE ASM _HMATextStart[]; /* first byte of HMAable CODE area */ +extern BYTE ASM _HMATextEnd[]; +#else +extern BYTE FAR ASM _HMATextStart[]; /* first byte of HMAable CODE area */ +extern BYTE FAR ASM _HMATextEnd[]; +#endif +extern BYTE DOSFAR ASM break_ena; /* break enabled flag */ extern BYTE DOSFAR ASM _InitTextStart[], /* first available byte of ram */ DOSFAR ASM _InitTextEnd[], DOSFAR ASM ReturnAnyDosVersionExpected, diff --git a/kernel/inithma.c b/kernel/inithma.c index 0462e5d..1e12f42 100644 --- a/kernel/inithma.c +++ b/kernel/inithma.c @@ -352,7 +352,8 @@ void MoveKernel(unsigned NewKernelSegment) style table */ - struct RelocationTable FAR *rp, rtemp; + struct RelocationTable FAR *rp; + struct RelocationTable rtemp; /* verify, that all entries are valid */ diff --git a/kernel/main.c b/kernel/main.c index c9a52c8..c915ef3 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -68,7 +68,12 @@ __segment DosTextSeg = 0; #endif -struct lol FAR *LoL = &DATASTART; +struct lol FAR *LoL +#ifndef __GNUC__ +/* cannot initialize from far data with GCC */ += &DATASTART; +#endif +; VOID ASMCFUNC FreeDOSmain(void) { @@ -90,6 +95,9 @@ VOID ASMCFUNC FreeDOSmain(void) at 50:e0 */ +#ifdef __GNUC__ + LoL = &DATASTART; +#endif drv = LoL->BootDrive + 1; p = MK_FP(0, 0x5e0); if (fmemcmp(p+2,"CONFIG",6) == 0) /* UPX */ @@ -775,8 +783,12 @@ STATIC void CheckContinueBootFromHarddisk(void) init_call_intr(0x13, &r); { +#if __GNUC__ + asm volatile("jmp $0,$0x7c00"); +#else void (far *reboot)(void) = (void (far*)(void)) MK_FP(0x0,0x7c00); (*reboot)(); +#endif } } diff --git a/kernel/memmgr.c b/kernel/memmgr.c index 96edcef..40de39a 100644 --- a/kernel/memmgr.c +++ b/kernel/memmgr.c @@ -316,7 +316,7 @@ COUNT DosMemFree(UWORD para) */ COUNT DosMemChange(UWORD para, UWORD size, UWORD * maxSize) { - REG mcb FAR *p, FAR * q; + REG mcb FAR *p; mcb FAR * q; /* Initialize */ p = para2far(para - 1); /* pointer to MCB */ diff --git a/kernel/nls.c b/kernel/nls.c index e885bdc..6e62aae 100644 --- a/kernel/nls.c +++ b/kernel/nls.c @@ -66,8 +66,13 @@ struct nlsInfoBlock ASM nlsInfo = { #ifdef NLS_REORDER_POINTERS | NLS_CODE_REORDER_POINTERS #endif +#ifdef __GNUC__ + , {.seg=DosDataSeg, .off=&nlsPackageHardcoded} /* hardcoded first package */ + , {.seg=DosDataSeg, .off=&nlsPackageHardcoded} /* first item in chain */ +#else , &nlsPackageHardcoded /* hardcoded first package */ , &nlsPackageHardcoded /* first item in chain */ +#endif }; /* getTableX return the pointer to the X'th table; X==subfct */ diff --git a/kernel/prf.c b/kernel/prf.c index fe585be..edff14c 100644 --- a/kernel/prf.c +++ b/kernel/prf.c @@ -29,7 +29,11 @@ #include "portab.h" #ifdef FORSYS +#ifdef __GNUC__ +#include +#else #include +#endif #include #endif @@ -105,6 +109,8 @@ void put_console(int c) __int__(0x29); #elif defined(__WATCOMC__) int29(c); +#elif defined(__GNUC__) + asm volatile("int $0x29" : : "a"(c) : "bx"); #elif defined(I86) __asm { @@ -227,7 +233,8 @@ int VA_CDECL sprintf(char * buff, CONST char * fmt, ...) STATIC void do_printf(CONST BYTE * fmt, va_list arg) { int base; - BYTE s[11], FAR * p; + BYTE s[11]; + BYTE FAR * p; int size; unsigned char flags; diff --git a/kernel/task.c b/kernel/task.c index deda778..b7a1e58 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -509,7 +509,7 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd) VOID return_user(void) { - psp FAR *p, FAR * q; + psp FAR *p; psp FAR * q; REG COUNT i; iregs FAR *irp; /* long j;*/ diff --git a/mkfiles/gcc.mak b/mkfiles/gcc.mak new file mode 100644 index 0000000..7f09f27 --- /dev/null +++ b/mkfiles/gcc.mak @@ -0,0 +1,50 @@ +# +# GCC.MAK - kernel compiler options for ia16-elf-gcc +# + +CC=ia16-elf-gcc -c +CL=echo ia16-elf-gcc +INCLUDEPATH=. + +!if $(XCPU) != 186 +!if $(XCPU) != 386 +TARGETOPT=-march=i8086 +!endif +!endif + +LIBUTIL=wlib -q +LIBPLUS= +LIBTERM= + +TINY=-mcmodel=tiny +CFLAGST=-w -o $@ +CFLAGSC= + +TARGET=KGC + +# +# heavy stuff - building +# +# -mcmodel=small small memory model (small code/small data) +# -fleading-underscore underscores leading field for DOS compiler compat +# -fno-common no "common" variables, just BSS for uninitialized data +# -fpack-struct pack structure members +# -ffreestanding don't assume any headers +# -fcall-used-es es clobbered in function calls +# -mrtd use stdcall calling convention +# -w disable warnings for now +# -Werror treat all warnings as errors + +ALLCFLAGS=-I../hdr $(TARGETOPT) $(ALLCFLAGS) -mcmodel=small -fleading-underscore -fno-common -fpack-struct -ffreestanding -fcall-used-es -mrtd -w -Werror +INITCFLAGS=$(ALLCFLAGS) -o $@ +CFLAGS=$(ALLCFLAGS) -o $@ + +DIRSEP=/ +RM=rm -f +CP=echo cp +ECHOTO=echo>> +INITPATCH=@echo > /dev/null +CLDEF=1 +CLT=gcc -DDOSC_TIME_H -I../hdr -o $@ +CLC=$(CLT) +XLINK=echo $(XLINK) debug all op symfile format dos option map,statics,verbose F { $(OBJS) } L ../lib/device.lib N kernel.exe $# diff --git a/sys/fdkrncfg.c b/sys/fdkrncfg.c index 0aa421c..6ad2dd1 100644 --- a/sys/fdkrncfg.c +++ b/sys/fdkrncfg.c @@ -19,7 +19,9 @@ char KERNEL[] = "KERNEL.SYS"; #include #include +#ifndef __GNUC__ #include +#endif #include "portab.h" /* These definitions deliberately put here instead of @@ -29,7 +31,7 @@ char KERNEL[] = "KERNEL.SYS"; extern int VA_CDECL printf(CONST char * fmt, ...); extern int VA_CDECL sprintf(char * buff, CONST char * fmt, ...); -#ifdef __WATCOMC__ +#if defined(__WATCOMC__) unsigned _dos_close(int handle); #define close _dos_close #define SEEK_SET 0 @@ -44,6 +46,11 @@ unsigned long lseek(int fildes, unsigned long offset, int whence); parm [bx] [dx cx] [ax] \ value [dx ax]; +#elif defined(__GNUC__) +#include +#include +#define memicmp strncasecmp +#define O_BINARY 0 #else #include #ifndef SEEK_SET diff --git a/sys/sys.c b/sys/sys.c index f8758bf..65e9919 100644 --- a/sys/sys.c +++ b/sys/sys.c @@ -48,8 +48,11 @@ #endif #include +#ifndef __GNUC__ #include +#endif #include +#ifndef __GNUC__ #include #include #ifdef __TURBOC__ @@ -57,6 +60,7 @@ #else #include #endif +#endif #include #ifdef __TURBOC__ #include @@ -91,7 +95,31 @@ extern int VA_CDECL sprintf(char * buff, CONST char * fmt, ...); #ifndef __WATCOMC__ +#ifdef __GNUC__ +#include +#include +#include +#include +#define O_BINARY 0 +#define stricmp strcasecmp +#define memicmp strncasecmp +union REGS { + struct { + unsigned char al, ah, bl, bh, cl, ch, dl, dh; + } h; + struct { + unsigned short ax, bx, cx, dx, si, di, cflag; + } x; +}; +struct SREGS { + unsigned short ds, es; +}; +struct _diskfree_t { + unsigned short avail_clusters, sectors_per_cluster, bytes_per_sector; +}; +#else #include +#endif /* returns current DOS drive, A=0, B=1,C=2, ... */ #ifdef __TURBOC__ @@ -973,7 +1001,7 @@ void reset_drive(int DosDrive); #pragma aux reset_drive = \ "push ds" \ "inc dx" \ - "mov ah, 0xd" \ + "mov ah, 0xd" \ "int 0x21" \ "mov ah,0x32" \ "int 0x21" \ @@ -1798,7 +1826,7 @@ BOOL copy(const BYTE *source, COUNT drive, const BYTE * filename) { ULONG filesize; UWORD theseg; - BYTE far *buffer, far *bufptr; + BYTE far *buffer; BYTE far *bufptr; UWORD offs; unsigned chunk_size;