improved alignment checking
This commit is contained in:
parent
80af6ce214
commit
4b265a4f0a
1 changed files with 37 additions and 20 deletions
|
@ -66,6 +66,22 @@ char hdr[HDR_LENGTH] ;
|
||||||
FILE *input;
|
FILE *input;
|
||||||
FILE *output;
|
FILE *output;
|
||||||
|
|
||||||
|
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[];
|
||||||
|
@ -114,41 +130,42 @@ main(argc, argv)
|
||||||
outsect[TEXT].os_base) ;
|
outsect[TEXT].os_base) ;
|
||||||
if ( outsect[BSS].os_flen != 0 )
|
if ( outsect[BSS].os_flen != 0 )
|
||||||
fatal("bss space contains initialized data\n") ;
|
fatal("bss space contains initialized data\n") ;
|
||||||
if ( outsect[BSS].os_base != outsect[DATA].os_base+
|
if ( ! follows(&outsect[BSS], &outsect[DATA]))
|
||||||
outsect[DATA].os_size )
|
|
||||||
fatal("bss segment must follow data segment\n") ;
|
fatal("bss segment must follow data segment\n") ;
|
||||||
if ( outsect[ROM].os_lign == 0x8000 ) {
|
if ( outsect[ROM].os_lign == 0x8000 ) {
|
||||||
/* 410 file with ROM in data space */
|
/* 410 file with ROM in data space */
|
||||||
|
if ( ! follows(&outsect[DATA], &outsect[ROM]))
|
||||||
|
fatal("data segment must follow rom\n") ;
|
||||||
magic= 0410 ;
|
magic= 0410 ;
|
||||||
textsize= outsect[TEXT].os_size ;
|
textsize= outsect[TEXT].os_size ;
|
||||||
datasize= outsect[ROM].os_size + outsect[DATA].os_size ;
|
datasize= outsect[BSS].os_base - outsect[ROM].os_base ;
|
||||||
if ( outsect[DATA].os_base != outsect[ROM].os_base+
|
outsect[ROM].os_size = outsect[DATA].os_base - outsect[ROM].os_base;
|
||||||
outsect[ROM].os_size )
|
outsect[DATA].os_size = outsect[BSS].os_base - outsect[DATA].os_base;
|
||||||
fatal("data segment must follow rom\n") ;
|
|
||||||
} else
|
} else
|
||||||
if ( outsect[DATA].os_lign == 0x8000 ) {
|
if ( outsect[DATA].os_lign == 0x8000 ) {
|
||||||
/* 410 file with ROM in instruction space */
|
/* 410 file with ROM in instruction space */
|
||||||
magic= 0410 ;
|
if ( ! follows(& outsect[ROM], &outsect[TEXT].os_base))
|
||||||
textsize= outsect[TEXT].os_size + outsect[ROM].os_size ;
|
|
||||||
datasize= outsect[DATA].os_size ;
|
|
||||||
if ( outsect[ROM].os_base != outsect[TEXT].os_base+
|
|
||||||
outsect[TEXT].os_size )
|
|
||||||
fatal("rom segment must follow text\n") ;
|
fatal("rom segment must follow text\n") ;
|
||||||
|
magic= 0410 ;
|
||||||
|
outsect[TEXT].os_size = outsect[ROM].os_base - outsect[TEXT].os_base;
|
||||||
|
textsize= outsect[TEXT].os_size + outsect[ROM].os_size ;
|
||||||
|
datasize= outsect[BSS].os_base - outsect[DATA].os_base ;
|
||||||
|
outsect[DATA].os_size = datasize;
|
||||||
} else {
|
} else {
|
||||||
/* Plain 407 file */
|
/* Plain 407 file */
|
||||||
magic= 0407 ;
|
if ( ! follows(& outsect[ROM], &outsect[TEXT]))
|
||||||
textsize= outsect[TEXT].os_size ;
|
|
||||||
datasize= outsect[ROM].os_size + outsect[DATA].os_size ;
|
|
||||||
if ( outsect[ROM].os_base != outsect[TEXT].os_base+
|
|
||||||
outsect[TEXT].os_size )
|
|
||||||
fatal("rom segment must follow text\n") ;
|
fatal("rom segment must follow text\n") ;
|
||||||
if ( outsect[DATA].os_base != outsect[ROM].os_base+
|
if ( ! follows(& outsect[DATA], &outsect[ROM]))
|
||||||
outsect[ROM].os_size )
|
|
||||||
fatal("data segment must follow rom\n") ;
|
fatal("data segment must follow rom\n") ;
|
||||||
|
magic= 0407 ;
|
||||||
|
outsect[TEXT].os_size = textsize
|
||||||
|
= outsect[ROM].os_base - outsect[TEXT].os_base;
|
||||||
|
outsect[ROM].os_size = outsect[DATA].os_base - outsect[ROM].os_base;
|
||||||
|
outsect[DATA].os_size = outsect[BSS].os_base - outsect[DATA].os_base;
|
||||||
|
datasize= outsect[ROM].os_size + outsect[DATA].os_size ;
|
||||||
}
|
}
|
||||||
if ( outhead.oh_nsect==NSECT ) {
|
if ( outhead.oh_nsect==NSECT ) {
|
||||||
if ( outsect[LSECT].os_base != outsect[BSS].os_base+
|
if (! follows(&outsect[LSECT], &outsect[BSS]))
|
||||||
outsect[BSS].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") ;
|
||||||
|
|
Loading…
Reference in a new issue