《操作系统》的实验代码。
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.

81 lines
1.8 KiB

  1. #define Descriptor(base,lim,type)\
  2. .word lim&0xffff;\
  3. .word base&0xffff;\
  4. .byte (base>>16)&0xff;\
  5. .word ((lim>>8)&0xf00)|(type&0x0f0ff);\
  6. .byte ((base>>24)&0xff)
  7. DA_C = 0x98
  8. DA_32 = 0x4000
  9. DA_DRW = 0x92
  10. .text
  11. .globl start
  12. .code16
  13. start:
  14. jmpl $0x0, $code
  15. GDT_START:
  16. Descriptor_DUMMY:Descriptor(0x0,0x0,0x0) /* 00 */
  17. Descript_CODE32 :Descriptor(0x0,0xffffffff,DA_C+DA_32) /* 32访 */
  18. Descriptor_VIDEO:Descriptor(0xb8000,0x0ffff,DA_DRW) /* 访 */
  19. GDT_END:
  20. GdtPtr:
  21. .word (GDT_END-GDT_START)-1 # so does gdt
  22. .long GDT_START # This will be rewrite by code.
  23. msg:
  24. .string "Hello world!"
  25. code:
  26. mov %cs,%ax
  27. mov %ax,%ds
  28. mov %ax,%es
  29. mov %ax,%ss
  30. mov $0x8000,%sp
  31. /*HelloWorld字符串*/
  32. mov $msg ,%ax
  33. mov %ax ,%bp
  34. mov $12 ,%cx
  35. mov $0x1301,%ax
  36. mov $0x000c,%bx
  37. mov $0 ,%dl
  38. int $0x10
  39. /*gdtr即将全局描述符表gdt的首地址和gdt的界限赋给gdtr寄存器*/
  40. lgdt GdtPtr
  41. /**/
  42. cli
  43. /*线A20*/
  44. inb $0x92,%al
  45. or $0x02,%al
  46. outb %al,$0x92
  47. /*cr0寄存器,*/
  48. movl %cr0,%eax
  49. or $1,%eax
  50. movl %eax,%cr0
  51. /*,CS=0x8,IP=LABEL_SEG_CODE32的偏移地址*/
  52. ljmp $0x8,$(LABEL_SEG_CODE32)
  53. /*CS:IP=1(0x8>>3)+LABEL_SEG_CODE32的偏移地址*/
  54. LABEL_SEG_CODE32:
  55. .align 32
  56. .code32
  57. movw $0x10,%ax
  58. movw %ax,%gs
  59. movl $((80*11+79)*2),%edi/*1179*/
  60. movb $0x0c,%ah/*,*/
  61. movb $'P',%al/**/
  62. movw %ax,%gs:(%edi)
  63. loop2:
  64. jmp loop2
  65. .org 0x1fe, 0x90
  66. .word 0xaa55