Java Primer: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
m (Bot: Replace deprecated source tag with syntaxhighlight)
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
Line 40:
The fact that getting the number of arguments is convoluted to perform on the caller's side, we do callee-cleanup using <tt>RET imm</tt> instead of the regular <tt>RET</tt>. Locals is a convoluted issue as well, so we just reserve room for 8 because you're not meant to copy this code anyway.
 
<sourcesyntaxhighlight lang="java">
// File: compiler/nl/combuster/minijava/Compiler.java
package nl.combuster.minijava;
Line 299:
}
 
</syntaxhighlight>
</source>
 
Yes, that's a compiler in a magic 256 lines of code. The result is Intel syntax assembly, because there already are decent tools for assembly out there that deal with object formats out there. Of course you can write your own later as well.
Line 340:
"Hello world!" is a very overrated thing. Or is it? Strings are a full-blown object in Java, and passing objects safely is one of the things skipped in the compiler itself. Instead, we can count our numbers to show what we have actually works:
 
<sourcesyntaxhighlight lang="java">
package nl.combuster.minijavaos;
 
Line 359:
}
}
</syntaxhighlight>
</source>
This is little more than some simple VGA code, but it demonstrates that we can call Java code, do some calculations, and then call our hardware abstraction layer to complete the little bits Java just couldn't do.
 
Line 367:
==== Multiboot ====
We use GRUB as a bootloader, so the mechanics are the same. The only real difference is that we have to cope with the name mangling and be unable to call something kmain.
<sourcesyntaxhighlight lang="asm">
; File: os/multiboot.asm
 
Line 404:
;hlt
jmp .hang
</syntaxhighlight>
</source>
 
====Linker script====
Line 476:
 
In this example, GRUB is assumed to be preinstalled in /boot where it resides by default on a linux system that has it installed. We also need mkisofs and the binutils step from the [[GCC Cross-Compiler]]. Of course, at some point in time you can decide to write these tools in Java as well
<sourcesyntaxhighlight lang="make">
 
COMPILER_J=$(shell find -L compiler -iname '*.java')
Line 527:
mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o $@ build/iso
 
</syntaxhighlight>
</source>
 
If you paid attention, you'll notice that the JAR step requires a manifest at <tt>compiler/compiler.manifest</tt>. It only really marks it as runnable so that we can use it easily: