diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/unexhp9k800.c | 167 |
1 files changed, 83 insertions, 84 deletions
diff --git a/src/unexhp9k800.c b/src/unexhp9k800.c index c7902f1e948..0d8f1a7cf0e 100644 --- a/src/unexhp9k800.c +++ b/src/unexhp9k800.c | |||
| @@ -32,9 +32,9 @@ | |||
| 32 | conjunction with this routine, the following code must executed when | 32 | conjunction with this routine, the following code must executed when |
| 33 | the new process starts up. | 33 | the new process starts up. |
| 34 | 34 | ||
| 35 | void _sigreturn(); | 35 | void _sigreturn (); |
| 36 | ... | 36 | ... |
| 37 | sigsetreturn(_sigreturn); | 37 | sigsetreturn (_sigreturn); |
| 38 | */ | 38 | */ |
| 39 | 39 | ||
| 40 | #include <stdio.h> | 40 | #include <stdio.h> |
| @@ -43,14 +43,13 @@ | |||
| 43 | 43 | ||
| 44 | #include <a.out.h> | 44 | #include <a.out.h> |
| 45 | 45 | ||
| 46 | #define NBPG 2048 | 46 | #define roundup(x,n) (((x) + ((n) - 1)) & ~((n) - 1)) /* n is power of 2 */ |
| 47 | #define roundup(x,n) ( ( (x)+(n-1) ) & ~(n-1) ) /* n is power of 2 */ | 47 | #define min(x,y) (((x) < (y)) ? (x) : (y)) |
| 48 | #define min(x,y) ( ((x)<(y))?(x):(y) ) | ||
| 49 | 48 | ||
| 50 | 49 | ||
| 51 | /* Create a new a.out file, same as old but with current data space */ | 50 | /* Create a new a.out file, same as old but with current data space */ |
| 52 | 51 | ||
| 53 | unexec(new_name, old_name, new_end_of_text, dummy1, dummy2) | 52 | unexec (new_name, old_name, new_end_of_text, dummy1, dummy2) |
| 54 | char new_name[]; /* name of the new a.out file to be created */ | 53 | char new_name[]; /* name of the new a.out file to be created */ |
| 55 | char old_name[]; /* name of the old a.out file */ | 54 | char old_name[]; /* name of the old a.out file */ |
| 56 | char *new_end_of_text; /* ptr to new edata/etext; NOT USED YET */ | 55 | char *new_end_of_text; /* ptr to new edata/etext; NOT USED YET */ |
| @@ -70,15 +69,15 @@ unexec(new_name, old_name, new_end_of_text, dummy1, dummy2) | |||
| 70 | intact. NOT implemented. */ | 69 | intact. NOT implemented. */ |
| 71 | 70 | ||
| 72 | /* Open the input and output a.out files */ | 71 | /* Open the input and output a.out files */ |
| 73 | old = open(old_name, O_RDONLY); | 72 | old = open (old_name, O_RDONLY); |
| 74 | if (old < 0) | 73 | if (old < 0) |
| 75 | { perror(old_name); exit(1); } | 74 | { perror (old_name); exit (1); } |
| 76 | new = open(new_name, O_CREAT|O_RDWR|O_TRUNC, 0777); | 75 | new = open (new_name, O_CREAT|O_RDWR|O_TRUNC, 0777); |
| 77 | if (new < 0) | 76 | if (new < 0) |
| 78 | { perror(new_name); exit(1); } | 77 | { perror (new_name); exit (1); } |
| 79 | 78 | ||
| 80 | /* Read the old headers */ | 79 | /* Read the old headers */ |
| 81 | read_header(old, &hdr, &auxhdr); | 80 | read_header (old, &hdr, &auxhdr); |
| 82 | 81 | ||
| 83 | /* Decide how large the new and old data areas are */ | 82 | /* Decide how large the new and old data areas are */ |
| 84 | old_size = auxhdr.exec_dsize; | 83 | old_size = auxhdr.exec_dsize; |
| @@ -88,39 +87,39 @@ unexec(new_name, old_name, new_end_of_text, dummy1, dummy2) | |||
| 88 | new_size = i - auxhdr.exec_dmem; | 87 | new_size = i - auxhdr.exec_dmem; |
| 89 | 88 | ||
| 90 | /* Copy the old file to the new, up to the data space */ | 89 | /* Copy the old file to the new, up to the data space */ |
| 91 | lseek(old, 0, 0); | 90 | lseek (old, 0, 0); |
| 92 | copy_file(old, new, auxhdr.exec_dfile); | 91 | copy_file (old, new, auxhdr.exec_dfile); |
| 93 | 92 | ||
| 94 | /* Skip the old data segment and write a new one */ | 93 | /* Skip the old data segment and write a new one */ |
| 95 | lseek(old, old_size, 1); | 94 | lseek (old, old_size, 1); |
| 96 | save_data_space(new, &hdr, &auxhdr, new_size); | 95 | save_data_space (new, &hdr, &auxhdr, new_size); |
| 97 | 96 | ||
| 98 | /* Copy the rest of the file */ | 97 | /* Copy the rest of the file */ |
| 99 | copy_rest(old, new); | 98 | copy_rest (old, new); |
| 100 | 99 | ||
| 101 | /* Update file pointers since we probably changed size of data area */ | 100 | /* Update file pointers since we probably changed size of data area */ |
| 102 | update_file_ptrs(new, &hdr, &auxhdr, auxhdr.exec_dfile, new_size-old_size); | 101 | update_file_ptrs (new, &hdr, &auxhdr, auxhdr.exec_dfile, new_size-old_size); |
| 103 | 102 | ||
| 104 | /* Save the modified header */ | 103 | /* Save the modified header */ |
| 105 | write_header(new, &hdr, &auxhdr); | 104 | write_header (new, &hdr, &auxhdr); |
| 106 | 105 | ||
| 107 | /* Close the binary file */ | 106 | /* Close the binary file */ |
| 108 | close(old); | 107 | close (old); |
| 109 | close(new); | 108 | close (new); |
| 110 | return 0; | 109 | return 0; |
| 111 | } | 110 | } |
| 112 | 111 | ||
| 113 | /* Save current data space in the file, update header. */ | 112 | /* Save current data space in the file, update header. */ |
| 114 | 113 | ||
| 115 | save_data_space(file, hdr, auxhdr, size) | 114 | save_data_space (file, hdr, auxhdr, size) |
| 116 | int file; | 115 | int file; |
| 117 | struct header *hdr; | 116 | struct header *hdr; |
| 118 | struct som_exec_auxhdr *auxhdr; | 117 | struct som_exec_auxhdr *auxhdr; |
| 119 | int size; | 118 | int size; |
| 120 | { | 119 | { |
| 121 | /* Write the entire data space out to the file */ | 120 | /* Write the entire data space out to the file */ |
| 122 | if (write(file, auxhdr->exec_dmem, size) != size) | 121 | if (write (file, auxhdr->exec_dmem, size) != size) |
| 123 | { perror("Can't save new data space"); exit(1); } | 122 | { perror ("Can't save new data space"); exit (1); } |
| 124 | 123 | ||
| 125 | /* Update the header to reflect the new data size */ | 124 | /* Update the header to reflect the new data size */ |
| 126 | auxhdr->exec_dsize = size; | 125 | auxhdr->exec_dsize = size; |
| @@ -129,7 +128,7 @@ save_data_space(file, hdr, auxhdr, size) | |||
| 129 | 128 | ||
| 130 | /* Update the values of file pointers when something is inserted. */ | 129 | /* Update the values of file pointers when something is inserted. */ |
| 131 | 130 | ||
| 132 | update_file_ptrs(file, hdr, auxhdr, location, offset) | 131 | update_file_ptrs (file, hdr, auxhdr, location, offset) |
| 133 | int file; | 132 | int file; |
| 134 | struct header *hdr; | 133 | struct header *hdr; |
| 135 | struct som_exec_auxhdr *auxhdr; | 134 | struct som_exec_auxhdr *auxhdr; |
| @@ -144,32 +143,32 @@ update_file_ptrs(file, hdr, auxhdr, location, offset) | |||
| 144 | 143 | ||
| 145 | /* Update the various file pointers in the header */ | 144 | /* Update the various file pointers in the header */ |
| 146 | #define update(ptr) if (ptr > location) ptr = ptr + offset | 145 | #define update(ptr) if (ptr > location) ptr = ptr + offset |
| 147 | update(hdr->aux_header_location); | 146 | update (hdr->aux_header_location); |
| 148 | update(hdr->space_strings_location); | 147 | update (hdr->space_strings_location); |
| 149 | update(hdr->init_array_location); | 148 | update (hdr->init_array_location); |
| 150 | update(hdr->compiler_location); | 149 | update (hdr->compiler_location); |
| 151 | update(hdr->symbol_location); | 150 | update (hdr->symbol_location); |
| 152 | update(hdr->fixup_request_location); | 151 | update (hdr->fixup_request_location); |
| 153 | update(hdr->symbol_strings_location); | 152 | update (hdr->symbol_strings_location); |
| 154 | update(hdr->unloadable_sp_location); | 153 | update (hdr->unloadable_sp_location); |
| 155 | update(auxhdr->exec_tfile); | 154 | update (auxhdr->exec_tfile); |
| 156 | update(auxhdr->exec_dfile); | 155 | update (auxhdr->exec_dfile); |
| 157 | 156 | ||
| 158 | /* Do for each subspace dictionary entry */ | 157 | /* Do for each subspace dictionary entry */ |
| 159 | lseek(file, hdr->subspace_location, 0); | 158 | lseek (file, hdr->subspace_location, 0); |
| 160 | for (i = 0; i < hdr->subspace_total; i++) | 159 | for (i = 0; i < hdr->subspace_total; i++) |
| 161 | { | 160 | { |
| 162 | if (read(file, &subspace, sizeof(subspace)) != sizeof(subspace)) | 161 | if (read (file, &subspace, sizeof (subspace)) != sizeof (subspace)) |
| 163 | { perror("Can't read subspace record"); exit(1); } | 162 | { perror ("Can't read subspace record"); exit (1); } |
| 164 | 163 | ||
| 165 | /* If subspace has a file location, update it */ | 164 | /* If subspace has a file location, update it */ |
| 166 | if (subspace.initialization_length > 0 | 165 | if (subspace.initialization_length > 0 |
| 167 | && subspace.file_loc_init_value > location) | 166 | && subspace.file_loc_init_value > location) |
| 168 | { | 167 | { |
| 169 | subspace.file_loc_init_value += offset; | 168 | subspace.file_loc_init_value += offset; |
| 170 | lseek(file, -sizeof(subspace), 1); | 169 | lseek (file, -sizeof (subspace), 1); |
| 171 | if (write(file, &subspace, sizeof(subspace)) != sizeof(subspace)) | 170 | if (write (file, &subspace, sizeof (subspace)) != sizeof (subspace)) |
| 172 | { perror("Can't update subspace record"); exit(1); } | 171 | { perror ("Can't update subspace record"); exit (1); } |
| 173 | } | 172 | } |
| 174 | } | 173 | } |
| 175 | 174 | ||
| @@ -180,69 +179,69 @@ update_file_ptrs(file, hdr, auxhdr, location, offset) | |||
| 180 | 179 | ||
| 181 | /* Read in the header records from an a.out file. */ | 180 | /* Read in the header records from an a.out file. */ |
| 182 | 181 | ||
| 183 | read_header(file, hdr, auxhdr) | 182 | read_header (file, hdr, auxhdr) |
| 184 | int file; | 183 | int file; |
| 185 | struct header *hdr; | 184 | struct header *hdr; |
| 186 | struct som_exec_auxhdr *auxhdr; | 185 | struct som_exec_auxhdr *auxhdr; |
| 187 | { | 186 | { |
| 188 | 187 | ||
| 189 | /* Read the header in */ | 188 | /* Read the header in */ |
| 190 | lseek(file, 0, 0); | 189 | lseek (file, 0, 0); |
| 191 | if (read(file, hdr, sizeof(*hdr)) != sizeof(*hdr)) | 190 | if (read (file, hdr, sizeof (*hdr)) != sizeof (*hdr)) |
| 192 | { perror("Couldn't read header from a.out file"); exit(1); } | 191 | { perror ("Couldn't read header from a.out file"); exit (1); } |
| 193 | 192 | ||
| 194 | if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC | 193 | if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC |
| 195 | && hdr->a_magic != DEMAND_MAGIC) | 194 | && hdr->a_magic != DEMAND_MAGIC) |
| 196 | { | 195 | { |
| 197 | fprintf(stderr, "a.out file doesn't have legal magic number\n"); | 196 | fprintf (stderr, "a.out file doesn't have legal magic number\n"); |
| 198 | exit(1); | 197 | exit (1); |
| 199 | } | 198 | } |
| 200 | 199 | ||
| 201 | lseek(file, hdr->aux_header_location, 0); | 200 | lseek (file, hdr->aux_header_location, 0); |
| 202 | if (read(file, auxhdr, sizeof(*auxhdr)) != sizeof(*auxhdr)) | 201 | if (read (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr)) |
| 203 | { | 202 | { |
| 204 | perror("Couldn't read auxiliary header from a.out file"); | 203 | perror ("Couldn't read auxiliary header from a.out file"); |
| 205 | exit(1); | 204 | exit (1); |
| 206 | } | 205 | } |
| 207 | } | 206 | } |
| 208 | 207 | ||
| 209 | /* Write out the header records into an a.out file. */ | 208 | /* Write out the header records into an a.out file. */ |
| 210 | 209 | ||
| 211 | write_header(file, hdr, auxhdr) | 210 | write_header (file, hdr, auxhdr) |
| 212 | int file; | 211 | int file; |
| 213 | struct header *hdr; | 212 | struct header *hdr; |
| 214 | struct som_exec_auxhdr *auxhdr; | 213 | struct som_exec_auxhdr *auxhdr; |
| 215 | { | 214 | { |
| 216 | /* Update the checksum */ | 215 | /* Update the checksum */ |
| 217 | hdr->checksum = calculate_checksum(hdr); | 216 | hdr->checksum = calculate_checksum (hdr); |
| 218 | 217 | ||
| 219 | /* Write the header back into the a.out file */ | 218 | /* Write the header back into the a.out file */ |
| 220 | lseek(file, 0, 0); | 219 | lseek (file, 0, 0); |
| 221 | if (write(file, hdr, sizeof(*hdr)) != sizeof(*hdr)) | 220 | if (write (file, hdr, sizeof (*hdr)) != sizeof (*hdr)) |
| 222 | { perror("Couldn't write header to a.out file"); exit(1); } | 221 | { perror ("Couldn't write header to a.out file"); exit (1); } |
| 223 | lseek(file, hdr->aux_header_location, 0); | 222 | lseek (file, hdr->aux_header_location, 0); |
| 224 | if (write(file, auxhdr, sizeof(*auxhdr)) != sizeof(*auxhdr)) | 223 | if (write (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr)) |
| 225 | { perror("Couldn't write auxiliary header to a.out file"); exit(1); } | 224 | { perror ("Couldn't write auxiliary header to a.out file"); exit (1); } |
| 226 | } | 225 | } |
| 227 | 226 | ||
| 228 | /* Calculate the checksum of a SOM header record. */ | 227 | /* Calculate the checksum of a SOM header record. */ |
| 229 | 228 | ||
| 230 | calculate_checksum(hdr) | 229 | calculate_checksum (hdr) |
| 231 | struct header *hdr; | 230 | struct header *hdr; |
| 232 | { | 231 | { |
| 233 | int checksum, i, *ptr; | 232 | int checksum, i, *ptr; |
| 234 | 233 | ||
| 235 | checksum = 0; ptr = (int *) hdr; | 234 | checksum = 0; ptr = (int *) hdr; |
| 236 | 235 | ||
| 237 | for (i=0; i<sizeof(*hdr)/sizeof(int)-1; i++) | 236 | for (i = 0; i < sizeof (*hdr) / sizeof (int) - 1; i++) |
| 238 | checksum ^= ptr[i]; | 237 | checksum ^= ptr[i]; |
| 239 | 238 | ||
| 240 | return(checksum); | 239 | return (checksum); |
| 241 | } | 240 | } |
| 242 | 241 | ||
| 243 | /* Copy size bytes from the old file to the new one. */ | 242 | /* Copy size bytes from the old file to the new one. */ |
| 244 | 243 | ||
| 245 | copy_file(old, new, size) | 244 | copy_file (old, new, size) |
| 246 | int new, old; | 245 | int new, old; |
| 247 | int size; | 246 | int size; |
| 248 | { | 247 | { |
| @@ -251,47 +250,47 @@ copy_file(old, new, size) | |||
| 251 | 250 | ||
| 252 | for (; size > 0; size -= len) | 251 | for (; size > 0; size -= len) |
| 253 | { | 252 | { |
| 254 | len = min(size, sizeof(buffer)); | 253 | len = min (size, sizeof (buffer)); |
| 255 | if (read(old, buffer, len) != len) | 254 | if (read (old, buffer, len) != len) |
| 256 | { perror("Read failure on a.out file"); exit(1); } | 255 | { perror ("Read failure on a.out file"); exit (1); } |
| 257 | if (write(new, buffer, len) != len) | 256 | if (write (new, buffer, len) != len) |
| 258 | { perror("Write failure in a.out file"); exit(1); } | 257 | { perror ("Write failure in a.out file"); exit (1); } |
| 259 | } | 258 | } |
| 260 | } | 259 | } |
| 261 | 260 | ||
| 262 | /* Copy the rest of the file, up to EOF. */ | 261 | /* Copy the rest of the file, up to EOF. */ |
| 263 | 262 | ||
| 264 | copy_rest(old, new) | 263 | copy_rest (old, new) |
| 265 | int new, old; | 264 | int new, old; |
| 266 | { | 265 | { |
| 267 | int buffer[4096]; | 266 | int buffer[4096]; |
| 268 | int len; | 267 | int len; |
| 269 | 268 | ||
| 270 | /* Copy bytes until end of file or error */ | 269 | /* Copy bytes until end of file or error */ |
| 271 | while ( (len = read(old, buffer, sizeof(buffer))) > 0) | 270 | while ((len = read (old, buffer, sizeof (buffer))) > 0) |
| 272 | if (write(new, buffer, len) != len) break; | 271 | if (write (new, buffer, len) != len) break; |
| 273 | 272 | ||
| 274 | if (len != 0) | 273 | if (len != 0) |
| 275 | { perror("Unable to copy the rest of the file"); exit(1); } | 274 | { perror ("Unable to copy the rest of the file"); exit (1); } |
| 276 | } | 275 | } |
| 277 | 276 | ||
| 278 | #ifdef DEBUG | 277 | #ifdef DEBUG |
| 279 | display_header(hdr, auxhdr) | 278 | display_header (hdr, auxhdr) |
| 280 | struct header *hdr; | 279 | struct header *hdr; |
| 281 | struct som_exec_auxhdr *auxhdr; | 280 | struct som_exec_auxhdr *auxhdr; |
| 282 | { | 281 | { |
| 283 | /* Display the header information (debug) */ | 282 | /* Display the header information (debug) */ |
| 284 | printf("\n\nFILE HEADER\n"); | 283 | printf ("\n\nFILE HEADER\n"); |
| 285 | printf("magic number %d \n", hdr->a_magic); | 284 | printf ("magic number %d \n", hdr->a_magic); |
| 286 | printf("text loc %.8x size %d \n", auxhdr->exec_tmem, auxhdr->exec_tsize); | 285 | printf ("text loc %.8x size %d \n", auxhdr->exec_tmem, auxhdr->exec_tsize); |
| 287 | printf("data loc %.8x size %d \n", auxhdr->exec_dmem, auxhdr->exec_dsize); | 286 | printf ("data loc %.8x size %d \n", auxhdr->exec_dmem, auxhdr->exec_dsize); |
| 288 | printf("entry %x \n", auxhdr->exec_entry); | 287 | printf ("entry %x \n", auxhdr->exec_entry); |
| 289 | printf("Bss segment size %u\n", auxhdr->exec_bsize); | 288 | printf ("Bss segment size %u\n", auxhdr->exec_bsize); |
| 290 | printf("\n"); | 289 | printf ("\n"); |
| 291 | printf("data file loc %d size %d\n", | 290 | printf ("data file loc %d size %d\n", |
| 292 | auxhdr->exec_dfile, auxhdr->exec_dsize); | 291 | auxhdr->exec_dfile, auxhdr->exec_dsize); |
| 293 | printf("som_length %d\n", hdr->som_length); | 292 | printf ("som_length %d\n", hdr->som_length); |
| 294 | printf("unloadable sploc %d size %d\n", | 293 | printf ("unloadable sploc %d size %d\n", |
| 295 | hdr->unloadable_sp_location, hdr->unloadable_sp_size); | 294 | hdr->unloadable_sp_location, hdr->unloadable_sp_size); |
| 296 | } | 295 | } |
| 297 | #endif /* DEBUG */ | 296 | #endif /* DEBUG */ |