Skip to content

Commit

Permalink
causeway: use new macros to optimize code
Browse files Browse the repository at this point in the history
do code more transparent
  • Loading branch information
jmalak committed Jan 23, 2025
1 parent 07c6f54 commit 65cc5f6
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 60 deletions.
4 changes: 2 additions & 2 deletions bld/causeway/asm/api.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,7 @@ _SetSelector proc near
jc api61_ok
cmp ebx,-1
jz api61_ok
RoundUP ebx,4096
RoundPageUP ebx
dec ebx
;
api61_ok:
Expand Down Expand Up @@ -3248,7 +3248,7 @@ cwAPI_GetMCBSize endp
;
cwAPI_SetMCBSize proc near
mov ecx,[ebp+Int_ECX]
RoundUP ecx,4096
RoundPageUP ecx
cmp ecx,65536+1
jc api68_1
stc
Expand Down
10 changes: 5 additions & 5 deletions bld/causeway/asm/cw32.asm
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ InitBits macro r,v
endif
endm

ClearRPLandTI macro r
GetDescIndex macro r
_and_not_7 r ;clear RPL & TI bits
endm

Expand Down Expand Up @@ -1319,7 +1319,7 @@ cw5_A20OFF:
movzx eax,ax
shl eax,4 ;linear address.
mov ebx,eax
RoundUP eax,4096 ;round up to next page.
RoundPageUP eax ;round up to next page.
sub eax,ebx
shr eax,4
mov bx,ax
Expand Down Expand Up @@ -1348,7 +1348,7 @@ cw5_OldWay:
movzx eax,ax ;get segment address.
shl eax,4 ;make linear.
mov ebx,eax
RoundUP eax,4096 ;round up to nearest page.
RoundPageUP eax ;round up to nearest page.
mov ecx,eax
sub ecx,ebx
shr ecx,4
Expand Down Expand Up @@ -5006,7 +5006,7 @@ MakeDesc proc near
;
.386
pushad
and di,not 7 ;lose RPL & TI
GetDescIndex di ;lose RPL & TI
cmp ecx,0100000h ; see if we need to set g bit
jc cw18_0
shr ecx,12 ; div by 4096
Expand Down Expand Up @@ -5041,7 +5041,7 @@ MakeDesc endp
MakeDesc2 proc near
.386
pushad
and edi,not 7 ;lose RPL & TI
GetDescIndex edi ;lose RPL & TI
cmp ecx,0100000h ; see if we need to set g bit
jc cw19_0
shr ecx,12 ; div by 4096
Expand Down
4 changes: 2 additions & 2 deletions bld/causeway/asm/exceptn.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ exc22_mcbmc1:
;Update Total memory value and skip this block.
;
mov eax,es:[esi+8]
RoundUP eax,4096
RoundPageUP eax
add TotalLinearMem+4,eax
pop edi
jmp exc22_m1
Expand All @@ -2144,7 +2144,7 @@ exc22_MEM:
mov eax,es:[esi+8]
add TotalLinearMem,eax
push eax
RoundUP eax,4096
RoundPageUP eax
add TotalLinearMem+4,eax
pop eax
inc TotalLinearMem+8
Expand Down
39 changes: 20 additions & 19 deletions bld/causeway/asm/ldt.asm
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,27 @@ RawRelDescriptor proc near
push eax
push ebx
push ecx
and ebx,0ffffh AND (NOT 7) ;lose RPL & TI
movzx ebx,bx
GetDescIndex ebx ;lose RPL & TI
xor ecx,ecx
xor eax,eax
mov ax,ds
and eax,not 7 ;lose RPL & TI
GetDescIndex eax ;lose RPL & TI
cmp eax,ebx
jnz ldt2_0
mov ds,cx
ldt2_0: mov ax,es
and eax,not 7 ;lose RPL & TI
GetDescIndex eax ;lose RPL & TI
cmp eax,ebx
jnz ldt2_1
mov es,cx
ldt2_1: mov ax,fs
and eax,not 7 ;lose RPL & TI
GetDescIndex eax ;lose RPL & TI
cmp eax,ebx
jnz ldt2_2
mov fs,cx
ldt2_2: mov ax,gs
and eax,not 7 ;lose RPL & TI
GetDescIndex eax ;lose RPL & TI
cmp eax,ebx
jnz ldt2_3
mov gs,cx
Expand All @@ -158,7 +159,7 @@ ldt2_3:
add esi,MDTLinear+4
mov BYTE PTR es:[esi],0 ;mark this entry as free.
movzx esi,bx
and esi,not 7
GetDescIndex esi
add esi,MDTLinear
xor eax,eax
mov DWORD PTR es:[esi],eax
Expand Down Expand Up @@ -291,13 +292,13 @@ RawSetSelType proc near
push esi
push ds
push es
mov ax,KernalDS ;make our data addresable.
mov ax,KernalDS ;make our data addresable.
mov ds,ax
assume ds:_cwRaw
mov ax,KernalZero ;make LDT addresable.
mov es,ax
movzx esi,bx ;Get the selector.
and si,0fff8h ;lose RPL & TI.
GetDescIndex 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 @@ -336,7 +337,7 @@ RawSetSelLimit proc near
mov ax,KernalZero ;make LDT addresable.
mov es,ax
movzx esi,bx ;Get the selector.
and si,NOT 7 ;lose RPL & TI.
GetDescIndex esi ;lose RPL & TI.
add esi,MDTLinear ;offset into descriptor table.
shl ecx,16
mov cx,dx
Expand Down Expand Up @@ -383,7 +384,7 @@ RawSetSelBase proc near
mov ax,KernalZero ;make LDT addressable.
mov es,ax
movzx esi,bx ;Get the selector.
and si,NOT 7 ;lose RPL & TI.
GetDescIndex 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 @@ -416,17 +417,17 @@ RawGetSelBase proc near
push esi
push ds
push es
mov ax,KernalDS ;make our data addresable.
mov ax,KernalDS ;make our data addresable.
mov ds,ax
assume ds:_cwRaw
mov ax,KernalZero ;make LDT addresable.
mov es,ax
movzx esi,bx ;Get the selector.
and si,0fff8h ;lose RPL & TI.
GetDescIndex 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.
mov dx,es:[esi+2] ;base low.
mov cl,es:[esi+4] ;base mid.
mov ch,es:[esi+7] ;base high.
mov dx,es:[esi+2] ;base low.
clc
pop es
pop ds
Expand Down Expand Up @@ -454,11 +455,11 @@ RawBPutDescriptor proc near
push edi
push ds
push es
mov ax,KernalDS ;make our data addresable.
mov ax,KernalDS ;make our data addresable.
mov ds,ax
assume ds:_cwRaw
movzx esi,bx ;Get the selector.
and si,0fff8h ;lose RPL & TI.
GetDescIndex esi ;lose RPL & TI.
add esi,MDTLinear ;offset into descriptor table.
test BYTE PTR RawSystemFlags,1
jz ldt8_Use32
Expand Down Expand Up @@ -506,11 +507,11 @@ RawBGetDescriptor proc near
push esi
push edi
push ds
mov ax,KernalDS ;make our data addresable.
mov ax,KernalDS ;make our data addresable.
mov ds,ax
assume ds:_cwRaw
movzx esi,bx ;Get the selector.
and si,0fff8h ;lose RPL & TI.
GetDescIndex esi ;lose RPL & TI.
add esi,MDTLinear ;offset into descriptor table.
test BYTE PTR RawSystemFlags,1
jz ldt9_Use32
Expand Down
2 changes: 1 addition & 1 deletion bld/causeway/asm/loadle.asm
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ load1_NoExports:
xor ebp,ebp ;clear memory requirement.
load1_objup0:
mov eax,es:LE_OBJ.LE_OBJ_Size[esi]
RoundUP eax,4096 ;page align objects
RoundPageUP eax ;page align objects
mov es:LE_OBJ.LE_OBJ_Size[esi],eax
add ebp,eax ;update program memory length.
add esi,size LE_OBJ
Expand Down
30 changes: 15 additions & 15 deletions bld/causeway/asm/memory.asm
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ RawDiscardPages proc near
;Round start up a page.
;
mov eax,ebx
RoundUP ebx,4096
RoundPageUP ebx
sub eax,ebx
neg eax
cmp eax,esi
Expand All @@ -671,7 +671,7 @@ RawDiscardPages proc near
;
;Round length down a page.
;
RoundDN esi,4096
RoundPageDN esi
or esi,esi
jz mem4_8
;
Expand Down Expand Up @@ -940,9 +940,9 @@ RawLockMemory proc near
shl esi,16
mov si,di
add esi,ebx
RoundDN ebx,4096 ;round down to nearest page.
RoundPageDN ebx ;round down to nearest page.
mov d[_LM_BlockBase],ebx
RoundUP esi,4096 ;round up to next page.
RoundPageUP esi ;round up to next page.
dec esi
mov d[_LM_BlockEnd],esi ;store address of last page.
;
Expand Down Expand Up @@ -1120,9 +1120,9 @@ RawUnLockMemory proc near
shl esi,16
mov si,di
add esi,ebx
RoundDN ebx,4096 ;round down to nearest page.
RoundPageDN ebx ;round down to nearest page.
mov d[_LM_BlockBase],ebx
RoundUP esi,4096 ;round up to next page.
RoundPageUP esi ;round up to next page.
dec esi
mov d[_LM_BlockEnd],esi ;store address of last page.
;
Expand Down Expand Up @@ -2467,6 +2467,7 @@ RawGetDOSMemory proc near
mov ds,ax
assume ds:_cwRaw
;
movzx ebx,bx
cmp bx,-1 ;maximum?
jz mem19_0
inc ebx ;para extra for us.
Expand Down Expand Up @@ -2530,7 +2531,7 @@ mem19_2:
push ecx
push eax
mov edi,offset RawSelBuffer
RoundUP edi,8
Round8UP edi
movzx esi,bx
shl esi,4
movzx ecx,cx
Expand Down Expand Up @@ -2713,8 +2714,7 @@ mem20_2:
push ecx
push eax
mov edi,offset RawSelBuffer
add edi,7
and edi,0fffffff8h
Round8UP edi
movzx esi,bx
shl esi,4
movzx ecx,cx
Expand Down Expand Up @@ -2769,30 +2769,30 @@ RawRelDOSMemory proc near
push eax
push ebx
push ecx
mov ebx,edx
and ebx,0ffffh AND (NOT 7) ;lose RPL & TI
movzx ebx,dx
GetDescIndex ebx ;lose RPL & TI
xor ecx,ecx
xor eax,eax
mov ax,ds
and eax,not 7 ;lose RPL & TI
GetDescIndex eax ;lose RPL & TI
cmp eax,ebx
jnz mem21_z0
mov ds,cx
mem21_z0:
mov ax,es
and eax,not 7 ;lose RPL & TI
GetDescIndex eax ;lose RPL & TI
cmp eax,ebx
jnz mem21_z1
mov es,cx
mem21_z1:
mov ax,fs
and eax,not 7 ;lose RPL & TI
GetDescIndex eax ;lose RPL & TI
cmp eax,ebx
jnz mem21_z2
mov fs,cx
mem21_z2:
mov ax,gs
and eax,not 7 ;lose RPL & TI
GetDescIndex eax ;lose RPL & TI
cmp eax,ebx
jnz mem21_z3
mov gs,cx
Expand Down
Loading

0 comments on commit 65cc5f6

Please sign in to comment.