bootstr_32.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * bootstr.c: Boot string/argument acquisition from the PROM.
  3. *
  4. * Copyright(C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #include <linux/string.h>
  7. #include <asm/oplib.h>
  8. #include <linux/init.h>
  9. #define BARG_LEN 256
  10. static char barg_buf[BARG_LEN] = { 0 };
  11. static char fetched __initdata = 0;
  12. char * __init
  13. prom_getbootargs(void)
  14. {
  15. int iter;
  16. char *cp, *arg;
  17. /* This check saves us from a panic when bootfd patches args. */
  18. if (fetched) {
  19. return barg_buf;
  20. }
  21. switch(prom_vers) {
  22. case PROM_V0:
  23. cp = barg_buf;
  24. /* Start from 1 and go over fd(0,0,0)kernel */
  25. for(iter = 1; iter < 8; iter++) {
  26. arg = (*(romvec->pv_v0bootargs))->argv[iter];
  27. if (arg == NULL)
  28. break;
  29. while(*arg != 0) {
  30. /* Leave place for space and null. */
  31. if(cp >= barg_buf + BARG_LEN-2){
  32. /* We might issue a warning here. */
  33. break;
  34. }
  35. *cp++ = *arg++;
  36. }
  37. *cp++ = ' ';
  38. }
  39. *cp = 0;
  40. break;
  41. case PROM_V2:
  42. case PROM_V3:
  43. /*
  44. * V3 PROM cannot supply as with more than 128 bytes
  45. * of an argument. But a smart bootstrap loader can.
  46. */
  47. strlcpy(barg_buf, *romvec->pv_v2bootargs.bootargs, sizeof(barg_buf));
  48. break;
  49. default:
  50. break;
  51. }
  52. fetched = 1;
  53. return barg_buf;
  54. }