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