[105] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Register related macros.
|
---|
| 3 | %ifndef REGISTERS_INC
|
---|
| 4 | %define REGISTERS_INC
|
---|
| 5 |
|
---|
[146] | 6 | struc INTPACK
|
---|
| 7 | %ifdef USE_386
|
---|
[322] | 8 | ; .gs resb 2
|
---|
| 9 | ; .fs resb 2
|
---|
[146] | 10 | %endif
|
---|
| 11 | .es resb 2
|
---|
| 12 | .ds resb 2
|
---|
| 13 | .di resb 2
|
---|
| 14 | .si resb 2
|
---|
| 15 | .bp resb 2
|
---|
| 16 | .sp resb 2
|
---|
| 17 | .bx:
|
---|
| 18 | .bl resb 1
|
---|
| 19 | .bh resb 1
|
---|
| 20 | .dx:
|
---|
| 21 | .dl resb 1
|
---|
| 22 | .dh resb 1
|
---|
| 23 | .cx:
|
---|
| 24 | .cl resb 1
|
---|
| 25 | .ch resb 1
|
---|
| 26 | .ax:
|
---|
| 27 | .al resb 1
|
---|
| 28 | .ah resb 1
|
---|
| 29 | .ip resb 2
|
---|
| 30 | .cs resb 2
|
---|
| 31 | .flags resb 2
|
---|
| 32 | endstruc
|
---|
| 33 |
|
---|
| 34 | ; 8086/8088 FLAGS
|
---|
| 35 | FLG_FLAGS_CF EQU (1<<0)
|
---|
| 36 | FLG_FLAGS_PF EQU (1<<2)
|
---|
| 37 | FLG_FLAGS_AF EQU (1<<4)
|
---|
| 38 | FLG_FLAGS_ZF EQU (1<<6)
|
---|
| 39 | FLG_FLAGS_SF EQU (1<<7)
|
---|
| 40 | FLG_FLAGS_TF EQU (1<<8)
|
---|
| 41 | FLG_FLAGS_IF EQU (1<<9)
|
---|
| 42 | FLG_FLAGS_DF EQU (1<<10)
|
---|
| 43 | FLG_FLAGS_OF EQU (1<<11)
|
---|
| 44 |
|
---|
| 45 |
|
---|
[105] | 46 | ;--------------------------------------------------------------------
|
---|
[146] | 47 | ; This macro must be the first thing to call on Interrupt Service Routine.
|
---|
| 48 | ;
|
---|
[154] | 49 | ; CREATE_INTPACK_TO_SSBP
|
---|
[146] | 50 | ; Parameters
|
---|
| 51 | ; Nothing
|
---|
| 52 | ; Returns:
|
---|
| 53 | ; SS:BP: Points to INTPACK
|
---|
| 54 | ; Corrupts registers:
|
---|
| 55 | ; Nothing
|
---|
| 56 | ;--------------------------------------------------------------------
|
---|
[154] | 57 | %macro CREATE_INTPACK_TO_SSBP 0
|
---|
[146] | 58 | ePUSHA
|
---|
| 59 | push ds
|
---|
| 60 | push es
|
---|
| 61 | %ifdef USE_386
|
---|
[322] | 62 | ; push fs
|
---|
| 63 | ; push gs
|
---|
[146] | 64 | %endif
|
---|
| 65 | mov bp, sp
|
---|
| 66 | %endmacro
|
---|
| 67 |
|
---|
| 68 | ;--------------------------------------------------------------------
|
---|
| 69 | ; This macro must be the last thing to call on Interrupt Service Routine.
|
---|
| 70 | ;
|
---|
| 71 | ; RESTORE_INTPACK_FROM_SSBP
|
---|
| 72 | ; Parameters
|
---|
| 73 | ; SS:BP: Ptr to INTPACK
|
---|
| 74 | ; Returns:
|
---|
| 75 | ; All Registers will be loaded from INTPACK
|
---|
| 76 | ;--------------------------------------------------------------------
|
---|
| 77 | %macro RESTORE_INTPACK_FROM_SSBP 0
|
---|
| 78 | %ifdef USE_386
|
---|
[322] | 79 | ; pop gs
|
---|
| 80 | ; pop fs
|
---|
[146] | 81 | %endif
|
---|
| 82 | pop es
|
---|
| 83 | pop ds
|
---|
| 84 | ePOPA
|
---|
| 85 | iret
|
---|
| 86 | %endmacro
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | ;--------------------------------------------------------------------
|
---|
[149] | 90 | ; This macro must be the first thing to call on Interrupt Service Routine.
|
---|
| 91 | ;
|
---|
[154] | 92 | ; CREATE_FRAME_INTPACK_TO_SSBP
|
---|
[149] | 93 | ; Parameters
|
---|
[154] | 94 | ; %1: Number of extra bytes to reserve before INTPACK
|
---|
[149] | 95 | ; Returns:
|
---|
| 96 | ; SS:BP: Points to INTPACK
|
---|
| 97 | ; Corrupts registers:
|
---|
| 98 | ; Nothing
|
---|
| 99 | ;--------------------------------------------------------------------
|
---|
[154] | 100 | %macro CREATE_FRAME_INTPACK_TO_SSBP 1
|
---|
[149] | 101 | ePUSHA
|
---|
| 102 | push ds
|
---|
| 103 | push es
|
---|
| 104 | %ifdef USE_386
|
---|
[322] | 105 | ; push fs
|
---|
| 106 | ; push gs
|
---|
[149] | 107 | %endif
|
---|
[154] | 108 | sub sp, BYTE %1
|
---|
[149] | 109 | mov bp, sp
|
---|
| 110 | %endmacro
|
---|
| 111 |
|
---|
| 112 | ;--------------------------------------------------------------------
|
---|
| 113 | ; This macro must be the last thing to call on Interrupt Service Routine.
|
---|
| 114 | ;
|
---|
[154] | 115 | ; RESTORE_FRAME_INTPACK_FROM_SSBP
|
---|
[149] | 116 | ; Parameters
|
---|
[154] | 117 | ; %1: Number of extra bytes in INTPACK
|
---|
[149] | 118 | ; SS:BP: Ptr to INTPACK
|
---|
| 119 | ; Returns:
|
---|
| 120 | ; All Registers will be loaded from INTPACK
|
---|
| 121 | ;--------------------------------------------------------------------
|
---|
[154] | 122 | %macro RESTORE_FRAME_INTPACK_FROM_SSBP 1
|
---|
| 123 | add sp, BYTE %1
|
---|
[149] | 124 | %ifdef USE_386
|
---|
[322] | 125 | ; pop gs
|
---|
| 126 | ; pop fs
|
---|
[149] | 127 | %endif
|
---|
| 128 | pop es
|
---|
| 129 | pop ds
|
---|
| 130 | ePOPA
|
---|
| 131 | iret
|
---|
| 132 | %endmacro
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | ;--------------------------------------------------------------------
|
---|
[105] | 136 | ; NORMALIZE_FAR_POINTER
|
---|
| 137 | ; Parameters:
|
---|
| 138 | ; %1:%2: Far pointer to normalize
|
---|
| 139 | ; %3: Scratch register
|
---|
| 140 | ; %4: Scratch register
|
---|
| 141 | ; Returns:
|
---|
| 142 | ; %1:%2: Normalized far pointer
|
---|
| 143 | ; Corrupts registers:
|
---|
| 144 | ; %3, %4
|
---|
| 145 | ;--------------------------------------------------------------------
|
---|
| 146 | %macro NORMALIZE_FAR_POINTER 4
|
---|
| 147 | mov %4, %2 ; Copy offset to scratch reg
|
---|
| 148 | and %2, BYTE 0Fh ; Clear offset bits 15...4
|
---|
| 149 | eSHR_IM %4, 4 ; Divide offset by 16
|
---|
| 150 | mov %3, %1 ; Copy segment to scratch reg
|
---|
| 151 | add %3, %4 ; Add shifted offset to segment
|
---|
| 152 | mov %1, %3 ; Set normalized segment
|
---|
| 153 | %endmacro
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | ;--------------------------------------------------------------------
|
---|
| 157 | ; COPY_SSBP_TO_ESDI
|
---|
| 158 | ; COPY_SSBP_TO_DSSI
|
---|
| 159 | ; COPY_DSSI_TO_ESDI
|
---|
| 160 | ; COPY_ESDI_to_DSSI
|
---|
| 161 | ; Parameters
|
---|
| 162 | ; Nothing
|
---|
| 163 | ; Returns:
|
---|
| 164 | ; Copies farm pointer to different segment/pointer register pair
|
---|
| 165 | ; Corrupts registers:
|
---|
| 166 | ; Nothing
|
---|
| 167 | ;--------------------------------------------------------------------
|
---|
| 168 | %macro COPY_SSBP_TO_ESDI 0
|
---|
| 169 | push ss
|
---|
| 170 | pop es
|
---|
| 171 | mov di, bp
|
---|
| 172 | %endmacro
|
---|
| 173 |
|
---|
| 174 | %macro COPY_SSBP_TO_DSSI 0
|
---|
| 175 | push ss
|
---|
| 176 | pop ds
|
---|
| 177 | mov si, bp
|
---|
| 178 | %endmacro
|
---|
| 179 |
|
---|
| 180 | %macro COPY_DSSI_TO_ESDI 0
|
---|
| 181 | push ds
|
---|
| 182 | pop es
|
---|
| 183 | mov di, si
|
---|
| 184 | %endmacro
|
---|
| 185 |
|
---|
| 186 | %macro COPY_ESDI_to_DSSI 0
|
---|
| 187 | push es
|
---|
| 188 | pop ds
|
---|
| 189 | mov si, di
|
---|
| 190 | %endmacro
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | %endif ; REGISTERS_INC
|
---|