|
Checksum section of Listing 1, Unix Kernel Load Utility: 'boot.exe' (file: boot.c)
...
/* 16 bit checksum of program. */
far_cksum(base, len) long len; char far *base; {
char far *tmp;
unsigned seg,offs ;
long nbytes,sum, tlen;
tmp = base;
sum = 0;
nbytes = 0;
while (len) {
/* normalize far pointer to handle segment rollover case */
tmp = normalize(tmp);
/* Do a page at a time */
tlen = (len > PGSIZE)? PGSIZE : len;
len -= tlen ;
while (tlen--) {
nbytes++;
if (sum&01)
sum = (sum>>1) + 0x8000;
else
sum >>= 1;
sum += *tmp++ ;
sum &= 0xFFFF;
}
}
printf("\nChecksum %05lu%6ld ", sum, (nbytes+CLSIZE)/PGSIZE);
}
...
[ Learned a lesson with the 2BSD kernel back in the early 80's - be careful with bootstrap artifacts. Let someone else develop a new bootstrap which "seemed to work", but months later after the bootstrap was forgotten, the kernel started acting up. Had assumed that the problem was the new features and radical changes underway, so we withdrew them relentlessly. Sometimes it would work, sometimes not.
Burned out on this with regression tests, and ended up going off to a Unix Conference in Texas telling the audience the release was delayed. Months later, I find out that it was a bootstrap artifact, where portions of the kernel were overwritten by the bootstrap loading it. In every port this would come up. Software systems are fragile, especially at the beginning. -wfj ]
|