oricode Posted January 9, 2008 Share Posted January 9, 2008 Hi ppl, I am writing a bootstrapper routine. What I am trying to do is, call a 'C' routine from the bootstrapper routine(writen in ASM). This is to be done before any OS loads. I am not sure how to call a 'C' binary that contains my logic, and run it without any environment. Maybe something like what a Live CD does while checking for available peripheral devices. Any help appreciated.Regards,Oricode. Link to comment
metr0 Posted January 9, 2008 Share Posted January 9, 2008 Do I understand you right that you'd like to do sth like a mini-os? If so, my old lame sources could help you: (click here). - I am using gcc, nasm and bochs for compiling and emulating that stuff, just google, there are many tutorials out there. Hope I could help you. metr0 Link to comment
human Posted January 9, 2008 Share Posted January 9, 2008 well i think its almost impossible, due bootstrap code loads and is organized at 7c00h address and c++ must be compiled as binary and also hardcoded with any address,if you dont have memory menager compatible at least with bios. its easier to write whole thing in asm. Link to comment
Killboy Posted January 9, 2008 Share Posted January 9, 2008 Many defrag programs can defrag your HDD at boot time to defrag system files.I doubt they code all the defrag stuff in MASM ? Is there no way to load a dll for example ? Link to comment
metr0 Posted January 9, 2008 Share Posted January 9, 2008 Hehe, library loading would be nice, indeed. But a dll is a ms-thingy, and bootable code doesn't support ms stuff at all (monopol isn't big enough, I guess). The only thing you got access to are the interrupts the BIOS offers. You have to code all the routines on your own (hard disc access, graphical stuff inside protected mode etc.). You don't use C++ here because it gives you access to predefined functions - no, they're not there. It's only a thing of which syntax you prefer. You have to code all that stuff. It's up to you if you'd like to do it in asm or C++. Link to comment
human Posted January 9, 2008 Share Posted January 9, 2008 have you ever seen boot defrag exe its pe32 exe, and they dont use own code, only use windows, windows boots bootloader, then loads kernel and then they are set like driver at startup to do whole thing. due then yet partition arent mounted yet. it like linux, it also repairs all after kernel loaded and before mounting. in windows you cant repair partition with page file and system others can be forced to close handles and unmount and remount back. those things do pqmagic or perfect disk.so you have 2 options code bootstrap in asm if its for simple thing or learn how to code driver or service that can do things like those.and question was about bootstrapper not boot service or driver. so for this i already answered. Link to comment
oricode Posted January 10, 2008 Author Share Posted January 10, 2008 (edited) @metr0 Yeah you got me right! Something like a mini-OS... But the problem is I have to write the logic in 'C'. I coded the bootstrap in ASM(its easy and the best way). But then as I already mentioned I need to jump to my logic routine, just like our Windows gets loaded from the bootstrap. I tried having a look at memtest, which is an open source project to get some idea. I am also trying to look at some Linux(or maybe minix) source code. I am having a look at your code metr0.. Thanks a lot @human Yeah, the bootstrap should be at that very address. But thats what my dought is, can I load some binary file written in 'C' from that bootstrap routine written in NASM/ASM? EDIT: yeah metr0, thanks very helpful code that you have provided !! Got some idea how do I proceed.. Oricode. Edited January 10, 2008 by oricode Link to comment
oricode Posted January 10, 2008 Author Share Posted January 10, 2008 @metr0 Er... stuck. Can u help me with how to proceed compiling those 'C' codes.I tried gcc in Red hat, and exactly how do i write the C binary at the 0x01000h offset. I am a bit new to this stuff, so go easy Oricode. Link to comment
human Posted January 10, 2008 Share Posted January 10, 2008 memtest also uses kernel like mini floppy linux. with any way you want to load file you need to use int 13 from bios to read from hdd or code your own code to program ide controller or sata.there is no function in bios to read file from fat or ntfs. if you need small thing then its better to do all in asm. if its bigger maybe then make some mini image like vista activator works or acronis to recover partition. they both use mini linux images to handle their functions. install grub, load linux kernel and run app and then you can do all in C under gcc Link to comment
metr0 Posted January 10, 2008 Share Posted January 10, 2008 Thanks human, didn't know that stuff about boot defrag and since I'm not into driver coding that idea didn't came up my mind. Oricode, use this batch file to compile the whole thing: REM @echo offset PATH=c:\DJGPP;%PATH%set DJGPP=c:\DJGPP\djgpp.envnasmw -f bin bootsector-ckernel.asm -o bootsect.bingcc -ffreestanding -c main.c -o main.ogcc -c video.c -o video.ogcc -c ports.c -o ports.old -e _main -Ttext 0x1000 -o kernel.o main.o video.o ports.old -i -e _main -Ttext 0x1000 -o kernel.o main.o video.o ports.oobjcopy -R .note -R .comment -S -O binary kernel.o kernel.binmakeboot bootable.img bootsect.bin kernel.bin I hope this works for you, then. If not, just let me know. - About FAT support I remember several tutorials on how to implement it, but I do not remember the sites' names. Maybe Google helps you. Regards, metr0 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now