📄 cwl.asm
字号:
mov edi,PUBLICList
mov eax,[edi]
inc d[edi] ;update number of entries.
lea edi,[edi+4+eax*4] ;point to new entry.
mov [edi],offset InternalPUBDEF__estack
or d[PUB.PFlags+InternalPUBDEF__estack],2
;
clc
jmp @@10
;
@@9: stc
@@10: popad
ret
AddInternalPUBDEFs endp
;------------------------------------------------------------------------------
;
;Update internaly maintained PUBDEFs.
;
;On Entry:
;
;nothing.
;
;On Exit:
;
;Carry set on error else,
;
;All registers preserved.
;
UpdateInternalPUBDEFs proc near
pushad
;
;Work out _end values.
;
mov esi,offset SegClassBSS
xor edi,edi
call FindLastSEGDEFClass ;Look for last class of BSS
jc @@0
inc eax ;Publics use +1
mov edi,offset InternalPUBDEF__end
mov PUB.PSeg[edi],eax
dec eax
shl eax,2
add eax,4
add eax,SEGDEFList
mov eax,[eax]
mov eax,LSeg.SLength[eax]
mov PUB.PValue[edi],eax
;
;Work out _edata values.
;
@@0: mov esi,offset SegClassBSS
xor edi,edi
call FindSEGDEFClass ;Look for first class of BSS
jc @@1
inc eax ;Publics use +1
mov edi,offset InternalPUBDEF__edata
mov PUB.PSeg[edi],eax
;
;Work out _estack values.
;
@@1: mov esi,offset SegClassSTACK
xor edi,edi
call FindLastSEGDEFClass ;Look for last class of BSS
jc @@2
inc eax ;Publics use +1
mov edi,offset InternalPUBDEF__estack
mov PUB.PSeg[edi],eax
dec eax
shl eax,2
add eax,4
add eax,SEGDEFList
mov eax,[eax]
mov eax,LSeg.SLength[eax]
mov PUB.PValue[edi],eax
;
@@2: clc
jmp @@10
;
@@9: stc
@@10: popad
ret
UpdateInternalPUBDEFs endp
;------------------------------------------------------------------------------
;
;Works it's way through initial object list calling object pass one processing
;routine(s)
;
;On Entry:
;
;nothing.
;
;On Exit:
;
;Carry set on error else,
;
;All registers preserved.
;
InitialPassOne proc near
pushad
mov edi,ObjList ;Point to list.
mov ebp,[edi] ;Get number of entries.
add edi,4 ;Point to real data.
@@0: push edi
mov edi,[edi]
call ObjPassOne ;Do pass one processing.
pop edi
jc @@9
add edi,4
dec ebp
jnz @@0
clc
jmp @@10
@@9: stc
@@10: popad
ret
InitialPassOne endp
;------------------------------------------------------------------------------
;
;Do pass one processing of an object module. This includes checking we know
;about all record types, checking all checksums, extracting LIB names and
;registering PUBDEF and EXTDEF records.
;
;On Entry:
;
;EDI - Module struc.
;
;On Exit:
;
;Carry set on error else,
;
;All registers preserved.
;
ObjPassOne proc near
pushad
mov esi,Obj.Module[edi] ;point to current module.
mov ebp,Obj.MLength[edi] ;get length so we can check for over-run.
mov PharLapFlag,0
jmp ObjPassOneProcess
ObjPassOne endp
;------------------------------------------------------------------------------
;
;This is the processing header stuff. It checks record type validity and
;optionaly the checksum.
;
ObjPassOneProcess proc near
push ebp
;
@@2: ;Check this record doesn't extend past the end of the file.
;
movzx eax,w[esi+1] ;Get record length.
add eax,3 ;Include type and length.
cmp ebp,eax ;Longer than what we have left?
jnc @@3
;
;Try and work out what the module name is.
;
mov ErrorNumber,5
mov eax,Obj.MFileName[edi]
mov ErrorName,eax
mov esi,Obj.MName[edi]
or esi,esi
jz ObjPassOneError
movzx ecx,b[esi]
inc esi
mov edi,offset ErrorNameSpace2
mov ErrorName+4,edi
rep movsb
mov b[edi],0
jmp ObjPassOneError
;
@@3: ;Check the checksum.
;
cmp CHKSums,0
jz @@4
movzx ecx,w[esi+1] ;Get record length.
add ecx,3 ;Include type and length.
xor al,al
push esi
@@3_0: add al,[esi] ;Update checksum.
inc esi
dec ecx
jnz @@3_0
pop esi
or al,al ;Should be zero at this point.
jz @@4
mov ErrorNumber,6
;
;Try and work out what the module name is.
;
mov ErrorNumber,5
mov eax,Obj.MFileName[edi]
mov ErrorName,eax
mov esi,Obj.MName[edi]
or esi,esi
jz ObjPassOneError
movzx ecx,b[esi]
inc esi
mov edi,offset ErrorNameSpace2
mov ErrorName+4,edi
rep movsb
mov b[edi],0
jmp ObjPassOneError
;
@@4: ;Now we can process this record if it's relavent at this point.
;
xor eax,eax
mov al,[esi] ;Get the record type.
mov ObjPassOneType,al
movzx edx,w[esi+1]
add esi,3
pop ebp
sub ebp,3
sub ebp,edx ;Update length remaining count.
push ebp
;
jmp d[ObjPassOneTable+eax*4] ;Pass to relavent routine.
ObjPassOneProcess endp
;------------------------------------------------------------------------------
;
;Deal with an entry we're not really interested in.
;
ObjPassOneNext proc near
add esi,edx
pop ebp
jmp ObjPassOneProcess
ObjPassOneNext endp
;------------------------------------------------------------------------------
;
;Bad (un-recognised) record type found, display info and exit.
;
ObjPassOneBad proc near
push edi
mov edi,offset ErrorM19_N
mov ecx,2
call Bin2Hex
pop edi
mov ErrorNumber,19
;
;Try and work out what the module name is.
;
mov eax,Obj.MFileName[edi]
mov ErrorName,eax
mov esi,Obj.MName[edi]
or esi,esi
jz ObjPassOneError
movzx ecx,b[esi]
inc esi
mov edi,offset ErrorNameSpace2
mov ErrorName+4,edi
rep movsb
mov b[edi],0
; call ShowInvalidObjRecType
jmp ObjPassOneError
ObjPassOneBad endp
;------------------------------------------------------------------------------
;
;Some sort of error has occured so set carry and exit.
;
ObjPassOneError proc near
stc
jmp ObjPassOneExit
ObjPassOneError endp
;------------------------------------------------------------------------------
;
;Everything went well so clear carry and exit.
;
ObjPassOneOK proc near
clc
jmp ObjPassOneExit
ObjPassOneOK endp
;------------------------------------------------------------------------------
;
;Clean up the stack and exit.
;
ObjPassOneExit proc near
pop ebp
popad
ret
ObjPassOneExit endp
;------------------------------------------------------------------------------
;
;Get modules source file name for debug info storage.
;
ObjPassOne_THEADR proc near
mov Obj.MName[edi],esi
jmp ObjPassOneNext
ObjPassOne_THEADR endp
;------------------------------------------------------------------------------
;
;Process a COMENT record.
;
ObjPassOne_COMENT proc near
mov al,[esi+1] ;Get the comment type.
cmp al,COM_PHARLAP ;32-bit default?
jnz @@com0
or PharLapFlag,-1
jmp ObjPassOneNext
;
@@com0: cmp al,COM_LIBDEF ;LIB?
jnz @@com1
cmp DefaultLibraries,0
jz ObjPassOneNext ;Skip it for /NOD
add esi,2 ;Point to the name.
sub edx,2
dec edx ;Don't include the checksum.
push edi
mov edi,offset FileNameSpace
xor ebx,ebx
mov ecx,edx
@@com0_1: mov al,[esi]
mov [edi],al
inc esi
inc edi
cmp al,"."
jnz @@com0_2
mov ebx,edi
@@com0_2: cmp al,"\"
jnz @@com0_3
xor ebx,ebx
@@com0_3: dec ecx
jnz @@com0_1
or ebx,ebx
jnz @@com0_4
push esi
mov esi,offset ExtensionList+12
mov ecx,4
rep movsb
pop esi
@@com0_4: xor al,al
stosb ;has to be zero terminated.
pop edi
inc esi ;skip the checksum.
;
mov edx,offset FileNameSpace
call LoadLIBFile
jc ObjPassOneError
xor edx,edx
jmp ObjPassOneNext
;
@@com1: cmp al,0a2h ;pass one marker?
jnz @@com2
jmp ObjPassOneOK ;pretend we finished.
;
@@com2: cmp al,COM_DOSSEG
jnz @@com3
or DOSSEGSegmentOrder,-1
jmp ObjPassOneNext
;
@@com3: cmp al,COM_OMF1 ;OMF extension 1?
jnz @@com4
cmp b[esi+2],1 ;IMPDEF?
jnz @@com3_0
;
;Create a text IMPORT command and pass to IMPORT processor.
;
pushad
mov edi,offset DefLineBuffer
mov b[edi+0],"I"
mov b[edi+1],"M"
mov b[edi+2],"P"
mov b[edi+3],"O"
mov b[edi+4],"R"
mov b[edi+5],"T"
mov b[edi+6]," "
add edi,7
;
;Do local name.
;
lea edx,[esi+1+1+1+1]
movzx ecx,b[edx]
inc edx
@@com3_1_0: mov al,[edx]
mov [edi],al
inc edx
inc edi
dec ecx
jnz @@com3_1_0
mov b[edi]," "
inc edi
;
;Do module name.
;
lea edx,[esi+1+1+1+1]
movzx eax,b[edx]
inc eax
add edx,eax
movzx ecx,b[edx]
inc edx
@@com3_1_1: mov al,[edx]
mov [edi],al
inc edx
inc edi
dec ecx
jnz @@com3_1_1
mov b[edi],"."
inc edi
;
;Do external name or ordinal.
;
lea edx,[esi+1+1+1+1]
movzx eax,b[edx]
inc eax
add edx,eax
movzx eax,b[edx]
inc eax
add edx,eax
cmp b[esi+3],0
jz @@com3_1_2
;
;Generate ordinal number.
;
movzx eax,w[edx]
call Bin2Dec
jmp @@com3_1_4
;
@@com3_1_2: ;Generate external name.
;
movzx ecx,b[edx]
inc edx
or ecx,ecx
jnz @@com3_1_3
lea edx,[esi+1+1+1+1] ;use local name.
movzx ecx,b[edx]
inc edx
@@com3_1_3: mov al,[edx]
mov [edi],al
inc edx
inc edi
dec ecx
jnz @@com3_1_1
;
@@com3_1_4: ;Call IMPORT handler.
;
mov b[edi],0
mov edi,offset DefLineBuffer+6
call DEF_ImportCOM
popad
jmp ObjPassOneNext
;
@@com3_0: jmp ObjPassOneNext
;
@@com4: jmp ObjPassOneNext
ObjPassOne_COMENT endp
;------------------------------------------------------------------------------
;
;Deal with a PUBDEF record.
;
ObjPassOne_PUBDEF proc near
cmp PharLapFlag,0
jz @@pdx0
or ObjPassOneType,1
@@pdx0: ;
dec edx ;Don't include checksum.
GetIndex ;Get the group index.
mov PUBDEF_GRP,eax
GetIndex ;Get the SEGDEF index.
mov PUBDEF_SEG,eax
;
;Get the FRAME number if needed.
;
mov eax,PUBDEF_GRP
or eax,PUBDEF_SEG
jnz @@pd2
xor eax,eax
mov ax,w[esi]
add esi,2
sub edx,2
mov PUBDEF_FRAME,eax
;
@@pd2: ;Now sit in a loop getting names and values.
;
or edx,edx ;Anything left?
jz @@pd9
;
;Check this isn't a duplicate symbol.
;
mov PUBDEFObj,edi
xor eax,eax
mov al,ObjPassOneType
and al,not 1 ;lose size bit.
xor al,PUBDEF
; not al
mov PUBDEFScope,eax
call FindGlobalPUBDEF
jc @@pd2_0
;
;oops, already got this symbol so issue a warning.
;
;Show this entries details.
;
mov ErrorNumber,29
push esi
mov esi,Obj.MFileName[edi]
mov ErrorName,esi
mov esi,Obj.MName[edi]
mov ErrorName+4,esi
or esi,esi
jz @@NoSName0
push ecx
push edi
movzx ecx,b[esi]
inc esi
mov edi,offset ErrorNameSpace2
mov ErrorName+4,edi
rep movsb
mov b[edi],0
pop edi
pop ecx
@@NoSName0: pop esi
pushm ecx,esi,edi
movzx ecx,b[esi]
inc esi
mov edi,offset ErrorNameSpace3
mov ErrorName+8,edi
mov b[edi],13
inc edi
mov b[edi],10
inc edi
rep movsb
mov b[edi],0
popm ecx,esi,edi
call PrintError
;
;Show origional entries details.
;
mov ErrorNumber,30
pushad
shl eax,2 ;Write name of module that has
add eax,4 ;origional definition.
add eax,PUBLICList
mov esi,[eax]
push esi
mov esi,PUB.PObj[esi]
mov eax,Obj.MFileName[esi]
mov ErrorName,eax
mov esi,Obj.MName[esi]
mov ErrorName+4,esi
or esi,esi
jz @@NoSName1
movzx ecx,b[esi]
inc esi
mov edi,offset ErrorNameSpace2
mov ErrorName+4,edi
rep movsb
mov b[edi],0
@@NoSName1: pop esi
popad
mov ErrorName+8,0
call PrintError
dec ErrorCount
;
@@pd2_0: ;Expand the list.
;
ExpandList PUBLICList,ListBumpG
mov ErrorNumber,2
jc ObjPassOneError
;
;Get PUB struc.
;
push esi
mov ecx,size PUB
call Malloc
mov eax,esi
pop esi
mov ErrorNumber,2
jc ObjPassOneError
push edi
mov edi,eax
push eax
xor al,al
rep stosb
;
;Add this entry to the list.
;
mov edi,PUBLICList
mov eax,[edi]
inc d[edi] ;update number of entries.
lea edi,[edi+4+eax*4] ;point to new entry.
pop eax
mov [edi],eax
mov ebx,eax
pop edi
;
;Set this entries details.
;
mov PUB.PObj[ebx],edi
mov eax,PUBDEF_GRP
mov PUB.PGRP[ebx],eax
mov eax,PUBDEF_SEG
mov PUB.PSEG[ebx],eax
mov eax,PUBDEF_FRAME
mov PUB.PFRAME[ebx],eax
mov PUB.PName[ebx],esi
;
;Skip name.
;
movzx eax,b[esi]
inc eax
add esi,eax
sub edx,eax
;
;Now get the value.
;
xor eax,eax
mov ax,w[esi]
add esi,2
sub edx,2
test ObjPassOneType,1 ;32-bit version?
jz @@pd5
rol eax,16
mov ax,w[esi]
add esi,2
sub edx,2
rol eax,16
@@pd5: mov PUB.PValue[ebx],eax
;
;Get the type.
;
GetIndex
mov PUB.PType[ebx],eax
;
;Set the scope.
;
xor eax,eax
mov al,ObjPassOneType
and al,not 1 ;lose size bit.
cmp al,LPUBDEF
mov al,-1
jz @@0
xor al,al
@@0: mov PUB.PScope[ebx],eax ;store scope.
;
jmp @@pd2
;
@@pd9: inc esi
xor edx,edx
jmp ObjPassOneNext
ObjPassOne_PUBDEF endp
;------------------------------------------------------------------------------
;
;Do EXTDEF processing.
;
ObjPassOne_EXTDEF proc near
dec edx ;Don't include checksum.
;
@@ed0: or edx,edx
jz @@ed9
;
;See if this external already exists.
;
call FindGlobalEXTDEF
jnc @@ed1
call AddGlobalEXTDEF
mov ErrorNumber,2
jc ObjPassOneError
;
@@ed1: ;Expand the list so we can add this entry.
;
ExpandList Obj.MExtDefs[edi],ListBumpL
mov ErrorNumber,2
jc ObjPassOneError
;
;Add this entry to the list.
;
mov ebx,Obj.MExtDefs[edi]
mov ecx,[ebx]
inc d[ebx]
mov [ebx+4+ecx*4],eax
;
;Set the scope.
;
mov ebx,EXTDEFList
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -