锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 濡傛灉闇瑕侀綣佺殑鎿嶄綔鏂囦歡錛屽垯闇瑕佷竴涓被鏉ラ暱鏈熸寔鏈夊彞鏌勶紝閬垮厤緇忓父鎬х殑鎵撳紑鍜屽叧闂枃浠訛紝鏁呮寮曞叆FileInfo綾匯侳ileInfo鎵цAppend絳夋搷浣滄椂錛?wbr>閮芥槸浣跨敤浜嬪厛鎵撳紑鐨勬枃浠跺彞鏌勩?
涓嬭澆鍦板潃錛?br>http://www.shnenglu.com/Files/huyi/kanji.rar
浣跨敤鏂瑰紡錛?br>閫変腑涓嶇煡閬撹闊崇殑鏃ユ枃姹夊瓧錛堜腑鍥芥眽瀛楁棤鏁堬級(jí)錛岀劧鍚嶤trl+C鍗沖彲銆傚湪緋葷粺鎵樼洏鍥炬爣涓婄偣鍑誨乏閿紝鍙互鎵撳紑鍏抽棴鐩戣鍔熻兘銆?br>
杞歡鎴睆:
2007騫?鏈?1鏃?br>鏀懼嚭1.5鐗堬紝鏀瑰姩濡備笅錛?br>1.緹庡寲浜?jiǎn)鐣岄潰锛屾敼杩涗簡(jiǎn)鍓嶄竴鐗堟湰涓樉紺洪敊浣嶇殑闂銆?br>2.3縐掑悗鏌ヨ紿楀彛鑷姩灝忔椂銆?br>3.鍋氫簡(jiǎn)閮ㄥ垎榪囨護(hù)錛岃兘榪囨護(hù)鎺夎澶氶潪鏃ユ枃姹夊瓧鐨勪笢瑗褲?br>4.宸﹂敭榛樿绔嬪嵆鍏抽棴紿楀彛錛屽彸閿畾浣忕獥鍙o紝浣夸箣涓嶄細(xì)鑷姩娑堝け銆?br>鏂扮殑鎴浘灝變笉鏀懼嚭浜?jiǎn)锛屾諱箣婕備寒浜?jiǎn)寰堝锛屽笇鏈涘ぇ瀹毒lх畫鏀寔銆?br>
]]>
{
聽(tīng)聽(tīng)聽(tīng) ......
}
for_each(books.begin(), books.end(), std::bind1st(mem_fun(&CBookEditDlg::ForEachBookFunctor), this));
鍏抽敭鐐瑰湪浜巑em_fun鍜宐ind1st鐨勪嬌鐢ㄣ?br />
for_each鐨勫疄鐜頒腑鏈鏍稿績(jī)鐨勪竴涓皟鐢細(xì)functor(*iterater);
鐢變簬綾婚潪闈?rùn)鎬佹垚鍛樺嚱鏁幫紝蹇呴』鍦ㄥ疄渚嬩笂璋冪敤錛?instance->*pfn)(params);
鎵浠or_each鏃犳硶鐩存帴浣跨敤浼犺繃鍘葷殑鍑芥暟鍦板潃錛屽嚱鏁版寚閽堢殑絎竴涓弬鏁版槸綾葷殑涓涓疄渚嬫寚閽堬紙this鎸囬拡)錛屾墍浠ュ繀欏繪兂鍔炴硶鎶婅繖涓寚閽堜紶榪囧幓錛堜嬌鐢╯td::bind1st錛?br />
鍏充簬mem_fun鐨勪竴浜涜祫鏂欙紝璇峰弬鑰?br />http://www.stlchina.org/documents/EffectiveSTL/files/item_41.html
瀵逛簬甯︿袱涓互涓婂弬鏁扮殑鎴愬憳鍑芥暟錛岀敤stl鏄笉鑳借揪鍒扮洰鐨勭殑錛屽洜涓簃em_fun鍙兘鐢熸垚涓嶅甫鍙傛暟錛屾垨鑰呮槸浠呭甫涓涓弬鏁扮殑鍑芥暟瀵硅薄錛坒unctor)錛宐ind1st鍜宐ind2st涔熷彧鑳藉絎竴涓垨鑰呮槸絎簩涓弬鏁拌繘琛岀粦瀹氥?br />瑕佸疄鐜板浠繪剰鏁伴噺鍙傛暟鐨勬垚鍛樺嚱鏁扮敓鎴恌unctor錛屽繀欏誨stl榪涜鎵╁睍錛屾墍騫竍oost宸茬粡鍋氬埌浜?jiǎn)杩欑偣锛宐oost::bind鍜宐oost::mem_fn灝辨槸鏇村姞娉涘寲鐨剆td::bind1st鍜宻td::mem_func
聽(tīng)聽(tīng)聽(tīng) void ForEachClassFunctor(Class c, CTreeItem treeItem)
聽(tīng)聽(tīng)聽(tīng) {
聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) treeView.InsertItem(c.name.c_str(), treeItem, NULL);
聽(tīng)聽(tīng)聽(tīng) }
聽(tīng)聽(tīng)聽(tīng) void ForEachBookFunctor(Book book)
聽(tīng)聽(tīng) 聽(tīng){
聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) 聽(tīng)CTreeItem treeItem = treeView.InsertItem(book.name.c_str(), NULL, NULL);
聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) 聽(tīng)vector<Class> v;
聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) 聽(tīng)v.push_back(Class(0,0,"nameClass1", "titleClass1"));
聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) 聽(tīng)for_each(v.begin(), v.end(),
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) boost::bind(boost::mem_fn(&CBookEditDlg::ForEachClassFunctor), this, _1, treeItem));
聽(tīng)聽(tīng) 聽(tīng)}
]]>
鎴戠◢寰敼榪涗簡(jiǎn)涓涓?
聽(tīng)聽(tīng)聽(tīng) static WCHAR* UTF82Unicode(WCHAR* pBuffer,char *pSource, int buff_size)
聽(tīng)聽(tīng)聽(tīng) {
聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) int i, j, max;
聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) char* uchar = (char *)pBuffer;
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) max = buff_size - 2;
聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) for(i = 0, j = 0; pSource[j] != '\0'; i += 2, j += 3)
聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) {
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) if (i > max) {
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) break;
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) }
聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) uchar[i+1] = ((pSource[j] & 0x0F) << 4) + ((pSource[j+1] >> 2) & 0x0F);
聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) uchar[i] = ((pSource[j+1] & 0x03) << 6) + (pSource[j+2] & 0x3F);
聽(tīng)聽(tīng)聽(tīng) 聽(tīng)聽(tīng)聽(tīng) }
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) uchar[i] = '\0';
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) uchar[i+1] = '\0';
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) return pBuffer;
聽(tīng)聽(tīng)聽(tīng) }
鍦╓indows涓殑璇濓紝榪樻湁鏇寸畝鍗曠殑鏂規(guī)硶瀹屾垚杞崲錛?br />姣斿浠嶶TF-8鍒癠nicode:
聽(tīng)聽(tīng)聽(tīng) WCHAR buff[255];
聽(tīng)聽(tīng)聽(tīng) MultiByteToWideChar(CP_UTF8, 0, argv[i], -1, buff, sizeof(buff));
聽(tīng)聽(tīng)聽(tīng) item.name = W2A(buff);
argv[i]鏄杞崲鐨勫瓧鑺傛暟緇?img src ="http://www.shnenglu.com/huyi/aggbug/16734.html" width = "1" height = "1" />
]]>
File鐨凮pen絳夋柟娉曞彲浠ュ垱寤洪拡瀵規(guī)寚瀹氭枃浠惰鍐欑殑嫻佸璞ileStream錛屽彞鏌勭敱FileStream鑷繁鍒涘緩鍜屾寔鏈夌鐞嗭紝File::Open鍙槸浼?wbr>杈捐礬寰勪俊鎭?
鍙互鎶奆ile鐪嬩綔鏄竴涓棬闈紝闆嗕腑浜?jiǎn)瀵规枃錃g鐨勬墍鏈夋搷浣滐紝騫朵笖涓嶉渶瑕佸垱寤篎ile瀵硅薄灝卞彲浠ョ洿鎺ユ墽琛岃繖浜涙搷浣溿傛墍浠ヨFile涓烘枃浠剁殑鍗曚竴鎿嶄綔鎻愪緵浜?jiǎn)蹇嶏L(fēng)畝渚跨殑
闄や簡(jiǎn)鍑犱釜鍒涘緩FileStream嫻佺殑鎿嶄綔澶栵紝鍏朵粬鎿嶄綔閮戒笉浼?xì)闀挎湡鍗犵敤鍙ユ焺璧勬簮锛岄伒弩@"鍙ユ焺鍒涘緩-鎵ц鍏蜂綋鎿嶄綔-閲婃斁鍙ユ焺"鐨勬楠ゃ?
鍚屾椂錛孎ileInfo涔熷彲浠ュ垱寤篎ileStream瀹炰緥錛屼絾榪欎釜鏃跺欙紝鏂囦歡鐨勫彞鏌勭敓鍛藉懆鏈熷簲璇ョ敱FileInfo鏉ョ鐞嗭紝FileStream鍙互浣跨敤榪欎釜
榪欑鎯呭喌涓嬶紝FileInfo鎵鍒涘緩鐨凢ileStream::Close()鐨勮涓哄拰鍓嶉潰File鎵鍒涘緩鐨凢ileStream::Close()琛屼負(fù)鏈夊樊寮?wbr>銆傚洜涓篎ile騫朵笉鎸佹湁鍙ユ焺錛屾墍浠ュ畠鍒涘緩浜?jiǎn)FileStream瀵硅薄鍚庯紝鍙ユ焺搴旇鐢盕ileStream鏉ョ鐞嗐備絾FileInfo鎵鍒涘緩鐨凢ileStrea
瀹炵幇絳栫暐錛?
1.浣跨敤鍩轟簬緇ф壙鐨勫鎬佹垨鍩轟簬妯℃澘鐨勯潤(rùn)澶氭併?
2.浣跨敤鍑芥暟鍥炶皟銆傛妸Close鍋氭垚璋冪敤鍑芥暟鎸囬拡錛岄氳繃涓嶅悓鐨凢ileStream鏋勯犲嚱鏁拌皟鐢紝鏉ヨ緗寚閽堟寚鍚戜笉鍚岀殑Close鍑芥暟瀹炵幇銆傦紙鍏抽棴鍙ユ焺鎴栦笉鍏抽棴
榪欎袱縐嶅仛娉曠殑浼樺姡鎬ф鍦ㄨ冭瘉涓紝璇鋒彁鍑烘剰瑙併?
琛ュ厖錛欶ile鍜孎ileInfo鐨勫叧緋誨湪dotnet涓篃鏈変綋鐜幫紝涓嶈繃浠栦滑涓昏鏄粠閿欒媯(gè)嫻嬫柟闈㈣冭檻銆?br />鏈緇堢殑鐩殑鏄涓哄鎴鋒彁渚涗竴涓粺涓鐨勭晫闈紝鎵浠ヤ笉鑳界敤澶鏉傜殑妯℃澘銆?br />
緇忚繃鎱庨噸鑰冭檻錛屾垜榪樻槸鍐沖畾鐢ㄨ櫄鍑芥暟錛屾斁寮冧簡(jiǎn)妯℃澘銆?br />
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) H. Peter Anvin <hpa@zytor.com>
聽(tīng)聽(tīng)聽(tīng)Last update 2005-09-02
On the i386 platform, the Linux kernel uses a rather complicated boot
convention.聽(tīng) This has evolved partially due to historical aspects, as
well as the desire in the early days to have the kernel itself be a
bootable image, the complicated PC memory model and due to changed
expectations in the PC industry caused by the effective demise of
real-mode DOS as a mainstream operating system.
Currently, four versions of the Linux/i386 boot protocol exist.
Old kernels:聽(tīng)zImage/Image support only.聽(tīng) Some very early kernels
聽(tīng)聽(tīng)may not even support a command line.
Protocol 2.00:聽(tīng)(Kernel 1.3.73) Added bzImage and initrd support, as
聽(tīng)聽(tīng)well as a formalized way to communicate between the
聽(tīng)聽(tīng)boot loader and the kernel.聽(tīng) setup.S made relocatable,
聽(tīng)聽(tīng)although the traditional setup area still assumed
聽(tīng)聽(tīng)writable.
Protocol 2.01:聽(tīng)(Kernel 1.3.76) Added a heap overrun warning.
Protocol 2.02:聽(tīng)(Kernel 2.4.0-test3-pre3) New command line protocol.
聽(tīng)聽(tīng)Lower the conventional memory ceiling.聽(tīng)No overwrite
聽(tīng)聽(tīng)of the traditional setup area, thus making booting
聽(tīng)聽(tīng)safe for systems which use the EBDA from SMM or 32-bit
聽(tīng)聽(tīng)BIOS entry points.聽(tīng) zImage deprecated but still
聽(tīng)聽(tīng)supported.
Protocol 2.03:聽(tīng)(Kernel 2.4.18-pre1) Explicitly makes the highest possible
聽(tīng)聽(tīng)initrd address available to the bootloader.
Protocol 2.04:聽(tīng)(Kernel 2.6.14) Extend the syssize field to four bytes.
**** MEMORY LAYOUT
The traditional memory map for the kernel loader, used for Image or
zImage kernels, typically looks like:
聽(tīng)|聽(tīng)聽(tīng)聽(tīng) |
0A0000聽(tīng)+------------------------+
聽(tīng)|聽(tīng) Reserved for BIOS聽(tīng) |聽(tīng)Do not use.聽(tīng) Reserved for BIOS EBDA.
09A000聽(tīng)+------------------------+
聽(tīng)|聽(tīng) Stack/heap/cmdline聽(tīng) |聽(tīng)For use by the kernel real-mode code.
098000聽(tīng)+------------------------+聽(tīng)
聽(tīng)|聽(tīng) Kernel setup聽(tīng)聽(tīng) |聽(tīng)The kernel real-mode code.
090200聽(tīng)+------------------------+
聽(tīng)|聽(tīng) Kernel boot sector聽(tīng) |聽(tīng)The kernel legacy boot sector.
090000聽(tīng)+------------------------+
聽(tīng)|聽(tīng) Protected-mode kernel |聽(tīng)The bulk of the kernel image.
010000聽(tīng)+------------------------+
聽(tīng)|聽(tīng) Boot loader聽(tīng)聽(tīng) |聽(tīng)<- Boot sector entry point 0000:7C00
001000聽(tīng)+------------------------+
聽(tīng)|聽(tīng) Reserved for MBR/BIOS |
000800聽(tīng)+------------------------+
聽(tīng)|聽(tīng) Typically used by MBR |
000600聽(tīng)+------------------------+
聽(tīng)|聽(tīng) BIOS use only聽(tīng) |
000000聽(tīng)+------------------------+
When using bzImage, the protected-mode kernel was relocated to
0x100000 ("high memory"), and the kernel real-mode block (boot sector,
setup, and stack/heap) was made relocatable to any address between
0x10000 and end of low memory.聽(tīng)Unfortunately, in protocols 2.00 and
2.01 the command line is still required to live in the 0x9XXXX memory
range, and that memory range is still overwritten by the early kernel.
The 2.02 protocol resolves that problem.
It is desirable to keep the "memory ceiling" -- the highest point in
low memory touched by the boot loader -- as low as possible, since
some newer BIOSes have begun to allocate some rather large amounts of
memory, called the Extended BIOS Data Area, near the top of low
memory.聽(tīng) The boot loader should use the "INT 12h" BIOS call to verify
how much low memory is available.
Unfortunately, if INT 12h reports that the amount of memory is too
low, there is usually nothing the boot loader can do but to report an
error to the user.聽(tīng) The boot loader should therefore be designed to
take up as little space in low memory as it reasonably can.聽(tīng) For
zImage or old bzImage kernels, which need data written into the
0x90000 segment, the boot loader should make sure not to use memory
above the 0x9A000 point; too many BIOSes will break above that point.
**** THE REAL-MODE KERNEL HEADER
In the following text, and anywhere in the kernel boot sequence, "a
sector" refers to 512 bytes.聽(tīng) It is independent of the actual sector
size of the underlying medium.
The first step in loading a Linux kernel should be to load the
real-mode code (boot sector and setup code) and then examine the
following header at offset 0x01f1.聽(tīng) The real-mode code can total up to
32K, although the boot loader may choose to load only the first two
sectors (1K) and then examine the bootup sector size.
The header looks like:
Offset聽(tīng)Proto聽(tīng)Name聽(tīng)聽(tīng)Meaning
/Size
01F1/1聽(tīng)ALL(1聽(tīng)setup_sects聽(tīng)The size of the setup in sectors
01F2/2聽(tīng)ALL聽(tīng)root_flags聽(tīng)I(yíng)f set, the root is mounted readonly
01F4/4聽(tīng)2.04+(2聽(tīng)syssize聽(tīng)聽(tīng)The size of the 32-bit code in 16-byte paras
01F8/2聽(tīng)ALL聽(tīng)ram_size聽(tīng)DO NOT USE - for bootsect.S use only
01FA/2聽(tīng)ALL聽(tīng)vid_mode聽(tīng)Video mode control
01FC/2聽(tīng)ALL聽(tīng)root_dev聽(tīng)Default root device number
01FE/2聽(tīng)ALL聽(tīng)boot_flag聽(tīng)0xAA55 magic number
0200/2聽(tīng)2.00+聽(tīng)jump聽(tīng)聽(tīng)Jump instruction
0202/4聽(tīng)2.00+聽(tīng)header聽(tīng)聽(tīng)Magic signature "HdrS"
0206/2聽(tīng)2.00+聽(tīng)version聽(tīng)聽(tīng)Boot protocol version supported
0208/4聽(tīng)2.00+聽(tīng)realmode_swtch聽(tīng)Boot loader hook (see below)
020C/2聽(tīng)2.00+聽(tīng)start_sys聽(tīng)The load-low segment (0x1000) (obsolete)
020E/2聽(tīng)2.00+聽(tīng)kernel_version聽(tīng)Pointer to kernel version string
0210/1聽(tīng)2.00+聽(tīng)type_of_loader聽(tīng)Boot loader identifier
0211/1聽(tīng)2.00+聽(tīng)loadflags聽(tīng)Boot protocol option flags
0212/2聽(tīng)2.00+聽(tīng)setup_move_size聽(tīng)Move to high memory size (used with hooks)
0214/4聽(tīng)2.00+聽(tīng)code32_start聽(tīng)Boot loader hook (see below)
0218/4聽(tīng)2.00+聽(tīng)ramdisk_image聽(tīng)initrd load address (set by boot loader)
021C/4聽(tīng)2.00+聽(tīng)ramdisk_size聽(tīng)initrd size (set by boot loader)
0220/4聽(tīng)2.00+聽(tīng)bootsect_kludge聽(tīng)DO NOT USE - for bootsect.S use only
0224/2聽(tīng)2.01+聽(tīng)heap_end_ptr聽(tīng)Free memory after setup end
0226/2聽(tīng)N/A聽(tīng)pad1聽(tīng)聽(tīng)Unused
0228/4聽(tīng)2.02+聽(tīng)cmd_line_ptr聽(tīng)32-bit pointer to the kernel command line
022C/4聽(tīng)2.03+聽(tīng)initrd_addr_max聽(tīng)Highest legal initrd address
(1) For backwards compatibility, if the setup_sects field contains 0, the
聽(tīng)聽(tīng)聽(tīng) real value is 4.
(2) For boot protocol prior to 2.04, the upper two bytes of the syssize
聽(tīng)聽(tīng)聽(tīng) field are unusable, which means the size of a bzImage kernel
聽(tīng)聽(tīng)聽(tīng) cannot be determined.
If the "HdrS" (0x53726448) magic number is not found at offset 0x202,
the boot protocol version is "old".聽(tīng) Loading an old kernel, the
following parameters should be assumed:
聽(tīng)I(yíng)mage type = zImage
聽(tīng)initrd not supported
聽(tīng)Real-mode kernel must be located at 0x90000.
Otherwise, the "version" field contains the protocol version,
e.g. protocol version 2.01 will contain 0x0201 in this field.聽(tīng) When
setting fields in the header, you must make sure only to set fields
supported by the protocol version in use.
The "kernel_version" field, if set to a nonzero value, contains a
pointer to a null-terminated human-readable kernel version number
string, less 0x200.聽(tīng) This can be used to display the kernel version to
the user.聽(tīng) This value should be less than (0x200*setup_sects).聽(tīng) For
example, if this value is set to 0x1c00, the kernel version number
string can be found at offset 0x1e00 in the kernel file.聽(tīng) This is a
valid value if and only if the "setup_sects" field contains the value
14 or higher.
Most boot loaders will simply load the kernel at its target address
directly.聽(tīng) Such boot loaders do not need to worry about filling in
most of the fields in the header.聽(tīng) The following fields should be
filled out, however:
聽(tīng) vid_mode:
聽(tīng)Please see the section on SPECIAL COMMAND LINE OPTIONS.
聽(tīng) type_of_loader:
聽(tīng)I(yíng)f your boot loader has an assigned id (see table below), enter
聽(tīng)0xTV here, where T is an identifier for the boot loader and V is
聽(tīng)a version number.聽(tīng) Otherwise, enter 0xFF here.
聽(tīng)Assigned boot loader ids:
聽(tīng)0聽(tīng) LILO
聽(tīng)1聽(tīng) Loadlin
聽(tīng)2聽(tīng) bootsect-loader
聽(tīng)3聽(tīng) SYSLINUX
聽(tīng)4聽(tīng) EtherBoot
聽(tīng)5聽(tīng) ELILO
聽(tīng)7聽(tīng) GRuB
聽(tīng)8聽(tīng) U-BOOT
聽(tīng)Please contact <hpa@zytor.com> if you need a bootloader ID
聽(tīng)value assigned.
聽(tīng) loadflags, heap_end_ptr:
聽(tīng)I(yíng)f the protocol version is 2.01 or higher, enter the
聽(tīng)offset limit of the setup heap into heap_end_ptr and set the
聽(tīng)0x80 bit (CAN_USE_HEAP) of loadflags.聽(tīng) heap_end_ptr appears to
聽(tīng)be relative to the start of setup (offset 0x0200).
聽(tīng) setup_move_size:
聽(tīng)When using protocol 2.00 or 2.01, if the real mode
聽(tīng)kernel is not loaded at 0x90000, it gets moved there later in
聽(tīng)the loading sequence.聽(tīng) Fill in this field if you want
聽(tīng)additional data (such as the kernel command line) moved in
聽(tīng)addition to the real-mode kernel itself.
聽(tīng) ramdisk_image, ramdisk_size:
聽(tīng)I(yíng)f your boot loader has loaded an initial ramdisk (initrd),
聽(tīng)set ramdisk_image to the 32-bit pointer to the ramdisk data
聽(tīng)and the ramdisk_size to the size of the ramdisk data.
聽(tīng)The initrd should typically be located as high in memory as
聽(tīng)possible, as it may otherwise get overwritten by the early
聽(tīng)kernel initialization sequence.聽(tīng) However, it must never be
聽(tīng)located above the address specified in the initrd_addr_max
聽(tīng)field.聽(tīng)The initrd should be at least 4K page aligned.
聽(tīng) cmd_line_ptr:
聽(tīng)I(yíng)f the protocol version is 2.02 or higher, this is a 32-bit
聽(tīng)pointer to the kernel command line.聽(tīng) The kernel command line
聽(tīng)can be located anywhere between the end of setup and 0xA0000.
聽(tīng)Fill in this field even if your boot loader does not support a
聽(tīng)command line, in which case you can point this to an empty
聽(tīng)string (or better yet, to the string "auto".)聽(tīng) If this field
聽(tīng)is left at zero, the kernel will assume that your boot loader
聽(tīng)does not support the 2.02+ protocol.
聽(tīng) ramdisk_max:
聽(tīng)The maximum address that may be occupied by the initrd
聽(tīng)contents.聽(tīng) For boot protocols 2.02 or earlier, this field is
聽(tīng)not present, and the maximum address is 0x37FFFFFF.聽(tīng) (This
聽(tīng)address is defined as the address of the highest safe byte, so
聽(tīng)if your ramdisk is exactly 131072 bytes long and this field is
聽(tīng)0x37FFFFFF, you can start your ramdisk at 0x37FE0000.)
**** THE KERNEL COMMAND LINE
The kernel command line has become an important way for the boot
loader to communicate with the kernel.聽(tīng) Some of its options are also
relevant to the boot loader itself, see "special command line options"
below.
The kernel command line is a null-terminated string currently up to
255 characters long, plus the final null.聽(tīng) A string that is too long
will be automatically truncated by the kernel, a boot loader may allow
a longer command line to be passed to permit future kernels to extend
this limit.
If the boot protocol version is 2.02 or later, the address of the
kernel command line is given by the header field cmd_line_ptr (see
above.)聽(tīng) This address can be anywhere between the end of the setup
heap and 0xA0000.
If the protocol version is *not* 2.02 or higher, the kernel
command line is entered using the following protocol:
聽(tīng)At offset 0x0020 (word), "cmd_line_magic", enter the magic
聽(tīng)number 0xA33F.
聽(tīng)At offset 0x0022 (word), "cmd_line_offset", enter the offset
聽(tīng)of the kernel command line (relative to the start of the
聽(tīng)real-mode kernel).
聽(tīng)
聽(tīng)The kernel command line *must* be within the memory region
聽(tīng)covered by setup_move_size, so you may need to adjust this
聽(tīng)field.
**** SAMPLE BOOT CONFIGURATION
As a sample configuration, assume the following layout of the real
mode segment (this is a typical, and recommended layout):
聽(tīng)0x0000-0x7FFF聽(tīng)Real mode kernel
聽(tīng)0x8000-0x8FFF聽(tīng)Stack and heap
聽(tīng)0x9000-0x90FF聽(tīng)Kernel command line
Such a boot loader should enter the following fields in the header:
聽(tīng)unsigned long base_ptr;聽(tīng)/* base address for real-mode segment */
聽(tīng)if ( setup_sects == 0 ) {
聽(tīng)聽(tīng)setup_sects = 4;
聽(tīng)}
聽(tīng)if ( protocol >= 0x0200 ) {
聽(tīng)聽(tīng)type_of_loader = <type code>;
聽(tīng)聽(tīng)if ( loading_initrd ) {
聽(tīng)聽(tīng)聽(tīng)ramdisk_image = <initrd_address>;
聽(tīng)聽(tīng)聽(tīng)ramdisk_size = <initrd_size>;
聽(tīng)聽(tīng)}
聽(tīng)聽(tīng)if ( protocol >= 0x0201 ) {
聽(tīng)聽(tīng)聽(tīng)heap_end_ptr = 0x9000 - 0x200;
聽(tīng)聽(tīng)聽(tīng)loadflags |= 0x80; /* CAN_USE_HEAP */
聽(tīng)聽(tīng)}
聽(tīng)聽(tīng)if ( protocol >= 0x0202 ) {
聽(tīng)聽(tīng)聽(tīng)cmd_line_ptr = base_ptr + 0x9000;
聽(tīng)聽(tīng)} else {
聽(tīng)聽(tīng)聽(tīng)cmd_line_magic聽(tīng)= 0xA33F;
聽(tīng)聽(tīng)聽(tīng)cmd_line_offset = 0x9000;
聽(tīng)聽(tīng)聽(tīng)setup_move_size = 0x9100;
聽(tīng)聽(tīng)}
聽(tīng)} else {
聽(tīng)聽(tīng)/* Very old kernel */
聽(tīng)聽(tīng)cmd_line_magic聽(tīng)= 0xA33F;
聽(tīng)聽(tīng)cmd_line_offset = 0x9000;
聽(tīng)聽(tīng)/* A very old kernel MUST have its real-mode code
聽(tīng)聽(tīng)聽(tīng)聽(tīng) loaded at 0x90000 */
聽(tīng)聽(tīng)if ( base_ptr != 0x90000 ) {
聽(tīng)聽(tīng)聽(tīng)/* Copy the real-mode kernel */
聽(tīng)聽(tīng)聽(tīng)memcpy(0x90000, base_ptr, (setup_sects+1)*512);
聽(tīng)聽(tīng)聽(tīng)/* Copy the command line */
聽(tīng)聽(tīng)聽(tīng)memcpy(0x99000, base_ptr+0x9000, 256);
聽(tīng)聽(tīng)聽(tīng)base_ptr = 0x90000;聽(tīng)聽(tīng) /* Relocated */
聽(tīng)聽(tīng)}
聽(tīng)聽(tīng)/* It is recommended to clear memory up to the 32K mark */
聽(tīng)聽(tīng)memset(0x90000 + (setup_sects+1)*512, 0,
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng) (64-(setup_sects+1))*512);
聽(tīng)}
**** LOADING THE REST OF THE KERNEL
The 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512
in the kernel file (again, if setup_sects == 0 the real value is 4.)
It should be loaded at address 0x10000 for Image/zImage kernels and
0x100000 for bzImage kernels.
The kernel is a bzImage kernel if the protocol >= 2.00 and the 0x01
bit (LOAD_HIGH) in the loadflags field is set:
聽(tīng)is_bzImage = (protocol >= 0x0200) && (loadflags & 0x01);
聽(tīng)load_address = is_bzImage ? 0x100000 : 0x10000;
Note that Image/zImage kernels can be up to 512K in size, and thus use
the entire 0x10000-0x90000 range of memory.聽(tīng) This means it is pretty
much a requirement for these kernels to load the real-mode part at
0x90000.聽(tīng) bzImage kernels allow much more flexibility.
**** SPECIAL COMMAND LINE OPTIONS
If the command line provided by the boot loader is entered by the
user, the user may expect the following command line options to work.
They should normally not be deleted from the kernel command line even
though not all of them are actually meaningful to the kernel.聽(tīng) Boot
loader authors who need additional command line options for the boot
loader itself should get them registered in
Documentation/kernel-parameters.txt to make sure they will not
conflict with actual kernel options now or in the future.
聽(tīng) vga=<mode>
聽(tīng)<mode> here is either an integer (in C notation, either
聽(tīng)decimal, octal, or hexadecimal) or one of the strings
聽(tīng)"normal" (meaning 0xFFFF), "ext" (meaning 0xFFFE) or "ask"
聽(tīng)(meaning 0xFFFD).聽(tīng) This value should be entered into the
聽(tīng)vid_mode field, as it is used by the kernel before the command
聽(tīng)line is parsed.
聽(tīng) mem=<size>
聽(tīng)<size> is an integer in C notation optionally followed by K, M
聽(tīng)or G (meaning << 10, << 20 or << 30).聽(tīng) This specifies the end
聽(tīng)of memory to the kernel. This affects the possible placement
聽(tīng)of an initrd, since an initrd should be placed near end of
聽(tīng)memory.聽(tīng) Note that this is an option to *both* the kernel and
聽(tīng)the bootloader!
聽(tīng) initrd=<file>
聽(tīng)An initrd should be loaded.聽(tīng) The meaning of <file> is
聽(tīng)obviously bootloader-dependent, and some boot loaders
聽(tīng)(e.g. LILO) do not have such a command.
In addition, some boot loaders add the following options to the
user-specified command line:
聽(tīng) BOOT_IMAGE=<file>
聽(tīng)The boot image which was loaded.聽(tīng) Again, the meaning of <file>
聽(tīng)is obviously bootloader-dependent.
聽(tīng) auto
聽(tīng)The kernel was booted without explicit user intervention.
If these options are added by the boot loader, it is highly
recommended that they are located *first*, before the user-specified
or configuration-specified command line.聽(tīng) Otherwise, "init=/bin/sh"
gets confused by the "auto" option.
**** RUNNING THE KERNEL
The kernel is started by jumping to the kernel entry point, which is
located at *segment* offset 0x20 from the start of the real mode
kernel.聽(tīng) This means that if you loaded your real-mode kernel code at
0x90000, the kernel entry point is 9020:0000.
At entry, ds = es = ss should point to the start of the real-mode
kernel code (0x9000 if the code is loaded at 0x90000), sp should be
set up properly, normally pointing to the top of the heap, and
interrupts should be disabled.聽(tīng) Furthermore, to guard against bugs in
the kernel, it is recommended that the boot loader sets fs = gs = ds =
es = ss.
In our example from above, we would do:
聽(tīng)/* Note: in the case of the "old" kernel protocol, base_ptr must
聽(tīng)聽(tīng)聽(tīng) be == 0x90000 at this point; see the previous sample code */
聽(tīng)seg = base_ptr >> 4;
聽(tīng)cli();聽(tīng)/* Enter with interrupts disabled! */
聽(tīng)/* Set up the real-mode kernel stack */
聽(tīng)_SS = seg;
聽(tīng)_SP = 0x9000;聽(tīng)/* Load SP immediately after loading SS! */
聽(tīng)_DS = _ES = _FS = _GS = seg;
聽(tīng)jmp_far(seg+0x20, 0);聽(tīng)/* Run the kernel */
If your boot sector accesses a floppy drive, it is recommended to
switch off the floppy motor before running the kernel, since the
kernel boot leaves interrupts off and thus the motor will not be
switched off, especially if the loaded kernel has the floppy driver as
a demand-loaded module!
**** ADVANCED BOOT TIME HOOKS
If the boot loader runs in a particularly hostile environment (such as
LOADLIN, which runs under DOS) it may be impossible to follow the
standard memory location requirements.聽(tīng) Such a boot loader may use the
following hooks that, if set, are invoked by the kernel at the
appropriate time.聽(tīng) The use of these hooks should probably be
considered an absolutely last resort!
IMPORTANT: All the hooks are required to preserve %esp, %ebp, %esi and
%edi across invocation.
聽(tīng) realmode_swtch:
聽(tīng)A 16-bit real mode far subroutine invoked immediately before
聽(tīng)entering protected mode.聽(tīng) The default routine disables NMI, so
聽(tīng)your routine should probably do so, too.
聽(tīng) code32_start:
聽(tīng)A 32-bit flat-mode routine *jumped* to immediately after the
聽(tīng)transition to protected mode, but before the kernel is
聽(tīng)uncompressed.聽(tīng) No segments, except CS, are set up; you should
聽(tīng)set them up to KERNEL_DS (0x18) yourself.
聽(tīng)After completing your hook, you should jump to the address
聽(tīng)that was in this field before your boot loader overwrote it.