Need Help in ASM
; 02.11.2002 - METAKERN.SYS - a boot menu that replaces the Admin*pack kernel; Updated 26.03.2003: Allow up to 4 boot sectors, 4 partitions, 3 drives.; Updated 01.04.2003: Autogenerate kernel names for several Admin*pack boots.; Updated 18.04.2003: Repaired and improved partition list display; Updated 04.05.2003: You can now compile with -DCLS and -DTIMEOUT; Updated 15.05.2003: Bugfix for the timeout option.; Updated 11.10.2003: Use "new style" with MetaKern loaded as metakern.sys; (you need at least SYS 2.9 / kernel 2032a or better);; Please read the documentation for more details! In particular:; DO NOT USE THIS IF YOU HAVE NO KNOWLEDGE OF THE DOS BOOT PROCESS.;; Disclaimer:; This is a beta version. Use it at your own risk. You may end up being; unable to boot (then SYS again). License: GPL 2. Copyright 2002-2003; Eric Auer, eric@coli.uni-sb.de - please send feedback or patches. For; space reasons, please fetch the GPL text at www.gnu.org/licenses/ ...; Basically it means: Freeware and open source, but may only included; in projects which are open source, too. I allow you to boot non-free; operating systems using MetaKern (but not to distribute it with / as; part of a non-free / non-open operating system or software package).;; Compile:; nasm -o metakern.bin metakern.asm; or if you want TIMEOUT and CLS features as described:; nasm -DCLS -DTIMEOUT -o metakern.bin metakern.asm org 0 ; flat binary file, gets loaded to 0x60:0 by the Admin*pack; boot sector, which passes on the current drive number; in BL and can find us, kernel.sys anywhere in the root; directory (may even be fragmented)...; stack will be at 0x1fe0:7be0 or something,; fat will be loaded to RAM, too. See the Admin*pack sources.; set this to 1 if you do not want MetaKern to attempt to offer; partition table entries in the menu when booting from floppy:%define WEAKFLOPPY 0; set this to 1 if you do not want to see the active partition; entry when booting from harddisk - because it will probably; simply point to where you came from, and unless your MBR is; broken, it will be equivalent to the "boot from C:" selection:%define HIDEACTIVE 1; set this to 1 if you do want to see the active partition when; booting from floppy%define SHOWACTIVEIFFLOPPY 1; Use -DCLS, -DCLSin or -DCLSout compile flags to cause clear screen; on entering / leaving MetaKern. If you want another screen mode; than 3 (80x25 color), change the code at the places after %ifdef CLS.%ifdef TIMEOUT;; set this to some value (unit: (1/18.2) second) to auto-trigger; some menu item after VALUE amount of time has elapsed and the; user still did not type anything. Only enabled if TIMEOUT you; gave the -DTIMEOUT flag at compile time.%define TimeOutTicks 180; roughly 10 seconds; the timeout in seconds as a string for a message%define TimeOutText "10"; set this to the key that MetaKern should pretend to be pressed; if the user did not type anything before the time out.%define DefaultKey '1';%endif; only if TIMEOUT is defined...; Please only change %define lines ABOVE this line if you have no; real clue on the internal workings of MetaKern. Actually, even; the above define lines could be replaced by using -D...=... with; nasm. Then you could select all options without editing this file.; *************************************************************; if you change this to have more or less than 4 boot sector menu; entries, you must change the code, too. However, you can simply; copy /b less than 4 boot sectors if you want to USE less entries,; which is probably all that you need!%define boot1(sign+2); %define boot2 (sign+0x202); %define boot3 (sign+0x402); %define boot4 (sign+0x602); the mbr buffer MUST be a multiple of 0x200 after the boot1 buffer!%define mbr(sign+0x802)%ifdef CLS%define CLSin CLS; CLS sets both CLSin and CLSout%define CLSout CLS; CLS sets both CLSin and CLSout%endif; *************************************************************start:push cspop ds; init dspush cspop es; init esmov [cs:drive],bl; remember drivemov [cs:realdrive],bl; remember drivecldmov cx,0x100xor ax,axmov di,mbrrep stosw; clear buffer for MBR%if WEAKFLOPPYor bl,bljns nothard; "pop sicall print; print partition descriptionmov si,partition; message telling the type as numbercall printstrcrlf; print and add CR LFclcjmp short checknothing; return, no further printing; *************************************************************checkfail:stc; invalid choicecheckdone:; use SI to print a menu entryjc checknothing; no valid menu entry, print nothingpushfcall printchoice; SI is entry namepopfchecknothing:pop sipop axret; *************************************************************checkboot:; scan 512 bytes from SI for boot sector stuff...mov [cs:choice],al; store the hotkeypush axpush sicmp word [si+0x1fe],0xaa55; bootable (magic value)?jnz checkfail; nope! (everything else is accepted!)push bxpush dipush bppush cxpush dxmov bp,si; where to searchmov bx,searchlistmov di,fdsearch; first search stringcheckone:mov ax,[di]or ax,axjz notypefoundcall stringfind; search in BP..BP+0x1f8, string DI, len 11jz typefound; Z = hit, at offset SI, DI unchangednexttype:inc bx; next messageinc bxadd di,11; next search stringjmp short checkone; go on with searchingtypefound:cmp di,fdsearch; did we find THAT one?jnz notypefound; else, no special actions neededmov cx,[ds:fdreplacecnt]; fetch current replace snippetor cx,0x2020; turn into lower case (technically not needed; for new style, only for OLDSTYLE "EL"->"el")mov [ds:fdtypecnt],cx; update snippet in entry namemov cx,11mov di,si; overwrite (BEFORE counting up)mov si,fdreplace; patch the name! (only first occurance)rep movsb; replaced "kernel sys" by a new value...typecounting:; count up the replacement string: first; value is kernel.sys (OLDSTYLE: fdkernel.sys); next are kernel2.sys, kernel3.sys etc.; (OLDSTYLE: fdkern2.sys, fdkern3.sys etc.)push axmov ax,[ds:fdreplacecnt]%ifdef OLDSTYLEcmp ax,"EL"; if last was not numerical, start counting%elsecmp ax," "; if last was not numerical, start counting%endifjnz typecount1mov ax,"1 "; one LESS than the first numerical suffixtypecount1:inc axmov word [ds:fdreplacecnt],ax; update the name tailpop axnotypefound:mov si,[bx]; message for our typepop dxpop cxpop bppop dipop bxclc; SI now holds a describtion of the found boot sectorjmp short checkdone; print the boot menu entry and returnstringfind:; search for string at DI, len 11, in area BP..BP+0x1ff; return Z for hit at offset SI, DI unchangedpush axpush cxxor ax,ax; start search at buffer startrestringfind:mov si,bp; buffer startadd si,ax; current search startmov cx,11push dipush si; needed for "return hit offset"repe cmpsb; compare strings herepop si; needed for "return hit offset"pop dijz foundstring; ZF set - foundinc ax; next search startcmp ax,0x200-11; still in range?jb restringfindor ax,ax; clear ZF - not foundfoundstring:pop cxpop axret; *************************************************************printchoice:; print choice + " -> " + string SI + CR + LFpush simov si,choice; the hotkey, followed by an arrowcall printpop siprintstrcrlf:; print string SI + CR + LFpush sicall print; the menu item descriptionpop siprintcrlf:; print CR + LFpush axmov al,13call printchar; carriage returnmov al,10call printchar; newlinepop axretprint:; print zero-terminated string at CS:SIpush ax; updates SI to point to the end of the stringpush dsmov ax,csmov ds,axprint2:lodsbor al,aljz eprintcall printcharjmp short print2; loopeprint:pop dspop axretprintchar:; print char from ALpush axpush bxmov ah,0x0e; TTYxor bx,bxint 0x10; BIOS screen stuffpop bxpop axret; *************************************************************drivedb 0; handed on to boot sectorsrealdrivedb 0; actual boot drivevaliddb 0; bitmask of allowed choicesmessagedb 13,10,"Welcome to the Admin*pack MetaKern boot menu"db 13,10,"Please type a digit to select a list item"db 13,10,"or type A or C to reboot from A: or C:..."%ifdef TIMEOUTdb 13,10,"Using if no choice after "db TimeOutText, "s."%endifdb 13,10,0choicedb "X"; this must be the byte before arrowarrowdb " -> ",0; menu entries look like "X -> selection"sectormenumsgdb "Boot sectors:",13,10,0partnmenumsgdb "Partitions:",13,10,0readytogomsgdb "kick!",13,10,0; removed explicit list 18apr2003; diskmasterdb "Reboot from disk "; dmasterdb "Z:",0diskbootmsgdb "Booting from "diskbootnamedb "Z:"db "... ",0bootsectmsgdb "Loading "bootsectnamedb "9th "db " stored boot sector... ",0partnslotmsgdb "Loading boot sector of "partnslotnamedb "9th "db " partition... ",0enumnamesdb "1st 2nd 3rd 4th ",0loadfailmsgdb "Disk read error, try again!",13,10,0loadinvmsgdb "No system on that disk or partition, try again!",13,10,0dosptypedb "DOS ",0 ; 1 FAT12 4 FAT16 small 6 FAT16 bigwinptypedb "Win9x",0; B..E CHS/LBA x normal/hidden...qnxptypedb "WinNT, QNX or OS/2",0; 7linptypedb "Linux",0; 83 ext2, that isxyzptypedb "??? ",0; auto-skipped types ( -> no type name string needed ) are:; nultypedb "empty",0; 0; extptypedb "extended",0; 5/F CHS/LBApartitiondb " - type "ptypedb "xx",0%ifdef OLDSTYLEfdtypedb "Admin*pack (chain to fdkern"fdtypecntdb "el.sys!)",0%elsefdtypedb "Admin*pack (chain to kernel"fdtypecntdb " .sys!)",0%endifmstypedb "MS (Win-) DOS (io.sys / msdos.sys)",0ibmtypedb "IBM or DR DOS (ibmbio.com / ibmdos.com)",0wintypedb "MS Windows (winboot.sys)",0; could add others here and in search stringsothertypedb "unknown operating system",0fdsearchdb "KERNEL SYS"mssearchdb "IO SYS" ; and "MSDOS SYS"ibmsearchdb "IBMBIO COM" ; and "IBMDOS COM"winsearchdb "WINBOOT SYS"dw 0; end of search list; map fdsearch to fdreplace, and in addition, count.%ifdef OLDSTYLEfdreplacedb "FDKERN"fdreplacecntdb "ELSYS"%elsefdreplacedb "KERNEL"fdreplacecntdb " SYS"%endif; must match order of search strings:searchlistdw fdtype, mstype, ibmtype, wintype, othertype; *************************************************************; make us exactly 3 sectors in size, for coolness: times 0x05fe-$+$$ db 0signdb 0xc0, 0x01; "c001-ness :-)"; next sectors can be the Admin*pack and the MS DOS boot; sector and so on (up to 4 boot sectors, 0x200 bytes; each, at 0x600, 0x800, 0xa00 and 0xc00 in the file); and after that (at 0xe00) we try to load the MBR...; *************************************************************; use copy /b to put:; boot1 at: sign+2; boot2 at: sign+0x202; boot3 at: sign+0x402; boot4 at: sign+0x602; MetaKern will load:; mbr at: sign+0x802Greseala este dar nu pot sa o gasesc ..... cine ma ajuta din partea mea bereAm gasit niste surse le-am modificat si Hz dar ceva nu este corect