reactos操作系统实现(91)
驱动程序很多配置参数是保存在注册表里,比如IO资源参数,中断号等内容。因此只有了解注册表的读取,以及相关内容才可以清楚知道键盘驱动程序,主要操作那些相关的端口,还有配置参数。下面来分析函数ReadRegistryEntries的实现,如下:
#001 NTSTATUS
#002 ReadRegistryEntries(
#003 IN PUNICODE_STRING RegistryPath,
#004 OUT PI8042_SETTINGS Settings)
#005 {
#006 RTL_QUERY_REGISTRY_TABLE Parameters[17];
#007 NTSTATUS Status;
#008
设置键盘缺省的队列大小。
#009 ULONG DefaultKeyboardDataQueueSize = 0x64;
其它缺省参数。
#010 PCWSTR DefaultKeyboardDeviceBaseName = L"KeyboardPort";
#011 ULONG DefaultMouseDataQueueSize = 0x64;
#012 ULONG DefaultMouseResolution = 3;
#013 ULONG DefaultMouseSynchIn100ns = 20000000;
#014 ULONG DefaultNumberOfButtons = 2;
#015 PCWSTR DefaultPointerDeviceBaseName = L"PointerPort";
#016 ULONG DefaultPollStatusIterations = 1;
#017 ULONG DefaultOverrideKeyboardType = 4;
#018 ULONG DefaultOverrideKeyboardSubtype = 0;
#019 ULONG DefaultPollingIterations = 12000;
#020 ULONG DefaultPollingIterationsMaximum = 12000;
#021 ULONG DefaultResendIterations = 0x3;
#022 ULONG DefaultSampleRate = 60;
#023 ULONG DefaultCrashOnCtrlScroll;
#024
#025 /* Default value for CrashOnCtrlScroll depends if we're
#026 * running a debug build or a normal build.
#027 */
#028 #ifdef DBG
#029 DefaultCrashOnCtrlScroll = 1;
#030 #else
#031 DefaultCrashOnCtrlScroll = 0;
#032 #endif
#033
初始化参数内存。
#034 RtlZeroMemory(Parameters, sizeof(Parameters));
#035
#036 Parameters[0].Flags = RTL_QUERY_REGISTRY_SUBKEY;
#037 Parameters[0].Name = L"Parameters";
#038
#039 Parameters[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#040 Parameters[1].Name = L"KeyboardDataQueueSize";
#041 Parameters[1].EntryContext = &Settings->KeyboardDataQueueSize;
#042 Parameters[1].DefaultType = REG_DWORD;
#043 Parameters[1].DefaultData = &DefaultKeyboardDataQueueSize;
#044 Parameters[1].DefaultLength = sizeof(ULONG);
#045
#046 Parameters[2].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#047 Parameters[2].Name = L"KeyboardDeviceBaseName";
#048 Parameters[2].EntryContext = &Settings->KeyboardDeviceBaseName;
#049 Parameters[2].DefaultType = REG_SZ;
#050 Parameters[2].DefaultData = (PVOID)DefaultKeyboardDeviceBaseName;
#051 Parameters[2].DefaultLength = 0;
#052
#053 Parameters[3].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#054 Parameters[3].Name = L"MouseDataQueueSize";
#055 Parameters[3].EntryContext = &Settings->MouseDataQueueSize;
#056 Parameters[3].DefaultType = REG_DWORD;
#057 Parameters[3].DefaultData = &DefaultMouseDataQueueSize;
#058 Parameters[3].DefaultLength = sizeof(ULONG);
#059
#060 Parameters[4].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#061 Parameters[4].Name = L"MouseResolution";
#062 Parameters[4].EntryContext = &Settings->MouseResolution;
#063 Parameters[4].DefaultType = REG_DWORD;
#064 Parameters[4].DefaultData = &DefaultMouseResolution;
#065 Parameters[4].DefaultLength = sizeof(ULONG);
#066
#067 Parameters[5].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#068 Parameters[5].Name = L"MouseSynchIn100ns";
#069 Parameters[5].EntryContext = &Settings->MouseSynchIn100ns;
#070 Parameters[5].DefaultType = REG_DWORD;
#071 Parameters[5].DefaultData = &DefaultMouseSynchIn100ns;
#072 Parameters[5].DefaultLength = sizeof(ULONG);
#073
#074 Parameters[6].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#075 Parameters[6].Name = L"NumberOfButtons";
#076 Parameters[6].EntryContext = &Settings->NumberOfButtons;
#077 Parameters[6].DefaultType = REG_DWORD;
#078 Parameters[6].DefaultData = &DefaultNumberOfButtons;
#079 Parameters[6].DefaultLength = sizeof(ULONG);
#080
#081 Parameters[7].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#082 Parameters[7].Name = L"PointerDeviceBaseName";
#083 Parameters[7].EntryContext = &Settings->PointerDeviceBaseName;
#084 Parameters[7].DefaultType = REG_SZ;
#085 Parameters[7].DefaultData = (PVOID)DefaultPointerDeviceBaseName;
#086 Parameters[7].DefaultLength = 0;
#087
#088 Parameters[8].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#089 Parameters[8].Name = L"PollStatusIterations";
#090 Parameters[8].EntryContext = &Settings->PollStatusIterations;
#091 Parameters[8].DefaultType = REG_DWORD;
#092 Parameters[8].DefaultData = &DefaultPollStatusIterations;
#093 Parameters[8].DefaultLength = sizeof(ULONG);
#094
#095 Parameters[9].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#096 Parameters[9].Name = L"OverrideKeyboardType";
#097 Parameters[9].EntryContext = &Settings->OverrideKeyboardType;
#098 Parameters[9].DefaultType = REG_DWORD;
#099 Parameters[9].DefaultData = &DefaultOverrideKeyboardType;
#100 Parameters[9].DefaultLength = sizeof(ULONG);
#101
#102 Parameters[10].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#103 Parameters[10].Name = L"OverrideKeyboardSubtype";
#104 Parameters[10].EntryContext = &Settings->OverrideKeyboardSubtype;
#105 Parameters[10].DefaultType = REG_DWORD;
#106 Parameters[10].DefaultData = &DefaultOverrideKeyboardSubtype;
#107 Parameters[10].DefaultLength = sizeof(ULONG);
#108
#109 Parameters[11].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#110 Parameters[11].Name = L"PollingIterations";
#111 Parameters[11].EntryContext = &Settings->PollingIterations;
#112 Parameters[11].DefaultType = REG_DWORD;
#113 Parameters[11].DefaultData = &DefaultPollingIterations;
#114 Parameters[11].DefaultLength = sizeof(ULONG);
#115
#116 Parameters[12].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#117 Parameters[12].Name = L"PollingIterationsMaximum";
#118 Parameters[12].EntryContext = &Settings->PollingIterationsMaximum;
#119 Parameters[12].DefaultType = REG_DWORD;
#120 Parameters[12].DefaultData = &DefaultPollingIterationsMaximum;
#121 Parameters[12].DefaultLength = sizeof(ULONG);
#122
#123 Parameters[13].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#124 Parameters[13].Name = L"ResendIterations";
#125 Parameters[13].EntryContext = &Settings->ResendIterations;
#126 Parameters[13].DefaultType = REG_DWORD;
#127 Parameters[13].DefaultData = &DefaultResendIterations;
#128 Parameters[13].DefaultLength = sizeof(ULONG);
#129
#130 Parameters[14].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#131 Parameters[14].Name = L"SampleRate";
#132 Parameters[14].EntryContext = &Settings->SampleRate;
#133 Parameters[14].DefaultType = REG_DWORD;
#134 Parameters[14].DefaultData = &DefaultSampleRate;
#135 Parameters[14].DefaultLength = sizeof(ULONG);
#136
#137 Parameters[15].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL;
#138 Parameters[15].Name = L"CrashOnCtrlScroll";
#139 Parameters[15].EntryContext = &Settings->CrashOnCtrlScroll;
#140 Parameters[15].DefaultType = REG_DWORD;
#141 Parameters[15].DefaultData = &DefaultCrashOnCtrlScroll;
#142 Parameters[15].DefaultLength = sizeof(ULONG);
#143
读取注册表里的值。
#144 Status = RtlQueryRegistryValues(
#145 RTL_REGISTRY_ABSOLUTE,
#146 RegistryPath->Buffer,
#147 Parameters,
#148 NULL,
#149 NULL);
#150
保存到Settings里面。
#151 if (NT_SUCCESS(Status))
#152 {
#153 /* Check values */
#154 if (Settings->KeyboardDataQueueSize < 1)
#155 Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize;
#156 if (Settings->MouseDataQueueSize < 1)
#157 Settings->MouseDataQueueSize = DefaultMouseDataQueueSize;
#158 if (Settings->NumberOfButtons < 1)
#159 Settings->NumberOfButtons = DefaultNumberOfButtons;
#160 if (Settings->PollingIterations < 0x400)
#161 Settings->PollingIterations = DefaultPollingIterations;
#162 if (Settings->PollingIterationsMaximum < 0x400)
#163 Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum;
#164 if (Settings->ResendIterations < 1)
#165 Settings->ResendIterations = DefaultResendIterations;
#166 }
#167 else if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
#168 {
#169 /* Registry path doesn't exist. Set defaults */
#170 Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize;
#171 Settings->MouseDataQueueSize = DefaultMouseDataQueueSize;
#172 Settings->MouseResolution = DefaultMouseResolution;
#173 Settings->MouseSynchIn100ns = DefaultMouseSynchIn100ns;
#174 Settings->NumberOfButtons = DefaultNumberOfButtons;
#175 Settings->PollStatusIterations = DefaultPollStatusIterations;
#176 Settings->OverrideKeyboardType = DefaultOverrideKeyboardType;
#177 Settings->OverrideKeyboardSubtype = DefaultOverrideKeyboardSubtype;
#178 Settings->PollingIterations = DefaultPollingIterations;
#179 Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum;
#180 Settings->ResendIterations = DefaultResendIterations;
#181 Settings->SampleRate = DefaultSampleRate;
#182 Settings->CrashOnCtrlScroll = DefaultCrashOnCtrlScroll;
#183 if (!RtlCreateUnicodeString(&Settings->KeyboardDeviceBaseName, DefaultKeyboardDeviceBaseName)
#184 || !RtlCreateUnicodeString(&Settings->PointerDeviceBaseName, DefaultPointerDeviceBaseName))
#185 {
#186 WARN_(I8042PRT, "RtlCreateUnicodeString() failed/n");
#187 Status = STATUS_NO_MEMORY;
#188 }
#189 else
#190 {
#191 Status = STATUS_SUCCESS;
#192 }
#193 }
#194
进行调试输出信息。
#195 if (NT_SUCCESS(Status))
#196 {
#197 INFO_(I8042PRT, "KeyboardDataQueueSize : 0x%lx/n", Settings->KeyboardDataQueueSize);
#198 INFO_(I8042PRT, "KeyboardDeviceBaseName : %wZ/n", &Settings->KeyboardDeviceBaseName);
#199 INFO_(I8042PRT, "MouseDataQueueSize : 0x%lx/n", Settings->MouseDataQueueSize);
#200 INFO_(I8042PRT, "MouseResolution : 0x%lx/n", Settings->MouseResolution);
#201 INFO_(I8042PRT, "MouseSynchIn100ns : %lu/n", Settings->MouseSynchIn100ns);
#202 INFO_(I8042PRT, "NumberOfButtons : 0x%lx/n", Settings->NumberOfButtons);
#203 INFO_(I8042PRT, "PointerDeviceBaseName : %wZ/n", &Settings->PointerDeviceBaseName);
#204 INFO_(I8042PRT, "PollStatusIterations : 0x%lx/n", Settings->PollStatusIterations);
#205 INFO_(I8042PRT, "OverrideKeyboardType : 0x%lx/n", Settings->OverrideKeyboardType);
#206 INFO_(I8042PRT, "OverrideKeyboardSubtype : 0x%lx/n", Settings->OverrideKeyboardSubtype);
#207 INFO_(I8042PRT, "PollingIterations : 0x%lx/n", Settings->PollingIterations);
#208 INFO_(I8042PRT, "PollingIterationsMaximum : %lu/n", Settings->PollingIterationsMaximum);
#209 INFO_(I8042PRT, "ResendIterations : 0x%lx/n", Settings->ResendIterations);
#210 INFO_(I8042PRT, "SampleRate : %lu/n", Settings->SampleRate);
#211 }
#212
#213 return Status;
#214 }