Reputation: 5541
I have Intel i5 Processor and Windows 7 operating system. I was dabbling around with the system trying to learn more about it. I realized that I do not have access to privileged instructions of the processor. For example I cannot write to Model Specific Registers and code like the following fails to execute
.model flat,stdcall
.stack 4096
.code
main proc
xor eax,eax
xor edx,edx
mov ecx,176h
wrmsr
main endp
end main
Is there a way to write applications that can make complete use of the processor and the system with all its instructions without having to write Windows device drivers?
P.S : I don't mind a system crash or file system corruption
Upvotes: 1
Views: 1035
Reputation: 1822
I assume you know what is privilege instruction and that it can only be executed in ring 0 the most privilege level of sofrware. and second assumption is that you want to play with operating system not necessarily windows which is not as good as open source OS for learning OS with code available
you have some options to try with:
write linux module and transition to privilege level and perform privilege operation there.
implement your own system call for specific purpose.
use emulators bochs, qemu simic etc to test your code with some extra effort.
Upvotes: -3
Reputation: 366036
Your best bet is to play with this stuff inside a virtual machine. If you do get a privileged instruction to run somehow, either from a device driver or some other context that executes in ring 0, you're probably going to lock up the system or worse. (Worse = corrupts your filesystem on disk).
If you want your code to run in long mode, rather than 16bit real mode, maybe start with an open-source toy OS, and put your code in right after it initializes stuff and switches out of real mode. memtest86+ is one example of a bootable program, and I think it's open source.
You'll probably want to use a bootloader like GRUB, too, to get your non-Windows toy OS loaded.
You'll probably want to look at the OSdev wiki for tutorials and guides to stuff that is normally only done by OSes, whether you consider your running-on-the-bare-metal program for playing with stuff an OS or not.
Of course, once you get something working in an emulator like bochs (which has a built-in debugger that would let you single-step whatever code you want), you might want to test it on real hardware. If grub in a VM can load it, so can grub on your real hard drive. Or syslinux on a USB flash drive would mean you didn't have to mess with your Windows install's bootloader.
Upvotes: 4