I'm interested in writing software that runs with as little booting as possible. What do I do? Is this an assembly question? Do I have to do something special with the disk the software i开发者_Go百科s to run from?
To clarify, I'm looking for a point at which stdin and stdout are available, but not much else.
If you want to run code after POST but before the OS starts, you need to either hook or replace the bootloader. There are no simple answers to the next few questions you're going to ask.
There are quite a few resources on the internet for writing your own bootloader - you might want to start with them:
- http://www.osdever.net/tutorials/hello_btldr.php?the_id=85
- http://www.codeproject.com/KB/tips/boot-loader.aspx
If you find yourself looking for a good book on x86 assembly, try:
- The Art of Assembly Language
- Introduction to 80x86 Assembly Language and Computer Architecture
A way to achive that effect might be to re-use some very limited OS like some cut-down Linux or maybe even old DOS and then having them run your code automatically at startup. But it depends on exactly why you want to do this if that solution would be suitable for you.
Edit: Or if that's not enough, I'd suggest looking at the Lilo or grub4dos or something similar to see if you can insert your code in there in some way. The forums at the Boot Land site might be useful also since they seem quite into figuring out how to customize the boot process.
Just run Linux without all the junk that distributions provide? My kernel takes 1.8 seconds to load. This is the easiest way to do it. See Linux From Scratch.
stdin and stdout are OS specific concepts, they don't exist pre-boot, (although maybe in some custom BIOS or bootloaders they do...)
The next lowest place would be the boot loader, some things are initialized at that point, but you still will have tons of work to do.
You can go even lower than that, load your own BIOS, but then you have to take care of all the non-standardized things that your BIOS takes care of.
It depends on the operating system. You have to add your program to RunOnce registry key under windows, and to init script under linux (there are various init methods under linux, so there are various methods).
Here is a simple boot loader to get you started. You will need nasm, dd, and a floppy disk.
http://www.cs.umbc.edu/courses/undergraduate/313/spring05/burt_katz/lectures/Lect11/newBootSector.html
; boot1.asm stand alone program for floppy boot sector
; Compiled using nasm -f bin boot1.asm
; Written to floppy with dd if=boot1 of=/dev/fd0
; Boot record is loaded at 0000:7C00,
ORG 7C00h
; load message address into SI register:
LEA SI,[msg]
; screen function:
MOV AH,0Eh
print: MOV AL,[SI]
CMP AL,0
JZ done ; zero byte at end of string
INT 10h ; write character to screen.
INC SI
JMP print
; wait for 'any key':
done: MOV AH,0
INT 16h ; waits for key press
; AL is ASCII code or zero
; AH is keyboard code
; store magic value at 0040h:0072h to reboot:
; 0000h - cold boot.
; 1234h - warm boot.
MOV AX,0040h
MOV DS,AX
MOV word[0072h],0000h ; cold boot.
JMP 0FFFFh:0000h ; reboot!
msg DB 'Welcome, I have control of the computer.',13,10
DB 'Press any key to reboot.',13,10
DB '(after removing the floppy)',13,10,0
; end boot1
精彩评论