📄 cw32.asm
字号:
mov XMSPresent,1 ;flag XMS is available.
; MED, 09/10/99, support extended XMS API to calculate XMS available to CauseWay
; (maximum of 2G-32K, i.e. 32 handles/entries of 64K-1)
mov ah,0
call d[XMSControl] ; get info
cmp ah,3
jb xms2
cmp bh,3
jb xms2
cmp bl,8
jb xms2 ; treat early 3.x drivers < 3.08 as 2.x
; use extended XMS API
mov XMSVer3Present,1 ; flag XMS 3.x driver present
mov ah,88h
call d[XMSControl] ;get size of biggest block free.
mov edx,eax
test eax,eax
jz @@YesXMS ;no memory available.
mov cs:d[@@XMSSize],edx
mov ah,89h
call d[XMSControl] ;claim biggest block to force XMS
cmp ax,1 ;to stake a claim on int 15h.
jnz @@YesXMS
mov cs:b[@@NumXMSHandles],1
push dx
mov ah,8eh
call d[XMSControl] ; get handle information
cmp ax,1
jnz @@NoHandles3
cmp cx,4
jc @@NoHandles3
sub cx,2
mov cs:b[@@NumXMSHandles],32
cmp cx,32
jnc @@NoHandles3
mov cs:b[@@NumXMSHandles],cl ; cx known 8-bit value
@@NoHandles3:
pop dx
mov ah,0ah
call d[XMSControl] ;now free it.
movzx eax, BYTE PTR cs:[@@NumXMSHandles]
mov edx,eax
shl eax,16
sub eax,edx ; eax == handles (up to 32) * 65535
cmp eax,cs:d[@@XMSSize]
jae @@ComputeSize
mov cs:d[@@XMSSize],eax ; throttle maximum size
@@ComputeSize:
push eax
xor edx,edx
movzx ebx,BYTE PTR cs:[@@NumXMSHandles]
div ebx
pop ebx
cmp ax,4 ; eax known 16-bit value
jnc @@SizeOK3
mov ax,bx ; ebx == maximum size, known 16-bit value here
@@SizeOK3:
mov XMSBlockSize,ax
jmp @@YesXMS
xms2:
mov ah,8
call d[XMSControl] ;get size of biggest block free.
mov dx,ax
or ax,ax
jz @@YesXMS ;no memory available.
mov cs:w[@@XMSSize],dx
mov ah,9
call d[XMSControl] ;claim biggest block to force XMS
cmp ax,1 ;to stake a claim on int 15h.
jnz @@YesXMS
mov cs:b[@@NumXMSHandles],1
push dx
mov ah,0eh
call d[XMSControl] ;now free it.
cmp ax,1
jnz @@NoHandles
cmp bl,4
jc @@NoHandles
sub bl,2
mov cs:b[@@NumXMSHandles],32
cmp bl,32
jnc @@NoHandles
mov cs:b[@@NumXMSHandles],bl
@@NoHandles: pop dx
mov ah,0ah
call d[XMSControl] ;now free it.
mov ax,cs:w[@@XMSSize]
push ax
xor dx,dx
xor bh,bh
mov bl,cs:b[@@NumXMSHandles]
div bx
pop bx
cmp ax,4
jnc @@SizeOK
mov ax,bx
@@SizeOK: mov XMSBlockSize,ax
jmp @@YesXMS
;
;Install raw A20 handler.
;
@@NoXMS: call InstallA20
;
;Get A20 state.
;
@@YesXMS: push ds
les di,HighMemory ; with the four at FFFF:0090
lds si,LowMemory ; Compare the four words at 0000:0080
mov cx,4
cld
repe cmpsw
pop ds
xor ax,ax
jcxz @@A20OFF ; Are the two areas the same?
inc ax ; No, return A20 Enabled
@@A20OFF: mov A20Flag,al
;
;Change DOS allocation stratergy to highest so we'll get UMB's if available.
;
mov ax,5800h
int 21h
mov cs:w[@@OldStrat],ax
mov ax,5802h
int 21h
mov cs:w[@@OldStrat+2],ax
mov bx,1
mov ax,5803h
int 21h
mov bx,81h
mov ax,5801h
int 21h
;
;Grab memory for page dir, page alias & first page table entry.
;
mov bx,(4096*3)/16 ;smallest allocation possible.
mov ah,48h
int 21h
jc @@OldWay
push ax
movzx eax,ax
shl eax,4 ;linear address.
mov ebx,eax
add eax,4095
and eax,0ffffffffh-4095 ;round up to next page.
sub eax,ebx
shr eax,4
mov bx,ax
mov cx,ax
add bx,(4096*3)/16
mov ah,4ah
pop es
pushm bx,cx,es
int 21h ;re-size the block.
popm bx,cx,es
jnc @@NewWay
mov ah,49h
int 21h ;release this block.
;
@@OldWay: mov cs:IErrorNumber,5
mov bx,(4096*4)/16 ;need space for 3 page tables on
mov ah,48h ;4k boundary.
int 21h
jc InitError
mov dx,ax
movzx eax,ax ;get segment address.
shl eax,4 ;make linear.
mov ebx,eax
add eax,4095
and eax,0FFFFFFFFh-4095 ;round up to nearest page.
mov ecx,eax
sub ecx,ebx
shr ecx,4
shr eax,4 ;Get segment value again.
jmp @@GotSeg
;
@@NewWay: mov ax,es
mov dx,ax
add ax,cx ;move to real start.
;
@@GotSeg:
pushm cx,dx
mov es,ax
; MED 09/19/96
; mov PageDirReal,ax ;setup page directory address.
; add ax,4096/16
; mov Page1stReal,ax ;setup 1st page table address.
mov Page1stReal,ax ;setup 1st page table address.
add ax,4096/16
mov PageDirReal,ax ;setup page directory address.
add ax,4096/16
mov PageAliasReal,ax ;setup alias table address.
xor di,di
mov cx,4096*3
xor al,al
cld
rep stosb ;clear it.
movzx eax,PageDIRReal
shl eax,4
mov PageDIRLinear,eax
mov VCPI_CR3,eax
movzx eax,PageALIASReal
shl eax,4
mov PageAliasLinear,eax
movzx eax,Page1stReal
shl eax,4
mov Page1stLinear,eax
popm cx,dx
;
;See if enough wasted space to squeeze TSS into.
;
cmp cx,(((size TSSFields)+2+16)/16)
jc @@TSSOld
mov ax,dx ;get segment.
add dx,(((size TSSFields)+2+16)/16) ;move segment base.
sub cx,(((size TSSFields)+2+16)/16) ;update space left size.
jmp @@TSSGot
;
;Allocate memory for Kernal TSS.
;
@@TSSOld: mov cs:IErrorNumber,5
mov bx,(((size TSSFields)+2+16)/16) ;(4096/2)+2+16)/16
mov ah,48h
int 21h
jc InitError
@@TSSGot: mov KernalTSSReal,ax
;
;See if enough wasted space to squeeze GDT into.
;
cmp cx,((8*GDT_Entries)/16)+1
jc @@GDTOld
mov ax,dx ;get segment.
add dx,((8*GDT_Entries)/16)+1 ;move segment base.
sub cx,((8*GDT_Entries)/16)+1 ;update space left size.
jmp @@GDTGot
;
;Allocate some memory for the GDT.
;
@@GDTOld: mov cs:IErrorNumber,5
mov bx,((8*GDT_Entries)/16)+1
mov ah,48h
int 21h
jc InitError
@@GDTGot: mov GDTReal,ax
mov es,ax
movzx eax,ax
shl eax,4
mov GDTLinear,eax
xor di,di
mov cx,(8*GDT_Entries)
xor al,al
cld
rep stosb
;
;Allocate some memory for the stack.
;
mov cs:IErrorNumber,5
mov ebx,RawStackPos
shr ebx,4
mov ah,48h
int 21h
jc InitError
mov RawStackReal,ax
mov es,ax
mov cx,w[RawStackPos]
xor di,di
xor al,al
cld
rep stosb
; MED 09/19/96
; Set address for VMM page to disk buffer.
mov cs:IErrorNumber,5
mov bx,4096/16
mov ah,48h
int 21h
jc InitError
mov PageBufferReal,ax
movzx eax,ax
shl eax,4
mov PageBufferLinear,eax
;
;Restore DOS memory allocation stratergy.
;
mov bx,cs:w[@@OldStrat+2]
xor bh,bh
mov ax,5803h
int 21h
mov bx,cs:w[@@OldStrat]
xor bh,bh
mov ax,5801h
int 21h
;
;Need to initialise 1st page table to map <1meg+64k 1:1.
;
mov es,Page1stReal
xor di,di
mov cx,256+16 ;1st 1 meg + 64k.
mov esi,111b ;user+write+present
@@0: mov es:[di],esi
add di,4 ;next page table entry.
add esi,4096 ;next physical page address.
dec cx
jnz @@0
; MED 09/19/96
COMMENT !
;
;Set address for VMM page to disk buffer.
;
mov ax,PageDIRReal
mov PageBufferReal,ax
movzx eax,ax
shl eax,4
mov PageBufferLinear,eax
END COMMENT !
;
;Set address for DOS INT 21h PM to Real transfer buffer.
;
; MED 09/19/96
; mov bx,Page1stReal
mov bx,PageDirReal
push ds
mov ax,_cwMain
mov ds,ax
assume ds:_cwMain
mov TransferReal,bx
assume ds:_cwRaw
pop ds
;
;Allocate the GDT entries.
;
mov es,GDTReal
;
;Fill in the null entry just for the hell of it.
;
xor esi,esi ;Null entry at 0.
xor ecx,ecx
xor ax,ax
xor di,di
call MakeDesc
;
;Fill in the VCPI entries so we don't try to use them later.
;
xor esi,esi
xor ecx,ecx
mov ah,DescPresent+DescPL3+DescMemory+DescRWData
mov di,VCPI_0
call MakeDesc
xor esi,esi
xor ecx,ecx
mov ah,DescPresent+DescPL3+DescMemory+DescRWData
mov di,VCPI_1
call MakeDesc
xor esi,esi
xor ecx,ecx
mov ah,DescPresent+DescPL3+DescMemory+DescRWData
mov di,VCPI_2
call MakeDesc
;
;Allocate 40h descriptor.
;
mov esi,400h
mov ecx,65535
xor al,al
mov ah,DescPresent+DescPL3+DescMemory+DescRWData
mov di,Kernal40h
call MakeDesc
;
;Allocate kernal task descriptors, TSS itself first.
;
movzx esi,KernalTSSReal
shl esi,4
mov ecx,size TSSFields+2
xor al,al
mov ah,DescPresent+DescPL3+Desc386Tss
mov di,KernalTS
call MakeDesc
;
;TSS PL0 stack.
;
movzx esi,KernalTSSReal
shl esi,4
add esi,tPL1Stack
mov ecx,65535
mov al,b[RawSystemFlags]
xor al,1
shl al,6
mov ah,DescPresent+DescPL0+DescMemory+DescRWData
mov di,KernalPL0
call MakeDesc
;
;Mode switch PL0 stack.
;
movzx esi,KernalTSSReal
shl esi,4
add esi,tPL1Stack
mov ecx,65535
xor al,al
mov ah,DescPresent+DescPL0+DescMemory+DescRWData
mov di,KernalSwitchPL0
call MakeDesc
;
;LDT
;
xor esi,esi
xor ecx,ecx
xor al,al
mov ah,DescPresent+DescPL3+DescLDT
mov di,KernalLDT
call MakeDesc
;
;Kernal (RAW) code seg.
;
xor esi,esi
mov si,_cwRaw
shl esi,4
mov ecx,65535
xor al,al
mov ah,DescPresent+DescPL3+DescMemory+DescERCode
mov di,KernalCS
call MakeDesc
;
;Kernal (RAW) code seg at PL0
;
xor esi,esi
mov si,_cwRaw
shl esi,4
mov ecx,65535
xor al,al
mov ah,DescPresent+DescPL0+DescMemory+DescERCode
mov di,KernalCS0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -