Java For Starters: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
m Bot: Replace deprecated source tag with syntaxhighlight
 
(4 intermediate revisions by 3 users not shown)
Line 13:
Well, it's simple - you can use your legs. But yes, it's not very convenient. And it's better to have some kind of a vehicle to help you to get some speed. That's why it is important to understand what tools we have.
 
First, it is possible to use some combination of tools, written in C or Assembly, with some source code, written according to the Java syntax, and another part of code, written in C or assemblyAssembly. It's actually the way many people prefer, [[Pascal_Bare_Bones | and here is the Pascal example]], which shows such approach. But it should be noted, there's just a small part of the job done in Pascal. Without tools, written in other languages, there will be no Pascal OS. Also, without code in other languages (mostly assembly) there will be no Pascal OS.
 
Second, it's possible to write absolutely everything in the preferred language. And of course, it means somebody should write the "everything". Because in case of many languages there's no native tools available, it's the OS developer who should write "everything".
Line 21:
==Here are some tools available for Java OS developers.==
 
First, of course, it's the standard tool set [[Getting_Started#Choosing_your_development_environment | as described here]]. It supports the first way of doing things - just some language flavor around the same C and assemblyAssembly based environment. And the flavor can be compiled by the [https://gcc.gnu.org/java/ GNU Compiler for the Java] (GCJ), for example. The GCJ was written in C and supports only standard C related conventions. If a developer prefers this way it should be noted this article is not intended to be of a great help for such approach.
 
The second option (everything in Java) is described below. But it introduces some tools, already written in Java. The tools here are used as an example and there's no attempt to enforce you to use them. Following article shows how to create a simple bootloader in Java. There is a jump in the end of the bootloader code and all your potential Java OS can start after the jump is performed. So, your OS in Java can start with this article and end in some very interesting form, unseen until you'll have it done.
Line 47:
 
The collection of assembly instructions can look like this:
<sourcesyntaxhighlight lang="java">
mov.x32(EAX,EDX);
</syntaxhighlight>
</source>
 
* Here the "mov" is the class's field name.
Line 58:
 
Next it is required to understand how the instruction above can be executed. For it to be possible the translation phase is required. But before the translation step it is usually a good idea to have the actual program. The program actually is just a number of text strings in the form described above. It can be good to separate code fragments intended for different purposes in separate methods like this:
<sourcesyntaxhighlight lang="java">
protected void writeBootCodeInitialization(short stackAddress, short bootLoaderAddress)
{
Line 69:
mov.x16(SP,stackAddress);
}
</syntaxhighlight>
</source>
And the class, where code fragments are supposed to be, can look like this:
<sourcesyntaxhighlight lang="java">
public class AnAssemblyWriter extends AssemblerProgram
{
Line 79:
... // your code fragment methods
}
</syntaxhighlight>
</source>
Here we see the class's constructor with two parameters, the mode parameter can be one of the following:
CODE16 // Generate 16-bit code
Line 88:
 
Next you can add a particular code to the bootloader for it to be able to actually load something. You can write a method like this:
<sourcesyntaxhighlight lang="java">
protected void loadImageUsingInt13x42(String problemLabel, String diskAddressPacketLabel, int imageSizeInDiskSectors)
{
Line 120:
}
}
</syntaxhighlight>
</source>
The the final program (it's main method) can look like this:
<sourcesyntaxhighlight lang="java">
private void createBootCode(int imageStartAbsoluteBlockNumber, int imageSizeInDiskSectors,
short memoryAddressToPlaceBootstrapImageAt, short bootLoaderNewAddress,
Line 141:
imageSizeInDiskSectors,imageStartAbsoluteBlockNumber,memoryAddressToPlaceBootstrapImageAt);
}
</syntaxhighlight>
</source>
And here you can see how helper procedures and data structures are written together with the actual bootloader's code.
<sourcesyntaxhighlight lang="java">
private void writeProceduresAndData(String diskReadProblemLabel, String diskAddressPacketLabel,
int imageSizeInDiskSectors, int imageStartAbsoluteBlockNumber, short memoryAddressToPlaceBootstrapImageAt)
Line 175:
writeBytes(bs); // now add the bs buffer to the actual program
}
</syntaxhighlight>
</source>
After you have all inline assembly instructions in place you can first call the methods with the instructions for them to write their binary representation and next call AssemblerProgram's getProgram() method to get the actual machine code stored in the returned byte array. The resulting bytes can be written to the boot sector using appropriate tools.
 
Line 185:
 
[[Category:Bare bones tutorials]]
[[Category:Java]]