source: xtideuniversalbios/trunk/Assembly_Library/Inc/Registers.inc @ 149

Last change on this file since 149 was 149, checked in by aitotat, 13 years ago

Changes to Assembly Library:

  • Added pointer normalization functions
File size: 4.3 KB
Line 
1; Project name  :   Assembly Library
2; Description   :   Register related macros.
3%ifndef REGISTERS_INC
4%define REGISTERS_INC
5
6struc INTPACK
7%ifdef USE_386
8    .gs             resb    2
9    .fs             resb    2
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
32endstruc
33
34; 8086/8088 FLAGS
35FLG_FLAGS_CF        EQU (1<<0)
36FLG_FLAGS_PF        EQU (1<<2)
37FLG_FLAGS_AF        EQU (1<<4)
38FLG_FLAGS_ZF        EQU (1<<6)
39FLG_FLAGS_SF        EQU (1<<7)
40FLG_FLAGS_TF        EQU (1<<8)
41FLG_FLAGS_IF        EQU (1<<9)
42FLG_FLAGS_DF        EQU (1<<10)
43FLG_FLAGS_OF        EQU (1<<11)
44
45
46;--------------------------------------------------------------------
47; This macro must be the first thing to call on Interrupt Service Routine.
48;
49; SAVE_AND_GET_INTPACK_TO_SSBP
50;   Parameters
51;       Nothing
52;   Returns:
53;       SS:BP:  Points to INTPACK
54;   Corrupts registers:
55;       Nothing
56;--------------------------------------------------------------------
57%macro SAVE_AND_GET_INTPACK_TO_SSBP 0
58    ePUSHA
59    push    ds
60    push    es
61%ifdef USE_386
62    push    fs
63    push    gs
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
79    pop     gs
80    pop     fs
81%endif
82    pop     es
83    pop     ds
84    ePOPA
85    iret
86%endmacro
87
88
89;--------------------------------------------------------------------
90; This macro must be the first thing to call on Interrupt Service Routine.
91; Extra words will be initialized to zero.
92;
93; SAVE_AND_GET_INTPACK_WITH_EXTRA_WORDS_TO_SSBP
94;   Parameters
95;       %1:     Number of extra words to reserve before INTPACK
96;   Returns:
97;       SS:BP:  Points to INTPACK
98;   Corrupts registers:
99;       Nothing
100;--------------------------------------------------------------------
101%macro SAVE_AND_GET_INTPACK_WITH_EXTRA_WORDS_TO_SSBP 1
102    ePUSHA
103    push    ds
104    push    es
105%ifdef USE_386
106    push    fs
107    push    gs
108%endif
109    xor     bp, bp
110    times %1 push bp        ; Initialize to zero
111    mov     bp, sp
112%endmacro
113
114;--------------------------------------------------------------------
115; This macro must be the last thing to call on Interrupt Service Routine.
116;
117; RESTORE_INTPACK_WITH_EXTRA_WORDS_FROM_SSBP
118;   Parameters
119;       %1:     Number of extra words in INTPACK
120;       SS:BP:  Ptr to INTPACK
121;   Returns:
122;       All Registers will be loaded from INTPACK
123;--------------------------------------------------------------------
124%macro RESTORE_INTPACK_WITH_EXTRA_WORDS_FROM_SSBP 1
125    add     sp, BYTE (%1)*2
126%ifdef USE_386
127    pop     gs
128    pop     fs
129%endif
130    pop     es
131    pop     ds
132    ePOPA
133    iret
134%endmacro
135
136
137;--------------------------------------------------------------------
138; NORMALIZE_FAR_POINTER
139;   Parameters:
140;       %1:%2:      Far pointer to normalize
141;       %3:         Scratch register
142;       %4:         Scratch register
143;   Returns:
144;       %1:%2:      Normalized far pointer
145;   Corrupts registers:
146;       %3, %4
147;--------------------------------------------------------------------
148%macro NORMALIZE_FAR_POINTER 4
149    mov     %4, %2              ; Copy offset to scratch reg
150    and     %2, BYTE 0Fh        ; Clear offset bits 15...4
151    eSHR_IM %4, 4               ; Divide offset by 16
152    mov     %3, %1              ; Copy segment to scratch reg
153    add     %3, %4              ; Add shifted offset to segment
154    mov     %1, %3              ; Set normalized segment
155%endmacro
156
157
158;--------------------------------------------------------------------
159; COPY_SSBP_TO_ESDI
160; COPY_SSBP_TO_DSSI
161; COPY_DSSI_TO_ESDI
162; COPY_ESDI_to_DSSI
163;   Parameters
164;       Nothing
165;   Returns:
166;       Copies farm pointer to different segment/pointer register pair
167;   Corrupts registers:
168;       Nothing
169;--------------------------------------------------------------------
170%macro COPY_SSBP_TO_ESDI 0
171    push    ss
172    pop     es
173    mov     di, bp
174%endmacro
175
176%macro COPY_SSBP_TO_DSSI 0
177    push    ss
178    pop     ds
179    mov     si, bp
180%endmacro
181
182%macro COPY_DSSI_TO_ESDI 0
183    push    ds
184    pop     es
185    mov     di, si
186%endmacro
187
188%macro COPY_ESDI_to_DSSI 0
189    push    es
190    pop     ds
191    mov     si, di
192%endmacro
193
194
195
196%endif ; REGISTERS_INC
Note: See TracBrowser for help on using the repository browser.