diff -Nurd linux86.vold/ar/alloca.c linux86/ar/alloca.c --- linux86.vold/ar/alloca.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/ar/alloca.c 2003-10-07 22:31:03.000000000 +0100 @@ -0,0 +1,61 @@ + +#ifdef __STDC__ +#include +#else +#include +#include +#endif + +#if defined(__TINYC__) || defined(__HP_cc) +typedef union mem_cell +{ + union mem_cell *next; /* A pointer to the next mem */ + unsigned int size; /* An int >= sizeof pointer */ + char *depth; /* For the alloca hack */ +} +mem; + +#define m_size(p) ((p) [0].size) /* For malloc */ +#define m_next(p) ((p) [1].next) /* For malloc and alloca */ +#define m_deep(p) ((p) [0].depth) /* For alloca */ + +static mem *alloca_stack = 0; + +void * +alloca(size) +size_t size; +{ + auto char probe; /* Probes stack depth: */ + register mem *hp; + + /* + * Reclaim garbage, defined as all alloca'd storage that was allocated + * from deeper in the stack than currently. + */ + + for (hp = alloca_stack; hp != 0;) + if (m_deep(hp) < &probe) + { + register mem *np = m_next(hp); + free((void *) hp); /* Collect garbage. */ + hp = np; /* -> next header. */ + } + else + break; /* Rest are not deeper. */ + + alloca_stack = hp; /* -> last valid storage. */ + if (size == 0) + return 0; /* No allocation required. */ + + hp = (mem *) malloc(sizeof(mem)*2 + size); + if (hp == 0) + return hp; + + m_next(hp) = alloca_stack; + m_deep(hp) = &probe; + alloca_stack = hp; + + /* User storage begins just after header. */ + return (void *) (hp + 2); +} +#endif diff -Nurd linux86.vold/ar/ar.c linux86/ar/ar.c --- linux86.vold/ar/ar.c 2000-12-03 08:20:47.000000000 +0000 +++ linux86/ar/ar.c 2004-01-21 15:09:51.000000000 +0000 @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + #include #include @@ -23,27 +23,26 @@ #include #include #include +#include #endif #include #include #include #include +#include #include "ar.h" #include "rel_aout.h" -#ifdef __BCC__ +#if defined(__BCC__) || defined(__HP_cc) #define HAVE_RENAME #undef HAVE_FSYNC #define SHORT_FILENAME -extern char **sys_errlist; -extern int sys_nerr; #else #define HAVE_FCHMOD #define HAVE_RENAME #undef HAVE_FSYNC #endif - -extern int errno; +#define HAVE_TRAILING_SLASH_IN_NAME #ifdef __GNUC__ # ifndef alloca @@ -52,8 +51,6 @@ #else # if defined(sparc) || defined(HAVE_ALLOCA_H) # include -# else -char *alloca (); # endif #endif @@ -65,9 +62,6 @@ /* Locking is normally disabled because fcntl hangs on the Sun and it isn't supported properly across NFS anyway. */ -#ifdef LOCKS -#include -#endif /* This structure is used internally to represent the info on a member of an archive. This is to make it easier to change format. */ @@ -234,7 +228,7 @@ void write_symdef_member (); void read_old_symdefs (); void two_operations (); -void usage (), fatal (), error (), error_with_file (); +void usage (), fatal (), error (), error3(), error_with_file (); void perror_with_name (), pfatal_with_name (); void write_archive (); void touch_symdef_member (); @@ -245,14 +239,17 @@ void print_modes (); char *make_tempname (); void copy_out_member (); +#define const #else /* Grrr. */ -extern void error (); -extern void fatal (); -extern void extract_members (); +extern void error (char * s1, char * s2); +extern void error3 (char * s1, char * s2, char * s3); +extern void fatal (char * s1, char * s2); +extern void extract_members (void (*function) (struct member_desc member, FILE *istream)); +extern void scan (void (*function) (struct member_desc member, FILE *istream), int crflag); extern char *basename (char *path); -extern char *concat (char *s1, char *s2, char *s3); +extern char *concat (const char *s1, const char *s2, const char *s3); extern char *make_tempname (char *name); extern char *xmalloc (unsigned int size); extern char *xrealloc (char *ptr, unsigned int size); @@ -266,7 +263,7 @@ extern struct mapelt *last_mapelt (struct mapelt *map); extern struct mapelt *make_map (int nonexistent_ok); extern struct mapelt *prev_mapelt (struct mapelt *map, struct mapelt *elt); -extern void add_to_map (struct member_desc member); +extern void add_to_map (struct member_desc member, FILE * istream); extern void close_archive (void); extern void copy_out_member (struct mapelt *mapelt, int archive_indesc, int outdesc, char *outname); extern void delete_from_map (char *name, struct mapelt *map); @@ -277,11 +274,11 @@ extern void lock_for_update (void); extern void make_new_symdefs (struct mapelt *mapelt, int archive_indesc); extern void move_members (void); -extern void mywrite (int desc, char *buf, int bytes, char *file); +extern void mywrite (int desc, void *buf, int bytes, char *file); extern void perror_with_name (char *name); extern void pfatal_with_name (char *name); extern void print_contents (struct member_desc member, FILE *istream); -extern void print_descr (struct member_desc member); +extern void print_descr (struct member_desc member, FILE * instream); extern void print_modes (int modes); extern void quick_append (void); extern void read_old_symdefs (struct mapelt *map, int archive_indesc); @@ -289,7 +286,7 @@ extern void touch_symdef_member (int outdesc, char *outname); extern void two_operations (void); extern void update_symdefs (struct mapelt *map, int archive_indesc); -extern void usage (char *s1, char *s2); +extern void usage (char *s1, int val); extern void write_archive (struct mapelt *map, int appendflag); extern void write_symdef_member (struct mapelt *mapelt, struct mapelt *map, int outdesc, char *outname); #endif @@ -298,13 +295,14 @@ FILE is the name of the file (for error messages). */ void -mywrite (desc, buf, bytes, file) +mywrite (desc, pbuf, bytes, file) int desc; - char *buf; + void *pbuf; int bytes; char *file; { register int val; + register char * buf = pbuf; while (bytes > 0) { @@ -349,7 +347,7 @@ if (*p == '-') p++; - while (c = *p++) + while ((c = *p++)) { switch (c) { @@ -445,10 +443,12 @@ i = 2; if (postype != POS_DEFAULT) + { if (i < argc) posname = argv[i++]; else usage ("no position operand", 0); + } if (i >= argc) usage ("no archive specified", 0); @@ -514,7 +514,11 @@ void scan (function, crflag) +#ifdef __STDC__ + void (*function) (struct member_desc member, FILE *istream); +#else void (*function) (); +#endif int crflag; { FILE *arcstream = fopen (archive, "r"); @@ -597,8 +601,9 @@ } void -print_descr (member) +print_descr (member, instream) struct member_desc member; + FILE * instream; { char *timestring; if (!verbose) @@ -673,7 +678,7 @@ if (preserve_dates) { -#if defined(USG) || defined(linux) || defined(__BCC__) +#if defined(USG) || defined(__BCC__) long tv[2]; tv[0] = member.date; tv[1] = member.date; @@ -735,8 +740,9 @@ } void -add_to_map (member) +add_to_map (member, istream) struct member_desc member; + FILE * istream; { struct mapelt *mapelt = (struct mapelt *) xmalloc (sizeof (struct mapelt)); mapelt->info = member; @@ -1075,7 +1081,7 @@ header->ar_name[sizeof (header->ar_name) - 2] = 'o'; } header->ar_name[sizeof (header->ar_name) - 1] = '\0'; - error ("member name `%s' truncated to `%s'", + error3 ("member name `%s' truncated to `%s'", mapelt->info.name, header->ar_name); } #if defined(USG) || defined(HAVE_TRAILING_SLASH_IN_NAME) @@ -1275,7 +1281,7 @@ { struct mapelt *map = make_map (0); char **p; - struct mapelt *after_mapelt; + struct mapelt *after_mapelt = 0; struct mapelt mapstart; struct mapelt *change_map; @@ -1337,7 +1343,7 @@ { struct mapelt *map = make_map (1); struct mapelt mapstart; - struct mapelt *after_mapelt; + struct mapelt *after_mapelt = 0; struct mapelt *change_map; char **p; int changed; @@ -1469,7 +1475,11 @@ void extract_members (function) +#ifdef __STDC__ + void (*function) (struct member_desc member, FILE *istream); +#else void (*function) (); +#endif { struct mapelt *map; FILE *arcstream; @@ -1954,7 +1964,7 @@ } else if (pos > old_strings_size) fatal ("Old archive's string size was %u too small.", - pos - old_strings_size); + (void*)(pos - old_strings_size)); for (tail = map; tail != 0; tail = tail->next) if (tail->info.symdefs) @@ -1977,10 +1987,13 @@ /* Print error message and usage message, and exit. */ void -usage (s1, s2) - char *s1, *s2; +usage (s1, val) + char *s1; + int val; { - error (s1, s2); + char vbuf[16]; + sprintf(vbuf, "%d", val); + error (s1, vbuf); fprintf (stderr, "\ Usage: %s [d|m|p|q|r|t|x [[abi [position-name] [cilouv]] archive file...\n", program_name); @@ -2000,11 +2013,20 @@ /* Print error message. `s1' is printf control string, the rest are args. */ void -error (s1, s2, s3, s4, s5) - char *s1, *s2, *s3, *s4, *s5; +error (s1, s2) + char *s1, *s2; { fprintf (stderr, "%s: ", program_name); - fprintf (stderr, s1, s2, s3, s4, s5); + fprintf (stderr, s1, s2); + fprintf (stderr, "\n"); +} + +void +error3 (s1, s2, s3) + char *s1, *s2, *s3; +{ + fprintf (stderr, "%s: ", program_name); + fprintf (stderr, s1, s2, s3); fprintf (stderr, "\n"); } @@ -2026,26 +2048,14 @@ perror_with_name (name) char *name; { - char *s; - - if (errno < sys_nerr) - s = concat ("", sys_errlist[errno], " for %s"); - else - s = "unknown error for %s"; - error (s, name); + error (concat ("", strerror(errno), " for %s"), name); } void pfatal_with_name (name) char *name; { - char *s; - - if (errno < sys_nerr) - s = concat ("", sys_errlist[errno], " for %s"); - else - s = "cannot open %s"; - fatal (s, name); + fatal (concat ("", strerror(errno), " for %s"), name); } /* Return a newly-allocated string whose contents @@ -2053,7 +2063,7 @@ char * concat (s1, s2, s3) - char *s1, *s2, *s3; + const char *s1, *s2, *s3; { int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); char *result = (char *) xmalloc (len1 + len2 + len3 + 1); @@ -2089,7 +2099,7 @@ { char *result = realloc (ptr, size); if (result == 0) - fatal ("virtual memory exhausted"); + fatal ("virtual memory exhausted", 0); return result; } diff -Nurd linux86.vold/ar/Makefile linux86/ar/Makefile --- linux86.vold/ar/Makefile 2001-01-06 12:14:55.000000000 +0000 +++ linux86/ar/Makefile 2003-08-31 13:54:08.000000000 +0100 @@ -6,29 +6,29 @@ CFLAGS =-O LDFLAGS = DEFS = -OBJS= ar.o +OBJS= ar.o alloca.o all: ar86 ar86: $(OBJS) - $(CC) $(LDFLAGS) $^ -o $@ + $(CC) $(LDFLAGS) $(OBJS) -o $@ install: ar86 install -d $(LIBDIR) install -m 755 ar86 $(LIBDIR) clean realclean clobber: - rm -f *.o ar86 ar.h rel_aout.h + rm -f *.o ar86 ar ar.h rel_aout.h $(OBJS): ar.h rel_aout.h ar.h: - [ -f ar.h ] || \ + test -f ar.h || \ { rm -f ar.h ; ln -s ../libc/include/ar.h . ; } || \ ln ../libc/include/ar.h . rel_aout.h: - [ -f rel_aout.h ] || \ + test -f rel_aout.h || \ { rm -f rel_aout.h ; ln -s ../ld/rel_aout.h . ; } || \ ln ../ld/rel_aout.h . diff -Nurd linux86.vold/as/alloc.c linux86/as/alloc.c --- linux86.vold/as/alloc.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/as/alloc.c 2002-05-26 08:17:14.000000000 +0100 @@ -0,0 +1,100 @@ + +#include "syshead.h" +#include "const.h" +#include "type.h" +#include "align.h" + +PRIVATE char NOMEMEORY[] = "Cannot allocate sufficient memory"; + +#ifdef USE_FIXED_HEAP +PRIVATE char *heapend; /* end of free space for symbol list */ +PRIVATE char *heapptr; /* next free space in symbol list */ +#endif + +#ifndef USE_FIXED_HEAP +PRIVATE char tempbuf[2048]; +#endif + +void +init_heap() +{ +#ifdef USE_FIXED_HEAP +#ifndef USERMEM +#define USERMEM 0xAC00U +#endif + +#ifdef __AS386_16__ + int stk; + heapptr = sbrk(0); + heapend = ((char*)&stk) - STAKSIZ - 16; + brk(heapend); + if(sbrk(0) != heapend) + as_abort(NOMEMEORY); +#else +#ifdef SOS_EDOS + heapend = stackreg() - STAKSIZ; +#else + heapptr = malloc(USERMEM); + heapend = heapptr + USERMEM; + if (heapptr == 0) + as_abort(NOMEMEORY); +#endif +#endif +#endif +} + +void * temp_buf() +{ +#ifdef USE_FIXED_HEAP + return heapptr; +#else + return tempbuf; +#endif +} + +void * +asalloc(size) +unsigned int size; +{ + void * rv; +#ifdef USE_FIXED_HEAP + align(heapptr); + if (heapptr+size < heapend) + { + rv = heapptr; + heapptr += size; + } + else + rv = 0; +#else + rv = malloc(size); +#endif + if (rv == 0 && size) as_abort(NOMEMEORY); + return rv; +} + + +void * +asrealloc(oldptr, size) +void * oldptr; +unsigned int size; +{ + void * rv; +#ifdef USE_FIXED_HEAP + if (oldptr == 0) return asalloc(size); + + if ((char*)oldptr+size < heapend) + { + heapptr = (char*)oldptr + size; + rv = oldptr; + } + else + rv = 0; +#else + rv = realloc(oldptr, size); +#endif + + if (rv == 0) as_abort(NOMEMEORY); + return rv; +} + diff -Nurd linux86.vold/as/as.c linux86/as/as.c --- linux86.vold/as/as.c 2000-09-26 21:08:13.000000000 +0100 +++ linux86/as/as.c 2004-06-03 19:50:21.000000000 +0100 @@ -15,6 +15,7 @@ #include "file.h" #include "flag.h" #include "globvar.h" +#include "version.h" PUBLIC char hexdigit[] = "0123456789ABCDEF"; /* XXX - ld uses lower case */ @@ -25,6 +26,10 @@ PRIVATE struct macro_s hid_macstak[MAXBLOCK]; /* macro stack */ PRIVATE struct sym_s *hid_spt[SPTSIZ]; /* hash table */ +PRIVATE char * binfilename = 0; +PRIVATE char * objfilename = 0; +PRIVATE int keep_bad_output = 0; + FORWARD void initp1 P((void)); FORWARD int my_creat P((char *name, char *message)); FORWARD void process_args P((int argc, char **argv)); @@ -32,30 +37,11 @@ FORWARD void summ_number P((unsigned num)); FORWARD void usage P((void)); -#ifndef USERMEM -#define USERMEM (sizeof(int) <= 2 ? (unsigned) 0xAC00 : (unsigned) 0x28000L) -#endif - PUBLIC int main(argc, argv) int argc; char **argv; { -#ifdef __AS386_16__ - heapptr = sbrk(0); - heapend = ((char*)&argc) - STAKSIZ - 16; - brk(heapend); - if(sbrk(0) != heapend) - as_abort("Cannot allocate memory"); -#else -#ifdef SOS_EDOS - heapend = stackreg() - STAKSIZ; -#else - heapptr = malloc(USERMEM); - heapend = heapptr + USERMEM; - if (heapptr == 0) - as_abort("cannot allocate memory"); -#endif -#endif + init_heap(); initp1(); initp1p2(); inst_keywords(); @@ -96,6 +82,16 @@ if (lstfil != STDOUT && (toterr != 0 || totwarn != 0)) summary(STDOUT); statistics(); + + /* If an output binary is in error remove it */ + close(binfil); binfil=0; + close(objfil); objfil=0; + if (toterr != 0 && !keep_bad_output) + { + if(binfilename) unlink(binfilename); + if(objfilename) unlink(objfilename); + } + exit(toterr != 0 ? 1 : 0); /* should close output files and check */ } @@ -194,6 +190,15 @@ } switch (arg[1]) { + case 'v': + outfd = STDOUT; + writes("as86 version: "); +#ifdef VERSION + writesn(VERSION); +#else + writesn("Unknown!"); +#endif + exit(1); #ifdef I80386 case '0': case '1': case '2': idefsize = defsize = 0x2; @@ -210,7 +215,7 @@ case 'b': if (!isnextarg || binfil != 0) usage(); - binfil = my_creat(nextarg, "error creating binary file"); + binfil = my_creat(binfilename=nextarg, "error creating binary file"); binaryg = TRUE; --argc; ++argv; @@ -253,7 +258,7 @@ if (!isnextarg || objfil != 0) usage(); objectg = TRUE; - objfil = my_creat(nextarg, "error creating object file"); + objfil = my_creat(objfilename=nextarg, "error creating object file"); --argc; ++argv; break; @@ -280,6 +285,9 @@ if( flag_state ) as_warn.semaphore = -1; else as_warn.semaphore = 0; break; + case 'k': + keep_bad_output = 1; + break; default: usage(); /* bad option */ } @@ -321,9 +329,10 @@ PRIVATE void summ_number(num) unsigned num; { - /* format number like line numbers, build it at free spot heapptr */ - *build_number(num, LINUM_LEN, heapptr) = 0; - writes(heapptr); + /* format number like line numbers */ + char buf[16]; + *build_number(num, LINUM_LEN, buf) = 0; + writes(buf); } PRIVATE void usage() diff -Nurd linux86.vold/as/as.doc linux86/as/as.doc --- linux86.vold/as/as.doc 1999-07-26 10:54:00.000000000 +0100 +++ linux86/as/as.doc 1970-01-01 01:00:00.000000000 +0100 @@ -1,169 +0,0 @@ -as options ----------- - -as [-03agjuw] [-b [bin]] [-lm [list]] [-n name] [-o obj] [-s sym] src - -The 6809 version does not support -0, -3, -a or -j. - -The 'src' file can be '-' for stdin but ONLY on 'big' machines. - -defaults (off or none except for these; no output is produced without a flag): --03 native -list stdout (beware of clobbering next arg) -name basename of the source name - --0 start with 16-bit code segment --3 start with 32-bit code segment --a enable partial compatibility with asld --g only put global symbols in object or symbol file --j force all jumps to be long --l produce list file, filename may follow --m print macro expansions in listing --n name of module follows (goes in object instead of source name) --o produce object file, filename follows --b produce a raw binary file, filename may follow --s produce an ASCII symbol file, filename follows --u take undefined symbols as imported-with-unspecified segment --w don't print warnings - -The -u and -w options are perhaps back to front because they are needed for -cc1 output and Minix's make does the wrong thing with .s files left around. -However, all assembler code not written by compilers should assemble with -them turned off. - -The -b flag produces a 'raw' binary file with no header, if there's no --s flag the file starts at location 0. The -s generates an ASCII symbol -table, if a binary file doesn't start at location zero the first two items -are the start and end addresses of the binary file. - -BCC is classed as a 'small' compiler, with this there is a maximum line -length of 256 characters. - -Using GASP ----------- - -The Gnu assembler preprocessor provides some reasonable implementations -of user biased pseudo operations. - -It can be invoked as: - gasp [-a] ... file.s [file2.s ...] | as86 [...] - [-o obj] [-b bin] - -Notes: -Gasp generates an error for '.org' commands if you're not using -'alternate' syntax you can use 'org' instead, otherwise use 'block'. - -Export is translated in .global, if you are making a 'bin' file use -'public' or '.define' instead. - -The GASP list options have no support in as86. - -as source ---------- - -Conditionals: - IF, ELSE, ELSEIF, ENDIF Numeric condition - IFC, ELSEIFC String compare (str1,str2) - FAIL .FAIL Generate user error. - -Segments: - .TEXT .ROM .DATA .BSS - .SECT Follow with one of above - LOC Set numeric segment 0=TEXT, 3=DATA,ROM,BSS, 15=MAX - -Lable type definition: - Export label defined in this object: EXPORT PUBLIC .DEFINE - Force linker to include label in a.out: ENTRY - - Define label as external or imported: .GLOBL .GLOBAL - Import list of externally defined labels: EXTRN EXTERN IMPORT .EXTERN - NB: Can't use imports in 'bin' files. - - Mark entry for old binary file (obs) .ENTER - -Data init - 1 byte: DB .DATA1 .BYTE FCB - 2 byte: DW .DATA2 .SHORT FDB .WORD - 4 byte: DD .DATA4 .LONG - String: .ASCII FCC - String+Zero: .ASCIZ - -Data uninit - byte count: .BLKB RMB .SPACE - word count: .BLKW .ZEROW - -Data Common - COMM .COMM LCOMM .LCOMM - -Alignment - .ALIGN .EVEN - -Misc - EQU Define label - SET Define re-definable label - ORG .ORG Set assemble location - BLOCK Set assemble location and stack old one - ENDB Return to stacked assemble location - GET INCLUDE Insert new file (no quotes on name) - USE16 Define default operand size as 16 bit - USE32 Define default operand size as 32 bit - END End of compilation for this file. - .WARN Switch warnings - .LIST Listings on/off (1,-1) - .MACLIST Macro listings on/off (1,-1) - -Macros - MACRO sax - mov ax,#?1 - MEND - sax(1) - -Unimplemented/unused. - IDENT Define object identity string. - SETDP Set DP value on 6809 - .MAP Set binary symbol table map number. - -Registers - BP BX DI SI - EAX EBP EBX ECX EDI EDX ESI ESP - AX CX DX SP - AH AL BH BL CH CL DH DL - CS DS ES FS GS SS - CR0 CR2 CR3 DR0 DR1 DR2 DR3 DR6 DR7 - TR3 TR4 TR5 TR6 TR7 ST - -Operand type specifiers - BYTE DWORD FWORD FAR PTR PWORD QWORD TBYTE WORD NEAR - - -Instructions - -AAA AAD AAM AAS ADC ADD AND ARPL BCC BCS BEQ BGE BGT BHI BHIS BLE BLO -BLOS BLT BMI BNE BOUND BPC BPL BPS BR BVC BVS CALL CALLF CALLI CBW CLC -CLD CLI CMC CMP CMPS CMPSB CMPSD CMPSW CMPW CSEG CWD CWDE CDQ DAA DAS -DSEG DEC DIV ENTER ESEG FSEG GSEG HLT IDIV IMUL IN INC INS INSB INSD -INSW INT INTO INW IRET IRETD J JA JAE JB JBE JC JCXE JCXZ JECXE JECXZ JE -JG JGE JL JLE JMP JMPF JMPI JNA JNAE JNB JNBE JNC JNE JNG JNGE JNL JNLE -JNO JNP JNS JNZ JO JP JPE JPO JS JZ LAHF LDS LEA LEAVE LES LOCK LODB -LODS LODSB LODSD LODSW LODW LOOP LOOPE LOOPNE LOOPNZ LOOPZ MOV MOVS -MOVSB MOVSD MOVSW MOVW MUL NEG NOP NOT OR OUT OUTS OUTSB OUTSD OUTSW -OUTW POP POPA POPAD POPF POPFD PUSH PUSHA PUSHAD PUSHF PUSHFD RCL RCR -ROL ROR REP REPE REPNE REPNZ REPZ RET RETF RETI SAHF SAL SAR SBB SCAB -SCAS SCASB SCASD SCASW SCAW SEG SHL SHR SSEG STC STD STI STOB STOS STOSB -STOSD STOSW STOW SUB TEST WAIT XCHG XLAT XLATB XOR - -F2XM1 FABS FADD FADDP FBLD FBSTP FCHS FCLEX FCOM FCOMP FCOMPP FCOS -FDECSTP FDISI FDIV FDIVP FDIVR FDIVRP FENI FFREE FIADD FICOM FICOMP -FIDIV FIDIVR FILD FIMUL FINCSTP FINIT FIST FISTP FISUB FISUBR FLD FLD1 -FLDL2E FLDL2T FLDCW FLDENV FLDLG2 FLDLN2 FLDPI FLDZ FMUL FMULP FNCLEX -FNDISI FNENI FNINIT FNOP FNSAVE FNSTCW FNSTENV FNSTSW FPATAN FPREM -FPREM1 FPTAN FRNDINT FRSTOR FSAVE FSCALE FSETPM FSIN FSINCOS FSQRT FST -FSTCW FSTENV FSTP FSTSW FSUB FSUBP FSUBR FSUBRP FTST FUCOM FUCOMP -FUCOMPP FWAIT FXAM FXCH FXTRACT FYL2X FYL2XP1 - -BSF BSR BSWAP BT BTC BTR BTS CLTS CMPXCHG INVD INVLPG LAR LFS LGDT LGS -LIDT LLDT LMSW LSL LSS LTR MOVSX MOVZX SETA SETAE SETB SETBE SETC SETE -SETG SETGE SETL SETLE SETNA SETNAE SETNB SETNBE SETNC SETNE SETNG SETNGE -SETNL SETNLE SETNO SETNP SETNS SETNZ SETO SETP SETPE SETPO SETS SETZ -SGDT SIDT SHLD SHRD SLDT SMSW STR VERR VERW WBINVD XADD ADCB ADDB ANDB -CMPB DECB DIVB IDIVB IMULB INB INCB MOVB MULB NEGB NOTB ORB OUTB RCLB -RCRB ROLB RORB SALB SARB SHLB SHRB SBBB SUBB TESTB XCHGB XORB diff -Nurd linux86.vold/as/assemble.c linux86/as/assemble.c --- linux86.vold/as/assemble.c 2000-10-27 09:02:12.000000000 +0100 +++ linux86/as/assemble.c 2001-06-24 08:19:37.000000000 +0100 @@ -38,7 +38,9 @@ pfcb, pfcc, pfdb, +#if SIZEOF_OFFSET_T > 2 pfqb, +#endif pget, pglobl, pident, diff -Nurd linux86.vold/as/chk linux86/as/chk --- linux86.vold/as/chk 2000-09-27 22:34:45.000000000 +0100 +++ linux86/as/chk 2004-01-02 21:49:35.000000000 +0000 @@ -1,8 +1,8 @@ compile() { - # /lib/elksemu ./as86 -3 "$@" - ./as86 -3 "$@" + # /lib/elksemu ./as86 -3 -k "$@" + ./as86 -3 -k "$@" } for i in `ls asm/*.asm` diff -Nurd linux86.vold/as/const.h linux86/as/const.h --- linux86.vold/as/const.h 1997-04-24 21:25:29.000000000 +0100 +++ linux86/as/const.h 2001-06-27 16:38:16.000000000 +0100 @@ -7,14 +7,14 @@ #define S_ALIGNMENT sizeof(long) #endif -#include "align.h" - /* const.h - constants for assembler */ /* major switches */ +/* #define MC6809 */ /* generate 6809 code */ +#ifndef MC6809 #define I80386 /* generate 80386 code */ -#undef MC6809 /* generate 6809 code */ +#endif #define MNSIZE /* allow byte size in mnemonic, e.g. "movb" */ #undef SOS_EDOS /* source OS is EDOS */ @@ -215,116 +215,6 @@ COLON }; -enum -{ -/* Error codes. */ - -/* Syntax errors. */ - COMEXP, - DELEXP, - FACEXP, - IREGEXP, - LABEXP, - LPEXP, - OPEXP, - RBEXP, - REGEXP, - RPEXP, - SPEXP, - -/* Expression errors. */ - ABSREQ, - NONIMPREQ, - RELBAD, - -/* Label errors. */ - ILLAB, - MACUID, - MISLAB, - MNUID, - REGUID, - RELAB, - UNBLAB, - UNLAB, - VARLAB, - -/* Addressing errors. */ - ABOUNDS, - DBOUNDS, - ILLMOD, - ILLREG, - -/* Control structure errors. */ - ELSEBAD, -#define ELSEIFBAD ELSEBAD - ENDBBAD, -#define ENDIFBAD ELSEBAD - EOFBLOCK, - EOFIF, - EOFLC, - EOFMAC, - FAILERR, - -/* Overflow errors. */ - BLOCKOV, - BWRAP, - COUNTOV, - COUNTUN, - GETOV, - IFOV, - - LINLONG, - MACOV, - OBJSYMOV, - OWRITE, - PAROV, - SYMOV, - SYMOUTOV, - -/* I/O errors. */ - OBJOUT, - -/* Miscellaneous errors. */ - AL_AX_EAX_EXP, - CTLINS, - FURTHER, - ILL_IMM_MODE, - ILL_IND_TO_IND, - ILL_IND, - ILL_IND_PTR, - ILL_SCALE, - ILL_SECTION, - ILL_SEG_REG, - ILL_SOURCE_EA, - ILL_SIZE, - IMM_REQ, - INDEX_REG_EXP, - IND_REQ, - MISMATCHED_SIZE, - NOIMPORT, - REENTER, - REL_REQ, - REPEATED_DISPL, - SEGREL, - SEG_REG_REQ, - SIZE_UNK, - UNKNOWN_ESCAPE_SEQUENCE, - - FP_REG_REQ, - FP_REG_NOT_ALLOWED, - ILL_FP_REG, - ILL_FP_REG_PAIR, - JUNK_AFTER_OPERANDS, - - ALREADY, - UNSTABLE_LABEL, - -/* Warnings. */ -#define MINWARN CPUCLASH - CPUCLASH, - SHORTB -}; - /* symbol table entry */ /* type entry contains following flags */ @@ -423,3 +313,6 @@ #define DPLOC 2 #define STRLOC 1 #define TEXTLOC 0 + +#include "errors.h" + diff -Nurd linux86.vold/as/error.c linux86/as/error.c --- linux86.vold/as/error.c 2000-09-26 20:52:45.000000000 +0100 +++ linux86/as/error.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,102 +0,0 @@ -/* error.c - error routines for assembler */ - -#include "syshead.h" -#include "const.h" -#include "type.h" - -PRIVATE char *errormessage[] = -{ - "comma expected", - "delimiter expected", - "factor expected", - "index register expected", - "label expected", - "left parentheses expected", - "opcode expected", - "right bracket expected", - "register expected", - "right parentheses expected", - "space expected", - "absolute expression required", - "non-imported expression required", - "relocation impossible", - "illegal label", - "MACRO used as identifier", - "missing label", - "opcode used as identifier", - "register used as identifier", - "redefined label", - "unbound label", - "undefined label", - "variable used as label", - "address out of bounds", - "data out of bounds", - "illegal address mode", - "illegal register", - "no matching IF", - "no matching BLOCK", - "end of file in BLOCK", - "end of file in IF", - "location counter was undefined at end", - "end of file in MACRO", - "user-generated error", - "BLOCK stack overflow", - "binary file wrap-around", - "counter overflow", - "counter underflow", - "GET stack overflow", - "IF stack overflow", - "line too long", - "MACRO stack overflow", - "object symbol table overflow", - "program overwrite", - "parameter table overflow", - "symbol table overflow", - "output symbol table overflow", - "error writing object file", - "al, ax or eax expected", - "control character in string", - "futher errors suppressed", - "illegal immediate mode", - "illegal indirect to indirect", - "illegal indirection", - "illegal indirection from previous 'ptr'", - "illegal scale", - "illegal section", - "illegal segment register", - "illegal source effective address", - "illegal size", - "immediate expression expected", - "index register expected", - "indirect expression required", - "mismatched size", - "no imports with binary file output", - "multiple ENTER pseudo-ops", - "relative expression required", - "repeated displacement", - "segment or relocatability redefined", - "segment register required", - "size unknown", - "unknown escape sequence", - "FP register required", - "FP register not allowed", - "illegal FP register", - "illegal FP register pair", - "junk after operands", - "already defined", - "label moved in last pass, add -O?", - "instruction illegal for current cpu", - "short branch would do", - "unknown error", -}; - -/* build null-terminated error message for given error at given spot */ - -PUBLIC char *build_error_message(errnum, buf) -error_pt errnum; -char *buf; -{ - if (errnum >= sizeof errormessage / sizeof errormessage[0]) - errnum = sizeof errormessage / sizeof errormessage[0] - 1; - return strcpy(buf, errormessage[errnum]); -} diff -Nurd linux86.vold/as/errors.c linux86/as/errors.c --- linux86.vold/as/errors.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/as/errors.c 2003-12-31 11:36:39.000000000 +0000 @@ -0,0 +1,108 @@ + +#include "syshead.h" +#include "const.h" +#include "errors.h" + +/* Error codes. */ + +/* Syntax errors. */ +PUBLIC char COMEXP[] = "comma expected"; +PUBLIC char DELEXP[] = "delimiter expected"; +PUBLIC char FACEXP[] = "factor expected"; +PUBLIC char IREGEXP[] = "index register expected"; +PUBLIC char LABEXP[] = "label expected"; +PUBLIC char LPEXP[] = "left parentheses expected"; +PUBLIC char OPEXP[] = "opcode expected"; +PUBLIC char RBEXP[] = "right bracket expected"; +PUBLIC char REGEXP[] = "register expected"; +PUBLIC char RPEXP[] = "right parentheses expected"; +PUBLIC char SPEXP[] = "space expected"; + +/* Expression errors. */ +PUBLIC char ABSREQ[] = "absolute expression required"; +PUBLIC char NONIMPREQ[] = "non-imported expression required"; +PUBLIC char RELBAD[] = "relocation impossible"; + +/* Label errors. */ +PUBLIC char ILLAB[] = "illegal label"; +PUBLIC char MACUID[] = "MACRO used as identifier"; +PUBLIC char MISLAB[] = "missing label"; +PUBLIC char MNUID[] = "opcode used as identifier"; +PUBLIC char REGUID[] = "register used as identifier"; +PUBLIC char RELAB[] = "redefined label"; +PUBLIC char UNBLAB[] = "unbound label"; +PUBLIC char UNLAB[] = "undefined label"; +PUBLIC char VARLAB[] = "variable used as label"; + +/* Addressing errors. */ +PUBLIC char ABOUNDS[] = "address out of bounds"; +PUBLIC char DBOUNDS[] = "data out of bounds"; +PUBLIC char ILLMOD[] = "illegal address mode"; +PUBLIC char ILLREG[] = "illegal register"; + +/* Control structure errors. */ +PUBLIC char ELSEBAD[] = "no matching IF"; +PUBLIC char ENDBBAD[] = "no matching BLOCK"; +PUBLIC char EOFBLOCK[] = "end of file in BLOCK"; +PUBLIC char EOFIF[] = "end of file in IF"; +PUBLIC char EOFLC[] = "location counter was undefined at end"; +PUBLIC char EOFMAC[] = "end of file in MACRO"; +PUBLIC char FAILERR[] = "user-generated error"; + +/* Overflow errors. */ +PUBLIC char BLOCKOV[] = "BLOCK stack overflow"; +PUBLIC char BWRAP[] = "binary file wrap-around"; +PUBLIC char COUNTOV[] = "counter overflow"; +PUBLIC char COUNTUN[] = "counter underflow"; +PUBLIC char GETOV[] = "GET stack overflow"; +PUBLIC char IFOV[] = "IF stack overflow"; + +PUBLIC char LINLONG[] = "line too long"; +PUBLIC char MACOV[] = "MACRO stack overflow"; +PUBLIC char OBJSYMOV[] = "object symbol table overflow"; +PUBLIC char OWRITE[] = "program overwrite"; +PUBLIC char PAROV[] = "parameter table overflow"; +PUBLIC char SYMOV[] = "symbol table overflow"; +PUBLIC char SYMOUTOV[] = "output symbol table overflow"; + +/* I/O errors. */ +PUBLIC char OBJOUT[] = "error writing object file"; + +/* Miscellaneous errors. */ +PUBLIC char AL_AX_EAX_EXP[] = "al ax or eax expected"; +PUBLIC char CTLINS[] = "control character in string"; +PUBLIC char FURTHER[] = "futher errors suppressed"; +PUBLIC char ILL_IMM_MODE[] = "illegal immediate mode"; +PUBLIC char ILL_IND_TO_IND[] = "illegal indirect to indirect"; +PUBLIC char ILL_IND[] = "illegal indirection"; +PUBLIC char ILL_IND_PTR[] = "illegal indirection from previous 'ptr'"; +PUBLIC char ILL_SCALE[] = "illegal scale"; +PUBLIC char ILL_SECTION[] = "illegal section"; +PUBLIC char ILL_SEG_REG[] = "illegal segment register"; +PUBLIC char ILL_SOURCE_EA[] = "illegal source effective address"; +PUBLIC char ILL_SIZE[] = "illegal size"; +PUBLIC char IMM_REQ[] = "immediate expression expected"; +PUBLIC char INDEX_REG_EXP[] = "index register expected"; +PUBLIC char IND_REQ[] = "indirect expression required"; +PUBLIC char MISMATCHED_SIZE[] = "mismatched size"; +PUBLIC char NOIMPORT[] = "no imports with binary file output"; +PUBLIC char REENTER[] = "multiple ENTER pseudo-ops"; +PUBLIC char REL_REQ[] = "relative expression required"; +PUBLIC char REPEATED_DISPL[] = "repeated displacement"; +PUBLIC char SEGREL[] = "segment or relocatability redefined"; +PUBLIC char SEG_REG_REQ[] = "segment register required"; +PUBLIC char SIZE_UNK[] = "size unknown"; +PUBLIC char UNKNOWN_ESCAPE_SEQUENCE[] = "unknown escape sequence"; + +PUBLIC char FP_REG_REQ[] = "FP register required"; +PUBLIC char FP_REG_NOT_ALLOWED[] = "FP register not allowed"; +PUBLIC char ILL_FP_REG[] = "illegal FP register"; +PUBLIC char ILL_FP_REG_PAIR[] = "illegal FP register pair"; +PUBLIC char JUNK_AFTER_OPERANDS[] = "junk after operands"; + +PUBLIC char ALREADY[] = "already defined"; +PUBLIC char UNSTABLE_LABEL[] = "label moved in last pass add -O?"; + +/* Warnings. */ +PUBLIC char CPUCLASH[] = "instruction illegal for current cpu"; +PUBLIC char SHORTB[] = "short branch would do"; diff -Nurd linux86.vold/as/errors.h linux86/as/errors.h --- linux86.vold/as/errors.h 1970-01-01 01:00:00.000000000 +0100 +++ linux86/as/errors.h 2003-12-31 11:36:39.000000000 +0000 @@ -0,0 +1,105 @@ +/* Error codes. */ + +/* Syntax errors. */ +EXTERN char COMEXP[]; /* "comma expected" */ +EXTERN char DELEXP[]; /* "delimiter expected" */ +EXTERN char FACEXP[]; /* "factor expected" */ +EXTERN char IREGEXP[]; /* "index register expected" */ +EXTERN char LABEXP[]; /* "label expected" */ +EXTERN char LPEXP[]; /* "left parentheses expected" */ +EXTERN char OPEXP[]; /* "opcode expected" */ +EXTERN char RBEXP[]; /* "right bracket expected" */ +EXTERN char REGEXP[]; /* "register expected" */ +EXTERN char RPEXP[]; /* "right parentheses expected" */ +EXTERN char SPEXP[]; /* "space expected" */ + +/* Expression errors. */ +EXTERN char ABSREQ[]; /* "absolute expression required" */ +EXTERN char NONIMPREQ[]; /* "non-imported expression required" */ +EXTERN char RELBAD[]; /* "relocation impossible" */ + +/* Label errors. */ +EXTERN char ILLAB[]; /* "illegal label" */ +EXTERN char MACUID[]; /* "MACRO used as identifier" */ +EXTERN char MISLAB[]; /* "missing label" */ +EXTERN char MNUID[]; /* "opcode used as identifier" */ +EXTERN char REGUID[]; /* "register used as identifier" */ +EXTERN char RELAB[]; /* "redefined label" */ +EXTERN char UNBLAB[]; /* "unbound label" */ +EXTERN char UNLAB[]; /* "undefined label" */ +EXTERN char VARLAB[]; /* "variable used as label" */ + +/* Addressing errors. */ +EXTERN char ABOUNDS[]; /* "address out of bounds" */ +EXTERN char DBOUNDS[]; /* "data out of bounds" */ +EXTERN char ILLMOD[]; /* "illegal address mode" */ +EXTERN char ILLREG[]; /* "illegal register" */ + +/* Control structure errors. */ +EXTERN char ELSEBAD[]; /* "no matching IF" */ +#define ELSEIFBAD ELSEBAD +EXTERN char ENDBBAD[]; /* "no matching BLOCK" */ +#define ENDIFBAD ELSEBAD +EXTERN char EOFBLOCK[]; /* "end of file in BLOCK" */ +EXTERN char EOFIF[]; /* "end of file in IF" */ +EXTERN char EOFLC[]; /* "location counter was undefined at end" */ +EXTERN char EOFMAC[]; /* "end of file in MACRO" */ +EXTERN char FAILERR[]; /* "user-generated error" */ + +/* Overflow errors. */ +EXTERN char BLOCKOV[]; /* "BLOCK stack overflow" */ +EXTERN char BWRAP[]; /* "binary file wrap-around" */ +EXTERN char COUNTOV[]; /* "counter overflow" */ +EXTERN char COUNTUN[]; /* "counter underflow" */ +EXTERN char GETOV[]; /* "GET stack overflow" */ +EXTERN char IFOV[]; /* "IF stack overflow" */ + +EXTERN char LINLONG[]; /* "line too long" */ +EXTERN char MACOV[]; /* "MACRO stack overflow" */ +EXTERN char OBJSYMOV[]; /* "object symbol table overflow" */ +EXTERN char OWRITE[]; /* "program overwrite" */ +EXTERN char PAROV[]; /* "parameter table overflow" */ +EXTERN char SYMOV[]; /* "symbol table overflow" */ +EXTERN char SYMOUTOV[]; /* "output symbol table overflow" */ + +/* I/O errors. */ +EXTERN char OBJOUT[]; /* "error writing object file" */ + +/* Miscellaneous errors. */ +EXTERN char AL_AX_EAX_EXP[]; /* "al ax or eax expected" */ +EXTERN char CTLINS[]; /* "control character in string" */ +EXTERN char FURTHER[]; /* "futher errors suppressed" */ +EXTERN char ILL_IMM_MODE[]; /* "illegal immediate mode" */ +EXTERN char ILL_IND_TO_IND[]; /* "illegal indirect to indirect" */ +EXTERN char ILL_IND[]; /* "illegal indirection" */ +EXTERN char ILL_IND_PTR[]; /* "illegal indirection from previous 'ptr'" */ +EXTERN char ILL_SCALE[]; /* "illegal scale" */ +EXTERN char ILL_SECTION[]; /* "illegal section" */ +EXTERN char ILL_SEG_REG[]; /* "illegal segment register" */ +EXTERN char ILL_SOURCE_EA[]; /* "illegal source effective address" */ +EXTERN char ILL_SIZE[]; /* "illegal size" */ +EXTERN char IMM_REQ[]; /* "immediate expression expected" */ +EXTERN char INDEX_REG_EXP[]; /* "index register expected" */ +EXTERN char IND_REQ[]; /* "indirect expression required" */ +EXTERN char MISMATCHED_SIZE[]; /* "mismatched size" */ +EXTERN char NOIMPORT[]; /* "no imports with binary file output" */ +EXTERN char REENTER[]; /* "multiple ENTER pseudo-ops" */ +EXTERN char REL_REQ[]; /* "relative expression required" */ +EXTERN char REPEATED_DISPL[]; /* "repeated displacement" */ +EXTERN char SEGREL[]; /* "segment or relocatability redefined" */ +EXTERN char SEG_REG_REQ[]; /* "segment register required" */ +EXTERN char SIZE_UNK[]; /* "size unknown" */ +EXTERN char UNKNOWN_ESCAPE_SEQUENCE[]; /* "unknown escape sequence" */ + +EXTERN char FP_REG_REQ[]; /* "FP register required" */ +EXTERN char FP_REG_NOT_ALLOWED[]; /* "FP register not allowed" */ +EXTERN char ILL_FP_REG[]; /* "illegal FP register" */ +EXTERN char ILL_FP_REG_PAIR[]; /* "illegal FP register pair" */ +EXTERN char JUNK_AFTER_OPERANDS[]; /* "junk after operands" */ + +EXTERN char ALREADY[]; /* "already defined" */ +EXTERN char UNSTABLE_LABEL[]; /* "label moved in last pass add -O?" */ + +/* Warnings. */ +EXTERN char CPUCLASH[]; /* "instruction illegal for current cpu" */ +EXTERN char SHORTB[]; /* "short branch would do" */ diff -Nurd linux86.vold/as/express.c linux86/as/express.c --- linux86.vold/as/express.c 1999-07-26 11:23:39.000000000 +0100 +++ linux86/as/express.c 2001-06-24 08:09:40.000000000 +0100 @@ -8,7 +8,7 @@ #include "scan.h" #include "source.h" -FORWARD void experror P((error_pt errnum)); +FORWARD void experror P((char * err_str)); FORWARD void expundefined P((void)); FORWARD void simple2 P((void)); FORWARD void simple P((void)); @@ -33,10 +33,10 @@ } } -PRIVATE void experror(errnum) -error_pt errnum; +PRIVATE void experror(err_str) +char * err_str; { - error(errnum); + error(err_str); expundefined(); } @@ -312,6 +312,7 @@ getsym(); return; } +#ifndef MC6809 case LBRACKET: if (!asld_compatible) break; /* error, LPAREN is the grouping symbol */ @@ -322,9 +323,12 @@ else getsym(); return; +#endif case LPAREN: +#ifndef MC6809 if (asld_compatible) break; /* error, LBRACKET is the grouping symbol */ +#endif getsym(); expres(); if (sym != RPAREN) diff -Nurd linux86.vold/as/genbin.c linux86/as/genbin.c --- linux86.vold/as/genbin.c 1997-01-02 09:54:07.000000000 +0000 +++ linux86/as/genbin.c 2002-12-04 21:10:00.000000000 +0000 @@ -7,9 +7,11 @@ #include "file.h" #include "globvar.h" +#ifdef USE_FIXED_HEAP PRIVATE char *asmbeg; /* beginning of assembler code */ /* for overwrite check */ /* bss-init to zero = NULL and not changed */ +#endif /* Sneaky stuff, the start of a binary file can be _negative_ for the I80386 assembler. The -ve addresses are ones over 2GB (or "org -32") */ @@ -234,17 +236,19 @@ } } } +#ifdef USE_FIXED_HEAP else if (binaryc && !(lcdata & UNDBIT)) /* memory output, and enabled */ { register char *bufptr; - if ((bufptr = (char *) binmbuf) >= asmbeg && bufptr < heapptr) + if ((bufptr = (char *) binmbuf) >= asmbeg && bufptr < temp_buf()) error(OWRITE); else *bufptr = ch; ++binmbuf; } +#endif } /* write sized offset to binary file or directly to memory */ diff -Nurd linux86.vold/as/genlist.c linux86/as/genlist.c --- linux86.vold/as/genlist.c 2000-06-17 11:23:51.000000000 +0100 +++ linux86/as/genlist.c 2001-06-23 21:13:19.000000000 +0100 @@ -17,7 +17,7 @@ struct error_s /* to record error info */ { - unsigned char errnum; + char * err_str; unsigned char position; }; @@ -131,36 +131,39 @@ /* record number and position of error (or error buffer overflow) */ -PUBLIC void error(errnum) -error_pt errnum; +PUBLIC void warning(err_str) +char * err_str; +{ + if (!as_warn.current) return; + ++totwarn; + --toterr; + error(err_str); +} + +PUBLIC void error(err_str) +char * err_str; { register struct error_s *errptr; register struct error_s *errptrlow; unsigned char position; - if ((unsigned) errnum < MINWARN || as_warn.current) + if (errcount >= MAXERR) + erroverflow = TRUE; + else { - if (errcount >= MAXERR) - erroverflow = TRUE; - else + position = symname - linebuf; + for (errptr = errbuf + errcount; + errptr > errbuf && errptr->position > position; + errptr = errptrlow) { - position = symname - linebuf; - for (errptr = errbuf + errcount; - errptr > errbuf && errptr->position > position; - errptr = errptrlow) - { - errptrlow = errptr - 1; - errptr->errnum = errptrlow->errnum; - errptr->position = errptrlow->position; - } - errptr->errnum = errnum; - errptr->position = position; - ++errcount; - if ((unsigned)errnum >= MINWARN) - ++totwarn; - else - ++toterr; + errptrlow = errptr - 1; + errptr->err_str = errptrlow->err_str; + errptr->position = errptrlow->position; } + errptr->err_str = err_str; + errptr->position = position; + ++errcount; + ++toterr; } } @@ -208,7 +211,7 @@ unsigned numlength; char *numptr; - listptr = (struct code_listing_s *) heapptr; + listptr = (struct code_listing_s *) temp_buf(); memset((char *) listptr, ' ', sizeof *listptr); listptr->nullterm = 0; if (macflag) @@ -354,7 +357,7 @@ { writenl(); paderrorline(1); } - writes(errmsg = build_error_message(errptr->errnum, heapptr)); + writes(errmsg = errptr->err_str); errcol = strlen(errmsg)+LINUM_LEN+1; column = 0; linep = linebuf; errcolw = CODE_LIST_LENGTH; @@ -390,7 +393,7 @@ paderrorline((unsigned) errcolw - LINUM_LEN); } writec('^'); - writes(errmsg = build_error_message(errptr->errnum, heapptr)); + writes(errmsg = errptr->err_str); errcol += strlen(errmsg); #endif ++errptr; @@ -404,7 +407,7 @@ #else paderrorline(CODE_LIST_LENGTH - LINUM_LEN); #endif - writesn(build_error_message(FURTHER, heapptr)); + writesn(FURTHER); } } diff -Nurd linux86.vold/as/genobj.c linux86/as/genobj.c --- linux86.vold/as/genobj.c 1999-03-18 07:08:48.000000000 +0000 +++ linux86/as/genobj.c 2003-01-28 21:45:27.000000000 +0000 @@ -345,6 +345,7 @@ unsigned symosiz; /* size of object symbol table */ register struct sym_s *symptr; u32_T textlength; + int symcount = 0; if ((objectc = objectg) == 0) return; @@ -362,9 +363,22 @@ if ((nameptr = strrchr(module_name, '.')) != NUL_PTR) *nameptr = 0; strsiz = strlen(module_name) + 1; - align(heapptr); - for (hashptr = spt, arrext = copyptr = (struct sym_s **) heapptr; - hashptr < spt_top;) + + for (hashptr = spt; hashptr < spt_top;) + if ((symptr = *hashptr++) != NUL_PTR) + do + { + if ((symptr->type & EXPBIT || symptr->data & IMPBIT) || + (!globals_only_in_obj && symptr->name[0] != '.' && + !(symptr->type & (MNREGBIT | MACBIT | VARBIT)))) + { + symcount ++; + } + } + while ((symptr = symptr->next) != NUL_PTR); + arrext = copyptr = asalloc( sizeof(struct sym_s *) * symcount); + + for (hashptr = spt; hashptr < spt_top;) if ((symptr = *hashptr++) != NUL_PTR) do { @@ -372,11 +386,6 @@ (!globals_only_in_obj && symptr->name[0] != '.' && !(symptr->type & (MNREGBIT | MACBIT | VARBIT)))) { - if (copyptr >= (struct sym_s **) heapend) - { - heapptr = (char *) copyptr; - fatalerror(OBJSYMOV); - } *copyptr++ = symptr; strsiz += symptr->length + 1; if (textseg>=0 && (symptr->data & SEGM) == textseg) @@ -399,7 +408,7 @@ } } while ((symptr = symptr->next) != NUL_PTR); - heapptr = (char *) (copytop = copyptr); + copytop = copyptr; /* calculate length of text, and number of seg size bytes in header */ @@ -625,7 +634,7 @@ char buf[sizeof offset]; u4c4(buf, offset); - writeobj(buf, sizeof buf); + writeobj(buf, 4); } /* write sized offset to object code buffer assuming ... */ diff -Nurd linux86.vold/as/gensym.c linux86/as/gensym.c --- linux86.vold/as/gensym.c 1996-07-22 00:33:40.000000000 +0100 +++ linux86/as/gensym.c 2001-06-23 20:25:18.000000000 +0100 @@ -29,35 +29,34 @@ #ifdef BINSYM unsigned label_stringptr; /* offset of label str from start of file */ #endif + int symcount = 0; labels_length = label_count = 0; /* make copy of all relavant symbol ptrs on heap */ /* original ptrs can now be modified, but need to be an array for sort */ - align(heapptr); - for (hashptr = spt, symlptr = copyptr = (struct sym_s **) heapptr; - hashptr < spt_top;) + for (hashptr = spt; hashptr < spt_top;) + if ((symptr = *hashptr++) != NUL_PTR) + do + if (!(symptr->type & (MACBIT | MNREGBIT | VARBIT))) + symcount++; + while ((symptr = symptr->next) != NUL_PTR); + symlptr = copyptr = asalloc( sizeof(struct sym_s *) * symcount); + + for (hashptr = spt; hashptr < spt_top;) if ((symptr = *hashptr++) != NUL_PTR) do if (!(symptr->type & (MACBIT | MNREGBIT | VARBIT))) { - if (copyptr >= (struct sym_s **) heapend) - { - heapptr = (char *) copyptr; - error(SYMOUTOV); /* avoid recursive fatalerror */ - listline(); /* the main job is OK if here */ - goto sort_symbols; - } *copyptr++ = symptr; ++label_count; labels_length += symptr->length + 3; /* 3 for type, value */ } while ((symptr = symptr->next) != NUL_PTR); -sort_symbols: sort(symlptr, copyptr, TRUE); /* sort on name */ - heapptr = (char *) (copytop = copyptr); + copytop = copyptr; if (list.global) { outfd = lstfil; @@ -147,7 +146,7 @@ char *outname; char *symname; - listptr = (struct sym_listing_s *) heapptr; + listptr = (struct sym_listing_s *) temp_buf(); memset((char *) listptr, ' ', SYMLIS_LEN); listptr->nullterm = 0; if ((length = symptr->length) > SYMLIS_NAMELEN) diff -Nurd linux86.vold/as/globvar.h linux86/as/globvar.h --- linux86.vold/as/globvar.h 2000-09-27 20:03:50.000000000 +0100 +++ linux86/as/globvar.h 2001-06-23 21:18:19.000000000 +0100 @@ -35,8 +35,6 @@ /* for symbol table routines */ -EXTERN char *heapend; /* end of free space for symbol list */ -EXTERN char *heapptr; /* next free space in symbol list */ EXTERN unsigned char inidata; /* init sym entry data governed by "u" flag */ EXTERN struct sym_s **spt; /* symbol pointer table */ EXTERN struct sym_s **spt_top; /* top of symbol ptr table */ @@ -112,7 +110,7 @@ #ifdef I80386 #ifndef __AS386_16__ #define iscpu(x) (cpuid>=(x)) -#define needcpu(x) do{ if(cpuid<(x)) {error(CPUCLASH); cpuid|=0x10;} }while(0) +#define needcpu(x) do{ if(cpuid<(x)) {warning(CPUCLASH); cpuid|=0x10;} }while(0) #define setcpu(x) (cpuid=(x)) #define cpuwarn() (cpuid&=0xF) #endif diff -Nurd linux86.vold/as/keywords.c linux86/as/keywords.c --- linux86.vold/as/keywords.c 1996-07-22 00:33:42.000000000 +0100 +++ linux86/as/keywords.c 2003-01-07 08:31:23.000000000 +0000 @@ -135,9 +135,13 @@ 5, '.', 'D', 'A', 'T', 'A', DATAOP, 0, 6, '.', 'D', 'A', 'T', 'A', '1', FCBOP, 0, 6, '.', 'D', 'A', 'T', 'A', '2', FDBOP, 0, +#if SIZEOF_OFFSET_T > 2 6, '.', 'D', 'A', 'T', 'A', '4', FQBOP, 0, +#endif 2, 'D', 'B', FCBOP, 0, +#if SIZEOF_OFFSET_T > 2 2, 'D', 'D', FQBOP, 0, +#endif 7, '.', 'D', 'E', 'F', 'I', 'N', 'E', EXPORTOP, 0, 2, 'D', 'W', FDBOP, 0, 3, 'E', 'N', 'D', PROCEOFOP, 0, @@ -165,7 +169,9 @@ 6, '.', 'L', 'C', 'O', 'M', 'M', LCOMMOP1, 0, 5, '.', 'L', 'I', 'S', 'T', LISTOP, 0, 3, 'L', 'O', 'C', LOCOP, 0, +#if SIZEOF_OFFSET_T > 2 5, '.', 'L', 'O', 'N', 'G', FQBOP, 0, +#endif 8, '.', 'M', 'A', 'C', 'L', 'I', 'S', 'T', MACLISTOP, 0, 5, 'M', 'A', 'C', 'R', 'O', MACROOP, 0, 4, '.', 'M', 'A', 'P', MAPOP, 0, @@ -180,8 +186,10 @@ 6, '.', 'S', 'H', 'O', 'R', 'T', FDBOP, 0, 6, '.', 'S', 'P', 'A', 'C', 'E', RMBOP, 0, 5, '.', 'T', 'E', 'X', 'T', TEXTOP, 0, +#ifndef MC6809 5, 'U', 'S', 'E', '1', '6', USE16OP, 0, 5, 'U', 'S', 'E', '3', '2', USE32OP, 0, +#endif 5, '.', 'W', 'A', 'R', 'N', WARNOP, 0, 5, '.', 'W', 'O', 'R', 'D', FDBOP, 0, 6, '.', 'Z', 'E', 'R', 'O', 'W', BLKWOP, 0, @@ -613,6 +621,7 @@ 3, 'L', 'T', 'R', GROUP6, 0x18, 5, 'M', 'O', 'V', 'S', 'X', MOVX, 0xBE, 5, 'M', 'O', 'V', 'Z', 'X', MOVX, 0xB6, + 5, 'R', 'D', 'M', 'S', 'R', INHER, 0x32, 4, 'S', 'E', 'T', 'A', SETCC, 0x97, 5, 'S', 'E', 'T', 'A', 'E', SETCC, 0x93, 4, 'S', 'E', 'T', 'B', SETCC, 0x92, @@ -653,6 +662,7 @@ 4, 'V', 'E', 'R', 'R', GROUP6, 0x20, 4, 'V', 'E', 'R', 'W', GROUP6, 0x28, 6, 'W', 'B', 'I', 'N', 'V', 'D', INHER, 0x09, + 5, 'W', 'R', 'M', 'S', 'R', INHER, 0x30, 4, 'X', 'A', 'D', 'D', ExGx, 0xC0, #endif /* I80386 */ diff -Nurd linux86.vold/as/macro.c linux86/as/macro.c --- linux86.vold/as/macro.c 1997-01-02 09:54:07.000000000 +0000 +++ linux86/as/macro.c 2001-06-23 22:54:14.000000000 +0100 @@ -38,9 +38,12 @@ macpar = (struct schain_s *) (stringptr + 1); /* TODO: alignment */ getsym(); - if (sym != LPAREN) + if (sym == EOLSYM) return; /* no other params */ - reglineptr = lineptr; + if (sym != LPAREN) + reglineptr = symname; + else + reglineptr = lineptr; stringptr = macpar->string; while (TRUE) { @@ -51,10 +54,11 @@ return; } ch = *reglineptr++; - if (ch == '/') + if (ch == '\\') /* escaped means no special meaning for slash, comma, paren */ ch = *reglineptr++; - else if (ch == ',' || ch == ')') + else if (ch == ',' || ch == ')' || ch == '!' || ch == ';' + || ch == '\n' || ch == 0) { if (stringptr >= (char *) macptop) { @@ -69,7 +73,7 @@ macpar = (struct schain_s *) (stringptr + 1); /* but is finished OK - TODO align */ stringptr = macpar->string; - if (ch == ')') + if (ch != ',') return; continue; } @@ -90,6 +94,9 @@ bool_t saving; bool_t savingc; struct sym_s *symptr=0; + int maclen = 8; + int macoff = 0; + char * macbuf = asalloc(8); saving = /* prepare for bad macro */ savingc = FALSE; /* normally don't save comments */ @@ -114,9 +121,7 @@ else symptr->type |= MACBIT; symptr->data = UNDBIT; /* undefined till end */ - symptr->value_reg_or_op.value = (offset_t) heapptr; - /* beginning of store for macro */ - /* value s.b. (char *) */ + symptr->value_reg_or_op.value = (offset_t) macbuf; getsym_nolookup(); /* test for "C" */ if (sym == IDENT && lineptr == symname + 1 && *symname == 'C') savingc = TRUE; @@ -147,27 +152,24 @@ if (!saving) continue; { - register char *reglineptr; - register char *regheapptr; + char * p = strchr(linebuf, EOLCHAR); + int len = (p-linebuf+1); - reglineptr = linebuf; - regheapptr = heapptr; - do + if ( macoff + len > maclen-4 ) { - if (regheapptr >= heapend) - { - heapptr = regheapptr; - fatalerror(SYMOV); /* won't fit */ - } + maclen = maclen * 2 + len; + macbuf = asrealloc(macbuf, maclen); } - while ((*regheapptr++ = *reglineptr++) != EOLCHAR); - heapptr = regheapptr; + memcpy(macbuf+macoff, linebuf, len); + macoff += len; + } } macload = FALSE; if (saving) { - *heapptr++ = ETB; + macbuf[macoff] = ETB; + symptr->value_reg_or_op.value = (offset_t) macbuf; symptr->data = 0; } } diff -Nurd linux86.vold/as/Makefile linux86/as/Makefile --- linux86.vold/as/Makefile 2001-01-06 09:52:28.000000000 +0000 +++ linux86/as/Makefile 2003-12-31 11:36:39.000000000 +0000 @@ -4,10 +4,10 @@ LIBDIR=/usr/bin BINDIR=/usr/bin -OBJS =as.o assemble.o error.o express.o \ +OBJS =as.o assemble.o errors.o express.o \ genbin.o genlist.o genobj.o gensym.o \ keywords.o macro.o mops.o pops.o readsrc.o \ - scan.o table.o typeconv.o + scan.o table.o typeconv.o alloc.o all: as86 as86_encap @@ -16,7 +16,7 @@ as86_encap: as86_encap.sh sed -e "s:%%LIBDIR%%:$(LIBDIR):" -e "s:%%BINDIR%%:$(BINDIR):" \ - < $^ > tmp + < as86_encap.sh > tmp @mv -f tmp $@ chmod +x $@ @@ -30,6 +30,11 @@ clean realclean clobber: rm -f *.o as86 as86_encap +.c.o: + $(CC) $(CFLAGS) -c $< + +$(OBJS): const.h errors.h + as.o: const.h type.h byteord.h macro.h file.h flag.h globvar.h assemble.o: const.h type.h address.h globvar.h opcode.h scan.h error.o: const.h type.h @@ -46,4 +51,3 @@ readsrc.o: const.h type.h flag.h file.h globvar.h macro.h scan.h source.h scan.o: const.h type.h globvar.h scan.h table.o: const.h type.h globvar.h opcode.h scan.h - diff -Nurd linux86.vold/as/mops.c linux86/as/mops.c --- linux86.vold/as/mops.c 2000-09-27 21:15:14.000000000 +0100 +++ linux86/as/mops.c 2001-06-24 08:22:44.000000000 +0100 @@ -409,7 +409,7 @@ FORWARD void getindirect P((struct ea_s *eap)); FORWARD void getshift P((struct ea_s *eap)); FORWARD reg_pt indregchk P((reg_pt matchreg)); -FORWARD void kgerror P((error_pt errnum)); +FORWARD void kgerror P((char * err_str)); FORWARD void lbranch P((int backamount)); FORWARD void notbytesize P((struct ea_s *eap)); FORWARD void notimmed P((struct ea_s *eap)); @@ -1050,10 +1050,10 @@ return reg; } -PRIVATE void kgerror(errnum) -error_pt errnum; +PRIVATE void kgerror(err_str) +char * err_str; { - error(errnum); + error(err_str); sprefix = oprefix = aprefix = mcount = 0x0; } @@ -1071,7 +1071,7 @@ if ( last_pass<2 && backamount != 0x0 && !(lastexp.data & IMPBIT) && lastexp.offset + backamount < 0x80 + backamount) - error(SHORTB); /* -0x8? to 0x7F, warning */ + warning(SHORTB); /* -0x8? to 0x7F, warning */ } } } @@ -2427,7 +2427,7 @@ FORWARD void do1altind P((void)); FORWARD void fixupind P((void)); FORWARD void getindexnopost P((void)); -FORWARD void inderror P((error_pt errnum)); +FORWARD void inderror P((char * err_str)); FORWARD reg_pt indreg P((reg_pt maxindex)); FORWARD void predec1 P((void)); FORWARD void sustack P((reg_pt stackreg)); @@ -2617,8 +2617,8 @@ inderror(ILLMOD); /* e.g. LEAX $10 */ else { - if (byteflag || !wordflag && !(lastexp.data & (FORBIT | RELBIT)) && - (lastexp.offset >> 0x8) == dirpag) + if (byteflag || (!wordflag && !(lastexp.data & (FORBIT | RELBIT)) && + (lastexp.offset >> 0x8) == dirpag)) { /* direct addressing */ if (opcode >= 0x80) opcode |= 0x10; @@ -2634,7 +2634,7 @@ !(lastexp.data & IMPBIT) && lastexp.offset + (0x81 - 0x3) < 0x101) /* JSR or JMP could be done with BSR or BRA */ - error(SHORTB); + warning(SHORTB); } } } @@ -2657,10 +2657,10 @@ fixupind(); } -PRIVATE void inderror(errnum) -error_pt errnum; +PRIVATE void inderror(err_str) +char * err_str; { - error(errnum); + error(err_str); if (postb & INDIRECTBIT) sym = RBRACKET; /* fake right bracket to kill further errors */ fixupind(); @@ -2754,7 +2754,7 @@ lastexp.offset = lastexp.offset - lc - lcjump; if ( last_pass<2 && !(lastexp.data & IMPBIT) && lastexp.offset + 0x81 < 0x101) - error(SHORTB); /* -0x81 to 0x7F, warning */ + warning(SHORTB); /* -0x81 to 0x7F, warning */ } } } diff -Nurd linux86.vold/as/opcode.h linux86/as/opcode.h --- linux86.vold/as/opcode.h 1993-07-10 18:07:21.000000000 +0100 +++ linux86/as/opcode.h 2001-06-24 08:18:46.000000000 +0100 @@ -31,7 +31,9 @@ FCBOP, FCCOP, FDBOP, +#if SIZEOF_OFFSET_T > 2 FQBOP, +#endif GETOP, GLOBLOP, IDENTOP, diff -Nurd linux86.vold/as/pops.c linux86/as/pops.c --- linux86.vold/as/pops.c 2000-10-27 09:00:01.000000000 +0100 +++ linux86/as/pops.c 2001-06-23 21:03:47.000000000 +0100 @@ -420,10 +420,10 @@ } } -PUBLIC void fatalerror(errnum) -error_pt errnum; +PUBLIC void fatalerror(err_str) +char * err_str; { - error(errnum); + error(err_str); skipline(); listline(); finishup(); @@ -432,8 +432,8 @@ /* swap position with label position, do error, put back posn */ /* also clear label ptr */ -PUBLIC void labelerror(errnum) -error_pt errnum; +PUBLIC void labelerror(err_str) +char * err_str; { struct sym_s *oldgsymptr; char *oldlineptr; @@ -447,7 +447,7 @@ lineptr = linebuf; getsym(); /* 1st symbol is label or symbol after * missing one */ - error(errnum); + error(err_str); gsymptr = oldgsymptr; lineptr = oldlineptr; sym = oldsym; diff -Nurd linux86.vold/as/proto.h linux86/as/proto.h --- linux86.vold/as/proto.h 1999-03-18 07:06:04.000000000 +0000 +++ linux86/as/proto.h 2001-06-24 08:19:03.000000000 +0100 @@ -10,9 +10,6 @@ /* assemble.c */ void assemble P((void)); -/* error.c */ -char *build_error_message P((error_pt errnum, char *buf)); - /* express.c */ void absexpres P((void)); void chkabs P((void)); @@ -34,7 +31,8 @@ /* genlist.c */ char *build_2hex_number P((unsigned num, char *where)); char *build_number P((unsigned num, unsigned width, char *where)); -void error P((error_pt errnum)); +void warning P((char * errorstr)); +void error P((char * errorstr)); void listline P((void)); void writec P((int ch)); void writenl P((void)); @@ -139,8 +137,8 @@ bool_pt checksegrel P((struct sym_s *symptr)); void checkdatabounds P((void)); void datatoobig P((void)); -void fatalerror P((error_pt errnum)); -void labelerror P((error_pt errnum)); +void fatalerror P((char * errorstr)); +void labelerror P((char * errorstr)); void palign P((void)); void pasciz P((void)); void pblkw P((void)); @@ -163,7 +161,9 @@ void pfcb P((void)); void pfcc P((void)); void pfdb P((void)); +#if SIZEOF_OFFSET_T > 2 void pfqb P((void)); +#endif void pglobl P((void)); void pident P((void)); void pif P((void)); @@ -216,3 +216,10 @@ void u2cn P((char *buf, u16_pt offset, unsigned count)); void u4cn P((char *buf, u32_T offset, unsigned count)); bool_pt typeconv_init P((bool_pt big_endian, bool_pt long_big_endian)); + +/* alloc.c */ +void * asalloc P((unsigned int size)); +void * asrealloc P((void * oldptr, unsigned int size)); +void * temp_buf P((void)); +void init_heap P((void)); + diff -Nurd linux86.vold/as/readsrc.c linux86/as/readsrc.c --- linux86.vold/as/readsrc.c 2000-09-27 07:45:09.000000000 +0100 +++ linux86/as/readsrc.c 2004-06-20 18:49:53.000000000 +0100 @@ -50,7 +50,7 @@ PRIVATE struct get_s *getstak; /* ptr */ #if BIGBUFFER == 1 -PRIVATE char *mem_start, *mem_end; +PRIVATE char *mem_start = 0, *mem_end; #endif PRIVATE char hid_linebuf[LINLEN]; /* line buffer */ @@ -109,6 +109,9 @@ #if BIGBUFFER == 1 if( mem_start == 0 ) { + size_t memsize = 0; + int cc; + if(fd) { struct stat st; @@ -120,33 +123,34 @@ goto cant_do_this; } } - if( filelength > 0 ) - { - if( (mem_start = malloc(filelength+2)) == 0 ) + + if (filelength > 0) { + if( (mem_start = malloc(filelength+4)) == 0 ) { mem_end = mem_start = "\n\n"; goto cant_do_this; - } + } + memsize = filelength; + filelength = read(fd, mem_start, filelength); - } - else - { - size_t memsize = 0; - int cc; + } else filelength = 0; - for(;;) - { - if( filelength >= memsize ) - mem_start = realloc(mem_start, (memsize+=16000)+4); - if(mem_start == 0) - as_abort("Cannot allocate memory for BIG buffer"); - cc = read(fd, mem_start+filelength, - (size_t)(memsize-filelength)); - if( cc <= 0 ) break; - filelength+=cc; - } + for(;;) + { + if( filelength >= memsize ) + { + if (memsize > 16000) + mem_start = asrealloc(mem_start, (memsize+=16384)+4); + else + mem_start = asrealloc(mem_start, (memsize+=memsize+32)+4); + } + cc = read(fd, mem_start+filelength, + (size_t)(memsize-filelength)); + if( cc <= 0 ) break; + filelength+=cc; } + *(mem_end=mem_start+filelength) = '\n'; mem_end[1] = '\0'; diff -Nurd linux86.vold/as/scan.c linux86/as/scan.c --- linux86.vold/as/scan.c 1996-08-04 19:45:42.000000000 +0100 +++ linux86/as/scan.c 2001-06-27 16:06:10.000000000 +0100 @@ -233,6 +233,7 @@ PUBLIC void initscan() { +#ifndef MC6809 if (asld_compatible) { lindirect = LPAREN; @@ -241,8 +242,11 @@ } else { +#endif lindirect = LBRACKET; rindexp = RBEXP; rindirect = RBRACKET; +#ifndef MC6809 } +#endif } diff -Nurd linux86.vold/as/scan.h linux86/as/scan.h --- linux86.vold/as/scan.h 1996-06-29 21:05:18.000000000 +0100 +++ linux86/as/scan.h 2001-06-23 21:14:28.000000000 +0100 @@ -6,7 +6,7 @@ EXTERN char lindirect; /* left symbol for indirect addressing */ EXTERN char *lineptr; /* current line position */ EXTERN offset_t number; /* constant number */ -EXTERN int rindexp; /* error code for missing rindirect */ +EXTERN char * rindexp; /* error code for missing rindirect */ EXTERN char rindirect; /* right symbol for indirect addressing */ EXTERN char sym; /* current symbol */ EXTERN char *symname; /* current symbol name */ diff -Nurd linux86.vold/as/syshead.h linux86/as/syshead.h --- linux86.vold/as/syshead.h 1997-09-28 10:02:43.000000000 +0100 +++ linux86/as/syshead.h 2002-12-04 21:09:53.000000000 +0000 @@ -16,8 +16,10 @@ #include #include #include +#include #undef min #undef POSIX_HEADERS_MISSING +#define VERSION "MSDOS Compile" #endif #if __STDC__ && !defined(__minix) diff -Nurd linux86.vold/as/table.c linux86/as/table.c --- linux86.vold/as/table.c 1997-04-13 12:53:11.000000000 +0100 +++ linux86/as/table.c 2004-06-20 13:37:52.000000000 +0100 @@ -22,7 +22,7 @@ EXTERN char typesizes[]; #endif -#ifdef DEBUG +#ifdef DEBUG_HASH unsigned nhash; unsigned nlookup; unsigned nsym; @@ -100,7 +100,7 @@ register struct sym_s *symptr; register unsigned hashval; register unsigned length; -#ifdef DEBUG +#ifdef DEBUG_HASH int tries; ++nlookup; @@ -129,7 +129,7 @@ hashval ^= hconv(nameptr[-1]); } else - hashval = hconv(nameptr[-(length / 2)]) * MULTIPLIER, + hashval = hconv(symname[length-(length / 2)]) * MULTIPLIER, hashval ^= hconv(nameptr[-2]) << 2, hashval ^= hconv(nameptr[-1]); nameptr = symname; @@ -139,14 +139,14 @@ { do { -#ifdef DEBUG +#ifdef DEBUG_HASH if (tries != 0) --nx[tries]; ++tries; if (tries < sizeof nx / sizeof nx[0]) ++nx[tries]; if (tries >= 5) - printchain(hashptr - spt) + printchain(hashptr - spt); #endif if ((unsigned char) length != symptr->length) continue; @@ -168,28 +168,22 @@ } if (!ifflag) return NUL_PTR; - align(heapptr); - if (heapptr >= heapend) - fatalerror(SYMOV); -#ifdef DEBUG +#ifdef DEBUG_HASH ++nsym; if (hashptr >= spt && hashptr < spt + SPTSIZ) ++nhash; #endif - *hashptr = symptr = (struct sym_s *) heapptr; + *hashptr = symptr = asalloc(sizeof(struct sym_s) + length); symptr->type = 0; symptr->data = inidata; symptr->length = length; symptr->value_reg_or_op.value = (offset_t) (symptr->next = NUL_PTR); - heapptr = symptr->name; - do - *heapptr++ = *nameptr++; - while (--length != 0); - *heapptr++ = 0; + memcpy(symptr->name, nameptr, length); + symptr->name[length] = 0; return symptr; } -#ifdef DEBUG +#ifdef DEBUG_HASH static void printchain(hashval) unsigned hashval; @@ -206,7 +200,7 @@ PUBLIC void statistics() { -#ifdef DEBUG +#ifdef DEBUG_HASH int i; int weight; @@ -220,6 +214,6 @@ weight += nx[i] * i; } printf("\n"); - printf("weight = %d%d\n", w; + printf("weight = %d%d\n", weight); #endif } diff -Nurd linux86.vold/as/TODO linux86/as/TODO --- linux86.vold/as/TODO 1999-07-26 14:42:45.000000000 +0100 +++ linux86/as/TODO 1970-01-01 01:00:00.000000000 +0100 @@ -1,13 +0,0 @@ -Update 6809/const.h. - -Produce bsd symbol tables. - -Accept gas format. - -Decide how to choose between 8-bit and 32-bit branches. 16-bit branches in -32-bit mode are unusable because top 16 bits of PC are messed up. - -Buffer for printing of listing. - -Need to make assembler remember the code it generated in the penultimate -pass and regenerate code of exactly the same length in the last pass. diff -Nurd linux86.vold/as/typeconv.c linux86/as/typeconv.c --- linux86.vold/as/typeconv.c 1997-06-07 08:38:46.000000000 +0100 +++ linux86/as/typeconv.c 2003-01-28 21:39:40.000000000 +0000 @@ -13,17 +13,21 @@ void xxerr P((char *)); void xxerr(x) char * x; { write(2, x, strlen(x)); } +#ifdef __AS386_16__ static int no_swap = 1; +#endif -static long_off[4] = {0,1,2,3}; -static int_off[2] = {0,1}; +static int long_off[4] = {0,1,2,3}; +static int int_off[2] = {0,1}; PUBLIC bool_pt typeconv_init(big_endian, long_big_endian) bool_pt big_endian; bool_pt long_big_endian; { int i; +#ifdef __AS386_16__ no_swap = (!big_endian && !long_big_endian); +#endif for(i=0; i<4; i++) long_off[i] = i; for(i=0; i<2; i++) int_off[i] = i; diff -Nurd linux86.vold/as/type.h linux86/as/type.h --- linux86.vold/as/type.h 1996-06-29 21:20:30.000000000 +0100 +++ linux86/as/type.h 2001-06-23 21:01:37.000000000 +0100 @@ -22,7 +22,6 @@ typedef unsigned char bool_t; typedef int bool_pt; typedef unsigned count_t; -typedef int error_pt; typedef int fd_t; typedef unsigned char indcount_t; #ifdef I80386 diff -Nurd linux86.vold/bcc/assign.c linux86/bcc/assign.c --- linux86.vold/bcc/assign.c 1998-09-29 13:15:31.000000000 +0100 +++ linux86/bcc/assign.c 2002-08-03 17:41:53.000000000 +0100 @@ -316,7 +316,7 @@ extend(target); load(target, DREG); target->storage = targreg = getindexreg(); - if (oldscalar & (UNSIGNED | CHAR) || + if (oldscalar & UNSIGNED || target->type->constructor & (ARRAY | FUNCTION | POINTER)) uitol(targreg); else @@ -356,7 +356,7 @@ load(target, DREG); if (target->type == sctype) sctoi(); -#ifdef I8088 +#if defined(I8088) && defined(I80386) else if (tscalar & SHORT) { if (tscalar & UNSIGNED) diff -Nurd linux86.vold/bcc/bcc.bugs linux86/bcc/bcc.bugs --- linux86.vold/bcc/bcc.bugs 1992-11-09 15:58:42.000000000 +0000 +++ linux86/bcc/bcc.bugs 1970-01-01 01:00:00.000000000 +0100 @@ -1,169 +0,0 @@ -compiler limitations --------------------- - -These are not implemented: - -a. bit fields - kludgily implemented (everything padded to char, int or long; can store - values wider than the specified field width) - -g. signed char type, other ANSI extensions - -compiler bugs -------------- - -6. weird but doable casts are not always done for initializers - -15. calls to a (casted) absolute address produce an immediate prefix. as386 - doesn't mind this but complains about the absolute address. as09 complains - about the prefix but can handle the absolute address - -23. char *f(); &f() is accepted as f() but produces botched nodetype - (calc char **). - -31. null byte in string initialiser should be ignored if it doesn't fit - Non-null bytes which don't fit should be ignored with a warning - -32. static char c = "xyz"; is allowed, and bad FCB is generated - -37. init of union will store multiple comma-separated entries - -38. arrays sizes larger than the amount of memory are accepted - -40. structure and union definitions are confused with each other. So - struct foo may be used in a declaration like "union foo bar;" - -42. pointer arithmetic is performed on pointers to undefined structures - (of unknown size). Size is taken as 0 although alignmask is set early - -59. preprocessor stuff (# lines or macro names) between the identifier for - a label and the colon for the label messes up the label - -60. some things involving switches are now broken for 6809 due to lack of - frame pointer - -61. assembler may get lost on lines of length exactly (?) 256 - -65. expressions in emum lists or not properly checked for overflow. They - should fit in ints. The ordinal number is allowed to overflow - -66. sizeof has type int instead of size_t - -68. "return expr;" in a function returning a void is reported as a compiler - bug not as a semantic error - -69. an argument declared as float is (correctly) promoted to double, but - not demoted to float when it is used - -71. identifiers longer than 64 are botched (scanning of the identifier is - stopped but the remaining characters in the identifier are left to - mess up the input stream - -72. check for too many macro parameters is not working - -74. union { char a, b; } foo; gives the wrong offset for b. Unions work OK - if the declaration lists have length 1 - -75. stack gets cleaned up too early in bee = foo ? bar : baz() where baz() - returns a struct although there is kludge to make plain bee = baz() work - -76. have reintroduced reduced-type bugs, so sizeof(1 ? 1 : 2) is 1 - -78. fix to require comma in arg list may be half-baked - -79. compiler starts trying to load the void expression (i ? (void)0 : (void)0) - -80. (unsigned char *) - (char *) causes error and message is obscure - -81. 'defined' is a reserved word - -82. conditionals with voids don't work - -83. float = 1e100 gets overflow exception - -84. #endif seems to be seen in -#if 1 -foo #endif bar - -85. line numbers from cpp are not quite right. - -bugs that may be fixed ----------------------- - -41. typedef's are not scoped properly - -nonstandard things that are not done quite right ------------------------------------------------- - -3. arguments declared as register are not being dumped by #asm, register - vars anyway not being passed to #asm - -26. should clear label ptrs when starting #asm - -things that have to be be done better -------------------------------------- - -11. push order reversed in genloads.c (temp) - might try to get DP order right - -12. need to clean up handling of sc specs (maybe rename flags to sc) - And local statics and externs - -24. gvarsc is not returned properly for struct/union since the members - affect gvarsc (incorrectly). There should be a flag set when - inside a struct/union definition to disable sc specs. This could - replace the tests in abdeclarator and declselt - Best may be to carry the sc along with the type a bit more (in a - global symbol structure). Also, the symbol should record sc in a better - way than now - -25. need to check stack sometimes. Xenix cc does it when allocating >= 100 - bytes locals and this is essential in Xenix as the stack is grown - dynamically - -68. overflow checking for constants - -things that could be done better --------------------------------- - -4. install new 6809 code for branch patching (after redundancy checks) - -5. can improve code for compare with global adr in non-posindependent case - -6. char *s; long *pl; - code for *s += *pl is poor, for *s += (int) *pl is good - -7. most mov's from to ax would be faster and smaller done by xchg's - -7a. check ptr add/sub operations earlier - -8. tests for against 1 and -1 can sometimes be done with dec's and inc's - -9. __opreg is used unnec when the ptr is already in it - -9a. double indirect ptrs should maybe be made direct rather than singly - indirect by makelessindirect - -10. in cmpsmallconst(), the comparison constant should be incorporated in - the offset if the indcount is 0 and lea() called. It is harmless to - use the lea() trick for non-small constants - -20. when saved registers are popped in assign() they may overwrite the - expression value, anywhere else? May be fixed now - -27. better if loadexpression returned the register used - -28. better if source.c did not #include storage.h - it only references - DEFINITION, in some blank-skipping code which could be moved to - scan.c or preproc.c. preproc.c, scan.c and type.c also #include - storage.h, just to get at the DEFINITION and KEYWORD definitions - -29. need nodetype() to know about all optimisations in advance, including - int % small power of 2 (including 0, 1). Need to delete all type - assignments in final code gen, specially the one that convert short - to int - -30. overflow checking at runtime - -31. Use more than the first char from multiple character constants - -56. --i++ is not detected as an error in the parser diff -Nurd linux86.vold/bcc/bcc.c linux86/bcc/bcc.c --- linux86.vold/bcc/bcc.c 2000-09-27 21:43:51.000000000 +0100 +++ linux86/bcc/bcc.c 2005-01-03 22:41:55.000000000 +0000 @@ -1,26 +1,72 @@ -/* bcc.c - driver for Bruce's C compiler (bcc) and for CvW's C compiler */ - -/* Copyright (C) 1992 Bruce Evans */ - -#define _POSIX_SOURCE 1 - -#include -#include +/* + * bcc.c Version 2001.1 + * Complete rewrite because the old one was just too confusing! + * + * There are no significant compile time options (MC6809 and CCC + * just change defaults) but you should set LOCALPREFIX. + * + * Personality flags are: + * + * -Mn Normal ELKS + * -Md MSDOS + * -Ms PC Standalone. + * -Ml i386 Linux + * -M8 CvW's c386 + * -M9 MC6809 with bcc + * -M0 A framework for the -B option. + */ +#include +#ifdef __STDC__ +#include #ifndef MSDOS -#include #include #endif -#include -#include +#else +#include +#endif #include +#include #include +#include +#include +#ifndef MSDOS +#include +#include +#endif +#include "version.h" -#define FALSE 0 -#define FORWARD static -#define NUL_PTR ((void*)0) -#define PRIVATE static -#define PUBLIC -#define TRUE 1 +#ifdef MSDOS +#define LOCALPREFIX /linux86 +#define EXESUF ".exe" +#define R_OK 4 /* Test for read permission. */ +#define W_OK 2 /* Test for write permission. */ +#define X_OK 1 /* Test for execute permission. */ +#define F_OK 0 /* Test for existence. */ +#define DEFARCH 0 /* Default to 8086 code */ +#include "version.h" +#else +#define EXESUF +#endif + +#define AS "as" EXESUF +#define LD "ld" EXESUF +#define CPP "cpp" EXESUF +#define CC1 "cc1" EXESUF +#define OPT "opt" EXESUF + +#define CC1C386 "c386" EXESUF + +#define AS09 "as09" EXESUF +#define LD09 "ld09" EXESUF + +#define CPPBCC "bcc-cpp" EXESUF +#define CC1BCC "bcc-cc1" EXESUF +#define AS86 "as86" EXESUF +#define LD86 "ld86" EXESUF + +#define GCC "gcc" +#define UNPROTO "unproto" EXESUF +#define OPTIM "copt" EXESUF #if __STDC__ == 1 #define P(x) x @@ -32,932 +78,1233 @@ #define QUOT(x) "x" #endif -#ifdef MSDOS -#define LOCALPREFIX /linux86 -#define EXESUF ".exe" -#define R_OK 4 /* Test for read permission. */ -#define W_OK 2 /* Test for write permission. */ -#define X_OK 1 /* Test for execute permission. */ -#define F_OK 0 /* Test for existence. */ -#define L_TREE 1 /* Use different tree style */ -#define DEFARCH 0 /* Default to 8086 code */ +struct command { + char * cmd; + char * altcmd; + char * fullpath; + int numargs; + int maxargs; + char ** arglist; +} command = { 0,0,0,0,0,0 }; + +struct file_list { + struct file_list * next; + char * file; + char * oldfile; + char * name; + int filetype; /* Char, notional extention of file. */ +} * files; + +struct opt_list { + struct opt_list * next; + char * opt; + int opttype; /* Where the option should go */ +} * options; + +int opt_v, opt_V, opt_e, opt_x, opt_I, opt_L, opt_W, opt_i, + opt_O, opt_M, opt_f; + +#ifdef DEFARCH +int opt_arch = (DEFARCH != 0); #else -#define EXESUF +int opt_arch = sizeof (char *) >= 4; #endif -#if defined(__minix) || defined(__BCC__) -#define realpath(x,y) 0 +int do_preproc = 1; /* c -> i */ +int do_unproto = 0; /* i -> i */ +int do_compile = 1; /* i -> s */ +int do_optim = 0; /* s -> s */ +int do_as = 1; /* s -> o */ +int do_link = 1; /* o -> done */ +char * executable_name = 0; + +int file_count = 0; +int dyn_count = 0; +int error_count = 0; +char * progname = "C"; +#ifdef MSDOS +char * tmpdir = ""; +#else +char * tmpdir = "/tmp/"; #endif -#define BAS86 -#define BCC86 +int main P((int argc, char **argv)); +void getargs P((int argc, char **argv)); +void add_prefix P((char * path)); +void build_prefix P((char * path1, char * path2, char * path3)); +void run_aspreproc P((struct file_list * file)); +void run_preproc P((struct file_list * file)); +void run_unproto P((struct file_list * file)); +void run_compile P((struct file_list * file)); +void run_optim P((struct file_list * file)); +void run_as P((struct file_list * file)); +void run_link P((void)); +void command_reset P((void)); +void command_opt P((char * option)); +void command_arch P((void)); +void command_opts P((int opykey)); +void newfilename P((struct file_list * file, int last_stage, int new_extn, int use_o)); +void run_unlink P((void)); +void validate_link_opts P((void)); +void append_file P((char * filename, int ftype)); +void append_option P((char * option, int otype)); +void prepend_option P((char * option, int otype)); +char * build_libpath P((char * opt, char * str, char * suffix)); +void * xalloc P((int size)); +void Usage P((void)); +void fatal P((char * why)); +char * copystr P((char * str)); +char * catstr P((char * str, char * str2)); +void reset_prefix_path P((void)); +void run_command P((struct file_list * file)); -#define AS "as86" EXESUF -#define CC1 "bcc-cc1" EXESUF -#define CC1_MINUS_O_BROKEN FALSE -#define CPP "bcc-cc1" EXESUF -#define CPPFLAGS "-E" -#define GCC "gcc" -#define LD "ld86" EXESUF -#define UNPROTO "unproto" EXESUF -#define OPTIM "copt" EXESUF +char * prefix_path = ""; -#ifdef L_TREE -#define STANDARD_CRT0_0_PREFIX "~/lib/" -#define STANDARD_CRT0_3_PREFIX "~/lib/i386/" -#define STANDARD_EXEC_PREFIX "~/lib/" -#define STANDARD_EXEC_PREFIX_2 "~/bin/" -#define DEFAULT_INCLUDE "-I~/include" -#define DEFAULT_LIBDIR0 "-L~/lib/" -#define DEFAULT_LIBDIR3 "-L~/lib/i386/" -#define OPTIM_RULES "-d~/lib" +#ifdef LOCALPREFIX +char * localprefix = QUOT(LOCALPREFIX); #else -#define STANDARD_CRT0_0_PREFIX "~/lib/bcc/i86/" -#define STANDARD_CRT0_3_PREFIX "~/lib/bcc/i386/" -#define STANDARD_EXEC_PREFIX "~/lib/bcc/" -#ifdef BINDIR -#define STANDARD_EXEC_PREFIX_2 QUOT(BINDIR) "/" +char * localprefix = "/"; +#endif + +/* These paths are NATIVE install paths, change others below */ +char * default_include = "/usr/include"; +char * optim_rules = "/lib"; +#ifdef LIBDIR +char * default_libdir = QUOT(LIBDIR); #else -#define STANDARD_EXEC_PREFIX_2 "/usr/bin/" +char * default_libdir = "/lib"; #endif -#define DEFAULT_INCLUDE "-I~/include" -#define DEFAULT_LIBDIR0 "-L~/lib/bcc/i86/" -#define DEFAULT_LIBDIR3 "-L~/lib/bcc/i386/" -#define OPTIM_RULES "-d~/lib/bcc/i86" +char * libdir_suffix = ""; + +char devnull[] = "/dev/null"; +char * exec_prefixs[16] = { + 0 /* Last chance is contents of $PATH */ +}; + +char * libc = "-lc"; + +int +main(argc, argv) +int argc; +char ** argv; +{ + struct file_list * next_file; + char * temp; + + progname = argv[0]; + if ((temp = getenv("BCC_PREFIX")) != 0 ) + localprefix = copystr(temp); + + getargs(argc, argv); + validate_link_opts(); + + reset_prefix_path(); + + if (!*localprefix || !localprefix[1]) { + + if (*localprefix == '/') { + /* Paths for full NATIVE install "-M/" */ + build_prefix(default_libdir, libdir_suffix, ""); + build_prefix(default_libdir, "", ""); + + default_include = build_libpath("-I", "/usr/include", ""); + default_libdir = build_libpath("-L", default_libdir, libdir_suffix); + optim_rules = build_libpath("-d", optim_rules, libdir_suffix); +#if 0 + } else if (*localprefix == '+') { + /* Paths for a special */ #endif + } else { + /* Relative paths to a build dir "-M-" */ + build_prefix("/lib", libdir_suffix, ""); + build_prefix("/lib", "", ""); -#ifdef CCC -#undef BCC86 -#undef CC1 -#define CC1 "c386" -#undef CC1_MINUS_O_BROKEN -#define CC1_MINUS_O_BROKEN TRUE -#undef STANDARD_CRT0_0_PREFIX -#undef STANDARD_CRT0_3_PREFIX -#define STANDARD_CRT0_PREFIX "~/lib/i386/" -#endif /* CCC */ + default_include = build_libpath("-I", "/include", ""); + default_libdir = build_libpath("-L", "/lib", libdir_suffix); + optim_rules = build_libpath("-d", "/lib", libdir_suffix); + } -#ifdef MC6809 -#undef BAS86 -#undef BCC86 -#undef CRT0 -#undef GCC -#undef STANDARD_CRT0_0_PREFIX -#undef STANDARD_CRT0_3_PREFIX -#undef STANDARD_EXEC_PREFIX -#define STANDARD_EXEC_PREFIX "~/lib/bcc/m09/" -#endif /* MC6809 */ + } else { + /* Relative paths to normal PREFIX directory */ + default_include = build_libpath("-I", "/lib/bcc/include", ""); + default_libdir = build_libpath("-L", "/lib/bcc", libdir_suffix); + optim_rules = build_libpath("-d", "/lib/bcc", libdir_suffix); -#define ALLOC_UNIT 16 /* allocation unit for arg arrays */ -#define DIRCHAR '/' -#define START_ARGS 4 /* number of reserved args */ + build_prefix("/lib/bcc", libdir_suffix, ""); + build_prefix("/lib/bcc", "", ""); + } -typedef unsigned char bool_T; /* boolean: TRUE if nonzero */ + build_prefix("/bin", "", ""); +#ifdef BINDIR + add_prefix(QUOT(BINDIR) "/"); +#endif -struct arg_s + if (opt_v>1) { command.cmd = ""; command_reset(); } + + for(next_file = files; next_file && !error_count; next_file = next_file->next) + { + if (next_file->filetype == 'o') continue; + + if (opt_V) + fprintf(stderr, "%s:\n", next_file->file); + + /* Assembler that's not to be optimised. */ + if (do_preproc && next_file->filetype == 'x') run_aspreproc(next_file); + if (do_preproc && next_file->filetype == 'S') run_aspreproc(next_file); + if (do_as && next_file->filetype == 's') run_as(next_file); + + /* C source */ + if (do_preproc && next_file->filetype == 'c') run_preproc(next_file); + if (do_unproto && do_compile && next_file->filetype == 'i') + run_unproto(next_file); + if (do_compile && next_file->filetype == 'i') run_compile(next_file); + if (do_optim && next_file->filetype == 's') run_optim(next_file); + if (do_as && next_file->filetype == 's') run_as(next_file); + } + + if (do_link && !error_count) + run_link(); + + run_unlink(); + exit(error_count>0); +} + +char * +copystr(str) +char * str; { - char *prog; - bool_T minus_O_broken; - int argc; - char **argv; - unsigned nr_allocated; -}; + return strcpy(xalloc(strlen(str)+1), str); +} -struct prefix_s +char * +catstr(str, str2) +char * str, * str2; { - char *name; - struct prefix_s *next; -}; + return strcat(strcpy(xalloc(strlen(str)+strlen(str2)+1), str), str2); +} -PRIVATE struct arg_s asargs = { AS, }; -PRIVATE struct arg_s ccargs = { CC1, CC1_MINUS_O_BROKEN, }; -PRIVATE struct arg_s cppargs = { CPP, }; -PRIVATE struct arg_s unprotoargs = { UNPROTO, TRUE }; -PRIVATE struct arg_s optargs = { OPTIM }; -PRIVATE struct prefix_s exec_prefix; -PRIVATE struct arg_s ldargs = { LD, }; -#ifdef BAS86 -PRIVATE struct arg_s ldrargs = { LD, }; -#endif -PRIVATE char *progname; -PRIVATE bool_T runerror; /* = FALSE */ -PRIVATE struct arg_s tmpargs; /* = empty */ -PRIVATE char *tmpdir; -PRIVATE unsigned verbosity; /* = 0 */ +void +run_aspreproc(file) +struct file_list * file; +{ + static char cc1bcc[] = CC1BCC; -PRIVATE char * localprefix = QUOT(LOCALPREFIX); + if (opt_arch<5) { + if (opt_e) + command.cmd = cc1bcc; + else { + command.cmd = CPPBCC; + command.altcmd = cc1bcc; + } + } else + command.cmd = CPP; + command_reset(); + newfilename(file, (!do_as && !do_optim), (do_compile?'s':'i'), (opt_arch<5)); + if (opt_arch<5 && command.cmd == cc1bcc) + command_opt("-E"); + else if (opt_arch<5 && do_unproto) + command_opt("-A"); + command_opts('p'); + command_opt("-D__ASSEMBLER__"); -#ifdef REDECLARE_STDC_FUNCTIONS -void exit P((int status)); -char *getenv P((const char *name)); -void *malloc P((size_t size)); -void *realloc P((void *ptr, size_t size)); -void (*signal P((int sig, void (*func) P((int sig))))) P((int sig)); -char *strcpy P((char *dest, const char *src)); -size_t strlen P((const char *s)); -char *strrchr P((const char *s, int c)); -#endif + command_arch(); + run_command(file); +} -#ifdef REDECLARE_POSIX_FUNCTIONS -int access P((const char *path, int amode)); -int execv P((const char *path, char * const *argv)); -int execve P((const char *path, char * const *argv, char * const envp)); -pid_t fork P((void)); -pid_t getpid P((void)); -int unlink P((const char *path)); -pid_t wait P((int *status)); -ssize_t write P((int fd, const void *buf, size_t nbytes)); -#endif +void +run_preproc(file) +struct file_list * file; +{ + int last_stage = 0; + int combined_cpp; + static char cc1bcc[] = CC1BCC; -int main P((int argc, char **argv)); + if (opt_arch<5) { + if (opt_e) + command.cmd = cc1bcc; + else { + command.cmd = CPPBCC; + command.altcmd = cc1bcc; + } + } else + command.cmd = CPP; + command_reset(); -FORWARD void addarg P((struct arg_s *argp, char *arg)); -FORWARD void adddefine P((char *arg)); -FORWARD void addprefix P((struct prefix_s *prefix, char *name)); -FORWARD char *expand_tilde P((char * str, int canfree)); -FORWARD void fatal P((char *message)); -FORWARD char *fixpath P((char *path, struct prefix_s *prefix, int mode)); -FORWARD void killtemps P((void)); -FORWARD void *my_malloc P((unsigned size, char *where)); -FORWARD char *my_mktemp P((void)); -FORWARD void my_unlink P((char *name)); -FORWARD void outofmemory P((char *where)); -FORWARD int run P((char *in_name, char *out_name, struct arg_s *argp)); -#ifdef L_TREE -FORWARD void reset_localprefix P((void)); -#endif -FORWARD void set_trap P((void)); -FORWARD void show_who P((char *message)); -FORWARD void startarg P((struct arg_s *argp)); -FORWARD char *stralloc P((char *s)); -FORWARD char *stralloc2 P((char *s1, char *s2)); -FORWARD void trap P((int signum)); -FORWARD void writen P((void)); -FORWARD void writes P((char *s)); -FORWARD void writesn P((char *s)); -FORWARD void linux_patch P((char * fname)); + combined_cpp = (command.cmd == cc1bcc && + opt_arch != 3 && + opt_e < 2 && + !do_unproto && + do_compile); -#ifdef __BCC__ -char ** minienviron[] = { - "PATH=/bin:/usr/bin", - "SHELL=/bin/sh", - 0 -}; -#endif + if (combined_cpp && !do_optim && !do_as ) last_stage =1; + if (!combined_cpp && !do_compile ) last_stage =1; -PUBLIC int main(argc, argv) -int argc; -char **argv; + newfilename(file, last_stage, (combined_cpp?'s':'i'), (opt_arch<5)); + + if (!combined_cpp && opt_arch<5) { + if (command.cmd == cc1bcc) + command_opt("-E"); + else if (do_unproto) + command_opt("-A"); + } + + command_opts('p'); + command_opts('C'); + if (combined_cpp) + { + if (opt_arch<5 && !do_as) + command_opt("-t"); + command_opts('c'); + } + + if (!opt_I) + command_opt(default_include); + + command_arch(); + + run_command(file); +} + +void +run_unproto(file) +struct file_list * file; { - char *arg; - int add_default_inc = 1; - int add_default_lib = 1; - int argcount = argc; - bool_T *argdone = my_malloc((unsigned) argc * sizeof *argdone, "argdone"); - bool_T as_only = FALSE; - char *basename; -#ifdef BCC86 -#ifdef DEFARCH - bool_T bits32 = (DEFARCH != 0); -#else - bool_T bits32 = sizeof (char *) >= 4; -#endif - char *bits_arg; + command.cmd = UNPROTO; + command_reset(); + newfilename(file, !do_compile, 'i', 0); + command_opts('u'); + + run_command(file); +} + +void +run_compile(file) +struct file_list * file; +{ + if (opt_arch == 3) command.cmd = CC1C386; + else if (opt_arch<5) command.cmd = CC1BCC; + else command.cmd = CC1; + command_reset(); + newfilename(file, !(do_optim || do_as), 's', (opt_arch != 3 && opt_arch<5)); + + if (opt_arch<5 && !do_as) + command_opt("-t"); + + command_opts('c'); + command_opts('C'); + + command_arch(); + + run_command(file); +} + +void +run_optim(file) +struct file_list * file; +{ + char buf[32]; + if (opt_arch<5) command.cmd = OPTIM; + else command.cmd = OPT; + command_reset(); + newfilename(file, !do_as, 's', 1); + command_opt("-c!"); + if (opt_O && opt_arch == 0) + { + sprintf(buf, "-huse16 %c86", opt_O); + command_opt(buf); + } + command_opt(optim_rules); + + command_opt("rules.start"); + command_opts('o'); + + if (opt_O) { + if (opt_arch == 0) + sprintf(buf, "rules.%c86", opt_O); + else + sprintf(buf, "rules.lv_%c", opt_O); + command_opt(buf); + } + + switch(opt_arch) { + case 0: command_opt("rules.86"); break; + case 1: + case 2: command_opt("rules.i386"); break; + case 4: command_opt("rules.6809"); break; + default:command_opt("rules.mid"); break; + } + + command_opt("rules.end"); + + run_command(file); +} + +void +run_as(file) +struct file_list * file; +{ + char * buf; + switch(opt_arch) + { + case 0: case 1: case 2: + command.cmd = AS86; break; + case 4: command.cmd = AS09; break; + default: command.cmd = AS; break; + } + command_reset(); + newfilename(file, (!do_link && opt_arch!=2), 'o', 1); + if (opt_arch==3) + command_opt("-j"); + if (opt_arch<5) + command_opt("-u"); + command_opts('a'); + if (opt_W) + command_opt("-w-"); + else + command_opt("-w"); + command_arch(); + command_opt("-n"); + buf = catstr(file->name, ".s"); + command_opt(buf); + free(buf); + + run_command(file); + + if (opt_arch == 2) + { + command.cmd = LD86; + command_reset(); + command_opt("-r"); + command_opt("-N"); + newfilename(file, !do_link, 'o', 1); + run_command(file); + } +} + +void +run_link() +{ + struct file_list * next_file; + + switch(opt_arch) + { + case 0: case 1: + command.cmd = LD86; break; + case 2: command.cmd = GCC; break; + case 4: command.cmd = LD09; break; + default: command.cmd = LD; break; + } + command_reset(); + if (executable_name) { + command_opt("-o"); + command_opt(executable_name); + } + + if (opt_arch < 2) + command_opt("-y"); + + command_opts('l'); + if (opt_arch != 2) + { + if (opt_arch == 0 && !opt_i) + command_opt("-i"); + + if (!opt_L) + command_opt(default_libdir); + command_arch(); + + if (!opt_x) + command_opt("-C0"); + } + /* Current Debian compilers only work in with this: */ + else command_opt("--static"); + + for(next_file = files; next_file; next_file = next_file->next) + command_opt(next_file->file); + + if (opt_arch != 2) + command_opt(libc); + run_command(0); +} + +void +validate_link_opt(char * option) +{ + int err = 0; + if (option[0] != '-') return; + + switch(option[1]) { + default: + err = 1; + break; + case '0': /* use 16-bit libraries */ + case '3': /* use 32-bit libraries */ + case 'M': /* print symbols linked */ + case 'i': /* separate I & D output */ + case 'm': /* print modules linked */ + case 's': /* strip symbols */ + case 't': /* trace modules linked */ + case 'z': /* unmapped zero page */ + case 'N': /* Native format a.out */ + case 'd': /* Make a headerless outfile */ + case 'c': /* Write header in CP/M-86 format */ + case 'y': /* Use a newer symbol table */ + if (option[2] != 0 && option[2] != '-') + err = 1; + break; + case 'C': /* startfile name */ + case 'L': /* library path */ + case 'O': /* library file name */ + case 'T': /* text base address */ + case 'D': /* data base address */ + case 'H': /* heap top address */ + case 'l': /* library name */ + case 'o': /* output file name */ + break; + } + if (err) { + if (do_link) + fprintf(stderr, "warning: unknown option %s passed to linker.\n", + option); + else + fprintf(stderr, "warning: option %s not recognised.\n", option); + } else if (!do_link) + fprintf(stderr, "warning: linker option %s unused.\n", option); +} + +void +validate_link_opts() +{ + struct opt_list * ol; + struct file_list * next_file; + if (opt_arch>1) return; /* Only check ld86 options */ + + for(ol=options; ol; ol=ol->next) + if (ol->opttype == 'l') + validate_link_opt(ol->opt); + + for(next_file = files; next_file; next_file = next_file->next) + validate_link_opt(next_file->file); + + if (!do_link) { + if (opt_i) + fprintf(stderr, "warning: linker option -i unused.\n"); + if (opt_x) + fprintf(stderr, "warning: linker option -x unused.\n"); + if (opt_L) + fprintf(stderr, "warning: linker option -L unused.\n"); + } +} + +void +command_reset() +{ +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 #endif - bool_T cc_only = FALSE; - bool_T ansi_pass = FALSE; -#ifdef CCC - bool_T cpp_pass = TRUE; + char buf[MAXPATHLEN]; + char ** prefix; + char * saved_cmd; + + if (command.arglist) + { + int i; + for(i=0; inext) + if (ol->opttype == optkey) + command_opt(ol->opt); +} + +void newfilename(file, last_stage, new_extn, use_o) +struct file_list * file; +int last_stage; +int new_extn; +int use_o; +{ + file->filetype = new_extn; + if (file->oldfile) free(file->oldfile); + file->oldfile = file->file; + file->file = 0; + + if (last_stage) { + if (executable_name) + file->file = copystr(executable_name); + else + { + char buf[4]; + buf[0] = '.'; + buf[1] = file->filetype; + buf[2] = 0; + file->file = catstr(file->name, buf); + } + } + else + { + char buf[16]; +#ifdef MSDOS + sprintf(buf, "$$%05d$", dyn_count++); #else - bool_T cpp_pass = FALSE; + sprintf(buf, "$$%04d%05d", dyn_count++, getpid()); #endif - char *libc = "-lc"; + file->file = catstr(tmpdir, buf); + } + + command_opt(file->oldfile); + /* *.i files go to the stdout */ + if (last_stage && file->filetype == 'i') return; + if (use_o) command_opt("-o"); + command_opt(file->file); +} + +void +run_unlink() +{ + int i; + for(i=0; iOMAGIC */ + p = catstr(tmpdir, buf); + if (opt_v>1) + fprintf(stderr, "rm %s\n", p); + if (opt_v>2) + continue; + if (unlink(p) < 0) + { + if (error_count==0 || opt_v>1) + fprintf(stderr, "Error unlinking %s\n", p); + error_count++; + } + free(p); + } +} - progname = argv[0]; - addarg(&cppargs, CPPFLAGS); -#ifdef CCC - addarg(&asargs, "-j"); -#endif - addarg(&asargs, "-u"); -#ifdef BAS86 - addarg(&ldrargs, "-r"); - addarg(&ldrargs, "-N"); /* GCC uses native objects */ - /* GCC also uses 386 how to add -3 too ? */ - addarg(&optargs, "-c!"); - optflags = stralloc("start"); -#endif +void +getargs(argc, argv) +int argc; +char ** argv; +{ + int ar; + char * pflag = 0; + int control_count = 0; + int exe_count = 0; -#ifdef L_TREE - reset_localprefix(); -#endif - /* Pass 1 over argv to gather compile options. */ - for (; --argc != 0;) - { - arg = *++argv; - *++argdone = TRUE; - if (arg[0] == '-' && arg[1] != 0 && arg[2] == 0) - switch (arg[1]) - { -#ifdef BCC86 - case '0': - bits32 = FALSE; - break; - case '3': - bits32 = TRUE; - break; -#endif - case 'E': - prep_only = prep_line_numbers = cpp_pass = TRUE; - break; -#ifdef BAS86 - case 'G': - gnu_objects = TRUE; - add_default_lib = 0; - break; + for(ar=1; ar= '1' && arg[2] <= '3' )) - { - temp=optflags; - optflags=stralloc2(optflags,"86,86"); - free(temp); - switch(arg[2]) - { - case '1': addarg(&optargs, "-huse16 186"); break; - case '2': addarg(&optargs, "-huse16 286"); break; - case '3': addarg(&optargs, "-huse16 386"); break; - } - } - break; - case 'P': - addarg(&cppargs, arg + 2); - break; - case 'Q': - addarg(&ccargs, arg); - break; - case 'T': - tmpdir = arg + 2; - break; - default: - *argdone = FALSE; - break; - } - else - { - ++nifiles; - *argdone = FALSE; - length = strlen(arg); - if (length >= 2 && arg[length - 2] == '.' - && ((ext = arg[length - 1]) == 'c' || ext == 'i' || ext == 'S' - || ext == 's')) - ++ncisfiles; - } - } - npass_specs = prep_only + cc_only + as_only; - if (npass_specs != 0) - { - if (npass_specs > 1) - { - ++errcount; - show_who("more than 1 option from -E -P -S -c\n"); - } - if (f_out != NUL_PTR && ncisfiles > 1) - { - ++errcount; - show_who("cannot have more than 1 input with non-linked output\n"); - } - } - if (nifiles == 0) - { - ++errcount; - show_who("no input files\n"); - } - if (errcount != 0) - exit(1); + case 'L': + append_option(argv[ar], 'l'); + break; -#ifdef BCC86 - if(!major_mode && !bits32) major_mode='n'; - switch(major_mode) - { - case 'd': /* DOS compile */ - bits32 = FALSE; - libc= "-ldos"; - adddefine("-D__MSDOS__"); - addarg(&ldargs, "-d"); - addarg(&ldargs, "-T100"); - break; + case 'Q': + append_option(argv[ar], 'c'); + break; - case 'n': /* Normal Linux-86 */ - bits32 = FALSE; - libc= "-lc"; - adddefine("-D__ELKS__"); - adddefine("-D__unix__"); - break; + case 'O': + do_optim=1; + if (!opt_arg[1] && ( opt_arg[0] >= '1' && opt_arg[0] <= '9' )) + opt_O = opt_arg[0]; + else if (opt_arg[0] == '-') + append_option(opt_arg, 'o'); + else + { + char * p = xalloc(strlen(opt_arg)+8); + strcpy(p, "rules."); + strcat(p, opt_arg); + append_option(p, 'o'); + free(p); + } + break; - case 'f': /* Caller saves+ax is first arg */ - bits32 = FALSE; - libc= "-lc_f"; - adddefine("-D__ELKS__"); - adddefine("-D__unix__"); - addarg(&ccargs, "-f"); - addarg(&ccargs, "-c"); - break; + case 'o': + exe_count++; + executable_name = opt_arg; + break; - case 'c': /* Just caller saves, normal C-lib is ok */ - bits32 = FALSE; - libc= "-lc"; - adddefine("-D__ELKS__"); - adddefine("-D__unix__"); - addarg(&ccargs, "-c"); - break; + case 'B': + add_prefix(opt_arg); + break; - case 's': /* Standalone executable */ - bits32 = FALSE; - libc= "-lc_s"; - adddefine("-D__STANDALONE__"); - break; + case 'I': + case 'D': + case 'U': + append_option(argv[ar], 'p'); + break; - case 'l': /* Large Linux compile */ - bits32 = TRUE; - libc= "-lc"; - adddefine("-D__linux__"); - adddefine("-D__unix__"); -#ifdef __linux__ - addarg(&ldargs, "-N"); /* Make OMAGIC */ -#else - patch_exe = TRUE; -#endif - break; + case 'T': + tmpdir = catstr(opt_arg, "/"); + break; - case '?': - case 0: - break; + case 'M': + if (opt_arg[0] == '/') { + localprefix = copystr(opt_arg); + break; + } + if (opt_arg[1]) Usage(); + if (opt_arg[0] == '-') { + localprefix = ""; + break; + } + opt_M = *opt_arg; + break; - default: - fatal("Fatal error: illegal -M option given"); - } -#endif + default: + pflag = argv[ar]+1; + used_arg = 0; + break; + } + /* Singleton flags */ + if(pflag) switch(opt = *pflag++) + { + case 'P': + append_option("-P", 'p'); + /*FALLTHROUGH*/ + case 'E': + control_count++; + do_compile = do_link = do_as = 0; + break; + case 'S': + control_count++; + do_as = do_link = 0; + break; + case 'c': + control_count++; + do_link = 0; + break; + case 'O': + do_optim=1; + break; - if( aswarn ) - addarg(&asargs, "-w-"); - else - addarg(&asargs, "-w"); - if( patch_exe ) - addarg(&ldargs, "-s"); -#ifdef BCC86 - else if( !bits32 ) - addarg(&ldargs, "-i"); -#endif - if (verbosity > 2) - { - show_who("localprefix set to "); - writesn(localprefix); - } - if ((temp = getenv("BCC_EXEC_PREFIX")) != NUL_PTR) - addprefix(&exec_prefix, temp); - if( add_default_inc ) - adddefine(DEFAULT_INCLUDE); - if( add_default_lib ) - { -#ifdef BCC86 -#ifdef DEFAULT_LIBDIR3 - if( bits32 ) - addarg(&ldargs, DEFAULT_LIBDIR3); - else -#endif -#endif - addarg(&ldargs, DEFAULT_LIBDIR0); - } + case 'G': opt_M = 'g'; break; - if (optimize) - addarg(&asargs, "-O"); - addarg(&optargs, OPTIM_RULES); - temp=optflags; optflags=stralloc2(optflags,",end"); free(temp); - for(temp=strtok(optflags,","); temp; temp=strtok((char*)0,",")) - { - temp = stralloc2("rules.", temp); - addarg(&optargs, temp); - } - addprefix(&exec_prefix, STANDARD_EXEC_PREFIX); - addprefix(&exec_prefix, STANDARD_EXEC_PREFIX_2); - cppargs.prog = fixpath(cppargs.prog, &exec_prefix, X_OK); - ccargs.prog = fixpath(ccargs.prog, &exec_prefix, X_OK); - asargs.prog = fixpath(asargs.prog, &exec_prefix, X_OK); - ldargs.prog = fixpath(ldargs.prog, &exec_prefix, X_OK); -#ifdef BAS86 - ldrargs.prog = fixpath(ldrargs.prog, &exec_prefix, X_OK); + case 'v': opt_v++; break; + case 'V': opt_V++; break; + case 'e': opt_e++; break; + case 'x': opt_x++; break; + case 'I': opt_I++; break; + case 'L': opt_L++; break; + case 'i': opt_i++; break; + case 'f': opt_f++; break; + + case 'W': opt_W++; break; + + case '0': opt_arch=0; break; + case '3': opt_arch=1; break; + + case 'w': /*IGNORED*/ break; + case 'g': /*IGNORED*/ break; + case 'p': /*IGNORED*/ break; + + default: + if (pflag == argv[ar]+2) { + /* Special; unknown options saved as flags for the linker */ + append_file(argv[ar], 'o'); + pflag = 0; + } + else + Usage(); + } + if (!pflag || !*pflag) { ar++; pflag = 0; } + if (used_arg && inc_ar) ar++; + if (used_arg && inc_ar==2) + fatal("Last option requires an argument"); + } + + if (control_count>1) + fatal("only one option from -E -P -S -c allowed"); + if (exe_count>1) + fatal("only one -o option allowed"); + + if (file_count==0) Usage(); + + if (exe_count && file_count != 1 && !do_link) + fatal("only one input file for each non-linked output"); + + add_prefix(getenv("BCC_EXEC_PREFIX")); + +#ifdef MC6809 + if (opt_M==0) opt_M = '9'; +#endif +#ifdef CCC + if (opt_M==0) opt_M = '8'; #endif - unprotoargs.prog=fixpath(unprotoargs.prog, &exec_prefix, X_OK); - optargs.prog = fixpath(optargs.prog, &exec_prefix, X_OK); - if (tmpdir == NUL_PTR && (tmpdir = getenv("TMPDIR")) == NUL_PTR) #ifdef MSDOS - tmpdir = "."; -#else - tmpdir = "/tmp"; + if (opt_M==0) opt_M = 'd'; #endif - - if (prep_only && !prep_line_numbers) - addarg(&cppargs, "-P"); -#ifdef BCC86 -#ifdef STANDARD_CRT0_3_PREFIX - if (bits32) - bits_arg = "-3"; - else +#ifdef __CYGWIN__ + if (opt_M==0) opt_M = 'd'; #endif - bits_arg = "-0"; - addarg(&ccargs, bits_arg); - addarg(&cppargs, bits_arg); - addarg(&asargs, bits_arg); -#ifdef BAS86 - if (!gnu_objects) - { - addarg(&ldargs, bits_arg); - addarg(&ldrargs, bits_arg); - if( has_crt0 ) - addarg(&ldargs, "-C0"); - } -#endif /* BAS86 */ -#endif /* BCC86 */ - set_trap(); + if (opt_M==0) opt_M = (opt_arch==1 ?'l':'n'); + switch(opt_M) + { + case 'n': /* Normal Elks */ + prepend_option("-D__unix__", 'p'); + prepend_option("-D__ELKS__", 'p'); + libc="-lc"; + break; + case 'f': /* Fast Call Elks */ + prepend_option("-D__unix__", 'p'); + prepend_option("-D__ELKS__", 'p'); + append_option("-c", 'C'); + append_option("-f", 'C'); + libc="-lc_f"; + break; + case 'c': /* Caller saves Elks */ + prepend_option("-D__unix__", 'p'); + prepend_option("-D__ELKS__", 'p'); + append_option("-c", 'C'); + libc="-lc"; + break; + case 's': /* Standalone 8086 */ + prepend_option("-D__STANDALONE__", 'p'); + libc="-lc_s"; + break; + case 'd': /* DOS COM file */ + prepend_option("-D__MSDOS__", 'p'); + if (do_link) { + libc="-ldos"; + append_option("-d", 'l'); + append_option("-T100", 'l'); + } + break; + case 'l': /* 386 Linux a.out */ + opt_arch=1; + prepend_option("-D__unix__", 'p'); + prepend_option("-D__linux__", 'p'); + if (do_link) { + libc="-lc"; + append_option("-N", 'l'); + } + break; + case 'g': /* 386 Linux object using gcc as linker */ + opt_arch = 2; + prepend_option("-D__unix__", 'p'); + prepend_option("-D__linux__", 'p'); - /* Pass 2 over argv to compile and assemble .c, .i, .S and .s files and - * gather arguments for linker. - */ - for (argv -= (argc = argcount) - 1, argdone -= argcount - 1; --argc != 0;) - { - arg = *++argv; - if (!*++argdone) - { - length = strlen(arg); - if (length >= 2 && arg[length - 2] == '.' - && ((ext = arg[length - 1]) == 'c' || ext == 'i' || ext == 'S' - || ext == 's')) - { - if (echo || verbosity != 0) - { - writes(arg); - writesn(":"); - } - if ((basename = strrchr(arg, DIRCHAR)) == NUL_PTR) - basename = arg; - else - ++basename; - in_name = arg; - if (ext == 'c') - { - if (cpp_pass) - { - if (prep_only && !ansi_pass) - out_name = f_out; - else - out_name = my_mktemp(); - if (run(in_name, out_name, &cppargs) != 0) - continue; - in_name = out_name; - if (ansi_pass) - { - if (prep_only) - out_name = f_out; - else - out_name = my_mktemp(); + /* This is a more traditional libc, it also gives a 20k executable + * for hello world vs. 400k with glibc2 and --static. + * NB: DLL libc no longer seems to work. + */ + add_prefix("/usr/bin/i386-uclibc-"); + break; + case '8': /* Use 'c386' program as compiler */ + opt_arch = 3; + prepend_option("-D__unix__", 'p'); + prepend_option("-D__c386__", 'p'); + break; + case '9': /* 6809 compiler */ + opt_arch = 4; + prepend_option("-D__6809__", 'p'); + break; + case '0': /* Plain old Unix V7 style */ + opt_arch = 5; + opt_I = 1; + opt_L = 1; + opt_x = 1; + append_option("/lib/crt0.o", 'l'); + break; + default: + fatal("Unknown model specifier for -M valid are: n,f,c,s,d,l,g,8,9,0"); + } - if (run(in_name, out_name, &unprotoargs) != 0) - continue; - in_name=out_name; - } - } - ext = 'i'; - } - if (ext == 'i') - { - if (prep_only) - continue; - if (cc_only && !optimize) - { - if (f_out != NUL_PTR) - out_name = f_out; - else - { - out_name = stralloc(basename); - out_name[strlen(out_name) - 1] = 's'; - } - } - else - out_name = my_mktemp(); - if (run(in_name, out_name, &ccargs) != 0) - continue; - in_name = out_name; - if( optimize ) - { - if (cc_only) - { - if (f_out != NUL_PTR) - out_name = f_out; - else - { - out_name = stralloc(basename); - out_name[strlen(out_name) - 1] = 's'; - } - } - else - out_name = my_mktemp(); + if (do_optim) + { + append_option("-O", 'C'); + append_option("-O", 'a'); + } - if (run(in_name, out_name, &optargs) != 0) - continue; - in_name = out_name; - } - ext = 's'; - } - if (ext == 'S') - { - if (prep_only) - out_name = f_out; - else if (cc_only) - { - if (f_out != NUL_PTR) - out_name = f_out; - else - { - out_name = stralloc(basename); - out_name[strlen(out_name) - 1] = 's'; - } - } - else - out_name = my_mktemp(); - if (run(in_name, out_name, &cppargs) != 0) - continue; - in_name = out_name; - ext = 's'; - } - if (ext == 's') - { - if (prep_only || cc_only) - continue; - out_name = stralloc(basename); - out_name[strlen(out_name) - 1] = 'o'; - if (as_only) - { - if (f_out != NUL_PTR) - out_name = f_out; - else - { - out_name = stralloc(basename); - out_name[strlen(out_name) - 1] = 'o'; - } - } - else - out_name = my_mktemp(); - addarg(&asargs, "-n"); - arg[length - 1] = 's'; - addarg(&asargs, arg); -#ifdef BAS86 - if (gnu_objects) - { - char *tmp_out_name; + if (opt_arch == 0) { + if (opt_f) { + /* append_option("--enable-floats", 'c'); */ + libc = catstr(libc, "+f"); + } else + append_option("-D__HAS_NO_FLOATS__", 'p'); + } - tmp_out_name = my_mktemp(); - status = run(in_name, tmp_out_name, &asargs); - asargs.argc -= 2; - if (status != 0) - continue; - if (run(tmp_out_name, out_name, &ldrargs) != 0) - continue; - } - else + if (opt_arch == 1) libdir_suffix = "/i386"; + if (opt_arch == 4) libdir_suffix = "/m09"; + +#ifdef VERSION + { + char verbuf[64]; + sprintf(verbuf, "-D__BCC_VERSION__=0x%02x%02x%02xL", + VER_MAJ, VER_MIN, VER_PAT); + append_option(verbuf, 'p'); + } #endif - { - status = run(in_name, out_name, &asargs); - asargs.argc -= 2; - if (status != 0) - continue; - } - ext = 'o'; - in_name = out_name; - } - if (ext == 'o') - { - if (prep_only || cc_only || as_only) - continue; - addarg(&ldargs, in_name); - } - } - else - addarg(&ldargs, arg); - } - } +} - if (!prep_only && !cc_only && !as_only && !runerror) - { - int link_st; +void +build_prefix(path1, path2, path3) +char * path1, * path2, * path3; +{ + char * newstr; + int l; + newstr = xalloc(strlen(path1)+strlen(path2)+strlen(path3) + + strlen(prefix_path)+2); - if (f_out == NUL_PTR) - f_out = "a.out"; -#ifdef BAS86 - if (gnu_objects) - { - /* Remove -i and -i-. */ - for (argc = ldargs.argc - 1; argc >= START_ARGS; --argc) - { - arg = ldargs.argv[argc]; - if (arg[0] == '-' && arg[1] == 'i' - && (arg[2] == 0 || (arg[2] == '-' && arg[3] == 0))) - { - --ldargs.argc; - memmove(ldargs.argv + argc, ldargs.argv + argc + 1, - (ldargs.argc - argc) * sizeof ldargs.argv[0]); - ldargs.argv[ldargs.argc] = NUL_PTR; - } - } + strcpy(newstr, prefix_path); + strcat(newstr, path1); + strcat(newstr, path2); + strcat(newstr, path3); + l = strlen(newstr); + if (l>1 && newstr[l-1] != '/') + strcat(newstr, "/"); - ldargs.prog = fixpath(GCC, &exec_prefix, X_OK); - link_st = run((char *) NUL_PTR, f_out, &ldargs); - } - else -#endif - { - addarg(&ldargs, libc); - link_st = run((char *) NUL_PTR, f_out, &ldargs); - } - if( patch_exe && link_st == 0 ) - linux_patch(f_out); - } - if( runerror && f_out != NUL_PTR ) - my_unlink(f_out); - killtemps(); - return runerror ? 1 : 0; + add_prefix(newstr); } -PRIVATE void linux_patch(fname) -char * fname; +void +add_prefix(path) +char * path; { -/* OMAGIC */ - -#define AOUT_MAG "\x07\x01\x64\x00" /* 0x640107L */ -#define ELKS_MAG1 0x10 -#define ELKS_MAG2 0x11 /* -z */ -#define ELKS_MAG3 0x20 /* -i */ -#define ELKS_MAG4 0x21 /* -i -z */ + char ** p; + if (!path || !*path) return; -static struct ELKS_exec { /* ELKS a.out header */ - char a_magic1; /* magic number */ - char a_magic2; /* magic number */ - char a_magic3; /* magic number */ - char a_magic4; /* magic number */ - char a_hdrlen; /* length, etc of header */ - char a_hdrlen3[3]; - long a_text; /* size of text segement in bytes */ - long a_data; /* size of data segment in bytes */ - long a_bss; /* size of bss segment in bytes */ - long a_entry; /* entry point */ - long a_total; /* total memory allocated */ - long a_syms; /* size of symbol table */ -} instr; + for( p=exec_prefixs; + pfile = copystr(filename); + name = copystr(filename); - fd = open(fname, O_RDWR); - if( fd<0 ) return; + s = strrchr(name, '.'); - if( read(fd, &instr, sizeof(instr)) != sizeof(instr) ) + if (ftype) { - writesn("Cannot re-read executable header"); - return; + newfile->name = copystr(name); + newfile->filetype = ftype; + } + else if (s && s == name + strlen(name) - 2) { + newfile->filetype = s[1]; + *s = 0; + newfile->name = copystr(name); } + else + newfile->name = copystr(name); + free(name); - if( instr.a_hdrlen != 0x20 || instr.a_magic1 != 0x01 || - instr.a_magic2 != 0x03 || instr.a_magic4 != 0x10 ) + if (newfile->filetype == 0) newfile->filetype = 'o'; /* Objects */ + + if (files==0) + files = newfile; + else { - writesn("Executable cannot be converted to OMAGIC - bad magics"); - return; + struct file_list * fptr; + for(fptr=files; fptr->next; fptr=fptr->next); + fptr->next = newfile; } +} - switch((int)(instr.a_magic3)) +void +append_option (option, otype) +char * option; +int otype; +{ + struct opt_list * newopt = xalloc(sizeof(struct opt_list)); + + newopt->opt = copystr(option); + newopt->opttype = otype; + + if (options==0) + options = newopt; + else { - case ELKS_MAG1: - break; - case ELKS_MAG2: - writesn("Executable cannot be converted to OMAGIC (compiled with -z)"); - return; - case ELKS_MAG3: - case ELKS_MAG4: - writesn("Executable file is split I/D, data overlaps text"); - return; - default: - writesn("Executable cannot be converted to OMAGIC (unknown type)"); - return; + struct opt_list * optr; + for(optr=options; optr->next; optr=optr->next); + optr->next = newopt; } +} - if( instr.a_syms != 0 ) - writesn("Warning: executable file isn't stripped"); +void +prepend_option (option, otype) +char * option; +int otype; +{ + struct opt_list * newopt = xalloc(sizeof(struct opt_list)); - memcpy(outstr.a_info, AOUT_MAG, 4); - outstr.a_text = instr.a_text; - outstr.a_data = instr.a_data; - outstr.a_bss = instr.a_bss; - outstr.a_entry= instr.a_entry; + newopt->opt = copystr(option); + newopt->opttype = otype; - lseek(fd, 0L, 0); + newopt->next = options; + options = newopt; +} - if( write(fd, &outstr, sizeof(outstr)) != sizeof(outstr) ) - { - writesn("Cannot re-write executable header"); - return; - } +char * build_libpath(opt, str, suffix) +char * opt, * str, * suffix; +{ + char * newstr; + newstr = xalloc(strlen(opt)+strlen(str)+strlen(prefix_path)+strlen(suffix)+1); + strcpy(newstr, opt); + strcat(newstr, prefix_path); + strcat(newstr, str); + strcat(newstr, suffix); + return newstr; +} - close(fd); +void * +xalloc (size) +int size; +{ + void * p = malloc(size); + if (!p) fatal("Out of memory"); + memset(p, '\0', size); + return p; +} + +void Usage() +{ +#ifdef VERSION +#ifdef __AS386_16__ + if (opt_v) + fprintf(stderr, "%s: version %s (16bit)\n", progname, VERSION); +#else + if (opt_v) + fprintf(stderr, "%s: version %s\n", progname, VERSION); +#endif +#endif + fprintf(stderr, + "Usage: %s [-ansi] [-options] [-o output] file [files].\n", progname); + exit(1); +} + +void fatal(str) +char * str; +{ + fprintf(stderr, "%s: Fatal error: %s.\n", progname, str); + exit(1); } -#ifdef L_TREE #ifdef MSDOS -PRIVATE void reset_localprefix() +void reset_prefix_path() { char *ptr, *temp; - temp = stralloc(progname); + if (*localprefix && localprefix[1]) { + prefix_path = localprefix; + return; + } + + temp = copystr(progname); if( (ptr = strrchr(temp, '\\')) != 0 && temp 2) - { - show_who("localprefix is now "); - writesn(localprefix); - } + prefix_path = temp; } else free(temp); } #else -PRIVATE void reset_localprefix() +void reset_prefix_path() { char *ptr, *temp; + if (*localprefix && localprefix[1]) { + prefix_path = localprefix; + return; + } + + if ( *localprefix == '/' && !localprefix[1]) { + prefix_path = ""; + return; + } + if( *progname == '/' ) - temp = stralloc(progname); + temp = copystr(progname); else { char * s, * d; ptr = getenv("PATH"); if( ptr==0 || *ptr == 0 ) return; - ptr = stralloc(ptr); - temp = stralloc(""); + ptr = copystr(ptr); + temp = copystr(""); for(d=s=ptr; d && *s; s=d) { @@ -970,22 +1317,24 @@ free(temp); d=strchr(s, ':'); if( d ) *d='\0'; - temp = my_malloc(strlen(progname)+strlen(s)+2, "prefixing"); + temp = xalloc(strlen(progname)+strlen(s)+2); strcpy(temp, s); strcat(temp, "/"); strcat(temp, progname); +#ifndef __BCC__ if( realpath(temp, buf) != 0 ) { free(temp); - temp = stralloc(buf); + temp = copystr(buf); } +#endif if( access(temp, X_OK) == 0 ) break; d++; } if( s == 0 ) { free(temp); - temp = stralloc(progname); + temp = copystr(progname); } free(ptr); } @@ -994,368 +1343,89 @@ && temp 2) - { - show_who("localprefix is now "); - writesn(localprefix); - } + prefix_path = temp; } else free(temp); } #endif -#endif - -PRIVATE char * expand_tilde(str, canfree) -char * str; -int canfree; -{ - char * newstr; - char * ptr = strchr(str, '~'); - if( ptr == 0 ) return str; - newstr = my_malloc(strlen(str)+strlen(localprefix), "expand tilde"); - if( ptr!=str ) memcpy(newstr, str, ptr-str); - strcpy(newstr+(ptr-str), localprefix); - strcat(newstr, ptr+1); - if( canfree ) free(str); - return newstr; -} - -PRIVATE void adddefine(arg) -char *arg; +void +run_command(file) +struct file_list * file; { -#ifndef CCC - addarg(&ccargs, arg); +#ifdef __BCC__ +static char ** minienviron[] = { + "PATH=/bin:/usr/bin", + "SHELL=/bin/sh", + 0 +}; +#endif + int i, status; +#ifndef MSDOS + void *oqsig, *oisig, *otsig, *ocsig; #endif - addarg(&cppargs, arg); -} - -PRIVATE void addarg(argp, arg) -register struct arg_s *argp; -char *arg; -{ - int new_argc; - char **new_argv; - - if (argp->nr_allocated == 0) - startarg(argp); - new_argc = argp->argc + 1; - if (new_argc >= argp->nr_allocated) - { - argp->nr_allocated += ALLOC_UNIT; - new_argv = realloc(argp->argv, argp->nr_allocated * sizeof *argp->argv); - if (new_argv == NUL_PTR) - outofmemory("addarg"); - argp->argv = new_argv; - } - argp->argv[argp->argc] = expand_tilde(arg, 0); - argp->argv[argp->argc = new_argc] = NUL_PTR; -} - -PRIVATE void addprefix(prefix, name) -struct prefix_s *prefix; -char *name; -{ - struct prefix_s *new_prefix; - - if (prefix->name == NUL_PTR) - prefix->name = name; - else - { - new_prefix = my_malloc(sizeof *new_prefix, "addprefix"); - new_prefix->name = expand_tilde(name, 0); - new_prefix->next = NUL_PTR; - while (prefix->next != NUL_PTR) - prefix = prefix->next; - prefix->next = new_prefix; - } -} - -PRIVATE void fatal(message) -char *message; -{ - writesn(message); - killtemps(); - exit(1); -} - -PRIVATE char *fixpath(path, prefix, mode) -char *path; -struct prefix_s *prefix; -int mode; -{ - char *ppath; - - for (; prefix != NUL_PTR; prefix = prefix->next) - { - if (verbosity > 2) - { - show_who("searching for "); - if (mode == R_OK) - writes("readable file "); - else - writes("executable file "); - } - ppath = expand_tilde(stralloc2(prefix->name, path), 1); - if (verbosity > 2) - writes(ppath); - if (access(ppath, mode) == 0) - { - if (verbosity > 2) - writesn(" - found."); - return ppath; - } - if (verbosity > 2) - writesn(" - nope."); - free(ppath); - } - return path; -} - -PRIVATE void killtemps() -{ - while (tmpargs.argc > START_ARGS) - my_unlink(tmpargs.argv[--tmpargs.argc]); -} - -PRIVATE void *my_malloc(size, where) -unsigned size; -char *where; -{ - void *block; - if ((block = malloc(size)) == NUL_PTR) - outofmemory(where); - return block; -} -PRIVATE char *my_mktemp() -{ - char *p; - unsigned digit; - unsigned digits; - char *template; - static unsigned tmpnum; + if (opt_v) + { + fprintf(stderr, "%s", command.fullpath); + for(i=1; command.arglist[i]; i++) + fprintf(stderr, " %s", command.arglist[i]); + fprintf(stderr, "\n"); + if (opt_v>2) return; + } #ifdef MSDOS - digits = 42; - p = template = stralloc2(tmpdir, "/$$YYYYXX"); + status = spawnv(0, command.fullpath, command.arglist); + if (status<0) + { + fprintf(stderr, "Unable to execute %s\n", command.fullpath); + } #else - digits = getpid(); - p = template = stralloc2(tmpdir, "/bccYYYYXXXX"); -#endif - p += strlen(p); - - while (*--p == 'X') - { - if ((digit = digits % 16) > 9) - digit += 'A' - ('9' + 1); - *p = digit + '0'; - digits /= 16; - } - digits = tmpnum; - while (*p == 'Y') - { - if ((digit = digits % 16) > 9) - digit += 'A' - ('9' + 1); - *p-- = digit + '0'; - digits /= 16; - } - ++tmpnum; - addarg(&tmpargs, template); - return template; -} - -PRIVATE void my_unlink(name) -char *name; -{ - if (verbosity > 1) - { - show_who("unlinking "); - writesn(name); - } - if (verbosity > 4) return; - if (unlink(name) < 0) - { - if( !runerror || verbosity > 1) - { - show_who("error unlinking "); - writesn(name); - runerror = TRUE; - } - } -} - -PRIVATE void outofmemory(where) -char *where; -{ - show_who("out of memory in "); - fatal(where); -} + oqsig = signal(SIGQUIT, SIG_IGN); + oisig = signal(SIGINT, SIG_IGN); + otsig = signal(SIGTERM, SIG_IGN); + ocsig = signal(SIGCHLD, SIG_DFL); -PRIVATE int run(in_name, out_name, argp) -char *in_name; -char *out_name; -struct arg_s *argp; -{ - int arg0; - int i; - int status; + switch(fork()) + { + case -1: + fatal("Forking failure"); + case 0: + (void) signal(SIGQUIT, SIG_DFL); + (void) signal(SIGINT, SIG_DFL); + (void) signal(SIGTERM, SIG_DFL); + (void) signal(SIGCHLD, SIG_DFL); - arg0 = 0; - if (in_name == NUL_PTR) - ++arg0; - if (out_name == NUL_PTR) - arg0 += 2; - else if (argp->minus_O_broken) - ++arg0; - if (argp->nr_allocated == 0) - startarg(argp); - argp->argv[arg0] = argp->prog; - i = arg0 + 1; - if (in_name != NUL_PTR) - argp->argv[i++] = in_name; - if (out_name != NUL_PTR) - { - if (!argp->minus_O_broken) - argp->argv[i++] = "-o"; - argp->argv[i++] = out_name; - } - if (verbosity != 0) - { - for (i = arg0; i < argp->argc; ++i) - { - writes(argp->argv[i]); - writes(" "); - } - writen(); - } - if (verbosity > 4 ) return 0; -#ifdef MSDOS - status = spawnv(0, argp->prog, argp->argv+arg0); - if( status<0 ) - { - show_who("spawn of "); - writes(argp->prog); - writesn(" failed"); - } -#else - switch (fork()) - { - case -1: - show_who("fork failed"); - fatal(""); - case 0: #ifdef __BCC__ - execve(argp->prog, argp->argv + arg0, minienviron); + execve(command.fullpath, command.arglist, minienviron); #else - execv(argp->prog, argp->argv + arg0); -#endif - show_who("exec of "); - writes(argp->prog); - fatal(" failed"); - default: - wait(&status); - if (status & 0xFF) - { - writes(argp->prog); - writesn(": killed by fatal signal"); - } - } -#endif - for (i = tmpargs.argc - 1; i >= START_ARGS; --i) - if (in_name == tmpargs.argv[i]) - { - my_unlink(in_name); - --tmpargs.argc; - memmove(tmpargs.argv + i, tmpargs.argv + i + 1, - (tmpargs.argc - i) * sizeof tmpargs.argv[0]); - tmpargs.argv[tmpargs.argc] = NUL_PTR; - break; - } - if (status != 0) - { - runerror = TRUE; - killtemps(); - } - return status; -} - -PRIVATE void set_trap() -{ -#ifdef SIGINT - signal(SIGINT, trap); -#endif -#ifdef SIGQUIT - signal(SIGQUIT, trap); -#endif -#ifdef SIGTERM - signal(SIGTERM, trap); + if (command.fullpath[0] =='/') + execv(command.fullpath, command.arglist); + else + execvp(command.fullpath, command.arglist); #endif -} + fprintf(stderr, "Unable to execute %s.\n", command.fullpath); + exit(1); + default: + wait(&status); + if (status&0xFF) + { + fprintf(stderr, "%s: killed by signal %d\n", + command.fullpath, (status&0xFF)); + } + } -PRIVATE void show_who(message) -char *message; -{ -#ifdef MSDOS - char * ptr; - ptr = strrchr(progname, '\\'); - if(ptr) ptr++; else ptr = progname; - writes(ptr); -#else - writes(progname); + (void) signal(SIGQUIT, oqsig); + (void) signal(SIGINT, oisig); + (void) signal(SIGTERM, otsig); + (void) signal(SIGCHLD, ocsig); #endif - writes(": "); - writes(message); -} - -PRIVATE void startarg(argp) -struct arg_s *argp; -{ - argp->argv = my_malloc((argp->nr_allocated = ALLOC_UNIT) - * sizeof *argp->argv, "startarg"); - argp->argc = START_ARGS; - argp->argv[START_ARGS] = NUL_PTR; -} - -PRIVATE char *stralloc(s) -char *s; -{ - return strcpy(my_malloc(strlen(s) + 1, "stralloc"), s); -} - -PRIVATE char *stralloc2(s1, s2) -char *s1; -char *s2; -{ - return strcat(strcpy(my_malloc( - strlen(s1) + strlen(s2) + 1, "stralloc2"), s1), s2); -} - -PRIVATE void trap(signum) -int signum; -{ - signal(signum, SIG_IGN); - show_who("caught signal"); - fatal(""); -} - -PRIVATE void writen() -{ - writes("\n"); -} - -PRIVATE void writes(s) -char *s; -{ - write(2, s, strlen(s)); + if (status) + { + if (file) file->filetype = '~'; + error_count++; + } } -PRIVATE void writesn(s) -char *s; -{ - writes(s); - writen(); -} diff -Nurd linux86.vold/bcc/bcc-cc1.c linux86/bcc/bcc-cc1.c --- linux86.vold/bcc/bcc-cc1.c 1998-02-06 18:43:15.000000000 +0000 +++ linux86/bcc/bcc-cc1.c 2004-06-20 13:57:34.000000000 +0100 @@ -8,11 +8,14 @@ int argc; char **argv; { + debug(1, "Start"); growheap(0); /* init order is important */ syminit(); etreeinit(); +#ifdef BUILTIN_CPP ifinit(); predefine(); +#endif openio(argc, argv); codeinit(); typeinit(); diff -Nurd linux86.vold/bcc/bcc.doc linux86/bcc/bcc.doc --- linux86.vold/bcc/bcc.doc 1996-09-03 20:05:03.000000000 +0100 +++ linux86/bcc/bcc.doc 2004-01-18 13:14:05.000000000 +0000 @@ -1,3 +1,5 @@ +WARNING: This document bis out of date; it's kept mainly for the 6809 notes. + bcc options ----------- @@ -15,7 +17,7 @@ somewhere/file.[cis] -> file.o for assembler output a.out for ld output --ansi Pass the source through '/usr/bin/unprotoize' first +-ansi Pass the source through 'unproto' first -0 8086 target (works even on 80386 host) -3 80386 target (works even on 8086 host) -A pass remainder of option to assembler (e.g. -A-l -Alistfile for a listing) diff -Nurd linux86.vold/bcc/codefrag.c linux86/bcc/codefrag.c --- linux86.vold/bcc/codefrag.c 1999-07-24 14:32:11.000000000 +0100 +++ linux86/bcc/codefrag.c 2004-06-03 08:25:10.000000000 +0100 @@ -350,6 +350,7 @@ if (i386_32) { outmovsx(); + outaccum(); outncregname(BREG); } else @@ -374,6 +375,7 @@ outhiaccum(); outncregname(BREG); } +#ifdef I80386 PUBLIC void ustoi() { outmovzx(); @@ -382,6 +384,7 @@ outshortregname(DREG); outnl(); } +#endif /* I80386 */ #endif /* I8088 */ #ifdef MC6809 @@ -1616,7 +1619,41 @@ outstr(name); outset(); outshex(value); +#ifdef FRAMEPOINTER +#ifdef I8088 +#ifndef NO_DEL_PUSH + if (framep && optimise && !callersaves && value+sp-framep >= 0 + && !(regfuse & callee1mask)) { + outbyte('-'); + outstr(funcname); + outstr(".off"); + } +#endif +#endif +#endif outnl(); +#ifdef FRAMEPOINTER + if (framep) + { + outbyte(LOCALSTARTCHAR); + outstr(funcname); + outbyte(LOCALSTARTCHAR); + outstr(name); + outset(); + outshex(value+sp-framep); +#ifdef I8088 +#ifndef NO_DEL_PUSH + if (optimise && !callersaves && value+sp-framep < 0 + && !(regfuse & callee1mask)) { + outbyte('+'); + outstr(funcname); + outstr(".off"); + } +#endif +#endif + outnl(); + } +#endif } /* shift left register by 1 */ diff -Nurd linux86.vold/bcc/const.h linux86/bcc/const.h --- linux86.vold/bcc/const.h 1998-09-29 13:29:15.000000000 +0100 +++ linux86/bcc/const.h 2004-06-20 20:49:37.000000000 +0100 @@ -8,6 +8,8 @@ #include #endif +#include "debug.h" + /* switches for code generation */ #if !defined(I8088) && !defined(MC6809) @@ -21,10 +23,14 @@ #define VERY_SMALL_MEMORY #endif +#ifndef VERY_SMALL_MEMORY #define SELFTYPECHECK /* check calculated type = runtime type */ +#define DBNODE /* generate compiler node debugging code */ +#define OPTIMISE /* include optimisation code */ +#endif -#ifndef VERY_SMALL_MEMORY -#define DEBUG /* generate compiler-debugging code */ +#ifndef __BCC__ +#define BUILTIN_CPP /* Remove the built in C preprocessor */ #endif #ifdef I8088 @@ -33,20 +39,21 @@ * since assembler has only 1 data seg */ # define DYNAMIC_LONG_ORDER 1 /* long word order spec. at compile time */ -#ifdef VERY_SMALL_MEMORY - +#ifdef __HAS_NO_FLOATS__ /* Humm, now this is nasty :-) */ #define float no_hope #define double no_hope #define atof atol #define NOFLOAT typedef long no_hope; +#endif -#else +#ifndef VERY_SMALL_MEMORY #ifndef NO_I80386 # define I80386 /* Little BCC doesn't need 386 */ #endif #endif + #endif #ifdef MC6809 @@ -84,3 +91,6 @@ #define FORWARD static #define PRIVATE static #define PUBLIC + +/* #define C_CODE * Don't use assembler outstr() function. */ + diff -Nurd linux86.vold/bcc/dbnode.c linux86/bcc/dbnode.c --- linux86.vold/bcc/dbnode.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/bcc/dbnode.c 2004-06-20 13:25:03.000000000 +0100 @@ -0,0 +1,200 @@ +/* dbnode.c - print debug messages for operators for bcc */ + +/* Copyright (C) 1992 Bruce Evans */ + +#include "bcc.h" + +#ifdef DBNODE +#include "gencode.h" +#include "reg.h" +#include "sc.h" +#include "scan.h" +#include "type.h" + +PRIVATE char *opname[LASTOP - FIRSTOP + 1] = /* operator names */ +{ /* order must agree with op.h */ + "cond?", + "or", + "eor", + "and", + "gt", "lt", + "add", + "div", "mod", + "lognot", "not", + "strucelt", "strucptr", + "eq", + "addab", "andab", "divab", "eorab", "modab", "mulab", "orab", + "slab", "srab", "subab", + "comma", + "cond:", + "logor", + "logand", + "logeq", + "ne", + "ge", "le", + "sl", "sr", + "sub", + "mul", + "address", "cast", "indirect", "neg", + "predec", "preinc", "postdec", "postinc", + "func", "list", "rootlist", + "leaf", + "ptraddab", "ptradd", "ptrsub", +}; + +FORWARD void outindchars P((int byte, indn_pt count)); + +PUBLIC void dbitem(item) +struct symstruct *item; +{ + dbtype(item->type); + if (item->storage == NOSTORAGE) + { + outbyte(' '); + outstr(item->name.namep + 2); + outstr(" (offset "); + outshex(item->offset.offi); + outbyte(')'); + return; + } + if (item->storage == LOCAL) + { + outbyte(' '); + if (item->flags == TEMP) + outstr("(temp)"); + else + outstr(item->name.namep); + } + outstr(" = "); + outindchars('[', item->indcount); + switch (item->storage) + { + case CONSTANT: + outstr("const "); + if (item->type->scalar & RSCALAR) + outstr("(whatever)"); + else if (item->type->scalar & UNSIGNED) + outuvalue((uvalue_t) item->offset.offv); + else + outvalue(item->offset.offv); + break; + case BREG: + case DREG: + case INDREG0: + case INDREG1: + case INDREG2: +#ifdef DATREG1 + case DATREG1: +#endif +#ifdef DATREG2 + case DATREG2: +#endif + outregname(item->storage); + if (item->level == OFFKLUDGELEVEL) + { + outplus(); + if (item->flags & LABELLED) + outlabel(item->name.label); + else + outccname(item->name.namep); + } + break; + case LOCAL: + outbyte('S'); + if (sp <= 0) + outplus(); + outshex(-sp); + break; + case GLOBAL: + if (item->flags & LABELLED) + outlabel(item->name.label); + else + outstr(item->name.namep); + break; + default: + outstr("bad storage ("); + outhex((uoffset_T) item->storage); + outbyte(')'); + outstr(" offset "); + } + if (item->storage != CONSTANT) + { + if (item->offset.offi >= 0) + outplus(); + outshex(item->offset.offi); + } + outindchars(']', item->indcount); +} + +PUBLIC void dbtype(type) +struct typestruct *type; +{ + for ( ; type != NULL; type = type->nexttype) + { + outbyte(' '); + switch (type->constructor) + { + case ARRAY: + outbyte('['); + outhex(type->typesize / type->nexttype->typesize); + outbyte(']'); + break; + case FUNCTION: + outstr("()"); + break; + case POINTER: + outbyte('*'); + break; + case STRUCTU: + outstr("struct "); + default: + if (type->scalar & UNSIGNED) + outstr("unsigned "); + outstr(type->tname); + break; + } + } +} + +PUBLIC void dbnode(exp) /* sub-nodes must be leaves */ +struct nodestruct *exp; +{ + if (!dbnodeon) + return; + outstr("! Debug: "); + if (exp->tag < FIRSTOP && exp->tag > LASTOP) + outstr("unknown op"); + else + outstr(opname[exp->tag - FIRSTOP]); + if (exp->right != NULL && exp->tag != FUNCOP && + exp->tag != LISTOP && exp->tag != ROOTLISTOP) + { + dbitem(exp->right->left.symptr); + outstr(" to"); + } + dbitem(exp->left.nodeptr->left.symptr); + outstr(" (used reg = "); + if (reguse & INDREG0) + outregname(INDREG0); + if (reguse & INDREG1) + outregname(INDREG1); + if (reguse & INDREG2) + outregname(INDREG2); + outnstr(")"); +} + +PUBLIC void dbnodeswap() +{ + if (dbnodeon) + outnstr("! Debug: expression subtree swapping"); +} + +PRIVATE void outindchars(byte, count) +int byte; +indn_pt count; +{ + while (count--) + outbyte(byte); +} + +#endif /* DBNODE */ diff -Nurd linux86.vold/bcc/dbprintf.c linux86/bcc/dbprintf.c --- linux86.vold/bcc/dbprintf.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/bcc/dbprintf.c 2004-06-20 18:14:58.000000000 +0100 @@ -0,0 +1,257 @@ + +#include +#include + +#if defined(__STDC__) && !defined(__FIRST_ARG_IN_AX__) +#include +#define va_strt va_start +#else +#include +#define va_strt(p,i) va_start(p) +#endif + +#if defined(__STDC__) && !defined(__FIRST_ARG_IN_AX__) +int dbprintf(const char * fmt, ...) +#else +int dbprintf(fmt, va_alist) +__const char *fmt; +va_dcl +#endif +{ + va_list ptr; + int rv; + va_strt(ptr, fmt); + rv = vdbprintf(fmt,ptr); + va_end(ptr); + return rv; +} + +static unsigned char * __numout (long i, int base); +static void putch(int ch) { static char buf[2]; *buf = ch; write(2,buf,1); } + +int +vdbprintf(fmt, ap) +register __const char *fmt; +register va_list ap; +{ + int c; + int count = 0; + int type, base; + long val; + char * cp; + char padch=' '; + int minsize, maxsize; + + while(c=*fmt++) + { + count++; + if(c!='%') + putch(c); + else + { + type=1; + padch = *fmt; + maxsize=minsize=0; + if(padch == '-') fmt++; + + for(;;) + { + c=*fmt++; + if( c<'0' || c>'9' ) break; + minsize*=10; minsize+=c-'0'; + } + + if( c == '.' ) + for(;;) + { + c=*fmt++; + if( c<'0' || c>'9' ) break; + maxsize*=10; maxsize+=c-'0'; + } + + if( padch == '-' ) minsize = -minsize; + else + if( padch != '0' ) padch=' '; + + if( c == 0 ) break; + if(c=='h') + { + c=*fmt++; + type = 0; + } + else if(c=='l') + { + c=*fmt++; + type = 2; + } + + switch(c) + { + case 'x': base=16; type |= 4; if(0) { + case 'o': base= 8; type |= 4; } if(0) { + case 'u': base=10; type |= 4; } if(0) { + case 'd': base=-10; } + switch(type) + { + case 0: /* Promoted: val=va_arg(ap, short); break; */ + case 1: val=va_arg(ap, int); break; + case 2: val=va_arg(ap, long); break; + case 4: /* Promoted: val=va_arg(ap, unsigned short); break; */ + case 5: val=va_arg(ap, unsigned int); break; + case 6: val=va_arg(ap, unsigned long); break; + default:val=0; break; + } + cp = __numout(val,base); + if(0) { + case 's': + cp=va_arg(ap, char *); + } + count--; + c = strlen(cp); + if( !maxsize ) maxsize = c; + if( minsize > 0 ) + { + minsize -= c; + while(minsize>0) { putch(padch); count++; minsize--; } + minsize=0; + } + if( minsize < 0 ) minsize= -minsize-c; + while(*cp && maxsize-->0 ) + { + putch(*cp++); + count++; + } + while(minsize>0) { putch(' '); count++; minsize--; } + break; + case 'c': + putch(va_arg(ap, int)); + break; + case 'C': + c = va_arg(ap, int); + if (c>0x7F) { + c &=0x7F; + putch('M'); putch('-'); + } + if (c<' ' || c == '\177') { + putch('^'); putch(c^'@'); + } else + putch(c); + break; + default: + putch(c); + break; + } + } + } + return count; +} + +static char nstring[]="0123456789ABCDEF"; + +#ifndef __AS386_16__ +#define NUMLTH 11 + +static unsigned char * +__numout(long i, int base) +{ + static unsigned char out[NUMLTH+1]; + int n; + int flg = 0; + unsigned long val; + + if (base<0) + { + base = -base; + if (i<0) + { + flg = 1; + i = -i; + } + } + val = i; + + out[NUMLTH] = '\0'; + n = NUMLTH-1; + do + { + out[n--] = nstring[val % base]; + val /= base; + } + while(val); + if(flg) out[n--] = '-'; + return &out[n+1]; +} + +#else + +#asm +! numout.s +! +.bss +___out lcomm $C + +.text +___numout: +push bp +mov bp,sp +push di +push si +add sp,*-4 +mov byte ptr -8[bp],*$0 ! flg = 0 +mov si,4[bp] ; i or val.lo +mov di,6[bp] ; i or val.hi +mov cx,8[bp] ; base +test cx,cx ! base < 0 ? +jge .3num +neg cx ! base = -base +or di,di ! i < 0 ? +jns .5num +mov byte ptr -8[bp],*1 ! flg = 1 +neg di ! i = -i +neg si +sbb di,0 +.5num: +.3num: +mov byte ptr [___out+$B],*$0 ! out[11] = nul +mov -6[bp],*$A ! n = 10 + +.9num: +!!! out[n--] = nstring[val % base]; +xor dx,dx +xchg ax,di +div cx +xchg ax,di +xchg ax,si +div cx +xchg ax,si ! val(new) = val / base + +mov bx,dx ! dx = val % base + +mov al,_nstring[bx] +mov bx,-6[bp] +dec word ptr -6[bp] +mov ___out[bx],al + +mov ax,si +or ax,di ! while (val) +jne .9num + +cmp byte ptr -8[bp],*$0 ! flg == 0 ? +je .Dnum + +mov bx,-6[bp] +dec word ptr -6[bp] +mov byte ptr ___out[bx],*$2D ! out[n--] = minus + +.Dnum: +mov ax,-6[bp] +add ax,#___out+1 + +add sp,*4 +pop si +pop di +pop bp +ret +#endasm + +#endif diff -Nurd linux86.vold/bcc/debug.c linux86/bcc/debug.c --- linux86.vold/bcc/debug.c 1998-01-11 12:18:34.000000000 +0000 +++ linux86/bcc/debug.c 2004-06-20 14:31:44.000000000 +0100 @@ -1,200 +1,216 @@ -/* debug.c - print debug messages for operators for bcc */ +/* + * debug.c: a generic debugging facility for unix programs. + * + * The calling program is required to call debug_setlevel(lvl) to set + * which messages will be displayed. The level is a two part value + * where the least significant (decimal) digit is a level as described + * below. The most significant digits are a class code. For a message + * to be displayed the class code must either be zero or match the + * class code of the debug(...) message. + * + * The 'debug(lvl, fmt, ...)' function displays debugging messages + * complete with source and line number. The function can be used + * as a normal one in if() smt else smt constructs. It returns the + * actual number of bytes printed so it's return value can be used + * inside an if(debug(...)) to enable more debugging code. This code + * will be removed by the compiler (as dead code) if debugging is + * not enabled. + * + * The level on the debug() statment also consists of a level and class + * code where the class code must be zero or match the setlevel's class + * code for the message to be displayed. + * + * Level 0 + * Always displayed if the debugging is enabled. + * You probably shouldn't use this. + * + * Level 1 + * Important state changes and errors that cause a significant change + * in program flow. + * + * Level 2 + * Rare things that cause a minor program flow adjustment. + * + * Level 3 + * Errors and useful messages that are slightly too verbose or common + * for 0-2 or don't quite fit in the classifications. + * + * Level 4 + * All remote responses or major results. (Trace results) + * + * Level 5 + * All remote commands or major tasks. (Trace jobs) + * + * Level 6 + * General information that will not be too verbose but is normally a + * little less important. (Trace state) + * + * Level 7 + * Similar to level 3 but verbose or not as useful. + * + * Level 8 + * Very verbose information that'll probably be useful sometime. + * + * Level 9 + * Anything and everything else, debugs that probably won't be useful + * ever again. (unclassified) + * + * Notes: + * If the programmer doesn't set the debug level this is not an important + * debug message or is only important right now. + * => default debug level == 9 + * + * If something fits in one of the lower levels but is very verbose + * it should nevertheless be moved upto level 3 or levels 7-9. + * (Possibly leaving a single line 'oops' at the lower level) + * + * The general idea is that debug levels 0-3 should not scroll too fast + * to read and nothing below level 7 should be much more verbose than + * levels 4 or 5. + * + ***************************************************************************** + * + * 2004-06-20: Added __STDC__ to debug.h so it can be called from non-ansi + * compiler. This file still needs ansi or unproto. + * + * 2004-06-20: Added check of DEBUG environment variable if setlevel isn't + * called before a debug(). + * + * 2004-06-20: Added #define VARARG_MACROS so the preprocessor can remove + * all the debugging 'stuff'. + * + */ -/* Copyright (C) 1992 Bruce Evans */ +#include +#include +#include -#include "bcc.h" +#include "debug.h" -#ifdef DEBUG -#include "gencode.h" -#include "reg.h" -#include "sc.h" -#include "scan.h" -#include "type.h" +#define USE_DBPRINTF -PRIVATE char *opname[LASTOP - FIRSTOP + 1] = /* operator names */ -{ /* order must agree with op.h */ - "cond?", - "or", - "eor", - "and", - "gt", "lt", - "add", - "div", "mod", - "lognot", "not", - "strucelt", "strucptr", - "eq", - "addab", "andab", "divab", "eorab", "modab", "mulab", "orab", - "slab", "srab", "subab", - "comma", - "cond:", - "logor", - "logand", - "logeq", - "ne", - "ge", "le", - "sl", "sr", - "sub", - "mul", - "address", "cast", "indirect", "neg", - "predec", "preinc", "postdec", "postinc", - "func", "list", "rootlist", - "leaf", - "ptraddab", "ptradd", "ptrsub", -}; +#ifndef DEBUG +static char ident[] = + "$Id: debug.c: (c) 1995-2004 Robert de Bath. Debugging disabled. $"; +#else +static char ident[] = + "$Id: debug.c: (c) 1995-2004 Robert de Bath. Debugging enabled. $"; -FORWARD void outindchars P((int byte, indn_pt count)); +static char * db_file = 0; +static int db_lineno = 0; +static int disp_state = 0; +static int disp_pos(void); -PUBLIC void dbitem(item) -struct symstruct *item; +static void debug_envvar(void); + +int debug_level = -1; + +void debug_do_setlevel(char * fname, int lineno, int level) { - dbtype(item->type); - if (item->storage == NOSTORAGE) - { - outbyte(' '); - outstr(item->name.namep + 2); - outstr(" (offset "); - outshex(item->offset.offi); - outbyte(')'); - return; - } - if (item->storage == LOCAL) - { - outbyte(' '); - if (item->flags == TEMP) - outstr("(temp)"); - else - outstr(item->name.namep); - } - outstr(" = "); - outindchars('[', item->indcount); - switch (item->storage) - { - case CONSTANT: - outstr("const "); - if (item->type->scalar & RSCALAR) - outstr("(whatever)"); - else if (item->type->scalar & UNSIGNED) - outuvalue((uvalue_t) item->offset.offv); - else - outvalue(item->offset.offv); - break; - case BREG: - case DREG: - case INDREG0: - case INDREG1: - case INDREG2: -#ifdef DATREG1 - case DATREG1: -#endif -#ifdef DATREG2 - case DATREG2: -#endif - outregname(item->storage); - if (item->level == OFFKLUDGELEVEL) - { - outplus(); - if (item->flags & LABELLED) - outlabel(item->name.label); - else - outccname(item->name.namep); - } - break; - case LOCAL: - outbyte('S'); - if (sp <= 0) - outplus(); - outshex(-sp); - break; - case GLOBAL: - if (item->flags & LABELLED) - outlabel(item->name.label); - else - outstr(item->name.namep); - break; - default: - outstr("bad storage ("); - outhex((uoffset_T) item->storage); - outbyte(')'); - outstr(" offset "); - } - if (item->storage != CONSTANT) - { - if (item->offset.offi >= 0) - outplus(); - outshex(item->offset.offi); - } - outindchars(']', item->indcount); + if(level || !debug_level) + debug_level = level; + debug_pos(fname, lineno); + debug_msg(1, "Debug level now %d", level); + debug_level = level; } -PUBLIC void dbtype(type) -struct typestruct *type; +int debug_pos(char * file, int lineno) { - for ( ; type != NULL; type = type->nexttype) - { - outbyte(' '); - switch (type->constructor) - { - case ARRAY: - outbyte('['); - outhex(type->typesize / type->nexttype->typesize); - outbyte(']'); - break; - case FUNCTION: - outstr("()"); - break; - case POINTER: - outbyte('*'); - break; - case STRUCTU: - outstr("struct "); - default: - if (type->scalar & UNSIGNED) - outstr("unsigned "); - outstr(type->tname); - break; - } - } + db_file = file; + db_lineno = lineno; + disp_state |= 1; + return disp_pos(); } -PUBLIC void debug(exp) /* sub-nodes must be leaves */ -struct nodestruct *exp; +int debug_msg(int level, char * fmt, ...) { - if (!debugon) - return; - comment(); - if (exp->tag < FIRSTOP && exp->tag > LASTOP) - outstr("unknown op"); - else - outstr(opname[exp->tag - FIRSTOP]); - if (exp->right != NULL && exp->tag != FUNCOP && - exp->tag != LISTOP && exp->tag != ROOTLISTOP) - { - dbitem(exp->right->left.symptr); - outstr(" to"); - } - dbitem(exp->left.nodeptr->left.symptr); - outstr(" (used reg = "); - if (reguse & INDREG0) - outregname(INDREG0); - if (reguse & INDREG1) - outregname(INDREG1); - if (reguse & INDREG2) - outregname(INDREG2); - outnstr(")"); + va_list ap; + int rv = 0; + int disp = 0; + + if (debug_level == -1) debug_envvar(); + + if (level == -1) { + level = 0; + disp_state |= 1; + db_lineno = -1; + } + + disp_state |= 2; + + if (level>9 || debug_level>9) { + disp = (level%10 <= debug_level%10); + if (disp && level>9 && debug_level>9 && level/10 != debug_level/10) + disp = 0; + } else disp = (level <= debug_level); + + if (disp) + { + disp_state |= 4; + + va_start(ap, fmt); +#ifdef USE_DBPRINTF + rv = vdbprintf(fmt, ap); +#else + rv = vfprintf(stderr, fmt, ap); +#endif + va_end(ap); + } + return rv + disp_pos(); } -PUBLIC void debugswap() +int +disp_pos() { - if (debugon) - outnstr("* swapping"); + int rv = 0; + if (disp_state == 7 && db_lineno != -1) +#ifdef USE_DBPRINTF + rv = dbprintf(" at %s:%d\n", db_file, db_lineno); +#else + rv = fprintf(stderr, " at %s:%d\n", db_file, db_lineno); +#endif + + if ((disp_state&3) == 3) { + db_file = 0; + db_lineno = disp_state = 0; + } + return rv; } -PRIVATE void outindchars(byte, count) -int byte; -indn_pt count; +/* If setlevel isn't called check the environment */ + +static void debug_envvar(void) { - while (count--) - outbyte(byte); + char * p = getenv("DEBUG"); + if (!p || !*p) + debug_level = 0; + else + debug_level = atoi(p); + if (debug_level) +#ifdef USE_DBPRINTF + dbprintf("Debug level now %d from environment.\n", debug_level); +#else + fprintf(stderr, "Debug level now %d from environment.\n", debug_level); +#endif } -#endif /* DEBUG */ +#endif + +#ifndef VARARG_MACROS +/* + * This function should never be called. + * + * If ident sees the message in a binary then your compiler is wasting + * space by allocating it for unused strings. + * + * We know GNU-C is ok, but it complains. + */ +int debug_never(int level, char * name, ...) +{ +#ifndef __GNUC__ + 1?0:debug_never(0, "$Warning: Debugging strings exist in non-debug binary $"); +#endif + return 0; +} +#endif + diff -Nurd linux86.vold/bcc/debug.h linux86/bcc/debug.h --- linux86.vold/bcc/debug.h 1970-01-01 01:00:00.000000000 +0100 +++ linux86/bcc/debug.h 2004-06-20 12:57:51.000000000 +0100 @@ -0,0 +1,38 @@ + +#ifndef _DEBUG_H_ +#define _DEBUG_H_ + +#if __STDC__ +void debug_do_setlevel(char * fname, int lineno, int level); +int debug_pos(char * file, int lineno); +int debug_msg(int level, char * name, ...); +int debug_never(int level, char * name, ...); +#else +void debug_do_setlevel(); +int debug_pos(); +int debug_msg(); +int debug_never(); +#endif /* __STDC__ */ + +/* The new CPP has these. */ +#if defined(__BCC__) && (__BCC_VERSION__ >= 0x001011L) +#define VARARG_MACROS +#endif + +#ifdef DEBUG + +extern int debug_level; +#define debug !debug_level?0:debug_pos(__FILE__,__LINE__)+debug_msg +#define debug_setlevel(lvl) debug_do_setlevel(__FILE__, __LINE__, lvl) + +#else /* !DEBUG */ + +#ifdef VARARG_MACROS +# define debug(junk ...) 0 +#else +# define debug 1?0:debug_never +#endif +# define debug_setlevel(lvl) + +#endif /* DEBUG */ +#endif /* _DEBUG_H_ */ diff -Nurd linux86.vold/bcc/declare.c linux86/bcc/declare.c --- linux86.vold/bcc/declare.c 1999-12-17 17:51:13.000000000 +0000 +++ linux86/bcc/declare.c 2005-01-14 08:25:18.000000000 +0000 @@ -412,12 +412,13 @@ PRIVATE bool_pt declspec() { unsigned nsc; + unsigned nsigned; unsigned ntype; unsigned nunsigned; gvarsc = NULLDECL; gvartype = itype; - nunsigned = ntype = nsc = 0; + nsigned = nunsigned = ntype = nsc = 0; while (TRUE) { switch (sym) @@ -460,6 +461,15 @@ && (gsymptr->type == stype || gsymptr->type == ltype)) ntype = 0; + /* Allow long double and long float */ + if (gvartype == ltype + && (gsymptr->type == fltype || gsymptr->type == dtype)) + { + gvartype = dtype; + nextsym(); + break; + } + /* allow int short and int long, blech */ if (gsymptr->type == itype && (gvartype == stype || gvartype == ltype)) @@ -484,15 +494,34 @@ gvartype = gsymptr->type; nextsym(); break; + case SIGNDECL: + ++nsigned; + nextsym(); + break; case UNSIGNDECL: ++nunsigned; nextsym(); break; + case ASMSYM: + nextsym(); + doasm(); + break; default: goto break2; } } break2: + if (nsigned > 0) + { + if (ntype == 0) + { + gvartype = itype; + ntype = 1; + } + gvartype = tosigned(gvartype); + if (nsigned > 1 || nunsigned > 0) + ntype = 2; + } if (nunsigned > 0) { if (ntype == 0) @@ -501,7 +530,7 @@ ntype = 1; } gvartype = tounsigned(gvartype); - if (nunsigned > 1) + if (nunsigned > 1 || nsigned > 0) ntype = 2; } if (nsc > 0) @@ -664,8 +693,35 @@ if( main_flag > 2 ) globl("environ"); } +#ifdef I8088 + regfuse = 0; +#endif lbrace(); compound(); +#ifdef I8088 + if (regfuse & (callee1mask | INDREG0)) { + outstr("! Register"); + if (regfuse & INDREG0 ) outstr(" BX"); + if (regfuse & INDREG1 & callee1mask) outstr(" SI"); + if (regfuse & INDREG2 & callee1mask) outstr(" DI"); + if (regfuse & LOCAL & callee1mask) outstr(" BP"); + outstr(" used in function "); + outnstr(funcname); + if (optimise && !callersaves) { + outstr(funcname); + outnstr(".off = 0"); + } + } else + if (optimise && !callersaves) { + outstr(funcname); + outstr(".off = "); +#ifndef I80386 + outnhex(4); +#else + outnhex(i386_32?12:4); +#endif + } +#endif clearfunclabels(); } @@ -997,9 +1053,11 @@ PUBLIC void program() { +#ifdef BUILTIN_CPP if (orig_cppmode) cppscan(0); else +#endif { nextsym(); while (sym != EOFSYM) @@ -1093,6 +1151,7 @@ PUBLIC void semicolon() { + outnstr("!BCC_EOS"); if (sym != SEMICOLON) need(';'); else diff -Nurd linux86.vold/bcc/exptree.c linux86/bcc/exptree.c --- linux86.vold/bcc/exptree.c 1999-03-14 12:23:01.000000000 +0000 +++ linux86/bcc/exptree.c 2004-06-02 19:54:31.000000000 +0100 @@ -397,7 +397,12 @@ if (target->storage == CONSTANT) { if (rscalar & CHAR) + { target->offset.offv &= CHMASKTO; + if (p2->nodetype == sctype && + target->offset.offv&((~CHMASKTO)>>1)) + target->offset.offv |= ~CHMASKTO; + } else if (rscalar & SHORT) { target->offset.offv &= shortmaskto; diff -Nurd linux86.vold/bcc/function.c linux86/bcc/function.c --- linux86.vold/bcc/function.c 1999-07-24 14:31:34.000000000 +0100 +++ linux86/bcc/function.c 2004-06-20 13:25:16.000000000 +0100 @@ -237,7 +237,7 @@ if (sp != lastargsp - target->type->typesize) { bugerror("botched push of arg"); -#ifdef DEBUG +#ifdef DBNODE outstr("arg type is "); dbtype(target->type); outnl(); @@ -270,7 +270,23 @@ PUBLIC void popframe() { +#ifdef STUPIDFRAME +#ifndef NO_DEL_PUSH + if (optimise && !callersaves) { + outstr("if "); + outstr(funcname); + outnstr(".off=0"); + } + poplist(callee1mask); + if (optimise && !callersaves) + outnstr("endif"); +#else + poplist(callee1mask); +#endif + poplist(FRAMEREG); +#else poplist(frame1list); +#endif } #endif @@ -308,7 +324,18 @@ pushreg(FRAMEREG); regtransfer(STACKREG, FRAMEREG); framep = sp; +#ifndef NO_DEL_PUSH + if (optimise && !callersaves) { + outstr("if "); + outstr(funcname); + outnstr(".off=0"); + } + pushlist(callee1mask); + if (optimise && !callersaves) + outnstr("endif"); +#else pushlist(callee1mask); +#endif # else /* not STUPIDFRAME */ # ifdef CANHANDLENOFRAME if (stackarg || softsp != -frameregsize) /* args or locals */ diff -Nurd linux86.vold/bcc/gencode.c linux86/bcc/gencode.c --- linux86.vold/bcc/gencode.c 1998-03-15 13:05:37.000000000 +0000 +++ linux86/bcc/gencode.c 2004-06-20 13:25:48.000000000 +0100 @@ -223,8 +223,8 @@ if ((right = exp->right) == NULL) { makeleaf(left); -#ifdef DEBUG - debug(exp); +#ifdef DBNODE + dbnode(exp); #endif return; } @@ -265,8 +265,8 @@ exp->left.nodeptr = right; right = exp->right = left; left = exp->left.nodeptr; -#ifdef DEBUG - debugswap(); +#ifdef DBNODE + dbnodeswap(); #endif } makeleaf(right); @@ -346,8 +346,8 @@ indirec(source); } reguse = regmark; -#ifdef DEBUG - debug(exp); +#ifdef DBNODE + dbnode(exp); #endif if (commutop && ((target->storage == CONSTANT @@ -358,8 +358,8 @@ { exp->left.nodeptr = right; exp->right = left; -#ifdef DEBUG - debugswap(); +#ifdef DBNODE + dbnodeswap(); #endif } } @@ -720,7 +720,7 @@ { { bugerror("botched nodetype calculation"); -#ifdef DEBUG +#ifdef DBNODE comment(); outstr("runtime type is "); dbtype(target->type); diff -Nurd linux86.vold/bcc/gencode.h linux86/bcc/gencode.h --- linux86.vold/bcc/gencode.h 1998-03-15 10:16:31.000000000 +0000 +++ linux86/bcc/gencode.h 2004-06-20 13:26:03.000000000 +0100 @@ -14,8 +14,8 @@ /* zero after allocation of 1st arg */ EXTERN store_pt callee1mask; /* calleemask with doubleregs masked if nec */ EXTERN uoffset_T dataoffset; /* amount of initialized data so far */ -#ifdef DEBUG -EXTERN bool_t debugon; /* nonzero to print debugging messages */ +#ifdef DBNODE +EXTERN bool_t dbnodeon; /* nonzero to print debugging messages */ /* depends on zero init */ #endif #ifdef FRAMEPOINTER @@ -47,11 +47,13 @@ EXTERN offset_T softsp; /* software sp (leads sp during declares) */ EXTERN offset_T sp; /* hardware relative stack ptr */ /* depends on zero init */ +EXTERN store_t regfuse; /* registers in use in function. */ #ifdef FRAMEPOINTER EXTERN bool_t stackarg; /* nonzero to show function has arg on stack */ #endif EXTERN struct switchstruct *switchnow; /* currently active switch */ /* depends on NULL init */ +EXTERN bool_t optimise; /* nonzero to add optimisation code */ /* variables to be initialised to nonzero */ diff -Nurd linux86.vold/bcc/genloads.c linux86/bcc/genloads.c --- linux86.vold/bcc/genloads.c 1999-07-24 14:36:08.000000000 +0100 +++ linux86/bcc/genloads.c 2005-01-14 08:16:20.000000000 +0000 @@ -573,6 +573,41 @@ } else { +#ifdef I8088 + /* Added acess to CPU registers. Just declare _AX etc. as + * extern int, and you can use them to get/set + * the register values. (vak) */ + if (source->storage == GLOBAL && !(source->flags & LABELLED) && + *source->name.namep != 0 && + strncmp(source->name.namep, "__", 2) == 0) + { + if (strcmp (source->name.namep, "__AX") == 0) + { + /* Load AX register - do nothing. */ +done: + if (targreg != AXREG) + bugerror("specified access of register clone variable not implemented"); + source->storage = AXREG; /* in register for further use */ + source->flags = 0; + if (source->level == OFFKLUDGELEVEL) + source->level = EXPRLEVEL; + source->offset.offi = 0; /* indcount was adjusted by outadr */ + return; + } + if (strcmp (source->name.namep, "__BX") == 0) { outstr ("mov\tax,bx\n"); goto done; } + if (strcmp (source->name.namep, "__CX") == 0) { outstr ("mov\tax,cx\n"); goto done; } + if (strcmp (source->name.namep, "__DX") == 0) { outstr ("mov\tax,dx\n"); goto done; } + if (strcmp (source->name.namep, "__SP") == 0) { outstr ("mov\tax,sp\n"); goto done; } + if (strcmp (source->name.namep, "__BP") == 0) { outstr ("mov\tax,bp\n"); goto done; } + if (strcmp (source->name.namep, "__SI") == 0) { outstr ("mov\tax,si\n"); goto done; } + if (strcmp (source->name.namep, "__DI") == 0) { outstr ("mov\tax,di\n"); goto done; } + if (strcmp (source->name.namep, "__CS") == 0) { outstr ("mov\tax,cs\n"); goto done; } + if (strcmp (source->name.namep, "__DS") == 0) { outstr ("mov\tax,ds\n"); goto done; } + if (strcmp (source->name.namep, "__ES") == 0) { outstr ("mov\tax,es\n"); goto done; } + if (strcmp (source->name.namep, "__SS") == 0) { outstr ("mov\tax,ss\n"); goto done; } + if (strcmp (source->name.namep, "__FLAGS") == 0) { outstr ("pushf\npop\tax\n"); goto done; } + } +#endif outload(); if (source->storage == GLOBAL && source->indcount != 0 && (store_t) targreg & (AXREG | ALREG)) @@ -621,6 +656,12 @@ { if ((store_t) targreg & ALLDATREGS && source->type->scalar & CHAR) targreg = BREG; +#ifdef I8086 + if (source->type->scalar & CHAR && + targreg != BREG && targreg != DATREG1B ) { + bugerror("moving char sym into int register"); + } +#endif #ifdef I80386 if (i386_32 && source->type->scalar & SHORT && source->indcount <= 1) @@ -784,10 +825,19 @@ bumplc(); else { + int off; if (switchnow != NULL && adr->flags == TEMP) - outswoffset(adr->offset.offi); + outswoffset(off = adr->offset.offi); else - outoffset(adr->offset.offi - framep); + outoffset(off = adr->offset.offi - framep); +#ifndef NO_DEL_PUSH + if (optimise && !callersaves && off < 0) + { + outstr("+"); + outstr(funcname); + outstr(".off"); + } +#endif } outindleft(); } @@ -948,15 +998,19 @@ #endif case INDREG0: outstr(ireg0str); + regfuse |= INDREG0; break; case INDREG1: outstr(ireg1str); + regfuse |= INDREG1; break; case INDREG2: outstr(ireg2str); + regfuse |= INDREG2; break; case LOCAL: outstr(localregstr); + regfuse |= LOCAL; break; #ifdef STACKREG case STACKREG: @@ -996,7 +1050,7 @@ } } -#ifdef I8088 +#if defined(I8088) && defined(I80386) /* print register name for short type */ PUBLIC void outshortregname(reg) @@ -1264,6 +1318,29 @@ } else { +#ifdef I8088 + /* Added acess to CPU registers. Just declare _AX etc. as + * extern int, and you can use them to get/set + * the register values. (vak) */ + if (target->storage == GLOBAL && !(target->flags & LABELLED) && + *target->name.namep != 0 && + strncmp(target->name.namep, "__", 2) == 0) + { + if (strcmp (target->name.namep, "__AX") == 0) { return; } + if (strcmp (target->name.namep, "__BX") == 0) { outstr ("mov\tbx,"); outregname(sourcereg); outnl(); return; } + if (strcmp (target->name.namep, "__CX") == 0) { outstr ("mov\tcx,"); outregname(sourcereg); outnl(); return; } + if (strcmp (target->name.namep, "__DX") == 0) { outstr ("mov\tdx,"); outregname(sourcereg); outnl(); return; } + if (strcmp (target->name.namep, "__SP") == 0) { outstr ("mov\tsp,"); outregname(sourcereg); outnl(); return; } + if (strcmp (target->name.namep, "__BP") == 0) { outstr ("mov\tbp,"); outregname(sourcereg); outnl(); return; } + if (strcmp (target->name.namep, "__SI") == 0) { outstr ("mov\tsi,"); outregname(sourcereg); outnl(); return; } + if (strcmp (target->name.namep, "__DI") == 0) { outstr ("mov\tdi,"); outregname(sourcereg); outnl(); return; } + if (strcmp (target->name.namep, "__CS") == 0) { outstr ("mov\tcs,"); outregname(sourcereg); outnl(); return; } + if (strcmp (target->name.namep, "__DS") == 0) { outstr ("mov\tds,"); outregname(sourcereg); outnl(); return; } + if (strcmp (target->name.namep, "__ES") == 0) { outstr ("mov\tes,"); outregname(sourcereg); outnl(); return; } + if (strcmp (target->name.namep, "__SS") == 0) { outstr ("mov\tss,"); outregname(sourcereg); outnl(); return; } + if (strcmp (target->name.namep, "__FLAGS") == 0) { outstr ("push\tax"); outregname(sourcereg); outstr ("\npopf\n"); return; } + } +#endif outstore(); #ifdef I8088 if (target->storage == GLOBAL && (store_t) sourcereg & (AXREG | ALREG)) diff -Nurd linux86.vold/bcc/hashcmd.c linux86/bcc/hashcmd.c --- linux86.vold/bcc/hashcmd.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/bcc/hashcmd.c 2004-06-20 07:28:05.000000000 +0100 @@ -0,0 +1,211 @@ + +/* decode remaining preprocessor lines, minimal version. */ + +/* Copyright (C) GPL V2, derived from preproc.c by RDB. */ + +#include "bcc.h" +#include "input.h" +#include "os.h" +#include "output.h" +#include "parse.h" +#include "sc.h" +#include "scan.h" +#include "table.h" +#include "type.h" + +#ifndef BUILTIN_CPP +FORWARD void control P((void)); +FORWARD void asmcontrol P((void)); +FORWARD void warningcntl P((void)); +FORWARD void errorcntl P((void)); + +/* docontrol() - process control statement, #line and #asm only. */ +PUBLIC void docontrol() +{ + control(); + skipline(); + return; +} + +/* control() - select and switch to control statement */ + +PRIVATE void control() +{ + char sname[NAMESIZE + 1]; + sym_t ctlcase; + struct symstruct *symptr; + if (ctext && asmmode) + { + comment(); + outudec(input.linenumber); + outbyte(' '); + outline(lineptr); + } + + sname[0] = '#'; /* prepare for bad control */ + sname[1] = 0; + if (blanksident()) + strcat(sname, gsname); + if (sname[1] == 0 && ch == EOL) + return; + if (SYMOFCHAR(ch) == INTCONST) + { linecontol(); return; } + if ((symptr = findlorg(sname)) == NULL) + { + error(" bad control"); + return; + } + ctlcase = symptr->offset.offsym; + + switch (ctlcase) + { + case ASMCNTL: + if (asmmode) + error(" bad control"); + else + asmcontrol(); + break; + case ENDASMCNTL: + if (!asmmode) + error(" bad control"); + asmmode = FALSE; + break; + case LINECNTL: + { linecontol(); break; } + case WARNINGCNTL: + warningcntl(); + break; + case ERRORCNTL: + errorcntl(); + break; + default: + error(" bad control"); + break; + } +} + +/* asmcontrol() - process #asm */ + +PRIVATE void asmcontrol() +{ +#ifdef ASM_BARE + char treasure; /* to save at least one leading blank */ +#endif + + asmmode = TRUE; + if (expect_statement) + return; + + outnstr("!BCC_ASM"); + dumplocs(); +#ifndef ASM_BARE + cppscan(1); +#else + while (TRUE) + { + skipline(); + skipeol(); + if (eofile) + { + eofin("#asm"); + break; + } + if (SYMOFCHAR(ch) == SPECIALCHAR) + specialchar(); + treasure = 0; + if (SYMOFCHAR(ch) == WHITESPACE) + treasure = ch; + blanks(); + if (ch == '#') + { + if (ctext) + { + register char *lptr; + + comment(); + if (treasure != 0) + outbyte(treasure); + lptr = lineptr; + while (*lptr++ != EOL) /* XXX - handle COEOL too */ + outbyte(ch); + outnl(); + } + gch1(); + docontrol(); + if (!asmmode) + break; + } + else + { + if (treasure != 0) + outbyte(treasure); + while (ch != EOL) /* XXX - handle COEOL too */ + { + outbyte(ch); + gch1(); + } + outnl(); + } + } +#endif + outnstr("!BCC_ENDASM"); +} + +/* warningcntl() - process #warning */ + +PRIVATE void warningcntl() +{ + char estr[256], *ep = estr; + + *ep++ = '%'; *ep++ = 'w'; + while( ch != EOL ) { + if (ep < estr+sizeof(estr)-2 ) + *ep++ = ch; + gch1(); + } + *ep = 0; + error(estr); +} + +/* errorcntl() - process #error */ + +PRIVATE void errorcntl() +{ + char estr[256], *ep = estr; + + while( ch != EOL ) { + if (ep < estr+sizeof(estr)-2 ) + *ep++ = ch; + gch1(); + } + *ep = 0; + + error(estr); +} + +/* skipline() - skip rest of line */ + +PUBLIC void skipline() +{ + while (TRUE) + { + blanks(); + if (ch == EOL) + return; + if (ch == '\\') + { + gch1(); + if (ch == EOL) /* XXX - I think blanks() eats \EOL */ + return; + gch1(); /* XXX - escape() better? */ + } + else if (ch == '"' || ch == '\'') + { + stringorcharconst(); + charptr = constant.value.s; + } + else + gch1(); + } +} +#endif diff -Nurd linux86.vold/bcc/idcc linux86/bcc/idcc --- linux86.vold/bcc/idcc 1996-10-13 22:04:52.000000000 +0100 +++ linux86/bcc/idcc 1970-01-01 01:00:00.000000000 +0100 @@ -1,328 +0,0 @@ -#!/bin/ash -# -# This is a shell version of the bcc compiler driver. It's a little slower -# than a C version but overall seems to be a lot cleaner, perhaps a C version -# based on this might be a good idea ... -# -# The compiler works on a 'modal' basis certain flags given to it put the -# compiler into specific modes, it can only be in one mode for a run. -# -# The mode defines the basic passes and specific options that are available -# -# To define a mode see the functions 'run_0' and 'run_3' for examples. The -# variable assignments just above the definitions enable the functions. -# -# This script is specifically designed so the there is as little interaction -# between the modes as is possible. -# -# It's run using ash because this appears to be _much_ faster than bash, it's -# also reasonable with ksh. -# (On other interpreters I think perl would be too big, but awk might work...) -# - -TMPFIL="/tmp/cc$$" -trap "rm -f $TMPFIL.* ; exit 1" 1 2 3 15 -TMPCNT=0 - -FILES= -OPTS= -RESEXTN= -VERBOSE=no -MULTISRC=no - -LDOPTS= -DESTDEF=no -LDDEST=a.out -DEFMODE=0 - -ccmode= -LIBPATH="/lib:/usr/lib:/usr/bin" - -main() { - scanargs "$@" - - PATH="$LIBPATH:$PATH" - [ "$EXEC_PREFIX" != "" ] && PATH="$EXEC_PREFIX:$PATH" - - rv=0 - LDFILES= - [ "$MULTISRC" = yes -o "$RESEXTN" = "" ] && DESTDEF=no - - for FILE in $FILES - do - case "$FILE" in - *.c ) PASS=cpp ; BASE="`basename $FILE .c`" ;; - *.s ) PASS=as ; BASE="`basename $FILE .s`" ;; - * ) PASS=lnk ;; - esac - - NAME="`basename $FILE`" - DEST="`dirname $FILE`/" - [ "$DEST" = "./" ] && DEST= - DEST="$DEST$BASE.$RESEXTN" - [ "$DESTDEF" = yes ] && DEST="$LDDEST" - - STEMP=0 INTEMP=0 - [ "$PASS" = "cpp" ] && { compile $FILE || rv=$? ; } - [ "$PASS" = "as" ] && { assem $FILE || rv=$? ; } - if [ "$PASS" = "lnk" ] - then - LDFILES="$LDFILES $FILE" - else - # If there's a fail can't link - still assembling to temps tho. - [ "$RESEXTN" = "" ] && RESEXTN=O - fi - [ "$STEMP" = 1 ] && rm -f "$SFILE" - done - - [ "$RESEXTN" != "" ] && { - rm -f $TMPFIL.* - exit $rv - } - - [ "$VERBOSE" = yes ] && eval "echo \"$LINK\"" 1>&2 - eval "$LINK" - rv=$? - rm -f $TMPFIL.* - exit "$rv" -} - -scanargs() { - WILDOPT=no - - while [ "$#" -gt 0 ] - do - case "$1" in - -[DU]* ) CPPDEFS="$CPPDEFS $1" ;; - -B?* ) PATH="`echo '.$1:$PATH' | sed 's/...//'`" ;; - -I?* ) CPPFLAGS="$CPPFLAGS $1" ;; - -L?* ) LDOPTS="$LDOPTS $1" ;; - -o ) LDDEST="$2"; DESTDEF=yes ; shift ;; - -b ) . /usr/lib/idcc/opts_$2 || exit 1; shift ;; - -E ) RESEXTN=i ;; - -S ) RESEXTN=s ;; - -c ) RESEXTN=o ;; - -v ) VERBOSE=yes ;; - -l?* ) FILES="$FILES $1" ; MULTISRC=yes ;; - -* ) OPTS="$OPTS `echo .$1 | sed 's/..//'`" ;; - * ) [ "$FILES" != "" ] && MULTISRC=yes ; FILES="$FILES $1" ;; - esac - shift - done - - while [ "$OPTS" != "" -o "$DEFMODE" != "" ] - do - # So they can try again ... with DEFMODE if needed - MOPTS="$OPTS" - OPTS= - - for opt in $MOPTS - do - # Option can be defined only for specific mode so if we haven't seen - # the mode yet save the opt. If we have check for conflicts too. - [ "$ccmode" = "" -a "$DEFMODE" != "" ] && { - eval "[ \"\$opt_$opt\" = yes ]" || { OPTS="$OPTS $opt" ; opt= ; } - } - [ "$opt" != "" ] && { - [ "$ccmode" = "" ] || { - eval "[ \"\$mode_$opt\" = yes ]" && { - echo Option "-$opt incompatible with -$ccmode" 1>&2 - exit 2 - } - } - - eval "[ \"\$opt_$opt\" = yes ]" || { - { eval "[ \"$WILDOPT\" = yes ]" && wild_opt "-$opt" ; } || { - echo Option '-'$opt unknown for this mode 1>&2 - exit 3 - } - } - - eval "[ \"\$opt_$opt\" = yes ]" && run_$opt - eval "[ \"\$mode_$opt\" = yes ]" && ccmode="$opt" - } - done - [ "$ccmode" = "" -a "$DEFMODE" != "" ] && OPTS="$DEFMODE $OPTS" - DEFMODE= - done -} - -compile() { - [ -r "$FILE" ] || { echo "Cannot open $FILE" 1>&2 ; return 1 ; } - - # Loop for the pass list - # The CCX variables _are_ expanded again. - - ret=1 - for pass in $PASSLIST - do - for extn in '' res opt - do eval "CCX$extn=\"\$CC$pass$extn\"" - done - - [ "$CCX" = "" ] && continue; - - shuffel "$RESEXTN" $CCXres - [ "$VERBOSE" = yes ] && eval "echo \"$CCX\"" 1>&2 - eval "$CCX" || return 1 - ret=0 - [ "$CCXres" = "$RESEXTN" ] && break - done - [ "$ret" = 1 ] && { echo 'CC configuration error' 1>&2 ; return $ret ; } - - [ "$RESEXTN" != "$CCXres" ] && PASS=as - return 0 -} - -assem() { - [ -r "$FILE" ] || { echo "Cannot open $FILE" 1>&2 ; return 1 ; } - - shuffel "$RESEXTN" o - - n= - [ "$ASNAME" != "" ] && n="$ASNAME$NAME" - - [ "$VERBOSE" = yes ] && echo "$AS $ASFLAGS $n $SFILE -o $FILE" 1>&2 - $AS $ASFLAGS $n $SFILE -o $FILE || return - - [ "$RESEXTN" != "o" ] && PASS=lnk - return 0 -} - -if [ "2" = "$[1+1]" ] ; then inc_tmpcnt() { TMPCNT="$[$TMPCNT+1]" ; } -else inc_tmpcnt() { TMPCNT="`expr $TMPCNT + 1`" ; } -fi - -shuffel() { - [ "$STEMP" = 1 ] && rm -f "$SFILE" - - SFILE="$FILE" - STEMP="$INTEMP" - - if [ "$1" = "$2" ] - then - FILE="$DEST" - INTEMP=0 - else - inc_tmpcnt - FILE="$TMPFIL.$TMPCNT.$2" - INTEMP=1 - fi -} - -mode_0=yes opt_0=yes -run_0() -{ - SYSINC="-I/usr/bcc/include" - SYSLIB="-L/usr/bcc/lib/bcc/i86/" - LIBPATH="/usr/bcc/lib/bcc" - CRT0="-C0" - LIBS="-lc" - CGEN='-0' - DEFS= - - CPP="cpp" - - PASSLIST=2 - CC2='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -o $FILE' - CC2res=s - AS="as86" ASFLAGS='-u -w -0' ASNAME='-n ' - LINK='ld86 $SYSLIB $LDOPTS $LDFLAGS -o $LDDEST $CRT0 $LDFILES $LIBS' - LDFLAGS='-i -0' - - [ "$RESEXTN" = "i" ] && { - PASSLIST="0" - CC0='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -E' - CC0res=i - } - - opt_ansi=yes - run_ansi() - { - PASSLIST="0 1 2" - CC0='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -o $FILE -E' - CC0res=k - CC1res=i CC1='unproto $SFILE $FILE' - CC2res=s CC2='bcc-cc1 $CGEN $SFILE -o $FILE' - DEFS='-D__STDC__=0' - } - opt_I=yes; run_I() { SYSINC= ; } - opt_L=yes; run_L() { SYSLIB= ; } - opt_O=yes; run_O() { echo Warning -O ignored 1>&2 ; } - opt_Mf=yes; run_Mf() { LIBS=-lc_f ; CGEN='-0 -f -c' ;} - opt_Md=yes; - run_Md() { LIBS=-ldos ; DEFS=$DEFS' -D__MSDOS__' LDFLAGS='-i -0 -d' ;} - - WILDOPT=yes - wild_opt() - { - case "$1" in - # For normal CC operation unknowns go to the linker. ie: - # * ) LDFLAGS="$LDFLAGS $1" ; return 0 ;; - # But do this instead. - -[dMizmts] ) LDFLAGS="$LDFLAGS $1" ; return 0 ;; - -[dMizmt]- ) LDFLAGS="$LDFLAGS $1" ; return 0 ;; - -T* ) LDFLAGS="$LDFLAGS $1" ; return 0 ;; - * ) return 1 ;; - esac - return 0 - } -} - -mode_3=yes opt_3=yes -run_3() -{ - SYSINC="-I/usr/bcc/include" - SYSLIB="-L/usr/bcc/lib/bcc/i386/" - LIBPATH="/usr/bcc/lib/bcc" - CRT0="-C0" - LIBS="-lc" - CGEN='-3' - DEFS= - - CPP="cpp" - - PASSLIST=2 - CC2='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -o $FILE' - CC2res=s - AS="as86" ASFLAGS='-u -w -3' ASNAME='-n ' - LINK='ld86 $SYSLIB $LDOPTS $LDFLAGS -o $LDDEST $CRT0 $LDFILES $LIBS' - LDFLAGS='-3' - - [ "$RESEXTN" = "i" ] && { - PASSLIST="0" - CC0='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -E' - CC0res=i - } - - opt_ansi=yes - run_ansi() - { - PASSLIST="0 1 2" - CC0='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -o $FILE -E' - CC0res=k - CC1res=i CC1='unproto $SFILE $FILE' - CC2res=s CC2='bcc-cc1 $CGEN $SFILE -o $FILE' - DEFS='-D__STDC__=0' - } - opt_I=yes; run_I() { SYSINC= ; } - opt_L=yes; run_L() { SYSLIB= ; } - opt_O=yes; run_O() { echo Warning -O ignored 1>&2 ; } - - WILDOPT=yes - wild_opt() - { - case "$1" in - # For normal CC operation unknowns go to the linker. ie: - # * ) LDFLAGS="$LDFLAGS $1" ; return 0 ;; - # But do this instead. - -[dMizmts] ) LDFLAGS="$LDFLAGS $1" ; return 0 ;; - -[dMizmt]- ) LDFLAGS="$LDFLAGS $1" ; return 0 ;; - -T* ) LDFLAGS="$LDFLAGS $1" ; return 0 ;; - * ) return 1 ;; - esac - return 0 - } -} - -main "$@" diff -Nurd linux86.vold/bcc/input.c linux86/bcc/input.c --- linux86.vold/bcc/input.c 1998-02-07 00:41:41.000000000 +0000 +++ linux86/bcc/input.c 2004-06-20 16:17:29.000000000 +0100 @@ -18,6 +18,7 @@ #include "input.h" #define INBUFSIZE 2048 +#define NO_EOFHACK struct fbufstruct /* file buffer structure */ { @@ -30,6 +31,7 @@ char fbuf[INBUFSIZE + 1]; /* buffer to read into */ }; +#ifdef BUILTIN_CPP struct inclist /* list of include file directories */ { char *incdirname; @@ -53,6 +55,7 @@ }; PRIVATE fastin_t inclevel; /* nest level of include files */ /* depends on zero init */ +#endif PRIVATE struct fbufstruct *inputbuf; /* current input file buffer */ /* its fcb only to date in includes */ /* depends on zero (NULL) init */ @@ -61,9 +64,11 @@ #ifdef ARBITRARY_BACKSLASH_NEWLINES FORWARD void backslash P((void)); #endif +#ifdef BUILTIN_CPP FORWARD void definefile P((char *fname)); -FORWARD void inputinit P((char *fname, fd_t fd)); FORWARD void leaveinclude P((void)); +#endif +FORWARD void inputinit P((char *fname, fd_t fd)); FORWARD void usage P((void)); #ifdef ARBITRARY_BACKSLASH_NEWLINES @@ -138,10 +143,13 @@ #else close(input.fd); #endif +#ifdef BUILTIN_CPP while (inclevel != 0) leaveinclude(); +#endif } +#ifdef BUILTIN_CPP PRIVATE void definefile(fname) char *fname; { @@ -155,6 +163,7 @@ definestring(def); ourfree(def); } +#endif PUBLIC void errorloc() { @@ -170,6 +179,7 @@ { outudec(input.linenumber); outbyte('.'); +#ifdef BUILTIN_CPP if (maclevel == 0) outudec((unsigned) (lineptr - inputbuf->fbuf) - input.lineoffset); else @@ -180,6 +190,9 @@ outudec((unsigned) maclevel); outbyte(')'); } +#else + outudec((unsigned) (lineptr - inputbuf->fbuf) - input.lineoffset); +#endif } infbuf->fcb.includer = input.includer; while ((infbuf = infbuf->fcb.includer) != NULL) @@ -202,6 +215,7 @@ specialchar(); } +#ifdef BUILTIN_CPP /* process #include */ PUBLIC void include() @@ -238,6 +252,7 @@ if (ch == terminator) { gch1(); + blanks(); break; } if (charptr >= chartop) @@ -344,6 +359,7 @@ #endif charptr = fnameptr; } +#endif /* initialise current input file */ @@ -372,19 +388,21 @@ inputbuf = newinputbuf; newinputbuf->fname = fname; newinputbuf->fname_malloced = FALSE; +#ifdef BUILTIN_CPP undefinestring(filemacro); definefile(fname); if (orig_cppmode && !suppress_line_numbers) outcpplinenumber(1, fname, input.includer == NULL ? "" : " 1"); +#endif *(input.limit = newinputbuf->fbuf) = EOL; - /* dummy line so #include processing can start with skipline() */ + /* dummy line so processing can start with skipline() */ ch = *(lineptr = newinputbuf->fbuf - 1) = EOL; } PUBLIC void linecontol() { -static char linename[32]; + char linename[256]; char * ptr; int i=0; @@ -407,15 +425,20 @@ #endif ourfree(inputbuf->fname); } - inputbuf->fname_malloced = FALSE; - inputbuf->fname = linename; + inputbuf->fname_malloced = TRUE; + ptr = ourmalloc(strlen(linename)+1); + strcpy(ptr, linename); + inputbuf->fname = ptr; ptr=lineptr; +#ifdef BUILTIN_CPP undefinestring(filemacro); definefile(inputbuf->fname); +#endif ch = *(lineptr = ptr); } +#ifdef BUILTIN_CPP /* switch from include file to file which included it */ PRIVATE void leaveinclude() @@ -448,6 +471,7 @@ if (orig_cppmode && !suppress_line_numbers) outcpplinenumber(input.linenumber, inputbuf->fname, " 2"); } +#endif /* open input and output files and get options */ @@ -459,8 +483,10 @@ int argn; fd_t fd; char *fname; +#ifdef BUILTIN_CPP struct inclist *incnew; struct inclist *incptr; +#endif bool_t flag[128]; #if 0 @@ -472,7 +498,9 @@ flag['3'] = sizeof (int) >= 4; #endif fname = "stdin"; +#ifdef BUILTIN_CPP (incptr = &incfirst)->incnext = &inclast; +#endif initout(); for (argn = 1; argn < argc; ++argn) { @@ -495,10 +523,12 @@ case '3': /* generate 32-bit code */ #endif case 'c': /* caller saves */ -#ifdef DEBUG +#ifdef DBNODE case 'd': /* print debugging information in asm output */ #endif +#ifdef BUILTIN_CPP case 'E': /* acting as cpp */ +#endif case 'f': /* pass first argument in register */ #ifdef DYNAMIC_LONG_ORDER case 'l': /* long big-endian */ @@ -509,6 +539,7 @@ #endif case 't': /* print source code in asm output */ case 'w': /* watch location counter */ + case 'O': /* Optimisation. */ if (arg[2] == 0) flag[(int)arg[1]] = TRUE; else if (arg[2] == '-' && arg[3] == 0) @@ -518,6 +549,7 @@ if (arg[1] == '0') /* flag 0 is negative logic flag 3 */ flag['3'] = TRUE + FALSE - flag['0']; break; +#ifdef BUILTIN_CPP case 'D': definestring(arg + 2); break; @@ -534,6 +566,7 @@ case 'U': undefinestring(arg + 2); break; +#endif case 'o': if (arg[2] != 0 || ++argn >= argc) usage(); @@ -544,6 +577,7 @@ break; } } +#ifdef BUILTIN_CPP #ifdef I8088 #ifdef I80386 if (flag['3']) @@ -567,8 +601,8 @@ callersaves = TRUE; definestring("__CALLER_SAVES__"); } -#ifdef DEBUG - debugon = flag['d']; +#ifdef DBNODE + dbnodeon = flag['d']; #endif orig_cppmode = cppmode = flag['E']; if (flag['f']) @@ -597,10 +631,40 @@ definestring("__POS_INDEPENDENT__"); } #endif + if (flag['O']) + { + optimise = TRUE; + definestring("__OPTIMISED__"); + } #ifdef NOFLOAT definestring("__HAS_NO_FLOATS__"); #endif + +#else /* !BUILTIN_CPP */ + +#ifdef I80386 + if (flag['3']) i386_32 = TRUE; +#endif + if (flag['c']) callersaves = TRUE; +#ifdef DBNODE + dbnodeon = flag['d']; +#endif + if (flag['f']) arg1inreg = TRUE; + arg1op = arg1inreg ? ROOTLISTOP : LISTOP; +#ifdef DYNAMIC_LONG_ORDER + if (flag['l']) long_big_endian = TRUE; +#endif + suppress_line_numbers = flag['P']; +#ifdef POSINDEPENDENT + if (flag['p']) posindependent = TRUE; +#endif + if (flag['O']) optimise = TRUE; + +#endif ctext = flag['t']; +#ifdef DBNODE + if (ctext) dbnodeon = 1; +#endif watchlc = flag['w']; setoutbufs(); inputinit(fname, fd); @@ -618,6 +682,7 @@ static bool_t skip_printing_nl; #endif int nread; + debug(7, "skipeol %s:%d", inputbuf->fname, input.linenumber); if (eofile) return; @@ -632,6 +697,7 @@ outbyte(' '); outline(lineptr); } +#ifdef BUILTIN_CPP #ifndef ASM_BARE if (!virtual_nl && (orig_cppmode || asmmode)) #else @@ -641,6 +707,13 @@ if (!skip_printing_nl) #endif outbyte('\n'); +#else /* !BUILTIN_CPP */ + if (asmmode) +#ifdef INSERT_BACKSLASH_NEWLINES + if (!skip_printing_nl) +#endif + outbyte('\n'); +#endif #ifdef INSERT_BACKSLASH_NEWLINES if (bs_state == 1 && *(lineptr - 1) == EOL) @@ -689,6 +762,7 @@ #endif nread = read(input.fd, lineptr = inputbuf->fbuf, INBUFSIZE); #ifndef NO_EOFHACK +#ifdef BUILTIN_CPP if( nread == 0 && inclevel > 0 ) { close(input.fd); @@ -696,6 +770,7 @@ memcpy(inputbuf->fbuf, "\n", 1); nread = 1; } +#endif } #endif #endif @@ -705,6 +780,7 @@ ch = *lineptr; if (nread == 0) { +#ifdef BUILTIN_CPP if (inclevel == 0) { eofile = TRUE; @@ -715,6 +791,9 @@ leaveinclude(); skipeol(); } +#else + eofile = TRUE; +#endif return; } if (ctext && !asmmode) @@ -728,6 +807,7 @@ PUBLIC void specialchar() { +#ifdef BUILTIN_CPP if (maclevel != 0) { if (ch == EOL) /* it might also be backslash or COEOL */ @@ -735,6 +815,7 @@ if (ch != EOL) return; } +#endif more: #ifdef ARBITRARY_BACKSLASH_NEWLINES if (ch == '\\') @@ -798,13 +879,22 @@ PRIVATE void usage() { fatalerror( -#ifdef MC6809 -"usage: cc1 [-cdfptw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]"); -#else -#ifdef I80386 -"usage: cc1 [-03cdfltw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]"); +#ifdef BUILTIN_CPP +# ifdef MC6809 +"usage: cc1 [-cdfptw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]" +# else +# ifdef I80386 +"usage: cc1 [-03cdfltw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]" +# else +"usage: cc1 [-cdfltw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]" +# endif +# endif #else -"usage: cc1 [-cdfltw[-]] [-Ddefine] [-Iincdir] [-Uundef] [-o outfile] [infile]"); -#endif +# ifdef I80386 +"usage: cc1 [-03cdfltw[-]] [-o outfile] [infile]" +# else +"usage: cc1 [-cdfltw[-]] [-o outfile] [infile]" +# endif #endif + ); } diff -Nurd linux86.vold/bcc/input.h linux86/bcc/input.h --- linux86.vold/bcc/input.h 1996-11-02 14:23:58.000000000 +0000 +++ linux86/bcc/input.h 2004-06-20 09:20:46.000000000 +0100 @@ -26,13 +26,16 @@ EXTERN bool_t asmmode; /* nonzero when processing assembler code */ /* depends on zero init */ EXTERN char ch; /* current char */ -EXTERN bool_t cppmode; /* nonzero if acting as cpp not as compiler */ EXTERN bool_t eofile; /* nonzero after end of main file reached */ /* depends on zero init */ EXTERN struct fcbstruct input; /* current input file control block */ /* input.lineptr is not kept up to date */ EXTERN char *lineptr; /* ptr to current char */ + +#ifdef BUILTIN_CPP +EXTERN bool_t cppmode; /* nonzero if acting as cpp not as compiler */ EXTERN maclev_t maclevel; /* nest level of #defined identifiers */ /* depends on zero init */ EXTERN bool_t orig_cppmode; /* same as cppmode ex. not varied while in # */ EXTERN bool_t virtual_nl; /* For -C and asm, don't print first nl */ +#endif diff -Nurd linux86.vold/bcc/longop.c linux86/bcc/longop.c --- linux86.vold/bcc/longop.c 1998-01-11 12:18:35.000000000 +0000 +++ linux86/bcc/longop.c 2004-06-03 20:43:51.000000000 +0100 @@ -39,7 +39,8 @@ else scalar |= source->type->scalar; if ((source->indcount == 0 && !shiftflag) || - source->storage & (DREG | OPREG | OPWORKREG)) + source->type->scalar & CHAR || + source->storage & (BREG | DREG | OPREG | OPWORKREG)) { pres2(source, target); push(source); @@ -60,6 +61,16 @@ if (source->offset.offv == 0) goto shiftdone; } +#ifdef I8088 + /* This is ugly! But it works. I should be able to stop it being used + * by removing the char demotion. */ + if (source->type->scalar & CHAR && + !(source->storage & (BREG|DREG|DATREG1B))) { + load(source, DATREG1B); + outop2str("xor\tch,ch"); outnl(); + source->storage = DATREG1; + } +#endif load(source, OPWORKREG); switch ((op_t) op) { diff -Nurd linux86.vold/bcc/Makefile linux86/bcc/Makefile --- linux86.vold/bcc/Makefile 2001-01-06 09:55:53.000000000 +0000 +++ linux86/bcc/Makefile 2004-06-20 18:15:21.000000000 +0100 @@ -4,18 +4,19 @@ # PREFIX=/usr -LIBPRE=$(PREFIX) CFLAGS =-O LDFLAGS =-s BINDIR =$(PREFIX)/bin -LIBDIR =$(LIBPRE)/lib/bcc -BCCDEFS =-DLOCALPREFIX=$(LIBPRE) -DBINDIR=$(BINDIR) -DDEFARCH=0 +LIBDIR =$(PREFIX)/lib/bcc +BCCDEFS =-DLOCALPREFIX=$(PREFIX) -DBINDIR=$(BINDIR) -DDEFARCH=0 -OBJS = bcc-cc1.o codefrag.o debug.o declare.o express.o exptree.o floatop.o \ +BCFLAGS=$(ANSI) $(CFLAGS) $(LDFLAGS) + +OBJS = bcc-cc1.o codefrag.o dbnode.o declare.o express.o exptree.o floatop.o \ function.o gencode.o genloads.o glogcode.o hardop.o input.o label.o \ loadexp.o longop.o output.o preproc.o preserve.o scan.o softop.o \ - state.o table.o type.o assign.o + state.o table.o type.o assign.o hashcmd.o debug.o dbprintf.o all: bcc-cc1 bcc @@ -26,20 +27,26 @@ install -m 755 bcc-cc1 $(LIBDIR)/bcc-cc1 bcc: bcc.c - $(CC) $(ANSI) $(CFLAGS) $(BCCDEFS) $(LDFLAGS) $^ -o $@ + $(CC) $(BCFLAGS) $(BCCDEFS) bcc.c -o $@ ncc: bcc.c - $(CC) $(ANSI) $(CFLAGS) -DL_TREE -DDEFARCH=0 $(LDFLAGS) $^ -o $@ + $(CC) $(BCFLAGS) -DLOCALPREFIX= -DDEFARCH=0 bcc.c -o $@ bcc09: bcc.c - $(CC) $(ANSI) $(CFLAGS) -DMC6809 $(BCCDEFS) $(LDFLAGS) $^ -o $@ + $(CC) $(BCFLAGS) -DMC6809 $(BCCDEFS) bcc.c -o $@ ccc: bcc.c - $(CC) $(ANSI) $(CFLAGS) -DCCC $(BCCDEFS) $(LDFLAGS) $^ -o $@ + $(CC) $(BCFLAGS) -DCCC $(BCCDEFS) bcc.c -o $@ bcc-cc1: $(OBJS) $(CC) $(BCCARCH) $(LDFLAGS) $(OBJS) -o bcc-cc1 +debug.o: debug.c debug.h + $(CC) $(ANSI) $(BCCARCH) $(CFLAGS) -c debug.c + +dbprintf.o: dbprintf.c + $(CC) $(ANSI) $(BCCARCH) $(CFLAGS) -c dbprintf.c + clean realclean: rm -f bcc bcc-cc1 ncc bcc09 ccc bcc.o $(OBJS) diff -Nurd linux86.vold/bcc/misc/sformat linux86/bcc/misc/sformat --- linux86.vold/bcc/misc/sformat 1987-07-27 08:06:34.000000000 +0100 +++ linux86/bcc/misc/sformat 1970-01-01 01:00:00.000000000 +0100 @@ -1,56 +0,0 @@ -int x; -.comm _x,2 - -int x = 1; -.global _x -.data -_x: -1 - -static int x; -.bss -_x: -.=.+2 - -static int x = 1; -.bss | implicit -.data -_x: -1 - -char x[10]; -.comm _x,12 - -char x[10] = "1"; -.globl _x -.data -_x: -.byte 61,0 -.=.+10 - -static char x[10]; -.bss; -_cc: -.=.+12 - -static char x[10] = "1"; -.data -_x: -.byte 61,0 -.=.+10 - -test() -.globl _test -.text -_test: - -{ -static int x; -.bss -L3: -.=.+2 - -static int x = 1; -.bss -.data -L5:1 diff -Nurd linux86.vold/bcc/misc/test/8queens.pas linux86/bcc/misc/test/8queens.pas --- linux86.vold/bcc/misc/test/8queens.pas 1986-04-09 11:24:36.000000000 +0100 +++ linux86/bcc/misc/test/8queens.pas 1970-01-01 01:00:00.000000000 +0100 @@ -1,33 +0,0 @@ -program eightqueens; - -var i: integer; - a: array[ 1..8 ] of boolean; - b: array[ 2..16] of boolean; - c: array[-7..7 ] of boolean; - x: array[ 1..8 ] of integer; - -procedure print; -var k: integer; -begin - for k:= 1 to 8 do write(x[k]:4); - writeln; -end; - -procedure try(i: integer); -var j: integer; -begin - for j:= 1 to 8 do if a[j] and b[i+j] and c[i-j] then - begin - x[i]:= j; - a[j]:= false; b[i+j]:= false; c[i-j]:= false; - if i < 8 then try(i+1) else print; - a[j]:= true; b[i+j]:= true; c[i-j]:= true; - end; -end; - -begin - for i:= 1 to 8 do a[i]:= true; - for i:= 2 to 16 do b[i]:= true; - for i:= -7 to 7 do c[i]:= true; - try(1); -end. diff -Nurd linux86.vold/bcc/misc/test/8queens.t linux86/bcc/misc/test/8queens.t --- linux86.vold/bcc/misc/test/8queens.t 1986-04-28 10:45:59.000000000 +0100 +++ linux86/bcc/misc/test/8queens.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,74 +0,0 @@ -/* 8queens - straightforward translation of pascal version */ - -#define TRUE 1 -#define FALSE 0 - -int i; -char a[8],b[15],c[15],x[8]; - -main() -{ - for (i=0;i<8;i++) - a[i]=TRUE; - for (i=0;i<15;i++) - b[i]=TRUE; - for (i=0;i<15;i++) - c[i]=TRUE; - try(0); -} - -print() -{ - int k; - - for (k=0;k<8;k++) - write(x[k]); - writeln(); -} - -write(i) -int i; -{ - { -#asm - LDA #$20 - JSR $E820 - LDD .i,S - JSR $C682 -#endasm - } -} - -writeln() -{ - { -#asm - LDA #13 - JSR $E820 - LDA #10 - JSR $E820 -#endasm - } -} - -try(i) -int i; -{ - int j; - - for(j=0;j<8;j++) - if (a[j] && b[i+j] && c[7+i-j]) - { - x[i]=j; - a[j]=FALSE; - b[i+j]=FALSE; - c[7+i-j]=FALSE; - if (i<7) - try(i+1); - else - print(); - a[j]=TRUE; - b[i+j]=TRUE; - c[7+i-j]=TRUE; - } -} diff -Nurd linux86.vold/bcc/misc/test/atol.t linux86/bcc/misc/test/atol.t --- linux86.vold/bcc/misc/test/atol.t 1987-07-14 01:48:36.000000000 +0100 +++ linux86/bcc/misc/test/atol.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,29 +0,0 @@ -/* atol.c - long atol( char *s ) */ - -/* atol converts s to a long */ -/* leading spaces and tabs are ignored, an optional sign is recognised, */ -/* and the digits (0 to 9) following determine the long */ - -long atol( s ) -register char *s; -{ - char signflag; - long number; - - while ( *s == ' ' || *s == '\t') - s++; - signflag = 0; - if ( *s == '+' ) - s++; - else if ( *s == '-' ) - { - signflag = 1; - s++; - } - number = 0; - while ( *s >= '0' && *s <= '9' ) - number = 10 * number + *s++ - '0'; - if ( signflag ) - return -number; - return number; -} diff -Nurd linux86.vold/bcc/misc/test/bigsievec.t linux86/bcc/misc/test/bigsievec.t --- linux86.vold/bcc/misc/test/bigsievec.t 1988-08-13 18:19:06.000000000 +0100 +++ linux86/bcc/misc/test/bigsievec.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,29 +0,0 @@ -#define TRUE 1 -#define FALSE 0 -#define NITER 10 -#define SIZE 100000 - -char flags[SIZE+1]; - -main() -{ - int i,prime,k,count,iter; - - for (iter=0;iter 100) && (k < 0 || n > 50)) - i = 1; -} - -struct complex -{ - int re; - int im; -} - znum, *zptr, zarr[10], *zptrarr[10]; - -test10() -{ - int i; - - znum.re = i; - znum.im = 1; - zptr -> re = 1; - zptr -> im = i; - zarr[3].im = i; - zptrarr[4] -> im = 1; -} - -test11() -{ - char symtab[100]; - - char *p; - - if (p > symtab) - ; -} - -test12() -{ -char symtab[100]; - - char *p; - - p = symtab - 21; -} - -test13() -{ - char a[10]; - int i; - - i = a - 1; -} - -test14() -{ - int i, **pi; - - **pi = i; -} - -test15() -{ - int i, j; - - if ( (i = j ) == 2 ) - test(); -} - -test16() -{ - struct cx3 - { - int re3; - char im3; - } - z[10], *pz, *pz1; - int i; - - i = z[i].re3; - i = pz1 - pz; -} - -test17() -{ - int i; - char c; - - c &= ~i; -} - -test18() -{ - typedef int (*PFI)(); - PFI h(); - - (*h())( 0 ); -} - -test19() -{ - register int *p, *q; - int ***z,i,a[10]; - - test(***z + a[i]); -} - -char a[2][3][5]; - -char *p = a; -char *q = a[1]; -char *r = a[1][2]; - -char test20(); -char (*test21)(); - -test22() -{ - char i,k; - char *p; - - p = a; - p = a[1]; - p = a[1][2]; - p = a[k]; - p = a[k][k]; - i = sizeof a; - i = sizeof a[k]; - i = sizeof a[k][k]; - i = sizeof test20; - i = sizeof test21; - i = sizeof test20(); - i = sizeof (*test21)(); -} - -test23() -{ - long *pl; - int i; - char *s; - - *pl += i; - *s += *pl; -} - -test24() -{ - float f; - double *dp1(), *dp2(); - - f = *dp1()++; /* illegal */ - f = *++dp1(); /* illegal */ - f = *dp1() + *dp2(); /* bad code (pushes ptr to doubly indirect) */ -} - -test25() -{ - test25( "2"[1] ); /* added 1 to label number, not label address */ -} - -struct stat -{ - int st_dev; -}; - -test26( buf ) -struct stat buf; /* wrong declare, s.b. struct stat *buf */ -{ - buf->st_dev = 1; /* error caused null pointer to be dereferenced */ -} - -union -{ - long l; -} - test27; - -test28() -{ - test27.l = test27.l + 1; /* produced poor code */ -} - -int test29 = (char) 1; /* cast was clobbering the global symptr */ - -struct { int i; } test30; - -test31() -{ - return test30; /* a structure cannot be returned (yet) */ -} - -int *test32, test33() {} /* this is illegal */ - -test35() -{ - char a[1]; - char b[1]; - int i; - - i = i == 1 ? a : b; /* arrays were not converted to ptrs */ -} - -test36() -{ - struct fp - { - struct filp *fp_filp[1]; - }; - struct filp - { - int filp_int; - long filp_long; - }; - int i; - register char *junk; - register struct fp *cp; - - cp->fp_filp[i]->filp_int++; /* used to push lvalue */ - cp->fp_filp[i]->filp_long++; /* used to push lvalue */ - cp->fp_filp[i]->filp_int += 1; /* was OK */ - cp->fp_filp[i]->filp_long += 1; /* used to load long into DREG:DREG */ -} - -test37() -{ - unsigned u; - - u = -u; /* used to give botched nodetype */ -} - -test38() -{ - char c; - int i; - - i = -c; /* did i = (char) -c for a time */ -} - -test39() -{ - int i; - - i = (char) 1000; /* the constant wasn't being truncated */ -} - -#define test40(x) (x) - -test41() -{ - int i; - int j; - int k; - - i = test40( j + /* was confused by EOL in macro argument */ - k ); -} - -test42() -{ - register char *junk1; - register char *junk2; - long *longptr; - long longfn(); - - *longptr = longfn(); /* used to run out of index regs */ -} - -test43() -{ - register char *jnk1, *junk2; - unsigned char *bp; - struct FILE_BUF - { - char *bufp; - } *op; - - *op->bufp++ = *bp; /* used to push lvalue */ -} - -test44() -{ - register char *x, *y; - int i; - char a[2]; - char **p; - - a[**p] = **p; /* used to push lvalue */ -} - -struct test45 -{ - int i; - int j; -} test45[10]; - -test46() -{ - register char *p, *q; - int i; - int j; - - test45[i] = test45[j]; /* used to push lvalue */ -} - -int (*test100( x )() {} /* this is legal, keep last avoid swallowing */ diff -Nurd linux86.vold/bcc/misc/test/cast1.t linux86/bcc/misc/test/cast1.t --- linux86.vold/bcc/misc/test/cast1.t 1991-10-01 21:12:28.000000000 +0100 +++ linux86/bcc/misc/test/cast1.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,144 +0,0 @@ -/* cast1.t */ - -char c; -unsigned char uc; -short s; -unsigned short us; -int i; -unsigned int ui; -long l; -unsigned long ul; -float f; -double d; -int *p; - -cast() -{ - c = c; - uc = c; - s = c; - us = c; - i = c; - ui = c; - l = c; - ul = c; - f = c; - d = c; - p = c; - - c = uc; - uc = uc; - s = uc; - us = uc; - i = uc; - ui = uc; - l = uc; - ul = uc; - f = uc; - d = uc; - p = uc; - - c = s; - uc = s; - s = s; - us = s; - i = s; - ui = s; - l = s; - ul = s; - f = s; - d = s; - p = s; - - c = us; - uc = us; - s = us; - us = us; - i = us; - ui = us; - l = us; - ul = us; - f = us; - d = us; - p = us; - - c = i; - uc = i; - s = i; - us = i; - i = i; - ui = i; - l = i; - ul = i; - f = i; - d = i; - p = i; - - c = ui; - uc = ui; - s = ui; - us = ui; - i = ui; - ui = ui; - l = ui; - ul = ui; - f = ui; - d = ui; - p = ui; - - c = l; - uc = l; - s = l; - us = l; - i = l; - ui = l; - l = l; - ul = l; - f = l; - d = l; - p = l; - - c = ul; - uc = ul; - s = ul; - us = ul; - i = ul; - ui = ul; - l = ul; - ul = ul; - f = ul; - d = ul; - p = ul; - - c = f; - uc = f; - s = f; - us = f; - i = f; - ui = f; - l = f; - ul = f; - f = f; - d = f; - - c = d; - uc = d; - s = d; - us = d; - i = d; - ui = d; - l = d; - ul = d; - f = d; - d = d; - - c = p; - uc = p; - s = p; - us = p; - i = p; - ui = p; - l = p; - ul = p; - p = p; -} diff -Nurd linux86.vold/bcc/misc/test/castest.t linux86/bcc/misc/test/castest.t --- linux86.vold/bcc/misc/test/castest.t 1987-06-29 01:57:09.000000000 +0100 +++ linux86/bcc/misc/test/castest.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,74 +0,0 @@ -/* castest.c */ - -/* -#define signedchar -#define bigints -*/ -#define unsigchar -#define unsigshort -#define unsiglong - -#define TEST(u,c) if ( (u) != (c) )\ - { printf( "u != c\n" ); ++bad; } ++possible - -main() -{ - int bad; - int possible; - char c; -#ifdef signedchar - signed char sc; -#endif -#ifdef unsigchar - unsigned char uc; -#endif - short s; -#ifdef unsigshort - unsigned short us; -#endif - int i; - unsigned u; - long l; -#ifdef unsiglong - unsigned long ul; -#endif - - bad = possible = 0; - u = 0x1ff; - c = (char) u; - if ( c < 0 ) - printf( "characters are signed\n" ); - TEST((char)u,c); - i = (int)(char) u; - TEST(i,(int)c); - TEST((int)(char)u,i); - -#ifdef signedchar - sc = (signed char) u; - if ( sc >= 0 ) - printf( "??? signed char not signed\n" ); - TEST((signed char)u,sc); - TEST((int)(signed char)u,(int)sc); - i = (int) sc; - TEST((int)(signed char)u,i); -#endif - -#ifdef bigints - u = 0x1ffff; - s = (short) u; - TEST((short)u,s); - TEST((int)(short)u,(int)s); - i = (int) s; - TEST((int)(short)u,i); - -#ifdef unsigshort - us = (unsigned short) u; - TEST((unsigned short)u,us); - TEST((int)(unsigned short)u,(int)us); - i = (int) us; - TEST((int)(unsigned short)u,i); -#endif -#endif - - printf( "%d bad out of a possible %d\n", bad, possible ); -} diff -Nurd linux86.vold/bcc/misc/test/cast.t linux86/bcc/misc/test/cast.t --- linux86.vold/bcc/misc/test/cast.t 1991-11-21 19:24:50.000000000 +0000 +++ linux86/bcc/misc/test/cast.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,144 +0,0 @@ -/* cast.t */ - -char c; -unsigned char uc; -short s; -unsigned short us; -int i; -unsigned int ui; -long l; -unsigned long ul; -float f; -double d; -int *p; - -cast() -{ - c = (char) c; - uc = (unsigned char) c; - s = (short) c; - us = (unsigned short) c; - i = (int) c; - ui = (unsigned int) c; - l = (long) c; - ul = (unsigned long) c; - f = (float) c; - d = (double) c; - p = (int *) c; - - c = (char) uc; - uc = (unsigned char) uc; - s = (short) uc; - us = (unsigned short) uc; - i = (int) uc; - ui = (unsigned int) uc; - l = (long) uc; - ul = (unsigned long) uc; - f = (float) uc; - d = (double) uc; - p = (int *) uc; - - c = (char) s; - uc = (unsigned char) s; - s = (short) s; - us = (unsigned short) s; - i = (int) s; - ui = (unsigned int) s; - l = (long) s; - ul = (unsigned long) s; - f = (float) s; - d = (double) s; - p = (int *) s; - - c = (char) us; - uc = (unsigned char) us; - s = (short) us; - us = (unsigned short) us; - i = (int) us; - ui = (unsigned int) us; - l = (long) us; - ul = (unsigned long) us; - f = (float) us; - d = (double) us; - p = (int *) us; - - c = (char) i; - uc = (unsigned char) i; - s = (short) i; - us = (unsigned short) i; - i = (int) i; - ui = (unsigned int) i; - l = (long) i; - ul = (unsigned long) i; - f = (float) i; - d = (double) i; - p = (int *) i; - - c = (char) ui; - uc = (unsigned char) ui; - s = (short) ui; - us = (unsigned short) ui; - i = (int) ui; - ui = (unsigned int) ui; - l = (long) ui; - ul = (unsigned long) ui; - f = (float) ui; - d = (double) ui; - p = (int *) ui; - - c = (char) l; - uc = (unsigned char) l; - s = (short) l; - us = (unsigned short) l; - i = (int) l; - ui = (unsigned int) l; - l = (long) l; - ul = (unsigned long) l; - f = (float) l; - d = (double) l; - p = (int *) l; - - c = (char) ul; - uc = (unsigned char) ul; - s = (short) ul; - us = (unsigned short) ul; - i = (int) ul; - ui = (unsigned int) ul; - l = (long) ul; - ul = (unsigned long) ul; - f = (float) ul; - d = (double) ul; - p = (int *) ul; - - c = (char) f; - uc = (unsigned char) f; - s = (short) f; - us = (unsigned short) f; - i = (int) f; - ui = (unsigned int) f; - l = (long) f; - ul = (unsigned long) f; - f = (float) f; - d = (double) f; - - c = (char) d; - uc = (unsigned char) d; - s = (short) d; - us = (unsigned short) d; - i = (int) d; - ui = (unsigned int) d; - l = (long) d; - ul = (unsigned long) d; - f = (float) d; - d = (double) d; - - c = (char) p; - uc = (unsigned char) p; - s = (short) p; - us = (unsigned short) p; - i = (int) p; - ui = (unsigned int) p; - l = (long) p; - ul = (unsigned long) p; - p = (int *) p; -} diff -Nurd linux86.vold/bcc/misc/test/ctype.t linux86/bcc/misc/test/ctype.t --- linux86.vold/bcc/misc/test/ctype.t 1987-06-29 01:57:11.000000000 +0100 +++ linux86/bcc/misc/test/ctype.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,38 +0,0 @@ -/* ctype.h */ - -#define _C 1 /* control */ -#define _D 2 /* digit */ -#define _L 4 /* lower */ -#define _P 8 /* punctuation */ -#define _S 16 /* space */ -#define _U 32 /* upper */ -#define _UN 64 /* underline */ -#define _X '\200' /* hex digit, not digit */ - -extern char _ctype_[]; - -#define _ct1_ (_ctype_+1) - -#define isalnum(c) (_ct1_[c]&(_U|_L|_D)) -#define isalpha(c) (_ct1_[c]&(_U|_L)) -#define isascii(i) ((unsigned)(i)<=0x7f) -#define isalpha(c) (_ct1_[c]&(_U|_L)) -#define iscntrl(c) (_ct1_[c]&_C) -#define iscsym(c) (_ct1_[c]&(_U|_L|_D|_UN)) -#define iscsymf(c) (_ct1_[c]&(_U|_L|_UN)) -#define isdigit(c) (_ct1_[c]&_D) -#define isgraph(c) (_ct1_[c]&(_U|_L|_D|_P)) -#define islower(c) (_ct1_[c]&_L) -/* isodigit(i) is a function */ -/* isprint(i) is a function */ -#define ispunct(c) (_ct1_[c]&_P) -#define isspace(c) (_ct1_[c]&_S) -#define isupper(c) (_ct1_[c]&_U) -#define isxdigit(c) (_ct1_[c]&(_D|_X)) - -#define toascii(i) ((i)&0x7f) -/* toint(i) is a function */ -/* tolower(i) is a function */ -#define _tolower(c) ((c)+('a'-'A')) -/* toupper(i) is a function */ -#define _toupper(c) ((c)+('A'-'a')) diff -Nurd linux86.vold/bcc/misc/test/error.t linux86/bcc/misc/test/error.t --- linux86.vold/bcc/misc/test/error.t 1987-06-29 01:57:13.000000000 +0100 +++ linux86/bcc/misc/test/error.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,78 +0,0 @@ -static char *errorstring[] = -{ - "# in a macro: not preprocessed", - "already declared", - "array of functions is illegal", - "bad address", - "bad case label", - "bad character constant", - "bad character", - "bad control", - "bad default label", - "bad expression", - "bad file name", - "bad indirection count", - "bad initializer address", - "bad register store", - "call of non-function", - "can't continue in switch", - "can't index", - "can't load char to index reg", - "can't open", - "can't open input", - "can't open output", - "case can't be reached with char switch", - "constant expression expected", - "else without if", - "end of file in #asm", - "end of file in #define", - "end of file in comment", - "end of file in failed #if", - "end of file in macro parameter expansion", - "end of file in string constant", - "end of line in string constant", - "endif without if", - "function returning array is illegal", - "function returning function is illegal", - "function returning structure is illegal", - "if stack overflow", - "illegal indirection", - "illegal macro name", - "illegal non-external function", - "illegal symbol name", - "illegal type conversion", - "illegal type name", - "initializer too complicated", - "input error", - "load of long constants not implemented", - "loading direct long with offset not implemented", - "local symbol table overflow", - "macro stack overflow", - "missing '('", - "missing while at end of do-while", - "need '", - "need int or char", - "need lvalue", - "need scalar or ptr type", - "need structure", - "no active fors, switches or whiles", - "not in a compound statement", - "null dimension", - "out of index registers", - "redefined macro", - "repeated argument", - "repeated default label", - "repeated parameter", - "table full", - "too few macro parameters", - "too many active whiles", - "too many cases", - "too many macro parameters", - "too many open compound statements", - "too many parameters", - "undeclared variable", - "undefined structure element", - "undefined structure", - "unsigned ints only", - "variable not in argument list" -}; diff -Nurd linux86.vold/bcc/misc/test/extern.t linux86/bcc/misc/test/extern.t --- linux86.vold/bcc/misc/test/extern.t 1986-05-04 13:48:10.000000000 +0100 +++ linux86/bcc/misc/test/extern.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,236 +0,0 @@ -/* extern.c - external declarations (K & R p218-9) */ - -#include "def.h" -#include "globvar.h" -#include "symbol.h" - -struct typestruct *declarator(); -struct typestruct *extypespec(); -int paramlist(); -struct typestruct *typespec(); - -/*============================================================================= - -- notation is 1st attempt at EBNF (see Modula-2 book) - program = { type-definition | function-or-data-definition }. - type-definition = "typedef" type-definition-list. -=============================================================================*/ - -program() -{ - nextsym(); - while ( sym != EOFSYM ) - { - if ( sym = TYPEDEFDECL ) - deftypes(); - else - functordata(); - } -} - -/*============================================================================= - type-definition-list. -- not implemented -=============================================================================*/ - -deftypes() -{} - -/*============================================================================= - function-or-data-definition = external-type-specification - ( function-definition | init-declarators ). - function-definition = "(" parameter-list ")" arg-list compound-statement. - -- this is different from K & R who omit typedefs and static functions -=============================================================================*/ - -functordata() -{ - struct typestruct *type; - int nargs; - - type = extypespec(); - if ( sym == LPAREN ) - { - nextsym(); - nargs = paramlist(); - need( RPAREN ); - arglist( nargs ); - need( LBRACE ); - compound( 1 + locptr-pstartloc );/* 1 = function flag, rest = nargs */ - oldlevel(); - } - else - initdecl( type ); -} - -/*============================================================================= - external-type-specification = extern-sc type-specifier declarator. - extern-sc = [ extern | static ]. -=============================================================================*/ - -struct typestruct *extypespec() -{ - int sc; - - switch( sym ) - { - case EXTERNDECL: - case STATICDECL: - sc = sym; nextsym(); break; - default: - sc = EXTERNDECL; break; - } - return declarator( typespec() ); -} - -/*============================================================================= - parameter-list = [identifier { "," identifier }]. -=============================================================================*/ - -int paramlist() -{ - int nargs; - - locptr = pstartloc; - newlevel(); - nargs = 0; - while ( sym == IDENT ) - { - addloc( gsname, itype, 0 ); /* fix up types and offsets later */ - nextsym(); - ++nargs; - if ( sym != COMMA ) - break; - nextsym(); - } - return nargs; -} - -/*============================================================================= - arg-list = -=============================================================================*/ - -arglist( nargs ) -int nargs; -{ - struct symstruct *symptr; - int argsize, argsp; - int lastsym; - struct typestruct *basetype; - char declflag; - - declflag = TRUE; - do - { - switch( sym ) - { - case TYPEDECL: - basetype = gsymptr->type; - nextsym(); - getarg1( basetype ); - break; - case STRUCTDECL: - case UNIONDECL: - lastsym = sym; - nextsym(); - getarg( declsu( lastsym ) ); - break; - case AUTODECL: - case EXTERNDECL: - case REGDECL: - case STATICDECL: - case SEMICOLON: - nextsym(); - break; - default: - declflag = FALSE; - break; - } - } - while ( declflag ); - argsp = -2; - symptr = pstartloc; - while ( nargs && symptr < locptr ) /* convert arg sizes to offsets */ - { - argsize = symptr->offset; - if ( symptr->type == ctype ) - { - ++argsp; - --argsize; - } - symptr->offset = argsp; - argsp += argsize; - if ( symptr == pstartloc ) - argsp += 2; - --nargs; - ++symptr; - } - if ( nargs ) - error( "arguments not all declared" ); -} - -/* getarg( basetype ) - fill in argument types and sizes */ - -getarg1( basetype ) -struct typestruct *basetype; -{ - char sname[NAMESIZE]; - struct typestruct *type; - int size; - struct symstruct *symptr; - - if ( sym != SEMICOLON ) - while ( TRUE ) - { - type = basetype; - size = getvar( sname, &type ); - if ( (symptr = findlorg( sname )) == NULL || symptr->level != ARGLEVEL ) - error( "variable not in argument list" ); - else if ( symptr->offset != 0 ) /* already in arg list */ - multidecl( sname, type, symptr ); - else - { - if ( size < 2 || type->typeop == ATYPEOP ) - size = 2; - symptr->offset = size; - symptr->type = type; - } - if ( sym == COMMA ) - nextsym(); - else - break; - } - ns(); -} - -struct typestruct *declarator( basetype ) -struct typestruct *basetype; -{ - char sname[NAMESIZE]; - int size; - struct symstruct *multi; - - size = getvar( sname, &type ); - if ( multi = findlorg( sname ) ) - multidecl( sname, type, multi ); - else - addglb( sname, type, size ); - nextsym(); -} - -struct typestruct *typespec() -{ - int lastsym; - - switch( sym ) - { - case TYPEDECL: - nextsym(); - return gsymptr->type; - case STRUCTDECL: - case UNIONDECL: - lastsym = sym; - nextsym(); - return declsu( lastsym ); - default: - return itype; - } -} diff -Nurd linux86.vold/bcc/misc/test/hilbert.t linux86/bcc/misc/test/hilbert.t --- linux86.vold/bcc/misc/test/hilbert.t 1986-07-07 01:37:00.000000000 +0100 +++ linux86/bcc/misc/test/hilbert.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,169 +0,0 @@ -/* hilbert.c */ - -/* S1 stuff - -#define PIFBUF ( *(struct IFBUF **) 0xf010 ) -#define PSET 2 - -struct IFBUF -{ - char ERR; - char COMMAND; - char COLOR; - char PLOTOPTION; - int LINESTYLE; - int X1; - int Y1; - int X2; - int Y2; - char BFFLAG; -}; -end of S1 stuff */ - -/* L3 stuff */ - -#define PIFBUF ( (struct IFBUF *) 0xa1 ) -#define PSET 1 - -struct IFBUF -{ - char PLOTOPTION; - char junk1[0xa8-0xa2]; - int X1; - int Y1; - int X2; - int Y2; - char junk2[0xf0-0xb0]; - char ERR; /* this to BFFLAG are dummies to keep S1 code */ - char COMMAND; - int LINESTYLE; - char BFFLAG; - char junk3[0x3ea-0xf5]; - char COLOR; -}; - -#define H0 512 /* square size */ -#define XOFFS 80 /* offset to centre square */ -#define XNUM 15 /* scale 512 * 15/16 = 480 */ -#define XDENOM 16 -#define YNUM 25 /* scale 512 * 25/64 = 200 */ -#define YDENOM 64 /* to give max height, dot ratio 480/200 = 2.4 */ - -int h, x, y; - -main() -{ - int i, x0, y0; - char color; - - PIFBUF->PLOTOPTION = PSET; - PIFBUF->LINESTYLE = /* normal */ - PIFBUF->COMMAND = /* ?? */ - PIFBUF->BFFLAG = 0; /* not a box */ - color = i = 0; - x0 = y0 = (h = H0)/2; - while ( h > 1 ) - { - ++i; - h = h/2; - if ( ++color > 7 ) - color = 1; - gcolor( color ); - x = x0 += h/2; - y = y0 += h/2; - glocate(); - a( i ); - } -} - -a( i ) -int i; -{ - if ( --i >= 0 ) - { - d( i ); x -= h; plot(); - a( i ); y -= h; plot(); - a( i ); x += h; plot(); - b( i ); - } -} - -b( i ) -int i; -{ - if ( --i >= 0 ) - { - c( i ); y += h; plot(); - b( i ); x += h; plot(); - b( i ); y -= h; plot(); - a( i ); - } -} - -c( i ) -int i; -{ - if ( --i >= 0 ) - { - b( i ); x += h; plot(); - c( i ); y += h; plot(); - c( i ); x -= h; plot(); - d( i ); - } -} - -d( i ) -int i; -{ - if ( --i >= 0 ) - { - a( i ); y -= h; plot(); - d( i ); x -= h; plot(); - d( i ); y += h; plot(); - c( i ); - } -} - -glocate() -{ - PIFBUF->X2 = x - x * (XDENOM - XNUM) / XDENOM + XOFFS; - PIFBUF->Y2 = (y * YNUM) / YDENOM; -} - -/* S1 gcolor and plot - -gcolor( color ) -int color; -{ - PIFBUF->COLOR = color; -} - -plot() -{ - PIFBUF->X1 = PIFBUF->X2; - PIFBUF->Y1 = PIFBUF->Y2; - glocate(); -#asm - SWI2 - FDB $4201 call LINEMA -#endasm -} - -end S1 plot */ - -gcolor( color ) -int color; -{ - PIFBUF->COLOR = color | 0x10; -} - -plot() -{ - PIFBUF->X1 = PIFBUF->X2; - PIFBUF->Y1 = PIFBUF->Y2; - glocate(); -#asm - JSR $D709 - JSR $D79A -#endasm -} diff -Nurd linux86.vold/bcc/misc/test/longtest.c linux86/bcc/misc/test/longtest.c --- linux86.vold/bcc/misc/test/longtest.c 1987-12-30 06:12:14.000000000 +0000 +++ linux86/bcc/misc/test/longtest.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,24 +0,0 @@ -int i,j; -long m,n; - -main() -{ - while ( 1 ) - { - if ( scanf( "%ld %ld", &m, &n ) <= 0 ) - exit( 0 ); - printf( "m = %ld n = %ld m + n = %ld m - n = %ld m * n = %ld\n", - m, n, m + n, m - n, m * n ); - printf( "m = %ld n = %ld m / n = %ld m %% n = %ld\n", - m, n, m / n, m % n ); - printf( "m = %ld n = %ld m&n = %ld m | n = %ld m^n = %ld\n", - m, n, m & n, m | n, m ^ n ); - printf( "m = %ld n = %ld m << n = %ld m >> n = %ld\n", - m, n, m << (int) n, m >> (int) n ); - printf( - "m = %ld n = %ld m < n is %d m == n is %d m > n is %d m == 0 is %d\n", - m, n, m < n, m == n, m > n, m == 0 ); - printf( "m = %ld n = %ld -m = %ld ~m = %ld ++m = %ld --n = %ld\n", - m, n, -m, ~m, ++m, --n ); - } -} diff -Nurd linux86.vold/bcc/misc/test/longtest.dat linux86/bcc/misc/test/longtest.dat --- linux86.vold/bcc/misc/test/longtest.dat 1987-12-30 06:10:33.000000000 +0000 +++ linux86/bcc/misc/test/longtest.dat 1970-01-01 01:00:00.000000000 +0100 @@ -1,15 +0,0 @@ -1 1 --1 1 -1 -1 --1 -1 -2 3 -4 5 -234234 34554 -4534534 34535 -345324523 3245325 -345435345 319755 -34534 345 --352351235 23535 -533512351 -3535345 --351351313 -12235 -123456789 987654321 diff -Nurd linux86.vold/bcc/misc/test/longtest.mak linux86/bcc/misc/test/longtest.mak --- linux86.vold/bcc/misc/test/longtest.mak 1987-12-30 05:28:16.000000000 +0000 +++ linux86/bcc/misc/test/longtest.mak 1970-01-01 01:00:00.000000000 +0100 @@ -1,3 +0,0 @@ -cc -o cclongtest longtest.c -sc longtest.c sclongtest.s -cc -o sclongtest sclongtest.s $HOME/lib/libcb.a $HOME/lib/liblb.a diff -Nurd linux86.vold/bcc/misc/test/longtest.sh linux86/bcc/misc/test/longtest.sh --- linux86.vold/bcc/misc/test/longtest.sh 1987-09-21 11:51:28.000000000 +0100 +++ linux86/bcc/misc/test/longtest.sh 1970-01-01 01:00:00.000000000 +0100 @@ -1,4 +0,0 @@ -./sclongtest < longtest.dat >scl.out -./cclongtest < longtest.dat >ccl.out -diff scl.out ccl.out >longtest.diff -cat longtest.diff diff -Nurd linux86.vold/bcc/misc/test/miniltest.t linux86/bcc/misc/test/miniltest.t --- linux86.vold/bcc/misc/test/miniltest.t 1987-11-16 02:21:01.000000000 +0000 +++ linux86/bcc/misc/test/miniltest.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,72 +0,0 @@ -long x; -int i; -unsigned u; - -long test1(x) -long x; -{ - return x; -} - -long test2(x) -int x; -{ - return x; -} - -main() -{ - printlong( "x=1 is ", x = 1 ); - printlong( "test1(x) is ", test1(x) ); - printlong( "test1(1L) is ", test1(1L) ); - printlong( "x = test1(1L) is ", x = test1(1L) ); - printlong( "x = test1(x=1) is ", x = test1(x=1) ); - printlong( "i=1 is ", (long) (i = 1) ); - printlong( "test2(i) is ", test2(i) ); - printlong( "test2(1) is ", test2(1) ); - printlong( "i = test2(1) is ", (long) (i = test2(1)) ); - printlong( "i = test2(i=1) is ", (long) (i = test2(i=1)) ); - printlong( "(long) (i = -1) is ", (long) (i=-1) ); - printlong( "(long) (u = -1) is ", (long) (u=-1) ); - printlong( "x = -1 is ", x = -1 ); -} - -printlong( s, x ) -char *s; -long x; -{ - printf( "%s", s ); - if ( x & 0x80000000 ) - { - putchar( '-' ); - x = -x; - } - printf( "%08lx", (x >> 16) + (x << 16) ); - putchar( '\n' ); -} - -outulhex( pnum ) -char *pnum; -{ - int i; - - for ( i = 3; i >=0; --i ) - p2( pnum[i] ); -} - -p2(i) -int i; -{ - p1(i>>4); - p1(i); -} - -p1(num) -int num; -{ - int digit; - - if ( (digit = num & 0xf) >= 10 ) - digit += 'A' - ('9' + 1); - putchar( digit + '0' ); -} diff -Nurd linux86.vold/bcc/misc/test/op1.t linux86/bcc/misc/test/op1.t --- linux86.vold/bcc/misc/test/op1.t 1986-10-10 15:04:00.000000000 +0100 +++ linux86/bcc/misc/test/op1.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,120 +0,0 @@ -/* op1.t - test and, or (eor same as or ) */ - -char cfn(); -int ifn(); - -char *op1() -{ - char c, *pc, **ppc; - int i, *pi, **ppi; - - i = c & 1; - i = 1 & c; - i = i & 1; - i = 1 & i; - - i = c & 500; - i = 500 & c; - i = i & 500; - i = 500 & i; - - i = c | 1; - i = 1 | c; - i = i | 1; - i = 1 | i; - - i = c | 500; - i = 500 | c; - i = i | 500; - i = 500 | i; - - i = c & c; - i = c & i; - i = i & c; - i = i & i; - - i = c | c; - i = c | i; - i = i | c; - i = i | i; - - i = c & c++; - i = c & i++; - i = i & c++; - i = i & i++; - - i = c++ & c; - i = i++ & c; - i = c++ & i; - i = i++ & i; - - i = c | c++; - i = c | i++; - i = i | c++; - i = i | i++; - - i = c++ | c; - i = i++ | c; - i = c++ | i; - i = i++ | i; - - i = c & cfn(); - i = c & ifn(); - i = i & cfn(); - i = i & ifn(); - - i = cfn() & c; - i = ifn() & c; - i = cfn() & i; - i = ifn() & i; - - i = c | cfn(); - i = c | ifn(); - i = i | cfn(); - i = i | ifn(); - - i = cfn() | c; - i = ifn() | c; - i = cfn() | i; - i = ifn() | i; - - i = *pc & c++; - i = *pc & i++; - i = *pi & c++; - i = *pi & i++; - - i = c++ & *pc; - i = i++ & *pc; - i = c++ & *pi; - i = i++ & *pi; - - i = *pc | c++; - i = *pc | i++; - i = *pi | c++; - i = *pi | i++; - - i = c++ | *pc; - i = i++ | *pc; - i = c++ | *pi; - i = i++ | *pi; - - i = **ppc & c++; - i = **ppc & i++; - i = **ppi & c++; - i = **ppi & i++; - - i = c++ & **ppc; - i = i++ & **ppc; - i = c++ & **ppi; - i = i++ & **ppi; - - i = **ppc | c++; - i = **ppc | i++; - i = **ppi | c++; - i = **ppi | i++; - - i = c++ | **ppc; - i = i++ | **ppc; - i = c++ | **ppi; - i = i++ | **ppi; -} diff -Nurd linux86.vold/bcc/misc/test/opcmp.t linux86/bcc/misc/test/opcmp.t --- linux86.vold/bcc/misc/test/opcmp.t 1986-10-28 05:15:24.000000000 +0000 +++ linux86/bcc/misc/test/opcmp.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,106 +0,0 @@ -/* opcmp.t - test logical compare operations */ - -/* only doing chars, shorts, ints and unsigneds */ -/* not doing longs, floats or doubles */ - -/* short = int, so only a few examples */ -/* unsigned like int, so only a few examples */ -/* all examples < */ - -op1() -{ - char c, *pc, **ppc, cfn(); - short s, *ps, **pps, sfn(); - int i, *pi, **ppi, ifn(); - unsigned u, *pu, **ppu, ufn(); - - c < 0; - 0 < c; - i < 0; - 0 < i; - - s < 0; - 0 < s; - - 0 < u; - u < 0; - 1 < u; - u < 1; - - c < 1; - 1 < c; - c < 500; - 500 < c; - - c < c; - c < i; - i < c; - i < i; - - s < c; - i < u; - - c < c++; - c < i++; - i < c++; - i < i++; - - s < i++; - c < u++; - - c++ < c; - i++ < c; - c++ < i; - i++ < i; - - s++ < c; - i++ < u; - - c < cfn(); - c < ifn(); - i < cfn(); - i < ifn(); - - s < cfn(); - c < ufn(); - - cfn() < c; - ifn() < c; - cfn() < i; - ifn() < i; - - sfn() < c; - ifn() < u; - - *pc < c++; - *pc < i++; - *pi < c++; - *pi < i++; - - *ps < c++; - *pi < u++; - - c++ < *pc; - i++ < *pc; - c++ < *pi; - i++ < *pi; - - s++ < *pc; - i++ < *pu; - - **ppc < c++; - **ppc < i++; - **ppi < c++; - **ppi < i++; - - **pps < c++; - **ppi < u++; - - c++ < **ppc; - i++ < **ppc; - c++ < **ppi; - i++ < **ppi; - - s++ < **ppc; - i++ < **ppu; -} diff -Nurd linux86.vold/bcc/misc/test/oplong.t linux86/bcc/misc/test/oplong.t --- linux86.vold/bcc/misc/test/oplong.t 1987-06-29 01:57:24.000000000 +0100 +++ linux86/bcc/misc/test/oplong.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,264 +0,0 @@ -/* oplong.t - test long operations */ - -/* this is just opsoft.t with int defined as long */ - -#define int long -#define UNSIGNED unsigned long - -/* only doing chars, shorts, ints and unsigneds */ -/* not doing longs, floats or doubles */ - -/* short = int, so only a few examples */ -/* unsigned like int, so only a few examples */ -/* most examples for DIVOP */ -/* only (all) special cases of MULOP, MODOP, SLOP and SROP are tried */ - -op1() -{ - char c, *pc, **ppc, cfn(); - short s, *ps, **pps, sfn(); - int i, *pi, **ppi, ifn(); - UNSIGNED u, *pu, **ppu, ufn(); - - i = c / 0; - i = 0 / c; - i = i / 0; - i = 0 / i; - - i = s / 0; - i = 0 / u; - - i = c / 1; - i = 1 / c; - i = i / 1; - i = 1 / i; - - i = s / 1; - i = 1 / u; - - i = c / 2; - i = 2 / c; - i = i / 2; - i = 2 / i; - - i = s / 2; - i = 2 / u; - - i = c / 500; - i = 500 / c; - i = i / 500; - i = 500 / i; - - i = s / 500; - i = 500 / u; - - i = c / c; - i = c / i; - i = i / c; - i = i / i; - - i = s / c; - i = i / u; - - i = c / c++; - i = c / i++; - i = i / c++; - i = i / i++; - - i = s / i++; - i = c / u++; - - i = c++ / c; - i = i++ / c; - i = c++ / i; - i = i++ / i; - - i = s++ / c; - i = i++ / u; - - i = c / cfn(); - i = c / ifn(); - i = i / cfn(); - i = i / ifn(); - - i = s / cfn(); - i = c / ufn(); - - i = cfn() / c; - i = ifn() / c; - i = cfn() / i; - i = ifn() / i; - - i = sfn() / c; - i = ifn() / u; - - i = *pc / c++; - i = *pc / i++; - i = *pi / c++; - i = *pi / i++; - - i = *ps / c++; - i = *pi / u++; - - i = c++ / *pc; - i = i++ / *pc; - i = c++ / *pi; - i = i++ / *pi; - - i = s++ / *pc; - i = i++ / *pu; - - i = **ppc / c++; - i = **ppc / i++; - i = **ppi / c++; - i = **ppi / i++; - - i = **pps / c++; - i = **ppi / u++; - - i = c++ / **ppc; - i = i++ / **ppc; - i = c++ / **ppi; - i = i++ / **ppi; - - i = s++ / **ppc; - i = i++ / **ppu; - - i = c * 0; - i = 0 * c; - i = i * 0; - i = 0 * i; - - i = s * 0; - i = 0 * u; - - i = c * 1; - i = 1 * c; - i = i * 1; - i = 1 * i; - - i = s * 1; - i = 1 * u; - - i = c * 2; - i = 2 * c; - i = i * 2; - i = 2 * i; - - i = s * 2; - i = 2 * u; - - i = c * 500; - i = 500 * c; - i = i * 500; - i = 500 * i; - - i = s * 500; - i = 500 * u; - - i = c * c; - i = c * c++; - i = c++ * c; - i = c * cfn(); - i = cfn() * c; - i = *pc * c++; - i = c++ * *pc; - i = **ppc * c++; - i = c++ * **ppc; - - i = c % 0; - i = 0 % c; - i = i % 0; - i = 0 % i; - - i = s % 0; - i = 0 % u; - - i = c % 1; - i = 1 % c; - i = i % 1; - i = 1 % i; - - i = s % 1; - i = 1 % u; - - i = c % 2; - i = 2 % c; - i = i % 2; - i = 2 % i; - - i = s % 2; - i = 2 % u; - - i = c % 500; - i = 500 % c; - i = i % 500; - i = 500 % i; - - i = s % 500; - i = 500 % u; - - i = c << 0; - i = 0 << c; - i = i << 0; - i = 0 << i; - - i = s << 0; - i = 0 << u; - - i = c << 1; - i = 1 << c; - i = i << 1; - i = 1 << i; - - i = s << 1; - i = 1 << u; - - i = c << 8; - i = 8 << c; - i = i << 8; - i = 8 << i; - - i = s << 8; - i = 8 << u; - - i = c << 9; - i = 9 << c; - i = i << 9; - i = 9 << i; - - i = s << 9; - i = 9 << u; - - i = c >> 0; - i = 0 >> c; - i = i >> 0; - i = 0 >> i; - - i = s >> 0; - i = 0 >> u; - - i = c >> 1; - i = 1 >> c; - i = i >> 1; - i = 1 >> i; - - i = s >> 1; - i = 1 >> u; - - i = c >> 8; - i = 8 >> c; - i = i >> 8; - i = 8 >> i; - - i = s >> 8; - i = 8 >> u; - - i = c >> 9; - i = 9 >> c; - i = i >> 9; - i = 9 >> i; - - i = s >> 9; - i = 9 >> u; -} diff -Nurd linux86.vold/bcc/misc/test/opplus.t linux86/bcc/misc/test/opplus.t --- linux86.vold/bcc/misc/test/opplus.t 1986-10-28 05:18:43.000000000 +0000 +++ linux86/bcc/misc/test/opplus.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,122 +0,0 @@ -/* op+-.t - test plus, minus operators */ - -/* only doing chars and ints, not shorts, longs, floats, doubles */ -/* not doing pointer arithmetic */ - -op1() -{ - char cfn(); - int ifn(); - char c, *pc, **ppc; - int i, *pi, **ppi; - - i = c + 1; - i = 1 + c; - i = i + 1; - i = 1 + i; - - i = c + 500; - i = 500 + c; - i = i + 500; - i = 500 + i; - - i = c - 1; - i = 1 - c; - i = i - 1; - i = 1 - i; - - i = c - 500; - i = 500 - c; - i = i - 500; - i = 500 - i; - - i = c + c; - i = c + i; - i = i + c; /* -2 cycles, +1 byte different from c + i, lhs loaded 1st */ - i = i + i; - - i = c - c; - i = c - i; - i = i - c; - i = i - i; - - i = c + c++; - i = c + i++; - i = i + c++; - i = i + i++; - - i = c++ + c; - i = i++ + c; - i = c++ + i; - i = i++ + i; - - i = c - c++; - i = c - i++; - i = i - c++; - i = i - i++; - - i = c++ - c; - i = i++ - c; - i = c++ - i; - i = i++ - i; - - i = c + cfn(); - i = c + ifn(); - i = i + cfn(); - i = i + ifn(); - - i = cfn() + c; - i = ifn() + c; - i = cfn() + i; - i = ifn() + i; - - i = c - cfn(); - i = c - ifn(); - i = i - cfn(); - i = i - ifn(); - - i = cfn() - c; - i = ifn() - c; - i = cfn() - i; - i = ifn() - i; - - i = *pc + c++; - i = *pc + i++; - i = *pi + c++; - i = *pi + i++; - - i = c++ + *pc; - i = i++ + *pc; - i = c++ + *pi; - i = i++ + *pi; - - i = *pc - c++; - i = *pc - i++; - i = *pi - c++; - i = *pi - i++; - - i = c++ - *pc; - i = i++ - *pc; - i = c++ - *pi; - i = i++ - *pi; - - i = **ppc + c++; - i = **ppc + i++; - i = **ppi + c++; - i = **ppi + i++; - - i = c++ + **ppc; - i = i++ + **ppc; - i = c++ + **ppi; - i = i++ + **ppi; - - i = **ppc - c++; - i = **ppc - i++; - i = **ppi - c++; - i = **ppi - i++; - - i = c++ - **ppc; - i = i++ - **ppc; - i = c++ - **ppi; - i = i++ - **ppi; -} diff -Nurd linux86.vold/bcc/misc/test/opsoft.t linux86/bcc/misc/test/opsoft.t --- linux86.vold/bcc/misc/test/opsoft.t 1986-10-18 03:45:43.000000000 +0100 +++ linux86/bcc/misc/test/opsoft.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,259 +0,0 @@ -/* opsoft.t - test software operations */ - -/* only doing chars, shorts, ints and unsigneds */ -/* not doing longs, floats or doubles */ - -/* short = int, so only a few examples */ -/* unsigned like int, so only a few examples */ -/* most examples for DIVOP */ -/* only (all) special cases of MULOP, MODOP, SLOP and SROP are tried */ - -op1() -{ - char c, *pc, **ppc, cfn(); - short s, *ps, **pps, sfn(); - int i, *pi, **ppi, ifn(); - unsigned u, *pu, **ppu, ufn(); - - i = c / 0; - i = 0 / c; - i = i / 0; - i = 0 / i; - - i = s / 0; - i = 0 / u; - - i = c / 1; - i = 1 / c; - i = i / 1; - i = 1 / i; - - i = s / 1; - i = 1 / u; - - i = c / 2; - i = 2 / c; - i = i / 2; - i = 2 / i; - - i = s / 2; - i = 2 / u; - - i = c / 500; - i = 500 / c; - i = i / 500; - i = 500 / i; - - i = s / 500; - i = 500 / u; - - i = c / c; - i = c / i; - i = i / c; - i = i / i; - - i = s / c; - i = i / u; - - i = c / c++; - i = c / i++; - i = i / c++; - i = i / i++; - - i = s / i++; - i = c / u++; - - i = c++ / c; - i = i++ / c; - i = c++ / i; - i = i++ / i; - - i = s++ / c; - i = i++ / u; - - i = c / cfn(); - i = c / ifn(); - i = i / cfn(); - i = i / ifn(); - - i = s / cfn(); - i = c / ufn(); - - i = cfn() / c; - i = ifn() / c; - i = cfn() / i; - i = ifn() / i; - - i = sfn() / c; - i = ifn() / u; - - i = *pc / c++; - i = *pc / i++; - i = *pi / c++; - i = *pi / i++; - - i = *ps / c++; - i = *pi / u++; - - i = c++ / *pc; - i = i++ / *pc; - i = c++ / *pi; - i = i++ / *pi; - - i = s++ / *pc; - i = i++ / *pu; - - i = **ppc / c++; - i = **ppc / i++; - i = **ppi / c++; - i = **ppi / i++; - - i = **pps / c++; - i = **ppi / u++; - - i = c++ / **ppc; - i = i++ / **ppc; - i = c++ / **ppi; - i = i++ / **ppi; - - i = s++ / **ppc; - i = i++ / **ppu; - - i = c * 0; - i = 0 * c; - i = i * 0; - i = 0 * i; - - i = s * 0; - i = 0 * u; - - i = c * 1; - i = 1 * c; - i = i * 1; - i = 1 * i; - - i = s * 1; - i = 1 * u; - - i = c * 2; - i = 2 * c; - i = i * 2; - i = 2 * i; - - i = s * 2; - i = 2 * u; - - i = c * 500; - i = 500 * c; - i = i * 500; - i = 500 * i; - - i = s * 500; - i = 500 * u; - - i = c * c; - i = c * c++; - i = c++ * c; - i = c * cfn(); - i = cfn() * c; - i = *pc * c++; - i = c++ * *pc; - i = **ppc * c++; - i = c++ * **ppc; - - i = c % 0; - i = 0 % c; - i = i % 0; - i = 0 % i; - - i = s % 0; - i = 0 % u; - - i = c % 1; - i = 1 % c; - i = i % 1; - i = 1 % i; - - i = s % 1; - i = 1 % u; - - i = c % 2; - i = 2 % c; - i = i % 2; - i = 2 % i; - - i = s % 2; - i = 2 % u; - - i = c % 500; - i = 500 % c; - i = i % 500; - i = 500 % i; - - i = s % 500; - i = 500 % u; - - i = c << 0; - i = 0 << c; - i = i << 0; - i = 0 << i; - - i = s << 0; - i = 0 << u; - - i = c << 1; - i = 1 << c; - i = i << 1; - i = 1 << i; - - i = s << 1; - i = 1 << u; - - i = c << 8; - i = 8 << c; - i = i << 8; - i = 8 << i; - - i = s << 8; - i = 8 << u; - - i = c << 9; - i = 9 << c; - i = i << 9; - i = 9 << i; - - i = s << 9; - i = 9 << u; - - i = c >> 0; - i = 0 >> c; - i = i >> 0; - i = 0 >> i; - - i = s >> 0; - i = 0 >> u; - - i = c >> 1; - i = 1 >> c; - i = i >> 1; - i = 1 >> i; - - i = s >> 1; - i = 1 >> u; - - i = c >> 8; - i = 8 >> c; - i = i >> 8; - i = 8 >> i; - - i = s >> 8; - i = 8 >> u; - - i = c >> 9; - i = 9 >> c; - i = i >> 9; - i = 9 >> i; - - i = s >> 9; - i = 9 >> u; -} diff -Nurd linux86.vold/bcc/misc/test/puzzle.t linux86/bcc/misc/test/puzzle.t --- linux86.vold/bcc/misc/test/puzzle.t 1987-08-08 04:41:24.000000000 +0100 +++ linux86/bcc/misc/test/puzzle.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,178 +0,0 @@ -/* puzzle.t - from C puzzle book */ - -#define puzzle(which) ( puts( "-----which-----\n" ), which() ) - -main() -{ - puzzle( op1 ); - puzzle( op2 ); - puzzle( op3 ); - puzzle( op4 ); - puzzle( op5 ); - puzzle( op6 ); - puzzle( prep1 ); - puzzle( prep2 ); -} - -op1() -{ - int x; - - x = - 3 + 4 * 5 - 6; printf("%d\n",x); - x = 3 + 4 % 5 - 6; printf("%d\n",x); - x = - 3 * 4 % - 6 / 5; printf("%d\n",x); - x = ( 7 + 6 ) % 5 /2; printf("%d\n",x); -} - -#define PRINTX printf( "%d\n", x ) - -op2() -{ - int x, y, z; - - x = 2; - x *= 3 + 2; PRINTX; - x *= y = z = 4; PRINTX; - x = y == z; PRINTX; - x == (y == z); PRINTX; -} - -#define PRINT(int) printf( "int = %d\n", int ) - -op3() -{ - int x, y, z; - - x = 2; y = 1; z = 0; - x = x && y || z; PRINT(x); - PRINT( x || ! y && z ); - - x = y = 1; - z = x ++ - 1; PRINT(x); PRINT(z); - z += - x ++ + ++ y;PRINT(x);PRINT(z); - z = x / ++ x; PRINT(z); -} - -op4() -{ - int x, y, z; - - x = 03; y = 02; z = 01; - PRINT( x | y & z ); - PRINT( x | y & ~ z ); - PRINT( x ^ y & ~ z ); - PRINT( x & y && z ); - - x = 1; y = -1; - PRINT( ! x | x ); - PRINT( ~ x | x ); - PRINT( x ^ x ); - x <<= 3; PRINT(x); - y <<= 3; PRINT(y); - y >>= 3; PRINT(y); -} - -op5() -{ - int x, y, z; - - x = 1; y = 1; z = 1; - - x += y += z; - PRINT( x < y ? y : x ); - - PRINT( x < y ? x ++ : y ++ ); - PRINT(x); PRINT(y); - - PRINT( z += x < y ? x ++ : y ++ ); - PRINT(y); PRINT(z); - - x = 3; y=z=4; - PRINT( (z >= y >= x) ? 1 : 0 ); - PRINT( z >= y && y >= x ); -} - -#define PRINT3(x,y,z) printf("x=%d\ty=%d\tz=%d\n",x,y,z) - -op6() -{ - int x, y, z; - - x = y = z = 1; - ++x || ++y && ++z; PRINT3(x,y,z); - - x = y = z = 1; - ++x && ++y || ++z; PRINT3(x,y,z); - - x = y = z = 1; - ++x && ++y && ++z; PRINT3(x,y,z); - - x = y = z = -1; - ++x && ++y || ++z; PRINT3(x,y,z); - - x = y = z = -1; - ++x || ++y && ++z; PRINT3(x,y,z); - - x = y = z = -1; - ++x && ++y && ++z; PRINT3(x,y,z); -} - -#define FUDGE(k) k+3 -#define PR(a) printf("a= %d\t",(int)(a)) -#define PRINTNEW(a) PR(a); putchar( '\n' ); -#define PRINT2(a,b) PR(a); PRINT(b) -#define PRINT3NEW(a,b,c) PR(a); PRINT2(b,c) -#define MAX(a,b) (aPLOTOPTION = PSET; - pifbuf->LINESTYLE = /* normal */ - pifbuf->COMMAND = /* ?? */ - pifbuf->BFFLAG = 0; /* not a box */ - color = i = 0; - x0 = 2 * (h = H0/4); - y0 = 3 * (H0/4); - while ( h > 1 ) - { - ++i; - if ( ++color > 7 ) - color = 1; - pifbuf->COLOR = color; - x = x0 -= h; - y = y0 += h /= 2; - glocate(); - a( i ); x += h; y -= h; plot(); - b( i ); x -= h; y -= h; plot(); - c( i ); x -= h; y += h; plot(); - d( i ); x += h; y += h; plot(); - } -} - -a( i ) -int i; -{ - if ( --i >= 0 ) - { - a( i ); x += h; y -=h; plot(); - b( i ); x += 2*h; plot(); - d( i ); x += h; y += h; plot(); - a( i ); - } -} - -b( i ) -int i; -{ - if ( --i >= 0 ) - { - b( i ); x -= h; y -=h; plot(); - c( i ); y -= 2*h; plot(); - a( i ); x += h; y -= h; plot(); - b( i ); - } -} - -c( i ) -int i; -{ - if ( --i >= 0 ) - { - c( i ); x -= h; y +=h; plot(); - d( i ); x -= 2*h; plot(); - b( i ); x -= h; y -= h; plot(); - c( i ); - } -} - -d( i ) -int i; -{ - if ( --i >= 0 ) - { - d( i ); x += h; y +=h; plot(); - a( i ); y += 2*h; plot(); - c( i ); x -= h; y += h; plot(); - d( i ); - } -} - -glocate() -{ - pifbuf->X2 = x - x * (XDENOM - XNUM) / XDENOM + XOFFS; - pifbuf->Y2 = (y * YNUM) / YDENOM; -} - -plot() -{ - pifbuf->X1 = pifbuf->X2; - pifbuf->Y1 = pifbuf->Y2; - glocate(); -#asm - SWI2 - FDB $4201 call LINEMA -#endasm -} diff -Nurd linux86.vold/bcc/misc/test/sievecp.t linux86/bcc/misc/test/sievecp.t --- linux86.vold/bcc/misc/test/sievecp.t 1986-08-10 14:39:39.000000000 +0100 +++ linux86/bcc/misc/test/sievecp.t 1970-01-01 01:00:00.000000000 +0100 @@ -1,45 +0,0 @@ -/* sieve using pointers */ - -#define TRUE 1 -#define FALSE 0 -#define NITER 100 -#define SIZE 8191 /* last prime <= 2*this+3 */ -#define SQRSIZE 63 /* last divisor tested = 2*this+3 */ - -char flags[SIZE+2*SQRSIZE+3]; /* avoid ptr+=prime overflowing */ - -main() -{ - int i,count,iter; - register char *ptr; - char *endptr; - int prime; - - for (iter=0;iter 20 ) - { - printf( "usage: sort [args], where 500*argc is the array size\n" ); - exit( 1 ); - } - size = 500 * argc; - repet = 1; - for (i = 0; i < size; i++) - s[i] = size-i; - printf("\npress key to begin shell sorting\n"); - getchar(); - for (zz=0;zz0) - { - for (j=h; j=0; i-=h) - { - ++comp; - if (t[i]<=t[i+h]) - break; - ++swap; - temp=t[i]; - t[i]=t[i+h]; - t[i+h]=temp; - } - h=(h-1)/3; - } -} - -qqsort() -{ - qsort(0,size-1); -} - -qsort(l,r) -int l,r; -{ - int i,j; - unsigned x,w; - - i=l;j=r; - x=t[(l+r)>>1]; - do - { - while (t[i] < x) - { - ++comp; - i++; - } - while (x < t[j]) {--j;} - if (i<=j) - { - ++swap; - w=t[i];t[i]=t[j];t[j]=w; - i++;j--; - } - } - while (i<=j); - if (lflags&=~_IOERR) -#define getchar() getc(stdin) -#define feof(fp) ((fp)->_flags&_IOEOF) -#define ferror(fp) ((fp)->_flags&_IOERR) -#define fileno(fp) ((fp)->_fd) -#define putchar(c) putc((c),stdout) - -#define void int - -FILE *fdopen(); -char *fgets(); -FILE *fopen(); -FILE *freopen(); -long ftell(); - -long lseek(); -unsigned read(); -unsigned write(); - -char *malloc(); -char *realloc(); -char *sbrk(); - -char *index(); -char *rindex(); -char *strcat(); -char *strcpy(); -char *strncat(); -char *strncpy(); - -#asm - -BLANK EQU 32 -COEOL EQU 10 -EOL EQU 13 -MAXCONTROL EQU 31 - -* struct _iobuf translated into offsets - - BLOCK 0 -PTR RMB 2 -BASE RMB 2 -RTOP RMB 2 -WTOP RMB 2 -FLAGS RMB 1 -FD RMB 1 -IOB.SIZE - ENDB - -#endasm diff -Nurd linux86.vold/bcc/output.c linux86/bcc/output.c --- linux86.vold/bcc/output.c 1998-01-11 12:18:36.000000000 +0000 +++ linux86/bcc/output.c 2004-06-21 09:12:22.000000000 +0100 @@ -32,7 +32,7 @@ FORWARD void errorsummary P((void)); FORWARD void errsum1 P((void)); #ifdef MC6809 -#ifdef DEBUG +#ifdef DBNODE FORWARD void outvaldigs P((uvalue_t num)); #endif #endif @@ -40,7 +40,7 @@ PUBLIC void bugerror(message) char *message; { - error2error("compiler bug - ", message); + error2error("compiler bug? - ", message); } PUBLIC void closeout() @@ -116,6 +116,7 @@ output = old_output; outstage = old_outstage; } + outstr("fail"); comment(); errorloc(); outstr(warning); @@ -157,7 +158,9 @@ PUBLIC void finishup() { +#ifdef BUILTIN_CPP if (!orig_cppmode) +#endif { if (watchlc) { @@ -208,7 +211,9 @@ } if (nbytes != 0) { +#ifdef BUILTIN_CPP if (!orig_cppmode) +#endif clearlabels(outbufptr, outbufptr + nbytes); if (write(output, outbufptr, nbytes) != nbytes) { @@ -730,7 +735,7 @@ } #ifdef MC6809 -#ifdef DEBUG +#ifdef DBNODE /* print unsigned value, hex format (like outhex except value_t is larger) */ @@ -774,7 +779,7 @@ outuvalue((uoffset_T) num); } -#endif /* DEBUG */ +#endif /* DBNODE */ #endif /* MC6809 */ /* push decimal digits of an unsigned onto a stack of chars */ diff -Nurd linux86.vold/bcc/preproc.c linux86/bcc/preproc.c --- linux86.vold/bcc/preproc.c 1998-12-30 12:39:10.000000000 +0000 +++ linux86/bcc/preproc.c 2004-01-02 21:49:35.000000000 +0000 @@ -12,6 +12,16 @@ #include "table.h" #include "type.h" +/* blanksident() - return nonzero if at blanks followed by an identifier */ + +PUBLIC bool_pt blanksident() +{ + blanks(); + return isident(); +} + +#ifdef BUILTIN_CPP + #define MAX_IF 32 #define MAX__LINE__ 10 /* enough for 32-bit source unsigneds */ #define MAX_MACRO 32 @@ -40,6 +50,7 @@ char *paramspot; bool_t inparam; indn_t nparam; + struct symstruct *symptr; }; PRIVATE char dummyparam[] = { EOL, 0 }; @@ -51,8 +62,11 @@ PRIVATE struct macroposition macrostack[MAX_MACRO]; FORWARD void asmcontrol P((void)); +FORWARD void warningcntl P((void)); +FORWARD void errorcntl P((void)); FORWARD void control P((void)); FORWARD void defineorundefinestring P((char *str, bool_pt defineflag)); +FORWARD void elifcontrol P((void)); FORWARD void elsecontrol P((void)); FORWARD void endif P((void)); FORWARD fastin_pt getparnames P((void)); @@ -68,8 +82,11 @@ #endif asmmode = TRUE; + if (expect_statement) + return; + if (orig_cppmode) - outstr("#asm\n"); + outnstr("#asm"); else { outnstr("!BCC_ASM"); @@ -126,17 +143,9 @@ } #endif if (orig_cppmode) - outstr("#endasm"); /* nl is done by skipeol */ + outnstr("#endasm"); else - outstr("!BCC_ENDASM\n"); -} - -/* blanksident() - return nonzero if at blanks followed by an identifier */ - -PUBLIC bool_pt blanksident() -{ - blanks(); - return isident(); + outnstr("!BCC_ENDASM"); } PUBLIC void checknotinif() @@ -151,6 +160,51 @@ } } +/* warningcntl() - process #warning */ + +PRIVATE void warningcntl() +{ + char estr[256], *ep = estr; + + if (!orig_cppmode) { + *ep++ = '%'; *ep++ = 'w'; + } + while( ch != EOL ) { + if (ep < estr+sizeof(estr)-2 ) + *ep++ = ch; + gch1(); + } + *ep = 0; + + if (!orig_cppmode) + error(estr); + else { + outstr("#warning"); + outnstr(estr); + } +} + +/* errorcntl() - process #error */ + +PRIVATE void errorcntl() +{ + char estr[256], *ep = estr; + + while( ch != EOL ) { + if (ep < estr+sizeof(estr)-2 ) + *ep++ = ch; + gch1(); + } + *ep = 0; + + if (!orig_cppmode) + error(estr); + else { + outstr("#error"); + outnstr(estr); + } +} + /* control() - select and switch to control statement */ PRIVATE void control() @@ -158,6 +212,13 @@ char sname[NAMESIZE + 1]; sym_t ctlcase; struct symstruct *symptr; + if (ctext && asmmode) + { + comment(); + outudec(input.linenumber); + outbyte(' '); + outline(lineptr); + } sname[0] = '#'; /* prepare for bad control */ sname[1] = 0; @@ -183,20 +244,34 @@ } ctlcase = symptr->offset.offsym; if (ifstate.ifflag == FALSE && - (ctlcase < ELSECNTL || ctlcase > IFNDEFCNTL)) + (ctlcase < ELIFCNTL || ctlcase > IFNDEFCNTL)) return; switch (ctlcase) { case ASMCNTL: - asmcontrol(); + if (asmmode) + { + if (ifstate.ifflag) + error(" bad control"); + } + else + asmcontrol(); break; case DEFINECNTL: define(); break; + case ELIFCNTL: + elifcontrol(); + break; case ELSECNTL: elsecontrol(); break; case ENDASMCNTL: + if (!asmmode) + { + if (ifstate.ifflag) + error(" bad control"); + } asmmode = FALSE; break; case ENDIFCNTL: @@ -215,6 +290,12 @@ case UNDEFCNTL: undef(); break; + case WARNINGCNTL: + warningcntl(); + break; + case ERRORCNTL: + errorcntl(); + break; } } @@ -323,8 +404,12 @@ { gch1(); skipcomment(); +#if 0 /* comment is space in modern cpp's but they have '##' too */ ch = *--lineptr = ' '; +#else + continue; +#endif } } #ifdef TS @@ -343,12 +428,13 @@ && (--rcp == macstring || *(rcp - 1) != EOL); ) charptr = rcp; } - if (charptr >= char1top) - macstring = growobject(macstring, 2); + if (charptr+1 >= char1top) + macstring = growobject(macstring, 3); #ifdef TS ++ts_n_macstring_term; -ts_s_macstring += 2; +ts_s_macstring += 3; #endif + *charptr++ = ' '; /* Added to prevent tail recursion on expansion */ *charptr++ = EOL; *charptr++ = 0; if (nparnames) @@ -477,6 +563,29 @@ } } +/* elifcontrol() - process #elif */ + +PRIVATE void elifcontrol() +{ + if (iflevel == 0) + { + error("elif without if"); + return; + } + if (ifstate.elseflag) { + register struct ifstruct *ifptr; + + ifptr = &ifstack[(int)--iflevel]; + ifstate.elseflag = ifptr->elseflag; + ifstate.ifflag = ifptr->ifflag; + + ifcontrol(IFCNTL); + } else { + ifstate.ifflag = ifstate.elseflag; + ifstate.elseflag = FALSE; + } +} + /* elsecontrol() - process #else */ PRIVATE void elsecontrol() @@ -526,6 +635,7 @@ return; } symptr = gsymptr; + symptr->name.namea[0] |= 0x80; /* SMUDGE macro definition */ ngoodparams = 0; paramhead = NULL; if (symptr->indcount != 0) @@ -551,6 +661,7 @@ { if (nparleft > 0) /* macro has params, doesn't match bare word */ { + symptr->name.namea[0] &= 0x7f; /* UnSMUDGE macro definition */ outstr(symptr->name.namea); return; } @@ -716,6 +827,8 @@ ch = *(lineptr = symptr->offset.offp); mpptr->inparam = FALSE; mpptr->nparam = ngoodparams; + mpptr->symptr = symptr; + mpptr->symptr->name.namea[0] |= 0x80; /* SMUDGE macro definition */ ++maclevel; } /* @@ -832,6 +945,7 @@ } else { + mpptr->symptr->name.namea[0] &= 0x7F;/* UnSMUDGE macro definition */ ch = *++lineptr; /* gch1() would mess up next param == EOL-1 */ if (ch != 0) { @@ -964,3 +1078,5 @@ { defineorundefinestring(str, FALSE); } + +#endif diff -Nurd linux86.vold/bcc/preserve.c linux86/bcc/preserve.c --- linux86.vold/bcc/preserve.c 1999-07-24 12:31:27.000000000 +0100 +++ linux86/bcc/preserve.c 2004-06-02 17:08:57.000000000 +0100 @@ -6,6 +6,7 @@ #include "gencode.h" #include "reg.h" #include "type.h" +#include "scan.h" /* change stack ptr without changing condition codes */ @@ -18,11 +19,20 @@ #ifdef FRAMEPOINTER if (newsp != framep || (!(bool_t) absflag && switchnow != NULL)) { + int off; outleasp(); if (!(bool_t) absflag && switchnow != NULL) - outswoffset(newsp); + outswoffset(off = newsp); else - outoffset(newsp - framep); + outoffset(off = newsp - framep); +#ifndef NO_DEL_PUSH + if (optimise && !callersaves && off < 0) + { + outstr("+"); + outstr(funcname); + outstr(".off"); + } +#endif outindframereg(); outnl(); } diff -Nurd linux86.vold/bcc/proto.h linux86/bcc/proto.h --- linux86.vold/bcc/proto.h 1998-01-11 12:18:36.000000000 +0000 +++ linux86/bcc/proto.h 2004-06-20 13:27:29.000000000 +0100 @@ -102,11 +102,11 @@ void restoreopreg P((void)); void saveopreg P((void)); -/* debug.c */ +/* dbnode.c */ void dbitem P((struct symstruct *item)); void dbtype P((struct typestruct *type)); -void debug P((struct nodestruct *exp)); -void debugswap P((void)); +void dbnode P((struct nodestruct *exp)); +void dbnodeswap P((void)); /* declare.c */ void colon P((void)); @@ -276,8 +276,10 @@ void outstr P((char *s)); void outtab P((void)); void outudec P((unsigned num)); +#ifndef I8088 void outuvalue P((uvalue_t num)); void outvalue P((value_t num)); +#endif char *pushudec P((char *s, unsigned num)); void setoutbufs P((void)); @@ -325,6 +327,7 @@ void compound P((void)); void outswoffset P((offset_T offset)); void outswstacklab P((void)); +void doasm P((void)); /* table.c */ struct symstruct *addglb P((char *name, struct typestruct *type)); @@ -362,6 +365,6 @@ struct typestruct *prefix P((constr_pt constructor, uoffset_T size, struct typestruct *type)); struct typestruct *promote P((struct typestruct *type)); +struct typestruct *tosigned P((struct typestruct *type)); struct typestruct *tounsigned P((struct typestruct *type)); void typeinit P((void)); - diff -Nurd linux86.vold/bcc/scan.c linux86/bcc/scan.c --- linux86.vold/bcc/scan.c 1998-02-07 16:55:22.000000000 +0000 +++ linux86/bcc/scan.c 2004-06-20 17:26:32.000000000 +0100 @@ -119,6 +119,7 @@ continue; reglineptr = lineptr; } +#ifdef BUILTIN_CPP if (*reglineptr != '/') return; if (SYMOFCHAR(*(reglineptr + 1)) == SPECIALCHAR) @@ -131,6 +132,9 @@ return; gch1(); skipcomment(); +#else + return; +#endif } } @@ -139,8 +143,10 @@ { int start_of_line = 1; #ifndef ASM_BARE +#ifdef BUILTIN_CPP virtual_nl = 1; #endif +#endif while (!asm_only || asmmode) { int sym = SYMOFCHAR(ch); @@ -172,6 +178,7 @@ outstr(constant.value.s); /* XXX - embedded null would kill it */ charptr = constant.value.s; break; +#ifdef BUILTIN_CPP case CONTROL: gch1(); if (maclevel != 0) @@ -182,7 +189,10 @@ else { docontrol(); - break; +#ifndef ASM_BARE + virtual_nl = 1; +#endif + continue; } case SLASH: gch1(); @@ -193,6 +203,12 @@ } outbyte('/'); break; +#else /* !BUILTIN_CPP */ + case CONTROL: + gch1(); + docontrol(); + continue; +#endif case FLOATCONST: gch1(); if (SYMOFCHAR(ch) == INTCONST) @@ -208,6 +224,7 @@ break; case IDENT: getident(); +#ifdef BUILTIN_CPP if ((gsymptr = findlorg(gsname)) != NULL) { if (gsymptr->flags == DEFINITION) @@ -216,6 +233,7 @@ break; } } +#endif outstr(gsname); break; case INTCONST: @@ -250,7 +268,11 @@ /* must be '\\' */ default: /* Allow for multi-instruction lines in asm */ +#ifdef BUILTIN_CPP if( ch == '^' && !orig_cppmode && asmmode ) ch='\n'; +#else + if( ch == '^' && asmmode ) ch='\n'; +#endif OUTBYTE(ch); ch = *++lineptr; @@ -258,8 +280,10 @@ break; } #ifndef ASM_BARE +#ifdef BUILTIN_CPP virtual_nl = 0; #endif +#endif } } @@ -291,6 +315,7 @@ while (symofchar[c] <= MAXIDSYM && --length != 0); ch = c; *idptr = 0; + debug(7, "Got ident %s", gsname); lineptr = reglineptr; if (symofchar[c] == SPECIALCHAR) { @@ -431,7 +456,14 @@ static char lastch; register char *reglineptr; - while (TRUE) /* exit with short, fast returns */ + if (expect_statement && asmmode) + { + outnstr("!BCC_ASM"); + dumplocs(); + cppscan(1); + outnstr("!BCC_ENDASM"); + } + else while (TRUE) /* exit with short, fast returns */ { reglineptr = lineptr; while ((sym = SYMOFCHAR(*reglineptr)) == WHITESPACE) @@ -440,6 +472,7 @@ if (SYMOFCHAR(ch = *(lineptr = reglineptr + 1)) == SPECIALCHAR && sym != SPECIALCHAR) specialchar(); + debug(7, "In nextsym, got %d \"%C\"", sym, lastch); switch (sym) { case CHARCONST: @@ -463,14 +496,22 @@ constant.type = itype; return; case CONTROL: +#ifdef BUILTIN_CPP if (maclevel != 0) { error("# in a macro: not preprocessed"); /* XXX? */ return; } else +#endif { + int old_asmmode = asmmode; docontrol(); + if (asmmode && !old_asmmode) + { + sym = SEMICOLON; + return; + } break; } case FLOATCONST: @@ -489,11 +530,13 @@ getident(); if ((gsymptr = findlorg(gsname)) != NULL) { +#ifdef BUILTIN_CPP if (gsymptr->flags == DEFINITION) { entermac(); break; } +#endif if (gsymptr->flags == KEYWORD) sym = gsymptr->offset.offsym; } @@ -593,11 +636,13 @@ } return; case SLASH: +#ifdef BUILTIN_CPP if (ch == '*') { skipcomment(); break; } +#endif if (ch == '=') { sym = DIVABOP; @@ -733,7 +778,9 @@ gch1(); if (ch == EOL) { +#ifdef BUILTIN_CPP if (!orig_cppmode) +#endif eofin("escape sequence"); break; } @@ -742,7 +789,9 @@ GCH1(); if (ch == EOL) { +#ifdef BUILTIN_CPP if (!orig_cppmode && ifcheck() ) +#endif error(terminator == '"' ? "end of line in string constant" : "end of line in character constant"); break; diff -Nurd linux86.vold/bcc/scan.h linux86/bcc/scan.h --- linux86.vold/bcc/scan.h 1999-07-24 14:27:42.000000000 +0100 +++ linux86/bcc/scan.h 2002-07-28 08:42:14.000000000 +0100 @@ -136,6 +136,7 @@ ENUMDECL, NULLDECL, + SIGNDECL, STRUCTDECL, TYPEDECL, TYPEDEFNAME, @@ -170,6 +171,8 @@ INCLUDECNTL, LINECNTL, UNDEFCNTL, + WARNINGCNTL, + ERRORCNTL, ELIFCNTL, /* "IF" controls must be contiguous */ ELSECNTL, @@ -200,3 +203,6 @@ EXTERN bool_t incppexpr; /* nonzero while scanning cpp expression */ EXTERN sym_t sym; /* current symbol */ extern sym_t symofchar[]; /* table to convert chars to their symbols */ +EXTERN bool_t expect_statement; /* If set #asm needs to clear the recursive + * pending operations. ie: if stmts. */ + diff -Nurd linux86.vold/bcc/softop.c linux86/bcc/softop.c --- linux86.vold/bcc/softop.c 1998-02-06 20:20:14.000000000 +0000 +++ linux86/bcc/softop.c 2004-06-20 08:19:31.000000000 +0100 @@ -219,7 +219,18 @@ { case DIVOP: #ifdef I8088 - call("idiv_"); + if (uflag) + call("idiv_"); + else { +#ifdef I80386 + if (i386_32) + outnop1str("cdq"); + else +#endif + outnop1str("cwd"); + outop2str("idiv\t"); + outregname(INDREG0); + } #else call("idiv"); #endif diff -Nurd linux86.vold/bcc/state.c linux86/bcc/state.c --- linux86.vold/bcc/state.c 1999-07-24 12:14:36.000000000 +0100 +++ linux86/bcc/state.c 2002-08-03 16:02:29.000000000 +0100 @@ -72,7 +72,6 @@ FORWARD void dowhile P((void)); FORWARD void jumptocases P((void)); FORWARD void statement P((void)); -FORWARD void doasm P((void)); /* --- utility routines --- */ @@ -188,6 +187,7 @@ #endif spmark = sp; newlevel(); + expect_statement++; decllist(); softsp &= alignmask; if (sym != RBRACE) /* no need for locals if empty compound */ @@ -195,6 +195,7 @@ returnflag = FALSE; while (sym != RBRACE && sym != EOFSYM) statement(); + expect_statement--; oldlevel(); if (!returnflag) { @@ -231,19 +232,29 @@ rbrace(); } -PRIVATE void doasm() +PUBLIC void doasm() { - lparen(); + if (sym == LPAREN) nextsym(); if (sym!=STRINGCONST) error("string const expected"); else { - nextsym(); - constant.value.s[charptr-constant.value.s]='\0'; outnstr("!BCC_ASM"); - outbyte('\t'); - outnstr(constant.value.s); + for(;;) + { + constant.value.s[charptr-constant.value.s]='\0'; + outbyte('\t'); + outnstr(constant.value.s); + /* XXX: Need to investigate: wasting memory? + * + * charptr = constant.value.s; + */ + + nextsym(); + if (sym == COMMA) nextsym(); + if (sym!=STRINGCONST) break; + } outnstr("!BCC_ENDASM"); - rparen(); + if (sym == RPAREN) nextsym(); semicolon(); } } @@ -718,6 +729,10 @@ nextsym(); doif(); break; + case ELSESYM: + error("unexpected else"); + nextsym(); + break; case WHILESYM: nextsym(); dowhile(); @@ -764,6 +779,7 @@ semicolon(); break; case SEMICOLON: + outnstr("!BCC_EOS"); nextsym(); return; case ASMSYM: diff -Nurd linux86.vold/bcc/table.c linux86/bcc/table.c --- linux86.vold/bcc/table.c 1997-09-28 09:57:30.000000000 +0100 +++ linux86/bcc/table.c 2004-06-20 13:21:57.000000000 +0100 @@ -30,7 +30,7 @@ #define MAXEXPR 500 #endif #define MAXLOCAL 100 -#define NKEYWORDS 35 +#define NKEYWORDS 39 #ifdef NOFLOAT #define NSCALTYPES 10 #else @@ -91,6 +91,7 @@ { "struct", STRUCTDECL, }, { "union", UNIONDECL, }, { "unsigned", UNSIGNDECL, }, + { "signed", SIGNDECL, }, { "auto", AUTODECL, }, { "extern", EXTERNDECL, }, @@ -116,6 +117,7 @@ { "#asm", ASMCNTL, }, { "#define", DEFINECNTL, }, + { "#elif", ELIFCNTL, }, { "#else", ELSECNTL, }, { "#endasm", ENDASMCNTL, }, { "#endif", ENDIFCNTL, }, @@ -125,6 +127,8 @@ { "#ifndef", IFNDEFCNTL, }, { "#line", LINECNTL, }, { "#undef", UNDEFCNTL, }, + { "#warning", WARNINGCNTL, }, + { "#error", ERRORCNTL, }, { "defined", DEFINEDSYM, }, /* should be deactivated except in #if's */ }; @@ -396,6 +400,13 @@ register struct symstruct *symptr; int i; +#ifdef ASM_USES_CALLEE_REGS + if (framep && optimise && !callersaves) { + regfuse |= callee1mask; + outnstr("! Assuming #asm uses all callee saves registers"); + } +#endif + for (i = 0; i < HASHTABSIZE; ++i) for (symptr = hashtab[i]; symptr != NULL; symptr = symptr->next) if (symptr->storage == LOCAL) @@ -563,7 +574,7 @@ { error2error("compiler out of memory", message); -#if defined(DEBUG) && 0 +#ifdef __AS386_16__ { unsigned size; char *ptr; diff -Nurd linux86.vold/bcc/type.c linux86/bcc/type.c --- linux86.vold/bcc/type.c 1998-01-11 12:18:37.000000000 +0000 +++ linux86/bcc/type.c 2002-08-04 10:35:41.000000000 +0100 @@ -157,6 +157,25 @@ return type; } +PUBLIC struct typestruct *tosigned(type) +struct typestruct *type; +{ + switch (type->scalar & ~(UNSIGNED | DLONG)) + { + case CHAR: + return sctype; + case SHORT: + return stype; + case INT: + return itype; + case LONG: + return ltype; + default: + error("signed only applies to integral types"); + return type; + } +} + PUBLIC struct typestruct *tounsigned(type) struct typestruct *type; { diff -Nurd linux86.vold/bin86/Makefile linux86/bin86/Makefile --- linux86.vold/bin86/Makefile 2001-05-04 09:40:18.000000000 +0100 +++ linux86/bin86/Makefile 2003-12-31 11:36:40.000000000 +0000 @@ -27,13 +27,11 @@ install: all install $(INSTALL_OPTS) as/as86 $(BINDIR)/as$(SUF) - install $(INSTALL_OPT) as/as86_encap $(BINDIR)/as$(SUF)_encap install $(INSTALL_OPTS) ld/ld86 $(BINDIR)/ld$(SUF) install $(INSTALL_OPTS) ld/objdump86 $(BINDIR)/objdump$(SUF) install $(MAN_OPTS) man/*.1 $(MANDIR) ln -sf objdump$(SUF) $(BINDIR)/nm$(SUF) ln -sf objdump$(SUF) $(BINDIR)/size$(SUF) - ln -sf as86.1 $(MANDIR)/as86_encap.1 depend clean clobber: set -e ; for d in $(DIRS); do \ @@ -48,5 +46,5 @@ mkdir man cp -p ../man/ld86.1 man cp -p ../man/as86.1 man - touch -r ChangeLog . as ld man + touch -r ../Changes . as ld man diff -Nurd linux86.vold/Changes linux86/Changes --- linux86.vold/Changes 2001-05-21 14:09:17.000000000 +0100 +++ linux86/Changes 2004-06-21 08:20:45.000000000 +0100 @@ -1,3 +1,147 @@ +For version 0.16.*. + +> Sorry forgot to flip this back: perror and strerror are back to using + the /lib/liberror.txt file for all 8086 Elks modes. Only i386 has the + file linked. Elksemu now traps accesses to this file and substitutes + a fake. + +> Added vararg macros to new preprocessor. + +> Builtin CPP removed for __BCC__ compile, bcc-cc1 fit in 16bit but + crashes. Thirty two bit works fine, gcc or bcc. (almost any 32bit.) + +> Added __BCC_VERSION__ macro, defined by bcc.c contains hex version no. + +> Bugfix for offsets generated by #asm when using -O option to bcc-cc1. + Extra compile option ASM_USES_CALLEE_REGS. + +> Extra checking and bugfix for mixing char values with long shifts. + +> WARNING to distributions: I've altered the install scripts and paths + you will want to check them. Altered paths for bcc.c and normal + installs, defaults should now be good for distributions where bcc is a + cross compiler. If you set the PREFIX to / it'll install to suggested + Native paths. As86_encap moved to LIBDIR. + +> I've altered 'perror' and 'strerror' to be normal when compiled for + everything except libc_f.a. Only with that library will it look for the + liberror.txt file and it now looks in "/lib/liberror.txt" only. + This means there's no need to install it anywhere except ELKS itself. + +> Change -Mg option to use uclibc as glibc2 seems to have stopped working. + +> ar.c switch to using strerror. + +> Move elksemu, it's used like a shared library but is best treated like + an emulator so it's now installed in DISTBIN. Also on Linux-386 it's + compiled using the system compiler. + +> Use the POSIX -R argument to cp rather than the normal standard -r because + some new systems have decided to stop supporting their '-r' option. + +> Oops, the constant error strings in the assembler were char pointers not + char arrays, small waste of space. + +> Allow for Linux-2.6 32bit dev_t. + +> More changes so it compiles better on 'other' machines. + Removed some GNU-Make'isms in the top header file. + +> It seems that CYGWin's problem with _P is inherited from BSD. It also + seems most of my problems come from BSD recently, haven't they realised + that they down own the 'Unix Standard' anymore and haven't since SYSV + got popular. + +> Some changes for cygwin, it isn't quite as nasty as compiling for minix + but it doesn't miss by much! + +> Compiling for the 'tcc' complier, nice and easy. + +> Hitting bcc.c again, bcc-cpp now the default. + +> Some bugfixes for DEC Alpha -- 64 bit longs! + Constant folding still done with 64bit longs though. + +> The fopen function (and friends) is now a real function not a macro. + +> Ctype.h updated to ansi. + +> Libraries appear to compile properly with -O and -ansi now. + +> Copt's hash string table adjusted; should now have fewer pathological cases. + +> Order of copt's rule processing reversed; it now works from the top of a + rule file to the bottom. Also comment lines may be include in the match + lines. !BCC_EOS added to bcc-cc1 for 'end of statment'. + +> bcc-cc1's asm("") now works in declare mode too. + +> New independed cpp added, has both K&R and Ansi modes. + Changes made to the embedded cpp too to try and fix some bad bits. + +> Conditional assembler added around push and pop of 'si' and 'di' if the + optimiser (and as86's optimiser) are to be run. + +> Signed keyword added to bcc-cc1 for 'signed char' also works with other + int types but is usually just a noiseword. + +> As86 macro syntax altered, you now don't have to include any brackets. + +> Gcc warnings in ar86 cleaned up. + +> Mk_dist now makes incremental patch files too. + +> Update magic file. + +> Various updates to the bios libc, the vt52 and ansi emulations are + now seperated (and can be both included if needed) and don't have + to be linked. Conio functions work properly in bios and msdos. + +> Added -v (version) + +> as86 and ld86 now delete their binary outputs if there were errors. + +> Added more 'set' commands generated by '#asm' lines. The new ones begin + with '.' rather than '_' an are based off the 'bp' register rather than + the 'sp' register. + +> Various unused, test and old document files removed. + +> as86 modified to use normal malloc routines - no longer has limited + input file size. + +> as6809 repaired, appears to work. + +> as86 error display adjusted, some errors demoted to warnings. + +> Complete re-write of bcc.c driver program. Should now be easier to + modify, does have more versatility so that things that were formerly + compile time options are all run time. + +> #asm and #endasm now interact with statment processing inside functions. + If statments and case labels no longer need special layout however #asm + must be placed between statments now. + +> The __heap_top virtual constant added, allows the -H option to be used + with the -d option in the linker. + +> Conio routines added, merged with bios_getc/bios_putc routines which + now no longer exist under those names. + +> monitor.out now copes with very old zimages, like the memtest86 program, + and has 'Retry' prompt for disk errors. + +> msdos.s and tarboot.s loading of non-a.out executables adjusted for + dos BIN like files. + +> Standalone library startup adjusted to allow execution of a '-d' + executable from DOS, if __argr.x.cflag is set this is running under + DOS. + +> Compile for DOS again, disable cpm86 headers under DOS. + +> Minor bugfix for as86 binary output re sizeof(int)/K&R problem. + For version 0.16.0. > As major bugs seem to be absent 0.16.0 is escaping. @@ -56,7 +200,7 @@ Added lsys.com to install the dosfs boot sector under dos. monitor.out now (finally!) loads zImage files. Monitor.out now works with a TAR "filesystem" on a floppy. - Added two conpile time options (-DTARFLOPPY and -DDOSFLOPPY) for smaller + Added two compile time options (-DTARFLOPPY and -DDOSFLOPPY) for smaller executables to only boot linux-386 from a floppy. Makeboot can install the mbr. Removed the ELKS specific code from the minixfs loader, added a helper @@ -108,7 +252,7 @@ > Added -x option to bcc to prevent it linking in crt0.o. > Added various improvemnts to the optimiser, I don't think it'll generate - illegal code now for "-O", "-O1", or "-Oi". the last inlines the functions + illegal code now for "-O", "-O1", or "-Oi". The last inlines the functions __get_es(), __seg_es(), __poke_es(), __peek_es() etc. > Code generator improvement for integer multiply and shifts. (Including diff -Nurd linux86.vold/Contributors linux86/Contributors --- linux86.vold/Contributors 2000-02-10 08:47:58.000000000 +0000 +++ linux86/Contributors 2003-08-31 06:29:07.000000000 +0100 @@ -5,16 +5,13 @@ Then there's me, I'm controlling the releases of Dev86 and have the master files. -Robert de Bath +Robert de Bath The files are available at linux.mit.edu with the source and yesterday's -patch file available via http://poboxes.com/rdebath +patch file available via http://cix.co.uk/~mayday/ We're all available through the Linux-8086 mailing list at: - linux-8086@vger.rutgers.edu - -send a blank message to for help on joining -the list. + linux-8086@vger.kernel.org Rob. @@ -33,3 +30,4 @@ Joel Weber II Claudio Matsuoka Andrew Chittenden +John Coffman Binary files linux86.vold/copt/copt1 and linux86/copt/copt1 differ diff -Nurd linux86.vold/copt/copt.c linux86/copt/copt.c --- linux86.vold/copt/copt.c 1999-07-23 08:47:43.000000000 +0100 +++ linux86/copt/copt.c 2003-10-07 20:46:35.000000000 +0100 @@ -36,14 +36,17 @@ #include #include -#include #include #include #define KEEPCOMMENTS #define MAXLINE 1024 +#ifdef __BCC__ #define HASHSIZE 107 +#else +#define HASHSIZE 1999 +#endif #define NOCHAR '\177' #define VARNUM 10 @@ -112,7 +115,7 @@ struct hash_s *hp; char *chkstr; char *cp; - int hashval; + unsigned int hashval; /* Clear the hashing table if not already done */ if (!hash_init) { @@ -131,7 +134,7 @@ /* Determine hashing value of string */ hashval = 0; for (cp = chkstr; *cp; cp++) - hashval += *cp; + hashval = hashval*75 + *cp; hashval %= HASHSIZE; /* Check if the string is already in the hashing table */ @@ -183,7 +186,7 @@ * has been found in the first column of the input line. All lines with the * 'comment' character in the first position will be skipped. */ -static struct line_s *readlist(FILE *fp, char quit, char comment) +static struct line_s *readlist(FILE *fp, int quit, int comment) { struct line_s *lp; struct line_s *first_line = NULL; @@ -238,14 +241,25 @@ rp = (struct rule_s *)mymalloc(sizeof(struct rule_s)); rp->old = readlist(fp, '=', '#'); rp->new = readlist(fp, '\0', '#'); - rp->next = first; if (rp->old == NULL || rp->new == NULL) { free(rp); break; } + +/* This put the rules into the table in reverse order; this is confusing * + rp->next = first; first = rp; if (last == NULL) last = rp; +*/ + rp->next = NULL; + if (last) { + last->next = rp; + last = rp; + } else { + first = last = rp; + } + } /* Close pattern file */ @@ -293,7 +307,7 @@ /* * Read input file */ -static void readinfile(char *filename, char comment) +static void readinfile(char *filename, int comment) { FILE *fp; @@ -352,7 +366,7 @@ */ static long eval(char *str, int len) { - char *oldcp, *cp, c; + char *cp, c; int state = 0; int i, varnum; @@ -438,7 +452,7 @@ char *cp, *oldpat; long val; int varnum; - int len; + int len = 0; while (*ins && *pat) { @@ -679,6 +693,11 @@ if (!ins->comment_flg) pat = pat->next; + else if (ins->text[0]==pat->text[0]) /* Matching a comment! */ + { + if (match(ins->text, pat->text)) + pat = pat->next; + } ins = ins->next; } @@ -688,7 +707,7 @@ lp1 = cur; cur = cur->prev; while (lp1 != ins) { -#if 0 /* I'd like to keep the comment lines but this doesn't work XXX */ +#if 0 if( lp1->comment_flg ) { lp2 = lp1; @@ -811,7 +830,8 @@ /* * Main program */ -void main(int argc, char **argv) +int +main(int argc, char **argv) { char comment = NOCHAR; char *srcfile = NULL; diff -Nurd linux86.vold/copt/Makefile linux86/copt/Makefile --- linux86.vold/copt/Makefile 2001-01-06 12:35:38.000000000 +0000 +++ linux86/copt/Makefile 2003-08-31 13:49:29.000000000 +0100 @@ -1,9 +1,7 @@ copt: copt.c - $(CC) $(ANSI) $(CFLAGS) $(LDFLAGS) -o $@ $< + $(CC) $(ANSI) $(CFLAGS) $(LDFLAGS) -o $@ copt.c realclean clean: rm -f *.o copt - -# $(CC) $(ANSI) $(CFLAGS) $(LDFLAGS) -o copt copt.c diff -Nurd linux86.vold/copt/rules.186 linux86/copt/rules.186 --- linux86.vold/copt/rules.186 1998-02-07 11:11:09.000000000 +0000 +++ linux86/copt/rules.186 2002-08-03 21:28:02.000000000 +0100 @@ -28,3 +28,13 @@ = push #%1 +mov ax,*%1 +push ax += +push *%1 + +mov bx,*%1 +push bx += +push *%1 + diff -Nurd linux86.vold/copt/rules.386 linux86/copt/rules.386 --- linux86.vold/copt/rules.386 1998-02-07 16:07:44.000000000 +0000 +++ linux86/copt/rules.386 2002-08-03 21:37:27.000000000 +0100 @@ -1,5 +1,7 @@ # Rules to optimize BCC assembler output for 386 +# Many of these rules are very broken, ho hum. + # Rules for loading a long constant xor ax,ax @@ -351,7 +353,7 @@ mov %[ax|bx|cx|dx|si|di]2,%[#|*]0%1 push %[ax|bx|cx|dx|si|di]2 = -push word %0%1 +push %0%1 # Shifting rules diff -Nurd linux86.vold/copt/rules.86 linux86/copt/rules.86 --- linux86.vold/copt/rules.86 1999-01-22 19:06:03.000000000 +0000 +++ linux86/copt/rules.86 2004-06-21 21:51:04.000000000 +0100 @@ -2,94 +2,112 @@ # Rules for loading short variables -mov %0$0[%2],%3 -= -mov %0[%2],%3 - mov %2,%[ax|bx|cx|dx]1 mov %[ax|bx|cx|dx]1,%2 = mov %2,%1 -# Breaks: a = b = 125; -# mov %[ax|bx|cx|dx]3,%[#|*]0%1 -# mov %2[%4],%[ax|bx|cx|dx]3 -# = -# mov word ptr %2[%4],%0%1 - -# This gets a few back. +# Assign a constant mov %[ax|bx|cx|dx]3,%[#|*]0%1 mov %2[%4],%[ax|bx|cx|dx]3 -mov %[ax|bx|cx|dx]3,%5 +!BCC_EOS = mov word ptr %2[%4],%0%1 -mov %3,%5 +!BCC_EOS -mov %[ax|bx|cx|dx]3,%[#|*]0%1 -mov %[ax|bx|cx|dx]2,%[ax|bx|cx|dx]3 +# Assign a constant char +mov al,%[#|*]0%1 +mov %2,al +!BCC_EOS = -mov %2,%0%1 - -# Breaks: a = b = 'a'; -# mov al,%[#|*]0%1 -# mov %2,al -# = -# mov byte ptr %2,%0%1 +mov byte ptr %2,%0%1 +!BCC_EOS +# Assign a constant long from a small int xor ax,ax mov bx,%[#|*]0%1 mov [%2],ax mov [%2+2],bx +!BCC_EOS = mov word ptr [%2],#0 mov word ptr [%2+2],%0%1 +!BCC_EOS +# Assign a constant long from a 2^16 mod int. mov ax,%[#|*]0%1 xor bx,bx mov [%2],ax mov [%2+2],bx +!BCC_EOS = mov word ptr [%2],%0%1 mov word ptr [%2+2],#0 +!BCC_EOS +# Assign a constant long from a big int mov ax,%[#|*]4%1 mov bx,%[#|*]5%3 mov [%2],ax mov [%2+2],bx +!BCC_EOS = mov word ptr [%2],%4%1 mov word ptr [%2+2],%5%3 +!BCC_EOS +# rule for (char*) *x++ +mov bx,%1 +%[inc|dec]2 bx +mov %1,bx +mov al,-1[bx] +xor ah,ah += +mov bx,%1 +%2 word ptr %1 +mov al,[bx] +xor ah,ah # Rules for incrementing short variables +mov %[ax|bx|si|di]2,%1 +%[inc|dec]3 %[ax|bx|si|di]2 +mov %1,%[ax|bx|si|di]2 +!BCC_EOS += +%3 word ptr %1 +!BCC_EOS -mov %[ax|bx]2,%1 -%[inc|dec]3 %[ax|bx]2 -mov %1,%[ax|bx]2 +mov %[ax|bx|si|di]2,%1 +%[inc|dec]3 %[ax|bx|si|di]2 +mov %1,%[ax|bx|si|di]2 = %3 word ptr %1 mov %2,%1 -# Rules for manipulating characters +# Rules for manipulating characters with register char*s inc %[si|di]* inc %[si|di]* mov al,-1[si] mov -1[di],al +!BCC_EOS = lodsb stosb +!BCC_EOS inc %[si|di]* inc %[si|di]* mov al,-1[di] mov -1[si],al +!BCC_EOS = xchg si,di lodsb stosb xchg si,di +!BCC_EOS inc si mov al,-1[si] @@ -140,37 +158,44 @@ # Rules for manipulating short values -# This is the broken rule - Chad - -#mov %[ax|bx]2,%1 -#%[add|and|xor|sub|or]4 %[ax|bx]2,%3 -#mov %1,%[ax|bx]2 -#= -#mov %2,%3 -#%4 %1,%2 +# These rules only apply at end of statment. +mov %[ax|bx]2,%1 +%[add|and|xor|sub|or]4 %[ax|bx]2,%3 +mov %1,%[ax|bx]2 +!BCC_EOS += +mov %2,%3 +%4 %1,%2 +!BCC_EOS mov %[ax|bx]2,%1 %[add|and|xor|or]4 %[ax|bx]2,%3 mov %3,%[ax|bx]2 +!BCC_EOS = mov %2,%1 %4 %3,%2 - -mov %[ax|bx]4,%1 -%[add|and|xor|sub|or]2 %[si|di]3,%[ax|bx]4 -= -%2 %3,%1 +!BCC_EOS mov al,%1 xor ah,ah %[add|and|xor|sub|or]2 ax,%[#|*]0%3 mov %1,al +!BCC_EOS = %2 byte ptr %1,%0%3 +!BCC_EOS +# This is safe with an embedded assign. +mov %[ax|bx]4,%1 +%[add|and|xor|sub|or]2 %[si|di]3,%[ax|bx]4 += +%2 %3,%1 # Rules for comparing short values +# Compare doesn't need to leave any register in a specific state. + mov %[ax|bx]3,%1[%4] cmp %[ax|bx]3,%[#|*]0%2 = @@ -264,23 +289,24 @@ push %1 mov %[ax|bx|cx|dx]3,%2 -%[add|sub|and|xor|or]4 %[ax|bx|cx|dx]3,%*[bp] +%[add|and|xor|or]4 %[ax|bx|cx|dx]3,%*[bp] inc sp inc sp = -mov %3,%2 -%4 %3,%1 +mov %3,%1 +%4 %3,%2 -push %1 -mov %[ax|bx|cx|dx]3,%2 -%[add|sub|and|xor|or]5 %[ax|bx|cx|dx]3,%6 -%[add|sub|and|xor|or]4 %[ax|dx|cx|dx]3,%*[bp] -inc sp -inc sp -= -mov %3,%2 -%5 %3,%6 -%4 %3,%1 +# If %1 is ax this fails badly. +# push %1 +# mov %[ax|bx|cx|dx]3,%2 +# %[add|sub|and|xor|or]5 %[ax|bx|cx|dx]3,%6 +# %[add|sub|and|xor|or]4 %[ax|dx|cx|dx]3,%*[bp] +# inc sp +# inc sp +# = +# mov %3,%2 +# %5 %3,%6 +# %4 %3,%1 push %1 mov %[ax|bx|cx|dx]3,%*[bp] @@ -348,9 +374,11 @@ jmp .%1 .%2: +!BCC_EOS .%1: = .%2: +!BCC_EOS .%1: jmp .%1 @@ -445,4 +473,90 @@ pop cx pop dx = -! push/pop +! push/pop float + +# Long right shift by 16 unsigned +mov ax,%1 +mov bx,%2 +xchg bx,ax +xor bx,bx += +mov ax,%2 +xor bx,bx + +# Long right shift by 16 signed +mov ax,%1 +mov bx,%2 +xchg bx,ax +cwd += +mov ax,%2 +cwd + +# Load long and exchange +mov ax,%1 +mov bx,%2 +xchg bx,ax += +mov bx,%1 +mov ax,%2 + +# Repeated clear. +xor bx,bx +xchg bx,ax +xor ax,ax += +xchg bx,ax +xor ax,ax + +# Long expression assigned to an int +cwd +mov bx,dx +mov %1,ax +!BCC_EOS += +mov %1,ax +!BCC_EOS + +# Load unsigned into high word of long +mov ax,%1 +xchg bx,ax +xor ax,ax += +mov bx,%1 +xor ax,ax + +# Souped up strcpy; "while(*d++ = *s++);" in a function with no reg vars. +.%3: +!BCC_EOS +.%4: +mov bx,%1 +inc bx +mov %1,bx +mov si,%2 +inc si +mov %2,si +mov al,-1[bx] +mov -1[si],al +test al,al +jne .%3 += +.%4: +mov si,%1 +mov di,%2 +.%3: +lodsb +stosb +test al,al +jne .%3 +mov %1,si +mov %2,di +!BCC_EOS + +### +mov ax,%1 +mov %[ax|bx|cx|dx]2,ax +mov ax,%3 += +mov %2,%1 +mov ax,%3 diff -Nurd linux86.vold/copt/rules.end linux86/copt/rules.end --- linux86.vold/copt/rules.end 1998-02-13 21:39:38.000000000 +0000 +++ linux86/copt/rules.end 2002-08-03 21:25:07.000000000 +0100 @@ -15,8 +15,3 @@ pop di pop bp ret - -pmov %1,%2 -= -push %1 -mov %1,%2 diff -Nurd linux86.vold/copt/rules.i linux86/copt/rules.i --- linux86.vold/copt/rules.i 1999-05-10 21:49:56.000000000 +0100 +++ linux86/copt/rules.i 2002-08-03 21:50:04.000000000 +0100 @@ -57,7 +57,7 @@ inc sp inc sp = -mov ax,#%1 +mov ax,%0%1 mov es,ax mov ax,%[#|*]0%1 @@ -66,7 +66,7 @@ inc sp inc sp = -mov ax,#%1 +mov ax,%0%1 mov es,ax push %0[%1] @@ -290,5 +290,5 @@ mov ax,ax = -! +!mov ax,ax diff -Nurd linux86.vold/copt/rules.start linux86/copt/rules.start --- linux86.vold/copt/rules.start 1998-02-13 21:40:44.000000000 +0000 +++ linux86/copt/rules.start 2002-08-03 21:24:39.000000000 +0100 @@ -17,7 +17,3 @@ = proc_end -push %1 -mov %1,%2 -= -pmov %1,%2 diff -Nurd linux86.vold/cpp/cc.h linux86/cpp/cc.h --- linux86.vold/cpp/cc.h 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/cc.h 2004-06-20 12:08:00.000000000 +0100 @@ -0,0 +1,115 @@ + +#ifndef P +#if __STDC__ +#define P(x) x +#else +#define P(x) () +#endif +#endif + +extern void cfatal P((char*)); +extern void cerror P((char*)); +extern void cwarn P((char*)); +extern FILE * open_include P((char*, char*, int)); + +extern FILE * curfile; +extern char curword[]; +extern char * c_fname; +extern int c_lineno; +extern int alltok; +extern int dialect; + +#define DI_KNR 1 +#define DI_ANSI 2 + +extern int gettok P((void)); + +struct token_trans { char * name; int token; }; +struct token_trans * is_ctok P((const char *str, unsigned int len)); +struct token_trans * is_ckey P((const char *str, unsigned int len)); + +#define WORDSIZE 128 +#define TK_WSPACE 256 +#define TK_WORD 257 +#define TK_NUM 258 +#define TK_FLT 259 +#define TK_QUOT 260 +#define TK_STR 261 +#define TK_FILE 262 +#define TK_LINE 263 +#define TK_COPY 264 + +#define TKS_CTOK 0x200 +#define TKS_CKEY 0x300 + +#define TK_NE_OP (TKS_CTOK+ 0) +#define TK_MOD_ASSIGN (TKS_CTOK+ 1) +#define TK_AND_OP (TKS_CTOK+ 2) +#define TK_AND_ASSIGN (TKS_CTOK+ 3) +#define TK_MUL_ASSIGN (TKS_CTOK+ 4) +#define TK_INC_OP (TKS_CTOK+ 5) +#define TK_ADD_ASSIGN (TKS_CTOK+ 6) +#define TK_DEC_OP (TKS_CTOK+ 7) +#define TK_SUB_ASSIGN (TKS_CTOK+ 8) +#define TK_PTR_OP (TKS_CTOK+ 9) +#define TK_ELLIPSIS (TKS_CTOK+10) +#define TK_DIV_ASSIGN (TKS_CTOK+11) +#define TK_LEFT_OP (TKS_CTOK+12) +#define TK_LEFT_ASSIGN (TKS_CTOK+13) +#define TK_LE_OP (TKS_CTOK+14) +#define TK_EQ_OP (TKS_CTOK+15) +#define TK_GE_OP (TKS_CTOK+16) +#define TK_RIGHT_OP (TKS_CTOK+17) +#define TK_RIGHT_ASSIGN (TKS_CTOK+18) +#define TK_XOR_ASSIGN (TKS_CTOK+19) +#define TK_OR_ASSIGN (TKS_CTOK+20) +#define TK_OR_OP (TKS_CTOK+21) + +#define TK_AUTO (TKS_CKEY+ 0) +#define TK_BREAK (TKS_CKEY+ 1) +#define TK_CASE (TKS_CKEY+ 2) +#define TK_CHAR (TKS_CKEY+ 3) +#define TK_CONST (TKS_CKEY+ 4) +#define TK_CONTINUE (TKS_CKEY+ 5) +#define TK_DEFAULT (TKS_CKEY+ 6) +#define TK_DO (TKS_CKEY+ 7) +#define TK_DOUBLE (TKS_CKEY+ 8) +#define TK_ELSE (TKS_CKEY+ 9) +#define TK_ENUM (TKS_CKEY+10) +#define TK_EXTERN (TKS_CKEY+11) +#define TK_FLOAT (TKS_CKEY+12) +#define TK_FOR (TKS_CKEY+13) +#define TK_GOTO (TKS_CKEY+14) +#define TK_IF (TKS_CKEY+15) +#define TK_INT (TKS_CKEY+16) +#define TK_LONG (TKS_CKEY+17) +#define TK_REGISTER (TKS_CKEY+18) +#define TK_RETURN (TKS_CKEY+19) +#define TK_SHORT (TKS_CKEY+20) +#define TK_SIGNED (TKS_CKEY+21) +#define TK_SIZEOF (TKS_CKEY+22) +#define TK_STATIC (TKS_CKEY+23) +#define TK_STRUCT (TKS_CKEY+24) +#define TK_SWITCH (TKS_CKEY+25) +#define TK_TYPEDEF (TKS_CKEY+26) +#define TK_UNION (TKS_CKEY+27) +#define TK_UNSIGNED (TKS_CKEY+28) +#define TK_VOID (TKS_CKEY+29) +#define TK_VOLATILE (TKS_CKEY+30) +#define TK_WHILE (TKS_CKEY+31) + +#define MAX_INCLUDE 64 /* Nested includes */ +#define MAX_DEFINE 64 /* Nested defines */ + +extern char * set_entry P((int,char*,void*)); +extern void * read_entry P((int,char*)); + +struct define_item +{ + struct define_arg * next; + char * name; + int arg_count; /* -1 = none; >=0 = brackets with N args */ + int in_use; /* Skip this one for looking up #defines */ + int varargs; /* No warning if unexpected arguments. */ + char value[1]; /* [arg,]*value */ +}; diff -Nurd linux86.vold/cpp/cpp.c linux86/cpp/cpp.c --- linux86.vold/cpp/cpp.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/cpp.c 2004-06-20 12:11:25.000000000 +0100 @@ -0,0 +1,1511 @@ + +#include +#include +#ifdef __STDC__ +#include +#else +#include +#endif +#include "cc.h" + +#define CPP_DEBUG 0 /* LOTS of junk to stderr. */ + +/* + * This file comprises the 'guts' of a C preprocessor. + * + * Functions exported from this file: + * gettok() Returns the next token from the source + * curword contains the text of the token + * + * Variables + * curword Contains the text of the last token parsed. + * curfile Currently open primary file + * c_fname Name of file being parsed + * c_lineno Current line number in file being parsed. + * + * alltok Control flag for the kind of tokens you want (C or generic) + * dialect Control flag to change the preprocessor for Ansi C. + * + * TODO: + * #asm -> asm("...") translation. + * ?: in #if expressions + * Complete #line directive. + * \n in "\n" in a stringized argument. + * Comments in stringized arguments should be deleted. + * + * Poss: Seperate current directory for #include from errors (#line). + * (For editors that hunt down source files) + * Poss: C99 Variable macro args. + */ + +#define KEEP_SPACE 0 +#define SKIP_SPACE 1 + +#define EOT 4 +#define SYN 22 + +char curword[WORDSIZE]; +int alltok = 0; +int dialect = 0; + +FILE * curfile; +char * c_fname; +int c_lineno = 0; + +#ifdef __BCC__ +typedef long int_type; /* Used for preprocessor expressions */ +#else +typedef int int_type; /* Used for preprocessor expressions */ +#endif +static int curtok = 0; /* Used for preprocessor expressions */ + +static int fi_count = 0; +static FILE * saved_files[MAX_INCLUDE]; +static char * saved_fname[MAX_INCLUDE]; +static int saved_lines[MAX_INCLUDE]; + +static char * def_ptr = 0; +static char * def_start = 0; +static struct define_item * def_ref = 0; + +static int def_count =0; +static char * saved_def[MAX_DEFINE]; +static char * saved_start[MAX_DEFINE]; +static long saved_unputc[MAX_DEFINE]; +static struct define_item * saved_ref[MAX_DEFINE]; + +static long unputc = 0; + +static int last_char = '\n'; +static int in_preproc = 0; +static int dont_subst = 0; +static int quoted_str = 0; + +static int if_count = 0; +static int if_false = 0; +static int if_has_else = 0; +static int if_hidden = 0; +static unsigned int if_stack = 0; + +struct arg_store { + char * name; + char * value; + int in_define; +}; + +static int chget P((void)); +static int chget_raw P((void)); +static void unchget P((int)); +static int gettok_nosub P((void)); +static int get_onetok P((int)); +static int pgetc P((void)); +static int do_preproc P((void)); +static int do_proc_copy_hashline P((void)); +static int do_proc_if P((int)); +static void do_proc_include P((void)); +static void do_proc_define P((void)); +static void do_proc_undef P((void)); +static void do_proc_else P((void)); +static void do_proc_endif P((void)); +static void do_proc_tail P((void)); +static int get_if_expression P((void)); +static int_type get_expression P((int)); +static int_type get_exp_value P((void)); +static void gen_substrings P((char *, char *, int, int)); +static char * insert_substrings P((char *, struct arg_store *, int)); + +int +gettok() +{ + int ch; + + for(;;) + { + /* Tokenised C-Preprocessing */ + if (!quoted_str) + { + if (alltok) + ch = get_onetok(KEEP_SPACE); + else + ch = get_onetok(SKIP_SPACE); + + if( ch == '"' || ch == '\'' ) + quoted_str = ch; + + if( ch == TK_WORD ) + { + struct token_trans *p = is_ckey(curword, strlen(curword)) ; + if( p ) + return p->token; + } + + if (ch == '\n') continue; + return ch; + } + + /* Special for quoted strings */ + *curword = '\0'; + ch = chget(); + if( ch == EOF ) return ch; + + *curword = ch; + curword[1] = '\0'; + + if( ch == quoted_str ) { + if( ch == '"' ) + { + if (dialect == DI_ANSI) { + /* Found a terminator '"' check for ansi continuation */ + while( (ch = pgetc()) <= ' ' && ch != EOF) ; + if( ch == '"' ) continue; + unchget(ch); + *curword = '"'; + curword[1] = '\0'; + } + + quoted_str = 0; + return '"'; + } else { + quoted_str = 0; + return ch; + } + } + if( ch == '\n' ) { + quoted_str = 0; + unchget(ch); /* Make sure error line is right */ + return ch; + } + if( ch == '\\' ) { + unchget(ch); + ch = get_onetok(KEEP_SPACE); + return ch; + } + return TK_STR; + } +} + +static int +gettok_nosub() +{ int rv; dont_subst++; rv=get_onetok(SKIP_SPACE); dont_subst--; return rv; } + +static int +get_onetok(keep) +int keep; +{ + char * p; + int state; + int ch, cc; + +Try_again: + *(p=curword) = '\0'; + state=cc=ch=0; + + /* First skip whitespace, if the arg says so then we need to keep it */ + while( (ch = pgetc()) == ' ' || ch == '\t' ) + { + if (keep == KEEP_SPACE) { + if( p < curword + WORDSIZE-1 ) { + *p++ = ch; /* Clip to WORDSIZE */ + *p = '\0'; + } + } + } + + if( ch > 0xFF ) return ch; + if( p != curword ) { unchget(ch); return TK_WSPACE; } + if( ch == '\n') return ch; + if( ch == EOF ) return ch; + if( ch >= 0 && ch < ' ' ) goto Try_again; + + for(;;) + { + switch(state) + { + case 0: if( (ch >= 'A' && ch <= 'Z') + || (ch >= 'a' && ch <= 'z') + || ch == '_' || ch == '$' ) + state = 1; + else if(ch == '0') + state = 2; + else if(ch >= '1' && ch <= '9') + state = 5; + else + goto break_break; + break; + case 1: if( (ch >= '0' && ch <= '9') + || (ch >= 'A' && ch <= 'Z') + || (ch >= 'a' && ch <= 'z') + || ch == '_' || ch == '$' ) + break; + else + goto break_break; + case 2: if( ch >= '0' && ch <= '7') + state = 3; + else if( ch == 'x' || ch == 'X' ) + state = 4; + else + goto break_break; + break; + case 3: if( ch >= '0' && ch <= '7') + break; + else + goto break_break; + case 4: if( (ch >= '0' && ch <= '9') + || (ch >= 'A' && ch <= 'F') + || (ch >= 'a' && ch <= 'f') ) + break; + else + goto break_break; + case 5: + case 6: if( ch >= '0' && ch <= '9') + ; + else if( ch == '.' && state != 6 ) + state = 6; + else if( ch == 'e' || ch == 'E' ) + state = 7; + else + goto break_break; + break; + case 7: if( ch == '+' || ch == '-' ) + break; + state = 8; + /* FALLTHROUGH */ + case 8: if( ch >= '0' && ch <= '9') + break; + else + goto break_break; + } + if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */ + *p = '\0'; cc++; + ch = chget(); + if (ch == SYN) ch = chget(); + } +break_break: + /* Numbers */ + if( state >= 2 ) + { + if( state < 6 ) + { + if( ch == 'u' || ch == 'U' ) + { + if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */ + *p = '\0'; cc++; + ch = chget(); + } + if( ch == 'l' || ch == 'L' ) + { + if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */ + *p = '\0'; cc++; + } + else unchget(ch); + return TK_NUM; + } + unchget(ch); + return TK_FLT; + } + + /* Words */ + if( state == 1 ) + { + struct define_item * ptr; + unchget(ch); + if( !dont_subst + && (ptr = read_entry(0, curword)) != 0 + && !ptr->in_use + ) + { + if ( def_count >= MAX_DEFINE ) { + cwarn("Preprocessor recursion overflow"); + return TK_WORD; + } else if( ptr->arg_count >= 0 ) + { + /* An open bracket must follow the word */ + int ch1 = 0; + while ((ch = chget()) == ' ' || ch == '\t' ) ch1 = ch; + if (ch != '(') { + unchget(ch); + if (ch1) unchget(ch1); + return TK_WORD; + } + + /* We have arguments to process so lets do so. */ + gen_substrings(ptr->name, ptr->value, ptr->arg_count, ptr->varargs); + + /* Don't mark macros with arguments as in use, it's very + * difficult to say what the correct result would be so + * I'm letting the error happen. Also if I do block + * recursion then it'll also block 'pseudo' recursion + * where the arguments have a call to this macro. + * + def_ref = ptr; + ptr->in_use = 1; + */ + } + else if (ptr->value[0]) + { + /* Simple direct substitution; note the shortcut (above) for + * macros that are defined as null */ + saved_ref[def_count] = def_ref; + saved_def[def_count] = def_ptr; + saved_start[def_count] = def_start; + saved_unputc[def_count] = unputc; + def_count++; + unputc = 0; + def_ref = ptr; + def_ptr = ptr->value; + def_start = 0; + ptr->in_use = 1; + } + goto Try_again; + } + return TK_WORD; + } + + /* Quoted char for preprocessor expressions */ + if(in_preproc && ch == '\'' ) + { + *p++ = ch; ch = chget(); + for(;;) + { + if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */ + *p = '\0'; cc++; + if( ch == '\'' || ch == '\n' ) break; + + if( ch == '\\' ) + { + ch = chget(); + if( cc < WORDSIZE-1 ) *p++ = ch; /* Clip to WORDSIZE */ + *p = '\0'; cc++; + } + ch = chget(); + } + ch = TK_QUOT; + } + + /* Collect and translate \xyx strings, (should probably translate these + * all to some standard form (eg \ooo plus \N ) + * + * ___________________________________________________________________ + * | new-line NL (LF) \n| audible alert BEL \a | + * | horizontal tab HT \t| question mark ? \? | + * | vertical tab VT \v| double quote " \" | + * | backspace BS \b| octal escape ooo \ooo| + * | carriage return CR \r| hexadecimal escape hh \xhh| + * | formfeed FF \f| backslash \ \\ | + * | single quote ' \'| | + * |_______________________________|_________________________________| + */ + + if( ch == '\\' ) + { + int i; + + *p++ = ch; ch = chget(); + if (ch >= '0' && ch <= '7' ) { + for(i=0; i<3; i++) { + if (ch >= '0' && ch <= '7' ) { + *p++ = ch; ch = chget(); + } + } + unchget(ch); + } else if (ch == 'x' || ch == 'X') { + *p++ = ch; ch = chget(); + for(i=0; i<2; i++) { + if ( (ch >= '0' && ch <= '9' ) || + (ch >= 'A' && ch <= 'F' ) || + (ch >= 'a' && ch <= 'f' ) ) { + *p++ = ch; ch = chget(); + } + } + unchget(ch); + } else if (ch == '?') { + p[-1] = '?'; + } else if (ch != '\n' && ch != EOF) { + *p++ = ch; + } else + unchget(ch); + *p = '\0'; + return TK_STR; + } + + /* Possible composite tokens */ + if( ch > ' ' && ch <= '~' ) + { + struct token_trans *p; + *curword = cc = ch; + + for(state=1; ; state++) + { + curword[state] = ch = chget(); + if( !(p=is_ctok(curword, state+1)) ) + { + unchget(ch); + curword[state] = '\0'; + return cc; + } + cc=p->token; + } + } + return ch; +} + +static int +pgetc() +{ + int ch, ch1; + + for(;;) + { + if ((ch = chget()) == EOF) return ch; + + if( !in_preproc && last_char == '\n' && ch == '#' ) + { + in_preproc = 1; + ch = do_preproc(); + in_preproc = 0; + if(if_false || ch == 0) continue; + + last_char = '\n'; + return ch; + } + if( last_char != '\n' || (ch != ' ' && ch != '\t') ) + last_char = ch; + + /* Remove comments ... */ + if( ch != '/' ) + { if(if_false && !in_preproc) continue; return ch; } + ch1 = chget(); /* Allow "/\\\n*" as comment start too!? */ + + if( ch1 == '/' ) /* Double slash style comments */ + { + do { ch = chget(); } while(ch != '\n' && ch != EOF); + return ch; /* Keep the return. */ + } + + if( ch1 != '*' ) + { + unchget(ch1); + if(if_false && !in_preproc) continue; + return ch; + } + + for(;;) + { + if( ch == '*' ) + { + ch = chget(); + if( ch == EOF ) return EOF; + if( ch == '/' ) break; + } + else ch = chget(); + } + if (dialect == DI_ANSI) + return ' '; /* If comments become " " */ + else return SYN; /* Comments become nulls, but we need a + * marker so I can do token concat properly. */ + } +} + +/* This function handles the first and second translation phases of Ansi-C */ +static int +chget() +{ + int ch, ch1; + for(;;) { + ch = chget_raw(); + if (ch == '\\') { + ch1 = chget_raw(); + if (ch1 == '\n') continue; + unchget(ch1); + } + + /* Ansi trigraphs -- Ewww, it needs lots of 'unchget' space too. */ + if (dialect == DI_ANSI && ch == '?') { + ch1 = chget_raw(); + if (ch1 != '?') + unchget(ch1); + else { + static char trig1[] = "()<>/!'-="; + static char trig2[] = "[]{}\\|^~#"; + char * s; + ch1 = chget_raw(); + s = strchr(trig1, ch1); + if (s) { + unchget(trig2[s-trig1]); /* Unchget so that ??/ can be used as */ + continue; /* a real backslash at EOL. */ + } else { + unchget(ch1); + unchget('?'); + } + } + } + + return ch; + } +} + +static void +unchget(ch) +{ +#if CPP_DEBUG + fprintf(stderr, "\b", ch); +#endif + if(ch == 0) return; /* Hummm */ + if(ch == EOF) ch=EOT; /* EOF is pushed back as a normal character. */ + ch &= 0xFF; + + if(unputc&0xFF000000) + cerror("Internal character pushback stack overflow"); + else unputc = (unputc<<8) + (ch); + if( ch == '\n' ) c_lineno--; +} + +static int +chget_raw() +#if CPP_DEBUG +{ + int ch; +static int last_def = 0; +static int last_fi = 0; + if (last_fi != fi_count) fprintf(stderr, "", fi_count); + if (last_def != def_count) fprintf(stderr, "", def_count); + last_def = def_count; last_fi = fi_count; + + ch = realchget(); + if (ch == EOF) fprintf(stderr, ""); else fprintf(stderr, "%c", ch); + + if (last_def != def_count) fprintf(stderr, "", def_count); + if (last_fi != fi_count) fprintf(stderr, "", fi_count); + last_def = def_count; last_fi = fi_count; + + return ch; +} + +static int +realchget() +#endif +{ + int ch; + for(;;) + { + if( unputc ) + { + if((unputc&0xFF)==EOT && in_preproc) return '\n'; + ch=(unputc&0xFF); unputc>>=8; + if( ch == EOT ) ch = EOF; + if( ch == '\n' ) c_lineno++; + return ch; + } + + if( def_ptr ) + { + ch = *def_ptr++; if(ch) return (unsigned char)ch; + if( def_start ) free(def_start); + if( def_ref ) def_ref->in_use = 0; + + def_count--; + def_ref = saved_ref[def_count]; + def_ptr = saved_def[def_count]; + def_start = saved_start[def_count]; + unputc = saved_unputc[def_count]; + continue; + } + + ch = getc(curfile); + if( ch == EOF && fi_count != 0) + { + fclose(curfile); + fi_count--; + curfile = saved_files[fi_count]; + if(c_fname) free(c_fname); + c_fname = saved_fname[fi_count]; + c_lineno = saved_lines[fi_count]; + ch = '\n'; /* Ensure end of line on end of file */ + } + else if( ch == '\n' ) c_lineno++; + + /* Treat all control characters, except the standard whitespace + * characters of TAB and NL as completely invisible. + */ + if( ch >= 0 && ch < ' ' && ch!='\n' && ch!='\t' && ch!=EOF ) continue; + + if( ch == EOF ) { unchget(ch); return '\n'; } /* Ensure EOL before EOF */ + return (unsigned char)ch; + } +} + +static int +do_preproc() +{ + int val, no_match=0; + + if( (val=get_onetok(SKIP_SPACE)) == TK_WORD ) + { + if( strcmp(curword, "ifdef") == 0 ) + do_proc_if(0); + else if( strcmp(curword, "ifndef") == 0 ) + do_proc_if(1); + else if( strcmp(curword, "if") == 0 ) + do_proc_if(2); + else if( strcmp(curword, "elif") == 0 ) + do_proc_if(3); + else if( strcmp(curword, "else") == 0 ) + do_proc_else(); + else if( strcmp(curword, "endif") == 0 ) + do_proc_endif(); + else if(if_false) + no_match=1; + else + { + if( strcmp(curword, "include") == 0 ) + do_proc_include(); + else if( strcmp(curword, "define") == 0 ) + do_proc_define(); + else if( strcmp(curword, "undef") == 0 ) + do_proc_undef(); + else if( strcmp(curword, "error") == 0 ) { + strcpy(curword, "#error"); + do_proc_copy_hashline(); pgetc(); + cerror(curword); + } else if( strcmp(curword, "warning") == 0 ) { + strcpy(curword, "#warning"); + do_proc_copy_hashline(); pgetc(); + cwarn(curword); + } else if( strcmp(curword, "pragma") == 0 ) { + do_proc_copy_hashline(); pgetc(); + /* Ignore #pragma ? */ + } else if( strcmp(curword, "line") == 0 ) { + do_proc_copy_hashline(); pgetc(); + /* Ignore #line for now. */ + } else if( strcmp(curword, "asm") == 0 ) { + alltok |= 0x100; + return do_proc_copy_hashline(); + } else if( strcmp(curword, "endasm") == 0 ) { + alltok &= ~0x100; + return do_proc_copy_hashline(); + } else + no_match=1; + } + } + else no_match=1; + + if( no_match ) + { + if(!if_false) cerror("Unknown preprocessor directive"); + while( val != '\n' ) val = pgetc(); + } + + *curword = 0; /* Just in case */ + return 0; +} + +static int +do_proc_copy_hashline() +{ + int off, ch; + + off = strlen(curword); + + while( (ch=pgetc()) != '\n' ) + { + if( off < WORDSIZE ) curword[off++] = ch; + } + if( off == WORDSIZE ) + { + cerror("Preprocessor directive too long"); + curword[WORDSIZE-1] = '\0'; + } + else + curword[off] = '\0'; + + unchget('\n'); + return TK_COPY; +} + +static void +do_proc_include() +{ + int ch, ch1; + char * p; + FILE * fd; + + ch = get_onetok(SKIP_SPACE); + if( ch == '<' || ch == '"' ) + { + if( ch == '"' ) ch1 = ch; else ch1 = '>'; + p = curword; + while(p< curword+WORDSIZE-1) + { + ch = pgetc(); + if( ch == '\n' ) break; + if( ch == ch1 ) + { + *p = '\0'; + p = strdup(curword); + + do { ch1 = pgetc(); } while(ch1 == ' ' || ch1 == '\t'); + unchget(ch1); + do_proc_tail(); + + saved_files[fi_count] = curfile; + saved_fname[fi_count] = c_fname; + saved_lines[fi_count] = c_lineno; + + fd = open_include(p, "r", (ch=='"')); + if( fd ) { + fi_count++; + curfile = fd; + } else + cerror("Cannot open include file"); + + return; + } + *p++ = ch; + } + } + cerror("Bad #include command"); + while(ch != '\n') ch = pgetc(); + return; +} + +static void +do_proc_define() +{ + int ch, ch1; + struct define_item * ptr, * old_value = 0; + int cc, len; + char name[WORDSIZE]; + + if( (ch=gettok_nosub()) == TK_WORD ) + { + strcpy(name, curword); + ptr = read_entry(0, name); + if(ptr) + { + set_entry(0, name, (void*)0); /* Unset var */ + if (ptr->in_use) + /* Eeeek! This shouldn't happen; so just let it leak. */ + cwarn("macro redefined while it was in use!?"); + else + old_value = ptr; + } + + /* Skip blanks */ + for(ch=ch1=pgetc(); ch == ' ' || ch == '\t' ; ch=pgetc()) ; + + len = WORDSIZE; + ptr = malloc(sizeof(struct define_item) + WORDSIZE); + if(ptr==0) cfatal("Preprocessor out of memory"); + ptr->value[cc=0] = '\0'; + + /* Add in arguments */ + if( ch1 == '(' ) + { + ptr->arg_count=0; + for(;;) + { + ch=gettok_nosub(); + if( ptr->arg_count==0 && ch == ')' ) break; + if( ch == TK_WORD ) + { + if( cc+strlen(curword)+4 >= len) + { + len = cc + WORDSIZE; + ptr = (struct define_item *) realloc(ptr, sizeof(struct define_item) + len); + if(ptr==0) cfatal("Preprocessor out of memory"); + } + if( cc+strlen(curword) < len) + { + strcpy(ptr->value+cc, curword); + cc+=strlen(curword); + strcpy(ptr->value+cc, ","); + cc++; + ptr->arg_count++; + ch=gettok_nosub(); + if( ch == TK_ELLIPSIS ) { + ptr->varargs = 1; + ch=gettok_nosub(); + if (ch == ',') ch = '*'; /* Force error if not ')' */ + } + if( ch == ')' ) break; + if( ch == ',' ) continue; + } + } + cerror("Bad #define command"); + free(ptr); + while(ch != '\n') ch = pgetc(); + set_entry(0, name, (void*)old_value); /* Return var to old. */ + return; + } + while((ch=pgetc())==' ' || ch=='\t'); + } + else ptr->arg_count = -1; + + /* And the substitution string */ + while(ch != '\n') + { + if( cc+4 > len ) + { + len = cc + WORDSIZE; + ptr = (struct define_item *) realloc(ptr, sizeof(struct define_item) + len); + if(ptr==0) cfatal("Preprocessor out of memory"); + } + ptr->value[cc++] = ch; + ch = pgetc(); + } + if (cc) + ptr->value[cc++] = ' ';/* Byte of lookahead for recursive macros */ + ptr->value[cc++] = '\0'; + +#if CPP_DEBUG + if (cc == 1) + fprintf(stderr, "\n### Define '%s' as null\n", name); + else if (ptr->arg_count<0) + fprintf(stderr, "\n### Define '%s' as '%s'\n", + name, ptr->value); + else + fprintf(stderr, "\n### Define '%s' as %d args '%s'\n", + name, ptr->arg_count, ptr->value); +#endif + + /* Clip to correct size and save */ + ptr = (struct define_item *) realloc(ptr, sizeof(struct define_item) + cc); + ptr->name = set_entry(0, name, ptr); + ptr->in_use = 0; + ptr->next = 0; + + if (old_value) { + if (strcmp(old_value->value, ptr->value) != 0) + cwarn("#define redefined macro"); + free(old_value); + } + } + else cerror("Bad #define command"); + while(ch != '\n') ch = pgetc(); +} + +static void +do_proc_undef() +{ + int ch; + struct define_item * ptr; + if( (ch=gettok_nosub()) == TK_WORD ) + { + ptr = read_entry(0, curword); + if(ptr) + { + set_entry(0, curword, (void*)0); /* Unset var */ + if (ptr->in_use) + /* Eeeek! This shouldn't happen; so just let it leak. */ + cwarn("macro undefined while it was in use!?"); + else + free(ptr); + } + do_proc_tail(); + } + else + { + cerror("Bad #undef command"); + while(ch != '\n') ch = pgetc(); + } +} + +static int +do_proc_if(type) +int type; +{ + int ch = 0; + if(if_false && if_hidden) + { + if( type != 3 ) if_hidden++; + do_proc_tail(); + return 0; + } + + if( type == 3 ) + { + if( if_count == 0 ) + cerror("#elif without matching #if"); + else + { + if( if_has_else ) + cerror("#elif following #else for one #if"); + if( if_has_else || if_false != 1 ) + { + if_false=2; + while(ch != '\n') ch = pgetc(); + return 0; + } + if_false=0; + } + if_has_else = 0; + } + if(if_false) + { + if( type != 3 ) if_hidden++; + do_proc_tail(); + } + else + { + if( type != 3 ) + { + if_count++; + if_stack <<= 1; + if_stack |= if_has_else; + if_has_else = 0; + } + if(type > 1) + { + ch = get_if_expression(); + if_false=!ch; + } + else + { + ch = gettok_nosub(); + if( ch == TK_WORD ) + { + do_proc_tail(); + if_false = (read_entry(0, curword) == 0); + if(type == 1) if_false = !if_false; + } + else + { + cerror("Bad #if command"); + if_false = 0; + while(ch != '\n') ch = pgetc(); + } + } + } + return 0; +} + +static void +do_proc_else() +{ + if( if_hidden == 0 ) + { + if( if_count == 0 ) + cerror("#else without matching #if"); + else + if_false = (if_false^1); + if( if_has_else ) + cerror("Multiple #else's for one #if"); + if_has_else = 1; + } + do_proc_tail(); +} + +static void +do_proc_endif() +{ + if( if_hidden ) + if_hidden--; + else + { + if( if_count == 0 ) + cerror("Unmatched #endif"); + else + { + if_count--; + if_false=0; + if_has_else = (if_stack&1); + if_stack >>=1; + } + } + do_proc_tail(); +} + +static void +do_proc_tail() +{ + int ch, flg=1; + while((ch = pgetc()) != '\n') if(ch > ' ') + { + if (!if_false && flg) + cwarn("Unexpected text following preprocessor command"); + flg=0; + } +} + +static int +get_if_expression() +{ + int value = get_expression(0); + + if (curtok != '\n') + do_proc_tail(); + + return value; +} + +static int_type +get_expression(prio) +int prio; +{ + int_type lvalue; + int_type rvalue; + int no_op = 0; + + curtok = get_onetok(SKIP_SPACE); + lvalue = get_exp_value(); + + do + { + switch(curtok) + { + case '*': case '/': case '%': + if (prio >= 10) return lvalue; + break; + case '+': case '-': + if (prio >= 9) return lvalue; + break; + case TK_RIGHT_OP: case TK_LEFT_OP: + if (prio >= 8) return lvalue; + break; + case '<': case '>': case TK_LE_OP: case TK_GE_OP: + if (prio >= 7) return lvalue; + break; + case TK_EQ_OP: case TK_NE_OP: + if (prio >= 6) return lvalue; + break; + case '&': + if (prio >= 5) return lvalue; + break; + case '^': + if (prio >= 4) return lvalue; + break; + case '|': + if (prio >= 3) return lvalue; + break; + case TK_AND_OP: + if (prio >= 2) return lvalue; + break; + case TK_OR_OP: + if (prio >= 1) return lvalue; + break; + } + switch(curtok) + { + case '*': + rvalue = get_expression(10); + lvalue *= rvalue; + break; + case '/': + rvalue = get_expression(10); + if (rvalue) + lvalue /= rvalue; + break; + case '%': + rvalue = get_expression(10); + if (rvalue) + lvalue %= rvalue; + break; + case '+': + rvalue = get_expression(9); + lvalue += rvalue; + break; + case '-': + rvalue = get_expression(9); + lvalue -= rvalue; + break; + case TK_RIGHT_OP: + rvalue = get_expression(8); + lvalue >>= rvalue; + break; + case TK_LEFT_OP: + rvalue = get_expression(8); + lvalue <<= rvalue; + break; + case '<': + rvalue = get_expression(7); + lvalue = (lvalue < rvalue); + break; + case '>': + rvalue = get_expression(7); + lvalue = (lvalue > rvalue); + break; + case TK_LE_OP: + rvalue = get_expression(7); + lvalue = (lvalue <= rvalue); + break; + case TK_GE_OP: + rvalue = get_expression(7); + lvalue = (lvalue >= rvalue); + break; + case TK_EQ_OP: + rvalue = get_expression(6); + lvalue = (lvalue == rvalue); + break; + case TK_NE_OP: + rvalue = get_expression(6); + lvalue = (lvalue != rvalue); + break; + case '&': + rvalue = get_expression(5); + lvalue = (lvalue & rvalue); + break; + case '^': + rvalue = get_expression(4); + lvalue = (lvalue ^ rvalue); + break; + case '|': + rvalue = get_expression(3); + lvalue = (lvalue | rvalue); + break; + case TK_AND_OP: + rvalue = get_expression(2); + lvalue = (lvalue && rvalue); + break; + case TK_OR_OP: + rvalue = get_expression(1); + lvalue = (lvalue || rvalue); + break; + + case '?': /* XXX: To add */ + + default: + no_op = 1; + } + } + while(prio == 0 && !no_op); + + return lvalue; +} + +static int_type +get_exp_value() +{ + int_type value = 0; + int sign = 1; + + if (curtok == '!') { + curtok = get_onetok(SKIP_SPACE); + return !get_exp_value(); + } + if (curtok == '~') { + curtok = get_onetok(SKIP_SPACE); + return ~get_exp_value(); + } + + while (curtok == '+' || curtok == '-') { + if (curtok == '-') sign = -sign; + curtok = get_onetok(SKIP_SPACE); + } + + if (curtok == TK_NUM) { + value = strtoul(curword, (void*)0, 0); + curtok = get_onetok(SKIP_SPACE); + } else if (curtok == TK_QUOT) { + value = curword[1]; + if (value == '\\') { + if (curword[2] >= '0' && curword[2] <= '7') { + value = curword[2] - '0'; + if (curword[3] >= '0' && curword[3] <= '7') { + value = (value<<3) + curword[3] - '0'; + if (curword[4] >= '0' && curword[4] <= '7') { + value = (value<<3) + curword[4] - '0'; + } + } + } else switch(curword[2]) { + case 'n': value = '\n'; break; + case 'f': value = '\f'; break; + case 't': value = '\t'; break; + default: value = curword[2]; break; + } + } +#ifdef NATIVE_CPP + value = (char) value; /* Fix range */ +#elif SIGNED_CHAR + value = (signed char) value; +#else + value = (unsigned char) value; +#endif + curtok = get_onetok(SKIP_SPACE); + } else if (curtok == TK_WORD) { + value = 0; + if (strcmp("defined", curword) == 0) { + curtok = gettok_nosub(); + if (curtok == '(' && gettok_nosub() != TK_WORD) + cerror("'defined' keyword requires argument"); + else { + value = (read_entry(0, curword) != 0); + if (curtok == '(' && gettok_nosub() != ')') + cerror("'defined' keyword requires closing ')'"); + else + curtok = get_onetok(SKIP_SPACE); + } + } + else + curtok = get_onetok(SKIP_SPACE); + + } else if (curtok == '(') { + value = get_expression(0); + if (curtok == ')') + curtok = get_onetok(SKIP_SPACE); + else { + curtok = '$'; + cerror("Expected ')'"); + } + } + + return sign<0 ? -value: value; +} + +void +gen_substrings(macname, data_str, arg_count, is_vararg) +char * macname; +char * data_str; +int arg_count; +int is_vararg; +{ + char * mac_text = 0; + struct arg_store *arg_list; + int ac, ch, cc, len; + + int paren_count = 0; + int in_quote = 0; + int quote_char = 0; + int commas_found = 0; + int args_found = 0; + + arg_list = malloc(sizeof(struct arg_store) * arg_count); + memset(arg_list, 0, sizeof(struct arg_store) * arg_count); + + for(ac=0; *data_str && ac < arg_count; data_str++) { + if( *data_str == ',' ) { ac++; continue; } + + if (arg_list[ac].name == 0) cc = len = 0; + + if (cc+2 >= len) { + len += 20; + arg_list[ac].name = realloc(arg_list[ac].name, len); + } + arg_list[ac].name[cc++] = *data_str; + arg_list[ac].name[cc] = '\0'; + } + + for(;;) { + if ((ch = chget()) == EOF) break; + if(in_quote == 2) { + in_quote = 1; + } else if (in_quote) { + if ( ch == quote_char ) in_quote = 0; + if ( ch == '\\') in_quote = 2; + } else { + if ( ch == '(' ) paren_count++; + if ( ch == '"' || ch == '\'' ) { in_quote = 1; quote_char = ch; } + if (paren_count == 0 && ch == ',' ) { + commas_found++; + if (commas_found < arg_count) + continue; + } + if ( ch == ')' ) { + if (paren_count == 0) break; + paren_count--; + } + } + args_found = 1; + /* Too many args, deal with, or ignore, the rest. */ + if (commas_found >= arg_count) { + if(arg_count == 0) continue; + ac = arg_count-1; + } else + ac = commas_found; + + if (arg_list[ac].value == 0) { + cc = len = 0; + arg_list[ac].in_define = def_count; + } + + if (cc+2 >= len) { + len += 20; + arg_list[ac].value = realloc(arg_list[ac].value, len); + } + +#if 0 + if (ch == '\n' && cc>0 && arg_list[ac].value[cc-1] == '\n' ) { + ... ? + } +#endif + + arg_list[ac].value[cc++] = ch; + arg_list[ac].value[cc] = '\0'; + } + + if (commas_found || args_found) args_found = commas_found+1; + + if( arg_count == 0 && args_found != 0 ) + cerror("Arguments given to macro without them."); + else if( !is_vararg && arg_count != args_found ) + cwarn("Incorrect number of macro arguments"); + + mac_text = insert_substrings(data_str, arg_list, arg_count); + + /* + * At this point 'mac_text' contains the full expansion of the macro. + * + * So we could scan this for calls to this macro and if we find one + * that _exactly_ matches this call (including arguments) then we mark + * this call's in_use flag. + * + * OTOH, it would probably be best to throw away this expansion and + * pretend we never noticed this macro expansion in the first place. + * + * Still this is mostly academic as the error trapping works and + * recursive macros _with_arguments_ are both rare and unpredictable. + */ + + if (arg_list) { + for (ac=0; ac\n", def_count, mac_text); +#endif +} + +static char * +insert_substrings(data_str, arg_list, arg_count) +char * data_str; +struct arg_store *arg_list; +int arg_count; +{ + int ac, ch; + char * p, * s; + char * rv = 0; + int len = 0; + int cc = 0; + int in_quote = 0; + int quote_char = 0; + int ansi_stringize = 0; + +#if CPP_DEBUG + fprintf(stderr, "\n### Macro substitution in '%s'\n", data_str); + for (ac=0; ac= '0' && ch <= '9') + || (ch >= 'A' && ch <= 'Z') + || (ch >= 'a' && ch <= 'z') + || ch == '_' || ch == '$' ) + *p++ = *data_str++; + else + break; + } + + if (p == curword) { + /* Ansi Stringize and concat */ + if (*data_str == '#' && dialect != DI_KNR) { + if (data_str[1] == '#') { + while(cc>0 && (rv[cc-1] == ' ' || rv[cc-1] == '\t')) + cc--; + data_str+=2; + while(*data_str == ' ' || *data_str == '\t') + data_str++; + if (*data_str == '\0') { /* Hummm */ + data_str--; + cerror("'##' operator at end of macro"); + } + continue; + } + data_str++; + ansi_stringize = 1; + continue; + } + + if (ansi_stringize) { + ansi_stringize = 0; + cerror("'#' operator should be followed by a macro argument name"); + } + + /* Other characters ... */ + if (cc+2 > len) { len += 20; rv = realloc(rv, len); } + rv[cc++] = *data_str++; + continue; + } + *p = '\0'; s = curword; + for (ac=0; acarg_count == -1) { + s = ptr->value; + } + } + + rv[cc++] = '"'; + while(*s == ' ' || *s == '\t') s++; + while (*s) { + if (cc+4 > len) { len += 20; rv = realloc(rv, len); } + if (*s == '"') rv[cc++] = '\\'; + rv[cc++] = *s++; + } + while(cc>0 && (rv[cc-1] == ' ' || rv[cc-1] == '\t')) + cc--; + rv[cc++] = '"'; + rv[cc++] = '\0'; + ansi_stringize = 0; + s = ""; + break; + } + + break; + } + } + + if (ansi_stringize) { + ansi_stringize = 0; + cerror("'#' operator should be followed by a macro argument name"); + } + + if (cc+2+strlen(s) > len) { len += strlen(s)+20; rv = realloc(rv, len); } + strcpy(rv+cc, s); + cc = strlen(rv); + } + + rv[cc] = '\0'; + return rv; +} diff -Nurd linux86.vold/cpp/hash.c linux86/cpp/hash.c --- linux86.vold/cpp/hash.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/hash.c 2004-06-20 12:12:28.000000000 +0100 @@ -0,0 +1,119 @@ + +#include +#ifdef __STDC__ +#include +#include +#else +#include +#endif +#include "cc.h" + +/* + * Two functions: + * char * set_entry(int namespace, char * name, void * value); + * returns a pointer to the copy of the name; + * + * void * read_entry(int namespace, char * name); + * returns the value; + */ + +struct hashentry +{ + struct hashentry * next; + void * value; + int namespace; + char word[1]; +}; + +struct hashentry ** hashtable; +int hashsize = 0xFF; /* 2^X -1 */ +int hashcount = 0; +static int hashvalue P((int namespace, char * word)); + +void * +read_entry(namespace, word) +int namespace; +char * word; +{ + int hash_val; + struct hashentry * hashline; + if( hashtable == 0 ) return 0; + hash_val = hashvalue(namespace, word); + + hashline = hashtable[hash_val]; + + for(; hashline; hashline = hashline->next) + { + if(namespace != hashline->namespace) continue; + if(word[0] != hashline->word[0]) continue; + if(strcmp(word, hashline->word) ) continue; + return hashline->value; + } + return 0; +} + +char * +set_entry(namespace, word, value) +int namespace; +char * word; +void * value; +{ + int hash_val, i; + struct hashentry * hashline, *prev; + hash_val = hashvalue(namespace, word); + + if( hashtable ) + { + hashline = hashtable[hash_val]; + + for(prev=0; hashline; prev=hashline, hashline = hashline->next) + { + if(namespace != hashline->namespace) continue; + if(word[0] != hashline->word[0]) continue; + if(strcmp(word, hashline->word) ) continue; + if( value ) hashline->value = value; + else + { + if( prev == 0 ) hashtable[hash_val] = hashline->next; + else prev->next = hashline->next; + free(hashline); + return 0; + } + return hashline->word; + } + } + if( value == 0 ) return 0; + if( hashtable == 0 ) + { + hashtable = malloc((hashsize+1)*sizeof(char*)); + if( hashtable == 0 ) cfatal("Out of memory"); + for(i=0; i<=hashsize; i++) hashtable[i] = 0; + } + /* Add record */ + hashline = malloc(sizeof(struct hashentry)+strlen(word)); + if( hashline == 0 ) cfatal("Out of memory"); + else + { + hashline->next = hashtable[hash_val]; + hashline->namespace = namespace; + hashline->value = value; + strcpy(hashline->word, word); + hashtable[hash_val] = hashline; + } + return hashline->word; +} + +static int hashvalue(namespace, word) +int namespace; +char * word; +{ + int val = namespace; + char *p = word; + + while(*p) + { + val = ((val<<4)^((val>>12)&0xF)^((*p++)&0xFF)); + } + val &= hashsize; + return val; +} diff -Nurd linux86.vold/cpp/main.c linux86/cpp/main.c --- linux86.vold/cpp/main.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/main.c 2003-11-02 08:12:14.000000000 +0000 @@ -0,0 +1,526 @@ + +#include +#if __STDC__ +#include +#include +#else +#include +#endif +#include +#include +#include + +#include "cc.h" + +#define MAXINCPATH 5 + +int main P((int argc, char ** argv)); +void undefine_macro P((char * name)); +void define_macro P((char * name)); +void print_toks_cpp P((void)); +void print_toks_raw P((void)); +void define_macro P((char *)); +void undefine_macro P((char *)); +void cmsg P((char * mtype, char * str)); +char * token_txn P((int)); +void pr_indent P((int)); +void hash_line P((void)); + +char * include_paths[MAXINCPATH]; + +char last_name[512] = ""; +int last_line = -1; +int debug_mode = 0; +int p_flag = 0; +int exit_code = 0; + +char * outfile = 0; +FILE * ofd = 0; + +int +main(argc, argv) +int argc; +char ** argv; +{ + int ar, i; + char * p; +static char Usage[] = "Usage: cpp -E -0 -Dxxx -Uxxx -Ixxx infile -o outfile"; + +#ifdef LC_CTYPE + setlocale(LC_CTYPE, ""); +#endif + + alltok = 1; /* Get all tokens from the cpp. */ + + for(ar=1; ar=argc) cfatal(Usage); + p = argv[ar]; + } + for(i=0; i=MAXINCPATH) + cfatal("Too many items in include path for CPP"); + break; + case 'D': + if (argv[ar][2]) p=argv[ar]+2; + else { + ar++; + if (ar>=argc) cfatal(Usage); + p = argv[ar]; + } + define_macro(p); + break; + case 'U': + if (argv[ar][2]) p=argv[ar]+2; + else { + ar++; + if (ar>=argc) cfatal(Usage); + p = argv[ar]; + } + undefine_macro(p); + break; + case 'o': + if (argv[ar][2]) p=argv[ar]+2; + else { + ar++; + if (ar>=argc) cfatal(Usage); + p = argv[ar]; + } + if (outfile) cfatal(Usage); + outfile = p; + break; + default: + fprintf(stderr, "CPP Unknown option %s\n", argv[ar]); + cfatal(Usage); + } else if (!curfile) { + /* Input file */ + curfile = fopen(argv[ar], "r"); + c_fname = argv[ar]; c_lineno = 1; + if (!curfile) + cfatal("Cannot open input file"); + } else + cfatal(Usage); + + if (!curfile) + cfatal(Usage); + + /* Define date and time macros. */ + if (dialect != DI_KNR) { + time_t now; + char * timep; + char buf[128]; + time(&now); + timep = ctime(&now); + + /* Yes, well */ + sprintf(buf, "__TIME__=\"%.8s\"", timep + 11); + define_macro(buf); + /* US order; Seems to be mandated by standard. */ + sprintf(buf, "__DATE__=\"%.3s %.2s %.4s\"", timep + 4, timep + 8, timep + 20); + define_macro(buf); + } + + if (outfile) ofd = fopen(outfile, "w"); + else ofd = stdout; + if (!ofd) + cfatal("Cannot open output file"); + + if (debug_mode) + print_toks_raw(); + else + print_toks_cpp(); + + if (outfile) fclose(ofd); + exit(exit_code); +} + +void +undefine_macro(name) +char * name; +{ + struct define_item * ptr; + + ptr = read_entry(0, name); + if (ptr) { + set_entry(0, name, (void*)0); + if (!ptr->in_use) free(ptr); + } +} + +void +define_macro(name) +char * name; +{ + char * p; + char * value; + struct define_item * ptr; + + if ((p=strchr(name, '=')) != 0) { + *p = 0; + value = p+1; + } else + value = "1"; + + undefine_macro(name); + + ptr = malloc(sizeof(struct define_item) + strlen(value)); + ptr->name = set_entry(0, name, ptr); + strcpy(ptr->value, value); + ptr->arg_count = -1; + ptr->in_use = 0; + ptr->next = 0; +} + +FILE * +open_include(fname, mode, checkrel) +char * fname; +char * mode; +int checkrel; +{ + FILE * fd = 0; + int i; + char buf[256], *p; + + if( checkrel ) + { + strcpy(buf, c_fname); + p = strrchr(buf, '/'); + if (p) *++p = 0; else *(p=buf) = 0; + strcpy(p, fname); + + fd=fopen(buf, mode); + } + if (!fd) { + for(i=0; i10) count=10; + while(count>0) {fprintf(ofd, "\t"); count--; } +} + +void +hash_line() +{ + if( strcmp(last_name, c_fname) != 0 ) last_line = -1; + if( c_lineno != last_line || last_line <= 0 ) + { + if( outpos != 0 ) { + fputc('\n', ofd); outpos=0; + if (last_line > 0) last_line++; + } + while( c_lineno > last_line && + (p_flag || c_lineno < last_line+4) && + last_line > 0 && + !debug_mode ) + { + fputc('\n', ofd); last_line++; + } + + if( !p_flag && (c_lineno != last_line || last_line <= 0 )) + { + fprintf(ofd, "# %d", c_lineno); + if( last_line <= 0 ) fprintf(ofd, " \"%s\"", c_fname); + fprintf(ofd, "\n"); + } + + strcpy(last_name, c_fname); + last_line = c_lineno; + } +} + +void +print_toks_cpp() +{ + int i; + int indent=0; + int paren=0; + + hash_line(); + while( (i=gettok()) != EOF ) + { + hash_line(); + switch(i) + { + case '\n': + cwarn("newline received from tokeniser!"); + break; + + case TK_STR: + outpos += fprintf(ofd, "%s", curword); + break; + + case TK_COPY: + if( outpos ) { fputc('\n', ofd); last_line++; } + outpos = 0; last_line++; + fprintf(ofd, "#%s\n", curword); + break; + + case TK_FILE: sprintf(curword, "\"%s\"", c_fname); if(0) { + case TK_LINE: sprintf(curword, "%d", c_lineno); + } + /*FALLTHROUGH*/ + default: + if (!alltok) { + if(i == '}' || i == TK_CASE || i == TK_DEFAULT ) indent--; + if(i ==')') paren--; + + if(outpos) { fputc(' ', ofd); outpos++; } + else pr_indent(indent+(paren!=0)); + + if(i == '{' || i == TK_CASE || i == TK_DEFAULT ) indent++; + if(i ==';') paren=0; + if(i =='(') paren++; + } + + outpos += fprintf(ofd, "%s", curword); + + if ( i == '"' || i == '\'' ) + { + while((i=gettok()) == TK_STR) { + outpos += fprintf(ofd, "%s", curword); + } + if (i != '\n') + outpos += fprintf(ofd, "%s", curword); + } + break; + } + } + if( outpos ) fputc('\n', ofd); + outpos = 0; +} + +void +print_toks_raw() +{ + int i; + long val; + + hash_line(); + while( (i=gettok()) != EOF ) + { + hash_line(); + switch(i) + { + case '"': case '\'': + if (debug_mode < 2) { + fprintf(ofd, "%-16s: %s", "Quoted string", curword); + while((i=gettok()) == TK_STR) + outpos+= fprintf(ofd, "%s", curword); + if ( i == '\n' ) fprintf(ofd, " --> EOL!!\n"); + else outpos+= fprintf(ofd, "%s\n", curword); + break; + } + /*FALLTHROUGH*/ + default: fprintf(ofd, "%-16s: '", token_txn(i)); + { + char *p; + for(p=curword; *p; p++) + if(isprint(*p) && *p != '\'' && *p != '\\') + fputc(*p, ofd); + else if (*p == '\n') fprintf(ofd, "\\n"); + else if (*p == '\t') fprintf(ofd, "\\t"); + else if (*p == '\v') fprintf(ofd, "\\v"); + else if (*p == '\b') fprintf(ofd, "\\b"); + else if (*p == '\r') fprintf(ofd, "\\r"); + else if (*p == '\f') fprintf(ofd, "\\f"); + else if (*p == '\a') fprintf(ofd, "\\a"); + else + fprintf(ofd, "\\x%02x", (unsigned char)*p); + } + fprintf(ofd, "'\n"); + break; + case TK_NUM: + val = strtoul(curword, (void*)0, 0); + fprintf(ofd, "%-16s: ", token_txn(i)); + fprintf(ofd, "%s => %ld\n", curword, val); + break; + case TK_COPY: + fprintf(ofd, "%-16s: ", token_txn(i)); + fprintf(ofd, "#%s\n", curword); + break; + case '\n': + fprintf(ofd, "%-16s:\n", "Newline char"); + break; + } + } +} + +char * +token_txn(token) +int token; +{ + char * s = "UNKNOWN"; + static char buf[17]; + + if (token> ' ' && token <= '~') + { + sprintf(buf, "TK_CHAR('%c')", token); + return buf; + } + if (token >= 0 && token < 0x100) + { + sprintf(buf, "TK_CHAR(%d)", token); + return buf; + } + + switch(token) + { + case TK_WSPACE : s="TK_WSPACE"; break; + case TK_WORD : s="TK_WORD"; break; + case TK_NUM : s="TK_NUM"; break; + case TK_FLT : s="TK_FLT"; break; + case TK_QUOT : s="TK_QUOT"; break; + case TK_STR : s="TK_STR"; break; + case TK_FILE : s="TK_FILE"; break; + case TK_LINE : s="TK_LINE"; break; + case TK_COPY : s="TK_COPY"; break; + case TK_NE_OP : s="TK_NE_OP"; break; + case TK_MOD_ASSIGN : s="TK_MOD_ASSIGN"; break; + case TK_AND_OP : s="TK_AND_OP"; break; + case TK_AND_ASSIGN : s="TK_AND_ASSIGN"; break; + case TK_MUL_ASSIGN : s="TK_MUL_ASSIGN"; break; + case TK_INC_OP : s="TK_INC_OP"; break; + case TK_ADD_ASSIGN : s="TK_ADD_ASSIGN"; break; + case TK_DEC_OP : s="TK_DEC_OP"; break; + case TK_SUB_ASSIGN : s="TK_SUB_ASSIGN"; break; + case TK_PTR_OP : s="TK_PTR_OP"; break; + case TK_ELLIPSIS : s="TK_ELLIPSIS"; break; + case TK_DIV_ASSIGN : s="TK_DIV_ASSIGN"; break; + case TK_LEFT_OP : s="TK_LEFT_OP"; break; + case TK_LEFT_ASSIGN : s="TK_LEFT_ASSIGN"; break; + case TK_LE_OP : s="TK_LE_OP"; break; + case TK_EQ_OP : s="TK_EQ_OP"; break; + case TK_GE_OP : s="TK_GE_OP"; break; + case TK_RIGHT_OP : s="TK_RIGHT_OP"; break; + case TK_RIGHT_ASSIGN : s="TK_RIGHT_ASSIGN"; break; + case TK_XOR_ASSIGN : s="TK_XOR_ASSIGN"; break; + case TK_OR_ASSIGN : s="TK_OR_ASSIGN"; break; + case TK_OR_OP : s="TK_OR_OP"; break; + case TK_AUTO : s="TK_AUTO"; break; + case TK_BREAK : s="TK_BREAK"; break; + case TK_CASE : s="TK_CASE"; break; + case TK_CHAR : s="TK_CHAR"; break; + case TK_CONST : s="TK_CONST"; break; + case TK_CONTINUE : s="TK_CONTINUE"; break; + case TK_DEFAULT : s="TK_DEFAULT"; break; + case TK_DO : s="TK_DO"; break; + case TK_DOUBLE : s="TK_DOUBLE"; break; + case TK_ELSE : s="TK_ELSE"; break; + case TK_ENUM : s="TK_ENUM"; break; + case TK_EXTERN : s="TK_EXTERN"; break; + case TK_FLOAT : s="TK_FLOAT"; break; + case TK_FOR : s="TK_FOR"; break; + case TK_GOTO : s="TK_GOTO"; break; + case TK_IF : s="TK_IF"; break; + case TK_INT : s="TK_INT"; break; + case TK_LONG : s="TK_LONG"; break; + case TK_REGISTER : s="TK_REGISTER"; break; + case TK_RETURN : s="TK_RETURN"; break; + case TK_SHORT : s="TK_SHORT"; break; + case TK_SIGNED : s="TK_SIGNED"; break; + case TK_SIZEOF : s="TK_SIZEOF"; break; + case TK_STATIC : s="TK_STATIC"; break; + case TK_STRUCT : s="TK_STRUCT"; break; + case TK_SWITCH : s="TK_SWITCH"; break; + case TK_TYPEDEF : s="TK_TYPEDEF"; break; + case TK_UNION : s="TK_UNION"; break; + case TK_UNSIGNED : s="TK_UNSIGNED"; break; + case TK_VOID : s="TK_VOID"; break; + case TK_VOLATILE : s="TK_VOLATILE"; break; + case TK_WHILE : s="TK_WHILE"; break; + } + return s; +} diff -Nurd linux86.vold/cpp/Makefile linux86/cpp/Makefile --- linux86.vold/cpp/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/Makefile 2002-08-03 07:18:31.000000000 +0100 @@ -0,0 +1,28 @@ +CFLAGS=-Wall -Wstrict-prototypes + +all: bcc-cpp + +bcc-cpp: main.o cpp.o hash.o token1.o token2.o + $(CC) $(CFLAGS) -o bcc-cpp main.o cpp.o hash.o token1.o token2.o + +clean realclean: + rm -f bcc-cpp main.o cpp.o hash.o token1.o token2.o tmp.h + +maintclean: realclean + rm -f token1.h token2.h + +main.o: cc.h +cpp.o: cc.h +hash.o: cc.h +tree.o: cc.h + +token1.o: token1.h +token2.o: token2.h + +token1.h: token1.tok + gperf -aptTc -N is_ctok -H hash1 token1.tok > tmp.h + mv tmp.h token1.h + +token2.h: token2.tok + gperf -aptTc -k1,3 -N is_ckey -H hash2 token2.tok > tmp.h + mv tmp.h token2.h diff -Nurd linux86.vold/cpp/token1.c linux86/cpp/token1.c --- linux86.vold/cpp/token1.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/token1.c 2003-11-02 08:11:22.000000000 +0000 @@ -0,0 +1,11 @@ + +#include +#include +#include "cc.h" + +#ifdef __GNUC__ +__inline +#endif +static unsigned int hash1 P((register const char *, register unsigned int)); + +#include "token1.h" diff -Nurd linux86.vold/cpp/token1.h linux86/cpp/token1.h --- linux86.vold/cpp/token1.h 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/token1.h 2002-08-03 18:21:06.000000000 +0100 @@ -0,0 +1,117 @@ +/* C code produced by gperf version 2.7.1 (19981006 egcs) */ +/* Command-line: gperf -aptTc -N is_ctok -H hash1 token1.tok */ + +#define TOTAL_KEYWORDS 23 +#define MIN_WORD_LENGTH 2 +#define MAX_WORD_LENGTH 3 +#define MIN_HASH_VALUE 2 +#define MAX_HASH_VALUE 63 +/* maximum key range = 62, duplicates = 0 */ + +#ifdef __GNUC__ +__inline +#endif +static unsigned int +hash1 (str, len) + register const char *str; + register unsigned int len; +{ + static unsigned char asso_values[] = + { + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 1, 64, 64, 64, 3, 25, 64, + 64, 64, 13, 18, 64, 8, 30, 15, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 5, 0, 20, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 30, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 23, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64 + }; + return len + asso_values[(unsigned char)str[len - 1]] + asso_values[(unsigned char)str[0]]; +} + +#ifdef __GNUC__ +__inline +#endif +struct token_trans * +is_ctok (str, len) + register const char *str; + register unsigned int len; +{ + static struct token_trans wordlist[] = + { + {""}, {""}, + {"==", TK_EQ_OP}, + {"!=", TK_NE_OP}, + {""}, + {"%=", TK_MOD_ASSIGN}, + {""}, + {"<=", TK_LE_OP}, + {"<<=", TK_LEFT_ASSIGN}, + {""}, + {"-=", TK_SUB_ASSIGN}, + {""}, + {"<<", TK_LEFT_OP}, + {""}, {""}, + {"*=", TK_MUL_ASSIGN}, + {""}, + {"/=", TK_DIV_ASSIGN}, + {"--", TK_DEC_OP}, + {""}, + {"+=", TK_ADD_ASSIGN}, + {""}, + {">=", TK_GE_OP}, + {">>=", TK_RIGHT_ASSIGN}, + {""}, + {"|=", TK_OR_ASSIGN}, + {""}, + {"&=", TK_AND_ASSIGN}, + {""}, {""}, + {"->", TK_PTR_OP}, + {""}, + {"^=", TK_XOR_ASSIGN}, + {""}, {""}, {""}, {""}, {""}, + {"++", TK_INC_OP}, + {""}, {""}, {""}, + {">>", TK_RIGHT_OP}, + {""}, {""}, {""}, {""}, {""}, + {"||", TK_OR_OP}, + {""}, {""}, {""}, + {"&&", TK_AND_OP}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {"..", TK_WORD}, + {"...", TK_ELLIPSIS} + }; + + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) + { + register int key = hash1 (str, len); + + if (key <= MAX_HASH_VALUE && key >= 0) + { + register const char *s = wordlist[key].name; + + if (*str == *s && !strncmp (str + 1, s + 1, len - 1)) + return &wordlist[key]; + } + } + return 0; +} diff -Nurd linux86.vold/cpp/token1.tok linux86/cpp/token1.tok --- linux86.vold/cpp/token1.tok 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/token1.tok 2002-07-29 09:35:43.000000000 +0100 @@ -0,0 +1,25 @@ +struct token_trans { char * name; int token; }; +%% +..., TK_ELLIPSIS +>>=, TK_RIGHT_ASSIGN +<<=, TK_LEFT_ASSIGN ++=, TK_ADD_ASSIGN +-=, TK_SUB_ASSIGN +*=, TK_MUL_ASSIGN +/=, TK_DIV_ASSIGN +%=, TK_MOD_ASSIGN +&=, TK_AND_ASSIGN +^=, TK_XOR_ASSIGN +|=, TK_OR_ASSIGN +>>, TK_RIGHT_OP +<<, TK_LEFT_OP +++, TK_INC_OP +--, TK_DEC_OP +->, TK_PTR_OP +&&, TK_AND_OP +||, TK_OR_OP +<=, TK_LE_OP +>=, TK_GE_OP +==, TK_EQ_OP +!=, TK_NE_OP +.., TK_WORD diff -Nurd linux86.vold/cpp/token2.c linux86/cpp/token2.c --- linux86.vold/cpp/token2.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/token2.c 2003-11-02 08:11:39.000000000 +0000 @@ -0,0 +1,11 @@ + +#include +#include +#include "cc.h" + +#ifdef __GNUC__ +__inline +#endif +static unsigned int hash2 P((register const char *, register unsigned int)); + +#include "token2.h" diff -Nurd linux86.vold/cpp/token2.h linux86/cpp/token2.h --- linux86.vold/cpp/token2.h 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/token2.h 2002-08-03 18:21:06.000000000 +0100 @@ -0,0 +1,139 @@ +/* C code produced by gperf version 2.7.1 (19981006 egcs) */ +/* Command-line: gperf -aptTc -k1,3 -N is_ckey -H hash2 token2.tok */ + +#define TOTAL_KEYWORDS 34 +#define MIN_WORD_LENGTH 2 +#define MAX_WORD_LENGTH 8 +#define MIN_HASH_VALUE 2 +#define MAX_HASH_VALUE 69 +/* maximum key range = 68, duplicates = 0 */ + +#ifdef __GNUC__ +__inline +#endif +static unsigned int +hash2 (str, len) + register const char *str; + register unsigned int len; +{ + static unsigned char asso_values[] = + { + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 5, 70, 70, 70, 70, 70, 0, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 0, 70, 5, 5, 10, + 10, 20, 20, 25, 70, 0, 70, 70, 50, 70, + 0, 15, 0, 70, 15, 0, 40, 20, 0, 0, + 70, 70, 10, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70 + }; + register int hval = len; + + switch (hval) + { + default: + case 3: + hval += asso_values[(unsigned char)str[2]]; + case 2: + case 1: + hval += asso_values[(unsigned char)str[0]]; + break; + } + return hval; +} + +#ifdef __GNUC__ +__inline +#endif +struct token_trans * +is_ckey (str, len) + register const char *str; + register unsigned int len; +{ + static struct token_trans wordlist[] = + { + {""}, {""}, + {"if", TK_IF}, + {""}, + {"void", TK_VOID}, + {"while", TK_WHILE}, + {"switch", TK_SWITCH}, + {""}, + {"__LINE__", TK_LINE}, + {""}, {""}, + {"static", TK_STATIC}, + {"do", TK_DO}, + {"__FILE__", TK_FILE}, + {"case", TK_CASE}, + {"const", TK_CONST}, + {"sizeof", TK_SIZEOF}, + {""}, + {"continue", TK_CONTINUE}, + {"char", TK_CHAR}, + {"short", TK_SHORT}, + {"struct", TK_STRUCT}, + {""}, {""}, + {"else", TK_ELSE}, + {"union", TK_UNION}, + {""}, {""}, + {"unsigned", TK_UNSIGNED}, + {""}, + {"break", TK_BREAK}, + {"signed", TK_SIGNED}, + {""}, {""}, {""}, {""}, + {"double", TK_DOUBLE}, + {"default", TK_DEFAULT}, + {"for", TK_FOR}, + {""}, + {"float", TK_FLOAT}, + {""}, {""}, + {"int", TK_INT}, + {"enum", TK_ENUM}, + {""}, {""}, + {"typedef", TK_TYPEDEF}, + {"register", TK_REGISTER}, + {"auto", TK_AUTO}, + {""}, {""}, {""}, {""}, + {"long", TK_LONG}, + {""}, {""}, {""}, + {"volatile", TK_VOLATILE}, + {""}, {""}, + {"return", TK_RETURN}, + {""}, {""}, {""}, {""}, + {"extern", TK_EXTERN}, + {""}, {""}, + {"goto", TK_GOTO} + }; + + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) + { + register int key = hash2 (str, len); + + if (key <= MAX_HASH_VALUE && key >= 0) + { + register const char *s = wordlist[key].name; + + if (*str == *s && !strncmp (str + 1, s + 1, len - 1)) + return &wordlist[key]; + } + } + return 0; +} diff -Nurd linux86.vold/cpp/token2.tok linux86/cpp/token2.tok --- linux86.vold/cpp/token2.tok 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/token2.tok 1996-08-10 17:53:36.000000000 +0100 @@ -0,0 +1,36 @@ +struct token_trans { char * name; int token; }; +%% +auto, TK_AUTO +break, TK_BREAK +case, TK_CASE +char, TK_CHAR +const, TK_CONST +continue, TK_CONTINUE +default, TK_DEFAULT +do, TK_DO +double, TK_DOUBLE +else, TK_ELSE +enum, TK_ENUM +extern, TK_EXTERN +float, TK_FLOAT +for, TK_FOR +goto, TK_GOTO +if, TK_IF +int, TK_INT +long, TK_LONG +register, TK_REGISTER +return, TK_RETURN +short, TK_SHORT +signed, TK_SIGNED +sizeof, TK_SIZEOF +static, TK_STATIC +struct, TK_STRUCT +switch, TK_SWITCH +typedef, TK_TYPEDEF +union, TK_UNION +unsigned, TK_UNSIGNED +void, TK_VOID +volatile, TK_VOLATILE +while, TK_WHILE +__FILE__, TK_FILE +__LINE__, TK_LINE diff -Nurd linux86.vold/cpp/torture.c linux86/cpp/torture.c --- linux86.vold/cpp/torture.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/cpp/torture.c 2002-08-02 18:32:28.000000000 +0100 @@ -0,0 +1,18 @@ +/\ +* \ This _evil_ little file is compilable Ansi C. +* / There are NO extensions ... Waddya think ? +\/ + +// ***/ func() { printf("Hello /* world */ %d ???/?=\n" ??/ +, 1? +'\\ +007': +'??/"'/*"*/ + );} + + +main() +{ + func(); + +} diff -Nurd linux86.vold/elksemu/elks.c linux86/elksemu/elks.c --- linux86.vold/elksemu/elks.c 1998-02-06 19:05:29.000000000 +0000 +++ linux86/elksemu/elks.c 2004-01-24 10:40:44.000000000 +0000 @@ -223,7 +223,8 @@ *pip++ = 0; } -void main(int argc, char *argv[], char *envp[]) +int +main(int argc, char *argv[], char *envp[]) { int fd; struct stat st; @@ -258,7 +259,7 @@ setregid(rgid, egid); setreuid(ruid, euid); - dbprintf(("ELKSEMU 0.12.0\n")); + dbprintf(("ELKSEMU\n")); elks_init(); /* The Linux vm will deal with not allocating the unused pages */ diff -Nurd linux86.vold/elksemu/elks.h linux86/elksemu/elks.h --- linux86.vold/elksemu/elks.h 1997-05-12 20:24:49.000000000 +0100 +++ linux86/elksemu/elks.h 2004-01-18 12:33:09.000000000 +0000 @@ -24,17 +24,17 @@ struct elks_stat { - unsigned short st_dev; - unsigned short st_inode; - unsigned short st_mode; - unsigned short st_nlink; - unsigned short st_uid; - unsigned short st_gid; - unsigned short st_rdev; - int st_size; - int st_atime; - int st_mtime; - int st_ctime; + unsigned short est_dev; + unsigned short est_inode; + unsigned short est_mode; + unsigned short est_nlink; + unsigned short est_uid; + unsigned short est_gid; + unsigned short est_rdev; + int est_size; + int est_atime; + int est_mtime; + int est_ctime; }; diff -Nurd linux86.vold/elksemu/elks_sys.c linux86/elksemu/elks_sys.c --- linux86.vold/elksemu/elks_sys.c 1999-07-02 08:12:13.000000000 +0100 +++ linux86/elksemu/elks_sys.c 2004-01-19 22:13:45.000000000 +0000 @@ -24,6 +24,8 @@ #include #include "elks.h" +#include "efile.h" + #ifdef DEBUG #define dbprintf(x) db_printf x #else @@ -69,17 +71,17 @@ ELKS_POKE(long, bx+26, s->st_ctime); #else struct elks_stat * ms = ELKS_PTR(struct elks_stat, bx); - ms->st_dev=s->st_dev; - ms->st_inode=(unsigned short)s->st_ino; /* Bits lost */ - ms->st_mode=s->st_mode; - ms->st_nlink=s->st_nlink; - ms->st_uid=s->st_uid; - ms->st_gid=s->st_gid; - ms->st_rdev=s->st_rdev; - ms->st_size=s->st_size; - ms->st_atime=s->st_atime; - ms->st_mtime=s->st_mtime; - ms->st_ctime=s->st_ctime; + ms->est_dev=s->st_dev; + ms->est_inode=(unsigned short)s->st_ino; /* Bits lost */ + ms->est_mode=s->st_mode; + ms->est_nlink=s->st_nlink; + ms->est_uid=s->st_uid; + ms->est_gid=s->st_gid; + ms->est_rdev=s->st_rdev; + ms->est_size=s->st_size; + ms->est_atime=s->st_atime; + ms->est_mtime=s->st_mtime; + ms->est_ctime=s->st_ctime; #endif } @@ -142,6 +144,17 @@ dbprintf(("open(%s, %d, %d)\n", dp,cx,dx)); + /* Nasty hack so /lib/liberror.txt doesn't exist on the host. + */ + if (strcmp(dp, "/lib/liberror.txt") == 0 ) { + int fd = open("/tmp/liberror.txt", O_CREAT|O_EXCL|O_RDWR, 0666); + if (fd < 0) return fd; + unlink("/tmp/liberror.txt"); + write(fd, efile, sizeof(efile)); + lseek(fd, 0L, 0); + return fd; + } + if( cx == O_RDONLY ) { if(stat(dp,&s)==-1) @@ -404,7 +417,7 @@ * * For now we run elksemu ourselves and do token attempts at binary checking. * - * Of course with the Patch in the Linux kernel we could just run the exe. + * Of course if the kernel misc module is confiured we could just run the exe. */ #define sys_execve elks_execve static int elks_execve(int bx,int cx,int dx,int di,int si) @@ -451,7 +464,7 @@ ct=0; if( is_elks ) { - argp[0]="/lib/elksemu"; + argp[0]="/usr/bin/elksemu"; /* argp[1]=ELKS_PTR(char, bx); */ ct=1; } diff -Nurd linux86.vold/elksemu/Makefile linux86/elksemu/Makefile --- linux86.vold/elksemu/Makefile 2001-01-06 12:33:39.000000000 +0000 +++ linux86/elksemu/Makefile 2004-10-02 14:58:49.000000000 +0100 @@ -26,13 +26,16 @@ elksemu: $(OBJ) $(CC) $(CFLAGS) -o $@ $^ -elks_sys.o: call_tab.v +elks_sys.o: call_tab.v efile.h $(OBJ): elks.h call_tab.v: dummy -cp -p ../libc/syscall/call_tab.v . 2>/dev/null -cp -p ../libc/syscall/defn_tab.v . 2>/dev/null +efile.h: ../libc/error/liberror.txt + sh mkefile ../libc/error/liberror.txt + dummy: # The kernel patch or module _requires_ this location but binfmt-misc is easy @@ -42,7 +45,7 @@ install -s -o root -g root -m 4555 elksemu $(DIST)/lib/elksemu clean realclean: - rm -f $(OBJ) binfmt_elks.o elksemu call_tab.v defn_tab.v + rm -f $(OBJ) binfmt_elks.o elksemu call_tab.v defn_tab.v efile.h module: binfmt_elks.o diff -Nurd linux86.vold/elksemu/mkefile linux86/elksemu/mkefile --- linux86.vold/elksemu/mkefile 1970-01-01 01:00:00.000000000 +0100 +++ linux86/elksemu/mkefile 2004-01-19 21:53:14.000000000 +0000 @@ -0,0 +1,11 @@ +#!/bin/sh - + +awk ' +BEGIN { + printf "char efile[] =\n" +} +{ printf " \"%s\\n\"\n", $0 } +END{ + printf ";\n"; +} +' < "$1" > efile.h diff -Nurd linux86.vold/elksemu/README linux86/elksemu/README --- linux86.vold/elksemu/README 1999-01-15 23:25:58.000000000 +0000 +++ linux86/elksemu/README 2004-01-18 12:43:48.000000000 +0000 @@ -3,12 +3,14 @@ real ELKS machine. The emulator only runs on linux-i386 or similar. If you're using a 2.0.36, 2.1.43, 2.2.0 or later kernel then the -binfmt_misc driver is in the stock kernel add the following line to a -/etc/rc*/* file and you don't need to install a patch or module! +binfmt_misc driver is in the stock kernel and all you need to do is +add the following line into the relevent /etc/rc* file. -echo ':i86-elks:M::\x01\x03\x20\x00:\xff\xff\xff\x83:/lib/elksemu:' \ +echo ':i86-elks:M::\x01\x03\x20\x00:\xff\xff\xff\x83:/usr/bin/elksemu:' \ > /proc/sys/fs/binfmt_misc/register +Note, however, if binfmt_misc is compiled as a module it will not auto +load so you will have to do this manually. If your kernel version is 1.2.13 then apply the patch in the Kernel_patch file. diff -Nurd linux86.vold/elksemu/Security linux86/elksemu/Security --- linux86.vold/elksemu/Security 1996-04-13 20:24:34.000000000 +0100 +++ linux86/elksemu/Security 2004-01-19 22:38:17.000000000 +0000 @@ -1,4 +1,4 @@ -The install scripts now install /lib/elksemu as a suid-root executable. +Is is possible to install /usr/bin/elksemu as a suid-root executable. This gives two additional facilities when running elks executables. 1) It is now possible to run programs that are execute only, without diff -Nurd linux86.vold/ifdef.c linux86/ifdef.c --- linux86.vold/ifdef.c 1999-07-23 08:56:52.000000000 +0100 +++ linux86/ifdef.c 2004-10-02 14:59:29.000000000 +0100 @@ -5,7 +5,7 @@ #include #ifdef __STDC__ /* == Not braindead compiler (hopefully!) */ -#include +#include #define P(x) x #else @@ -109,8 +109,19 @@ void Usage(prog) char * prog; { - fprintf(stderr, "Usage: %s [-DFLAG] [-UFLAG] [-blcrMDU] [-C##] files\n", + fprintf(stderr, "Usage: %s [-DFLAG] [-UFLAG] [-blcrhMDU] [-C##] files\n", prog); + fprintf(stderr, "\t-DFLAG\tDefine flag.\n"); + fprintf(stderr, "\t-UFLAG\tUndefine flag.\n"); + fprintf(stderr, "\t-C##\tComment out liines with '##'\n"); + fprintf(stderr, "\t-b\tRemove contents of lines leaving empty lines\n"); + fprintf(stderr, "\t-l\tUse #line lines.\n"); + fprintf(stderr, "\t-c\tComment out with '# '\n"); + fprintf(stderr, "\t-r\tRemove undefined lines completely.\n"); + fprintf(stderr, "\t-h\tRemove any line beginning with a '#'\n"); + fprintf(stderr, "\t-M\tInclude manifest constants.\n"); + fprintf(stderr, "\t-D\tAssume any unknown names are defined.\n"); + fprintf(stderr, "\t-U\tAssume any unknown names are undefined.\n"); exit(1); } @@ -430,7 +441,11 @@ #ifdef __linux__ save_name("__linux__", 'D'); #ifdef __i386__ - save_name("XX__linux_i386__", 'D'); + save_name("__elksemu_works__", 'D'); +#endif +/* Is this true ? */ +#ifdef __x86_64__ + save_name("__elksemu_works__", 'D'); #endif #endif #ifdef __unix__ @@ -484,4 +499,11 @@ #ifdef __minix save_name("__minix", 'D'); #endif +/* This isn't much nicer */ +#ifdef __CYGWIN__ + save_name("__CYGWIN__", 'D'); +#endif +#ifdef __APPLE__ + save_name("__APPLE__", 'D'); +#endif } diff -Nurd linux86.vold/later.c linux86/later.c --- linux86.vold/later.c 1996-12-01 09:09:12.000000000 +0000 +++ linux86/later.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,38 +0,0 @@ - -#include -#include -#include - -main(argc, argv) -int argc; -char ** argv; -{ - struct stat st; - long exe_mtime = 0; - int verbose = 0; - int ar; - - if( strcmp(argv[1], "+") == 0 ) { verbose++; argc--; argv++; } - - if( stat(argv[1], &st) < 0 ) - { - if( verbose ) printf("%s not found\n", argv[1]); - exit(2); - } - exe_mtime = st.st_mtime; - - for(ar=2; ar -# else -# define A_OUT_INCL "bsd-a.out.h" -# endif -# define A_OUT_INCL "a.out.h" /* maybe local copy of for X-link */ -# endif /* BSD_A_OUT */ +#define A_OUT_INCL #endif #include A_OUT_INCL @@ -75,4 +73,3 @@ #endif #endif /* NO_AOUT */ -#endif /* MSDOS */ diff -Nurd linux86.vold/ld/dumps.c linux86/ld/dumps.c --- linux86.vold/ld/dumps.c 1998-01-28 20:24:26.000000000 +0000 +++ linux86/ld/dumps.c 2003-10-07 09:02:28.000000000 +0100 @@ -83,4 +83,12 @@ putbyte('\n'); } } + + putstr("Total memory used: "); +#ifdef LONG_OFFSETS + put08lx(memory_used()); +#else + put08x(memory_used()); +#endif + putbyte('\n'); } diff -Nurd linux86.vold/ld/globvar.h linux86/ld/globvar.h --- linux86.vold/ld/globvar.h 1996-12-01 17:52:24.000000000 +0000 +++ linux86/ld/globvar.h 2002-12-04 21:11:19.000000000 +0000 @@ -13,6 +13,9 @@ /* K&R _explicitly_ says extern followed by public is OK */ extern char hexdigit[]; /* constant */ extern int headerless; /* Don't output header on exe */ +#ifndef MSDOS +extern int cpm86; /* Generate CP/M-86 CMD header */ +#endif extern bin_off_t text_base_value; /* Base address of text seg */ extern bin_off_t data_base_value; /* Base or alignment of data seg */ diff -Nurd linux86.vold/ld/include/fcntl.h linux86/ld/include/fcntl.h --- linux86.vold/ld/include/fcntl.h 1996-01-06 13:36:03.000000000 +0000 +++ linux86/ld/include/fcntl.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,2 +0,0 @@ -#define O_RDONLY 0 -#define O_WRONLY 1 diff -Nurd linux86.vold/ld/io.c linux86/ld/io.c --- linux86.vold/ld/io.c 1998-01-28 20:02:04.000000000 +0000 +++ linux86/ld/io.c 2004-06-03 19:51:34.000000000 +0100 @@ -6,6 +6,7 @@ #include "const.h" #include "type.h" #include "globvar.h" +#include "version.h" #define DRELBUFSIZE 3072 #define ERR (-1) @@ -127,8 +128,10 @@ PUBLIC void executable() { + if (errcount) + unlink(outputname); #ifndef MSDOS - if (errcount == 0) + else chmod(outputname, outputperms); #endif } @@ -612,11 +615,22 @@ #ifdef REL_OUTPUT errexit("\ [-03NMdimrstz[-]] [-llib_extension] [-o outfile] [-Ccrtfile]\n\ - [-Llibdir] [-Olibfile] [-T textaddr] [-D dataaddr] [-H heapsize] infile..."); + [-Llibdir] [-Olibfile] [-Ttextaddr] [-Ddataaddr] [-Hheapsize] infile..."); #else errexit("\ [-03NMdimstz[-]] [-llib_extension] [-o outfile] [-Ccrtfile]\n\ - [-Llibdir] [-Olibfile] [-T textaddr] [-D dataaddr] [-H heapsize] infile..."); + [-Llibdir] [-Olibfile] [-Ttextaddr] [-Ddataaddr] [-Hheapsize] infile..."); +#endif +} + +PUBLIC void version_msg() +{ + stderr_out(); +#ifdef VERSION + putstr("ld86 version: "); + errexit(VERSION); +#else + errexit("ld86 version unknown"); #endif } diff -Nurd linux86.vold/ld/ld86r.c linux86/ld/ld86r.c --- linux86.vold/ld/ld86r.c 1997-10-05 12:39:35.000000000 +0100 +++ linux86/ld/ld86r.c 2003-10-06 11:51:58.000000000 +0100 @@ -1,8 +1,13 @@ #include +#include #include #include -#include +#ifdef __STDC__ +#include +#include +#else #include +#endif #define ARMAG "!\n" #define SARMAG 8 diff -Nurd linux86.vold/ld/ld.c linux86/ld/ld.c --- linux86.vold/ld/ld.c 1998-12-30 12:20:50.000000000 +0000 +++ linux86/ld/ld.c 2004-01-21 21:17:09.000000000 +0000 @@ -19,6 +19,9 @@ PUBLIC bin_off_t data_base_value = 0; /* XXX */ PUBLIC bin_off_t heap_top_value = 0; /* XXX */ PUBLIC int headerless = 0; +#ifndef MSDOS +PUBLIC int cpm86 = 0; +#endif PUBLIC char hexdigit[] = "0123456789abcdef"; PRIVATE bool_t flag[128]; @@ -50,13 +53,15 @@ PRIVATE char *expandlib(fn) char *fn; { - char *path; + char *path, *s; int i; for (i = lastlib - 1; i >= 0; --i) { - path = ourmalloc(strlen(libs[i]) + strlen(fn) + 1); + path = ourmalloc(strlen(libs[i]) + strlen(fn) + 2); strcpy(path, libs[i]); + s = path + strlen(path); + if (s!=path && s[-1] != '/') strcat(path, "/"); strcat(path, fn); if (access(path, R_OK) == 0) return path; @@ -99,17 +104,13 @@ else switch (arg[1]) { + case 'v': + version_msg(); case 'r': /* relocatable output */ -#ifndef REL_OUTPUT -#ifndef MSDOS - /* Ok, try for an alternate linker */ - if( strcmp(argv[0], "ld86r") != 0 ) - { - argv[0] = "ld86r"; - execv("/usr/bin/ld86r", argv); - } -#endif - usage(); + case 't': /* trace modules linked */ + if (icount > 0) usage(); +#ifdef REL_OUTPUT + case 'B': /* Broken -r for dosemu. */ #endif case '0': /* use 16-bit libraries */ case '3': /* use 32-bit libraries */ @@ -117,10 +118,12 @@ case 'i': /* separate I & D output */ case 'm': /* print modules linked */ case 's': /* strip symbols */ - case 't': /* trace modules linked */ case 'z': /* unmapped zero page */ case 'N': /* Native format a.out */ case 'd': /* Make a headerless outfile */ +#ifndef MSDOS + case 'c': /* Write header in CP/M-86 format */ +#endif case 'y': /* Use a newer symbol table */ if (arg[2] == 0) flag[(int) arg[1]] = TRUE; @@ -201,22 +204,21 @@ usage(); } } - if(icount==0) fatalerror("no input files"); + if(icount==0) usage(); + +#ifdef BUGCOMPAT + if( icount==1 && ( flag['r'] && !flag['N'] ) ) { + flag['r'] = 0; + flag['B'] = 1; + } +#endif #ifdef REL_OUTPUT #ifndef MSDOS -#ifdef BUGCOMPAT - if( icount>1 && ( flag['r'] && !flag['N'] ) ) -#else if( flag['r'] && !flag['N'] ) -#endif { - /* Ok, try for an alternate linker */ - if( strcmp(argv[0], "ld86r") != 0 ) - { - argv[0] = "ld86r"; - execv("/usr/bin/ld86r", argv); - } + /* Do a relocatable link -- actually fake it with 'ar.c' */ + ld86r(argc, argv); } #endif #endif @@ -235,7 +237,13 @@ headerless = flag['d']; if( headerless ) flag['s'] = 1; - linksyms(flag['r']); +#ifndef MSDOS + /* CP/M-86 executables can't use symbols. */ + cpm86 = flag['c']; + if ( cpm86 ) flag['s'] = 1; +#endif + + linksyms(flag['r'] | flag['B']); if (outfilename == NUL_PTR) outfilename = "a.out"; #ifndef MSDOS @@ -244,12 +252,10 @@ flag['z'] & flag['3']); else #endif -#ifdef BUGCOMPAT - if( flag['r'] ) - write_rel(outfilename, flag['i'], flag['3'], flag['s'], - flag['z'] & flag['3']); + if( flag['B'] ) + write_dosemu(outfilename, flag['i'], flag['3'], flag['s'], + flag['z'] & flag['3']); else -#endif write_elks(outfilename, flag['i'], flag['3'], flag['s'], flag['z'], flag['y']); if (flag['m']) diff -Nurd linux86.vold/ld/Makefile linux86/ld/Makefile --- linux86.vold/ld/Makefile 2001-01-06 10:02:20.000000000 +0000 +++ linux86/ld/Makefile 2003-10-06 18:14:16.000000000 +0100 @@ -3,29 +3,31 @@ CFLAGS =-O LDFLAGS = -# May need some of these if the auto-sense fails. +# Will need some of these if you want native executables on non-Linux/i386 +# -DDETECTAOUT # Turn on detection. # -DV7_A_OUT # a.out.h is like V7 # -DBSD_A_OUT # a.out.h is like BSD # -DSTANDARD_GNU_A_OUT # a.out.h is like GNU normal. -# -DNO_AOUT # a.out.h is like nothing known! # -DEFS =-DREL_OUTPUT -DBUGCOMPAT +# -DREL_OUTPUT -DBUGCOMPAT # -r Produces weird *.o files. +# +DEFS =-DREL_OUTPUT # An alternative file for a non-standard a.out.h (eg i386 linux on an Alpha) # # NATIVE=-DA_OUT_INCL='"a_out_local.h"' -OBJS= dumps.o io.o ld.o readobj.o table.o typeconv.o linksyms.o \ - writex86.o writebin.o writerel.o +OBJS= dumps.o io.o ld.o readobj.o table.o typeconv.o linksyms.o mkar.o \ + writex86.o writebin.o writeemu.o all: ld86 objchop catimage objdump86 ld86: $(OBJS) - $(CC) $(LDFLAGS) $^ -o $@ + $(CC) $(LDFLAGS) $(OBJS) -o $@ install: ld86 install -d $(LIBDIR) - install -m 755 $^ $(LIBDIR) + install -m 755 ld86 $(LIBDIR) clean realclean clobber: rm -f *.o ld86 ld86r objchop catimage objdump86 @@ -34,7 +36,7 @@ syshead.h type.h x86_aout.h ar.h: - [ -f ar.h ] || \ + test -f ar.h || \ { rm -f ar.h ; ln -s ../libc/include/ar.h . ; } || \ ln ../libc/include/ar.h . diff -Nurd linux86.vold/ld/mkar.c linux86/ld/mkar.c --- linux86.vold/ld/mkar.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/ld/mkar.c 2004-06-20 08:23:27.000000000 +0100 @@ -0,0 +1,79 @@ + +#include +#include +#include +#include +#ifdef __STDC__ +#include +#include +#else +#include +#endif + +#include "ar.h" + +static struct ar_hdr arbuf; + +#ifdef __STDC__ +void +ld86r(int argc, char ** argv) +#else +ld86r(argc, argv) + int argc; char ** argv; +#endif +{ +char buf[128]; + FILE * fd, * ifd; + struct stat st; + int ar, libarg=0, need_o = 0, got_o = 0; + + for(ar=1; ar 1 || need_o > got_o ) + fatalerror("-o option required for -r"); + + if( (fd =fopen(argv[libarg], "wb")) == 0 ) fatalerror("Cannot open archive"); + if( fwrite(ARMAG, 1, SARMAG, fd) != SARMAG) fatalerror("Cannot write magic"); + + for(ar=1; ar -#include -#include #ifdef __STDC__ #include +#else +#include #endif +#include +#include "const.h" #include "ar.h" #include "obj.h" @@ -36,6 +38,7 @@ long get_long _((void)); long get_sized _((int sz)); unsigned int get_word _((void)); +int get_byte _((void)); int main _((int argc, char**argv)); void do_file _((char * fname)); long read_arheader _((char *archentry)); @@ -44,6 +47,8 @@ int read_objheader _((void)); int read_sectheader _((void)); int read_syms _((void)); +void disp_sectheader _((void)); +int disp_syms _((void)); void read_databytes _((void)); void hex_output _((int ch)); void fetch_aout_hdr _((void)); @@ -51,20 +56,33 @@ void size_aout _((void)); void nm_aout _((void)); +int obj_ver; int sections; long segsizes[16]; -long textoff, textlen; -long str_off, str_len; +long textoff; +long textlen; +long str_off; +long str_len; long filepos; +int num_syms; +long code_bytes; char ** symnames; -char * symtab; +char * strtab; + +struct { + unsigned int nameoff, symtype; + long offset; +} *symtab; int display_mode = 0; int multiple_files = 0; int byte_order = 0; +int opt_o; + long size_text, size_data, size_bss; +long tot_size_text=0, tot_size_data=0, tot_size_bss=0; int main(argc, argv) @@ -89,6 +107,7 @@ { case 's': display_mode = 1; break; case 'n': display_mode = 2; break; + case 'o': opt_o++; break; } else multiple_files++; @@ -104,6 +123,12 @@ for(ar=1; ar>(2*(15-ss)))&3); segsizes[i] = get_sized(ss); - if( segsizes[i] && !display_mode ) - printf("SEG%x %08lx\n", i, segsizes[i]); } - if( !display_mode ) - printf("\n"); + + num_syms = get_word(); /* Number of symbol codes */ return 0; } +void +disp_sectheader() +{ + int i; + if( display_mode ) return; + + printf("MODULE '%s'\n", strtab); + printf("BYTEPOS %08lx\n", textoff); + printf("BINLEN %08lx\n", textlen); + printf("STRINGS %04lx +%04lx\n", str_off, str_len); + printf("VERSION %d.%d\n", obj_ver/256, obj_ver%256); + + for(i=0; i<16; i++) + if( segsizes[i] ) + printf("SEG%x %08lx\n", i, segsizes[i]); + + printf("\n"); + printf("SYMS %u\n", num_syms); +} + int read_syms() { - int syms, i; - - syms=get_word(); + int i; - if( !display_mode ) printf("SYMS %u\n", syms); - if( syms < 0 ) return error("Bad symbol table"); + if( num_syms < 0 ) return error("Bad symbol table"); - symnames = malloc(syms*sizeof(char*)+1); + symnames = malloc(num_syms*sizeof(char*)+1); if( symnames == 0 ) return error("Out of memory"); - if(display_mode == 2 && multiple_files) + symtab = calloc(num_syms, sizeof(*symtab)); + if( symtab == 0 ) return error("Out of memory"); + + for(i=0; i>14)&3); + + if( symtype == 0x43 || symtype == 0x2003 ) + size_bss += symtab[i].offset; + } + + return 0; +} + +int +disp_syms() +{ + int i; + + if(display_mode == 2 && multiple_files && !opt_o) printf("\n%s:\n", ifname); - for(i=0; i>14)&3); + nameoff = symtab[i].nameoff; + symtype = symtab[i].symtype; + offset = symtab[i].offset; + symtype &= 0x3FFF; - symnames[i] = symtab+nameoff; + if (nameoff > str_len || nameoff < 0) + symnames[i] = strtab + str_len; + else + symnames[i] = strtab+nameoff; if( !display_mode ) { @@ -390,6 +445,8 @@ } if( display_mode == 2 ) { + if (opt_o) + printf("%s: ", ifname); if( symtype == 0x004f || symtype == 0x0040 ) printf(" "); else @@ -418,9 +475,6 @@ } printf(" %s\n", symnames[i]); } - - if( symtype == 0x43 || symtype == 0x2003 ) - size_bss += offset; } if( !display_mode ) printf("\n"); @@ -432,16 +486,18 @@ read_databytes() { static char * relstr[] = {"ERR", "DB", "DW", "DD"}; - long l; + long l, cpos; int ch, i; int curseg = 0; int relsize = 0; + + cpos = ftell(ifd); fseek(ifd, filepos+textoff, 0); printf("\nBYTECODE\n"); for(;;) { - if( (ch=getc(ifd)) == EOF ) break; + if( (ch=get_byte()) == -1 ) break; if( ch == 0 ) break; @@ -460,7 +516,7 @@ printf("SEG %x\n", curseg= (ch&0xF)); break; default: printf("CODE %02x - unknown\n", ch); - return ; + goto break_break ; } break; case 0x40: /* Raw bytes */ @@ -469,12 +525,12 @@ if( abscnt == 0 ) abscnt = 64; for( i=0; i 16) @@ -737,6 +810,8 @@ } if( pending_nl ) putchar('\n'); + if (opt_o) + printf("%s: ", ifname); if( n_sclass == 0x10 ) printf(" "); else diff -Nurd linux86.vold/ld/obj.h linux86/ld/obj.h --- linux86.vold/ld/obj.h 1996-06-29 16:47:35.000000000 +0100 +++ linux86/ld/obj.h 2004-06-20 09:40:10.000000000 +0100 @@ -4,10 +4,6 @@ #define OBJ_H -#ifdef I80386 -# define LONG_OFFSETS /* others can use this, but wasteful */ -#endif - #ifndef OMAGIC # ifdef I80386 # define OMAGIC 0x86A3 diff -Nurd linux86.vold/ld/syshead.h linux86/ld/syshead.h --- linux86.vold/ld/syshead.h 1997-10-17 19:53:21.000000000 +0100 +++ linux86/ld/syshead.h 2002-08-24 07:20:00.000000000 +0100 @@ -23,8 +23,9 @@ #define R_OK 0 #define mode_t unsigned short #define SEEK_SET 0 -#define STDOUT_FILENO 0 -#define STDERR_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 +#define VERSION "MSDOS Compile" #endif /******************************************************************************/ @@ -54,7 +55,7 @@ #define R_OK 0 int access P((const char *path, int amode)); #define SEEK_SET 0 -#define STDOUT_FILENO 0 +#define STDOUT_FILENO 1 #define STDERR_FILENO 2 #define mode_t unsigned short diff -Nurd linux86.vold/ld/table.c linux86/ld/table.c --- linux86.vold/ld/table.c 1996-07-22 00:36:33.000000000 +0100 +++ linux86/ld/table.c 2003-10-07 20:35:17.000000000 +0100 @@ -16,7 +16,11 @@ PRIVATE char *tableptr; /* next free spot in catchall table */ PRIVATE char *tableend; /* ptr to spot after last in table */ +PUBLIC int maxused = 0; /* Stats */ +PRIVATE int mainavail, usedtop; /* Stats */ + FORWARD struct symstruct **gethashptr P((char *name)); +FORWARD void check_used P((void)); /* initialise symbol table */ @@ -33,6 +37,9 @@ tableend = tableptr + i; for (i = 0; i < HASHTABSIZE; i++) hashtab[i] = NUL_PTR; + + mainavail = tableend - tableptr; + usedtop = 0; } /* add named symbol to end of table - initialise only name and next fields */ @@ -130,6 +137,9 @@ register char *source; register char *target; + usedtop += nbytes; + mainavail -= nbytes; + source = tableptr; target = tableend; while (nbytes--) @@ -157,7 +167,9 @@ PUBLIC void ourfree(cptr) char *cptr; { + check_used(); tableptr = cptr; + check_used(); } /* read string from file into table at offset suitable for next symbol */ @@ -172,6 +184,7 @@ start = s = ((struct symstruct *) tableptr)->name; while (TRUE) { + /* Stats: need a checkused against 's', maybe. */ if (s >= tableend) outofmemory(); if ((c = readchar()) < 0) @@ -187,9 +200,27 @@ PUBLIC void release(cptr) char *cptr; { + check_used(); + mainavail += cptr - tableend; + usedtop -= cptr - tableend; + tableend = cptr; } +PRIVATE void check_used() +{ + int used; + + used = usedtop + mainavail - (tableend - tableptr); + if (used > maxused) maxused = used; +} + +PUBLIC int memory_used() +{ + check_used(); + return maxused; +} + /* allocate space for string */ PUBLIC char *stralloc(s) diff -Nurd linux86.vold/ld/typeconv.c linux86/ld/typeconv.c --- linux86.vold/ld/typeconv.c 1997-06-07 08:38:46.000000000 +0100 +++ linux86/ld/typeconv.c 2002-02-17 21:37:57.000000000 +0000 @@ -15,8 +15,8 @@ static int no_swap = 1; -static long_off[4] = {0,1,2,3}; -static int_off[2] = {0,1}; +static int long_off[4] = {0,1,2,3}; +static int int_off[2] = {0,1}; PUBLIC bool_pt typeconv_init(big_endian, long_big_endian) bool_pt big_endian; diff -Nurd linux86.vold/ld/type.h linux86/ld/type.h --- linux86.vold/ld/type.h 1998-12-30 12:21:25.000000000 +0000 +++ linux86/ld/type.h 2003-10-07 20:35:51.000000000 +0100 @@ -119,6 +119,7 @@ void size_error P((int seg, bin_off_t count, bin_off_t size)); void undefined P((char *name)); void usage P((void)); +void version_msg P((void)); void use_error P((char *message)); /* ld.c */ @@ -143,6 +144,7 @@ void ourfree P((char *cptr)); char *readstring P((void)); void release P((char *cptr)); +int memory_used P((void)); char *stralloc P((char *s)); /* typeconvert.c */ @@ -160,7 +162,7 @@ void writebin P((char *outfilename, bool_pt argsepid, bool_pt argbits32, bool_pt argstripflag, bool_pt arguzp)); -void write_rel P((char *outfilename, bool_pt argsepid, bool_pt argbits32, +void write_dosemu P((char *outfilename, bool_pt argsepid, bool_pt argbits32, bool_pt argstripflag, bool_pt arguzp)); /* write_elks.c */ diff -Nurd linux86.vold/ld/writebin.c linux86/ld/writebin.c --- linux86.vold/ld/writebin.c 1999-03-14 13:07:12.000000000 +0000 +++ linux86/ld/writebin.c 2003-10-07 20:21:02.000000000 +0100 @@ -3,12 +3,6 @@ /* Copyright (C) 1994 Bruce Evans */ -#ifndef NO_AOUT -#ifndef A_OUT_INCL -#define A_OUT_INCL -#endif -#endif - #include "syshead.h" #include "bindef.h" #include "const.h" @@ -1053,13 +1047,19 @@ } #else -PUBLIC void writebin(outfilename, argsepid, argbits32, argstripflag, arguzp) +#ifndef FUNCNAME +#define FUNCNAME writebin +#endif + +PUBLIC void FUNCNAME(outfilename, argsepid, argbits32, argstripflag, arguzp) char *outfilename; bool_pt argsepid; bool_pt argbits32; bool_pt argstripflag; bool_pt arguzp; { - fatalerror("Native a.out generation not included, sorry"); + char * s = "WARNING: Native a.out generation not included, sorry\n"; + write(2, s, strlen(s)); + write_elks(outfilename, argsepid, argbits32, argstripflag, arguzp, 0); } #endif diff -Nurd linux86.vold/ld/writeemu.c linux86/ld/writeemu.c --- linux86.vold/ld/writeemu.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/ld/writeemu.c 2003-10-07 20:19:36.000000000 +0100 @@ -0,0 +1,20 @@ +/* + * This uses a special version of writebin for bug compatibility with + * the old bin86 package. + * + * This _should_ be replaced by a function that writes out a as86 object + * but then it would completely **** up dosemu compiles. + * + * NOTE: A some time I intend to replace this with a routine that generates + * an as86 object file. + */ + +#undef A_OUT_INCL +#define A_OUT_INCL "rel_aout.h" +#define BSD_A_OUT 1 +#define FILEHEADERLENGTH 32 +#define ELF_SYMS 0 + +#define FUNCNAME write_dosemu + +#include "writebin.c" diff -Nurd linux86.vold/ld/writerel.c linux86/ld/writerel.c --- linux86.vold/ld/writerel.c 1997-04-23 22:05:51.000000000 +0100 +++ linux86/ld/writerel.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,22 +0,0 @@ -/* - * This uses a special version of writebin for bug compatibility with - * the old bin86 package. - * - * This _should_ be replaced by a function that writes out a as86 object - * but then it would completely **** up dosemu compiles. - * - * NOTE: A some time I intend to replace this with a routine that generates - * an as86 object file. - */ - -#ifdef BUGCOMPAT -#define A_OUT_INCL "rel_aout.h" -#define BSD_A_OUT 1 -#define FILEHEADERLENGTH 32 -#define ELF_SYMS 0 - -#define FUNCNAME write_rel -#undef NO_AOUT - -#include "writebin.c" -#endif diff -Nurd linux86.vold/ld/writex86.c linux86/ld/writex86.c --- linux86.vold/ld/writex86.c 1998-12-30 12:45:29.000000000 +0000 +++ linux86/ld/writex86.c 2003-01-31 21:26:15.000000000 +0000 @@ -4,6 +4,9 @@ #include "syshead.h" #include "x86_aout.h" +#ifndef MSDOS +#include "x86_cpm86.h" +#endif #include "const.h" #include "obj.h" #include "type.h" @@ -17,7 +20,11 @@ #define ELF_SYMS 0 #endif +#ifdef MSDOS # define FILEHEADERLENGTH (headerless?0:A_MINHDR) +#else +# define FILEHEADERLENGTH (headerless?0:(cpm86?CPM86_HEADERLEN:A_MINHDR)) +#endif /* part of header not counted in offsets */ #define DPSEG 2 @@ -76,6 +83,9 @@ FORWARD void setseg P((fastin_pt newseg)); FORWARD void skip P((unsigned countsize)); FORWARD void writeheader P((void)); +#ifndef MSDOS +FORWARD void cpm86header P((void)); +#endif FORWARD void writenulls P((bin_off_t count)); EXTERN bool_t reloc_output; @@ -143,6 +153,7 @@ curseg = 3; symres("__edata"); symres("__end"); + symres("__heap_top"); curseg = 0; /* text seg, s.b. variable */ symres("__etext"); symres("__segoff"); @@ -315,8 +326,17 @@ fatalerror("data segment too large for 16bit"); } + if( heap_top_value < 0x100 || endoffset > heap_top_value-0x100) + heap_top_value = endoffset + 0x8000; + if( heap_top_value > 0x10000 && !bits32 ) heap_top_value = 0x10000; + setsym("__heap_top", (bin_off_t)heap_top_value); + openout(outfilename); - writeheader(); +#ifndef MSDOS + if (cpm86) cpm86header(); + else +#endif + writeheader(); for (modptr = modfirst; modptr != NUL_PTR; modptr = modptr->modnext) if (modptr->loadflag) { @@ -348,9 +368,9 @@ sizeof extsym.n_name); else { - memcpy((char *) extsym.n_name, "__", 2); - strncpy((char *) extsym.n_name+2, symptr->name, - sizeof(extsym.n_name)-2); + memcpy((char *) extsym.n_name, "$", 1); + strncpy((char *) extsym.n_name+1, symptr->name, + sizeof(extsym.n_name)-1); } #else strncpy((char *) extsym.n_name, symptr->name, @@ -395,7 +415,8 @@ { int i; extsym.n_sclass = 0; - extsym.n_value = 0; + memset((void*)&extsym.n_value,0, + sizeof(extsym.n_value)); for(i=sizeof extsym.n_name; iname); i+=sizeof extsym.n_name) @@ -593,6 +614,33 @@ writenulls((bin_off_t) readsize(countsize)); } +#ifndef MSDOS +PRIVATE void cpm86header() +{ + struct cpm86_exec header; + memset(&header, 0, sizeof header); + + if (sepid) + { + header.ce_group[0].cg_type = CG_CODE; + u2c2(header.ce_group[0].cg_len, (15 + etextpadoff) / 16); + u2c2(header.ce_group[0].cg_min, (15 + etextpadoff) / 16); + header.ce_group[1].cg_type = CG_DATA; + u2c2(header.ce_group[1].cg_len, (15 + edataoffset) / 16); + u2c2(header.ce_group[1].cg_min, (15 + endoffset ) / 16); + u2c2(header.ce_group[1].cg_max, 0x1000); + } + else + { + header.ce_group[0].cg_type = CG_CODE; + u2c2(header.ce_group[0].cg_len, (15 + edataoffset) / 16); + u2c2(header.ce_group[0].cg_min, (15 + endoffset ) / 16); + } + if( FILEHEADERLENGTH ) + writeout((char *) &header, FILEHEADERLENGTH); +} +#endif + PRIVATE void writeheader() { struct exec header; @@ -614,9 +662,6 @@ if (uzp) offtocn((char *) &header.a_entry, page_size(), sizeof header.a_entry); - if( heap_top_value < 0x100 || endoffset > heap_top_value-0x100) - heap_top_value = endoffset + 0x8000; - if( heap_top_value > 0x10000 && !bits32 ) heap_top_value = 0x10000; offtocn((char *) &header.a_total, (bin_off_t) heap_top_value, sizeof header.a_total); diff -Nurd linux86.vold/ld/x86_aout.h linux86/ld/x86_aout.h --- linux86.vold/ld/x86_aout.h 1997-07-22 21:56:45.000000000 +0100 +++ linux86/ld/x86_aout.h 2003-01-28 22:17:14.000000000 +0000 @@ -101,7 +101,7 @@ struct nlist { /* symbol table entry */ char n_name[8]; /* symbol name */ - long n_value; /* value */ + Long n_value; /* value */ unsigned char n_sclass; /* storage class */ unsigned char n_numaux; /* number of auxiliary entries (not used) */ unsigned short n_type; /* language base and derived type (not used) */ diff -Nurd linux86.vold/ld/x86_cpm86.h linux86/ld/x86_cpm86.h --- linux86.vold/ld/x86_cpm86.h 1970-01-01 01:00:00.000000000 +0100 +++ linux86/ld/x86_cpm86.h 2002-07-23 22:19:39.000000000 +0100 @@ -0,0 +1,44 @@ +/* Copyright (C) 2002 + * This file is part of the ld86 command for Linux-86 + * It is distributed under the GNU Library General Public License. + * + * CP/M-86 CMD file header + */ + +#ifndef __CPM86_H +#define __CPM86_H + +typedef char Short16[2]; + +struct cpm86_group { + unsigned char cg_type; /* 1=Code 2=Data */ + Short16 cg_len; /* Group length, paragraphs */ + Short16 cg_base; /* Group address, normally 0 for relocatable */ + Short16 cg_min; /* Minimum size, normally = group length */ + Short16 cg_max; /* Maximum size, normally 0x1000 (64k) */ +}; + + +struct cpm86_exec { /* CP/M-86 header */ + struct cpm86_group ce_group[8]; + unsigned char ce_spare[51]; + Short16 ce_rsxs; /* Record with RSX list */ + Short16 ce_fixups; /* Record with fixups */ + unsigned char ce_flags; /* Concurrent CP/M flags */ +}; + +/* Group types */ +#define CG_EMPTY 0 +#define CG_CODE 1 +#define CG_DATA 2 +#define CG_EXTRA 3 +#define CG_STACK 4 +#define CG_AUX1 5 +#define CG_AUX2 6 +#define CG_AUX3 7 +#define CG_AUX4 8 +#define CG_PURE 9 /* Code that is known to be pure */ + +#define CPM86_HEADERLEN 0x80 + +#endif /* _CPM86_H */ diff -Nurd linux86.vold/libbsd/Makefile linux86/libbsd/Makefile --- linux86.vold/libbsd/Makefile 1996-12-14 21:17:36.000000000 +0000 +++ linux86/libbsd/Makefile 2002-02-17 21:55:59.000000000 +0000 @@ -32,7 +32,7 @@ make -C tests $(LIBBSD): $(OBJS) - $(AR) rcs $(LIBBSD) $(OBJS) + $(AR) rc $(LIBBSD) $(OBJS) realclean: clean clean: dummy diff -Nurd linux86.vold/libc/bios/ansi.c linux86/libc/bios/ansi.c --- linux86.vold/libc/bios/ansi.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/bios/ansi.c 2002-03-16 16:47:37.000000000 +0000 @@ -0,0 +1,262 @@ +/* Copyright (C) 1996 Robert de Bath + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ + +#if !__FIRST_ARG_IN_AX__ +#ifdef __AS386_16__ +#ifdef __STANDALONE__ + +#include +#include +int errno; + +extern void (*__smart_putch)(); + +#define CTRL(x) ((x)&0x1F) +static int last_attr = 0x07; +static int con_mode; +static unsigned char con_height = 24, con_width = 79; + +static int con_colour = 0; +static unsigned char con_row, con_col; + +#ifdef ANSI_CON +#define MAX_ARGS 8 +static int colconv[] = { 0, 4, 2, 6, 1, 5, 3, 7 }; +static int vidcnt = 0; +static int ansi_2 = 0; +static int ansi_argc = 0; +static int ansi_argv[MAX_ARGS]; +static void do_ansi(); + +ansi_putch(c) +int c; +{ + if( con_mode==0 ) asm_coninit(); + __smart_putch = ansi_putch; + + if( vidcnt == 0 || c < ' ' || c > '~' ) + { + switch(c & 0xFF) + { + default: + asm_colour(last_attr); + asm_putc(c); + break; + case CTRL('I'): + asm_gpos(); + con_col = ((con_col+8)& -8); + asm_cpos(con_row, con_col); + break; + case CTRL('L'): + asm_cpos(0,0); + asm_cls(); + break; + case CTRL('['): + vidcnt=1; + break; + } + return; + } + + /* ... ansi/vt100 interpretation, this collects _all_ ansi control strings */ + switch(vidcnt) + { + case 1: for(ansi_argc=0; ansi_argc= '0' && c <= '9' ) + ansi_argv[ansi_argc] = ansi_argv[ansi_argc] * 10 + c - '0'; + else if( c >= '@' ) + { + do_ansi(c+ansi_2, ++ansi_argc, ansi_argv); + vidcnt = 0; + } + else + ansi_2 = (c<<8); + break; + + default: vidcnt = 0; /* This definitly won't happen ... definitly ... */ + } +} + +void +do_ansi(ctrl, argc, argv) +int ctrl, argc, *argv; +{ + switch(ctrl) + { + case 'A': + case 'B': + case 'C': + case 'D': + asm_gpos(); + if( argv[0] < 1 ) argv[0] = 1; + switch(ctrl) + { + case 'A': if( argv[0]>con_row ) con_row=0; else con_row-=argv[0]; break; + case 'B': if( argv[0]+con_row>con_height ) + con_row = con_height; + else + con_row += argv[0]; + break; + case 'C': if( argv[0]+con_col>con_width ) + con_col = con_width; + else + con_col += argv[0]; + break; + case 'D': if( argv[0]>con_col ) con_col=0; else con_col-=argv[0]; break; + } + asm_cpos(con_row, con_col); + break; + + case 'H': + if( --argv[0] < 0 ) argv[0] = 0; + if( --argv[1] < 0 ) argv[1] = 0; + asm_cpos(argv[0],argv[1]); + break; + case 'J': if( argv[0] == 2 ) asm_cls(); + break; + case 'm': + { + int ar; + for(ar=0; ar 39 ) con_width = (con_mode>>8); + if( (con_mode&0xFF) != 0x7) + con_colour = 1; +} + +static asm_putc(c) +{ +#asm +#if !__FIRST_ARG_IN_AX__ + mov bx,sp + mov ax,[bx+2] +#endif + cmp al,#$0A + jne not_nl + mov ax,#$0E0D + mov bx,#7 + int $10 + mov al,#$0A +not_nl: + mov ah,#$0E + mov bx,#7 + int $10 +#endasm +} + +static asm_cls() +{ +#asm + push bp ! Bug in some old BIOS`s + !mov ax,#$0500 + !int $10 + mov ax,#$0600 + mov bh,_last_attr + mov cx,#$0000 + mov dl,_con_width + mov dh,_con_height + int $10 + pop bp +#endasm +} + +static asm_cpos(r,c) +{ +#asm +#if __FIRST_ARG_IN_AX__ + mov bx,sp + mov dh,al + mov ax,[bx+2] + mov dl,al +#else + mov bx,sp + mov ax,[bx+2] + mov dh,al + mov ax,[bx+4] + mov dl,al +#endif + mov ah,#$02 + mov bx,#7 + int $10 +#endasm +} + +static asm_colour(c) +{ +#asm +#if __FIRST_ARG_IN_AX__ + mov bx,ax +#else + mov bx,sp + mov bx,[bx+2] +#endif + mov ah,#$08 + int $10 + mov ah,#$09 + mov cx,#1 + int $10 +#endasm +} + +static asm_gpos() +{ +#asm + mov ah,#$03 + mov bx,#7 + int $10 + mov [_con_row],dh + mov [_con_col],dl + mov ax,cx +#endasm +} + +#endif +#endif +#endif diff -Nurd linux86.vold/libc/bios/bios.c linux86/libc/bios/bios.c --- linux86.vold/libc/bios/bios.c 2001-05-12 10:14:37.000000000 +0100 +++ linux86/libc/bios/bios.c 2003-07-31 19:37:03.000000000 +0100 @@ -3,6 +3,8 @@ * under the GNU Library General Public License. */ +#undef AOUT_STANDALONE + #if !__FIRST_ARG_IN_AX__ #ifdef __AS386_16__ #ifdef __STANDALONE__ @@ -22,7 +24,7 @@ .data export ___argr ___argr: - .word 0,0,0,0,0,0,0 ! A struct REGS + .word 0,0,0,0,0,0,0,0 ! A struct REGS: ax, bx, cx, dx, si, di, cflag, flags defarg: .word boot_str, 0 boot_str: @@ -33,16 +35,55 @@ .text export ___cstartup ! Crt0 startup ___cstartup: - mov ___argr+0,ax - mov ___argr+2,bx - mov ___argr+4,cx - mov ___argr+6,dx - mov ___argr+8,si - mov ___argr+10,di + cli +#ifndef AOUT_STANDALONE + seg cs + cmp word ptr [0],#$20CD ! "int 20h" at psp: CS:0000 + jne not_dos + + ! DOS - only AX has a defined value. + ! All the segment registers are pointing at the PSP + ! SP points to the top of the segment so is probably useable. + + push ax ! Save AX + mov ax,cs + add ax,#$10 ! bump CS by 0x10 + push ax + mov ax,#is_dos ! resume address + push ax + retf ! continue at next instruction +dos_flag: + .word 0 ! Set to 1 if DOS +is_dos: + seg cs + inc dos_flag + pop ax ! restore saved AX + +not_dos: + mov sp,cs + add sp,#__segoff + mov ds,sp + mov ss,sp + mov bp,#__heap_top + mov sp,#___argr+14 + seg cs + push [dos_flag] ! Set the carry flag if we're under DOS. +#else + mov bp,sp + mov sp,#___argr+12 +#endif + push di + push si + push dx + push cx + push bx + push ax + mov sp,bp + sti zap_bss: ! Clear the BSS - mov ax,ds - mov es,ax ! ES now data seg + push ds + pop es ! ES now data seg mov di,#__edata mov cx,#__end sub cx,di @@ -51,6 +92,7 @@ rep stosb + !mov bp,ax ! Top frame pointer, only needed if we get a debugger push [_environ] mov ax,#defarg ! Don`t define __mkargv, standalone programs don`t push ax ! get any arguments. @@ -97,22 +139,27 @@ export __exit __exit: +#ifndef AOUT_STANDALONE + seg cs + cmp [dos_flag],#0 ! Should we do a DOS exit + je do_reboot + mov ax,#$4c00 + int $21 +do_reboot: +#endif xor ax,ax - mov es,ax + mov ds,ax mov ax,cs - seg es mov [$E6*4+2],ax - mov ax,#reti_ins - seg es + mov ax,#iret_ins mov [$E6*4],ax mov ax,#$FFFF int $E6 ! Try to exit DOSEMU ! If we get here we`re not in dosemu. - seg es mov [$472],#$1234 ! Warm reboot. jmpi $0000,$FFFF -reti_ins: - reti +iret_ins: + iret #endasm @@ -131,8 +178,7 @@ for(v=len; v>0; v--) { c= *buf++; - if( c == '\n') bios_putc('\r'); - bios_putc(c); + putch(c); } return len; } @@ -211,6 +257,19 @@ /****************************************************************************/ +#ifdef L_bios_abort +abort() +{ + static const char msg[] = "Program aborted, press return:"; + write(2, msg, sizeof(msg)-1); + getch(); + _exit(255); +} + +#endif + +/****************************************************************************/ + #endif #endif #endif diff -Nurd linux86.vold/libc/bios/bios_disk.c linux86/libc/bios/bios_disk.c --- linux86.vold/libc/bios/bios_disk.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/bios/bios_disk.c 2002-08-03 13:05:04.000000000 +0100 @@ -0,0 +1,158 @@ + +#if !__FIRST_ARG_IN_AX__ +#ifdef __AS386_16__ + +#include +#include + +#ifdef L_bios_disk_rd +_bios_disk_read(drive, cyl, head, sect, length, buffer) +{ +#asm + push bp + mov bp,sp + + push es + push ds + pop es + + mov dl,[bp+2+__bios_disk_read.drive] + mov ch,[bp+2+__bios_disk_read.cyl] + mov dh,[bp+2+__bios_disk_read.head] + mov bx,[bp+2+__bios_disk_read.buffer] + +#if 0 + mov ax,[bp+2+__bios_disk_read.cyl] ! Bits 10-11 of cylinder, AMI BIOS. + mov cl,#4 + sar ax,cl + and al,#$C0 + xor dh,al +#endif + + mov cl,[bp+2+__bios_disk_read.sect] + and cl,#$3F + mov ax,[bp+2+__bios_disk_read.cyl] ! Bits 8-9 of cylinder. + sar ax,#1 + sar ax,#1 + and al,#$C0 + or cl,al + + mov al,[bp+2+__bios_disk_read.length] + mov ah,#$02 + int $13 + jc read_err1 + mov ax,#0 +read_err1: + xchg ah,al + xor ah,ah + + pop es + pop bp +#endasm +} +#endif + +#ifdef L_bios_disk_wr +_bios_disk_write(drive, cyl, head, sect, length, buffer) +{ +#asm + push bp + mov bp,sp + + push es + push ds + pop es + + mov dl,[bp+2+__bios_disk_write.drive] + mov ch,[bp+2+__bios_disk_write.cyl] + mov dh,[bp+2+__bios_disk_write.head] + mov bx,[bp+2+__bios_disk_write.buffer] + +#if 0 + mov ax,[bp+2+__bios_disk_write.cyl] ! Bits 10-11 of cylinder, AMI BIOS. + mov cl,#4 + sar ax,cl + and al,#$C0 + xor dh,al +#endif + + mov cl,[bp+2+__bios_disk_write.sect] + and cl,#$3F + mov ax,[bp+2+__bios_disk_write.cyl] ! Bits 8-9 of cylinder. + sar ax,#1 + sar ax,#1 + and al,#$C0 + or cl,al + + mov al,[bp+2+__bios_disk_write.length] + mov ah,#$03 + int $13 + jc read_err2 + mov ax,#0 +read_err2: + xchg ah,al + xor ah,ah + + pop es + pop bp +#endasm +} +#endif + +#ifdef L_bios_get_dpt +long +_bios_get_dpt(drive) +{ +#asm + push bp + mov bp,sp + + push di + push es + + mov dl,[bp+2+__bios_get_dpt.drive] + + mov ah,#$08 + int $13 + jnc func_ok + mov cx,ax + mov dx,#-1 +func_ok: + mov ax,cx + + pop es + pop di + pop bp +#endasm +} +#endif + +#ifdef L_bios_disk_rs +_bios_disk_reset(drive) +{ +#asm + push bp + mov bp,sp + + push di + push es + + mov dl,[bp+2+__bios_disk_reset.drive] + + mov ah,#$08 + int $13 + jnc reset_ok + mov cx,ax + mov dx,#-1 +reset_ok: + mov ax,cx + + pop es + pop di + pop bp +#endasm +} +#endif + +#endif +#endif diff -Nurd linux86.vold/libc/bios/bios_min.c linux86/libc/bios/bios_min.c --- linux86.vold/libc/bios/bios_min.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/bios/bios_min.c 2002-03-16 19:20:23.000000000 +0000 @@ -0,0 +1,61 @@ +/* Copyright (C) 1996 Robert de Bath + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ + +#ifdef __AS386_16__ +#ifdef __STANDALONE__ + +#include + +#ifdef L_bios_putc +bios_putc(c) +{ +#asm +#if !__FIRST_ARG_IN_AX__ + mov bx,sp + mov ax,[bx+2] +#endif + mov ah,#$0E + mov bx,#7 + int $10 +#endasm +} +#endif + +/****************************************************************************/ + +#ifdef L_bios_getc +bios_getc() +{ +#asm + xor ax,ax + int $16 +#endasm +} +#endif + +/****************************************************************************/ + +#ifdef L_bios_khit +bios_khit() +{ +#asm + mov ah,#1 + int $16 + jz nokey + cmp ax,#0 + jnz dort + mov ax,#3 +dort: + ret +nokey: + xor ax,ax +#endasm +} +#endif + +/****************************************************************************/ + +#endif +#endif diff -Nurd linux86.vold/libc/bios/bios_vid.c linux86/libc/bios/bios_vid.c --- linux86.vold/libc/bios/bios_vid.c 1998-11-23 09:10:20.000000000 +0000 +++ linux86/libc/bios/bios_vid.c 2002-03-16 18:20:52.000000000 +0000 @@ -3,12 +3,6 @@ * under the GNU Library General Public License. */ -/* Various possible console types */ -#define VT52_CON /* IMO the best, no clear to EOS/EOL tho */ -#define XANSI_CON /* Largest but still not complete */ -#define XDUMB_CON /* Can't do much */ -#define XSPEC_CON /* Incomplete, best for slow links */ - #if !__FIRST_ARG_IN_AX__ #ifdef __AS386_16__ #ifdef __STANDALONE__ @@ -17,351 +11,136 @@ #include int errno; -#ifdef L_bios_putc -#define CTRL(x) ((x)&0x1F) -static int last_attr = 0x07; -static int con_mode; -static unsigned char con_height = 24, con_width = 79; - -static int con_colour = 0; -static unsigned char con_row, con_col; +#ifdef L_bios_putch +void (*__smart_putch)() = 0; -#ifdef VT52_CON -bios_putc(c) +putch(c) int c; { -static int ctrl = 0; - int new_attr; - if( con_mode==0 ) asm_coninit(); - - switch( ctrl ) +static int col = 0; + if (__smart_putch) + (*__smart_putch)(c); + else if (c&0xE0) { + col++; + asm_putc(c); + } + else switch(c) { - case 1: - ctrl=0; - switch(c) - { - case 'A': if( con_row ) con_row--; asm_cpos(con_row, con_col); break; - case 'B': if( con_row != con_height ) con_row++; - asm_cpos(con_row, con_col); break; - case 'C': if( con_col != con_height ) con_col++; - asm_cpos(con_row, con_col); break; - case 'D': if( con_col ) con_col--; asm_cpos(con_row, con_col); break; - case 'E': last_attr = 0x07; asm_cls(); - case 'H': asm_cpos(0,0); break; - case 'J': asm_cls(); break; - case 'K': break; - case 'R': ctrl = 2; break; /* Foreground */ - case 'S': ctrl = 3; break; /* Background */ - case 'Y': ctrl = 4; break; /* ttypos */ - } + case '\t': + do putch(' '); while(col&7); break; - case 2: ctrl=0; new_attr = (last_attr & 0xF0) + (c&0xF); - if(0) { - case 3: ctrl=0; new_attr = (last_attr & 0x0F) + (c<<4); - } - switch(c) - { - case '_': if( !con_colour ) last_attr = (last_attr&0x88) + 1; - break; - case '!': last_attr = (last_attr&0x88) + 0x70; break; - case ' ': last_attr = 0x07; break; - case '+': last_attr |= 0x08; break; - case '*': last_attr |= 0x80; break; - - default: if( con_colour ) - last_attr = new_attr; - } - break; - case 4: ctrl=5; con_col = c-' '; break; - case 5: ctrl=0; con_row = c-' '; asm_cpos(con_row, con_col); break; + case '\n': + asm_putc('\r'); + case '\r': + col = 0; + asm_putc(c); break; - - default: - if( c & 0xE0 ) - { asm_colour(last_attr) ; asm_putc(c); } - else switch(c) - { - default: - asm_putc(c); - break; - case CTRL('I'): - asm_putc(' '); /* Only some BIOS's have this, so play safe */ - break; - case CTRL('L'): - asm_cpos(0,0); - asm_cls(); - break; - case CTRL('['): - ctrl = 1; - asm_gpos(); - break; - } + case '\f': + col = 0; +#asm + mov ah,#$0F + int $10 + mov ah,#$00 + int $10 +#endasm break; } } -#endif -#ifdef ANSI_CON -#define MAX_ARGS 8 -static int colconv[] = { 0, 4, 2, 6, 1, 5, 3, 7 }; -static int vidcnt = 0; -static int ansi_2 = 0; -static int ansi_argc = 0; -static int ansi_argv[MAX_ARGS]; -static void do_ansi(); - -bios_putc(c) -int c; +static asm_putc(c) { - if( con_mode==0 ) asm_coninit(); - - if( vidcnt == 0 || c < ' ' || c > '~' ) - { - switch(c & 0xFF) - { - default: - asm_colour(last_attr); - asm_putc(c); - break; - case CTRL('L'): - asm_cpos(0,0); - asm_cls(); - break; - case CTRL('['): - vidcnt=1; - break; - } - return; - } - - /* ... ansi/vt100 interpretation, this collects _all_ ansi control strings */ - switch(vidcnt) - { - case 1: for(ansi_argc=0; ansi_argc= '0' && c <= '9' ) - ansi_argv[ansi_argc] = ansi_argv[ansi_argc] * 10 + c - '0'; - else if( c >= '@' ) - { - do_ansi(c+ansi_2, ++ansi_argc, ansi_argv); - vidcnt = 0; - } - else - ansi_2 = (c<<8); - break; - - default: vidcnt = 0; /* This definitly won't happen ... definitly ... */ - } +#asm +#if !__FIRST_ARG_IN_AX__ + mov bx,sp + mov ax,[bx+2] +#endif + mov ah,#$0E + mov bx,#7 + int $10 +#endasm } -void -do_ansi(ctrl, argc, argv) -int ctrl, argc, *argv; -{ - switch(ctrl) - { - case 'A': - case 'B': - case 'C': - case 'D': - asm_gpos(); - if( argv[0] < 1 ) argv[0] = 1; - switch(ctrl) - { - case 'A': if( argv[0]>con_row ) con_row=0; else con_row-=argv[0]; break; - case 'B': if( argv[0]+con_row>con_height ) - con_row = con_height; - else - con_row += argv[0]; - break; - case 'C': if( argv[0]+con_col>con_width ) - con_col = con_width; - else - con_col += argv[0]; - break; - case 'D': if( argv[0]>con_col ) con_col=0; else con_col-=argv[0]; break; - } - asm_cpos(con_row, con_col); - break; - - case 'H': - if( --argv[0] < 0 ) argv[0] = 0; - if( --argv[1] < 0 ) argv[1] = 0; - asm_cpos(argv[0],argv[1]); - break; - case 'J': if( argv[0] == 2 ) asm_cls(); - break; - case 'm': - { - int ar; - for(ar=0; ar 'p')) - return; - - if( vidbuf[0] == CTRL('P') ) - { - if( vidbuf[1] >= 32 && vidbuf[1] <= 56 - && vidbuf[2] >= 32 && vidbuf[2] <= 111 ) - asm_cpos((vidbuf[1]-32), (vidbuf[2]-32)); - } - else - { - if( vidbuf[1] >= '`' ) - last_attr = ( (vidbuf[1]&0xF) | (last_attr&0xF0)); - else - last_attr = ( (vidbuf[2]&0xF) | ((vidbuf[1]&0xF)<<4)); - - if( !con_colour ) - last_attr = (last_attr&0x88) + ((last_attr&7)?0x07:0x70); - } - vidcnt=0; - } +#asm + xor ax,ax + int $16 +#endasm } #endif -#ifdef DUMB_CON -bios_putc(c) -int c; -{ - if( con_mode==0 ) asm_coninit(); - if( c & 0xE0 ) asm_putc(c); - else switch(c) - { - default: - asm_putc(c); - break; - case CTRL('L'): - asm_cls(); - case CTRL('^'): - asm_cpos(0,0); - break; - } -} -#endif +/****************************************************************************/ -static asm_coninit() +#ifdef L_bios_kbhit +kbhit() { #asm - mov ax,#$0F00 - int $10 - mov _con_mode,ax + mov ah,#1 + int $16 + jz nokey + cmp ax,#0 + jnz dort + mov ax,#3 +dort: + ret +nokey: + xor ax,ax #endasm - if( (con_mode &0xFF) > 39 ) con_width = (con_mode>>8); - if( (con_mode&0xFF) != 0x7) - con_colour = 1; } +#endif -static asm_putc(c) +/****************************************************************************/ + +#ifdef L_bios_cputs +cputs(str) + char * str; { -#asm -#if !__FIRST_ARG_IN_AX__ - mov bx,sp - mov ax,[bx+2] -#endif - mov ah,#$0E - mov bx,#7 - int $10 -#endasm + while(*str) putch(*str++); } +#endif -static asm_cls() +/****************************************************************************/ + +#ifdef L_bios_getche +getche() { -#asm - push bp ! Bug in some old BIOS`s - !mov ax,#$0500 - !int $10 - mov ax,#$0600 - mov bh,_last_attr - mov cx,#$0000 - mov dl,_con_width - mov dh,_con_height - int $10 - pop bp -#endasm + static char linebuf[80]; + static int nextc = 0, endc=0; + int rv; + + if (nextc >= endc) + { + endc = bios_readline(linebuf, sizeof(linebuf)); + nextc= 0; + } + if (endc <= nextc) return 3; + rv = linebuf[endc++]; + if (endc == nextc) return '\r'; + return rv; } +#endif -static asm_cpos(r,c) +/****************************************************************************/ + +#ifdef L_bios_gotoxy +static gotoxy(x,y) { #asm #if __FIRST_ARG_IN_AX__ mov bx,sp - mov dh,al - mov ax,[bx+2] mov dl,al -#else - mov bx,sp mov ax,[bx+2] mov dh,al +#else + mov bx,sp mov ax,[bx+4] + mov dh,al + mov ax,[bx+2] mov dl,al #endif mov ah,#$02 @@ -369,37 +148,6 @@ int $10 #endasm } - -#ifndef DUMB_CON -static asm_colour(c) -{ -#asm -#if __FIRST_ARG_IN_AX__ - mov bx,ax -#else - mov bx,sp - mov bx,[bx+2] -#endif - mov ah,#$08 - int $10 - mov ah,#$09 - mov cx,#1 - int $10 -#endasm -} - -static asm_gpos() -{ -#asm - mov ah,#$03 - mov bx,#7 - int $10 - mov [_con_row],dh - mov [_con_col],dl - mov ax,cx -#endasm -} -#endif #endif /****************************************************************************/ @@ -415,13 +163,13 @@ if( len < 0 ) { errno = EINVAL; return -1; } if( len == 0 ) { - if( bios_khit() == 0 ) return 0; + if( kbhit() == 0 ) return 0; errno = EINTR; return -1; } if( len == 1 ) { - buf[0]=((ch=bios_getc())&0xFF?ch&0xFF:((ch>>8)&0xFF|0x80)); + buf[0]=((ch=getch())&0xFF?ch&0xFF:((ch>>8)&0xFF|0x80)); return 1; } @@ -429,70 +177,38 @@ { if(ch != '\003') { - ch = bios_getc(); + ch = getch(); if( pos == 0 && (ch&0xFF) == 0 ) { buf[0] = ((ch>>8)|0x80); return 1; } ch &= 0x7F; - if( ch == '\033' ) ch=3; /* ESC= Interrupt too */ } if( ch == '\r' ) { - bios_putc('\r'); bios_putc('\n'); + putch('\n'); buf[pos++] = '\n'; return pos; } if( ch >= ' ' && ch != 0x7F && pos < len-1) - bios_putc(buf[pos++] = ch); + putch(buf[pos++] = ch); else if( (ch == '\003' || ch == '\b') && pos > 0 ) { - bios_putc('\b'); bios_putc(' '); bios_putc('\b'); + putch('\b'); putch(' '); putch('\b'); pos--; } else if( ch == '\003' ) return 0; else - bios_putc('\007'); + putch('\007'); } } #endif /****************************************************************************/ -#ifdef L_bios_getc -bios_getc() -{ -#asm - xor ax,ax - int $16 -#endasm -} -#endif - -/****************************************************************************/ - -#ifdef L_bios_khit -bios_khit() -{ -#asm - mov ah,#1 - int $16 - jz nokey - cmp ax,#0 - jnz dort - mov ax,#3 -dort: - ret -nokey: - xor ax,ax -#endasm -} -#endif - -/****************************************************************************/ - #endif #endif #endif + diff -Nurd linux86.vold/libc/bios/cprintf.c linux86/libc/bios/cprintf.c --- linux86.vold/libc/bios/cprintf.c 2000-01-29 15:23:20.000000000 +0000 +++ linux86/libc/bios/cprintf.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,132 +0,0 @@ - -#include -#define wchar(ch) putch(ch) - -cprintf(char * fmt, va_list ap) -{ - register int c; - int count = 0; - int type, base; - long val; - char * cp; - char padch=' '; - int minsize = 0; - - while(c=*fmt++) - { - if(c!='%') - { - wchar(c); - count++; - } - else - { - type=1; - do { c=*fmt++; } while( c>='0' && c<='9'); - - padch = *fmt; - minsize=0; - if(padch == '-') fmt++; - - for(;;) - { - c=*fmt++; - if( c<'0' || c>'9' ) break; - minsize*=10; minsize+=c-'0'; - } - - while( c=='.' || (c>='0' && c<='9')) { c=*fmt++; } - - if( padch == '-' ) minsize = -minsize; - else - if( padch == '0' ) padch='0'; else padch=' '; - - if( c == 0 ) break; - if(c=='h') - { - c=*fmt++; - type = 0; - } - else if(c=='l') - { - c=*fmt++; - type = 2; - } - - switch(c) - { - case 'x': base=16; type|=4; if(0) { - case 'o': base= 8; type|=4; } if(0) { - case 'u': base=10; type|=4; } if(0) { - case 'd': base=10; } - val=0; - switch(type) - { - case 0: val=va_arg(ap, short); break; - case 1: val=va_arg(ap, int); break; - case 2: val=va_arg(ap, long); break; - case 4: val=va_arg(ap, unsigned short); break; - case 5: val=va_arg(ap, unsigned int); break; - case 6: val=va_arg(ap, unsigned long); break; - } - cp = __numout(val,base); - if(0) { - case 's': - cp=va_arg(ap, char *); - } - if( minsize > 0 ) - { - minsize -= strlen(cp); - while(minsize>0) { wchar(padch); minsize--; } - minsize=0; - } - if( minsize < 0 ) minsize= -minsize-strlen(cp); - while(*cp) - wchar(*cp++); - while(minsize>0) { wchar(' '); minsize--; } - break; - case 'c': - wchar(va_arg(ap, int)); - break; - default: - wchar(c); - break; - } - } - } - return count; -} - - - -static char nstring[]="0123456789ABCDEF"; - -static unsigned char * -__numout(long i, int base) -{ - static unsigned char out[16]; - int n; - int flg = 0; - unsigned long val; - - if (i<0 && base==10) - { - flg = 1; - i = -i; - } - val = i; - - for (n = 0; n < 15; n++) - out[n] = ' '; - out[15] = '\0'; - n = 14; - do - { - out[n] = nstring[val % base]; - n--; - val /= base; - } - while(val); - if(flg) out[n--] = '-'; - return &out[n+1]; -} diff -Nurd linux86.vold/libc/bios/fs_dos.c linux86/libc/bios/fs_dos.c --- linux86.vold/libc/bios/fs_dos.c 1998-11-21 10:18:18.000000000 +0000 +++ linux86/libc/bios/fs_dos.c 2002-05-26 10:29:45.000000000 +0100 @@ -1,13 +1,14 @@ +#ifdef DEBUG #include +#endif + #include #include #include #include "io.h" #include "rawio.h" -#define DONT_BUFFER_FAT - #define DOS_SECT(P) get_uint(P,0x0B) #define DOS_CLUST(P) get_byte(P,0x0D) #define DOS_RESV(P) get_uint(P,0x0E) @@ -22,6 +23,7 @@ #define DOS4_MAXSECT(P) get_long(P,0x20) #define DOS4_PHY_DRIVE(P) get_byte(P,0x24) #define DOS4_SERIAL(P) get_long(P,0x27) +#define DOS4_FATTYPE(P) get_uint(P,0x39) /* These assume alignment is not a problem */ #define get_byte(P,Off) *((unsigned char*)((char*)(P)+(Off))) @@ -33,15 +35,11 @@ static int dos_clust0, dos_spc, dos_fatpos; static int last_serial = 0; -#ifdef BUFFER_FAT -static char * fat_buf = 0; -#endif - struct filestatus { char fname[12]; unsigned short first_cluster; unsigned short cur_cluster; - unsigned short sector_no; + unsigned short sector_no; /* Max filesize = 32M */ long file_length; }; @@ -61,11 +59,10 @@ char conv_name[12]; char *d, *s; int i; - int dodir = 0; struct filestatus* cur_file; #ifdef DEBUG - printf("fsdos_open_file(%x, %s, %d, %d, %d)\n", + fprintf(stderr, "fsdos_open_file(%x, %s, %d, %d, %d)\n", iob, fname, flags, mode, sizeof(iob)); #endif iob->block_read = fsdos_read_block; @@ -74,9 +71,6 @@ /* Get the superblock */ if( read_bootblock() < 0 ) return -1; - if(strcmp(fname, ".") == 0) - dodir = 1; - else { /* Convert the name to MSDOS directory format */ strcpy(conv_name, " "); @@ -97,38 +91,7 @@ } } #ifdef DEBUG - printf("fsdos_open_file: converted filename=<%s>\n", conv_name); -#endif - -#ifdef BUFFER_FAT - rawio_read_sector(0, sect); - - if( !dodir ) - { - /* Read in and buffer the FAT */ - if( fat_buf ) free(fat_buf); - fat_buf = malloc(DOS_FATLEN(sect) * 512); - if( fat_buf == 0 ) - { - errno = ENOMEM; - return -1; - } - else - { - int fatsec = DOS_RESV(sect); - int nsec = DOS_FATLEN(sect); - - for(i=0; i\n", conv_name); #endif /* Scan the root directory for the file */ @@ -141,37 +104,7 @@ return -1; } d = s + (i%16)*32; - if( dodir ) - { - char dtime[20]; - char lbuf[90]; - *lbuf = 0; - - sprintf(dtime, " %02d/%02d/%04d %02d:%02d", - (get_uint(d,24)&0x1F), - ((get_uint(d,24)>>5)&0xF), - ((get_uint(d,24)>>9)&0x7F)+1980, - ((get_uint(d,22)>>11)&0x1F), - ((get_uint(d,22)>>5)&0x3F) - ); - if( *d > ' ' && *d <= '~' ) switch(d[11]&0x18) - { - case 0: - printf("%-8.8s %-3.3s %10ld%s\n", d, d+8, get_long(d,28), dtime); - break; - case 0x10: - printf("%-8.8s %-3.3s %s\n", d, d+8, dtime); - break; - case 8: - if( (d[11] & 7) == 0 ) - printf("%-11.11s %s\n", d, dtime); - break; - } -#if 0 - if( more_strn(lbuf, sizeof(lbuf)) < 0 ) break; -#endif - } - else if( memcmp(d, conv_name, 11) == 0 && (d[11]&0x18) == 0 ) + if( memcmp(d, conv_name, 11) == 0 && (d[11]&0x18) == 0 ) { /* Name matches and is normal file */ #ifdef DEBUG @@ -233,11 +166,6 @@ free(cur_file); iob->context = NULL; -#ifdef BUFFER_FAT - if( fat_buf ) free(fat_buf); - fat_buf = 0; -#endif - rawio_reset_disk(); return 0; } @@ -278,7 +206,9 @@ #endif if (iob == NULL || iob->context == NULL) { +#ifdef DEBUG fprintf(stderr, "rb: no context\n"); +#endif errno = EBADF; return -1; } @@ -345,9 +275,6 @@ unsigned int val, val2; val = cur_file->cur_cluster + (cur_file->cur_cluster>>1); -#ifdef BUFFER_FAT - val2 = get_uint(fat_buf, val); -#else if (rawio_read_sector(dos_fatpos+(val/512), sect) <= 0) return -1; if( val%512 == 511 ) { @@ -357,7 +284,6 @@ } else val2 = get_uint(sect, (val%512)); -#endif if( odd ) val2>>=4; @@ -380,7 +306,7 @@ int rv, media_byte = 0; #ifdef DEBUG - printf("fs_dos:read_bootblock:\n"); + fprintf(stderr, "fs_dos:read_bootblock:\n"); #endif if (rawio_read_sector(1, sect) <= 0) return -1; media_byte = *(unsigned char*)sect; @@ -412,7 +338,7 @@ } #ifdef DEBUG - printf("read_bootblock: heads(%d), spt(%d), dir_sect(%d)\n", + fprintf(stderr, "read_bootblock: heads(%d), spt(%d), dir_sect(%d)\n", rawio_disk_heads, rawio_disk_spt, dir_sect); diff -Nurd linux86.vold/libc/bios/Makefile linux86/libc/bios/Makefile --- linux86.vold/libc/bios/Makefile 2001-05-12 10:11:00.000000000 +0100 +++ linux86/libc/bios/Makefile 2003-07-31 19:33:02.000000000 +0100 @@ -4,13 +4,21 @@ ifeq ($(LIB_OS),BIOS) ASRC=bios.c -AOBJ=bios_start.o bios_isatty.o bios_nofiles.o \ +AOBJ=bios_start.o bios_isatty.o bios_abort.o bios_nofiles.o \ bios_read.o bios_write.o bios_lseek.o bios_close.o BSRC=bios_vid.c -BOBJ=bios_putc.o bios_getc.o bios_khit.o bios_rdline.o +BOBJ=bios_putch.o bios_getch.o bios_getche.o bios_cputs.o bios_kbhit.o \ + bios_rdline.o -OBJ=$(AOBJ) $(BOBJ) time.o fileops.o fs_dos.o rawio.o +CSRC=bios_min.c +COBJ=bios_putc.o bios_getc.o bios_khit.o + +DSRC=bios_disk.c +DOBJ=bios_disk_rd.o bios_disk_wr.o bios_disk_rs.o bios_get_dpt.o + +OBJ=$(AOBJ) $(BOBJ) $(COBJ) $(DOBJ) \ + time.o fileops.o fs_dos.o rawio.o vt52.o ansi.o CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) @@ -24,6 +32,14 @@ $(LIBC)($(BOBJ)): $(BSRC) $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o $(AR) $(ARFLAGS) $@ $*.o + +$(LIBC)($(COBJ)): $(CSRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(AR) $(ARFLAGS) $@ $*.o + +$(LIBC)($(DOBJ)): $(DSRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(AR) $(ARFLAGS) $@ $*.o else all: @: diff -Nurd linux86.vold/libc/bios/rawio.c linux86/libc/bios/rawio.c --- linux86.vold/libc/bios/rawio.c 1998-11-23 08:24:12.000000000 +0000 +++ linux86/libc/bios/rawio.c 2002-05-26 10:32:20.000000000 +0100 @@ -2,7 +2,10 @@ * rawio.c - plagiarised from ../../bootblocks/trk_buf.c */ +#ifdef DEBUG #include +#endif + #include #include #include @@ -124,18 +127,24 @@ data_buf1 = malloc(512); if( data_buf1 == 0 ) { +#ifdef DEBUG fprintf(stderr, "Cannot allocate memory for disk read!!!\n"); +#endif return 0; } +#ifdef DEBUG fprintf(stderr, "WARNING: Single sector read\n"); +#endif do { rv = rawio_phy_read(rawio_disk_drive, phy_c, phy_h, phy_s+1, 1, data_buf1); tries--; +#ifdef DEBUG if( rv ) fprintf(stderr, "Error in phy_read(%d,%d,%d,%d,%d,%d);\n", rawio_disk_drive, phy_c, phy_h, phy_s+1, 1, data_buf1); +#endif } while(rv && tries > 0); @@ -239,8 +248,10 @@ rv = rawio_phy_read(rawio_disk_drive, phy_c, phy_h, phy_s/data_len+1, data_len, data_buf1); tries--; +#ifdef DEBUG if( rv ) fprintf(stderr, "Error in phy_read(%d,%d,%d,%d,%d,%d);\n", rawio_disk_drive, phy_c, phy_h, phy_s/data_len+1, data_len, data_buf1); +#endif } while(rv && tries > 0); diff -Nurd linux86.vold/libc/bios/README linux86/libc/bios/README --- linux86.vold/libc/bios/README 1996-10-19 12:43:24.000000000 +0100 +++ linux86/libc/bios/README 2002-04-17 21:02:35.000000000 +0100 @@ -5,6 +5,7 @@ This is a very simple set of functions for standalone executables. There is a choice as to which console type you want to use, I think -the VT52 clone is best. +the VT52 clone is best. To activate it you have to call 'vt52_putc' +at least once. -Robert diff -Nurd linux86.vold/libc/bios/vt52.c linux86/libc/bios/vt52.c --- linux86.vold/libc/bios/vt52.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/bios/vt52.c 2002-03-16 16:47:45.000000000 +0000 @@ -0,0 +1,202 @@ +/* Copyright (C) 1996 Robert de Bath + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ + +#if !__FIRST_ARG_IN_AX__ +#ifdef __AS386_16__ +#ifdef __STANDALONE__ + +#include +#include +int errno; + +extern void (*__smart_putch)(); + +#define CTRL(x) ((x)&0x1F) +static int last_attr = 0x07; +static int con_mode; +static unsigned char con_height = 24, con_width = 79; + +static int con_colour = 0; +static unsigned char con_row, con_col; + +vt52_putch(c) +int c; +{ +static int ctrl = 0; + int new_attr; + __smart_putch = vt52_putch(); + + if( con_mode==0 ) asm_coninit(); + + switch( ctrl ) + { + case 1: + ctrl=0; + switch(c) + { + case 'A': if( con_row ) con_row--; asm_cpos(con_row, con_col); break; + case 'B': if( con_row != con_height ) con_row++; + asm_cpos(con_row, con_col); break; + case 'C': if( con_col != con_height ) con_col++; + asm_cpos(con_row, con_col); break; + case 'D': if( con_col ) con_col--; asm_cpos(con_row, con_col); break; + case 'E': last_attr = 0x07; asm_cls(); + case 'H': asm_cpos(0,0); break; + case 'J': asm_cls(); break; + case 'K': break; + case 'R': ctrl = 2; break; /* Foreground */ + case 'S': ctrl = 3; break; /* Background */ + case 'Y': ctrl = 4; break; /* ttypos */ + } + break; + case 2: ctrl=0; new_attr = (last_attr & 0xF0) + (c&0xF); + if(0) { + case 3: ctrl=0; new_attr = (last_attr & 0x0F) + (c<<4); + } + switch(c) + { + case '_': if( !con_colour ) last_attr = (last_attr&0x88) + 1; + break; + case '!': last_attr = (last_attr&0x88) + 0x70; break; + case ' ': last_attr = 0x07; break; + case '+': last_attr |= 0x08; break; + case '*': last_attr |= 0x80; break; + + default: if( con_colour ) + last_attr = new_attr; + } + break; + case 4: ctrl=5; con_col = c-' '; break; + case 5: ctrl=0; con_row = c-' '; asm_cpos(con_row, con_col); break; + break; + + default: + if( c & 0xE0 ) + { asm_colour(last_attr) ; asm_putc(c); } + else switch(c) + { + default: + asm_putc(c); + break; + case CTRL('I'): + asm_gpos(); + con_col = ((con_col+8)& -8); + asm_cpos(con_row, con_col); + break; + case CTRL('L'): + asm_cpos(0,0); + asm_cls(); + break; + case CTRL('['): + ctrl = 1; + asm_gpos(); + break; + } + break; + } +} + +static asm_coninit() +{ +#asm + mov ax,#$0F00 + int $10 + mov _con_mode,ax +#endasm + if( (con_mode &0xFF) > 39 ) con_width = (con_mode>>8); + if( (con_mode&0xFF) != 0x7) + con_colour = 1; +} + +static asm_putc(c) +{ +#asm +#if !__FIRST_ARG_IN_AX__ + mov bx,sp + mov ax,[bx+2] +#endif + cmp al,#$0A + jne not_nl + mov ax,#$0E0D + mov bx,#7 + int $10 + mov al,#$0A +not_nl: + mov ah,#$0E + mov bx,#7 + int $10 +#endasm +} + +static asm_cls() +{ +#asm + push bp ! Bug in some old BIOS`s + !mov ax,#$0500 + !int $10 + mov ax,#$0600 + mov bh,_last_attr + mov cx,#$0000 + mov dl,_con_width + mov dh,_con_height + int $10 + pop bp +#endasm +} + +static asm_cpos(r,c) +{ +#asm +#if __FIRST_ARG_IN_AX__ + mov bx,sp + mov dh,al + mov ax,[bx+2] + mov dl,al +#else + mov bx,sp + mov ax,[bx+2] + mov dh,al + mov ax,[bx+4] + mov dl,al +#endif + mov ah,#$02 + mov bx,#7 + int $10 +#endasm +} + +static asm_colour(c) +{ +#asm +#if __FIRST_ARG_IN_AX__ + mov bx,ax +#else + mov bx,sp + mov bx,[bx+2] +#endif + mov ah,#$08 + int $10 + mov ah,#$09 + mov cx,#1 + int $10 +#endasm +} + +static asm_gpos() +{ +#asm + mov ah,#$03 + mov bx,#7 + int $10 + mov [_con_row],dh + mov [_con_col],dl + mov ax,cx +#endasm +} + +#endif +#endif +#endif + diff -Nurd linux86.vold/libc/Config.dflt linux86/libc/Config.dflt --- linux86.vold/libc/Config.dflt 2000-12-03 09:29:07.000000000 +0000 +++ linux86/libc/Config.dflt 2001-12-03 21:16:05.000000000 +0000 @@ -1,5 +1,6 @@ bcc:+: bios:+: +conio:+: error:+: getent:+: gtermcap:+: diff -Nurd linux86.vold/libc/conio/Config linux86/libc/conio/Config --- linux86.vold/libc/conio/Config 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/conio/Config 2001-12-03 21:05:14.000000000 +0000 @@ -0,0 +1 @@ +conio: Console io functions for BIOS and DOS. diff -Nurd linux86.vold/libc/conio/conio.c linux86/libc/conio/conio.c --- linux86.vold/libc/conio/conio.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/conio/conio.c 2002-03-16 14:45:37.000000000 +0000 @@ -0,0 +1,97 @@ +/* Copyright (C) 1999 Robert de Bath + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ + +#include + +/* + * I'm not sure if these should be BIOS or dos calls, so I'll assume they're + * BIOS calls but I may have to do something about Ctrl-C. + * + * Not implemented: cgets() cscanf() getpass() ungetch() + */ + +#ifdef L_getch +getch() +{ +#asm + xor ax,ax + int $16 +#endasm +} +#endif + +#ifdef L_getche +getche() +{ + int i = getch(); + if( i & 0xFF ) putch(i); + return i; +} +#endif + +#ifdef L_kbhit +kbhit() +{ +#asm + mov ah,#1 + int $16 + jz nokey + cmp ax,#0 + jnz dort + mov ax,#3 +dort: + ret +nokey: + xor ax,ax +#endasm +} +#endif + +#ifdef L_putch +putch() +{ +#asm +#if !__FIRST_ARG_IN_AX__ + mov bx,sp + mov ax,[bx+2] +#endif + mov ah,#$0E + mov bx,#7 + int $10 +#endasm +} +#endif + +#ifdef L_cputs +cputs(str) +char * str; +{ + while(*str) putch(*str++); +} +#endif + +#ifdef L_gotoxy +static gotoxy(x,y) +{ +#asm +#if __FIRST_ARG_IN_AX__ + mov bx,sp + mov dl,al + mov ax,[bx+2] + mov dh,al +#else + mov bx,sp + mov ax,[bx+4] + mov dh,al + mov ax,[bx+2] + mov dl,al +#endif + mov ah,#$02 + mov bx,#7 + int $10 +#endasm +} +#endif + diff -Nurd linux86.vold/libc/conio/cprintf.c linux86/libc/conio/cprintf.c --- linux86.vold/libc/conio/cprintf.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/conio/cprintf.c 2002-03-16 18:35:14.000000000 +0000 @@ -0,0 +1,226 @@ +/* Copyright (C) 1999-2002 Robert de Bath + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ + +#include +#include + +static unsigned char * __numout(long i, int base); + +int cprintf(char * fmt, ...) +{ + register int c; + register int count = 0; + int type, base; + long val; + char * cp; + char padch=' '; + int minsize, maxsize; + va_list ap; + + va_start(ap, fmt); + + while(c=*fmt++) + { + count++; + if(c!='%') + putch(c); + else + { + type=1; + padch = *fmt; + maxsize=minsize=0; + if(padch == '-') fmt++; + + for(;;) + { + c=*fmt++; + if( c<'0' || c>'9' ) break; + minsize*=10; minsize+=c-'0'; + } + + if( c == '.' ) + for(;;) + { + c=*fmt++; + if( c<'0' || c>'9' ) break; + maxsize*=10; maxsize+=c-'0'; + } + + if( padch == '-' ) minsize = -minsize; + else + if( padch != '0' ) padch=' '; + + if( c == 0 ) break; + if(c=='h') + { + c=*fmt++; + type = 0; + } + else if(c=='l') + { + c=*fmt++; + type = 2; + } + + switch(c) + { + case 'x': base=16; type |= 4; if(0) { + case 'o': base= 8; type |= 4; } if(0) { + case 'u': base=10; type |= 4; } if(0) { + case 'd': base=-10; } + switch(type) + { + case 0: val=va_arg(ap, short); break; + case 1: val=va_arg(ap, int); break; + case 2: val=va_arg(ap, long); break; + case 4: val=va_arg(ap, unsigned short); break; + case 5: val=va_arg(ap, unsigned int); break; + case 6: val=va_arg(ap, unsigned long); break; + default:val=0; break; + } + cp = __numout(val,base); + if(0) { + case 's': + cp=va_arg(ap, char *); + } + count--; + c = strlen(cp); + if( !maxsize ) maxsize = c; + if( minsize > 0 ) + { + minsize -= c; + while(minsize>0) { putch(padch); count++; minsize--; } + minsize=0; + } + if( minsize < 0 ) minsize= -minsize-c; + while(*cp && maxsize-->0 ) + { + putch(*cp++); + count++; + } + while(minsize>0) { putch(' '); count++; minsize--; } + break; + case 'c': + putch(va_arg(ap, int)); + break; + default: + putch(c); + break; + } + } + } + va_end(ap); + return count; +} + +static char nstring[]="0123456789ABCDEF"; + +#ifndef __AS386_16__ +#define NUMLTH 11 + +static unsigned char * +__numout(long i, int base) +{ + static unsigned char out[NUMLTH+1]; + int n; + int flg = 0; + unsigned long val; + + if (base<0) + { + base = -base; + if (i<0) + { + flg = 1; + i = -i; + } + } + val = i; + + out[NUMLTH] = '\0'; + n = NUMLTH-1; + do + { + out[n--] = nstring[val % base]; + val /= base; + } + while(val); + if(flg) out[n--] = '-'; + return &out[n+1]; +} + +#else + +#asm +! numout.s +! +.bss +___out lcomm $C + +.text +___numout: +push bp +mov bp,sp +push di +push si +add sp,*-4 +mov byte ptr -8[bp],*$0 ! flg = 0 +mov si,4[bp] ; i or val.lo +mov di,6[bp] ; i or val.hi +mov cx,8[bp] ; base +test cx,cx ! base < 0 ? +jge .3num +neg cx ! base = -base +or di,di ! i < 0 ? +jns .5num +mov byte ptr -8[bp],*1 ! flg = 1 +neg di ! i = -i +neg si +sbb di,0 +.5num: +.3num: +mov byte ptr [___out+$B],*$0 ! out[11] = nul +mov -6[bp],*$A ! n = 10 + +.9num: +!!! out[n--] = nstring[val % base]; +xor dx,dx +xchg ax,di +div cx +xchg ax,di +xchg ax,si +div cx +xchg ax,si ! val(new) = val / base + +mov bx,dx ! dx = val % base + +mov al,_nstring[bx] +mov bx,-6[bp] +dec word ptr -6[bp] +mov ___out[bx],al + +mov ax,si +or ax,di ! while (val) +jne .9num + +cmp byte ptr -8[bp],*$0 ! flg == 0 ? +je .Dnum + +mov bx,-6[bp] +dec word ptr -6[bp] +mov byte ptr ___out[bx],*$2D ! out[n--] = minus + +.Dnum: +mov ax,-6[bp] +add ax,#___out+1 + +add sp,*4 +pop si +pop di +pop bp +ret +#endasm + +#endif diff -Nurd linux86.vold/libc/conio/Makefile linux86/libc/conio/Makefile --- linux86.vold/libc/conio/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/conio/Makefile 2002-03-16 14:43:36.000000000 +0000 @@ -0,0 +1,39 @@ +# Copyright (C) 1996 Robert de Bath +# This file is part of the Linux-8086 C library and is distributed +# under the GNU Library General Public License. + +ASRC=conio.c +AOBJ=getch.o getche.o kbhit.o putch.o cputs.o gotoxy.o + +BIOSOBJ=cprintf.o +DOSOBJ=$(AOBJ) cprintf.o + +CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) + +ifeq ($(LIB_CPU)-$(LIB_OS),i86-BIOS) +all: $(LIBC)($(BIOSOBJ)) + @$(RM) $(BIOSOBJ) +else +ifeq ($(LIB_CPU)-$(LIB_OS),i86-DOS) +all: $(LIBC)($(DOSOBJ)) + @$(RM) $(DOSOBJ) +else +all: + @: +endif +endif + +$(LIBC)($(AOBJ)): $(ASRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(AR) $(ARFLAGS) $@ $*.o + +$(LIBC)($(BOBJ)): $(BSRC) + $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o + $(AR) $(ARFLAGS) $@ $*.o + +$(LIBC)(cprintf.o): cprintf.c + $(CC) -c -ansi $(ARCH) $(CCFLAGS) $(DEFS) $*.c + $(AR) $(ARFLAGS) $@ $*.o + +clean: + rm -f *.o libc.a diff -Nurd linux86.vold/libc/error/error2.c linux86/libc/error/error2.c --- linux86.vold/libc/error/error2.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/error/error2.c 2004-01-19 21:30:58.000000000 +0000 @@ -0,0 +1,21 @@ +/* Copyright (C) 1996,2004 Robert de Bath + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ +#include + +#include "error_list.h" + +char * +strerror(err) +int err; +{ + static char retbuf[20]; + + if( err > 0 && err <= sys_nerr ) + return sys_errlist[err]; + + strcpy(retbuf, "Error "); + strcpy(retbuf+6, itoa(err)); + return retbuf; +} diff -Nurd linux86.vold/libc/error/error.c linux86/libc/error/error.c --- linux86.vold/libc/error/error.c 1996-02-15 20:16:24.000000000 +0000 +++ linux86/libc/error/error.c 2004-01-19 21:10:31.000000000 +0000 @@ -24,7 +24,7 @@ } if( err <= 0 ) goto unknown; /* NB the <= allows comments in the file */ - fd = open("/usr/lib/liberror.txt", 0); + fd = open("/lib/liberror.txt", 0); if( fd < 0 ) goto unknown; while( (cc=read(fd, inbuf, sizeof(inbuf))) > 0 ) diff -Nurd linux86.vold/libc/error/Makefile linux86/libc/error/Makefile --- linux86.vold/libc/error/Makefile 1997-03-08 20:11:22.000000000 +0000 +++ linux86/libc/error/Makefile 2004-06-21 08:12:31.000000000 +0100 @@ -5,14 +5,24 @@ CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) ifeq ($(LIB_OS),ELKS) + +ifneq ($(LIB_CPU),i86) +OBJ=error2.o perror.o sys_siglist.o __assert.o +else OBJ=error.o sys_errlist.o perror.o sys_siglist.o __assert.o +endif -all: $(LIBC)($(OBJ)) - @$(RM) $(OBJ) else -all: - @: +OBJ=__assert.o endif +all: $(LIBC)($(OBJ)) + @$(RM) $(OBJ) + clean: - rm -f *.o libc.a + rm -f *.o libc.a error_list.h + +$(LIBC)(error2.o): error_list.h + +error_list.h: liberror.txt + sh mktab.sh diff -Nurd linux86.vold/libc/error/mktab.sh linux86/libc/error/mktab.sh --- linux86.vold/libc/error/mktab.sh 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/error/mktab.sh 2004-01-19 20:57:55.000000000 +0000 @@ -0,0 +1,25 @@ +#!/bin/sh - + +awk '{ + e=$0; + sub("^[^ ]* ", "", e); + sub(" [^ ]*$", "", e); + n=0+$1; + if (!(n in errlist)) + errlist[n] = e; + if(n > maxerr) maxerr=n; +} +END{ + printf ("#define NR_ERRORS\t%d\n", maxerr+1); + printf ("int sys_nerr = NR_ERRORS;\n"); + printf ("char *sys_errlist[NR_ERRORS] = {\n"); + + for(i=0; i<=maxerr; i++) { + if (errlist[i] == "") + printf(" \"Error %d\"", i); + else + printf(" \"%s\"", errlist[i]); + if (i != maxerr) printf(",\n"); else printf("\n"); + } + printf ("};\n"); +}' < liberror.txt > error_list.h diff -Nurd linux86.vold/libc/error/README linux86/libc/error/README --- linux86.vold/libc/error/README 1996-01-20 21:02:57.000000000 +0000 +++ linux86/libc/error/README 2004-01-20 08:39:50.000000000 +0000 @@ -1,10 +1,11 @@ -Copyright (C) 1996 Robert de Bath +Copyright (C) 1996,2004 Robert de Bath This file is part of the Linux-8086 C library and is distributed under the GNU Library General Public License. -These routines assume the existance of a file /usr/lib/liberror.txt, -this file contains the actual error messages. One useful feature, -the language of the error messages can be easily changed. +The file "liberror.txt" is the master list of errors for ELKS only. +WARNING: + If you use the -Mf compile style this file must be in the filessystem + as "/lib/liberror.txt" unless you're using elksemu. -Robert diff -Nurd linux86.vold/libc/error/sys_errlist.c linux86/libc/error/sys_errlist.c --- linux86.vold/libc/error/sys_errlist.c 1997-10-19 22:55:46.000000000 +0100 +++ linux86/libc/error/sys_errlist.c 2004-01-19 21:10:40.000000000 +0000 @@ -42,7 +42,7 @@ int i, cc, fd, err, len, bufoff=0; char * ptr; - fd = open("/usr/lib/liberror.txt", 0); + fd = open("/lib/liberror.txt", 0); if( fd < 0 ) return; for(i=0; i>= 1; + i++; + } + pow = 256; + i = 0; + while (val >= 10) { + while (val >= postab[i]) { + val /= postab[i]; + decpt += pow; + } + pow >>= 1; + i++; + } + if (cnvflag == FCVT) { + ndig += decpt; + ndig = (ndig < 0) ? 0 : (ndig < DIGMAX) ? ndig : DIGMAX; + } + + /* Pick off digits 1 by 1 and stuff into digstr[] */ + /* Do 1 extra digit for rounding purposes */ + for (p = &digstr[0]; p <= &digstr[ndig]; p++) { + int n; + + /* 'twould be silly to have zillions of digits */ + /* when only DIGPREC are significant */ + if (p >= &digstr[DIGPREC]) + *p = '0'; + + else { + n = val; + *p = n + '0'; + val = (val - n) * 10; /* get next digit */ + } + } + if (*--p >= '5') { /* if we need to round */ + while (1) { + if (p == &digstr[0]) { /* if at start */ + ndig += cnvflag; + decpt++; /* shift dec pnt */ + digstr[0] = '1'; /* "100000..." */ + break; + } + *p = '0'; + --p; + if (*p != '9') { + (*p)++; + break; + } + } /* while */ + } /* if */ + } /* else */ + *pdecpt = decpt; + digstr[ndig] = 0; /* terminate string */ + return &digstr[0]; +} diff -Nurd linux86.vold/libc/i386fp/Makefile linux86/libc/i386fp/Makefile --- linux86.vold/libc/i386fp/Makefile 1997-03-08 20:12:59.000000000 +0000 +++ linux86/libc/i386fp/Makefile 2005-01-23 14:14:20.000000000 +0000 @@ -2,29 +2,26 @@ .SUFFIXES: .x # .x files are .s files that need C-preprocessing .x.o: - cp $< tmp.c - $(CC) $(CFLAGS) -E tmp.c >tmp.s - $(CC) $(CFLAGS) -c tmp.s -A-n -A$* -o $@ + $(CC) $(CFLAGS) -c $< -o $@ FPDIST =Makefile $(FPSRC) test.c bccfp.tex FPSRC =fadd.x fcomp.x fdiv.x fmul.x fbsr.x \ fperr.c fperror.x fptoi.x fpushd.x fpulld.x \ fpushi.x fpushf.x fpullf.x frexp.x ftst.x \ gcclib.x \ - fabs.x ldexp.x modf.c \ + fabs.x ldexp.x ecvt.c \ fperr.h fplib.h FPOBJ =fadd.o fcomp.o fdiv.o fmul.o fpbsr.o \ fperr.o fperror.o fptoi.o fpushd.o fpulld.o \ fpushi.o fpushf.o fpullf.o frexp.o ftst.o \ - fabs.o ldexp.o modf.o -JUNK =tmp tmp.c tmp.s tmp.lst + fabs.o ldexp.o ecvt.o LIB =. CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) ifeq ($(LIB_CPU),i386) all: $(LIBC)($(FPOBJ)) - rm -f $(JUNK) $(FPOBJ) + rm -f $(FPOBJ) else all: @: @@ -34,5 +31,5 @@ $(LIBC)(fperr.o fperror.o): fperr.h clean: - rm -f $(FPOBJ) $(JUNK) test + rm -f $(FPOBJ) test rm -f $(LIB)/libfp.a bccfp.tar.Z bccfp.uue diff -Nurd linux86.vold/libc/i386sys/Makefile linux86/libc/i386sys/Makefile --- linux86.vold/libc/i386sys/Makefile 1997-08-17 15:29:17.000000000 +0100 +++ linux86/libc/i386sys/Makefile 2005-01-03 23:00:39.000000000 +0000 @@ -12,7 +12,7 @@ DOBJ=opendir.o closedir.o readdir.o ifeq ($(LIB_CPU)-$(LIB_OS),i386-ELKS) -OBJ=$(LOBJ3) $(LOBJ) $(EOBJ) $(DOBJ) +OBJ=$(LOBJ3) $(LOBJ) $(EOBJ) $(DOBJ) setjmp3.o SYSCALLS=syscalls CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) diff -Nurd linux86.vold/libc/i386sys/setjmp3.c linux86/libc/i386sys/setjmp3.c --- linux86.vold/libc/i386sys/setjmp3.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/i386sys/setjmp3.c 2005-01-03 23:01:16.000000000 +0000 @@ -0,0 +1,56 @@ + +#include + +#if __AS386_32__ + +int +setjmp(env) +jmp_buf env; +{ +#asm +export __setjmp +__setjmp: + + pop ecx ! PC +#if __FIRST_ARG_IN_AX__ + mov ebx,eax +#else + mov ebx,esp + mov ebx,[ebx] ! TOS is prt -> env +#endif + mov [ebx+0],ecx ! PC + mov [ebx+4],esp ! This registers are all that may be constant. + mov [ebx+8],ebp + mov [ebx+12],esi ! Is saving these the "right thing" ? + mov [ebx+16],edi + xor eax,eax + jmp ecx +#endasm +} + +void +longjmp(env, rv) +jmp_buf env; +int rv; +{ +#asm +export __longjmp +__longjmp: + + pop ecx ! pc +#if __FIRST_ARG_IN_AX__ + mov ebx,eax ! env-> +#else + pop ebx ! env-> +#endif + pop eax ! rv + mov ecx,[ebx+0] ! PC + mov esp,[ebx+4] + mov ebp,[ebx+8] + mov esi,[ebx+12] + mov edi,[ebx+16] + jmp ecx +#endasm +} + +#endif diff -Nurd linux86.vold/libc/i386sys/syscall.dat linux86/libc/i386sys/syscall.dat --- linux86.vold/libc/i386sys/syscall.dat 1997-01-30 19:15:59.000000000 +0000 +++ linux86/libc/i386sys/syscall.dat 2005-01-04 00:03:36.000000000 +0000 @@ -1,4 +1,3 @@ - # # Name No Args Flag, comment # @@ -6,6 +5,8 @@ # * = Needs libc code (Prefix __) # - = Obsolete/not required # +# Last updated 2005-01-01 +# # Name N C setup 0 X exit 1 1 * @@ -60,7 +61,7 @@ geteuid 49 0 getegid 50 0 acct 51 1 -phys 52 X - +umount2 52 X - lock 53 X - ioctl 54 3 fcntl 55 3 @@ -111,7 +112,7 @@ fstatfs 100 2 ioperm 101 3 socketcall 102 2 * This is a lib internal for socket stuff -klog 103 X +syslog 103 X setitimer 104 3 getitimer 105 2 dv32_stat 106 2 * Has correct args for 32 bit dev_t @@ -121,7 +122,7 @@ iopl 110 1 vhangup 111 0 idle 112 0 - System internal -vm86 113 1 +vm86 113 1 * WARNING now vm86old wait4 114 4 swapoff 115 1 sysinfo 116 1 @@ -152,4 +153,133 @@ getdents 141 3 * New style readdir ? _newselect 142 X flock 143 2 -syscall_flock 143 X +msync 144 X +readv 145 X +writev 146 X +getsid 147 X +fdatasync 148 X +_sysctl 149 X +mlock 150 X +munlock 151 X +mlockall 152 X +munlockall 153 X +sched_setparam 154 X +sched_getparam 155 X +sched_setscheduler 156 X +sched_getscheduler 157 X +sched_yield 158 X +sched_get_priority_max 159 X +sched_get_priority_min 160 X +sched_rr_get_interval 161 X +nanosleep 162 2 +mremap 163 X +setresuid 164 X +getresuid 165 X +vm86 166 X +query_module 167 X +poll 168 X +nfsservctl 169 X +setresgid 170 X +getresgid 171 X +prctl 172 X +rt_sigreturn 173 X +rt_sigaction 174 X +rt_sigprocmask 175 X +rt_sigpending 176 X +rt_sigtimedwait 177 X +rt_sigqueueinfo 178 X +rt_sigsuspend 179 X +pread64 180 X +pwrite64 181 X +chown 182 X +getcwd 183 X +capget 184 X +capset 185 X +sigaltstack 186 X +sendfile 187 X +getpmsg 188 X +putpmsg 189 X +vfork 190 X +ugetrlimit 191 X +mmap2 192 X +truncate64 193 X +ftruncate64 194 X +stat64 195 X +lstat64 196 X +fstat64 197 X +lchown32 198 X +getuid32 199 X +getgid32 200 X +geteuid32 201 X +getegid32 202 X +setreuid32 203 X +setregid32 204 X +getgroups32 205 X +setgroups32 206 X +fchown32 207 X +setresuid32 208 X +getresuid32 209 X +setresgid32 210 X +getresgid32 211 X +chown32 212 X +setuid32 213 X +setgid32 214 X +setfsuid32 215 X +setfsgid32 216 X +pivot_root 217 X +mincore 218 X +madvise 219 X +madvise1 219 X +getdents64 220 X +fcntl64 221 X +Unused 223 X - /* is unused */ +gettid 224 X +readahead 225 X +setxattr 226 X +lsetxattr 227 X +fsetxattr 228 X +getxattr 229 X +lgetxattr 230 X +fgetxattr 231 X +listxattr 232 X +llistxattr 233 X +flistxattr 234 X +removexattr 235 X +lremovexattr 236 X +fremovexattr 237 X +tkill 238 X +sendfile64 239 X +futex 240 X +sched_setaffinity 241 X +sched_getaffinity 242 X +set_thread_area 243 X +get_thread_area 244 X +io_setup 245 X +io_destroy 246 X +io_getevents 247 X +io_submit 248 X +io_cancel 249 X +fadvise64 250 X +Unused 251 X - /* is unused */ +exit_group 252 X +lookup_dcookie 253 X +epoll_create 254 X +epoll_ctl 255 X +epoll_wait 256 X +remap_file_pages 257 X +set_tid_address 258 X +timer_create 259 X +timer_settime (__NR_timer_create+1) X +timer_gettime (__NR_timer_create+2) X +timer_getoverrun (__NR_timer_create+3) X +timer_delete (__NR_timer_create+4) X +clock_settime (__NR_timer_create+5) X +clock_gettime (__NR_timer_create+6) X +clock_getres (__NR_timer_create+7) X +clock_nanosleep (__NR_timer_create+8) X +statfs64 268 X +fstatfs64 269 X +tgkill 270 X +utimes 271 X +fadvise64_64 272 X +vserver 273 X diff -Nurd linux86.vold/libc/include/a.out.h linux86/libc/include/a.out.h --- linux86.vold/libc/include/a.out.h 1996-11-28 21:28:21.000000000 +0000 +++ linux86/libc/include/a.out.h 2002-02-17 07:56:29.000000000 +0000 @@ -48,6 +48,7 @@ #define A_UZP 0x01 /* unmapped zero page (pages) */ #define A_PAL 0x02 /* page aligned executable */ #define A_NSYM 0x04 /* new style symbol table */ +#define A_STAND 0x08 /* standalone executable */ #define A_EXEC 0x10 /* executable */ #define A_SEP 0x20 /* separate I/D */ #define A_PURE 0x40 /* pure text */ diff -Nurd linux86.vold/libc/include/asm/limits.h linux86/libc/include/asm/limits.h --- linux86.vold/libc/include/asm/limits.h 1997-10-31 20:50:22.000000000 +0000 +++ linux86/libc/include/asm/limits.h 2002-07-28 14:42:22.000000000 +0100 @@ -31,9 +31,9 @@ #define UINT_MAX 0xffff /* maximum unsigned int value */ #endif -/* BCC doesn't have signed char */ -/* #define SCHAR_MAX 127 /* maximum signed char value */ -/* #define SCHAR_MIN (-128) /* minimum signed char value */ +/* BCC does have signed char now. */ +#define SCHAR_MAX 127 /* maximum signed char value */ +#define SCHAR_MIN (-128) /* minimum signed char value */ #endif #if defined(__GNUC__) && defined(__i386__) @@ -46,12 +46,12 @@ #define UINT_MAX 0xffffffff /* maximum unsigned int value */ #endif -#ifndef INT_MAX -#error "Limits.h not fully implemented" -#endif - #ifndef RAND_MAX #define RAND_MAX INT_MAX #endif +#ifndef INT_MAX +#error "Limits.h not fully implemented, INT_MAX undefined!" +#endif + #endif diff -Nurd linux86.vold/libc/include/assert.h linux86/libc/include/assert.h --- linux86.vold/libc/include/assert.h 1996-02-24 15:21:20.000000000 +0000 +++ linux86/libc/include/assert.h 2003-07-31 19:20:04.000000000 +0100 @@ -1,4 +1,4 @@ -#ifdef __ASSERT_H +#ifndef __ASSERT_H #define __ASSERT_H #include diff -Nurd linux86.vold/libc/include/bios.h linux86/libc/include/bios.h --- linux86.vold/libc/include/bios.h 1999-03-09 20:06:51.000000000 +0000 +++ linux86/libc/include/bios.h 2002-05-26 11:14:57.000000000 +0100 @@ -22,6 +22,7 @@ int __deek_es __P((unsigned int off)); #define movedata __movedata +long _bios_get_dpt(drive); #ifdef __LIBC__ diff -Nurd linux86.vold/libc/include/conio.h linux86/libc/include/conio.h --- linux86.vold/libc/include/conio.h 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/include/conio.h 2002-03-16 14:45:26.000000000 +0000 @@ -0,0 +1,27 @@ + +#ifndef __CONIO_H +#define __CONIO_H +#include + +int cprintf __P((char *, ...)); +int cputs __P((char *)); +int getch __P((void)); +int getche __P((void)); +int kbhit __P((void)); +int putch __P((int)); +int gotoxy __P((int, int)); + +#if 0 /* Unimplemented as yet */ +char * cgets __P((char *)); +int ungetch __P((int)); +int cscanf __P((char *, ...)); +#endif + +#if 0 /* Hummm */ +unsigned outpw __P((unsigned int, unsigned int)); +unsigned inpw __P((unsigned int)); +int outp __P((unsigned int, int)); +int inp __P((unsigned int)); +#endif + +#endif diff -Nurd linux86.vold/libc/include/ctype.h linux86/libc/include/ctype.h --- linux86.vold/libc/include/ctype.h 1996-11-29 07:10:32.000000000 +0000 +++ linux86/libc/include/ctype.h 2002-05-25 13:57:30.000000000 +0100 @@ -15,24 +15,27 @@ #define __CT_p 0x20 /* punctuation */ #define __CT_x 0x40 /* hexadecimal */ -#define toupper(c) (islower(c) ? (c)^0x20 : (c)) -#define tolower(c) (isupper(c) ? (c)^0x20 : (c)) +/* Define these as simple old style ascii versions */ +#define toupper(c) (((c)>='a'&&(c)<='z') ? (c)^0x20 : (c)) +#define tolower(c) (((c)>='A'&&(c)<='Z') ? (c)^0x20 : (c)) #define _toupper(c) ((c)^0x20) #define _tolower(c) ((c)^0x20) #define toascii(c) ((c)&0x7F) +#define __CT(c) (__ctype[1+(unsigned char)c]) + /* Note the '!!' is a cast to 'bool' and even BCC deletes it in an if() */ -#define isalnum(c) (!!(__ctype[(int) c]&(__CT_u|__CT_l|__CT_d))) -#define isalpha(c) (!!(__ctype[(int) c]&(__CT_u|__CT_l))) +#define isalnum(c) (!!(__CT(c)&(__CT_u|__CT_l|__CT_d))) +#define isalpha(c) (!!(__CT(c)&(__CT_u|__CT_l))) #define isascii(c) (!((c)&~0x7F)) -#define iscntrl(c) (!!(__ctype[(int) c]&__CT_c)) -#define isdigit(c) (!!(__ctype[(int) c]&__CT_d)) -#define isgraph(c) (!(__ctype[(int) c]&(__CT_c|__CT_s))) -#define islower(c) (!!(__ctype[(int) c]&__CT_l)) -#define isprint(c) (!(__ctype[(int) c]&__CT_c)) -#define ispunct(c) (!!(__ctype[(int) c]&__CT_p)) -#define isspace(c) (!!(__ctype[(int) c]&__CT_s)) -#define isupper(c) (!!(__ctype[(int) c]&__CT_u)) -#define isxdigit(c) (!!(__ctype[(int) c]&__CT_x)) +#define iscntrl(c) (!!(__CT(c)&__CT_c)) +#define isdigit(c) (!!(__CT(c)&__CT_d)) +#define isgraph(c) (!(__CT(c)&(__CT_c|__CT_s))) +#define islower(c) (!!(__CT(c)&__CT_l)) +#define isprint(c) (!(__CT(c)&__CT_c)) +#define ispunct(c) (!!(__CT(c)&__CT_p)) +#define isspace(c) (!!(__CT(c)&__CT_s)) +#define isupper(c) (!!(__CT(c)&__CT_u)) +#define isxdigit(c) (!!(__CT(c)&__CT_x)) #endif /* __CTYPE_H */ diff -Nurd linux86.vold/libc/include/features.h linux86/libc/include/features.h --- linux86.vold/libc/include/features.h 1997-08-17 09:54:03.000000000 +0100 +++ linux86/libc/include/features.h 2002-07-30 23:49:05.000000000 +0100 @@ -7,8 +7,8 @@ #define __P(x) x #define __const const -/* Almost ansi */ -#if __STDC__ != 1 +/* Not really ansi */ +#ifdef __BCC__ #define const #define volatile #endif diff -Nurd linux86.vold/libc/include/linux/stat.h linux86/libc/include/linux/stat.h --- linux86.vold/libc/include/linux/stat.h 1997-08-16 12:20:00.000000000 +0100 +++ linux86/libc/include/linux/stat.h 2004-01-19 07:27:39.000000000 +0000 @@ -9,7 +9,6 @@ struct stat { dev_t st_dev; - unsigned short __pad1; ino_t st_ino; umode_t st_mode; nlink_t st_nlink; diff -Nurd linux86.vold/libc/include/linux/types.h linux86/libc/include/linux/types.h --- linux86.vold/libc/include/linux/types.h 1997-08-17 18:02:11.000000000 +0100 +++ linux86/libc/include/linux/types.h 2004-01-19 07:27:54.000000000 +0000 @@ -14,7 +14,7 @@ typedef __u32 loff_t; typedef __u32 speed_t; -typedef __u16 dev_t; +typedef __u32 dev_t; typedef __u32 ino_t; typedef __u32 tcflag_t; typedef __u8 cc_t; diff -Nurd linux86.vold/libc/include/malloc.h linux86/libc/include/malloc.h --- linux86.vold/libc/include/malloc.h 1996-07-23 22:03:28.000000000 +0100 +++ linux86/libc/include/malloc.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,30 +0,0 @@ - -#ifndef __MALLOC_H -#define __MALLOC_H -#include -#include - -/* - * Mini malloc allows you to use a less efficient but smaller malloc the - * cost is about 100 bytes of code in free but malloc (700bytes) doesn't - * have to be linked. Unfortunatly memory can only be reused if everything - * above it has been freed - * - */ - -extern void free __P((void *)); -extern void *malloc __P((size_t)); -extern void *realloc __P((void *, size_t)); -extern void *alloca __P((size_t)); - -extern void *(*__alloca_alloc) __P((size_t)); - -#ifdef __LIBC__ -#define __MINI_MALLOC__ -#endif - -#ifdef __MINI_MALLOC__ -#define malloc(x) ((*__alloca_alloc)(x)) -#endif - -#endif diff -Nurd linux86.vold/libc/include/regexp.h linux86/libc/include/regexp.h --- linux86.vold/libc/include/regexp.h 1989-03-03 21:54:51.000000000 +0000 +++ linux86/libc/include/regexp.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,21 +0,0 @@ -/* - * Definitions etc. for regexp(3) routines. - * - * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof], - * not the System V one. - */ -#define NSUBEXP 10 -typedef struct regexp { - char *startp[NSUBEXP]; - char *endp[NSUBEXP]; - char regstart; /* Internal use only. */ - char reganch; /* Internal use only. */ - char *regmust; /* Internal use only. */ - int regmlen; /* Internal use only. */ - char program[1]; /* Unwarranted chumminess with compiler. */ -} regexp; - -extern regexp *regcomp(); -extern int regexec(); -extern void regsub(); -extern void regerror(); diff -Nurd linux86.vold/libc/include/regmagic.h linux86/libc/include/regmagic.h --- linux86.vold/libc/include/regmagic.h 1989-03-03 21:55:06.000000000 +0000 +++ linux86/libc/include/regmagic.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,5 +0,0 @@ -/* - * The first byte of the regexp internal "program" is actually this magic - * number; the start node begins in the second byte. - */ -#define MAGIC 0234 diff -Nurd linux86.vold/libc/include/stdarg.h linux86/libc/include/stdarg.h --- linux86.vold/libc/include/stdarg.h 1997-01-25 17:22:09.000000000 +0000 +++ linux86/libc/include/stdarg.h 2004-06-20 14:37:51.000000000 +0100 @@ -26,6 +26,7 @@ #ifndef __STDARG_H #define __STDARG_H +#include #ifdef sparc # define _VA_ALIST_ "__builtin_va_alist" @@ -43,5 +44,5 @@ #endif /* __STDARG_H */ #if __FIRST_ARG_IN_AX__ -#error First arg is in a register, stdarg.h cannot take its address +#warning First arg is in a register, stdarg.h cannot take its address #endif diff -Nurd linux86.vold/libc/include/stdio.h linux86/libc/include/stdio.h --- linux86.vold/libc/include/stdio.h 1999-02-01 08:36:35.000000000 +0000 +++ linux86/libc/include/stdio.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,129 +0,0 @@ - -#ifndef __STDIO_H -#define __STDIO_H - -#include -#include - -#ifndef SEEK_SET -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 -#endif - -#define _IOFBF 0x00 /* full buffering */ -#define _IOLBF 0x01 /* line buffering */ -#define _IONBF 0x02 /* no buffering */ -#define __MODE_BUF 0x03 /* Modal buffering dependent on isatty */ - -#define __MODE_FREEBUF 0x04 /* Buffer allocated with malloc, can free */ -#define __MODE_FREEFIL 0x08 /* FILE allocated with malloc, can free */ - -#define __MODE_READ 0x10 /* Opened in read only */ -#define __MODE_WRITE 0x20 /* Opened in write only */ -#define __MODE_RDWR 0x30 /* Opened in read/write */ - -#define __MODE_READING 0x40 /* Buffer has pending read data */ -#define __MODE_WRITING 0x80 /* Buffer has pending write data */ - -#define __MODE_EOF 0x100 /* EOF status */ -#define __MODE_ERR 0x200 /* Error status */ -#define __MODE_UNGOT 0x400 /* Buffer has been polluted by ungetc */ - -#ifdef __MSDOS__ -#define __MODE_IOTRAN 0x1000 /* MSDOS nl <-> cr,nl translation */ -#else -#define __MODE_IOTRAN 0 -#endif - -/* when you add or change fields here, be sure to change the initialization - * in stdio_init and fopen */ -struct __stdio_file { - unsigned char *bufpos; /* the next byte to write to or read from */ - unsigned char *bufread; /* the end of data returned by last read() */ - unsigned char *bufwrite; /* highest address writable by macro */ - unsigned char *bufstart; /* the start of the buffer */ - unsigned char *bufend; /* the end of the buffer; ie the byte after the last - malloc()ed byte */ - - int fd; /* the file descriptor associated with the stream */ - int mode; - - char unbuf[8]; /* The buffer for 'unbuffered' streams */ - - struct __stdio_file * next; -}; - -#define EOF (-1) -#ifndef NULL -#define NULL ((void*)0) -#endif - -typedef struct __stdio_file FILE; - -#ifdef __AS386_16__ -#define BUFSIZ (256) -#else -#define BUFSIZ (2048) -#endif - -extern FILE stdin[1]; -extern FILE stdout[1]; -extern FILE stderr[1]; - -#ifdef __MSDOS__ -#define putc(c, fp) fputc(c, fp) -#define getc(fp) fgetc(fp) -#else -#define putc(c, stream) \ - (((stream)->bufpos >= (stream)->bufwrite) ? fputc((c), (stream)) \ - : (unsigned char) (*(stream)->bufpos++ = (c)) ) - -#define getc(stream) \ - (((stream)->bufpos >= (stream)->bufread) ? fgetc(stream): \ - (*(stream)->bufpos++)) -#endif - -#define putchar(c) putc((c), stdout) -#define getchar() getc(stdin) - -#define ferror(fp) (((fp)->mode&__MODE_ERR) != 0) -#define feof(fp) (((fp)->mode&__MODE_EOF) != 0) -#define clearerr(fp) ((fp)->mode &= ~(__MODE_EOF|__MODE_ERR),0) -#define fileno(fp) ((fp)->fd) - -/* declare functions; not like it makes much difference without ANSI */ -/* RDB: The return values _are_ important, especially if we ever use - 8086 'large' model - */ - -/* These two call malloc */ -#define setlinebuf(__fp) setvbuf((__fp), (char*)0, _IOLBF, 0) -extern int setvbuf __P((FILE*, char*, int, size_t)); - -/* These don't */ -#define setbuf(__fp, __buf) setbuffer((__fp), (__buf), BUFSIZ) -extern void setbuffer __P((FILE*, char*, int)); - -extern int fgetc __P((FILE*)); -extern int fputc __P((int, FILE*)); - -extern int fclose __P((FILE*)); -extern int fflush __P((FILE*)); -extern char *fgets __P((char*, size_t, FILE*)); -extern FILE *__fopen __P((char*, int, FILE*, char*)); - -#define fopen(__file, __mode) __fopen((__file), -1, (FILE*)0, (__mode)) -#define freopen(__file, __mode, __fp) __fopen((__file), -1, (__fp), (__mode)) -#define fdopen(__file, __mode) __fopen((char*)0, (__file), (FILE*)0, (__mode)) - -extern int fputs __P((char*, FILE*)); -extern int puts __P((char*)); - -extern int printf __P ((__const char*, ...)); -extern int fprintf __P ((FILE*, __const char*, ...)); -extern int sprintf __P ((char*, __const char*, ...)); - -#define stdio_pending(fp) ((fp)->bufread>(fp)->bufpos) - -#endif /* __STDIO_H */ diff -Nurd linux86.vold/libc/include/stdlib.h linux86/libc/include/stdlib.h --- linux86.vold/libc/include/stdlib.h 1996-07-20 12:26:59.000000000 +0100 +++ linux86/libc/include/stdlib.h 2004-06-20 17:43:20.000000000 +0100 @@ -14,10 +14,7 @@ #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 -extern void * malloc __P ((size_t)); -extern void * calloc __P ((size_t, size_t)); -extern void free __P ((void *)); -extern void * realloc __P ((void *, size_t)); +#include extern int rand __P ((void)); extern void srand __P ((unsigned int seed)); @@ -27,8 +24,12 @@ char ** endptr, int base)); #ifndef __HAS_NO_FLOATS__ extern double strtod __P ((const char * nptr, char ** endptr)); +extern double atof __P ((__const char *__nptr)); #endif +extern long int atol __P ((__const char *__nptr)); +extern int atoi __P ((__const char *__nptr)); + /* Returned by `div'. */ typedef struct { @@ -43,4 +44,8 @@ long int rem; /* Remainder. */ } ldiv_t; + +extern char *getenv __P ((__const char *__name)); +extern char *mktemp __P ((char *__template)); + #endif /* __STDLIB_H */ diff -Nurd linux86.vold/libc/include/string.h linux86/libc/include/string.h --- linux86.vold/libc/include/string.h 1996-03-19 20:16:38.000000000 +0000 +++ linux86/libc/include/string.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,53 +0,0 @@ - -#ifndef __STRING_H -#define __STRING_H -#include -#include -#include - -/* Basic string functions */ -extern size_t strlen __P ((__const char* __str)); - -extern char * strcat __P ((char*, __const char*)); -extern char * strcpy __P ((char*, __const char*)); -extern int strcmp __P ((__const char*, __const char*)); - -extern char * strncat __P ((char*, char*, size_t)); -extern char * strncpy __P ((char*, char*, size_t)); -extern int strncmp __P ((__const char*, __const char*, size_t)); - -extern char * strchr __P ((char*, int)); -extern char * strrchr __P ((char*, int)); -extern char * strdup __P ((char*)); - -/* Basic mem functions */ -extern void * memcpy __P ((void*, __const void*, size_t)); -extern void * memccpy __P ((void*, void*, int, size_t)); -extern void * memchr __P ((__const void*, __const int, size_t)); -extern void * memset __P ((void*, int, size_t)); -extern int memcmp __P ((__const void*, __const void*, size_t)); - -extern void * memmove __P ((void*, void*, size_t)); - -/* Minimal (very!) locale support */ -#define strcoll strcmp -#define strxfrm strncpy - -/* BSDisms */ -#define index strchr -#define rindex strrchr - -/* Other common BSD functions */ -extern int strcasecmp __P ((char*, char*)); -extern int strncasecmp __P ((char*, char*, size_t)); -char *strpbrk __P ((char *, char *)); -char *strsep __P ((char **, char *)); -char *strstr __P ((char *, char *)); -char *strtok __P ((char *, char *)); -size_t strcspn __P ((char *, char *)); -size_t strspn __P ((char *, char *)); - -/* Linux silly hour */ -char *strfry __P ((char *)); - -#endif diff -Nurd linux86.vold/libc/include/sys/cdefs.h linux86/libc/include/sys/cdefs.h --- linux86.vold/libc/include/sys/cdefs.h 1996-07-20 12:26:41.000000000 +0100 +++ linux86/libc/include/sys/cdefs.h 2004-06-20 17:42:47.000000000 +0100 @@ -3,14 +3,16 @@ #define __SYS_CDEFS_H #include -#if defined (__STDC__) && __STDC__ +#if __STDC__ #define __CONCAT(x,y) x ## y #define __STRING(x) #x /* This is not a typedef so `const __ptr_t' does the right thing. */ #define __ptr_t void * +#ifndef __HAS_NO_FLOATS__ typedef long double __long_double_t; +#endif #else diff -Nurd linux86.vold/libc/kinclude/Makefile linux86/libc/kinclude/Makefile --- linux86.vold/libc/kinclude/Makefile 1997-08-16 09:26:04.000000000 +0100 +++ linux86/libc/kinclude/Makefile 2003-01-29 19:40:25.000000000 +0000 @@ -9,8 +9,6 @@ -@rm -f ../include/linuxmt ../include/arch ln -s ../kinclude/linuxmt ../include ln -s ../kinclude/arch ../include - @touch Used clean: - -@rm -f ../include/linuxmt ../include/arch - -@rm -f Used + -rm -f ../include/linuxmt ../include/arch diff -Nurd linux86.vold/libc/Makefile linux86/libc/Makefile --- linux86.vold/libc/Makefile 2001-05-21 14:02:37.000000000 +0100 +++ linux86/libc/Makefile 2004-01-24 12:02:27.000000000 +0000 @@ -9,18 +9,19 @@ TOP=$(TOPDIR)/libc endif -VERMAJOR=0 -VERMINOR=16 -VERPATCH=0 -VER=$(VERMAJOR).$(VERMINOR).$(VERPATCH) - CC=bcc CCFLAGS=-I -I$(TOP)/include DEFS=-D__LIBC__ include Make.defs +ifeq ($(VERSION),) +include VERSION +endif + CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) +USERID=$(shell id -gn) +GROUPID=$(shell id -un) ############################################################################ @@ -38,13 +39,13 @@ done crt3.o: crt0.c Makefile - $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VER)"' -o $@ crt0.c + $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VERSION)"' -o $@ crt0.c crt0.o: crt0.c Makefile - $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VER)"' -o $@ crt0.c + $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VERSION)"' -o $@ crt0.c crtg.o: crt0.c Makefile - $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VER)"' -o $@ crt0.c + $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VERSION)"' -o $@ crt0.c crtX.o: @echo "You need to define the 'PLATFORM=...' variable," @@ -57,11 +58,10 @@ @for i in `cat .config.dir`; do \ grep -s '^transfer' $$i/Makefile && $(MAKE) -s -C $$i $@ ; \ done ; echo -n - @[ -f kinclude/Used ] || \ - { rm -f include/linuxmt include/arch ; \ - ln -s $(ELKSSRC)/include/linuxmt include ; \ - ln -s $(ELKSSRC)/include/arch include ; \ - } + @[ -d include/linuxmt/. ] || \ + ln -s $(ELKSSRC)/include/linuxmt include + @[ -d include/arch/. ] || \ + ln -s $(ELKSSRC)/include/arch include ############################################################################ @@ -75,17 +75,12 @@ ############################################################################ -install_incl: - install -d $(BCCHOME)/include - rm -f $(BCCHOME)/include/linuxmt $(BCCHOME)/include/arch ||: - cp -pr include/* $(BCCHOME)/include - if [ ! -f kinclude/Used ] ; \ - then rm -rf $(BCCHOME)/include/linuxmt $(BCCHOME)/include/arch ; \ - ln -s $(ELKSSRC)/include/linuxmt $(BCCHOME)/include ; \ - ln -s $(ELKSSRC)/include/arch $(BCCHOME)/include ; \ - fi - -chown -R root:root $(BCCHOME)/include 2>/dev/null - -chmod -R u=rwX,og=rX $(BCCHOME)/include +install_incl: transfer + install -d $(DISTINCL)/include + rm -f $(DISTINCL)/include/linuxmt $(DISTINCL)/include/arch ||: + cp -LpR include/* $(DISTINCL)/include + -chown -R $(USERID):$(GROUPID) $(DISTINCL)/include + -chmod -R ugo-x,u=rwX,og=rX $(DISTINCL)/include ############################################################################ @@ -103,6 +98,3 @@ rm -f .config.dir .config.lst .config.tmp ############################################################################ - -Libc_version: - echo $(VER) > ../Libc_version diff -Nurd linux86.vold/libc/malloc/Makefile linux86/libc/malloc/Makefile --- linux86.vold/libc/malloc/Makefile 1997-03-08 20:14:11.000000000 +0000 +++ linux86/libc/malloc/Makefile 2003-01-29 19:40:41.000000000 +0000 @@ -15,7 +15,7 @@ $(AR) $(ARFLAGS) $@ $*.o clean: - rm -f *.o libc.a + rm -f *.o libc.a ../include/malloc.h transfer: -@rm ../include/malloc.h diff -Nurd linux86.vold/libc/malloc/malloc.c linux86/libc/malloc/malloc.c --- linux86.vold/libc/malloc/malloc.c 1996-10-22 21:29:10.000000000 +0100 +++ linux86/libc/malloc/malloc.c 2003-12-31 11:36:41.000000000 +0000 @@ -78,6 +78,9 @@ #endif #ifdef L_alloca +/* This alloca is based on the same concept as the EMACS fallback alloca. + * It should probably be considered Copyright the FSF under the GPL. + */ static mem *alloca_stack = 0; void * diff -Nurd linux86.vold/libc/misc/atof.c linux86/libc/misc/atof.c --- linux86.vold/libc/misc/atof.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/misc/atof.c 2004-06-20 18:23:18.000000000 +0100 @@ -0,0 +1,16 @@ +/* Copyright (C) Robert de Bath + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ + +double +#ifdef __STDC__ +atof(const char *p) +#else +atof(p) +char *p; +#endif +{ + return strtod(p, (char**)0); +} + diff -Nurd linux86.vold/libc/misc/crypt.c linux86/libc/misc/crypt.c --- linux86.vold/libc/misc/crypt.c 1997-10-19 17:30:46.000000000 +0100 +++ linux86/libc/misc/crypt.c 2002-05-30 22:05:11.000000000 +0100 @@ -6,7 +6,7 @@ /* * I've: * Compared the TEA implementation to a reference source - OK - * Noted the cycles count at 64 is twice the suggested value. + * Reduced the cycles count from 64 to 32 (the suggested value) * Changed the types of 'n' and 'i' for better code with bcc. * Removed a possible overrun of rkey by looping the values, it's now * possible to _choose_ every bit of the 128bit PW with a 32 character word. @@ -26,7 +26,7 @@ k is the key, v is the data to be encrypted. */ unsigned long v[2], sum=0, delta=0x9e3779b9, k[4]; - int n=64, i, j; + int n=32, i, j; static char rkey[16]; /* Our constant string will be a string of zeros .. */ diff -Nurd linux86.vold/libc/misc/ctype.c linux86/libc/misc/ctype.c --- linux86.vold/libc/misc/ctype.c 1996-11-29 07:11:06.000000000 +0000 +++ linux86/libc/misc/ctype.c 2002-05-25 14:04:20.000000000 +0100 @@ -9,11 +9,9 @@ #include -#undef toupper -#undef tolower - -unsigned char __ctype[128] = +unsigned char __ctype[257] = { + 0, /* -1 */ __CT_c, __CT_c, __CT_c, __CT_c, /* 0x00..0x03 */ __CT_c, __CT_c, __CT_c, __CT_c, /* 0x04..0x07 */ __CT_c, __CT_c|__CT_s, __CT_c|__CT_s, __CT_c|__CT_s, /* 0x08..0x0B */ @@ -55,14 +53,3 @@ __CT_p, __CT_p, __CT_p, __CT_c /* 0x7C..0x7F */ }; -int toupper(c) -int c; -{ - return(islower(c) ? (c ^ 0x20) : (c)); -} - -int tolower(c) -int c; -{ - return(isupper(c) ? (c ^ 0x20) : (c)); -} diff -Nurd linux86.vold/libc/misc/ctypefn.c linux86/libc/misc/ctypefn.c --- linux86.vold/libc/misc/ctypefn.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/misc/ctypefn.c 2002-05-25 14:04:31.000000000 +0100 @@ -0,0 +1,25 @@ +/* Copyright (C) 1995,1996 Robert de Bath + * This file is part of the Linux-8086 C library and is distributed + * under the GNU Library General Public License. + */ + +/* + * CTYPE.C Character classification and conversion + */ + +#include + +#undef toupper +#undef tolower + +int toupper(c) +int c; +{ + return(islower(c) ? (c ^ 0x20) : (c)); +} + +int tolower(c) +int c; +{ + return(isupper(c) ? (c ^ 0x20) : (c)); +} diff -Nurd linux86.vold/libc/misc/Makefile linux86/libc/misc/Makefile --- linux86.vold/libc/misc/Makefile 1998-02-06 08:20:54.000000000 +0000 +++ linux86/libc/misc/Makefile 2004-06-20 18:19:42.000000000 +0100 @@ -10,7 +10,7 @@ EOBJ=on_exit.o atexit.o __do_exit.o GOBJ=atoi.o atol.o ltoa.o ltostr.o \ - ctype.o qsort.o bsearch.o rand.o lsearch.o getopt.o \ + ctype.o ctypefn.o qsort.o bsearch.o rand.o lsearch.o getopt.o \ itoa.o cputype.o strtol.o crypt.o UOBJ=getenv.o putenv.o popen.o system.o setenv.o getcwd.o tmpnam.o @@ -27,7 +27,7 @@ # No ELKS strtod() until BCC does 16 bit FP... ifneq ($(LIB_CPU),i86) -OBJ+=strtod.o +OBJ+=strtod.o atof.o endif CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS) diff -Nurd linux86.vold/libc/misc/strtod.c linux86/libc/misc/strtod.c --- linux86.vold/libc/misc/strtod.c 1996-12-10 22:38:25.000000000 +0000 +++ linux86/libc/misc/strtod.c 2004-06-20 19:17:25.000000000 +0100 @@ -20,9 +20,6 @@ #include #include -#ifndef __AS386_16__ -/* BCC-16 has broken FP code */ - double strtod(const char *nptr, char ** endptr) { @@ -97,4 +94,3 @@ } return (negative ? -number:number); } -#endif diff -Nurd linux86.vold/libc/misc/strtol.c linux86/libc/misc/strtol.c --- linux86.vold/libc/misc/strtol.c 1996-01-29 18:56:13.000000000 +0000 +++ linux86/libc/misc/strtol.c 2003-09-13 06:30:37.000000000 +0100 @@ -18,6 +18,8 @@ * */ +/* TODO: This needs range clamping and setting errno when it's done. */ + #include #include @@ -64,8 +66,8 @@ /* If base==0 and the string begins with "0x" then we're supposed to assume that it's hexadecimal (base 16). */ - else - if (base==0 && *nptr=='0') + if (base==0 && *nptr=='0') + { if (toupper(*(nptr+1))=='X') { base=16; @@ -78,7 +80,7 @@ base=8; nptr++; } - + } /* If base is still 0 (it was 0 to begin with and the string didn't begin with "0"), then we are supposed to assume that it's base 10 */ @@ -86,13 +88,16 @@ base=10; number=0; - while (isalnum(*nptr)) + while (isascii(*nptr) && isalnum(*nptr)) { - number= (number*base)+((isalpha(*nptr) ? toupper(*nptr) : *nptr) - - (isdigit(*nptr) ? '0' : 'A' + 9)); - nptr++; - if (*nptr>'0'+base) + int ch = *nptr; + if (islower(ch)) ch = toupper(ch); + ch -= (ch<='9' ? '0' : 'A'-10); + if (ch>base) break; + + number= (number*base)+ch; + nptr++; } /* Some code is simply _impossible_ to write with -Wcast-qual .. :-\ */ diff -Nurd linux86.vold/libc/msdos/conio.c linux86/libc/msdos/conio.c --- linux86.vold/libc/msdos/conio.c 1999-03-10 07:17:03.000000000 +0000 +++ linux86/libc/msdos/conio.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,83 +0,0 @@ -/* Copyright (C) 1999 Robert de Bath - * This file is part of the Linux-8086 C library and is distributed - * under the GNU Library General Public License. - */ - -/* - * I'm not sure if these should be BIOS or dos calls, so I'll assume they're - * BIOS calls but I may have to do something about Ctrl-C. - */ - -getch() -{ -#asm - xor ax,ax - int $16 -#endasm -} - -getche() -{ - int i = getch(); - if( i & 0xFF) putch(i); - return i; -} - -kbhit() -{ -#asm - mov ah,#1 - int $16 - jz nokey - cmp ax,#0 - jnz dort - mov ax,#3 -dort: - ret -nokey: - xor ax,ax -#endasm -} - -putch() -{ -#asm -#if !__FIRST_ARG_IN_AX__ - mov bx,sp - mov ax,[bx+2] -#endif - mov ah,#$0E - mov bx,#7 - int $10 -#endasm -} - -cputs(str) -char * str; -{ - while(*str) putch(*str++); -} - -#if 0 - -cgets() -{ -} - -cprintf() -{ -} - -cscanf() -{ -} - -getpass() -{ -} - -gotoxy() -{ -} - -#endif diff -Nurd linux86.vold/libc/README linux86/libc/README --- linux86.vold/libc/README 1998-12-04 17:52:48.000000000 +0000 +++ linux86/libc/README 2002-01-19 22:31:43.000000000 +0000 @@ -25,12 +25,11 @@ i386fp BCC's floating point routines for 386 code. include Some include files, some new others Glib or Glib hacked. kinclude Kernel include files, here for now. -malloc1 Robert's malloc routines -malloc2 Joel's malloc routines +malloc Malloc routines misc Various larger functions msdos This is the syscall directory for msdos. regexp Standard regular expression parser -stdio2 Robert's standard I/O +stdio Robert's standard I/O string The functions for string.h syscall All the system call functions, and some tied lib ones. termios Termimal mode control. diff -Nurd linux86.vold/libc/regexp/Makefile linux86/libc/regexp/Makefile --- linux86.vold/libc/regexp/Makefile 1997-03-08 20:15:45.000000000 +0000 +++ linux86/libc/regexp/Makefile 2003-01-29 19:41:07.000000000 +0000 @@ -23,3 +23,4 @@ clean: rm -f libc.a *.o core mon.out timer.t.h dMakefile dtr try timer + rm -f ../include/regexp.h ../include/regmagic.h diff -Nurd linux86.vold/libc/stdio/Makefile linux86/libc/stdio/Makefile --- linux86.vold/libc/stdio/Makefile 1997-03-08 20:16:05.000000000 +0000 +++ linux86/libc/stdio/Makefile 2005-01-23 13:09:11.000000000 +0000 @@ -7,12 +7,12 @@ endif ASRC=stdio.c -AOBJ=_stdio_init.o fputc.o fgetc.o fflush.o fgets.o gets.o fputs.o \ - puts.o fread.o fwrite.o fopen.o fclose.o fseek.o rewind.o ftell.o \ - setbuffer.o setvbuf.o ungetc.o +AOBJ=_stdio_init.o fputc.o fgetc.o fflush.o fgets.o gets.o fputs.o \ + puts.o fread.o fwrite.o fopen.o fdopen.o freopen.o __fopen.o \ + fclose.o fseek.o rewind.o ftell.o setbuffer.o setvbuf.o ungetc.o PSRC=printf.c -POBJ=printf.o sprintf.o fprintf.o vprintf.o vsprintf.o vfprintf.o +POBJ=printf.o sprintf.o fprintf.o vprintf.o vsprintf.o vfprintf.o fp_print.o SSRC=scanf.c SOBJ=scanf.o sscanf.o fscanf.o vscanf.o vsscanf.o vfscanf.o @@ -43,7 +43,7 @@ cp -p stdio.h ../include/. clean: - rm -f *.o libc.a + rm -f *.o libc.a ../include/stdio.h $(LIBC)($(OBJ)): stdio.h diff -Nurd linux86.vold/libc/stdio/printf.c linux86/libc/stdio/printf.c --- linux86.vold/libc/stdio/printf.c 1998-10-25 06:53:01.000000000 +0000 +++ linux86/libc/stdio/printf.c 2005-01-23 14:27:23.000000000 +0000 @@ -23,7 +23,7 @@ #include #include -#ifdef __STDC__ +#if defined(__STDC__) && !defined(__FIRST_ARG_IN_AX__) #include #define va_strt va_start #else @@ -35,7 +35,7 @@ #ifdef L_printf -#ifdef __STDC__ +#if defined(__STDC__) && !defined(__FIRST_ARG_IN_AX__) int printf(const char * fmt, ...) #else int printf(fmt, va_alist) @@ -53,7 +53,7 @@ #endif #ifdef L_sprintf -#ifdef __STDC__ +#if defined(__STDC__) && !defined(__FIRST_ARG_IN_AX__) int sprintf(char * sp, const char * fmt, ...) #else int sprintf(sp, fmt, va_alist) @@ -80,7 +80,7 @@ #endif #ifdef L_fprintf -#ifdef __STDC__ +#if defined(__STDC__) && !defined(__FIRST_ARG_IN_AX__) int fprintf(FILE * fp, const char * fmt, ...) #else int fprintf(fp, fmt, va_alist) @@ -129,7 +129,7 @@ #ifdef L_vfprintf -#ifdef FLOATS +#ifndef __HAS_NO_FLOATS__ int (*__fp_print)() = 0; #endif @@ -344,7 +344,7 @@ sign, pad, width, preci, buffer_mode); break; -#if FLOATS +#ifndef __HAS_NO_FLOATS__ case 'e': /* float */ case 'f': case 'g': @@ -378,3 +378,72 @@ return (cnt); } #endif + +#ifdef L_fp_print +#ifndef __HAS_NO_FLOATS__ + +#ifdef __AS386_16__ +#asm + loc 1 ! Make sure the pointer is in the correct segment +auto_func: ! Label for bcc -M to work. + .word ___xfpcvt ! Pointer to the autorun function + .text ! So the function after is also in the correct seg. +#endasm +#endif + +#ifdef __AS386_32__ +#asm + loc 1 ! Make sure the pointer is in the correct segment +auto_func: ! Label for bcc -M to work. + .long ___xfpcvt ! Pointer to the autorun function + .text ! So the function after is also in the correct seg. +#endasm +#endif + +void +__fp_print_func(pval, style, preci, ptmp) + double * pval; + int style; + int preci; + char * ptmp; +{ + int decpt, negative; + char * cvt; + double val = *pval; + + if (preci < 0) preci = 6; + + cvt = fcvt(val, preci, &decpt, &negative); + if(negative) + *ptmp++ = '-'; + + if (decpt<0) { + *ptmp++ = '0'; + *ptmp++ = '.'; + while(decpt<0) { + *ptmp++ = '0'; decpt++; + } + } + + while(*cvt) { + *ptmp++ = *cvt++; + if (decpt == 1) + *ptmp++ = '.'; + decpt--; + } + + while(decpt > 0) { + *ptmp++ = '0'; + decpt--; + } +} + +void +__xfpcvt() +{ + extern int (*__fp_print)(); + __fp_print = __fp_print_func; +} + +#endif +#endif diff -Nurd linux86.vold/libc/stdio/scanf.c linux86/libc/stdio/scanf.c --- linux86.vold/libc/stdio/scanf.c 1998-09-19 12:20:16.000000000 +0100 +++ linux86/libc/stdio/scanf.c 2002-07-28 09:01:26.000000000 +0100 @@ -16,7 +16,7 @@ #include #include -#ifdef __STDC__ +#if defined(__STDC__) && !defined(__FIRST_ARG_IN_AX__) #include #define va_strt va_start #else @@ -25,7 +25,7 @@ #endif #ifdef L_scanf -#ifdef __STDC__ +#if defined(__STDC__) && !defined(__FIRST_ARG_IN_AX__) int scanf(const char * fmt, ...) #else int scanf(fmt, va_alist) @@ -43,7 +43,7 @@ #endif #ifdef L_sscanf -#ifdef __STDC__ +#if defined(__STDC__) && !defined(__FIRST_ARG_IN_AX__) int sscanf(char * sp, const char * fmt, ...) #else int sscanf(sp, fmt, va_alist) @@ -69,7 +69,7 @@ #endif #ifdef L_fscanf -#ifdef __STDC__ +#if defined(__STDC__) && !defined(__FIRST_ARG_IN_AX__) int fscanf(FILE * fp, const char * fmt, ...) #else int fscanf(fp, fmt, va_alist) diff -Nurd linux86.vold/libc/stdio/stdio.c linux86/libc/stdio/stdio.c --- linux86.vold/libc/stdio/stdio.c 1999-03-09 14:54:35.000000000 +0000 +++ linux86/libc/stdio/stdio.c 2002-05-30 19:52:09.000000000 +0100 @@ -582,9 +582,39 @@ #endif #ifdef L_fopen +FILE * +fopen(file, mode) +char * file; +char * mode; +{ + return __fopen(file, -1, (FILE*)0, mode); +} +#endif + +#ifdef L_freopen +FILE * +freopen(file, mode, fp) +char * file; +char * mode; +FILE * fp; +{ + return __fopen(file, -1, fp, mode); +} +#endif + +#ifdef L_fdopen +FILE * +fdopen(file, mode) +int file; +char * mode; +{ + return __fopen((char*)0, file, (FILE*)0, mode); +} +#endif + +#ifdef L___fopen /* - * This Fopen is all three of fopen, fdopen and freopen. The macros in - * stdio.h show the other names. + * This is the common code for all three of fopen, fdopen and freopen. */ FILE * __fopen(fname, fd, fp, mode) diff -Nurd linux86.vold/libc/stdio/stdio.h linux86/libc/stdio/stdio.h --- linux86.vold/libc/stdio/stdio.h 1999-02-01 08:36:35.000000000 +0000 +++ linux86/libc/stdio/stdio.h 2002-05-30 19:53:49.000000000 +0100 @@ -111,11 +111,14 @@ extern int fclose __P((FILE*)); extern int fflush __P((FILE*)); extern char *fgets __P((char*, size_t, FILE*)); -extern FILE *__fopen __P((char*, int, FILE*, char*)); -#define fopen(__file, __mode) __fopen((__file), -1, (FILE*)0, (__mode)) -#define freopen(__file, __mode, __fp) __fopen((__file), -1, (__fp), (__mode)) -#define fdopen(__file, __mode) __fopen((char*)0, (__file), (FILE*)0, (__mode)) +extern FILE *fopen __P((char*, char*)); +extern FILE *fdopen __P((int, char*)); +extern FILE *freopen __P((char*, char*, FILE*)); + +#ifdef __LIBC__ +extern FILE *__fopen __P((char*, int, FILE*, char*)); +#endif extern int fputs __P((char*, FILE*)); extern int puts __P((char*)); diff -Nurd linux86.vold/libc/string/Makefile linux86/libc/string/Makefile --- linux86.vold/libc/string/Makefile 1997-03-08 20:16:28.000000000 +0000 +++ linux86/libc/string/Makefile 2003-01-29 19:41:21.000000000 +0000 @@ -26,4 +26,4 @@ cp -p string.h ../include/. clean: - rm -f *.o + rm -f *.o ../include/string.h diff -Nurd linux86.vold/libc/string/string.c linux86/libc/string/string.c --- linux86.vold/libc/string/string.c 1999-03-22 19:11:39.000000000 +0000 +++ linux86/libc/string/string.c 2003-08-18 08:17:22.000000000 +0100 @@ -42,10 +42,11 @@ #ifdef PARANOID push es - push ds ; Im not sure if this is needed, so just in case. + push ds ! Im not sure if this is needed, so just in case. pop es cld -#endif ! This is almost the same as memchr, but it can +#endif + ! This is almost the same as memchr, but it can ! stay as a special. #if __FIRST_ARG_IN_AX__ @@ -139,6 +140,7 @@ xor ax,ax ; so return zero jmp sc_3 sc_2: + cmc sbb ax,ax ; Collect correct val (-1,1). orb al,#1 sc_3: diff -Nurd linux86.vold/libc/syscall/syscall.dev86 linux86/libc/syscall/syscall.dev86 --- linux86.vold/libc/syscall/syscall.dev86 1997-10-18 15:28:19.000000000 +0100 +++ linux86/libc/syscall/syscall.dev86 2002-05-26 09:27:47.000000000 +0100 @@ -4,17 +4,15 @@ # ELKSemu and elks itself. Changes to this may require changes in # all three of those packages. # -# . = Ok, with comment -# * = Needs libc code (Prefix __) -# - = Obsolete/not required -# @ = May be required later +# '.' = Ok, with comment +# '*' = Needs libc code (Prefix __) +# '-' = Obsolete/not required +# '@' = May be required later +# '=' = Depends on stated config variable # # An initial plus on the call number specifies that this call is # implemented in the kernel. # -# Package versions are matched. -# Dev86/Elksemu version - 0.13.1 -# Elks version - 0.0.66 # # Name No Args Flag, comment # @@ -47,29 +45,29 @@ alarm 27 2 fstat +28 2 pause 29 0 -utime 30 2 +utime +30 2 chroot +31 1 -vfork 32 0 +vfork +32 0 access +33 2 nice 34 1 sleep 35 1 sync +36 0 -kill 37 2 +kill +37 2 rename +38 2 mkdir +39 2 rmdir +40 1 dup +41 1 . There is a fcntl lib function too. -pipe 42 1 +pipe +42 1 times 43 2 * 2nd arg is pointer for long ret val. profil 44 4 @ dup2 +45 2 setgid +46 1 getgid 47 1 * this gets both gid and egid -signal 48 2 * have put the despatch table in user space. +signal +48 2 * have put the despatch table in user space. getinfo 49 1 @ possible? gets pid,ppid,uid,euid etc fcntl +50 3 acct 51 1 @ Accounting to named file (off if null) -phys 52 3 - Replaced my mmap() +phys 52 3 - Replaced by mmap() lock 53 1 @ Prevent swapping for this proc if flg!=0 ioctl +54 3 . make this and fcntl the same ? reboot +55 3 . the magic number is 0xfee1,0xdead,... @@ -78,11 +76,20 @@ symlink +58 2 readlink +59 3 umask +60 1 -settimeofday 61 2 -gettimeofday 62 2 -select 63 5 * +settimeofday +61 2 +gettimeofday +62 2 +select +63 5 . 5 paramaters is possible readdir +64 3 * - +insmod 65 1 - Removed support for modules +fchown +66 3 +dlload +67 2 +setsid +68 0 +socket +69 3 +bind +70 3 +listen +71 2 +accept +72 3 +connect +73 3 +knlvsn +74 1 = CONFIG_SYS_VERSION # # Name No Args Flag&comment # diff -Nurd linux86.vold/libc/syscall/syscall.dev86.old linux86/libc/syscall/syscall.dev86.old --- linux86.vold/libc/syscall/syscall.dev86.old 1970-01-01 01:00:00.000000000 +0100 +++ linux86/libc/syscall/syscall.dev86.old 1997-10-18 15:28:19.000000000 +0100 @@ -0,0 +1,160 @@ +# +# WARNING! +# This file is used to generate the system call lists for Dev86(elks) +# ELKSemu and elks itself. Changes to this may require changes in +# all three of those packages. +# +# . = Ok, with comment +# * = Needs libc code (Prefix __) +# - = Obsolete/not required +# @ = May be required later +# +# An initial plus on the call number specifies that this call is +# implemented in the kernel. +# +# Package versions are matched. +# Dev86/Elksemu version - 0.13.1 +# Elks version - 0.0.66 +# +# Name No Args Flag, comment +# +exit +1 1 * c exit does stdio, _exit in crt0 +fork +2 0 +read +3 3 +write +4 3 +open +5 3 +close +6 1 +wait4 +7 4 +creat 8 0 - Not needed alias for open +link +9 2 +unlink +10 1 +execve +11 3 * execve minix style +chdir +12 1 +time 13 1 - Use settimeofday +mknod +14 3 +chmod +15 2 +chown +16 3 +brk +17 1 * This is only to tell the system +stat +18 2 +lseek +19 3 * nb 2nd arg is an io ptr to long not a long. +getpid +20 1 * this gets both pid & ppid +mount +21 5 +umount +22 1 +setuid +23 1 +getuid +24 1 * this gets both uid and euid +stime 25 2 - this must not exist - even as a libc. +ptrace 26 4 @ adb/sdb/dbx need this. +alarm 27 2 +fstat +28 2 +pause 29 0 +utime 30 2 +chroot +31 1 +vfork 32 0 +access +33 2 +nice 34 1 +sleep 35 1 +sync +36 0 +kill 37 2 +rename +38 2 +mkdir +39 2 +rmdir +40 1 +dup +41 1 . There is a fcntl lib function too. +pipe 42 1 +times 43 2 * 2nd arg is pointer for long ret val. +profil 44 4 @ +dup2 +45 2 +setgid +46 1 +getgid 47 1 * this gets both gid and egid +signal 48 2 * have put the despatch table in user space. +getinfo 49 1 @ possible? gets pid,ppid,uid,euid etc +fcntl +50 3 +acct 51 1 @ Accounting to named file (off if null) +phys 52 3 - Replaced my mmap() +lock 53 1 @ Prevent swapping for this proc if flg!=0 +ioctl +54 3 . make this and fcntl the same ? +reboot +55 3 . the magic number is 0xfee1,0xdead,... +mpx 56 2 - Replaced by fifos and select. +lstat +57 2 +symlink +58 2 +readlink +59 3 +umask +60 1 +settimeofday 61 2 +gettimeofday 62 2 +select 63 5 * +readdir +64 3 * + +# +# Name No Args Flag&comment +# +# ( awk '{$2=NR+500;OFS="\t";print ;}'| expand -24,32,40 | unexpand ) <28 long !0 not stripped -0 string \01\03\040\04 Linux-8086 executable +# Linux 8086 executable +0 lelong&0xFF0000FF 0xC30000E9 Linux-8086 executable, headerless +>5 string . +>>4 string >\0 \b, libc version %s + +0 lelong&0xFF00FFFF 0x04000301 Linux-8086 executable +>2 byte&0x01 !0 \b, unmapped zero page +>2 byte&0x20 0 \b, impure +>2 byte&0x20 !0 +>>2 byte&0x10 !0 \b, A_EXEC +>2 byte&0x02 !0 \b, A_PAL +>2 byte&0x04 !0 \b, A_NSYM +>2 byte&0x08 !0 \b, A_STAND +>2 byte&0x40 !0 \b, A_PURE +>2 byte&0x80 !0 \b, A_TOVLY +>28 long !0 \b, not stripped +>37 string . +>>36 string >\0 \b, libc version %s + +# Other ld86 executable formats ... +0 lelong 0x10200301 Minix-386 executable >28 long !0 not stripped -# -0 string \243\206\001\0 Linux-8086 object file -# There is _no_ difference between 16 and 32 bit .o files that file can see. -# -0 string \01\03\020\20 Minix-386 impure executable + +0 lelong 0x10100301 Minix-386 impure executable >28 long !0 not stripped -0 string \01\03\040\20 Minix-386 executable + +0 lelong&0xFF00FFFF 0x10000301 ld86 I80386 executable >28 long !0 not stripped -# -#------------------------------------------------------------------------------ + +# Never seen formats. +# 0 belong&0xFFFF00FF 0x0103000B ld86 M68K executable +# 0 belong&0xFFFF00FF 0x0103000C ld86 NS16K executable +# 0 belong&0xFFFF00FF 0x01030017 ld86 SPARC executable + +# AS86/LD86 object files. +# There is _no_ difference between 16 and 32 bit .o files that file can see. +0 string \243\206\001\0 Linux-8086 object file diff -Nurd linux86.vold/Makefile linux86/Makefile --- linux86.vold/Makefile 2001-05-12 08:03:01.000000000 +0100 +++ linux86/Makefile 2004-06-20 18:57:52.000000000 +0100 @@ -2,26 +2,30 @@ # This file is part of the Linux-8086 Development environment and is # distributed under the GNU General Public License. -TARGETS= \ - clean bcc unproto copt as86 ld86 elksemu \ - install install-all install-bcc install-emu install-lib \ +VERSION=0.16.17 + +TARGETS=install clean other \ + bcc86 unproto copt as86 ld86 elksemu \ + install-all install-bcc install-emu install-lib \ install-lib2 install-ln install-man install-other \ all-libs alt-libs library lib-386 lib-bsd lib-dos lib-fast lib-stand \ - config other tests dis88 doselks bootblocks ld86r + config tests dis88 doselks bootblocks ld86r ELKSSRC= /usr/src/elks PREFIX= /usr -LIBPRE= $(PREFIX)/bcc BINDIR= $(PREFIX)/bin -LIBDIR= $(LIBPRE)/lib/bcc +LIBDIR= $(PREFIX)/lib/bcc +INCLDIR= $(PREFIX)/lib/bcc +ASLDDIR= $(BINDIR) +MANDIR= $(PREFIX)/man CFLAGS= -O # Some makes take the last of a list as the default ... all: make.fil - PATH="`pwd`/bin:$$PATH" $(MAKE) -f make.fil TOPDIR=`pwd` $@ + PATH="`pwd`/bin:$$PATH" $(MAKE) -f make.fil VERSION=$(VERSION) TOPDIR=`pwd` $@ $(TARGETS): make.fil - PATH="`pwd`/bin:$$PATH" $(MAKE) -f make.fil TOPDIR=`pwd` $@ + PATH="`pwd`/bin:$$PATH" $(MAKE) -f make.fil VERSION=$(VERSION) TOPDIR=`pwd` $@ $(TARGETS): @@ -29,46 +33,41 @@ as: as86 realclean: - -[ ! -f make.fil ] || $(MAKE) -f make.fil TOPDIR=`pwd` $@ + -[ ! -f make.fil ] || $(MAKE) -f make.fil VERSION=$(VERSION) TOPDIR=`pwd` $@ -rm -f make.fil ifdef ifdef.o make.fil: ifdef makefile.in ./ifdef -MU makefile.in >tmp.mak - sed \ - -e "s:%PREFIX%:$(PREFIX):" \ - -e "s:%LIBPRE%:$(LIBPRE):" \ - -e "s:%BINDIR%:$(BINDIR):" \ - -e "s:%LIBDIR%:$(LIBDIR):" \ - -e "s:%ELKSSRC%:$(ELKSSRC):" \ - -e "s:%CC%:$(CC):" \ - -e "s:%CFLAGS%:$(CFLAGS):" \ - -e "s:%LDFLAGS%:$(LDFLAGS):" \ - < tmp.mak > make.tmp + echo > tmp.sed + [ "$(BINDIR)" != "//bin" ] || echo >> tmp.sed "s:%BINDIR%:/bin:" + [ "$(LIBDIR)" != "//lib/bcc" ] || echo >> tmp.sed "s:%LIBDIR%:/lib:" + [ "$(INCLDIR)" != "//lib/bcc" ] || echo >> tmp.sed "s:%INCLDIR%:/usr:" + [ "$(ASLDDIR)" != "//bin" ] || echo >> tmp.sed "s:%ASLDDIR%:/bin:" + [ "$(MANDIR)" != "//man" ] || echo >> tmp.sed "s:%MANDIR%:/usr/man:" + echo >> tmp.sed "s:%PREFIX%:$(PREFIX):" + echo >> tmp.sed "s:%BINDIR%:$(BINDIR):" + echo >> tmp.sed "s:%INCLDIR%:$(INCLDIR):" + echo >> tmp.sed "s:%LIBDIR%:$(LIBDIR):" + echo >> tmp.sed "s:%ASLDDIR%:$(ASLDDIR):" + echo >> tmp.sed "s:%MANDIR%:$(MANDIR):" + echo >> tmp.sed "s:%ELKSSRC%:$(ELKSSRC):" + echo >> tmp.sed "s:%CC%:$(CC):" + echo >> tmp.sed "s:%CFLAGS%:$(CFLAGS):" + echo >> tmp.sed "s:%LDFLAGS%:$(LDFLAGS):" + sed -f tmp.sed < tmp.mak > make.tmp mv -f make.tmp make.fil - @rm -f tmp.mak + @rm -f tmp.mak tmp.sed ifdef: ifdef.o - $(CC) $(LDFLAGS) -o ifdef ifdef.o + $(CC) $(IFDEFARCH) $(LDFLAGS) -o ifdef ifdef.o ifdef.o: ifdef.c - $(CC) $(CFLAGS) $(IFDEFFLAGS) -c ifdef.c + $(CC) $(IFDEFARCH) $(CFLAGS) $(IFDEFFLAGS) -c ifdef.c -Uninstall: - @# CHECK FROM HERE - @make -n Uninstall - @echo 'Are you really sure... have you checked this... ^C to interrupt' - @read line - rm -rf /usr/bcc - rm -f $(BINDIR)/bcc $(BINDIR)/as86_encap $(BINDIR)/dis86 - rm -f $(BINDIR)/as86 $(BINDIR)/ld86 - rm -f $(BINDIR)/objdump86 $(BINDIR)/nm86 $(BINDIR)/size86 - rm -f /lib/elksemu - rm -f /usr/lib/liberror.txt - rm -f /usr/man/man1/elks.1* /usr/man/man1/elksemu.1* - rm -f /usr/man/man1/dis86.1* /usr/man/man1/bcc.1* - rm -f /usr/man/man1/as86.1* /usr/man/man1/ld86.1* - @# TO HERE +uninstall: + @echo 'Sorry, no go; it was just wrong.' + false distribution: - @[ `id -u` -eq 0 ] || fakeroot -- sh ./Mk_dist - @[ `id -u` -ne 0 ] || sh ./Mk_dist + @[ `id -u` -eq 0 ] || fakeroot -- sh ./Mk_dist $(VERSION) + @[ `id -u` -ne 0 ] || sh ./Mk_dist $(VERSION) diff -Nurd linux86.vold/makefile.in linux86/makefile.in --- linux86.vold/makefile.in 2001-01-06 14:20:47.000000000 +0000 +++ linux86/makefile.in 2004-10-02 14:00:53.000000000 +0100 @@ -16,30 +16,33 @@ CC =%CC% CFLAGS =%CFLAGS% LDFLAGS = -MAKEARG =CC='$(CC)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' PREFIX=$(PREFIX) \ - LIBPRE='$(LIBPRE)' LIBDIR='$(LIBDIR)' BINDIR='$(BINDIR)' ANSI='$(ANSI)' +MAKEARG =CC='$(CC)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' \ + PREFIX=$(PREFIX) LIBDIR='$(LIBDIR)' \ + BINDIR='$(BINDIR)' ANSI='$(ANSI)' MAKEC=$(MAKE) -C MAKEX= # This is only allowed on Linux because make needs to know how to look # inside an archive to get the last modified times of the component .o -# files. This should be fine for Linux, but it won't be for AIX. +# files. This should be fine for Linux, but it won't be for AIX etc. +# Unfortunatly it's even _required_ for linux because some versions +# have a broken standard ar command. Ie they barf if given something +# they think is not an a.out. #ifdef __linux__ AR=ar86 #endif #ifdef __GNUC__ -# unproto is yukky, I've included '-w' in the local makefile. -WALL =-Wtraditional -Wshadow -Wid-clash-14 -Wpointer-arith \ +WALL =-Wall -Wtraditional -Wshadow -Wid-clash-14 -Wpointer-arith \ -Wcast-qual -Wcast-align -Wconversion -Waggregate-return \ -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls \ -Wnested-externs -Winline -WALL =-Wstrict-prototypes +WALL =-Wall -Wstrict-prototypes -CC =gcc -CFLAGS =$(GCCFLAG) -Wall $(WALL) -O6 -g +CC =%CC% +CFLAGS =$(GCCFLAG) $(WALL) -O2 -g #endif #ifndef GNUMAKE @@ -57,51 +60,68 @@ #ifdef __BCC__ ANSI =-ansi #ifdef __AS386_32__ -CFLAGS =-3 -LDFLAGS =-3 -s -N +CFLAGS =-Ml +LDFLAGS =-Ml -s #else -CFLAGS =-0 -LDFLAGS =-0 -s -H10000 -BCCARCH =-Mf -O +CFLAGS =-O +LDFLAGS =-s -H10000 +BCCARCH = #endif #endif -# Alter these if for some reason you don't want this done as root. -#ifdef __BCC__ -INDAT=-o root -g root -m 644 -INEXE=-o root -g root -m 755 -INSCR=-o root -g root -m 755 +# Apple cpp-precomp 6.14 (devkit-213/devkit_tools-214) cannot +# handle the QUOT macro in bcc. It puts a space in /usr so that +# it becomes / usr +#ifdef __APPLE__ +CFLAGS += -no-cpp-precomp +#endif + +# Install files with the userid of the currently running process. +INDAT=-m 644 +INEXE=-m 755 -s +INSCR=-m 755 + +#ifdef __CYGWIN__ +EXE=.exe #else -INDAT=-o root -g root -m 644 -INEXE=-o root -g root -m 755 -s -INSCR=-o root -g root -m 755 +EXE= #endif #ifdef GNUMAKE -all: check_config bcc unproto copt as86 ar86 ld86 objdump86 \ +all: check_config bcc86 cpp unproto copt as86 ar86 ld86 objdump86 \ library lib-bsd alt-libs elksemu + +install: check_config install-bcc install-man \ + install-lib install-emu + +install-all: install install-other + #else -all: check_config bcc unproto copt as86 ar86 ld86 objdump86 +all: check_config bcc86 cpp unproto copt as86 ar86 ld86 objdump86 @echo @echo 'NOTE: To build the libraries you need GNU-Make.' @echo ' They are available precompiled in the Dev86clb-X.X.X.zip file.' -#endif -install: check_config install-bcc install-man \ - install-lib install-lib2 install-emu +install install-all: check_config install-bcc install-man + @echo + @echo 'NOTE: To build the libraries you need GNU-Make.' + @echo ' They are available precompiled in the Dev86clb-X.X.X.zip file.' -install-all: install install-other +#endif ############################################################################## -LIBARGS= CC=ncc CCFLAGS= AR=$(AR) ARFLAGS=$(ARFLAGS) +LIBARGS= CC=ncc "CCFLAGS=-O" AR=$(AR) ARFLAGS=$(ARFLAGS) +LIB3ARGS= CC=ncc AR=$(AR) ARFLAGS=$(ARFLAGS) # Season in the top makefile ELKSSRC= %ELKSSRC% PREFIX= %PREFIX% -LIBPRE= %LIBPRE% BINDIR= %BINDIR% LIBDIR= %LIBDIR% +INCLDIR= %INCLDIR% +ASLDDIR= %ASLDDIR% +MANDIR= %MANDIR% #ifdef GNUMAKE export ELKSSRC @@ -109,12 +129,13 @@ DISTBIN= $(DIST)$(BINDIR) DISTLIB= $(DIST)$(LIBDIR) -DISTPRE= $(DIST)$(LIBPRE) +DISTASLD=$(DIST)$(ASLDDIR) +DISTINCL=$(DIST)$(INCLDIR) # Others to install OTHERS= tests dis88 doselks bootblocks -CLEANLIST= bcc as ar ld unproto copt libc elksemu libbsd $(OTHERS) +CLEANLIST= bcc as ar ld cpp unproto copt libc elksemu libbsd $(OTHERS) ############################################################################## @@ -128,109 +149,105 @@ @ln -s ../kinclude/arch include/arch 2>/dev/null || true #endif -bcc: bindir +bcc86: bindir + echo '#define VERSION "'"$(VERSION)"'"' > bcc/version.h + VER=$(VERSION) ; \ + echo "#define VER_MAJ $${VER%%.*}" >> bcc/version.h ; \ + VER="$${VER#*.}" ; \ + echo "#define VER_MIN $${VER%.*}" >> bcc/version.h ; \ + echo "#define VER_PAT $${VER#*.}" >> bcc/version.h $(MAKEC) bcc $(MAKEARG) BCCARCH='$(BCCARCH)' bcc ncc bcc-cc1 - cp -p bcc/bcc bin/Bcc - cp -p bcc/ncc bin/ncc - cp -p bcc/bcc-cc1 lib/bcc-cc1 + cp -p bcc/bcc$(EXE) bin/Bcc$(EXE) + cp -p bcc/ncc$(EXE) bin/ncc$(EXE) + cp -p bcc/bcc-cc1$(EXE) lib/bcc-cc1$(EXE) + +cpp: bindir + $(MAKEC) cpp $(MAKEARG) bcc-cpp + cp -p cpp/bcc-cpp$(EXE) lib/bcc-cpp$(EXE) unproto: bindir $(MAKEC) unproto $(MAKEARG) unproto - cp -p unproto/unproto lib/unproto + cp -p unproto/unproto$(EXE) lib/unproto$(EXE) copt: bindir $(MAKEC) copt $(MAKEARG) copt - cp -p copt/copt lib/copt + cp -p copt/copt$(EXE) lib/copt$(EXE) cp -p copt/rules.* lib/. + cp -p copt/rules.start lib/i386/. + cp -p copt/rules.386 lib/i386/. + cp -p copt/rules.end lib/i386/. as86: bindir + echo '#define VERSION "'"$(VERSION)"'"' > as/version.h $(MAKEC) as $(MAKEARG) all - cp -p as/as86 bin/as86 + cp -p as/as86$(EXE) bin/as86$(EXE) cp -p as/as86_encap bin/as86_encap ar86: bindir $(MAKEC) ar $(MAKEARG) all - cp -p ar/ar86 bin/ar86 + cp -p ar/ar86$(EXE) bin/ar86$(EXE) ld86: bindir + echo '#define VERSION "'"$(VERSION)"'"' > ld/version.h $(MAKEC) ld $(MAKEARG) ld86 - cp -p ld/ld86 bin/ld86 + cp -p ld/ld86$(EXE) bin/ld86$(EXE) ld86r: bindir $(MAKEC) ld $(MAKEARG) ld86r - cp -p ld/ld86r bin/ld86r + cp -p ld/ld86r$(EXE) bin/ld86r$(EXE) objdump86: bindir $(MAKEC) ld $(MAKEARG) objdump86 - cp -p ld/objdump86 bin/objdump86 + cp -p ld/objdump86$(EXE) bin/objdump86$(EXE) -elksemu: bindir #ifndef __AS386_16__ -#ifdef __linux_i386__ - $(MAKEC) elksemu \ - CC='$(CC)' PREFIX=$(PREFIX) LIBPRE='$(LIBPRE)' LIBDIR='$(LIBDIR)' BINDIR='$(BINDIR)' \ - elksemu +#ifdef __elksemu_works__ +elksemu: bindir + $(MAKEC) elksemu elksemu + cp -p elksemu/elksemu bin/elksemu #else +elksemu: bindir $(MAKEC) elksemu CC='ncc' elksemu -#endif cp -p elksemu/elksemu bin/elksemu #endif - -install-ln: bcc unproto copt as86 ar86 ld86 elksemu - install -d $(DISTBIN) - ln -fs `pwd`/bin/ncc $(DISTBIN)/bcc - ln -fs `pwd`/bin/as86_encap $(DISTBIN)/as86_encap - ln -fs `pwd`/bin/as86 $(DISTBIN)/as86 - ln -fs `pwd`/bin/ar86 $(DISTBIN)/ar86 - ln -fs `pwd`/bin/ld86 $(DISTBIN)/ld86 -#ifndef __AS386_16__ - ln -fs `pwd`/bin/elksemu $(DIST)/lib/elksemu #endif - -install -d $(DIST)/usr/lib - -install $(INDAT) libc/error/liberror.txt $(DIST)/usr/lib/liberror.txt -install-bcc: bcc unproto copt as86 ar86 ld86 objdump86 - install -d $(DISTBIN) $(DISTLIB) $(DISTLIB)/i86 - install $(INEXE) bin/Bcc $(DISTBIN)/bcc - install $(INSCR) bin/as86_encap $(DISTBIN)/as86_encap - install $(INEXE) bin/as86 $(DISTBIN)/as86 - install $(INEXE) bin/ar86 $(DISTBIN)/ar86 - install $(INEXE) bin/ld86 $(DISTBIN)/ld86 - install $(INEXE) bin/objdump86 $(DISTBIN)/objdump86 - install $(INEXE) bin/objdump86 $(DISTBIN)/nm86 - install $(INEXE) bin/objdump86 $(DISTBIN)/size86 - install $(INEXE) lib/bcc-cc1 $(DISTLIB)/bcc-cc1 - install $(INEXE) lib/unproto $(DISTLIB)/unproto - install $(INEXE) lib/copt $(DISTLIB)/copt - install $(INDAT) lib/rules.* $(DISTLIB)/i86 - @test ! -f $(DISTLIB)/as86 || rm -f $(DISTLIB)/as86 - @test ! -f $(DISTLIB)/ld86 || rm -f $(DISTLIB)/ld86 +install-bcc: bcc86 cpp unproto copt as86 ar86 ld86 objdump86 + install -d $(DISTBIN) $(DISTLIB) + install $(INEXE) bin/Bcc$(EXE) $(DISTBIN)/bcc$(EXE) + install $(INEXE) bin/as86$(EXE) $(DISTASLD)/as86$(EXE) + install $(INEXE) bin/ld86$(EXE) $(DISTASLD)/ld86$(EXE) + install $(INEXE) bin/ar86$(EXE) $(DISTBIN)/ar86$(EXE) + install $(INEXE) bin/objdump86$(EXE) $(DISTBIN)/objdump86$(EXE) + install $(INEXE) bin/objdump86$(EXE) $(DISTBIN)/nm86$(EXE) + install $(INEXE) bin/objdump86$(EXE) $(DISTBIN)/size86$(EXE) + install $(INSCR) bin/as86_encap $(DISTLIB)/as86_encap + install $(INEXE) lib/bcc-cc1$(EXE) $(DISTLIB)/bcc-cc1$(EXE) + install $(INEXE) lib/bcc-cpp$(EXE) $(DISTLIB)/bcc-cpp$(EXE) + install $(INEXE) lib/unproto$(EXE) $(DISTLIB)/unproto$(EXE) + install $(INEXE) lib/copt$(EXE) $(DISTLIB)/copt$(EXE) + install $(INDAT) lib/rules.* $(DISTLIB) + install -d $(DISTLIB)/i386 + install $(INDAT) lib/i386/rules.* $(DISTLIB)/i386 # NB: This doesn't install as a suid root, that's ok though. install-emu: elksemu -#ifndef __AS386_16__ - install -d $(DIST)/lib - install $(INEXE) bin/elksemu $(DIST)/lib/elksemu +#ifdef __elksemu_works__ + install -d $(DISTBIN) + install $(INEXE) bin/elksemu $(DISTBIN)/elksemu #endif install-man: - -$(MAKEC) man MANDIR=$(DIST)$(PREFIX)/man install - -install-lib: lib/lib0-done lib/lib2-done - install -d $(DISTLIB)/i86 - $(MAKEC) libc $(LIBARGS) BCCHOME=$(DISTPRE) install_incl - install $(INDAT) lib/crt0.o $(DISTLIB)/i86/crt0.o - install $(INDAT) lib/libc.a $(DISTLIB)/i86/libc.a - install $(INDAT) lib/libbsd.a $(DISTLIB)/i86/libbsd.a - -install -d $(DIST)/usr/lib - -install $(INDAT) libc/error/liberror.txt $(DIST)/usr/lib/liberror.txt - -install-lib2: lib/lib1-done - install -d $(DISTLIB)/i86 - install $(INDAT) lib/libc_f.a $(DISTLIB)/i86/libc_f.a - install $(INDAT) lib/libc_s.a $(DISTLIB)/i86/libc_s.a - install $(INDAT) lib/libdos.a $(DISTLIB)/i86/libdos.a + -$(MAKEC) man MANDIR=$(DIST)$(MANDIR) install +install-lib: lib/lib0-done lib/lib2-done lib/lib1-done + $(MAKEC) libc $(LIBARGS) DISTINCL=$(DISTINCL) install_incl + install $(INDAT) lib/crt0.o $(DISTLIB)/crt0.o + install $(INDAT) lib/libc.a $(DISTLIB)/libc.a + install $(INDAT) lib/libc_f.a $(DISTLIB)/libc_f.a + install $(INDAT) lib/libc_s.a $(DISTLIB)/libc_s.a + install $(INDAT) lib/libbsd.a $(DISTLIB)/libbsd.a + install $(INDAT) lib/libdos.a $(DISTLIB)/libdos.a #ifndef __AS386_16__ install -d $(DISTLIB)/i386 install $(INDAT) lib/i386/crt0.o $(DISTLIB)/i386/crt0.o @@ -265,10 +282,11 @@ #ifdef __AS386_16__ alt-libs: lib-stand lib-dos lib-fast + @touch lib/lib1-done #else alt-libs: lib-stand lib-dos lib-386 lib-fast -#endif @touch lib/lib1-done +#endif lib-fast: bindir test -f bin/ncc @@ -288,14 +306,12 @@ cp -p libc/libdos.a lib/libdos.a sh libcompat lib/libdos.a -#ifndef __AS386_16__ lib-386: bindir test -f bin/ncc - $(MAKEC) libc $(LIBARGS) PLATFORM=i386-BCC + $(MAKEC) libc $(LIB3ARGS) PLATFORM=i386-BCC cp -p libc/crt3.o lib/i386/crt0.o cp -p libc/libc3.a lib/i386/libc.a sh libcompat lib/i386/libc.a -#endif ############################################################################## @@ -319,15 +335,18 @@ ############################################################################## -install-other: +install-other: other @for i in $(OTHERS) ; do \ $(MAKEC) $$i BCC=ncc DIST=$(DIST) PREFIX=$(PREFIX) install || exit 1 ; \ done -other: $(OTHERS) +other: + echo '#define VERSION "'"$(VERSION)"'"' > bootblocks/version.h + @for i in $(OTHERS) ; do \ + $(MAKEC) $$i BCC=ncc DIST=$(DIST) PREFIX=$(PREFIX) || exit 1; \ + done -$(OTHERS): - $(MAKEC) $@ BCC=ncc +############################################################################## clean: -@for i in $(CLEANLIST) ; do $(MAKEC) $$i $@ ; true ; done @@ -338,5 +357,9 @@ rm -f include rm -f makec rm -f `find $(CLEANLIST) -type l -print` + rm -f bcc/version.h + rm -f as/version.h + rm -f ld/version.h + rm -f bootblocks/version.h ############################################################################## diff -Nurd linux86.vold/man/as86.1 linux86/man/as86.1 --- linux86.vold/man/as86.1 2000-09-26 21:18:31.000000000 +0100 +++ linux86/man/as86.1 2003-12-10 10:23:54.000000000 +0000 @@ -16,7 +16,7 @@ .B as86_encap\ prog.s\ prog.v .RB [ prefix_ ] -.RB [ as86\ options ] +.RB [ as86_options ] .SH DESCRIPTION .B as86 @@ -395,13 +395,13 @@ LFS LGDT LGS LIDT LLDT LMSW LOCK LODB LODS LODSB LODSD LODSW LODW LOOP LOOPE LOOPNE LOOPNZ LOOPZ LSL LSS LTR MOV MOVS MOVSB MOVSD MOVSW MOVSX MOVW MOVZX MUL NEG NOP NOT OR OUT OUTS OUTSB OUTSD OUTSW OUTW POP POPA -POPAD POPF POPFD PUSH PUSHA PUSHAD PUSHF PUSHFD RCL RCR REP REPE REPNE +POPAD POPF POPFD PUSH PUSHA PUSHAD PUSHF PUSHFD RCL RCR RDMSR REP REPE REPNE REPNZ REPZ RET RETF RETI ROL ROR SAHF SAL SAR SBB SCAB SCAS SCASB SCASD SCASW SCAW SEG SETA SETAE SETB SETBE SETC SETE SETG SETGE SETL SETLE SETNA SETNAE SETNB SETNBE SETNC SETNE SETNG SETNGE SETNL SETNLE SETNO SETNP SETNS SETNZ SETO SETP SETPE SETPO SETS SETZ SGDT SHL SHLD SHR SHRD SIDT SLDT SMSW STC STD STI STOB STOS STOSB STOSD STOSW STOW STR SUB TEST -VERR VERW WAIT WBINVD XADD XCHG XLAT XLATB XOR +VERR VERW WAIT WBINVD WRMSR XADD XCHG XLAT XLATB XOR .TP Floating point F2XM1 FABS FADD FADDP FBLD FBSTP FCHS FCLEX FCOM FCOMP FCOMPP FCOS diff -Nurd linux86.vold/man/bcc.1 linux86/man/bcc.1 --- linux86.vold/man/bcc.1 1999-03-16 07:10:02.000000000 +0000 +++ linux86/man/bcc.1 2004-06-20 23:47:36.000000000 +0100 @@ -14,6 +14,7 @@ .RB [ -o\ outfile ] .RB [ -ansi ] .RB [ -Ccc1_option ] +.RB [ -Pcpp_option ] .RB [ -Iinclude_dir ] .RB [ -Lld_option ] .RB [ -Ttmpdir ] @@ -71,7 +72,7 @@ produce preprocessor output to standard out. .TP .B -G -produce GCC objects (only useful for i386 code) +produce GCC objects (Same as -Mg) .TP .B -Ixyz include search 'xyz' path @@ -88,7 +89,7 @@ .B -Md alters the arguments for all passes to produce MSDOS executable COM files. These are small model executables, use -.B -i- +.B -i to get tiny model. .TP .B -Mf @@ -116,6 +117,11 @@ .B -z flag to generate QMAGIC a.out files instead of the normal OMAGIC. .TP +.B -Mg +switches to i386-Linux code generator and generates OMAGIC object files +that can be linked with some versions of gcc; unfortunatly the most recent +versions use 'collect2' to link and this crashes. +.TP .B -N makes the linker produce a native a.out file (Linux OMAGIC) if combined with -3 the executable will run under Linux-i386. @@ -155,21 +161,18 @@ .B -c produce object file .TP -.B -e -run the preprocess pass separately. This takes less memory, and may help -or harm by giving more traditional semantics like token pasting with /**/. -.TP .B -f -error (float emulation not supported) +turn on floating point support, no effect with i386, changes libc library +with 8086 code. .TP .B -g -produce debugging info (does nothing) +produce debugging info (ignored.) .TP .B -o output file name follows (assembler, object or executable) (as usual) .TP .B -p -error (profiling not supported) +produce profiling info (ignored.) .TP .B -t1 pass to the assembler to renumber the text segment for multi-segment programs. @@ -189,21 +192,20 @@ .TP .B -x don't include crt0.o in the link. +.TP +.B -i +don't pass +.B -i +to the linker so that it will create an impure executable. .P -Other options are passed to the linker, in particular -i-, -lx, -M, -m, -s, -H. -The -i option is always passed to the linker but can be cancelled using -i-. +Other options are passed to the linker, in particular -lx, -M, -m, -s, -H. .SH CODE GENERATOR OPTIONS These are all options that the code generator pass .B bcc-cc1 understands, only some will be useful for the .B -C -option of bcc. The code generator is normally used as a combined C preprocessor -and generator but the -.B -e -and -.B -ansi -options of bcc split the operation. +option of bcc. .TP .B -0 8086 target (works even on 80386 host, not on 6809) diff -Nurd linux86.vold/man/elksemu.1 linux86/man/elksemu.1 --- linux86.vold/man/elksemu.1 1999-08-12 11:59:53.000000000 +0100 +++ linux86/man/elksemu.1 2004-01-19 22:56:56.000000000 +0000 @@ -16,11 +16,11 @@ .B bcc(1) C compiler. -It is not usual to invoke -.I /lib/elksemu -directly, either the simple patch or kernel module distributed with it -will cause the kernel to run -.I /lib/elksemu +Yom may use the +.I binfmt-misc +module under Linux 2.1.43 or greater as described in the elksemu README +which will cause the kernel to run +.I elksemu with the correct arguments whenever the user tries to execute an ELKS executable directly. @@ -28,14 +28,17 @@ There are no flag options to elksemu, the first argument is the name of the program to run the rest are arguments that are passed to the Elks program. +.SH SECURITY The .B elksemu -program is normally installed suid-root and in this event it is able to +program may be installed suid-root and in this event it is able to run execute only (chmod 111) elks executables and act correctly on the -suid permission bits on those executable. This may be considered a -security hazard so elksemu does +suid permission bits on any executable. +This should be considered a security hazard so elksemu does .I not -have to be installed suid-root. +have to be installed suid-root. +If you consider using this facility you should also be aware that it will +override the 'nosuid' mount(8) option. .SH SEE ALSO bcc(1), as86(1), ld86(1) diff -Nurd linux86.vold/man/ld86.1 linux86/man/ld86.1 --- linux86.vold/man/ld86.1 1999-04-13 09:47:43.000000000 +0100 +++ linux86/man/ld86.1 2002-02-19 08:00:06.000000000 +0000 @@ -64,7 +64,7 @@ option is also included the linker can generate a QMAGIC executable. .TP .B -Ox -add library libdir-from-search/x to list of files linked +add library or object file libdir-from-search/x to list of files linked .TP .B -T text base address follows (in format suitable for strtoul) diff -Nurd linux86.vold/mkcompile linux86/mkcompile --- linux86.vold/mkcompile 1997-03-23 10:52:29.000000000 +0000 +++ linux86/mkcompile 2002-12-05 00:54:49.000000000 +0000 @@ -1,41 +1,42 @@ #!/bin/sh SRC_BCC='bcc.c' +SRC_CPP='main.c cpp.c hash.c token1.c token2.c' +SRC_UPR='unproto.c error.c hash.c strsave.c symbol.c tok_clas.c tok_io.c + tok_pool.c unproto.c vstring.c' SRC_CC1='bcc-cc1.c assign.c codefrag.c debug.c declare.c express.c exptree.c floatop.c function.c gencode.c genloads.c glogcode.c hardop.c input.c label.c loadexp.c longop.c output.c preproc.c preserve.c scan.c softop.c state.c table.c type.c' -SRC_AS=' as.c assemble.c error.c express.c genbin.c genlist.c genobj.c gensym.c - keywords.c macro.c mops.c pops.c readsrc.c scan.c table.c typeconv.c' +SRC_AS=' alloc.c as.c assemble.c errors.c express.c genbin.c genlist.c genobj.c + gensym.c keywords.c macro.c mops.c pops.c readsrc.c scan.c table.c + typeconv.c' SRC_LD=' ld.c dumps.c io.c linksyms.c readobj.c table.c typeconv.c writebin.c writex86.c' -HDR_BCC='' -HDR_CC1='align.h byteord.h condcode.h const.h gencode.h input.h label.h os.h - output.h parse.h proto.h reg.h sc.h scan.h sizes.h table.h type.h - types.h' -HDR_AS=' address.h byteord.h const.h file.h flag.h globvar.h macro.h opcode.h - proto.h scan.h source.h syshead.h type.h' -HDR_LD=' align.h ar.h bindef.h byteord.h config.h const.h globvar.h obj.h - syshead.h type.h x86_aout.h' +SRC_UP=' unproto.c tok_io.c tok_class.c tok_pool.c vstring.c symbol.c error.c + hash.c strsave.c' main() { echo '@echo off' - echo -n 'if not exist later.exe ' - echo 'cl -nologo -O later.c %LIB%\setargv.obj -link /NOE' - echo CFLAGS='-nologo -O' LDFLAGS='%LIB%\setargv.obj -link /NOE' ARCH=-Ms - build bcc bcc bin "$HDR_BCC" $SRC_BCC + build bcc bcc bin $SRC_BCC CFLAGS='-nologo -O -DPOSIX_HEADERS_MISSING' LDFLAGS= ARCH=-Ml - build bcc bcc-cc1 lib "$HDR_CC1" $SRC_CC1 - build as as86 bin "$HDR_AS" $SRC_AS - build ld ld86 bin "$HDR_LD" $SRC_LD + + build cpp bcc-cpp lib $SRC_CPP + build bcc bcc-cc1 lib $SRC_CC1 + build as as86 bin $SRC_AS + build ld ld86 bin $SRC_LD + + build unproto unproto lib $SRC_UPR + + echo "echo Compile complete." echo ":exit_now" } @@ -43,7 +44,6 @@ DIR="$1" ; shift PRG="$1" ; shift BIN="$1" ; shift - HDR="$1" ; shift OBJ= BOBJ= COBJ= @@ -53,51 +53,35 @@ for i in $SRC do j=`basename $i .c` - check_time $DIR/$j.obj $i $HDR - echo -n "if errorlevel 1 " - echo "cl $ARCH $CFLAGS -c -Fo$DIR\\$j.obj $DIR\\$i" + echo "cl $ARCH $CFLAGS -c -Fo%TMP%\\$j.obj $DIR\\$i" if [ "$BOBJ" = "" ] - then BOBJ="$DIR\\$j.obj" - else LOBJ="$LOBJ +$DIR\\$j.obj" + then BOBJ="%TMP%\\$j.obj" + else LOBJ="$LOBJ +%TMP%\\$j.obj" fi - COBJ="$COBJ $DIR\\$j.obj" + COBJ="$COBJ %TMP%\\$j.obj" OBJ="$OBJ $j.obj" echo "if errorlevel 1 goto exit_now" done + echo if [ `echo $COBJ | wc -c` -lt 50 ] then - check_time $BIN/$PRG.exe $OBJ - echo -n "if errorlevel 1 " echo "cl $ARCH -o $BIN\\$PRG.exe$COBJ $LDFLAGS" echo "if errorlevel 1 goto exit_now" else - check_time $BIN/$PRG.exe $OBJ - echo "if not errorlevel 1 goto done_$PRG" - echo "if exist doslib.lib del doslib.lib" + echo "if exist %TMP%\\doslib.lib del %TMP%\\doslib.lib" echo $LOBJ | fmt -62 | \ - sed 's/\(.*\)/lib doslib.lib \1; >NUL/' - echo "cl $ARCH -o $BIN\\$PRG.exe $BOBJ doslib.lib $LDFLAGS" + sed "s/\(.*\)/lib %TMP%\\\\doslib.lib \1; /" | + sed 's/$/@if errorlevel 1 goto exit_now/' | + tr '@' '\012' + echo + echo "cl $ARCH -o $BIN\\$PRG.exe $BOBJ %TMP%\\doslib.lib $LDFLAGS" echo "if errorlevel 1 goto exit_now" - echo "if exist doslib.lib del doslib.lib" - echo "if exist doslib.bak del doslib.bak" - echo ":done_$PRG" fi echo } -check_time() { - TARG="$1" ; shift - - for i - do echo "$DIR/$i" - done | fmt -70 | \ - sed -e "s;\(.*\);later $TARG \1@if errorlevel 3 goto exit_now;" \ - -e '2,$s/^/if not errorlevel 1 /' | \ - tr '@' '\012' -} - main "$@" | sed 's/$/ /' > compile.bat diff -Nurd linux86.vold/mkcompile2 linux86/mkcompile2 --- linux86.vold/mkcompile2 1997-03-23 10:52:34.000000000 +0000 +++ linux86/mkcompile2 1970-01-01 01:00:00.000000000 +0100 @@ -1,103 +0,0 @@ -#!/bin/sh - -SRC_BCC='bcc.c' -SRC_CC1='bcc-cc1.c assign.c codefrag.c debug.c declare.c express.c exptree.c - floatop.c function.c gencode.c genloads.c glogcode.c hardop.c input.c - label.c loadexp.c longop.c output.c preproc.c preserve.c scan.c - softop.c state.c table.c type.c' -SRC_AS=' as.c assemble.c error.c express.c genbin.c genlist.c genobj.c gensym.c - keywords.c macro.c mops.c pops.c readsrc.c scan.c table.c typeconv.c' -SRC_LD=' ld.c dumps.c io.c linksyms.c readobj.c table.c typeconv.c - writebin.c writex86.c' - -HDR_BCC='' -HDR_CC1='align.h byteord.h condcode.h const.h gencode.h input.h label.h os.h - output.h parse.h proto.h reg.h sc.h scan.h sizes.h table.h type.h - types.h' -HDR_AS=' address.h byteord.h const.h file.h flag.h globvar.h macro.h opcode.h - proto.h scan.h source.h syshead.h type.h' -HDR_LD=' align.h ar.h bindef.h byteord.h config.h const.h globvar.h obj.h - syshead.h type.h x86_aout.h' - -main() { - echo '@echo off' - echo -n 'if not exist later.exe ' - echo 'bcc -O later.c' - echo - - CFLAGS='-O -D__STDC__=1 -DMSDOS' - LDFLAGS='' - ARCH= - build bcc bcc bin "$HDR_BCC" $SRC_BCC - - CFLAGS='-O -D__STDC__=1 -DMSDOS -DPOSIX_HEADERS_MISSING' - LDFLAGS= - ARCH=-ml - build bcc bcc-cc1 lib "$HDR_CC1" $SRC_CC1 - build as as86 bin "$HDR_AS" $SRC_AS - build ld ld86 bin "$HDR_LD" $SRC_LD - echo ":exit_now" -} - -build() { - DIR="$1" ; shift - PRG="$1" ; shift - BIN="$1" ; shift - HDR="$1" ; shift - OBJ= - BOBJ= - COBJ= - LOBJ= - SRC="$*" - - for i in $SRC - do - j=`basename $i .c` - check_time $DIR/$j.obj $i $HDR - echo -n "if errorlevel 1 " - - echo "bcc $ARCH $CFLAGS -c -I$DIR -o$DIR\\$j.obj $DIR\\$i" - if [ "$BOBJ" = "" ] - then BOBJ="$DIR\\$j.obj" - else LOBJ="$LOBJ +$DIR\\$j.obj" - fi - COBJ="$COBJ $DIR\\$j.obj" - OBJ="$OBJ $j.obj" - - echo "if errorlevel 1 goto exit_now" - done - - if [ `echo $COBJ | wc -c` -lt 50 ] - then - check_time $BIN/$PRG.exe $OBJ - echo -n "if errorlevel 1 " - echo "bcc $ARCH -e$BIN\\$PRG.exe$COBJ $LDFLAGS" - echo "if errorlevel 1 goto exit_now" - else - check_time $BIN/$PRG.exe $OBJ - echo "if not errorlevel 1 goto done_$PRG" - echo "if exist doslib.lib del doslib.lib" - echo $LOBJ | fmt -62 | \ - sed 's/\(.*\)/tlib doslib.lib \1/' - echo "bcc $ARCH -e$BIN\\$PRG.exe $BOBJ doslib.lib $LDFLAGS" - echo "if errorlevel 1 goto exit_now" - echo "if exist doslib.lib del doslib.lib" - echo "if exist doslib.bak del doslib.bak" - echo ":done_$PRG" - fi - echo -} - -check_time() { - TARG="$1" ; shift - - for i - do echo "$DIR/$i" - done | fmt -70 | \ - sed -e "s;\(.*\);later $TARG \1@if errorlevel 3 goto exit_now;" \ - -e '2,$s/^/if not errorlevel 1 /' | \ - tr '@' '\012' -} - -main "$@" | sed 's/$/ /' > compile.bat - diff -Nurd linux86.vold/Mk_dist linux86/Mk_dist --- linux86.vold/Mk_dist 2001-05-21 15:15:45.000000000 +0100 +++ linux86/Mk_dist 2004-01-24 14:33:15.000000000 +0000 @@ -1,8 +1,8 @@ -#!/bin/sh - +#!/bin/bash - # # This script builds _and checks_ all the distribution files from my source # directory. It's very selective because I've got a lot of historical and -# other 'junk' in the same directory. (85Mb!) +# other 'junk' in the same directory. (120Mb at the last count!) # trap "exit 1" 1 2 3 15 @@ -12,24 +12,25 @@ TMPSRC=linux86 ARCDIR="$DIR"/dev86arc -SRCDIRS='bcc unproto as ar ld copt man elksemu dis88 tests libbsd bin86' -DISTFILES='Libc_version Makefile README COPYING MAGIC Changes Contributors - mkcompile mkcompile2 later.c GNUmakefile libcompat - ifdef.c makefile.in Mk_dist' +SRCDIRS='bcc cpp unproto as ar ld copt man elksemu dis88 tests libbsd bin86' +DISTFILES='Makefile README COPYING Changes Contributors MAGIC + mkcompile GNUmakefile libcompat ifdef.c makefile.in Mk_dist' +VERSION="$1" TMPDIST=$TMPDIR/$TMPSRC rm -rf ${TMPDIR} mkdir -p ${TMPDIST} -#----------------------------------------------------------------------- - -echo Checking version +[ "$VERSION" = '' ] && { + echo 'Usage: $0 ' 1>&2 + exit 1 +} -make -s -C libc Libc_version -make -s -C bin86 ungrab -VER=`cat Libc_version` +#----------------------------------------------------------------------- echo Copying most program files. + +make -s -C bin86 ungrab || exit cp -a $DISTFILES $SRCDIRS ${TMPDIST} #----------------------------------------------------------------------- @@ -61,21 +62,52 @@ ( cd ${TMPDIST}/doselks ; tar xzf /tmp/doselks.tar.gz ) [ "`id -un`" = "root" ] && { - chown -R root:root ${TMPDIST} + chown -R root:0 ${TMPDIST} chmod -R og=u-w ${TMPDIST} } -rm -f /tmp/bootblocks.tar.gz /tmp/doselks.tar.gz /tmp/libc-8086-$VER.tar.gz +rm -f /tmp/bootblocks.tar.gz /tmp/doselks.tar.gz /tmp/libc-8086-$VERSION.tar.gz -echo Extracting previous version -rm -f $ARCDIR/Dev86src-$VER.tar.gz +MINOR=${VERSION##*.} +MAJOR=${VERSION%.*} +MID=${MAJOR##*.} +MAJOR=${MAJOR%.*} +OLDVER= -mkdir ${TMPDIST}.tmp -( cd ${TMPDIST}.tmp - tar xzf `ls -tr $ARCDIR/Dev86src*.0.tar.gz | tail -1` - mv * ${TMPDIST}.old -) -rmdir ${TMPDIST}.tmp +case "$VERSION" in +0.0.0 ) BASEVER=0.0.0.0 ;; # Naa. +*.0.0 ) BASEVER=$((MAJOR-1)).$MID.$MINOR ;; +*.*.0 ) BASEVER=$MAJOR.$((MID-1)).$MINOR ;; +* ) BASEVER=$MAJOR.$MID.$((MINOR-1)) + OLDVER=$MAJOR.$MID.0 + ;; +esac +if [ "$MAJOR.$MID.$((MINOR-1))" != "$BASEVER" ] +then PATCHNAME="$VERSION-$BASEVER" +else PATCHNAME="$VERSION" +fi + +[ -f $ARCDIR/Dev86src-$BASEVER.tar.gz ] && { + echo "Extracting previous version ($BASEVER)" + + mkdir ${TMPDIST}.tmp + ( cd ${TMPDIST}.tmp + tar xzf $ARCDIR/Dev86src-$BASEVER.tar.gz + mv * ${TMPDIST}.old + ) + rmdir ${TMPDIST}.tmp +} + +[ "$OLDVER" != "" -a -f $ARCDIR/Dev86src-$OLDVER.tar.gz ] && { + echo "Extracting previous version ($OLDVER)" + + mkdir ${TMPDIST}.tmp + ( cd ${TMPDIST}.tmp + tar xzf $ARCDIR/Dev86src-$OLDVER.tar.gz + mv * ${TMPDIST}.vold + ) + rmdir ${TMPDIST}.tmp +} # ARCDIR=${TMPDIR}/arc ; mkdir -p ${ARCDIR} cd ${TMPDIST} @@ -100,38 +132,58 @@ rm -f $EXCL rm -f `find . -type l` -echo Generating patch against previous .0 version. - cd ${TMPDIR} +[ -d ${TMPSRC}.old ] && { +echo "Generating patch against version $BASEVER." + mv ${TMPSRC}.old/bootblocks boot.old mv ${TMPSRC}/bootblocks boot -diff -Nurd ${TMPSRC}.old ${TMPSRC} > ${ARCDIR}/Dev86src-$VER.patch +diff -Nurd ${TMPSRC}.old ${TMPSRC} > ${ARCDIR}/patch-$PATCHNAME mv boot.old ${TMPSRC}.old/bootblocks mv boot ${TMPSRC}/bootblocks -diff -Nurd ${TMPSRC}.old/bootblocks ${TMPSRC}/bootblocks >> ${ARCDIR}/Dev86src-$VER.patch +diff -Nurd ${TMPSRC}.old/bootblocks ${TMPSRC}/bootblocks >> ${ARCDIR}/patch-$PATCHNAME -gzip -f9 ${ARCDIR}/Dev86src-$VER.patch +gzip -f9 ${ARCDIR}/patch-$PATCHNAME +} + +[ -d ${TMPSRC}.vold ] && { +echo "Generating patch against version $OLDVER." + +mv ${TMPSRC}.vold/bootblocks boot.old +mv ${TMPSRC}/bootblocks boot + +diff -Nurd ${TMPSRC}.vold ${TMPSRC} > ${ARCDIR}/patch-$VERSION-$OLDVER + +mv boot.old ${TMPSRC}.vold/bootblocks +mv boot ${TMPSRC}/bootblocks + +diff -Nurd ${TMPSRC}.vold/bootblocks ${TMPSRC}/bootblocks >> ${ARCDIR}/patch-$VERSION-$OLDVER + +gzip -f9 ${ARCDIR}/patch-$VERSION-$OLDVER +} echo Creating full source archive. -ln -s ${TMPSRC} dev86-$VER -tar cf ${ARCDIR}/Dev86src-$VER.tar dev86-$VER/* -gzip -f9 ${ARCDIR}/Dev86src-$VER.tar +ln -s ${TMPSRC} dev86-$VERSION +tar cf ${ARCDIR}/Dev86src-$VERSION.tar dev86-$VERSION/* +gzip -f9 ${ARCDIR}/Dev86src-$VERSION.tar echo Creating as86 source archive. -ln -s ${TMPSRC}/as as86-$VER -cp -p ${TMPSRC}/man/as86.1 as86-$VER/as86.1 -cp -p ${TMPSRC}/COPYING as86-$VER/COPYING -tar cf ${ARCDIR}/as86-$VER.tar `find as86-$VER/* -prune -type f` +ln -s ${TMPSRC}/as as86-$VERSION +cp -p ${TMPSRC}/man/as86.1 as86-$VERSION/as86.1 +cp -p ${TMPSRC}/COPYING as86-$VERSION/COPYING +echo '#define VERSION "'"$VERSION"'"' > as86-$VERSION/version.h +tar cf ${ARCDIR}/as86-$VERSION.tar `find as86-$VERSION/* -prune -type f` gzip -f9 ${ARCDIR}/as86-*.tar echo Creating bin86 source archive. -make -s -C ${TMPSRC}/bin86 grab -ln -s ${TMPSRC}/bin86 bin86-$VER -tar chf ${ARCDIR}/bin86-$VER.tar bin86-$VER +make -s -C ${TMPSRC}/bin86 VERSION=${VERSION} grab +ln -s ${TMPSRC}/bin86 bin86-$VERSION +echo '#define VERSION "'"$VERSION"'"' > bin86-$VERSION/ld/version.h +tar chf ${ARCDIR}/bin86-$VERSION.tar bin86-$VERSION make -s -C ${TMPSRC}/bin86 ungrab gzip -f9 ${ARCDIR}/bin86-*.tar @@ -141,19 +193,21 @@ cd ${TMPDIR} || exit 1 mkdir -p ${TMPDIST}.ins -make -C ${TMPDIST} install ARFLAGS=q DIST=${TMPDIST}.ins ELKSSRC=/dev/null || +make -C ${TMPDIST} install install-other \ + ARFLAGS=q ELKSSRC=/dev/null \ + DIST=${TMPDIST}.ins 'ASLDDIR=$(BINDIR)' || exit make -C ${TMPDIST} other || exit -tar cf ${ARCDIR}/Dev86bin-$VER.tar -C ${TMPDIST}.ins . -rm -f ${ARCDIR}/Dev86clb-$VER.zip Bcc +tar cf ${ARCDIR}/Dev86bin-$VERSION.tar -C ${TMPDIST}.ins . +rm -f ${ARCDIR}/Dev86clb-$VERSION.zip Bcc ln -s ${TMPDIST} Bcc -zip -9rpk ${ARCDIR}/Dev86clb-$VER.zip \ +zip -9rpk ${ARCDIR}/Dev86clb-$VERSION.zip \ Bcc/lib/crt0.o Bcc/lib/libc.a Bcc/lib/libbsd.a \ Bcc/lib/libdos.a Bcc/lib/libc_f.a Bcc/lib/libc_s.a \ Bcc/lib/i386/crt0.o Bcc/lib/i386/libc.a || exit rm Bcc -gzip -9f ${ARCDIR}/Dev86bin-$VER.tar || exit +gzip -9f ${ARCDIR}/Dev86bin-$VERSION.tar || exit echo Process completed. diff -Nurd linux86.vold/README linux86/README --- linux86.vold/README 1999-04-13 09:51:41.000000000 +0100 +++ linux86/README 2004-01-24 12:44:51.000000000 +0000 @@ -1,11 +1,11 @@ This is a development environment for ELKS-86 and standalone 8086 code. -All you need to do is 'make' from the top directory and the main -parts of the package will be made. These can be tested by use the 'ncc' -program from the newly created bin subdirectory. +All you need to do is 'make' from the top directory and the main parts +of the package will be made. These can be tested by using the 'ncc' +program from the newly created bin subdirectory. (ncc is a varient of +the bcc driver program that doesn't need to be installed to be used). Use 'make install' to install them. -Use 'make Uninstall' to remove everything (Beware with this though!) Some other bits can be built by 'make other' and installed with 'make install-other'. @@ -18,16 +18,40 @@ there are also some hints for using as86 well. The tests and bootblocks directories give some example code. -The bcc command defaults to using /usr/bcc/include and /usr/bcc/lib/bcc +The bcc command defaults to using /usr/lib/bcc/include and /usr/lib/bcc the libraries _and_ include files are copied to these locations by -install. This can be changed by overriding 'PREFIX=/usr' or -'LIBDIR=/usr/bcc/lib/bcc' on the initial make. Also available in the -same way the 'ELKSSRC=/usr/src/elks' variable can be altered if you -have ELKS on a different path. +install. This can be changed by overriding 'PREFIX=/usr/...' or +'LIBDIR=/usr/...' on the initial make. Also available in the +same way are the BINDIR, INCLDIR, ASLDDIR, MANDIR and ELSESRC. +The 'ELKSSRC=/usr/src/elks' variable can be altered if you have ELKS on +path different from the default or ELKSSRC=/dev/null uses the supplied +ELKS headers. The ASLDDIR variable can be used to move as86 and ld86 +into the LIBDIR with 'ASLDDIR=$(LIBDIR)'. The final '/include' is added +to the end of INCLDIR. In the unlikely event you're makeing a non-cross development environment -you can, on the initial make, do "make LIBPRE=/usr' to have the libraries -and include files directly under /usr rather than /usr/bcc. +you can, on the initial make, do "make PREFIX=/' to have the libraries +and include files in 'Native' locations. + +Note: These prefix options only effect the 'bcc.c' driver program and + the install scripts, all the others get their paths from bcc.c. + The ELKSSRC location can, however, greatly effect how the ELKS + libraries are built. + +If you don't want to install in the locations specified above there +is also a DIST= argument to make install that is used to specify the +distribution root to install to. + +The last option is not to install at all. All the executables in the +bin directory can be moved to whereever you wish except for bcc and ncc. +To use bcc at any other location you can create a symlink from your +new location to the 'ncc' executable and it will be able to find +the libraries in the build directory: + +eg: + cp ar86 elksemu objdump86 $HOME/bin/. + cp as86 as86_encap ld86 $HOME/bin/. # Optional. + ln -s `pwd`/ncc $HOME/bin/bcc All the versions of the library are built by make; 'normal', 'fast', 'MSDOS', 'standalone' and Linux-i386. @@ -49,7 +73,8 @@ The 'standalone' version creates executables like normal ELKS a.out files but with no operating system calls, just BIOS ones. These files are suitable for running on a bare machine started by one of -the boot blocks in the bootblocks subdirectory. +the boot blocks in the bootblocks subdirectory. If you add a '-d' +option to the link stage the a.out header will be removed. The Linux-i386 version generates static Linux OMAGIC a.out programs, they need neither elksemu nor a.out shared libraries to run. Unfortunatly @@ -67,12 +92,15 @@ I _strongly_ suggest you install the kernel patch or load the module to allow transparent execution of elks executables. If you're using -a post 2.1.43 or 2.0.36 kernel the module you need is the binfmt_misc +a post 2.1.43 or 2.0.36 kernel the only module you need is the binfmt_misc driver configured like this: -echo ':i86-elks:M::\x01\x03\x20\x00:\xff\xff\xff\x83:/lib/elksemu:' \ +echo ':i86-elks:M::\x01\x03\x20\x00:\xff\xff\xff\x83:/usr/bin/elksemu:' \ > /proc/sys/fs/binfmt_misc/register +The elksemu executable must be stored in /usr/bin/elksemu or the above +line adjusted. + Previous versions need a special module or patch described in elksemu/README (All the options need the elksemu executable installed correctly) diff -Nurd linux86.vold/tests/ft.c linux86/tests/ft.c --- linux86.vold/tests/ft.c 1999-03-14 12:19:09.000000000 +0000 +++ linux86/tests/ft.c 2004-01-25 08:51:22.000000000 +0000 @@ -42,7 +42,7 @@ #define PR(x) () #endif -void main PR((int argc, char ** argv)); +int main PR((int argc, char ** argv)); int select_command PR((char * argv)); void do_prep PR((void)); void do_post PR((void)); @@ -156,7 +156,7 @@ int done_something = 0; -void +int main(argc, argv) int argc; char ** argv; { @@ -261,7 +261,7 @@ else Usage(); } - exit(0); + return 0; } int select_command(argv) @@ -588,7 +588,7 @@ } } - if( set_user < 0 && set_group < 0 && set_mode < 0 && *mode_str == 0) + if( set_user == -1 && set_group == -1 && set_mode < 0 && *mode_str == 0) { error(EINVAL, "", "Permission string has no changes"); exit(1); @@ -664,6 +664,7 @@ static int last_uid=-1, last_gid=-1, last_mode=-1; struct passwd * pptr; struct group * gptr; + int major, minor; if( flg_verbose>1 ) { @@ -721,6 +722,16 @@ if( (cur_file_stat.st_mode&07777) != (last_mode&07777) ) printf(":%03o", cur_file_stat.st_mode & 07777); +#ifdef __linux__ + major = ((cur_file_stat.st_rdev >> 8) & 0xfff); + if (sizeof(cur_file_stat.st_rdev) > 4) + major |= ((cur_file_stat.st_rdev >> 32) & ~0xfff); + minor = (cur_file_stat.st_rdev & 0xff) | + ((cur_file_stat.st_rdev >> 12) & ~0xff); +#else + major = ((cur_file_stat.st_rdev >> 8) & 0xFF); + minor = (cur_file_stat.st_rdev&0xFF); +#endif switch(cur_file_stat.st_mode & S_IFMT) { case S_IFDIR: printf("\td"); break; @@ -728,11 +739,9 @@ #ifdef __HAS_SOCKETS case S_IFSOCK: printf("\ts"); break; #endif - case S_IFBLK: printf("\tb,%d,%d", cur_file_stat.st_rdev>>8, - cur_file_stat.st_rdev&0xFF); + case S_IFBLK: printf("\tb,%d,%d", major, minor); break; - case S_IFCHR: printf("\tc,%d,%d", cur_file_stat.st_rdev>>8, - cur_file_stat.st_rdev&0xFF); + case S_IFCHR: printf("\tc,%d,%d", major, minor); break; } last_mode = ((cur_file_stat.st_mode&07777)|S_IFREG); @@ -987,8 +996,8 @@ /* Try to preserve ownership. For non-root it might fail, but that's ok. But root probably wants to know, e.g. if NFS disallows it. */ - user = cur_file_stat.st_uid; if(set_user>=0) user = set_user; - group = cur_file_stat.st_gid; if(set_group>=0) group = set_group; + user = cur_file_stat.st_uid; if(set_user != -1) user = set_user; + group = cur_file_stat.st_gid; if(set_group != -1) group = set_group; if (chown (file, user, group) && (errno != EPERM || geteuid() == 0 || (flg_preserve==0 && flg_force==0))) @@ -1157,7 +1166,7 @@ } if( retv>=0 && cmd_tok == CMD_MKDIR ) { - if( set_user > 0 || set_group > 0 ) + if( set_user != -1 || set_group != -1 ) { if( chown(dirname, set_user, set_group) < 0) warning(errno, "Cannot change directory owner ", dirname); @@ -1173,12 +1182,19 @@ int cmd_mknod() { - int device; + int device, major, minor; int rv = -1; int mode=0666; if( set_mode >= 0 ) mode=set_mode; - device = (atoi(flist[2])<<8) + atoi(flist[3]); + major = atoi(flist[2]); + minor = atoi(flist[3]); +#ifdef __linux__ + /* Linux 2.6+ uses an odd arrangment. */ + device = (major<<8) + (minor & 0xFF) + ((minor & 0xFFF00) << 12); +#else + device = (major<<8) + (minor & 0xFF); +#endif if(flist[1][0] == 'b') rv = mknod(flist[0], S_IFBLK|mode, device); diff -Nurd linux86.vold/tests/hd.c linux86/tests/hd.c --- linux86.vold/tests/hd.c 1997-07-03 22:31:15.000000000 +0100 +++ linux86/tests/hd.c 2002-05-30 20:45:22.000000000 +0100 @@ -1,7 +1,27 @@ +/* + * This is a Xenix style hex dump command. + * + * The 'reverse hex dump' option is an addition that allows a simple + * method of editing binary files. + * + * The overkill Linux 'hexdump' command can be configured to generate + * the same format as this command by this shell macro: + * + * hd() { hexdump -e '"%06.6_ax:" 8/1 " %02x" " " 8/1 " %02x" " " ' \ + * -e '16/1 "%_p" "\n"' \ + * "$@" + * } + * + */ #include #include #include +#ifndef MSDOS +#ifndef __BCC__ +#include +#endif +#endif int lastnum[16] = {-1}; long lastaddr = -1; @@ -9,7 +29,7 @@ FILE *fd; -FILE * ofd = stdout; +FILE * ofd; char * outfile = 0; int reverse = 0; @@ -21,6 +41,14 @@ int ar; int aflag = 1; +#ifndef MSDOS +#ifndef __BCC__ + setlocale(LC_CTYPE, ""); +#endif +#endif + + ofd = stdout; + for (ar = 1; ar < argc; ar++) if (aflag && argv[ar][0] == '-') switch (argv[ar][1]) @@ -119,7 +147,7 @@ break; num[j] = ch; - if (isascii(ch) && isprint(ch)) + if (isprint(ch)) buf[j] = ch; else buf[j] = '.'; @@ -195,8 +223,12 @@ ptr = str; if( *ptr == '*' ) zap_last = 0; - if( !isxdigit(*ptr) ) continue; - addr = strtol(ptr, &ptr, 16); + if( *ptr != ':' ) { + if( !isxdigit(*ptr) ) continue; + addr = strtol(ptr, &ptr, 16); + } + else + addr = nxtaddr; if( *ptr == ':' ) ptr++; if (nxtaddr == 0) diff -Nurd linux86.vold/tests/Makefile linux86/tests/Makefile --- linux86.vold/tests/Makefile 1998-12-30 11:38:46.000000000 +0000 +++ linux86/tests/Makefile 2004-01-24 10:52:55.000000000 +0000 @@ -6,16 +6,23 @@ CC=$(BCC) CFLAGS=-O -SRC=env.c ft.c hd.c size.c sync.c compr.c ucomp.c ouch.c lines.c \ +SRC=env.c ft.c hd.c sync.c compr.c ucomp.c ouch.c lines.c \ wc.c line2.c rand.c grab.c OBJ= -EXE=env ft hd size sync compr ucomp ouch lines wc line2 rand grab +EXE=env ft hd sync compr ucomp ouch lines wc line2 rand grab LINK_FILES=cat chgrp chmod chown cp install ln mkdir mkfifo mknod mv rm all: $(EXE) -install links: +install: + echo Use real-install if you actually want to install these + +real-install: + install wc hd env ft $(DIST)$(PREFIX)/bin + for i in $(LINK_FILES) ; do ln -s ft $(DIST)$(PREFIX)/bin/$$i ; done + +install_links: for i in $(LINK_FILES) ; do ln -s ft $$i ; done no_links: diff -Nurd linux86.vold/tests/size.c linux86/tests/size.c --- linux86.vold/tests/size.c 1997-01-05 11:07:42.000000000 +0000 +++ linux86/tests/size.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,83 +0,0 @@ -#include -#include - -int verbose = 0; - -void size(filename) - char *filename; -{ - int f; - struct exec ex; - long total; - int cc; - - if ((f = open(filename, O_RDONLY)) < 0 ) - { - perror(filename); - return; - } - cc = read(f, &ex, sizeof(ex)); - - if (cc == sizeof(ex) && !BADMAG(ex)) - { - total = ex.a_text + ex.a_data + ex.a_bss; - if( verbose ) - { - printf("Text segment of %s = %5ld (0x%lx)\n", - filename, ex.a_text, ex.a_text); - printf("Init data of %s = %5ld (0x%lx)\n", - filename, ex.a_data, ex.a_data); - printf("Uninit data of %s = %5ld (0x%lx)\n", - filename, ex.a_bss, ex.a_bss); - printf("Data segment of %s = %5ld (0x%lx)\n", - filename, ex.a_total, ex.a_total); - printf("Minimum size of %s = %5ld (0x%lx)\n", - filename, total, total); - - total = ex.a_total; - if( ex.a_flags & A_SEP ) - total += ex.a_text; - printf("Maximum size of %s = %5ld (0x%lx)\n", - filename, total, total); - } - else - printf("%-ld\t%-ld\t%-ld\t%-ld\t%-lx\t%s\n", - ex.a_text, ex.a_data, ex.a_bss, total, total, - filename); - } - else if( cc > 16 && memcmp(&ex, "\243\206\001\000*", 5) == 0 ) - { /* *.o file */ - total = ((unsigned char*)&ex)[9] + - ((unsigned char*)&ex)[10] * 256; - if( verbose ) - printf("Size of object %s = %5ld (0x%lx)\n", - filename, total, total); - else - printf("\t\t\t%-ld\t%-lx\t%s\n", - total, total, filename); - } - else - printf("%s: Not an a.out file\n", filename); - close(f); -} - -int main(argc, argv) - int argc; - char **argv; -{ - if (argc > 1 && strcmp(argv[1], "-v") == 0 ) - { - verbose++; - argc--, argv++; - } - if (argc < 2) - { - printf("Usage: %s [-v] file\n", argv[0]); - exit(1); - } - if(!verbose) - printf("text\tdata\tbss\tdec\thex\tfilename\n"); - for (--argc, ++argv; argc > 0; --argc, ++argv) - size(*argv); - exit(0); -} diff -Nurd linux86.vold/unproto/Makefile linux86/unproto/Makefile --- linux86.vold/unproto/Makefile 2001-01-06 12:37:21.000000000 +0000 +++ linux86/unproto/Makefile 2003-10-06 18:01:45.000000000 +0100 @@ -38,7 +38,7 @@ # 7. Specify a string constant with exactly three octal digits. If you # change this definition, you will have to update the example.out file. # -BELL = -DBELL=\"007\" +# BELL = -DBELL=\"007\" # Some C compilers have problems with "void". The nature of the problems # depends on the age of the compiler. @@ -89,7 +89,7 @@ #CFLAGS = -g $(PIPE) $(SKIP) $(BELL) $(MAP) $(ALIAS) -DDEBUG $(PROG): $(OBJECTS) - $(CC) $(CCFLAGS) $(LDFLAGS) -o $@ $^ $(MALLOC) + $(CC) $(CCFLAGS) $(LDFLAGS) -o $@ $(OBJECTS) $(MALLOC) .c.o: $(CC) $(CCFLAGS) -c $< -o $@ diff -Nurd linux86.vold/unproto/unproto.c linux86/unproto/unproto.c --- linux86.vold/unproto/unproto.c 1997-04-24 20:21:33.000000000 +0100 +++ linux86/unproto/unproto.c 2003-08-31 13:45:36.000000000 +0100 @@ -146,12 +146,12 @@ /* Application-specific stuff */ -#include "vstring.h" -#ifdef _AIX +#ifdef __STDC__ #include #else #include "stdarg.h" #endif +#include "vstring.h" #include "token.h" #include "error.h" #include "symbol.h" @@ -219,7 +219,10 @@ cpp_pid = pipe_stdin_through_cpp(argv); #endif -#ifdef REOPEN +#if defined(REOPEN) || defined(MSDOS) +#ifdef PIPE_THROUGH_CPP +#error Defines REOPEN and PIPE_THROUGH_CPP are incompatible. +#endif if ( argc > 1 ) { if( freopen(argv[1], "r", stdin) == 0 ) { fprintf(stderr, "Cannot open '%s'\n", argv[1]); diff -Nurd linux86.vold/bootblocks/bb_init1.s linux86/bootblocks/bb_init1.s --- linux86.vold/bootblocks/bb_init1.s 1970-01-01 01:00:00.000000000 +0100 +++ linux86/bootblocks/bb_init1.s 2003-02-01 17:31:21.000000000 +0000 @@ -0,0 +1,25 @@ +ORGADDR=0x0600 + +.org ORGADDR +entry start +public start +start: + cld + xor ax,ax + mov si,#$7C00 + mov di,#ORGADDR + + mov ss,ax + mov sp,si ! ax, di or si + + push ax + pop ds + push ax + pop es + + mov cx,#256 + rep + movsw + jmpi go,#0 +go: + diff -Nurd linux86.vold/bootblocks/bb_init2.s linux86/bootblocks/bb_init2.s --- linux86.vold/bootblocks/bb_init2.s 1970-01-01 01:00:00.000000000 +0100 +++ linux86/bootblocks/bb_init2.s 2002-03-16 14:22:51.000000000 +0000 @@ -0,0 +1,17 @@ +ORGADDR=$0500 + +org ORGADDR + cld + mov bx,#$7C00 ! Pointer to start of BB. + xor ax,ax ! Segs all to zero + mov ds,ax + mov es,ax + mov ss,ax + mov sp,bx ! SP Just below BB + mov cx,#$100 ! Move 256 words + mov si,bx ! From default BB + mov di,#ORGADDR ! To the correct address. + rep + movsw + jmpi cont,#0 ! Set CS:IP correct. +cont: diff -Nurd linux86.vold/bootblocks/bb_linux.s linux86/bootblocks/bb_linux.s --- linux86.vold/bootblocks/bb_linux.s 1970-01-01 01:00:00.000000000 +0100 +++ linux86/bootblocks/bb_linux.s 2002-03-16 17:11:48.000000000 +0000 @@ -0,0 +1,22 @@ + +INITSEG = $9000 + +org 0 +mov ax,#$07c0 +mov ds,ax +mov ax,#INITSEG +mov es,ax +mov cx,#256 +sub si,si +sub di,di +cld +rep + movsw +jmpi go,INITSEG +go: + +mov di,#0x4000-12 +mov ds,ax +mov ss,ax ! put stack at INITSEG:0x4000-12. +mov sp,di + diff -Nurd linux86.vold/bootblocks/boot_fpy.s linux86/bootblocks/boot_fpy.s --- linux86.vold/bootblocks/boot_fpy.s 1970-01-01 01:00:00.000000000 +0100 +++ linux86/bootblocks/boot_fpy.s 2002-05-26 14:21:51.000000000 +0100 @@ -0,0 +1,258 @@ +! This binary is for loading a dev86 a.out file from a floppy without +! a filesystem; to make a bootable disk just do: +! +! cat boot_fpy.bin monitor.out > /dev/fd0 +! + +ORGADDR=0x0600 +EXEADDR=0x0800 ! This must be up to 0x7E0 or 0x0800 +LOADSEG=0x0080 ! Must be 512b aligned for DMA + +! Padding so you can join with 'cat'. +.org EXEADDR-1 +.byte 0 + +! This marker is needed by many boot managers (and bochs) but the BIOS does +! NOT require it on a floppy. +if EXEADDR=0x0800 +.org ORGADDR+0x1FE +.word 0xAA55 +endif + +.org ORGADDR +entry start +public start +start: + xor ax,ax + mov si,#$7C00 + mov di,#ORGADDR + + mov ss,ax + mov sp,di ! Or si or ax + + push ax + pop ds + push ax + pop es + + mov cx,#256 + cld + rep + movsw + jmpi go,#0 +go: + +! Grrr, have to load sector 1 in by hand. +if EXEADDR=0x0800 +Loopi: + mov ax,#$0201 ! Read 1 sector + mov bx,#EXEADDR ! Into EXEADDR + mov cx,#$0002 ! From sector 2 + xor dx,dx ! Of the floppy drive head zero + int $13 + jc Loopi +endif + + mov si,#Boot_message + call puts + + mov ax,[a_text] ! How many sectors to load + mov cl,#4 + shr ax,cl + mov bx,ax + mov ax,[a_data] + mov cl,#4 + shr ax,cl + add ax,bx + add ax,#$1F + mov cl,#5 + shr ax,cl ! ax = sectors to read + + ! This routine starts by loading one sector at a time, with most + ! modern PCs the processor is fast enough to keep up with single + ! sector reads, in reality an 8Mhz 286 can keep up! + ! But occasionally some older machines have really poor BIOSes + ! (Some modern ones too) so once we know how many sectors to read + ! we switch to reading a track at a time. But we only try it once + ! for each track. Normally, as long as the load address is sector + ! aligned, this will work every time but with some BIOSes we can't + ! read a track without messing with the BPB so if the track read + ! fails it's one try we fall back to sector reads. + ! + ! Overall this usually gives good performance, and with a BIOS that + ! isn't completely broken and correctly formatted floppies will run + ! at about 2.5 rotations per cylinder (1.25 per track). If you find + ! your BIOS is one of the bad ones you'll have to format your disks + ! to a 2:1 interleave. + ! + ! BTW: It's very easy to make superformat incorrectly calculate the + ! inter-sector gaps so it ends up squeezing the sectors to the start + ! of the track. This means that only a full track read is fast enough. + ! I suggest you use fdformat as it always uses 'safe' parameters for + ! a 1440k floppy. + + ! AX = count of sectors + mov cx,#2 ! CX = First sector + mov bx,#LOADSEG ! ES:BX = Where to load + mov es,bx + xor bx,bx ! Initial offset + + xor dx,dx ! DX = Drive 0 + + ! ax=cnt, dl=drv, ch=*, dh=*, cl=sec, es:bx=buffer. + +read_data: + mov si,ax ! Save big count. + xor ch,ch + xor dh,dh + + mov maxsect,cl ! Save first sector. + +load_loop: + mov di,#5 ! Error retry. + +sect_retry: + mov ax,#$0201 + ! ah=2, al=1, dl=drv, ch=cyl, dh=head, cl=sec, es:bx=buffer. + int $13 + jnc next_sect + + dec di ! Retry counter + jz sect_error + + cmp cl,maxsect ! If this is first sector or previously ok sector + jle sect_retry ! number then retry. + + mov maxsect,cl + j inc_trk + +next_sect: + mov ax,es ! Inc load address. + add ax,#32 + mov es,ax + + dec si ! Had enough ? + jz all_loaded + +inc_sect: + inc cl + cmp cl,maxsect + jnz load_loop +inc_trk: ! Reached end of track, seek to next. + mov cl,#1 + xor dh,cl + jnz load_track + inc ch +load_track: + cmp si,maxsect ! Is the whole track needed ? + jb load_loop ! no, goto load_loop for 1 by 1 + + ! Try to load the track _once_ only, if it fails go 1 by 1 again. + + mov ax,maxsect + dec ax + mov ah,#$02 + ! ah=2, al=*, dl=drv, ch=cyl, dh=head, cl=sec, es:bx=buffer. + int $13 + jc load_loop + + mov ax,maxsect ! Ok that worked, update the pointers + dec ax + mov cl,#5 + shl ax,cl + mov di,es + add ax,di + mov es,ax + + inc si + sub si,maxsect + jnz inc_trk + +all_loaded: + ! Now it's loaded turn off the floppy motor. + mov dx,#0x3f2 + xor al, al + outb + + ! And start up the program. + + xor dx,dx ! DX=0 => floppy drive + push dx ! CX=0 => partition offset = 0 + mov si,dx ! Sect/track = 0 + + mov bx,#EXEADDR>>4 + mov ds,bx ! DS = loadaddress + xor di,di ! Zero + mov ax,[di+2] + and ax,#$20 ! Is it split I/D ? + jz impure ! No ... + mov cl,#4 + mov ax,[di+8] + shr ax,cl +impure: + pop cx ! Partition offset. + inc bx + inc bx ! bx = initial CS + add ax,bx + mov ss,ax + mov sp,[di+24] ! Chmem value + mov ds,ax + + ! AX=ds, BX=cs, CX=X, DX=X, SI=X, DI=0, BP=X, ES=X, DS=*, SS=*, CS=* + +bad_magic: + push bx ! jmpi 0,#LOADSEG+2 + push di + retf + +sect_error: + ! Disk error, wait then reboot. + + mov si,#reboot_msg + call puts + + xor ax,ax ! Wait for the user. + int $16 + jmpi $0,$FFFF + +puts: + lodsb + cmp al,#0 + jz EOS + push bx + mov bx,#7 + mov ah,#$E ! Can't use $13 cause that's AT+ only! + int $10 + pop bx + jmp puts +EOS: + ret + +maxsect: + .word 0 + +reboot_msg: + .asciz "Disk error, press a key to reboot:" + +Boot_message: + .asciz "Boot sector loaded.\r\n" + +! Check for overlap +end_of_code: + if end_of_code>hitme + fail! Overlap at end_of_code + endif + +.org EXEADDR +hitme: + +magic: .space 2 ! A.out header +btype: .space 2 +headerlen: .space 4 +a_text: .space 4 +a_data: .space 4 +a_bss: .space 4 +a_entry: .space 4 +a_total: .space 4 +a_syms: .space 4 + diff -Nurd linux86.vold/bootblocks/boot_win.c linux86/bootblocks/boot_win.c --- linux86.vold/bootblocks/boot_win.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/bootblocks/boot_win.c 2004-04-28 14:41:01.000000000 +0100 @@ -0,0 +1,320 @@ +/* + * This program is designed to be put onto an MSDOS filesystem floppy or + * a floppy image on a CD-ROM. + * + * The hexdump at the end is from Windows 95 boot sector and can be used + * to start a Windows 9X io.sys. + * + * This program runs first and if the hard disk appears bootable will load + * and start that unless you press return. + * + * If you press a key you have the option of Zapping the MBR! + * + */ + +#include + +#define sysboot_dosfs_stat 0x000B +#define sysboot_codestart 0x003E +#define sysboot_bootblock_magic 0x01FE + +extern char win95_bb[512]; +char bs_buf[512]; +char buf2[512]; +unsigned memseg, memlen; + +fatal(str) + char * str; +{ + cprintf(str); + getch(); + exit(0); +} + +main() +{ + int i, rv; + int floppy_only = 0; + int c,h,s,os; + + reset_screen(); + cprintf("...\n"); + relocate(); + if (__get_cs() != 0x80) + fatal("ERROR - program incorrectly compiled.\n"); + + for(i=0; i<6; i++) + if (!(rv = _bios_disk_read(0x80, 0, 0, 1, 1, bs_buf))) break; + + if (rv != 0 || bs_buf[510] != 0x55 || bs_buf[511] != (char)0xAA) { + cprintf("Hard disk not bootable.\n"); + floppy_only = 1; + + /* Check for zapped MBR */ + for(i=0; i<512; i++) { + if (bs_buf[i]) break; + if (i==511) + boot_floppy(); + } + } + + if (!floppy_only) { + for(rv=-1, i=0x1BE; i<0x1FE; i+= 16) { + if (bs_buf[i] == (char)0x80) { + rv = 0; + s = (bs_buf[i+2] & 63) ; + h = (bs_buf[i+1] & 255) ; + c = (bs_buf[i+3] & 255) + ((bs_buf[i+2] & 0xC0) << 2); + + os = (bs_buf[i+4] & 255) ; + break; + } + } + + if (rv) { + cprintf("Hard disk has no active partition.\n"); + floppy_only = 1; + } + } + + if (!floppy_only && (os==4 || os==6 || os==11 || os==12 || os==13)) { + for(i=0; i<6; i++) + if (!(rv = _bios_disk_read(0x80, c, h, s, 1, bs_buf))) break; + + if (rv != 0 || bs_buf[510] != 0x55 || bs_buf[511] != (char)0xAA) { + cprintf("DOS Partition not bootable.\n"); + floppy_only = 1; + } + } + + if (floppy_only) + cprintf("Press return to wipe MBR: "); + else + cprintf("Press return to skip hard disk boot: "); + + __set_es(0x40); + for(i=0; ; i++) { + unsigned int tv = __deek_es(0x6c); + while (tv == __deek_es(0x6c)) + if (kbhit()) { + getch(); + cprintf("\n"); + goto break_break; + } + if (i%10 == 0) cprintf("."); + + if (i>= 18*5) { + cprintf(" Booting.\n"); + if(floppy_only) + boot_floppy(); + else + boot_hd(); + } + } +break_break:; + + cprintf("Do you want to leave the hard disk intact?\n"); + cprintf("(Y/n) "); + i = (getch() & 0xFF); + if (i == 'n' || i == 'N') { + cprintf("No\n"); + + cprintf("WARNING: This WILL delete everything on the hard disk!\n"); + cprintf("Do you want to clear the hard disk MBR?\n"); + cprintf("(N/y) "); + + i = (getch() & 0xFF); + if (i == 'y' || i == 'Y') { + cprintf("Yes\n"); + memset(bs_buf, 0, sizeof(bs_buf)); + + for(i=0; i<6; i++) + if (!(rv = _bios_disk_write(0x80, 0, 0, 1, 1, bs_buf))) break; + + if (rv) { + cprintf("Disk error 0x%2x on disk write:", rv); + getch(); + cprintf("\n"); + } else { + cprintf("Hard disk MBR wiped!\n"); + } + } else + cprintf("No -- Disk is still untouched\n"); + } else + cprintf("Ok -- Disk is untouched\n"); + + boot_floppy(); +} + +reset_screen() +{ +#asm + mov ah,#$0F + int $10 + cmp al,#$07 + je dont_touch + mov ax,#$0003 + int $10 +dont_touch: +#endasm +} + +boot_floppy() +{ + _bios_disk_read(0, 0, 0, 1, 1, bs_buf); + make_floppy_bb(); + +#asm + mov ax,#$00 + push ax + pop ds + mov bx,#$7c00 + mov dx,#$0000 ! Of the floppy drive + jmpi $7c00,0 +#endasm +} + +boot_hd() +{ + int i; + /* If we're booting from a CD we want to turn off the floppy emulation */ + buf2[0] = 0x13; /* Sizeof a 'Specification packet' */ + +#asm + mov ax,#$4B01 + mov dl,#$7F + mov si,#_buf2 + int $13 + ! Ignore the return value; it's meaningless if we aren't on a CD +#endasm + + /* Now boot the hard disk */ + __set_es(0x07c0); + for(i=0; i<512; i++) __poke_es(i, bs_buf[i]); + +#asm + mov ax,#$00 + push ax + pop ds + mov bx,#$7c00 + mov dx,#$0080 ! Of the hard drive + jmpi $7c00,0 +#endasm +} + +make_floppy_bb() +{ + int i; + __set_es(0x07c0); + for(i=0; i> 4); + + /* + if (__deek_es(0) == 0x0301 ) memlen = (__deek_es(24) >> 4); + */ + + if( memlen == 0 ) memlen = 0x1000; + memlen += codelen; + __set_es(es); + } + + newseg = 0x80; + + /* If the old area overlaps the new then fail */ + if( newseg >= memseg && newseg < memseg+memlen ) return; + if( memseg >= newseg && memseg < newseg+memlen ) return; + + /* Copy segments, done in 32k chunks */ + for(moved=0; moved < memlen; ) + { + unsigned int lump; + if( memlen-moved <= 0x800 ) lump = memlen-moved; else lump = 0x800; + + __movedata(memseg+moved, 0, newseg+moved, 0, (lump<<4)); + moved += lump; + } + + /* re-link int 0x80, this one is only an example (used by 'standalone.c') */ + /* __set_es(0); __doke_es(0x80*4+2, newseg); __set_es(es); */ + + /* The actual jump ... */ + memseg = newseg; + +#asm + mov ax,ds + mov bx,cs + sub ax,bx + mov bx,[_memseg] + add ax,bx + push bx + call L_x + mov ds,ax + mov ss,ax + mov [_memseg],bx +#endasm +} +#asm +L_x: + retf +#endasm + +#else +} +#endif + +char win95_bb[512] = { +0xeb,0x3c,0x90,0x29,0x69,0x71,0x22,0x5a,0x49,0x48,0x43,0x00,0x02,0x01,0x01,0x00, +0x02,0xe0,0x00,0x40,0x0b,0xf0,0x09,0x00,0x12,0x00,0x02,0x00,0x00,0x00,0x00,0x00, +0x40,0x0b,0x00,0x00,0x00,0x00,0x29,0xfa,0x16,0x58,0x2c,0x4e,0x4f,0x20,0x4e,0x41, +0x4d,0x45,0x20,0x20,0x20,0x20,0x46,0x41,0x54,0x31,0x32,0x20,0x20,0x20,0xfa,0x33, +0xc9,0x8e,0xd1,0xbc,0xfc,0x7b,0x16,0x07,0xbd,0x78,0x00,0xc5,0x76,0x00,0x1e,0x56, +0x16,0x55,0xbf,0x22,0x05,0x89,0x7e,0x00,0x89,0x4e,0x02,0xb1,0x0b,0xfc,0xf3,0xa4, +0x06,0x1f,0xbd,0x00,0x7c,0xc6,0x45,0xfe,0x0f,0x8b,0x46,0x18,0x88,0x45,0xf9,0x38, +0x4e,0x24,0x7d,0x22,0x8b,0xc1,0x99,0xe8,0x77,0x01,0x72,0x1a,0x83,0xeb,0x3a,0x66, +0xa1,0x1c,0x7c,0x66,0x3b,0x07,0x8a,0x57,0xfc,0x75,0x06,0x80,0xca,0x02,0x88,0x56, +0x02,0x80,0xc3,0x10,0x73,0xed,0x33,0xc9,0x8a,0x46,0x10,0x98,0xf7,0x66,0x16,0x03, +0x46,0x1c,0x13,0x56,0x1e,0x03,0x46,0x0e,0x13,0xd1,0x8b,0x76,0x11,0x60,0x89,0x46, +0xfc,0x89,0x56,0xfe,0xb8,0x20,0x00,0xf7,0xe6,0x8b,0x5e,0x0b,0x03,0xc3,0x48,0xf7, +0xf3,0x01,0x46,0xfc,0x11,0x4e,0xfe,0x61,0xbf,0x00,0x07,0xe8,0x23,0x01,0x72,0x39, +0x38,0x2d,0x74,0x17,0x60,0xb1,0x0b,0xbe,0xd8,0x7d,0xf3,0xa6,0x61,0x74,0x39,0x4e, +0x74,0x09,0x83,0xc7,0x20,0x3b,0xfb,0x72,0xe7,0xeb,0xdd,0xbe,0x7f,0x7d,0xac,0x98, +0x03,0xf0,0xac,0x84,0xc0,0x74,0x17,0x3c,0xff,0x74,0x09,0xb4,0x0e,0xbb,0x07,0x00, +0xcd,0x10,0xeb,0xee,0xbe,0x82,0x7d,0xeb,0xe5,0xbe,0x80,0x7d,0xeb,0xe0,0x98,0xcd, +0x16,0x5e,0x1f,0x66,0x8f,0x04,0xcd,0x19,0xbe,0x81,0x7d,0x8b,0x7d,0x1a,0x8d,0x45, +0xfe,0x8a,0x4e,0x0d,0xf7,0xe1,0x03,0x46,0xfc,0x13,0x56,0xfe,0xb1,0x04,0xe8,0xc1, +0x00,0x72,0xd6,0xea,0x00,0x02,0x70,0x00,0xb4,0x42,0xeb,0x2d,0x60,0x66,0x6a,0x00, +0x52,0x50,0x06,0x53,0x6a,0x01,0x6a,0x10,0x8b,0xf4,0x74,0xec,0x91,0x92,0x33,0xd2, +0xf7,0x76,0x18,0x91,0xf7,0x76,0x18,0x42,0x87,0xca,0xf7,0x76,0x1a,0x8a,0xf2,0x8a, +0xe8,0xc0,0xcc,0x02,0x0a,0xcc,0xb8,0x01,0x02,0x8a,0x56,0x24,0xcd,0x13,0x8d,0x64, +0x10,0x61,0x72,0x0a,0x40,0x75,0x01,0x42,0x03,0x5e,0x0b,0x49,0x75,0x77,0xc3,0x03, +0x18,0x01,0x27,0x0d,0x0a,0x49,0x6e,0x76,0x61,0x6c,0x69,0x64,0x20,0x73,0x79,0x73, +0x74,0x65,0x6d,0x20,0x64,0x69,0x73,0x6b,0xff,0x0d,0x0a,0x44,0x69,0x73,0x6b,0x20, +0x49,0x2f,0x4f,0x20,0x65,0x72,0x72,0x6f,0x72,0xff,0x0d,0x0a,0x52,0x65,0x70,0x6c, +0x61,0x63,0x65,0x20,0x74,0x68,0x65,0x20,0x64,0x69,0x73,0x6b,0x2c,0x20,0x61,0x6e, +0x64,0x20,0x74,0x68,0x65,0x6e,0x20,0x70,0x72,0x65,0x73,0x73,0x20,0x61,0x6e,0x79, +0x20,0x6b,0x65,0x79,0x0d,0x0a,0x00,0x00,0x49,0x4f,0x20,0x20,0x20,0x20,0x20,0x20, +0x53,0x59,0x53,0x4d,0x53,0x44,0x4f,0x53,0x20,0x20,0x20,0x53,0x59,0x53,0x7f,0x01, +0x00,0x41,0xbb,0x00,0x07,0x80,0x7e,0x02,0x0e,0xe9,0x40,0xff,0x00,0x00,0x55,0xaa +}; diff -Nurd linux86.vold/bootblocks/buffer.c linux86/bootblocks/buffer.c --- linux86.vold/bootblocks/buffer.c 1970-01-01 01:00:00.000000000 +0100 +++ linux86/bootblocks/buffer.c 2002-05-26 15:30:01.000000000 +0100 @@ -0,0 +1,142 @@ + +#include "monitor.h" + +#ifndef MAXTRK +#define MAXTRK 18 +#endif + +int disk_drive = 0; +int disk_spt = 7; +int disk_heads = 0; +int disk_cyls = 0; +long disk_partition_offset = 0; + +static long bad_start = -1; +static long buf_start = -1; +static int buf_sec = 0; +static int buf_len = 0; +static char buffer[MAXTRK*512]; /* WARNING: This must be DMAable */ + +void reset_disk() +{ + disk_spt = 7; /* Defaults for reading floppy boot area. */ + disk_heads = 0; + disk_cyls = 0; + bad_start = -1; + disk_partition_offset = 0; + +#ifdef __STANDALONE__ + if( disk_drive == __argr.h.dl && __argr.x.si >= 9 && __argr.x.si <= 63 ) + { + disk_spt = __argr.x.si; + disk_heads = 2; + disk_cyls = 80; + } + if( disk_drive & 0x80 ) + { + /* Hard disk, get parameters from bios */ + long dpt; + int v; + + if( disk_drive == __argr.h.dl ) + disk_partition_offset = __argr.x.cx + ((long)__argr.h.dh<<16); + + dpt = _bios_get_dpt(disk_drive); + v = ((dpt>>16) & 0xFF); + if( v != 0xFF && v > (disk_drive&0x7F) ) + { + disk_spt = (dpt & 0x3F); /* Max sector number 1-63 */ + if( disk_spt == 0 ) disk_spt = 64; /* 1-64 ? */ + disk_heads = ((dpt>>24) & 0xFF) + 1; /* Head count 1-256 */ + disk_cyls = ((dpt>>8) & 0xFF) + ((dpt<<2) & 0x300) + 1; + + /* Cyls count, unchecked, only needs != 0, if AMI 386 bios can be + * upto 4096 cylinder, otherwise BIOS limit is 1024 cyl. + */ + } + } +#endif +} + +char * read_lsector(sectno) +long sectno; +{ + int tries; + int rv = 0; + + int phy_s = 1; + int phy_h = 0; + int phy_c = 0; + + long bstart; + + if( sectno == 0 || disk_heads == 0 ) reset_disk(); + if( disk_partition_offset > 0 ) sectno += disk_partition_offset; + + if( disk_spt < 1 || disk_heads < 1 ) + phy_s = sectno; + else + { + phy_s = sectno%disk_spt; + phy_h = sectno/disk_spt%disk_heads; + phy_c = sectno/disk_spt/disk_heads; + + bstart = (long)phy_c*disk_heads+phy_h; + if (disk_spt > MAXTRK) { + bstart = bstart * (disk_spt+MAXTRK-1)/MAXTRK; + buf_sec = phy_s/MAXTRK; + bstart = bstart + buf_sec; + buf_sec *= MAXTRK; + + if (disk_spt > buf_sec+MAXTRK) buf_len = MAXTRK; + else buf_len = disk_spt-buf_sec; + } else { + buf_sec = 0; + buf_len = disk_spt; + } + + if( bstart != buf_start && bstart != bad_start && buf_len > 1 ) + { + rv = _bios_disk_read(disk_drive,phy_c,phy_h,buf_sec+1,buf_len,buffer); + if( rv == 0 ) + buf_start = bstart; + else { + bad_start = bstart; + buf_start = -1; + } +#ifdef DEBUG + printf("Track read %d,%d,%d,%d,%d,%d -> %d\n", + disk_drive,phy_c,phy_h,buf_sec+1,buf_len,buffer, rv); +#endif + } + + if( bstart == buf_start ) + return buffer + (phy_s-buf_sec) * 512; + } + + tries = 6; + do + { + if( rv && tries<0) { + int v; + printf("Disk error 0x%02x %d:%d:%d:%d[%2d] -> 0x%04x[]\n", + rv, disk_drive, phy_c, phy_h, phy_s+1, 1, buffer); + printf("Retry ?"); v = (getch()&0x7F); printf("\n"); + if (v == 3 || v == 27 || v == 'n' || v == 'N') + return 0; + tries = 6; + } + + if (tries == 3) _bios_disk_reset(disk_drive); + + rv = _bios_disk_read(disk_drive, phy_c, phy_h, phy_s+1, 1, buffer); + tries--; + } + while(rv); +#ifdef DEBUG + printf("Sector read %d,%d,%d,%d,%d,%d -> %d\n", + disk_drive,phy_c,phy_h,phy_s+1,1,buffer, rv); +#endif + + if(rv) return 0; else return buffer; +} diff -Nurd linux86.vold/bootblocks/bzimage.c linux86/bootblocks/bzimage.c --- linux86.vold/bootblocks/bzimage.c 2000-06-18 19:55:44.000000000 +0100 +++ linux86/bootblocks/bzimage.c 2003-02-02 08:01:21.000000000 +0000 @@ -6,9 +6,13 @@ #define __MINI_MALLOC__ #include "monitor.h" +#define MAXRDPART 32 + int auto_flag = 1; -static char * initrd_name = 0; /* Name of init_ramdisk to load */ +/* Names of init_ramdisk files to load */ +static char *initrd_names[MAXRDPART]; +static int initrd_count = 0; static long initrd_start = 0; static long initrd_length = 0; static int vga_mode = -1; /* SVGA_MODE = normal */ @@ -21,7 +25,12 @@ static char * read_cmdfile(); static char * input_cmd(); -#define ZIMAGE_LOAD_SEG 0x10000 /* Segment that zImage data is loaded */ +/* ZIMAGE_LOAD_SEG: Segment that zImage data is loaded + * 0x10000 For largest possible zImage + * 0x1000 Normal load address, smallest monitor.sys + * 0x100 Largest zImage without using extended memory + */ +#define ZIMAGE_LOAD_SEG 0x10000 #define COMMAND_LINE_POS 0x4000 /* Offset in segment 0x9000 of command line */ static char * linux_command_line = 0; @@ -61,7 +70,7 @@ int low_sects; unsigned int address; - initrd_name = 0; + initrd_count = 0; initrd_start = initrd_length = 0; vga_mode = -1; is_zimage = 0; @@ -106,18 +115,16 @@ } if( main_mem_top < 3072 ) printf("RTFM warning: Linux needs at least 4MB of memory.\n"); - - len = (len+1023)/1024+1; /* Where to load the RD image (Mb) */ - if (len<6) len=6; /* Default to 6Mb mark */ - initrd_start = len * 4096; /* 256 bytes pages. */ #endif low_sects = buffer[497] + 1; /* setup sects + boot sector */ + if (low_sects == 1) low_sects = 5; image_length = (file_length()+511)/512 - low_sects; address = 0x900; #ifndef __ELKS__ #if ZIMAGE_LOAD_SEG == 0x10000 +#if 0 /* Don't warn about this limit, the format is old. */ if( is_zimage ) { if( image_length > 0x7FF0/32 ) @@ -127,11 +134,10 @@ return -1; } } +#endif #else if( is_zimage ) { - relocator(8); /* Need space in low memory */ - if( image_length > (__get_cs()>>5) - ZIMAGE_LOAD_SEG/32 ) { printf("This zImage file is too large, maximum is %dk bytes\n", @@ -154,11 +160,11 @@ printf("%dk to go \r", (int)(len/1024)); fflush(stdout); #ifndef NOCOMMAND - v = (bios_khit()&0x7F); + v = (kbhit()&0x7F); if( v == 3 || v == 27 ) { printf("User interrupt!\n"); - bios_getc(); + getch(); return -1; } #endif @@ -174,8 +180,11 @@ #endif for(v=0; v<1024; v+=512) { - if( putsect(buffer+v, address) < 0 ) + int rv; + if( (rv=mem_write(buffer+v, 0L, address/2, 1)) != 0 ) { + printf("Error 0x%02x while copying to extended memory\n", rv); return -1; + } address += 2; @@ -205,7 +214,7 @@ printf(" \r"); fflush(stdout); - if( initrd_name ) + if( initrd_count ) if( load_initrd(address) < 0 ) return -1; @@ -213,6 +222,7 @@ if( check_crc() < 0 && !keep_going() ) return -1; #endif +#ifndef NOMONITOR if( x86 < 3 || x86_emu ) { if( x86 < 3 ) @@ -221,6 +231,7 @@ printf("RTFM error: Linux-i386 cannot be run in an emulator.\n"); if( !keep_going() ) return -1; } +#endif printf("linux "); if( linux_command_line ) @@ -228,19 +239,6 @@ printf("\n"); fflush(stdout); - if( a20_closed() ) open_a20(); - if( a20_closed() ) - { - printf("Normal routine for opening A20 Gate failed, Trying PS/2 Bios\n"); - bios_open_a20(); - } - if( a20_closed() ) - { - printf("All routines for opening A20 Gate failed, if I can't open it\n"); - printf("then Linux probably can't either!\n"); - if( !keep_going() ) return -1; - } - __set_es(0x9000); /* Save pointer to command line */ @@ -274,7 +272,7 @@ #endif /* Tell the kernel where ramdisk is */ - if( initrd_name ) + if( initrd_count ) { __set_es(0x9000); @@ -286,7 +284,7 @@ } - if( !is_zimage || initrd_name ) + if( !is_zimage || initrd_count ) __poke_es(0x210, 0xFF); /* Patch setup to deactivate safety switch */ /* Set SVGA_MODE if not 'normal' */ @@ -332,84 +330,43 @@ { is_zimage = 0; - /* Boot sector magic number */ + /* Boot sector magic numbers */ if( *(unsigned short*)(image_buf+510) != 0xAA55 || - - /* Setup start */ - memcmp(image_buf+0x202, "HdrS", 4) != 0 || - - /* Setup version */ - *(unsigned short*)(image_buf+0x206) < 0x200 ) + memcmp(image_buf, "\270\300\007\216") != 0 ) { printf("File %s is not a linux Image file\n", fname); return -1; } - /* Code 32 start address for zImage */ - if( *(unsigned long*)(image_buf+0x214) == 0x1000 ) - { - printf("File %s is a zImage file\n", fname); - is_zimage = 1; - return 0; - } - else - /* Code 32 start address bzImage */ - if( *(unsigned long*)(image_buf+0x214) != 0x100000 ) - { - printf("File %s is a strange Image file\n", fname); - return -1; - } - printf("File %s is a bzImage file\n", fname); - - return 0; -} - -#ifndef __ELKS__ -putsect(put_buf, address) -char * put_buf; -unsigned int address; -{ - int rv, tc=3; - /* In real mode memory, just put it directly */ - if( address < 0xA00 ) - { - __movedata(__get_ds(), put_buf, address*16, 0, 512); - return 0; - } - -retry: - tc--; - - if( x86_test ) - return 0; /* In an EMU we can't write to high mem but - we'll pretend we can for debuggering */ - - if( (rv=ext_put(put_buf, address, 512)) != 0 ) + /* Setup start */ + if ( memcmp(image_buf+0x202, "HdrS", 4) == 0 && + /* Setup version */ + *(unsigned short*)(image_buf+0x206) >= 0x200 ) { - switch(rv) + /* Code 32 start address for zImage */ + if( *(unsigned long*)(image_buf+0x214) == 0x1000 ) { - case 1: - printf("Parity error while copying to extended memory\n"); - break; - case 2: - printf("Interrupt error while copying to extended memory\n"); - if ( tc>0 ) goto retry; - break; - case 3: - printf("BIOS cannot open A20 Gate\n"); - break; - case 0x80: case 0x86: - printf("BIOS has no extended memory support\n"); - break; - default: - printf("Error %d while copying to extended memory\n", rv); - break; + printf("File %s is a zImage file\n", fname); + is_zimage = 1; + return 0; + } + else + /* Code 32 start address bzImage */ + if( *(unsigned long*)(image_buf+0x214) == 0x100000 ) + { + printf("File %s is a bzImage file\n", fname); + return 0; } - return -1; } + + is_zimage = 1; + printf("File %s is an old Image file\n", fname); +#if ZIMAGE_LOAD_SEG == 0x10000 || ZIMAGE_LOAD_SEG == 0x1000 return 0; -} +#else + return -1; #endif +} static char * read_cmdfile(iname) @@ -495,8 +452,6 @@ char * free_cmd = 0, * cmd = 0; char * free_inp = 0; - image_name = strdup(image); - if( linux_command_line ) free(linux_command_line); linux_command_line = 0; @@ -516,7 +471,14 @@ free(ptr); } else if( inp == 0 ) + { inp = free_inp = input_cmd(image); + if( inp == 0 ) + { + printf("\nAborted\n"); + return -1; + } + } if( auto_flag ) len += strlen(auto_str) + 1; if( image ) len += strlen(image_str) + strlen(image) + 1; @@ -571,11 +533,11 @@ } else if( strncasecmp(s, "ramdisk_file=", 13) == 0 ) { - if( initrd_name ) free(initrd_name); - if( s[13] ) - initrd_name = strdup(s+13); - else - initrd_name = 0; + if (initrd_count >= MAXRDPART) { + printf("Too many ramdisk files\n"); + return -1; + } + initrd_names[initrd_count++] = strdup(s+13); } else if( strncasecmp(s, image_str, 11) == 0 ) { @@ -632,85 +594,84 @@ printf("Yes, Ok%s\n", burning?"":", burn baby burn!"); return burning=1; } -#ifdef NOCOMMAND - printf("No, Ok press enter to reboot\n"); -#else - printf("No, Ok returning to monitor prompt\n"); -#endif + printf("No\n"); return 0; } load_initrd(k_top) unsigned int k_top; { - unsigned int address, rd_start, rd_len; + char * fname; + long baseaddress; long file_len; - char * fname = initrd_name; + unsigned sectcount, sectno; + int fno; - /* Top of accessable memory */ - if( main_mem_top >= 15360 ) address = 0xFFFF; - else address = 0x1000 + main_mem_top*4; + initrd_length = 0; + baseaddress = (long)k_top * 256; - if( *initrd_name == '+' ) + for(fno = 0; fno 15000000L || k_top + rd_len*4 > address ) - { - printf("Ramdisk file %s is too large to load\n", fname); - return -1; - } + /* Move ramdisk to top of accessable memory. */ + baseaddress = (long)k_top * 256; - rd_start = address - rd_len*4; - rd_start &= -16; /* Page boundry */ - if (initrd_start && initrd_start= 15360 ) initrd_start = 0x1000000L; + else initrd_start = 0x100000 + main_mem_top*1024; - printf("Loading %s at 0x%x00\n", fname, rd_start); + sectcount = (initrd_length+511)/512; + initrd_start -= (long)sectcount *512; + initrd_start &= -4096; - for( ; rd_len>0 ; rd_len--) - { -#ifndef NOCOMMAND - int v = (bios_khit()&0x7F); - if( v == 3 || v == 27 ) - { - printf("User interrupt!\n"); - bios_getc(); - return -1; - } -#endif + printf("Moving ramdisk to 0x%06lx..0x%06lx, (%ld)\n", + initrd_start, initrd_start + initrd_length, initrd_length); - printf("%dk to go \r", rd_len); fflush(stdout); - if( read_block(buffer) < 0 ) + while(sectcount>0) { + sectcount--; + if ( mem_read(buffer, baseaddress, sectcount) != 0 || + mem_write(buffer, initrd_start, sectcount, 1) != 0) { - printf("Read error loading ramdisk\n"); + printf("Error moving ramdisk\n"); return -1; } - if( putsect(buffer, address) < 0 ) return -1; - address+=2; - if( putsect(buffer+512, address) < 0 ) return -1; - address+=2; } - printf(" \r"); fflush(stdout); - - close_file(); - - initrd_start = ((long) rd_start <<8); - initrd_length = file_len; return 0; } @@ -727,19 +688,15 @@ __movedata(address*16, 0, __get_ds(), buffer, 512); low_sects = buffer[497] + 1; /* setup sects + boot sector */ + if (low_sects == 1) low_sects = 5; for(len=image_size; len>0; len-=512) { - if( address >= 0xA00 ) + if (mem_read(buffer, 0L, address/2) != 0) { - if( ext_get(address, buffer, 512) != 0 ) - { - printf("Unable to read back for CRC check\n"); - return; - } + printf("Unable to read back for CRC check\n"); + return; } - else - __movedata(address*16, 0, __get_ds(), buffer, 512); if( len > 512 ) addcrc(buffer, 512); else addcrc(buffer, (int)len); diff -Nurd linux86.vold/bootblocks/com_bcc.s linux86/bootblocks/com_bcc.s --- linux86.vold/bootblocks/com_bcc.s 1996-11-30 12:55:56.000000000 +0000 +++ linux86/bootblocks/com_bcc.s 1970-01-01 01:00:00.000000000 +0100 @@ -1,65 +0,0 @@ - -! This header assumes only that we're loaded at a 16 byte boundry - -ENDOFF=4 ! If you add code adjust this till it stops failing. - -org 0 -entry start -public start -start: - call chk ! This chunk allows this code to exist at _any_ click -chk: - pop ax - mov cl,#4 - shr ax,cl - mov bx,cs - add ax,bx - push ax - mov bx,#going - push bx - retf -going: - mov ds,ax - - add ax,#ENDOFF+2 ! New CS - mov bx,ax ! Saved - mov dx,[a_entry] ! Save the entry - zero - mov ax,[btype] - and ax,#$20 ! Split I/D ? - jz impure - mov cl,#4 - mov ax,[a_text] - shr ax,cl -impure: ! ax is now offset 'tween CS&DS - add ax,bx ! ax = DS - mov ss,ax - mov sp,[a_total] ! SS:SP is now ready for prog. - mov ds,ax - xor cx,cx ! argc, argv and envp = 0 - push cx - push cx - push cx - push bx ! CS - push dx ! Entry address - retf ! Gone. - -! Check for overlap -end_of_code: - if end_of_code>hitme - fail! At end_of_code - endif - -.org ((ENDOFF)<<4)-1 -hitme: -.byte 0xFF ! Marker - -magic: .space 2 ! A.out header -btype: .space 2 -headerlen: .space 4 -a_text: .space 4 -a_data: .space 4 -a_bss: .space 4 -a_entry: .space 4 -a_total: .space 4 -a_syms: .space 4 -.org (ENDOFF+2)<<4 ! Code start. diff -Nurd linux86.vold/bootblocks/commands.c linux86/bootblocks/commands.c --- linux86.vold/bootblocks/commands.c 1998-08-27 19:48:33.000000000 +0100 +++ linux86/bootblocks/commands.c 2002-02-10 11:26:52.000000000 +0000 @@ -155,6 +155,7 @@ printf(": AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x", __argr.x.ax, __argr.x.bx, __argr.x.cx, __argr.x.dx, __argr.x.si, __argr.x.di); + printf(" CF=%x", __argr.x.cflag); printf(" CS=%04x DS=%04x ES=%04x\n", __get_cs(), __get_ds(), __get_es()); #else printf("Only in standalone\n"); diff -Nurd linux86.vold/bootblocks/cprintf.c linux86/bootblocks/cprintf.c --- linux86.vold/bootblocks/cprintf.c 2000-01-29 15:23:44.000000000 +0000 +++ linux86/bootblocks/cprintf.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,150 +0,0 @@ - -#include - -static unsigned char * __numout(long i, int base); - -cputchar(ch) -int ch; -{ - if(ch == '\n') bios_putc('\r'); - return bios_putc(ch); -} - -cprintf(char * fmt, ...) -{ - register int c; - int count = 0; - int type, base; - long val; - char * cp; - char padch=' '; - int minsize, maxsize; - va_list ap; - - va_start(ap, fmt); - - while(c=*fmt++) - { - count++; - if(c!='%') - cputchar(c); - else - { - type=1; - padch = *fmt; - maxsize=minsize=0; - if(padch == '-') fmt++; - - for(;;) - { - c=*fmt++; - if( c<'0' || c>'9' ) break; - minsize*=10; minsize+=c-'0'; - } - - if( c == '.' ) - for(;;) - { - c=*fmt++; - if( c<'0' || c>'9' ) break; - maxsize*=10; maxsize+=c-'0'; - } - - if( padch == '-' ) minsize = -minsize; - else - if( padch == '0' ) padch='0'; else padch=' '; - - if( c == 0 ) break; - if(c=='h') - { - c=*fmt++; - type = 0; - } - else if(c=='l') - { - c=*fmt++; - type = 2; - } - - switch(c) - { - case 'x': base=16; type |= 4; if(0) { - case 'o': base= 8; type |= 4; } if(0) { - case 'u': base=10; type |= 4; } if(0) { - case 'd': base=10; } - switch(type) - { - case 0: val=va_arg(ap, short); break; - case 1: val=va_arg(ap, int); break; - case 2: val=va_arg(ap, long); break; - case 4: val=va_arg(ap, unsigned short); break; - case 5: val=va_arg(ap, unsigned int); break; - case 6: val=va_arg(ap, unsigned long); break; - default:val=0; break; - } - cp = __numout(val,base); - if(0) { - case 's': - cp=va_arg(ap, char *); - } - count--; - c = strlen(cp); - if( !maxsize ) maxsize = c; - if( minsize > 0 ) - { - minsize -= c; - while(minsize>0) { cputchar(padch); count++; minsize--; } - minsize=0; - } - if( minsize < 0 ) minsize= -minsize-c; - while(*cp && maxsize-->0 ) - { - cputchar(*cp++); - count++; - } - while(minsize>0) { cputchar(' '); count++; minsize--; } - break; - case 'c': - cputchar(va_arg(ap, int)); - break; - default: - cputchar(c); - break; - } - } - } - va_end(ap); - return count; -} - -static char nstring[]="0123456789ABCDEF"; - -static unsigned char * -__numout(long i, int base) -{ - static unsigned char out[16]; - int n; - int flg = 0; - unsigned long val; - - if (i<0 && base==10) - { - flg = 1; - i = -i; - } - val = i; - - for (n = 0; n < 15; n++) - out[n] = ' '; - out[15] = '\0'; - n = 14; - do - { - out[n] = nstring[val % base]; - n--; - val /= base; - } - while(val); - if(flg) out[n--] = '-'; - return &out[n+1]; -} diff -Nurd linux86.vold/bootblocks/crc.c linux86/bootblocks/crc.c --- linux86.vold/bootblocks/crc.c 1998-03-19 07:01:39.000000000 +0000 +++ linux86/bootblocks/crc.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,216 +0,0 @@ - -#include - -/* crctab calculated by Mark G. Mendel, Network Systems Corporation */ -static unsigned short crctab[256] = { - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, - 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, - 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, - 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, - 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, - 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, - 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, - 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, - 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, - 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, - 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, - 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, - 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, - 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, - 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, - 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, - 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, - 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, - 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, - 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, - 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, - 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, - 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, - 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, - 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 -}; - -/* - * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. - * NOTE: First srgument must be in range 0 to 255. - * Second argument is referenced twice. - * - * Programmers may incorporate any or all code into their programs, - * giving proper credit within the source. Publication of the - * source routines is permitted so long as proper credit is given - * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, - * Omen Technology. - */ - -#define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp) - -/* - * Copyright (C) 1986 Gary S. Brown. You may use this program, or - * code or tables extracted from it, as desired without restriction. - */ - -/* First, the polynomial itself and its table of feedback terms. The */ -/* polynomial is */ -/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */ -/* Note that we take it "backwards" and put the highest-order term in */ -/* the lowest-order bit. The X^32 term is "implied"; the LSB is the */ -/* X^31 term, etc. The X^0 term (usually shown as "+1") results in */ -/* the MSB being 1. */ - -/* Note that the usual hardware shift register implementation, which */ -/* is what we're using (we're merely optimizing it by doing eight-bit */ -/* chunks at a time) shifts bits into the lowest-order term. In our */ -/* implementation, that means shifting towards the right. Why do we */ -/* do it this way? Because the calculated CRC must be transmitted in */ -/* order from highest-order term to lowest-order term. UARTs transmit */ -/* characters in order from LSB to MSB. By storing the CRC this way, */ -/* we hand it to the UART in the order low-byte to high-byte; the UART */ -/* sends each low-bit to hight-bit; and the result is transmission bit */ -/* by bit from highest- to lowest-order term without requiring any bit */ -/* shuffling on our part. Reception works similarly. */ - -/* The feedback terms table consists of 256, 32-bit entries. Notes: */ -/* */ -/* The table can be generated at runtime if desired; code to do so */ -/* is shown later. It might not be obvious, but the feedback */ -/* terms simply represent the results of eight shift/xor opera- */ -/* tions for all combinations of data and CRC register values. */ -/* */ -/* The values must be right-shifted by eight bits by the "updcrc" */ -/* logic; the shift must be unsigned (bring in zeroes). On some */ -/* hardware you could probably optimize the shift in assembler by */ -/* using byte-swap instructions. */ - -static long cr3tab[] = { /* CRC polynomial 0xedb88320 */ -0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, -0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, -0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, -0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, -0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, -0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, -0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, -0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, -0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, -0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, -0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, -0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, -0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, -0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, -0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, -0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, -0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, -0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, -0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, -0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, -0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, -0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, -0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, -0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, -0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, -0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, -0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, -0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, -0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, -0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, -0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, -0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d -}; - -#define UPDC32(b, c) (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF)) - -int skip = 0; -int do_16 = 0; -int do_hex = 0; - -main(argc, argv) -int argc; -char ** argv; -{ - int ar; - int done = 0; - for(ar=1; ar= skip ) - { - crc = updcrc(ch, crc); - crc32 = UPDC32(ch, crc32); - } - count++; - } - fclose(fd); - crc32 ^= 0xFFFFFFFF; - - printf("%-14s: %6ld CRC32=0x%08lx (%10lu)", fname, count, crc32, crc32); - printf(" CRC16=0x%04lx (%5u)\n", crc, crc); - -/* - if(do_hex) - { - if(do_16) - printf("%-14s:\t%6ld %04x\n", fname, count, crc); - else - printf("%-14s:\t%6ld %08lx\n", fname, count, crc32); - } - else - { - if(do_16) - printf("%-14s:\t%6ld %5u\n", fname, count, crc); - else - printf("%-14s:\t%6ld %10lu\n", fname, count, crc32); - } -*/ - fflush(stdout); -} - diff -Nurd linux86.vold/bootblocks/elf_info.c linux86/bootblocks/elf_info.c --- linux86.vold/bootblocks/elf_info.c 1996-06-30 15:54:26.000000000 +0100 +++ linux86/bootblocks/elf_info.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,189 +0,0 @@ - -#include -#include "elf_info.h" - -Elf32_Ehdr elf_head; -Elf32_Phdr *elf_prog; - -#ifdef TEST -FILE *ifd; - -main(argc, argv) -int argc; -char **argv; -{ - ifd = fopen(argv[1], "r"); - if (ifd == 0) - exit(1); - - read_elfprog(); - write_ram("", -1L, 0); - - fclose(ifd); -} - -read_file(buf, offset, len) -void *buf; -long offset; -int len; -{ - fseek(ifd, offset, 0); - return fread(buf, 1, len, ifd); -} - -write_ram(buf, linear, len) -char *buf; -long linear; -int len; -{ -static long llen = 0; -static long lastlin= -1; - - if( llen > 0 && lastlin + llen != linear ) - { - printf("for %8ld bytes\n", llen); - lastlin= -1; - } - if( lastlin == -1 ) - { - lastlin = linear; - llen = 0; - - if( linear != -1 ) - printf("Write %08lx ", linear); - } - llen += len; - return len; -} - -error(str) -char *str; -{ - printf("Error: %s\n", str); - return -1; -} -#endif - -info_elf() -{ - int i; - - printf("ELF-386 executable, entry = 0x%08lx\n", elf_head.e_entry); - printf("\t\toffset paddr vaddr filesz memsz align\n"); - for (i = 0; i < elf_head.e_phnum; i++) - { - printf(" %d: ", i); - switch ((int) elf_prog[i].p_type) - { - case PT_NULL: - printf("PT_NULL"); - break; - case PT_LOAD: - printf("PT_LOAD"); - break; - case PT_DYNAMIC: - printf("PT_DYNAMIC"); - break; - case PT_INTERP: - printf("PT_INTERP"); - break; - case PT_NOTE: - printf("PT_NOTE"); - break; - case PT_SHLIB: - printf("PT_SHLIB"); - break; - case PT_PHDR: - printf("PT_PHDR"); - break; - default: - printf("PT_(%d)", elf_prog[i].p_type); - break; - } - printf("\t%08lx %08lx %08lx %08lx %08lx %08lx", - elf_prog[i].p_offset, - elf_prog[i].p_paddr, - elf_prog[i].p_vaddr, - elf_prog[i].p_filesz, - elf_prog[i].p_memsz, - elf_prog[i].p_align - ); - printf("\n"); - } -} - -read_elfprog() -{ - static unsigned char elf_ok[] = - {ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, ELFCLASS32, ELFDATA2LSB, EV_CURRENT}; - - int i; - char page_buf[4096]; - - if (read_file(&elf_head, 0L, sizeof(elf_head)) != sizeof(elf_head)) - return error("Can't read ELF header"); - - if (memcmp(elf_head.e_ident, elf_ok, 7) != 0 || - elf_head.e_type != ET_EXEC || - elf_head.e_machine != EM_386 || - elf_head.e_phnum <= 0 || - elf_head.e_phentsize != sizeof(Elf32_Phdr) - ) - return error("Not a 386 executable ELF program"); - - elf_prog = malloc(i = sizeof(Elf32_Phdr) * elf_head.e_phnum); - if (elf_prog == 0) - return error("Out of memory"); - - if (read_file(elf_prog, elf_head.e_phoff, i) != i) - return error("Can't read ELF program header"); - - info_elf(); - - for (i = 0; i < elf_head.e_phnum; i++) - { - long from, to, length, copied; - int chunk; - - switch ((int) elf_prog[i].p_type) - { - case PT_NULL: - case PT_NOTE: - continue; - default: - return error("ELF: Unusable program segment (Must be static)"); - case PT_LOAD: - break; - } - from=elf_prog[i].p_offset; - to=elf_prog[i].p_vaddr; - length=elf_prog[i].p_filesz; - - for(copied=0; copiedcopied+sizeof(page_buf)) chunk=sizeof(page_buf); - else chunk=length-copied; - - if( (chunk=read_file(page_buf, from, chunk)) <= 0 ) - return error("ELF Cannot read executable"); - if( write_ram(page_buf, to, chunk) < 0 ) - return error("Memory save failed"); - copied+=chunk; from+=chunk; to+=chunk; - } - length=elf_prog[i].p_memsz; - if( length > copied ) - { - write_ram("", -1L, 0); - memset(page_buf, '\0', sizeof(page_buf)); - for(; copiedcopied+sizeof(page_buf)) chunk=sizeof(page_buf); - else chunk=length-copied; - - if( write_ram(page_buf, to, chunk) < 0 ) - return error("Memory zap failed"); - copied+=chunk; to+=chunk; - } - } - } -} diff -Nurd linux86.vold/bootblocks/elf_info.h linux86/bootblocks/elf_info.h --- linux86.vold/bootblocks/elf_info.h 1996-06-15 12:14:30.000000000 +0100 +++ linux86/bootblocks/elf_info.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,282 +0,0 @@ - -/* ELF layout information */ - -/* NOTE: I'm copying the file format information here because the _format_ - * is standard, but the Linux header files are not and may depend on - * headers not available when compiling Linux-86 code. - */ - -#ifndef _LINUX_ELF_H -#define _LINUX_ELF_H - -typedef unsigned long Elf32_Addr; -typedef unsigned short Elf32_Half; -typedef unsigned long Elf32_Off; -typedef long Elf32_Sword; -typedef unsigned long Elf32_Word; - -/* These constants are for the segment types stored in the image headers */ -#define PT_NULL 0 -#define PT_LOAD 1 -#define PT_DYNAMIC 2 -#define PT_INTERP 3 -#define PT_NOTE 4 -#define PT_SHLIB 5 -#define PT_PHDR 6 -#define PT_LOPROC 0x70000000L -#define PT_HIPROC 0x7fffffffL - -/* These constants define the different elf file types */ -#define ET_NONE 0 -#define ET_REL 1 -#define ET_EXEC 2 -#define ET_DYN 3 -#define ET_CORE 4 -#define ET_LOPROC 5 -#define ET_HIPROC 6 - -/* These constants define the various ELF target machines */ -#define EM_NONE 0 -#define EM_M32 1 -#define EM_SPARC 2 -#define EM_386 3 -#define EM_68K 4 -#define EM_88K 5 -#define EM_486 6 /* Perhaps disused */ -#define EM_860 7 - -/* This is the info that is needed to parse the dynamic section of the file */ -#define DT_NULL 0 -#define DT_NEEDED 1 -#define DT_PLTRELSZ 2 -#define DT_PLTGOT 3 -#define DT_HASH 4 -#define DT_STRTAB 5 -#define DT_SYMTAB 6 -#define DT_RELA 7 -#define DT_RELASZ 8 -#define DT_RELAENT 9 -#define DT_STRSZ 10 -#define DT_SYMENT 11 -#define DT_INIT 12 -#define DT_FINI 13 -#define DT_SONAME 14 -#define DT_RPATH 15 -#define DT_SYMBOLIC 16 -#define DT_REL 17 -#define DT_RELSZ 18 -#define DT_RELENT 19 -#define DT_PLTREL 20 -#define DT_DEBUG 21 -#define DT_TEXTREL 22 -#define DT_JMPREL 23 -#define DT_LOPROC 0x70000000L -#define DT_HIPROC 0x7fffffffL - -/* This info is needed when parsing the symbol table */ -#define STB_LOCAL 0 -#define STB_GLOBAL 1 -#define STB_WEAK 2 - -#define STT_NOTYPE 0 -#define STT_OBJECT 1 -#define STT_FUNC 2 -#define STT_SECTION 3 -#define STT_FILE 4 - -#define ELF32_ST_BIND(x) ((x) >> 4) -#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf) - -/* Symbolic values for the entries in the auxiliary table - put on the initial stack */ -#define AT_NULL 0 /* end of vector */ -#define AT_IGNORE 1 /* entry should be ignored */ -#define AT_EXECFD 2 /* file descriptor of program */ -#define AT_PHDR 3 /* program headers for program */ -#define AT_PHENT 4 /* size of program header entry */ -#define AT_PHNUM 5 /* number of program headers */ -#define AT_PAGESZ 6 /* system page size */ -#define AT_BASE 7 /* base address of interpreter */ -#define AT_FLAGS 8 /* flags */ -#define AT_ENTRY 9 /* entry point of program */ -#define AT_NOTELF 10 /* program is not ELF */ -#define AT_UID 11 /* real uid */ -#define AT_EUID 12 /* effective uid */ -#define AT_GID 13 /* real gid */ -#define AT_EGID 14 /* effective gid */ - - -typedef struct dynamic{ - Elf32_Sword d_tag; - union{ - Elf32_Sword d_val; - Elf32_Addr d_ptr; - } d_un; -} Elf32_Dyn; - -extern Elf32_Dyn _DYNAMIC []; - -/* The following are used with relocations */ -#define ELF32_R_SYM(x) ((x) >> 8) -#define ELF32_R_TYPE(x) ((x) & 0xff) - -#define R_386_NONE 0 -#define R_386_32 1 -#define R_386_PC32 2 -#define R_386_GOT32 3 -#define R_386_PLT32 4 -#define R_386_COPY 5 -#define R_386_GLOB_DAT 6 -#define R_386_JMP_SLOT 7 -#define R_386_RELATIVE 8 -#define R_386_GOTOFF 9 -#define R_386_GOTPC 10 -#define R_386_NUM 11 - -typedef struct elf32_rel { - Elf32_Addr r_offset; - Elf32_Word r_info; -} Elf32_Rel; - -typedef struct elf32_rela{ - Elf32_Addr r_offset; - Elf32_Word r_info; - Elf32_Sword r_addend; -} Elf32_Rela; - -typedef struct elf32_sym{ - Elf32_Word st_name; - Elf32_Addr st_value; - Elf32_Word st_size; - unsigned char st_info; - unsigned char st_other; - Elf32_Half st_shndx; -} Elf32_Sym; - - -#define EI_NIDENT 16 - -typedef struct elfhdr{ - unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; /* Entry point */ - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; -} Elf32_Ehdr; - -/* These constants define the permissions on sections in the program - header, p_flags. */ -#define PF_R 0x4 -#define PF_W 0x2 -#define PF_X 0x1 - -typedef struct elf_phdr{ - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; -} Elf32_Phdr; - -/* sh_type */ -#define SHT_NULL 0 -#define SHT_PROGBITS 1 -#define SHT_SYMTAB 2 -#define SHT_STRTAB 3 -#define SHT_RELA 4 -#define SHT_HASH 5 -#define SHT_DYNAMIC 6 -#define SHT_NOTE 7 -#define SHT_NOBITS 8 -#define SHT_REL 9 -#define SHT_SHLIB 10 -#define SHT_DYNSYM 11 -#define SHT_NUM 12 -#define SHT_LOPROC 0x70000000L -#define SHT_HIPROC 0x7fffffffL -#define SHT_LOUSER 0x80000000L -#define SHT_HIUSER 0xffffffffL - -/* sh_flags */ -#define SHF_WRITE 0x1 -#define SHF_ALLOC 0x2 -#define SHF_EXECINSTR 0x4 -#define SHF_MASKPROC 0xf0000000L - -/* special section indexes */ -#define SHN_UNDEF 0 -#define SHN_LORESERVE 0xff00L -#define SHN_LOPROC 0xff00L -#define SHN_HIPROC 0xff1fL -#define SHN_ABS 0xfff1L -#define SHN_COMMON 0xfff2L -#define SHN_HIRESERVE 0xffffL - -typedef struct { - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; -} Elf32_Shdr; - -#define EI_MAG0 0 /* e_ident[] indexes */ -#define EI_MAG1 1 -#define EI_MAG2 2 -#define EI_MAG3 3 -#define EI_CLASS 4 -#define EI_DATA 5 -#define EI_VERSION 6 -#define EI_PAD 7 - -#define ELFMAG0 0x7f /* EI_MAG */ -#define ELFMAG1 'E' -#define ELFMAG2 'L' -#define ELFMAG3 'F' -#define ELFMAG "\177ELF" -#define SELFMAG 4 - -#define ELFCLASSNONE 0 /* EI_CLASS */ -#define ELFCLASS32 1 -#define ELFCLASS64 2 -#define ELFCLASSNUM 3 - -#define ELFDATANONE 0 /* e_ident[EI_DATA] */ -#define ELFDATA2LSB 1 -#define ELFDATA2MSB 2 - -#define EV_NONE 0 /* e_version, EI_VERSION */ -#define EV_CURRENT 1 -#define EV_NUM 2 - -/* Notes used in ET_CORE */ -#define NT_PRSTATUS 1 -#define NT_PRFPREG 2 -#define NT_PRPSINFO 3 -#define NT_TASKSTRUCT 4 - -/* Note header in a PT_NOTE section */ -typedef struct elf_note { - Elf32_Word n_namesz; /* Name size */ - Elf32_Word n_descsz; /* Content size */ - Elf32_Word n_type; /* Content type */ -} Elf32_Nhdr; - -#endif /* _LINUX_ELF_H */ diff -Nurd linux86.vold/bootblocks/fs.c linux86/bootblocks/fs.c --- linux86.vold/bootblocks/fs.c 1999-05-27 17:36:51.000000000 +0100 +++ linux86/bootblocks/fs.c 2003-02-01 13:15:08.000000000 +0000 @@ -13,6 +13,9 @@ #endif if( fs_type ) close_file(); + /* If we can't read the boot sector there is a _real_ problem */ + if (read_sector(0) == 0) return -1; + if( tar_open_file(fname) >= 0 ) { fs_type = 1; return 0; } if( min_open_file(fname) >= 0 ) { fs_type = 2; return 0; } if( dos_open_file(fname) >= 0 ) { fs_type = 3; return 0; } diff -Nurd linux86.vold/bootblocks/fs_tar.c linux86/bootblocks/fs_tar.c --- linux86.vold/bootblocks/fs_tar.c 1999-05-27 17:15:54.000000000 +0100 +++ linux86/bootblocks/fs_tar.c 2002-02-10 12:32:39.000000000 +0000 @@ -168,7 +168,7 @@ { printf("Please insert next disk and press return:"); fflush(stdout); - while( (k=(bios_getc() & 0x7F)) != '\r' && k != '\n') + while( (k=(getch() & 0x7F)) != '\r' && k != '\n') if( k == 27 || k == 3 ) { printf("... Aborting\n"); diff -Nurd linux86.vold/bootblocks/i86_funcs.c linux86/bootblocks/i86_funcs.c --- linux86.vold/bootblocks/i86_funcs.c 1998-12-29 10:04:18.000000000 +0000 +++ linux86/bootblocks/i86_funcs.c 2003-02-01 10:48:36.000000000 +0000 @@ -1,77 +1,21 @@ #include "monitor.h" -int x86 = 0; /* CPU major number */ +#ifndef NOMONITOR +int x86 = 3; /* CPU major number */ char *x86_name = ""; /* and it's name */ int x86_emu = 0; /* Is this a PC emulator ? */ -int x86_a20_closed = 1; /* Is the A20 gate closed ? */ int x86_fpu = 0; +#endif int x86_test = 0; /* In test mode */ unsigned boot_mem_top = 0x2000; /* Default 128k, the minimum */ long main_mem_top = 0; /* K of extended memory */ -int a20_closed() -{ - register int v, rv = 0; - if (x86_test) return 1; /* If not standalone don't try */ - - __set_es(0); - v = __peek_es(512); - __set_es(0xFFFF); - if (v == __peek_es(512+16)) - { - __set_es(0); - __poke_es(512, v+1); - __set_es(0xFFFF); - if (v+1 == __peek_es(512+16)) - rv = 1; - __set_es(0); - __poke_es(512, v); - } - return x86_a20_closed = rv; -} - -static void asm_open_a20() -{ -#asm - call empty_8042 - mov al,#0xD1 ! command write - out #0x64,al - call empty_8042 - mov al,#0xDF ! A20 on - out #0x60,al -empty_8042: - .word 0x00eb,0x00eb - in al,#0x64 ! 8042 status port - test al,#2 ! is input buffer full? - jnz empty_8042 ! yes - loop, with no timeout! -#endasm -} - -void open_a20() { if(!x86_test) asm_open_a20(); } - -/* This calls the BIOS to open the A20 gate, officially this is only supported - on PS/2s but if the normal routine fails we may as well try this. - */ -void asm_bios_open_a20() -{ -#asm - mov ax,#$2401 - int $15 - jc bios_failed_a20 - xor ax,ax -bios_failed_a20: - mov al,ah - xor ah,ah -#endasm -} - -void bios_open_a20() { if(!x86_test) asm_bios_open_a20(); } - void cpu_check() { +#ifndef NOMONITOR static char *name_808x[] = { "8088", "8086", "80C88", "80C86", "NEC V20", "NEC V30", "808x Clone" @@ -107,8 +51,14 @@ if (c & 0x01) x86_emu = 1; /* Already in protected mode !!! */ } -#ifdef __STANDALONE__ x86_test = x86_emu; + if (x86<3) + x86_test = 1; +#endif + +#ifdef __STANDALONE__ + if (__argr.x.cflag) + x86_test = 1; #else x86_test = 1; #endif @@ -116,39 +66,82 @@ void mem_check() { -#ifndef __STANDALONE__ - main_mem_top = 16384; - return; /* If not standalone don't try */ -#else - { + if (x86_test) { + main_mem_top = 0; + return; + } + #asm int 0x12 ! Amount of boot memory mov cl,#6 sal ax,cl ! In segments mov [_boot_mem_top],ax - ! Next check for extended - mov al,[_x86] ! If we ain't got a 286+ we can't access it anyway - cmp al,#2 - jl is_xt - - mov ah,#0x88 ! + mov ah,#0x88 ! Next check for extended int 0x15 - jnc got_ext ! Error!? This should _not_ happen ... but ... + jnc got_ext ! Error! is_xt: xor ax,ax got_ext: mov word ptr [_main_mem_top+2],#0 mov [_main_mem_top],ax +#endasm + /* Try int $15 EAX=$E820 */ + { + struct e820_dat { + unsigned long base_lo, base_hi; + unsigned long len_lo, len_hi; + long addr_type; + } e820_item; + long epoll = 0; + + do + { + e820_item.addr_type = 0; +#asm + mov eax,#$E820 + mov ebx,.mem_check.epoll[bp] + mov ecx,#20 + mov edx,#$534D4150 + push ds + pop es + lea di,.mem_check.e820_item[bp] + int $15 + jnc got_e820 + xor ebx,ebx +got_e820: + mov .mem_check.epoll[bp],ebx #endasm - } + if (e820_item.addr_type == 1 + && e820_item.base_hi == 0 + && e820_item.base_lo == 0x100000L) + { + /* XXX Later ... */ + if (e820_item.len_hi) main_mem_top = 0x40000; + else + main_mem_top = (e820_item.len_lo >> 10); + return; + } + } + while(epoll); + } - if( main_mem_top == 0xFFFFL ) - { - /* It say 64Mb-1k - Hmmmm I think it might be 128! */ - } -#endif + /* Try int $15 EAX=$E801 */ + { + unsigned int mem_64, mem_16; /* For int $15,AX=$E801 */ +#asm + mov ax,#$E801 + int $15 + jc no_e801 + mov .mem_check.mem_16[bp],ax + mov .mem_check.mem_64[bp],bx +#endasm + main_mem_top = ((unsigned long)mem_64<<6) + mem_16; +#asm +no_e801: +#endasm + } } #define RIGHTS (0x93000000L) @@ -171,26 +164,40 @@ "" }; -ext_put(from, to, length) -unsigned int from, to, length; +mem_write(buffer, baseaddr, sectno, sectcount) +void * buffer; +long baseaddr; +unsigned sectno, sectcount; { - if(x86_test) return 3; - GDT.src_seg = RIGHTS + from + ((long)__get_ds()<<4); - GDT.dst_seg = RIGHTS + ((long)to<<8); - if( length == 0xFFFF ) length = 0x8000; - else length = ((length+1)>>1); - return asm_copy(length); + if(x86_test) return 0; + /* In an EMU we can't write to high mem but + we'll pretend we can for debuggering */ + + baseaddr += ((long)sectno<<9); + if( baseaddr < 0xA0000L ) + { + __movedata(__get_ds(), buffer, + (unsigned)(baseaddr>>4), (unsigned)(baseaddr&0xF), + sectcount * 512); + return 0; + } + + GDT.src_seg = RIGHTS + (unsigned)buffer + ((long)__get_ds()<<4); + GDT.dst_seg = RIGHTS + baseaddr; + return asm_copy(sectcount << 8); } -ext_get(from, to, length) -unsigned int from, to, length; +mem_read(buffer, baseaddr, sectno) +void * buffer; +long baseaddr; +int sectno; { if(x86_test) return 3; - GDT.src_seg = RIGHTS + ((long)from<<8); - GDT.dst_seg = RIGHTS + to + ((long)__get_ds()<<4); - if( length == 0xFFFF ) length = 0x8000; - else length = ((length+1)>>1); - return asm_copy(length); + baseaddr += ((long)sectno<<9); + + GDT.dst_seg = RIGHTS + (unsigned)buffer + ((long)__get_ds()<<4); + GDT.src_seg = RIGHTS + baseaddr; + return asm_copy(256); } static asm_copy(length) diff -Nurd linux86.vold/bootblocks/i86_funcs.h linux86/bootblocks/i86_funcs.h --- linux86.vold/bootblocks/i86_funcs.h 1998-07-24 15:58:05.000000000 +0100 +++ linux86/bootblocks/i86_funcs.h 2002-05-26 14:33:22.000000000 +0100 @@ -5,16 +5,12 @@ extern int x86; /* CPU major number (0-3) */ extern char *x86_name; /* and it's name */ extern int x86_emu; /* Is this a PC emulator ? */ -extern int x86_a20_closed; /* Is the A20 gate closed ? */ extern int x86_fpu; extern int x86_test; /* Running in test mode ? */ extern unsigned boot_mem_top; /* Top of RAM below 1M */ extern long main_mem_top; /* Top of RAM above 1M */ -int a20_closed(); -void open_a20(); -void bios_open_a20(); void cpu_check(); void mem_check(); int ext_put(); diff -Nurd linux86.vold/bootblocks/killhd.s linux86/bootblocks/killhd.s --- linux86.vold/bootblocks/killhd.s 1970-01-01 01:00:00.000000000 +0100 +++ linux86/bootblocks/killhd.s 2003-05-20 12:05:23.000000000 +0100 @@ -0,0 +1,64 @@ +! +! This program destroys the MBR and the start of the first partition of +! the hard disk. IT DOES NOT HAVE AN 'ARE YOU SURE?' +! + +org $7c00 + +include sysboot.s + +org dos_sysid + .ascii "DEATH" ! System ID + + org codestart + + cld + xor ax,ax + mov es,ax + mov ds,ax + mov ss,ax + mov sp,ax + + mov di,#$8000 + mov cx,#$0800 + rep + stosw ! Zap a space. + + mov dx,#$0080 + mov cx,#$0001 + mov bx,#$8000 + mov ax,#$0308 + int $13 ! Zap the MBR (and a disk manager?) + + mov dx,#$0180 + mov cx,#$0001 + mov bx,#$8000 + mov ax,#$0308 + int $13 ! Zap the first partition boot and super. + +!---------------------------------------------------------------- + +prtmsg: ! SI = pointer to error message + mov si,#boot_message + +nextc: + lodsb + cmp al,#0 + jz eos + mov bx,#7 + mov ah,#$E ! Can't use $13 cause that's AT+ only! + int $10 + jmp nextc + +!---------------------------------------------------------------- + +eos: ! Wait for a key then reboot +reboot: + xor ax,ax + int $16 + jmpi $0,$FFFF ! Wam! Try or die! + +export boot_message +boot_message: + .asciz "PANIC! OS Destroyed!\r\n" + diff -Nurd linux86.vold/bootblocks/li86.s linux86/bootblocks/li86.s --- linux86.vold/bootblocks/li86.s 2001-05-12 09:01:21.000000000 +0100 +++ linux86/bootblocks/li86.s 1970-01-01 01:00:00.000000000 +0100 @@ -1,47 +0,0 @@ -!---------------------------------------------------------------------------- -! -! This is a skeleton for creating an impure Linux-8086 executable without -! using the linker. The .text and .data areas are correctly positioned. -! -! This file needs to be compiled using the 3 pass mode (-O) -! eg: as86 -O li86.s -s li86.sym -b li86.bin -! -!---------------------------------------------------------------------------- -.text -org -32 -.word 0x0301 ! Magic -.word 0x0410 ! Btype -.long 0x20 ! header length -.long _etext ! a_text -.long _edata-_etext ! a_data -.long 0 ! a_bss -.long 0 ! a_entry -.long STACK_SIZE ! a_total -.long 0 ! a_syms -.data -.blkb _etext -.even -.text -!---------------------------------------------------------------------------- - -STACK_SIZE = 0x10000 - -.data -var: -.word $1234 - -.text - int $20 - mov ax,var - mov bx,_edata - push ax - ret - -!---------------------------------------------------------------------------- -! This trailer must be at the end of the file. -.text -_etext: -.data -_edata: -END - diff -Nurd linux86.vold/bootblocks/makeboot.c linux86/bootblocks/makeboot.c --- linux86.vold/bootblocks/makeboot.c 2000-09-05 19:18:19.000000000 +0100 +++ linux86/bootblocks/makeboot.c 2003-05-22 08:25:17.000000000 +0100 @@ -9,6 +9,7 @@ #include "msdos.v" #include "msdos16.v" #include "skip.v" +#include "killhd.v" #include "tarboot.v" #include "minix.v" #include "minixhd.v" @@ -58,13 +59,42 @@ { "hdmin","Minix Hard disk FS booter", minixhd_data, minixhd_size, 2, minixhd_bootfile-minixhd_start, FS_ZERO}, +{ "killhd", "Deletes MBR from hard disk when booted", + killhd_data, killhd_size, + 2, killhd_boot_message-killhd_start, FS_ADOS}, +#if __STDC__ +{ "mbr", "Master boot record for HD" +#if defined(mbr_Banner) || mbr_diskman || mbr_linear || mbr_mbrkey || mbr_preboot + ", Options:" #ifdef mbr_Banner -{ "mbr", "Master boot record for HD (with optional message)", + " Banner" +#endif +#if mbr_diskman + " DiskMan" +#endif +#if mbr_linear + " LBA" +#if !mbr_useCHS + "-Only" +#endif +#endif +#if mbr_mbrkey + " BootKeys" +#endif +#if mbr_preboot + " PreBoot" +#endif +#endif + , mbr_data,mbr_size, +#ifdef mbr_Banner 2, mbr_Banner-mbr_start, FS_MBR}, #else -{ "mbr", "Master boot record for HD", - mbr_data,mbr_size, 0, 0, FS_MBR}, + 0, 0, FS_MBR}, +#endif +#else +{ "mbr", "Master boot record for HD", + mbr_data,mbr_size, 0, 0, FS_MBR}, #endif { "stat", "Display dosfs superblock", 0, 0, 0, 0, FS_STAT}, @@ -757,6 +787,14 @@ { 0x30, 2, 0}, { 0x32, 2, 0}, + { 0x40, 1, 0}, + { 0x43, 4, 0}, + { 0x47, 11, 0}, + { 0x52, 8, 0}, + + { 0x3e8, 4, 0}, + { 0x3ec, 4, 0}, + { -1,0,0} }; @@ -777,13 +815,13 @@ "Heads", "Hidden sectors (Partition offset)", - "Large FS sector count", + "Large Filesystem sector count", "Phys drive", "Serial number", "Disk Label (DOS 4+)", "FAT type", - "FAT32 FS sector count", + "Large Filesystem sector count", "FAT32 FAT length", "FAT32 Flags", "FAT32 version", @@ -791,6 +829,14 @@ "FAT32 Info Sector", "FAT32 Backup Boot", + "FAT32 Phys Drive", + "FAT32 Serial number", + "FAT32 Disk Label", + "FAT32 FAT Type", + + "FAT32 Free clusters", + "FAT32 Next free cluster", + 0 }; int i; @@ -1083,9 +1129,10 @@ break; /* Check for Disk Manager partition tables */ - if( buffer[252] == 0xAA && buffer[253] == 0x55 ) + if( buffer[252] == 0x55 && buffer[253] == 0xAA ) { - if( (unsigned char)mbr_data[252] != 0xAA || mbr_data[253] != 0x55 ) + if( (unsigned char)mbr_data[252] != 0x55 || + (unsigned char)mbr_data[253] != 0xAA ) i = 252; } diff -Nurd linux86.vold/bootblocks/Makefile linux86/bootblocks/Makefile --- linux86.vold/bootblocks/Makefile 2001-05-12 09:17:53.000000000 +0100 +++ linux86/bootblocks/Makefile 2004-01-24 10:55:38.000000000 +0000 @@ -2,107 +2,124 @@ HOSTCC=cc HOSTCCFLAGS=-O BCC=bcc +AS86=as86 +DEFS= CC=$(BCC) -CFLAGS=-ansi -Ms -Oi -O -s -# CFLAGS=-ansi -Ms +CFLAGS=-ansi -Ms -Oi -O $(DEFS) +LDFLAGS=-s -i -H0x10000 ASFLAGS=-0 -w MINIXDEFS=-DDOTS -MONDEFS= +# CFLAGS=-ansi -Ms $(DEFS) # LST=-l $*.lst -# CLST=-A-l -A$*.lst -default: makeboot makeboot.com monitor.out minix_elks.bin lsys.com +default: makeboot makeboot.com monitor.sys minix_elks.bin lsys.com all: bootbin bootsys default tgz -bootsys: bootfile.sys boottar.sys bootminix.sys +bootsys: bootfile.sys boottar.sys bootminix.sys monitor.sys boot_win.sys CSRC=minix.c -SSRC=sysboot.s tarboot.s skip.s com_bcc.s tich.s mbr.s msdos.s noboot.s +SSRC=sysboot.s tarboot.s skip.s mbr.s msdos.s noboot.s \ + boot_fpy.s killhd.s bb_linux.s bb_init1.s bb_init2.s encap: $(SSRC:s=v) $(CSRC:c=v) minixhd.v msdos16.v bootbin: $(SSRC:s=bin) $(CSRC:c=bin) minixhd.bin msdos16.bin minix_elks.bin MOBJ=monitor.o commands.o i86_funcs.o relocate.o help.o bzimage.o \ - trk_buf.o min_buf.o unix.o fs.o fs_tar.o fs_min.o fs_dos.o cprintf.o + buffer.o unix.o fs.o fs_tar.o fs_min.o fs_dos.o MSRC=monitor.c commands.c i86_funcs.c relocate.c help.c bzimage.c \ - trk_buf.c min_buf.c unix.c fs.c fs_tar.c fs_min.c fs_dos.c cprintf.c + buffer.c unix.c fs.c fs_tar.c fs_min.c fs_dos.c MINC=i86_funcs.h readfs.h monitor.h BOOTBLOCKS=sysboot.v noboot.v skip.v msdos.v msdos16.v \ - tarboot.v minix.v minixhd.v mbr.v + tarboot.v minix.v minixhd.v mbr.v killhd.v -EXTRAS=minix.h elf_info.c elf_info.h standalone.c li86.s \ - zimage.s minix_elks.c crc.c lsys.c +EXTRAS=minix.h zimage.s minix_elks.c lsys.c boot_win.c -install: +install: makeboot + install -m 755 -s makeboot $(DIST)$(PREFIX)/bin/makeboot + +monitor.com: $(MOBJ) + $(CC) $(CFLAGS) $(LDFLAGS) $(MONDEFS) -d $(MOBJ) -o monitor.com -M > monitor.sym monitor.out: $(MOBJ) - $(CC) $(CFLAGS) $(MONDEFS) -H0x10000 $(MOBJ) -o monitor.out -M > monitor.sym + $(CC) $(CFLAGS) $(LDFLAGS) $(MONDEFS) $(MOBJ) -o monitor.out -M > monitor.sym -$(MOBJ): $(MINC) version.h +$(MOBJ): $(MINC) fs_min.o: minix.h bootfile.sys: $(MSRC) $(MINC) @rm -f $(MOBJ) - make 'CFLAGS=$(CFLAGS) -DDOSFLOPPY -i-' monitor.out + make 'CFLAGS=$(CFLAGS) -DDOSFLOPPY' monitor.out mv monitor.out bootfile.sys @rm -f $(MOBJ) boottar.sys: $(MSRC) $(MINC) tarboot.bin @rm -f $(MOBJ) - make 'CFLAGS=$(CFLAGS) -DTARFLOPPY -i-' monitor.out + make 'CFLAGS=$(CFLAGS) -DTARFLOPPY' monitor.out mv monitor.out boottar.sys @rm -f $(MOBJ) -bootminix.sys: $(MSRC) $(MINC) tarboot.bin +bootminix.sys: $(MSRC) $(MINC) minix.bin @rm -f $(MOBJ) - make 'CFLAGS=$(CFLAGS) -DMINFLOPPY -i-' monitor.out + make 'CFLAGS=$(CFLAGS) -DMINFLOPPY' monitor.out mv monitor.out bootminix.sys @rm -f $(MOBJ) +monitor.sys: $(MSRC) $(MINC) + @rm -f $(MOBJ) + make monitor.out + mv monitor.out monitor.sys + @rm -f $(MOBJ) + monitor: $(MSRC) $(MINC) @rm -f $(MOBJ) - make 'CFLAGS=-ansi -H0x8000' monitor.out + make 'CFLAGS=-ansi $(DEFS)' monitor.out mv monitor.out monitor @rm -f $(MOBJ) bzimage.o: bzimage.c zimage.v minix.s: minix.c Makefile - $(BCC) -Mf -O -DTRY_FLOPPY $(MINIXDEFS) -S minix.c + $(CC) -Mf -O -DTRY_FLOPPY $(MINIXDEFS) -S minix.c minix_elks.s: minix_elks.c Makefile minix.v - $(BCC) -Mf -O $(MINIXDEFS) -S minix_elks.c + $(CC) -Mf -O $(MINIXDEFS) -S minix_elks.c minixhd.s: minix.c Makefile - $(BCC) -Mf -O -DHARDDISK $(MINIXDEFS) -S minix.c -o minixhd.s + $(CC) -Mf -O -DHARDDISK $(MINIXDEFS) -S minix.c -o minixhd.s msdos16.s: msdos.s sed 's/^fatbits=12/fatbits=16/' < msdos.s > msdos16.s +mbr_dm.s: mbr.s + sed -e 's/^diskman=0/diskman=1/' \ + -e 's/^message=1/message=0/' \ + -e 's/^mbrkey=1/mbrkey=0/' \ + -e 's/^preboot=1/preboot=0/' \ + < mbr.s > mbr_dm.s + +boot_win.sys: boot_win.c + $(CC) -Ms -H0x6000 -s boot_win.c -o boot_win.sys + makeboot: makeboot.c $(BOOTBLOCKS) $(HOSTCC) $(HOSTCCFLAGS) -o makeboot makeboot.c makeboot.com: makeboot.c $(BOOTBLOCKS) - $(BCC) -Md -O -o makeboot.com makeboot.c + $(CC) -Md -O -o makeboot.com makeboot.c lsys.com: lsys.c msdos.v msdos16.v - $(BCC) -Md -O -o lsys.com lsys.c - -version.h: - head -1 ../Libc_version | \ - sed 's/\(.*\)/#define VERSION "\1"/' > version.h + $(CC) -Md -O -o lsys.com lsys.c clean realclean: - rm -f bootfile.sys boottar.sys bootminix.sys + rm -f bootfile.sys boottar.sys bootminix.sys monitor.sys boot_win.sys rm -f monitor makeboot bootblocks.tar.gz - rm -f minix.s minixhd.s minix_elks.s version.h msdos16.s + rm -f minix.s minixhd.s minix_elks.s msdos16.s mbr_dm.s rm -f *.com *.o *.bin *.out *.lst *.sym *.v *.tmp -tgz: minix.bin monitor.out makeboot.com makeboot - tar cfV bootblocks.tar ENIAC monitor.out \ +tgz: minix.bin monitor.sys makeboot.com makeboot + tar cfV bootblocks.tar ENIAC monitor.sys \ README Makefile \ $(MSRC) \ $(MINC) \ @@ -120,9 +137,7 @@ .SUFFIXES: .bin .v .s.bin: - $(BCC) -W -c $*.s -A-u- -A-b -A$*.tmp -A-s -A$*.sym $(CLST) - mv $*.tmp $*.bin - -@rm $*.o + $(AS86) -w- -0 -b $*.bin -s $*.sym $*.s $(LST) .s.v: as86_encap $*.s $*.v $*_ $(ASFLAGS) $(LST) diff -Nurd linux86.vold/bootblocks/mbr.s linux86/bootblocks/mbr.s --- linux86.vold/bootblocks/mbr.s 2000-09-26 20:20:18.000000000 +0100 +++ linux86/bootblocks/mbr.s 2003-05-22 06:42:00.000000000 +0100 @@ -2,25 +2,32 @@ ! This is a 'Master Boot Record' following the MSDOS 'standards'. ! This BB successfully boots MSDOS or Linux. ! -! In addition it has the facility to load and execute a small program -! before the boot blocks are checked. +! In addition it can: +! Display a message configure at install time. +! Load and execute a small program before the boot blocks are checked. ! ! Or ! -! Space for 12 extra partitions in the 'DiskManager' form that Linux -! _does_ understand. +! Space for 12 extra partitions in the 'Old Disk Manager' form that Linux +! _does_ understand (unfortunatly there doesn't appear to be an fdisk that +! understands them.) ! -! NB: This needs Dev86 0.15.2 or later +! NB: This needs as86 0.16.0 or later ! Lowest available is $0500, MSDOS appears to use $0600 ... I wonder why? ORGADDR=$0500 +copyright=1 ! Add in the copyright message; if room. preboot=0 ! Include the pre-boot loader. -mbrkey=0 ! Option to choose the boot record base on keystroke -message=0 ! Display boot message +mbrkey=0 ! Option to choose the boot record based on keystroke +message=1 ! Display boot message +use512=0 ! Put the end marker at byte 510..512 +markptab=1 ! Put an end marker just below the partition table. + diskman=0 ! Disk manager partitions, allows 16 partitions but ! don't overwrite this with a LILO BB. -linear=0 ! Use the linear addresses not the CHS ones +linear=1 ! Use the linear addresses not the CHS ones (if available) +useCHS=1 ! Disable CHS if you need space. partition_start=ORGADDR+0x1BE partition_size=0x10 @@ -34,6 +41,12 @@ table_start=partition_start endif +export linear +export diskman +export useCHS +export mbrkey +export preboot + org ORGADDR cli ! Assume _nothing_! cld @@ -52,7 +65,7 @@ cont: sti ! Let the interrupts back in. -! Next check for a pre-boot load or a keypress +! Next check for a pre-boot message, load or keypress if message call disp_message endif @@ -63,23 +76,39 @@ call key_wait endif + if (linear|useCHS) + ! Now check the partition table, must use SI as pointer cause that's what the ! partition boot blocks expect. +! If we're using diskman and we're short of space check the partitions in +! physical order. (Order. 4,3,2,1,5,6,7,8,9,10,11,12,13,14,15,16) + + if (diskman&linear&useCHS) + + mov si,#partition_end +check_next: + sub si,#partition_size + cmp byte [si],#$80 ! Flag for activated partition + jz found_active + cmp si,#low_partition + jnz check_next + + else + +! Normal active partition check, (Order: 1,2,3,4) mov si,#partition_start check_active: cmp byte [si],#$80 ! Flag for activated partition jz found_active - if mbrkey=0 -bad_boot: - endif +try_next_part: add si,#partition_size cmp si,#partition_end jnz check_active - ! Check for Disk manager partitions in the order that Linux numbers them. - if diskman - cmp word ptr diskman_magic,#$55AA +! Check for Disk manager partitions in the order that Linux numbers them. + if diskman&~(linear&useCHS) + cmp word ptr diskman_magic,#$AA55 jnz no_diskman mov si,#partition_start check_next: @@ -91,26 +120,78 @@ no_diskman: endif + endif + if mbrkey=0 +bad_boot: + endif mov si,#no_bootpart ! Message & boot jmp no_boot +! Active partition found, boot it. found_active: + mov di,#6 ! Max retries, int doc says 3 ... double it + movb [$7DFE],#0 ! Clear magic for dosemu +retry: + +! If the BIOS has LBA extensions use them. if linear - call linearise + if useCHS + mov ah,#$41 + mov bx,#$55AA + mov dx,[si] ! dh = Drive head, dl = $80 ie HD drive 0 + push si ! Save SI on read. + if mbrkey + test dl,#$80 + jz do_CHS + endif + int $13 + jc do_CHS + cmp bx,#$AA55 + jnz do_CHS else - mov di,#6 ! Max retries, int list says 3 ... double it + mov dx,[si] ! dh = Drive head, dl = $80 ie HD drive 0 + push si ! Save SI + endif + mov bx,#disk_address + mov ax,[si+8] + mov [bx],ax + mov ax,[si+10] + mov [bx+2],ax + mov si,#disk_packet + mov ah,#$42 + int $13 + pop si + jc retry_error + j sector_loaded +disk_packet: + .byte $10 + .byte 0 + .word 1 + .word $7C00 + .word 0 +disk_address: + .long 0 + .long 0 + + if useCHS +do_CHS: + pop si + endif + endif + +if useCHS mov dx,[si] ! dh = Drive head, dl = $80 ie HD drive 0 mov cx,[si+2] ! cx = Sector & head encoded for int $13 ! bx is correct at $7C00 - endif -retry: - movb [$7DFE],#0 ! Clear magic for dosemu + mov ax,#$0201 ! Read 1 sector int $13 ! Disk read. jnc sector_loaded +endif ! Error, reset and retry +retry_error: xor ax,ax int $13 ! Disk reset @@ -123,11 +204,19 @@ sector_loaded: mov di,#$7DFE ! End of sector loaded cmp [di],#$AA55 ! Check for magic - jnz bad_boot ! No? Try next partition. + if diskman + jnz bad_boot ! Can't try again, two places to return to. + else + jnz try_next_part ! No? Try next partition. + endif mov bp,si ! LILO says some BBs use bp rather than si jmpi #$7C00,#0 ! Go! + else + mov si,#no_bootpart ! Message & boot + endif !(linear|useCHS) + ! Fatal errors ........... if mbrkey bad_boot: @@ -136,9 +225,7 @@ call puts mov si,#crlf call puts -tick: - call key_wait - j tick + j key_pause else @@ -159,8 +246,7 @@ keyboot: ! Wait for a key then reboot xor ax,ax int $16 -! int $19 ! This rarely does anything useful... - jmpi $0,$FFFF ! Wam! Try or die! + jmpi $0,$FFFF ! Reboot. press_key: .asciz "\r\nPress return:" @@ -168,23 +254,9 @@ endif no_bootpart: - .asciz "No active partition" + .asciz "Bad partition" disk_read_error: - .asciz "Disk read error" - -!-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -! Instead of loading using the CHS data in the ptbl use the linear addr -! - if linear -linearise: - mov di,#6 ! Max retries, int list says 3 ... double it - mov dx,[si] ! dh = Drive head, dl = $80 ie HD drive 0 - mov cx,[si+2] ! cx = Sector & head encoded for int $13 - ! bx is correct at $7C00 - - fail! Todo ... - ret - endif + .asciz "Read error" !-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ! Choose the partition based on a pressed key ... @@ -193,12 +265,29 @@ key_wait: mov si,#Prompt call puts + call wait_key + jnz key_pause + + mov si,#Unprompt ! Nothing has happened, return. + call puts + ret + +key_pause: + mov si,#Pause + call puts + +key_tick: + call wait_key + jz key_tick + j Got_key + +wait_key: mov di,#19 ! Wait for 18-19 ticks next_loop: mov ah,#1 int $16 - jnz Got_key + jnz done_wait mov ah,#0 int $1A ! Get current tick cmp dx,si ! If changed DEC our counter. @@ -207,45 +296,39 @@ dec di jnz next_loop - mov si,#Unprompt ! Nothing has happened, return. - call puts - -bad_key: +done_wait: ret Got_key: - cmp al,#$20 - jnz not_space - mov si,#Pause - j showit -not_space: + mov ah,#0 ! Clean the kbd buffer. + int $16 + cmp al,#0x20 + jz key_tick + + push ax mov Showkey,al mov si,#Showkey -showit: call puts - - mov ah,#0 ! Clean the kbd buffer. - int $16 + pop ax ! ... Now we use our key ... ! 0 => Floppy ! 1 .. 4 => Hard disk partition. - mov di,#-1 - cmp al,#$20 - jz next_loop - - and ax,#0xF + if useCHS + cmp al,#'F + jz is_floppy + cmp al,#'f + jz is_floppy + endif - jnz not_floppy - mov si,#floppy_part - br found_active + cmp al,#'1 + jb key_pause + cmp al,#'4 + ja key_pause -not_floppy: + and ax,#0x7 dec ax - test ax,#0xC - jnz bad_key - mov cl,#4 shl ax,cl add ax,#partition_start @@ -253,8 +336,18 @@ ! Set active flag for disk interrupt. or byte [si],#$80 + br found_active + if useCHS +is_floppy: + mov si,#floppy_part br found_active + endif + + if message +disp_message: + mov si,#Banner + endif puts: lodsb @@ -270,11 +363,15 @@ ret Prompt: - .asciz "MBR: " + .asciz "\rMBR: " Unprompt: - .asciz "\b\b\b\b\b \b\b\b\b\b" + .asciz "\r \r" Pause: - .asciz "\b\b> " + if useCHS + .asciz "\rMBR F1234> " + else + .asciz "\rMBR 1234> " + endif Showkey: .ascii " " crlf: @@ -285,33 +382,6 @@ endif !-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -! - if message -disp_message: - mov si,#Banner - - if mbrkey - br puts - else - -puts: - lodsb - cmp al,#0 - jz .EOS - push bx - mov bx,#7 - mov ah,#$E ! Can't use $13 cause that's AT+ only! - int $10 - pop bx - jmp puts -.EOS: - ret - endif -export Banner -Banner: - .asciz "" - endif -!-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ! This is the pre-boot loader it uses CHS but that's ok for track 0 ! if preboot @@ -327,9 +397,9 @@ jz load_done mov bx,ax ! word 1 address lodsw - mov cx,ax ! word 2 CX, head/sector + mov cx,ax ! word 2 CX, cylinder/sector lodsw - mov dx,ax ! word 3 DX, drive, cylinder + mov dx,ax ! word 3 DX, drive, head lodsw ! word 4 AX, $02, sector count int $13 jnc more_boot ! This doesn't retry, with a HD it shouldn't be bad. @@ -353,23 +423,47 @@ ! .word ! Then repeat .. ! .word , , , + ! Or. + ! .word + ! .byte + ( & $300)>>2), & $FF, , , , 2 ! Finally ! .word 0 ! Example: Load rest of H0,C0 into mem at $7C00 (8k). - ! .word $7C00, $7C00,$0002,$8000,$0210, $0000 + ! .word $7C00 + ! .word $7C00,$0002,$8000,$0210 + ! .word $0000 + endif - ! Example: Use single LBA call - ! .word - ! .word 0,0,$8000,$4200, $0010 - ! .word - ! .long - ! .long - ! .long +!-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- +! + if message&~mbrkey +disp_message: + mov si,#Banner + +puts: + lodsb + cmp al,#0 + jz .EOS + push bx + mov bx,#7 + mov ah,#$E ! Can't use $13 cause that's AT+ only! + int $10 + pop bx + jmp puts +.EOS: + ret + endif + + if message +export Banner +Banner: + .blkb 16 ! 16 bytes for the message at least. endif !-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ! Now make sure this isn't too big! +end_of_code: if *>table_start fail! Partition table overlaps endif @@ -377,24 +471,43 @@ !-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ! The diskman magic number and empty DM partitions. if diskman - org ORGADDR+0xFC + org table_start public diskman_magic diskman_magic: .word 0xAA55 .blkb 12*partition_size-1 - .byte 0 endif !-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -! And finally a copyright message if there's room. +! And a copyright message if there's room. + if copyright if *= 9 && __argr.x.si <= 63 ) - { - disk_spt = __argr.x.si; - disk_heads = 2; - disk_cyls = 80; - } -#endif -} - -char * read_lsector(sectno) -long sectno; -{ - int tries = 5; - int rv = 0; - - int phy_s = 1; - int phy_h = 0; - int phy_c = 0; - int ltrack; - - if( sectno == 0 || disk_heads == 0 ) reset_disk(); - if( buf_len != disk_spt ) track_no = -1; - - if( disk_spt < 1 || disk_heads < 1 ) - phy_s = sectno; - else - { - phy_s = sectno%disk_spt; - phy_h = sectno/disk_spt%disk_heads; - phy_c = sectno/disk_spt/disk_heads; - } - -#ifdef DEBUG - fprintf(stderr, "read_sector(%ld = %d,%d,%d)\n", sectno, phy_c, phy_h, phy_s); -#endif - - ltrack = phy_c*disk_heads+phy_h; - if( disk_spt > 1 && disk_spt <= MAXTRK - && track_no != ltrack && ltrack != bad_track) - { - rv = phy_read(disk_drive, phy_c, phy_h, 1, disk_spt, buffer); - if( rv == 0 ) - { - track_no = ltrack; - buf_len = disk_spt; - } - else - bad_track = ltrack; - } - if( track_no == ltrack ) - return buffer + phy_s * 512; - - do - { - rv = phy_read(disk_drive, phy_c, phy_h, phy_s+1, 1, buffer); - tries--; - } - while(rv && tries > 0); - if( rv ) printf("Disk error 0x%02x %d:%d:%d:%d[%2d] -> 0x%04x[]\n", - rv, disk_drive, phy_c, phy_h, phy_s+1, 1, buffer); - - if(rv) return 0; else return buffer; -} - -#if defined(__MSDOS__) || defined(__STANDALONE__) -phy_read(drive, cyl, head, sect, length, buffer) -{ -#asm - push bp - mov bp,sp - - push ds - pop es - - mov dl,[bp+2+_phy_read.drive] - mov ch,[bp+2+_phy_read.cyl] - mov dh,[bp+2+_phy_read.head] - mov cl,[bp+2+_phy_read.sect] - mov al,[bp+2+_phy_read.length] - mov bx,[bp+2+_phy_read.buffer] - - mov ah,#$02 - int $13 - jc read_err - mov ax,#0 -read_err: - - pop bp -#endasm -} -#endif - -#endif diff -Nurd linux86.vold/bootblocks/minix.c linux86/bootblocks/minix.c --- linux86.vold/bootblocks/minix.c 1999-06-05 00:12:39.000000000 +0100 +++ linux86/bootblocks/minix.c 2002-03-16 13:22:36.000000000 +0000 @@ -230,8 +230,7 @@ min_eos: ! Wait for a key then reboot xor ax,ax int $16 - !int $19 ! This should be OK as we haven't touched anything. - jmpi $0,$FFFF ! Wam! Try or die! + jmpi $0,$FFFF ! Reboot. fail_fs: .byte 13,10 diff -Nurd linux86.vold/bootblocks/monitor.c linux86/bootblocks/monitor.c --- linux86.vold/bootblocks/monitor.c 1999-06-14 13:11:57.000000000 +0100 +++ linux86/bootblocks/monitor.c 2003-08-31 14:40:58.000000000 +0100 @@ -28,33 +28,35 @@ struct t_cmd_list * cptr; #ifdef __STANDALONE__ - printf("\r"); + printf("\r\n"); #endif init_prog(); + + if (!x86_test) + { #ifdef __STANDALONE__ #ifndef NOCOMMAND - if( __get_ds() != 0x1000 ) - { - /* First to top of RAM */ - relocator(-1); +#if 0 + /* First out of the way. */ + relocator(3); /* Then align DS to 64k boundry -> DMA is simple. */ relocator(0x1000-__get_ds()+__get_cs()); - - /* Oops, relocate down didn't work, try a little higher. */ - if( __get_ds() > 0x1000 ) relocator(2); +#else + relocator(-1); /* Top of available memory */ +#endif printf("Relocated to CS=$%04x DS=$%04x\n", __get_cs(), __get_ds()); - } #endif - disk_drive = __argr.h.dl; + disk_drive = __argr.h.dl; #endif #ifdef NOCOMMAND - cmd_type("help.txt"); + cmd_type("help.txt"); #else - display_help(0); + display_help(0); #endif - cmd_bzimage((void*)0); + cmd_bzimage((void*)0); + } #ifdef NOCOMMAND printf("Unable to boot, sorry\nreboot:"); @@ -123,7 +125,9 @@ void init_prog() { + char offt; #ifdef COLOUR + vt52_putch(0); printf("\033E\033Rg\033Sa\033J"); #endif printf("Linux x86"); @@ -140,42 +144,28 @@ #else printf(" boot monitor"); #endif -#ifdef VERSION printf(", Version %s", VERSION); -#endif printf(".\n"); cpu_check(); mem_check(); +#ifndef NOMONITOR printf("Processor: %s", x86_name); if(x86_fpu) printf(" with FPU"); if(x86_emu) printf(" in protected mode"); - if(x86 > 1) - { - printf(", A20 gate "); - if( a20_closed() ) - { - open_a20(); - if( a20_closed() ) - printf("won't open!!"); - else - printf("is now open"); - } - else printf("is already open."); - } printf("\n"); +#endif - printf("There is %dk of boot memory", boot_mem_top/64); + printf("There is %u bytes available", &offt-sbrk(0)); + printf(", %dk of boot memory", boot_mem_top/64); if( main_mem_top ) { - printf(" %d.%dM %sof main memory", + printf(", %d.%dM of main memory", (int)(main_mem_top/1024), - (int)((10*main_mem_top)/1024%10), - main_mem_top >= 0xFC00L ?"(perhaps more) ":"" - ); + (int)((10*main_mem_top)/1024%10)); } - printf("\n"); + printf(".\n"); } /****************************************************************************/ diff -Nurd linux86.vold/bootblocks/monitor.h linux86/bootblocks/monitor.h --- linux86.vold/bootblocks/monitor.h 1999-06-04 14:33:47.000000000 +0100 +++ linux86/bootblocks/monitor.h 2003-02-02 06:00:27.000000000 +0000 @@ -19,9 +19,6 @@ #ifdef TARFLOPPY #define SINGLEFS -#define NOMONITOR -#define NOCOMMAND -#define MINI_BUF #define open_file tar_open_file #define rewind_file tar_rewind_file @@ -32,9 +29,6 @@ #ifdef MINFLOPPY #define SINGLEFS -#define NOMONITOR -#define NOCOMMAND -#define MINI_BUF #define open_file min_open_file #define rewind_file min_rewind_file @@ -45,10 +39,6 @@ #ifdef DOSFLOPPY #define SINGLEFS -#define NOMONITOR -#define NOCOMMAND -#define MINI_BUF -#define MAXTRK 24 #define open_file dos_open_file #define rewind_file dos_rewind_file @@ -57,9 +47,14 @@ #define read_block dos_read_block #endif +#ifdef SINGLEFS +/* #define NOCOMMAND */ +#define NOMONITOR +#endif + #ifdef __STANDALONE__ #undef putchar -#define putchar cputchar +#define putchar putch #define printf cprintf #define fflush(x) #endif diff -Nurd linux86.vold/bootblocks/msdos.s linux86/bootblocks/msdos.s --- linux86.vold/bootblocks/msdos.s 2000-09-02 22:16:06.000000000 +0100 +++ linux86/bootblocks/msdos.s 2003-05-22 06:39:25.000000000 +0100 @@ -14,7 +14,7 @@ ! of the msdos files system: ! ! 1) All of the first 12 bit FAT must be on the first track. -! 2) The FAT must be 12 bit +! 2) The FAT must be 12 bit or 16 bit. (known at install time) ! 3) The value of the hidden sectors field must be zero ! ! All these are true for mtools created floppies on normal PC drives. @@ -213,8 +213,7 @@ EOS: xor ax,ax int $16 - int $19 ! This should be OK as we haven't touched anything. - jmpi $0,$FFFF ! Wam! Try or die! + jmpi $0,$FFFF ! Reboot. !--------------------------------------------------------------------------- ! This loads the boot program 1 sector at a time, funny thing is it actually @@ -341,11 +340,9 @@ !--------------------------------------------------------------------------- ! File is now loaded, execute it. maincode: - if harddisk=0 mov bx,#7 - mov ax,#$0E3E + mov ax,#$0E + ': int $10 ! Marker printed to say bootblock succeeded. - endif xor dx,dx ! DX=0 => floppy drive if harddisk @@ -356,8 +353,6 @@ mov bx,#LOADSEG mov ds,bx ! DS = loadaddress - inc bx - inc bx ! bx = initial CS xor di,di ! Zero mov ax,[di] cmp ax,#0x0301 ! Right magic ? @@ -370,19 +365,19 @@ shr ax,cl impure: pop cx ! Partition offset. + inc bx + inc bx ! bx = initial CS add ax,bx mov ss,ax mov sp,[di+24] ! Chmem value mov ds,ax + ! AX=ds, BX=cs, CX=X, DX=X, SI=X, DI=0, BP=X, ES=X, DS=*, SS=*, CS=* + +bad_magic: push bx ! jmpi 0,#LOADSEG+2 push di - - ! AX=ds, BX=cs, CX=X, DX=X, SI=X, DI=0, BP=X, ES=X, DS=*, SS=*, CS=* retf -bad_magic: - pop cx - jmpi LOADSEG<<4,0 ! No magics, just go. !--------------------------------------------------------------------------- ! initilised data @@ -390,13 +385,8 @@ fatsect: .word 0 -! if fatbits =16 error_msg: .asciz "\r\nError during initial boot\r\nPress a key:" -! else -! error_msg: -! .asciz "\r\nBoot error:" -! endif export boot_name boot_name: diff -Nurd linux86.vold/bootblocks/README linux86/bootblocks/README --- linux86.vold/bootblocks/README 1999-06-14 14:14:02.000000000 +0100 +++ linux86/bootblocks/README 2003-02-02 06:58:46.000000000 +0000 @@ -31,9 +31,16 @@ 1.1 ) Master boot sector - This MBR is a very simple one with no frills, being less that 254 bytes - long is can be used as an MBR for a disk with old style 'Disk manager' - partitions. All 16 partitions are bootable. + This MBR is a very simple one with no frills by default. + + The actual code is less that 254 bytes long so it can be used as + an MBR for a disk with old style 'Disk manager' partitions. All 16 + partitions are bootable. + + Option 2 is a boot message that displayed as soon as the MBR loads. + + Option 3 is code to accept a keypress from the user to select which + partition to boot (or the floppy). 1.2 ) Dosfs boot sector @@ -54,8 +61,9 @@ as my testing has gone this is only significant on 8086 machines, all others (286 8Mhz +) are fast enough to keep up at a 1-1 interleve. - But beware some older versions of superformat defeat this because - they do not correctly calculate intersector gaps. + But some versions of superformat can defeat this because they do + not correctly calculate intersector gaps. I suggest using fdformat + as this uses a 'safe' layout for standard 1440k disks. 1.3 ) Minixfs boot block @@ -79,12 +87,12 @@ bootable floppy image. The boot sector loads and executes the first item in the tar file after the label: - $ tar cvfV the_file.tar ENIAC monitor.out item2 item3 + $ tar cvfV the_file.tar ENIAC monitor.sys item2 item3 $ makeboot tar the_file.tar $ cp the_file.tar /dev/fd0 This sequence makes a bootable floppy that tar sees as a normal labeled - tar file but when booted from will load and execute 'monitor.out' at + tar file but when booted from will load and execute 'monitor.sys' at location $00800 (Yes thats 2k!) Warning: the tar boot sector moves the BPB to the location $666. @@ -119,12 +127,12 @@ 2.3 ) Booting Linux-i386 [b]zImage None of the boot blocks can _directly_ boot a Linux-i386 kernel the - program 'monitor.out' must loaded by the boot sector and this can + program 'monitor.sys' must loaded by the boot sector and this can load a zimage or bzimage from an MSDOS, Minix or Tar floppy. It can also load the image from a minix hard disk filesystem. This example is for and MSDOS floppy, Tar is very similar except that - 'monitor.out' must be the first file in the tar and can have any name. + 'monitor.sys' must be the first file in the tar and can have any name. Note also for a tar file the 'ramdisk.gz' file must start on the first disk but can extend across as many floppies as is needed. @@ -132,22 +140,24 @@ $ mformat a: $ makeboot dos /dev/fd0 $ mount -t msdos /dev/fd0 /mnt - $ cp monitor.out /mnt/bootfile.sys + $ cp monitor.sys /mnt/bootfile.sys $ cp /usr/src/linux/arch/i386/boot/zImage /mnt/vmlinuz $ echo 'root=/dev/ram ramdisk_file=ramdisk.gz mem=80M' > /mnt/vmlinuz.cfg $ cp /archive/ramdisk.gz /mnt/ramdisk.gz $ umount /dev/fd0 - The stuff about ramdisk is only if you want an init ramdisk, if the ramdisk - name begins with a '+' the program will ask for another disk first. + The stuff about ramdisk is only if you want an init ramdisk. If + the ramdisk isn't on this floppy monitor.sys will ask for the + right floppy. If you specify multiple ramdisk files then will be + concatenated and passed to the kernel as one ramdisk, each file + can be on a different floppy. If the file isn't called 'vmlinuz' you can still boot it by typing "=linux" at the prompt '>' where 'linux' is the name of the bzImage file. Escape or ^C will interrupt the boot and drop you to the '>' prompt. - Esacpe or ^C at the '>' prompt will reboot - (This may be a little too sensitive :-) + ^C at the '>' prompt will reboot A file called 'help.txt' will be displayed upto the first line that starts with a '%', chunks after that (seperated by '%'s) will be displayed when @@ -155,4 +165,4 @@ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -Robert de Bath 31 Dec 1998 +Robert de Bath diff -Nurd linux86.vold/bootblocks/relocate.c linux86/bootblocks/relocate.c --- linux86.vold/bootblocks/relocate.c 1998-07-24 15:53:59.000000000 +0100 +++ linux86/bootblocks/relocate.c 2003-02-02 05:37:52.000000000 +0000 @@ -23,14 +23,23 @@ unsigned moved, codelen; unsigned es = __get_es(); + /* If running under DOS don't relocate */ + if (__argr.x.cflag) return; + /* Where do we start */ if(memseg == 0) { + extern int _heap_top; memseg = __get_cs(); codelen = __get_ds()-memseg; __set_es(memseg-2); - memlen = __deek_es( 24 ); - memlen >>=4; + + memlen = (((int)&_heap_top) >> 4); + + /* + if (__deek_es(0) == 0x0301 ) memlen = (__deek_es(24) >> 4); + */ + if( memlen == 0 ) memlen = 0x1000; memlen += codelen; __set_es(es); diff -Nurd linux86.vold/bootblocks/skip.s linux86/bootblocks/skip.s --- linux86.vold/bootblocks/skip.s 1999-01-28 21:12:04.000000000 +0000 +++ linux86/bootblocks/skip.s 2002-03-16 13:21:41.000000000 +0000 @@ -72,8 +72,7 @@ xor ax,ax int $16 - int $19 ! This should be OK as we haven't touched anything. - jmpi $0,$FFFF ! Wam! Try or die! + jmpi $0,$FFFF ! Reboot. mesg2: .asciz "Disk error\r\n" mesg3: .asciz "Retrying\r\n" diff -Nurd linux86.vold/bootblocks/standalone.c linux86/bootblocks/standalone.c --- linux86.vold/bootblocks/standalone.c 1998-11-23 08:26:30.000000000 +0000 +++ linux86/bootblocks/standalone.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,310 +0,0 @@ - -#include -#include -#asm -entry _int_80 ! Tell ld86 we really do need this file. - ! then call the init stuff before main. - - loc 1 ! Make sure the pointer is in the correct segment -auto_func: ! Label for bcc -M to work. - .word _pre_main ! Pointer to the autorun function - .word no_op ! Space filler cause segs are padded to 4 bytes. - .text ! So the function after is also in the correct seg. -#endasm - -void int_80(); - -static void pre_main() -{ - /* Set the int 0x80 pointer to here */ - __set_es(0); - __doke_es(0x80*4+0, int_80); - __doke_es(0x80*4+2, __get_cs()); - bios_coninit(); -} - -void int_80() -{ -#asm -SYS_EXIT=1 -SYS_FORK=2 -SYS_READ=3 -SYS_WRITE=4 -SYS_OPEN=5 -SYS_CLOSE=6 -SYS_CHDIR=12 -SYS_LSEEK=19 -ENOSYS=38 - - push es - push si - push di - push dx - push cx - push bx - cmp ax,#SYS_READ - jne L1 - call _func_read - jmp L0 -L1: - cmp ax,#SYS_WRITE - jne L2 - call _func_write - jmp L0 -L2: - cmp ax,#SYS_LSEEK - jne L3 - call _func_lseek - jmp L0 -L3: - cmp ax,#SYS_EXIT - jne L4 - call _func_exit - jmp L0 -L4: - mov ax,#-ENOSYS -L0: - pop bx - pop cx - pop dx - pop di - pop si - pop es - iret -#endasm -} - -func_lseek() { return -38; } - -func_write(bx,cx,dx,di,si,es) -int bx,dx; -char * cx; -{ - register int v, c; - if(bx == 1 || bx == 2) - { - for(v=dx; v>0; v--) - { - c= *cx++; - if( c == '\n') bios_putc('\r'); - bios_putc(c); - } - return dx; - } - return -EBADF; -} - -func_read(bx,cx,dx,di,si,es) -int bx,dx; -char * cx; -{ - if(bx == 0) return read_line(cx, dx); - return -EBADF; -} - -read_line(buf, len) -char * buf; -int len; -{ - int ch; - int pos=0; - - if( len == 1 ) - { - buf[0]=((ch=bios_getc())&0xFF?ch&0xFF:((ch>>8)&0xFF|0x80)); - return 1; - } - - for(ch=0;;) - { - if(ch != '\003') - { - ch = bios_getc(); - if( pos == 0 && (ch&0xFF) == 0 ) - { - buf[0] = ((ch>>8)|0x80); - return 1; - } - ch &= 0x7F; - } - if( ch == '\r' ) - { - bios_putc('\r'); bios_putc('\n'); - buf[pos++] = '\n'; - return pos; - } - if( ch >= ' ' && ch != 0x7F && pos < len-1) - bios_putc(buf[pos++] = ch); - else if( (ch == '\003' || ch == '\b') && pos > 0 ) - { - bios_putc('\b'); bios_putc(' '); bios_putc('\b'); - pos--; - } - else if( ch == '\003' ) - return 0; - else - bios_putc('\007'); - } -} - -#define CTRL(x) ((x)&0x1F) -static int last_attr = 0x07; -static int con_mode; -static int con_size = 0x184F; -static int con_colour = 0; - -bios_coninit() -{ -#asm - mov ax,#$0F00 - int $10 - mov _con_mode,ax -#endasm - if( (con_mode &0xFF) > 39 ) con_size = (con_size&0xFF00) + (con_mode&0xFF); - if( (con_mode&0xFF00) != 0x700) - con_colour = 1; -} - -bios_putc(c) -int c; -{ -static char tbuf[3]; -static int tcnt=0; - if(tcnt) - { - tbuf[tcnt++] = c; - if( tcnt < 3 && (tbuf[0] != CTRL(']') || tbuf[1] < '`' || tbuf[1] > 'p')) - return; - if( tbuf[0] == CTRL('P') ) - { - if( tbuf[1] >= 32 && tbuf[1] <= 56 - && tbuf[2] >= 32 && tbuf[2] <= 111 ) - asm_cpos((tbuf[1]-32), (tbuf[2]-32)); - } - else - { - if( tbuf[1] >= '`' ) - last_attr = ( (tbuf[1]&0xF) | (last_attr&0xF0)); - else - last_attr = ( (tbuf[2]&0xF) | ((tbuf[1]&0xF)<<4)); - - if( !con_colour ) - last_attr = (last_attr&0x88) + ((last_attr&7)?0x07:0x70); - } - tcnt=0; - return; - } - if( c & 0xE0 ) { asm_colour(last_attr) ; asm_putc(c); } - else switch(c) - { - case CTRL('L'): - asm_cpos(0,0); - asm_cls(); - break; - case CTRL('P'): - case CTRL(']'): - tbuf[tcnt++] = c; - break; - default: - asm_putc(c); - break; - } - return; -} - -static asm_putc(c) -{ -#asm -#if !__FIRST_ARG_IN_AX__ - mov bx,sp - mov ax,[bx+2] -#endif - mov ah,#$0E - mov bx,#7 - int $10 -#endasm -} - -static asm_colour(c) -{ -#asm -#if __FIRST_ARG_IN_AX__ - mov bx,ax -#else - mov bx,sp - mov bx,[bx+2] -#endif - mov ah,#$08 - int $10 - mov ah,#$09 - mov cx,#1 - int $10 -#endasm -} - -static asm_cls() -{ -#asm - push bp ! Bug in some old BIOS's - !mov ax,#$0500 - !int $10 - mov ax,#$0600 - mov bh,_last_attr - mov cx,#$0000 - mov dx,_con_size - int $10 - pop bp -#endasm -} - -static asm_cpos(r,c) -{ -#asm -#if __FIRST_ARG_IN_AX__ - mov bx,sp - mov dh,al - mov ax,[bx+2] - mov dl,al -#else - mov bx,sp - mov ax,[bx+2] - mov dh,al - mov ax,[bx+4] - mov dl,al -#endif - mov ah,#$02 - mov bx,#7 - int $10 -#endasm -} - -bios_getc() -{ -#asm - xor ax,ax - int $16 -#endasm -} - -static void be_safe() -{ -#asm - iret -#endasm -} - -func_exit(bx,cx,dx,di,si,es) /* AKA reboot! */ -{ - __set_es(0); - __doke_es(0xE6*4+2,__get_cs()); - __doke_es(0xE6*4+0,be_safe); -#asm - mov ax,#$FFFF - int $E6 ! Try to exit DOSEMU - mov ax,#$0040 ! If we get here we're not in dosemu. - mov es,ax - seg es - mov [$72],#$1234 ! Warm reboot. - jmpi $0000,$FFFF -#endasm -} diff -Nurd linux86.vold/bootblocks/tarboot.s linux86/bootblocks/tarboot.s --- linux86.vold/bootblocks/tarboot.s 1999-06-18 16:58:58.000000000 +0100 +++ linux86/bootblocks/tarboot.s 2002-02-10 18:42:57.000000000 +0000 @@ -97,7 +97,7 @@ jz nogood ! If it`s zero .. Hmm if STACK = 0 - mov sp,#bad_magic ! Real bad magic :-) + mov sp,#overstack ! Real bad magic :-) endif call load_sectors @@ -262,9 +262,10 @@ loop div_loop mov di,bx -bad_magic: ret +overstack: + !-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ! ! This is good so far, is it an 8086 a.out file ? @@ -277,8 +278,6 @@ mov bx,#LOADSEG mov ds,bx ! DS = loadaddress - inc bx - inc bx ! bx = initial CS xor di,di ! Zero mov ax,[di] cmp ax,#0x0301 ! Right magic ? @@ -291,15 +290,18 @@ shr ax,cl impure: pop cx ! Partition offset. + inc bx + inc bx ! bx = initial CS add ax,bx mov ss,ax mov sp,[di+24] ! Chmem value mov ds,ax + ! AX=ds, BX=cs, CX=X, DX=X, SI=X, DI=0, BP=X, ES=X, DS=*, SS=*, CS=* + +bad_magic: push bx ! jmpi 0,#LOADSEG+2 push di - - ! AX=ds, BX=cs, CX=X, DX=X, SI=X, DI=0, BP=X, ES=X, DS=*, SS=*, CS=* retf !-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- @@ -463,28 +465,20 @@ if DEBUG pboot: - mov si,#mesg + mov si,#blk_load nextc: lodsb call putc cmp al,#0 jnz nextc ret - -locn(512-16) -mesg: -.ascii "Tarboot loading " endif !-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -! This isn't a hard disk boot sector so don't give it an HD magic -! locn(510) -! .word 0xAA55 -if DEBUG = 0 +! This isn't a hard disk boot sector but give it an HD magic anyway. locn(510) - .word 0 -endif + .word 0xAA55 ! From here down is where we load stuff. locn(512) diff -Nurd linux86.vold/bootblocks/tich.s linux86/bootblocks/tich.s --- linux86.vold/bootblocks/tich.s 1998-06-07 19:51:18.000000000 +0100 +++ linux86/bootblocks/tich.s 1970-01-01 01:00:00.000000000 +0100 @@ -1,38 +0,0 @@ -! - -org 0 - call chk !This chunk allows this code to exist at _any_ click -chk: - pop ax - mov cl,#4 - shr ax,cl - mov bx,cs - add ax,bx - push ax - mov bx,#going - push bx - retf -going: - mov ds,ax - mov es,ax - -! Print 'mesg' - mov ah,#0x03 ! read cursor pos - xor bh,bh - int 0x10 - - mov cx,#(emesg-mesg) - mov bp,#mesg - mov bx,#$7 ! page 0, attribute 7 (normal) - mov ax,#$1301 ! write string, move cursor - int $10 - -nogood: - j nogood - -mesg: -.ascii "Hello world" -emesg: - -org 510 - .word 0 diff -Nurd linux86.vold/bootblocks/trk_buf.c linux86/bootblocks/trk_buf.c --- linux86.vold/bootblocks/trk_buf.c 1999-06-14 13:12:42.000000000 +0100 +++ linux86/bootblocks/trk_buf.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,352 +0,0 @@ - -#include "monitor.h" - -#ifndef MINI_BUF - -/* #define DEBUG 1 /**/ - -int disk_drive = 0; -int disk_spt = 7; -int disk_heads = 0; -int disk_cyls = 0; -long disk_partition_offset = 0; - -int check_motor = 1; - -static int last_drive = -1; -static int data_len = 0; -static long data_trk1 = 0; -static char * data_buf1 = 0; -static long data_trk2 = 0; -static char * data_buf2 = 0; - -static long bad_track = -1; /* Track number of last unsuccesful read */ - -static long get_dpt(); - -void reset_disk() -{ -#ifdef DEBUG - fprintf(stderr, "Reset Disk: "); -#endif - if( data_buf1 ) free(data_buf1); - if( data_buf2 ) free(data_buf2); - data_buf1 = data_buf2 = 0; - last_drive = disk_drive; - bad_track = -1; - - disk_spt = 7; /* Defaults for reading floppy boot area. */ - disk_heads = 0; - disk_cyls = 0; - - if( !(disk_drive & 0x80 ) ) - { -#ifdef __STANDALONE__ - if( disk_drive == __argr.h.dl && __argr.x.si >= 9 && __argr.x.si <= 63 ) - { - disk_spt = __argr.x.si; - disk_heads = 2; - disk_cyls = 80; - } -#endif - - /* Floppy -> no partitions */ - /* Even if there were we couldn't deal with it anyway! */ - disk_partition_offset = 0; - } -#if defined(__MSDOS__) || defined(__STANDALONE__) - else - { - /* Hard disk, get parameters from bios */ - long dpt; - int v; - -#ifdef __STANDALONE__ - if( disk_partition_offset == 0 && disk_drive == __argr.h.dl ) - { - disk_partition_offset = __argr.x.cx + ((long)__argr.h.dh<<16); - } -#endif - - dpt = get_dpt(disk_drive); - v = ((dpt>>16) & 0xFF); - if( v != 0xFF && v > (disk_drive&0x7F) ) - { - disk_spt = (dpt & 0x3F); /* Max sector number 1-63 */ - if( disk_spt == 0 ) disk_spt = 64; /* 1-64 ? */ - disk_heads = ((dpt>>24) & 0xFF) + 1; /* Head count 1-256 */ - disk_cyls = ((dpt>>8) & 0xFF) + ((dpt<<2) & 0x300) + 1; - - /* Cyls count, unchecked, only needs != 0, if AMI 386 bios can be - * upto 4096 cylinder, otherwise BIOS limit is 1024 cyl. - */ - } - } -#endif - -#ifdef DEBUG - fprintf(stderr, "%d/%d/%d\n", disk_spt, disk_heads, disk_cyls); -#endif -} - -char * read_lsector(sectno) -long sectno; -{ - int tries = 6; - int rv; - - int phy_s = 1; - int phy_h = 0; - int phy_c = 0; - - rv = 0; - if( disk_drive != last_drive ) rv = 1; - else if( check_motor ) rv = ( motor_running() == 0 ); - else if( sectno == 0 ) rv = 1; - if( rv ) reset_disk(); - - if( disk_partition_offset > 0 ) - sectno += disk_partition_offset; - - if( disk_spt < 0 || disk_spt > 63 || disk_heads < 1 ) - { - phy_s = sectno; -#if DEBUG > 1 - fprintf(stderr, "read_sector(%ld = %d,%d,%d)\n", - sectno, phy_c, phy_h, phy_s+1); -#endif - } - else - { - phy_s = sectno%disk_spt; - phy_h = sectno/disk_spt%disk_heads; - phy_c = sectno/disk_spt/disk_heads; - -#if DEBUG > 1 - fprintf(stderr, "read_sector(%ld = %d,%d,%d)\n", - sectno, phy_c, phy_h, phy_s+1); -#endif - - if( fetch_track_buf(phy_c, phy_h, phy_s) >= 0 ) - return data_buf1 + (phy_s % data_len) * 512; - } - - data_len = -1; /* Zap the cache */ - if( data_buf1 == 0 ) - data_buf1 = malloc(512); - if( data_buf1 == 0 ) - { - printf("Cannot allocate memory for disk read!!!\n"); - return 0; - } - -#ifdef DEBUG - fprintf(stderr, "phy_read(%d,%d,%d,%d,%d,0x%x)\n", - disk_drive, phy_c, phy_h, phy_s+1, 1, data_buf1); -#endif - - do - { - rv = phy_read(disk_drive, phy_c, phy_h, phy_s+1, 1, data_buf1); - tries--; - } - while(rv && tries > 0); - if( rv ) printf("Disk error 0x%02x %d:%d:%d:%d[%2d] -> 0x%04x[]\n", - rv, disk_drive, phy_c, phy_h, phy_s+1, 1, data_buf1); - - check_motor = motor_running(); - - if(rv) return 0; else return data_buf1; -} - -fetch_track_buf(phy_c, phy_h, phy_s) -int phy_c, phy_h, phy_s; -{ - long trk_no, t; - char * p; - int tries = 6; - int rv, nlen; - - /* Big tracks get us short of memory so limit it. */ - nlen = (disk_spt-1)/24; - nlen = (disk_spt+nlen)/(nlen+1); - /* - trk_no = (long)phy_c*disk_heads*4+phy_h*4+phy_s/nlen+1; - */ - - trk_no = (long)(phy_c*disk_heads+phy_h)*((disk_spt+4)/nlen)+phy_s/nlen+1; - -#if DEBUG > 2 - fprintf(stderr, "Info len=%d,%d trk=%ld,%ld,%ld\n", - data_len,nlen, trk_no,data_trk1,data_trk2); -#endif - - if( data_len != nlen ) - { - if( data_buf1 ) free(data_buf1); - if( data_buf2 ) free(data_buf2); - data_buf1 = data_buf2 = 0; - data_len = nlen; - } - if( trk_no == bad_track ) return -1; - - if( data_buf1 && trk_no == data_trk1 ) return 0; - - /* Two cases: - * 1) buffer2 has the one we want, need to swap to make it most recent - * 2) Neither has it, need to swap to overwrite least recent. - */ - - /* But sequential reads may spoil this so don't swap if we are shifting - * to the next track. - */ - - if( trk_no == data_trk2 || trk_no != data_trk1 + 1 ) - { - p = data_buf1; data_buf1 = data_buf2; data_buf2 = p; - t = data_trk1; data_trk1 = data_trk2; data_trk2 = t; - } - - /* The other one right ? */ - if( data_buf1 && trk_no == data_trk1 ) return 0; - - /* If we get here we have to do a physical read ... */ - /* into data_buf1. */ - - if( data_buf1 == 0 ) - { - data_buf1 = malloc(disk_spt*512); - -#ifdef DEBUG - if( data_buf1 ) - fprintf(stderr, "Allocated buffer to %d\n", data_buf1); - else - fprintf(stderr, "Failed to allocated buffer.\n"); -#endif - } - if( data_buf1 == 0 ) - { - /* Is buf2 allocated ? Yes take it! */ - data_buf1 = data_buf2; data_buf2 = 0; data_trk2 = -1; - } - - data_trk1 = -1; - - /* Not enough memory for track read. */ - if( data_buf1 == 0 ) return -1; - -#ifdef DEBUG - fprintf(stderr, "phy_read(%d,%d,%d,%d,%d,0x%x)\n", - disk_drive, phy_c, phy_h, phy_s/data_len*data_len+1, data_len, data_buf1); -#endif - - do /* the physical read */ - { - rv = phy_read(disk_drive, phy_c, phy_h, phy_s/data_len*data_len+1, data_len, - data_buf1); - tries--; - } - while(rv && tries > 0); - if( rv ) printf("Disk error 0x%02x %d:%d:%d:%d[%2d] -> 0x%04x[]\n", - rv, disk_drive, phy_c, phy_h, phy_s/data_len+1, data_len, data_buf1); - - check_motor = motor_running(); - - /* Disk error, it'll try one at a time, _very_ slowly! */ - if(rv) - { - bad_track = trk_no; - return -1; - } - - /* Yes! */ - data_trk1 = trk_no; - return 0; -} - -#if defined(__MSDOS__) || defined(__STANDALONE__) -phy_read(drive, cyl, head, sect, length, buffer) -{ -#asm - push bp - mov bp,sp - - push es - push ds - pop es - - mov dl,[bp+2+_phy_read.drive] - mov ch,[bp+2+_phy_read.cyl] - mov dh,[bp+2+_phy_read.head] - mov bx,[bp+2+_phy_read.buffer] - - mov ax,[bp+2+_phy_read.cyl] ! Bits 10-11 of cylinder, AMI BIOS. - mov cl,#4 - sar ax,cl - and al,#$C0 - xor dh,al - - mov cl,[bp+2+_phy_read.sect] - and cl,#$3F - mov ax,[bp+2+_phy_read.cyl] ! Bits 8-9 of cylinder. - sar ax,#1 - sar ax,#1 - and al,#$C0 - or cl,al - - mov al,[bp+2+_phy_read.length] - mov ah,#$02 - int $13 - jc read_err - mov ax,#0 -read_err: - xchg ah,al - xor ah,ah - - pop es - pop bp -#endasm -} - -long -get_dpt(drive) -{ -#asm - push bp - mov bp,sp - - push di - push es - - mov dl,[bp+2+_get_dpt.drive] - - mov ah,#$08 - int $13 - jnc func_ok - mov cx,ax - mov dx,#-1 -func_ok: - mov ax,cx - - pop es - pop di - pop bp -#endasm -} - -motor_running() -{ -#asm - push es - mov ax,#$40 - mov es,ax - seg es - mov al,[$3f] - xor ah,ah - and al,#$0F - pop es -#endasm -} -#endif - -#endif diff -Nurd linux86.vold/bootblocks/unix.c linux86/bootblocks/unix.c --- linux86.vold/bootblocks/unix.c 1998-07-24 15:02:13.000000000 +0100 +++ linux86/bootblocks/unix.c 2003-07-31 19:38:56.000000000 +0100 @@ -3,27 +3,27 @@ #ifdef __ELKS__ -bios_khit() { +kbhit() { return 0; } -bios_getc() { - return 0; +getch() { + return 3; } static int phy_fd = -1; static open_fd() { - phy_fd = open("/dev/fd0", 0); + phy_fd = open("/tmp/ramdisk", 0); if( phy_fd < 0 ) { - fprintf(stderr, "Cannot open /dev/fd0\n"); + fprintf(stderr, "Cannot open /dev/ramdisk\n"); phy_fd= -2; } } -phy_read(drive, cyl, head, sect, len, buffer) +_bios_disk_read(drive, cyl, head, sect, len, buffer) int drive, cyl, head, sect, len; char *buffer; { @@ -61,6 +61,16 @@ return 0; } +_bios_disk_reset() +{ +} + +motor_running() +{ + return 1; +} + +#if 0 putsect(buffer, address) char * buffer; int address; @@ -70,6 +80,7 @@ return 0; } #endif +#endif /* crctab calculated by Mark G. Mendel, Network Systems Corporation */ static unsigned short crctab[256] = {