⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boot.txt

📁 linux 内核源代码
💻 TXT
📖 第 1 页 / 共 2 页
字号:
Field name:	ramdisk_sizeType:		write (obligatory)Offset/size:	0x21c/4Protocol:	2.00+  Size of the initial ramdisk or ramfs.  Leave at zero if there is no  initial ramdisk/ramfs.Field name:	bootsect_kludgeType:		kernel internalOffset/size:	0x220/4Protocol:	2.00+  This field is obsolete.Field name:	heap_end_ptrType:		write (obligatory)Offset/size:	0x224/2Protocol:	2.01+  Set this field to the offset (from the beginning of the real-mode  code) of the end of the setup stack/heap, minus 0x0200.Field name:	cmd_line_ptrType:		write (obligatory)Offset/size:	0x228/4Protocol:	2.02+  Set this field to the linear address of the kernel command line.  The kernel command line can be located anywhere between the end of  the setup heap and 0xA0000; it does not have to be located in the  same 64K segment as the real-mode code itself.  Fill in this field even if your boot loader does not support a  command line, in which case you can point this to an empty string  (or better yet, to the string "auto".)  If this field is left at  zero, the kernel will assume that your boot loader does not support  the 2.02+ protocol.Field name:	initrd_addr_maxType:		readOffset/size:	0x22c/4Protocol:	2.03+  The maximum address that may be occupied by the initial  ramdisk/ramfs contents.  For boot protocols 2.02 or earlier, this  field is not present, and the maximum address is 0x37FFFFFF.  (This  address is defined as the address of the highest safe byte, so if  your ramdisk is exactly 131072 bytes long and this field is  0x37FFFFFF, you can start your ramdisk at 0x37FE0000.)Field name:	kernel_alignmentType:		read (reloc)Offset/size:	0x230/4Protocol:	2.05+  Alignment unit required by the kernel (if relocatable_kernel is true.)Field name:	relocatable_kernelType:		read (reloc)Offset/size:	0x234/1Protocol:	2.05+  If this field is nonzero, the protected-mode part of the kernel can  be loaded at any address that satisfies the kernel_alignment field.  After loading, the boot loader must set the code32_start field to  point to the loaded code, or to a boot loader hook.Field name:	cmdline_sizeType:		readOffset/size:	0x238/4Protocol:	2.06+  The maximum size of the command line without the terminating  zero. This means that the command line can contain at most  cmdline_size characters. With protocol version 2.05 and earlier, the  maximum size was 255.Field name:	hardware_subarchType:		writeOffset/size:	0x23c/4Protocol:	2.07+  In a paravirtualized environment the hardware low level architectural  pieces such as interrupt handling, page table handling, and  accessing process control registers needs to be done differently.  This field allows the bootloader to inform the kernel we are in one  one of those environments.  0x00000000	The default x86/PC environment  0x00000001	lguest  0x00000002	XenField name:	hardware_subarch_dataType:		writeOffset/size:	0x240/8Protocol:	2.07+  A pointer to data that is specific to hardware subarch**** THE KERNEL COMMAND LINEThe kernel command line has become an important way for the bootloader to communicate with the kernel.  Some of its options are alsorelevant to the boot loader itself, see "special command line options"below.The kernel command line is a null-terminated string. The maximumlength can be retrieved from the field cmdline_size.  Before protocolversion 2.06, the maximum was 255 characters.  A string that is toolong will be automatically truncated by the kernel.If the boot protocol version is 2.02 or later, the address of thekernel command line is given by the header field cmd_line_ptr (seeabove.)  This address can be anywhere between the end of the setupheap and 0xA0000.If the protocol version is *not* 2.02 or higher, the kernelcommand line is entered using the following protocol:	At offset 0x0020 (word), "cmd_line_magic", enter the magic	number 0xA33F.	At offset 0x0022 (word), "cmd_line_offset", enter the offset	of the kernel command line (relative to the start of the	real-mode kernel).		The kernel command line *must* be within the memory region	covered by setup_move_size, so you may need to adjust this	field.**** MEMORY LAYOUT OF THE REAL-MODE CODEThe real-mode code requires a stack/heap to be set up, as well asmemory allocated for the kernel command line.  This needs to be donein the real-mode accessible memory in bottom megabyte.It should be noted that modern machines often have a sizable ExtendedBIOS Data Area (EBDA).  As a result, it is advisable to use as littleof the low megabyte as possible.Unfortunately, under the following circumstances the 0x90000 memorysegment has to be used:	- When loading a zImage kernel ((loadflags & 0x01) == 0).	- When loading a 2.01 or earlier boot protocol kernel.	  -> For the 2.00 and 2.01 boot protocols, the real-mode code	     can be loaded at another address, but it is internally	     relocated to 0x90000.  For the "old" protocol, the	     real-mode code must be loaded at 0x90000.When loading at 0x90000, avoid using memory above 0x9a000.For boot protocol 2.02 or higher, the command line does not have to belocated in the same 64K segment as the real-mode setup code; it isthus permitted to give the stack/heap the full 64K segment and locatethe command line above it.The kernel command line should not be located below the real-modecode, nor should it be located in high memory.**** SAMPLE BOOT CONFIGURATIONAs a sample configuration, assume the following layout of the realmode segment:    When loading below 0x90000, use the entire segment:	0x0000-0x7fff	Real mode kernel	0x8000-0xdfff	Stack and heap	0xe000-0xffff	Kernel command line    When loading at 0x90000 OR the protocol version is 2.01 or earlier:	0x0000-0x7fff	Real mode kernel	0x8000-0x97ff	Stack and heap	0x9800-0x9fff	Kernel command lineSuch a boot loader should enter the following fields in the header:	unsigned long base_ptr;	/* base address for real-mode segment */	if ( setup_sects == 0 ) {		setup_sects = 4;	}	if ( protocol >= 0x0200 ) {		type_of_loader = <type code>;		if ( loading_initrd ) {			ramdisk_image = <initrd_address>;			ramdisk_size = <initrd_size>;		}		if ( protocol >= 0x0202 && loadflags & 0x01 )			heap_end = 0xe000;		else			heap_end = 0x9800;		if ( protocol >= 0x0201 ) {			heap_end_ptr = heap_end - 0x200;			loadflags |= 0x80; /* CAN_USE_HEAP */		}		if ( protocol >= 0x0202 ) {			cmd_line_ptr = base_ptr + heap_end;			strcpy(cmd_line_ptr, cmdline);		} else {			cmd_line_magic	= 0xA33F;			cmd_line_offset = heap_end;			setup_move_size = heap_end + strlen(cmdline)+1;			strcpy(base_ptr+cmd_line_offset, cmdline);		}	} else {		/* Very old kernel */		heap_end = 0x9800;		cmd_line_magic	= 0xA33F;		cmd_line_offset = heap_end;		/* A very old kernel MUST have its real-mode code		   loaded at 0x90000 */		if ( base_ptr != 0x90000 ) {			/* Copy the real-mode kernel */			memcpy(0x90000, base_ptr, (setup_sects+1)*512);			base_ptr = 0x90000;		 /* Relocated */		}		strcpy(0x90000+cmd_line_offset, cmdline);		/* It is recommended to clear memory up to the 32K mark */		memset(0x90000 + (setup_sects+1)*512, 0,		       (64-(setup_sects+1))*512);	}**** LOADING THE REST OF THE KERNELThe 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512in the kernel file (again, if setup_sects == 0 the real value is 4.)It should be loaded at address 0x10000 for Image/zImage kernels and0x100000 for bzImage kernels.The kernel is a bzImage kernel if the protocol >= 2.00 and the 0x01bit (LOAD_HIGH) in the loadflags field is set:	is_bzImage = (protocol >= 0x0200) && (loadflags & 0x01);	load_address = is_bzImage ? 0x100000 : 0x10000;Note that Image/zImage kernels can be up to 512K in size, and thus usethe entire 0x10000-0x90000 range of memory.  This means it is prettymuch a requirement for these kernels to load the real-mode part at0x90000.  bzImage kernels allow much more flexibility.**** SPECIAL COMMAND LINE OPTIONSIf the command line provided by the boot loader is entered by theuser, the user may expect the following command line options to work.They should normally not be deleted from the kernel command line eventhough not all of them are actually meaningful to the kernel.  Bootloader authors who need additional command line options for the bootloader itself should get them registered inDocumentation/kernel-parameters.txt to make sure they will notconflict with actual kernel options now or in the future.  vga=<mode>	<mode> here is either an integer (in C notation, either	decimal, octal, or hexadecimal) or one of the strings	"normal" (meaning 0xFFFF), "ext" (meaning 0xFFFE) or "ask"	(meaning 0xFFFD).  This value should be entered into the	vid_mode field, as it is used by the kernel before the command	line is parsed.  mem=<size>	<size> is an integer in C notation optionally followed by	(case insensitive) K, M, G, T, P or E (meaning << 10, << 20,	<< 30, << 40, << 50 or << 60).  This specifies the end of	memory to the kernel. This affects the possible placement of	an initrd, since an initrd should be placed near end of	memory.  Note that this is an option to *both* the kernel and	the bootloader!  initrd=<file>	An initrd should be loaded.  The meaning of <file> is	obviously bootloader-dependent, and some boot loaders	(e.g. LILO) do not have such a command.In addition, some boot loaders add the following options to theuser-specified command line:  BOOT_IMAGE=<file>	The boot image which was loaded.  Again, the meaning of <file>	is obviously bootloader-dependent.  auto	The kernel was booted without explicit user intervention.If these options are added by the boot loader, it is highlyrecommended that they are located *first*, before the user-specifiedor configuration-specified command line.  Otherwise, "init=/bin/sh"gets confused by the "auto" option.**** RUNNING THE KERNELThe kernel is started by jumping to the kernel entry point, which islocated at *segment* offset 0x20 from the start of the real modekernel.  This means that if you loaded your real-mode kernel code at0x90000, the kernel entry point is 9020:0000.At entry, ds = es = ss should point to the start of the real-modekernel code (0x9000 if the code is loaded at 0x90000), sp should beset up properly, normally pointing to the top of the heap, andinterrupts should be disabled.  Furthermore, to guard against bugs inthe kernel, it is recommended that the boot loader sets fs = gs = ds =es = ss.In our example from above, we would do:	/* Note: in the case of the "old" kernel protocol, base_ptr must	   be == 0x90000 at this point; see the previous sample code */	seg = base_ptr >> 4;	cli();	/* Enter with interrupts disabled! */	/* Set up the real-mode kernel stack */	_SS = seg;	_SP = heap_end;	_DS = _ES = _FS = _GS = seg;	jmp_far(seg+0x20, 0);	/* Run the kernel */If your boot sector accesses a floppy drive, it is recommended toswitch off the floppy motor before running the kernel, since thekernel boot leaves interrupts off and thus the motor will not beswitched off, especially if the loaded kernel has the floppy driver asa demand-loaded module!**** ADVANCED BOOT LOADER HOOKSIf the boot loader runs in a particularly hostile environment (such asLOADLIN, which runs under DOS) it may be impossible to follow thestandard memory location requirements.  Such a boot loader may use thefollowing hooks that, if set, are invoked by the kernel at theappropriate time.  The use of these hooks should probably beconsidered an absolutely last resort!IMPORTANT: All the hooks are required to preserve %esp, %ebp, %esi and%edi across invocation.  realmode_swtch:	A 16-bit real mode far subroutine invoked immediately before	entering protected mode.  The default routine disables NMI, so	your routine should probably do so, too.  code32_start:	A 32-bit flat-mode routine *jumped* to immediately after the	transition to protected mode, but before the kernel is	uncompressed.  No segments, except CS, are guaranteed to be	set up (current kernels do, but older ones do not); you should	set them up to BOOT_DS (0x18) yourself.	After completing your hook, you should jump to the address	that was in this field before your boot loader overwrote it	(relocated, if appropriate.)**** 32-bit BOOT PROTOCOLFor machine with some new BIOS other than legacy BIOS, such as EFI,LinuxBIOS, etc, and kexec, the 16-bit real mode setup code in kernelbased on legacy BIOS can not be used, so a 32-bit boot protocol needsto be defined.In 32-bit boot protocol, the first step in loading a Linux kernelshould be to setup the boot parameters (struct boot_params,traditionally known as "zero page"). The memory for struct boot_paramsshould be allocated and initialized to all zero. Then the setup headerfrom offset 0x01f1 of kernel image on should be loaded into structboot_params and examined. The end of setup header can be calculated asfollow:	0x0202 + byte value at offset 0x0201In addition to read/modify/write the setup header of the structboot_params as that of 16-bit boot protocol, the boot loader shouldalso fill the additional fields of the struct boot_params as thatdescribed in zero-page.txt.After setupping the struct boot_params, the boot loader can load the32/64-bit kernel in the same way as that of 16-bit boot protocol.In 32-bit boot protocol, the kernel is started by jumping to the32-bit kernel entry point, which is the start address of loaded32/64-bit kernel.At entry, the CPU must be in 32-bit protected mode with pagingdisabled; a GDT must be loaded with the descriptors for selectors__BOOT_CS(0x10) and __BOOT_DS(0x18); both descriptors must be 4G flatsegment; __BOOS_CS must have execute/read permission, and __BOOT_DSmust have read/write permission; CS must be __BOOT_CS and DS, ES, SSmust be __BOOT_DS; interrupt must be disabled; %esi must hold the baseaddress of the struct boot_params; %ebp, %edi and %ebx must be zero.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -