/arch/ppc64/boot/piggyback.c

https://bitbucket.org/evzijst/gittest · C · 83 lines · 70 code · 5 blank · 8 comment · 10 complexity · f0091259abaa28a2a82c9dab24996e84 MD5 · raw file

  1. /*
  2. * Copyright 2001 IBM Corp
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <stdio.h>
  10. #include <unistd.h>
  11. #include <string.h>
  12. extern long ce_exec_config[];
  13. int main(int argc, char *argv[])
  14. {
  15. int i, cnt, pos, len;
  16. unsigned int cksum, val;
  17. unsigned char *lp;
  18. unsigned char buf[8192];
  19. char *varname;
  20. if (argc != 2)
  21. {
  22. fprintf(stderr, "usage: %s name <in-file >out-file\n",
  23. argv[0]);
  24. exit(1);
  25. }
  26. varname = strrchr(argv[1], '/');
  27. if (varname)
  28. varname++;
  29. else
  30. varname = argv[1];
  31. fprintf(stdout, "#\n");
  32. fprintf(stdout, "# Miscellaneous data structures:\n");
  33. fprintf(stdout, "# WARNING - this file is automatically generated!\n");
  34. fprintf(stdout, "#\n");
  35. fprintf(stdout, "\n");
  36. fprintf(stdout, "\t.data\n");
  37. fprintf(stdout, "\t.globl %s_data\n", varname);
  38. fprintf(stdout, "%s_data:\n", varname);
  39. pos = 0;
  40. cksum = 0;
  41. while ((len = read(0, buf, sizeof(buf))) > 0)
  42. {
  43. cnt = 0;
  44. lp = (unsigned char *)buf;
  45. len = (len + 3) & ~3; /* Round up to longwords */
  46. for (i = 0; i < len; i += 4)
  47. {
  48. if (cnt == 0)
  49. {
  50. fprintf(stdout, "\t.long\t");
  51. }
  52. fprintf(stdout, "0x%02X%02X%02X%02X", lp[0], lp[1], lp[2], lp[3]);
  53. val = *(unsigned long *)lp;
  54. cksum ^= val;
  55. lp += 4;
  56. if (++cnt == 4)
  57. {
  58. cnt = 0;
  59. fprintf(stdout, " # %x \n", pos+i-12);
  60. fflush(stdout);
  61. } else
  62. {
  63. fprintf(stdout, ",");
  64. }
  65. }
  66. if (cnt)
  67. {
  68. fprintf(stdout, "0\n");
  69. }
  70. pos += len;
  71. }
  72. fprintf(stdout, "\t.globl %s_len\n", varname);
  73. fprintf(stdout, "%s_len:\t.long\t0x%x\n", varname, pos);
  74. fflush(stdout);
  75. fclose(stdout);
  76. fprintf(stderr, "cksum = %x\n", cksum);
  77. exit(0);
  78. }