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