35 Commits

Author SHA1 Message Date
Manoel Trapier
7f1d330949 Update README to display better in markdown 2015-06-24 23:41:04 +01:00
Manoel Trapier
4db0d7b5fd Add markdown and license file 2015-06-24 23:41:04 +01:00
Manoel Trapier
8874cacc1b Add gitignore file. 2015-06-24 23:41:04 +01:00
Manoel Trapier
72fe23f09a Add NES platform to default build. (Still more to go to compile correctly) and re-enabling the "k&r" cpp 2015-06-24 23:41:04 +01:00
Manoel Trapier
00ea871e8e Correct mach cg pmfile that incorrectly reference PLATFORM where it should reference ARCH 2015-06-24 23:41:04 +01:00
Manoel Trapier
45121f6d87 Copy pc86 platform to nes platform, and make change accordingly. 2015-06-24 23:41:04 +01:00
David Given
dccecc5d45 Back out erroneous change. 2012-12-14 11:56:21 +00:00
George Koehler
0fc7fd5d33 Prevent segfault when trying to print an error message.
Use <stdarg.h> to pass arguments correctly, as ack/util/util.c
already uses <stdarg.h> the same way.
2012-10-24 13:44:50 -04:00
David Given
4349d702fa Change from using platform-specific types to stdint platform-independent types
when reading the structure header.
2012-09-27 11:32:40 +01:00
David Given
2beb3646a7 Change to use stdint's implementation independent types rather than short and
long (which vary depending on whether you're on a 64-bit system or not).
2012-09-27 10:54:41 +01:00
George Koehler
7ef9b79c11 Merge deletion of many undead files. 2012-09-23 15:31:16 -04:00
George Koehler
3dcc3bd1cf Allow pc86 bootloader to boot from more floppy drives.
When the bootloader probes the drive geometry, the BIOS can clobber the
es register.  If this happens, the bootloader loads the program to the
wrong address, and jumps off the code.  This happens with an emulated
floppy drive in Bochs or QEMU, but not with an emulated hard disk.
2012-09-23 14:43:22 -04:00
George Koehler
e7c79415b5 Prevent division by zero in aslod.
rhead() and rsect() had assumed sizeof(long) == 4, but OpenBSD/amd64
has sizeof(long) == 8.  The problem revealed itself when sect->os_lign
became zero, and align() divided by zero.
2012-09-21 22:51:12 -04:00
George Koehler
0131ca4d46 Delete 689 undead files.
These files "magically reappeared" after the conversion from CVS to
Mercurial.  The old CVS repository deleted these files but did not
record *when* it deleted these files.  The conversion resurrected these
files because they have no history of deletion.  These files were
probably deleted before year 1995.  The CVS repository begins to record
deletions around 1995.

These files may still appear in older revisions of this Mercurial
repository, when they should already be deleted.  There is no way to fix
this, because the CVS repository provides no dates of deletion.

See http://sourceforge.net/mailarchive/message.php?msg_id=29823032
2012-09-20 22:26:32 -04:00
George Koehler
be234ea759 *Again* fix fit16i() for systems with 64-bit long.
I already did this in abebf1586c06, but I edited the wrong file.  Then
in edddc6b7cd17, I deleted that file.

By fixing fit16i(), I can now compile ACK for OpenBSD/amd64.
2012-09-19 23:39:51 -04:00
George Koehler
8bf34937f1 Delete old and unused files from modules/src/em_code 2012-09-17 16:04:55 -04:00
George Koehler
99eb12a282 Fix fit16i() for systems with 64-bit long.
(long)0xFFFF8000 had expanded to 0x00000000FFFF8000.
With (long)(-0x8000), the compiler now extends the negative sign.
2012-09-16 19:57:07 -04:00
George Koehler
96ea0a5903 Fix more functions in util/ack for 64-bit hosts.
This continues the fix from changeset aabde0589450.  We must use
va_list to forward the arguments, because some of the arguments might
be 64-bit pointers.  A pointer does not fit in an int.
2012-09-07 16:28:10 -04:00
George Koehler
800d4ae032 Fix cemcom.ansi for 64-bit hosts.
Hosts with sizeof(arith) == sizeof(long) == 8 need to set full_mask[1]
through full_mask[8].  Because MAXSIZE == 8, we only had full_mask[0]
through full_mask[7].  This fix declares arith full_mask[MAXSIZE + 1]
and prevents a fatal error: "array full_mask too small for this machine"
2012-09-07 15:53:13 -04:00
David Given
6ea172d0d9 Fix a 64-bitness issue (removed some untyped K&R C code that assumed ints
and pointers were the same size).
2012-02-27 22:36:36 +00:00
Ceriel Jacobs
1072a8797e Added atol() that ignores overflow, so that unsigned long constants are dealt with properly 2011-06-15 11:13:48 +02:00
Ceriel Jacobs
2483e5723d Fixed CFU 2011-06-15 10:56:58 +02:00
cjhjacobs
58613009f8 Fixed bug reported on tack-devel mailing list on 20-3-2011 2011-05-18 19:19:19 +02:00
David Given
b6dfaefeff Removed file that the CVS conversion procedure left in (when it shouldn't have). 2011-03-20 20:47:10 +00:00
cvs2hg
eb0b730607 convert CVS tags 2011-02-11 00:51:45 +00:00
dtrg
45ee287136 Replaced dis and new with modern implementations donated by erik@backerud.se. 2010-10-02 21:52:29 +00:00
dtrg
075cb488a3 Call the correct kill() and getpid() syscalls rather than _kill() and _getpid(). 2010-10-02 21:51:40 +00:00
dtrg
a33473e0a5 Now call creat() and open() instead of _creat() and _open(). 2010-09-27 20:47:32 +00:00
dtrg
7292b538bc Added support for remove() and unlink(). 2010-09-27 20:44:49 +00:00
dtrg
a8ecb11013 Fixed very old bug where Streams.GetStreamPosition would return the wrong position --- thanks to Jan Verhoeven for finding this. 2010-09-01 19:55:15 +00:00
dtrg
085f346f8c Fixed definitions of O_* flags. 2010-08-20 19:27:09 +00:00
dtrg
c326f3c6a3 Remove references to using-machine-name-for-compiler, as we don't do that any more. 2010-08-09 22:47:33 +00:00
dtrg
a0c67da261 Changed to actually work. (On modern Linux systems the old version just
crashes. On old Linux systems it apparently only worked by accident.)
2010-08-06 17:06:31 +00:00
dtrg
293f34fa9b Flush stdout before prompting the user for input. 2010-08-06 17:02:16 +00:00
dtrg
da6111328d Flush output stream before waiting for user input. 2010-08-05 22:23:34 +00:00
74 changed files with 1082 additions and 23159 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*~
*.o
.*
-.gitignore

9
.hgtags Normal file
View File

@@ -0,0 +1,9 @@
5a0daa6017c4aa5ae23b870e97eb7431021762bc distr2
15b742c4c278c27029eca0e41f16463bc076de6e distr3
a0686e2ca8d6780ce37b8267b865f60e9317a340 llgen-1-0
d96cd06672c368e8aaa584fead379ce1d343acad oct-1
bf69b3579e8545ecfc03f5e2550586e3c479270d release-6-0-pre-4
e880082b57f12a7df1c33a2da2c7424d6368f185 dist2
fe535e3e8bc859d4a4e4a186f42670f9e588a5aa release-5-6
90102c21c4480102634c6a482d0dd55f2d9ca00f release-6-0-pre-3
ddc0de0e5e7d91b1dcd7c05602c9c2a6adf8d312 release-6-0-pre-1

1
LICENSE Symbolic link
View File

@@ -0,0 +1 @@
Copyright

10
README
View File

@@ -1,8 +1,7 @@
THE AMSTERDAM COMPILER KIT V6.0pre4
===================================
THE AMSTERDAM COMPILER KIT V6.0pre4
===================================
© 1987-2005 Vrije Universiteit, Amsterdam
2010-08-08
© 1987-2005 Vrije Universiteit, Amsterdam 2010-08-08
INTRODUCTION
@@ -165,6 +164,3 @@ David Given (dtrg on Sourceforge)
dg@cowlark.com
2010-08-08
# $Source$
# $State$
# $Revision$

1
README.md Symbolic link
View File

@@ -0,0 +1 @@
README

View File

@@ -6,13 +6,22 @@
MODULE HiLo;
FROM InOut IMPORT WriteInt, WriteLn, WriteString, ReadString, ReadInt;
FROM random IMPORT Uniform;
FROM Streams IMPORT FlushStream, OutputStream, StreamResult;
VAR
buffer : ARRAY [0..32] OF CHAR;
PROCEDURE flush;
VAR
strus : StreamResult;
BEGIN
FlushStream(OutputStream, strus);
END flush;
PROCEDURE reads;
BEGIN
WriteString("> ");
flush;
ReadString(buffer);
END reads;
@@ -31,8 +40,8 @@ BEGIN
finished := FALSE;
WHILE NOT finished DO
WriteLn;
WriteString("> ");
flush;
ReadInt(guess);
IF guess = Number THEN

View File

@@ -199,6 +199,13 @@ string sG2; /* Used to pass string results */
FILE *stream;
bool bFlag = FALSE; /* Prevent multiple file opens */
void
reads(char* buffer)
{
fflush(stdout);
gets(buffer);
}
/* Main Program */
int
@@ -228,7 +235,7 @@ intro(void)
printf("\nDo you need instructions (y/n): ");
gets(sTemp);
reads(sTemp);
if (sTemp[0] == 'y' || sTemp[0] == 'Y')
showfile("startrek.doc");
@@ -271,7 +278,7 @@ new_game(void)
printf("Command? ");
gets(sTemp);
reads(sTemp);
printf("\n");
if (! strncmp(sTemp, "nav", 3))
@@ -516,7 +523,7 @@ course_control(void)
printf("Course (0-9): ");
gets(sTemp);
reads(sTemp);
printf("\n");
@@ -537,7 +544,7 @@ course_control(void)
printf("Warp Factor (0-%s): ", sX);
gets(sTemp);
reads(sTemp);
printf("\n");
@@ -916,7 +923,7 @@ phaser_control(void)
printf("Number of units to fire: ");
gets(sTemp);
reads(sTemp);
printf("\n");
@@ -1002,7 +1009,7 @@ photon_torpedoes(void)
printf("Course (0-9): ");
gets(sTemp);
reads(sTemp);
printf("\n");
@@ -1214,7 +1221,7 @@ sheild_control(void)
printf("Input number of units to shields: ");
gets(sTemp);
reads(sTemp);
printf("\n");
@@ -1254,7 +1261,7 @@ library_computer(void)
printf("Computer active and awating command: ");
gets(sTemp);
reads(sTemp);
printf("\n");
if (! strncmp(sTemp, "0", 1))
@@ -1406,19 +1413,19 @@ dirdist_calc(void)
(int)s1, (int)s2);
printf("Please enter initial X coordinate: ");
gets(sTemp);
reads(sTemp);
c1 = atoi(sTemp);
printf("Please enter initial Y coordinate: ");
gets(sTemp);
reads(sTemp);
a = atoi(sTemp);
printf("Please enter final X coordinate: ");
gets(sTemp);
reads(sTemp);
w1 = atoi(sTemp);
printf("Please enter final Y coordinate: ");
gets(sTemp);
reads(sTemp);
x = atoi(sTemp);
compute_vector();
@@ -1589,7 +1596,7 @@ end_of_game(void)
printf("If there is a volunteer, let him step forward and");
printf(" enter 'aye': ");
gets(sTemp);
reads(sTemp);
printf("\n");
if (! strncmp(sTemp, "aye", 3))
@@ -1921,6 +1928,7 @@ closefile(void)
int
getline(char *s)
{
fflush(stdout);
if (fgets(s, MAXCOL, stream) == NULL)
return(0);
else

View File

@@ -20,7 +20,7 @@
#include "sizes.h"
extern char options[];
extern arith full_mask[/*MAXSIZE*/]; /* cstoper.c */
extern arith full_mask[/*MAXSIZE + 1*/]; /* cstoper.c */
char *symbol2str();
ch3mon(oper, expp)

View File

@@ -16,7 +16,8 @@
#include "Lpars.h"
#include "assert.h"
arith full_mask[MAXSIZE];/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */
/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */
arith full_mask[MAXSIZE + 1];
#ifndef NOCROSS
arith max_int; /* maximum integer on target machine */
arith max_unsigned; /* maximum unsigned on target machine */
@@ -247,7 +248,7 @@ init_cst()
while (!(bt < 0)) {
bt = (bt << 8) + 0377, i++;
if (i == MAXSIZE)
if (i > MAXSIZE)
fatal("array full_mask too small for this machine");
full_mask[i] = bt;
}

View File

@@ -9,13 +9,10 @@
#endif
#include <signal.h>
int _kill(int pid, int sig);
int _getpid(void);
int
raise(int sig)
{
if (sig < 0 || sig > _NSIG)
return -1;
return _kill(_getpid(), sig);
return kill(getpid(), sig);
}

View File

@@ -340,7 +340,7 @@ IMPLEMENTATION MODULE Streams;
RETURN;
END;
IF s^.mode = reading THEN
position := position + LONG(s^.maxcnt - s^.cnt + 1);
position := position - LONG(s^.maxcnt - s^.cnt + 1);
END;
END GetPosition;

View File

@@ -1,3 +1,15 @@
/*
* File: - dis.c
*
* dispose() built in standard procedure in Pascal (6.6.5.3)
*
* Re-implementation of storage allocator for Ack Pascal compiler
* under Linux, and other UNIX-like systems.
*
* Written by Erik Backerud, 2010-10-01
*
* Original copyright and author info below:
*/
/* $Id$ */
/*
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
@@ -23,65 +35,67 @@
#define assert() /* nothing */
/*
* use circular list of free blocks from low to high addresses
* _highp points to free block with highest address
* use a singly linked list of free blocks.
*/
struct adm {
struct adm *next;
int size;
};
extern struct adm *_lastp;
extern struct adm *_highp;
extern _trp();
struct adm *freep = 0; /* first element on free list */
static int merge(p1,p2) struct adm *p1,*p2; {
struct adm *p;
extern void _trp(int);
p = (struct adm *)((char *)p1 + p1->size);
if (p > p2)
/*
* Dispose
* Called with two arguments:
* n the size of the block to be freed, in bytes,
* pp address of pointer to data.
*/
void
_dis(int n, struct adm **pp)
{
struct adm *block; /* the block of data being freed (inc. header) */
struct adm *p, *q;
if (*pp == 0) {
_trp(EFREE);
}
block = *pp - 1;
if (freep == 0) {
freep = block;
block->next = 0;
} else {
q = 0; /* trail one behind */
for (p = freep; p < block; p = p->next) {
if (p == 0) { /* We reached the end of the free list. */
break;
}
q = p;
/* check if block is contained in the free block p */
if (p+p->size > block) {
_trp(EFREE);
if (p != p2)
return(0);
p1->size += p2->size;
p1->next = p2->next;
return(1);
}
_dis(n,pp) int n; struct adm **pp; {
struct adm *p1,*p2;
/*
* NOTE: dispose only objects whose size is a multiple of sizeof(*pp).
* this is always true for objects allocated by _new()
*/
n = ((n+sizeof(*p1)-1) / sizeof(*p1)) * sizeof(*p1);
if (n == 0)
return;
if ((p1= *pp) == (struct adm *) 0)
_trp(EFREE);
p1->size = n;
if ((p2 = _highp) == 0) /*p1 is the only free block*/
p1->next = p1;
else {
if (p2 > p1) {
/*search for the preceding free block*/
if (_lastp < p1) /*reduce search*/
p2 = _lastp;
while (p2->next < p1)
p2 = p2->next;
}
/* if p2 preceeds p1 in the circular list,
* try to merge them */
p1->next = p2->next; p2->next = p1;
if (p2 <= p1 && merge(p2,p1))
p1 = p2;
p2 = p1->next;
/* p1 preceeds p2 in the circular list */
if (p2 > p1) merge(p1,p2);
}
}
if (p1 >= p1->next)
_highp = p1;
_lastp = p1;
*pp = (struct adm *) 0;
}
if (p == block) { /* this block already freed */
_trp(EFREE);
}
if (q == 0) { /* block is first */
freep = block;
block->next = p;
} else {
q->next = block;
}
block->next = p;
/* merge with successor on free list? */
if (block + block->size == p) {
block->size = block->size + p->size;
block->next = p->next;
}
/* merge with preceding block on free list? */
if (q != 0 && q+q->size == block) {
q->size = q->size + block->size;
q->next = block->next;
}
}
} /* _dis */

View File

@@ -1,3 +1,15 @@
/*
* File: - new.c
*
* new() built in standard procedure in Pascal (6.6.5.3)
*
* Re-implementation of storage allocator for Ack Pascal compiler
* under Linux, and other UNIX-like systems.
*
* Written by Erik Backerud, 2010-10-01
*
* Original copyright and author info below:
*/
/* $Id$ */
/*
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
@@ -17,53 +29,92 @@
*/
/* Author: J.W. Stevenson */
extern _sav();
extern _rst();
#include <em_abs.h>
#include <pc_err.h>
#define assert(x) /* nothing */
#define UNDEF 0x8000
#define NALLOC (1024) /* request this many units from OS */
/*
* use a singly linked list of free blocks.
*/
struct adm {
struct adm *next;
int size;
};
struct adm *_lastp = 0;
struct adm *_highp = 0;
extern struct adm *freep;
_new(n,pp) int n; struct adm **pp; {
struct adm *p,*q;
int *ptmp;
extern void _trp(int); /* called on error */
n = ((n+sizeof(*p)-1) / sizeof(*p)) * sizeof(*p);
if ((p = _lastp) != 0)
do {
q = p->next;
if (q->size >= n) {
assert(q->size%sizeof(adm) == 0);
if ((q->size -= n) == 0) {
if (p == q)
p = 0;
else
p->next = q->next;
if (q == _highp)
_highp = p;
}
_lastp = p;
p = (struct adm *)((char *)q + q->size);
q = (struct adm *)((char *)p + n);
goto initialize;
}
p = q;
} while (p != _lastp);
/*no free block big enough*/
_sav(&p);
q = (struct adm *)((char *)p + n);
_rst(&q);
initialize:
*pp = p;
ptmp = (int *)p;
while (ptmp < (int *)q)
*ptmp++ = UNDEF;
}
extern void _dis(int, struct adm **);
/*
* Helper function to request 'nu' units of memory from the OS.
* A storage unit is sizeof(struct adm). Typically 8 bytes
* on a 32-bit machine like i386 etc.
*/
static struct adm *
morecore(unsigned nu)
{
char *cp, *sbrk(int);
struct adm *up;
if (nu < NALLOC)
nu = NALLOC;
cp = sbrk(nu * sizeof(struct adm));
if (cp == (char *) -1) /* no space at all */
return 0;
up = (struct adm*) cp;
up->size = nu;
up = up + 1;
_dis((nu - 1) * sizeof(struct adm), &up);
return freep;
} /* morecore */
/*
* Dispose
* Called with two arguments:
* n the size of the block to be freed, in bytes,
* pp address of pointer to data.
*/
void
_new(int n, struct adm **pp)
{
int nunits; /* the unit of storage is sizeof(struct adm) */
struct adm *p,*q;
/* round up size of request */
nunits = (n + sizeof(struct adm) - 1) / sizeof(struct adm) + 1;
q = 0;
for (p = freep; ; p = p->next) {
if (p == 0) {
p = morecore(nunits);
if (p == 0)
_trp(EHEAP);
q = 0;
}
if (p->size >= nunits) {
if (p->size == nunits) { /* exact fit */
if (q == 0) { /* first element on free list. */
freep = p->next;
} else {
q->next = p->next;
}
} else { /* allocate tail end */
q = p;
q->size = q->size - nunits;
p = q + q->size;
p->next = 0;
p->size = nunits;
}
break;
}
q = p;
}
*pp = p + 1;
} /* _new */

View File

@@ -87,10 +87,10 @@ static int initfl(descr,sz,f) int descr; int sz; struct file *f; {
f->fname = _pargv[i];
_cls(f);
if ((descr & WRBIT) == 0) {
if ((f->ufd = _open(f->fname,0)) < 0)
if ((f->ufd = open(f->fname,0)) < 0)
_trp(ERESET);
} else {
if ((f->ufd = _creat(f->fname,0644)) < 0)
if ((f->ufd = creat(f->fname,0644)) < 0)
_trp(EREWR);
}
}

View File

@@ -18,12 +18,12 @@
/* Author: J.W. Stevenson */
#include <unistd.h>
#include <pc_file.h>
#include <pc_err.h>
extern _cls();
extern _trp();
extern int _creat();
/* procedure pcreat(var f:text; s:string); */
@@ -36,6 +36,6 @@ pcreat(f,s) struct file *f; char *s; {
f->size = 1;
f->count = PC_BUFLEN;
f->buflen = PC_BUFLEN;
if ((f->ufd = _creat(s,0644)) < 0)
if ((f->ufd = creat(s,0644)) < 0)
_trp(EREWR);
}

View File

@@ -1,11 +0,0 @@
The file 'table' in this directory contains a back end table for the
MC68020 processor as well as one for the MC68000. Both tables use 2 or 4 bytes
for words and 4 bytes for pointers. The table must be preprocessed first
by the C preprocessor.
The file "whichone.h" specifies which code generator is generated:
it #defines either TBL68000 or TBL86020, and it defines WORD_SIZE to either
2 or 4.
The m68k4(TBL68000) cg can very well be used for the MC68010 processor,
for it makes rather efficient use of the 68010 loop mode.
The mach.[ch] files are also suitable for both the m68020 and the m68k[24].

View File

@@ -1,144 +0,0 @@
#if WORD_SIZE==2
#define LLP ldl
#define LEP lde
#define LFP ldf /* load offsetted pointer */
#define SLP sdl
#define SEP sde
#define SFP sdf /* store offsetted pointer */
#define ABS_off_int ABS_off2
#define ABS_indoff_int ABS_indoff2
#define ABSIND_off_int ABSIND_off2
#define INDOFF_off_int INDOFF_off2
#define OFF_off_int OFF_off2
#define OFF_indoff_int OFF_indoff2
#define abs_index_int abs_index2
#define absolute_int absolute2
#define any_int any2
#define conreg_int conreg2
#define data_int data2
#define datalt_int datalt2
#define dreg_int dreg2
#define imm_cmp_int imm_cmp2
#define immediate_int immediate2
#define indirect_int indirect2
#define index_off_int index_off2
#define offsetted_int offsetted2
#define post_inc_int post_inc2
#define pre_dec_int pre_dec2
#define store_int any2
#define test_set_int test_set2
#define add_i add_w
#define ADD_I "add.w"
#define and_i and_w
#define AND_I "and.w"
#define asl_i asl_w
#define ASL_I "asl.w"
#define asr_i asr_w
#define ASR_I "asr.w"
#define clr_i clr_w
#define CLR_I "clr.w"
#define cmp_i cmp_w
#define cmp2_i cmp2_w
#define DEC "sub.w #1,"
#define DIVS_I "divs.w"
#define DIVU_I "divu.w"
#define eor_i eor_w
#define EOR_I "eor.w"
#define INC "add.w #1,"
#define lsr_i lsr_w
#define LSR_I "lsr.w"
#define move_i move_w
#define MOVE_I "move.w"
#define muls_i muls_w
#define MULS_I "muls.w"
#define mulu_i mulu_w
#define MULU_I "mulu.w"
#define neg_i neg_w
#define NEG_I "neg.w"
#define not_i not_w
#define NOT_I "not.w"
#define or_i or_w
#define OR_I "or.w"
#define rol_i rol_w
#define ROL_I "rol.w"
#define ror_i ror_w
#define ROR_I "ror.w"
#define sub_i sub_w
#define SUB_I "sub.w"
#define tst_i tst_w
#else
#define LLP lol
#define LEP loe
#define LFP lof /* load offsetted pointer */
#define SLP stl
#define SEP ste
#define SFP stf /* store offsetted pointer */
#define ABS_off_int ABS_off4
#define ABS_indoff_int ABS_indoff4
#define ABSIND_off_int ABSIND_off4
#define INDOFF_off_int INDOFF_off4
#define OFF_off_int OFF_off4
#define OFF_indoff_int OFF_indoff4
#define abs_index_int abs_index4
#define absolute_int absolute4
#define any_int any4
#define conreg_int conreg4
#define data_int data4
#define datalt_int datalt4
#define dreg_int dreg4
#define imm_cmp_int imm_cmp4
#define immediate_int immediate4
#define indirect_int indirect4
#define index_off_int index_off4
#define offsetted_int offsetted4
#define post_inc_int post_inc4
#define pre_dec_int pre_dec4
#define store_int store4
#define test_set_int test_set4
#define add_i add_l
#define ADD_I "add.l"
#define and_i and_l
#define AND_I "and.l"
#define asl_i asl_l
#define ASL_I "asl.l"
#define asr_i asr_l
#define ASR_I "asr.l"
#define clr_i clr_l
#define CLR_I "clr.l"
#define cmp_i cmp_l
#define cmp2_i cmp2_l
#define DEC "sub.l #1,"
#define DIVS_I "divs.l"
#define DIVU_I "divu.l"
#define eor_i eor_l
#define EOR_I "eor.l"
#define INC "add.l #1,"
#define lsr_i lsr_l
#define LSR_I "lsr.l"
#define move_i move_l
#define MOVE_I "move.l"
#define muls_i muls_l
#define MULS_I "muls.l"
#define mulu_i mulu_l
#define MULU_I "mulu.l"
#define neg_i neg_l
#define NEG_I "neg.l"
#define not_i not_l
#define NOT_I "not.l"
#define or_i or_l
#define OR_I "or.l"
#define rol_i rol_l
#define ROL_I "rol.l"
#define ror_i ror_l
#define ROR_I "ror.l"
#define sub_i sub_l
#define SUB_I "sub.l"
#define tst_i tst_l
#endif

View File

@@ -1,288 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
*/
/*
* machine dependent back end routines for the Motorola 68000, 68010 or 68020
*/
#include <whichone.h>
#if TBL68020
#define SYNTAX_68020 1
#endif
#include <stb.h>
con_part(sz,w) register sz; word w; {
while (part_size % sz)
part_size++;
if (part_size == TEM_WSIZE)
part_flush();
if (sz == 1) {
w &= 0xFF;
#if WORD_SIZE==4
w <<= 8*(3-part_size);
part_word |= w;
} else if (sz == 2) {
w &= 0xFFFF;
#endif
if (part_size == 0) {
/* Shift 8 for m68k2, 16 otherwise */
w <<= 4 * TEM_WSIZE;
}
part_word |= w;
} else {
assert(sz == TEM_WSIZE);
part_word = w;
}
part_size += sz;
}
con_mult(sz) word sz; {
if (sz != 4)
fatal("bad icon/ucon size");
fprintf(codefile,".data4 %s\n",str);
}
#define IEEEFLOAT
#define CODE_GENERATOR
#define FL_MSL_AT_LOW_ADDRESS 1
#define FL_MSW_AT_LOW_ADDRESS 1
#define FL_MSB_AT_LOW_ADDRESS 1
#include <con_float>
regscore(off,size,typ,score,totyp)
long off;
{
if (score == 0) return -1;
switch(typ) {
case reg_float:
return -1;
case reg_pointer:
if (size != 4 || totyp != reg_pointer) return -1;
score += (score >> 1);
break;
case reg_loop:
score += 5;
/* fall through .. */
case reg_any:
if (size != TEM_WSIZE || totyp == reg_pointer) return -1;
break;
}
if (off >= 0) {
/* parameters must be initialised with an instruction
* like "move.l 4(a6),d0", which costs 2 words.
*/
score -= 2;
}
score--; /* save/restore */
return score;
}
struct regsav_t {
char *rs_reg; /* e.g. "a3" or "d5" */
long rs_off; /* offset of variable */
int rs_size; /* 2 or 4 bytes */
} regsav[9];
int regnr;
i_regsave()
{
regnr = 0;
}
full nlocals;
regreturn()
{
register struct regsav_t *p;
if (regnr > 1) {
#ifdef SYNTAX_68020
fprintf(codefile,"movem.l (-%ld,a6),", nlocals);
#else
fprintf(codefile,"movem.l -%ld(a6),", nlocals);
#endif
for (p = regsav; ;) {
fputs(p->rs_reg, codefile);
if (++p == &regsav[regnr]) break;
putc('/',codefile);
}
putc('\n',codefile);
} else if (regnr == 1) {
p = regsav;
#ifdef SYNTAX_68020
fprintf(codefile,"move.l (-%ld,a6),%s\n",nlocals, p->rs_reg);
#else
fprintf(codefile,"move.l -%ld(a6),%s\n",nlocals, p->rs_reg);
#endif
}
fputs("unlk a6\nrts\n", codefile);
}
f_regsave()
{
register struct regsav_t *p;
nlocals += regnr*4;
#ifdef TBL68020
fprintf(codefile,"link\ta6,#-%ld\n",nlocals);
#else
if (nlocals > 32768) {
fprintf(codefile, "move.l a6,-(sp)\nmove.l sp,a6\nsub #%ld,sp\n", nlocals);
}
else fprintf(codefile,"link\ta6,#-%ld\n",nlocals);
#endif
#ifndef NOSTACKTEST
fprintf(codefile, "tst.b %s\n",
#ifdef SYNTAX_68020
"(-40, sp)"
#else
"-40(sp)"
#endif
);
#endif
if (regnr > 1) {
fputs("movem.l ", codefile);
for (p = regsav; ;) {
fputs(p->rs_reg, codefile);
if (++p == &regsav[regnr]) break;
putc('/',codefile);
}
fputs(",(sp)\n", codefile);
} else if (regnr == 1) {
p = regsav;
fprintf(codefile,"move.l %s,(sp)\n",p->rs_reg);
}
/* initialise register-parameters */
for (p = regsav; p < &regsav[regnr]; p++) {
if (p->rs_off >= 0) {
#ifdef SYNTAX_68020
fprintf(codefile,"move.%c (%ld,a6),%s\n",
#else
fprintf(codefile,"move.%c %ld(a6),%s\n",
#endif
(p->rs_size == 4 ? 'l' : 'w'),
p->rs_off,
p->rs_reg);
}
}
}
regsave(s,off,size)
char *s;
long off;
{
assert (regnr < 9);
regsav[regnr].rs_reg = s;
regsav[regnr].rs_off = off;
regsav[regnr++].rs_size = size;
fprintf(codefile, "!Local %ld into %s\n",off,s);
}
prolog(n) full n; {
nlocals = n;
}
#ifdef MACH_OPTIONS
static int gdb_flag = 0;
mach_option(s)
char *s;
{
if (! strcmp(s, "-gdb")) {
gdb_flag = 1;
}
else {
error("Unknown flag %s", s);
}
}
#endif /* MACH_OPTIONS */
mes(type) word type ; {
int argt, a1, a2 ;
switch ( (int)type ) {
case ms_ext :
for (;;) {
switch ( argt=getarg(
ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
case sp_cend :
return ;
default:
strarg(argt) ;
fprintf(codefile,".define %s\n",argstr) ;
break ;
}
}
case ms_stb:
argt = getarg(str_ptyp | cst_ptyp);
if (argt == sp_cstx)
fputs(".symb \"\", ", codefile);
else {
fprintf(codefile, ".symb \"%s\", ", str);
argt = getarg(cst_ptyp);
}
a1 = argval;
argt = getarg(cst_ptyp);
a2 = argval;
argt = getarg(cst_ptyp|nof_ptyp|sof_ptyp|ilb_ptyp|pro_ptyp);
#ifdef MACH_OPTIONS
if (gdb_flag) {
if (a1 == N_PSYM) {
/* Change offset from AB into offset from
the frame pointer.
*/
argval += 8;
}
}
#endif
fprintf(codefile, "%s, 0x%x, %d\n", strarg(argt), a1, a2);
argt = getarg(end_ptyp);
break;
case ms_std:
argt = getarg(str_ptyp | cst_ptyp);
if (argt == sp_cstx)
str[0] = '\0';
else {
argt = getarg(cst_ptyp);
}
swtxt();
if (argval == N_SLINE
#ifdef MACH_OPTIONS
&& ! gdb_flag
#endif
) {
#ifdef SYNTAX_68020
fputs("jsr (___u_LiB)\n", codefile);
#else
fputs("jsr ___u_LiB\n", codefile);
#endif
cleanregs(); /* debugger might change variables */
}
fprintf(codefile, ".symd \"%s\", 0x%x,", str, (int) argval);
argt = getarg(cst_ptyp);
fprintf(codefile, "%d\n", (int) argval);
argt = getarg(end_ptyp);
break;
default :
while ( getarg(any_ptyp) != sp_cend ) ;
break ;
}
}
char *segname[] = {
".sect .text", /* SEGTXT */
".sect .data", /* SEGCON */
".sect .rom", /* SEGROM */
".sect .bss" /* SEGBSS */
};

View File

@@ -1,49 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#include <whichone.h>
#ifndef TBL68020
#ifndef TBL68000
Something is very wrong here. You must specify the machine: either
TBL68000 or TBL68020, in the file whichone.h, then REMOVE tables.c
and then run "make" again
#endif
#endif
#if WORD_SIZE!=2 && WORD_SIZE!=4
You must specify the appropriate word size, then REMOVE tables.c
#endif
#define ex_ap(y) fprintf(codefile,".extern %s\n",y)
#define in_ap(y) /* nothing */
#define newilb(x) fprintf(codefile,"%s:\n",x)
#define newdlb(x) fprintf(codefile,"%s:\n",x)
#define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y)
#define newlbss(l,x) fprintf(codefile,".comm %s,%ld\n",l,x);
#define pop_fmt "(sp)+"
#define cst_fmt "%ld"
#define off_fmt "%ld"
#define ilb_fmt "I%x_%x"
#define dlb_fmt "I_%d"
#define hol_fmt "hol%d"
#define hol_off "%ld+hol%d"
#if WORD_SIZE==2
#define con_cst(x) fprintf(codefile,".data2\t%ld\n",x)
#else
#define con_cst(x) fprintf(codefile,".data4\t%ld\n",x)
#endif
#define con_ilb(x) fprintf(codefile,".data4\t%s\n",x)
#define con_dlb(x) fprintf(codefile,".data4\t%s\n",x)
#define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n"
#define fmt_id(sf,st) sprintf(st,"_%s",sf)
#define BSS_INIT 0
#define MACH_OPTIONS

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +0,0 @@
The file 'table' in this directory contains a back end table for the
MC68020 processor as well as one for the MC68000. Both tables use 2 or 4 bytes
for words and 4 bytes for pointers. The table must be preprocessed first
by the C preprocessor.
The file "whichone.h" specifies which code generator is generated:
it #defines either TBL68000 or TBL86020, and it defines WORD_SIZE to either
2 or 4.
The m68k4(TBL68000) cg can very well be used for the MC68010 processor,
for it makes rather efficient use of the 68010 loop mode.
The mach.[ch] files are also suitable for both the m68020 and the m68k[24].

View File

@@ -1,144 +0,0 @@
#if WORD_SIZE==2
#define LLP ldl
#define LEP lde
#define LFP ldf /* load offsetted pointer */
#define SLP sdl
#define SEP sde
#define SFP sdf /* store offsetted pointer */
#define ABS_off_int ABS_off2
#define ABS_indoff_int ABS_indoff2
#define ABSIND_off_int ABSIND_off2
#define INDOFF_off_int INDOFF_off2
#define OFF_off_int OFF_off2
#define OFF_indoff_int OFF_indoff2
#define abs_index_int abs_index2
#define absolute_int absolute2
#define any_int any2
#define conreg_int conreg2
#define data_int data2
#define datalt_int datalt2
#define dreg_int dreg2
#define imm_cmp_int imm_cmp2
#define immediate_int immediate2
#define indirect_int indirect2
#define index_off_int index_off2
#define offsetted_int offsetted2
#define post_inc_int post_inc2
#define pre_dec_int pre_dec2
#define store_int any2
#define test_set_int test_set2
#define add_i add_w
#define ADD_I "add.w"
#define and_i and_w
#define AND_I "and.w"
#define asl_i asl_w
#define ASL_I "asl.w"
#define asr_i asr_w
#define ASR_I "asr.w"
#define clr_i clr_w
#define CLR_I "clr.w"
#define cmp_i cmp_w
#define cmp2_i cmp2_w
#define DEC "sub.w #1,"
#define DIVS_I "divs.w"
#define DIVU_I "divu.w"
#define eor_i eor_w
#define EOR_I "eor.w"
#define INC "add.w #1,"
#define lsr_i lsr_w
#define LSR_I "lsr.w"
#define move_i move_w
#define MOVE_I "move.w"
#define muls_i muls_w
#define MULS_I "muls.w"
#define mulu_i mulu_w
#define MULU_I "mulu.w"
#define neg_i neg_w
#define NEG_I "neg.w"
#define not_i not_w
#define NOT_I "not.w"
#define or_i or_w
#define OR_I "or.w"
#define rol_i rol_w
#define ROL_I "rol.w"
#define ror_i ror_w
#define ROR_I "ror.w"
#define sub_i sub_w
#define SUB_I "sub.w"
#define tst_i tst_w
#else
#define LLP lol
#define LEP loe
#define LFP lof /* load offsetted pointer */
#define SLP stl
#define SEP ste
#define SFP stf /* store offsetted pointer */
#define ABS_off_int ABS_off4
#define ABS_indoff_int ABS_indoff4
#define ABSIND_off_int ABSIND_off4
#define INDOFF_off_int INDOFF_off4
#define OFF_off_int OFF_off4
#define OFF_indoff_int OFF_indoff4
#define abs_index_int abs_index4
#define absolute_int absolute4
#define any_int any4
#define conreg_int conreg4
#define data_int data4
#define datalt_int datalt4
#define dreg_int dreg4
#define imm_cmp_int imm_cmp4
#define immediate_int immediate4
#define indirect_int indirect4
#define index_off_int index_off4
#define offsetted_int offsetted4
#define post_inc_int post_inc4
#define pre_dec_int pre_dec4
#define store_int store4
#define test_set_int test_set4
#define add_i add_l
#define ADD_I "add.l"
#define and_i and_l
#define AND_I "and.l"
#define asl_i asl_l
#define ASL_I "asl.l"
#define asr_i asr_l
#define ASR_I "asr.l"
#define clr_i clr_l
#define CLR_I "clr.l"
#define cmp_i cmp_l
#define cmp2_i cmp2_l
#define DEC "sub.l #1,"
#define DIVS_I "divs.l"
#define DIVU_I "divu.l"
#define eor_i eor_l
#define EOR_I "eor.l"
#define INC "add.l #1,"
#define lsr_i lsr_l
#define LSR_I "lsr.l"
#define move_i move_l
#define MOVE_I "move.l"
#define muls_i muls_l
#define MULS_I "muls.l"
#define mulu_i mulu_l
#define MULU_I "mulu.l"
#define neg_i neg_l
#define NEG_I "neg.l"
#define not_i not_l
#define NOT_I "not.l"
#define or_i or_l
#define OR_I "or.l"
#define rol_i rol_l
#define ROL_I "rol.l"
#define ror_i ror_l
#define ROR_I "ror.l"
#define sub_i sub_l
#define SUB_I "sub.l"
#define tst_i tst_l
#endif

View File

@@ -1,288 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
*/
/*
* machine dependent back end routines for the Motorola 68000, 68010 or 68020
*/
#include <whichone.h>
#if TBL68020
#define SYNTAX_68020 1
#endif
#include <stb.h>
con_part(sz,w) register sz; word w; {
while (part_size % sz)
part_size++;
if (part_size == TEM_WSIZE)
part_flush();
if (sz == 1) {
w &= 0xFF;
#if WORD_SIZE==4
w <<= 8*(3-part_size);
part_word |= w;
} else if (sz == 2) {
w &= 0xFFFF;
#endif
if (part_size == 0) {
/* Shift 8 for m68k2, 16 otherwise */
w <<= 4 * TEM_WSIZE;
}
part_word |= w;
} else {
assert(sz == TEM_WSIZE);
part_word = w;
}
part_size += sz;
}
con_mult(sz) word sz; {
if (sz != 4)
fatal("bad icon/ucon size");
fprintf(codefile,".data4 %s\n",str);
}
#define IEEEFLOAT
#define CODE_GENERATOR
#define FL_MSL_AT_LOW_ADDRESS 1
#define FL_MSW_AT_LOW_ADDRESS 1
#define FL_MSB_AT_LOW_ADDRESS 1
#include <con_float>
regscore(off,size,typ,score,totyp)
long off;
{
if (score == 0) return -1;
switch(typ) {
case reg_float:
return -1;
case reg_pointer:
if (size != 4 || totyp != reg_pointer) return -1;
score += (score >> 1);
break;
case reg_loop:
score += 5;
/* fall through .. */
case reg_any:
if (size != TEM_WSIZE || totyp == reg_pointer) return -1;
break;
}
if (off >= 0) {
/* parameters must be initialised with an instruction
* like "move.l 4(a6),d0", which costs 2 words.
*/
score -= 2;
}
score--; /* save/restore */
return score;
}
struct regsav_t {
char *rs_reg; /* e.g. "a3" or "d5" */
long rs_off; /* offset of variable */
int rs_size; /* 2 or 4 bytes */
} regsav[9];
int regnr;
i_regsave()
{
regnr = 0;
}
full nlocals;
regreturn()
{
register struct regsav_t *p;
if (regnr > 1) {
#ifdef SYNTAX_68020
fprintf(codefile,"movem.l (-%ld,a6),", nlocals);
#else
fprintf(codefile,"movem.l -%ld(a6),", nlocals);
#endif
for (p = regsav; ;) {
fputs(p->rs_reg, codefile);
if (++p == &regsav[regnr]) break;
putc('/',codefile);
}
putc('\n',codefile);
} else if (regnr == 1) {
p = regsav;
#ifdef SYNTAX_68020
fprintf(codefile,"move.l (-%ld,a6),%s\n",nlocals, p->rs_reg);
#else
fprintf(codefile,"move.l -%ld(a6),%s\n",nlocals, p->rs_reg);
#endif
}
fputs("unlk a6\nrts\n", codefile);
}
f_regsave()
{
register struct regsav_t *p;
nlocals += regnr*4;
#ifdef TBL68020
fprintf(codefile,"link\ta6,#-%ld\n",nlocals);
#else
if (nlocals > 32768) {
fprintf(codefile, "move.l a6,-(sp)\nmove.l sp,a6\nsub #%ld,sp\n", nlocals);
}
else fprintf(codefile,"link\ta6,#-%ld\n",nlocals);
#endif
#ifndef NOSTACKTEST
fprintf(codefile, "tst.b %s\n",
#ifdef SYNTAX_68020
"(-40, sp)"
#else
"-40(sp)"
#endif
);
#endif
if (regnr > 1) {
fputs("movem.l ", codefile);
for (p = regsav; ;) {
fputs(p->rs_reg, codefile);
if (++p == &regsav[regnr]) break;
putc('/',codefile);
}
fputs(",(sp)\n", codefile);
} else if (regnr == 1) {
p = regsav;
fprintf(codefile,"move.l %s,(sp)\n",p->rs_reg);
}
/* initialise register-parameters */
for (p = regsav; p < &regsav[regnr]; p++) {
if (p->rs_off >= 0) {
#ifdef SYNTAX_68020
fprintf(codefile,"move.%c (%ld,a6),%s\n",
#else
fprintf(codefile,"move.%c %ld(a6),%s\n",
#endif
(p->rs_size == 4 ? 'l' : 'w'),
p->rs_off,
p->rs_reg);
}
}
}
regsave(s,off,size)
char *s;
long off;
{
assert (regnr < 9);
regsav[regnr].rs_reg = s;
regsav[regnr].rs_off = off;
regsav[regnr++].rs_size = size;
fprintf(codefile, "!Local %ld into %s\n",off,s);
}
prolog(n) full n; {
nlocals = n;
}
#ifdef MACH_OPTIONS
static int gdb_flag = 0;
mach_option(s)
char *s;
{
if (! strcmp(s, "-gdb")) {
gdb_flag = 1;
}
else {
error("Unknown flag %s", s);
}
}
#endif /* MACH_OPTIONS */
mes(type) word type ; {
int argt, a1, a2 ;
switch ( (int)type ) {
case ms_ext :
for (;;) {
switch ( argt=getarg(
ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
case sp_cend :
return ;
default:
strarg(argt) ;
fprintf(codefile,".define %s\n",argstr) ;
break ;
}
}
case ms_stb:
argt = getarg(str_ptyp | cst_ptyp);
if (argt == sp_cstx)
fputs(".symb \"\", ", codefile);
else {
fprintf(codefile, ".symb \"%s\", ", str);
argt = getarg(cst_ptyp);
}
a1 = argval;
argt = getarg(cst_ptyp);
a2 = argval;
argt = getarg(cst_ptyp|nof_ptyp|sof_ptyp|ilb_ptyp|pro_ptyp);
#ifdef MACH_OPTIONS
if (gdb_flag) {
if (a1 == N_PSYM) {
/* Change offset from AB into offset from
the frame pointer.
*/
argval += 8;
}
}
#endif
fprintf(codefile, "%s, 0x%x, %d\n", strarg(argt), a1, a2);
argt = getarg(end_ptyp);
break;
case ms_std:
argt = getarg(str_ptyp | cst_ptyp);
if (argt == sp_cstx)
str[0] = '\0';
else {
argt = getarg(cst_ptyp);
}
swtxt();
if (argval == N_SLINE
#ifdef MACH_OPTIONS
&& ! gdb_flag
#endif
) {
#ifdef SYNTAX_68020
fputs("jsr (___u_LiB)\n", codefile);
#else
fputs("jsr ___u_LiB\n", codefile);
#endif
cleanregs(); /* debugger might change variables */
}
fprintf(codefile, ".symd \"%s\", 0x%x,", str, (int) argval);
argt = getarg(cst_ptyp);
fprintf(codefile, "%d\n", (int) argval);
argt = getarg(end_ptyp);
break;
default :
while ( getarg(any_ptyp) != sp_cend ) ;
break ;
}
}
char *segname[] = {
".sect .text", /* SEGTXT */
".sect .data", /* SEGCON */
".sect .rom", /* SEGROM */
".sect .bss" /* SEGBSS */
};

View File

@@ -1,49 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#include <whichone.h>
#ifndef TBL68020
#ifndef TBL68000
Something is very wrong here. You must specify the machine: either
TBL68000 or TBL68020, in the file whichone.h, then REMOVE tables.c
and then run "make" again
#endif
#endif
#if WORD_SIZE!=2 && WORD_SIZE!=4
You must specify the appropriate word size, then REMOVE tables.c
#endif
#define ex_ap(y) fprintf(codefile,".extern %s\n",y)
#define in_ap(y) /* nothing */
#define newilb(x) fprintf(codefile,"%s:\n",x)
#define newdlb(x) fprintf(codefile,"%s:\n",x)
#define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y)
#define newlbss(l,x) fprintf(codefile,".comm %s,%ld\n",l,x);
#define pop_fmt "(sp)+"
#define cst_fmt "%ld"
#define off_fmt "%ld"
#define ilb_fmt "I%x_%x"
#define dlb_fmt "I_%d"
#define hol_fmt "hol%d"
#define hol_off "%ld+hol%d"
#if WORD_SIZE==2
#define con_cst(x) fprintf(codefile,".data2\t%ld\n",x)
#else
#define con_cst(x) fprintf(codefile,".data4\t%ld\n",x)
#endif
#define con_ilb(x) fprintf(codefile,".data4\t%s\n",x)
#define con_dlb(x) fprintf(codefile,".data4\t%s\n",x)
#define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n"
#define fmt_id(sf,st) sprintf(st,"_%s",sf)
#define BSS_INIT 0
#define MACH_OPTIONS

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +0,0 @@
The file 'table' in this directory contains a back end table for the
MC68020 processor as well as one for the MC68000. Both tables use 2 or 4 bytes
for words and 4 bytes for pointers. The table must be preprocessed first
by the C preprocessor.
The file "whichone.h" specifies which code generator is generated:
it #defines either TBL68000 or TBL86020, and it defines WORD_SIZE to either
2 or 4.
The m68k4(TBL68000) cg can very well be used for the MC68010 processor,
for it makes rather efficient use of the 68010 loop mode.
The mach.[ch] files are also suitable for both the m68020 and the m68k[24].

View File

@@ -1,144 +0,0 @@
#if WORD_SIZE==2
#define LLP ldl
#define LEP lde
#define LFP ldf /* load offsetted pointer */
#define SLP sdl
#define SEP sde
#define SFP sdf /* store offsetted pointer */
#define ABS_off_int ABS_off2
#define ABS_indoff_int ABS_indoff2
#define ABSIND_off_int ABSIND_off2
#define INDOFF_off_int INDOFF_off2
#define OFF_off_int OFF_off2
#define OFF_indoff_int OFF_indoff2
#define abs_index_int abs_index2
#define absolute_int absolute2
#define any_int any2
#define conreg_int conreg2
#define data_int data2
#define datalt_int datalt2
#define dreg_int dreg2
#define imm_cmp_int imm_cmp2
#define immediate_int immediate2
#define indirect_int indirect2
#define index_off_int index_off2
#define offsetted_int offsetted2
#define post_inc_int post_inc2
#define pre_dec_int pre_dec2
#define store_int any2
#define test_set_int test_set2
#define add_i add_w
#define ADD_I "add.w"
#define and_i and_w
#define AND_I "and.w"
#define asl_i asl_w
#define ASL_I "asl.w"
#define asr_i asr_w
#define ASR_I "asr.w"
#define clr_i clr_w
#define CLR_I "clr.w"
#define cmp_i cmp_w
#define cmp2_i cmp2_w
#define DEC "sub.w #1,"
#define DIVS_I "divs.w"
#define DIVU_I "divu.w"
#define eor_i eor_w
#define EOR_I "eor.w"
#define INC "add.w #1,"
#define lsr_i lsr_w
#define LSR_I "lsr.w"
#define move_i move_w
#define MOVE_I "move.w"
#define muls_i muls_w
#define MULS_I "muls.w"
#define mulu_i mulu_w
#define MULU_I "mulu.w"
#define neg_i neg_w
#define NEG_I "neg.w"
#define not_i not_w
#define NOT_I "not.w"
#define or_i or_w
#define OR_I "or.w"
#define rol_i rol_w
#define ROL_I "rol.w"
#define ror_i ror_w
#define ROR_I "ror.w"
#define sub_i sub_w
#define SUB_I "sub.w"
#define tst_i tst_w
#else
#define LLP lol
#define LEP loe
#define LFP lof /* load offsetted pointer */
#define SLP stl
#define SEP ste
#define SFP stf /* store offsetted pointer */
#define ABS_off_int ABS_off4
#define ABS_indoff_int ABS_indoff4
#define ABSIND_off_int ABSIND_off4
#define INDOFF_off_int INDOFF_off4
#define OFF_off_int OFF_off4
#define OFF_indoff_int OFF_indoff4
#define abs_index_int abs_index4
#define absolute_int absolute4
#define any_int any4
#define conreg_int conreg4
#define data_int data4
#define datalt_int datalt4
#define dreg_int dreg4
#define imm_cmp_int imm_cmp4
#define immediate_int immediate4
#define indirect_int indirect4
#define index_off_int index_off4
#define offsetted_int offsetted4
#define post_inc_int post_inc4
#define pre_dec_int pre_dec4
#define store_int store4
#define test_set_int test_set4
#define add_i add_l
#define ADD_I "add.l"
#define and_i and_l
#define AND_I "and.l"
#define asl_i asl_l
#define ASL_I "asl.l"
#define asr_i asr_l
#define ASR_I "asr.l"
#define clr_i clr_l
#define CLR_I "clr.l"
#define cmp_i cmp_l
#define cmp2_i cmp2_l
#define DEC "sub.l #1,"
#define DIVS_I "divs.l"
#define DIVU_I "divu.l"
#define eor_i eor_l
#define EOR_I "eor.l"
#define INC "add.l #1,"
#define lsr_i lsr_l
#define LSR_I "lsr.l"
#define move_i move_l
#define MOVE_I "move.l"
#define muls_i muls_l
#define MULS_I "muls.l"
#define mulu_i mulu_l
#define MULU_I "mulu.l"
#define neg_i neg_l
#define NEG_I "neg.l"
#define not_i not_l
#define NOT_I "not.l"
#define or_i or_l
#define OR_I "or.l"
#define rol_i rol_l
#define ROL_I "rol.l"
#define ror_i ror_l
#define ROR_I "ror.l"
#define sub_i sub_l
#define SUB_I "sub.l"
#define tst_i tst_l
#endif

View File

@@ -1,288 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
*/
/*
* machine dependent back end routines for the Motorola 68000, 68010 or 68020
*/
#include <whichone.h>
#if TBL68020
#define SYNTAX_68020 1
#endif
#include <stb.h>
con_part(sz,w) register sz; word w; {
while (part_size % sz)
part_size++;
if (part_size == TEM_WSIZE)
part_flush();
if (sz == 1) {
w &= 0xFF;
#if WORD_SIZE==4
w <<= 8*(3-part_size);
part_word |= w;
} else if (sz == 2) {
w &= 0xFFFF;
#endif
if (part_size == 0) {
/* Shift 8 for m68k2, 16 otherwise */
w <<= 4 * TEM_WSIZE;
}
part_word |= w;
} else {
assert(sz == TEM_WSIZE);
part_word = w;
}
part_size += sz;
}
con_mult(sz) word sz; {
if (sz != 4)
fatal("bad icon/ucon size");
fprintf(codefile,".data4 %s\n",str);
}
#define IEEEFLOAT
#define CODE_GENERATOR
#define FL_MSL_AT_LOW_ADDRESS 1
#define FL_MSW_AT_LOW_ADDRESS 1
#define FL_MSB_AT_LOW_ADDRESS 1
#include <con_float>
regscore(off,size,typ,score,totyp)
long off;
{
if (score == 0) return -1;
switch(typ) {
case reg_float:
return -1;
case reg_pointer:
if (size != 4 || totyp != reg_pointer) return -1;
score += (score >> 1);
break;
case reg_loop:
score += 5;
/* fall through .. */
case reg_any:
if (size != TEM_WSIZE || totyp == reg_pointer) return -1;
break;
}
if (off >= 0) {
/* parameters must be initialised with an instruction
* like "move.l 4(a6),d0", which costs 2 words.
*/
score -= 2;
}
score--; /* save/restore */
return score;
}
struct regsav_t {
char *rs_reg; /* e.g. "a3" or "d5" */
long rs_off; /* offset of variable */
int rs_size; /* 2 or 4 bytes */
} regsav[9];
int regnr;
i_regsave()
{
regnr = 0;
}
full nlocals;
regreturn()
{
register struct regsav_t *p;
if (regnr > 1) {
#ifdef SYNTAX_68020
fprintf(codefile,"movem.l (-%ld,a6),", nlocals);
#else
fprintf(codefile,"movem.l -%ld(a6),", nlocals);
#endif
for (p = regsav; ;) {
fputs(p->rs_reg, codefile);
if (++p == &regsav[regnr]) break;
putc('/',codefile);
}
putc('\n',codefile);
} else if (regnr == 1) {
p = regsav;
#ifdef SYNTAX_68020
fprintf(codefile,"move.l (-%ld,a6),%s\n",nlocals, p->rs_reg);
#else
fprintf(codefile,"move.l -%ld(a6),%s\n",nlocals, p->rs_reg);
#endif
}
fputs("unlk a6\nrts\n", codefile);
}
f_regsave()
{
register struct regsav_t *p;
nlocals += regnr*4;
#ifdef TBL68020
fprintf(codefile,"link\ta6,#-%ld\n",nlocals);
#else
if (nlocals > 32768) {
fprintf(codefile, "move.l a6,-(sp)\nmove.l sp,a6\nsub #%ld,sp\n", nlocals);
}
else fprintf(codefile,"link\ta6,#-%ld\n",nlocals);
#endif
#ifndef NOSTACKTEST
fprintf(codefile, "tst.b %s\n",
#ifdef SYNTAX_68020
"(-40, sp)"
#else
"-40(sp)"
#endif
);
#endif
if (regnr > 1) {
fputs("movem.l ", codefile);
for (p = regsav; ;) {
fputs(p->rs_reg, codefile);
if (++p == &regsav[regnr]) break;
putc('/',codefile);
}
fputs(",(sp)\n", codefile);
} else if (regnr == 1) {
p = regsav;
fprintf(codefile,"move.l %s,(sp)\n",p->rs_reg);
}
/* initialise register-parameters */
for (p = regsav; p < &regsav[regnr]; p++) {
if (p->rs_off >= 0) {
#ifdef SYNTAX_68020
fprintf(codefile,"move.%c (%ld,a6),%s\n",
#else
fprintf(codefile,"move.%c %ld(a6),%s\n",
#endif
(p->rs_size == 4 ? 'l' : 'w'),
p->rs_off,
p->rs_reg);
}
}
}
regsave(s,off,size)
char *s;
long off;
{
assert (regnr < 9);
regsav[regnr].rs_reg = s;
regsav[regnr].rs_off = off;
regsav[regnr++].rs_size = size;
fprintf(codefile, "!Local %ld into %s\n",off,s);
}
prolog(n) full n; {
nlocals = n;
}
#ifdef MACH_OPTIONS
static int gdb_flag = 0;
mach_option(s)
char *s;
{
if (! strcmp(s, "-gdb")) {
gdb_flag = 1;
}
else {
error("Unknown flag %s", s);
}
}
#endif /* MACH_OPTIONS */
mes(type) word type ; {
int argt, a1, a2 ;
switch ( (int)type ) {
case ms_ext :
for (;;) {
switch ( argt=getarg(
ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
case sp_cend :
return ;
default:
strarg(argt) ;
fprintf(codefile,".define %s\n",argstr) ;
break ;
}
}
case ms_stb:
argt = getarg(str_ptyp | cst_ptyp);
if (argt == sp_cstx)
fputs(".symb \"\", ", codefile);
else {
fprintf(codefile, ".symb \"%s\", ", str);
argt = getarg(cst_ptyp);
}
a1 = argval;
argt = getarg(cst_ptyp);
a2 = argval;
argt = getarg(cst_ptyp|nof_ptyp|sof_ptyp|ilb_ptyp|pro_ptyp);
#ifdef MACH_OPTIONS
if (gdb_flag) {
if (a1 == N_PSYM) {
/* Change offset from AB into offset from
the frame pointer.
*/
argval += 8;
}
}
#endif
fprintf(codefile, "%s, 0x%x, %d\n", strarg(argt), a1, a2);
argt = getarg(end_ptyp);
break;
case ms_std:
argt = getarg(str_ptyp | cst_ptyp);
if (argt == sp_cstx)
str[0] = '\0';
else {
argt = getarg(cst_ptyp);
}
swtxt();
if (argval == N_SLINE
#ifdef MACH_OPTIONS
&& ! gdb_flag
#endif
) {
#ifdef SYNTAX_68020
fputs("jsr (___u_LiB)\n", codefile);
#else
fputs("jsr ___u_LiB\n", codefile);
#endif
cleanregs(); /* debugger might change variables */
}
fprintf(codefile, ".symd \"%s\", 0x%x,", str, (int) argval);
argt = getarg(cst_ptyp);
fprintf(codefile, "%d\n", (int) argval);
argt = getarg(end_ptyp);
break;
default :
while ( getarg(any_ptyp) != sp_cend ) ;
break ;
}
}
char *segname[] = {
".sect .text", /* SEGTXT */
".sect .data", /* SEGCON */
".sect .rom", /* SEGROM */
".sect .bss" /* SEGBSS */
};

View File

@@ -1,49 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#include <whichone.h>
#ifndef TBL68020
#ifndef TBL68000
Something is very wrong here. You must specify the machine: either
TBL68000 or TBL68020, in the file whichone.h, then REMOVE tables.c
and then run "make" again
#endif
#endif
#if WORD_SIZE!=2 && WORD_SIZE!=4
You must specify the appropriate word size, then REMOVE tables.c
#endif
#define ex_ap(y) fprintf(codefile,".extern %s\n",y)
#define in_ap(y) /* nothing */
#define newilb(x) fprintf(codefile,"%s:\n",x)
#define newdlb(x) fprintf(codefile,"%s:\n",x)
#define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y)
#define newlbss(l,x) fprintf(codefile,".comm %s,%ld\n",l,x);
#define pop_fmt "(sp)+"
#define cst_fmt "%ld"
#define off_fmt "%ld"
#define ilb_fmt "I%x_%x"
#define dlb_fmt "I_%d"
#define hol_fmt "hol%d"
#define hol_off "%ld+hol%d"
#if WORD_SIZE==2
#define con_cst(x) fprintf(codefile,".data2\t%ld\n",x)
#else
#define con_cst(x) fprintf(codefile,".data4\t%ld\n",x)
#endif
#define con_ilb(x) fprintf(codefile,".data4\t%s\n",x)
#define con_dlb(x) fprintf(codefile,".data4\t%s\n",x)
#define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n"
#define fmt_id(sf,st) sprintf(st,"_%s",sf)
#define BSS_INIT 0
#define MACH_OPTIONS

File diff suppressed because it is too large Load Diff

View File

@@ -4,15 +4,15 @@
local d = ROOTDIR.."mach/proto/cg/"
local make_tables = cgg {
CGGINCLUDEDIR = (ROOTDIR.."mach/%PLATFORM%/cg/"),
file (ROOTDIR.."mach/%PLATFORM%/cg/table")
CGGINCLUDEDIR = (ROOTDIR.."mach/%ARCH%/cg/"),
file (ROOTDIR.."mach/%ARCH%/cg/table")
}
local cfile_with_tables = cfile {
class = "cfile_with_tables",
dynamicheaders = {
make_tables,
file (ROOTDIR.."mach/%PLATFORM%/cg/"),
file (ROOTDIR.."mach/%ARCH%/cg/"),
file (ROOTDIR.."mach/")
}
}
@@ -39,7 +39,7 @@ proto_cg = cprogram {
cfile {
ith { make_tables, i = 1 },
dynamicheaders = {
file (ROOTDIR.."mach/%PLATFORM%/cg/"),
file (ROOTDIR.."mach/%ARCH%/cg/"),
file (d)
}
},
@@ -47,8 +47,8 @@ proto_cg = cprogram {
lib_em_data,
lib_flt_arith,
outputs = {"%U%/%PLATFORM%-cg"},
install = pm.install("%BINDIR%%PLATDEP%/%PLATFORM%/cg")
outputs = {"%U%/%ARCH%-cg"},
install = pm.install("%BINDIR%%PLATDEP%/%ARCH%/cg")
}
-- Revision history

View File

@@ -1,624 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*
*/
/*
* Convert ACK a.out file to SUN3 object format.
*/
#include <stdio.h>
#include <out.h>
#include <assert.h>
long lseek();
#if __STDC__
#include <stdlib.h>
#else
char *calloc(), *malloc();
#endif
#define OMAGIC 0407 /* old-fashioned */
#define NMAGIC 0410 /* text write protexted */
#define ZMAGIC 0413 /* demand paging */
struct bhdr {
short machtype;
short magic;
long tsize;
long dsize;
long bsize;
long ssize;
long entry;
long rtsize;
long rdsize;
};
struct machrelo {
long address;
long relodata;
};
#define setpcrel(X,f) (X |= (f<<7))
#define setsymbolnum(X,n) (X = (X & 0377) | ((long)n << 8))
#define setextern(X,f) (X |= (f << 4))
#define setlength(X,l) (X = (X & ~0x60)|((long) l << 5))
struct sym {
long name;
char type;
char other;
short desc;
long value;
};
#define N_UNDF 0
#define N_ABS 02
#define N_TEXT 04
#define N_DATA 06
#define N_BSS 010
#define N_EXT 01
#define N_FN 0x1f
/*
* Header and section table of new format object file.
*/
struct outhead outhead;
struct outsect outsect[S_MAX];
char *output_file;
int outputfile_created;
long magic;
int rom_in_data;
char *program ;
char flag ;
/* Output file definitions and such */
struct bhdr bh;
#define ENTRY 0x02000
#define TOT_HDRSIZE (sizeof(struct bhdr))
#define TEXTSG 0
#define ROMSG 1
#define DATASG 2
#define BSSSG 3
#define LSECT BSSSG+1
#define NSECT LSECT+1
int output;
int unresolved;
long textsize ;
long datasize ;
long bsssize;
long align(a,b)
long a,b;
{
a += b - 1;
return a - a % b;
}
int
follows(pa, pb)
register struct outsect *pa, *pb;
{
/* return 1 if pa follows pb */
return pa->os_base == align(pb->os_base+pb->os_size, pa->os_lign);
}
main(argc, argv)
int argc;
char *argv[];
{
register int nsect;
program= argv[0] ;
if ( argc>1 && argv[1][0]=='-' ) {
flag=argv[1][1] ;
if (flag == 'u') unresolved++;
argc-- ; argv++ ;
}
switch (argc) {
case 3: if ((output = creat(argv[2], 0644)) < 0 ||
(close(output), output = open(argv[2],2)) < 0)
fatal("Can't write %s.\n", argv[2]);
output_file = argv[2];
outputfile_created = 1;
if (! rd_open(argv[1]))
fatal("Can't read %s.\n", argv[1]);
break;
default:fatal("Usage: %s [-u] <ACK object> <Sun object>.\n", program);
}
rd_ohead(&outhead);
if (BADMAGIC(outhead))
fatal("Not an ack object file.\n");
if (outhead.oh_flags & HF_LINK) {
if (! unresolved) {
fprintf(stderr,"Warning: contains unresolved references.\n");
}
unresolved++;
}
else if (outhead.oh_nrelo > 0 && !unresolved)
fprintf(stderr, "Warning: relocation information present.\n");
if ( outhead.oh_nsect!=LSECT && outhead.oh_nsect!=NSECT )
fatal("Input file must have %d sections, not %ld\n",
NSECT,outhead.oh_nsect) ;
rd_sect(outsect, outhead.oh_nsect);
/* A few checks */
if ( outsect[BSSSG].os_flen != 0 )
fatal("bss space contains initialized data\n") ;
if ( !unresolved && ! follows(&outsect[BSSSG], &outsect[DATASG]))
fatal("bss segment must follow data segment\n") ;
if ( outsect[ROMSG].os_lign == 0x20000 ) {
/* 410/413 file with ROMSG in data space */
rom_in_data = 1;
magic= NMAGIC ;
textsize= outsect[TEXTSG].os_size ;
datasize= outsect[BSSSG].os_base - outsect[ROMSG].os_base ;
if (! follows(&outsect[DATASG], &outsect[ROMSG]))
fatal("data segment must follow rom\n") ;
outsect[ROMSG].os_size = outsect[DATASG].os_base - outsect[ROMSG].os_base;
outsect[DATASG].os_size = outsect[BSSSG].os_base - outsect[DATASG].os_base;
} else
if ( outsect[DATASG].os_lign == 0x20000 ) {
/* 410/413 file with ROMSG in instruction space */
rom_in_data = 0;
magic= NMAGIC ;
textsize= (outsect[ROMSG].os_base - outsect[TEXTSG].os_base) +
outsect[ROMSG].os_size ;
if (! follows(&outsect[ROMSG],&outsect[TEXTSG]))
fatal("rom segment must follow text\n") ;
outsect[TEXTSG].os_size = outsect[ROMSG].os_base - outsect[TEXTSG].os_base;
outsect[DATASG].os_size = outsect[BSSSG].os_base - outsect[DATASG].os_base;
datasize= outsect[DATASG].os_size ;
} else {
/* Plain 407 file */
rom_in_data = 0;
magic= OMAGIC ;
if (!unresolved) {
textsize= (outsect[DATASG].os_base - outsect[TEXTSG].os_base);
if (! follows(&outsect[ROMSG],&outsect[TEXTSG]))
fatal("rom segment must follow text\n") ;
if (! follows(&outsect[DATASG],&outsect[ROMSG]))
fatal("data segment must follow rom\n") ;
outsect[TEXTSG].os_size = outsect[ROMSG].os_base - outsect[TEXTSG].os_base;
outsect[ROMSG].os_size = outsect[DATASG].os_base - outsect[ROMSG].os_base;
outsect[DATASG].os_size = outsect[BSSSG].os_base - outsect[DATASG].os_base;
}
else {
textsize = outsect[TEXTSG].os_size+outsect[ROMSG].os_size;
}
datasize = outsect[DATASG].os_size;
}
if (outsect[TEXTSG].os_base == TOT_HDRSIZE+ENTRY) {
if (magic != NMAGIC) {
fatal("illegal alignments.\n");
}
magic = ZMAGIC;
textsize = (textsize + TOT_HDRSIZE + (0x2000 - 1)) & ~(0x2000 - 1);
datasize = (datasize + (0x2000 - 1)) & ~(0x2000 - 1);
}
bsssize = outsect[BSSSG].os_size;
if ( outhead.oh_nsect==NSECT ) {
if (! follows(&outsect[LSECT],&outsect[BSSSG]))
fatal("end segment must follow bss\n") ;
if ( outsect[LSECT].os_size != 0 )
fatal("end segment must be empty\n") ;
}
if (magic != OMAGIC && unresolved) {
fatal("unresolved references with wrong magic number\n");
}
if ((magic == ZMAGIC && outsect[TEXTSG].os_base != TOT_HDRSIZE+ENTRY) ||
(magic != ZMAGIC && !unresolved && outsect[TEXTSG].os_base != ENTRY)) {
fatal("Illegal entry point.\n");
}
bh.magic = magic;
bh.machtype = MACH;
bh.tsize = textsize;
bh.bsize = bsssize;
bh.dsize = datasize;
bh.rtsize = 0;
bh.rdsize = 0;
if (magic == ZMAGIC) bh.entry = TOT_HDRSIZE+ENTRY;
else if (!unresolved) bh.entry = ENTRY;
else bh.entry = 0;
/* Action at last */
lseek(output,(long) TOT_HDRSIZE,0);
emits(&outsect[TEXTSG]) ;
if (rom_in_data && magic == ZMAGIC) {
lseek(output,textsize,0);
}
emits(&outsect[ROMSG]) ;
if (!rom_in_data && magic == ZMAGIC) {
lseek(output,textsize,0);
}
emits(&outsect[DATASG]) ;
if (magic == ZMAGIC) {
lseek(output,textsize + datasize,0);
}
if (unresolved) emit_relo();
emit_symtab();
bh.ssize = outhead.oh_nname * sizeof(struct sym);
lseek(output,0L,0);
cvshort(&(bh.machtype));
cvshort(&(bh.magic));
cvlong(&(bh.tsize));
cvlong(&(bh.dsize));
cvlong(&(bh.bsize));
cvlong(&(bh.ssize));
cvlong(&(bh.entry));
cvlong(&(bh.rtsize));
cvlong(&(bh.rdsize));
writef(&bh, 1, (long) TOT_HDRSIZE);
if ( outputfile_created && !unresolved ) chmod(argv[2],0755);
return 0;
}
writef(addr,sz,cnt)
char *addr;
long cnt;
{
cnt *= sz;
while (cnt) {
int i = cnt >= 0x4000 ? 0x4000 : cnt;
cnt -= i;
if (write(output, addr, i) < i) {
fatal("write error\n");
}
addr += i;
}
}
/*
* Transfer the emitted byted from one file to another.
*/
emits(section) struct outsect *section ; {
char *p;
long sz = section->os_flen;
rd_outsect(section - outsect);
while (sz) {
unsigned int i = (sz >= 0x4000 ? 0x4000 : sz);
if (!(p = malloc(i))) {
fatal("No memory.\n");
}
rd_emit(p, i);
if (write(output, p, i) < i) {
fatal("write error.\n");
}
free(p);
sz -= i;
}
sz = section->os_size - section->os_flen;
if (sz) {
if (!(p = calloc(0x4000, 1))) {
fatal("No memory.\n");
}
while (sz) {
unsigned int i = (sz >= 0x4000 ? 0x4000 : sz);
if (write(output, p, i) < i) {
fatal("write error.\n");
}
sz -= i;
}
free(p);
}
}
struct outname *ACKnames;
emit_relo()
{
struct outrelo *ACKrelo;
struct machrelo *MACHtrelo,*MACHdrelo;
register struct outrelo *ap;
register struct machrelo *mtp, *mdp;
unsigned int cnt = outhead.oh_nrelo;
ACKrelo = (struct outrelo *) calloc(cnt, sizeof(struct outrelo));
MACHtrelo = (struct machrelo *) calloc(cnt, sizeof(struct machrelo));
MACHdrelo = (struct machrelo *) calloc(cnt, sizeof(struct machrelo));
ACKnames = (struct outname *) calloc(outhead.oh_nname, sizeof(struct outname));
if (!(ap = ACKrelo) || !(mtp = MACHtrelo) || !(mdp = MACHdrelo) ||
!ACKnames) {
fatal("No memory.\n");
}
rd_relo(ACKrelo, cnt);
rd_name(ACKnames, outhead.oh_nname);
while (cnt-- != 0) {
register struct machrelo *mp;
if (ap->or_sect - S_MIN <= ROMSG) mp = mtp++;
else mp = mdp++;
setlength(mp->relodata,(ap->or_type&RELSZ) >> 1);
setpcrel(mp->relodata,(ap->or_type&RELPC != 0));
mp->address = ap->or_addr;
if (ap->or_sect == ROMSG+S_MIN) {
mp->address += outsect[TEXTSG].os_size;
}
if (ap->or_nami < outhead.oh_nname) {
if (ACKnames[ap->or_nami].on_type & S_EXT) {
setsymbolnum(mp->relodata, ap->or_nami);
setextern(mp->relodata,1);
}
else {
patch(ap, &ACKnames[ap->or_nami], mp);
}
}
else {
setsymbolnum(mp->relodata, N_ABS);
}
cvlong(&(mp->address));
cvlong(&(mp->relodata));
ap++;
}
bh.rtsize = (char *) mtp - (char *) MACHtrelo;
bh.rdsize = (char *) mdp - (char *) MACHdrelo;
writef(MACHtrelo, 1, bh.rtsize);
writef(MACHdrelo, 1, bh.rdsize);
free(ACKrelo);
free(MACHtrelo);
free(MACHdrelo);
}
long
get(sz)
{
char buf[10];
long l = 0;
register char *p = buf;
read(output,buf,sz);
while (sz--) {
l = (l << 8) | (*p++ & 0377);
}
return l;
}
put(l,sz)
long l;
{
char buf[10];
register char *p = buf;
*p++ = l >> 24;
*p++ = l >> 16;
*p++ = l >> 8;
*p++ = l;
p -= sz;
if (write(output, p, sz) < sz) {
fatal("write error.\n");
}
}
patch(ap, an, mp)
register struct outrelo *ap;
register struct outname *an;
register struct machrelo *mp;
{
int whichsect = (an->on_type & S_TYP) - S_MIN;
long correction = 0;
long where = TOT_HDRSIZE+ap->or_addr;
long X;
long here;
int sz;
if (!(an->on_type & S_SCT)) {
fprintf(stderr,"funny on_type %x\n", an->on_type);
}
switch(whichsect) {
case TEXTSG:
setsymbolnum(mp->relodata,N_TEXT);
return;
case DATASG:
correction = outsect[ROMSG].os_size + outsect[TEXTSG].os_size;
setsymbolnum(mp->relodata,N_DATA);
break;
case ROMSG:
correction = outsect[TEXTSG].os_size;
setsymbolnum(mp->relodata,N_TEXT);
break;
case BSSSG:
correction = outsect[ROMSG].os_size + outsect[TEXTSG].os_size+
outsect[DATASG].os_size;
setsymbolnum(mp->relodata,N_BSS);
break;
default:
assert(0);
}
switch(ap->or_sect - S_MIN) {
case DATASG:
where += outsect[ROMSG].os_size;
case ROMSG:
where += outsect[TEXTSG].os_size;
case TEXTSG:
break;
default:
assert(0);
}
here = lseek(output, 0L, 1);
lseek(output, where, 0);
sz = ap->or_type & RELSZ;
X = get(sz) + correction;
lseek(output, where, 0);
put(X,sz);
lseek(output, here, 0);
}
cvlong(l)
long *l;
{
long x = *l;
char *p = (char *) l;
*p++ = x >> 24;
*p++ = x >> 16;
*p++ = x >> 8;
*p = x;
}
cvshort(s)
short *s;
{
short x = *s;
char *p = (char *) s;
*p++ = x >> 8;
*p = x;
}
int
is_rest_local(A, i)
register int i;
register struct outname *A;
{
while (i--) {
if (A->on_type & S_EXT) return 0;
A++;
}
return 1;
}
emit_symtab()
{
register unsigned short i = outhead.oh_nname;
register struct outname *A;
struct sym *MACHnames;
register struct sym *M;
char *chars;
long offX = OFF_CHAR(outhead) - 4;
if (!(A = ACKnames)) {
if (!(A = (struct outname *)
calloc(i, sizeof(struct outname)))) {
fatal("No memory.\n");
}
rd_name(A, outhead.oh_nname);
}
if (!(M = (struct sym *) calloc(i, sizeof(struct sym)))) {
fatal("No memory.\n");
}
MACHnames = M;
ACKnames = A;
for (; i; i--, A++) {
M->value = A->on_valu;
M->desc = A->on_desc;
if ((A->on_type & S_SCT) ||
(A->on_type & S_ETC) == S_FIL) {
static int rest_local;
if (! unresolved || rest_local || (rest_local = is_rest_local(A, i))) {
outhead.oh_nname--;
continue;
}
}
if (A->on_type & S_STB) {
M->type = A->on_type >> 8;
}
else if (A->on_type & S_COM) {
M->type = N_UNDF | N_EXT;
}
else switch(A->on_type & S_TYP) {
case S_UND:
switch(A->on_type & S_ETC) {
default:
M->type = N_UNDF;
break;
case S_MOD:
M->type = N_FN;
break;
case S_LIN:
M->type = N_ABS;
break;
}
break;
case S_ABS:
M->type = N_ABS;
break;
case S_MIN + TEXTSG:
M->type = N_TEXT;
break;
case S_MIN + ROMSG:
if (unresolved) {
M->value += outsect[TEXTSG].os_size;
}
M->type = (rom_in_data ? N_DATA : N_TEXT);
break;
case S_MIN + DATASG:
if (unresolved) {
M->value += outsect[TEXTSG].os_size +
outsect[ROMSG].os_size;
}
M->type = N_DATA;
break;
case S_MIN + BSSSG:
if (unresolved) {
M->value += outsect[TEXTSG].os_size +
outsect[ROMSG].os_size +
outsect[DATASG].os_size;
}
M->type = N_BSS;
break;
case S_MIN + LSECT:
M->type = N_BSS;
break;
default:
fprintf(stderr,"warning: unknown s_type: %d\n",
A->on_type & S_TYP);
}
if (A->on_type & S_EXT) M->type |= N_EXT;
M->name = A->on_foff;
M++;
}
M = MACHnames;
for (i = outhead.oh_nname; i; i--, M++) {
if (M->name) {
M->name -= offX;
}
else M->name = outhead.oh_nchar + 3; /* pointer to nullbyte */
cvlong(&(M->name));
cvlong(&(M->value));
cvshort(&(M->desc));
}
writef(MACHnames, sizeof(struct sym), (long) outhead.oh_nname);
free(MACHnames);
free(ACKnames);
if ((unsigned) outhead.oh_nchar != outhead.oh_nchar ||
!( chars = malloc((unsigned) outhead.oh_nchar))) {
fatal("No memory\n.");
}
put(outhead.oh_nchar+4,4);
rd_string(chars,outhead.oh_nchar);
writef(chars, 1, outhead.oh_nchar);
free(chars);
}
/* VARARGS1 */
fatal(s, a1, a2)
char *s;
{
fprintf(stderr,"%s: ",program) ;
fprintf(stderr, s, a1, a2);
if (outputfile_created)
unlink(output_file);
exit(-1);
}
rd_fatal() { fatal("read error.\n"); }

View File

@@ -353,7 +353,7 @@ C_magic()
}
/*** the compact code generating routines ***/
#define fit16i(x) ((x) >= (long)0xFFFF8000 && (x) <= (long)0x00007FFF)
#define fit16i(x) ((x) >= (long)(-0x8000) && (x) <= (long)0x7FFF)
#define fit8u(x) ((x) <= 0xFF) /* x is already unsigned */
void

View File

@@ -43,9 +43,9 @@ enum
O_WRONLY = 1,
O_RDWR = 2,
O_CREAT = 0x10,
O_TRUNC = 0x20,
O_APPEND = 0x40
O_CREAT = 0x40,
O_TRUNC = 0x200,
O_APPEND = 0x400
};
extern int open(const char* path, int access, ...);
@@ -55,6 +55,8 @@ extern int read(int fd, void* buffer, size_t count);
extern int write(int fd, void* buffer, size_t count);
extern off_t lseek(int fildes, off_t offset, int whence);
extern int fcntl(int fd, int op, ...);
extern int unlink(const char* path);
extern int remove(const char* path);
/* Special variables */

View File

@@ -26,6 +26,8 @@ libsys_linux386 = acklibrary {
ackfile (d.."sbrk.c"),
ackfile (d.."signal.c"),
ackfile (d.."write.c"),
ackfile (d.."unlink.c"),
ackfile (d.."remove.c"),
install = pm.install("%BINDIR%lib/%PLATFORM%/libsys.a"),
}

View File

@@ -0,0 +1,15 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <stdarg.h>
#include "libsys.h"
int remove(const char* path)
{
return unlink(path);
}

View File

@@ -9,23 +9,27 @@
#define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */
extern char _end[1];
static char* current = _end;
static char* current = NULL;
void* sbrk(intptr_t increment)
{
char* old;
char* new;
char* actual;
if (!current)
current = (char*) _syscall(__NR_brk, 0, 0, 0);
if (increment == 0)
return current;
old = current;
new = old + increment;
if (brk(new) < 0)
actual = (char*) _syscall(__NR_brk, (quad) new, 0, 0);
if (actual < new)
return OUT_OF_MEMORY;
current = new;
current = actual;
return old;
}

View File

@@ -0,0 +1,15 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <stdarg.h>
#include "libsys.h"
int unlink(const char* path)
{
return _syscall(__NR_unlink, (quad) path, 0, 0);
}

24
plat/nes/.distr Normal file
View File

@@ -0,0 +1,24 @@
descr
boot.s
pmfile
README
include/ack/config.h
include/unistd.h
libsys/pmfile
libsys/_hol0.s
libsys/brk.c
libsys/close.c
libsys/creat.c
libsys/errno.s
libsys/getpid.c
libsys/isatty.c
libsys/kill.c
libsys/libsys.h
libsys/lseek.c
libsys/open.c
libsys/read.c
libsys/signal.c
libsys/time.c
libsys/write.c
libsys/_sys_rawread.s
libsys/_sys_rawwrite.s

15
plat/nes/README Normal file
View File

@@ -0,0 +1,15 @@
# $Source$
# $State$
# $Revision$
The NES platform
=================
NES is a platform for the Nintendo Entertainment System.
Example command line
====================
ack -mnes -O -o nes.img examples/paranoia.c

36
plat/nes/boot.s Normal file
View File

@@ -0,0 +1,36 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
start2:
jmp _main
.define __exit
.extern __exit
.define EXIT
.extern EXIT
__exit:
EXIT:
.define begtext, begdata, begbss
.sect .data; begdata:
.sect .rom; begrom:
.sect .bss; begbss:
! Some magic data. All EM systems need these.
.define .trppc, .ignmask, _errno
.comm .trppc, 4
.comm .ignmask, 4
.comm _errno, 4

69
plat/nes/descr Normal file
View File

@@ -0,0 +1,69 @@
# $Source$
# $State$
# $Revision$
var w=2
var p=2
var s=2
var l=4
var f=4
var d=8
var ARCH=6500
var PLATFORM=nes
var PLATFORMDIR={EM}/lib/{PLATFORM}
var CPP_F=
var ALIGN=-a0:1 -a1:1 -a2:1 -a3:1
var MACHOPT_F=-m8
# Override the setting in fe so that files compiled for linux386 can see
# the platform-specific headers.
var C_INCLUDES=-I{PLATFORMDIR}/include -I{EM}/include/ansi
name be
from .m.g
to .s
program {EM}/lib.bin/{PLATFORM}/ncg
args <
stdout
need .e
end
name as
from .s.so
to .o
program {EM}/lib.bin/{PLATFORM}/as
args - -o > <
prep cond
end
name led
from .o.a
to .out
program {EM}/lib.bin/em_led
mapflag -l* LNAME={PLATFORMDIR}/lib*
mapflag -i SEPID=-b1:0
mapflag -fp FLOATS={EM}/{ILIB}fp
args {ALIGN} {SEPID?} \
(.e:{HEAD}={PLATFORMDIR}/boot.o) \
({RTS}:.ocm.b={PLATFORMDIR}/c-ansi.o) \
({RTS}:.c={PLATFORMDIR}/c-ansi.o) \
({RTS}:.mod={PLATFORMDIR}/modula2.o) \
({RTS}:.p={PLATFORMDIR}/pascal.o) \
-o > < \
(.p:{TAIL}={PLATFORMDIR}/libpascal.a) \
(.b:{TAIL}={PLATFORMDIR}/libbasic.a) \
(.mod:{TAIL}={PLATFORMDIR}/libmodula2.a) \
(.ocm:{TAIL}={PLATFORMDIR}/liboccam.a) \
(.ocm.b.mod.c.p:{TAIL}={PLATFORMDIR}/libc.a) \
{FLOATS?} \
(.e:{TAIL}={PLATFORMDIR}/libem.a \
{PLATFORMDIR}/libsys.a \
{PLATFORMDIR}/libend.a)
linker
end
name cv
from .out
to .img
program {EM}/bin/aslod
args < >
outfile nes.img
end

View File

@@ -0,0 +1,14 @@
/* $Source$
* $State$
* $Revision$
*/
#ifndef _ACK_CONFIG_H
#define _ACK_CONFIG_H
/* We're providing a time() system call rather than wanting a wrapper around
* gettimeofday() in the libc. */
#define ACKCONF_TIME_IS_A_SYSCALL
#endif

71
plat/nes/include/unistd.h Normal file
View File

@@ -0,0 +1,71 @@
/*
* unistd.h - standard system calls
*/
/* $Id$ */
#ifndef _UNISTD_H
#define _UNISTD_H
#include <stddef.h>
/* Types */
typedef int pid_t;
typedef int mode_t;
/* Constants for file access (open and friends) */
enum
{
O_ACCMODE = 0x3,
O_RDONLY = 0,
O_WRONLY = 1,
O_RDWR = 2,
O_CREAT = 0100,
O_TRUNC = 01000,
O_APPEND = 02000,
O_NONBLOCK = 04000
};
/* Special variables */
extern char** environ;
/* Implemented system calls */
extern void _exit(int);
extern pid_t getpid(void);
extern void* sbrk(intptr_t increment);
extern int isatty(int d);
extern off_t lseek(int fildes, off_t offset, int whence);
extern int close(int d);
extern int open(const char* path, int access, ...);
extern int creat(const char* path, mode_t mode);
extern int read(int fd, void* buffer, size_t count);
extern int write(int fd, void* buffer, size_t count);
/* Unimplemented system calls (these are just prototypes to let the library
* compile). */
extern int fcntl(int fd, int op, ...);
/* Signal handling */
typedef int sig_atomic_t;
#define SIG_ERR ((sighandler_t) -1) /* Error return. */
#define SIG_DFL ((sighandler_t) 0) /* Default action. */
#define SIG_IGN ((sighandler_t) 1) /* Ignore signal. */
#define SIGABRT 6 /* Abort (ANSI) */
#define SIGILL 11 /* Illegal instruction */
#define _NSIG 32 /* Biggest signal number + 1
(not including real-time signals). */
typedef void (*sighandler_t)(int);
extern sighandler_t signal(int signum, sighandler_t handler);
extern int raise(int signum);
#endif

19
plat/nes/libsys/_hol0.s Normal file
View File

@@ -0,0 +1,19 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .bss
! This data block is used to store information about the current line number
! and file.
.define hol0
.comm hol0, 8

View File

@@ -0,0 +1,23 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Reads a single byte.
.define __sys_rawread
__sys_rawread:
xorb ah, ah
int 0x16
xorb ah, ah
ret

View File

@@ -0,0 +1,29 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
.sect .text
! Writes a single byte to the console.
.define __sys_rawwrite
.extern __sys_rawwrite
__sys_rawwrite:
push bp
mov bp, sp
movb al, 4(bp)
movb ah, 0x0E
mov bx, 0x0007
int 0x10
jmp .cret

43
plat/nes/libsys/brk.c Normal file
View File

@@ -0,0 +1,43 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#define OUT_OF_MEMORY (void*)(-1) /* sbrk returns this on failure */
#define STACK_BUFFER 128 /* number of bytes to leave for stack */
extern char _end[1];
static char* current = _end;
int brk(void* newend)
{
/* This variable is used to figure out the current stack pointer,
* by taking its address. */
char dummy;
char* p = newend;
if ((p > (&dummy - STACK_BUFFER)) ||
(p < _end))
return -1;
current = p;
return 0;
}
void* sbrk(intptr_t increment)
{
char* old;
if (increment == 0)
return current;
old = current;
if (brk(old + increment) < 0)
return OUT_OF_MEMORY;
return old;
}

14
plat/nes/libsys/close.c Normal file
View File

@@ -0,0 +1,14 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
int close(int fd)
{
errno = EBADF;
return -1;
}

15
plat/nes/libsys/creat.c Normal file
View File

@@ -0,0 +1,15 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include "libsys.h"
int open(const char* path, int access, ...)
{
errno = EACCES;
return -1;
}

28
plat/nes/libsys/errno.s Normal file
View File

@@ -0,0 +1,28 @@
#
! $Source$
! $State$
! $Revision$
! Declare segments (the order is important).
.sect .text
.sect .rom
.sect .data
.sect .bss
#define D(e) .define e; e
.sect .data
! Define various ACK error numbers. Note that these are *not* ANSI C
! errnos, and are used for different purposes.
D(ERANGE) = 1
D(ESET) = 2
D(EIDIVZ) = 6
D(EHEAP) = 17
D(EILLINS) = 18
D(EODDZ) = 19
D(ECASE) = 20
D(EBADMON) = 25

13
plat/nes/libsys/getpid.c Normal file
View File

@@ -0,0 +1,13 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
pid_t getpid(void)
{
return 0;
}

4
plat/nes/libsys/hello.c Normal file
View File

@@ -0,0 +1,4 @@
int hello(void)
{
return 42;
}

13
plat/nes/libsys/isatty.c Normal file
View File

@@ -0,0 +1,13 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
int isatty(int fd)
{
return 1;
}

14
plat/nes/libsys/kill.c Normal file
View File

@@ -0,0 +1,14 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
int kill(pid_t pid, int sig)
{
errno = EINVAL;
return -1;
}

16
plat/nes/libsys/libsys.h Normal file
View File

@@ -0,0 +1,16 @@
/* $Source$
* $State$
* $Revision$
*/
#ifndef LIBSYS_H
#define LIBSYS_H
extern void _sys_rawwrite(unsigned char b);
extern unsigned char _sys_rawread(void);
extern void _sys_write_tty(char c);
/* extern int _sys_ttyflags; */
#endif

14
plat/nes/libsys/lseek.c Normal file
View File

@@ -0,0 +1,14 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
off_t lseek(int fd, off_t offset, int whence)
{
errno = EINVAL;
return -1;
}

14
plat/nes/libsys/open.c Normal file
View File

@@ -0,0 +1,14 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include "libsys.h"
int creat(const char* path, int mode)
{
return open(path, O_CREAT|O_WRONLY|O_TRUNC, mode);
}

31
plat/nes/libsys/pmfile Normal file
View File

@@ -0,0 +1,31 @@
-- $Source$
-- $State$
-- $Revision$
local d = ROOTDIR.."plat/nes/libsys/"
libsys_nes = acklibrary {
ACKBUILDFLAGS = {PARENT, "-ansi"},
ACKINCLUDES = {"%BINDIR%include"},
-- ackfile (d.."errno.s"),
-- ackfile (d.."_hol0.s"),
-- ackfile (d.."_sys_rawread.s"),
-- ackfile (d.."_sys_rawwrite.s"),
-- ackfile (d.."open.c"),
-- ackfile (d.."creat.c"),
-- ackfile (d.."close.c"),
-- ackfile (d.."read.c"),
-- ackfile (d.."write.c"),
-- ackfile (d.."brk.c"),
-- ackfile (d.."getpid.c"),
-- ackfile (d.."kill.c"),
-- ackfile (d.."isatty.c"),
-- ackfile (d.."lseek.c"),
-- ackfile (d.."time.c"),
-- ackfile (d.."signal.c"),
ackfile (d.."hello.c"),
install = pm.install("%BINDIR%lib/%PLATFORM%/libsys.a"),
}

43
plat/nes/libsys/read.c Normal file
View File

@@ -0,0 +1,43 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include "libsys.h"
int read(int fd, void* buffer, size_t count)
{
char i;
/* We're only allowed to read from fd 0, 1 or 2. */
if ((fd < 0) || (fd > 2))
{
errno = EBADF;
return -1;
}
/* Empty buffer? */
if (count == 0)
return 0;
/* Read one byte. */
i = _sys_rawread();
#if 0
if ((i == '\r') && !(_sys_ttyflags & RAW))
i = '\n';
if (_sys_ttyflags & ECHO)
_sys_write_tty(i);
#endif
if (i == '\r')
i = '\n';
_sys_write_tty(i);
*(char*)buffer = i;
return 1;
}

15
plat/nes/libsys/signal.c Normal file
View File

@@ -0,0 +1,15 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include "libsys.h"
sighandler_t signal(int signum, sighandler_t handler)
{
return SIG_DFL;
}

17
plat/nes/libsys/time.c Normal file
View File

@@ -0,0 +1,17 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include "libsys.h"
time_t time(time_t* t)
{
if (t)
*t = 0;
return 0;
}

48
plat/nes/libsys/write.c Normal file
View File

@@ -0,0 +1,48 @@
/* $Source$
* $State$
* $Revision$
*/
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include "libsys.h"
void _sys_write_tty(char c)
{
_sys_rawwrite(c);
#if 0
if ((c == '\n') && !(_sys_ttyflags & RAW))
_sys_rawwrite('\r');
#endif
if (c == '\n')
_sys_rawwrite('\r');
}
int write(int fd, void* buffer, size_t count)
{
int i;
char* p = buffer;
/* We're only allowed to write to fd 0, 1 or 2. */
if ((fd < 0) || (fd > 2))
{
errno = EBADF;
return -1;
}
/* Write all data. */
i = 0;
while (i < count)
{
_sys_write_tty(*p++);
i++;
}
/* No failures. */
return count;
}

45
plat/nes/pmfile Normal file
View File

@@ -0,0 +1,45 @@
-- $Source$
-- $State$
-- $Revision$
local d = ROOTDIR.."plat/nes/"
include (d.."libsys/pmfile")
local bootsector = ackfile {
file (d.."boot.s"),
install = pm.install("%BINDIR%lib/nes/boot.o"),
}
local descr = group {
install = pm.install(d.."descr", "%BINDIR%%PLATIND%/%PLATFORM%/descr")
}
local headers = group {
install = {
pm.install(d.."include/ack/config.h", "%BINDIR%%PLATIND%/%PLATFORM%/include/ack/config.h"),
pm.install(d.."include/unistd.h", "%BINDIR%%PLATIND%/%PLATFORM%/include/unistd.h"),
}
}
platform_nes = group {
ARCH = "6500",
PLATFORM = "nes",
OPTIMISATION = "-O",
-- Ensure the descr and headers are installed first because we'll need
-- them to build the libraries.
descr,
headers,
-- Build the back-end support.
mach_6500,
support_6500,
lang_runtimes,
-- Build the NES library.
libsys_nes,
bootsector
}

View File

@@ -23,7 +23,7 @@
! If you ever need to change the boot code, this needs adjusting. I recommend
! a hex editor.
PADDING = 0xB9
PADDING = 0xB7
! Some definitions.
@@ -45,8 +45,8 @@ start2:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
! Defer setting es until after probing the drive.
! Initialise the stack, which will start at the top of our segment and work
! down.
@@ -65,10 +65,13 @@ start2:
call write_string
! Probe the drive to figure out its geometry.
! This might clobber es.
push dx
push dx
mov ax, 0x0800 ! service number
int 0x13
mov ax, cs ! restore es
mov es, ax
pop ax
jc cant_boot

13
pmfile
View File

@@ -38,7 +38,7 @@ include "util/amisc/pmfile"
include "util/cmisc/pmfile"
include "util/ack/pmfile"
include "util/arch/pmfile"
-- include "util/cpp/pmfile"
include "util/cpp/pmfile"
include "lang/cem/cpp.ansi/pmfile"
include "util/cgg/pmfile"
include "util/ncgg/pmfile"
@@ -98,6 +98,9 @@ include "plat/linux386/pmfile" -- Linux executables
include "mach/i80/pmfile" -- generic 8080
include "plat/cpm/pmfile" -- CP/M
include "mach/6500/pmfile" -- generic 6500
include "plat/nes/pmfile" -- NES
default = group {
-- Lots of things use LLgen, so we need to build it first.
@@ -127,7 +130,7 @@ default = group {
tool_tabgen,
tool_aal,
tool_ack,
-- tool_cpp, -- K&R C
tool_cpp, -- K&R C
tool_cpp_ansi, -- ANSI C
tool_cgg,
tool_ncgg,
@@ -157,8 +160,7 @@ default = group {
-- libraries.
--[[
mach_6500,
lang_runtimes { ARCH="6500", OPTIMISATION="-O" },
mach_6500, lang_runtimes { ARCH="6500", OPTIMISATION="-O" },
mach_6800,
mach_6805,
@@ -180,7 +182,8 @@ default = group {
platform_pc86,
platform_linux386,
platform_cpm
platform_cpm,
platform_nes,
}
-- Ensure that the work directories exist.

View File

@@ -15,20 +15,6 @@
ack \- Amsterdam Compiler Kit
.SH SYNOPSIS
\fBack\fP arguments
.br
\fBacc\fP arguments
.br
\fBapc\fP arguments
.br
\fBabc\fP arguments
.br
\fBm2\fP arguments
.br
\fBocm\fP arguments
.br
\fBf2c\fP arguments
.br
\fImachine\fP arguments
.SH DESCRIPTION
This program transforms sources in several
languages to load files for a variety of machines,
@@ -89,10 +75,6 @@ Object file.
\fIAck\fP accepts the following flags:
.IP \-m\fImachine\fP
This flag tells \fIack\fP to generate a load file for \fImachine\fP.
\fIMachine\fP can also be used as the program call
name, instead of \fIack\fP.
e.g. \fIack \-mi86 file.p\fP is equivalent to \fIi86
file.p\fP.
.IP \-o
Use the next argument as the name of the resulting file.
\fIAck\fP produces \fIa.out\fP or \fIe.out\fP by default.

View File

@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include "ack.h"
@@ -83,19 +84,26 @@ char *firstblank(str) char *str ; {
}
/* VARARGS1 */
fatal(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
void fatal(const char* fmt, ...)
{
/* Fatal internal error */
va_list ap;
va_start(ap, fmt);
fprintf(STDOUT,"%s: fatal internal error, ",progname) ;
fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
vfprintf(STDOUT, fmt, ap);
fprintf(STDOUT,"\n") ;
quit(-2) ;
}
/* VARARGS1 */
vprint(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
void vprint(const char* fmt, ...)
{
/* Diagnostic print, no auto NL */
fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
va_list ap;
va_start(ap, fmt);
vfprintf(STDOUT, fmt, ap);
va_end(ap);
}
#ifdef DEBUG
@@ -108,30 +116,38 @@ prns(s) register char *s ; {
#endif
/* VARARGS1 */
fuerror(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
void fuerror(const char *fmt, ...) {
/* Fatal user error */
va_list ap;
va_start(ap, fmt);
fprintf(STDOUT,"%s: ",progname) ;
fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
vfprintf(STDOUT, fmt, ap);
fprintf(STDOUT,"\n") ;
quit(-1) ;
}
/* VARARGS1 */
werror(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
void werror(const char *fmt, ...) {
/* Warning user error, w_flag */
va_list ap;
if ( w_flag ) return ;
va_start(ap, fmt);
fprintf(STDOUT,"%s: warning, ",progname) ;
fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
vfprintf(STDOUT, fmt, ap);
fprintf(STDOUT,"\n") ;
va_end(ap);
}
/* VARARGS1 */
error(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
void error(const char *fmt, ...) {
/* User error, it is the callers responsibility to quit */
va_list ap;
va_start(ap, fmt);
fprintf(STDOUT,"%s: ",progname) ;
fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
vfprintf(STDOUT, fmt, ap);
fprintf(STDOUT,"\n") ;
n_error++ ;
va_end(ap);
}
do_flush() {

View File

@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include "out.h"
@@ -221,7 +222,7 @@ void iconvert(char* buf, char* str, char* fmt)
{
register char *nf, *ni, *no ;
int last, i ;
long value ;
uint32_t value ;
ni=buf ; no=str ; nf=fmt ;
while ( last = *nf++ ) {
last -= '0' ;
@@ -234,8 +235,8 @@ void iconvert(char* buf, char* str, char* fmt)
switch ( last ) {
case 0 : break ;
case 1 : *no= value ; break ;
case 2 : *(unsigned short *)no = value ; break ;
case 4 : *(long *)no = value ; break ;
case 2 : *(uint16_t *)no = value ; break ;
case 4 : *(uint32_t *)no = value ; break ;
default :
fatal("illegal out.h format string\n");
}

View File

@@ -140,42 +140,29 @@ void emits(struct outsect* section)
}
void iconvert(char* buf, char* str, char* fmt)
{
register char *nf, *ni, *no ;
int last, i ;
long value ;
ni=buf ; no=str ; nf=fmt ;
while ( last = *nf++ ) {
last -= '0' ;
if ( last<1 || last >9 ) fatal("illegal out.h format string\n");
value=0 ;
i=last ;
while ( i-- ) {
value = (value<<8) + (ni[i]&0xFF) ;
}
switch ( last ) {
case 0 : break ;
case 1 : *no= value ; break ;
case 2 : *(unsigned short *)no = value ; break ;
case 4 : *(long *)no = value ; break ;
default :
fatal("illegal out.h format string\n");
}
ni += last ; no += last ;
}
}
/* Macros from modules/src/object/obj.h */
#define Xchar(ch) ((ch) & 0377)
#define uget2(c) (Xchar((c)[0]) | ((unsigned) Xchar((c)[1]) << 8))
#define get4(c) (uget2(c) | ((long) uget2((c)+2) << 16))
/* Read the ack.out file header. */
int rhead(FILE* f, struct outhead* head)
{
char buf[sizeof(struct outhead)];
char buf[SZ_HEAD], *c;
if (fread(buf, sizeof(buf), 1, f) != 1)
return 0;
iconvert(buf, (char*) head, SF_HEAD);
c = buf;
head->oh_magic = uget2(c); c += 2;
head->oh_stamp = uget2(c); c += 2;
head->oh_flags = uget2(c); c += 2;
head->oh_nsect = uget2(c); c += 2;
head->oh_nrelo = uget2(c); c += 2;
head->oh_nname = uget2(c); c += 2;
head->oh_nemit = get4(c); c += 4;
head->oh_nchar = get4(c);
return 1;
}
@@ -183,12 +170,17 @@ int rhead(FILE* f, struct outhead* head)
int rsect(FILE* f, struct outsect* sect)
{
char buf[sizeof(struct outsect)];
char buf[SZ_SECT], *c;
if (fread(buf, sizeof(buf), 1, f) != 1)
return 0;
iconvert(buf, (char*) sect, SF_SECT);
c = buf;
sect->os_base = get4(c); c += 4;
sect->os_size = get4(c); c += 4;
sect->os_foff = get4(c); c += 4;
sect->os_flen = get4(c); c += 4;
sect->os_lign = get4(c);
return 1 ;
}

View File

@@ -189,7 +189,13 @@ cons_t xgetarb(l,f) int l; FILE *f ; {
shift=0 ; val=0 ;
while ( l-- ) {
val += ((cons_t)(c = ctrunc(xgetc(f))))<<shift ;
// val += ((cons_t)(c = ctrunc(xgetc(f))))<<shift ;
// Bug here: shifts with too large shift counts
// get unspecified results. --Ceriel
c = ctrunc(xgetc(f));
if (shift < 8 * sizeof(cons_t)) {
val += ((cons_t)c)<<shift ;
}
shift += 8 ;
}
if (c == 0377 && shift > 8 && ((shift>>3)&1)) {

View File

@@ -849,8 +849,28 @@ extxcon(header) {
return ;
}
/* Added atol() that ignores overflow. --Ceriel */
long atol(s)
register char *s;
{
register long total = 0;
register unsigned digit;
int minus = 0;
while (*s == ' ' || *s == '\t') s++;
if (*s == '+') s++;
else if (*s == '-') {
s++;
minus = 1;
}
while ((digit = *s++ - '0') < 10) {
total *= 10;
total += digit;
}
return(minus ? -total : total);
}
extvcon(header) {
extern long atol() ;
/*
* generate data for a constant initialized by a string.
*/

View File

@@ -357,22 +357,22 @@ DoCFU()
wtrap(WILLCONV, EILLINS);
}
f = fpop(4L);
npush((long) f, 2L);
npush((unsigned long) f, 2L);
return;
case 44:
f = fpop(4L);
npush((long) f, 4L);
npush((unsigned long) f, 4L);
return;
case 82:
if (wsize == 4) {
wtrap(WILLCONV, EILLINS);
}
f = fpop(8L);
npush((long) f, 2L);
npush((unsigned long) f, 2L);
return;
case 84:
f = fpop(8L);
npush((long) f, 4L);
npush((unsigned long) f, 4L);
return;
default:
wtrap(WILLCONV, EILLINS);

View File

@@ -6,13 +6,14 @@
static char rcsid[] = "$Id$";
#endif
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <out.h>
#include "const.h"
static short nerrors = 0;
static diag();
static void diag(char *, char *, va_list);
stop()
{
@@ -28,40 +29,49 @@ stop()
}
/* VARARGS1 */
fatal(format, a1, a2, a3, a4)
char *format;
void
fatal(char *format, ...)
{
va_list ap;
va_start(ap, format);
nerrors++;
diag("fatal", format, a1, a2, a3, a4);
diag("fatal", format, ap);
stop();
}
/* VARARGS1 */
warning(format, a1, a2, a3, a4)
char *format;
void
warning(char *format, ...)
{
diag("warning", format, a1, a2, a3, a4);
va_list ap;
va_start(ap, format);
diag("warning", format, ap);
va_end(ap);
}
/* VARARGS1 */
error(format, a1, a2, a3, a4)
char *format;
void
error(char *format, ...)
{
va_list ap;
va_start(ap, format);
nerrors++;
diag("error", format, a1, a2, a3, a4);
diag("error", format, ap);
va_end(ap);
}
/* VARARGS1 */
do_verbose(format, a1, a2, a3, a4)
char *format;
void
do_verbose(char *format, ...)
{
diag((char *) 0, format, a1, a2, a3, a4);
va_list ap;
va_start(ap, format);
diag((char *) 0, format, ap);
va_end(ap);
}
static
diag(tail, format, a1, a2, a3, a4)
char *tail;
char *format;
static void
diag(char *tail, char *format, va_list ap)
{
extern char *progname, *archname, *modulname;
@@ -72,7 +82,7 @@ diag(tail, format, a1, a2, a3, a4)
fprintf(stderr, "%s: ", archname);
else if (modulname)
fprintf(stderr, "%s: ", modulname);
fprintf(stderr, format, a1, a2, a3, a4);
vfprintf(stderr, format, ap);
if (tail) fprintf(stderr, " (%s)\n", tail);
else putc('\n', stderr);
}