Today I decide to write my blog in English,though... beacause...
I rewrite the head.s in masm assemble language.
the following...
.386p
.model flat,stdcall
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
LATCH equ 11930
SCRN_SEL equ 18h
TSS0_SEL equ 20h
LDT0_SEL equ 28h
TSS1_SEL equ 30h
LDT1_SEL equ 38h
.code
;make the ds point a segment same to cs
org 0h
start: mov eax,10h
mov ds,ax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
lss esp,fword ptr [ds:[init_stack - start]]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
call setup_idt
call setup_gdt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov eax,10h
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
lss esp,fword ptr [ds:[init_stack - start]]
;setting the timing chip
mov al,36h
mov edx,43h
out dx,al
mov eax,LATCH
mov edx,40h
out dx,al
mov ah,al
out dx,al
;setting the timer interrupt(8th) and calls interrupt(128th) in IDT table.
mov eax,00080000h
mov ax,word ptr (timer_interrupt - start)
mov dx,8e00h
mov ecx,08h
lea esi,(idt - start)[ecx*8]
mov dword ptr [esi],eax
mov dword ptr [esi + 4],edx
;中断80h设置
mov ax,word ptr (system_interrupt - start)
mov dx,0ef00h
mov ecx,80h
lea esi,(idt - start)[ecx*8]
mov dword ptr [esi],eax
mov dword ptr [esi + 4],edx
pushfd
and dword ptr [esp],0ffffbfffh
popfd
mov eax,TSS0_SEL
ltr ax
mov eax,LDT0_SEL
lldt ax
mov dword ptr [ds:[current - start]],0
sti
pushd 17h
pushd esp
pushfd
pushd 0fh
pushd task0 - start
iretd
setup_gdt:
lgdt fword ptr [ds:[lgdt_opcode - start]]
ret
setup_idt:
mov edx,word ptr (ignore_int - start)
mov eax,00080000h
mov ax,dx
mov dx,8e00h
lea edi,dword ptr [ds:[idt - start]]
mov ecx,256
rp_idt:
mov dword ptr [edi],eax
mov dword ptr [edi+4],edx
add edi,8
dec ecx
jne rp_idt
lidt fword ptr [ds:[idt_opcode - start]]
ret
write_char:
push gs
push ebx
mov ebx,SCRN_SEL
mov gs,bx
mov ebx,dword ptr [ds:[scr_loc - start]]
shl ebx,1
assume gs:nothing
mov byte ptr [gs:[ebx]],al
shr ebx,1
inc ebx
cmp ebx,2000
jb fl_write
mov ebx,0
fl_write:
mov dword ptr [ds:[scr_loc - start]],ebx
pop ebx
pop gs
ret
ALIGN 4
ignore_int:
push ds
push eax
mov eax,10h
mov ds,ax
mov eax,67
call write_char
pop eax
pop ds
iretd
ALiGN 4
timer_interrupt:
push ds
push eax
mov eax,10h
mov ds,ax
mov al,20h
out 20h,al
mov eax,1
cmp dword ptr [ds:[current - start]],eax
je time_i0
mov dword ptr [ds:[current - start]],eax
;;jmp far TSS1_SEL:0h
db 0eah
dd 0
dw TSS1_SEL
jmp time_i20
time_i0:
mov dword ptr [ds:[current - start]],0
;;jmp far TSS0_SEL:06h
db 0eah
dd 0
dw TSS0_SEL
time_i20:
pop eax
pop ds
iretd
ALIGN 4
system_interrupt:
push ds
push edx
push ecx
push ebx
push eax
mov edx,10h
mov ds,dx
call write_char
pop eax
pop ebx
pop ecx
pop edx
pop ds
iretd
current:
dd 0
scr_loc:
dd 0
idt_opcode:
dw 256*8-1
dd idt - start
lgdt_opcode:
dw (end_gdt - gdt)-1
dd gdt - start
align 4
idt:
dq 256 dup(0)
gdt:
dq 0000000000000000h
dq 00c09a00000007ffh
dq 00c09200000007ffh
dq 00c0920b80000002h
dw 68h,(tss0 - start),0e900h,0
dw 40h,(ldt0 - start),0e200h,0
dw 68h,(tss1 - start),0e900h,0
dw 40h,(ldt1 - start),0e200h,0
end_gdt:
dd 128 dup(0)
init_stack:
dd (init_stack - start)
dw 10h
align 4
ldt0:
dq 0000000000000000h
dq 00c0fa00000003ffh
dq 00c0f200000003ffh
tss0:
dd 0
dd (krn_stk0 - start),10h
dd 0,0,0,0,0
dd 0,0,0,0,0
dd 0,0,0,0,0
dd 0,0,0,0,0,0
dd LDT0_SEL,8000000h
dd 128 dup(0)
krn_stk0:
align 4
ldt1:
dq 0000000000000000h
dq 00c0fa00000003ffh
dq 00c0f200000003ffh
tss1:
dd 0
dd (krn_stk1- start),10h
dd 0,0,0,0,0
dd task1 - start,200h
dd 0,0,0,0
dd (usr_stk1 - start),0,0,0
dd 17h,0fh,17h,17h,17h,17h
dd LDT1_SEL,8000000h
dd 128 dup(0)
krn_stk1:
task0:
mov eax,17h
mov ds,ax
mov al,65
int 80h
mov ecx,0fffh
t01:loop t01
jmp task0
task1:
mov al,66
int 80h
mov ecx,0fffh
t11: loop t11
jmp task1
dd 128 dup(0)
usr_stk1:
END start