《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.8 KiB

  1. #README
  2. Try below command
  3. ```
  4. gcc -g -m32 lab0_ex3.c 2>&1|tee make.log
  5. ```
  6. If you get gcc's error, try to read make.log and fix the bugs.
  7. If gcc successed, then you will get a.out.
  8. Try to answer below question.
  9. 对于如下的代码段,
  10. ```
  11. ...
  12. #define STS_CG32 0xC // 32-bit Call Gate
  13. #define STS_IG32 0xE // 32-bit Interrupt Gate
  14. #define SETGATE(gate, istrap, sel, off, dpl) { \
  15. (gate).gd_off_15_0 = (uint32_t)(off) & 0xffff; \
  16. (gate).gd_ss = (sel); \
  17. (gate).gd_args = 0; \
  18. (gate).gd_rsv1 = 0; \
  19. (gate).gd_type = (istrap) ? STS_TG32 : STS_IG32; \
  20. (gate).gd_s = 0; \
  21. (gate).gd_dpl = (dpl); \
  22. (gate).gd_p = 1; \
  23. (gate).gd_off_31_16 = (uint32_t)(off) >> 16; \
  24. }
  25. /* Gate descriptors for interrupts and traps */
  26. struct gatedesc {
  27. unsigned gd_off_15_0 : 16; // low 16 bits of offset in segment
  28. unsigned gd_ss : 16; // segment selector
  29. unsigned gd_args : 5; // # args, 0 for interrupt/trap gates
  30. unsigned gd_rsv1 : 3; // reserved(should be zero I guess)
  31. unsigned gd_type : 4; // type(STS_{TG,IG32,TG32})
  32. unsigned gd_s : 1; // must be 0 (system)
  33. unsigned gd_dpl : 2; // descriptor(meaning new) privilege level
  34. unsigned gd_p : 1; // Present
  35. unsigned gd_off_31_16 : 16; // high bits of offset in segment
  36. };
  37. ...
  38. ```
  39. 如果在其他代码段中有如下语句,
  40. ```
  41. unsigned intr;
  42. intr=8;
  43. SETGATE(intr, 0,1,2,3);
  44. ```
  45. 请问执行上述指令后, intr的值是多少?