init.c 901 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <libc/unistd.h>
  2. #include <libc/stdio.h>
  3. #include <libc/fcntl.h>
  4. int main()
  5. {
  6. char string[] = "333.txt";
  7. uint8_t buf[128] = {0};
  8. char tips_str[] = "The first application 'init.bin' started successfully!\n";
  9. put_string(tips_str, COLOR_GREEN, COLOR_BLACK);
  10. int fd = open(string, 0);
  11. read(fd, buf, 128);
  12. put_string(buf, COLOR_ORANGE, COLOR_BLACK);
  13. lseek(fd, 0, SEEK_SET);
  14. write(fd, tips_str, sizeof(tips_str)-1);
  15. lseek(fd, 0, SEEK_SET);
  16. // 由于暂时没有实现用户态的memset,因此先手动清零
  17. for(int i=0;i<128;++i)
  18. buf[i] = 0;
  19. read(fd, buf, 128);
  20. put_string(buf, COLOR_YELLOW, COLOR_BLACK);
  21. close(fd);
  22. pid_t p = fork();
  23. if(p == 0)
  24. put_string("subproc\n", COLOR_PURPLE, COLOR_BLACK);
  25. else put_string("parent proc\n", COLOR_ORANGE, COLOR_BLACK);
  26. while (1)
  27. ;
  28. }