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