Page 1 of 1

Boot: Asm Rest: C, C++ or Pascal

Posted: Thu Aug 09, 2001 2:58 am
by Nok
(1)Can i boot from a boot.bin (coded in assembler!) , and then close boot.bin and exec a .exe file?
(2)If possibel, do you know any boot that loads in asm and then pass to a program coded in C or Pascal?
(3)or other language...
(4)For booting from hard disk we have to put in it 1 sector the boot like diskettes?
(5)How can i delete the first sector of a diskette?

Tks sorry for so any questions...
Hope some one saves me...
:P

Re: Boot: Asm Rest: C, C++ or Pascal

Posted: Thu Aug 09, 2001 5:26 am
by BLoggins02
>> (1)Can i boot from a boot.bin (coded in assembler!) , and >> then close boot.bin and exec a .exe file?

Yes! ?But there are some rules: ?you have to know how to parse the .exe (probably PE) file format; you have to use statically linked libraries at first (if you want to do your kernel in this format); and you should probably have memory management already going before you do this. ?So it's possible, but why? ?The linker is the program that is responsible for taking your object file(s) and converting them into the output format of choice. ?If you use GNU ld as your linker for instance, you can output to straight binary format, which is really what you want. ?You can also use any format for input. ?For example, all your source object files could be ELF, PE, whatever and have GLOBALS, EXTERNS and the like, if you link it to a binary output file, those references will be statically resolved. ?You just have to tell the linker where to put the text segment and where code execution begins, which brings us to:

>> (2)If possibel, do you know any boot that loads in asm
>> and then pass to a program coded in C or Pascal?

The good news is that it really makes no difference what language it was originally coded in, it's all in machine language at the end anyway. ?What you DO need to know is where program execution normally begins. ?In C, it's usually a place called _start (it's before main, and if you're an application programmer you don't see it). ?So if you declare a function called _start() in C, the linker can find it and will know to start execution there. ?With GNU ld, you can use the -e option to force execution to start at a certain function. ?For example, ld foo.o -e bar would cause the foo program to be executed starting at function bar(). ?Once you know the address of this starting point, just have your boot code jump to it, it's really that easy. ?If you want to interface C with ASM (and you'll probably have to if you're doing an OS) you'll need to understand calling conventions, stack management, and things like that, but there are many places to look for that information.

The rest of your questions I'll leave to someone else, mainly because I don't know much about Hard Disks yet (haven't gotten there as you'll be able to tell if you visit my website, hehe). ?As far as deleting the first sector of a diskette, it's not very clear what you mean. ?As far as getting rid of sector 1, you could do a format a: /s in DOS and that would overwrite the boot sector there. ?But you deal with that sector usually directly using DEBUG, RAWRITE, DD, and the like. ?Keep in mind that if you don't have the FAT info after the first three bytes of the first sector, DOS/Win won't be able to recognize your disk and you'll have to reformat everytime. ?Take a look at the bootsector code on my website (see signature); I wrote some stuff about it there.

Hope this helps you :)
Breckin