feat(shell): implement full interactive UNIX shell (osh), CMOS RTC, dual serial+PS2 keyboard input, and power management
This commit is contained in:
+41
-6
@@ -12,8 +12,11 @@
|
||||
#define SYS_THREAD_YIELD 7 /* Yield CPU slice */
|
||||
#define SYS_THREAD_EXIT 8 /* Terminate current thread */
|
||||
#define SYS_LOG_DEBUG 9 /* Direct Ring 0 debug print */
|
||||
#define SYS_KEY_READ 10 /* Read character from keyboard buffer */
|
||||
#define SYS_KEY_READ 10 /* Read character from keyboard / serial buffer */
|
||||
#define SYS_SYSINFO 11 /* Query system/memory/thread information */
|
||||
#define SYS_SHUTDOWN 12 /* Power off QEMU / system */
|
||||
#define SYS_REBOOT 13 /* Reboot system */
|
||||
#define SYS_RTC_GET 14 /* Get CMOS real-time clock */
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
|
||||
@@ -21,6 +24,23 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct sysinfo_data {
|
||||
uint64_t uptime_ticks;
|
||||
uint64_t total_memory_bytes;
|
||||
uint64_t free_memory_bytes;
|
||||
uint32_t active_threads;
|
||||
uint32_t cpu_cores;
|
||||
} sysinfo_data_t;
|
||||
|
||||
typedef struct rtc_data {
|
||||
uint16_t year;
|
||||
uint8_t month;
|
||||
uint8_t day;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
} rtc_data_t;
|
||||
|
||||
/* Low-level inline syscall invocations adhering to System V AMD64 ABI + Fast-Path */
|
||||
|
||||
static inline sysret_t sys_ipc_call_raw(cap_t dest_cap, uint64_t msg_code,
|
||||
@@ -94,15 +114,30 @@ static inline int sys_key_read(void) {
|
||||
return (int)rax;
|
||||
}
|
||||
|
||||
static inline sysret_t sys_sysinfo(uint64_t info_type, void *out_buf, size_t max_len) {
|
||||
static inline sysret_t sys_sysinfo(sysinfo_data_t *out_info) {
|
||||
register uint64_t rax __asm__("rax") = SYS_SYSINFO;
|
||||
register uint64_t rdi __asm__("rdi") = info_type;
|
||||
register uint64_t rsi __asm__("rsi") = (uint64_t)out_buf;
|
||||
register uint64_t rdx __asm__("rdx") = (uint64_t)max_len;
|
||||
__asm__ volatile("syscall" : "+r"(rax) : "r"(rdi), "r"(rsi), "r"(rdx) : "rcx", "r11", "memory");
|
||||
register uint64_t rdi __asm__("rdi") = (uint64_t)out_info;
|
||||
__asm__ volatile("syscall" : "+r"(rax) : "r"(rdi) : "rcx", "r11", "memory");
|
||||
return (sysret_t)rax;
|
||||
}
|
||||
|
||||
static inline sysret_t sys_rtc_get(rtc_data_t *out_rtc) {
|
||||
register uint64_t rax __asm__("rax") = SYS_RTC_GET;
|
||||
register uint64_t rdi __asm__("rdi") = (uint64_t)out_rtc;
|
||||
__asm__ volatile("syscall" : "+r"(rax) : "r"(rdi) : "rcx", "r11", "memory");
|
||||
return (sysret_t)rax;
|
||||
}
|
||||
|
||||
static inline void sys_shutdown(void) {
|
||||
register uint64_t rax __asm__("rax") = SYS_SHUTDOWN;
|
||||
__asm__ volatile("syscall" : "+r"(rax) : : "rcx", "r11", "memory");
|
||||
}
|
||||
|
||||
static inline void sys_reboot(void) {
|
||||
register uint64_t rax __asm__("rax") = SYS_REBOOT;
|
||||
__asm__ volatile("syscall" : "+r"(rax) : : "rcx", "r11", "memory");
|
||||
}
|
||||
|
||||
static inline sysret_t sys_yield(void) {
|
||||
register uint64_t rax __asm__("rax") = SYS_THREAD_YIELD;
|
||||
__asm__ volatile("syscall" : "+r"(rax) : : "rcx", "r11", "memory");
|
||||
|
||||
Reference in New Issue
Block a user