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