-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
109 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
[patch."https://github.com/Byte-OS/fs.git".fs] | ||
path = "crates/fs" | ||
|
||
[profile.release] | ||
debug = true | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts"; | ||
import { cliCommand as buildCommand } from './scripts/cli-build.ts'; | ||
import { cliCommand as qemuCommand } from './scripts/cli-qemu.ts'; | ||
import { cliCommand as rootfsCommand } from './scripts/cli-rootfs.ts'; | ||
import { logLevelEnum, archEnum } from './scripts/cli-types.ts'; | ||
import { parse } from "jsr:@std/yaml"; | ||
|
||
|
@@ -18,6 +19,7 @@ const command = new Command() | |
|
||
// Sub Command build | ||
.command("build", buildCommand) | ||
.command("rootfs", rootfsCommand) | ||
.command("qemu", qemuCommand); | ||
|
||
// parse yaml file | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { Command, CommandOptions } from "https://deno.land/x/[email protected]/command/mod.ts"; | ||
import { globalArgType } from "./cli-types.ts"; | ||
import { KernelBuilder } from "./kernel.ts"; | ||
import { runCommand } from "./runHelper.ts"; | ||
import { parseArgsString } from "./runHelper.ts"; | ||
|
||
class QemuRunner { | ||
arch: string; | ||
|
@@ -9,72 +11,53 @@ class QemuRunner { | |
memorySize: string = "1G"; | ||
smp: string = "1"; | ||
|
||
|
||
constructor(options: CommandOptions<globalArgType>, builder: KernelBuilder) { | ||
this.arch = options.arch; | ||
this.builder = builder; | ||
if(this.arch == "x86_64" || this.arch == "loongarch64") | ||
if (this.arch == "x86_64" || this.arch == "loongarch64") | ||
this.bus = "pci"; | ||
} | ||
|
||
getQemuArchExec(): string[] { | ||
return { | ||
x86_64: [ | ||
"-machine", | ||
"q35", | ||
"-kernel", | ||
this.builder.elfPath, | ||
"-cpu", | ||
"IvyBridge-v2" | ||
], | ||
riscv64: [ | ||
"-machine", | ||
"virt", | ||
"-kernel", | ||
this.builder.binPath | ||
], | ||
aarch64: [ | ||
"-cpu", | ||
"cortex-a72", | ||
"-machine", | ||
"virt", | ||
"-kernel", | ||
this.builder.binPath | ||
], | ||
loongarch64: [ | ||
"-kernel", | ||
this.builder.elfPath | ||
] | ||
x86_64: parseArgsString(` | ||
-machine q35 | ||
-kernel ${this.builder.elfPath} | ||
-cpu IvyBridge-v2 | ||
`), | ||
riscv64: parseArgsString(` | ||
-machine virt | ||
-kernel ${this.builder.binPath} | ||
`), | ||
aarch64: parseArgsString(` | ||
-machine virt | ||
-cpu cortex-a72 | ||
-kernel ${this.builder.binPath} | ||
`), | ||
loongarch64: parseArgsString(` | ||
-kernel ${this.builder.elfPath} | ||
`) | ||
}[this.arch] ?? []; | ||
} | ||
|
||
async run() { | ||
const qemuCommand = new Deno.Command(`qemu-system-${this.arch}`, { | ||
args: [ | ||
...this.getQemuArchExec(), | ||
"-m", | ||
this.memorySize, | ||
"-nographic", | ||
"-smp", | ||
this.smp, | ||
// Dump Debug information. | ||
"-D", | ||
"qemu.log", | ||
"-d", | ||
"in_asm,int,pcall,cpu_reset,guest_errors", | ||
// Add virtio block device. | ||
"-drive", | ||
"file=mount.img,if=none,format=raw,id=x0", | ||
"-device", | ||
"virtio-blk-device,drive=x0" | ||
] | ||
}); | ||
await qemuCommand.spawn().status; | ||
await runCommand(` | ||
qemu-system-${this.arch} ${this.getQemuArchExec().join(" ")} | ||
-m ${this.memorySize} | ||
-smp ${this.smp} | ||
-D qemu.log", | ||
-d in_asm,int,pcall,cpu_reset,guest_errors | ||
-drive | ||
file=mount.img,if=none,format=raw,id=x0 | ||
-device | ||
virtio-blk-${this.bus},drive=x0 | ||
-nographic | ||
`).spawn().status; | ||
} | ||
} | ||
|
||
async function runQemu(options: CommandOptions<globalArgType>) { | ||
const builder = new KernelBuilder(options.arch); | ||
const builder = new KernelBuilder(options.arch, options.logLevel); | ||
await builder.buildElf(); | ||
await builder.convertBin(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Command, CommandOptions } from "https://deno.land/x/[email protected]/command/mod.ts"; | ||
import { globalArgType } from "./cli-types.ts"; | ||
import { runCommand } from "./runHelper.ts"; | ||
|
||
/** | ||
* Build the root filesystem image for the kernel. | ||
* @param options Global arguments for the command. | ||
*/ | ||
async function buildRootFS(options: CommandOptions<globalArgType>) { | ||
// Create disk image | ||
const ddStatus = await runCommand(` | ||
dd if=/dev/zero of=mount.img bs=1M count=64 | ||
`).spawn().status; | ||
if (!ddStatus.success) return; | ||
|
||
// Format the disk image as ext4 | ||
const mkfsStatus = await runCommand(` | ||
mkfs.ext4 -F -O ^metadata_csum_seed mount.img | ||
`).spawn().status; | ||
if (!mkfsStatus.success) return; | ||
|
||
// Mount the disk image to a temporary directory | ||
// and copy the necessary files into it | ||
if(!(await Deno.lstat("mount")).isDirectory) { | ||
await Deno.mkdir("mount"); | ||
}; | ||
|
||
await runCommand(`sudo mount mount.img mount`).spawn().status; | ||
await runCommand(`sudo rsync -r tools/testcase-${options.arch}/ mount`).spawn().status; | ||
await runCommand(`sudo umount mount`).spawn().status; | ||
} | ||
|
||
export const cliCommand = new Command<globalArgType>() | ||
.description("Build root fs image for the kernel") | ||
.action(buildRootFS); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function parseArgsString(cmdLine: string): string[] { | ||
return cmdLine.trim().split(/\s+/); | ||
} | ||
|
||
export function runCommand(cmdLine: string): Deno.Command { | ||
const args = parseArgsString(cmdLine); | ||
return new Deno.Command(args[0], { | ||
args: args.slice(1) | ||
}); | ||
} | ||
|
||
export function testParse() { | ||
const args = parseArgsString("qemu-system-x86_64 --arch x86_64 --log-level info"); | ||
console.log(args); | ||
} |