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