| 1 | /* crumf2ux - convert PC master file to UNIX/Linux format |
|---|
| 2 | crunchmf/AOT, 10/04/2001 |
|---|
| 3 | */ |
|---|
| 4 | #include <stdio.h> |
|---|
| 5 | #include <string.h> |
|---|
| 6 | #include "cisis.h" |
|---|
| 7 | #include "cirun.h" |
|---|
| 8 | |
|---|
| 9 | #define ULONG unsigned long /* */ |
|---|
| 10 | |
|---|
| 11 | #define pc_SIZEOF_M0STRU_FFI 32 |
|---|
| 12 | /*#define pc_LEADER_FFI 22*/ |
|---|
| 13 | #define pc_MSNVSPLT_FFI 18 /* gdb .mst never split - 'til base */ |
|---|
| 14 | #define pc_SIZEOF_M0STRU 32 |
|---|
| 15 | /*#define pc_LEADER 18*/ |
|---|
| 16 | #define pc_MSNVSPLT 14 /* gdb .mst never split - 'til base */ |
|---|
| 17 | |
|---|
| 18 | #define ux_SIZEOF_M0STRU_FFI 32 |
|---|
| 19 | /*#define ux_LEADER_FFI 24*/ |
|---|
| 20 | #define ux_MSNVSPLT_FFI 20 /* gdb .mst never split - 'til base */ |
|---|
| 21 | #define ux_SIZEOF_M0STRU 32 |
|---|
| 22 | /*#define ux_LEADER 20*/ |
|---|
| 23 | #define ux_MSNVSPLT 16 /* gdb .mst never split - 'til base */ |
|---|
| 24 | |
|---|
| 25 | #define NOSW_20 0 |
|---|
| 26 | #define NOSW_21 1 |
|---|
| 27 | #define NOSW_40 0 |
|---|
| 28 | #define NOSW_41 1 |
|---|
| 29 | #define NOSW_42 2 |
|---|
| 30 | #define NOSW_43 3 |
|---|
| 31 | |
|---|
| 32 | #define SWAP_20 1 |
|---|
| 33 | #define SWAP_21 0 |
|---|
| 34 | #define SWAP_40 3 |
|---|
| 35 | #define SWAP_41 2 |
|---|
| 36 | #define SWAP_42 1 |
|---|
| 37 | #define SWAP_43 0 |
|---|
| 38 | |
|---|
| 39 | int target_SIZEOF_M0STRU; |
|---|
| 40 | /*int target_LEADER;*/ |
|---|
| 41 | int target_MSNVSPLT; |
|---|
| 42 | |
|---|
| 43 | char *movtmp; |
|---|
| 44 | int alignment; |
|---|
| 45 | int mv20,mv21,mv40,mv41,mv42,mv43; |
|---|
| 46 | int xalign; |
|---|
| 47 | long mov4val; |
|---|
| 48 | #if CIFFI |
|---|
| 49 | UWORD UWORDarea; |
|---|
| 50 | #else |
|---|
| 51 | ULONG ULONGarea; |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | #define mov2(moved,movp,source) \ |
|---|
| 55 | movtmp = (char *)&(source); \ |
|---|
| 56 | if (alignment >= 2) if ((xalign=moved%2) != 0) while (xalign--) { *movp++ = '\0'; moved++; } \ |
|---|
| 57 | *movp++ = movtmp[mv20]; \ |
|---|
| 58 | *movp++ = movtmp[mv21]; \ |
|---|
| 59 | moved+=2; |
|---|
| 60 | |
|---|
| 61 | #define mov4(moved,movp,source) \ |
|---|
| 62 | if (alignment >= 4) if ((xalign=moved%4) != 0) while (xalign--) { *movp++ = '\0'; moved++; } \ |
|---|
| 63 | movtmp = (char *)&(source); \ |
|---|
| 64 | *movp++ = movtmp[mv40]; \ |
|---|
| 65 | *movp++ = movtmp[mv41]; \ |
|---|
| 66 | *movp++ = movtmp[mv42]; \ |
|---|
| 67 | *movp++ = movtmp[mv43]; \ |
|---|
| 68 | moved+=4; |
|---|
| 69 | |
|---|
| 70 | #define movx(moved,movp,sourcep,len) \ |
|---|
| 71 | memcpy(movp,sourcep,(size_t)len); \ |
|---|
| 72 | movp+=len; \ |
|---|
| 73 | moved+=len; |
|---|
| 74 | |
|---|
| 75 | #if CIFFI |
|---|
| 76 | #define movF(moved,movp,source) \ |
|---|
| 77 | if (xtargfmt == FORMAT_FFI) { mov4(moved,movp,source); } \ |
|---|
| 78 | else { UWORDarea=(UWORD)source; mov2(moved,movp,UWORDarea); } |
|---|
| 79 | #else |
|---|
| 80 | #define movF(moved,movp,source) \ |
|---|
| 81 | if (xtargfmt == FORMAT_isis) { mov2(moved,movp,source); } \ |
|---|
| 82 | else { ULONGarea=(ULONG)source; mov4(moved,movp,ULONGarea); } |
|---|
| 83 | /* 0 1 2 3 4 5 6 7 8 */ |
|---|
| 84 | #endif |
|---|
| 85 | /* |
|---|
| 86 | #define mov2(moved,movp,source) \ |
|---|
| 87 | movtmp = (char *)&(source); \ |
|---|
| 88 | swab(movtmp,movp,2); movp+=2; \ |
|---|
| 89 | moved+=2; |
|---|
| 90 | */ |
|---|
| 91 | |
|---|
| 92 | #if ANSI |
|---|
| 93 | void putuxmst(long mfn, FFI reclen); |
|---|
| 94 | void putuxxrf(long mfn, long comb, int comp); |
|---|
| 95 | void enduxmst(FFI reclen); |
|---|
| 96 | #else |
|---|
| 97 | void putuxmst(); |
|---|
| 98 | void putuxxrf(); |
|---|
| 99 | void enduxmst(); |
|---|
| 100 | #endif |
|---|
| 101 | |
|---|
| 102 | int xrf_fd; |
|---|
| 103 | char *xrf_buffer; |
|---|
| 104 | long xrf_lastmfn; |
|---|
| 105 | int mst_fd; |
|---|
| 106 | char *mst_buffer,*mst_record; |
|---|
| 107 | FFI mst_left; |
|---|
| 108 | #if DBXMSTXL |
|---|
| 109 | int mst_mstxl; |
|---|
| 110 | #endif |
|---|
| 111 | long mst_nxtmfb; |
|---|
| 112 | UWORD mst_nxtmfp; |
|---|
| 113 | UWORD mst_type; |
|---|
| 114 | |
|---|
| 115 | void main(argc,argv) |
|---|
| 116 | int argc; |
|---|
| 117 | char *argv[]; |
|---|
| 118 | { |
|---|
| 119 | RECSTRU *recp; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */ |
|---|
| 120 | char *dbnp,*uxdbnp; |
|---|
| 121 | long irec,mfn; |
|---|
| 122 | FFI mfrl,base,datalen; |
|---|
| 123 | DIRSTRU *dirp; |
|---|
| 124 | int xdir; |
|---|
| 125 | char *p,line[BUFSIZ]; |
|---|
| 126 | long count1,count2; |
|---|
| 127 | int argnext=1; |
|---|
| 128 | int parmtrace=0; |
|---|
| 129 | long parmfrom,parmto,parmtell,parmloop,parmcount; |
|---|
| 130 | /* int zero=0; */ |
|---|
| 131 | char *movp,*mfrlmovp,*basemovp; |
|---|
| 132 | FFI moved,mfrlmoved,basemoved; |
|---|
| 133 | FFI mfrl_max = 0L; |
|---|
| 134 | ULONG ulongzero=0L; |
|---|
| 135 | #if DBXMSTXL |
|---|
| 136 | UWORD mftype; |
|---|
| 137 | int parmmstxl=(-1); |
|---|
| 138 | int pow, vtot; |
|---|
| 139 | #endif |
|---|
| 140 | |
|---|
| 141 | /* |
|---|
| 142 | #if PC || VAX || UNISYSCPU || INTELCPU |
|---|
| 143 | #define SWAPPED 1 |
|---|
| 144 | #endif |
|---|
| 145 | */ |
|---|
| 146 | #define TARGET_pc 0 |
|---|
| 147 | #define TARGET_linux 1 |
|---|
| 148 | #define TARGET_hpux 2 |
|---|
| 149 | #define TARGET_sun 3 |
|---|
| 150 | #define TARGET_alpha 4 |
|---|
| 151 | #define TARGET_vax 5 |
|---|
| 152 | #define TARGET_unisys 6 |
|---|
| 153 | #define TARGET_mpe 7 |
|---|
| 154 | #define TARGET_cdc 8 |
|---|
| 155 | /* 0 1 2 3 4 5 6 7 8 */ |
|---|
| 156 | char *target_id[] = {"pc","linux","hpux","sun","alpha","vax","unisys","mpe","cdc",NULL}; |
|---|
| 157 | int target_align[] = { 1, 4, 4, 4, 4, 1, 4, 4, 4, 0 }; |
|---|
| 158 | int target_swapped[]= { 1, 1, 0, 0, 1, 1, 1, 0, 0, 0 }; |
|---|
| 159 | int i; |
|---|
| 160 | |
|---|
| 161 | #define FORMAT_isis 0 |
|---|
| 162 | #define FORMAT_FFI 1 |
|---|
| 163 | /* 0 1 2 3 4 5 6 7 8 */ |
|---|
| 164 | |
|---|
| 165 | char *format_id[] = {"isis","cisisX",NULL}; |
|---|
| 166 | |
|---|
| 167 | #if CIFFI |
|---|
| 168 | int xtargfmt=FORMAT_FFI; |
|---|
| 169 | #else |
|---|
| 170 | int xtargfmt=FORMAT_isis; |
|---|
| 171 | #endif |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | #if PC |
|---|
| 175 | int xtarget=TARGET_linux; |
|---|
| 176 | #else |
|---|
| 177 | int xtarget=TARGET_pc; |
|---|
| 178 | #endif |
|---|
| 179 | |
|---|
| 180 | int xorigin=TARGET_alpha; |
|---|
| 181 | #if PC |
|---|
| 182 | xorigin=TARGET_pc; |
|---|
| 183 | #endif |
|---|
| 184 | #if UNIX |
|---|
| 185 | #if INTELCPU |
|---|
| 186 | xorigin=TARGET_linux; |
|---|
| 187 | #endif |
|---|
| 188 | #endif |
|---|
| 189 | #if BRME || BRMXCPU |
|---|
| 190 | xorigin=TARGET_hpux; |
|---|
| 191 | #endif |
|---|
| 192 | #if SUN |
|---|
| 193 | xorigin=TARGET_sun; |
|---|
| 194 | #endif |
|---|
| 195 | #if VAX |
|---|
| 196 | xorigin=TARGET_vax; |
|---|
| 197 | #endif |
|---|
| 198 | #if UNISYSCPU |
|---|
| 199 | xorigin=TARGET_unisys; |
|---|
| 200 | #endif |
|---|
| 201 | #if MPE |
|---|
| 202 | xorigin=TARGET_mpe; |
|---|
| 203 | #endif |
|---|
| 204 | #if CDCS4320 |
|---|
| 205 | xorigin=TARGET_cds; |
|---|
| 206 | #endif |
|---|
| 207 | |
|---|
| 208 | if (argc == 2 && strcmp(argv[1],"what") == 0) { |
|---|
| 209 | printf("%s",cicopyr("?Utility CRUNCHMF")); |
|---|
| 210 | printf("\n"); |
|---|
| 211 | exit(0); |
|---|
| 212 | } |
|---|
| 213 | if (argc < 3) { |
|---|
| 214 | printf("%s",cicopyr("Utility CRUNCHMF")); |
|---|
| 215 | printf("\n"); |
|---|
| 216 | printf("crunchmf <dbn> <target_dbn> [<option> [...]] \n"); |
|---|
| 217 | printf(" \n"); |
|---|
| 218 | printf("options: \n"); |
|---|
| 219 | printf("\n"); |
|---|
| 220 | printf(" {from|to|loop|count|tell}=<n> \n"); |
|---|
| 221 | printf("\n"); |
|---|
| 222 | printf(" mfrl=<n> \n"); |
|---|
| 223 | printf("\n"); |
|---|
| 224 | printf(" target={"); |
|---|
| 225 | for (i=0; target_id[i]; i++) printf("%s|",target_id[i]); |
|---|
| 226 | printf("same} default: %s\n",target_id[xtarget]); |
|---|
| 227 | printf(" \n"); |
|---|
| 228 | printf(" format={%s",format_id[xtargfmt]); |
|---|
| 229 | for (i=0; format_id[i]; i++) |
|---|
| 230 | if (i != xtargfmt) printf("|%s",format_id[i]); |
|---|
| 231 | printf("} default: %s\n",format_id[xtargfmt]); |
|---|
| 232 | #if DBXMSTXL |
|---|
| 233 | printf(" \n"); |
|---|
| 234 | printf(" mstxl={0|1|2|4|(2-512)G"); |
|---|
| 235 | printf("} default: as <dbn>\n"); |
|---|
| 236 | #endif |
|---|
| 237 | printf(" \n"); |
|---|
| 238 | exit(1); |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | /* get positional parms */ |
|---|
| 242 | dbnp=argv[argnext++]; |
|---|
| 243 | uxdbnp=argv[argnext++]; |
|---|
| 244 | |
|---|
| 245 | /* get optional parms */ |
|---|
| 246 | parmfrom=1L; parmto=LONG_MAX; parmtell=0L; parmloop=1L; |
|---|
| 247 | |
|---|
| 248 | if (strcmp(dbnp,"null")) parmcount=LONG_MAX; else parmcount=0L; |
|---|
| 249 | |
|---|
| 250 | for (; argnext < argc; ) { |
|---|
| 251 | p=argv[argnext++]; |
|---|
| 252 | if (strncmp(p,"from?",5) == 0 || strncmp(p,"from=",5) == 0) { |
|---|
| 253 | if (sscanf(p+5,"%"_LD_,&parmfrom) != 1) fatal(p); |
|---|
| 254 | continue; |
|---|
| 255 | } |
|---|
| 256 | if (strncmp(p,"to?",3) == 0 || strncmp(p,"to=",3) == 0) { |
|---|
| 257 | if (sscanf(p+3,"%"_LD_,&parmto) != 1) fatal(p); |
|---|
| 258 | continue; |
|---|
| 259 | } |
|---|
| 260 | if (strncmp(p,"count?",6) == 0 || strncmp(p,"count=",6) == 0) { |
|---|
| 261 | if (sscanf(p+6,"%"_LD_,&parmcount) != 1) |
|---|
| 262 | fatal(p); |
|---|
| 263 | continue; |
|---|
| 264 | } |
|---|
| 265 | if (strncmp(p,"loop?",5) == 0 || strncmp(p,"loop=",5) == 0) { |
|---|
| 266 | if (sscanf(p+5,"%"_LD_,&parmloop) != 1) |
|---|
| 267 | fatal(p); |
|---|
| 268 | continue; |
|---|
| 269 | } |
|---|
| 270 | if (strncmp(p,"tell?",5) == 0 || strncmp(p,"tell=",5) == 0) { |
|---|
| 271 | if (sscanf(p+5,"%"_LD_,&parmtell) != 1) fatal(p); |
|---|
| 272 | continue; |
|---|
| 273 | } |
|---|
| 274 | if (strcmp(p,"trace?all") == 0|| strcmp(p,"trace=all") == 0) { |
|---|
| 275 | parmtrace=dbxtrace=rectrace=1; |
|---|
| 276 | continue; |
|---|
| 277 | } |
|---|
| 278 | if (strcmp(p,"trace") == 0) { |
|---|
| 279 | parmtrace=1; |
|---|
| 280 | continue; |
|---|
| 281 | } |
|---|
| 282 | if (strcmp(p,"target?same") == 0 || strcmp(p,"target=same") == 0) { |
|---|
| 283 | xtarget=xorigin; |
|---|
| 284 | continue; |
|---|
| 285 | } |
|---|
| 286 | if (strncmp(p,"target?",7) == 0 || strncmp(p,"target=",7) == 0) { |
|---|
| 287 | int found=0; |
|---|
| 288 | for (xtarget=0; target_id[xtarget]; xtarget++) { |
|---|
| 289 | if (strcmp(p+7,target_id[xtarget])) continue; |
|---|
| 290 | found=1; break; |
|---|
| 291 | } |
|---|
| 292 | if (!found) fatal(p); |
|---|
| 293 | continue; |
|---|
| 294 | } |
|---|
| 295 | if (strncmp(p,"format?",7) == 0 || strncmp(p,"format=",7) == 0) { |
|---|
| 296 | int found=0; |
|---|
| 297 | for (xtargfmt=0; format_id[xtargfmt]; xtargfmt++) { |
|---|
| 298 | if (strcmp(p+7,format_id[xtargfmt])) continue; |
|---|
| 299 | found=1; break; |
|---|
| 300 | } |
|---|
| 301 | if (!found) fatal(p); |
|---|
| 302 | continue; |
|---|
| 303 | } |
|---|
| 304 | #if DBXMSTXL |
|---|
| 305 | if (strncmp(p,"mstxl?",6) == 0 || strncmp(p,"mstxl=",6) == 0) { |
|---|
| 306 | if (p[strlen(p)-1] == 'G') { |
|---|
| 307 | int num=atoi(p+6); |
|---|
| 308 | int cap = 1; |
|---|
| 309 | parmmstxl = 1; |
|---|
| 310 | while (num != cap) { |
|---|
| 311 | if (num < cap) { |
|---|
| 312 | fatal("mstxl/G"); |
|---|
| 313 | } |
|---|
| 314 | parmmstxl++; |
|---|
| 315 | cap *= 2; |
|---|
| 316 | } |
|---|
| 317 | } else { |
|---|
| 318 | if (sscanf(p+6,"%d",&parmmstxl) != 1) |
|---|
| 319 | fatal(p); |
|---|
| 320 | if (parmmstxl < 0 || parmmstxl > 4) fatal(p); |
|---|
| 321 | if (parmmstxl == 4) parmmstxl=3; |
|---|
| 322 | } |
|---|
| 323 | continue; |
|---|
| 324 | } |
|---|
| 325 | #endif |
|---|
| 326 | if (strncmp(p,"mfrl?",5) == 0 || strncmp(p,"mfrl=",5) == 0) { |
|---|
| 327 | if (sscanf(p+5,"%d",&mfrl_max) != 1) |
|---|
| 328 | fatal(p); |
|---|
| 329 | if (mfrl_max > MAXMFRL) rec_maxmfrl = mfrl_max; |
|---|
| 330 | continue; |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | fatal(p); |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | /* setup processing */ |
|---|
| 337 | alignment=target_align[xtarget]; |
|---|
| 338 | |
|---|
| 339 | if (xtarget == TARGET_pc) { |
|---|
| 340 | target_SIZEOF_M0STRU=(xtargfmt==FORMAT_FFI)?pc_SIZEOF_M0STRU_FFI:pc_SIZEOF_M0STRU; |
|---|
| 341 | target_MSNVSPLT=(xtargfmt==FORMAT_FFI)?pc_MSNVSPLT_FFI:pc_MSNVSPLT; |
|---|
| 342 | } else { |
|---|
| 343 | target_SIZEOF_M0STRU=(xtargfmt==FORMAT_FFI)?ux_SIZEOF_M0STRU_FFI:ux_SIZEOF_M0STRU; |
|---|
| 344 | target_MSNVSPLT=(xtargfmt==FORMAT_FFI)?ux_MSNVSPLT_FFI:ux_MSNVSPLT; |
|---|
| 345 | } |
|---|
| 346 | |
|---|
| 347 | mv20=NOSW_20; |
|---|
| 348 | mv21=NOSW_21; |
|---|
| 349 | mv40=NOSW_40; |
|---|
| 350 | mv41=NOSW_41; |
|---|
| 351 | mv42=NOSW_42; |
|---|
| 352 | mv43=NOSW_43; |
|---|
| 353 | if (target_swapped[xtarget] != target_swapped[xorigin]) { |
|---|
| 354 | mv20=SWAP_20; |
|---|
| 355 | mv21=SWAP_21; |
|---|
| 356 | mv40=SWAP_40; |
|---|
| 357 | mv41=SWAP_41; |
|---|
| 358 | mv42=SWAP_42; |
|---|
| 359 | mv43=SWAP_43; |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | /* get control record */ |
|---|
| 363 | RECORD(irec=nrecs,dbnp,0L); |
|---|
| 364 | if (parmtrace) prtcontrol(recp,dbnp); |
|---|
| 365 | |
|---|
| 366 | /* create .xrf and allocate putuxxrf() output buffer */ |
|---|
| 367 | strcpy(line,uxdbnp); |
|---|
| 368 | strcat(line,xx1extp); |
|---|
| 369 | p=dbxopenc(uxdbnp,line,&xrf_fd,NULL,NULL,1,0); /*..force create= */ |
|---|
| 370 | if (xrf_fd <= 0) fatal(line); |
|---|
| 371 | if (parmtrace) printf("+++ %s=%d\n",p,xrf_fd); |
|---|
| 372 | xrf_buffer=(char *)ALLOC((ALLOPARM)XRBSIZ); |
|---|
| 373 | if (xrf_buffer == (char *)ALLONULL) fatal("ALLOC/xrf_buffer"); |
|---|
| 374 | |
|---|
| 375 | /* create .mst and allocate putuxmst() output buffer */ |
|---|
| 376 | strcpy(line,uxdbnp); |
|---|
| 377 | strcat(line,mx1extp); |
|---|
| 378 | p=dbxopenc(uxdbnp,line,&mst_fd,NULL,NULL,1,0); /*..force create= */ |
|---|
| 379 | if (mst_fd <= 0) fatal(line); |
|---|
| 380 | if (parmtrace) printf("+++ %s=%d\n",p,mst_fd); |
|---|
| 381 | mst_buffer=(char *)ALLOC((ALLOPARM)MSBSIZ); |
|---|
| 382 | if (mst_buffer == (char *)ALLONULL) fatal("ALLOC/mst_buffer"); |
|---|
| 383 | |
|---|
| 384 | /* initialize putuxxrf() */ |
|---|
| 385 | xrf_lastmfn=MF0nxtmfn-1; |
|---|
| 386 | if (parmto < xrf_lastmfn) xrf_lastmfn=parmto; |
|---|
| 387 | |
|---|
| 388 | /* initialize putuxmst() */ |
|---|
| 389 | mst_left=MSBSIZ; |
|---|
| 390 | mst_nxtmfb=1L; |
|---|
| 391 | mst_nxtmfp=1; |
|---|
| 392 | mst_type=MF0mftype; |
|---|
| 393 | #if DBXMSTXL |
|---|
| 394 | mst_mstxl=RDBmstxl; |
|---|
| 395 | if (parmmstxl >=0) { |
|---|
| 396 | /* |
|---|
| 397 | HB 20080911 - movido para nao alterar parametro G4 |
|---|
| 398 | if (parmmstxl == 4) parmmstxl=3; |
|---|
| 399 | */ |
|---|
| 400 | mst_mstxl=parmmstxl; |
|---|
| 401 | } |
|---|
| 402 | vtot = 1; |
|---|
| 403 | for (pow = 1; pow <= mst_mstxl; pow++) { |
|---|
| 404 | vtot *= 2; |
|---|
| 405 | //printf("vtot=%d\n", vtot); |
|---|
| 406 | } |
|---|
| 407 | vtot -= 1; |
|---|
| 408 | #endif |
|---|
| 409 | |
|---|
| 410 | /* allocate processing buffer */ |
|---|
| 411 | mst_record=(char *)ALLOC((ALLOPARM)rec_maxmfrl); |
|---|
| 412 | |
|---|
| 413 | if (mst_record == (char *)ALLONULL) fatal("ALLOC/mst_record"); |
|---|
| 414 | |
|---|
| 415 | /* initialize control record */ |
|---|
| 416 | movp=mst_record; |
|---|
| 417 | moved=target_SIZEOF_M0STRU+target_SIZEOF_M0STRU; /* gdb */ |
|---|
| 418 | #if DBXMSTXL |
|---|
| 419 | while (moved & vtot) { |
|---|
| 420 | moved++; |
|---|
| 421 | } |
|---|
| 422 | #endif |
|---|
| 423 | memset(movp,0x00,moved); |
|---|
| 424 | putuxmst(0L,moved); |
|---|
| 425 | for (mfn=1L; mfn < parmfrom; mfn++) { |
|---|
| 426 | putuxxrf(mfn,(-1L),0); /* PDEL pointer */ |
|---|
| 427 | } |
|---|
| 428 | |
|---|
| 429 | /* convert mf records */ |
|---|
| 430 | for (count1=count2=0L, mfn=parmfrom; mfn <= parmto; mfn+=parmloop) { |
|---|
| 431 | RECORD(irec,dbnp,mfn); |
|---|
| 432 | if (RECrc == RCEOF) break; |
|---|
| 433 | if (count1 >= parmcount) break; |
|---|
| 434 | count1++; |
|---|
| 435 | if (RECrc != RCNORMAL) { |
|---|
| 436 | putuxxrf(mfn,(-1L),0); /* PDEL pointer */ |
|---|
| 437 | continue; |
|---|
| 438 | } |
|---|
| 439 | count2++; |
|---|
| 440 | /* base=target_LEADER+MFRnvf*sizeof(DIRSTRU);*/ |
|---|
| 441 | datalen=0; |
|---|
| 442 | for (dirp=MFRdir, xdir=MFRnvf; xdir--; dirp++) datalen+=dirp->len; |
|---|
| 443 | /* mfrl=base+datalen; */ |
|---|
| 444 | MFRmfbwb=0L; |
|---|
| 445 | MFRmfbwp=0; |
|---|
| 446 | movp=mst_record; moved=0; |
|---|
| 447 | |
|---|
| 448 | /* move leader segment */ |
|---|
| 449 | mov4(moved,movp,MFRmfn); |
|---|
| 450 | mfrlmovp=movp; /* will move mfrl later */ |
|---|
| 451 | mfrlmoved=moved; |
|---|
| 452 | movF(moved,movp,ulongzero); |
|---|
| 453 | mov4(moved,movp,MFRmfbwb); /* align - in putuxmst.. */ |
|---|
| 454 | mov2(moved,movp,MFRmfbwp); |
|---|
| 455 | basemovp=movp; /* will move base later */ |
|---|
| 456 | basemoved=moved; |
|---|
| 457 | movF(moved,movp,ulongzero); |
|---|
| 458 | mov2(moved,movp,MFRnvf); |
|---|
| 459 | mov2(moved,movp,MFRstatus); |
|---|
| 460 | |
|---|
| 461 | /* move dir segment */ |
|---|
| 462 | for (dirp=MFRdir, xdir=0; xdir < MFRnvf; xdir++, dirp++) { |
|---|
| 463 | mov2(moved,movp,dirp->tag); |
|---|
| 464 | movF(moved,movp,dirp->pos); |
|---|
| 465 | movF(moved,movp,dirp->len); |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | /* store actual base */ |
|---|
| 469 | base=moved; |
|---|
| 470 | movF(basemoved,basemovp,base); |
|---|
| 471 | |
|---|
| 472 | /* move data segment */ |
|---|
| 473 | movx(moved,movp,MFX+MFRbase,datalen); |
|---|
| 474 | |
|---|
| 475 | /* make mfrl fits address scheme */ |
|---|
| 476 | if (moved & 0x01) { |
|---|
| 477 | *movp++=' '; moved++; /* gdb always an even number */ |
|---|
| 478 | } |
|---|
| 479 | #if DBXMSTXL |
|---|
| 480 | while (moved & vtot) { |
|---|
| 481 | *movp++=' '; moved++; |
|---|
| 482 | } |
|---|
| 483 | //printf("moved=%d vtot=%d (moved & vtot)=%d\n", moved, vtot, (int)(moved & vtot)); |
|---|
| 484 | |
|---|
| 485 | /* |
|---|
| 486 | if (mst_mstxl == 2) |
|---|
| 487 | while (moved & 0x03) { |
|---|
| 488 | *movp=' '; moved++; |
|---|
| 489 | } |
|---|
| 490 | if (mst_mstxl == 3) |
|---|
| 491 | while (moved & 0x07) { |
|---|
| 492 | *movp=' '; moved++; |
|---|
| 493 | } |
|---|
| 494 | */ |
|---|
| 495 | #endif |
|---|
| 496 | |
|---|
| 497 | /* store actual mfrl */ |
|---|
| 498 | mfrl=moved; |
|---|
| 499 | movF(mfrlmoved,mfrlmovp,mfrl); |
|---|
| 500 | |
|---|
| 501 | putuxmst(mfn,moved); |
|---|
| 502 | |
|---|
| 503 | if (parmtell) |
|---|
| 504 | if (count1 % parmtell == 0) |
|---|
| 505 | fprintf(stderr,"+++ %"_LD_"/%"_LD_" \n",count1,count2); |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | if (mst_left < MSBSIZ) { |
|---|
| 509 | memset(&mst_buffer[MSBSIZ-mst_left],0x00,mst_left); |
|---|
| 510 | if (CIWRITE(mst_fd,mst_buffer,MSBSIZ) < MSBSIZ) fatal("enduxmst/write"); |
|---|
| 511 | // mst_nxtmfb++; mst_nxtmfp=1; HB ????? |
|---|
| 512 | } |
|---|
| 513 | |
|---|
| 514 | /* update control record */ |
|---|
| 515 | RECORD(irec,dbnp,0L); |
|---|
| 516 | MF0nxtmfn=xrf_lastmfn+1; |
|---|
| 517 | MF0nxtmfb=mst_nxtmfb; |
|---|
| 518 | MF0nxtmfp=mst_nxtmfp; |
|---|
| 519 | MF0reccnt=MF0mfcxx1=MF0mfcxx2=MF0mfcxx3=0; |
|---|
| 520 | movp=mst_record; moved=0; |
|---|
| 521 | mov4(moved,movp,MF0ctlmfn); |
|---|
| 522 | mov4(moved,movp,MF0nxtmfn); |
|---|
| 523 | mov4(moved,movp,MF0nxtmfb); |
|---|
| 524 | mov2(moved,movp,MF0nxtmfp); /* bug */ |
|---|
| 525 | #if DBXMSTXL |
|---|
| 526 | mftype = MF0mftype + mst_mstxl * 256; /* AOT/AARG 05/01/99 */ |
|---|
| 527 | mov2(moved,movp,mftype); |
|---|
| 528 | #else |
|---|
| 529 | mov2(moved,movp,MF0mftype); |
|---|
| 530 | #endif |
|---|
| 531 | mov4(moved,movp,MF0reccnt); |
|---|
| 532 | mov4(moved,movp,MF0mfcxx1); |
|---|
| 533 | mov4(moved,movp,MF0mfcxx2); |
|---|
| 534 | mov4(moved,movp,MF0mfcxx3); |
|---|
| 535 | enduxmst(moved); |
|---|
| 536 | if (parmtell) { |
|---|
| 537 | if (count1 % parmtell == 0) ; else |
|---|
| 538 | fprintf(stderr,"+++ %"_LD_"/%"_LD_" \n",count1,count2); |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | exit(0); |
|---|
| 542 | } |
|---|
| 543 | |
|---|
| 544 | void putuxmst(mfn,reclen) |
|---|
| 545 | long mfn; |
|---|
| 546 | FFI reclen; |
|---|
| 547 | { |
|---|
| 548 | char *p; |
|---|
| 549 | int n; |
|---|
| 550 | #if MSTTRACE |
|---|
| 551 | FFI loop; |
|---|
| 552 | for (p=mst_record, loop=0; loop<reclen; p++) { |
|---|
| 553 | printf("%02x ",*p); |
|---|
| 554 | if (++loop%16 == 0) printf("\n"); |
|---|
| 555 | } |
|---|
| 556 | printf("\n"); |
|---|
| 557 | #endif |
|---|
| 558 | if (mst_type == MSMFTMSG) { |
|---|
| 559 | n = reclen % MSBSIZ; |
|---|
| 560 | if (n) { |
|---|
| 561 | n=MSBSIZ-n; |
|---|
| 562 | memset(mst_record+reclen,0x00,n); reclen+=n; |
|---|
| 563 | } |
|---|
| 564 | } |
|---|
| 565 | if (mst_left < target_MSNVSPLT) { |
|---|
| 566 | memset(&mst_buffer[MSBSIZ-mst_left],0x00,mst_left); |
|---|
| 567 | if (CIWRITE(mst_fd,mst_buffer,MSBSIZ) < MSBSIZ) fatal("putuxmst/write"); |
|---|
| 568 | mst_nxtmfb++; mst_nxtmfp=1; |
|---|
| 569 | mst_left=MSBSIZ; |
|---|
| 570 | } |
|---|
| 571 | |
|---|
| 572 | putuxxrf(mfn,mst_nxtmfb,mst_nxtmfp-1); |
|---|
| 573 | |
|---|
| 574 | for (p=mst_record; reclen; ) { |
|---|
| 575 | if (reclen <= mst_left) { |
|---|
| 576 | memcpy(&mst_buffer[MSBSIZ-mst_left],p,(size_t)reclen); |
|---|
| 577 | mst_left-=reclen; |
|---|
| 578 | mst_nxtmfp+=reclen; |
|---|
| 579 | break; |
|---|
| 580 | } |
|---|
| 581 | memcpy(&mst_buffer[MSBSIZ-mst_left],p,mst_left); |
|---|
| 582 | if (CIWRITE(mst_fd,mst_buffer,MSBSIZ) < MSBSIZ) fatal("putuxmst/write"); |
|---|
| 583 | reclen-=mst_left; |
|---|
| 584 | p+=mst_left; |
|---|
| 585 | mst_left=MSBSIZ; |
|---|
| 586 | mst_nxtmfb++; mst_nxtmfp=1; |
|---|
| 587 | } |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | void enduxmst(reclen) |
|---|
| 591 | FFI reclen; |
|---|
| 592 | { |
|---|
| 593 | #if MSTTRACE |
|---|
| 594 | char *p; |
|---|
| 595 | FFI loop; |
|---|
| 596 | for (p=mst_record, loop=0; loop<reclen; p++) { |
|---|
| 597 | printf("%02x ",*p); |
|---|
| 598 | if (++loop%16 == 0) printf("\n"); |
|---|
| 599 | } |
|---|
| 600 | printf("\n"); |
|---|
| 601 | #endif |
|---|
| 602 | /* if (mst_left < MSBSIZ) { |
|---|
| 603 | memset(&mst_buffer[MSBSIZ-mst_left],0x00,mst_left); |
|---|
| 604 | if (CIWRITE(mst_fd,mst_buffer,MSBSIZ) < MSBSIZ) fatal("enduxmst/write"); |
|---|
| 605 | } */ |
|---|
| 606 | putuxxrf(-1L,0L,0); |
|---|
| 607 | if (reclen) { |
|---|
| 608 | if (lseek(mst_fd,SEEK_SET,0L) != 0L) fatal("enduxmst/seek"); |
|---|
| 609 | if (CIWRITE(mst_fd,mst_record,(unsigned)reclen) < reclen) fatal("enduxmst/write"); |
|---|
| 610 | } |
|---|
| 611 | } |
|---|
| 612 | |
|---|
| 613 | void putuxxrf(mfn,comb,comp) |
|---|
| 614 | long mfn; |
|---|
| 615 | long comb; |
|---|
| 616 | int comp; |
|---|
| 617 | { |
|---|
| 618 | static XRSTRU *xrxp; |
|---|
| 619 | static long xrf_block,xrf_lastblock; |
|---|
| 620 | static int xrf_lastidx; |
|---|
| 621 | static int xrf_towrit=0L; |
|---|
| 622 | XRPTR pointer,xrftiv; |
|---|
| 623 | int thisidx,n; |
|---|
| 624 | XRPOS thispos; |
|---|
| 625 | char x[4]; |
|---|
| 626 | char *movp; |
|---|
| 627 | UWORD moved; |
|---|
| 628 | |
|---|
| 629 | if (mfn < 0L) if (xrf_towrit) { |
|---|
| 630 | for (moved=0, movp=xrf_buffer, n=XRBSIZ; n; n-=4) {memcpy(x,movp,4); mov4(moved,movp,x[0]);} |
|---|
| 631 | if (CIWRITE(xrf_fd,xrf_buffer,XRBSIZ) != XRBSIZ) fatal("putuxxrf/write"); |
|---|
| 632 | if (xrxp->xrxrpos < 0) return; |
|---|
| 633 | |
|---|
| 634 | xrxp->xrxrpos = -xrf_lastblock; |
|---|
| 635 | xrftiv = (0)*XRXDIVIDE + (0); /* EOF pointer */ |
|---|
| 636 | for (n=0; n < XRMAXTIV; ) xrxp->xrmfptr[n++]=xrftiv; |
|---|
| 637 | for (moved=0, movp=xrf_buffer, n=XRBSIZ; n; n-=4) {memcpy(x,movp,4); mov4(moved,movp,x[0]);} |
|---|
| 638 | if (CIWRITE(xrf_fd,xrf_buffer,XRBSIZ) != XRBSIZ) fatal("putuxxrf/write"); |
|---|
| 639 | return; |
|---|
| 640 | } |
|---|
| 641 | if (mfn == 0) { |
|---|
| 642 | if (mfn + XRBSIZ % 4) fatal("putuxxrf/XRBSIZ"); |
|---|
| 643 | xrxp=(XRSTRU *)xrf_buffer; |
|---|
| 644 | xrf_block=0L; |
|---|
| 645 | xrf_lastblock=(xrf_lastmfn+XRMAXTV1)/XRMAXTIV; |
|---|
| 646 | if (xrf_lastmfn%XRMAXTIV == 0) xrf_lastblock++; /* 127 */ |
|---|
| 647 | xrf_lastidx=0; |
|---|
| 648 | |
|---|
| 649 | xrxp->xrxrpos = ++xrf_block; |
|---|
| 650 | if (xrf_block == xrf_lastblock) xrxp->xrxrpos = -xrf_block; |
|---|
| 651 | xrftiv = (0)*XRXDIVIDE + (0); /* EOF pointer */ |
|---|
| 652 | for (n=0; n < XRMAXTIV; ) xrxp->xrmfptr[n++]=xrftiv; |
|---|
| 653 | xrf_towrit=1; |
|---|
| 654 | return; |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | thispos=(mfn+XRMAXTV1)/XRMAXTIV; |
|---|
| 658 | thisidx=(mfn-1)%XRMAXTIV; |
|---|
| 659 | #if DBXMSTXL /* AOT 20/09/2001 */ |
|---|
| 660 | pointer = comb * (XRXDIVIDE>>mst_mstxl) + (comp>>mst_mstxl); |
|---|
| 661 | #else /* DBXMSTXL */ |
|---|
| 662 | pointer = comb * XRXDIVIDE + comp; |
|---|
| 663 | #endif /* DBXMSTXL */ |
|---|
| 664 | |
|---|
| 665 | if (thispos < xrf_block) fatal("putuxxrf/thispos"); |
|---|
| 666 | if (thispos == xrf_block) { |
|---|
| 667 | xrftiv=(-1)*XRXDIVIDE + (0); /* PDEL pointer */ |
|---|
| 668 | for (n=xrf_lastidx+1; n<thisidx; n++) xrxp->xrmfptr[n] = xrftiv; |
|---|
| 669 | xrxp->xrmfptr[xrf_lastidx=thisidx] = pointer; |
|---|
| 670 | xrf_towrit=1; |
|---|
| 671 | return; |
|---|
| 672 | } |
|---|
| 673 | |
|---|
| 674 | /* thispos > xrf_block */ |
|---|
| 675 | for (moved=0, movp=xrf_buffer, n=XRBSIZ; n; n-=4) {memcpy(x,movp,4); mov4(moved,movp,x[0]);} |
|---|
| 676 | if (CIWRITE(xrf_fd,xrf_buffer,XRBSIZ) != XRBSIZ) fatal("putuxxrf/write"); |
|---|
| 677 | xrftiv=(-1)*XRXDIVIDE + (0); /* PDEL pointer */ |
|---|
| 678 | for (n=0; n < XRMAXTIV; ) xrxp->xrmfptr[n++]=xrftiv; |
|---|
| 679 | while (++xrf_block < thispos) { |
|---|
| 680 | xrxp->xrxrpos = xrf_block; |
|---|
| 681 | if (xrf_block == xrf_lastblock) fatal("putuxxrf/lastblock"); |
|---|
| 682 | for (moved=0, movp=xrf_buffer, n=XRBSIZ; n; n-=4) {memcpy(x,movp,4); mov4(moved,movp,x[0]);} |
|---|
| 683 | if (CIWRITE(xrf_fd,xrf_buffer,XRBSIZ) != XRBSIZ) fatal("putuxxrf/write"); |
|---|
| 684 | } |
|---|
| 685 | xrxp->xrxrpos = xrf_block; |
|---|
| 686 | if (xrf_block == xrf_lastblock) xrxp->xrxrpos = -xrf_block; |
|---|
| 687 | xrxp->xrmfptr[xrf_lastidx=thisidx] = pointer; |
|---|
| 688 | xrftiv= (0)*XRXDIVIDE + (0); /* EOF pointer */ |
|---|
| 689 | for (n=thisidx+1; n<XRMAXTIV; n++) xrxp->xrmfptr[n] = xrftiv; |
|---|
| 690 | xrf_towrit=1; |
|---|
| 691 | return; |
|---|
| 692 | } |
|---|