Add bios time module
This commit is contained in:
1
src/os/src/kernel/modules/bios/bios.kmod.ts
Normal file
1
src/os/src/kernel/modules/bios/bios.kmod.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./time"
|
||||
2
src/os/src/kernel/modules/bios/config.ts
Normal file
2
src/os/src/kernel/modules/bios/config.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export const CFG_KMOD_BIOS_TIME_CMOS_ADDR = 0x70;
|
||||
export const CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR = 0x71;
|
||||
96
src/os/src/kernel/modules/bios/time.ts
Normal file
96
src/os/src/kernel/modules/bios/time.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import { portin, portout } from "../../../lib/libts/port";
|
||||
import { padStart } from "../../../lib/libts/string";
|
||||
import {
|
||||
CFG_KMOD_BIOS_TIME_CMOS_ADDR,
|
||||
CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR,
|
||||
} from "./config";
|
||||
|
||||
export function kmod_bios_time_getCentury(): number {
|
||||
const val = 0x32;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getYear(): number {
|
||||
const val = 0x09;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getMonth(): number {
|
||||
const val = 0x08;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getDay(): number {
|
||||
const val = 0x07;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getHours(): number {
|
||||
const val = 0x04;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getMinutes(): number {
|
||||
const val = 0x02;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getSeconds(): number {
|
||||
const val = 0x00;
|
||||
|
||||
portout(CFG_KMOD_BIOS_TIME_CMOS_ADDR, val);
|
||||
const data = portin(CFG_KMOD_BIOS_TIME_CMOS_DATA_ADDR);
|
||||
|
||||
return (data & 0x0f) + ((data >> 4) & 0x0f) * 10;
|
||||
}
|
||||
|
||||
export function kmod_bios_time_getTimestamp(): string {
|
||||
const century = kmod_bios_time_getCentury();
|
||||
const year = kmod_bios_time_getYear();
|
||||
const month = kmod_bios_time_getMonth();
|
||||
const day = kmod_bios_time_getDay();
|
||||
const hours = kmod_bios_time_getHours();
|
||||
const minutes = kmod_bios_time_getMinutes();
|
||||
const seconds = kmod_bios_time_getSeconds();
|
||||
|
||||
return (
|
||||
century.toString() +
|
||||
year.toString() +
|
||||
"-" +
|
||||
padStart(month.toString(), 2, "0") +
|
||||
"-" +
|
||||
padStart(day.toString(), 2, "0") +
|
||||
"T" +
|
||||
padStart(hours.toString(), 2, "0") +
|
||||
":" +
|
||||
padStart(minutes.toString(), 2, "0") +
|
||||
":" +
|
||||
padStart(seconds.toString(), 2, "0") +
|
||||
+".000" +
|
||||
"Z"
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
kmod_graphics_vga_clear,
|
||||
kmod_graphics_vga_writeChar,
|
||||
} from "./modules/graphics/vga";
|
||||
} from "./modules/graphics/graphics.kmod";
|
||||
|
||||
export function kpanic(reason?: string) {
|
||||
kmod_graphics_vga_clear();
|
||||
|
||||
7
src/os/src/lib/libts/port.ts
Normal file
7
src/os/src/lib/libts/port.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export function portin(port: number): number {
|
||||
return $ptin(port);
|
||||
}
|
||||
|
||||
export function portout(port: number, value: number): void {
|
||||
$ptout(port, value);
|
||||
}
|
||||
11
src/os/src/lib/libts/string.ts
Normal file
11
src/os/src/lib/libts/string.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export function padStart(
|
||||
str: string,
|
||||
targetLength: number,
|
||||
padString: string
|
||||
): string {
|
||||
while (str.length < targetLength) {
|
||||
str = padString + str;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
5
src/os/src/lib/sys/date.ts
Normal file
5
src/os/src/lib/sys/date.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { kmod_bios_time_getTimestamp } from "../../kernel/modules/bios/time";
|
||||
|
||||
export function getDate(): Date {
|
||||
return new Date(kmod_bios_time_getTimestamp());
|
||||
}
|
||||
Reference in New Issue
Block a user