Skip to content

Commit

Permalink
causeway: cleanup code
Browse files Browse the repository at this point in the history
update comments
use new macros to do code more readable
  • Loading branch information
jmalak committed Jan 26, 2025
1 parent 5367f7d commit bc9d850
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 99 deletions.
18 changes: 12 additions & 6 deletions bld/causeway/asm/api.asm
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ api1_GotCall:
movzx ebp,bp
mov esi,Int_Flags16
api1_32Bit0:
and BYTE PTR ss:[ebp+esi],not EFLAG_CF ;clear carry.
;clear CF (carry).
and BYTE PTR ss:[ebp+esi],not EFLAG_CF
cld ;Default direction.
test WORD PTR ss:[ebp+esi],EFLAG_IF ;Were interrupts enabled?
jz api1_NoInts
Expand Down Expand Up @@ -847,7 +848,8 @@ medUse32Bit8:

medUse16Bit8:
mov ax,ss:[ebp+ebx]
and ax,NOT (EFLAG_IF or EFLAG_TF) ;clear Trap and INT flag.
;clear IF & TF (Trap and INT).
and ax,NOT (EFLAG_IF or EFLAG_TF)
mov es:RealRegsStruc.Real_Flags[edi],ax ; explicitly set flags on DPMI 300h call

assume ds:_apiCode
Expand Down Expand Up @@ -886,8 +888,10 @@ api15_Use32Bit8:
mov ebx,Int_Flags32
api15_Use16Bit8:
mov ax,ss:[ebp+ebx]
and ax,EFLAG_IF or EFLAG_DF ;retain IF & DF.
and es:RealRegsStruc.Real_Flags[edi],NOT (EFLAG_IF or EFLAG_DF) ;lose IF & DF.
;retain IF & DF.
and ax,EFLAG_IF or EFLAG_DF
;clear IF & DF.
and es:RealRegsStruc.Real_Flags[edi],NOT (EFLAG_IF or EFLAG_DF)
or es:RealRegsStruc.Real_Flags[edi],ax
ret
cwAPI_IntXX endp
Expand Down Expand Up @@ -961,8 +965,10 @@ api16_Use32Bit8:
mov ebx,Int_Flags32
api16_Use16Bit8:
mov ax,ss:[ebp+ebx]
and ax,EFLAG_IF or EFLAG_DF ;retain IF & DF.
and es:RealRegsStruc.Real_Flags[edi],NOT (EFLAG_IF or EFLAG_DF) ;lose IF & DF.
;retain IF & DF.
and ax,EFLAG_IF or EFLAG_DF
;clear IF & DF.
and es:RealRegsStruc.Real_Flags[edi],NOT (EFLAG_IF or EFLAG_DF)
or es:RealRegsStruc.Real_Flags[edi],ax
ret
cwAPI_FarCallReal endp
Expand Down
8 changes: 5 additions & 3 deletions bld/causeway/asm/cw32.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2164,8 +2164,10 @@ nosse:
push edx ;ESP
pushfd ;EFlags
pop eax
and ax,NOT (EFLAG_NT or EFLAG_IOPL) ;clear NT & IOPL.
or ax,EFLAG_IOPL ;force IOPL 3.
;clear NT & IOPL.
and ax,NOT (EFLAG_NT or EFLAG_IOPL)
;force IOPL 3.
or ax,EFLAG_IOPL
push eax
popfd
push eax
Expand Down Expand Up @@ -5108,7 +5110,7 @@ MakeDesc endp
;
;On Entry:-
;
;ES:DI - Descriptor entry to use.
;ES:EDI - Descriptor entry to use.
;ESI - Linear base to set.
;ECX - limit in bytes.
;AL - Code size bit.
Expand Down
5 changes: 3 additions & 2 deletions bld/causeway/asm/int21h.asm
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ Int21h proc near
mov esi,Int_Flags16
int211_32Bit0:
add esi,ebp
and BYTE PTR ss:[esi],not EFLAG_CF
;clear CF (carry)
and BYTE PTR ss:[esi],NOT EFLAG_CF
cld ;Default direction.
test WORD PTR ss:[esi],EFLAG_IF ;Were interrupts enabled?
jz int211_NoInts
Expand Down Expand Up @@ -1109,7 +1110,7 @@ int2121_Ef15:
;
pop ax
int2121_Ef13:
and ax,EFLAG_CF
and al,EFLAG_CF
call Int21hAL2Carry
ret
Int21hExecFile endp
Expand Down
31 changes: 21 additions & 10 deletions bld/causeway/asm/interrup.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,8 @@ inter15_Int:
push ax
xor eax,eax
mov ax,[ebx+(4+4+4+4+4)+IFrame16.i16_flags] ;get flags again.
and ax,NOT (EFLAG_IF or EFLAG_TF) ;lose IF & TF
;clear IF & TF
and ax,NOT (EFLAG_IF or EFLAG_TF)
push eax ;int handler flags.
jmp inter15_i2Use0
;
Expand All @@ -1094,7 +1095,8 @@ inter15_i2Use32:
mov eax,[ebx+(4+4+4+4+4)+IFrame.i_eip] ;get IP
push eax
mov eax,[ebx+(4+4+4+4+4)+IFrame.i_eflags] ;get flags again.
and ax,NOT (EFLAG_IF or EFLAG_TF) ;lose IF & TF
;clear IF & TF
and ax,NOT (EFLAG_IF or EFLAG_TF)
push eax ;int handler flags.
;
inter15_i2Use0:
Expand Down Expand Up @@ -1230,6 +1232,7 @@ IntDispatch proc near
push ds
mov ax,DpmiEmuDS
mov ds,ax
;clear IF & TF.
and w[ExceptionFlags],NOT (EFLAG_IF or EFLAG_TF)
mov esi,ExceptionIndex ;Get the exception number.
add esi,esi ;*2
Expand Down Expand Up @@ -1302,8 +1305,10 @@ inter17_Resume:
;
movzx ebx,bx
lss sp,d[ebx+(4+4+4+4)+IFrame16.i16_sp] ;get old stack address.
and w[ebx+(4+4+4+4)+IFrame16.i16_flags],EFLAG_IF or EFLAG_TF or EFLAG_DF ;retain IF & TF & DF.
and w[ebx+(4+4+4)],NOT (EFLAG_IF or EFLAG_TF or EFLAG_DF) ;lose IF & TF & DF.
;retain IF & TF & DF.
and w[ebx+(4+4+4+4)+IFrame16.i16_flags],EFLAG_IF or EFLAG_TF or EFLAG_DF
;clear IF & TF & DF.
and w[ebx+(4+4+4)],NOT (EFLAG_IF or EFLAG_TF or EFLAG_DF)
mov ax,[ebx+(4+4+4)]
or ax,[ebx+(4+4+4+4)+IFrame16.i16_flags]
push ax ;EFlags.
Expand All @@ -1330,8 +1335,10 @@ inter17_Resume:
;
inter17_Use32:
lss esp,f[ebx+(4+4+4+4)+IFrame.i_esp] ;get old stack address.
and w[ebx+(4+4+4+4)+IFrame.i_eflags],EFLAG_IF or EFLAG_TF or EFLAG_DF ;retain IF & TF & DF.
and w[ebx+(4+4+4)],NOT (EFLAG_IF or EFLAG_TF or EFLAG_DF) ;lose IF & TF & DF.
;retain IF & TF & DF.
and w[ebx+(4+4+4+4)+IFrame.i_eflags],EFLAG_IF or EFLAG_TF or EFLAG_DF
;clear IF & TF & DF.
and w[ebx+(4+4+4)],NOT (EFLAG_IF or EFLAG_TF or EFLAG_DF)
mov eax,[ebx+(4+4+4)]
or eax,[ebx+(4+4+4+4)+IFrame.i_eflags]
push eax ;EFlags.
Expand Down Expand Up @@ -1542,7 +1549,8 @@ inter18_c2:
;Now pass control to the INT simulator.
;
mov eax,[ebp+(4+4+4+4+4+4+4+4)+(10*2)+(4+4+4+4)]
and eax,0ffffh and NOT (EFLAG_IF or EFLAG_TF or EFLAG_DF)
;clear IF & TF & DF.
and ax,NOT (EFLAG_IF or EFLAG_TF or EFLAG_DF)
push eax
popfd
mov ebx,edx
Expand All @@ -1565,12 +1573,14 @@ inter18_NoCall:
;Update the flags.
;
mov ax,es:RealRegsStruc.Real_Flags[edi]
and ax,NOT (EFLAG_NT or EFLAG_IOPL or EFLAG_IF or EFLAG_TF or EFLAG_DF) ;lose IF & TF & DF & NT & IOPL.
;clear IF & TF & DF & NT & IOPL.
and ax,NOT (EFLAG_NT or EFLAG_IOPL or EFLAG_IF or EFLAG_TF or EFLAG_DF)
;
test BYTE PTR DpmiEmuSystemFlags,1
jz inter18_Use32Bit
mov bx,[ebp+(4+4+4+4+4+4+4+4)+(10*2)+(4+4+4+4)+(4+4+4)+IFrame16.i16_flags]
and bx,EFLAG_NT or EFLAG_IOPL or EFLAG_IF or EFLAG_TF or EFLAG_DF ;retain IF & TF & DF & NT & IOPL.
;retain IF & TF & DF & NT & IOPL.
and bx,EFLAG_NT or EFLAG_IOPL or EFLAG_IF or EFLAG_TF or EFLAG_DF
or ax,bx
mov [ebp+(4+4+4+4+4+4+4+4)+(10*2)+(4+4+4+4)+(4+4+4)+IFrame16.i16_flags],ax
popad
Expand All @@ -1585,7 +1595,8 @@ inter18_NoCall:
;
inter18_Use32Bit:
mov bx,[ebp+(4+4+4+4+4+4+4+4)+(10*2)+(4+4+4+4)+(4+4+4)+IFrame.i_eflags]
and bx,EFLAG_NT or EFLAG_IOPL or EFLAG_IF or EFLAG_TF or EFLAG_DF ;retain IF & TF & DF & NT & IOPL.
;retain IF & TF & DF & NT & IOPL.
and bx,EFLAG_NT or EFLAG_IOPL or EFLAG_IF or EFLAG_TF or EFLAG_DF
or ax,bx
mov [ebp+(4+4+4+4+4+4+4+4)+(10*2)+(4+4+4+4)+(4+4+4)+IFrame.i_eflags],ax
popad
Expand Down
12 changes: 6 additions & 6 deletions bld/causeway/asm/ldt.asm
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ RawSetSelType proc near
mov ax,KernalZero ;make LDT addresable.
mov es,ax
movzx esi,bx ;Get the selector.
GetDescIndex esi ;lose RPL & TI.
ClearDescTIRPL esi ;lose RPL & TI.
add esi,MDTLinear ;offset into descriptor table.
mov BYTE PTR es:[esi+5],cl
and ch,11110000b
Expand Down Expand Up @@ -337,7 +337,7 @@ RawSetSelLimit proc near
mov ax,KernalZero ;make LDT addresable.
mov es,ax
movzx esi,bx ;Get the selector.
GetDescIndex esi ;lose RPL & TI.
ClearDescTIRPL esi ;lose RPL & TI.
add esi,MDTLinear ;offset into descriptor table.
shl ecx,16 ;cx:dx -> ecx
mov cx,dx ;/
Expand Down Expand Up @@ -384,7 +384,7 @@ RawSetSelBase proc near
mov ax,KernalZero ;make LDT addressable.
mov es,ax
movzx esi,bx ;Get the selector.
GetDescIndex esi ;lose RPL & TI.
ClearDescTIRPL esi ;lose RPL & TI.
add esi,MDTLinear ;offset into descriptor table.
mov es:[esi+4],cl ;base mid.
mov es:[esi+7],ch ;base high.
Expand Down Expand Up @@ -423,7 +423,7 @@ RawGetSelBase proc near
mov ax,KernalZero ;make LDT addresable.
mov es,ax
movzx esi,bx ;Get the selector.
GetDescIndex esi ;lose RPL & TI.
ClearDescTIRPL esi ;lose RPL & TI.
add esi,MDTLinear ;offset into descriptor table.
mov cl,es:[esi+4] ;base mid.
mov ch,es:[esi+7] ;base high.
Expand Down Expand Up @@ -459,7 +459,7 @@ RawBPutDescriptor proc near
mov ds,ax
assume ds:_cwRaw
movzx esi,bx ;Get the selector.
GetDescIndex esi ;lose RPL & TI.
ClearDescTIRPL esi ;lose RPL & TI.
add esi,MDTLinear ;offset into descriptor table.
test BYTE PTR RawSystemFlags,1
jz ldt8_Use32
Expand Down Expand Up @@ -511,7 +511,7 @@ RawBGetDescriptor proc near
mov ds,ax
assume ds:_cwRaw
movzx esi,bx ;Get the selector.
GetDescIndex esi ;lose RPL & TI.
ClearDescTIRPL esi ;lose RPL & TI.
add esi,MDTLinear ;offset into descriptor table.
test BYTE PTR RawSystemFlags,1
jz ldt9_Use32
Expand Down
Loading

0 comments on commit bc9d850

Please sign in to comment.