Recently using Vmware and writing to a floppy image I have been
experimenting with some helloworld bootload 16 bit asm code and it has
got me thinking about whether I could also load a C helloworld program
(linked of course) and get the bootload code to run it.
Looking at this, I'm beginning to think this might be a monumental
task. Maybe a floppy seek needs to be written? The asm needs to jmp to
a memory location and then unload itself? Then what about the linked C
code? it probably needs a number of kernel modules linked just to run?
What do you guys think? are there simple examples or would I be better
looking at what Minux does as a starting example or is this just a
pipe dream for basically a hobby project?
The problem with this is that a "linked" program is not a loadable memory
image. It requires additional processing in order to become runnable,
provided by a system loader of some kind that can interpret the linker
tables in the executable. You don't have that loader at boot time. That
is one of the services provided by lilo and grub; besides providing a user
interface, their last step is to be a loader to read in the Linux kernel
image (which is an executable file) and turn it into a runnable memory
image.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
You can play with mine:
http://alexfru.narod.ru/os/fat/fat.html
You can modify it to switch to protected 32-bit mode and do much more
interesting stuff there. For that you'll need to use a 32-bit compiler
(Watcom, DJGPP/GCC, etc) at some point.
Alex
It's doable. It's some work. alt.os.development is more suited to the
question. A few guys there have done exactly this, but usually to start
assembly code. C requires that you setup a stack and stack frame that is
compatible with the _specific_ C compiler's prolog and epilog. You then
need a method to tell your linker and/or loader code where the initial code
entry point is. This can be simple or hard depending on the compiler. You
may need to write a small amount of assembly as a header for this, even if
you're primarily using C code. Your bootloader will likely be 16-bit. If
your C code is 32-bit or 64-bit, you'll need to also switch the cpu to
32-bit or 64-bit mode from 16-bit.
Another problem with C code is that portions of the C library are dependent
on the host OS. I.e., you can't use them in your OS. Most write their own
small C library for functions like memcpy() and sprintf() etc. I did it the
other way around. Some parts of the C library are simple enough that they
are OS independent. You can use these "clean" parts of the host C library
without issues, or you can eliminate it later on. This is faster, but the
functions will have to be eliminated once the OS becomes self-hosting. I
can post a link to other posts of mine that mention what functions are
typically "clean", if you want.
C has other issues too that require assembly: need assembly wrappers around
interrupt routines, no special x86 instructions, etc.
But, I'd recommend a Multiboot compliant bootloader, e.g., GRUB or GRUB4DOS.
A Multiboot loader will load ELF (e.g., produced by GNU toolchain or Unix
environments) and other .obj's or executable code if the values in the
header are setup correctly. This will start your code as 32-bit, if it has
the multi-boot header. If you're doing 16-bit, you'll need something else.
If you're doing 64-bit, you'll need to write a 32-bit to 64-bit stub. There
are also other types of loaders available. I.e., you can load MS-DOS .exe's
or .obj's, or .coff or ELF .obj's and executables directly. You can look
at:
Coff2Com and OSLoader by Alexei Frounze (coff .obj's)
http://alexfru.chat.ru/programming/coffutil.zip
from here in "Coff Utils" section:
http://alexfru.chat.ru/epm.html
BootProg by Alexei Frounze (.com's, .exe's)
http://alexfru.chat.ru/programming/bootprog.zip
from here in "Bootsector that loads ..." section:
http://alexfru.chat.ru/epm.html
RunReloc by Chris Giese (elf, djgpp coff, win32 pe coff .obj's)
http://geezer.osdevbrasil.net/osd/exec/runreloc.zip
from here:
http://geezer.osdevbrasil.net/os/index.htm
DOS Multiboot loader by Chris Giese (multi-boot loader for DOS)
http://geezer.osdevbrasil.net/temp/mbload.zip
from here:
http://geezer.osdevbrasil.net/os/index.htm
HTH,
Rod Pemberton
Hi Alex, I have had a quick look at yours and a more indepth look at
fatbootsect. One of the prereqs is that I can load this in using a
VMware floppy boot image as I do not have easy access to a floppy
disk. I do not see anything in your instructions regarding the use of
VMware. Can this be done? what you have provided looks very good.
BTW, this is some of my favorite asm source this decade. Nice and
clean, performs as advertised with 13 bytes to spare, and generally
good source to learn x86 asm from.
There's nothing VMWare-specific in the code. It's general-purpose.
> Can this be done? what you have provided looks very good.
Try it. There're prebuilt floppy images that you can use right away
(fdda?.img).
Alex
Hi Alex, did you know that Nod32 thinks the pre built floppy images
are threats and quarantines them?
On 24 Dec 2009 00:44:31 GMT, oraclerob
I can't know about all idiosyncrasies of every single antiviral
program. I don't use Nod32.
Alex
On 24 Dec 2009 14:30:19 GMT, "Alexei A. Frounze"