nullplan wrote:Code: Select all
.section ".rodata", "a", @progbits
.global font_start
.type font_start, @object
font_start:
.incbin "font.psf"
.global font_end
.type font_end, @object
font_end:
That should work for all ELF architectures.
I seriously doubt that the FreePascal or the Rust compiler for example can do anything with this code... (Pascal uses a
different inline asm syntax, and Rust for example
doesn't really support global labels in inline asm).
As I've said, it was an important goal to only use the main language with its compiler, but nothing else, which means no additional tools nor assemblers. This is why Assembly is out of question for the mykernel examples (in a real kernel project, where an assembler is a must have sure, you can use "incbin" too, or "file" or "bininc" or whatever syntax your chosen assembler supports).
nullplan wrote:For PE the section name would be ".rdata", which you can abstract with a preprocessor directive, as necessary.
Unlike C, Pascal and Ada, for example the Go compiler doesn't have a preprocessor at all. (And it can't import variables from another object file, just functions with a very overcomplicated way, btw. so even if you compile this with an assembler, there's no way to access the included data from Go. FYI, ld and objconv doesn't work either with Go, I had to use the bin2h way, furthermore, Go can't store initialized static byte arrays, so I had to use a string constant... Ugly and dirty workaround. You have probably figured that out, my dislike towards Go is because I had the most issues and trouble with that port. That's a shitty, not a well-tough language which required the most workarounds by far. Oh, and the official compiler doesn't work for bare metal, not even their own tutorials compile with that, you _must_ use the GNU compiler, gccgo.)
nullplan wrote:Since the file contains no architecture specific code, any version of GNU as should be able to compile this, no matter the target architecture, and probably also some other assemblers. The C interface is "extern const char font_start[], font_end[]".
ld does exactly the same, but needs no additional assembler to achieve that goal. First, doesn't matter what language you use, you'll need the linker anyway, you can't leave that out; second, it creates the object no matter the target architecture. So, why not use the tool that we already have?
nullplan wrote:And if you need to support MSVC
I don't think MSVC can compile Pascal, Ada or Go for example. The GNU compiler can. (That put aside, I do support MSVC C/C++ for kernels, the bootboot.h is written carefully in a way to support the messed up MSVC pragma syntax too, but I don't provide a mykernel example for that compiler.)
Cheers,
bzt