《操作系统》的实验代码。

33 rader
742 B

12 år sedan
  1. #include <stdio.h>
  2. #include <ulib.h>
  3. #define ARRAYSIZE (1024*1024)
  4. uint32_t bigarray[ARRAYSIZE];
  5. int
  6. main(void) {
  7. cprintf("Making sure bss works right...\n");
  8. int i;
  9. for (i = 0; i < ARRAYSIZE; i ++) {
  10. if (bigarray[i] != 0) {
  11. panic("bigarray[%d] isn't cleared!\n", i);
  12. }
  13. }
  14. for (i = 0; i < ARRAYSIZE; i ++) {
  15. bigarray[i] = i;
  16. }
  17. for (i = 0; i < ARRAYSIZE; i ++) {
  18. if (bigarray[i] != i) {
  19. panic("bigarray[%d] didn't hold its value!\n", i);
  20. }
  21. }
  22. cprintf("Yes, good. Now doing a wild write off the end...\n");
  23. cprintf("testbss may pass.\n");
  24. bigarray[ARRAYSIZE + 1024] = 0;
  25. asm volatile ("int $0x14");
  26. panic("FAIL: T.T\n");
  27. }