Compare commits
4 Commits
tools
...
dual_sramc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ecdf678dac | ||
|
|
d859d3b71d | ||
|
|
3409198544 | ||
|
|
d6a6d80d6e |
5
Makefile
5
Makefile
@@ -82,7 +82,6 @@ SHARE_FILES = share/re.help share/example/Makefile \
|
|||||||
share/example/blkjack.bas share/example/hilow.bas \
|
share/example/blkjack.bas share/example/hilow.bas \
|
||||||
share/example/stars.bas share/example/prime.scm \
|
share/example/stars.bas share/example/prime.scm \
|
||||||
share/example/fact.fth share/example/echo.S \
|
share/example/fact.fth share/example/echo.S \
|
||||||
share/example/stdarg.c share/example/skeleton.c \
|
|
||||||
$(wildcard share/smallc/*)
|
$(wildcard share/smallc/*)
|
||||||
MANFILES = share/man/ share/man/cat1/ share/man/cat2/ share/man/cat3/ \
|
MANFILES = share/man/ share/man/cat1/ share/man/cat2/ share/man/cat3/ \
|
||||||
share/man/cat4/ share/man/cat5/ share/man/cat6/ share/man/cat7/ \
|
share/man/cat4/ share/man/cat5/ share/man/cat6/ share/man/cat7/ \
|
||||||
@@ -195,11 +194,11 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
# TODO: make it relative to Target
|
# TODO: make it relative to Target
|
||||||
installflash:
|
installflash:
|
||||||
sudo pic32prog sys/pic32/fubarino/unix.hex
|
sudo pic32prog sys/pic32/fubarino/unix.hex
|
||||||
|
|
||||||
# TODO: make it relative to Target
|
# TODO: make it relative to Target
|
||||||
installboot:
|
installboot:
|
||||||
sudo pic32prog sys/pic32/fubarino/bootloader.hex
|
sudo pic32prog sys/pic32/fubarino/bootloader.hex
|
||||||
|
|
||||||
.profile: etc/root/dot.profile
|
.profile: etc/root/dot.profile
|
||||||
|
|||||||
@@ -33,7 +33,29 @@
|
|||||||
#ifndef _AOUT_H_
|
#ifndef _AOUT_H_
|
||||||
#define _AOUT_H_
|
#define _AOUT_H_
|
||||||
|
|
||||||
#include <sys/exec_aout.h>
|
#include <sys/exec.h>
|
||||||
|
|
||||||
|
/* Valid magic number check. */
|
||||||
|
#define N_BADMAG(x) (((x).a_magic) != RMAGIC && \
|
||||||
|
((x).a_magic) != OMAGIC && \
|
||||||
|
((x).a_magic) != NMAGIC)
|
||||||
|
|
||||||
|
/* Text segment offset. */
|
||||||
|
#define N_TXTOFF(x) sizeof(struct exec)
|
||||||
|
|
||||||
|
/* Data segment offset. */
|
||||||
|
#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
|
||||||
|
|
||||||
|
/* Text relocation table offset. */
|
||||||
|
#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
|
||||||
|
|
||||||
|
/* Data relocation table offset. */
|
||||||
|
#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_reltext)
|
||||||
|
|
||||||
|
/* Symbol table offset. */
|
||||||
|
#define N_SYMOFF(x) ((x).a_magic == RMAGIC ? \
|
||||||
|
N_DRELOFF(x) + (x).a_reldata : \
|
||||||
|
N_DATOFF(x) + (x).a_data)
|
||||||
|
|
||||||
#define _AOUT_INCLUDE_
|
#define _AOUT_INCLUDE_
|
||||||
#include <nlist.h>
|
#include <nlist.h>
|
||||||
|
|||||||
@@ -4,49 +4,32 @@
|
|||||||
#ifndef _STDARG_H
|
#ifndef _STDARG_H
|
||||||
#define _STDARG_H
|
#define _STDARG_H
|
||||||
|
|
||||||
/*
|
/* Define __gnuc_va_list. */
|
||||||
* Define va_start, va_arg, va_end, va_copy.
|
|
||||||
*/
|
|
||||||
#if defined(__GNUC__) /* Gnu C */
|
|
||||||
# define va_start(ap, last) __builtin_va_start((ap), last)
|
|
||||||
# define va_arg(ap, type) __builtin_va_arg((ap), type)
|
|
||||||
# define va_end(ap) __builtin_va_end((ap))
|
|
||||||
# define va_copy(dest, src) __builtin_va_copy((dest), (src))
|
|
||||||
|
|
||||||
#elif defined(__PCC__) /* PCC */
|
|
||||||
# define va_start(ap, last) __builtin_stdarg_start((ap), last)
|
|
||||||
# define va_arg(ap, type) __builtin_va_arg((ap), type)
|
|
||||||
# define va_end(ap) __builtin_va_end((ap))
|
|
||||||
# define va_copy(dest, src) __builtin_va_copy((dest), (src))
|
|
||||||
|
|
||||||
#else /* SmallerC, LCC */
|
#ifdef __GNUC__
|
||||||
# define va_start(ap, last) (ap = ((char*)&(last) + \
|
# ifndef __GNUC_VA_LIST
|
||||||
(((sizeof(last) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))))
|
# define __GNUC_VA_LIST
|
||||||
# define va_arg(ap, type) ((type*)(ap += \
|
typedef __builtin_va_list __gnuc_va_list;
|
||||||
sizeof(type) == sizeof(int) ? sizeof(type) : \
|
# endif
|
||||||
(-(int)(ap) & (sizeof(type) - 1)) + sizeof(type)))[-1]
|
# define va_start(ap, last) __builtin_va_start((ap), last)
|
||||||
# define va_end(ap)
|
|
||||||
# define va_copy(dest, src) (dest = (src))
|
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __PCC__
|
||||||
|
# define va_start(ap, last) __builtin_stdarg_start((ap), last)
|
||||||
|
#endif
|
||||||
|
#define va_arg(ap, type) __builtin_va_arg((ap), type)
|
||||||
|
#define va_end(ap) __builtin_va_end((ap))
|
||||||
|
#define va_copy(dest, src) __builtin_va_copy((dest), (src))
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Define va_list.
|
|
||||||
*/
|
|
||||||
#ifndef _VA_LIST_T
|
#ifndef _VA_LIST_T
|
||||||
# define _VA_LIST_T
|
#define _VA_LIST_T
|
||||||
# if defined(__GNUC__) || defined(__PCC__)
|
#ifdef __GNUC__
|
||||||
typedef __builtin_va_list va_list;
|
typedef __builtin_va_list va_list;
|
||||||
# else
|
|
||||||
typedef char *va_list;
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __SMALLER_C__
|
||||||
/*
|
typedef int *va_list;
|
||||||
* Define __gnuc_va_list.
|
#endif
|
||||||
*/
|
|
||||||
#if defined(__GNUC__) && !defined(__GNUC_VA_LIST)
|
|
||||||
# define __GNUC_VA_LIST
|
|
||||||
typedef __builtin_va_list __gnuc_va_list;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* not _STDARG_H */
|
#endif /* not _STDARG_H */
|
||||||
|
|||||||
@@ -110,12 +110,7 @@ int scanf (const char *, ...);
|
|||||||
int sscanf (const char *, const char *, ...);
|
int sscanf (const char *, const char *, ...);
|
||||||
|
|
||||||
#ifndef _VA_LIST_
|
#ifndef _VA_LIST_
|
||||||
# ifdef __GNUC__
|
#define va_list __builtin_va_list /* For GCC */
|
||||||
# define va_list __builtin_va_list /* For Gnu C */
|
|
||||||
# endif
|
|
||||||
# ifdef __SMALLER_C__
|
|
||||||
# define va_list char * /* For Smaller C */
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int vfprintf (FILE *, const char *, va_list);
|
int vfprintf (FILE *, const char *, va_list);
|
||||||
@@ -131,7 +126,7 @@ int _doprnt (const char *, va_list, FILE *);
|
|||||||
int _doscan (FILE *, const char *, va_list);
|
int _doscan (FILE *, const char *, va_list);
|
||||||
|
|
||||||
#ifndef _VA_LIST_
|
#ifndef _VA_LIST_
|
||||||
# undef va_list
|
#undef va_list
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void perror (const char *);
|
void perror (const char *);
|
||||||
|
|||||||
@@ -54,51 +54,49 @@
|
|||||||
|
|
||||||
#define RAND_MAX 0x7fff
|
#define RAND_MAX 0x7fff
|
||||||
|
|
||||||
void abort (void);
|
void abort();
|
||||||
int abs (int);
|
int abs (int);
|
||||||
int atexit (void (*)(void));
|
int atexit (void (*)(void));
|
||||||
int atoi (const char *);
|
double atof();
|
||||||
long atol (const char *);
|
int atoi();
|
||||||
|
long atol();
|
||||||
void *calloc (size_t, size_t);
|
void *calloc (size_t, size_t);
|
||||||
void exit (int);
|
void exit (int);
|
||||||
void free (void *);
|
void free (void *);
|
||||||
char *getenv (const char *);
|
char *getenv();
|
||||||
long labs (long);
|
long labs (long);
|
||||||
void *malloc (size_t);
|
void *malloc (size_t);
|
||||||
char *mktemp (char *);
|
char *mktemp (char *);
|
||||||
int mkstemp (char *);
|
int mkstemp (char *);
|
||||||
void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
|
void qsort();
|
||||||
int rand (void);
|
int rand();
|
||||||
void *realloc (void*, size_t);
|
void *realloc (void*, size_t);
|
||||||
void srand (unsigned);
|
void srand();
|
||||||
long strtol (const char *, char **, int);
|
double strtod();
|
||||||
unsigned long strtoul (const char *, char **, int);
|
long strtol();
|
||||||
int system (const char *);
|
unsigned long strtoul();
|
||||||
|
int system();
|
||||||
|
|
||||||
int putenv (char *string);
|
int putenv (char *string);
|
||||||
int setenv (const char *name, const char *value, int overwrite);
|
int setenv (const char *name, const char *value, int overwrite);
|
||||||
int unsetenv (const char *name);
|
int unsetenv (const char *name);
|
||||||
char *_findenv (const char *name, int *offset);
|
char *_findenv (const char *name, int *offset);
|
||||||
|
|
||||||
void *alloca (size_t size);
|
void *alloca();
|
||||||
|
|
||||||
int daemon (int, int);
|
int daemon();
|
||||||
char *devname (dev_t dev, mode_t type);
|
char *devname();
|
||||||
int getloadavg (unsigned loadavg[], int nelem);
|
int getloadavg(unsigned loadavg[], int nelem);
|
||||||
|
|
||||||
extern char *suboptarg; /* getsubopt(3) external variable */
|
extern char *suboptarg; /* getsubopt(3) external variable */
|
||||||
int getsubopt (char **, char **, char **);
|
int getsubopt();
|
||||||
|
|
||||||
long random (void);
|
long random (void);
|
||||||
char *setstate (char *);
|
char *setstate (char *);
|
||||||
void srandom (unsigned);
|
void srandom (unsigned);
|
||||||
|
|
||||||
#ifndef __SMALLER_C__
|
char *ecvt (double, int, int *, int *);
|
||||||
double atof (const char *);
|
char *fcvt (double, int, int *, int *);
|
||||||
double strtod (const char *, char **);
|
char *gcvt (double, int, char *);
|
||||||
char *ecvt (double, int, int *, int *);
|
|
||||||
char *fcvt (double, int, int *, int *);
|
|
||||||
char *gcvt (double, int, char *);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* _STDLIB_H_ */
|
#endif /* _STDLIB_H_ */
|
||||||
|
|||||||
@@ -143,12 +143,7 @@ extern char *optarg; /* getopt(3) external variables */
|
|||||||
extern int opterr, optind, optopt;
|
extern int opterr, optind, optopt;
|
||||||
|
|
||||||
#ifndef _VA_LIST_
|
#ifndef _VA_LIST_
|
||||||
# ifdef __GNUC__
|
#define va_list __builtin_va_list /* For GCC */
|
||||||
# define va_list __builtin_va_list /* For Gnu C */
|
|
||||||
# endif
|
|
||||||
# ifdef __SMALLER_C__
|
|
||||||
# define va_list char * /* For Smaller C */
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void err (int eval, const char *fmt, ...);
|
void err (int eval, const char *fmt, ...);
|
||||||
@@ -161,6 +156,6 @@ void vwarn (const char *fmt, va_list ap);
|
|||||||
void vwarnx (const char *fmt, va_list ap);
|
void vwarnx (const char *fmt, va_list ap);
|
||||||
|
|
||||||
#ifndef _VA_LIST_
|
#ifndef _VA_LIST_
|
||||||
# undef va_list
|
#undef va_list
|
||||||
#endif
|
#endif
|
||||||
#endif /* !_UNISTD_H_ */
|
#endif /* !_UNISTD_H_ */
|
||||||
|
|||||||
1
lib/.gitignore
vendored
1
lib/.gitignore
vendored
@@ -11,4 +11,3 @@ ranlib.h
|
|||||||
retroImage
|
retroImage
|
||||||
size
|
size
|
||||||
strip
|
strip
|
||||||
gccdump.s
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
all: ashello echo chello
|
all: ashello echo
|
||||||
|
|
||||||
ashello: ashello.o
|
ashello: ashello.o
|
||||||
$(LD) ashello.o -o $@
|
$(LD) ashello.o -o $@
|
||||||
@@ -11,4 +11,4 @@ echo: echo.o
|
|||||||
$(LD) $@.o -o $@
|
$(LD) $@.o -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o ashello echo chello *.dis *~
|
rm -f *.o ashello echo *.dis *~
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ CFLAGS += -Werror
|
|||||||
ASFLAGS += -DCROSS
|
ASFLAGS += -DCROSS
|
||||||
ASLDFLAGS = --oformat=elf32-tradlittlemips -N -nostartfiles -T $(TOPSRC)/src/elf32-mips.ld
|
ASLDFLAGS = --oformat=elf32-tradlittlemips -N -nostartfiles -T $(TOPSRC)/src/elf32-mips.ld
|
||||||
|
|
||||||
all: chello cplus echo stdarg
|
all: hello cplus
|
||||||
|
|
||||||
chello: chello.o
|
hello: hello.o
|
||||||
${CC} ${LDFLAGS} -o chello.elf chello.o ${LIBS}
|
${CC} ${LDFLAGS} -o hello.elf hello.o ${LIBS}
|
||||||
${OBJDUMP} -S chello.elf > chello.dis
|
${OBJDUMP} -S hello.elf > hello.dis
|
||||||
${SIZE} chello.elf
|
${SIZE} hello.elf
|
||||||
${ELF2AOUT} chello.elf $@
|
${ELF2AOUT} hello.elf $@
|
||||||
|
|
||||||
cplus: cplus.o
|
cplus: cplus.o
|
||||||
${CXX} ${LDFLAGS} -nostdlib -o cplus.elf cplus.o ${LIBS}
|
${CXX} ${LDFLAGS} -nostdlib -o cplus.elf cplus.o ${LIBS}
|
||||||
@@ -24,6 +24,7 @@ echo: echo.o
|
|||||||
${OBJDUMP} -S $@.elf > $@.dis
|
${OBJDUMP} -S $@.elf > $@.dis
|
||||||
${SIZE} $@.elf
|
${SIZE} $@.elf
|
||||||
${ELF2AOUT} $@.elf $@
|
${ELF2AOUT} $@.elf $@
|
||||||
|
./aout $@ > $@.dis
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.elf ${MAN} chello cplus echo stdarg *.elf *.dis tags *~
|
rm -f *.o *.elf ${MAN} hello cplus *.elf *.dis tags *~
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
printf ("Hello, C World!\n");
|
printf ("Hello, C World!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Generic skeleton for a C program.
|
|
||||||
* When you create your own program based on this skeleton,
|
|
||||||
* you can replace the author's name and copyright with
|
|
||||||
* whatever your want. When you redistribute this skeleton or
|
|
||||||
* enhance it, please leave my name and copyright on it.
|
|
||||||
*
|
|
||||||
* Copyright (C) 1993-2014 Serge Vakulenko, <vak@cronyx.ru>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software
|
|
||||||
* and its documentation for any purpose and without fee is hereby
|
|
||||||
* granted, provided that the above copyright notice appear in all
|
|
||||||
* copies and that both that the copyright notice and this
|
|
||||||
* permission notice and warranty disclaimer appear in supporting
|
|
||||||
* documentation, and that the name of the author not be used in
|
|
||||||
* advertising or publicity pertaining to distribution of the
|
|
||||||
* software without specific, written prior permission.
|
|
||||||
*
|
|
||||||
* The author disclaim all warranties with regard to this
|
|
||||||
* software, including all implied warranties of merchantability
|
|
||||||
* and fitness. In no event shall the author be liable for any
|
|
||||||
* special, indirect or consequential damages or any damages
|
|
||||||
* whatsoever resulting from loss of use, data or profits, whether
|
|
||||||
* in an action of contract, negligence or other tortious action,
|
|
||||||
* arising out of or in connection with the use or performance of
|
|
||||||
* this software.
|
|
||||||
*/
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
const char version[] = "1.0";
|
|
||||||
const char copyright[] = "Copyright (C) 1993-2014 Serge Vakulenko";
|
|
||||||
|
|
||||||
char *progname; /* Name of the current program (argv[0]) */
|
|
||||||
int verbose; /* Option -v */
|
|
||||||
int trace; /* Option -t */
|
|
||||||
int debug; /* Option -d */
|
|
||||||
|
|
||||||
void usage ()
|
|
||||||
{
|
|
||||||
fprintf (stderr, "Generic C skeleton, Version %s, %s\n", version, copyright);
|
|
||||||
fprintf (stderr, "Usage:\n\t%s [-vtd] [-r count] file...\n", progname);
|
|
||||||
fprintf (stderr, "Options:\n");
|
|
||||||
fprintf (stderr, "\t-v\tverbose mode\n");
|
|
||||||
fprintf (stderr, "\t-t\ttrace mode\n");
|
|
||||||
fprintf (stderr, "\t-d\tdebug\n");
|
|
||||||
fprintf (stderr, "\t-r #\trepeat count\n");
|
|
||||||
exit (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
int count = 1; /* Option -r # */
|
|
||||||
|
|
||||||
progname = *argv;
|
|
||||||
for (;;) {
|
|
||||||
switch (getopt (argc, argv, "vtdr:")) {
|
|
||||||
case EOF:
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
++verbose;
|
|
||||||
continue;
|
|
||||||
case 't':
|
|
||||||
++trace;
|
|
||||||
continue;
|
|
||||||
case 'd':
|
|
||||||
++debug;
|
|
||||||
continue;
|
|
||||||
case 'r':
|
|
||||||
count = strtol (optarg, 0, 0);
|
|
||||||
continue;
|
|
||||||
default:
|
|
||||||
usage ();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
argc -= optind;
|
|
||||||
argv += optind;
|
|
||||||
|
|
||||||
if (argc < 1)
|
|
||||||
usage ();
|
|
||||||
|
|
||||||
while (count-- > 0) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0; i<argc; ++i)
|
|
||||||
printf ("%s ", argv[i]);
|
|
||||||
printf ("\n");
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
void print(char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
int d;
|
|
||||||
char c, *s;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
while (*fmt) {
|
|
||||||
switch (*fmt++) {
|
|
||||||
case 's': /* string */
|
|
||||||
s = va_arg(ap, char*);
|
|
||||||
printf("string %s\n", s);
|
|
||||||
break;
|
|
||||||
case 'd': /* int */
|
|
||||||
d = va_arg(ap, int);
|
|
||||||
printf("int %d\n", d);
|
|
||||||
break;
|
|
||||||
case 'c': /* char */
|
|
||||||
c = va_arg(ap, int);
|
|
||||||
printf("char %c\n", c);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
print("sdcsdc", "abracadabra", 12345, 'Z', "foo", 365, '%');
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -55,7 +55,7 @@ int fgethdr (text, h)
|
|||||||
register FILE *text;
|
register FILE *text;
|
||||||
register struct exec *h;
|
register struct exec *h;
|
||||||
{
|
{
|
||||||
h->a_midmag = fgetword (text);
|
h->a_magic = fgetword (text);
|
||||||
h->a_text = fgetword (text);
|
h->a_text = fgetword (text);
|
||||||
h->a_data = fgetword (text);
|
h->a_data = fgetword (text);
|
||||||
h->a_bss = fgetword (text);
|
h->a_bss = fgetword (text);
|
||||||
@@ -235,7 +235,7 @@ void disasm (fname)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (rflag) {
|
if (rflag) {
|
||||||
if (N_GETMAGIC(hdr) != RMAGIC) {
|
if (hdr.a_magic != RMAGIC) {
|
||||||
fprintf (stderr, "aout: %s is not relocatable\n",
|
fprintf (stderr, "aout: %s is not relocatable\n",
|
||||||
fname);
|
fname);
|
||||||
rflag = 0;
|
rflag = 0;
|
||||||
@@ -250,9 +250,9 @@ void disasm (fname)
|
|||||||
}
|
}
|
||||||
printf ("File %s:\n", fname);
|
printf ("File %s:\n", fname);
|
||||||
printf (" a_magic = %08x (%s)\n", hdr.a_magic,
|
printf (" a_magic = %08x (%s)\n", hdr.a_magic,
|
||||||
N_GETMAGIC(hdr) == RMAGIC ? "relocatable" :
|
hdr.a_magic == RMAGIC ? "relocatable" :
|
||||||
N_GETMAGIC(hdr) == OMAGIC ? "OMAGIC" :
|
hdr.a_magic == OMAGIC ? "OMAGIC" :
|
||||||
N_GETMAGIC(hdr) == NMAGIC ? "NMAGIC" : "unknown");
|
hdr.a_magic == NMAGIC ? "NMAGIC" : "unknown");
|
||||||
printf (" a_text = %08x (%u bytes)\n", hdr.a_text, hdr.a_text);
|
printf (" a_text = %08x (%u bytes)\n", hdr.a_text, hdr.a_text);
|
||||||
printf (" a_data = %08x (%u bytes)\n", hdr.a_data, hdr.a_data);
|
printf (" a_data = %08x (%u bytes)\n", hdr.a_data, hdr.a_data);
|
||||||
printf (" a_bss = %08x (%u bytes)\n", hdr.a_bss, hdr.a_bss);
|
printf (" a_bss = %08x (%u bytes)\n", hdr.a_bss, hdr.a_bss);
|
||||||
@@ -261,7 +261,7 @@ void disasm (fname)
|
|||||||
printf (" a_syms = %08x (%u bytes)\n", hdr.a_syms, hdr.a_syms);
|
printf (" a_syms = %08x (%u bytes)\n", hdr.a_syms, hdr.a_syms);
|
||||||
printf (" a_entry = %08x\n", hdr.a_entry);
|
printf (" a_entry = %08x\n", hdr.a_entry);
|
||||||
|
|
||||||
addr = ((hdr.a_magic) == RMAGIC) ? 0 : USER_CODE_START;
|
addr = (hdr.a_magic == RMAGIC) ? 0 : USER_CODE_START;
|
||||||
|
|
||||||
if (hdr.a_text > 0) {
|
if (hdr.a_text > 0) {
|
||||||
printf ("\nSection .text:\n");
|
printf ("\nSection .text:\n");
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ enum {
|
|||||||
LIDENT, /* .ident */
|
LIDENT, /* .ident */
|
||||||
LWEAK, /* .weak */
|
LWEAK, /* .weak */
|
||||||
LLOCAL, /* .local */
|
LLOCAL, /* .local */
|
||||||
LNAN, /* .nan */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -373,7 +372,7 @@ int mode_reorder = 1; /* .set reorder option (default) */
|
|||||||
int mode_macro; /* .set macro option */
|
int mode_macro; /* .set macro option */
|
||||||
int mode_mips16; /* .set mips16 option */
|
int mode_mips16; /* .set mips16 option */
|
||||||
int mode_micromips; /* .set micromips option */
|
int mode_micromips; /* .set micromips option */
|
||||||
int mode_at = 1; /* .set at option */
|
int mode_at; /* .set at option */
|
||||||
int reorder_full; /* instruction buffered for reorder */
|
int reorder_full; /* instruction buffered for reorder */
|
||||||
unsigned reorder_word; /* buffered instruction... */
|
unsigned reorder_word; /* buffered instruction... */
|
||||||
unsigned reorder_clobber; /* ...modified this register */
|
unsigned reorder_clobber; /* ...modified this register */
|
||||||
@@ -732,9 +731,6 @@ int lookacmd ()
|
|||||||
case 'm':
|
case 'm':
|
||||||
if (! strcmp (".mask", name)) return (LMASK);
|
if (! strcmp (".mask", name)) return (LMASK);
|
||||||
break;
|
break;
|
||||||
case 'n':
|
|
||||||
if (! strcmp (".nan", name)) return (LNAN);
|
|
||||||
break;
|
|
||||||
case 'p':
|
case 'p':
|
||||||
if (! strcmp (".previous", name)) return (LPREVIOUS);
|
if (! strcmp (".previous", name)) return (LPREVIOUS);
|
||||||
break;
|
break;
|
||||||
@@ -1242,7 +1238,7 @@ void emitword (w, r, clobber_reg)
|
|||||||
reorder_word = w;
|
reorder_word = w;
|
||||||
reorder_rel = *r;
|
reorder_rel = *r;
|
||||||
reorder_full = 1;
|
reorder_full = 1;
|
||||||
reorder_clobber = clobber_reg & 15;
|
reorder_clobber = clobber_reg;
|
||||||
} else {
|
} else {
|
||||||
fputword (w, sfile[segm]);
|
fputword (w, sfile[segm]);
|
||||||
fputrel (r, rfile[segm]);
|
fputrel (r, rfile[segm]);
|
||||||
@@ -1321,9 +1317,10 @@ void makecmd (opcode, type, emitfunc)
|
|||||||
unsigned opcode;
|
unsigned opcode;
|
||||||
void (*emitfunc) (unsigned, struct reloc*);
|
void (*emitfunc) (unsigned, struct reloc*);
|
||||||
{
|
{
|
||||||
unsigned offset, orig_opcode = 0;
|
register int clex;
|
||||||
|
register unsigned offset;
|
||||||
struct reloc relinfo;
|
struct reloc relinfo;
|
||||||
int clex, cval, segment, clobber_reg, negate_literal;
|
int cval, segment, clobber_reg, negate_literal;
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
relinfo.flags = RABS;
|
relinfo.flags = RABS;
|
||||||
@@ -1483,7 +1480,6 @@ frs1: clex = getlex (&cval);
|
|||||||
cval = (opcode >> 11) & 31; /* get 1-st register */
|
cval = (opcode >> 11) & 31; /* get 1-st register */
|
||||||
newop |= cval << 16; /* set 1-st register */
|
newop |= cval << 16; /* set 1-st register */
|
||||||
newop |= opcode & (31 << 21); /* set 2-nd register */
|
newop |= opcode & (31 << 21); /* set 2-nd register */
|
||||||
orig_opcode = opcode;
|
|
||||||
opcode = newop;
|
opcode = newop;
|
||||||
type = FRT1 | FRS2 | FOFF16 | FMOD;
|
type = FRT1 | FRS2 | FOFF16 | FMOD;
|
||||||
goto foff16;
|
goto foff16;
|
||||||
@@ -1576,65 +1572,24 @@ fsa: offset = getexpr (&segment);
|
|||||||
}
|
}
|
||||||
} else if (type & (FOFF16 | FOFF18 | FAOFF18 | FAOFF28 | FHIGH16)) {
|
} else if (type & (FOFF16 | FOFF18 | FAOFF18 | FAOFF28 | FHIGH16)) {
|
||||||
/* Relocatable offset */
|
/* Relocatable offset */
|
||||||
int valid_range;
|
|
||||||
|
|
||||||
if ((type & (FOFF16 | FOFF18 | FHIGH16)) && getlex (&cval) != ',')
|
if ((type & (FOFF16 | FOFF18 | FHIGH16)) && getlex (&cval) != ',')
|
||||||
uerror ("comma expected");
|
uerror ("comma expected");
|
||||||
foff16: expr_flags = 0;
|
foff16: expr_flags = 0;
|
||||||
offset = getexpr (&segment);
|
offset = getexpr (&segment);
|
||||||
relinfo.flags = segmrel [segment];
|
relinfo.flags = segmrel [segment];
|
||||||
|
if (negate_literal) {
|
||||||
|
// Negate literal arg for sub and subu
|
||||||
|
offset = -offset;
|
||||||
|
if (relinfo.flags != RABS)
|
||||||
|
uerror ("cannot negate relocatable literal");
|
||||||
|
}
|
||||||
if (relinfo.flags == REXT)
|
if (relinfo.flags == REXT)
|
||||||
relinfo.index = extref;
|
relinfo.index = extref;
|
||||||
if (expr_flags & EXPR_GPREL)
|
if (expr_flags & EXPR_GPREL)
|
||||||
relinfo.flags |= RGPREL;
|
relinfo.flags |= RGPREL;
|
||||||
switch (type & (FOFF16 | FOFF18 | FAOFF18 | FAOFF28 | FHIGH16)) {
|
switch (type & (FOFF16 | FOFF18 | FAOFF18 | FAOFF28 | FHIGH16)) {
|
||||||
case FOFF16: /* low 16-bit byte address */
|
case FOFF16: /* low 16-bit byte address */
|
||||||
/* Test whether the immediate is in valid range
|
opcode |= offset & 0xffff;
|
||||||
* for the opcode. */
|
|
||||||
if (negate_literal) {
|
|
||||||
// Negate literal arg for sub and subu
|
|
||||||
offset = -offset;
|
|
||||||
if (relinfo.flags != RABS)
|
|
||||||
uerror ("cannot negate relocatable literal");
|
|
||||||
}
|
|
||||||
switch (opcode & 0xfc000000) {
|
|
||||||
default: /* addi, addiu, slti, sltiu, lw, sw */
|
|
||||||
/* 16-bit signed value. */
|
|
||||||
valid_range = (offset >= -0x8000) || (offset <= 0x7fff);
|
|
||||||
break;
|
|
||||||
case 0x30000000: /* andi */
|
|
||||||
case 0x34000000: /* ori */
|
|
||||||
case 0x38000000: /* xori */
|
|
||||||
/* 16-bit unsigned value. */
|
|
||||||
valid_range = (offset <= 0xffff);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (valid_range) {
|
|
||||||
opcode |= offset & 0xffff;
|
|
||||||
} else if (orig_opcode == 0 || ! mode_at) {
|
|
||||||
uerror ("value out of range");
|
|
||||||
} else {
|
|
||||||
/* Convert back to 3-reg opcode.
|
|
||||||
* Insert an extra LI instruction. */
|
|
||||||
if (segment != SABS)
|
|
||||||
uerror ("absolute value required");
|
|
||||||
if (negate_literal)
|
|
||||||
offset = -offset;
|
|
||||||
|
|
||||||
if (offset <= 0xffff) {
|
|
||||||
/* ori $1, $zero, value */
|
|
||||||
emitword (0x34010000 | offset, &relabs, 1);
|
|
||||||
} else if (offset >= -0x8000) {
|
|
||||||
/* addiu $1, $zero, value */
|
|
||||||
emitword (0x24010000 | (offset & 0xffff), &relabs, 1);
|
|
||||||
} else {
|
|
||||||
/* lui $1, value[31:16]
|
|
||||||
* ori $1, $1, value[15:0]) */
|
|
||||||
emitword (0x3c010000 | (offset >> 16), &relabs, 1);
|
|
||||||
emitword (0x34210000 | (offset & 0xffff), &relabs, 1);
|
|
||||||
}
|
|
||||||
opcode = orig_opcode | 0x10000;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case FHIGH16: /* high 16-bit byte address */
|
case FHIGH16: /* high 16-bit byte address */
|
||||||
if (expr_flags & EXPR_HI) {
|
if (expr_flags & EXPR_HI) {
|
||||||
@@ -2202,7 +2157,7 @@ void pass1 ()
|
|||||||
case LSECTION:
|
case LSECTION:
|
||||||
/* .section name[,"flags"[,type[,entsize]]] */
|
/* .section name[,"flags"[,type[,entsize]]] */
|
||||||
clex = getlex (&cval);
|
clex = getlex (&cval);
|
||||||
if (clex != LNAME && clex != LBSS && clex != LTEXT && clex != LDATA)
|
if (clex != LNAME && clex != LBSS)
|
||||||
uerror ("bad name of .section");
|
uerror ("bad name of .section");
|
||||||
setsection();
|
setsection();
|
||||||
clex = getlex (&cval);
|
clex = getlex (&cval);
|
||||||
@@ -2210,12 +2165,7 @@ void pass1 ()
|
|||||||
ungetlex (clex, cval);
|
ungetlex (clex, cval);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
clex = getlex (&cval);
|
skipstring();
|
||||||
if (clex == '"') {
|
|
||||||
ungetlex (clex, cval);
|
|
||||||
skipstring();
|
|
||||||
} else if (clex != LNAME)
|
|
||||||
uerror ("bad type of .section");
|
|
||||||
clex = getlex (&cval);
|
clex = getlex (&cval);
|
||||||
if (clex != ',') {
|
if (clex != ',') {
|
||||||
ungetlex (clex, cval);
|
ungetlex (clex, cval);
|
||||||
@@ -2262,12 +2212,6 @@ void pass1 ()
|
|||||||
uerror ("bad parameter of .end");
|
uerror ("bad parameter of .end");
|
||||||
cval = lookname();
|
cval = lookname();
|
||||||
break;
|
break;
|
||||||
case LNAN:
|
|
||||||
/* .nan name */
|
|
||||||
clex = getlex (&cval);
|
|
||||||
if (clex != LNAME)
|
|
||||||
uerror ("bad parameter of .nan");
|
|
||||||
break;
|
|
||||||
case LTYPE:
|
case LTYPE:
|
||||||
/* .type name,type */
|
/* .type name,type */
|
||||||
if (getlex (&cval) != LNAME)
|
if (getlex (&cval) != LNAME)
|
||||||
@@ -2397,7 +2341,7 @@ void makeheader (rtsize, rdsize)
|
|||||||
{
|
{
|
||||||
struct exec hdr;
|
struct exec hdr;
|
||||||
|
|
||||||
hdr.a_midmag = RMAGIC;
|
hdr.a_magic = RMAGIC;
|
||||||
hdr.a_text = count [STEXT];
|
hdr.a_text = count [STEXT];
|
||||||
hdr.a_data = count [SDATA] + count [SSTRNG];
|
hdr.a_data = count [SDATA] + count [SSTRNG];
|
||||||
hdr.a_bss = count [SBSS];
|
hdr.a_bss = count [SBSS];
|
||||||
@@ -2717,12 +2661,8 @@ int main (argc, argv)
|
|||||||
break;
|
break;
|
||||||
case 'I': /* include dir */
|
case 'I': /* include dir */
|
||||||
// TODO
|
// TODO
|
||||||
if (cp[1] == 0) {
|
while (*++cp);
|
||||||
i++;
|
--cp;
|
||||||
} else {
|
|
||||||
while (*++cp);
|
|
||||||
--cp;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'O': /* optimization level */
|
case 'O': /* optimization level */
|
||||||
// TODO
|
// TODO
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ RDHWR Read Hardware Register Allows unprivileged acce
|
|||||||
RDPGPR Read GPR from Previous Shadow Set Rt = SGPR[SRSCtl.PSS, Rd]
|
RDPGPR Read GPR from Previous Shadow Set Rt = SGPR[SRSCtl.PSS, Rd]
|
||||||
|
|
||||||
RESTORE Restore registers and deallocate stack See Architecture Reference Manual
|
RESTORE Restore registers and deallocate stack See Architecture Reference Manual
|
||||||
frame (MIPS16e only)
|
frame (MIPS16eª only)
|
||||||
|
|
||||||
ROTR Rotate Word Right Rd = Rt[sa-1..0] || Rt[31..sa]
|
ROTR Rotate Word Right Rd = Rt[sa-1..0] || Rt[31..sa]
|
||||||
|
|
||||||
|
|||||||
@@ -1534,7 +1534,7 @@ int get_value()
|
|||||||
value = get_num();
|
value = get_num();
|
||||||
else {
|
else {
|
||||||
++cmdptr;
|
++cmdptr;
|
||||||
switch ((int)c) {
|
switch (c) {
|
||||||
case '(': /* nesting */
|
case '(': /* nesting */
|
||||||
value = eval_sub();
|
value = eval_sub();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -26,4 +26,4 @@ clean:
|
|||||||
install: all
|
install: all
|
||||||
install cc $(DESTDIR)/bin/
|
install cc $(DESTDIR)/bin/
|
||||||
install cc $(DESTDIR)/bin/scc
|
install cc $(DESTDIR)/bin/scc
|
||||||
install cc $(DESTDIR)/bin/lcc
|
install cc $(DESTDIR)/bin/srcc
|
||||||
|
|||||||
@@ -449,16 +449,17 @@ main(int argc, char *argv[])
|
|||||||
pass0 = LIBEXECDIR "/smallc";
|
pass0 = LIBEXECDIR "/smallc";
|
||||||
incdir = STDINC "/smallc";
|
incdir = STDINC "/smallc";
|
||||||
|
|
||||||
} else if (strcmp ("lcc", progname) == 0) {
|
} else if (strcmp ("srcc", progname) == 0) {
|
||||||
/* LCC: retargetable C compiler. */
|
|
||||||
mode = MODE_LCC;
|
|
||||||
cppadd[0] = "-D__LCC__";
|
|
||||||
pass0 = LIBEXECDIR "/lccom";
|
|
||||||
} else {
|
|
||||||
/* Smaller C. */
|
/* Smaller C. */
|
||||||
mode = MODE_SMALLERC;
|
mode = MODE_SMALLERC;
|
||||||
cppadd[0] = "-D__SMALLER_C__";
|
cppadd[0] = "-D__SMALLER_C__";
|
||||||
pass0 = LIBEXECDIR "/smlrc";
|
pass0 = LIBEXECDIR "/smlrc";
|
||||||
|
incdir = STDINC "/smallerc";
|
||||||
|
} else {
|
||||||
|
/* LCC: retargetable C compiler. */
|
||||||
|
mode = MODE_LCC;
|
||||||
|
cppadd[0] = "-D__LCC__";
|
||||||
|
pass0 = LIBEXECDIR "/lccom";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ $(MAN): ${MANSRC}
|
|||||||
${MANROFF} $< > $@
|
${MANROFF} $< > $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.0 *.elf cpp *.dis tags *~ lex.yy.c y.tab.[ch] tests/run*
|
rm -f *.o *.0 *.elf cpp *.elf *.dis tags *~ lex.yy.c y.tab.[ch] tests/run*
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
install cpp $(DESTDIR)/bin/
|
install cpp $(DESTDIR)/bin/
|
||||||
@@ -41,23 +41,23 @@ cpy.o y.tab.h: cpy.y
|
|||||||
$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -c -o cpy.o y.tab.c
|
$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -c -o cpy.o y.tab.c
|
||||||
|
|
||||||
test:
|
test:
|
||||||
./cpp < tests/test1 > tests/run1
|
./cpp.elf < tests/test1 > tests/run1
|
||||||
cmp tests/run1 tests/res1
|
cmp tests/run1 tests/res1
|
||||||
./cpp < tests/test2 > tests/run2
|
./cpp.elf < tests/test2 > tests/run2
|
||||||
cmp tests/run2 tests/res2
|
cmp tests/run2 tests/res2
|
||||||
./cpp < tests/test3 > tests/run3
|
./cpp.elf < tests/test3 > tests/run3
|
||||||
cmp tests/run3 tests/res3
|
cmp tests/run3 tests/res3
|
||||||
./cpp < tests/test4 > tests/run4
|
./cpp.elf < tests/test4 > tests/run4
|
||||||
cmp tests/run4 tests/res4
|
cmp tests/run4 tests/res4
|
||||||
./cpp < tests/test5 > tests/run5
|
./cpp.elf < tests/test5 > tests/run5
|
||||||
cmp tests/run5 tests/res5
|
cmp tests/run5 tests/res5
|
||||||
./cpp < tests/test6 > tests/run6
|
./cpp.elf < tests/test6 > tests/run6
|
||||||
cmp tests/run6 tests/res6
|
cmp tests/run6 tests/res6
|
||||||
./cpp < tests/test7 > tests/run7
|
./cpp.elf < tests/test7 > tests/run7
|
||||||
cmp tests/run7 tests/res7
|
cmp tests/run7 tests/res7
|
||||||
./cpp < tests/test8 > tests/run8
|
./cpp.elf < tests/test8 > tests/run8
|
||||||
cmp tests/run8 tests/res8
|
cmp tests/run8 tests/res8
|
||||||
./cpp < tests/test9 > tests/run9
|
./cpp.elf < tests/test9 > tests/run9
|
||||||
cmp tests/run9 tests/res9
|
cmp tests/run9 tests/res9
|
||||||
./cpp < tests/test10 > tests/run10
|
./cpp.elf < tests/test10 > tests/run10
|
||||||
cmp tests/run10 tests/res10
|
cmp tests/run10 tests/res10
|
||||||
|
|||||||
@@ -350,8 +350,7 @@ addidir(char *idir, struct incs **ww)
|
|||||||
return;
|
return;
|
||||||
ww = &w->next;
|
ww = &w->next;
|
||||||
}
|
}
|
||||||
w = calloc(sizeof(struct incs), 1);
|
if ((w = calloc(sizeof(struct incs), 1)) == NULL)
|
||||||
if (w == NULL)
|
|
||||||
error("couldn't add path %s", idir);
|
error("couldn't add path %s", idir);
|
||||||
w->dir = (uchar *)idir;
|
w->dir = (uchar *)idir;
|
||||||
w->dev = st.st_dev;
|
w->dev = st.st_dev;
|
||||||
@@ -1311,18 +1310,14 @@ expdef(const uchar *vp, struct recur *rp, int gotwarn)
|
|||||||
int ellips = 0, shot = gotwarn;
|
int ellips = 0, shot = gotwarn;
|
||||||
|
|
||||||
DPRINT(("expdef rp %s\n", (rp ? (const char *)rp->sp->namep : "")));
|
DPRINT(("expdef rp %s\n", (rp ? (const char *)rp->sp->namep : "")));
|
||||||
c = sloscan();
|
if ((c = sloscan()) != '(')
|
||||||
if (c != '(')
|
|
||||||
error("got %c, expected (", c);
|
error("got %c, expected (", c);
|
||||||
|
|
||||||
if (vp[1] == VARG) {
|
if (vp[1] == VARG) {
|
||||||
narg = *vp--;
|
narg = *vp--;
|
||||||
ellips = 1;
|
ellips = 1;
|
||||||
} else
|
} else
|
||||||
narg = vp[1];
|
narg = vp[1];
|
||||||
|
if ((args = malloc(sizeof(uchar *) * (narg+ellips))) == NULL)
|
||||||
args = malloc(sizeof(uchar *) * (narg+ellips));
|
|
||||||
if (args == NULL)
|
|
||||||
error("expdef: out of mem");
|
error("expdef: out of mem");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ extern int ofd;
|
|||||||
#define ENTER 1
|
#define ENTER 1
|
||||||
|
|
||||||
/* buffer used internally */
|
/* buffer used internally */
|
||||||
#define CPPBUF 512
|
#define CPPBUF BUFSIZ
|
||||||
|
|
||||||
#define NAMEMAX CPPBUF /* currently pushbackbuffer */
|
#define NAMEMAX CPPBUF /* currently pushbackbuffer */
|
||||||
|
|
||||||
@@ -138,8 +138,13 @@ void line(void);
|
|||||||
uchar *sheap(const char *fmt, ...);
|
uchar *sheap(const char *fmt, ...);
|
||||||
void xwarning(uchar *);
|
void xwarning(uchar *);
|
||||||
void xerror(uchar *);
|
void xerror(uchar *);
|
||||||
#define warning(args...) xwarning(sheap(args))
|
#ifdef HAVE_CPP_VARARG_MACRO_GCC
|
||||||
#define error(args...) xerror(sheap(args))
|
#define warning(...) xwarning(sheap(__VA_ARGS__))
|
||||||
|
#define error(...) xerror(sheap(__VA_ARGS__))
|
||||||
|
#else
|
||||||
|
#define warning printf
|
||||||
|
#define error printf
|
||||||
|
#endif
|
||||||
void expmac(struct recur *);
|
void expmac(struct recur *);
|
||||||
int cinput(void);
|
int cinput(void);
|
||||||
void getcmnt(void);
|
void getcmnt(void);
|
||||||
|
|||||||
932
src/cmd/cpp/scanner.l
Normal file
932
src/cmd/cpp/scanner.l
Normal file
@@ -0,0 +1,932 @@
|
|||||||
|
%{
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2004 Anders Magnusson. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
|
#include "cpp.h"
|
||||||
|
#include "y.tab.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%{
|
||||||
|
static void cvtdig(int rad);
|
||||||
|
static int charcon(uchar *);
|
||||||
|
static void elsestmt(void);
|
||||||
|
static void ifdefstmt(void);
|
||||||
|
static void ifndefstmt(void);
|
||||||
|
static void endifstmt(void);
|
||||||
|
static void ifstmt(void);
|
||||||
|
static void cpperror(void);
|
||||||
|
static void pragmastmt(void);
|
||||||
|
static void undefstmt(void);
|
||||||
|
static void cpperror(void);
|
||||||
|
static void elifstmt(void);
|
||||||
|
static void storepb(void);
|
||||||
|
static void badop(const char *);
|
||||||
|
void include(void);
|
||||||
|
void define(void);
|
||||||
|
|
||||||
|
extern int yyget_lineno (void);
|
||||||
|
extern void yyset_lineno (int);
|
||||||
|
|
||||||
|
static int inch(void);
|
||||||
|
|
||||||
|
static int scale, gotdef, contr;
|
||||||
|
int inif;
|
||||||
|
|
||||||
|
#ifdef FLEX_SCANNER /* should be set by autoconf instead */
|
||||||
|
static int
|
||||||
|
yyinput(char *b, int m)
|
||||||
|
{
|
||||||
|
int c, i;
|
||||||
|
|
||||||
|
for (i = 0; i < m; i++) {
|
||||||
|
if ((c = inch()) < 0)
|
||||||
|
break;
|
||||||
|
*b++ = c;
|
||||||
|
if (c == '\n') {
|
||||||
|
i++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
#undef YY_INPUT
|
||||||
|
#undef YY_BUF_SIZE
|
||||||
|
#define YY_BUF_SIZE (8*65536)
|
||||||
|
#define YY_INPUT(b,r,m) (r = yyinput(b, m))
|
||||||
|
#ifdef HAVE_CPP_VARARG_MACRO_GCC
|
||||||
|
#define fprintf(x, ...) error(__VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
#define ECHO putstr((uchar *)yytext)
|
||||||
|
#undef fileno
|
||||||
|
#define fileno(x) 0
|
||||||
|
|
||||||
|
#if YY_FLEX_SUBMINOR_VERSION >= 31
|
||||||
|
/* Hack to avoid unnecessary warnings */
|
||||||
|
FILE *yyget_in (void);
|
||||||
|
FILE *yyget_out (void);
|
||||||
|
int yyget_leng (void);
|
||||||
|
char *yyget_text (void);
|
||||||
|
void yyset_in (FILE * in_str );
|
||||||
|
void yyset_out (FILE * out_str );
|
||||||
|
int yyget_debug (void);
|
||||||
|
void yyset_debug (int bdebug );
|
||||||
|
int yylex_destroy (void);
|
||||||
|
#endif
|
||||||
|
#else /* Assume lex here */
|
||||||
|
#undef input
|
||||||
|
#undef unput
|
||||||
|
#define input() inch()
|
||||||
|
#define unput(ch) unch(ch)
|
||||||
|
#endif
|
||||||
|
#define PRTOUT(x) if (YYSTATE || slow) return x; if (!flslvl) putstr((uchar *)yytext);
|
||||||
|
/* protection against recursion in #include */
|
||||||
|
#define MAX_INCLEVEL 100
|
||||||
|
static int inclevel;
|
||||||
|
%}
|
||||||
|
|
||||||
|
D [0-9]
|
||||||
|
L [a-zA-Z_]
|
||||||
|
H [a-fA-F0-9]
|
||||||
|
E [Ee][+-]?{D}+
|
||||||
|
FS (f|F|l|L)
|
||||||
|
IS (u|U|l|L)*
|
||||||
|
WS [\t ]
|
||||||
|
|
||||||
|
%s IFR CONTR DEF COMMENT
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
"\n" { int os = YYSTATE;
|
||||||
|
if (os != IFR)
|
||||||
|
BEGIN 0;
|
||||||
|
ifiles->lineno++;
|
||||||
|
if (flslvl == 0) {
|
||||||
|
if (ifiles->lineno == 1)
|
||||||
|
prtline();
|
||||||
|
else
|
||||||
|
putch('\n');
|
||||||
|
}
|
||||||
|
if ((os != 0 || slow) && !contr)
|
||||||
|
return '\n';
|
||||||
|
contr = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
"\r" { ; /* Ignore CR's */ }
|
||||||
|
|
||||||
|
<IFR>"++" { badop("++"); }
|
||||||
|
<IFR>"--" { badop("--"); }
|
||||||
|
<IFR>"==" { return EQ; }
|
||||||
|
<IFR>"!=" { return NE; }
|
||||||
|
<IFR>"<=" { return LE; }
|
||||||
|
<IFR>"<<" { return LS; }
|
||||||
|
<IFR>">>" { return RS; }
|
||||||
|
<IFR>">=" { return GE; }
|
||||||
|
<IFR>"||" { return OROR; }
|
||||||
|
<IFR>"&&" { return ANDAND; }
|
||||||
|
<IFR>"defined" { int p, c;
|
||||||
|
gotdef = 1;
|
||||||
|
if ((p = c = yylex()) == '(')
|
||||||
|
c = yylex();
|
||||||
|
if (c != IDENT || (p != IDENT && p != '('))
|
||||||
|
error("syntax error");
|
||||||
|
if (p == '(' && yylex() != ')')
|
||||||
|
error("syntax error");
|
||||||
|
return NUMBER;
|
||||||
|
}
|
||||||
|
|
||||||
|
<IFR>{WS}+ { ; }
|
||||||
|
<IFR>{L}({L}|{D})* {
|
||||||
|
yylval.node.op = NUMBER;
|
||||||
|
if (gotdef) {
|
||||||
|
yylval.node.nd_val
|
||||||
|
= lookup((uchar *)yytext, FIND) != 0;
|
||||||
|
gotdef = 0;
|
||||||
|
return IDENT;
|
||||||
|
}
|
||||||
|
yylval.node.nd_val = 0;
|
||||||
|
return NUMBER;
|
||||||
|
}
|
||||||
|
|
||||||
|
[0-9][0-9]* {
|
||||||
|
if (slow && !YYSTATE)
|
||||||
|
return IDENT;
|
||||||
|
scale = yytext[0] == '0' ? 8 : 10;
|
||||||
|
goto num;
|
||||||
|
}
|
||||||
|
|
||||||
|
0[xX]{H}+{IS}? { scale = 16;
|
||||||
|
num: if (YYSTATE == IFR)
|
||||||
|
cvtdig(scale);
|
||||||
|
PRTOUT(NUMBER);
|
||||||
|
}
|
||||||
|
0{D}+{IS}? { scale = 8; goto num; }
|
||||||
|
{D}+{IS}? { scale = 10; goto num; }
|
||||||
|
'(\\.|[^\\'])+' {
|
||||||
|
if (YYSTATE || slow) {
|
||||||
|
yylval.node.op = NUMBER;
|
||||||
|
yylval.node.nd_val = charcon((uchar *)yytext);
|
||||||
|
return (NUMBER);
|
||||||
|
}
|
||||||
|
if (tflag)
|
||||||
|
yyless(1);
|
||||||
|
if (!flslvl)
|
||||||
|
putstr((uchar *)yytext);
|
||||||
|
}
|
||||||
|
|
||||||
|
<IFR>. { return yytext[0]; }
|
||||||
|
|
||||||
|
{D}+{E}{FS}? { PRTOUT(FPOINT); }
|
||||||
|
{D}*"."{D}+({E})?{FS}? { PRTOUT(FPOINT); }
|
||||||
|
{D}+"."{D}*({E})?{FS}? { PRTOUT(FPOINT); }
|
||||||
|
|
||||||
|
^{WS}*#{WS}* { extern int inmac;
|
||||||
|
|
||||||
|
if (inmac)
|
||||||
|
error("preprocessor directive found "
|
||||||
|
"while expanding macro");
|
||||||
|
contr = 1;
|
||||||
|
BEGIN CONTR;
|
||||||
|
}
|
||||||
|
{WS}+ { PRTOUT(WSPACE); }
|
||||||
|
|
||||||
|
<CONTR>"ifndef" { contr = 0; ifndefstmt(); }
|
||||||
|
<CONTR>"ifdef" { contr = 0; ifdefstmt(); }
|
||||||
|
<CONTR>"if" { contr = 0; storepb(); BEGIN IFR; ifstmt(); BEGIN 0; }
|
||||||
|
<CONTR>"include" { contr = 0; BEGIN 0; include(); prtline(); }
|
||||||
|
<CONTR>"else" { contr = 0; elsestmt(); }
|
||||||
|
<CONTR>"endif" { contr = 0; endifstmt(); }
|
||||||
|
<CONTR>"error" { contr = 0; if (slow) return IDENT; cpperror(); BEGIN 0; }
|
||||||
|
<CONTR>"define" { contr = 0; BEGIN DEF; define(); BEGIN 0; }
|
||||||
|
<CONTR>"undef" { contr = 0; if (slow) return IDENT; undefstmt(); }
|
||||||
|
<CONTR>"line" { contr = 0; storepb(); BEGIN 0; line(); }
|
||||||
|
<CONTR>"pragma" { contr = 0; pragmastmt(); BEGIN 0; }
|
||||||
|
<CONTR>"elif" { contr = 0; storepb(); BEGIN IFR; elifstmt(); BEGIN 0; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"//".*$ { /* if (tflag) yyless(..) */
|
||||||
|
if (Cflag && !flslvl && !slow)
|
||||||
|
putstr((uchar *)yytext);
|
||||||
|
else if (!flslvl)
|
||||||
|
putch(' ');
|
||||||
|
}
|
||||||
|
"/*" { int c, wrn;
|
||||||
|
int prtcm = Cflag && !flslvl && !slow;
|
||||||
|
extern int readmac;
|
||||||
|
|
||||||
|
if (Cflag && !flslvl && readmac)
|
||||||
|
return CMNT;
|
||||||
|
|
||||||
|
if (prtcm)
|
||||||
|
putstr((uchar *)yytext);
|
||||||
|
wrn = 0;
|
||||||
|
more: while ((c = input()) && c != '*') {
|
||||||
|
if (c == '\n')
|
||||||
|
putch(c), ifiles->lineno++;
|
||||||
|
else if (c == 1) /* WARN */
|
||||||
|
wrn = 1;
|
||||||
|
else if (prtcm)
|
||||||
|
putch(c);
|
||||||
|
}
|
||||||
|
if (c == 0)
|
||||||
|
return 0;
|
||||||
|
if (prtcm)
|
||||||
|
putch(c);
|
||||||
|
if ((c = input()) && c != '/') {
|
||||||
|
unput(c);
|
||||||
|
goto more;
|
||||||
|
}
|
||||||
|
if (prtcm)
|
||||||
|
putch(c);
|
||||||
|
if (c == 0)
|
||||||
|
return 0;
|
||||||
|
if (!tflag && !Cflag && !flslvl)
|
||||||
|
unput(' ');
|
||||||
|
if (wrn)
|
||||||
|
unput(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
<DEF>"##" { return CONCAT; }
|
||||||
|
<DEF>"#" { return MKSTR; }
|
||||||
|
<DEF>"..." { return ELLIPS; }
|
||||||
|
<DEF>"__VA_ARGS__" { return VA_ARGS; }
|
||||||
|
|
||||||
|
L?\"(\\.|[^\\"])*\" { PRTOUT(STRING); }
|
||||||
|
[a-zA-Z_0-9]+ { /* {L}({L}|{D})* */
|
||||||
|
struct symtab *nl;
|
||||||
|
if (slow)
|
||||||
|
return IDENT;
|
||||||
|
if (YYSTATE == CONTR) {
|
||||||
|
if (flslvl == 0) {
|
||||||
|
/*error("undefined control");*/
|
||||||
|
while (input() != '\n')
|
||||||
|
;
|
||||||
|
unput('\n');
|
||||||
|
BEGIN 0;
|
||||||
|
goto xx;
|
||||||
|
} else {
|
||||||
|
BEGIN 0; /* do nothing */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (flslvl) {
|
||||||
|
; /* do nothing */
|
||||||
|
} else if (isdigit((int)yytext[0]) == 0 &&
|
||||||
|
(nl = lookup((uchar *)yytext, FIND)) != 0) {
|
||||||
|
uchar *op = stringbuf;
|
||||||
|
putstr(gotident(nl));
|
||||||
|
stringbuf = op;
|
||||||
|
} else
|
||||||
|
putstr((uchar *)yytext);
|
||||||
|
xx: ;
|
||||||
|
}
|
||||||
|
|
||||||
|
. {
|
||||||
|
if (contr) {
|
||||||
|
while (input() != '\n')
|
||||||
|
;
|
||||||
|
unput('\n');
|
||||||
|
BEGIN 0;
|
||||||
|
contr = 0;
|
||||||
|
goto yy;
|
||||||
|
}
|
||||||
|
if (YYSTATE || slow)
|
||||||
|
return yytext[0];
|
||||||
|
if (yytext[0] == 6) { /* PRAGS */
|
||||||
|
uchar *obp = stringbuf;
|
||||||
|
extern uchar *prtprag(uchar *);
|
||||||
|
*stringbuf++ = yytext[0];
|
||||||
|
do {
|
||||||
|
*stringbuf = input();
|
||||||
|
} while (*stringbuf++ != 14);
|
||||||
|
prtprag(obp);
|
||||||
|
stringbuf = obp;
|
||||||
|
} else {
|
||||||
|
PRTOUT(yytext[0]);
|
||||||
|
}
|
||||||
|
yy:;
|
||||||
|
}
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
uchar *yyp, yybuf[CPPBUF];
|
||||||
|
|
||||||
|
int yylex(void);
|
||||||
|
int yywrap(void);
|
||||||
|
|
||||||
|
static int
|
||||||
|
inpch(void)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (ifiles->curptr < ifiles->maxread)
|
||||||
|
return *ifiles->curptr++;
|
||||||
|
|
||||||
|
if ((len = read(ifiles->infil, ifiles->buffer, CPPBUF)) < 0)
|
||||||
|
error("read error on file %s", ifiles->orgfn);
|
||||||
|
if (len == 0)
|
||||||
|
return -1;
|
||||||
|
ifiles->curptr = ifiles->buffer;
|
||||||
|
ifiles->maxread = ifiles->buffer + len;
|
||||||
|
return inpch();
|
||||||
|
}
|
||||||
|
|
||||||
|
#define unch(c) *--ifiles->curptr = c
|
||||||
|
|
||||||
|
static int
|
||||||
|
inch(void)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
again: switch (c = inpch()) {
|
||||||
|
case '\\': /* continued lines */
|
||||||
|
msdos: if ((c = inpch()) == '\n') {
|
||||||
|
ifiles->lineno++;
|
||||||
|
putch('\n');
|
||||||
|
goto again;
|
||||||
|
} else if (c == '\r')
|
||||||
|
goto msdos;
|
||||||
|
unch(c);
|
||||||
|
return '\\';
|
||||||
|
case '?': /* trigraphs */
|
||||||
|
if ((c = inpch()) != '?') {
|
||||||
|
unch(c);
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
switch (c = inpch()) {
|
||||||
|
case '=': c = '#'; break;
|
||||||
|
case '(': c = '['; break;
|
||||||
|
case ')': c = ']'; break;
|
||||||
|
case '<': c = '{'; break;
|
||||||
|
case '>': c = '}'; break;
|
||||||
|
case '/': c = '\\'; break;
|
||||||
|
case '\'': c = '^'; break;
|
||||||
|
case '!': c = '|'; break;
|
||||||
|
case '-': c = '~'; break;
|
||||||
|
default:
|
||||||
|
unch(c);
|
||||||
|
unch('?');
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
unch(c);
|
||||||
|
goto again;
|
||||||
|
default:
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Let the command-line args be faked defines at beginning of file.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
prinit(struct initar *it, struct includ *ic)
|
||||||
|
{
|
||||||
|
char *a, *pre, *post;
|
||||||
|
|
||||||
|
if (it->next)
|
||||||
|
prinit(it->next, ic);
|
||||||
|
pre = post = NULL; /* XXX gcc */
|
||||||
|
switch (it->type) {
|
||||||
|
case 'D':
|
||||||
|
pre = "#define ";
|
||||||
|
if ((a = strchr(it->str, '=')) != NULL) {
|
||||||
|
*a = ' ';
|
||||||
|
post = "\n";
|
||||||
|
} else
|
||||||
|
post = " 1\n";
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
pre = "#undef ";
|
||||||
|
post = "\n";
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
pre = "#include \"";
|
||||||
|
post = "\"\n";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error("prinit");
|
||||||
|
}
|
||||||
|
strlcat((char *)ic->buffer, pre, CPPBUF+1);
|
||||||
|
strlcat((char *)ic->buffer, it->str, CPPBUF+1);
|
||||||
|
if (strlcat((char *)ic->buffer, post, CPPBUF+1) >= CPPBUF+1)
|
||||||
|
error("line exceeds buffer size");
|
||||||
|
|
||||||
|
ic->lineno--;
|
||||||
|
while (*ic->maxread)
|
||||||
|
ic->maxread++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A new file included.
|
||||||
|
* If ifiles == NULL, this is the first file and already opened (stdin).
|
||||||
|
* Return 0 on success, -1 if file to be included is not found.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
pushfile(uchar *file)
|
||||||
|
{
|
||||||
|
extern struct initar *initar;
|
||||||
|
struct includ ibuf;
|
||||||
|
struct includ *ic;
|
||||||
|
int c, otrulvl;
|
||||||
|
|
||||||
|
ic = &ibuf;
|
||||||
|
ic->next = ifiles;
|
||||||
|
|
||||||
|
slow = 0;
|
||||||
|
if (file != NULL) {
|
||||||
|
if ((ic->infil = open((char *)file, O_RDONLY)) < 0)
|
||||||
|
return -1;
|
||||||
|
ic->orgfn = ic->fname = file;
|
||||||
|
if (++inclevel > MAX_INCLEVEL)
|
||||||
|
error("Limit for nested includes exceeded");
|
||||||
|
} else {
|
||||||
|
ic->infil = 0;
|
||||||
|
ic->orgfn = ic->fname = (uchar *)"<stdin>";
|
||||||
|
}
|
||||||
|
ic->buffer = ic->bbuf+NAMEMAX;
|
||||||
|
ic->curptr = ic->buffer;
|
||||||
|
ifiles = ic;
|
||||||
|
ic->lineno = 1;
|
||||||
|
ic->maxread = ic->curptr;
|
||||||
|
prtline();
|
||||||
|
if (initar) {
|
||||||
|
*ic->maxread = 0;
|
||||||
|
prinit(initar, ic);
|
||||||
|
if (dMflag)
|
||||||
|
write(ofd, ic->buffer, strlen((char *)ic->buffer));
|
||||||
|
initar = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
otrulvl = trulvl;
|
||||||
|
|
||||||
|
if ((c = yylex()) != 0)
|
||||||
|
error("yylex returned %d", c);
|
||||||
|
|
||||||
|
if (otrulvl != trulvl || flslvl)
|
||||||
|
error("unterminated conditional");
|
||||||
|
|
||||||
|
ifiles = ic->next;
|
||||||
|
close(ic->infil);
|
||||||
|
inclevel--;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print current position to output file.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
prtline()
|
||||||
|
{
|
||||||
|
uchar *s, *os = stringbuf;
|
||||||
|
|
||||||
|
if (Mflag) {
|
||||||
|
if (dMflag)
|
||||||
|
return; /* no output */
|
||||||
|
if (ifiles->lineno == 1) {
|
||||||
|
s = sheap("%s: %s\n", Mfile, ifiles->fname);
|
||||||
|
write(ofd, s, strlen((char *)s));
|
||||||
|
}
|
||||||
|
} else if (!Pflag)
|
||||||
|
putstr(sheap("# %d \"%s\"\n", ifiles->lineno, ifiles->fname));
|
||||||
|
stringbuf = os;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cunput(int c)
|
||||||
|
{
|
||||||
|
#ifdef CPP_DEBUG
|
||||||
|
extern int dflag;
|
||||||
|
if (dflag)printf(": '%c'(%d)", c > 31 ? c : ' ', c);
|
||||||
|
#endif
|
||||||
|
unput(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
int yywrap(void) { return 1; }
|
||||||
|
|
||||||
|
static int
|
||||||
|
dig2num(int c)
|
||||||
|
{
|
||||||
|
if (c >= 'a')
|
||||||
|
c = c - 'a' + 10;
|
||||||
|
else if (c >= 'A')
|
||||||
|
c = c - 'A' + 10;
|
||||||
|
else
|
||||||
|
c = c - '0';
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert string numbers to unsigned long long and check overflow.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
cvtdig(int rad)
|
||||||
|
{
|
||||||
|
unsigned long long rv = 0;
|
||||||
|
unsigned long long rv2 = 0;
|
||||||
|
char *y = yytext;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
c = *y++;
|
||||||
|
if (rad == 16)
|
||||||
|
y++;
|
||||||
|
while (isxdigit(c)) {
|
||||||
|
rv = rv * rad + dig2num(c);
|
||||||
|
/* check overflow */
|
||||||
|
if (rv / rad < rv2)
|
||||||
|
error("Constant \"%s\" is out of range", yytext);
|
||||||
|
rv2 = rv;
|
||||||
|
c = *y++;
|
||||||
|
}
|
||||||
|
y--;
|
||||||
|
while (*y == 'l' || *y == 'L')
|
||||||
|
y++;
|
||||||
|
yylval.node.op = *y == 'u' || *y == 'U' ? UNUMBER : NUMBER;
|
||||||
|
yylval.node.nd_uval = rv;
|
||||||
|
if ((rad == 8 || rad == 16) && yylval.node.nd_val < 0)
|
||||||
|
yylval.node.op = UNUMBER;
|
||||||
|
if (yylval.node.op == NUMBER && yylval.node.nd_val < 0)
|
||||||
|
/* too large for signed */
|
||||||
|
error("Constant \"%s\" is out of range", yytext);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
charcon(uchar *p)
|
||||||
|
{
|
||||||
|
int val, c;
|
||||||
|
|
||||||
|
p++; /* skip first ' */
|
||||||
|
val = 0;
|
||||||
|
if (*p++ == '\\') {
|
||||||
|
switch (*p++) {
|
||||||
|
case 'a': val = '\a'; break;
|
||||||
|
case 'b': val = '\b'; break;
|
||||||
|
case 'f': val = '\f'; break;
|
||||||
|
case 'n': val = '\n'; break;
|
||||||
|
case 'r': val = '\r'; break;
|
||||||
|
case 't': val = '\t'; break;
|
||||||
|
case 'v': val = '\v'; break;
|
||||||
|
case '\"': val = '\"'; break;
|
||||||
|
case '\'': val = '\''; break;
|
||||||
|
case '\\': val = '\\'; break;
|
||||||
|
case 'x':
|
||||||
|
while (isxdigit(c = *p)) {
|
||||||
|
val = val * 16 + dig2num(c);
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
|
case '5': case '6': case '7':
|
||||||
|
p--;
|
||||||
|
while (isdigit(c = *p)) {
|
||||||
|
val = val * 8 + (c - '0');
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: val = p[-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
} else
|
||||||
|
val = p[-1];
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
chknl(int ignore)
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
|
||||||
|
slow = 1;
|
||||||
|
while ((t = yylex()) == WSPACE)
|
||||||
|
;
|
||||||
|
if (t != '\n') {
|
||||||
|
if (ignore) {
|
||||||
|
warning("newline expected, got \"%s\"", yytext);
|
||||||
|
/* ignore rest of line */
|
||||||
|
while ((t = yylex()) && t != '\n')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
error("newline expected, got \"%s\"", yytext);
|
||||||
|
}
|
||||||
|
slow = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
elsestmt(void)
|
||||||
|
{
|
||||||
|
if (flslvl) {
|
||||||
|
if (elflvl > trulvl)
|
||||||
|
;
|
||||||
|
else if (--flslvl!=0) {
|
||||||
|
flslvl++;
|
||||||
|
} else {
|
||||||
|
trulvl++;
|
||||||
|
prtline();
|
||||||
|
}
|
||||||
|
} else if (trulvl) {
|
||||||
|
flslvl++;
|
||||||
|
trulvl--;
|
||||||
|
} else
|
||||||
|
error("If-less else");
|
||||||
|
if (elslvl==trulvl+flslvl)
|
||||||
|
error("Too many else");
|
||||||
|
elslvl=trulvl+flslvl;
|
||||||
|
chknl(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ifdefstmt(void)
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
|
||||||
|
if (flslvl) {
|
||||||
|
/* just ignore the rest of the line */
|
||||||
|
while (input() != '\n')
|
||||||
|
;
|
||||||
|
unput('\n');
|
||||||
|
yylex();
|
||||||
|
flslvl++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
slow = 1;
|
||||||
|
do
|
||||||
|
t = yylex();
|
||||||
|
while (t == WSPACE);
|
||||||
|
if (t != IDENT)
|
||||||
|
error("bad ifdef");
|
||||||
|
slow = 0;
|
||||||
|
if (flslvl == 0 && lookup((uchar *)yytext, FIND) != 0)
|
||||||
|
trulvl++;
|
||||||
|
else
|
||||||
|
flslvl++;
|
||||||
|
chknl(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ifndefstmt(void)
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
|
||||||
|
slow = 1;
|
||||||
|
do
|
||||||
|
t = yylex();
|
||||||
|
while (t == WSPACE);
|
||||||
|
if (t != IDENT)
|
||||||
|
error("bad ifndef");
|
||||||
|
slow = 0;
|
||||||
|
if (flslvl == 0 && lookup((uchar *)yytext, FIND) == 0)
|
||||||
|
trulvl++;
|
||||||
|
else
|
||||||
|
flslvl++;
|
||||||
|
chknl(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
endifstmt(void)
|
||||||
|
{
|
||||||
|
if (flslvl) {
|
||||||
|
flslvl--;
|
||||||
|
if (flslvl == 0)
|
||||||
|
prtline();
|
||||||
|
} else if (trulvl)
|
||||||
|
trulvl--;
|
||||||
|
else
|
||||||
|
error("If-less endif");
|
||||||
|
if (flslvl == 0)
|
||||||
|
elflvl = 0;
|
||||||
|
elslvl = 0;
|
||||||
|
chknl(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note! Ugly!
|
||||||
|
* Walk over the string s and search for defined, and replace it with
|
||||||
|
* spaces and a 1 or 0.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
fixdefined(uchar *s)
|
||||||
|
{
|
||||||
|
uchar *bc, oc;
|
||||||
|
|
||||||
|
for (; *s; s++) {
|
||||||
|
if (*s != 'd')
|
||||||
|
continue;
|
||||||
|
if (memcmp(s, "defined", 7))
|
||||||
|
continue;
|
||||||
|
/* Ok, got defined, can scratch it now */
|
||||||
|
memset(s, ' ', 7);
|
||||||
|
s += 7;
|
||||||
|
#define WSARG(x) (x == ' ' || x == '\t')
|
||||||
|
if (*s != '(' && !WSARG(*s))
|
||||||
|
continue;
|
||||||
|
while (WSARG(*s))
|
||||||
|
s++;
|
||||||
|
if (*s == '(')
|
||||||
|
s++;
|
||||||
|
while (WSARG(*s))
|
||||||
|
s++;
|
||||||
|
#define IDARG(x) ((x>= 'A' && x <= 'Z') || (x >= 'a' && x <= 'z') || (x == '_'))
|
||||||
|
#define NUMARG(x) (x >= '0' && x <= '9')
|
||||||
|
if (!IDARG(*s))
|
||||||
|
error("bad defined arg");
|
||||||
|
bc = s;
|
||||||
|
while (IDARG(*s) || NUMARG(*s))
|
||||||
|
s++;
|
||||||
|
oc = *s;
|
||||||
|
*s = 0;
|
||||||
|
*bc = (lookup(bc, FIND) != 0) + '0';
|
||||||
|
memset(bc+1, ' ', s-bc-1);
|
||||||
|
*s = oc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get the full line of identifiers after an #if, pushback a WARN and
|
||||||
|
* the line and prepare for expmac() to expand.
|
||||||
|
* This is done before switching state. When expmac is finished,
|
||||||
|
* pushback the expanded line, change state and call yyparse.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
storepb(void)
|
||||||
|
{
|
||||||
|
uchar *opb = stringbuf;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
while ((c = input()) != '\n') {
|
||||||
|
if (c == '/') {
|
||||||
|
if ((c = input()) == '*') {
|
||||||
|
/* ignore comments here whatsoever */
|
||||||
|
uchar *g = stringbuf;
|
||||||
|
getcmnt();
|
||||||
|
stringbuf = g;
|
||||||
|
continue;
|
||||||
|
} else if (c == '/') {
|
||||||
|
while ((c = input()) && c != '\n')
|
||||||
|
;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
unput(c);
|
||||||
|
c = '/';
|
||||||
|
}
|
||||||
|
savch(c);
|
||||||
|
}
|
||||||
|
cunput('\n');
|
||||||
|
savch(0);
|
||||||
|
fixdefined(opb); /* XXX can fail if #line? */
|
||||||
|
cunput(1); /* WARN XXX */
|
||||||
|
unpstr(opb);
|
||||||
|
stringbuf = opb;
|
||||||
|
slow = 1;
|
||||||
|
expmac(NULL);
|
||||||
|
slow = 0;
|
||||||
|
/* line now expanded */
|
||||||
|
while (stringbuf > opb)
|
||||||
|
cunput(*--stringbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ifstmt(void)
|
||||||
|
{
|
||||||
|
if (flslvl == 0) {
|
||||||
|
slow = 1;
|
||||||
|
if (yyparse())
|
||||||
|
++trulvl;
|
||||||
|
else
|
||||||
|
++flslvl;
|
||||||
|
slow = 0;
|
||||||
|
} else
|
||||||
|
++flslvl;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
elifstmt(void)
|
||||||
|
{
|
||||||
|
if (flslvl == 0)
|
||||||
|
elflvl = trulvl;
|
||||||
|
if (flslvl) {
|
||||||
|
if (elflvl > trulvl)
|
||||||
|
;
|
||||||
|
else if (--flslvl!=0)
|
||||||
|
++flslvl;
|
||||||
|
else {
|
||||||
|
slow = 1;
|
||||||
|
if (yyparse()) {
|
||||||
|
++trulvl;
|
||||||
|
prtline();
|
||||||
|
} else
|
||||||
|
++flslvl;
|
||||||
|
slow = 0;
|
||||||
|
}
|
||||||
|
} else if (trulvl) {
|
||||||
|
++flslvl;
|
||||||
|
--trulvl;
|
||||||
|
} else
|
||||||
|
error("If-less elif");
|
||||||
|
}
|
||||||
|
|
||||||
|
static uchar *
|
||||||
|
svinp(void)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
uchar *cp = stringbuf;
|
||||||
|
|
||||||
|
while ((c = input()) && c != '\n')
|
||||||
|
savch(c);
|
||||||
|
savch('\n');
|
||||||
|
savch(0);
|
||||||
|
BEGIN 0;
|
||||||
|
return cp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cpperror(void)
|
||||||
|
{
|
||||||
|
uchar *cp;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
if (flslvl)
|
||||||
|
return;
|
||||||
|
c = yylex();
|
||||||
|
if (c != WSPACE && c != '\n')
|
||||||
|
error("bad error");
|
||||||
|
cp = svinp();
|
||||||
|
if (flslvl)
|
||||||
|
stringbuf = cp;
|
||||||
|
else
|
||||||
|
error("%s", cp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
undefstmt(void)
|
||||||
|
{
|
||||||
|
struct symtab *np;
|
||||||
|
|
||||||
|
slow = 1;
|
||||||
|
if (yylex() != WSPACE || yylex() != IDENT)
|
||||||
|
error("bad undef");
|
||||||
|
if (flslvl == 0 && (np = lookup((uchar *)yytext, FIND)))
|
||||||
|
np->value = 0;
|
||||||
|
slow = 0;
|
||||||
|
chknl(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
pragmastmt(void)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
slow = 1;
|
||||||
|
if (yylex() != WSPACE)
|
||||||
|
error("bad pragma");
|
||||||
|
if (!flslvl)
|
||||||
|
putstr((uchar *)"#pragma ");
|
||||||
|
do {
|
||||||
|
c = input();
|
||||||
|
if (!flslvl)
|
||||||
|
putch(c); /* Do arg expansion instead? */
|
||||||
|
} while (c && c != '\n');
|
||||||
|
ifiles->lineno++;
|
||||||
|
prtline();
|
||||||
|
slow = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
badop(const char *op)
|
||||||
|
{
|
||||||
|
error("invalid operator in preprocessor expression: %s", op);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
cinput()
|
||||||
|
{
|
||||||
|
return input();
|
||||||
|
}
|
||||||
@@ -767,10 +767,8 @@ pushfile(const uchar *file, const uchar *fn, int idx, void *incs)
|
|||||||
|
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
ic->infil = open((const char *)file, O_RDONLY);
|
ic->infil = open((const char *)file, O_RDONLY);
|
||||||
if (ic->infil < 0) {
|
if (ic->infil < 0)
|
||||||
free(ic);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
ic->orgfn = ic->fname = file;
|
ic->orgfn = ic->fname = file;
|
||||||
if (++inclevel > MAX_INCLEVEL)
|
if (++inclevel > MAX_INCLEVEL)
|
||||||
error("Limit for nested includes exceeded");
|
error("Limit for nested includes exceeded");
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ int fgethdr (text, h)
|
|||||||
register FILE *text;
|
register FILE *text;
|
||||||
register struct exec *h;
|
register struct exec *h;
|
||||||
{
|
{
|
||||||
h->a_midmag = fgetword (text);
|
h->a_magic = fgetword (text);
|
||||||
h->a_text = fgetword (text);
|
h->a_text = fgetword (text);
|
||||||
h->a_data = fgetword (text);
|
h->a_data = fgetword (text);
|
||||||
h->a_bss = fgetword (text);
|
h->a_bss = fgetword (text);
|
||||||
@@ -860,7 +860,7 @@ void readhdr (loc)
|
|||||||
fseek (text, loc, 0);
|
fseek (text, loc, 0);
|
||||||
if (! fgethdr (text, &filhdr))
|
if (! fgethdr (text, &filhdr))
|
||||||
error (2, "bad format");
|
error (2, "bad format");
|
||||||
if (N_GETMAGIC(filhdr) != RMAGIC)
|
if (filhdr.a_magic != RMAGIC)
|
||||||
error (2, "bad magic");
|
error (2, "bad magic");
|
||||||
if (filhdr.a_text % W)
|
if (filhdr.a_text % W)
|
||||||
error (2, "bad length of text");
|
error (2, "bad length of text");
|
||||||
@@ -880,7 +880,7 @@ int load1 (loc, libflg, nloc)
|
|||||||
int savindex, ndef, type, symlen, nsymbol;
|
int savindex, ndef, type, symlen, nsymbol;
|
||||||
|
|
||||||
readhdr (loc);
|
readhdr (loc);
|
||||||
if (N_GETMAGIC(filhdr) != RMAGIC) {
|
if (filhdr.a_magic != RMAGIC) {
|
||||||
error (1, "file not relocatable");
|
error (1, "file not relocatable");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -1293,7 +1293,7 @@ void setupout ()
|
|||||||
} else {
|
} else {
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
tcreat (&toutb, 1);
|
tcreat (&toutb, 1);
|
||||||
tcreat (&doutb, 1);
|
tcreat (&doutb, 1);
|
||||||
|
|
||||||
@@ -1494,7 +1494,7 @@ void finishout ()
|
|||||||
while (ssize++ % W)
|
while (ssize++ % W)
|
||||||
putc (0, outb);
|
putc (0, outb);
|
||||||
}
|
}
|
||||||
filhdr.a_midmag = output_relinfo ? RMAGIC : OMAGIC;
|
filhdr.a_magic = output_relinfo ? RMAGIC : OMAGIC;
|
||||||
filhdr.a_text = tsize;
|
filhdr.a_text = tsize;
|
||||||
filhdr.a_data = dsize;
|
filhdr.a_data = dsize;
|
||||||
filhdr.a_bss = bsize;
|
filhdr.a_bss = bsize;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
TOPSRC = $(shell cd ../../..; pwd)
|
TOPSRC = $(shell cd ../../..; pwd)
|
||||||
include $(TOPSRC)/target.mk
|
include $(TOPSRC)/target.mk
|
||||||
|
#include $(TOPSRC)/cross.mk
|
||||||
|
|
||||||
CFLAGS = -Os -Wall -DMIPS -DNO_ANNOTATIONS -DNO_PREPROCESSOR \
|
CFLAGS = -Os -Wall -DMIPS -DNO_ANNOTATIONS -DNO_PREPROCESSOR \
|
||||||
-DNO_PPACK -D_RETROBSD -D__SMALLER_C_SCHAR__ \
|
-DNO_PPACK -D_RETROBSD -D__SMALLER_C_SCHAR__ \
|
||||||
-D__SMALLER_C__ -D__SMALLER_C_32__
|
-D__SMALLER_C__ -D__SMALLER_C_32__
|
||||||
|
|
||||||
# For cross compile
|
# For cross compile
|
||||||
#include $(TOPSRC)/cross.mk
|
|
||||||
#CFLAGS = -Os -Wall -DMIPS -m32
|
#CFLAGS = -Os -Wall -DMIPS -m32
|
||||||
#LDFLAGS = -m32
|
#LDFLAGS = -m32
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ Copyright (c) 2012-2014, Alexey Frunze
|
|||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
list of conditions and the following disclaimer.
|
list of conditions and the following disclaimer.
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
@@ -23,7 +23,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
The views and conclusions contained in the software and documentation are those
|
The views and conclusions contained in the software and documentation are those
|
||||||
of the authors and should not be interpreted as representing official policies,
|
of the authors and should not be interpreted as representing official policies,
|
||||||
either expressed or implied, of the FreeBSD Project.
|
either expressed or implied, of the FreeBSD Project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -37,11 +37,6 @@ either expressed or implied, of the FreeBSD Project.
|
|||||||
/* */
|
/* */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
// Works around bugs in RetroBSD's as instruction reordering
|
|
||||||
#define REORDER_WORKAROUND
|
|
||||||
// Works around bugs in RetroBSD's as immediate operand truncation to 16 bits
|
|
||||||
//#define INSTR_IMM_WORKAROUND
|
|
||||||
|
|
||||||
int UseGp = 0;
|
int UseGp = 0;
|
||||||
|
|
||||||
void GenInit(void)
|
void GenInit(void)
|
||||||
@@ -52,7 +47,7 @@ void GenInit(void)
|
|||||||
CodeHeader = "\t.text";
|
CodeHeader = "\t.text";
|
||||||
DataHeader = "\t.data";
|
DataHeader = "\t.data";
|
||||||
UseLeadingUnderscores = 0;
|
UseLeadingUnderscores = 0;
|
||||||
#ifdef REORDER_WORKAROUND
|
#ifndef NO_REORDER_WORKAROUND
|
||||||
FileHeader = "\t.set\tnoreorder";
|
FileHeader = "\t.set\tnoreorder";
|
||||||
#else
|
#else
|
||||||
FileHeader = "\t.set\treorder";
|
FileHeader = "\t.set\treorder";
|
||||||
@@ -68,12 +63,6 @@ int GenInitParams(int argc, char** argv, int* idx)
|
|||||||
UseGp = 1;
|
UseGp = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[*idx], "-v"))
|
|
||||||
{
|
|
||||||
// RetroBSD's cc may supply this parameter. Just need to consume it.
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,19 +131,15 @@ void GenStartAsciiString(void)
|
|||||||
printf2("\t.ascii\t");
|
printf2("\t.ascii\t");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenAddrData(int Size, char* Label, int ofs)
|
void GenAddrData(int Size, char* Label)
|
||||||
{
|
{
|
||||||
ofs = truncInt(ofs);
|
|
||||||
if (Size == 1)
|
if (Size == 1)
|
||||||
printf2("\t.byte\t");
|
printf2("\t.byte\t");
|
||||||
else if (Size == 2)
|
else if (Size == 2)
|
||||||
printf2("\t.half\t");
|
printf2("\t.half\t");
|
||||||
else if (Size == 4)
|
else if (Size == 4)
|
||||||
printf2("\t.word\t");
|
printf2("\t.word\t");
|
||||||
GenPrintLabel(Label);
|
GenPrintLabel(Label); puts2("");
|
||||||
if (ofs)
|
|
||||||
printf2(" %+d", ofs);
|
|
||||||
puts2("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MipsInstrNop 0x00
|
#define MipsInstrNop 0x00
|
||||||
@@ -301,7 +286,7 @@ void GenPrintInstr(int instr, int val)
|
|||||||
#define MipsOpLabelGpOption 0x83
|
#define MipsOpLabelGpOption 0x83
|
||||||
#define MipsOpIndLocal MipsOpIndRegFp
|
#define MipsOpIndLocal MipsOpIndRegFp
|
||||||
|
|
||||||
#ifdef REORDER_WORKAROUND
|
#ifndef NO_REORDER_WORKAROUND
|
||||||
void GenNop(void)
|
void GenNop(void)
|
||||||
{
|
{
|
||||||
puts2("\tnop");
|
puts2("\tnop");
|
||||||
@@ -370,7 +355,7 @@ void GenPrintInstr1Operand(int instr, int instrval, int operand, int operandval)
|
|||||||
GenPrintOperand(operand, operandval);
|
GenPrintOperand(operand, operandval);
|
||||||
GenPrintNewLine();
|
GenPrintNewLine();
|
||||||
|
|
||||||
#ifdef REORDER_WORKAROUND
|
#ifndef NO_REORDER_WORKAROUND
|
||||||
if (instr == MipsInstrJ || instr == MipsInstrJAL)
|
if (instr == MipsInstrJ || instr == MipsInstrJAL)
|
||||||
GenNop();
|
GenNop();
|
||||||
#endif
|
#endif
|
||||||
@@ -394,61 +379,10 @@ void GenPrintInstr3Operands(int instr, int instrval,
|
|||||||
int operand2, int operand2val,
|
int operand2, int operand2val,
|
||||||
int operand3, int operand3val)
|
int operand3, int operand3val)
|
||||||
{
|
{
|
||||||
#ifdef INSTR_IMM_WORKAROUND
|
|
||||||
int useAt = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (operand3 == MipsOpConst && operand3val == 0 &&
|
if (operand3 == MipsOpConst && operand3val == 0 &&
|
||||||
(instr == MipsInstrAddU || instr == MipsInstrSubU))
|
(instr == MipsInstrAddU || instr == MipsInstrSubU))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef INSTR_IMM_WORKAROUND
|
|
||||||
if (operand3 == MipsOpConst)
|
|
||||||
{
|
|
||||||
unsigned imm = truncUint(operand3val);
|
|
||||||
|
|
||||||
switch (instr)
|
|
||||||
{
|
|
||||||
// signed imm16:
|
|
||||||
// addi[u], subi[u], slti[u]
|
|
||||||
case MipsInstrAddU:
|
|
||||||
case MipsInstrSLT:
|
|
||||||
case MipsInstrSLTU:
|
|
||||||
if (imm > 0x7FFF && imm < 0xFFFF8000) // if not (-0x8000 <= imm <= 0x7FFF)
|
|
||||||
useAt = 1;
|
|
||||||
break;
|
|
||||||
case MipsInstrSubU:
|
|
||||||
// subi[u] will be transformed into addi[u] and the immediate will be negated,
|
|
||||||
// hence the immediate range is shifted by 1
|
|
||||||
if (imm > 0x8000 && imm < 0xFFFF8001) // if not (-0x7FFF <= imm <= 0x8000)
|
|
||||||
useAt = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// unsigned imm16:
|
|
||||||
// andi, ori, xori
|
|
||||||
case MipsInstrAnd:
|
|
||||||
case MipsInstrOr:
|
|
||||||
case MipsInstrXor:
|
|
||||||
if (imm > 0xFFFF)
|
|
||||||
useAt = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// also: various trap instructions
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (useAt)
|
|
||||||
{
|
|
||||||
puts2("\t.set\tnoat");
|
|
||||||
GenPrintInstr2Operands(MipsInstrLI, 0,
|
|
||||||
MipsOpRegAt, 0,
|
|
||||||
MipsOpConst, operand3val);
|
|
||||||
operand3 = MipsOpRegAt;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
GenPrintInstr(instr, instrval);
|
GenPrintInstr(instr, instrval);
|
||||||
GenPrintOperand(operand1, operand1val);
|
GenPrintOperand(operand1, operand1val);
|
||||||
GenPrintOperandSeparator();
|
GenPrintOperandSeparator();
|
||||||
@@ -457,14 +391,7 @@ void GenPrintInstr3Operands(int instr, int instrval,
|
|||||||
GenPrintOperand(operand3, operand3val);
|
GenPrintOperand(operand3, operand3val);
|
||||||
GenPrintNewLine();
|
GenPrintNewLine();
|
||||||
|
|
||||||
#ifdef INSTR_IMM_WORKAROUND
|
#ifndef NO_REORDER_WORKAROUND
|
||||||
if (useAt)
|
|
||||||
{
|
|
||||||
puts2("\t.set\tat");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef REORDER_WORKAROUND
|
|
||||||
if (instr == MipsInstrBEQ || instr == MipsInstrBNE)
|
if (instr == MipsInstrBEQ || instr == MipsInstrBNE)
|
||||||
GenNop();
|
GenNop();
|
||||||
#endif
|
#endif
|
||||||
@@ -1198,13 +1125,11 @@ void GenExpr0(void)
|
|||||||
{
|
{
|
||||||
int reg = GenPopReg(MipsOpRegT0);
|
int reg = GenPopReg(MipsOpRegT0);
|
||||||
if (tok == '/' || tok == '%')
|
if (tok == '/' || tok == '%')
|
||||||
GenPrintInstr3Operands(MipsInstrDiv, 0,
|
GenPrintInstr2Operands(MipsInstrDiv, 0,
|
||||||
MipsOpRegZero, 0,
|
|
||||||
reg, 0,
|
reg, 0,
|
||||||
MipsOpRegV0, 0);
|
MipsOpRegV0, 0);
|
||||||
else
|
else
|
||||||
GenPrintInstr3Operands(MipsInstrDivU, 0,
|
GenPrintInstr2Operands(MipsInstrDivU, 0,
|
||||||
MipsOpRegZero, 0,
|
|
||||||
reg, 0,
|
reg, 0,
|
||||||
MipsOpRegV0, 0);
|
MipsOpRegV0, 0);
|
||||||
if (tok == '%' || tok == tokUMod)
|
if (tok == '%' || tok == tokUMod)
|
||||||
@@ -1307,13 +1232,11 @@ void GenExpr0(void)
|
|||||||
|
|
||||||
GenReadIndirect(MipsOpRegT1, reg, v);
|
GenReadIndirect(MipsOpRegT1, reg, v);
|
||||||
if (tok == tokAssignDiv || tok == tokAssignMod)
|
if (tok == tokAssignDiv || tok == tokAssignMod)
|
||||||
GenPrintInstr3Operands(MipsInstrDiv, 0,
|
GenPrintInstr2Operands(MipsInstrDiv, 0,
|
||||||
MipsOpRegZero, 0,
|
|
||||||
MipsOpRegT1, 0,
|
MipsOpRegT1, 0,
|
||||||
MipsOpRegV0, 0);
|
MipsOpRegV0, 0);
|
||||||
else
|
else
|
||||||
GenPrintInstr3Operands(MipsInstrDivU, 0,
|
GenPrintInstr2Operands(MipsInstrDivU, 0,
|
||||||
MipsOpRegZero, 0,
|
|
||||||
MipsOpRegT1, 0,
|
MipsOpRegT1, 0,
|
||||||
MipsOpRegV0, 0);
|
MipsOpRegV0, 0);
|
||||||
if (tok == tokAssignMod || tok == tokAssignUMod)
|
if (tok == tokAssignMod || tok == tokAssignUMod)
|
||||||
@@ -1673,11 +1596,11 @@ void GenFin(void)
|
|||||||
"\taddiu\t$3, $3, 1");
|
"\taddiu\t$3, $3, 1");
|
||||||
printf2("\tbne\t$4, $0, "); GenPrintNumLabel(lbl);
|
printf2("\tbne\t$4, $0, "); GenPrintNumLabel(lbl);
|
||||||
puts2("");
|
puts2("");
|
||||||
#ifdef REORDER_WORKAROUND
|
#ifndef NO_REORDER_WORKAROUND
|
||||||
GenNop();
|
GenNop();
|
||||||
#endif
|
#endif
|
||||||
puts2("\tj\t$31");
|
puts2("\tj\t$31");
|
||||||
#ifdef REORDER_WORKAROUND
|
#ifndef NO_REORDER_WORKAROUND
|
||||||
GenNop();
|
GenNop();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ Copyright (c) 2012-2014, Alexey Frunze
|
|||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
list of conditions and the following disclaimer.
|
list of conditions and the following disclaimer.
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
@@ -23,7 +23,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
The views and conclusions contained in the software and documentation are those
|
The views and conclusions contained in the software and documentation are those
|
||||||
of the authors and should not be interpreted as representing official policies,
|
of the authors and should not be interpreted as representing official policies,
|
||||||
either expressed or implied, of the FreeBSD Project.
|
either expressed or implied, of the FreeBSD Project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -237,9 +237,8 @@ void GenStartAsciiString(void)
|
|||||||
printf2("\tdb\t");
|
printf2("\tdb\t");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenAddrData(int Size, char* Label, int ofs)
|
void GenAddrData(int Size, char* Label)
|
||||||
{
|
{
|
||||||
ofs = truncInt(ofs);
|
|
||||||
#ifdef CAN_COMPILE_32BIT
|
#ifdef CAN_COMPILE_32BIT
|
||||||
if (OutputFormat == FormatSegHuge)
|
if (OutputFormat == FormatSegHuge)
|
||||||
{
|
{
|
||||||
@@ -257,10 +256,7 @@ void GenAddrData(int Size, char* Label, int ofs)
|
|||||||
else if (Size == 4)
|
else if (Size == 4)
|
||||||
printf2("\tdd\t");
|
printf2("\tdd\t");
|
||||||
#endif
|
#endif
|
||||||
GenPrintLabel(Label);
|
GenPrintLabel(Label); puts2("");
|
||||||
if (ofs)
|
|
||||||
printf2(" %+d", ofs);
|
|
||||||
puts2("");
|
|
||||||
if (!isdigit(*Label))
|
if (!isdigit(*Label))
|
||||||
GenAddGlobal(Label, 2);
|
GenAddGlobal(Label, 2);
|
||||||
}
|
}
|
||||||
@@ -803,79 +799,6 @@ void GenFxnEpilog(void)
|
|||||||
GenPrintInstrNoOperand(X86InstrRet);
|
GenPrintInstrNoOperand(X86InstrRet);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CAN_COMPILE_32BIT
|
|
||||||
/*
|
|
||||||
struct INTREGS
|
|
||||||
{
|
|
||||||
unsigned short gs, fs, es, ds;
|
|
||||||
unsigned edi, esi, ebp, esp, ebx, edx, ecx, eax;
|
|
||||||
unsigned short ss, ip, cs, flags;
|
|
||||||
};
|
|
||||||
void __interrupt isr(struct INTREGS** ppRegs)
|
|
||||||
{
|
|
||||||
// **ppRegs (input/output values of registers) can be modified to
|
|
||||||
// handle software interrupts requested via the int instruction and
|
|
||||||
// communicate data via registers
|
|
||||||
|
|
||||||
// *ppRegs (directly related to the stack pointer) can be modified to
|
|
||||||
// return to a different location & implement preemptive scheduling,
|
|
||||||
// e.g. save *ppRegs of the interrupted task somewhere, update *ppRegs
|
|
||||||
// with a value from another interrupted task.
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
void GenIsrProlog(void)
|
|
||||||
{
|
|
||||||
// The CPU has already done these:
|
|
||||||
// push flags
|
|
||||||
// push cs
|
|
||||||
// push ip
|
|
||||||
|
|
||||||
puts2("\tpush\tss");
|
|
||||||
puts2("\tpushad");
|
|
||||||
puts2("\tpush\tds\n"
|
|
||||||
"\tpush\tes\n"
|
|
||||||
"\tpush\tfs\n"
|
|
||||||
"\tpush\tgs");
|
|
||||||
|
|
||||||
// The context has been saved
|
|
||||||
|
|
||||||
puts2("\txor\teax, eax\n\tmov\tax, ss"); // mov r32, sreg leaves top 16 bits undefined on pre-Pentium CPUs
|
|
||||||
puts2("\txor\tebx, ebx\n\tmov\tbx, sp"); // top 16 bits of esp can contain garbage as well
|
|
||||||
puts2("\tshl\teax, 4\n\tadd\teax, ebx");
|
|
||||||
puts2("\tpush\teax"); // pointer to the structure with register values
|
|
||||||
puts2("\tsub\teax, 4\n\tpush\teax"); // pointer to the pointer to the structure with register values
|
|
||||||
|
|
||||||
puts2("\tpush\teax"); // fake return address allowing to use the existing bp-relative addressing of locals and params
|
|
||||||
|
|
||||||
puts2("\tpush\tebp\n"
|
|
||||||
"\tmov\tebp, esp");
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenIsrEpilog(void)
|
|
||||||
{
|
|
||||||
puts2("\tdb\t0x66\n\tleave");
|
|
||||||
|
|
||||||
puts2("\tpop\teax"); // fake return address
|
|
||||||
|
|
||||||
puts2("\tpop\teax"); // pointer to the pointer to the structure with register values
|
|
||||||
puts2("\tpop\tebx"); // pointer to the structure with register values
|
|
||||||
puts2("\tror\tebx, 4\n\tmov\tds, bx\n\tshr\tebx, 28"); // ds:bx = pointer to the structure with register values
|
|
||||||
puts2("\tmov\tax, [bx+4*10]\n\tmov\tbx, [bx+4*5]\n\tsub\tbx, 4*10"); // ax:bx = proper pointer (with original segment) to the struct...
|
|
||||||
puts2("\tmov\tss, ax\n\tmov\tsp, bx"); // restore ss:sp that we had after push gs
|
|
||||||
|
|
||||||
// The context is now going to be restored
|
|
||||||
|
|
||||||
puts2("\tpop\tgs\n"
|
|
||||||
"\tpop\tfs\n"
|
|
||||||
"\tpop\tes\n"
|
|
||||||
"\tpop\tds");
|
|
||||||
puts2("\tpopad");
|
|
||||||
puts2("\tpop\tss");
|
|
||||||
|
|
||||||
puts2("\tiret");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void GenReadIdent(int opSz, int label)
|
void GenReadIdent(int opSz, int label)
|
||||||
{
|
{
|
||||||
GenPrintInstr2Operands(X86InstrMov, 0,
|
GenPrintInstr2Operands(X86InstrMov, 0,
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ Copyright (c) 2012-2014, Alexey Frunze
|
|||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
list of conditions and the following disclaimer.
|
list of conditions and the following disclaimer.
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
@@ -23,7 +23,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
The views and conclusions contained in the software and documentation are those
|
The views and conclusions contained in the software and documentation are those
|
||||||
of the authors and should not be interpreted as representing official policies,
|
of the authors and should not be interpreted as representing official policies,
|
||||||
either expressed or implied, of the FreeBSD Project.
|
either expressed or implied, of the FreeBSD Project.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -302,7 +302,6 @@ int vfprintf(FILE*, char*, void*);
|
|||||||
#define tokTag 0x91
|
#define tokTag 0x91
|
||||||
#define tokMemberIdent 0x92
|
#define tokMemberIdent 0x92
|
||||||
#define tokEnumPtr 0x93
|
#define tokEnumPtr 0x93
|
||||||
#define tokIntr 0x94
|
|
||||||
|
|
||||||
#define FormatFlat 0
|
#define FormatFlat 0
|
||||||
#define FormatSegmented 1
|
#define FormatSegmented 1
|
||||||
@@ -332,6 +331,13 @@ int truncInt(int);
|
|||||||
int GetToken(void);
|
int GetToken(void);
|
||||||
char* GetTokenName(int token);
|
char* GetTokenName(int token);
|
||||||
|
|
||||||
|
int GetTokenValueInt(void);
|
||||||
|
|
||||||
|
char* GetTokenValueString(void);
|
||||||
|
int GetTokenValueStringLength(void);
|
||||||
|
|
||||||
|
char* GetTokenIdentName(void);
|
||||||
|
|
||||||
#ifndef NO_PREPROCESSOR
|
#ifndef NO_PREPROCESSOR
|
||||||
#ifndef NO_ANNOTATIONS
|
#ifndef NO_ANNOTATIONS
|
||||||
void DumpMacroTable(void);
|
void DumpMacroTable(void);
|
||||||
@@ -360,7 +366,7 @@ void GenNumLabel(int Label);
|
|||||||
void GenZeroData(unsigned Size);
|
void GenZeroData(unsigned Size);
|
||||||
void GenIntData(int Size, int Val);
|
void GenIntData(int Size, int Val);
|
||||||
void GenStartAsciiString(void);
|
void GenStartAsciiString(void);
|
||||||
void GenAddrData(int Size, char* Label, int ofs);
|
void GenAddrData(int Size, char* Label);
|
||||||
|
|
||||||
void GenJumpUncond(int Label);
|
void GenJumpUncond(int Label);
|
||||||
void GenJumpIfZero(int Label);
|
void GenJumpIfZero(int Label);
|
||||||
@@ -369,8 +375,6 @@ void GenJumpIfNotEqual(int val, int Label);
|
|||||||
|
|
||||||
void GenFxnProlog(void);
|
void GenFxnProlog(void);
|
||||||
void GenFxnEpilog(void);
|
void GenFxnEpilog(void);
|
||||||
void GenIsrProlog(void);
|
|
||||||
void GenIsrEpilog(void);
|
|
||||||
|
|
||||||
void GenLocalAlloc(int Size);
|
void GenLocalAlloc(int Size);
|
||||||
|
|
||||||
@@ -573,19 +577,8 @@ int CurFxnNameLabel = 0;
|
|||||||
int ParseLevel = 0; // Parse level/scope (file:0, fxn:1+)
|
int ParseLevel = 0; // Parse level/scope (file:0, fxn:1+)
|
||||||
int ParamLevel = 0; // 1+ if parsing params, 0 otherwise
|
int ParamLevel = 0; // 1+ if parsing params, 0 otherwise
|
||||||
|
|
||||||
int SyntaxStack[SYNTAX_STACK_MAX][2] =
|
int SyntaxStack[SYNTAX_STACK_MAX][2];
|
||||||
{
|
int SyntaxStackCnt = 0;
|
||||||
{ tokVoid }, // SymVoidSynPtr
|
|
||||||
{ tokInt }, // SymIntSynPtr
|
|
||||||
{ tokUnsigned }, // SymUintSynPtr
|
|
||||||
{ tokIdent }, // SymFuncPtr
|
|
||||||
{ '[' },
|
|
||||||
{ tokNumUint },
|
|
||||||
{ ']' },
|
|
||||||
{ tokChar }
|
|
||||||
};
|
|
||||||
|
|
||||||
int SyntaxStackCnt = 8; // number of explicitly initialized elements in SyntaxStack[][2]
|
|
||||||
|
|
||||||
// all code
|
// all code
|
||||||
|
|
||||||
@@ -593,7 +586,7 @@ int uint2int(unsigned n)
|
|||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
// Convert n to (int)n in such a way that (unsigned)(int)n == n,
|
// Convert n to (int)n in such a way that (unsigned)(int)n == n,
|
||||||
// IOW, avoid signed overflows in (int)n that result in an implementation-defined value/signal.
|
// IOW, avoid signed overflows in (int)n.
|
||||||
// We're assuming ints are 2's complement.
|
// We're assuming ints are 2's complement.
|
||||||
|
|
||||||
// "n < INT_MAX + 1u" is equivalent to "n <= INT_MAX" without the
|
// "n < INT_MAX + 1u" is equivalent to "n <= INT_MAX" without the
|
||||||
@@ -617,10 +610,8 @@ unsigned truncUint(unsigned n)
|
|||||||
// Truncate n to SizeOfWord * 8 bits
|
// Truncate n to SizeOfWord * 8 bits
|
||||||
if (SizeOfWord == 2)
|
if (SizeOfWord == 2)
|
||||||
n &= ~(~0u << 8 << 8);
|
n &= ~(~0u << 8 << 8);
|
||||||
#ifdef CAN_COMPILE_32BIT
|
|
||||||
else if (SizeOfWord == 4)
|
else if (SizeOfWord == 4)
|
||||||
n &= ~(~0u << 8 << 12 << 12);
|
n &= ~(~0u << 8 << 12 << 12);
|
||||||
#endif
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -633,13 +624,11 @@ int truncInt(int n)
|
|||||||
un &= ~(~0u << 8 << 8);
|
un &= ~(~0u << 8 << 8);
|
||||||
un |= (((un >> 8 >> 7) & 1) * ~0u) << 8 << 8;
|
un |= (((un >> 8 >> 7) & 1) * ~0u) << 8 << 8;
|
||||||
}
|
}
|
||||||
#ifdef CAN_COMPILE_32BIT
|
|
||||||
else if (SizeOfWord == 4)
|
else if (SizeOfWord == 4)
|
||||||
{
|
{
|
||||||
un &= ~(~0u << 8 << 12 << 12);
|
un &= ~(~0u << 8 << 12 << 12);
|
||||||
un |= (((un >> 8 >> 12 >> 11) & 1) * ~0u) << 8 << 12 << 12;
|
un |= (((un >> 8 >> 12 >> 11) & 1) * ~0u) << 8 << 12 << 12;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return uint2int(un);
|
return uint2int(un);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -909,8 +898,7 @@ char* rws[] =
|
|||||||
"static", "switch", "unsigned", "void", "while", "asm", "auto",
|
"static", "switch", "unsigned", "void", "while", "asm", "auto",
|
||||||
"const", "double", "enum", "float", "goto", "inline", "long",
|
"const", "double", "enum", "float", "goto", "inline", "long",
|
||||||
"register", "restrict", "short", "struct", "typedef", "union",
|
"register", "restrict", "short", "struct", "typedef", "union",
|
||||||
"volatile", "_Bool", "_Complex", "_Imaginary",
|
"volatile", "_Bool", "_Complex", "_Imaginary"
|
||||||
"__interrupt"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned char rwtk[] =
|
unsigned char rwtk[] =
|
||||||
@@ -920,8 +908,7 @@ unsigned char rwtk[] =
|
|||||||
tokStatic, tokSwitch, tokUnsigned, tokVoid, tokWhile, tok_Asm, tokAuto,
|
tokStatic, tokSwitch, tokUnsigned, tokVoid, tokWhile, tok_Asm, tokAuto,
|
||||||
tokConst, tokDouble, tokEnum, tokFloat, tokGoto, tokInline, tokLong,
|
tokConst, tokDouble, tokEnum, tokFloat, tokGoto, tokInline, tokLong,
|
||||||
tokRegister, tokRestrict, tokShort, tokStruct, tokTypedef, tokUnion,
|
tokRegister, tokRestrict, tokShort, tokStruct, tokTypedef, tokUnion,
|
||||||
tokVolatile, tok_Bool, tok_Complex, tok_Imagin,
|
tokVolatile, tok_Bool, tok_Complex, tok_Imagin
|
||||||
tokIntr
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int GetTokenByWord(char* word)
|
int GetTokenByWord(char* word)
|
||||||
@@ -1052,6 +1039,26 @@ char* GetTokenName(int token)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GetTokenValueInt(void)
|
||||||
|
{
|
||||||
|
return TokenValueInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* GetTokenValueString(void)
|
||||||
|
{
|
||||||
|
return TokenValueString;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetTokenValueStringLength(void)
|
||||||
|
{
|
||||||
|
return TokenStringLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* GetTokenIdentName(void)
|
||||||
|
{
|
||||||
|
return TokenIdentName;
|
||||||
|
}
|
||||||
|
|
||||||
int GetNextChar(void)
|
int GetNextChar(void)
|
||||||
{
|
{
|
||||||
int ch = EOF;
|
int ch = EOF;
|
||||||
@@ -1377,10 +1384,11 @@ void GetString(char terminator, int SkipNewLines)
|
|||||||
c = (c * 8) & 0xFF;
|
c = (c * 8) & 0xFF;
|
||||||
c += *p - '0';
|
c += *p - '0';
|
||||||
ShiftCharN(1);
|
ShiftCharN(1);
|
||||||
// octal escape sequence is terminated after three octal digits
|
cnt++;
|
||||||
if (++cnt == 3)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
if (!cnt)
|
||||||
|
//error("Unsupported or invalid character/string constant\n");
|
||||||
|
errorChrStr();
|
||||||
c -= (c >= 0x80 && CHAR_MIN) * 0x100;
|
c -= (c >= 0x80 && CHAR_MIN) * 0x100;
|
||||||
ch = c;
|
ch = c;
|
||||||
}
|
}
|
||||||
@@ -1538,13 +1546,11 @@ int GetNumber(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the constant fits into 16(32) bits
|
// Ensure the constant fits into 16(32) bits
|
||||||
if (
|
if ((SizeOfWord == 2 && n >> 8 >> 8) || // equiv. to SizeOfWord == 2 && n > 0xFFFF
|
||||||
(SizeOfWord == 2 && n >> 8 >> 8) // equiv. to SizeOfWord == 2 && n > 0xFFFF
|
|
||||||
#ifdef CAN_COMPILE_32BIT
|
#ifdef CAN_COMPILE_32BIT
|
||||||
|| (SizeOfWord == 2 && lSuffix) // long (which must have at least 32 bits) isn't supported in 16-bit models
|
(SizeOfWord == 2 && lSuffix) || // long (which must have at least 32 bits) isn't supported in 16-bit models
|
||||||
|| (SizeOfWord == 4 && n >> 8 >> 12 >> 12) // equiv. to SizeOfWord == 4 && n > 0xFFFFFFFF
|
|
||||||
#endif
|
#endif
|
||||||
)
|
(SizeOfWord == 4 && n >> 8 >> 12 >> 12)) // equiv. to SizeOfWord == 4 && n > 0xFFFFFFFF
|
||||||
error("Constant too big for %d-bit type\n", SizeOfWord * 8);
|
error("Constant too big for %d-bit type\n", SizeOfWord * 8);
|
||||||
|
|
||||||
TokenValueInt = uint2int(n);
|
TokenValueInt = uint2int(n);
|
||||||
@@ -1552,13 +1558,8 @@ int GetNumber(void)
|
|||||||
// Unsuffixed (with 'u') integer constants (octal, decimal, hex)
|
// Unsuffixed (with 'u') integer constants (octal, decimal, hex)
|
||||||
// fitting into 15(31) out of 16(32) bits are signed ints
|
// fitting into 15(31) out of 16(32) bits are signed ints
|
||||||
if (!uSuffix &&
|
if (!uSuffix &&
|
||||||
(
|
((SizeOfWord == 2 && !(n >> 8 >> 7)) || // equiv. to SizeOfWord == 2 && n <= 0x7FFF
|
||||||
(SizeOfWord == 2 && !(n >> 15)) // equiv. to SizeOfWord == 2 && n <= 0x7FFF
|
(SizeOfWord == 4 && !(n >> 8 >> 12 >> 11)))) // equiv. to SizeOfWord == 4 && n <= 0x7FFFFFFF
|
||||||
#ifdef CAN_COMPILE_32BIT
|
|
||||||
|| (SizeOfWord == 4 && !(n >> 8 >> 12 >> 11)) // equiv. to SizeOfWord == 4 && n <= 0x7FFFFFFF
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return tokNumInt;
|
return tokNumInt;
|
||||||
|
|
||||||
// Unlike octal and hex constants, decimal constants are always
|
// Unlike octal and hex constants, decimal constants are always
|
||||||
@@ -1731,9 +1732,9 @@ int GetToken(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// treat keywords auto, const, register, restrict and volatile as white space for now
|
// treat keywords auto, const, register, restrict and volatile as white space for now
|
||||||
if ((tok == tokConst) | (tok == tokVolatile) |
|
if (tok == tokConst || tok == tokVolatile ||
|
||||||
(tok == tokAuto) | (tok == tokRegister) |
|
tok == tokAuto || tok == tokRegister ||
|
||||||
(tok == tokRestrict))
|
tok == tokRestrict)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return tok;
|
return tok;
|
||||||
@@ -1787,7 +1788,7 @@ int GetToken(void)
|
|||||||
if (GetNumber() != tokNumInt)
|
if (GetNumber() != tokNumInt)
|
||||||
//error("Invalid line number in preprocessor output\n");
|
//error("Invalid line number in preprocessor output\n");
|
||||||
errorDirective();
|
errorDirective();
|
||||||
line = TokenValueInt;
|
line = GetTokenValueInt();
|
||||||
|
|
||||||
SkipSpace(0);
|
SkipSpace(0);
|
||||||
|
|
||||||
@@ -1798,16 +1799,16 @@ int GetToken(void)
|
|||||||
else
|
else
|
||||||
GetString('>', 0);
|
GetString('>', 0);
|
||||||
|
|
||||||
if (strlen(TokenValueString) > MAX_FILE_NAME_LEN)
|
if (strlen(GetTokenValueString()) > MAX_FILE_NAME_LEN)
|
||||||
//error("File name too long in preprocessor output\n");
|
//error("File name too long in preprocessor output\n");
|
||||||
errorFileName();
|
errorFileName();
|
||||||
strcpy(FileNames[FileCnt - 1], TokenValueString);
|
strcpy(FileNames[FileCnt - 1], GetTokenValueString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore gcc-style #line's flags, if any
|
// Ignore gcc-style #line's flags, if any
|
||||||
while (!strchr("\r\n", *p))
|
while (!strchr("\r\n", *p))
|
||||||
ShiftCharN(1);
|
ShiftCharN(1);
|
||||||
|
|
||||||
LineNo = line - 1; // "line" is the number of the next line
|
LineNo = line - 1; // "line" is the number of the next line
|
||||||
LinePos = 1;
|
LinePos = 1;
|
||||||
|
|
||||||
@@ -1876,7 +1877,7 @@ int GetToken(void)
|
|||||||
|
|
||||||
if (hadNumber)
|
if (hadNumber)
|
||||||
{
|
{
|
||||||
PragmaPackValue = TokenValueInt;
|
PragmaPackValue = GetTokenValueInt();
|
||||||
if (PragmaPackValue <= 0 ||
|
if (PragmaPackValue <= 0 ||
|
||||||
PragmaPackValue > SizeOfWord ||
|
PragmaPackValue > SizeOfWord ||
|
||||||
PragmaPackValue & (PragmaPackValue - 1))
|
PragmaPackValue & (PragmaPackValue - 1))
|
||||||
@@ -2162,7 +2163,6 @@ int popop()
|
|||||||
|
|
||||||
int isop(int tok)
|
int isop(int tok)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
switch (tok)
|
switch (tok)
|
||||||
{
|
{
|
||||||
case '!':
|
case '!':
|
||||||
@@ -2190,41 +2190,11 @@ int isop(int tok)
|
|||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
static unsigned char toks[] =
|
|
||||||
{
|
|
||||||
'!',
|
|
||||||
'~',
|
|
||||||
'&',
|
|
||||||
'*',
|
|
||||||
'/', '%',
|
|
||||||
'+', '-',
|
|
||||||
'|', '^',
|
|
||||||
'<', '>',
|
|
||||||
'=',
|
|
||||||
tokLogOr, tokLogAnd,
|
|
||||||
tokEQ, tokNEQ,
|
|
||||||
tokLEQ, tokGEQ,
|
|
||||||
tokLShift, tokRShift,
|
|
||||||
tokInc, tokDec,
|
|
||||||
tokSizeof,
|
|
||||||
tokAssignMul, tokAssignDiv, tokAssignMod,
|
|
||||||
tokAssignAdd, tokAssignSub,
|
|
||||||
tokAssignLSh, tokAssignRSh,
|
|
||||||
tokAssignAnd, tokAssignXor, tokAssignOr,
|
|
||||||
tokComma,
|
|
||||||
'?'
|
|
||||||
};
|
|
||||||
unsigned i;
|
|
||||||
for (i = 0; i < sizeof toks / sizeof toks[0]; i++)
|
|
||||||
if (toks[i] == tok)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int isunary(int tok)
|
int isunary(int tok)
|
||||||
{
|
{
|
||||||
return (tok == '!') | (tok == '~') | (tok == tokInc) | (tok == tokDec) | (tok == tokSizeof);
|
return tok == '!' || tok == '~' || tok == tokInc || tok == tokDec || tok == tokSizeof;
|
||||||
}
|
}
|
||||||
|
|
||||||
int preced(int tok)
|
int preced(int tok)
|
||||||
@@ -2328,7 +2298,7 @@ int exprUnary(int tok, int* gotUnary, int commaSeparator, int argOfSizeOf)
|
|||||||
|
|
||||||
if (tok == tokNumInt || tok == tokNumUint)
|
if (tok == tokNumInt || tok == tokNumUint)
|
||||||
{
|
{
|
||||||
push2(tok, TokenValueInt);
|
push2(tok, GetTokenValueInt());
|
||||||
*gotUnary = 1;
|
*gotUnary = 1;
|
||||||
tok = GetToken();
|
tok = GetToken();
|
||||||
}
|
}
|
||||||
@@ -2341,7 +2311,7 @@ int exprUnary(int tok, int* gotUnary, int commaSeparator, int argOfSizeOf)
|
|||||||
|
|
||||||
// imitate definition: char #[len] = "...";
|
// imitate definition: char #[len] = "...";
|
||||||
|
|
||||||
AddString(lbl, TokenValueString, len = 1 + TokenStringLen);
|
AddString(lbl, GetTokenValueString(), len = 1 + GetTokenValueStringLength());
|
||||||
|
|
||||||
*--p = '\0';
|
*--p = '\0';
|
||||||
p = lab2str(p, lbl);
|
p = lab2str(p, lbl);
|
||||||
@@ -2359,7 +2329,7 @@ int exprUnary(int tok, int* gotUnary, int commaSeparator, int argOfSizeOf)
|
|||||||
}
|
}
|
||||||
else if (tok == tokIdent)
|
else if (tok == tokIdent)
|
||||||
{
|
{
|
||||||
push2(tok, AddIdent(TokenIdentName));
|
push2(tok, AddIdent(GetTokenIdentName()));
|
||||||
*gotUnary = 1;
|
*gotUnary = 1;
|
||||||
tok = GetToken();
|
tok = GetToken();
|
||||||
}
|
}
|
||||||
@@ -2518,7 +2488,7 @@ int exprUnary(int tok, int* gotUnary, int commaSeparator, int argOfSizeOf)
|
|||||||
tok = GetToken();
|
tok = GetToken();
|
||||||
if (tok != tokIdent)
|
if (tok != tokIdent)
|
||||||
errorUnexpectedToken(tok);
|
errorUnexpectedToken(tok);
|
||||||
push2(tok, AddIdent(TokenIdentName));
|
push2(tok, AddIdent(GetTokenIdentName()));
|
||||||
// "->" in "a->b" will function as "+" in "*(type_of_b*)((char*)a + offset_of_b_in_a)"
|
// "->" in "a->b" will function as "+" in "*(type_of_b*)((char*)a + offset_of_b_in_a)"
|
||||||
push(tokArrow);
|
push(tokArrow);
|
||||||
push(tokUnaryStar);
|
push(tokUnaryStar);
|
||||||
@@ -4711,7 +4681,7 @@ int TokenStartsDeclaration(int t, int params)
|
|||||||
#ifndef NO_TYPEDEF_ENUM
|
#ifndef NO_TYPEDEF_ENUM
|
||||||
t == tokEnum ||
|
t == tokEnum ||
|
||||||
(t == tokIdent &&
|
(t == tokIdent &&
|
||||||
FindTypedef(TokenIdentName, &CurScope, 1) >= 0) ||
|
FindTypedef(GetTokenIdentName(), &CurScope, 1) >= 0) ||
|
||||||
#endif
|
#endif
|
||||||
(!params && (t == tokExtern ||
|
(!params && (t == tokExtern ||
|
||||||
#ifndef NO_TYPEDEF_ENUM
|
#ifndef NO_TYPEDEF_ENUM
|
||||||
@@ -5345,8 +5315,8 @@ int ParseBase(int tok, int base[2])
|
|||||||
{
|
{
|
||||||
// this is a structure/union/enum tag
|
// this is a structure/union/enum tag
|
||||||
gotTag = 1;
|
gotTag = 1;
|
||||||
declPtr = FindTaggedDecl(TokenIdentName, SyntaxStackCnt - 1, &curScope);
|
declPtr = FindTaggedDecl(GetTokenIdentName(), SyntaxStackCnt - 1, &curScope);
|
||||||
tagIdent = AddIdent(TokenIdentName);
|
tagIdent = AddIdent(GetTokenIdentName());
|
||||||
|
|
||||||
if (declPtr >= 0)
|
if (declPtr >= 0)
|
||||||
{
|
{
|
||||||
@@ -5412,7 +5382,7 @@ int ParseBase(int tok, int base[2])
|
|||||||
if (tok != tokIdent)
|
if (tok != tokIdent)
|
||||||
errorUnexpectedToken(tok);
|
errorUnexpectedToken(tok);
|
||||||
|
|
||||||
s = TokenIdentName;
|
s = GetTokenIdentName();
|
||||||
if (FindTypedef(s, &CurScope, 0) >= 0 && CurScope)
|
if (FindTypedef(s, &CurScope, 0) >= 0 && CurScope)
|
||||||
errorRedef(s);
|
errorRedef(s);
|
||||||
|
|
||||||
@@ -5563,7 +5533,7 @@ int ParseBase(int tok, int base[2])
|
|||||||
}
|
}
|
||||||
#ifndef NO_TYPEDEF_ENUM
|
#ifndef NO_TYPEDEF_ENUM
|
||||||
else if (tok == tokIdent &&
|
else if (tok == tokIdent &&
|
||||||
(base[1] = FindTypedef(TokenIdentName, &CurScope, 1)) >= 0)
|
(base[1] = FindTypedef(GetTokenIdentName(), &CurScope, 1)) >= 0)
|
||||||
{
|
{
|
||||||
base[0] = tokTypedef;
|
base[0] = tokTypedef;
|
||||||
tok = GetToken();
|
tok = GetToken();
|
||||||
@@ -5615,11 +5585,6 @@ int ParseDerived(int tok)
|
|||||||
{
|
{
|
||||||
int stars = 0;
|
int stars = 0;
|
||||||
int params = 0;
|
int params = 0;
|
||||||
#ifndef MIPS
|
|
||||||
#ifdef CAN_COMPILE_32BIT
|
|
||||||
int isInterrupt = 0;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (tok == '*')
|
while (tok == '*')
|
||||||
{
|
{
|
||||||
@@ -5627,19 +5592,6 @@ int ParseDerived(int tok)
|
|||||||
tok = GetToken();
|
tok = GetToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MIPS
|
|
||||||
#ifdef CAN_COMPILE_32BIT
|
|
||||||
if (tok == tokIntr)
|
|
||||||
{
|
|
||||||
// __interrupt is supported in the huge mode(l) only
|
|
||||||
if (OutputFormat != FormatSegHuge)
|
|
||||||
errorDecl();
|
|
||||||
isInterrupt = 1;
|
|
||||||
tok = GetToken();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (tok == '(')
|
if (tok == '(')
|
||||||
{
|
{
|
||||||
tok = GetToken();
|
tok = GetToken();
|
||||||
@@ -5658,7 +5610,7 @@ int ParseDerived(int tok)
|
|||||||
}
|
}
|
||||||
else if (tok == tokIdent)
|
else if (tok == tokIdent)
|
||||||
{
|
{
|
||||||
PushSyntax2(tok, AddIdent(TokenIdentName));
|
PushSyntax2(tok, AddIdent(GetTokenIdentName()));
|
||||||
tok = GetToken();
|
tok = GetToken();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -5675,15 +5627,7 @@ int ParseDerived(int tok)
|
|||||||
tok = GetToken();
|
tok = GetToken();
|
||||||
else
|
else
|
||||||
PushSyntax2(tokIdent, AddIdent("<something>"));
|
PushSyntax2(tokIdent, AddIdent("<something>"));
|
||||||
#ifndef MIPS
|
|
||||||
#ifdef CAN_COMPILE_32BIT
|
|
||||||
if (isInterrupt)
|
|
||||||
PushSyntax2('(', 1);
|
|
||||||
else // fallthrough
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
PushSyntax('(');
|
PushSyntax('(');
|
||||||
|
|
||||||
ParseLevel++;
|
ParseLevel++;
|
||||||
ParamLevel++;
|
ParamLevel++;
|
||||||
ParseFxnParams(tok);
|
ParseFxnParams(tok);
|
||||||
@@ -5849,7 +5793,6 @@ int InitScalar(int synPtr, int tok)
|
|||||||
int gotUnary, synPtr2, constExpr, exprVal;
|
int gotUnary, synPtr2, constExpr, exprVal;
|
||||||
int oldssp = SyntaxStackCnt;
|
int oldssp = SyntaxStackCnt;
|
||||||
int undoIdents = IdentTableLen;
|
int undoIdents = IdentTableLen;
|
||||||
int ttop;
|
|
||||||
|
|
||||||
tok = ParseExpr(tok, &gotUnary, &synPtr2, &constExpr, &exprVal, ',', 0);
|
tok = ParseExpr(tok, &gotUnary, &synPtr2, &constExpr, &exprVal, ',', 0);
|
||||||
|
|
||||||
@@ -5858,39 +5801,15 @@ int InitScalar(int synPtr, int tok)
|
|||||||
|
|
||||||
scalarTypeCheck(synPtr2);
|
scalarTypeCheck(synPtr2);
|
||||||
|
|
||||||
ttop = stack[sp - 1][0];
|
if (stack[sp - 1][0] == tokNumInt || stack[sp - 1][0] == tokNumUint)
|
||||||
if (ttop == tokNumInt || ttop == tokNumUint)
|
|
||||||
{
|
{
|
||||||
// TBD??? truncate values for types smaller than int (e.g. char and short),
|
// TBD??? truncate values for types smaller than int (e.g. char and short),
|
||||||
// so they are always in range?
|
// so they are always in range?
|
||||||
GenIntData(elementSz, stack[0][1]);
|
GenIntData(elementSz, stack[0][1]);
|
||||||
}
|
}
|
||||||
else if (elementSz == SizeOfWord + 0u)
|
else if (elementSz == SizeOfWord + 0u && stack[sp - 1][0] == tokIdent)
|
||||||
{
|
{
|
||||||
if (ttop == tokIdent)
|
GenAddrData(elementSz, IdentTable + stack[sp - 1][1]);
|
||||||
{
|
|
||||||
GenAddrData(elementSz, IdentTable + stack[sp - 1][1], 0);
|
|
||||||
}
|
|
||||||
else if (ttop == '+' || ttop == '-')
|
|
||||||
{
|
|
||||||
int tleft = stack[sp - 3][0];
|
|
||||||
int tright = stack[sp - 2][0];
|
|
||||||
if (tleft == tokIdent &&
|
|
||||||
(tright == tokNumInt || tright == tokNumUint))
|
|
||||||
{
|
|
||||||
GenAddrData(elementSz, IdentTable + stack[sp - 3][1], (ttop == '+') ? stack[sp - 2][1] : -stack[sp - 2][1]);
|
|
||||||
}
|
|
||||||
else if (ttop == '+' &&
|
|
||||||
tright == tokIdent &&
|
|
||||||
(tleft == tokNumInt || tleft == tokNumUint))
|
|
||||||
{
|
|
||||||
GenAddrData(elementSz, IdentTable + stack[sp - 2][1], stack[sp - 3][1]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
errorNotConst();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
errorNotConst();
|
|
||||||
// Defer storage of string literal data (if any) until the end.
|
// Defer storage of string literal data (if any) until the end.
|
||||||
// This will let us generate the contiguous array of pointers to
|
// This will let us generate the contiguous array of pointers to
|
||||||
// string literals unperturbed by the string literal data
|
// string literals unperturbed by the string literal data
|
||||||
@@ -5938,9 +5857,6 @@ int InitArray(int synPtr, int tok)
|
|||||||
int undoIdents = IdentTableLen;
|
int undoIdents = IdentTableLen;
|
||||||
int slen = StringTableLen;
|
int slen = StringTableLen;
|
||||||
|
|
||||||
if (elementsRequired * ((unsigned)TokenStringLen > elementsRequired))
|
|
||||||
warning("String literal truncated\n");
|
|
||||||
|
|
||||||
tok = ParseExpr(tok, &gotUnary, &synPtr2, &constExpr, &exprVal, ',', 0);
|
tok = ParseExpr(tok, &gotUnary, &synPtr2, &constExpr, &exprVal, ',', 0);
|
||||||
|
|
||||||
if (!gotUnary ||
|
if (!gotUnary ||
|
||||||
@@ -6166,7 +6082,7 @@ int ParseDecl(int tok, unsigned structInfo[4], int cast, int label)
|
|||||||
#ifndef NO_TYPEDEF_ENUM
|
#ifndef NO_TYPEDEF_ENUM
|
||||||
typeDef |
|
typeDef |
|
||||||
#endif
|
#endif
|
||||||
Static) &&
|
Static) &&
|
||||||
!strcmp(IdentTable + SyntaxStack[lastSyntaxPtr][1], "<something>") &&
|
!strcmp(IdentTable + SyntaxStack[lastSyntaxPtr][1], "<something>") &&
|
||||||
tok == ';')
|
tok == ';')
|
||||||
{
|
{
|
||||||
@@ -6620,16 +6536,7 @@ int ParseDecl(int tok, unsigned structInfo[4], int cast, int label)
|
|||||||
|
|
||||||
GenLabel(IdentTable + SyntaxStack[lastSyntaxPtr][1], Static);
|
GenLabel(IdentTable + SyntaxStack[lastSyntaxPtr][1], Static);
|
||||||
CurFxnEpilogLabel = LabelCnt++;
|
CurFxnEpilogLabel = LabelCnt++;
|
||||||
|
|
||||||
#ifndef MIPS
|
|
||||||
#ifdef CAN_COMPILE_32BIT
|
|
||||||
if (SyntaxStack[lastSyntaxPtr + 1][1] & 1)
|
|
||||||
GenIsrProlog();
|
|
||||||
else // fallthrough
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
GenFxnProlog();
|
GenFxnProlog();
|
||||||
|
|
||||||
GenJumpUncond(locAllocLabel + 1);
|
GenJumpUncond(locAllocLabel + 1);
|
||||||
GenNumLabel(locAllocLabel);
|
GenNumLabel(locAllocLabel);
|
||||||
|
|
||||||
@@ -6676,16 +6583,7 @@ int ParseDecl(int tok, unsigned structInfo[4], int cast, int label)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GenNumLabel(CurFxnEpilogLabel);
|
GenNumLabel(CurFxnEpilogLabel);
|
||||||
|
|
||||||
#ifndef MIPS
|
|
||||||
#ifdef CAN_COMPILE_32BIT
|
|
||||||
if (SyntaxStack[lastSyntaxPtr + 1][1] & 1)
|
|
||||||
GenIsrEpilog();
|
|
||||||
else // fallthrough
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
GenFxnEpilog();
|
GenFxnEpilog();
|
||||||
|
|
||||||
GenNumLabel(locAllocLabel + 1);
|
GenNumLabel(locAllocLabel + 1);
|
||||||
if (CurFxnMinLocalOfs)
|
if (CurFxnMinLocalOfs)
|
||||||
GenLocalAlloc(-CurFxnMinLocalOfs);
|
GenLocalAlloc(-CurFxnMinLocalOfs);
|
||||||
@@ -7488,7 +7386,7 @@ int ParseStatement(int tok, int BrkCntSwchTarget[4], int switchBody)
|
|||||||
//error("ParseStatement(): string literal expression expected in 'asm ( expression )'\n");
|
//error("ParseStatement(): string literal expression expected in 'asm ( expression )'\n");
|
||||||
errorUnexpectedToken(tok);
|
errorUnexpectedToken(tok);
|
||||||
|
|
||||||
puts2(TokenValueString);
|
puts2(GetTokenValueString());
|
||||||
|
|
||||||
tok = GetToken();
|
tok = GetToken();
|
||||||
if (tok != ')')
|
if (tok != ')')
|
||||||
@@ -7507,9 +7405,9 @@ int ParseStatement(int tok, int BrkCntSwchTarget[4], int switchBody)
|
|||||||
if ((tok = GetToken()) != tokIdent)
|
if ((tok = GetToken()) != tokIdent)
|
||||||
errorUnexpectedToken(tok);
|
errorUnexpectedToken(tok);
|
||||||
#ifndef NO_ANNOTATIONS
|
#ifndef NO_ANNOTATIONS
|
||||||
GenStartCommentLine(); printf2("goto %s\n", TokenIdentName);
|
GenStartCommentLine(); printf2("goto %s\n", GetTokenIdentName());
|
||||||
#endif
|
#endif
|
||||||
GenJumpUncond(AddGotoLabel(TokenIdentName, 0));
|
GenJumpUncond(AddGotoLabel(GetTokenIdentName(), 0));
|
||||||
if ((tok = GetToken()) != ';')
|
if ((tok = GetToken()) != ';')
|
||||||
errorUnexpectedToken(tok);
|
errorUnexpectedToken(tok);
|
||||||
tok = GetToken();
|
tok = GetToken();
|
||||||
@@ -7565,9 +7463,9 @@ int ParseBlock(int BrkCntSwchTarget[4], int switchBody)
|
|||||||
{
|
{
|
||||||
// found a label
|
// found a label
|
||||||
#ifndef NO_ANNOTATIONS
|
#ifndef NO_ANNOTATIONS
|
||||||
GenStartCommentLine(); printf2("%s:\n", TokenIdentName);
|
GenStartCommentLine(); printf2("%s:\n", GetTokenIdentName());
|
||||||
#endif
|
#endif
|
||||||
GenNumLabel(AddGotoLabel(TokenIdentName, 1));
|
GenNumLabel(AddGotoLabel(GetTokenIdentName(), 1));
|
||||||
tok = GetToken();
|
tok = GetToken();
|
||||||
// a statement is needed after "label:"
|
// a statement is needed after "label:"
|
||||||
tok = ParseStatement(tok, BrkCntSwchTarget, switchBody);
|
tok = ParseStatement(tok, BrkCntSwchTarget, switchBody);
|
||||||
@@ -7723,7 +7621,7 @@ int main(int argc, char** argv)
|
|||||||
LinePoss[0] = LinePos;
|
LinePoss[0] = LinePos;
|
||||||
FileCnt++;
|
FileCnt++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (FileCnt == 1 && OutFile == NULL)
|
else if (FileCnt == 1 && OutFile == NULL)
|
||||||
{
|
{
|
||||||
// This should be the output file name
|
// This should be the output file name
|
||||||
@@ -7731,7 +7629,7 @@ int main(int argc, char** argv)
|
|||||||
//error("Cannot open output file \"%s\"\n", argv[i]);
|
//error("Cannot open output file \"%s\"\n", argv[i]);
|
||||||
errorFile(argv[i]);
|
errorFile(argv[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
error("Invalid or unsupported command line option\n");
|
error("Invalid or unsupported command line option\n");
|
||||||
}
|
}
|
||||||
@@ -7741,6 +7639,16 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
GenInitFinalize();
|
GenInitFinalize();
|
||||||
|
|
||||||
|
// some manual initialization because there's no 2d array initialization yet
|
||||||
|
PushSyntax(tokVoid); // SymVoidSynPtr
|
||||||
|
PushSyntax(tokInt); // SymIntSynPtr
|
||||||
|
PushSyntax(tokUnsigned); // SymUintSynPtr
|
||||||
|
PushSyntax(tokIdent); // SymFuncPtr
|
||||||
|
PushSyntax('[');
|
||||||
|
PushSyntax(tokNumUint);
|
||||||
|
PushSyntax(']');
|
||||||
|
PushSyntax(tokChar);
|
||||||
|
|
||||||
#ifndef NO_PREPROCESSOR
|
#ifndef NO_PREPROCESSOR
|
||||||
// Define a few macros useful for conditional compilation
|
// Define a few macros useful for conditional compilation
|
||||||
DefineMacro("__SMALLER_C__", "0x0100");
|
DefineMacro("__SMALLER_C__", "0x0100");
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ strip(name)
|
|||||||
status = 1;
|
status = 1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (head.a_syms == 0 && (head.a_magic) != RMAGIC)
|
if (head.a_syms == 0 && head.a_magic != RMAGIC)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
size = N_DATOFF(head) + head.a_data;
|
size = N_DATOFF(head) + head.a_data;
|
||||||
@@ -45,7 +45,7 @@ strip(name)
|
|||||||
status = 1;
|
status = 1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
head.a_midmag = OMAGIC;
|
head.a_magic = OMAGIC;
|
||||||
head.a_reltext = 0;
|
head.a_reltext = 0;
|
||||||
head.a_reldata = 0;
|
head.a_reldata = 0;
|
||||||
head.a_syms = 0;
|
head.a_syms = 0;
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ SECTIONS
|
|||||||
*(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
|
*(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
|
||||||
}
|
}
|
||||||
.sbss2 : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) }
|
.sbss2 : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) }
|
||||||
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
|
.eh_frame_hdr : { *(.eh_frame_hdr) }
|
||||||
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }
|
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }
|
||||||
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
|
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
|
||||||
/* Adjust the address for the data segment. */
|
/* Adjust the address for the data segment. */
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ OBJS = battlestar.o cmd1.o cmd2.o cmd3.o cmd4.o cmd5.o cmd6.o cmd7.o
|
|||||||
init.o cypher.o getcom.o parse.o room.o save.o fly.o misc.o \
|
init.o cypher.o getcom.o parse.o room.o save.o fly.o misc.o \
|
||||||
_globals.o _dayfile.o _nightfile.o dayobjs.o nightobjs.o words.o \
|
_globals.o _dayfile.o _nightfile.o dayobjs.o nightobjs.o words.o \
|
||||||
curses.o doprnt.o
|
curses.o doprnt.o
|
||||||
LIBS = -lc
|
LIBS =
|
||||||
MAN = battlestar.0
|
MAN = battlestar.0
|
||||||
MANSRC = battlestar.6
|
MANSRC = battlestar.6
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ CFLAGS += -Os -mips16 -Werror -Wall
|
|||||||
OBJS = main.o pl_main.o pl_1.o pl_2.o pl_3.o pl_4.o pl_5.o pl_6.o pl_7.o \
|
OBJS = main.o pl_main.o pl_1.o pl_2.o pl_3.o pl_4.o pl_5.o pl_6.o pl_7.o \
|
||||||
dr_main.o dr_1.o dr_2.o dr_3.o dr_4.o dr_5.o lo_main.o \
|
dr_main.o dr_1.o dr_2.o dr_3.o dr_4.o dr_5.o lo_main.o \
|
||||||
assorted.o game.o globals.o misc.o parties.o sync.o version.o doprnt.o
|
assorted.o game.o globals.o misc.o parties.o sync.o version.o doprnt.o
|
||||||
LIBS = -lcurses -ltermcap -lc
|
LIBS = -lcurses -ltermcap
|
||||||
MAN = sail.0
|
MAN = sail.0
|
||||||
MANSRC = sail.6
|
MANSRC = sail.6
|
||||||
|
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ Sync()
|
|||||||
switch (*p++ = getc(sync_fp)) {
|
switch (*p++ = getc(sync_fp)) {
|
||||||
case '\n':
|
case '\n':
|
||||||
p--;
|
p--;
|
||||||
case (char)EOF:
|
case EOF:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (p >= buf + sizeof buf)
|
if (p >= buf + sizeof buf)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ OBJS = abandon.o attack.o autover.o capture.o check_out.o checkcond.o
|
|||||||
ranf.o rest.o schedule.o score.o setup.o setwarp.o shell.o \
|
ranf.o rest.o schedule.o score.o setup.o setwarp.o shell.o \
|
||||||
shield.o snova.o srscan.o systemname.o torped.o utility.o \
|
shield.o snova.o srscan.o systemname.o torped.o utility.o \
|
||||||
visual.o warp.o win.o
|
visual.o warp.o win.o
|
||||||
LIBS = -lm -lc
|
LIBS = -lm
|
||||||
MAN = trek.0
|
MAN = trek.0
|
||||||
MANSRC = trek.6
|
MANSRC = trek.6
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ main(argc, argv)
|
|||||||
{
|
{
|
||||||
long vect;
|
long vect;
|
||||||
/* extern FILE *f_log; */
|
/* extern FILE *f_log; */
|
||||||
/* register char opencode; */
|
register char opencode;
|
||||||
int prio;
|
int prio;
|
||||||
register int ac;
|
register int ac;
|
||||||
register char **av;
|
register char **av;
|
||||||
@@ -132,7 +132,7 @@ main(argc, argv)
|
|||||||
av++;
|
av++;
|
||||||
time(&vect);
|
time(&vect);
|
||||||
srand(vect);
|
srand(vect);
|
||||||
/* opencode = 'w'; */
|
opencode = 'w';
|
||||||
prio = PRIO;
|
prio = PRIO;
|
||||||
if (ioctl(1, TIOCGETP, &argp) == 0)
|
if (ioctl(1, TIOCGETP, &argp) == 0)
|
||||||
{
|
{
|
||||||
@@ -144,7 +144,7 @@ main(argc, argv)
|
|||||||
switch (av[0][1])
|
switch (av[0][1])
|
||||||
{
|
{
|
||||||
case 'a': /* append to log file */
|
case 'a': /* append to log file */
|
||||||
/* opencode = 'a'; */
|
opencode = 'a';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f': /* set fast mode */
|
case 'f': /* set fast mode */
|
||||||
@@ -179,6 +179,10 @@ main(argc, argv)
|
|||||||
}
|
}
|
||||||
if (ac > 2)
|
if (ac > 2)
|
||||||
syserr(0, "arg count");
|
syserr(0, "arg count");
|
||||||
|
/*
|
||||||
|
if (ac > 1)
|
||||||
|
f_log = fopen(av[0], opencode);
|
||||||
|
*/
|
||||||
|
|
||||||
printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n");
|
printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n");
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ memccpy(vt, vf, c, n)
|
|||||||
register char *t = vt;
|
register char *t = vt;
|
||||||
register const char *f = vf;
|
register const char *f = vf;
|
||||||
|
|
||||||
while (n-- > 0)
|
while (--n >= 0)
|
||||||
if ((*t++ = *f++) == c)
|
if ((*t++ = *f++) == c)
|
||||||
return (t);
|
return (t);
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ memchr(vs, c, n)
|
|||||||
{
|
{
|
||||||
register const char *s = vs;
|
register const char *s = vs;
|
||||||
|
|
||||||
while (n-- > 0)
|
while (--n >= 0)
|
||||||
if (*s++ == c)
|
if (*s++ == c)
|
||||||
return (void*) --s;
|
return (void*) --s;
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ memcmp (vs1, vs2, n)
|
|||||||
{
|
{
|
||||||
register const char *s1 = vs1, *s2 = vs2;
|
register const char *s1 = vs1, *s2 = vs2;
|
||||||
|
|
||||||
while (n-- > 0)
|
while (--n >= 0)
|
||||||
if (*s1++ != *s2++)
|
if (*s1++ != *s2++)
|
||||||
return (*--s1 - *--s2);
|
return (*--s1 - *--s2);
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ memcpy (vt, vf, n)
|
|||||||
register char *t = vt;
|
register char *t = vt;
|
||||||
register const char *f = vf;
|
register const char *f = vf;
|
||||||
|
|
||||||
while (n-- > 0)
|
while (--n >= 0)
|
||||||
*t++ = *f++;
|
*t++ = *f++;
|
||||||
|
|
||||||
return vt;
|
return vt;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ memset (vs, c, n)
|
|||||||
{
|
{
|
||||||
register char *s = vs;
|
register char *s = vs;
|
||||||
|
|
||||||
while (n-- > 0)
|
while (--n >= 0)
|
||||||
*s++ = c;
|
*s++ = c;
|
||||||
|
|
||||||
return vs;
|
return vs;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
getenv(name)
|
getenv(name)
|
||||||
const char *name;
|
char *name;
|
||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
char *_findenv();
|
char *_findenv();
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ strncasecmp(s1, s2, n)
|
|||||||
{
|
{
|
||||||
register char *cm = charmap;
|
register char *cm = charmap;
|
||||||
|
|
||||||
while (n-- > 0 && cm[(unsigned char)*s1] == cm[(unsigned char)*s2++])
|
while (--n >= 0 && cm[(unsigned char)*s1] == cm[(unsigned char)*s2++])
|
||||||
if (*s1++ == '\0')
|
if (*s1++ == '\0')
|
||||||
return(0);
|
return(0);
|
||||||
return(n == -1 ? 0 : cm[(unsigned char)*s1] - cm[(unsigned char)*--s2]);
|
return(n < 0 ? 0 : cm[(unsigned char)*s1] - cm[(unsigned char)*--s2]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ strncat(s1, s2, n)
|
|||||||
;
|
;
|
||||||
--s1;
|
--s1;
|
||||||
while ((*s1++ = *s2++))
|
while ((*s1++ = *s2++))
|
||||||
if (n-- == 0) {
|
if (--n < 0) {
|
||||||
*--s1 = '\0';
|
*--s1 = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ strncpy(s1, s2, n)
|
|||||||
register const char *s2;
|
register const char *s2;
|
||||||
size_t n;
|
size_t n;
|
||||||
{
|
{
|
||||||
size_t i;
|
register int i;
|
||||||
register char *os1;
|
register char *os1;
|
||||||
|
|
||||||
os1 = s1;
|
os1 = s1;
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ char *suboptarg;
|
|||||||
|
|
||||||
int
|
int
|
||||||
getsubopt(optionp, tokens, valuep)
|
getsubopt(optionp, tokens, valuep)
|
||||||
register char **optionp;
|
register char **optionp, **valuep;
|
||||||
register char **valuep;
|
|
||||||
register char **tokens;
|
register char **tokens;
|
||||||
{
|
{
|
||||||
register int cnt;
|
register int cnt;
|
||||||
|
|||||||
@@ -43,11 +43,11 @@
|
|||||||
*/
|
*/
|
||||||
long
|
long
|
||||||
strtol(nptr, endptr, base)
|
strtol(nptr, endptr, base)
|
||||||
const char *nptr;
|
char *nptr;
|
||||||
char **endptr;
|
char **endptr;
|
||||||
register int base;
|
register int base;
|
||||||
{
|
{
|
||||||
register const char *s = nptr;
|
register char *s = nptr;
|
||||||
register unsigned long acc;
|
register unsigned long acc;
|
||||||
register int c;
|
register int c;
|
||||||
register unsigned long cutoff;
|
register unsigned long cutoff;
|
||||||
|
|||||||
@@ -43,11 +43,11 @@
|
|||||||
*/
|
*/
|
||||||
unsigned long
|
unsigned long
|
||||||
strtoul(nptr, endptr, base)
|
strtoul(nptr, endptr, base)
|
||||||
const char *nptr;
|
char *nptr;
|
||||||
char **endptr;
|
char **endptr;
|
||||||
register int base;
|
register int base;
|
||||||
{
|
{
|
||||||
register const char *s = nptr;
|
register char *s = nptr;
|
||||||
register unsigned long acc;
|
register unsigned long acc;
|
||||||
register int c;
|
register int c;
|
||||||
register unsigned long cutoff;
|
register unsigned long cutoff;
|
||||||
|
|||||||
@@ -4,103 +4,25 @@
|
|||||||
* specifies the terms and conditions for redistribution.
|
* specifies the terms and conditions for redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _SYS_EXEC_H_
|
#ifndef _EXEC_
|
||||||
#define _SYS_EXEC_H_
|
#define _EXEC_
|
||||||
#ifdef KERNEL
|
/*
|
||||||
|
* Header prepended to each a.out file.
|
||||||
#ifdef EXEC_SCRIPT
|
*/
|
||||||
#define SHSIZE 64
|
struct exec {
|
||||||
#define SHPATHLEN 64
|
int a_magic; /* magic number */
|
||||||
#endif
|
unsigned int a_text; /* size of text segment */
|
||||||
#ifdef EXEC_ELF
|
unsigned int a_data; /* size of initialized data */
|
||||||
#define STRLEN 32
|
unsigned int a_bss; /* size of uninitialized data */
|
||||||
#endif
|
unsigned int a_reltext; /* size of text relocation info */
|
||||||
#ifdef EXEC_AOUT
|
unsigned int a_reldata; /* size of data relocation info */
|
||||||
#include "exec_aout.h"
|
unsigned int a_syms; /* size of symbol table */
|
||||||
#endif
|
unsigned int a_entry; /* entry point */
|
||||||
#ifdef EXEC_ELF
|
|
||||||
#include "exec_elf.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define NO_ADDR ((caddr_t)(~0U)) /* Indicates addr. not yet filled in */
|
|
||||||
|
|
||||||
struct memsect {
|
|
||||||
caddr_t vaddr;
|
|
||||||
unsigned len;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct exec_params {
|
/* a_magic */
|
||||||
char *userfname; /* The arguments to the exec() call */
|
#define RMAGIC 0406 /* relocatable object file */
|
||||||
char **userargp;
|
#define OMAGIC 0407 /* old impure format */
|
||||||
char **userenvp;
|
#define NMAGIC 0410 /* read-only text */
|
||||||
union {
|
|
||||||
#ifdef EXEC_SCRIPT
|
|
||||||
char sh[SHSIZE];
|
|
||||||
#endif
|
|
||||||
#ifdef EXEC_AOUT
|
|
||||||
struct exec aout;
|
|
||||||
#endif
|
|
||||||
#ifdef EXEC_ELF
|
|
||||||
struct elf_ehdr elf;
|
|
||||||
#endif
|
|
||||||
} hdr; /* head of file to exec */
|
|
||||||
int hdr_len; /* number of bytes valid in image_header */
|
|
||||||
char **argp, **envp;
|
|
||||||
u_short argc, envc; /* count of argument and environment strings */
|
|
||||||
u_short argbc, envbc; /* total number of chars in argc and envc string pool */
|
|
||||||
union {
|
|
||||||
#ifdef EXEC_SCRIPT
|
|
||||||
struct {
|
|
||||||
char interpname[20]; /* real name of the script interpreter */
|
|
||||||
char interparg[SHPATHLEN]; /* interpreter arg */
|
|
||||||
char interpreted; /* flag - this executable is interpreted */
|
|
||||||
} sh;
|
|
||||||
#endif
|
|
||||||
#ifdef EXEC_ELF
|
|
||||||
struct {
|
|
||||||
struct buf *stbp; /* String table buffer pointer */
|
|
||||||
int stbpos; /* String table pos in buffer */
|
|
||||||
int stsize; /* String table size */
|
|
||||||
int stoffset; /* String table file pos */
|
|
||||||
char str[STRLEN];
|
|
||||||
} elf;
|
|
||||||
#endif
|
|
||||||
#ifdef EXEC_AOUT
|
|
||||||
struct {
|
|
||||||
} aout;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
gid_t gid;
|
|
||||||
uid_t uid;
|
|
||||||
#define MAXALLOCBUF 6
|
|
||||||
struct {
|
|
||||||
struct buf *bp; /* Memory allocator buffer */
|
|
||||||
u_short fill; /* Memory allocator "free" pointer */
|
|
||||||
} alloc[MAXALLOCBUF];
|
|
||||||
u_long ep_taddr, ep_tsize, ep_daddr, ep_dsize;
|
|
||||||
struct inode *ip; /* executable file ip */
|
|
||||||
struct memsect text, data, bss, heap, stack;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct execsw {
|
|
||||||
int (*es_check)(struct exec_params *epp);
|
|
||||||
const char* es_name;
|
|
||||||
};
|
|
||||||
extern const struct execsw execsw[];
|
|
||||||
extern int nexecs, exec_maxhdrsz;
|
|
||||||
|
|
||||||
|
|
||||||
struct buf *exec_copy_args(char **argp, struct exec_params *epp, int isargv, int *argc, int *argbc);
|
|
||||||
int exec_check(struct exec_params *epp);
|
|
||||||
void exec_setupstack(unsigned entryaddr, struct exec_params *epp);
|
|
||||||
void exec_alloc_freeall(struct exec_params *epp);
|
|
||||||
void *exec_alloc(int size, int ru, struct exec_params *epp);
|
|
||||||
int exec_estab(struct exec_params *epp);
|
|
||||||
void exec_save_args(struct exec_params *epp);
|
|
||||||
void exec_clear(struct exec_params *epp);
|
|
||||||
|
|
||||||
#else /* KERNEL */
|
|
||||||
#include <sys/exec_aout.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
#ifndef _SYS_EXEC_AOUT_H_
|
|
||||||
#define _SYS_EXEC_AOUT_H_
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Header prepended to each a.out file.
|
|
||||||
*/
|
|
||||||
struct exec {
|
|
||||||
unsigned a_midmag; /* magic number */
|
|
||||||
unsigned a_text; /* size of text segment */
|
|
||||||
unsigned a_data; /* size of initialized data */
|
|
||||||
unsigned a_bss; /* size of uninitialized data */
|
|
||||||
unsigned a_reltext; /* size of text relocation info */
|
|
||||||
unsigned a_reldata; /* size of data relocation info */
|
|
||||||
unsigned a_syms; /* size of symbol table */
|
|
||||||
unsigned a_entry; /* entry point */
|
|
||||||
};
|
|
||||||
|
|
||||||
#define a_magic a_midmag & 0xffff
|
|
||||||
|
|
||||||
/* a_magic (a_midmag & 0x0000ffff) */
|
|
||||||
#define RMAGIC 0406 /* relocatable object file */
|
|
||||||
#define OMAGIC 0407 /* old impure format */
|
|
||||||
#define NMAGIC 0410 /* read-only text */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* a_mid ((a_midmag & 0x03ff0000) >> 16)
|
|
||||||
*/
|
|
||||||
#define MID_ZERO 0 /* unknown - implementation dependent */
|
|
||||||
#define MID_SUN010 1 /* sun 68010/68020 binary */
|
|
||||||
#define MID_SUN020 2 /* sun 68020-only binary */
|
|
||||||
#define MID_PC386 100 /* 386 PC binary. (so quoth BFD) */
|
|
||||||
#define MID_HP200 200 /* hp200 (68010) BSD binary */
|
|
||||||
#define MID_I386 134 /* i386 BSD binary */
|
|
||||||
#define MID_M68K 135 /* m68k BSD binary with 8K page sizes */
|
|
||||||
#define MID_M68K4K 136 /* m68k BSD binary with 4K page sizes */
|
|
||||||
#define MID_NS32532 137 /* ns32532 */
|
|
||||||
#define MID_SPARC 138 /* sparc */
|
|
||||||
#define MID_PMAX 139 /* pmax */
|
|
||||||
#define MID_VAX1K 140 /* vax 1K page size binaries */
|
|
||||||
#define MID_ALPHA 141 /* Alpha BSD binary */
|
|
||||||
#define MID_MIPS 142 /* big-endian MIPS */
|
|
||||||
#define MID_ARM6 143 /* ARM6 */
|
|
||||||
#define MID_SH3 145 /* SH3 */
|
|
||||||
#define MID_POWERPC 149 /* big-endian PowerPC */
|
|
||||||
#define MID_VAX 150 /* vax */
|
|
||||||
#define MID_SPARC64 151 /* LP64 sparc */
|
|
||||||
#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */
|
|
||||||
#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */
|
|
||||||
#define MID_HPUX800 0x20B /* hp800 HP-UX binary */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* a_flags ((a_midmag & 0xfc000000 ) << 26)
|
|
||||||
*/
|
|
||||||
#define EX_PIC 0x10
|
|
||||||
#define EX_DYNAMIC 0x20
|
|
||||||
#define EX_DPMASK 0x30
|
|
||||||
/*
|
|
||||||
* Interpretation of the (a_flags & EX_DPMASK) bits:
|
|
||||||
*
|
|
||||||
* 00 traditional executable or object file
|
|
||||||
* 01 object file contains PIC code (set by `as -k')
|
|
||||||
* 10 dynamic executable
|
|
||||||
* 11 position independent executable image
|
|
||||||
* (eg. a shared library)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The a.out structure's a_midmag field is a network-byteorder encoding
|
|
||||||
* of this int
|
|
||||||
* FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
|
|
||||||
* Where `F' is 6 bits of flag like EX_DYNAMIC,
|
|
||||||
* `m' is 10 bits of machine-id like MID_I386, and
|
|
||||||
* `M' is 16 bits worth of magic number, ie. ZMAGIC.
|
|
||||||
* The macros below will set/get the needed fields.
|
|
||||||
*/
|
|
||||||
#define N_GETMAGIC(ex) (((ex).a_midmag)&0x0000ffff)
|
|
||||||
#define N_GETMID(ex) ((((ex).a_midmag)&0x03ff0000) >> 16)
|
|
||||||
#define N_GETFLAG(ex) ((((ex).a_midmag)&0xfc000000 ) << 26)
|
|
||||||
|
|
||||||
/* Valid magic number check. */
|
|
||||||
#define N_BADMAG(x) (N_GETMAGIC(x) != RMAGIC && \
|
|
||||||
N_GETMAGIC(x) != OMAGIC && \
|
|
||||||
N_GETMAGIC(x) != NMAGIC)
|
|
||||||
|
|
||||||
/* Text segment offset. */
|
|
||||||
#define N_TXTOFF(x) sizeof(struct exec)
|
|
||||||
|
|
||||||
/* Data segment offset. */
|
|
||||||
#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
|
|
||||||
|
|
||||||
/* Text relocation table offset. */
|
|
||||||
#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
|
|
||||||
|
|
||||||
/* Data relocation table offset. */
|
|
||||||
#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_reltext)
|
|
||||||
|
|
||||||
/* Symbol table offset. */
|
|
||||||
#define N_SYMOFF(x) (N_GETMAGIC(x) == RMAGIC ? \
|
|
||||||
N_DRELOFF(x) + (x).a_reldata : \
|
|
||||||
N_DATOFF(x) + (x).a_data)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,496 +0,0 @@
|
|||||||
/* $NetBSD: exec_elf.h,v 1.37.4.1 2000/07/26 23:57:06 mycroft Exp $ */
|
|
||||||
|
|
||||||
/*-
|
|
||||||
* Copyright (c) 1994 The NetBSD Foundation, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This code is derived from software contributed to The NetBSD Foundation
|
|
||||||
* by Christos Zoulas.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
|
||||||
* must display the following acknowledgement:
|
|
||||||
* This product includes software developed by the NetBSD
|
|
||||||
* Foundation, Inc. and its contributors.
|
|
||||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived
|
|
||||||
* from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
||||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
||||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _SYS_EXEC_ELF_H_
|
|
||||||
#define _SYS_EXEC_ELF_H_
|
|
||||||
|
|
||||||
#ifndef _SYS_TYPES_H_
|
|
||||||
#include <machine/types.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ELF Header
|
|
||||||
*/
|
|
||||||
#define ELF_NIDENT 16
|
|
||||||
|
|
||||||
struct elf_ehdr {
|
|
||||||
unsigned char e_ident[ELF_NIDENT]; /* Id bytes */
|
|
||||||
unsigned short e_type; /* file type */
|
|
||||||
unsigned short e_machine; /* machine type */
|
|
||||||
unsigned int e_version; /* version number */
|
|
||||||
unsigned int e_entry; /* entry point */
|
|
||||||
unsigned int e_phoff; /* Program header table offset */
|
|
||||||
unsigned int e_shoff; /* Section header table offset */
|
|
||||||
unsigned int e_flags; /* Processor flags (currently unused, should be 0) */
|
|
||||||
unsigned short e_ehsize; /* sizeof elf_ehdr */
|
|
||||||
unsigned short e_phentsize; /* Program header entry size */
|
|
||||||
unsigned short e_phnum; /* Number of program headers */
|
|
||||||
unsigned short e_shentsize; /* Section header entry size */
|
|
||||||
unsigned short e_shnum; /* Number of section headers */
|
|
||||||
unsigned short e_shstrndx; /* String table index */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* e_ident offsets */
|
|
||||||
#define EI_MAG0 0 /* first byte of magic number */
|
|
||||||
#define ELFMAG0 0x7f
|
|
||||||
#define EI_MAG1 1 /* second byte of magic number */
|
|
||||||
#define ELFMAG1 'E'
|
|
||||||
#define EI_MAG2 2 /* third byte of magic number */
|
|
||||||
#define ELFMAG2 'L'
|
|
||||||
#define EI_MAG3 3 /* fourth byte of magic number */
|
|
||||||
#define ELFMAG3 'F'
|
|
||||||
|
|
||||||
#define EI_CLASS 4 /* 5:th byte: File class */
|
|
||||||
#define ELFCLASSNONE 0 /* Invalid class */
|
|
||||||
#define ELFCLASS32 1 /* 32-bit objects */
|
|
||||||
#define ELFCLASS64 2 /* 64-bit objects */
|
|
||||||
#define ELFCLASSNUM 3
|
|
||||||
|
|
||||||
#define EI_DATA 5 /* 6:th byte: Data encoding */
|
|
||||||
#define ELFDATANONE 0 /* Unknown data format */
|
|
||||||
#define ELFDATA2LSB 1 /* two's complement, little-endian */
|
|
||||||
#define ELFDATA2MSB 2 /* two's complement, big-endian */
|
|
||||||
|
|
||||||
#define EI_VERSION 6 /* Version number of the ELF specification */
|
|
||||||
#define EV_NONE 0 /* Invalid version */
|
|
||||||
#define EV_CURRENT 1 /* Current version */
|
|
||||||
#define EV_NUM 2
|
|
||||||
|
|
||||||
#define EI_OSABI 7 /* Operating system/ABI identification */
|
|
||||||
#define ELFOSABI_SYSV 0 /* UNIX System V ABI */
|
|
||||||
#define ELFOSABI_HPUX 1 /* HP-UX operating system */
|
|
||||||
#define ELFOSABI_NETBSD /* NetBSD ABI */
|
|
||||||
#define ELFOSABI_LINUX /* Linux ABI */
|
|
||||||
#define ELFOSABI_SOLARIS /* Solaris ABI */
|
|
||||||
#define ELFOSABI_FREEBSD /* FreeBSD ABI */
|
|
||||||
#define ELFOSABI_ARM /* ARM architecture ABI */
|
|
||||||
#define ELFOSABI_STANDALONE 255 /* Stand-alone (embedded) application */
|
|
||||||
|
|
||||||
#define EI_ABIVERSION 8 /* ABI version */
|
|
||||||
|
|
||||||
#define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/
|
|
||||||
|
|
||||||
#define ELFMAG "\177ELF"
|
|
||||||
#define SELFMAG 4
|
|
||||||
|
|
||||||
/* e_type */
|
|
||||||
#define ET_NONE 0 /* Unknown file type */
|
|
||||||
#define ET_REL 1 /* A Relocatable file */
|
|
||||||
#define ET_EXEC 2 /* An Executable file */
|
|
||||||
#define ET_DYN 3 /* A Shared object file */
|
|
||||||
#define ET_CORE 4 /* A Core file */
|
|
||||||
#define ET_NUM 5
|
|
||||||
|
|
||||||
#define ET_LOOS 0xfe00 /* Operating system specific range */
|
|
||||||
#define ET_HIOS 0xfeff
|
|
||||||
#define ET_LOPROC 0xff00 /* Processor-specific range */
|
|
||||||
#define ET_HIPROC 0xffff
|
|
||||||
|
|
||||||
/* e_machine */
|
|
||||||
#define EM_NONE 0 /* No machine */
|
|
||||||
#define EM_M32 1 /* AT&T WE 32100 */
|
|
||||||
#define EM_SPARC 2 /* SPARC */
|
|
||||||
#define EM_386 3 /* Intel 80386 */
|
|
||||||
#define EM_68K 4 /* Motorola 68000 */
|
|
||||||
#define EM_88K 5 /* Motorola 88000 */
|
|
||||||
#define EM_486 6 /* Intel 80486 */
|
|
||||||
#define EM_860 7 /* Intel 80860 */
|
|
||||||
#define EM_MIPS 8 /* MIPS I Architecture */
|
|
||||||
#define EM_S370 9 /* Amdahl UTS on System/370 */
|
|
||||||
#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */
|
|
||||||
#define EM_RS6000 11 /* IBM RS/6000 XXX reserved */
|
|
||||||
#define EM_PARISC 15 /* Hewlett-Packard PA-RISC */
|
|
||||||
#define EM_NCUBE 16 /* NCube XXX reserved */
|
|
||||||
#define EM_VPP500 17 /* Fujitsu VPP500 */
|
|
||||||
#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
|
|
||||||
#define EM_960 19 /* Intel 80960 */
|
|
||||||
#define EM_PPC 20 /* PowerPC */
|
|
||||||
#define EM_V800 36 /* NEC V800 */
|
|
||||||
#define EM_FR20 37 /* Fujitsu FR20 */
|
|
||||||
#define EM_RH32 38 /* TRW RH-32 */
|
|
||||||
#define EM_RCE 39 /* Motorola RCE */
|
|
||||||
#define EM_ARM 40 /* Advanced RISC Machines ARM */
|
|
||||||
#define EM_ALPHA 41 /* DIGITAL Alpha */
|
|
||||||
#define EM_SH 42 /* Hitachi Super-H */
|
|
||||||
#define EM_SPARCV9 43 /* SPARC Version 9 */
|
|
||||||
#define EM_TRICORE 44 /* Siemens Tricore */
|
|
||||||
#define EM_ARC 45 /* Argonaut RISC Core */
|
|
||||||
#define EM_H8_300 46 /* Hitachi H8/300 */
|
|
||||||
#define EM_H8_300H 47 /* Hitachi H8/300H */
|
|
||||||
#define EM_H8S 48 /* Hitachi H8S */
|
|
||||||
#define EM_H8_500 49 /* Hitachi H8/500 */
|
|
||||||
#define EM_IA_64 50 /* Intel Merced Processor */
|
|
||||||
#define EM_MIPS_X 51 /* Stanford MIPS-X */
|
|
||||||
#define EM_COLDFIRE 52 /* Motorola Coldfire */
|
|
||||||
#define EM_68HC12 53 /* Motorola MC68HC12 */
|
|
||||||
#define EM_VAX 75 /* DIGITAL VAX */
|
|
||||||
#define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */
|
|
||||||
#define EM_NUM 36903
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ELF Program Header
|
|
||||||
*/
|
|
||||||
struct elf_phdr {
|
|
||||||
unsigned int p_type; /* entry type */
|
|
||||||
unsigned int p_offset; /* file offset */
|
|
||||||
unsigned int p_vaddr; /* virtual address */
|
|
||||||
unsigned int p_paddr; /* physical address (reserved, 0) */
|
|
||||||
unsigned int p_filesz; /* file size of segment (may be 0) */
|
|
||||||
unsigned int p_memsz; /* memory size of segment (may be 0) */
|
|
||||||
unsigned int p_flags; /* flags */
|
|
||||||
unsigned int p_align; /* memory & file alignment */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* p_type */
|
|
||||||
#define PT_NULL 0 /* Program header table entry unused */
|
|
||||||
#define PT_LOAD 1 /* Loadable program segment */
|
|
||||||
#define PT_DYNAMIC 2 /* Dynamic linking information */
|
|
||||||
#define PT_INTERP 3 /* Program interpreter */
|
|
||||||
#define PT_NOTE 4 /* Auxiliary information */
|
|
||||||
#define PT_SHLIB 5 /* Reserved, unspecified semantics */
|
|
||||||
#define PT_PHDR 6 /* Entry for header table itself */
|
|
||||||
#define PT_NUM 7
|
|
||||||
#define PT_LOPROC 0x70000000 /* Start of processor-specific semantics */
|
|
||||||
#define PT_HIPROC 0x7fffffff /* end of processor-specific semantics */
|
|
||||||
#define PT_GNU_STACK /* GNU stack extension */
|
|
||||||
|
|
||||||
/* p_flags */
|
|
||||||
#define PF_R 0x4 /* Segment is readable */
|
|
||||||
#define PF_W 0x2 /* Segment is writable */
|
|
||||||
#define PF_X 0x1 /* Segment is executable */
|
|
||||||
/* A text segment commonly have PF_X|PF_R, a data segment PF_X|PF_W and PF_R */
|
|
||||||
|
|
||||||
#define PF_MASKOS 0x0ff00000 /* Opersting system specific values */
|
|
||||||
#define PF_MASKPROC 0xf0000000 /* Processor-specific values */
|
|
||||||
|
|
||||||
|
|
||||||
#define PT_MIPS_REGINFO 0x70000000
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Section Headers
|
|
||||||
*/
|
|
||||||
struct elf_shdr {
|
|
||||||
unsigned int sh_name; /* section name (.shstrtab index) */
|
|
||||||
unsigned int sh_type; /* section type */
|
|
||||||
unsigned int sh_flags; /* section flags */
|
|
||||||
unsigned int sh_addr; /* virtual address */
|
|
||||||
unsigned int sh_offset; /* file offset */
|
|
||||||
unsigned int sh_size; /* section size */
|
|
||||||
unsigned int sh_link; /* link to another */
|
|
||||||
unsigned int sh_info; /* misc info */
|
|
||||||
unsigned int sh_addralign; /* memory alignment */
|
|
||||||
unsigned int sh_entsize; /* table entry size */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* sh_type */
|
|
||||||
#define SHT_NULL 0 /* inactive */
|
|
||||||
#define SHT_PROGBITS 1 /* program defined contents */
|
|
||||||
#define SHT_SYMTAB 2 /* holds symbol table */
|
|
||||||
#define SHT_STRTAB 3 /* holds string table */
|
|
||||||
#define SHT_RELA 4 /* holds relocation info with explicit addends */
|
|
||||||
#define SHT_HASH 5 /* holds symbol hash table */
|
|
||||||
#define SHT_DYNAMIC 6 /* holds dynamic linking information */
|
|
||||||
#define SHT_NOTE 7 /* holds information marking */
|
|
||||||
#define SHT_NOBITS 8 /* holds a section that does not occupy space */
|
|
||||||
#define SHT_REL 9 /* holds relocation info without explicit addends */
|
|
||||||
#define SHT_SHLIB 10 /* reserved with unspecified semantics */
|
|
||||||
#define SHT_DYNSYM 11 /* holds a minimal set of dynamic linking symbols */
|
|
||||||
#define SHT_NUM 12
|
|
||||||
|
|
||||||
#define SHT_LOOS 0x60000000 /* Operating system specific range */
|
|
||||||
#define SHT_HIOS 0x6fffffff
|
|
||||||
#define SHT_LOPROC 0x70000000 /* Processor-specific range */
|
|
||||||
#define SHT_HIPROC 0x7fffffff
|
|
||||||
#define SHT_LOUSER 0x80000000 /* Application-specific range */
|
|
||||||
#define SHT_HIUSER 0xffffffff
|
|
||||||
|
|
||||||
/* sh_flags */
|
|
||||||
#define SHF_WRITE 0x1 /* Section contains writable data */
|
|
||||||
#define SHF_ALLOC 0x2 /* Section occupies memory */
|
|
||||||
#define SHF_EXECINSTR 0x4 /* Section contains executable insns */
|
|
||||||
|
|
||||||
#define SHF_MASKOS 0x0f000000 /* Operating system specific values */
|
|
||||||
#define SHF_MASKPROC 0xf0000000 /* Processor-specific values */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Symbol Table
|
|
||||||
*/
|
|
||||||
struct elf_sym {
|
|
||||||
unsigned int st_name; /* Symbol name (.symtab index) */
|
|
||||||
unsigned int st_value; /* value of symbol */
|
|
||||||
unsigned int st_size; /* size of symbol */
|
|
||||||
unsigned char st_info; /* type / binding attrs */
|
|
||||||
unsigned char st_other; /* unused */
|
|
||||||
unsigned short st_shndx; /* section index of symbol */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Symbol Table index of the undefined symbol */
|
|
||||||
#define ELF_SYM_UNDEFINED 0
|
|
||||||
|
|
||||||
/* st_info: Symbol Bindings */
|
|
||||||
#define STB_LOCAL 0 /* local symbol */
|
|
||||||
#define STB_GLOBAL 1 /* global symbol */
|
|
||||||
#define STB_WEAK 2 /* weakly defined global symbol */
|
|
||||||
#define STB_NUM 3
|
|
||||||
|
|
||||||
#define STB_LOOS 10 /* Operating system specific range */
|
|
||||||
#define STB_HIOS 12
|
|
||||||
#define STB_LOPROC 13 /* Processor-specific range */
|
|
||||||
#define STB_HIPROC 15
|
|
||||||
|
|
||||||
/* st_info: Symbol Types */
|
|
||||||
#define STT_NOTYPE 0 /* Type not specified */
|
|
||||||
#define STT_OBJECT 1 /* Associated with a data object */
|
|
||||||
#define STT_FUNC 2 /* Associated with a function */
|
|
||||||
#define STT_SECTION 3 /* Associated with a section */
|
|
||||||
#define STT_FILE 4 /* Associated with a file name */
|
|
||||||
#define STT_NUM 5
|
|
||||||
|
|
||||||
#define STT_LOOS 10 /* Operating system specific range */
|
|
||||||
#define STT_HIOS 12
|
|
||||||
#define STT_LOPROC 13 /* Processor-specific range */
|
|
||||||
#define STT_HIPROC 15
|
|
||||||
|
|
||||||
/* st_info utility macros */
|
|
||||||
#define ELF_ST_BIND(info) ((unsigned int)(info) >> 4)
|
|
||||||
#define ELF_ST_TYPE(info) ((unsigned int)(info) & 0xf)
|
|
||||||
#define ELF_ST_INFO(bind,type) ((unsigned char)(((bind) << 4) | ((type) & 0xf)))
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Special section indexes
|
|
||||||
*/
|
|
||||||
#define SHN_UNDEF 0 /* Undefined section */
|
|
||||||
|
|
||||||
#define SHN_LORESERVE 0xff00 /* Start of Reserved range */
|
|
||||||
#define SHN_ABS 0xfff1 /* Absolute symbols */
|
|
||||||
#define SHN_COMMON 0xfff2 /* Common symbols */
|
|
||||||
#define SHN_HIRESERVE 0xffff
|
|
||||||
|
|
||||||
#define SHN_LOPROC 0xff00 /* Start of Processor-specific range */
|
|
||||||
#define SHN_HIPROC 0xff1f
|
|
||||||
#define SHN_LOOS 0xff20 /* Operating system specific range */
|
|
||||||
#define SHN_HIOS 0xff3f
|
|
||||||
|
|
||||||
#define SHN_MIPS_ACOMMON 0xff00
|
|
||||||
#define SHN_MIPS_TEXT 0xff01
|
|
||||||
#define SHN_MIPS_DATA 0xff02
|
|
||||||
#define SHN_MIPS_SCOMMON 0xff03
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Relocation Entries
|
|
||||||
*/
|
|
||||||
struct elf_rel {
|
|
||||||
unsigned int r_offset; /* where to do it */
|
|
||||||
unsigned int r_info; /* index & type of relocation */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct elf_rela {
|
|
||||||
unsigned int r_offset; /* where to do it */
|
|
||||||
unsigned int r_info; /* index & type of relocation */
|
|
||||||
int r_addend; /* adjustment value */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* r_info utility macros */
|
|
||||||
#define ELF_R_SYM(info) ((info) >> 8)
|
|
||||||
#define ELF_R_TYPE(info) ((info) & 0xff)
|
|
||||||
#define ELF_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Dynamic Section structure array
|
|
||||||
*/
|
|
||||||
struct elf_dyn {
|
|
||||||
unsigned int d_tag; /* entry tag value */
|
|
||||||
union {
|
|
||||||
unsigned int d_ptr;
|
|
||||||
unsigned int d_val;
|
|
||||||
} d_un;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* d_tag */
|
|
||||||
#define DT_NULL 0 /* Marks end of dynamic array */
|
|
||||||
#define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */
|
|
||||||
#define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */
|
|
||||||
#define DT_PLTGOT 3 /* Address of PLT and/or GOT */
|
|
||||||
#define DT_HASH 4 /* Address of symbol hash table */
|
|
||||||
#define DT_STRTAB 5 /* Address of string table */
|
|
||||||
#define DT_SYMTAB 6 /* Address of symbol table */
|
|
||||||
#define DT_RELA 7 /* Address of Rela relocation table */
|
|
||||||
#define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */
|
|
||||||
#define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */
|
|
||||||
#define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */
|
|
||||||
#define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */
|
|
||||||
#define DT_INIT 12 /* Address of initialization function */
|
|
||||||
#define DT_FINI 13 /* Address of termination function */
|
|
||||||
#define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */
|
|
||||||
#define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */
|
|
||||||
#define DT_SYMBOLIC 16 /* Start symbol search within local object */
|
|
||||||
#define DT_REL 17 /* Address of Rel relocation table */
|
|
||||||
#define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */
|
|
||||||
#define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */
|
|
||||||
#define DT_PLTREL 20 /* Type of PLT relocation entries */
|
|
||||||
#define DT_DEBUG 21 /* Used for debugging; unspecified */
|
|
||||||
#define DT_TEXTREL 22 /* Relocations might modify non-writable seg */
|
|
||||||
#define DT_JMPREL 23 /* Address of relocations associated with PLT */
|
|
||||||
#define DT_BIND_NOW 24 /* Process all relocations at load-time */
|
|
||||||
#define DT_INIT_ARRAY 25 /* Address of initialization function array */
|
|
||||||
#define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */
|
|
||||||
#define DT_INIT_ARRAYSZ 27 /* Address of termination function array */
|
|
||||||
#define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/
|
|
||||||
#define DT_NUM 29
|
|
||||||
|
|
||||||
#define DT_LOOS 0x60000000 /* Operating system specific range */
|
|
||||||
#define DT_HIOS 0x6fffffff
|
|
||||||
#define DT_LOPROC 0x70000000 /* Processor-specific range */
|
|
||||||
#define DT_HIPROC 0x7fffffff
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Auxiliary Vectors
|
|
||||||
*/
|
|
||||||
struct elf_auxinfo {
|
|
||||||
unsigned int a_type; /* 32-bit id */
|
|
||||||
unsigned int a_v; /* 32-bit id */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* a_type */
|
|
||||||
#define AT_NULL 0 /* Marks end of array */
|
|
||||||
#define AT_IGNORE 1 /* No meaning, a_un is undefined */
|
|
||||||
#define AT_EXECFD 2 /* Open file descriptor of object file */
|
|
||||||
#define AT_PHDR 3 /* &phdr[0] */
|
|
||||||
#define AT_PHENT 4 /* sizeof(phdr[0]) */
|
|
||||||
#define AT_PHNUM 5 /* # phdr entries */
|
|
||||||
#define AT_PAGESZ 6 /* PAGESIZE */
|
|
||||||
#define AT_BASE 7 /* Interpreter base addr */
|
|
||||||
#define AT_FLAGS 8 /* Processor flags */
|
|
||||||
#define AT_ENTRY 9 /* Entry address of executable */
|
|
||||||
#define AT_DCACHEBSIZE 10 /* Data cache block size */
|
|
||||||
#define AT_ICACHEBSIZE 11 /* Instruction cache block size */
|
|
||||||
#define AT_UCACHEBSIZE 12 /* Unified cache block size */
|
|
||||||
|
|
||||||
/* Vendor specific */
|
|
||||||
#define AT_MIPS_NOTELF 10 /* XXX a_val != 0 -> MIPS XCOFF executable */
|
|
||||||
|
|
||||||
#define AT_SUN_UID 2000 /* euid */
|
|
||||||
#define AT_SUN_RUID 2001 /* ruid */
|
|
||||||
#define AT_SUN_GID 2002 /* egid */
|
|
||||||
#define AT_SUN_RGID 2003 /* rgid */
|
|
||||||
|
|
||||||
/* Solaris kernel specific */
|
|
||||||
#define AT_SUN_LDELF 2004 /* dynamic linker's ELF header */
|
|
||||||
#define AT_SUN_LDSHDR 2005 /* dynamic linker's section header */
|
|
||||||
#define AT_SUN_LDNAME 2006 /* dynamic linker's name */
|
|
||||||
#define AT_SUN_LPGSIZE 2007 /* large pagesize */
|
|
||||||
|
|
||||||
/* Other information */
|
|
||||||
#define AT_SUN_PLATFORM 2008 /* sysinfo(SI_PLATFORM) */
|
|
||||||
#define AT_SUN_HWCAP 2009 /* process hardware capabilities */
|
|
||||||
#define AT_SUN_IFLUSH 2010 /* do we need to flush the instruction cache? */
|
|
||||||
#define AT_SUN_CPU 2011 /* cpu name */
|
|
||||||
/* ibcs2 emulation band aid */
|
|
||||||
#define AT_SUN_EMUL_ENTRY 2012 /* coff entry point */
|
|
||||||
#define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */
|
|
||||||
/* Executable's fully resolved name */
|
|
||||||
#define AT_SUN_EXECNAME 2014
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Note Headers
|
|
||||||
*/
|
|
||||||
struct elf_nhdr {
|
|
||||||
|
|
||||||
unsigned int n_namesz;
|
|
||||||
unsigned int n_descsz;
|
|
||||||
unsigned int n_type;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define ELF_NOTE_TYPE_OSVERSION 1
|
|
||||||
|
|
||||||
/* NetBSD-specific note type: Emulation name. desc is emul name string. */
|
|
||||||
#define ELF_NOTE_NETBSD_TYPE_EMULNAME 2
|
|
||||||
|
|
||||||
/* NetBSD-specific note name and description sizes */
|
|
||||||
#define ELF_NOTE_NETBSD_NAMESZ 7
|
|
||||||
#define ELF_NOTE_NETBSD_DESCSZ 4
|
|
||||||
/* NetBSD-specific note name */
|
|
||||||
#define ELF_NOTE_NETBSD_NAME "NetBSD\0\0"
|
|
||||||
|
|
||||||
/* GNU-specific note name and description sizes */
|
|
||||||
#define ELF_NOTE_GNU_NAMESZ 4
|
|
||||||
#define ELF_NOTE_GNU_DESCSZ 4
|
|
||||||
/* GNU-specific note name */
|
|
||||||
#define ELF_NOTE_GNU_NAME "GNU\0"
|
|
||||||
|
|
||||||
/* GNU-specific OS/version value stuff */
|
|
||||||
#define ELF_NOTE_GNU_OSMASK (unsigned int)0xff000000
|
|
||||||
#define ELF_NOTE_GNU_OSLINUX (unsigned int)0x01000000
|
|
||||||
#define ELF_NOTE_GNU_OSMACH (unsigned int)0x00000000
|
|
||||||
|
|
||||||
//#define CONCAT(x,y) __CONCAT(x,y)
|
|
||||||
|
|
||||||
|
|
||||||
#include <machine/elf_machdep.h>
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _KERNEL
|
|
||||||
|
|
||||||
#define ELF_AUX_ENTRIES 8 /* Size of aux array passed to loader */
|
|
||||||
|
|
||||||
struct elf_args {
|
|
||||||
unsigned int arg_entry; /* program entry point */
|
|
||||||
unsigned int arg_interp; /* Interpreter load address */
|
|
||||||
unsigned int arg_phaddr; /* program header address */
|
|
||||||
unsigned int arg_phentsize; /* Size of program header */
|
|
||||||
unsigned int arg_phnum; /* Number of program headers */
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifndef _LKM
|
|
||||||
#include "opt_execfmt.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef EXEC_ELF
|
|
||||||
int exec_elf_makecmds __P((struct proc *, struct exec_package *));
|
|
||||||
int elf_read_from __P((struct proc *, struct vnode *, u_long,
|
|
||||||
caddr_t, int));
|
|
||||||
void *elf_copyargs __P((struct exec_package *, struct ps_strings *,
|
|
||||||
void *, void *));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* common */
|
|
||||||
int exec_elf_setup_stack __P((struct proc *, struct exec_package *));
|
|
||||||
|
|
||||||
#endif /* _KERNEL */
|
|
||||||
|
|
||||||
#endif /* !_SYS_EXEC_ELF_H_ */
|
|
||||||
@@ -97,7 +97,7 @@ struct proc *pidhash [PIDHSZ];
|
|||||||
extern struct proc proc[]; /* the proc table itself */
|
extern struct proc proc[]; /* the proc table itself */
|
||||||
struct proc *freeproc, *zombproc, *allproc, *qs;
|
struct proc *freeproc, *zombproc, *allproc, *qs;
|
||||||
/* lists of procs in various states */
|
/* lists of procs in various states */
|
||||||
extern int nproc;
|
int nproc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Init the process queues.
|
* Init the process queues.
|
||||||
@@ -272,8 +272,6 @@ void fatalsig (int signum);
|
|||||||
*/
|
*/
|
||||||
int procxmt (void);
|
int procxmt (void);
|
||||||
|
|
||||||
void execsigs(register struct proc *p);
|
|
||||||
|
|
||||||
#endif /* KERMEL */
|
#endif /* KERMEL */
|
||||||
|
|
||||||
/* stat codes */
|
/* stat codes */
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
#include "param.h"
|
|
||||||
#include "systm.h"
|
|
||||||
#include "map.h"
|
|
||||||
#include "inode.h"
|
|
||||||
#include "user.h"
|
|
||||||
#include "proc.h"
|
|
||||||
#include "buf.h"
|
|
||||||
#include "namei.h"
|
|
||||||
#include "fs.h"
|
|
||||||
#include "mount.h"
|
|
||||||
#include "file.h"
|
|
||||||
#include "resource.h"
|
|
||||||
#include "exec.h"
|
|
||||||
#include "exec_aout.h"
|
|
||||||
#include "dir.h"
|
|
||||||
#include "uio.h"
|
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
int exec_aout_check(struct exec_params *epp)
|
|
||||||
{
|
|
||||||
int error;
|
|
||||||
|
|
||||||
if (epp->hdr_len < sizeof(struct exec))
|
|
||||||
return ENOEXEC;
|
|
||||||
if (!(N_GETMID(epp->hdr.aout) == MID_ZERO &&
|
|
||||||
N_GETFLAG(epp->hdr.aout) == 0))
|
|
||||||
return ENOEXEC;
|
|
||||||
|
|
||||||
switch (N_GETMAGIC(epp->hdr.aout)) {
|
|
||||||
case OMAGIC:
|
|
||||||
epp->hdr.aout.a_data += epp->hdr.aout.a_text;
|
|
||||||
epp->hdr.aout.a_text = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("Bad a.out magic = %0o\n", N_GETMAGIC(epp->hdr.aout));
|
|
||||||
return ENOEXEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Save arglist
|
|
||||||
*/
|
|
||||||
exec_save_args(epp);
|
|
||||||
|
|
||||||
DEBUG("Exec file header:\n");
|
|
||||||
DEBUG("a_midmag = %#x\n", epp->hdr.aout.a_midmag); /* magic number */
|
|
||||||
DEBUG("a_text = %d\n", epp->hdr.aout.a_text); /* size of text segment */
|
|
||||||
DEBUG("a_data = %d\n", epp->hdr.aout.a_data); /* size of initialized data */
|
|
||||||
DEBUG("a_bss = %d\n", epp->hdr.aout.a_bss); /* size of uninitialized data */
|
|
||||||
DEBUG("a_reltext = %d\n", epp->hdr.aout.a_reltext); /* size of text relocation info */
|
|
||||||
DEBUG("a_reldata = %d\n", epp->hdr.aout.a_reldata); /* size of data relocation info */
|
|
||||||
DEBUG("a_syms = %d\n", epp->hdr.aout.a_syms); /* size of symbol table */
|
|
||||||
DEBUG("a_entry = %#x\n", epp->hdr.aout.a_entry); /* entry point */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set up memory allocation
|
|
||||||
*/
|
|
||||||
epp->text.vaddr = epp->heap.vaddr = NO_ADDR;
|
|
||||||
epp->text.len = epp->heap.len = 0;
|
|
||||||
|
|
||||||
epp->data.vaddr = (caddr_t)USER_DATA_START;
|
|
||||||
epp->data.len = epp->hdr.aout.a_data;
|
|
||||||
epp->bss.vaddr = epp->data.vaddr + epp->data.len;
|
|
||||||
epp->bss.len = epp->hdr.aout.a_bss;
|
|
||||||
epp->heap.vaddr = epp->bss.vaddr + epp->bss.len;
|
|
||||||
epp->heap.len = 0;
|
|
||||||
epp->stack.len = SSIZE + roundup(epp->argbc + epp->envbc, NBPW) + (epp->argc + epp->envc+4)*NBPW;
|
|
||||||
epp->stack.vaddr = (caddr_t)USER_DATA_END - epp->stack.len;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate core at this point, committed to the new image.
|
|
||||||
* TODO: What to do for errors?
|
|
||||||
*/
|
|
||||||
exec_estab(epp);
|
|
||||||
|
|
||||||
/* read in text and data */
|
|
||||||
DEBUG("reading a.out image\n");
|
|
||||||
error = rdwri (UIO_READ, epp->ip,
|
|
||||||
(caddr_t)epp->data.vaddr, epp->hdr.aout.a_data,
|
|
||||||
sizeof(struct exec) + epp->hdr.aout.a_text, IO_UNIT, 0);
|
|
||||||
if (error)
|
|
||||||
DEBUG("read image returned error=%d\n", error);
|
|
||||||
if (error) {
|
|
||||||
/*
|
|
||||||
* Error - all is lost, when the old image is possible corrupt
|
|
||||||
* and we could not load a new.
|
|
||||||
*/
|
|
||||||
psignal (u.u_procp, SIGSEGV);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
exec_clear(epp);
|
|
||||||
exec_setupstack(epp->hdr.aout.a_entry, epp);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
/* $NetBSD: exec_conf.c,v 1.43 2000/06/09 22:38:57 oki Exp $ */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 1993, 1994 Christopher G. Demetriou
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
|
||||||
* must display the following acknowledgement:
|
|
||||||
* This product includes software developed by Christopher G. Demetriou.
|
|
||||||
* 4. The name of the author may not be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "param.h"
|
|
||||||
#include "inode.h"
|
|
||||||
#include "exec.h"
|
|
||||||
|
|
||||||
#ifdef EXEC_SCRIPT
|
|
||||||
int exec_script_check(struct exec_params *epp);
|
|
||||||
#endif
|
|
||||||
#ifdef EXEC_AOUT
|
|
||||||
int exec_aout_check(struct exec_params *epp);
|
|
||||||
#endif
|
|
||||||
#ifdef EXEC_ELF
|
|
||||||
int exec_elf_check(struct exec_params *epp);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const struct execsw execsw[] = {
|
|
||||||
#ifdef EXEC_AOUT
|
|
||||||
{ exec_aout_check, "a.out" }, /* a.out binaries */
|
|
||||||
#endif
|
|
||||||
#ifdef EXEC_ELF
|
|
||||||
{ exec_elf_check, "elf" }, /* 32bit ELF bins */
|
|
||||||
#endif
|
|
||||||
#ifdef EXEC_SCRIPT
|
|
||||||
{ exec_script_check, "script" }, /* shell scripts */
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
int nexecs = (sizeof(execsw) / sizeof(*execsw));
|
|
||||||
int exec_maxhdrsz;
|
|
||||||
@@ -1,207 +0,0 @@
|
|||||||
/* $NetBSD: exec_elf32.c,v 1.49.2.2 2000/11/03 20:00:38 tv Exp $ */
|
|
||||||
|
|
||||||
/*-
|
|
||||||
* Copyright (c) 1994 The NetBSD Foundation, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This code is derived from software contributed to The NetBSD Foundation
|
|
||||||
* by Christos Zoulas.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
|
||||||
* must display the following acknowledgement:
|
|
||||||
* This product includes software developed by the NetBSD
|
|
||||||
* Foundation, Inc. and its contributors.
|
|
||||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived
|
|
||||||
* from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
||||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
||||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 1996 Christopher G. Demetriou
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. The name of the author may not be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
||||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "param.h"
|
|
||||||
#include "systm.h"
|
|
||||||
#include "kernel.h"
|
|
||||||
#include "map.h"
|
|
||||||
#include "user.h"
|
|
||||||
#include "proc.h"
|
|
||||||
//#include "malloc.h"
|
|
||||||
#include "inode.h"
|
|
||||||
#include "namei.h"
|
|
||||||
//#include "vnode.h"
|
|
||||||
#include "exec.h"
|
|
||||||
#include "exec_elf.h"
|
|
||||||
#include "fcntl.h"
|
|
||||||
//#include "syscall.h"
|
|
||||||
#include "signalvar.h"
|
|
||||||
#include "mount.h"
|
|
||||||
#include "stat.h"
|
|
||||||
|
|
||||||
|
|
||||||
extern char sigcode[], esigcode[];
|
|
||||||
|
|
||||||
/* round up and down to page boundaries. */
|
|
||||||
#define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1))
|
|
||||||
#define ELF_TRUNC(a, b) ((a) & ~((b) - 1))
|
|
||||||
|
|
||||||
/*
|
|
||||||
* elf_check(): Prepare an Elf binary's exec package
|
|
||||||
*
|
|
||||||
* First, set of the various offsets/lengths in the exec package.
|
|
||||||
*
|
|
||||||
* Then, mark the text image busy (so it can be demand paged) or error
|
|
||||||
* out if this is not possible. Finally, set up vmcmds for the
|
|
||||||
* text, data, bss, and stack segments.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
exec_elf_check(struct exec_params *epp)
|
|
||||||
{
|
|
||||||
struct elf_phdr *ph;
|
|
||||||
int error, i, phsize;
|
|
||||||
|
|
||||||
const char elfident[] = {ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3,
|
|
||||||
ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ELFOSABI_SYSV, 0};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check that this is an ELF file that we can handle,
|
|
||||||
* and do some sanity checks on the header
|
|
||||||
*/
|
|
||||||
if (epp->hdr_len < sizeof(struct elf_ehdr))
|
|
||||||
return ENOEXEC;
|
|
||||||
for (i = 0; i < sizeof elfident; i++)
|
|
||||||
if (epp->hdr.elf.e_ident[i] != elfident[i])
|
|
||||||
return ENOEXEC;
|
|
||||||
if (epp->hdr.elf.e_type != ET_EXEC)
|
|
||||||
return ENOEXEC;
|
|
||||||
if (epp->hdr.elf.e_machine != EM_MIPS || epp->hdr.elf.e_version != EV_CURRENT)
|
|
||||||
return ENOEXEC;
|
|
||||||
if (epp->hdr.elf.e_phentsize != sizeof(struct elf_phdr) || epp->hdr.elf.e_phoff == 0 || epp->hdr.elf.e_phnum == 0)
|
|
||||||
return ENOEXEC;
|
|
||||||
if (epp->hdr.elf.e_shnum == 0 || epp->hdr.elf.e_shentsize != sizeof(struct elf_shdr))
|
|
||||||
return ENOEXEC;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read program headers
|
|
||||||
*/
|
|
||||||
phsize = epp->hdr.elf.e_phnum * sizeof(struct elf_phdr);
|
|
||||||
ph = exec_alloc(phsize, NBPW, epp);
|
|
||||||
if (ph == NULL) {
|
|
||||||
printf("can't alloc ph[] sz=%d\n", phsize);
|
|
||||||
return ENOEXEC;
|
|
||||||
}
|
|
||||||
if ((error = rdwri(UIO_READ, epp->ip, (caddr_t)ph, phsize, epp->hdr.elf.e_phoff, IO_UNIT, 0)) != 0)
|
|
||||||
return ENOEXEC;
|
|
||||||
|
|
||||||
epp->text.len = epp->data.len = epp->bss.len = epp->stack.len = epp->heap.len = 0;
|
|
||||||
epp->text.vaddr = epp->data.vaddr = epp->bss.vaddr = epp->stack.vaddr = epp->heap.vaddr = NO_ADDR;
|
|
||||||
|
|
||||||
if (epp->hdr.elf.e_phnum == 1 && ph[0].p_type == PT_LOAD && ph[0].p_flags == (PF_R|PF_W|PF_X)) {
|
|
||||||
/*
|
|
||||||
* In the simple a.out type link, in elf format, there is only
|
|
||||||
* one loadable segment that is RWE containing everything
|
|
||||||
* Here we fix the memory allocation, and we are done.
|
|
||||||
*/
|
|
||||||
epp->data.vaddr = (caddr_t)ph[0].p_vaddr;
|
|
||||||
epp->data.len = ph[0].p_memsz;
|
|
||||||
epp->heap.vaddr = (caddr_t)ph[0].p_vaddr + ph[0].p_memsz;
|
|
||||||
epp->heap.len = 0;
|
|
||||||
epp->stack.len = SSIZE + epp->argbc + epp->envbc + (epp->argc+epp->envc+4)*NBPW;
|
|
||||||
epp->stack.vaddr = (caddr_t)USER_DATA_END - epp->stack.len;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We assume .bss is the different between the memory data
|
|
||||||
* section size and the file size.
|
|
||||||
*/
|
|
||||||
epp->bss.vaddr = epp->data.vaddr + ph[0].p_filesz;
|
|
||||||
epp->bss.len = ph[0].p_memsz - ph[0].p_filesz;
|
|
||||||
epp->data.len = epp->bss.vaddr - epp->data.vaddr;
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* At the current moment we don't handle anything else
|
|
||||||
* The rest of the code is implemented as need arise.
|
|
||||||
*/
|
|
||||||
return ENOEXEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Save arglist
|
|
||||||
*/
|
|
||||||
exec_save_args(epp);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Establish memory
|
|
||||||
*/
|
|
||||||
if ((error = exec_estab(epp)) != 0)
|
|
||||||
return error;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now load the program sections into memory
|
|
||||||
*/
|
|
||||||
for (i = 0; i < epp->hdr.elf.e_phnum; i++) {
|
|
||||||
if (ph[i].p_type != PT_LOAD)
|
|
||||||
continue;
|
|
||||||
/*
|
|
||||||
* Sanity check that the load is to our intended address space.
|
|
||||||
*/
|
|
||||||
if (!((epp->text.vaddr != NO_ADDR
|
|
||||||
&& ((caddr_t)ph[i].p_vaddr >= epp->text.vaddr
|
|
||||||
&& (caddr_t)ph[i].p_vaddr + ph[i].p_filesz <= epp->text.vaddr + epp->text.len))
|
|
||||||
|| (epp->data.vaddr != NO_ADDR
|
|
||||||
&& (caddr_t)ph[i].p_vaddr >= epp->data.vaddr
|
|
||||||
&& (caddr_t)ph[i].p_vaddr + ph[i].p_filesz <= epp->data.vaddr + epp->data.len))
|
|
||||||
|| ph[i].p_filesz >= ph[i].p_memsz || ph[i].p_filesz <= 0)
|
|
||||||
return ENOEXEC;
|
|
||||||
|
|
||||||
error = rdwri(UIO_READ, epp->ip, (caddr_t)ph[i].p_vaddr, ph[i].p_filesz, ph[i].p_offset, IO_UNIT, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
exec_clear(epp);
|
|
||||||
exec_setupstack(epp->hdr.elf.e_entry, epp);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
#include "param.h"
|
|
||||||
#include "inode.h"
|
|
||||||
#include "dir.h"
|
|
||||||
#include "namei.h"
|
|
||||||
#include "exec.h"
|
|
||||||
#include "user.h"
|
|
||||||
#include "systm.h"
|
|
||||||
|
|
||||||
int
|
|
||||||
exec_script_check(struct exec_params *epp)
|
|
||||||
{
|
|
||||||
char *cp;
|
|
||||||
struct nameidata nd;
|
|
||||||
struct nameidata *ndp;
|
|
||||||
int error;
|
|
||||||
struct inode *ip = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We come here with the first line of the executable
|
|
||||||
* script file.
|
|
||||||
* Check is to see if it starts with the magic marker: #!
|
|
||||||
*/
|
|
||||||
if (epp->hdr.sh[0] != '#' || epp->hdr.sh[1] != '!' || epp->sh.interpreted)
|
|
||||||
return ENOEXEC;
|
|
||||||
epp->sh.interpreted = 1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If setuid/gid scripts were to be disallowed this is where it would
|
|
||||||
* have to be done.
|
|
||||||
* u.u_uid = uid;
|
|
||||||
* u.u_gid = u_groups[0];
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The first line of the text file
|
|
||||||
* should be one line on the format:
|
|
||||||
* #! <interpreter-name> <interpreter-argument>\n
|
|
||||||
*/
|
|
||||||
cp = &epp->hdr.sh[2];
|
|
||||||
while (cp < &epp->hdr.sh[MIN(epp->hdr_len, SHSIZE)]) {
|
|
||||||
if (*cp == '\t')
|
|
||||||
*cp = ' ';
|
|
||||||
else if (*cp == '\n') {
|
|
||||||
*cp = '\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
cp++;
|
|
||||||
}
|
|
||||||
if (cp == &epp->hdr.sh[MIN(epp->hdr_len, SHSIZE)])
|
|
||||||
return ENOEXEC;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Pick up script interpreter file name
|
|
||||||
*/
|
|
||||||
cp = &epp->hdr.sh[2];
|
|
||||||
while (*cp == ' ')
|
|
||||||
cp++;
|
|
||||||
if (!*cp)
|
|
||||||
return ENOEXEC;
|
|
||||||
bzero(&nd, sizeof nd);
|
|
||||||
ndp = &nd;
|
|
||||||
ndp->ni_dirp = cp;
|
|
||||||
while (*cp && *cp != ' ')
|
|
||||||
cp++;
|
|
||||||
if (*cp != '\0') {
|
|
||||||
*cp++ = 0;
|
|
||||||
while (*cp && *cp == ' ')
|
|
||||||
cp++;
|
|
||||||
if (*cp) {
|
|
||||||
if ((error = copystr(cp, epp->sh.interparg, sizeof epp->sh.interparg, NULL)))
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* the interpreter is the new file to exec
|
|
||||||
*/
|
|
||||||
ndp->ni_nameiop = LOOKUP | FOLLOW;
|
|
||||||
ip = namei (ndp);
|
|
||||||
if (ip == NULL)
|
|
||||||
return u.u_error;
|
|
||||||
if ((error = copystr(ndp->ni_dent.d_name, epp->sh.interpname, sizeof epp->sh.interpname, NULL)))
|
|
||||||
goto done;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Everything set up, do the recursive exec()
|
|
||||||
*/
|
|
||||||
if (epp->ip)
|
|
||||||
iput(epp->ip);
|
|
||||||
epp->ip = ip;
|
|
||||||
error = exec_check(epp);
|
|
||||||
done:
|
|
||||||
if (ip)
|
|
||||||
iput(ip);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
@@ -1,425 +0,0 @@
|
|||||||
#include "param.h"
|
|
||||||
#include "systm.h"
|
|
||||||
#include "map.h"
|
|
||||||
#include "inode.h"
|
|
||||||
#include "user.h"
|
|
||||||
#include "proc.h"
|
|
||||||
#include "buf.h"
|
|
||||||
#include "namei.h"
|
|
||||||
#include "fs.h"
|
|
||||||
#include "mount.h"
|
|
||||||
#include "file.h"
|
|
||||||
#include "resource.h"
|
|
||||||
#include "exec.h"
|
|
||||||
#include "dir.h"
|
|
||||||
#include "uio.h"
|
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* How memory is set up.
|
|
||||||
*
|
|
||||||
* var a:
|
|
||||||
* USER_DATA_END: !----------!
|
|
||||||
* ! +P_ssize ! stack
|
|
||||||
* p_saddr -> ¡----------!
|
|
||||||
*
|
|
||||||
* !----------!
|
|
||||||
* ! +P_dsize ! .data + .bss + heap
|
|
||||||
* P_daddr -> !----------!
|
|
||||||
*
|
|
||||||
* var b:
|
|
||||||
*
|
|
||||||
* USER_DATA_END: !--------!
|
|
||||||
* ! +ssize ! stack
|
|
||||||
* saddr -> ¡--------!
|
|
||||||
* ! +hsize ! heap
|
|
||||||
* haddr -> !--------!
|
|
||||||
* ! +dsize ! .data + .bss
|
|
||||||
* daddr -> !--------!
|
|
||||||
* ! +tsize ! .text
|
|
||||||
* taddr -> !--------!
|
|
||||||
* paddr -> +psize
|
|
||||||
*
|
|
||||||
* var c:
|
|
||||||
* !--------!
|
|
||||||
* ! +tsize ! .text (read only section)
|
|
||||||
* taddr -> !--------!
|
|
||||||
* ! +ssize ! stack
|
|
||||||
* saddr -> ¡--------!
|
|
||||||
* ! +hsize ! heap
|
|
||||||
* haddr -> !--------!
|
|
||||||
* ! +dsize ! .data + .bss
|
|
||||||
* daddr -> !--------!
|
|
||||||
* paddr -> +psize
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set up user memory.
|
|
||||||
*
|
|
||||||
* The following is a key to top of the stack and the variables used.
|
|
||||||
*
|
|
||||||
* topp-> [argv] top word for /bin/ps
|
|
||||||
* <0>
|
|
||||||
* n
|
|
||||||
* g
|
|
||||||
* r
|
|
||||||
* a
|
|
||||||
* ...
|
|
||||||
* <0>
|
|
||||||
* 0
|
|
||||||
* g
|
|
||||||
* r
|
|
||||||
* ucp -> a
|
|
||||||
* [0]
|
|
||||||
* [envn]
|
|
||||||
* ...
|
|
||||||
* envp -> [env0]
|
|
||||||
* [0]
|
|
||||||
* [argn] ptr to argn
|
|
||||||
* ...
|
|
||||||
* argp -> [arg0] ptr to arg0
|
|
||||||
* []
|
|
||||||
* []
|
|
||||||
* []
|
|
||||||
* sp -> []
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void exec_setupstack(unsigned entryaddr, struct exec_params *epp)
|
|
||||||
{
|
|
||||||
int nc,i;
|
|
||||||
u_int len;
|
|
||||||
char *ucp;
|
|
||||||
char **argp, **envp, ***topp;
|
|
||||||
|
|
||||||
DEBUG("exec_setupstack:\n");
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set up top of stack structure as above
|
|
||||||
* This depends on that kernel and user spaces
|
|
||||||
* map to the same addresses.
|
|
||||||
*/
|
|
||||||
topp = (char ***)(epp->stack.vaddr + epp->stack.len - NBPW); /* Last word of RAM */
|
|
||||||
ucp = (char *)((unsigned)topp - roundup(epp->envbc + epp->argbc,NBPW)); /* arg string space */
|
|
||||||
envp = (char **)(ucp - (epp->envc+1)*NBPW); /* Make place for envp[...], +1 for the 0 */
|
|
||||||
argp = envp - (epp->argc+1)*NBPW; /* Make place for argv[...] */
|
|
||||||
u.u_frame [FRAME_SP] = (int)(argp-16);
|
|
||||||
u.u_frame [FRAME_R4] = epp->argc; /* $a0 := argc */
|
|
||||||
u.u_frame [FRAME_R5] = (int)argp; /* $a1 := argp */
|
|
||||||
u.u_frame [FRAME_R6] = (int)envp; /* $a2 := env */
|
|
||||||
*topp = argp; /* for /bin/ps */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* copy the arguments into the structure
|
|
||||||
*/
|
|
||||||
nc = 0;
|
|
||||||
for (i = 0; i < epp->argc; i++) {
|
|
||||||
argp[i] = (caddr_t)ucp;
|
|
||||||
if (copystr((caddr_t)epp->argp[i], (caddr_t)ucp, (caddr_t)topp-ucp, &len) == 0) {
|
|
||||||
nc += len;
|
|
||||||
ucp += len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
argp[epp->argc] = NULL;
|
|
||||||
|
|
||||||
for (i = 0; i < epp->envc; i++) {
|
|
||||||
envp[i] = ucp;
|
|
||||||
if (copystr((caddr_t)epp->envp[i], (caddr_t)ucp, (caddr_t)topp-ucp, &len) == 0) {
|
|
||||||
nc += len;
|
|
||||||
ucp += len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
envp[epp->envc] = NULL;
|
|
||||||
|
|
||||||
ucp = (caddr_t)roundup((unsigned)ucp, NBPW);
|
|
||||||
if ((caddr_t)ucp != (caddr_t)topp) {
|
|
||||||
DEBUG("Copying of arg list went wrong, ucp=%#x, topp=%#x\n", ucp, topp);
|
|
||||||
panic("exec check");
|
|
||||||
}
|
|
||||||
|
|
||||||
u.u_frame [FRAME_PC] = entryaddr;
|
|
||||||
DEBUG("Setting up new PC=%#x\n", entryaddr);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Remember file name for accounting.
|
|
||||||
*/
|
|
||||||
(void) copystr(argp[0], u.u_comm, MAXCOMLEN, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* A simple memory allocator used within exec code using file buffers as storage.
|
|
||||||
* Will return NULL if allocation is not possible.
|
|
||||||
* Total max memory allocatable is MAXALLOCBUF*MAXBSIZE
|
|
||||||
* Max size of allocatable chunk is MAXBSIZE
|
|
||||||
*
|
|
||||||
* All memory allocated with this function will be freed by a call
|
|
||||||
* to exec_alloc_freeall()
|
|
||||||
*/
|
|
||||||
void *exec_alloc(int size, int ru, struct exec_params *epp)
|
|
||||||
{
|
|
||||||
char *cp;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < MAXALLOCBUF; i++)
|
|
||||||
if (MAXBSIZE - (ru<=1?epp->alloc[i].fill:roundup(epp->alloc[i].fill,ru)) >= size)
|
|
||||||
break;
|
|
||||||
if (i == MAXALLOCBUF)
|
|
||||||
return NULL;
|
|
||||||
if (epp->alloc[i].bp == NULL) {
|
|
||||||
if ((epp->alloc[i].bp = geteblk()) == NULL) {
|
|
||||||
DEBUG("exec_alloc: no buf\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ru > 1)
|
|
||||||
epp->alloc[i].fill = roundup(epp->alloc[i].fill, ru);
|
|
||||||
cp = epp->alloc[i].bp->b_addr + epp->alloc[i].fill;
|
|
||||||
epp->alloc[i].fill += size;
|
|
||||||
bzero (cp, size);
|
|
||||||
return cp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* this will deallocate all memory allocated by exec_alloc
|
|
||||||
*/
|
|
||||||
void exec_alloc_freeall(struct exec_params *epp)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < MAXALLOCBUF; i++) {
|
|
||||||
if (epp->alloc[i].bp) {
|
|
||||||
brelse(epp->alloc[i].bp);
|
|
||||||
epp->alloc[i].bp = NULL;
|
|
||||||
epp->alloc[i].fill = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Establish memory for the image based on the
|
|
||||||
* values picked up from the executable file and stored
|
|
||||||
* in the exec params block.
|
|
||||||
*/
|
|
||||||
int exec_estab(struct exec_params *epp)
|
|
||||||
{
|
|
||||||
DEBUG("text = %#x..%#x, len=%d\n", epp->text.vaddr, epp->text.vaddr+epp->text.len, epp->text.len);
|
|
||||||
DEBUG("data = %#x..%#x, len=%d\n", epp->data.vaddr, epp->data.vaddr+epp->data.len, epp->data.len);
|
|
||||||
DEBUG("bss = %#x..%#x, len=%d\n", epp->bss.vaddr, epp->bss.vaddr+epp->bss.len, epp->bss.len);
|
|
||||||
DEBUG("heap = %#x..%#x, len=%d\n", epp->heap.vaddr, epp->heap.vaddr+epp->heap.len, epp->heap.len);
|
|
||||||
DEBUG("stack = %#x..%#x, len=%d\n", epp->stack.vaddr, epp->stack.vaddr+epp->stack.len, epp->stack.len);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Right now we can only handle the simple original a.out
|
|
||||||
* case, so we double check for that case here.
|
|
||||||
*/
|
|
||||||
if (epp->text.vaddr != NO_ADDR || epp->data.vaddr == NO_ADDR
|
|
||||||
|| epp->data.vaddr != (caddr_t)USER_DATA_START || epp->stack.vaddr != (caddr_t)USER_DATA_END - epp->stack.len)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Try out for overflow
|
|
||||||
*/
|
|
||||||
if (epp->text.len + epp->data.len + epp->heap.len + epp->stack.len > MAXMEM)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
if (roundup((unsigned)epp->data.vaddr + epp->data.len, NBPW) != roundup((unsigned)epp->bss.vaddr, NBPW)) {
|
|
||||||
DEBUG(".bss do not follow .data\n");
|
|
||||||
return ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate core at this point, committed to the new image.
|
|
||||||
*/
|
|
||||||
u.u_prof.pr_scale = 0;
|
|
||||||
if (u.u_procp->p_flag & SVFORK)
|
|
||||||
endvfork();
|
|
||||||
u.u_procp->p_dsize = epp->data.len + epp->bss.len;
|
|
||||||
u.u_procp->p_daddr = (size_t)epp->data.vaddr;
|
|
||||||
u.u_procp->p_ssize = epp->stack.len;
|
|
||||||
u.u_procp->p_saddr = (size_t)epp->stack.vaddr;
|
|
||||||
|
|
||||||
DEBUG("core allocation: \n");
|
|
||||||
DEBUG("daddr =%#x..%#x\n", u.u_procp->p_daddr, u.u_procp->p_daddr + u.u_procp->p_dsize);
|
|
||||||
DEBUG("saddr =%#x..%#x\n", u.u_procp->p_saddr, u.u_procp->p_saddr + u.u_procp->p_ssize);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Save argv[] and envp[]
|
|
||||||
*/
|
|
||||||
void exec_save_args(struct exec_params *epp)
|
|
||||||
{
|
|
||||||
unsigned len;
|
|
||||||
caddr_t cp;
|
|
||||||
int argc, i, l;
|
|
||||||
char **argp, *ap;
|
|
||||||
|
|
||||||
epp->argc = epp->envc = 0;
|
|
||||||
epp->argbc = epp->envbc = 0;
|
|
||||||
|
|
||||||
argc = 0;
|
|
||||||
if ((argp = epp->userargp) != NULL)
|
|
||||||
while (argp[argc])
|
|
||||||
argc++;
|
|
||||||
#ifdef EXEC_SCRIPT
|
|
||||||
if (epp->sh.interpreted) {
|
|
||||||
argc++;
|
|
||||||
if (epp->sh.interparg[0])
|
|
||||||
argc++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (argc != 0) {
|
|
||||||
if ((epp->argp = (char **)exec_alloc(argc * sizeof(char *), NBPW, epp)) == NULL)
|
|
||||||
return;
|
|
||||||
for (;;) {
|
|
||||||
/*
|
|
||||||
* For a interpreter script, the arg list is changed to
|
|
||||||
* #! <interpreter name> <interpreter arg>
|
|
||||||
* arg[0] - the interpreter executable name (path)
|
|
||||||
* arg[1] - interpreter arg (optional)
|
|
||||||
* arg[2 or 1] - script name
|
|
||||||
* arg[3 or 2...] - script arg[1...]
|
|
||||||
*/
|
|
||||||
if (argp)
|
|
||||||
ap = *argp++;
|
|
||||||
else
|
|
||||||
ap = NULL;
|
|
||||||
#ifdef EXEC_SCRIPT
|
|
||||||
if (epp->sh.interpreted) {
|
|
||||||
if (epp->argc == 0)
|
|
||||||
ap = epp->sh.interpname;
|
|
||||||
else if (epp->argc == 1 && epp->sh.interparg[0]) {
|
|
||||||
ap = epp->sh.interparg;
|
|
||||||
--argp;
|
|
||||||
} else if ((epp->argc == 1 || (epp->argc == 2 && epp->sh.interparg[0]))) {
|
|
||||||
ap = epp->userfname;
|
|
||||||
--argp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (ap == 0)
|
|
||||||
break;
|
|
||||||
l = strlen(ap)+1;
|
|
||||||
if ((cp = exec_alloc(l, 1, epp)) == NULL)
|
|
||||||
return;
|
|
||||||
if (copystr(ap, cp, l, &len) != 0)
|
|
||||||
return;
|
|
||||||
epp->argp[epp->argc++] = cp;
|
|
||||||
epp->argbc += len;;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
argc = 0;
|
|
||||||
if ((argp = epp->userenvp) != NULL)
|
|
||||||
while (argp[argc])
|
|
||||||
argc++;
|
|
||||||
epp->envc = 0;
|
|
||||||
epp->envbc = 0;
|
|
||||||
if (argc != 0) {
|
|
||||||
if ((epp->envp = (char **)exec_alloc(argc * sizeof(char *), NBPW, epp)) == NULL)
|
|
||||||
return;
|
|
||||||
for (;;) {
|
|
||||||
if (argp)
|
|
||||||
ap = *argp++;
|
|
||||||
else
|
|
||||||
ap = NULL;
|
|
||||||
if (ap == 0)
|
|
||||||
break;
|
|
||||||
l = strlen(ap)+1;
|
|
||||||
if ((cp = exec_alloc(l, 1, epp)) == NULL)
|
|
||||||
return;
|
|
||||||
if (copystr(ap, cp, l, &len) != 0)
|
|
||||||
return;
|
|
||||||
epp->envp[epp->envc++] = cp;
|
|
||||||
epp->envbc += len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < epp->argc; i++)
|
|
||||||
DEBUG("arg[%d] = \"%s\"\n", i, epp->argp[i]);
|
|
||||||
|
|
||||||
for (i = 0; i < epp->envc; i++)
|
|
||||||
DEBUG("env[%d] = \"%s\"\n", i, epp->envp[i]);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Number of string pool chars needed for this arg list
|
|
||||||
*/
|
|
||||||
// return (bc + NBPW-1) & ~(NBPW-1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void exec_clear(struct exec_params *epp)
|
|
||||||
{
|
|
||||||
char *cp;
|
|
||||||
int cc;
|
|
||||||
|
|
||||||
/* clear BSS */
|
|
||||||
if (epp->bss.len > 0)
|
|
||||||
bzero((void *)epp->bss.vaddr, epp->bss.len);
|
|
||||||
if (epp->heap.len > 0)
|
|
||||||
bzero((void *)epp->heap.vaddr, epp->heap.len);
|
|
||||||
/* Clear stack */
|
|
||||||
bzero((void *)epp->stack.vaddr, epp->stack.len);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* set SUID/SGID protections, if no tracing
|
|
||||||
*/
|
|
||||||
if ((u.u_procp->p_flag & P_TRACED) == 0) {
|
|
||||||
u.u_uid = epp->uid;
|
|
||||||
u.u_procp->p_uid = epp->uid;
|
|
||||||
u.u_groups[0] = epp->gid;
|
|
||||||
} else
|
|
||||||
psignal (u.u_procp, SIGTRAP);
|
|
||||||
u.u_svuid = u.u_uid;
|
|
||||||
u.u_svgid = u.u_groups[0];
|
|
||||||
|
|
||||||
u.u_tsize = epp->text.len;
|
|
||||||
u.u_dsize = epp->data.len + epp->bss.len;
|
|
||||||
u.u_ssize = epp->stack.len;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Clear registers.
|
|
||||||
*/
|
|
||||||
u.u_frame [FRAME_R1] = 0; /* $at */
|
|
||||||
u.u_frame [FRAME_R2] = 0; /* $v0 */
|
|
||||||
u.u_frame [FRAME_R3] = 0; /* $v1 */
|
|
||||||
u.u_frame [FRAME_R7] = 0; /* $a3 */
|
|
||||||
u.u_frame [FRAME_R8] = 0; /* $t0 */
|
|
||||||
u.u_frame [FRAME_R9] = 0; /* $t1 */
|
|
||||||
u.u_frame [FRAME_R10] = 0; /* $t2 */
|
|
||||||
u.u_frame [FRAME_R11] = 0; /* $t3 */
|
|
||||||
u.u_frame [FRAME_R12] = 0; /* $t4 */
|
|
||||||
u.u_frame [FRAME_R13] = 0; /* $t5 */
|
|
||||||
u.u_frame [FRAME_R14] = 0; /* $t6 */
|
|
||||||
u.u_frame [FRAME_R15] = 0; /* $t7 */
|
|
||||||
u.u_frame [FRAME_R16] = 0; /* $s0 */
|
|
||||||
u.u_frame [FRAME_R17] = 0; /* $s1 */
|
|
||||||
u.u_frame [FRAME_R18] = 0; /* $s2 */
|
|
||||||
u.u_frame [FRAME_R19] = 0; /* $s3 */
|
|
||||||
u.u_frame [FRAME_R20] = 0; /* $s4 */
|
|
||||||
u.u_frame [FRAME_R21] = 0; /* $s5 */
|
|
||||||
u.u_frame [FRAME_R22] = 0; /* $s6 */
|
|
||||||
u.u_frame [FRAME_R23] = 0; /* $s7 */
|
|
||||||
u.u_frame [FRAME_R24] = 0; /* $t8 */
|
|
||||||
u.u_frame [FRAME_R25] = 0; /* $t9 */
|
|
||||||
u.u_frame [FRAME_FP] = 0;
|
|
||||||
u.u_frame [FRAME_RA] = 0;
|
|
||||||
u.u_frame [FRAME_LO] = 0;
|
|
||||||
u.u_frame [FRAME_HI] = 0;
|
|
||||||
u.u_frame [FRAME_GP] = 0;
|
|
||||||
|
|
||||||
execsigs (u.u_procp);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Clear (close) files
|
|
||||||
*/
|
|
||||||
for (cp = u.u_pofile, cc = 0; cc <= u.u_lastfile; cc++, cp++) {
|
|
||||||
if (*cp & UF_EXCLOSE) {
|
|
||||||
(void) closef (u.u_ofile [cc]);
|
|
||||||
u.u_ofile [cc] = NULL;
|
|
||||||
*cp = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (u.u_lastfile >= 0 && u.u_ofile [u.u_lastfile] == NULL)
|
|
||||||
u.u_lastfile--;
|
|
||||||
}
|
|
||||||
@@ -6,17 +6,15 @@
|
|||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "systm.h"
|
#include "systm.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "inode.h"
|
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
#include "buf.h"
|
#include "buf.h"
|
||||||
|
#include "inode.h"
|
||||||
#include "namei.h"
|
#include "namei.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "mount.h"
|
#include "mount.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "signalvar.h"
|
#include "signalvar.h"
|
||||||
#include "exec.h"
|
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* exec system call, with and without environments.
|
* exec system call, with and without environments.
|
||||||
@@ -28,70 +26,135 @@ struct execa {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is the internal form of the exec() function.
|
* Reset signals for an exec of the specified process. In 4.4 this function
|
||||||
*
|
* was in kern_sig.c but since in 2.11 kern_sig and kern_exec will likely be
|
||||||
* It is called with the inode of the executable
|
* in different overlays placing this here potentially saves a kernel overlay
|
||||||
* and the exec_params structure, which is used to
|
* switch.
|
||||||
* keep information during the exec.
|
|
||||||
*
|
|
||||||
* It returns the error code, and with the ip still locked.
|
|
||||||
*/
|
*/
|
||||||
int exec_check(struct exec_params *epp)
|
static void
|
||||||
|
execsigs(p)
|
||||||
|
register struct proc *p;
|
||||||
{
|
{
|
||||||
int error, i, r;
|
register int nc;
|
||||||
|
unsigned long mask;
|
||||||
DEBUG("Entering exec_check\n");
|
|
||||||
if (access (epp->ip, IEXEC))
|
|
||||||
return ENOEXEC;
|
|
||||||
if ((u.u_procp->p_flag & P_TRACED) && access (epp->ip, IREAD))
|
|
||||||
return ENOEXEC;
|
|
||||||
if ((epp->ip->i_mode & IFMT) != IFREG ||
|
|
||||||
(epp->ip->i_mode & (IEXEC | (IEXEC>>3) | (IEXEC>>6))) == 0)
|
|
||||||
return EACCES;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read in first few bytes of file for segment sizes, magic number:
|
* Reset caught signals. Held signals remain held
|
||||||
* 407 = plain executable
|
* through p_sigmask (unless they were caught,
|
||||||
* Also an ASCII line beginning with #! is
|
* and are now ignored by default).
|
||||||
* the file name of a ``interpreter'' and arguments may be prepended
|
|
||||||
* to the argument list if given here.
|
|
||||||
*
|
|
||||||
* INTERPRETER NAMES ARE LIMITED IN LENGTH.
|
|
||||||
*
|
|
||||||
* ONLY ONE ARGUMENT MAY BE PASSED TO THE INTERPRETER FROM
|
|
||||||
* THE ASCII LINE.
|
|
||||||
*/
|
*/
|
||||||
|
while (p->p_sigcatch) {
|
||||||
/*
|
nc = ffs(p->p_sigcatch);
|
||||||
* Read the first 'SHSIZE' bytes from the file to execute
|
mask = sigmask(nc);
|
||||||
*/
|
p->p_sigcatch &= ~mask;
|
||||||
DEBUG("Read header %d bytes from %d\n", sizeof(epp->hdr), 0);
|
if (sigprop[nc] & SA_IGNORE) {
|
||||||
#ifdef EXEC_SCRIPT
|
if (nc != SIGCONT)
|
||||||
epp->hdr.sh[0] = '\0'; /* for zero length files */
|
p->p_sigignore |= mask;
|
||||||
#endif
|
p->p_sig &= ~mask;
|
||||||
error = rdwri (UIO_READ, epp->ip,
|
}
|
||||||
(caddr_t) &epp->hdr, sizeof(epp->hdr),
|
u.u_signal[nc] = SIG_DFL;
|
||||||
(off_t)0, IO_UNIT, &r);
|
|
||||||
if (error)
|
|
||||||
return error;
|
|
||||||
epp->hdr_len = sizeof(epp->hdr) - r;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Given the first part of the image
|
|
||||||
* loop through the exec file handlers to find
|
|
||||||
* someone who can handle this file format.
|
|
||||||
*/
|
|
||||||
error = ENOEXEC;
|
|
||||||
DEBUG("Trying %d exec formats\n", nexecs);
|
|
||||||
for (i = 0; i < nexecs && error != 0; i++) {
|
|
||||||
DEBUG("Trying exec format %d : %s\n", i, execsw[i].es_name);
|
|
||||||
if (execsw[i].es_check == NULL)
|
|
||||||
continue;
|
|
||||||
error = (*execsw[i].es_check)(epp);
|
|
||||||
if (error == 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return error;
|
/*
|
||||||
|
* Reset stack state to the user stack (disable the alternate stack).
|
||||||
|
*/
|
||||||
|
u.u_sigstk.ss_flags = SA_DISABLE;
|
||||||
|
u.u_sigstk.ss_size = 0;
|
||||||
|
u.u_sigstk.ss_base = 0;
|
||||||
|
u.u_psflags = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read in and set up memory for executed file.
|
||||||
|
* u.u_error set on error
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
getxfile (ip, ep, nargc, uid, gid)
|
||||||
|
struct inode *ip;
|
||||||
|
register struct exec *ep;
|
||||||
|
int nargc, uid, gid;
|
||||||
|
{
|
||||||
|
u_int ds, ts, ss;
|
||||||
|
|
||||||
|
if (ep->a_magic == OMAGIC) {
|
||||||
|
ep->a_data += ep->a_text;
|
||||||
|
ep->a_text = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ep->a_text != 0 && (ip->i_flag & ITEXT) == 0 &&
|
||||||
|
ip->i_count != 1) {
|
||||||
|
register struct file *fp;
|
||||||
|
|
||||||
|
for (fp = file; fp < file+NFILE; fp++) {
|
||||||
|
if (fp->f_type == DTYPE_INODE &&
|
||||||
|
fp->f_count > 0 &&
|
||||||
|
(struct inode*)fp->f_data == ip &&
|
||||||
|
(fp->f_flag & FWRITE)) {
|
||||||
|
u.u_error = ETXTBSY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* find text and data sizes try; them out for possible
|
||||||
|
* overflow of max sizes
|
||||||
|
*/
|
||||||
|
ts = ep->a_text;
|
||||||
|
ds = ep->a_data + ep->a_bss;
|
||||||
|
ss = SSIZE + nargc;
|
||||||
|
|
||||||
|
//printf ("getxfile: size t/d/s = %u/%u/%u\n", ts, ds, ss);
|
||||||
|
if (ts + ds + ss > MAXMEM) {
|
||||||
|
u.u_error = ENOMEM;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate core at this point, committed to the new image.
|
||||||
|
*/
|
||||||
|
u.u_prof.pr_scale = 0;
|
||||||
|
if (u.u_procp->p_flag & SVFORK)
|
||||||
|
endvfork();
|
||||||
|
u.u_procp->p_dsize = ds;
|
||||||
|
u.u_procp->p_daddr = USER_DATA_START;
|
||||||
|
u.u_procp->p_ssize = ss;
|
||||||
|
u.u_procp->p_saddr = USER_DATA_END - ss;
|
||||||
|
|
||||||
|
/* read in text and data */
|
||||||
|
//printf ("getxfile: read %u bytes at %08x\n", ep->a_data, USER_DATA_START);
|
||||||
|
rdwri (UIO_READ, ip, (caddr_t) USER_DATA_START, ep->a_data,
|
||||||
|
sizeof(struct exec) + ep->a_text, IO_UNIT, (int*) 0);
|
||||||
|
|
||||||
|
/* clear BSS and stack */
|
||||||
|
//printf ("getxfile: clear %u bytes at %08x\n", USER_DATA_END - USER_DATA_START - ep->a_data, USER_DATA_START + ep->a_data);
|
||||||
|
bzero ((void*) (USER_DATA_START + ep->a_data),
|
||||||
|
USER_DATA_END - USER_DATA_START - ep->a_data);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set SUID/SGID protections, if no tracing
|
||||||
|
*/
|
||||||
|
if ((u.u_procp->p_flag & P_TRACED) == 0) {
|
||||||
|
u.u_uid = uid;
|
||||||
|
u.u_procp->p_uid = uid;
|
||||||
|
u.u_groups[0] = gid;
|
||||||
|
} else
|
||||||
|
psignal (u.u_procp, SIGTRAP);
|
||||||
|
u.u_svuid = u.u_uid;
|
||||||
|
u.u_svgid = u.u_groups[0];
|
||||||
|
|
||||||
|
u.u_tsize = ts;
|
||||||
|
u.u_dsize = ds;
|
||||||
|
u.u_ssize = ss;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printmem (unsigned addr, int nbytes)
|
||||||
|
{
|
||||||
|
for (; nbytes>0; addr+=16, nbytes-=16) {
|
||||||
|
unsigned char *p = (unsigned char*) addr;
|
||||||
|
printf ("%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
|
||||||
|
addr, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
|
||||||
|
p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -106,51 +169,371 @@ execv()
|
|||||||
void
|
void
|
||||||
execve()
|
execve()
|
||||||
{
|
{
|
||||||
|
register char *cp;
|
||||||
|
register struct buf *bp;
|
||||||
struct execa *uap = (struct execa *)u.u_arg;
|
struct execa *uap = (struct execa *)u.u_arg;
|
||||||
int error;
|
int nc, na, ne, ucp, ap, indir, uid, gid, resid, error;
|
||||||
|
register int cc;
|
||||||
|
unsigned len;
|
||||||
|
char *sharg;
|
||||||
struct inode *ip;
|
struct inode *ip;
|
||||||
|
size_t bno;
|
||||||
|
char cfname [MAXCOMLEN + 1];
|
||||||
|
#define SHSIZE 32
|
||||||
|
char cfarg [SHSIZE];
|
||||||
|
union {
|
||||||
|
char ex_shell [SHSIZE]; /* #! and name of interpreter */
|
||||||
|
struct exec ex_exec;
|
||||||
|
} exdata;
|
||||||
struct nameidata nd;
|
struct nameidata nd;
|
||||||
register struct nameidata *ndp = &nd;
|
register struct nameidata *ndp = &nd;
|
||||||
struct exec_params eparam;
|
|
||||||
|
|
||||||
DEBUG("execve ('%s', ['%s', '%s', ...])\n", uap->fname, uap->argp[0], uap->argp[1]);
|
//printf ("execve ('%s', ['%s', '%s', ...])\n", uap->fname, uap->argp[0], uap->argp[1]);
|
||||||
NDINIT (ndp, LOOKUP, FOLLOW, uap->fname);
|
NDINIT (ndp, LOOKUP, FOLLOW, uap->fname);
|
||||||
ip = namei (ndp);
|
ip = namei (ndp);
|
||||||
if (ip == NULL) {
|
if (ip == NULL) {
|
||||||
DEBUG("execve: file '%s' not found\n", uap->fname);
|
//printf ("execve: file not found\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*
|
bno = 0;
|
||||||
* The exec_param structure is used to
|
bp = 0;
|
||||||
* keep information about the executable during exec's processing
|
indir = 0;
|
||||||
*/
|
uid = u.u_uid;
|
||||||
bzero(&eparam, sizeof eparam);
|
gid = u.u_groups[0];
|
||||||
eparam.userfname = uap->fname;
|
|
||||||
eparam.userargp = uap->argp;
|
|
||||||
eparam.userenvp = uap->envp;
|
|
||||||
eparam.uid = u.u_uid;
|
|
||||||
eparam.gid = u.u_groups[0];
|
|
||||||
|
|
||||||
if (ip->i_fs->fs_flags & MNT_NOEXEC) {
|
if (ip->i_fs->fs_flags & MNT_NOEXEC) {
|
||||||
|
//printf ("execve: NOEXEC, flags=%o\n", ip->i_fs->fs_flags);
|
||||||
u.u_error = EACCES;
|
u.u_error = EACCES;
|
||||||
DEBUG("EACCES\n");
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if ((ip->i_fs->fs_flags & MNT_NOSUID) == 0) {
|
if ((ip->i_fs->fs_flags & MNT_NOSUID) == 0) {
|
||||||
if (ip->i_mode & ISUID)
|
if (ip->i_mode & ISUID)
|
||||||
eparam.uid = ip->i_uid;
|
uid = ip->i_uid;
|
||||||
if (ip->i_mode & ISGID)
|
if (ip->i_mode & ISGID)
|
||||||
eparam.gid = ip->i_gid;
|
gid = ip->i_gid;
|
||||||
|
}
|
||||||
|
again:
|
||||||
|
if (access (ip, IEXEC)) {
|
||||||
|
//printf ("execve: no IEXEC\n");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if ((u.u_procp->p_flag & P_TRACED) && access (ip, IREAD)) {
|
||||||
|
//printf ("execve: traced, but no IREAD\n");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if ((ip->i_mode & IFMT) != IFREG ||
|
||||||
|
(ip->i_mode & (IEXEC | (IEXEC>>3) | (IEXEC>>6))) == 0) {
|
||||||
|
//printf ("execve: no IEXEC, mode=%o\n", ip->i_mode);
|
||||||
|
u.u_error = EACCES;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
eparam.ip = ip;
|
/*
|
||||||
DEBUG("calling exec_check()\n");
|
* Read in first few bytes of file for segment sizes, magic number:
|
||||||
if ((error = exec_check(&eparam)))
|
* 407 = plain executable
|
||||||
u.u_error = error;
|
* Also an ASCII line beginning with #! is
|
||||||
DEBUG("back from exec_check()\n");
|
* the file name of a ``shell'' and arguments may be prepended
|
||||||
|
* to the argument list if given here.
|
||||||
|
*
|
||||||
|
* SHELL NAMES ARE LIMITED IN LENGTH.
|
||||||
|
*
|
||||||
|
* ONLY ONE ARGUMENT MAY BE PASSED TO THE SHELL FROM
|
||||||
|
* THE ASCII LINE.
|
||||||
|
*/
|
||||||
|
exdata.ex_shell[0] = '\0'; /* for zero length files */
|
||||||
|
u.u_error = rdwri (UIO_READ, ip, (caddr_t) &exdata, sizeof(exdata),
|
||||||
|
(off_t) 0, IO_UNIT, &resid);
|
||||||
|
if (u.u_error) {
|
||||||
|
//printf ("execve: rdwri error %d\n", u.u_error);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if (resid > sizeof(exdata) - sizeof(exdata.ex_exec) &&
|
||||||
|
exdata.ex_shell[0] != '#') {
|
||||||
|
//printf ("execve: short read, resid = %d, shell=%.32s\n", resid, exdata.ex_shell);
|
||||||
|
u.u_error = ENOEXEC;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
//printf ("execve: text=%u, data=%u, bss=%u\n", exdata.ex_exec.a_text, exdata.ex_exec.a_data, exdata.ex_exec.a_bss);
|
||||||
|
|
||||||
|
switch ((int) exdata.ex_exec.a_magic) {
|
||||||
|
case OMAGIC:
|
||||||
|
case NMAGIC:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (exdata.ex_shell[0] != '#' ||
|
||||||
|
exdata.ex_shell[1] != '!' ||
|
||||||
|
indir) {
|
||||||
|
//printf ("execve: bad shell=%.32s\n", exdata.ex_shell);
|
||||||
|
u.u_error = ENOEXEC;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* If setuid/gid scripts were to be disallowed this is where it would
|
||||||
|
* have to be done.
|
||||||
|
* u.u_uid = uid;
|
||||||
|
* u.u_gid = u_groups[0];
|
||||||
|
*/
|
||||||
|
cp = &exdata.ex_shell[2]; /* skip "#!" */
|
||||||
|
while (cp < &exdata.ex_shell[SHSIZE]) {
|
||||||
|
if (*cp == '\t')
|
||||||
|
*cp = ' ';
|
||||||
|
else if (*cp == '\n') {
|
||||||
|
*cp = '\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cp++;
|
||||||
|
}
|
||||||
|
if (*cp != '\0') {
|
||||||
|
u.u_error = ENOEXEC;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
cp = &exdata.ex_shell[2];
|
||||||
|
while (*cp == ' ')
|
||||||
|
cp++;
|
||||||
|
ndp->ni_dirp = cp;
|
||||||
|
while (*cp && *cp != ' ')
|
||||||
|
cp++;
|
||||||
|
cfarg[0] = '\0';
|
||||||
|
if (*cp) {
|
||||||
|
*cp++ = '\0';
|
||||||
|
while (*cp == ' ')
|
||||||
|
cp++;
|
||||||
|
if (*cp)
|
||||||
|
bcopy ((caddr_t) cp, (caddr_t) cfarg, SHSIZE);
|
||||||
|
}
|
||||||
|
indir = 1;
|
||||||
|
iput (ip);
|
||||||
|
ndp->ni_nameiop = LOOKUP | FOLLOW;
|
||||||
|
ip = namei (ndp);
|
||||||
|
if (ip == NULL)
|
||||||
|
return;
|
||||||
|
bcopy ((caddr_t) ndp->ni_dent.d_name, (caddr_t) cfname, MAXCOMLEN);
|
||||||
|
cfname [MAXCOMLEN] = '\0';
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Collect arguments on "file" in swap space.
|
||||||
|
*/
|
||||||
|
na = 0;
|
||||||
|
ne = 0;
|
||||||
|
nc = 0;
|
||||||
|
cc = 0;
|
||||||
|
cp = 0;
|
||||||
|
bno = malloc (swapmap, btod (NCARGS + MAXBSIZE));
|
||||||
|
if (bno == 0) {
|
||||||
|
u.u_error = ENOMEM;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Copy arguments into file in argdev area.
|
||||||
|
*/
|
||||||
|
if (uap->argp) for (;;) {
|
||||||
|
ap = NULL;
|
||||||
|
sharg = NULL;
|
||||||
|
if (indir && na == 0) {
|
||||||
|
sharg = cfname;
|
||||||
|
ap = (int) sharg;
|
||||||
|
uap->argp++; /* ignore argv[0] */
|
||||||
|
} else if (indir && (na == 1 && cfarg[0])) {
|
||||||
|
sharg = cfarg;
|
||||||
|
ap = (int) sharg;
|
||||||
|
} else if (indir && (na == 1 || (na == 2 && cfarg[0])))
|
||||||
|
ap = (int) uap->fname;
|
||||||
|
else if (uap->argp) {
|
||||||
|
ap = *(int*) uap->argp;
|
||||||
|
uap->argp++;
|
||||||
|
}
|
||||||
|
if (ap == NULL && uap->envp) {
|
||||||
|
uap->argp = NULL;
|
||||||
|
ap = *(int*) uap->envp;
|
||||||
|
if (ap != NULL)
|
||||||
|
uap->envp++, ne++;
|
||||||
|
}
|
||||||
|
if (ap == NULL)
|
||||||
|
break;
|
||||||
|
na++;
|
||||||
|
if (ap == -1) {
|
||||||
|
u.u_error = EFAULT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
if (cc <= 0) {
|
||||||
|
/*
|
||||||
|
* We depend on NCARGS being a multiple of
|
||||||
|
* DEV_BSIZE. This way we need only check
|
||||||
|
* overflow before each buffer allocation.
|
||||||
|
*/
|
||||||
|
if (nc >= NCARGS-1) {
|
||||||
|
//printf ("execve: too many args = %d\n", nc);
|
||||||
|
error = E2BIG;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (bp) {
|
||||||
|
bdwrite(bp);
|
||||||
|
}
|
||||||
|
cc = DEV_BSIZE;
|
||||||
|
bp = getblk (swapdev, dbtofsb(bno) + lblkno(nc));
|
||||||
|
cp = bp->b_addr;
|
||||||
|
}
|
||||||
|
if (sharg) {
|
||||||
|
error = copystr (sharg, cp, (unsigned) cc, &len);
|
||||||
|
//printf ("execve arg%d=%s: %u bytes from %08x to %08x\n", na-1, sharg, len, sharg, cp);
|
||||||
|
sharg += len;
|
||||||
|
} else {
|
||||||
|
error = copystr ((caddr_t) ap, cp, (unsigned) cc, &len);
|
||||||
|
//printf ("execve arg%d=%s: %u bytes from %08x to %08x\n", na-1, ap, len, ap, cp);
|
||||||
|
ap += len;
|
||||||
|
}
|
||||||
|
cp += len;
|
||||||
|
nc += len;
|
||||||
|
cc -= len;
|
||||||
|
} while (error == ENOENT);
|
||||||
|
if (error) {
|
||||||
|
//printf ("execve: copy arg error = %d\n", error);
|
||||||
|
u.u_error = error;
|
||||||
|
if (bp) {
|
||||||
|
bp->b_flags |= B_AGE;
|
||||||
|
bp->b_flags &= ~B_DELWRI;
|
||||||
|
brelse(bp);
|
||||||
|
}
|
||||||
|
bp = 0;
|
||||||
|
goto badarg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//printf ("execve: argc=%d, envc=%d, total %d bytes\n", na, ne, nc);
|
||||||
|
if (bp) {
|
||||||
|
bdwrite (bp);
|
||||||
|
}
|
||||||
|
bp = 0;
|
||||||
|
nc = (nc + NBPW-1) & ~(NBPW-1);
|
||||||
|
getxfile (ip, &exdata.ex_exec, nc + (na+4)*NBPW, uid, gid);
|
||||||
|
if (u.u_error) {
|
||||||
|
//printf ("execve: getxfile error = %d\n", u.u_error);
|
||||||
|
badarg:
|
||||||
|
for (cc = 0; cc < nc; cc += DEV_BSIZE) {
|
||||||
|
daddr_t blkno;
|
||||||
|
|
||||||
|
blkno = dbtofsb(bno) + lblkno(cc);
|
||||||
|
if (incore (swapdev, blkno)) {
|
||||||
|
bp = bread (swapdev, blkno);
|
||||||
|
bp->b_flags |= B_AGE; /* throw away */
|
||||||
|
bp->b_flags &= ~B_DELWRI; /* cancel io */
|
||||||
|
brelse(bp);
|
||||||
|
bp = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
iput(ip);
|
||||||
|
ip = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copy back arglist.
|
||||||
|
*/
|
||||||
|
ucp = USER_DATA_END - nc - NBPW;
|
||||||
|
ap = ucp - na*NBPW - 2*NBPW;
|
||||||
|
u.u_frame [FRAME_SP] = ap - 16;
|
||||||
|
u.u_frame [FRAME_R4] = na - ne; /* $a0 := argc */
|
||||||
|
u.u_frame [FRAME_R5] = ap; /* $a1 := argv */
|
||||||
|
u.u_frame [FRAME_R6] = ap + (na-ne+1)*NBPW; /* $a2 := env */
|
||||||
|
*(int*) (USER_DATA_END - NBPW) = ap; /* for /bin/ps */
|
||||||
|
nc = 0;
|
||||||
|
cc = 0;
|
||||||
|
for (;;) {
|
||||||
|
if (na == ne) {
|
||||||
|
*(int*) ap = 0;
|
||||||
|
ap += NBPW;
|
||||||
|
}
|
||||||
|
if (--na < 0)
|
||||||
|
break;
|
||||||
|
*(int*) ap = ucp;
|
||||||
|
do {
|
||||||
|
if (cc <= 0) {
|
||||||
|
if (bp) {
|
||||||
|
brelse(bp);
|
||||||
|
}
|
||||||
|
cc = DEV_BSIZE;
|
||||||
|
bp = bread (swapdev, dbtofsb(bno) + lblkno(nc));
|
||||||
|
bp->b_flags |= B_AGE; /* throw away */
|
||||||
|
bp->b_flags &= ~B_DELWRI; /* cancel io */
|
||||||
|
cp = bp->b_addr;
|
||||||
|
}
|
||||||
|
error = copystr (cp, (caddr_t) ucp, (unsigned) cc,
|
||||||
|
&len);
|
||||||
|
//printf ("execve copy '%s' %u bytes from %08x to %08x\n", cp, len, cp, ucp);
|
||||||
|
ucp += len;
|
||||||
|
cp += len;
|
||||||
|
nc += len;
|
||||||
|
cc -= len;
|
||||||
|
} while (error == ENOENT);
|
||||||
|
if (error == EFAULT)
|
||||||
|
panic ("exec: EFAULT");
|
||||||
|
ap += NBPW;
|
||||||
|
}
|
||||||
|
*(int*) ap = 0;
|
||||||
|
if (bp) {
|
||||||
|
bp->b_flags |= B_AGE;
|
||||||
|
brelse (bp);
|
||||||
|
bp = NULL;
|
||||||
|
}
|
||||||
|
execsigs (u.u_procp);
|
||||||
|
for (cp = u.u_pofile, cc = 0; cc <= u.u_lastfile; cc++, cp++) {
|
||||||
|
if (*cp & UF_EXCLOSE) {
|
||||||
|
(void) closef (u.u_ofile [cc]);
|
||||||
|
u.u_ofile [cc] = NULL;
|
||||||
|
*cp = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (u.u_lastfile >= 0 && u.u_ofile [u.u_lastfile] == NULL)
|
||||||
|
u.u_lastfile--;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Clear registers.
|
||||||
|
*/
|
||||||
|
u.u_frame [FRAME_R1] = 0; /* $at */
|
||||||
|
u.u_frame [FRAME_R2] = 0; /* $v0 */
|
||||||
|
u.u_frame [FRAME_R3] = 0; /* $v1 */
|
||||||
|
u.u_frame [FRAME_R7] = 0; /* $a3 */
|
||||||
|
u.u_frame [FRAME_R8] = 0; /* $t0 */
|
||||||
|
u.u_frame [FRAME_R9] = 0; /* $t1 */
|
||||||
|
u.u_frame [FRAME_R10] = 0; /* $t2 */
|
||||||
|
u.u_frame [FRAME_R11] = 0; /* $t3 */
|
||||||
|
u.u_frame [FRAME_R12] = 0; /* $t4 */
|
||||||
|
u.u_frame [FRAME_R13] = 0; /* $t5 */
|
||||||
|
u.u_frame [FRAME_R14] = 0; /* $t6 */
|
||||||
|
u.u_frame [FRAME_R15] = 0; /* $t7 */
|
||||||
|
u.u_frame [FRAME_R16] = 0; /* $s0 */
|
||||||
|
u.u_frame [FRAME_R17] = 0; /* $s1 */
|
||||||
|
u.u_frame [FRAME_R18] = 0; /* $s2 */
|
||||||
|
u.u_frame [FRAME_R19] = 0; /* $s3 */
|
||||||
|
u.u_frame [FRAME_R20] = 0; /* $s4 */
|
||||||
|
u.u_frame [FRAME_R21] = 0; /* $s5 */
|
||||||
|
u.u_frame [FRAME_R22] = 0; /* $s6 */
|
||||||
|
u.u_frame [FRAME_R23] = 0; /* $s7 */
|
||||||
|
u.u_frame [FRAME_R24] = 0; /* $t8 */
|
||||||
|
u.u_frame [FRAME_R25] = 0; /* $t9 */
|
||||||
|
u.u_frame [FRAME_FP] = 0;
|
||||||
|
u.u_frame [FRAME_RA] = 0;
|
||||||
|
u.u_frame [FRAME_LO] = 0;
|
||||||
|
u.u_frame [FRAME_HI] = 0;
|
||||||
|
u.u_frame [FRAME_GP] = 0;
|
||||||
|
u.u_frame [FRAME_PC] = exdata.ex_exec.a_entry;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remember file name for accounting.
|
||||||
|
*/
|
||||||
|
bcopy ((caddr_t) (indir ? cfname : ndp->ni_dent.d_name),
|
||||||
|
(caddr_t) u.u_comm, MAXCOMLEN);
|
||||||
done:
|
done:
|
||||||
exec_alloc_freeall(&eparam);
|
//printf ("execve done: PC=%08x, SP=%08x, R4=%08x, R5=%08x, R6=%08x\n",
|
||||||
|
// u.u_frame [FRAME_PC], u.u_frame [FRAME_SP],
|
||||||
|
// u.u_frame [FRAME_R4], u.u_frame [FRAME_R5], u.u_frame [FRAME_R6]);
|
||||||
|
if (bp) {
|
||||||
|
bp->b_flags |= B_AGE;
|
||||||
|
brelse (bp);
|
||||||
|
}
|
||||||
|
if (bno)
|
||||||
|
mfree (swapmap, btod (NCARGS + MAXBSIZE), bno);
|
||||||
if (ip)
|
if (ip)
|
||||||
iput(ip);
|
iput(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -662,40 +662,3 @@ postsig(sig)
|
|||||||
}
|
}
|
||||||
exit(sig);
|
exit(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Reset signals for an exec of the specified process. In 4.4 this function
|
|
||||||
* was in kern_sig.c but since in 2.11 kern_sig and kern_exec will likely be
|
|
||||||
* in different overlays placing this here potentially saves a kernel overlay
|
|
||||||
* switch.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
execsigs(register struct proc *p)
|
|
||||||
{
|
|
||||||
register int nc;
|
|
||||||
unsigned long mask;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Reset caught signals. Held signals remain held
|
|
||||||
* through p_sigmask (unless they were caught,
|
|
||||||
* and are now ignored by default).
|
|
||||||
*/
|
|
||||||
while (p->p_sigcatch) {
|
|
||||||
nc = ffs(p->p_sigcatch);
|
|
||||||
mask = sigmask(nc);
|
|
||||||
p->p_sigcatch &= ~mask;
|
|
||||||
if (sigprop[nc] & SA_IGNORE) {
|
|
||||||
if (nc != SIGCONT)
|
|
||||||
p->p_sigignore |= mask;
|
|
||||||
p->p_sig &= ~mask;
|
|
||||||
}
|
|
||||||
u.u_signal[nc] = SIG_DFL;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Reset stack state to the user stack (disable the alternate stack).
|
|
||||||
*/
|
|
||||||
u.u_sigstk.ss_flags = SA_DISABLE;
|
|
||||||
u.u_sigstk.ss_size = 0;
|
|
||||||
u.u_sigstk.ss_base = 0;
|
|
||||||
u.u_psflags = 0;
|
|
||||||
}
|
|
||||||
|
|||||||
1389
sys/kernel/rdisk.c
1389
sys/kernel/rdisk.c
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o oc.o rd_sd.o rd_sdramp.o rdisk.o sdram.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o oc.o rd_sd.o rd_sdramp.o rdisk.o sdram.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS = bootloader
|
EXTRA_TARGETS = bootloader
|
||||||
|
|
||||||
DEFS += -DADC_ENABLED=YES
|
DEFS += -DADC_ENABLED=YES
|
||||||
@@ -48,9 +48,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DFLASH_USER=0x1d005000
|
DEFS += -DFLASH_USER=0x1d005000
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o clock.o cons.o devcfg.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o clock.o cons.o devcfg.o devsw.o exception.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS =
|
EXTRA_TARGETS =
|
||||||
|
|
||||||
DEFS += -DBUS_DIV=1
|
DEFS += -DBUS_DIV=1
|
||||||
@@ -41,9 +41,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DKERNEL
|
DEFS += -DKERNEL
|
||||||
DEFS += -DLED_DISK_PIN=2
|
DEFS += -DLED_DISK_PIN=2
|
||||||
DEFS += -DLED_DISK_PORT=TRISD
|
DEFS += -DLED_DISK_PORT=TRISD
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
always
|
always
|
||||||
define KERNEL
|
define KERNEL
|
||||||
define UCB_METER
|
define UCB_METER
|
||||||
define EXEC_AOUT
|
|
||||||
define EXEC_ELF
|
|
||||||
define EXEC_SCRIPT
|
|
||||||
file _startup.o
|
file _startup.o
|
||||||
file clock.o
|
file clock.o
|
||||||
file devsw.o
|
file devsw.o
|
||||||
@@ -12,11 +9,6 @@ always
|
|||||||
file machdep.o
|
file machdep.o
|
||||||
file mem.o
|
file mem.o
|
||||||
file exception.o
|
file exception.o
|
||||||
file exec_aout.o
|
|
||||||
file exec_conf.o
|
|
||||||
file exec_elf.o
|
|
||||||
file exec_script.o
|
|
||||||
file exec_subr.o
|
|
||||||
file init_main.o
|
file init_main.o
|
||||||
file init_sysent.o
|
file init_sysent.o
|
||||||
file kern_clock.o
|
file kern_clock.o
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ always
|
|||||||
file rd_sramc.o
|
file rd_sramc.o
|
||||||
require rdisk
|
require rdisk
|
||||||
define SRAMC_ENABLED YES
|
define SRAMC_ENABLED YES
|
||||||
|
define SRAMC%0_ENABLED YES
|
||||||
end always
|
end always
|
||||||
|
|
||||||
option data
|
option data
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS = bootloader
|
EXTRA_TARGETS = bootloader
|
||||||
|
|
||||||
DEFS += -DBL_BUTTON_PIN=6
|
DEFS += -DBL_BUTTON_PIN=6
|
||||||
@@ -52,9 +52,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DFLASH_JUMP=0x9d000000
|
DEFS += -DFLASH_JUMP=0x9d000000
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS =
|
EXTRA_TARGETS =
|
||||||
|
|
||||||
DEFS += -DBUS_DIV=1
|
DEFS += -DBUS_DIV=1
|
||||||
@@ -41,9 +41,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DKERNEL
|
DEFS += -DKERNEL
|
||||||
DEFS += -DLED_DISK_PIN=12
|
DEFS += -DLED_DISK_PIN=12
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS =
|
EXTRA_TARGETS =
|
||||||
|
|
||||||
DEFS += -DBUS_DIV=1
|
DEFS += -DBUS_DIV=1
|
||||||
@@ -41,9 +41,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DKERNEL
|
DEFS += -DKERNEL
|
||||||
DEFS += -DLED_DISK_PIN=12
|
DEFS += -DLED_DISK_PIN=12
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
/* $NetBSD: elf_machdep.h,v 1.7 2000/04/02 15:35:50 minoura Exp $ */
|
|
||||||
|
|
||||||
#define ELF_MACHDEP_ID_CASES \
|
|
||||||
case EM_MIPS: \
|
|
||||||
break;
|
|
||||||
|
|
||||||
#define ARCH_ELFSIZE 32 /* MD native binary size */
|
|
||||||
|
|
||||||
/* mips relocs. */
|
|
||||||
|
|
||||||
#define R_MIPS_NONE 0
|
|
||||||
#define R_MIPS_16 1
|
|
||||||
#define R_MIPS_32 2
|
|
||||||
#define R_MIPS_REL32 3
|
|
||||||
#define R_MIPS_REL R_MIPS_REL32
|
|
||||||
#define R_MIPS_26 4
|
|
||||||
#define R_MIPS_HI16 5 /* high 16 bits of symbol value */
|
|
||||||
#define R_MIPS_LO16 6 /* low 16 bits of symbol value */
|
|
||||||
#define R_MIPS_GPREL16 7 /* GP-relative reference */
|
|
||||||
#define R_MIPS_LITERAL 8 /* Reference to literal section */
|
|
||||||
#define R_MIPS_GOT16 9 /* Reference to global offset table */
|
|
||||||
#define R_MIPS_GOT R_MIPS_GOT16
|
|
||||||
#define R_MIPS_PC16 10 /* 16 bit PC relative reference */
|
|
||||||
#define R_MIPS_CALL16 11 /* 16 bit call thru glbl offset tbl */
|
|
||||||
#define R_MIPS_CALL R_MIPS_CALL16
|
|
||||||
#define R_MIPS_GPREL32 12
|
|
||||||
|
|
||||||
/* 13, 14, 15 are not defined at this point. */
|
|
||||||
#define R_MIPS_UNUSED1 13
|
|
||||||
#define R_MIPS_UNUSED2 14
|
|
||||||
#define R_MIPS_UNUSED3 15
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The remaining relocs are apparently part of the 64-bit Irix ELF ABI.
|
|
||||||
*/
|
|
||||||
#define R_MIPS_SHIFT5 16
|
|
||||||
#define R_MIPS_SHIFT6 17
|
|
||||||
|
|
||||||
#define R_MIPS_64 18
|
|
||||||
#define R_MIPS_GOT_DISP 19
|
|
||||||
#define R_MIPS_GOT_PAGE 20
|
|
||||||
#define R_MIPS_GOT_OFST 21
|
|
||||||
#define R_MIPS_GOT_HI16 22
|
|
||||||
#define R_MIPS_GOT_LO16 23
|
|
||||||
#define R_MIPS_SUB 24
|
|
||||||
#define R_MIPS_INSERT_A 25
|
|
||||||
#define R_MIPS_INSERT_B 26
|
|
||||||
#define R_MIPS_DELETE 27
|
|
||||||
#define R_MIPS_HIGHER 28
|
|
||||||
#define R_MIPS_HIGHEST 29
|
|
||||||
#define R_MIPS_CALL_HI16 30
|
|
||||||
#define R_MIPS_CALL_LO16 31
|
|
||||||
#define R_MIPS_SCN_DISP 32
|
|
||||||
#define R_MIPS_REL16 33
|
|
||||||
#define R_MIPS_ADD_IMMEDIATE 34
|
|
||||||
#define R_MIPS_PJUMP 35
|
|
||||||
#define R_MIPS_RELGOT 36
|
|
||||||
|
|
||||||
#define R_MIPS_max 37
|
|
||||||
#define R_TYPE(name) __CONCAT(R_MIPS_,name)
|
|
||||||
|
|
||||||
|
|
||||||
/* mips dynamic tags */
|
|
||||||
|
|
||||||
#define DT_MIPS_RLD_VERSION 0x70000001
|
|
||||||
#define DT_MIPS_TIME_STAMP 0x70000002
|
|
||||||
#define DT_MIPS_ICHECKSUM 0x70000003
|
|
||||||
#define DT_MIPS_IVERSION 0x70000004
|
|
||||||
#define DT_MIPS_FLAGS 0x70000005
|
|
||||||
#define DT_MIPS_BASE_ADDRESS 0x70000006
|
|
||||||
#define DT_MIPS_CONFLICT 0x70000008
|
|
||||||
#define DT_MIPS_LIBLIST 0x70000009
|
|
||||||
#define DT_MIPS_CONFLICTNO 0x7000000b
|
|
||||||
#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* number of local got ents */
|
|
||||||
#define DT_MIPS_LIBLISTNO 0x70000010
|
|
||||||
#define DT_MIPS_SYMTABNO 0x70000011 /* number of .dynsym entries */
|
|
||||||
#define DT_MIPS_UNREFEXTNO 0x70000012
|
|
||||||
#define DT_MIPS_GOTSYM 0x70000013 /* first dynamic sym in got */
|
|
||||||
#define DT_MIPS_HIPAGENO 0x70000014
|
|
||||||
#define DT_MIPS_RLD_MAP 0x70000016 /* address of loader map */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Tell the kernel ELF exec code not to try relocating the interpreter
|
|
||||||
* (ld.so) for dynamically-linked ELF binaries.
|
|
||||||
*/
|
|
||||||
#ifdef _KERNEL
|
|
||||||
#define ELF_INTERP_NON_RELOCATABLE
|
|
||||||
#endif
|
|
||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o clock.o cons.o devcfg.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o clock.o cons.o devcfg.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS =
|
EXTRA_TARGETS =
|
||||||
|
|
||||||
DEFS += -DBUS_DIV=1
|
DEFS += -DBUS_DIV=1
|
||||||
@@ -41,9 +41,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DKERNEL
|
DEFS += -DKERNEL
|
||||||
DEFS += -DLED_DISK_PIN=0
|
DEFS += -DLED_DISK_PIN=0
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o glcd.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o oc.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o oc.o rd_sd.o rd_sramc.o rdisk.o signal.o spi.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS = bootloader
|
EXTRA_TARGETS = bootloader
|
||||||
|
|
||||||
DEFS += -DADC_ENABLED=YES
|
DEFS += -DADC_ENABLED=YES
|
||||||
@@ -16,11 +16,11 @@ DEFS += -DBL_CRYSTAL=8
|
|||||||
DEFS += -DBL_LED_PIN=5
|
DEFS += -DBL_LED_PIN=5
|
||||||
DEFS += -DBL_LED_PORT=TRISE
|
DEFS += -DBL_LED_PORT=TRISE
|
||||||
DEFS += -DBUS_DIV=1
|
DEFS += -DBUS_DIV=1
|
||||||
DEFS += -DBUS_KHZ=80000
|
DEFS += -DBUS_KHZ=120000
|
||||||
DEFS += -DCONSOLE_DEVICE=ttyUSB0
|
DEFS += -DCONSOLE_DEVICE=tty1
|
||||||
DEFS += -DCPU_IDIV=2
|
DEFS += -DCPU_IDIV=1
|
||||||
DEFS += -DCPU_KHZ=80000
|
DEFS += -DCPU_KHZ=120000
|
||||||
DEFS += -DCPU_MUL=20
|
DEFS += -DCPU_MUL=15
|
||||||
DEFS += -DCPU_ODIV=1
|
DEFS += -DCPU_ODIV=1
|
||||||
DEFS += -DCRYSTAL=8
|
DEFS += -DCRYSTAL=8
|
||||||
DEFS += -DDC0_DEBUG=DEVCFG0_DEBUG_DISABLED
|
DEFS += -DDC0_DEBUG=DEVCFG0_DEBUG_DISABLED
|
||||||
@@ -35,8 +35,8 @@ DEFS += -DDC1_POSCMOD=DEVCFG1_POSCMOD_HS
|
|||||||
DEFS += -DDC1_SOSC=0
|
DEFS += -DDC1_SOSC=0
|
||||||
DEFS += -DDC1_WDTEN=0
|
DEFS += -DDC1_WDTEN=0
|
||||||
DEFS += -DDC1_WDTPS=DEVCFG1_WDTPS_1
|
DEFS += -DDC1_WDTPS=DEVCFG1_WDTPS_1
|
||||||
DEFS += -DDC2_PLLIDIV=DEVCFG2_FPLLIDIV_2
|
DEFS += -DDC2_PLLIDIV=DEVCFG2_FPLLIDIV_1
|
||||||
DEFS += -DDC2_PLLMUL=DEVCFG2_FPLLMUL_20
|
DEFS += -DDC2_PLLMUL=DEVCFG2_FPLLMUL_15
|
||||||
DEFS += -DDC2_PLLODIV=DEVCFG2_FPLLODIV_1
|
DEFS += -DDC2_PLLODIV=DEVCFG2_FPLLODIV_1
|
||||||
DEFS += -DDC2_UPLL=0
|
DEFS += -DDC2_UPLL=0
|
||||||
DEFS += -DDC2_UPLLIDIV=DEVCFG2_UPLLIDIV_2
|
DEFS += -DDC2_UPLLIDIV=DEVCFG2_UPLLIDIV_2
|
||||||
@@ -47,11 +47,7 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DFLASH_JUMP=0x9d000000
|
DEFS += -DFLASH_JUMP=0x9d000000
|
||||||
DEFS += -DGLCD_ENABLED=YES
|
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
||||||
DEFS += -DHID_INPUT_REPORT_BYTES=2
|
DEFS += -DHID_INPUT_REPORT_BYTES=2
|
||||||
@@ -59,24 +55,36 @@ DEFS += -DHID_INT_IN_EP_SIZE=64
|
|||||||
DEFS += -DHID_INT_OUT_EP_SIZE=64
|
DEFS += -DHID_INT_OUT_EP_SIZE=64
|
||||||
DEFS += -DHID_OUTPUT_REPORT_BYTES=2
|
DEFS += -DHID_OUTPUT_REPORT_BYTES=2
|
||||||
DEFS += -DHID_RPT01_SIZE=29
|
DEFS += -DHID_RPT01_SIZE=29
|
||||||
|
DEFS += -DHZ=1000
|
||||||
DEFS += -DKERNEL
|
DEFS += -DKERNEL
|
||||||
DEFS += -DLED_KERNEL_PIN=5
|
DEFS += -DLED_KERNEL_PIN=5
|
||||||
DEFS += -DLED_KERNEL_PORT=TRISE
|
DEFS += -DLED_KERNEL_PORT=TRISE
|
||||||
|
DEFS += -DNBUF=8
|
||||||
|
DEFS += -DNMOUNT=3
|
||||||
|
DEFS += -DNPROC=25
|
||||||
DEFS += -DOC_ENABLED=YES
|
DEFS += -DOC_ENABLED=YES
|
||||||
|
DEFS += -DPARTITION="sramc0:sa@2048,fs@6140"
|
||||||
DEFS += -DPIC32MX7
|
DEFS += -DPIC32MX7
|
||||||
DEFS += -DSD0_CS_PIN=9
|
DEFS += -DSD0_CS_PIN=9
|
||||||
DEFS += -DSD0_CS_PORT=TRISG
|
DEFS += -DSD0_CS_PORT=TRISG
|
||||||
|
DEFS += -DSD0_MHZ=20
|
||||||
DEFS += -DSD0_PORT=2
|
DEFS += -DSD0_PORT=2
|
||||||
DEFS += -DUARTUSB_ENABLED=YES
|
DEFS += -DSPI_ENABLED=YES
|
||||||
|
DEFS += -DSRAMC0_ENABLED=YES
|
||||||
|
DEFS += -DSRAMC_ENABLED=YES
|
||||||
|
DEFS += -DUART1_BAUD=115200
|
||||||
|
DEFS += -DUART1_ENABLED=YES
|
||||||
|
DEFS += -DUART2_BAUD=115200
|
||||||
|
DEFS += -DUART2_ENABLED=YES
|
||||||
DEFS += -DUCB_METER
|
DEFS += -DUCB_METER
|
||||||
DEFS += -DUSB_EP0_BUFF_SIZE=8
|
DEFS += -DUSB_EP0_BUFF_SIZE=8
|
||||||
DEFS += -DUSB_MAX_EP_NUMBER=3
|
DEFS += -DUSB_MAX_EP_NUMBER=1
|
||||||
DEFS += -DUSB_NUM_STRING_DESCRIPTORS=3
|
DEFS += -DUSB_NUM_STRING_DESCRIPTORS=3
|
||||||
|
|
||||||
|
|
||||||
LDSCRIPT = ../../../tools/configsys/../../sys/pic32/cfg/bootloader.ld
|
LDSCRIPT = ../../../tools/configsys/../../sys/pic32/cfg/bootloader.ld
|
||||||
|
|
||||||
CONFIG = FUBARINO
|
CONFIG = FUBARINO-UART2CONS-UART1-SRAMC
|
||||||
CONFIGPATH = ../../../tools/configsys
|
CONFIGPATH = ../../../tools/configsys
|
||||||
|
|
||||||
include ../../../tools/configsys/../../sys/pic32/kernel-post.mk
|
include ../../../tools/configsys/../../sys/pic32/kernel-post.mk
|
||||||
|
|||||||
@@ -15,37 +15,18 @@ endif
|
|||||||
# MPLABX C32 compiler doesn't support some functionality
|
# MPLABX C32 compiler doesn't support some functionality
|
||||||
# we need, so use chipKIT compiler by default.
|
# we need, so use chipKIT compiler by default.
|
||||||
ifndef GCCPREFIX
|
ifndef GCCPREFIX
|
||||||
ifeq (/usr/local/pic32-tools/bin/pic32-gcc,$(wildcard /usr/local/pic32-tools/bin/pic32-gcc))
|
|
||||||
GCCPREFIX = /usr/local/pic32-tools/bin/pic32-
|
GCCPREFIX = /usr/local/pic32-tools/bin/pic32-
|
||||||
LDFLAGS = -Wl,--oformat=elf32-tradlittlemips
|
LDFLAGS = -Wl,--oformat=elf32-tradlittlemips
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
# Generic MIPS toolchain
|
# Generic MIPS toolchain
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# You can build it from sources, as described on page
|
# You can build it from sources, as described on page
|
||||||
# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips
|
# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips
|
||||||
ifndef GCCPREFIX
|
ifndef GCCPREFIX
|
||||||
ifeq (/usr/local/mips-gcc-4.7.2/bin/mips-elf-gcc,$(wildcard /usr/local/mips-gcc-4.7.2/bin/mips-elf-gcc))
|
|
||||||
GCCPREFIX = /usr/local/mips-gcc-4.7.2/bin/mips-elf-
|
GCCPREFIX = /usr/local/mips-gcc-4.7.2/bin/mips-elf-
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
# Mentor Sourcery CodeBench Lite toolchain
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
# You can download a Linux or Windows binary package from
|
|
||||||
# https://sourcery.mentor.com/GNUToolchain/release2641
|
|
||||||
ifndef GCCPREFIX
|
|
||||||
ifeq (/usr/local/mips-2013.11/bin/mips-sde-elf-gcc,$(wildcard /usr/local/mips-2013.11/bin/mips-sde-elf-gcc))
|
|
||||||
GCCPREFIX = /usr/local/mips-2013.11/bin/mips-sde-elf-
|
|
||||||
LDFLAGS = -Wl,--oformat=elf32-tradlittlemips
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifndef GCCPREFIX
|
|
||||||
$(error Unable to locate any GCC MIPS toolchain!)
|
|
||||||
endif
|
|
||||||
|
|
||||||
# chipKIT MPIDE on Mac OS X
|
# chipKIT MPIDE on Mac OS X
|
||||||
ifneq (,$(wildcard /Applications/Mpide.app/Contents/Resources/Java/hardware/tools/avr))
|
ifneq (,$(wildcard /Applications/Mpide.app/Contents/Resources/Java/hardware/tools/avr))
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS =
|
EXTRA_TARGETS =
|
||||||
|
|
||||||
DEFS += -DADC_ENABLED=YES
|
DEFS += -DADC_ENABLED=YES
|
||||||
@@ -42,9 +42,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DKERNEL
|
DEFS += -DKERNEL
|
||||||
DEFS += -DLED_KERNEL_PIN=3
|
DEFS += -DLED_KERNEL_PIN=3
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS =
|
EXTRA_TARGETS =
|
||||||
|
|
||||||
DEFS += -DADC_ENABLED=YES
|
DEFS += -DADC_ENABLED=YES
|
||||||
@@ -42,9 +42,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DKERNEL
|
DEFS += -DKERNEL
|
||||||
DEFS += -DLED_DISK_PIN=10
|
DEFS += -DLED_DISK_PIN=10
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS = bootloader
|
EXTRA_TARGETS = bootloader
|
||||||
|
|
||||||
DEFS += -DBL_BUTTON_PIN=13
|
DEFS += -DBL_BUTTON_PIN=13
|
||||||
@@ -47,9 +47,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DFLASH_USER=0x1d003000
|
DEFS += -DFLASH_USER=0x1d003000
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o clock.o cons.o devcfg.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o clock.o cons.o devcfg.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS =
|
EXTRA_TARGETS =
|
||||||
|
|
||||||
DEFS += -DBUS_DIV=1
|
DEFS += -DBUS_DIV=1
|
||||||
@@ -41,9 +41,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DKERNEL
|
DEFS += -DKERNEL
|
||||||
DEFS += -DLED_DISK_PIN=1
|
DEFS += -DLED_DISK_PIN=1
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS = bootloader
|
EXTRA_TARGETS = bootloader
|
||||||
|
|
||||||
DEFS += -DADC_ENABLED=YES
|
DEFS += -DADC_ENABLED=YES
|
||||||
@@ -56,9 +56,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DFLASH_JUMP=0x9d000000
|
DEFS += -DFLASH_JUMP=0x9d000000
|
||||||
DEFS += -DGPIO_CLEAR_PIN=2
|
DEFS += -DGPIO_CLEAR_PIN=2
|
||||||
DEFS += -DGPIO_CLEAR_PORT=TRISD
|
DEFS += -DGPIO_CLEAR_PORT=TRISD
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS = bootloader
|
EXTRA_TARGETS = bootloader
|
||||||
|
|
||||||
DEFS += -DADC_ENABLED=YES
|
DEFS += -DADC_ENABLED=YES
|
||||||
@@ -46,9 +46,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DFLASH_USER=0x1d005000
|
DEFS += -DFLASH_USER=0x1d005000
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
*
|
*
|
||||||
* This version is for 8MB RAMDISK v.1.1 and compatible
|
* This version is for 8MB RAMDISK v.1.1 and compatible
|
||||||
* Pito 7.4.2014 - PIC32MX PMP bus version
|
* Pito 7.4.2014 - PIC32MX PMP bus version
|
||||||
|
* Pito 28.4.2014 - Mod for 2 Units
|
||||||
* Under by retrobsd.org used Licence
|
* Under by retrobsd.org used Licence
|
||||||
* No warranties of any kind
|
* No warranties of any kind
|
||||||
*
|
*
|
||||||
@@ -29,23 +30,29 @@
|
|||||||
|
|
||||||
int sw_dkn = -1; /* Statistics slot number */
|
int sw_dkn = -1; /* Statistics slot number */
|
||||||
|
|
||||||
// Ramdisk v.1.1. wiring
|
// 8MB Ramdisk v.1.1. wiring
|
||||||
// PMP RAMDISK
|
// PMP RAMDISK
|
||||||
// ===================
|
// ===================
|
||||||
// PMD<D0-D7> D0-D7
|
// PMD<D0-D7> D0-D7
|
||||||
// PMRD /RD
|
// PMRD /RD
|
||||||
// PMWR /WR
|
// PMWR /WR
|
||||||
// PMA<0> /DATA
|
// PMA<0> /DATA
|
||||||
|
// PMA<1> 0-Unit0
|
||||||
|
// PMA<10> 0-Unit1
|
||||||
|
|
||||||
|
//#define NDATA (1<<0)
|
||||||
|
//#define UNIT0 (1<<1)
|
||||||
|
//#define UNIT1 (1<<10)
|
||||||
|
|
||||||
// RD and WR pulses duration settings
|
// RD and WR pulses duration settings
|
||||||
// Minimal recommended settings, increase them when unstable
|
// Minimal recommended settings, increase them when unstable
|
||||||
// No warranties of any kind
|
// No warranties of any kind
|
||||||
// for 120MHz clock, 70ns PSRAM, Ramdisk v.1.1.
|
// for 120MHz clock, 70ns PSRAM, 8MB Ramdisk v.1.1.
|
||||||
#define ADR_PULSE 1
|
#define ADR_PULSE 1
|
||||||
#define WR_PULSE 5
|
#define WR_PULSE 5
|
||||||
#define RD_PULSE 11
|
#define RD_PULSE 11
|
||||||
|
|
||||||
// for 80MHz clock, 70ns PSRAM, Ramdisk v.1.1.
|
// for 80MHz clock, 70ns PSRAM, 8MB Ramdisk v.1.1.
|
||||||
//#define ADR_PULSE 1
|
//#define ADR_PULSE 1
|
||||||
//#define WR_PULSE 3
|
//#define WR_PULSE 3
|
||||||
//#define RD_PULSE 8
|
//#define RD_PULSE 8
|
||||||
@@ -61,35 +68,31 @@ int sw_dkn = -1; /* Statistics slot number */
|
|||||||
//#define RD_PULSE 4
|
//#define RD_PULSE 4
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
unsigned value;
|
unsigned int value;
|
||||||
struct {
|
struct {
|
||||||
unsigned nib1: 4; // lowest nibble
|
unsigned nib1: 4; // lowest nibble
|
||||||
unsigned nib2: 4;
|
unsigned nib2: 4;
|
||||||
unsigned nib3: 4;
|
unsigned nib3: 4;
|
||||||
unsigned nib4: 4;
|
unsigned nib4: 4;
|
||||||
unsigned nib5: 4;
|
unsigned nib5: 4;
|
||||||
unsigned nib6: 4;
|
unsigned nib6: 4;
|
||||||
unsigned nib7: 4;
|
unsigned nib7: 4;
|
||||||
unsigned nib8: 4; // highest nibble
|
unsigned nib8: 4; // highest nibble
|
||||||
};
|
};
|
||||||
} nybbles ;
|
} nybbles;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load the 24 bit address to Ramdisk.
|
* Load the 24 bit address to Ramdisk.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
inline static void
|
inline static void dev_load_address (unsigned int addr)
|
||||||
dev_load_address (addr)
|
|
||||||
unsigned addr;
|
|
||||||
{
|
{
|
||||||
nybbles temp;
|
nybbles temp;
|
||||||
temp.value = addr;
|
temp.value = addr;
|
||||||
|
|
||||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||||
|
|
||||||
PMADDR = 1; // set ADR mode (1) to write the Address
|
|
||||||
|
|
||||||
PMMODE = 0b10<<8 | (ADR_PULSE<<2); // full ADR speed
|
PMMODE = 0b10<<8 | (ADR_PULSE<<2); // full ADR speed
|
||||||
|
|
||||||
PMDIN = temp.nib6; /* write 4 bits */
|
PMDIN = temp.nib6; /* write 4 bits */
|
||||||
@@ -108,7 +111,6 @@ dev_load_address (addr)
|
|||||||
|
|
||||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||||
PMDIN = temp.nib1; /* write 4 bits */
|
PMDIN = temp.nib1; /* write 4 bits */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -117,64 +119,82 @@ dev_load_address (addr)
|
|||||||
*/
|
*/
|
||||||
int sramc_size ( int unit )
|
int sramc_size ( int unit )
|
||||||
{
|
{
|
||||||
return 8192; // 4096 for 4MB ramdisk
|
int srsize;
|
||||||
|
|
||||||
|
switch (unit) {
|
||||||
|
case 0: srsize = 8192; break;
|
||||||
|
case 1: srsize = 8192; break;
|
||||||
|
}
|
||||||
|
return srsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read a block of data.
|
* Read a block of data.
|
||||||
*/
|
*/
|
||||||
inline int sramc_read (int unit, unsigned int blockno, char *data, unsigned int nbytes)
|
inline int sramc_read (int unit, unsigned int blockno, register char *data, register unsigned int nbytes)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
//DEBUG9("sramc%d: read block %u, length %u bytes, addr %p\n",
|
//printf("sramc%d: rd blockno %u, nbytes %u, addr %p\n", unit, blockno, nbytes, data);
|
||||||
// major(dev), blockno, nbytes, data);
|
|
||||||
|
|
||||||
dev_load_address (blockno * DEV_BSIZE);
|
|
||||||
|
|
||||||
/* Read data. */
|
|
||||||
|
|
||||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||||
|
|
||||||
PMADDR = 0; // set DATA mode (0)
|
switch (unit) {
|
||||||
|
// set Unit address and ADDRESS mode (1)
|
||||||
|
case 0: PMADDR = 0b10000000001; break;
|
||||||
|
case 1: PMADDR = 0b00000000011; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_load_address (blockno * DEV_BSIZE);
|
||||||
|
|
||||||
|
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||||
|
|
||||||
PMMODE = 0b10<<8 | (RD_PULSE<<2); // read slowly
|
PMMODE = 0b10<<8 | (RD_PULSE<<2); // read slowly
|
||||||
|
|
||||||
|
PMADDR = PMADDR & 0b10000000010; // set DATA mode
|
||||||
|
|
||||||
PMDIN; // Read the PMDIN to clear previous data and latch new data
|
PMDIN; // Read the PMDIN to clear previous data and latch new data
|
||||||
|
|
||||||
for (i=0; i<nbytes; i++) {
|
while (nbytes--) {
|
||||||
while(PMMODE & 0x8000); // Poll - if busy, wait before reading
|
while(PMMODE & 0x8000); // Poll - if busy, wait before reading
|
||||||
*data++ = PMDIN; /* read a byte of data */
|
*data++ = PMDIN; /* read a byte of data */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||||
|
PMADDR = 0b10000000011; // deselect
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write a block of data.
|
* Write a block of data.
|
||||||
*/
|
*/
|
||||||
inline int sramc_write (int unit, unsigned int blockno, char *data, unsigned int nbytes)
|
inline int sramc_write (int unit, unsigned int blockno, register char *data, register unsigned int nbytes)
|
||||||
{
|
{
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
//DEBUG9("sramc%d: write block %u, length %u bytes, addr %p\n",
|
//printf("sramc%d: wr blockno %u, nbytes %u , addr %p\n", unit, blockno, nbytes, data);
|
||||||
// major(dev), blockno, nbytes, data);
|
|
||||||
|
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||||
|
|
||||||
|
switch (unit) {
|
||||||
|
// set Unit address and ADDRESS mode (1)
|
||||||
|
case 0: PMADDR = 0b10000000001; break;
|
||||||
|
case 1: PMADDR = 0b00000000011; break;
|
||||||
|
}
|
||||||
|
|
||||||
dev_load_address (blockno * DEV_BSIZE);
|
dev_load_address (blockno * DEV_BSIZE);
|
||||||
|
|
||||||
/* Write data. */
|
|
||||||
|
|
||||||
while (PMMODE & 0x8000); // Poll - if busy, wait
|
while (PMMODE & 0x8000); // Poll - if busy, wait
|
||||||
|
|
||||||
PMADDR = 0; // set DATA mode (0)
|
|
||||||
|
|
||||||
PMMODE = 0b10<<8 | (WR_PULSE<<2); // faster with write
|
PMMODE = 0b10<<8 | (WR_PULSE<<2); // faster with write
|
||||||
|
|
||||||
for (i=0; i<nbytes; i++) {
|
PMADDR = PMADDR & 0b10000000010; // set DATA mode
|
||||||
while(PMMODE & 0x8000); // Poll - if busy, wait
|
|
||||||
PMDIN = (*data++); /* write a byte of data */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
while(nbytes--) {
|
||||||
|
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||||
|
PMDIN = (*data++); /* write a byte of data*/
|
||||||
|
}
|
||||||
|
|
||||||
|
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||||
|
PMADDR = 0b10000000011; // deselect
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +204,8 @@ inline int sramc_write (int unit, unsigned int blockno, char *data, unsigned int
|
|||||||
*/
|
*/
|
||||||
void sramc_init (int unit)
|
void sramc_init (int unit)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// printf("ramdisk%d: init\n",unit);
|
||||||
struct buf *bp;
|
struct buf *bp;
|
||||||
|
|
||||||
// Initialize PMP hardware
|
// Initialize PMP hardware
|
||||||
@@ -196,31 +218,50 @@ void sramc_init (int unit)
|
|||||||
// MODE WAITB WAITM WAITE
|
// MODE WAITB WAITM WAITE
|
||||||
PMMODE = 0b10<<8 | 0 | (14<<2) | 0 ; // Mode2 Master 8bit
|
PMMODE = 0b10<<8 | 0 | (14<<2) | 0 ; // Mode2 Master 8bit
|
||||||
|
|
||||||
PMAEN = 1; // PMA<0>, use A0 only
|
PMAEN = 0b10000000011; // PMA<>, use A10,A1,A0
|
||||||
|
|
||||||
PMADDR = 0; // start with DATA mode
|
PMADDR = 0b10000000010; // start with DATA mode
|
||||||
|
|
||||||
PMCONSET = 1<<15; // PMP enabled
|
PMCONSET = 1<<15; // PMP enabled
|
||||||
asm volatile ("nop");
|
asm volatile ("nop");
|
||||||
|
|
||||||
// make a couple of dummy reads - it refreshes the cpld internals a little bit :)
|
// make a couple of dummy reads - it refreshes the cpld internals a little bit :)
|
||||||
while(PMMODE & 0x8000); // Poll - if busy, wait before reading
|
switch (unit) {
|
||||||
PMDIN; /* read a byte of data */
|
|
||||||
while(PMMODE & 0x8000); // Poll - if busy, wait before reading
|
case 0: PMADDR = 0b10000000000; // start with DATA mode
|
||||||
PMDIN; /* read a byte of data */
|
while(PMMODE & 0x8000); // Poll - if busy, wait before reading
|
||||||
|
PMDIN; /* read a byte of data */
|
||||||
|
while(PMMODE & 0x8000); // Poll - if busy, wait before reading
|
||||||
|
PMDIN; /* read a byte of data */
|
||||||
|
|
||||||
|
bp = prepartition_device("sramc0");
|
||||||
|
|
||||||
PMADDR = 1; // go with with ADDRESS mode now
|
if(bp) {
|
||||||
|
|
||||||
|
|
||||||
DEBUG3("sramc%d: init done\n",unit);
|
|
||||||
bp = prepartition_device("sramc0");
|
|
||||||
if(bp)
|
|
||||||
{
|
|
||||||
sramc_write(0, 0, bp->b_addr, 512);
|
sramc_write(0, 0, bp->b_addr, 512);
|
||||||
brelse(bp);
|
brelse(bp);
|
||||||
}
|
}
|
||||||
|
// printf("sramc%d: init done\n",unit);
|
||||||
|
break;
|
||||||
|
|
||||||
return;
|
|
||||||
|
case 1: PMADDR = 0b00000000010; // start with DATA mode
|
||||||
|
while(PMMODE & 0x8000); // Poll - if busy, wait before reading
|
||||||
|
PMDIN; /* read a byte of data */
|
||||||
|
while(PMMODE & 0x8000); // Poll - if busy, wait before reading
|
||||||
|
PMDIN; /* read a byte of data */
|
||||||
|
|
||||||
|
bp = prepartition_device("sramc1");
|
||||||
|
|
||||||
|
if(bp) {
|
||||||
|
sramc_write(1, 0, bp->b_addr, 512);
|
||||||
|
brelse(bp);
|
||||||
|
}
|
||||||
|
// printf("sramc%d: init done\n",unit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(PMMODE & 0x8000); // Poll - if busy, wait
|
||||||
|
PMADDR = 0b10000000011; // go with with ADDRESS mode
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -228,6 +269,6 @@ void sramc_init (int unit)
|
|||||||
*/
|
*/
|
||||||
int sramc_open (int unit)
|
int sramc_open (int unit)
|
||||||
{
|
{
|
||||||
DEBUG3("sramc%d: open\n",unit);
|
// printf("sramc%d: open done\n",unit);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,12 +44,16 @@ int spi_open(unsigned int bus, unsigned int *tris, unsigned int pin)
|
|||||||
case 2:
|
case 2:
|
||||||
spi_devices[dno].bus = (struct spireg *)&SPI2CON;
|
spi_devices[dno].bus = (struct spireg *)&SPI2CON;
|
||||||
break;
|
break;
|
||||||
|
#ifdef SPI3CON
|
||||||
case 3:
|
case 3:
|
||||||
spi_devices[dno].bus = (struct spireg *)&SPI3CON;
|
spi_devices[dno].bus = (struct spireg *)&SPI3CON;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef SPI4CON
|
||||||
case 4:
|
case 4:
|
||||||
spi_devices[dno].bus = (struct spireg *)&SPI4CON;
|
spi_devices[dno].bus = (struct spireg *)&SPI4CON;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -103,7 +107,7 @@ void spi_close(int dno)
|
|||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (spi_devices[dno].cs_tris != NULL) {
|
if (spi_devices[dno].cs_tris != NULL) {
|
||||||
// Revert the CS pin to input.
|
// Revert the CS pin to input.
|
||||||
TRIS_CLR(*spi_devices[dno].cs_tris) = 1<<spi_devices[dno].cs_pin;
|
TRIS_CLR(*spi_devices[dno].cs_tris) = 1<<spi_devices[dno].cs_pin;
|
||||||
@@ -121,11 +125,11 @@ void spi_select(int dno)
|
|||||||
{
|
{
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (spi_devices[dno].cs_tris == NULL)
|
if (spi_devices[dno].cs_tris == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
spi_devices[dno].bus->brg = spi_devices[dno].baud;
|
spi_devices[dno].bus->brg = spi_devices[dno].baud;
|
||||||
@@ -139,11 +143,11 @@ void spi_deselect(int dno)
|
|||||||
{
|
{
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (spi_devices[dno].cs_tris == NULL)
|
if (spi_devices[dno].cs_tris == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LAT_SET(*spi_devices[dno].cs_tris) = 1<<spi_devices[dno].cs_pin;
|
LAT_SET(*spi_devices[dno].cs_tris) = 1<<spi_devices[dno].cs_pin;
|
||||||
@@ -155,10 +159,10 @@ void spi_set(int dno, unsigned int set)
|
|||||||
{
|
{
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
spi_devices[dno].mode |= set;
|
spi_devices[dno].mode |= set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,10 +172,10 @@ void spi_clr(int dno, unsigned int set)
|
|||||||
{
|
{
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
spi_devices[dno].mode &= ~set;
|
spi_devices[dno].mode &= ~set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,10 +185,10 @@ unsigned int spi_status(int dno)
|
|||||||
{
|
{
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return spi_devices[dno].bus->stat;
|
return spi_devices[dno].bus->stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +203,7 @@ unsigned char spi_transfer(int dno, unsigned char data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return 0xF0;
|
return 0xF0;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return 0xF1;
|
return 0xF1;
|
||||||
|
|
||||||
@@ -229,10 +233,10 @@ void spi_bulk_write_32_be(int dno, unsigned int len, char *data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
nread = 0;
|
nread = 0;
|
||||||
nwritten = words;
|
nwritten = words;
|
||||||
|
|
||||||
@@ -245,7 +249,7 @@ void spi_bulk_write_32_be(int dno, unsigned int len, char *data)
|
|||||||
nwritten--;
|
nwritten--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
||||||
{
|
{
|
||||||
(void) spi_devices[dno].bus->buf;
|
(void) spi_devices[dno].bus->buf;
|
||||||
nread++;
|
nread++;
|
||||||
@@ -263,10 +267,10 @@ void spi_bulk_write_32(int dno, unsigned int len, char *data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
nread = 0;
|
nread = 0;
|
||||||
nwritten = words;
|
nwritten = words;
|
||||||
|
|
||||||
@@ -279,7 +283,7 @@ void spi_bulk_write_32(int dno, unsigned int len, char *data)
|
|||||||
nwritten--;
|
nwritten--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
||||||
{
|
{
|
||||||
(void) spi_devices[dno].bus->buf;
|
(void) spi_devices[dno].bus->buf;
|
||||||
nread++;
|
nread++;
|
||||||
@@ -297,10 +301,10 @@ void spi_bulk_write_16(int dno, unsigned int len, char *data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
nread = 0;
|
nread = 0;
|
||||||
nwritten = words;
|
nwritten = words;
|
||||||
|
|
||||||
@@ -313,7 +317,7 @@ void spi_bulk_write_16(int dno, unsigned int len, char *data)
|
|||||||
nwritten--;
|
nwritten--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
||||||
{
|
{
|
||||||
(void) spi_devices[dno].bus->buf;
|
(void) spi_devices[dno].bus->buf;
|
||||||
nread++;
|
nread++;
|
||||||
@@ -326,18 +330,18 @@ void spi_bulk_write(int dno, unsigned int len, unsigned char *data)
|
|||||||
{
|
{
|
||||||
unsigned char *data8 = data;
|
unsigned char *data8 = data;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned char out;
|
unsigned char in,out;
|
||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(i=0; i<len; i++)
|
for(i=0; i<len; i++)
|
||||||
{
|
{
|
||||||
out = *data8;
|
out = *data8;
|
||||||
spi_transfer(dno, out);
|
in = spi_transfer(dno, out);
|
||||||
data8++;
|
data8++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,7 +359,7 @@ void spi_bulk_read_32_be(int dno, unsigned int len, char *data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -371,7 +375,7 @@ void spi_bulk_read_32_be(int dno, unsigned int len, char *data)
|
|||||||
nwritten--;
|
nwritten--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
||||||
{
|
{
|
||||||
*data32++ = mips_bswap(spi_devices[dno].bus->buf);
|
*data32++ = mips_bswap(spi_devices[dno].bus->buf);
|
||||||
nread++;
|
nread++;
|
||||||
@@ -389,7 +393,7 @@ void spi_bulk_read_32(int dno, unsigned int len, char *data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -405,7 +409,7 @@ void spi_bulk_read_32(int dno, unsigned int len, char *data)
|
|||||||
nwritten--;
|
nwritten--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
||||||
{
|
{
|
||||||
*data32++ = spi_devices[dno].bus->buf;
|
*data32++ = spi_devices[dno].bus->buf;
|
||||||
nread++;
|
nread++;
|
||||||
@@ -423,7 +427,7 @@ void spi_bulk_read_16(int dno, unsigned int len, char *data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -439,7 +443,7 @@ void spi_bulk_read_16(int dno, unsigned int len, char *data)
|
|||||||
nwritten--;
|
nwritten--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
||||||
{
|
{
|
||||||
*data16++ = mips_bswap(spi_devices[dno].bus->buf);
|
*data16++ = mips_bswap(spi_devices[dno].bus->buf);
|
||||||
nread++;
|
nread++;
|
||||||
@@ -456,7 +460,7 @@ void spi_bulk_read(int dno, unsigned int len, unsigned char *data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -479,7 +483,7 @@ void spi_bulk_rw_32_be(int dno, unsigned int len, char *data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -495,7 +499,7 @@ void spi_bulk_rw_32_be(int dno, unsigned int len, char *data)
|
|||||||
nwritten--;
|
nwritten--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
||||||
{
|
{
|
||||||
*read32++ = mips_bswap(spi_devices[dno].bus->buf);
|
*read32++ = mips_bswap(spi_devices[dno].bus->buf);
|
||||||
nread++;
|
nread++;
|
||||||
@@ -514,7 +518,7 @@ void spi_bulk_rw_32(int dno, unsigned int len, char *data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -530,7 +534,7 @@ void spi_bulk_rw_32(int dno, unsigned int len, char *data)
|
|||||||
nwritten--;
|
nwritten--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
||||||
{
|
{
|
||||||
*read32++ = spi_devices[dno].bus->buf;
|
*read32++ = spi_devices[dno].bus->buf;
|
||||||
nread++;
|
nread++;
|
||||||
@@ -549,7 +553,7 @@ void spi_bulk_rw_16(int dno, unsigned int len, char *data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -565,7 +569,7 @@ void spi_bulk_rw_16(int dno, unsigned int len, char *data)
|
|||||||
nwritten--;
|
nwritten--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
if(!(spi_devices[dno].bus->stat & PIC32_SPISTAT_SPIRBE))
|
||||||
{
|
{
|
||||||
*read16++ = mips_bswap(spi_devices[dno].bus->buf);
|
*read16++ = mips_bswap(spi_devices[dno].bus->buf);
|
||||||
nread++;
|
nread++;
|
||||||
@@ -582,7 +586,7 @@ void spi_bulk_rw(int dno, unsigned int len, unsigned char *data)
|
|||||||
|
|
||||||
if(dno >= MAXSPIDEV)
|
if(dno >= MAXSPIDEV)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(spi_devices[dno].bus==NULL)
|
if(spi_devices[dno].bus==NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -624,11 +628,14 @@ char *spi_name(int dno)
|
|||||||
if(spi_devices[dno].bus == (struct spireg *)&SPI2CON)
|
if(spi_devices[dno].bus == (struct spireg *)&SPI2CON)
|
||||||
return "SPI2";
|
return "SPI2";
|
||||||
|
|
||||||
|
#ifdef SPI3CON
|
||||||
if(spi_devices[dno].bus == (struct spireg *)&SPI3CON)
|
if(spi_devices[dno].bus == (struct spireg *)&SPI3CON)
|
||||||
return "SPI3";
|
return "SPI3";
|
||||||
|
#endif
|
||||||
|
#ifdef SPI4CON
|
||||||
if(spi_devices[dno].bus == (struct spireg *)&SPI4CON)
|
if(spi_devices[dno].bus == (struct spireg *)&SPI4CON)
|
||||||
return "SPI4";
|
return "SPI4";
|
||||||
|
#endif
|
||||||
|
|
||||||
return "SPI?";
|
return "SPI?";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o adc.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS = bootloader
|
EXTRA_TARGETS = bootloader
|
||||||
|
|
||||||
DEFS += -DADC_ENABLED=YES
|
DEFS += -DADC_ENABLED=YES
|
||||||
@@ -52,9 +52,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DFLASH_JUMP=0x9d000000
|
DEFS += -DFLASH_JUMP=0x9d000000
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rd_sdramp.o rdisk.o sdram.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rd_sdramp.o rdisk.o sdram.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS = bootloader
|
EXTRA_TARGETS = bootloader
|
||||||
|
|
||||||
DEFS += -DBL_BUTTON_PIN=7
|
DEFS += -DBL_BUTTON_PIN=7
|
||||||
@@ -52,9 +52,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DFLASH_USER=0x1d005000
|
DEFS += -DFLASH_USER=0x1d005000
|
||||||
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
||||||
DEFS += -DHID_INPUT_REPORT_BYTES=2
|
DEFS += -DHID_INPUT_REPORT_BYTES=2
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o uart.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS = bootloader
|
EXTRA_TARGETS = bootloader
|
||||||
|
|
||||||
DEFS += -DBL_BUTTON_PIN=7
|
DEFS += -DBL_BUTTON_PIN=7
|
||||||
@@ -52,9 +52,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DFLASH_USER=0x1d005000
|
DEFS += -DFLASH_USER=0x1d005000
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ S = ../../../tools/configsys/../../sys/kernel
|
|||||||
vpath %.c $(M):$(S)
|
vpath %.c $(M):$(S)
|
||||||
vpath %.S $(M):$(S)
|
vpath %.S $(M):$(S)
|
||||||
|
|
||||||
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o exec_aout.o exec_conf.o exec_elf.o exec_script.o exec_subr.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
KERNOBJ += _startup.o clock.o cons.o devsw.o exception.o gpio.o init_main.o init_sysent.o kern_clock.o kern_descrip.o kern_exec.o kern_exit.o kern_fork.o kern_mman.o kern_proc.o kern_prot.o kern_prot2.o kern_resource.o kern_sig.o kern_sig2.o kern_subr.o kern_synch.o kern_sysctl.o kern_time.o machdep.o mem.o rd_sd.o rdisk.o signal.o spi_bus.o subr_prf.o subr_rmap.o swap.o sys_generic.o sys_inode.o sys_pipe.o sys_process.o syscalls.o sysctl.o tty.o tty_subr.o tty_tty.o ufs_alloc.o ufs_bio.o ufs_bmap.o ufs_dsort.o ufs_fio.o ufs_inode.o ufs_mount.o ufs_namei.o ufs_subr.o ufs_syscalls.o ufs_syscalls2.o usb_device.o usb_function_cdc.o usb_uart.o vers.o vfs_vnops.o vm_sched.o vm_swap.o vm_swp.o
|
||||||
EXTRA_TARGETS = bootloader
|
EXTRA_TARGETS = bootloader
|
||||||
|
|
||||||
DEFS += -DBL_BUTTON_PIN=7
|
DEFS += -DBL_BUTTON_PIN=7
|
||||||
@@ -52,9 +52,6 @@ DEFS += -DDC3_SRS=DEVCFG3_FSRSSEL_7
|
|||||||
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
DEFS += -DDC3_USBID=DEVCFG3_FUSBIDIO
|
||||||
DEFS += -DDC3_USERID=0xffff
|
DEFS += -DDC3_USERID=0xffff
|
||||||
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
DEFS += -DDC3_VBUSON=DEVCFG3_FVBUSONIO
|
||||||
DEFS += -DEXEC_AOUT
|
|
||||||
DEFS += -DEXEC_ELF
|
|
||||||
DEFS += -DEXEC_SCRIPT
|
|
||||||
DEFS += -DFLASH_USER=0x1d005000
|
DEFS += -DFLASH_USER=0x1d005000
|
||||||
DEFS += -DGPIO_ENABLED=YES
|
DEFS += -DGPIO_ENABLED=YES
|
||||||
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
DEFS += -DHID_FEATURE_REPORT_BYTES=2
|
||||||
|
|||||||
24
target.mk
24
target.mk
@@ -1,5 +1,5 @@
|
|||||||
MACHINE = mips
|
MACHINE = mips
|
||||||
DESTDIR ?= $(TOPSRC)
|
DESTDIR ?= $(TOPSRC)
|
||||||
RELEASE = 0.0
|
RELEASE = 0.0
|
||||||
BUILD = $(shell git rev-list HEAD --count)
|
BUILD = $(shell git rev-list HEAD --count)
|
||||||
VERSION = $(RELEASE)-$(BUILD)
|
VERSION = $(RELEASE)-$(BUILD)
|
||||||
@@ -22,40 +22,20 @@ endif
|
|||||||
# MPLABX C32 compiler doesn't support some functionality
|
# MPLABX C32 compiler doesn't support some functionality
|
||||||
# we need, so use chipKIT compiler by default.
|
# we need, so use chipKIT compiler by default.
|
||||||
ifndef GCCPREFIX
|
ifndef GCCPREFIX
|
||||||
ifeq (/usr/local/pic32-tools/bin/pic32-gcc,$(wildcard /usr/local/pic32-tools/bin/pic32-gcc))
|
|
||||||
GCCPREFIX = /usr/local/pic32-tools/bin/pic32-
|
GCCPREFIX = /usr/local/pic32-tools/bin/pic32-
|
||||||
LDFLAGS = -Wl,--oformat=elf32-tradlittlemips
|
LDFLAGS = -Wl,--oformat=elf32-tradlittlemips
|
||||||
INCLUDES = -I/usr/local/pic32-tools/lib/gcc/pic32mx/4.5.1/include
|
INCLUDES = -I/usr/local/pic32-tools/lib/gcc/pic32mx/4.5.1/include
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
# Generic MIPS toolchain
|
# Generic MIPS toolchain
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# You can build it from sources, as described on page
|
# You can build it from sources, as described on page
|
||||||
# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips
|
# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips
|
||||||
ifndef GCCPREFIX
|
ifndef GCCPREFIX
|
||||||
ifeq (/usr/local/mips-gcc-4.7.2/bin/mips-elf-gcc,$(wildcard /usr/local/mips-gcc-4.7.2/bin/mips-elf-gcc))
|
|
||||||
GCCPREFIX = /usr/local/mips-gcc-4.7.2/bin/mips-elf-
|
GCCPREFIX = /usr/local/mips-gcc-4.7.2/bin/mips-elf-
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
INCLUDES =
|
INCLUDES =
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
# Mentor Sourcery CodeBench Lite toolchain
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
# You can download a Linux or Windows binary package from
|
|
||||||
# https://sourcery.mentor.com/GNUToolchain/release2641
|
|
||||||
ifndef GCCPREFIX
|
|
||||||
ifeq (/usr/local/mips-2013.11/bin/mips-sde-elf-gcc,$(wildcard /usr/local/mips-2013.11/bin/mips-sde-elf-gcc))
|
|
||||||
GCCPREFIX = /usr/local/mips-2013.11/bin/mips-sde-elf-
|
|
||||||
LDFLAGS = -Wl,--oformat=elf32-tradlittlemips
|
|
||||||
INCLUDES =
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifndef GCCPREFIX
|
|
||||||
$(error Unable to locate any GCC MIPS toolchain!)
|
|
||||||
endif
|
|
||||||
|
|
||||||
CC = $(GCCPREFIX)gcc -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES)
|
CC = $(GCCPREFIX)gcc -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES)
|
||||||
CXX = $(GCCPREFIX)g++ -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES)
|
CXX = $(GCCPREFIX)g++ -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES)
|
||||||
|
|||||||
@@ -361,16 +361,15 @@ usage: fprintf(stderr,
|
|||||||
for (i = 0; i < ex.e_phnum; i++) {
|
for (i = 0; i < ex.e_phnum; i++) {
|
||||||
/* Section types we can ignore... */
|
/* Section types we can ignore... */
|
||||||
if (ph[i].p_type == PT_NULL || ph[i].p_type == PT_NOTE ||
|
if (ph[i].p_type == PT_NULL || ph[i].p_type == PT_NOTE ||
|
||||||
ph[i].p_type == PT_PHDR || ph[i].p_type == PT_MIPS_REGINFO ||
|
ph[i].p_type == PT_PHDR || ph[i].p_type == PT_MIPS_REGINFO)
|
||||||
ph[i].p_type == PT_GNU_EH_FRAME)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* Section types we can't handle... */
|
||||||
|
if (ph[i].p_type != PT_LOAD)
|
||||||
|
errx(1, "Program header %d type %d can't be converted.", i, ph[i].p_type);
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf ("Section type=%x flags=%x vaddr=%x filesz=%x\n",
|
printf ("Section type=%x flags=%x vaddr=%x filesz=%x\n",
|
||||||
ph[i].p_type, ph[i].p_flags, ph[i].p_vaddr, ph[i].p_filesz);
|
ph[i].p_type, ph[i].p_flags, ph[i].p_vaddr, ph[i].p_filesz);
|
||||||
/* Section types we can't handle... */
|
|
||||||
if (ph[i].p_type != PT_LOAD && ph[i].p_type != PT_GNU_EH_FRAME)
|
|
||||||
errx(1, "Program header %d type %x can't be converted.", i, ph[i].p_type);
|
|
||||||
|
|
||||||
/* Writable (data) segment? */
|
/* Writable (data) segment? */
|
||||||
if (ph[i].p_flags & PF_W) {
|
if (ph[i].p_flags & PF_W) {
|
||||||
|
|||||||
1
tools/virtualmips/.gitignore
vendored
1
tools/virtualmips/.gitignore
vendored
@@ -1,3 +1,2 @@
|
|||||||
.deps
|
.deps
|
||||||
pic32
|
pic32
|
||||||
pic32-log.txt
|
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ unsigned dev_sdcard_io (cpu_mips_t *cpu, unsigned data)
|
|||||||
pic32->sdcard[1].select ? &pic32->sdcard[1] : 0;
|
pic32->sdcard[1].select ? &pic32->sdcard[1] : 0;
|
||||||
unsigned reply;
|
unsigned reply;
|
||||||
|
|
||||||
if (! d || ! d->fd) {
|
if (! d) {
|
||||||
TRACE ("sdcard: unselected i/o\n");
|
TRACE ("sdcard: unselected i/o\n");
|
||||||
return 0xFF;
|
return 0xFF;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user