shell.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <libc/unistd.h>
  2. #include <libc/stdio.h>
  3. #include <libc/fcntl.h>
  4. #include <libc/stdlib.h>
  5. #include <libKeyboard/keyboard.h>
  6. int main()
  7. {
  8. char string[] = "/333.txt";
  9. uint8_t buf[128] = {0};
  10. char tips_str[] = "The first application 'init.bin' started successfully!\n";
  11. put_string(tips_str, COLOR_GREEN, COLOR_BLACK);
  12. printf("test printf: %s size: %d\n", string, sizeof(string));
  13. char kb_file_path[] = "/dev/keyboard.dev";
  14. int kb_fd = open(kb_file_path, 0);
  15. printf("keyboard fd = %d\n", kb_fd);
  16. while (true)
  17. {
  18. int key = keyboard_analyze_keycode(kb_fd);
  19. if(key)
  20. printf("%c", (char)key);
  21. }
  22. /*
  23. int fd = open(string, 0);
  24. printf("fd=%d\n", fd);
  25. read(fd, buf, 128);
  26. put_string(buf, COLOR_ORANGE, COLOR_BLACK);
  27. lseek(fd, 0, SEEK_SET);
  28. write(fd, tips_str, sizeof(tips_str)-1);
  29. lseek(fd, 0, SEEK_SET);
  30. // 由于暂时没有实现用户态的memset,因此先手动清零
  31. for(int i=0;i<128;++i)
  32. buf[i] = 0;
  33. read(fd, buf, 128);
  34. put_string(buf, COLOR_YELLOW, COLOR_BLACK);
  35. close(fd);
  36. void *ptr[256] = {0};
  37. for (int k = 0; k < 2; ++k)
  38. {
  39. printf("try to malloc 256*1M=256MB\n");
  40. uint64_t js = 0;
  41. for (int i = 0; i < 256; ++i)
  42. {
  43. ptr[i] = malloc(1024 * 1024);
  44. js += *(uint64_t *)((uint64_t)(ptr[i]) - sizeof(uint64_t));
  45. // if (*(uint64_t *)((uint64_t)(ptr[i]) - sizeof(uint64_t)) > 0x4008)
  46. // printf("[%ld] start_addr = %#018lx, len = %#010lx\n", i, (uint64_t)(ptr[i]) - 8, *(uint64_t *)((uint64_t)(ptr[i]) - sizeof(uint64_t)));
  47. }
  48. // printf("ptr[0]->len=%lld\n", *(uint64_t *)((uint64_t)ptr[0] - sizeof(uint64_t)));
  49. // printf("ptr[1]->len=%lld\n", *(uint64_t *)((uint64_t)ptr[1] - sizeof(uint64_t)));
  50. // printf("ptr[24]->len=%lld\n", *(uint64_t*)((uint64_t)ptr[24] - sizeof(uint64_t)));
  51. printf("alloc done. total used: %lld bytes\n", js);
  52. printf("try to free...\n");
  53. for (int i = 0; i < 256; ++i)
  54. {
  55. free(ptr[i]);
  56. }
  57. printf("free done!\n");
  58. }
  59. */
  60. // *p = 'a';
  61. /*
  62. pid_t p = fork();
  63. if(p == 0)
  64. put_string("subproc\n", COLOR_PURPLE, COLOR_BLACK);
  65. else put_string("parent proc\n", COLOR_ORANGE, COLOR_BLACK);
  66. */
  67. while (1)
  68. ;
  69. }