├── .gitattributes ├── .gitignore ├── BOOTVID.lib ├── BugCheck2Linux.sln ├── BugCheck2Linux ├── BootImage.h ├── BugCheck2Linux.inf ├── BugCheck2Linux.vcxproj ├── BugCheck2Linux.vcxproj.filters ├── bootvid.h ├── default64mbdtc.h ├── entry.c └── mini-rv32ima.h └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /BOOTVID.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NSG650/BugCheck2Linux/5345bf3f728a71dc5497bff25f3158637c4f7031/BOOTVID.lib -------------------------------------------------------------------------------- /BugCheck2Linux.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.3.32825.248 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BugCheck2Linux", "BugCheck2Linux\BugCheck2Linux.vcxproj", "{299A00B7-228C-4E90-9844-E273FC5E1220}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|ARM64 = Debug|ARM64 11 | Debug|x64 = Debug|x64 12 | Release|ARM64 = Release|ARM64 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Debug|ARM64.ActiveCfg = Debug|ARM64 17 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Debug|ARM64.Build.0 = Debug|ARM64 18 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Debug|ARM64.Deploy.0 = Debug|ARM64 19 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Debug|x64.ActiveCfg = Debug|x64 20 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Debug|x64.Build.0 = Debug|x64 21 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Debug|x64.Deploy.0 = Debug|x64 22 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Release|ARM64.ActiveCfg = Release|ARM64 23 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Release|ARM64.Build.0 = Release|ARM64 24 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Release|ARM64.Deploy.0 = Release|ARM64 25 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Release|x64.ActiveCfg = Release|x64 26 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Release|x64.Build.0 = Release|x64 27 | {299A00B7-228C-4E90-9844-E273FC5E1220}.Release|x64.Deploy.0 = Release|x64 28 | EndGlobalSection 29 | GlobalSection(SolutionProperties) = preSolution 30 | HideSolutionNode = FALSE 31 | EndGlobalSection 32 | GlobalSection(ExtensibilityGlobals) = postSolution 33 | SolutionGuid = {5C95B5FB-C806-4156-A0D3-19E3F06467E7} 34 | EndGlobalSection 35 | EndGlobal 36 | -------------------------------------------------------------------------------- /BugCheck2Linux/BugCheck2Linux.inf: -------------------------------------------------------------------------------- 1 | ; 2 | ; BugCheck2Linux.inf 3 | ; 4 | 5 | [Version] 6 | Signature="$WINDOWS NT$" 7 | Class=System ; TODO: specify appropriate Class 8 | ClassGuid={4d36e97d-e325-11ce-bfc1-08002be10318} ; TODO: specify appropriate ClassGuid 9 | Provider=%ManufacturerName% 10 | CatalogFile=BugCheck2Linux.cat 11 | DriverVer= ; TODO: set DriverVer in stampinf property pages 12 | PnpLockdown=1 13 | 14 | [DestinationDirs] 15 | DefaultDestDir = 12 16 | BugCheck2Linux_Device_CoInstaller_CopyFiles = 11 17 | 18 | [SourceDisksNames] 19 | 1 = %DiskName%,,,"" 20 | 21 | [SourceDisksFiles] 22 | BugCheck2Linux.sys = 1,, 23 | WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll=1 ; make sure the number matches with SourceDisksNames 24 | 25 | ;***************************************** 26 | ; Install Section 27 | ;***************************************** 28 | 29 | [Manufacturer] 30 | %ManufacturerName%=Standard,NT$ARCH$ 31 | 32 | [Standard.NT$ARCH$] 33 | %BugCheck2Linux.DeviceDesc%=BugCheck2Linux_Device, Root\BugCheck2Linux ; TODO: edit hw-id 34 | 35 | [BugCheck2Linux_Device.NT] 36 | CopyFiles=Drivers_Dir 37 | 38 | [Drivers_Dir] 39 | BugCheck2Linux.sys 40 | 41 | ;-------------- Service installation 42 | [BugCheck2Linux_Device.NT.Services] 43 | AddService = BugCheck2Linux,%SPSVCINST_ASSOCSERVICE%, BugCheck2Linux_Service_Inst 44 | 45 | ; -------------- BugCheck2Linux driver install sections 46 | [BugCheck2Linux_Service_Inst] 47 | DisplayName = %BugCheck2Linux.SVCDESC% 48 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 49 | StartType = 3 ; SERVICE_DEMAND_START 50 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 51 | ServiceBinary = %12%\BugCheck2Linux.sys 52 | 53 | ; 54 | ;--- BugCheck2Linux_Device Coinstaller installation ------ 55 | ; 56 | 57 | [BugCheck2Linux_Device.NT.CoInstallers] 58 | AddReg=BugCheck2Linux_Device_CoInstaller_AddReg 59 | CopyFiles=BugCheck2Linux_Device_CoInstaller_CopyFiles 60 | 61 | [BugCheck2Linux_Device_CoInstaller_AddReg] 62 | HKR,,CoInstallers32,0x00010000, "WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller" 63 | 64 | [BugCheck2Linux_Device_CoInstaller_CopyFiles] 65 | WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll 66 | 67 | [BugCheck2Linux_Device.NT.Wdf] 68 | KmdfService = BugCheck2Linux, BugCheck2Linux_wdfsect 69 | [BugCheck2Linux_wdfsect] 70 | KmdfLibraryVersion = $KMDFVERSION$ 71 | 72 | [Strings] 73 | SPSVCINST_ASSOCSERVICE= 0x00000002 74 | ManufacturerName="" ;TODO: Replace with your manufacturer name 75 | DiskName = "BugCheck2Linux Installation Disk" 76 | BugCheck2Linux.DeviceDesc = "BugCheck2Linux Device" 77 | BugCheck2Linux.SVCDESC = "BugCheck2Linux Service" 78 | -------------------------------------------------------------------------------- /BugCheck2Linux/BugCheck2Linux.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | Debug 14 | ARM64 15 | 16 | 17 | Release 18 | ARM64 19 | 20 | 21 | 22 | {299A00B7-228C-4E90-9844-E273FC5E1220} 23 | {1bc93793-694f-48fe-9372-81e2b05556fd} 24 | v4.5 25 | 12.0 26 | Debug 27 | x64 28 | BugCheck2Linux 29 | 30 | 31 | 32 | Windows10 33 | true 34 | WindowsKernelModeDriver10.0 35 | Driver 36 | KMDF 37 | Universal 38 | false 39 | 40 | 41 | Windows10 42 | false 43 | WindowsKernelModeDriver10.0 44 | Driver 45 | KMDF 46 | Universal 47 | false 48 | 49 | 50 | Windows10 51 | true 52 | WindowsKernelModeDriver10.0 53 | Driver 54 | KMDF 55 | Universal 56 | 57 | 58 | Windows10 59 | false 60 | WindowsKernelModeDriver10.0 61 | Driver 62 | KMDF 63 | Universal 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | DbgengKernelDebugger 75 | false 76 | 77 | 78 | DbgengKernelDebugger 79 | false 80 | 81 | 82 | DbgengKernelDebugger 83 | 84 | 85 | DbgengKernelDebugger 86 | 87 | 88 | 89 | sha256 90 | 91 | 92 | TurnOffAllWarnings 93 | 94 | 95 | false 96 | 97 | 98 | $(SolutionDir)bootvid.lib;%(AdditionalDependencies) 99 | 100 | 101 | 102 | 103 | sha256 104 | 105 | 106 | TurnOffAllWarnings 107 | 108 | 109 | false 110 | 111 | 112 | $(SolutionDir)bootvid.lib;%(AdditionalDependencies) 113 | 114 | 115 | 116 | 117 | sha256 118 | 119 | 120 | 121 | 122 | sha256 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /BugCheck2Linux/BugCheck2Linux.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {8E41214B-6785-4CFE-B992-037D68949A14} 18 | inf;inv;inx;mof;mc; 19 | 20 | 21 | 22 | 23 | Driver Files 24 | 25 | 26 | 27 | 28 | Source Files 29 | 30 | 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | -------------------------------------------------------------------------------- /BugCheck2Linux/bootvid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //https://github.com/reactos/reactos/blob/master/sdk/include/reactos/drivers/bootvid/display.h 4 | //https://github.com/reactos/reactos/blob/master/sdk/include/reactos/drivers/bootvid/bootvid.h 5 | 6 | #include 7 | 8 | #define BV_COLOR_BLACK 0 9 | #define BV_COLOR_RED 1 10 | #define BV_COLOR_GREEN 2 11 | #define BV_COLOR_BROWN 3 12 | #define BV_COLOR_BLUE 4 13 | #define BV_COLOR_MAGENTA 5 14 | #define BV_COLOR_CYAN 6 15 | #define BV_COLOR_DARK_GRAY 7 16 | #define BV_COLOR_LIGHT_GRAY 8 17 | #define BV_COLOR_LIGHT_RED 9 18 | #define BV_COLOR_LIGHT_GREEN 10 19 | #define BV_COLOR_YELLOW 11 20 | #define BV_COLOR_LIGHT_BLUE 12 21 | #define BV_COLOR_LIGHT_MAGENTA 13 22 | #define BV_COLOR_LIGHT_CYAN 14 23 | #define BV_COLOR_WHITE 15 24 | #define BV_COLOR_NONE 16 25 | #define BV_MAX_COLORS 16 26 | 27 | NTKERNELAPI BOOLEAN VidInitialize(BOOLEAN SetMode); 28 | NTKERNELAPI VOID VidResetDisplay(BOOLEAN HalReset); 29 | NTKERNELAPI ULONG VidSetTextColor(ULONG Color); 30 | NTKERNELAPI VOID VidDisplayStringXY(PUCHAR String, ULONG Left, ULONG Top, BOOLEAN Transparent); 31 | NTKERNELAPI VOID VidSetScrollRegion(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom); 32 | NTKERNELAPI VOID VidCleanUp(VOID); 33 | NTKERNELAPI VOID VidBufferToScreenBlt(PUCHAR Buffer, ULONG Left, ULONG Top, ULONG Width, ULONG Height, ULONG Delta); 34 | NTKERNELAPI VOID VidDisplayString(PUCHAR String); 35 | NTKERNELAPI ULONG VidBitBlt(PVOID pbuff, ULONG x, ULONG y); 36 | NTKERNELAPI VOID VidScreenToBufferBlt(PUCHAR Buffer, ULONG Left, ULONG Top, ULONG Width, ULONG Height, ULONG Delta); 37 | NTKERNELAPI VOID VidSolidColorFill(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, UCHAR Color); 38 | -------------------------------------------------------------------------------- /BugCheck2Linux/default64mbdtc.h: -------------------------------------------------------------------------------- 1 | static const unsigned char default64mbdtb[] = {0xd0, 0x0d, 0xfe, 0xed, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x05, 0x00, 2 | 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 3 | 0x00, 0x00, 0x00, 0xe3, 0x00, 0x00, 0x04, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 5 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 6 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x02, 7 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1b, 0x72, 0x69, 0x73, 0x63, 8 | 0x76, 0x2d, 0x6d, 0x69, 0x6e, 0x69, 0x6d, 0x61, 0x6c, 0x2d, 0x6e, 0x6f, 0x6d, 0x6d, 0x75, 0x00, 9 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x26, 0x72, 0x69, 0x73, 0x63, 10 | 0x76, 0x2d, 0x6d, 0x69, 0x6e, 0x69, 0x6d, 0x61, 0x6c, 0x2d, 0x6e, 0x6f, 0x6d, 0x6d, 0x75, 0x2c, 11 | 0x71, 0x65, 0x6d, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x63, 0x68, 0x6f, 0x73, 12 | 0x65, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x2c, 13 | 0x65, 0x61, 0x72, 0x6c, 0x79, 0x63, 0x6f, 0x6e, 0x3d, 0x75, 0x61, 0x72, 0x74, 0x38, 0x32, 0x35, 14 | 0x30, 0x2c, 0x6d, 0x6d, 0x69, 0x6f, 0x2c, 0x30, 0x78, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 15 | 0x30, 0x2c, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 16 | 0x65, 0x3d, 0x68, 0x76, 0x63, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 17 | 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x40, 0x38, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 18 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x35, 0x6d, 0x65, 0x6d, 0x6f, 19 | 0x72, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x41, 20 | 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xc0, 0x00, 21 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x63, 0x70, 0x75, 0x73, 0x00, 0x00, 0x00, 0x00, 22 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 23 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 24 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x45, 0x00, 0x0f, 0x42, 0x40, 25 | 0x00, 0x00, 0x00, 0x01, 0x63, 0x70, 0x75, 0x40, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 26 | 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 27 | 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x35, 0x63, 0x70, 0x75, 0x00, 0x00, 0x00, 0x00, 0x03, 28 | 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 29 | 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x60, 0x6f, 0x6b, 0x61, 0x79, 0x00, 0x00, 0x00, 0x00, 30 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x1b, 0x72, 0x69, 0x73, 0x63, 31 | 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x67, 32 | 0x72, 0x76, 0x33, 0x32, 0x69, 0x6d, 0x61, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0b, 33 | 0x00, 0x00, 0x00, 0x71, 0x72, 0x69, 0x73, 0x63, 0x76, 0x2c, 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x00, 34 | 0x00, 0x00, 0x00, 0x01, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x72, 0x75, 0x70, 0x74, 0x2d, 0x63, 0x6f, 35 | 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 36 | 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 38 | 0x00, 0x00, 0x00, 0x1b, 0x72, 0x69, 0x73, 0x63, 0x76, 0x2c, 0x63, 0x70, 0x75, 0x2d, 0x69, 0x6e, 39 | 0x74, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x58, 40 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 41 | 0x63, 0x70, 0x75, 0x2d, 0x6d, 0x61, 0x70, 0x00, 0x00, 0x00, 0x00, 0x01, 0x63, 0x6c, 0x75, 0x73, 42 | 0x74, 0x65, 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x63, 0x6f, 0x72, 0x65, 43 | 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa0, 44 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 45 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x73, 0x6f, 0x63, 0x00, 0x00, 0x00, 0x00, 0x03, 46 | 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 47 | 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 48 | 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x1b, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x2d, 0x62, 49 | 0x75, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 50 | 0x00, 0x00, 0x00, 0x01, 0x75, 0x61, 0x72, 0x74, 0x40, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 51 | 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xab, 52 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x41, 53 | 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 54 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1b, 0x6e, 0x73, 0x31, 0x36, 55 | 0x38, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x70, 0x6f, 0x77, 0x65, 56 | 0x72, 0x6f, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 57 | 0x00, 0x00, 0x00, 0xbb, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 58 | 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 59 | 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 60 | 0x00, 0x00, 0x00, 0x1b, 0x73, 0x79, 0x73, 0x63, 0x6f, 0x6e, 0x2d, 0x70, 0x6f, 0x77, 0x65, 0x72, 61 | 0x6f, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x72, 0x65, 0x62, 0x6f, 62 | 0x6f, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xbb, 63 | 0x00, 0x00, 0x77, 0x77, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xc1, 64 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xc8, 65 | 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1b, 66 | 0x73, 0x79, 0x73, 0x63, 0x6f, 0x6e, 0x2d, 0x72, 0x65, 0x62, 0x6f, 0x6f, 0x74, 0x00, 0x00, 0x00, 67 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x73, 0x79, 0x73, 0x63, 0x6f, 0x6e, 0x40, 0x31, 68 | 0x31, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 69 | 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 70 | 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 71 | 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x1b, 72 | 0x73, 0x79, 0x73, 0x63, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 73 | 0x63, 0x6c, 0x69, 0x6e, 0x74, 0x40, 0x31, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 74 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xcf, 0x00, 0x00, 0x00, 0x02, 75 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 76 | 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 77 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x1b, 78 | 0x00, 0x00, 0x00, 0x1b, 0x73, 0x69, 0x66, 0x69, 0x76, 0x65, 0x2c, 0x63, 0x6c, 0x69, 0x6e, 0x74, 79 | 0x30, 0x00, 0x72, 0x69, 0x73, 0x63, 0x76, 0x2c, 0x63, 0x6c, 0x69, 0x6e, 0x74, 0x30, 0x00, 0x00, 80 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x09, 81 | 0x23, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x2d, 0x63, 0x65, 0x6c, 0x6c, 0x73, 0x00, 0x23, 82 | 0x73, 0x69, 0x7a, 0x65, 0x2d, 0x63, 0x65, 0x6c, 0x6c, 0x73, 0x00, 0x63, 0x6f, 0x6d, 0x70, 0x61, 83 | 0x74, 0x69, 0x62, 0x6c, 0x65, 0x00, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x00, 0x62, 0x6f, 0x6f, 0x74, 84 | 0x61, 0x72, 0x67, 0x73, 0x00, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 85 | 0x00, 0x72, 0x65, 0x67, 0x00, 0x74, 0x69, 0x6d, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2d, 0x66, 0x72, 86 | 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x79, 0x00, 0x70, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x00, 87 | 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x00, 0x72, 0x69, 0x73, 0x63, 0x76, 0x2c, 0x69, 0x73, 0x61, 88 | 0x00, 0x6d, 0x6d, 0x75, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x00, 0x23, 0x69, 0x6e, 0x74, 0x65, 0x72, 89 | 0x72, 0x75, 0x70, 0x74, 0x2d, 0x63, 0x65, 0x6c, 0x6c, 0x73, 0x00, 0x69, 0x6e, 0x74, 0x65, 0x72, 90 | 0x72, 0x75, 0x70, 0x74, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x00, 91 | 0x63, 0x70, 0x75, 0x00, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x00, 0x63, 0x6c, 0x6f, 0x63, 0x6b, 92 | 0x2d, 0x66, 0x72, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x79, 0x00, 0x76, 0x61, 0x6c, 0x75, 0x65, 93 | 0x00, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x00, 0x72, 0x65, 0x67, 0x6d, 0x61, 0x70, 0x00, 0x69, 94 | 0x6e, 0x74, 0x65, 0x72, 0x72, 0x75, 0x70, 0x74, 0x73, 0x2d, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x64, 95 | 0x65, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 96 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 97 | }; -------------------------------------------------------------------------------- /BugCheck2Linux/entry.c: -------------------------------------------------------------------------------- 1 | // The code mixes naming conventions as I worked on the linux version before porting to windows 2 | // This code is also not the best so forgive me as I was in a hurry. You are very much welcome to open a PR with your changes to improve the code. 3 | // This also works ONLY on BIOS systems as it makes use of bootvid.dll 4 | 5 | #include 6 | #include 7 | 8 | #include "bootvid.h" 9 | 10 | #include "BootImage.h" 11 | 12 | // static const unsigned char BootImage[] 13 | #define BOOT_IMAGE_SIZE 3476752 14 | #define SCREEN_CHAR_WIDTH 80 15 | #define SCREEN_CHAR_HEIGHT 30 16 | 17 | // Hello old friend! 18 | BOOLEAN UsingCapsOrNot = FALSE; 19 | 20 | static char ktocSHIFT(uint8_t key) { 21 | char c = 0; 22 | uint8_t dict[2][94] = { 23 | {41, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 26, 27, 43, 24 | 39, 40, 51, 52, 53, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 25 | 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 57}, 26 | {126, 33, 64, 35, 36, 37, 94, 38, 42, 40, 41, 95, 43, 123, 125, 124, 27 | 58, 34, 60, 62, 63, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 28 | 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 32} }; 29 | for (int i = 0; i < 94; i++) { 30 | if (dict[0][i] == key) { 31 | c = (char)dict[1][i]; 32 | } 33 | } 34 | return c; 35 | } 36 | 37 | 38 | static char ktoc(uint8_t key) { 39 | char c = 0; 40 | uint8_t dict[2][94] = { 41 | {57, 40, 51, 12, 52, 53, 11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 42 | 39, 13, 26, 43, 27, 41, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 43 | 37, 38, 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44}, 44 | {32, 39, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 45 | 54, 55, 56, 57, 59, 61, 91, 92, 93, 96, 97, 98, 46 | 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 47 | 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122} }; 48 | for (int i = 0; i < 94; i++) { 49 | if (dict[0][i] == key) { 50 | c = (char)dict[1][i]; 51 | } 52 | } 53 | return c; 54 | } 55 | 56 | 57 | // keep track of the cursor from our side 58 | INT cX = 0; 59 | INT cY = 0; 60 | 61 | BOOLEAN Vt100Parsing = FALSE; 62 | 63 | void mini_rv32ima_putchar(char c) { 64 | DbgPrint("%c", c); 65 | char string[2] = { c, 0 }; 66 | 67 | // Ignore any ANSI 68 | // Yes I have tried parsing ANSI escape sequences but bootvid is sloowww 69 | if (c == '\033') { 70 | Vt100Parsing = TRUE; 71 | } 72 | 73 | if (Vt100Parsing) { 74 | if (c == 'm' || c == 'A' || c == 'B' || c == 'C' || c == 'D') Vt100Parsing = FALSE; 75 | return; 76 | } 77 | 78 | if (c == '\n') cY += 16; 79 | if (c == '\r') cX = 0; 80 | 81 | // bootvid's scrolling is horribly broken so we clear the screen instead 82 | // not the best solution 83 | if (cY > 479) { VidResetDisplay(0); cX = 0; cY = 0; }; 84 | 85 | if (cX > 639) { cX = 0; cY += 16; } 86 | 87 | VidDisplayString(string); 88 | cX += 8; 89 | } 90 | 91 | void mini_rv32ima_print(char* string) { 92 | DbgPrint("RV32: %s\n", string); 93 | } 94 | 95 | int mini_rv32ima_key_hit(void) { 96 | return (__inbyte(0x64) & 1); 97 | } 98 | 99 | int mini_rv32ima_get_key(void) { 100 | char key = __inbyte(0x60); 101 | if (key == 0x1c) return '\r'; 102 | if (key == 0x3A) { UsingCapsOrNot = !UsingCapsOrNot; return -1; } 103 | if (UsingCapsOrNot) return ktocSHIFT(key); 104 | else return ktoc(key); 105 | } 106 | 107 | void* mini_rv32ima_malloc(size_t count) { 108 | return ExAllocatePoolWithTag(NonPagedPool, count, 'CISR'); 109 | } 110 | 111 | uint32_t mini_rv32ima_handle_control_store(uint32_t addy, uint32_t val) { 112 | if (addy == 0x10000000) mini_rv32ima_putchar(val); 113 | 114 | return 0; 115 | } 116 | 117 | uint32_t mini_rv32ima_handle_control_load(uint32_t addy) { 118 | if (addy == 0x10000005) return 0x60 | mini_rv32ima_key_hit(); 119 | 120 | return 0; 121 | } 122 | 123 | void mini_rv32ima_handle_other_csr_write(uint16_t csrno, uint32_t value) { 124 | if (csrno == 0x139) mini_rv32ima_putchar(value); 125 | } 126 | 127 | uint32_t mini_rv32ima_handle_other_csr_read(uint16_t csrno) { 128 | if (csrno == 0x140) { 129 | if (!mini_rv32ima_key_hit()) return -1; 130 | return mini_rv32ima_get_key(); 131 | } 132 | return 0; 133 | } 134 | 135 | #define RAM_SIZE 64 * 1024 * 1024 136 | 137 | #define MINIRV32WARN 138 | #define MINIRV32_DECORATE static 139 | #define MINI_RV32_RAM_SIZE RAM_SIZE 140 | #define MINIRV32_IMPLEMENTATION 141 | #define MINIRV32_HANDLE_MEM_STORE_CONTROL(addy, val) if(mini_rv32ima_handle_control_store( addy, val )) return val; 142 | #define MINIRV32_HANDLE_MEM_LOAD_CONTROL(addy, rval) rval = mini_rv32ima_handle_control_load( addy ); 143 | #define MINIRV32_OTHERCSR_WRITE(csrno, value) mini_rv32ima_handle_other_csr_write(csrno, value); 144 | #define MINIRV32_OTHERCSR_READ(csrno, value) value = mini_rv32ima_handle_other_csr_read(csrno); 145 | 146 | #include "mini-rv32ima.h" 147 | #include "default64mbdtc.h" 148 | 149 | UCHAR* memory = NULL; 150 | struct MiniRV32IMAState* cpu = NULL; 151 | 152 | PKBUGCHECK_CALLBACK_RECORD BugcheckCallbackRecord = NULL; 153 | 154 | VOID DriverUnload(PDRIVER_OBJECT DriverObject) { 155 | UNREFERENCED_PARAMETER(DriverObject); 156 | 157 | if (BugcheckCallbackRecord != NULL) { 158 | KeDeregisterBugCheckCallback(BugcheckCallbackRecord); 159 | ExFreePoolWithTag(BugcheckCallbackRecord, 'CSIR'); 160 | } 161 | 162 | DbgPrint("[*] Goodbye Cruel World\n"); 163 | } 164 | 165 | VOID BugcheckCallback(PVOID Buffer, ULONG Length) { 166 | UNREFERENCED_PARAMETER(Buffer); 167 | UNREFERENCED_PARAMETER(Length); 168 | 169 | VidResetDisplay(TRUE); 170 | VidSetTextColor(BV_COLOR_WHITE); 171 | VidSolidColorFill(0, 0, 639, 479, BV_COLOR_BLACK); 172 | VidSetScrollRegion(0, 0, 639, 479); 173 | 174 | // Enable the PS/2 Keyboard 175 | while ((__inbyte(0x64) & 2) != 0) 176 | ; 177 | __outbyte(0x64, 0xae); 178 | 179 | 180 | BOOLEAN running = TRUE; 181 | while (running) { 182 | int ret = MiniRV32IMAStep(cpu, memory, 0, 1, 1024); // Execute upto 1024 cycles before breaking out. 183 | 184 | //printf("Ret %d PC %p\n", ret, cpu->pc); 185 | 186 | switch (ret) { 187 | case 0: break; 188 | case 1: break; 189 | case 3: break; 190 | case 21845: mini_rv32ima_print("poweroff requested. shutting down\n"); running = FALSE; 191 | default: running = FALSE; 192 | } 193 | } 194 | VidDisplayString("Halting forever now\n"); 195 | for (;;) __halt(); 196 | } 197 | 198 | NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, 199 | PUNICODE_STRING RegistryPath) { 200 | UNREFERENCED_PARAMETER(RegistryPath); 201 | 202 | DriverObject->DriverUnload = DriverUnload; 203 | 204 | memory = mini_rv32ima_malloc(RAM_SIZE); 205 | RtlZeroMemory(memory, RAM_SIZE); 206 | 207 | RtlCopyMemory(memory, BootImage, BOOT_IMAGE_SIZE); 208 | 209 | ULONG_PTR dtbPtr = RAM_SIZE - sizeof(default64mbdtb) - sizeof(struct MiniRV32IMAState); 210 | RtlCopyMemory(memory + dtbPtr, default64mbdtb, sizeof(default64mbdtb)); 211 | 212 | cpu = (struct MiniRV32IMAState*)(memory + RAM_SIZE - sizeof(struct MiniRV32IMAState)); 213 | cpu->pc = MINIRV32_RAM_IMAGE_OFFSET; 214 | cpu->regs[10] = 0x00; //hart ID 215 | cpu->regs[11] = (dtbPtr + MINIRV32_RAM_IMAGE_OFFSET); //dtb_pa (Must be valid pointer) (Should be pointer to dtb) 216 | cpu->extraflags |= 3; // Machine-mode. 217 | 218 | uint32_t* dtb = (uint32_t*)(memory + dtbPtr); 219 | if (dtb[0x13c / 4] == 0x00c0ff03) { 220 | uint32_t validram = dtbPtr; 221 | dtb[0x13c / 4] = (validram >> 24) | (((validram >> 16) & 0xff) << 8) | (((validram >> 8) & 0xff) << 16) | ((validram & 0xff) << 24); 222 | } 223 | 224 | BugcheckCallbackRecord = ExAllocatePoolZero(NonPagedPool, sizeof(KBUGCHECK_CALLBACK_RECORD), 'CSIR'); 225 | if (BugcheckCallbackRecord == NULL) return STATUS_INSUFFICIENT_RESOURCES; 226 | 227 | KeInitializeCallbackRecord(BugcheckCallbackRecord); 228 | 229 | BOOLEAN Registered = KeRegisterBugCheckCallback(BugcheckCallbackRecord, BugcheckCallback, NULL, 0, (PUCHAR)"Loonix"); 230 | if (!Registered) { 231 | ExFreePoolWithTag(BugcheckCallbackRecord, 'BCHK'); 232 | 233 | return STATUS_UNSUCCESSFUL; 234 | } 235 | 236 | return STATUS_SUCCESS; 237 | } -------------------------------------------------------------------------------- /BugCheck2Linux/mini-rv32ima.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Charles Lohr, you may use this file or any portions herein under any of the BSD, MIT, or CC0 licenses. 2 | 3 | #ifndef _MINI_RV32IMAH_H 4 | #define _MINI_RV32IMAH_H 5 | 6 | /** 7 | To use mini-rv32ima.h for the bare minimum, the following: 8 | 9 | #define MINI_RV32_RAM_SIZE ram_amt 10 | #define MINIRV32_IMPLEMENTATION 11 | 12 | #include "mini-rv32ima.h" 13 | 14 | Though, that's not _that_ interesting. You probably want I/O! 15 | 16 | 17 | Notes: 18 | * There is a dedicated CLNT at 0x10000000. 19 | * There is free MMIO from there to 0x12000000. 20 | * You can put things like a UART, or whatever there. 21 | * Feel free to override any of the functionality with macros. 22 | */ 23 | 24 | #ifndef MINIRV32WARN 25 | #define MINIRV32WARN( x... ); 26 | #endif 27 | 28 | #ifndef MINIRV32_DECORATE 29 | #define MINIRV32_DECORATE static 30 | #endif 31 | 32 | #ifndef MINIRV32_RAM_IMAGE_OFFSET 33 | #define MINIRV32_RAM_IMAGE_OFFSET 0x80000000 34 | #endif 35 | 36 | #ifndef MINIRV32_POSTEXEC 37 | #define MINIRV32_POSTEXEC(...); 38 | #endif 39 | 40 | #ifndef MINIRV32_HANDLE_MEM_STORE_CONTROL 41 | #define MINIRV32_HANDLE_MEM_STORE_CONTROL(...); 42 | #endif 43 | 44 | #ifndef MINIRV32_HANDLE_MEM_LOAD_CONTROL 45 | #define MINIRV32_HANDLE_MEM_LOAD_CONTROL(...); 46 | #endif 47 | 48 | #ifndef MINIRV32_OTHERCSR_WRITE 49 | #define MINIRV32_OTHERCSR_WRITE(...); 50 | #endif 51 | 52 | #ifndef MINIRV32_OTHERCSR_READ 53 | #define MINIRV32_OTHERCSR_READ(...); 54 | #endif 55 | 56 | #ifndef MINIRV32_CUSTOM_MEMORY_BUS 57 | #define MINIRV32_STORE4( ofs, val ) *(uint32_t*)(image + ofs) = val 58 | #define MINIRV32_STORE2( ofs, val ) *(uint16_t*)(image + ofs) = val 59 | #define MINIRV32_STORE1( ofs, val ) *(uint8_t*)(image + ofs) = val 60 | #define MINIRV32_LOAD4( ofs ) *(uint32_t*)(image + ofs) 61 | #define MINIRV32_LOAD2( ofs ) *(uint16_t*)(image + ofs) 62 | #define MINIRV32_LOAD1( ofs ) *(uint8_t*)(image + ofs) 63 | #define MINIRV32_LOAD2_SIGNED( ofs ) *(int16_t*)(image + ofs) 64 | #define MINIRV32_LOAD1_SIGNED( ofs ) *(int8_t*)(image + ofs) 65 | #endif 66 | 67 | // As a note: We quouple-ify these, because in HLSL, we will be operating with 68 | // uint4's. We are going to uint4 data to/from system RAM. 69 | // 70 | // We're going to try to keep the full processor state to 12 x uint4. 71 | struct MiniRV32IMAState 72 | { 73 | uint32_t regs[32]; 74 | 75 | uint32_t pc; 76 | uint32_t mstatus; 77 | uint32_t cyclel; 78 | uint32_t cycleh; 79 | 80 | uint32_t timerl; 81 | uint32_t timerh; 82 | uint32_t timermatchl; 83 | uint32_t timermatchh; 84 | 85 | uint32_t mscratch; 86 | uint32_t mtvec; 87 | uint32_t mie; 88 | uint32_t mip; 89 | 90 | uint32_t mepc; 91 | uint32_t mtval; 92 | uint32_t mcause; 93 | 94 | // Note: only a few bits are used. (Machine = 3, User = 0) 95 | // Bits 0..1 = privilege. 96 | // Bit 2 = WFI (Wait for interrupt) 97 | // Bit 3+ = Load/Store reservation LSBs. 98 | uint32_t extraflags; 99 | }; 100 | 101 | #ifndef MINIRV32_STEPPROTO 102 | MINIRV32_DECORATE int32_t MiniRV32IMAStep( struct MiniRV32IMAState * state, uint8_t * image, uint32_t vProcAddress, uint32_t elapsedUs, int count ); 103 | #endif 104 | 105 | #ifdef MINIRV32_IMPLEMENTATION 106 | 107 | #ifndef MINIRV32_CUSTOM_INTERNALS 108 | #define CSR( x ) state->x 109 | #define SETCSR( x, val ) { state->x = val; } 110 | #define REG( x ) state->regs[x] 111 | #define REGSET( x, val ) { state->regs[x] = val; } 112 | #endif 113 | 114 | #ifndef MINIRV32_STEPPROTO 115 | MINIRV32_DECORATE int32_t MiniRV32IMAStep( struct MiniRV32IMAState * state, uint8_t * image, uint32_t vProcAddress, uint32_t elapsedUs, int count ) 116 | #else 117 | MINIRV32_STEPPROTO 118 | #endif 119 | { 120 | uint32_t new_timer = CSR( timerl ) + elapsedUs; 121 | if( new_timer < CSR( timerl ) ) CSR( timerh )++; 122 | CSR( timerl ) = new_timer; 123 | 124 | // Handle Timer interrupt. 125 | if( ( CSR( timerh ) > CSR( timermatchh ) || ( CSR( timerh ) == CSR( timermatchh ) && CSR( timerl ) > CSR( timermatchl ) ) ) && ( CSR( timermatchh ) || CSR( timermatchl ) ) ) 126 | { 127 | CSR( extraflags ) &= ~4; // Clear WFI 128 | CSR( mip ) |= 1<<7; //MTIP of MIP // https://stackoverflow.com/a/61916199/2926815 Fire interrupt. 129 | } 130 | else 131 | CSR( mip ) &= ~(1<<7); 132 | 133 | // If WFI, don't run processor. 134 | if( CSR( extraflags ) & 4 ) 135 | return 1; 136 | 137 | uint32_t trap = 0; 138 | uint32_t rval = 0; 139 | uint32_t pc = CSR( pc ); 140 | uint32_t cycle = CSR( cyclel ); 141 | 142 | if( ( CSR( mip ) & (1<<7) ) && ( CSR( mie ) & (1<<7) /*mtie*/ ) && ( CSR( mstatus ) & 0x8 /*mie*/) ) 143 | { 144 | // Timer interrupt. 145 | trap = 0x80000007; 146 | pc -= 4; 147 | } 148 | else // No timer interrupt? Execute a bunch of instructions. 149 | for( int icount = 0; icount < count; icount++ ) 150 | { 151 | uint32_t ir = 0; 152 | rval = 0; 153 | cycle++; 154 | uint32_t ofs_pc = pc - MINIRV32_RAM_IMAGE_OFFSET; 155 | 156 | if( ofs_pc >= MINI_RV32_RAM_SIZE ) 157 | { 158 | trap = 1 + 1; // Handle access violation on instruction read. 159 | break; 160 | } 161 | else if( ofs_pc & 3 ) 162 | { 163 | trap = 1 + 0; //Handle PC-misaligned access 164 | break; 165 | } 166 | else 167 | { 168 | ir = MINIRV32_LOAD4( ofs_pc ); 169 | uint32_t rdid = (ir >> 7) & 0x1f; 170 | 171 | switch( ir & 0x7f ) 172 | { 173 | case 0x37: // LUI (0b0110111) 174 | rval = ( ir & 0xfffff000 ); 175 | break; 176 | case 0x17: // AUIPC (0b0010111) 177 | rval = pc + ( ir & 0xfffff000 ); 178 | break; 179 | case 0x6F: // JAL (0b1101111) 180 | { 181 | int32_t reladdy = ((ir & 0x80000000)>>11) | ((ir & 0x7fe00000)>>20) | ((ir & 0x00100000)>>9) | ((ir&0x000ff000)); 182 | if( reladdy & 0x00100000 ) reladdy |= 0xffe00000; // Sign extension. 183 | rval = pc + 4; 184 | pc = pc + reladdy - 4; 185 | break; 186 | } 187 | case 0x67: // JALR (0b1100111) 188 | { 189 | uint32_t imm = ir >> 20; 190 | int32_t imm_se = imm | (( imm & 0x800 )?0xfffff000:0); 191 | rval = pc + 4; 192 | pc = ( (REG( (ir >> 15) & 0x1f ) + imm_se) & ~1) - 4; 193 | break; 194 | } 195 | case 0x63: // Branch (0b1100011) 196 | { 197 | uint32_t immm4 = ((ir & 0xf00)>>7) | ((ir & 0x7e000000)>>20) | ((ir & 0x80) << 4) | ((ir >> 31)<<12); 198 | if( immm4 & 0x1000 ) immm4 |= 0xffffe000; 199 | int32_t rs1 = REG((ir >> 15) & 0x1f); 200 | int32_t rs2 = REG((ir >> 20) & 0x1f); 201 | immm4 = pc + immm4 - 4; 202 | rdid = 0; 203 | switch( ( ir >> 12 ) & 0x7 ) 204 | { 205 | // BEQ, BNE, BLT, BGE, BLTU, BGEU 206 | case 0: if( rs1 == rs2 ) pc = immm4; break; 207 | case 1: if( rs1 != rs2 ) pc = immm4; break; 208 | case 4: if( rs1 < rs2 ) pc = immm4; break; 209 | case 5: if( rs1 >= rs2 ) pc = immm4; break; //BGE 210 | case 6: if( (uint32_t)rs1 < (uint32_t)rs2 ) pc = immm4; break; //BLTU 211 | case 7: if( (uint32_t)rs1 >= (uint32_t)rs2 ) pc = immm4; break; //BGEU 212 | default: trap = (2+1); 213 | } 214 | break; 215 | } 216 | case 0x03: // Load (0b0000011) 217 | { 218 | uint32_t rs1 = REG((ir >> 15) & 0x1f); 219 | uint32_t imm = ir >> 20; 220 | int32_t imm_se = imm | (( imm & 0x800 )?0xfffff000:0); 221 | uint32_t rsval = rs1 + imm_se; 222 | 223 | rsval -= MINIRV32_RAM_IMAGE_OFFSET; 224 | if( rsval >= MINI_RV32_RAM_SIZE-3 ) 225 | { 226 | rsval += MINIRV32_RAM_IMAGE_OFFSET; 227 | if( rsval >= 0x10000000 && rsval < 0x12000000 ) // UART, CLNT 228 | { 229 | if( rsval == 0x1100bffc ) // https://chromitem-soc.readthedocs.io/en/latest/clint.html 230 | rval = CSR( timerh ); 231 | else if( rsval == 0x1100bff8 ) 232 | rval = CSR( timerl ); 233 | else 234 | MINIRV32_HANDLE_MEM_LOAD_CONTROL( rsval, rval ); 235 | } 236 | else 237 | { 238 | trap = (5+1); 239 | rval = rsval; 240 | } 241 | } 242 | else 243 | { 244 | switch( ( ir >> 12 ) & 0x7 ) 245 | { 246 | //LB, LH, LW, LBU, LHU 247 | case 0: rval = MINIRV32_LOAD1_SIGNED( rsval ); break; 248 | case 1: rval = MINIRV32_LOAD2_SIGNED( rsval ); break; 249 | case 2: rval = MINIRV32_LOAD4( rsval ); break; 250 | case 4: rval = MINIRV32_LOAD1( rsval ); break; 251 | case 5: rval = MINIRV32_LOAD2( rsval ); break; 252 | default: trap = (2+1); 253 | } 254 | } 255 | break; 256 | } 257 | case 0x23: // Store 0b0100011 258 | { 259 | uint32_t rs1 = REG((ir >> 15) & 0x1f); 260 | uint32_t rs2 = REG((ir >> 20) & 0x1f); 261 | uint32_t addy = ( ( ir >> 7 ) & 0x1f ) | ( ( ir & 0xfe000000 ) >> 20 ); 262 | if( addy & 0x800 ) addy |= 0xfffff000; 263 | addy += rs1 - MINIRV32_RAM_IMAGE_OFFSET; 264 | rdid = 0; 265 | 266 | if( addy >= MINI_RV32_RAM_SIZE-3 ) 267 | { 268 | addy += MINIRV32_RAM_IMAGE_OFFSET; 269 | if( addy >= 0x10000000 && addy < 0x12000000 ) 270 | { 271 | // Should be stuff like SYSCON, 8250, CLNT 272 | if( addy == 0x11004004 ) //CLNT 273 | CSR( timermatchh ) = rs2; 274 | else if( addy == 0x11004000 ) //CLNT 275 | CSR( timermatchl ) = rs2; 276 | else if( addy == 0x11100000 ) //SYSCON (reboot, poweroff, etc.) 277 | { 278 | SETCSR( pc, pc + 4 ); 279 | return rs2; // NOTE: PC will be PC of Syscon. 280 | } 281 | else 282 | MINIRV32_HANDLE_MEM_STORE_CONTROL( addy, rs2 ); 283 | } 284 | else 285 | { 286 | trap = (7+1); // Store access fault. 287 | rval = addy; 288 | } 289 | } 290 | else 291 | { 292 | switch( ( ir >> 12 ) & 0x7 ) 293 | { 294 | //SB, SH, SW 295 | case 0: MINIRV32_STORE1( addy, rs2 ); break; 296 | case 1: MINIRV32_STORE2( addy, rs2 ); break; 297 | case 2: MINIRV32_STORE4( addy, rs2 ); break; 298 | default: trap = (2+1); 299 | } 300 | } 301 | break; 302 | } 303 | case 0x13: // Op-immediate 0b0010011 304 | case 0x33: // Op 0b0110011 305 | { 306 | uint32_t imm = ir >> 20; 307 | imm = imm | (( imm & 0x800 )?0xfffff000:0); 308 | uint32_t rs1 = REG((ir >> 15) & 0x1f); 309 | uint32_t is_reg = !!( ir & 0x20 ); 310 | uint32_t rs2 = is_reg ? REG(imm & 0x1f) : imm; 311 | 312 | if( is_reg && ( ir & 0x02000000 ) ) 313 | { 314 | switch( (ir>>12)&7 ) //0x02000000 = RV32M 315 | { 316 | case 0: rval = rs1 * rs2; break; // MUL 317 | #ifndef CUSTOM_MULH // If compiling on a system that doesn't natively, or via libgcc support 64-bit math. 318 | case 1: rval = ((int64_t)((int32_t)rs1) * (int64_t)((int32_t)rs2)) >> 32; break; // MULH 319 | case 2: rval = ((int64_t)((int32_t)rs1) * (uint64_t)rs2) >> 32; break; // MULHSU 320 | case 3: rval = ((uint64_t)rs1 * (uint64_t)rs2) >> 32; break; // MULHU 321 | #else 322 | CUSTOM_MULH 323 | #endif 324 | case 4: if( rs2 == 0 ) rval = -1; else rval = ((int32_t)rs1 == INT32_MIN && (int32_t)rs2 == -1) ? rs1 : ((int32_t)rs1 / (int32_t)rs2); break; // DIV 325 | case 5: if( rs2 == 0 ) rval = 0xffffffff; else rval = rs1 / rs2; break; // DIVU 326 | case 6: if( rs2 == 0 ) rval = rs1; else rval = ((int32_t)rs1 == INT32_MIN && (int32_t)rs2 == -1) ? 0 : ((uint32_t)((int32_t)rs1 % (int32_t)rs2)); break; // REM 327 | case 7: if( rs2 == 0 ) rval = rs1; else rval = rs1 % rs2; break; // REMU 328 | } 329 | } 330 | else 331 | { 332 | switch( (ir>>12)&7 ) // These could be either op-immediate or op commands. Be careful. 333 | { 334 | case 0: rval = (is_reg && (ir & 0x40000000) ) ? ( rs1 - rs2 ) : ( rs1 + rs2 ); break; 335 | case 1: rval = rs1 << (rs2 & 0x1F); break; 336 | case 2: rval = (int32_t)rs1 < (int32_t)rs2; break; 337 | case 3: rval = rs1 < rs2; break; 338 | case 4: rval = rs1 ^ rs2; break; 339 | case 5: rval = (ir & 0x40000000 ) ? ( ((int32_t)rs1) >> (rs2 & 0x1F) ) : ( rs1 >> (rs2 & 0x1F) ); break; 340 | case 6: rval = rs1 | rs2; break; 341 | case 7: rval = rs1 & rs2; break; 342 | } 343 | } 344 | break; 345 | } 346 | case 0x0f: // 0b0001111 347 | rdid = 0; // fencetype = (ir >> 12) & 0b111; We ignore fences in this impl. 348 | break; 349 | case 0x73: // Zifencei+Zicsr (0b1110011) 350 | { 351 | uint32_t csrno = ir >> 20; 352 | uint32_t microop = ( ir >> 12 ) & 0x7; 353 | if( (microop & 3) ) // It's a Zicsr function. 354 | { 355 | int rs1imm = (ir >> 15) & 0x1f; 356 | uint32_t rs1 = REG(rs1imm); 357 | uint32_t writeval = rs1; 358 | 359 | // https://raw.githubusercontent.com/riscv/virtual-memory/main/specs/663-Svpbmt.pdf 360 | // Generally, support for Zicsr 361 | switch( csrno ) 362 | { 363 | case 0x340: rval = CSR( mscratch ); break; 364 | case 0x305: rval = CSR( mtvec ); break; 365 | case 0x304: rval = CSR( mie ); break; 366 | case 0xC00: rval = cycle; break; 367 | case 0x344: rval = CSR( mip ); break; 368 | case 0x341: rval = CSR( mepc ); break; 369 | case 0x300: rval = CSR( mstatus ); break; //mstatus 370 | case 0x342: rval = CSR( mcause ); break; 371 | case 0x343: rval = CSR( mtval ); break; 372 | case 0xf11: rval = 0xff0ff0ff; break; //mvendorid 373 | case 0x301: rval = 0x40401101; break; //misa (XLEN=32, IMA+X) 374 | //case 0x3B0: rval = 0; break; //pmpaddr0 375 | //case 0x3a0: rval = 0; break; //pmpcfg0 376 | //case 0xf12: rval = 0x00000000; break; //marchid 377 | //case 0xf13: rval = 0x00000000; break; //mimpid 378 | //case 0xf14: rval = 0x00000000; break; //mhartid 379 | default: 380 | MINIRV32_OTHERCSR_READ( csrno, rval ); 381 | break; 382 | } 383 | 384 | switch( microop ) 385 | { 386 | case 1: writeval = rs1; break; //CSRRW 387 | case 2: writeval = rval | rs1; break; //CSRRS 388 | case 3: writeval = rval & ~rs1; break; //CSRRC 389 | case 5: writeval = rs1imm; break; //CSRRWI 390 | case 6: writeval = rval | rs1imm; break; //CSRRSI 391 | case 7: writeval = rval & ~rs1imm; break; //CSRRCI 392 | } 393 | 394 | switch( csrno ) 395 | { 396 | case 0x340: SETCSR( mscratch, writeval ); break; 397 | case 0x305: SETCSR( mtvec, writeval ); break; 398 | case 0x304: SETCSR( mie, writeval ); break; 399 | case 0x344: SETCSR( mip, writeval ); break; 400 | case 0x341: SETCSR( mepc, writeval ); break; 401 | case 0x300: SETCSR( mstatus, writeval ); break; //mstatus 402 | case 0x342: SETCSR( mcause, writeval ); break; 403 | case 0x343: SETCSR( mtval, writeval ); break; 404 | //case 0x3a0: break; //pmpcfg0 405 | //case 0x3B0: break; //pmpaddr0 406 | //case 0xf11: break; //mvendorid 407 | //case 0xf12: break; //marchid 408 | //case 0xf13: break; //mimpid 409 | //case 0xf14: break; //mhartid 410 | //case 0x301: break; //misa 411 | default: 412 | MINIRV32_OTHERCSR_WRITE( csrno, writeval ); 413 | break; 414 | } 415 | } 416 | else if( microop == 0x0 ) // "SYSTEM" 0b000 417 | { 418 | rdid = 0; 419 | if( csrno == 0x105 ) //WFI (Wait for interrupts) 420 | { 421 | CSR( mstatus ) |= 8; //Enable interrupts 422 | CSR( extraflags ) |= 4; //Infor environment we want to go to sleep. 423 | SETCSR( pc, pc + 4 ); 424 | return 1; 425 | } 426 | else if( ( ( csrno & 0xff ) == 0x02 ) ) // MRET 427 | { 428 | //https://raw.githubusercontent.com/riscv/virtual-memory/main/specs/663-Svpbmt.pdf 429 | //Table 7.6. MRET then in mstatus/mstatush sets MPV=0, MPP=0, MIE=MPIE, and MPIE=1. La 430 | // Should also update mstatus to reflect correct mode. 431 | uint32_t startmstatus = CSR( mstatus ); 432 | uint32_t startextraflags = CSR( extraflags ); 433 | SETCSR( mstatus , (( startmstatus & 0x80) >> 4) | ((startextraflags&3) << 11) | 0x80 ); 434 | SETCSR( extraflags, (startextraflags & ~3) | ((startmstatus >> 11) & 3) ); 435 | pc = CSR( mepc ) -4; 436 | } 437 | else 438 | { 439 | switch( csrno ) 440 | { 441 | case 0: trap = ( CSR( extraflags ) & 3) ? (11+1) : (8+1); break; // ECALL; 8 = "Environment call from U-mode"; 11 = "Environment call from M-mode" 442 | case 1: trap = (3+1); break; // EBREAK 3 = "Breakpoint" 443 | default: trap = (2+1); break; // Illegal opcode. 444 | } 445 | } 446 | } 447 | else 448 | trap = (2+1); // Note micrrop 0b100 == undefined. 449 | break; 450 | } 451 | case 0x2f: // RV32A (0b00101111) 452 | { 453 | uint32_t rs1 = REG((ir >> 15) & 0x1f); 454 | uint32_t rs2 = REG((ir >> 20) & 0x1f); 455 | uint32_t irmid = ( ir>>27 ) & 0x1f; 456 | 457 | rs1 -= MINIRV32_RAM_IMAGE_OFFSET; 458 | 459 | // We don't implement load/store from UART or CLNT with RV32A here. 460 | 461 | if( rs1 >= MINI_RV32_RAM_SIZE-3 ) 462 | { 463 | trap = (7+1); //Store/AMO access fault 464 | rval = rs1 + MINIRV32_RAM_IMAGE_OFFSET; 465 | } 466 | else 467 | { 468 | rval = MINIRV32_LOAD4( rs1 ); 469 | 470 | // Referenced a little bit of https://github.com/franzflasch/riscv_em/blob/master/src/core/core.c 471 | uint32_t dowrite = 1; 472 | switch( irmid ) 473 | { 474 | case 2: //LR.W (0b00010) 475 | dowrite = 0; 476 | CSR( extraflags ) = (CSR( extraflags ) & 0x07) | (rs1<<3); 477 | break; 478 | case 3: //SC.W (0b00011) (Make sure we have a slot, and, it's valid) 479 | rval = ( CSR( extraflags ) >> 3 != ( rs1 & 0x1fffffff ) ); // Validate that our reservation slot is OK. 480 | dowrite = !rval; // Only write if slot is valid. 481 | break; 482 | case 1: break; //AMOSWAP.W (0b00001) 483 | case 0: rs2 += rval; break; //AMOADD.W (0b00000) 484 | case 4: rs2 ^= rval; break; //AMOXOR.W (0b00100) 485 | case 12: rs2 &= rval; break; //AMOAND.W (0b01100) 486 | case 8: rs2 |= rval; break; //AMOOR.W (0b01000) 487 | case 16: rs2 = ((int32_t)rs2<(int32_t)rval)?rs2:rval; break; //AMOMIN.W (0b10000) 488 | case 20: rs2 = ((int32_t)rs2>(int32_t)rval)?rs2:rval; break; //AMOMAX.W (0b10100) 489 | case 24: rs2 = (rs2rval)?rs2:rval; break; //AMOMAXU.W (0b11100) 491 | default: trap = (2+1); dowrite = 0; break; //Not supported. 492 | } 493 | if( dowrite ) MINIRV32_STORE4( rs1, rs2 ); 494 | } 495 | break; 496 | } 497 | default: trap = (2+1); // Fault: Invalid opcode. 498 | } 499 | 500 | // If there was a trap, do NOT allow register writeback. 501 | if( trap ) 502 | break; 503 | 504 | if( rdid ) 505 | { 506 | REGSET( rdid, rval ); // Write back register. 507 | } 508 | } 509 | 510 | MINIRV32_POSTEXEC( pc, ir, trap ); 511 | 512 | pc += 4; 513 | } 514 | 515 | // Handle traps and interrupts. 516 | if( trap ) 517 | { 518 | if( trap & 0x80000000 ) // If prefixed with 1 in MSB, it's an interrupt, not a trap. 519 | { 520 | SETCSR( mcause, trap ); 521 | SETCSR( mtval, 0 ); 522 | pc += 4; // PC needs to point to where the PC will return to. 523 | } 524 | else 525 | { 526 | SETCSR( mcause, trap - 1 ); 527 | SETCSR( mtval, (trap > 5 && trap <= 8)? rval : pc ); 528 | } 529 | SETCSR( mepc, pc ); //TRICKY: The kernel advances mepc automatically. 530 | //CSR( mstatus ) & 8 = MIE, & 0x80 = MPIE 531 | // On an interrupt, the system moves current MIE into MPIE 532 | SETCSR( mstatus, (( CSR( mstatus ) & 0x08) << 4) | (( CSR( extraflags ) & 3 ) << 11) ); 533 | pc = (CSR( mtvec ) - 4); 534 | 535 | // If trapping, always enter machine mode. 536 | CSR( extraflags ) |= 3; 537 | 538 | trap = 0; 539 | pc += 4; 540 | } 541 | 542 | if( CSR( cyclel ) > cycle ) CSR( cycleh )++; 543 | SETCSR( cyclel, cycle ); 544 | SETCSR( pc, pc ); 545 | return 0; 546 | } 547 | 548 | #endif 549 | 550 | #endif 551 | 552 | 553 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BugCheck2Linux 2 | Windows crashed? Dropping you into a linux shell! 3 | 4 | 5 | 6 | https://user-images.githubusercontent.com/51860844/236764849-0b6bc55e-f4ee-442f-83c7-7450ce74be49.mp4 7 | 8 | 9 | 10 | # How to run it? 11 | 12 | 1. Enable test signing and reboot 13 | 14 | ``` 15 | bcdedit /set testsigning on 16 | shutdown /r /t 0 17 | ``` 18 | 19 | 2. Create a service using SC 20 | 21 | ``` 22 | sc create BugCheck2Linux binPath=C:\where\ever\the\driver\is\BugCheck2Linux.sys type=kernel start=demand 23 | ``` 24 | 25 | 3. Run it! 26 | 27 | ``` 28 | sc start BugCheck2Linux 29 | ``` 30 | 31 | *4. In case you change your mind then unload the driver to revert the changes 32 | ``` 33 | sc stop BugCheck2Linux 34 | ``` 35 | 36 | # How does this work? 37 | We simply register a BugCheck callback. The callback function runs a [tiny RISC V emulator](https://github.com/cnlohr/mini-rv32ima) running linux. 38 | 39 | For the video output we use bootvid.dll and for input we have a ~~horrible~~ simple polling based PS/2 keyboard driver. 40 | 41 | # Limitations? 42 | 43 | * No ANSI escape sequences supported. 44 | * Runs at 640x480 with 16 colors. 45 | * Only works on BIOS systems. 46 | * Is really slow at times. 47 | * Keyboard support is poor. You will have to use CapsLock instead of Shift if you want to access special letters or capital letters. Oh also Backspace does not work. 48 | 49 | # Credits 50 | 51 | [mini-rv32ima](https://github.com/cnlohr/mini-rv32ima) for the RISC V emulator and the Linux image. 52 | 53 | [ReactOS Project](https://doxygen.reactos.org/) for providing documentations for bootvid 54 | 55 | [OSdev Wiki](https://wiki.osdev.org/%228042%22_PS/2_Controller) for providing documentations for PS/2 56 | --------------------------------------------------------------------------------