用java开发一个Hello Word系统内核
生活随笔
收集整理的這篇文章主要介紹了
用java开发一个Hello Word系统内核
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1 最簡單的Hello World系統內核實現
- 2 使用VirtualBox創建虛擬機并加載上述生成的軟盤文件
- 2.1 創建虛擬機
- 2.2 加載軟盤中的內核
1 最簡單的Hello World系統內核實現
java代碼如下,代碼就不做過多解釋了,直接看就可以了:
import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList;public class OperatingSystem {private int[] imgContent = new int[]{0xeb,0x4e,0x90,0x48,0x45,0x4c,0x4c,0x4f,0x49,0x50,0x4c,0x00,0x02,0x01,0x01,0x00,0x02,0xe0,0x00,0x40,0x0b,0xf0,0x09,0x00,0x12,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x40,0x0b,0x00,0x00,0x00,0x00,0x29,0xff,0xff,0xff,0xff,0x48,0x45,0x4c,0x4c,0x4f,0x2d,0x4f,0x53,0x20,0x20,0x20,0x46,0x41,0x54,0x31,0x32,0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb8,0x00,0x00,0x8e,0xd0,0xbc,0x00,0x7c,0x8e,0xd8,0x8e,0xc0,0xbe,0x74,0x7c,0x8a,0x04,0x83,0xc6,0x01,0x3c,0x00,0x74,0x09,0xb4,0x0e,0xbb,0x0f,0x00,0xcd,0x10,0xeb,0xee,0xf4,0xeb,0xfd};private ArrayList<Integer> imgByteToWrite = new ArrayList<Integer>();public OperatingSystem(String s) {for (int i = 0; i < imgContent.length; i++) {imgByteToWrite.add(imgContent[i]);}imgByteToWrite.add(0x0a); // 換行符 \nimgByteToWrite.add(0x0a); // 換行符 \nfor (int j = 0; j < s.length(); j++) {imgByteToWrite.add((int)s.charAt(j));}imgByteToWrite.add(0x0a); // 換行符 \n// 這里一直從現有代碼之后到510字節的所有內容都填充為0int len = 0x1fe;int curSize = imgByteToWrite.size();for (int k = 0; k < len - curSize; k++) {imgByteToWrite.add(0);}// 第511、512字節為磁盤主引導扇區的有效標志,必須為0x55、0xaa// 0x1fe-0x1f: 0x55, 0xaa// 0x200-0x203: f0 ff ffimgByteToWrite.add(0x55);imgByteToWrite.add(0xaa);imgByteToWrite.add(0xf0);imgByteToWrite.add(0xff);imgByteToWrite.add(0xff);// 總共1.44MB大小len = 0x168000;curSize = imgByteToWrite.size();for (int l = 0; l < len - curSize; l++) {imgByteToWrite.add(0);}}public void makeFllopy() {try {DataOutputStream out = new DataOutputStream(new FileOutputStream("system.img"));for (int i = 0; i < imgByteToWrite.size(); i++) {out.writeByte(imgByteToWrite.get(i).byteValue());}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}public static void main(String[] args) {OperatingSystem op = new OperatingSystem("hello, this is my first line of my operating system code");op.makeFllopy();} }2 使用VirtualBox創建虛擬機并加載上述生成的軟盤文件
2.1 創建虛擬機
創建時,需要注意類型和版本的選擇:
一路下一步,這里不添加虛擬硬盤:
然后就創建完成。
我們需要設置虛擬機從軟驅啟動,點擊設置,設置方式如下:
然后添加軟驅:
然后選擇對應的虛擬軟盤即可:
2.2 加載軟盤中的內核
點擊啟動虛擬機,將出現如下界面,大功告成:
參考資料:
總結
以上是生活随笔為你收集整理的用java开发一个Hello Word系统内核的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 延时喷剂,能带上飞机吗?
- 下一篇: 用java和汇编开发一个Hello Wo