d3d5ce166759f825917545a19f2f40ec90a02acd
[reactos.git] / reactos / subsystems / ntvdm / registers.c
1 /*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: registers.c
5 * PURPOSE: Exported functions for manipulating registers
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #define NDEBUG
12
13 #include "emulator.h"
14
15 /* PUBLIC FUNCTIONS ***********************************************************/
16
17 static inline BOOLEAN EmulatorGetFlag(ULONG Flag)
18 {
19 return (EmulatorContext.Flags.Long & Flag) ? TRUE : FALSE;
20 }
21
22 static inline VOID EmulatorSetFlag(ULONG Flag)
23 {
24 EmulatorContext.Flags.Long |= Flag;
25 }
26
27 static inline VOID EmulatorClearFlag(ULONG Flag)
28 {
29 EmulatorContext.Flags.Long &= ~Flag;
30 }
31
32 VOID EmulatorSetStack(WORD Segment, DWORD Offset)
33 {
34 Fast486SetStack(&EmulatorContext, Segment, Offset);
35 }
36
37
38
39 PVOID
40 WINAPI
41 getIntelRegistersPointer(VOID)
42 {
43 UNIMPLEMENTED;
44 return NULL;
45 }
46
47 ULONG
48 WINAPI
49 getEAX(VOID)
50 {
51 return EmulatorContext.GeneralRegs[FAST486_REG_EAX].Long;
52 }
53
54 VOID
55 WINAPI
56 setEAX(ULONG Value)
57 {
58 EmulatorContext.GeneralRegs[FAST486_REG_EAX].Long = Value;
59 }
60
61 USHORT
62 WINAPI
63 getAX(VOID)
64 {
65 return EmulatorContext.GeneralRegs[FAST486_REG_EAX].LowWord;
66 }
67
68 VOID
69 WINAPI
70 setAX(USHORT Value)
71 {
72 EmulatorContext.GeneralRegs[FAST486_REG_EAX].LowWord = Value;
73 }
74
75 UCHAR
76 WINAPI
77 getAH(VOID)
78 {
79 return EmulatorContext.GeneralRegs[FAST486_REG_EAX].HighByte;
80 }
81
82 VOID
83 WINAPI
84 setAH(UCHAR Value)
85 {
86 EmulatorContext.GeneralRegs[FAST486_REG_EAX].HighByte = Value;
87 }
88
89 UCHAR
90 WINAPI
91 getAL(VOID)
92 {
93 return EmulatorContext.GeneralRegs[FAST486_REG_EAX].LowByte;
94 }
95
96 VOID
97 WINAPI
98 setAL(UCHAR Value)
99 {
100 EmulatorContext.GeneralRegs[FAST486_REG_EAX].LowByte = Value;
101 }
102
103 ULONG
104 WINAPI
105 getEBX(VOID)
106 {
107 return EmulatorContext.GeneralRegs[FAST486_REG_EBX].Long;
108 }
109
110 VOID
111 WINAPI
112 setEBX(ULONG Value)
113 {
114 EmulatorContext.GeneralRegs[FAST486_REG_EBX].Long = Value;
115 }
116
117 USHORT
118 WINAPI
119 getBX(VOID)
120 {
121 return EmulatorContext.GeneralRegs[FAST486_REG_EBX].LowWord;
122 }
123
124 VOID
125 WINAPI
126 setBX(USHORT Value)
127 {
128 EmulatorContext.GeneralRegs[FAST486_REG_EBX].LowWord = Value;
129 }
130
131 UCHAR
132 WINAPI
133 getBH(VOID)
134 {
135 return EmulatorContext.GeneralRegs[FAST486_REG_EBX].HighByte;
136 }
137
138 VOID
139 WINAPI
140 setBH(UCHAR Value)
141 {
142 EmulatorContext.GeneralRegs[FAST486_REG_EBX].HighByte = Value;
143 }
144
145 UCHAR
146 WINAPI
147 getBL(VOID)
148 {
149 return EmulatorContext.GeneralRegs[FAST486_REG_EBX].LowByte;
150 }
151
152 VOID
153 WINAPI
154 setBL(UCHAR Value)
155 {
156 EmulatorContext.GeneralRegs[FAST486_REG_EBX].LowByte = Value;
157 }
158
159
160
161 ULONG
162 WINAPI
163 getECX(VOID)
164 {
165 return EmulatorContext.GeneralRegs[FAST486_REG_ECX].Long;
166 }
167
168 VOID
169 WINAPI
170 setECX(ULONG Value)
171 {
172 EmulatorContext.GeneralRegs[FAST486_REG_ECX].Long = Value;
173 }
174
175 USHORT
176 WINAPI
177 getCX(VOID)
178 {
179 return EmulatorContext.GeneralRegs[FAST486_REG_ECX].LowWord;
180 }
181
182 VOID
183 WINAPI
184 setCX(USHORT Value)
185 {
186 EmulatorContext.GeneralRegs[FAST486_REG_ECX].LowWord = Value;
187 }
188
189 UCHAR
190 WINAPI
191 getCH(VOID)
192 {
193 return EmulatorContext.GeneralRegs[FAST486_REG_ECX].HighByte;
194 }
195
196 VOID
197 WINAPI
198 setCH(UCHAR Value)
199 {
200 EmulatorContext.GeneralRegs[FAST486_REG_ECX].HighByte = Value;
201 }
202
203 UCHAR
204 WINAPI
205 getCL(VOID)
206 {
207 return EmulatorContext.GeneralRegs[FAST486_REG_ECX].LowByte;
208 }
209
210 VOID
211 WINAPI
212 setCL(UCHAR Value)
213 {
214 EmulatorContext.GeneralRegs[FAST486_REG_ECX].LowByte = Value;
215 }
216
217
218
219 ULONG
220 WINAPI
221 getEDX(VOID)
222 {
223 return EmulatorContext.GeneralRegs[FAST486_REG_EDX].Long;
224 }
225
226 VOID
227 WINAPI
228 setEDX(ULONG Value)
229 {
230 EmulatorContext.GeneralRegs[FAST486_REG_EDX].Long = Value;
231 }
232
233 USHORT
234 WINAPI
235 getDX(VOID)
236 {
237 return EmulatorContext.GeneralRegs[FAST486_REG_EDX].LowWord;
238 }
239
240 VOID
241 WINAPI
242 setDX(USHORT Value)
243 {
244 EmulatorContext.GeneralRegs[FAST486_REG_EDX].LowWord = Value;
245 }
246
247 UCHAR
248 WINAPI
249 getDH(VOID)
250 {
251 return EmulatorContext.GeneralRegs[FAST486_REG_EDX].HighByte;
252 }
253
254 VOID
255 WINAPI
256 setDH(UCHAR Value)
257 {
258 EmulatorContext.GeneralRegs[FAST486_REG_EDX].HighByte = Value;
259 }
260
261 UCHAR
262 WINAPI
263 getDL(VOID)
264 {
265 return EmulatorContext.GeneralRegs[FAST486_REG_EDX].LowByte;
266 }
267
268 VOID
269 WINAPI
270 setDL(UCHAR Value)
271 {
272 EmulatorContext.GeneralRegs[FAST486_REG_EDX].LowByte = Value;
273 }
274
275
276
277 ULONG
278 WINAPI
279 getESP(VOID)
280 {
281 return EmulatorContext.GeneralRegs[FAST486_REG_ESP].Long;
282 }
283
284 VOID
285 WINAPI
286 setESP(ULONG Value)
287 {
288 EmulatorSetStack(getSS(), Value);
289 }
290
291 USHORT
292 WINAPI
293 getSP(VOID)
294 {
295 return EmulatorContext.GeneralRegs[FAST486_REG_ESP].LowWord;
296 }
297
298 VOID
299 WINAPI
300 setSP(USHORT Value)
301 {
302 EmulatorSetStack(getSS(), Value);
303 }
304
305
306
307 ULONG
308 WINAPI
309 getEBP(VOID)
310 {
311 return EmulatorContext.GeneralRegs[FAST486_REG_EBP].Long;
312 }
313
314 VOID
315 WINAPI
316 setEBP(ULONG Value)
317 {
318 EmulatorContext.GeneralRegs[FAST486_REG_EBP].Long = Value;
319 }
320
321 USHORT
322 WINAPI
323 getBP(VOID)
324 {
325 return EmulatorContext.GeneralRegs[FAST486_REG_EBP].LowWord;
326 }
327
328 VOID
329 WINAPI
330 setBP(USHORT Value)
331 {
332 EmulatorContext.GeneralRegs[FAST486_REG_EBP].LowWord = Value;
333 }
334
335
336
337 ULONG
338 WINAPI
339 getESI(VOID)
340 {
341 return EmulatorContext.GeneralRegs[FAST486_REG_ESI].Long;
342 }
343
344 VOID
345 WINAPI
346 setESI(ULONG Value)
347 {
348 EmulatorContext.GeneralRegs[FAST486_REG_ESI].Long = Value;
349 }
350
351 USHORT
352 WINAPI
353 getSI(VOID)
354 {
355 return EmulatorContext.GeneralRegs[FAST486_REG_ESI].LowWord;
356 }
357
358 VOID
359 WINAPI
360 setSI(USHORT Value)
361 {
362 EmulatorContext.GeneralRegs[FAST486_REG_ESI].LowWord = Value;
363 }
364
365
366
367 ULONG
368 WINAPI
369 getEDI(VOID)
370 {
371 return EmulatorContext.GeneralRegs[FAST486_REG_EDI].Long;
372 }
373
374 VOID
375 WINAPI
376 setEDI(ULONG Value)
377 {
378 EmulatorContext.GeneralRegs[FAST486_REG_EDI].Long = Value;
379 }
380
381 USHORT
382 WINAPI
383 getDI(VOID)
384 {
385 return EmulatorContext.GeneralRegs[FAST486_REG_EDI].LowWord;
386 }
387
388 VOID
389 WINAPI
390 setDI(USHORT Value)
391 {
392 EmulatorContext.GeneralRegs[FAST486_REG_EDI].LowWord = Value;
393 }
394
395
396
397 ULONG
398 WINAPI
399 getEIP(VOID)
400 {
401 return EmulatorContext.InstPtr.Long;
402 }
403
404 VOID
405 WINAPI
406 setEIP(ULONG Value)
407 {
408 EmulatorExecute(getCS(), Value);
409 }
410
411 USHORT
412 WINAPI
413 getIP(VOID)
414 {
415 return EmulatorContext.InstPtr.LowWord;
416 }
417
418 VOID
419 WINAPI
420 setIP(USHORT Value)
421 {
422 EmulatorExecute(getCS(), Value);
423 }
424
425
426
427 USHORT
428 WINAPI
429 getCS(VOID)
430 {
431 return EmulatorContext.SegmentRegs[FAST486_REG_CS].Selector;
432 }
433
434 VOID
435 WINAPI
436 setCS(USHORT Value)
437 {
438 Fast486SetSegment(&EmulatorContext, FAST486_REG_CS, Value);
439 }
440
441 USHORT
442 WINAPI
443 getSS(VOID)
444 {
445 return EmulatorContext.SegmentRegs[FAST486_REG_SS].Selector;
446 }
447
448 VOID
449 WINAPI
450 setSS(USHORT Value)
451 {
452 Fast486SetSegment(&EmulatorContext, FAST486_REG_SS, Value);
453 }
454
455 USHORT
456 WINAPI
457 getDS(VOID)
458 {
459 return EmulatorContext.SegmentRegs[FAST486_REG_DS].Selector;
460 }
461
462 VOID
463 WINAPI
464 setDS(USHORT Value)
465 {
466 Fast486SetSegment(&EmulatorContext, FAST486_REG_DS, Value);
467 }
468
469 USHORT
470 WINAPI
471 getES(VOID)
472 {
473 return EmulatorContext.SegmentRegs[FAST486_REG_ES].Selector;
474 }
475
476 VOID
477 WINAPI
478 setES(USHORT Value)
479 {
480 Fast486SetSegment(&EmulatorContext, FAST486_REG_ES, Value);
481 }
482
483 USHORT
484 WINAPI
485 getFS(VOID)
486 {
487 return EmulatorContext.SegmentRegs[FAST486_REG_FS].Selector;
488 }
489
490 VOID
491 WINAPI
492 setFS(USHORT Value)
493 {
494 Fast486SetSegment(&EmulatorContext, FAST486_REG_FS, Value);
495 }
496
497 USHORT
498 WINAPI
499 getGS(VOID)
500 {
501 return EmulatorContext.SegmentRegs[FAST486_REG_GS].Selector;
502 }
503
504 VOID
505 WINAPI
506 setGS(USHORT Value)
507 {
508 Fast486SetSegment(&EmulatorContext, FAST486_REG_GS, Value);
509 }
510
511
512
513 ULONG
514 WINAPI
515 getCF(VOID)
516 {
517 return EmulatorGetFlag(EMULATOR_FLAG_CF);
518 }
519
520 VOID
521 WINAPI
522 setCF(ULONG Flag)
523 {
524 if (Flag & 1)
525 EmulatorSetFlag(EMULATOR_FLAG_CF);
526 else
527 EmulatorClearFlag(EMULATOR_FLAG_CF);
528 }
529
530 ULONG
531 WINAPI
532 getPF(VOID)
533 {
534 return EmulatorGetFlag(EMULATOR_FLAG_PF);
535 }
536
537 VOID
538 WINAPI
539 setPF(ULONG Flag)
540 {
541 if (Flag & 1)
542 EmulatorSetFlag(EMULATOR_FLAG_PF);
543 else
544 EmulatorClearFlag(EMULATOR_FLAG_PF);
545 }
546
547 ULONG
548 WINAPI
549 getAF(VOID)
550 {
551 return EmulatorGetFlag(EMULATOR_FLAG_AF);
552 }
553
554 VOID
555 WINAPI
556 setAF(ULONG Flag)
557 {
558 if (Flag & 1)
559 EmulatorSetFlag(EMULATOR_FLAG_AF);
560 else
561 EmulatorClearFlag(EMULATOR_FLAG_AF);
562 }
563
564 ULONG
565 WINAPI
566 getZF(VOID)
567 {
568 return EmulatorGetFlag(EMULATOR_FLAG_ZF);
569 }
570
571 VOID
572 WINAPI
573 setZF(ULONG Flag)
574 {
575 if (Flag & 1)
576 EmulatorSetFlag(EMULATOR_FLAG_ZF);
577 else
578 EmulatorClearFlag(EMULATOR_FLAG_ZF);
579 }
580
581 ULONG
582 WINAPI
583 getSF(VOID)
584 {
585 return EmulatorGetFlag(EMULATOR_FLAG_SF);
586 }
587
588 VOID
589 WINAPI
590 setSF(ULONG Flag)
591 {
592 if (Flag & 1)
593 EmulatorSetFlag(EMULATOR_FLAG_SF);
594 else
595 EmulatorClearFlag(EMULATOR_FLAG_SF);
596 }
597
598 ULONG
599 WINAPI
600 getIF(VOID)
601 {
602 return EmulatorGetFlag(EMULATOR_FLAG_IF);
603 }
604
605 VOID
606 WINAPI
607 setIF(ULONG Flag)
608 {
609 if (Flag & 1)
610 EmulatorSetFlag(EMULATOR_FLAG_IF);
611 else
612 EmulatorClearFlag(EMULATOR_FLAG_IF);
613 }
614
615 ULONG
616 WINAPI
617 getDF(VOID)
618 {
619 return EmulatorGetFlag(EMULATOR_FLAG_DF);
620 }
621
622 VOID
623 WINAPI
624 setDF(ULONG Flag)
625 {
626 if (Flag & 1)
627 EmulatorSetFlag(EMULATOR_FLAG_DF);
628 else
629 EmulatorClearFlag(EMULATOR_FLAG_DF);
630 }
631
632 ULONG
633 WINAPI
634 getOF(VOID)
635 {
636 return EmulatorGetFlag(EMULATOR_FLAG_OF);
637 }
638
639 VOID
640 WINAPI
641 setOF(ULONG Flag)
642 {
643 if (Flag & 1)
644 EmulatorSetFlag(EMULATOR_FLAG_OF);
645 else
646 EmulatorClearFlag(EMULATOR_FLAG_OF);
647 }
648
649
650
651 ULONG
652 WINAPI
653 getEFLAGS(VOID)
654 {
655 return EmulatorContext.Flags.Long;
656 }
657
658 VOID
659 WINAPI
660 setEFLAGS(ULONG Flags)
661 {
662 EmulatorContext.Flags.Long = Flags;
663 }
664
665
666
667 USHORT
668 WINAPI
669 getMSW(VOID)
670 {
671 return LOWORD(EmulatorContext.ControlRegisters[FAST486_REG_CR0]);
672 }
673
674 VOID
675 WINAPI
676 setMSW(USHORT Value)
677 {
678 /* Set the lower 16 bits (Machine Status Word) of CR0 */
679 EmulatorContext.ControlRegisters[FAST486_REG_CR0] &= 0xFFFF0000;
680 EmulatorContext.ControlRegisters[FAST486_REG_CR0] |= Value & 0xFFFF;
681 }
682
683 /* EOF */