21,458
社区成员
发帖
与我相关
我的任务
分享
.386p
assume: cs:code,ds:data
;------------------------------------------------;
jump macro selector,offsetv
db 0eah
dw offsetv
dw selector
endm
;
descriptor struc
limitl dw 0
basel dw 0
basem db 0
attrib dw 0
baseh db 0
descriptor ends
;
pdesc struc
limit dw 0
base dd 0
pdesc ends
;
atdw = 92h
atce = 98h
;------------------------------------------------;
data segment use16
gdt lable byte
dummy descriptor <>
code descriptor <0ffffh,,,atce,>
code_sel = code - gdt
datas descriptor <0ffffh,0,11h,atdw,>
datas_sel = datas - gdt
datad descriptor <0ffffh,,,atdw,>
datad_sel = datad - gdt
gdtlen = $ - gdt
;
vgdtr pdesc<gdtlen-1,>
;
bufferlen = 256
buffer db bufferlen dup (0)
data ends
;------------------------------------------------;
code segment use16
start:
mov ax,data
mov ds,ax
;
mov bx,16
mul bx
add ax,offset gdt
adc dx,0
mov word ptr vgdtr.base,ax
mov word ptr vgdtr.base+2,dx
;
mov ax,cs
mul bx
mov code.basel,ax
mov code.basem,dl
mov code.baseh,dh
;
mov ax,ds
mul bx
add ax,offset buffer
adc dx,0
mov datad.basel,ax
mov datad.basem,dl
mov datad.baseh,dh
;
lgdt qword ptr vgdtr
;
cli
call ea20
;
mov eax,cr0
or eax,1
mov cr0,eax
;
jump <code_sel>,<offset virtual>
;
virtual:
mov ax,datas_sel
mov ds,ax
mov ax,datad_sel
mov es,ax
cld
xor si,si
xor di,di
mov cx,bufferlen/4
repz movsd
;
mov eax,cr0
and eax,0fffffffeh
mov cr0,eax
;
jump <seg real>,<offset real>
;
real:
call da20
sti
;
mov ax,data
mov ds,ax
mov bx,offset buffer
mov ah,4ch
int 21h
;------------------------------------------------;
;Enable A20
ea20 proc
push ax
in al,92h
or al,2
out 92h,al
pop ax
ret
ea20 endp
;
;Disable A20
da20 proc
push ax
in al,92h
and al,0fdh
out 92h,al
pop ax
ret
da20 endp
;
code ends
end start
.386p
assume cs:codeseg,ds:dataseg
;------------------------------------------------;
jump macro selector,offsetv
db 0eah
dw offsetv
dw selector
endm
;
descriptor struc
limitl dw 0
basel dw 0
basem db 0
attrib dw 0
baseh db 0
descriptor ends
;
pdesc struc
limit dw 0
base dd 0
pdesc ends
;
atdw = 92h
atce = 98h
;------------------------------------------------;
dataseg segment use16
gdt label byte
dummy descriptor <>
code descriptor <0ffffh,,,atce,>
code_sel = code - gdt
datas descriptor <0ffffh,0,11h,atdw,>
datas_sel = datas - gdt
datad descriptor <0ffffh,,,atdw,>
datad_sel = datad - gdt
gdtlen = $ - gdt
;
vgdtr pdesc<gdtlen-1,>
;
buffer db 256 dup (0)
dataseg ends
;------------------------------------------------;
codeseg segment use16
start:
mov ax,dataseg
mov ds,ax
;
mov bx,16
mul bx
add ax,offset gdt
adc dx,0
mov word ptr vgdtr.base,ax
mov word ptr vgdtr.base+2,dx
;
mov ax,cs
mul bx
mov code.basel,ax
mov code.basem,dl
mov code.baseh,dh
;
mov ax,ds
mul bx
add ax,offset buffer
adc dx,0
mov datad.basel,ax
mov datad.basem,dl
mov datad.baseh,dh
;
lgdt qword ptr vgdtr ;Error!!!错误1
;
cli
call ea20
;
mov eax,cr0
or eax,1
mov cr0,eax
;
jump <code_sel>,<offset virtual>
;
virtual:
mov ax,datas_sel
mov ds,ax
mov ax,datad_sel
mov es,ax
cld
xor si,si
xor di,di
mov cx,256/4
repz movsd ;Error!!!错误2
;
mov eax,cr0
and eax,0fffffffeh
mov cr0,eax
;
jump <seg real>,<offset real>
;
real:
call da20
sti
;
mov ax,dataseg
mov ds,ax
mov bx,offset buffer
mov ah,4ch
int 21h
;------------------------------------------------;
;Enable A20
ea20 proc
push ax
in al,92h
or al,2
out 92h,al
pop ax
ret
ea20 endp
;
;Disable A20
da20 proc
push ax
in al,92h
and al,0fdh
out 92h,al
pop ax
ret
da20 endp
;
codeseg ends
end start