In detail,
madmaxsantana wrote: |
---|
:O What the hell is that... LoL! |
By "kernel mode driver", Null was referring to a program that runs side-by-side with the operating system in "kernel mode" (aka "supervisor mode", "kernel space" or "ring 0"). A program running in ring 0 has unlimited access to hardware. Video card, hard drive and network drivers (to name a few) run in ring 0 (on a monolithic system; on other types of kernels (like microkernels) they run in userspace/usermode/userland/ring 3).
madmaxsantana wrote: |
---|
But seriously, if it is simple enough I might! |
It isn't simple at all, but it is certainly doable, and it's a fun and educational experience.
If you're thinking about doing it, you can use one of the following tutorials:
Linux:
http://tldp.org/HOWTO/Module-HOWTO/x73.html
Windows:
http://msdn.microsoft.com/en-us/library/ms809956.aspx
madmaxsantana wrote: |
---|
Is there a way I can run my programs directly through the processor without having to go through an operating system? |
Yes, but this is only achievable by writing a driver, operating system or bootsector program. All of those are quite complicated. The bootsector program is probably the simplest in theory, but it gets quickly complicated because you have to write everything in assembly language, and it all needs to fit into 512 bytes. If you want to use C/C++ and/or you need more than 512 bytes (there really isn't alot you can do with that much, and if you want to use C or C++, 512 bytes won't be enough) then you have to
1. Read a file from the hard disk (easy part, since the BIOS does this much for you)
2. Load and arrange an executable file into memory (difficult to do in just assembly)
3. Switch to protected mode or unreal mode (so that the C code can use 32-bit instructions) or long mode (for 64 bits)
4. Jump to the program.
And you get 512 bytes of code and less than 1 MiB of memory to work with. I think the best way is to do it in three stages (the first stage is located in the boot sector, it loads the second stage (which can be larger than 512 bytes; 4 kiB is a good size) which contains a loader for a simple executable file (such as a.out) that can load the third stage, which is your program) but that is way too complicated just for a normal program, and is the kind of thing you would do when writing an operating system (or you could do the smart thing and just use GRUB).
madmaxsantana wrote: |
---|
I once thought about writing my program to the boot sector of a floppy drive and booting my system with it. |
You'd have to compile it as a flat binary file, it would have to be exactly 512 bytes long, and the last two bytes would have to be the value "0xaa55". Once you've done that, you have to make your code perform a "segment jump" to 0x7c00 (which is where the BIOS loads the program), set up a stack pointer (usually, the stack starts at 0x9c00, which is right after your program in memory) and then you're good. Except it has to fit into 512 bytes, hence the suggestion of using stages like GRUB and other boot managers do.
madmaxsantana wrote: |
---|
But my computer didn't have a floppy drive. I couldn't waste a CD just for a small program and I didn't know how to write a program to the boot sector of a USB... |
This can be solved by using an emulator like Qemu or Bochs.
madmaxsantana wrote: |
---|
But in case that is possible, I would certainly like to try that. It should be fun... Running an "a=b+c" with 99.999999% of the processor power going waste. :p |
It doesn't matter. When your program is running it has 100% of the CPU's processing power at it's disposal (unless you're using SMP, in which case it gets between (l
p / 100)% and 100% of the CPU's power, where l
p is the number of logical processors present). There are no other programs running (again, unless you're using multiprocessing). The OS switches between your program and all the other programs running by setting a timer to periodically "wake" the OS so that it can switch programs.