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

#define Descriptor(base,lim,type)\
.word lim&0xffff;\
.word base&0xffff;\
.byte (base>>16)&0xff;\
.word ((lim>>8)&0xf00)|(type&0x0f0ff);\
.byte ((base>>24)&0xff)
DA_C = 0x98
DA_32 = 0x4000
DA_DRW = 0x92
.text
.globl start
.code16
start:
jmpl $0x0, $code
GDT_START:
Descriptor_DUMMY:Descriptor(0x0,0x0,0x0) /* 00 */
Descript_CODE32 :Descriptor(0x0,0xffffffff,DA_C+DA_32) /* 32访 */
Descriptor_VIDEO:Descriptor(0xb8000,0x0ffff,DA_DRW) /* 访 */
GDT_END:
GdtPtr:
.word (GDT_END-GDT_START)-1 # so does gdt
.long GDT_START # This will be rewrite by code.
msg:
.string "Hello world!"
code:
mov %cs,%ax
mov %ax,%ds
mov %ax,%es
mov %ax,%ss
mov $0x8000,%sp
/*HelloWorld字符串*/
mov $msg ,%ax
mov %ax ,%bp
mov $12 ,%cx
mov $0x1301,%ax
mov $0x000c,%bx
mov $0 ,%dl
int $0x10
/*gdtr即将全局描述符表gdt的首地址和gdt的界限赋给gdtr寄存器*/
lgdt GdtPtr
/**/
cli
/*线A20*/
inb $0x92,%al
or $0x02,%al
outb %al,$0x92
/*cr0寄存器,*/
movl %cr0,%eax
or $1,%eax
movl %eax,%cr0
/*,CS=0x8,IP=LABEL_SEG_CODE32的偏移地址*/
ljmp $0x8,$(LABEL_SEG_CODE32)
/*CS:IP=1(0x8>>3)+LABEL_SEG_CODE32的偏移地址*/
LABEL_SEG_CODE32:
.align 32
.code32
movw $0x10,%ax
movw %ax,%gs
movl $((80*11+79)*2),%edi/*1179*/
movb $0x0c,%ah/*,*/
movb $'P',%al/**/
movw %ax,%gs:(%edi)
loop2:
jmp loop2
.org 0x1fe, 0x90
.word 0xaa55