TheGameMaker90 wrote:The problem is (perhaps my explanation is off), but I effectively want to be able to use C headers for both. That is, I can call, the parts that the assembly requires in assembly, but use the same header (in an else condition to the macro you supplied) to do things in C.
Well, yes and no. Yes, you can share the same header file with both, and they both can share the same definitions. But no, you can't put Assembly and C things in that header. You have to limit yourself to a syntax that's common to both, which is not much, mostly pre-compiler stuff (parts which aren't common must be #ifdef guarded).
For example:
Code: Select all
/* stuff.h */
#define SOMETHING 123
Code: Select all
/* src.S */
#include "stuff.h"
movl %eax, $SOMETHING
Code: Select all
/* src.c */
#include "stuff.h"
variable = SOMETHING;
In this case the pre-compiler takes care of it that by the time the text source is passed to the C compiler and Assembler, what they actually receive would be:
and
Neither the C compiler, nor the Assembler parses "#include", and they never see "SOMETHING" either. Those are removed and replaced by the pre-compiler.
TheGameMaker90 wrote:If you look at GRUB for example, in the file "grub/grub-core/boot/i386/qemu/boot.S" it has a few includes at the top. config.h, grub/symbol., grub/machine/memory.h...
Those are nothing more than configuration defines. There's nothing Assembly nor C in them, purely pre-compiler things.
TheGameMaker90 wrote:All I want to be able to be able to do is compile the object file as always and link it similar to that link I posted without a proper linker
Which you can do. Include does not influence linking in any way. Think about include as you would copy'n'paste a text file into another; on the other hand linker operates on binary object files (non-text).
TheGameMaker90 wrote:generate a .bin to be run by QEMU.
Which as I've said, not simple. You must wrap the generated .bin in a disk image in order to run it in qemu. No compiler will do that for you (maybe an Assembler if you code all file system information into your source with 'db' instructions). You'll need other tools than a compiler and a linker. One way is to use dd, losetup, mount etc.
(FYI: the tutorial you linked uses
floppy.img as disk image, but the linker outputs
test.bin in that tutorial. In section "How to copy the executable code to a bootable device and then test it?" there's (an incorrect) dd command that should update
floppy.img with
test.bin. The dd command is incorrect as it's missing the notrunc option. Although that tutorial uses bochs, if you did everything right, you should be able the boot
floppy.img in qemu too as "qemu -fd floppy.img".)
Another way, which I prefer, is to use a specific tool that generates the disk image for you, that's what
mkbootimg is about. It takes a directory and its contents (with your ELF kernel in it) as input, adds the loader to it and wraps all of it, and finally outputs a single binary file which then you can feed to qemu.
TheGameMaker90 wrote:What are the command line operators I need to do this. I've already been on the pages you linked and they have helped me not. Thanks.
Those pages demonstrate exactly those commands. Don't get me wrong, but if those pages haven't helped you at all, then are you sure you have the
required knowledge for OSDev?
Cheers,
bzt