net.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * net.c
  3. *
  4. * This file is part of aboot, the SRM bootloader for Linux/Alpha
  5. * Copyright (C) 1996 Dave Larson, and David Mosberger.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <asm/console.h>
  22. #include "system.h"
  23. #include "config.h"
  24. #include "cons.h"
  25. #include "aboot.h"
  26. #include "bootfs.h"
  27. #include "utils.h"
  28. #include "string.h"
  29. #include "netwrap.h"
  30. extern char boot_file[256];
  31. void
  32. dang (void)
  33. {
  34. printf("aboot: oops, unimplemented net-bfs function called!\n");
  35. }
  36. extern char _end;
  37. static char *src = 0;
  38. static char *kern_src=0, *ird_src=0;
  39. static int header_size=0, kern_size=0, ird_size=0;
  40. int
  41. net_bread (int fd, long blkno, long nblks, char * buf)
  42. {
  43. int nbytes;
  44. #ifdef DEBUG
  45. printf("net_bread: %p -> %p (%ld blocks at %ld)\n", src, buf,
  46. nblks, blkno);
  47. #endif
  48. nbytes = bfs->blocksize * nblks;
  49. memcpy(buf, src, nbytes);
  50. src += nbytes;
  51. return nbytes;
  52. }
  53. struct bootfs netfs = {
  54. -1, 512,
  55. (int (*)(long, long, long)) dang, /* mount */
  56. (int (*)(const char *)) dang, /* open */
  57. net_bread, /* bread */
  58. (void (*)(int fd)) dang, /* close */
  59. (const char* (*)(int, int)) dang, /* readdir */
  60. (int (*)(int, struct stat*)) dang, /* fstat */
  61. };
  62. long
  63. read_initrd()
  64. {
  65. int nblocks, nread;
  66. /* put it as high up in memory as possible */
  67. initrd_start = free_mem_ptr - align_pagesize(ird_size);
  68. initrd_size = ird_size;
  69. /* update free_mem_ptr so malloc() still works */
  70. free_mem_ptr = initrd_start;
  71. #ifdef DEBUG
  72. printf("memory_end %x %x\n", free_mem_ptr, initrd_start);
  73. #endif
  74. nblocks = align_512(ird_size)/ 512;
  75. printf("aboot: loading initrd (%d bytes/%d blocks) at %#lx\n",
  76. ird_size, nblocks, initrd_start);
  77. nread = (*bfs->bread)(-1, 0, nblocks, (char*) initrd_start);
  78. return 0;
  79. }
  80. long
  81. load_kernel (void)
  82. {
  83. struct header *header;
  84. bfs = &netfs;
  85. header = (struct header *)align_512( (unsigned long)&_end );
  86. header_size = header->header_size;
  87. kern_src = (char *)align_512((unsigned long)header + header_size);
  88. kern_size = header->kern_size;
  89. ird_src = (char *)align_512((unsigned long)kern_src + kern_size);
  90. ird_size = header->ird_size;
  91. if (!free_mem_ptr)
  92. free_mem_ptr = memory_end();
  93. free_mem_ptr = free_mem_ptr & ~(PAGE_SIZE-1);
  94. #ifdef DEBUG
  95. printf("head %x %x kernel %x %x, initrd %x %x \n", header, header_size, kern_src, kern_size, ird_src, ird_size);
  96. #endif
  97. if (ird_size) {
  98. src = ird_src;
  99. if (read_initrd() < 0) {
  100. return -1;
  101. }
  102. }
  103. strcpy(boot_file, "network");
  104. //Move kernel to safe place before uncompression
  105. src = (char*)free_mem_ptr - align_pagesize(kern_size);
  106. free_mem_ptr = (unsigned long)src;
  107. memcpy(src, kern_src, kern_size);
  108. uncompress_kernel(-1);
  109. memset((char*)bss_start, 0, bss_size); /* clear bss */
  110. if (!kernel_args[0] && header->boot_arg[0]) { //have argument?
  111. strncpy(kernel_args, header->boot_arg, header_size - sizeof(int)*3);
  112. }
  113. while (kernel_args[0] == 'i' && !kernel_args[1]) {
  114. printf("Enter kernel arguments:\n");
  115. printf("aboot> ");
  116. getline(kernel_args, sizeof(kernel_args));
  117. printf("\n");
  118. }
  119. return 0;
  120. }