Add failed try
This commit is contained in:
@@ -97,6 +97,9 @@ duk_ret_t native_systable_pci_write_config(duk_context *ctx) {
|
|||||||
|
|
||||||
int kernel_main(EFI_SYSTEM_TABLE *st) {
|
int kernel_main(EFI_SYSTEM_TABLE *st) {
|
||||||
systemTable = st;
|
systemTable = st;
|
||||||
|
systemTable->ConOut->ClearScreen(systemTable->ConOut);
|
||||||
|
systemTable->ConOut->OutputString(systemTable->ConOut, L"START\r\n");
|
||||||
|
|
||||||
ctx = duk_create_heap_default();
|
ctx = duk_create_heap_default();
|
||||||
|
|
||||||
duk_push_c_function(ctx, native_systable_conout_output_string, 1);
|
duk_push_c_function(ctx, native_systable_conout_output_string, 1);
|
||||||
@@ -120,12 +123,12 @@ int kernel_main(EFI_SYSTEM_TABLE *st) {
|
|||||||
duk_push_c_function(ctx, native_systable_pci_write_config, 5);
|
duk_push_c_function(ctx, native_systable_pci_write_config, 5);
|
||||||
duk_put_global_string(ctx, "$___native_systable_pci_write_config");
|
duk_put_global_string(ctx, "$___native_systable_pci_write_config");
|
||||||
|
|
||||||
|
systemTable->ConOut->OutputString(systemTable->ConOut, L"RUN\r\n");
|
||||||
|
|
||||||
duk_push_string(ctx, EMBEDDED_JS);
|
duk_push_string(ctx, EMBEDDED_JS);
|
||||||
duk_int_t returnCode = duk_peval(ctx);
|
duk_int_t returnCode = duk_peval(ctx);
|
||||||
|
|
||||||
if (returnCode != 0)
|
/*if (returnCode != 0)
|
||||||
{
|
{
|
||||||
duk_safe_to_stacktrace(ctx, -1);
|
duk_safe_to_stacktrace(ctx, -1);
|
||||||
|
|
||||||
@@ -134,7 +137,7 @@ int kernel_main(EFI_SYSTEM_TABLE *st) {
|
|||||||
systemTable->ConOut->OutputString(systemTable->ConOut, buffer);
|
systemTable->ConOut->OutputString(systemTable->ConOut, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
duk_pop(ctx);
|
duk_pop(ctx);*/
|
||||||
|
|
||||||
systemTable->ConOut->OutputString(systemTable->ConOut, L"!!! KERNEL EXITED UNEXPECTEDLY !!!\r\n");
|
systemTable->ConOut->OutputString(systemTable->ConOut, L"!!! KERNEL EXITED UNEXPECTEDLY !!!\r\n");
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { Logger } from "../../../libs/logger";
|
import { Logger } from "../../../libs/logger";
|
||||||
|
import { Path } from "../../../libs/path";
|
||||||
|
import { sysfs, sysfs_mkdir, sysfs_writeFile } from "../../filesystem/sysfs";
|
||||||
|
|
||||||
export function kdriver_dev_pci_init() {}
|
export function kdriver_dev_pci_init() {
|
||||||
|
sysfs_mkdir("/pci");
|
||||||
|
}
|
||||||
|
|
||||||
export function kdriver_dev_pci_detectDevices() {
|
export function kdriver_dev_pci_detectDevices() {
|
||||||
Logger.log("[PCI] Scanning...");
|
Logger.log("[PCI] Scanning...");
|
||||||
@@ -51,6 +55,15 @@ export function kdriver_dev_pci_checkDevice(
|
|||||||
subclass.toString(16) +
|
subclass.toString(16) +
|
||||||
")"
|
")"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const dirname = Path.join("/pci", filename);
|
||||||
|
|
||||||
|
sysfs_mkdir(dirname);
|
||||||
|
sysfs_writeFile(Path.join(dirname, "vendor"), "Intel");
|
||||||
|
/*sysfs_writeFile(Path.join(dirname, "vendor"), vendorId.toString(16));
|
||||||
|
sysfs_writeFile(Path.join(dirname, "device"), deviceId.toString(16));
|
||||||
|
sysfs_writeFile(Path.join(dirname, "class"), classCode.toString(16));
|
||||||
|
sysfs_writeFile(Path.join(dirname, "subclass"), subclass.toString(16));*/
|
||||||
}
|
}
|
||||||
|
|
||||||
export function kdriver_dev_pci_getDeviceId(
|
export function kdriver_dev_pci_getDeviceId(
|
||||||
|
|||||||
106
os/src/kernel/filesystem/sysfs.ts
Normal file
106
os/src/kernel/filesystem/sysfs.ts
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
import { Logger } from "../../libs/logger";
|
||||||
|
import { Path } from "../../libs/path";
|
||||||
|
import {
|
||||||
|
FilesystemType,
|
||||||
|
type Filesystem,
|
||||||
|
type FilesystemEntity,
|
||||||
|
} from "../../types/kernel/filesystem";
|
||||||
|
|
||||||
|
const sysfs_data: FilesystemEntity[] = [];
|
||||||
|
|
||||||
|
export function sysfs(): Filesystem {
|
||||||
|
return {
|
||||||
|
type: FilesystemType.SYSFS,
|
||||||
|
mkdir: sysfs_mkdir,
|
||||||
|
ls: sysfs_ls,
|
||||||
|
writeFile(path, content) {
|
||||||
|
throw new Error("Cannot write to sysfs");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sysfs_root(): FilesystemEntity {
|
||||||
|
/*return {
|
||||||
|
name: "$root",
|
||||||
|
path: "/",
|
||||||
|
size: 0,
|
||||||
|
isDirectory: true,
|
||||||
|
contents: null,
|
||||||
|
};*/
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sysfs_get(path: string): FilesystemEntity | null {
|
||||||
|
if (path == "" || path == "/") return sysfs_root();
|
||||||
|
|
||||||
|
for (let i = 0; i < sysfs_data.length; i++) {
|
||||||
|
Logger.log(sysfs_data[i]);
|
||||||
|
|
||||||
|
if (sysfs_data[i]!.path === path) {
|
||||||
|
return sysfs_data[i]!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sysfs_mkdir(path: string) {
|
||||||
|
if (sysfs_get(path)) return;
|
||||||
|
|
||||||
|
const parent = sysfs_get(Path.dirname(path));
|
||||||
|
if (!parent || !parent.isDirectory) return;
|
||||||
|
|
||||||
|
Logger.log(path);
|
||||||
|
|
||||||
|
/*sysfs_data.push({
|
||||||
|
name: Path.filename(path),
|
||||||
|
path: path,
|
||||||
|
size: 0,
|
||||||
|
isDirectory: true,
|
||||||
|
contents: 0,
|
||||||
|
});*/
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sysfs_ls(path: string): FilesystemEntity[] | null {
|
||||||
|
/*const entity = sysfs_get(path);
|
||||||
|
if (!entity || !entity.isDirectory) return null;
|
||||||
|
|
||||||
|
const result: FilesystemEntity[] = [];
|
||||||
|
const prefix = path + "/";
|
||||||
|
|
||||||
|
for (let i = 0; i < globalThis.sysfs_data.length; i++) {
|
||||||
|
const itemPath = globalThis.sysfs_data[i]!.path;
|
||||||
|
|
||||||
|
// Only include direct children (no additional slashes after the prefix)
|
||||||
|
if (
|
||||||
|
itemPath.startsWith(prefix) &&
|
||||||
|
!itemPath.substring(prefix.length).includes("/")
|
||||||
|
) {
|
||||||
|
result.push(globalThis.sysfs_data[i]!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sysfs_createFile(path: string, content: string) {
|
||||||
|
if (sysfs_get(path)) return;
|
||||||
|
|
||||||
|
/*const parent = sysfs_getParent(path);
|
||||||
|
if (!parent || !parent.isDirectory) return;
|
||||||
|
|
||||||
|
globalThis.sysfs_data.push({
|
||||||
|
name: Path.filename(path),
|
||||||
|
path: path,
|
||||||
|
size: content.length,
|
||||||
|
isDirectory: false,
|
||||||
|
contents: content,
|
||||||
|
});*/
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sysfs_writeFile(path: string, content: string) {
|
||||||
|
const entity = sysfs_get(path);
|
||||||
|
/*if (!entity) return sysfs_createFile(path, content);
|
||||||
|
if (entity.isDirectory) return;
|
||||||
|
|
||||||
|
entity.contents = content;*/
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Logger } from "../libs/logger";
|
import { Logger } from "../libs/logger";
|
||||||
import { kdriver_dev_pci_detectDevices } from "./drivers/dev/pci.kdriver";
|
import { kdriver_dev_pci_detectDevices } from "./drivers/dev/pci.kdriver";
|
||||||
|
import { sysfs_ls } from "./filesystem/sysfs";
|
||||||
import {
|
import {
|
||||||
kmod_console_clearScreen,
|
kmod_console_clearScreen,
|
||||||
kmod_console_outputString,
|
kmod_console_outputString,
|
||||||
@@ -15,5 +16,11 @@ export function kmain() {
|
|||||||
|
|
||||||
kdriver_dev_pci_detectDevices();
|
kdriver_dev_pci_detectDevices();
|
||||||
|
|
||||||
|
/*const files = sysfs_ls("/");
|
||||||
|
|
||||||
|
files!.forEach(function (file) {
|
||||||
|
Logger.log(file.name);
|
||||||
|
});*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
12
os/src/libs/path.ts
Normal file
12
os/src/libs/path.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export const Path = {
|
||||||
|
join(p1: string, p2: string): string {
|
||||||
|
if (p1.endsWith("/")) return p1 + p2;
|
||||||
|
else return p1 + "/" + p2;
|
||||||
|
},
|
||||||
|
filename(path: string): string {
|
||||||
|
return path.split("/").pop()!;
|
||||||
|
},
|
||||||
|
dirname(path: string): string {
|
||||||
|
return path.split("/").slice(0, -1).join("/");
|
||||||
|
},
|
||||||
|
};
|
||||||
18
os/src/types/kernel/filesystem.ts
Normal file
18
os/src/types/kernel/filesystem.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
export enum FilesystemType {
|
||||||
|
SYSFS,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Filesystem {
|
||||||
|
type: FilesystemType;
|
||||||
|
mkdir(path: string): void;
|
||||||
|
ls(path: string): FilesystemEntity[] | null;
|
||||||
|
writeFile(path: string, content: string): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FilesystemEntity = {
|
||||||
|
name: string;
|
||||||
|
path: string;
|
||||||
|
size: number;
|
||||||
|
isDirectory: boolean;
|
||||||
|
contents: string | number | number[] | null;
|
||||||
|
};
|
||||||
@@ -1,4 +1 @@
|
|||||||
./scripts/build_ts.sh
|
./scripts/build_ts.sh && ./scripts/build_c.sh && ./scripts/out_to_iso.sh && ./scripts/run_vbox.sh
|
||||||
./scripts/build_c.sh
|
|
||||||
./scripts/out_to_iso.sh
|
|
||||||
./scripts/run_vbox.sh
|
|
||||||
Reference in New Issue
Block a user