take alignments into account

This commit is contained in:
ceriel 1987-08-11 15:28:06 +00:00
parent 0300bbf5cb
commit c3fec1f112
2 changed files with 44 additions and 24 deletions

View file

@ -95,6 +95,22 @@ long textsize ;
long datasize ; long datasize ;
long bsssize; 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) main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
@ -133,8 +149,7 @@ main(argc, argv)
/* A few checks */ /* A few checks */
if ( outsect[BSSSG].os_flen != 0 ) if ( outsect[BSSSG].os_flen != 0 )
fatal("bss space contains initialized data\n") ; fatal("bss space contains initialized data\n") ;
if ( !unresolved && outsect[BSSSG].os_base != outsect[DATASG].os_base+ if ( !unresolved && ! follows(&outsect[BSSSG], &outsect[DATASG]))
outsect[DATASG].os_size )
fatal("bss segment must follow data segment\n") ; fatal("bss segment must follow data segment\n") ;
if ( outsect[ROMSG].os_lign == 0x20000 ) { if ( outsect[ROMSG].os_lign == 0x20000 ) {
/* 410/413 file with ROMSG in data space */ /* 410/413 file with ROMSG in data space */
@ -142,8 +157,7 @@ main(argc, argv)
magic= NMAGIC ; magic= NMAGIC ;
textsize= outsect[TEXTSG].os_size ; textsize= outsect[TEXTSG].os_size ;
datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ; datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ;
if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ if (! follows(&outsect[DATASG], &outsect[ROMSG]))
outsect[ROMSG].os_size )
fatal("data segment must follow rom\n") ; fatal("data segment must follow rom\n") ;
} else } else
if ( outsect[DATASG].os_lign == 0x20000 ) { if ( outsect[DATASG].os_lign == 0x20000 ) {
@ -152,8 +166,7 @@ main(argc, argv)
magic= NMAGIC ; magic= NMAGIC ;
textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ; textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ;
datasize= outsect[DATASG].os_size ; datasize= outsect[DATASG].os_size ;
if ( outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ if (! follows(&outsect[ROMSG],&outsect[TEXTSG].os_base))
outsect[TEXTSG].os_size )
fatal("rom segment must follow text\n") ; fatal("rom segment must follow text\n") ;
} else { } else {
/* Plain 407 file */ /* Plain 407 file */
@ -162,11 +175,9 @@ main(argc, argv)
textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ; textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ;
datasize= outsect[DATASG].os_size ; datasize= outsect[DATASG].os_size ;
if (!unresolved) { if (!unresolved) {
if (outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ if (! follows(&outsect[ROMSG],&outsect[TEXTSG]))
outsect[TEXTSG].os_size )
fatal("rom segment must follow text\n") ; fatal("rom segment must follow text\n") ;
if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ if (! follows(&outsect[DATASG],&outsect[ROMSG]))
outsect[ROMSG].os_size )
fatal("data segment must follow rom\n") ; fatal("data segment must follow rom\n") ;
} }
} }
@ -180,8 +191,7 @@ main(argc, argv)
} }
bsssize = outsect[BSSSG].os_size; bsssize = outsect[BSSSG].os_size;
if ( outhead.oh_nsect==NSECT ) { if ( outhead.oh_nsect==NSECT ) {
if ( outsect[LSECT].os_base != outsect[BSSSG].os_base+ if (! follows(&outsect[LSECT],&outsect[BSSSG]))
outsect[BSSSG].os_size )
fatal("end segment must follow bss\n") ; fatal("end segment must follow bss\n") ;
if ( outsect[LSECT].os_size != 0 ) if ( outsect[LSECT].os_size != 0 )
fatal("end segment must be empty\n") ; fatal("end segment must be empty\n") ;

View file

@ -95,6 +95,22 @@ long textsize ;
long datasize ; long datasize ;
long bsssize; 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) main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
@ -133,8 +149,7 @@ main(argc, argv)
/* A few checks */ /* A few checks */
if ( outsect[BSSSG].os_flen != 0 ) if ( outsect[BSSSG].os_flen != 0 )
fatal("bss space contains initialized data\n") ; fatal("bss space contains initialized data\n") ;
if ( !unresolved && outsect[BSSSG].os_base != outsect[DATASG].os_base+ if ( !unresolved && ! follows(&outsect[BSSSG], &outsect[DATASG]))
outsect[DATASG].os_size )
fatal("bss segment must follow data segment\n") ; fatal("bss segment must follow data segment\n") ;
if ( outsect[ROMSG].os_lign == 0x20000 ) { if ( outsect[ROMSG].os_lign == 0x20000 ) {
/* 410/413 file with ROMSG in data space */ /* 410/413 file with ROMSG in data space */
@ -142,8 +157,7 @@ main(argc, argv)
magic= NMAGIC ; magic= NMAGIC ;
textsize= outsect[TEXTSG].os_size ; textsize= outsect[TEXTSG].os_size ;
datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ; datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ;
if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ if (! follows(&outsect[DATASG], &outsect[ROMSG]))
outsect[ROMSG].os_size )
fatal("data segment must follow rom\n") ; fatal("data segment must follow rom\n") ;
} else } else
if ( outsect[DATASG].os_lign == 0x20000 ) { if ( outsect[DATASG].os_lign == 0x20000 ) {
@ -152,8 +166,7 @@ main(argc, argv)
magic= NMAGIC ; magic= NMAGIC ;
textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ; textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ;
datasize= outsect[DATASG].os_size ; datasize= outsect[DATASG].os_size ;
if ( outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ if (! follows(&outsect[ROMSG],&outsect[TEXTSG].os_base))
outsect[TEXTSG].os_size )
fatal("rom segment must follow text\n") ; fatal("rom segment must follow text\n") ;
} else { } else {
/* Plain 407 file */ /* Plain 407 file */
@ -162,11 +175,9 @@ main(argc, argv)
textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ; textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ;
datasize= outsect[DATASG].os_size ; datasize= outsect[DATASG].os_size ;
if (!unresolved) { if (!unresolved) {
if (outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ if (! follows(&outsect[ROMSG],&outsect[TEXTSG]))
outsect[TEXTSG].os_size )
fatal("rom segment must follow text\n") ; fatal("rom segment must follow text\n") ;
if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ if (! follows(&outsect[DATASG],&outsect[ROMSG]))
outsect[ROMSG].os_size )
fatal("data segment must follow rom\n") ; fatal("data segment must follow rom\n") ;
} }
} }
@ -180,8 +191,7 @@ main(argc, argv)
} }
bsssize = outsect[BSSSG].os_size; bsssize = outsect[BSSSG].os_size;
if ( outhead.oh_nsect==NSECT ) { if ( outhead.oh_nsect==NSECT ) {
if ( outsect[LSECT].os_base != outsect[BSSSG].os_base+ if (! follows(&outsect[LSECT],&outsect[BSSSG]))
outsect[BSSSG].os_size )
fatal("end segment must follow bss\n") ; fatal("end segment must follow bss\n") ;
if ( outsect[LSECT].os_size != 0 ) if ( outsect[LSECT].os_size != 0 )
fatal("end segment must be empty\n") ; fatal("end segment must be empty\n") ;