Feat: lab 3 w/o adv 2

This commit is contained in:
2025-03-26 15:30:57 +08:00
parent c5fc7e3102
commit 96cfdc4de2
25 changed files with 618 additions and 113 deletions

View File

@@ -1,4 +1,6 @@
#include <stddef.h>
#include <logger.h>
#include <timer.h>
#include <errcode.h>
#include <kmalloc.h>
#include <utils.h>
@@ -109,6 +111,35 @@ void _exec(file_node_t *root, const char *filename)
}
}
static inline
void _settimeout_cb_func(uint64_t args)
{
vector_t *v = (void *)args;
for (int i = 2; i < (int)v->size; ++i) {
uart_puts(VEC_AT(char, v, i));
uart_puts(" ");
}
uart_puts(ENDL);
}
static inline
void _settimeout(int32_t sec, vector_t *args)
{
uint64_t cntpct_el0, cntfrq_el0;
R_SYSREG(cntpct_el0, cntpct_el0);
R_SYSREG(cntfrq_el0, cntfrq_el0);
task_t task = (task_t){
.firing_tick = cntpct_el0 + sec * cntfrq_el0,
.interval = sec * cntfrq_el0,
.repeat = 1,
.func = _settimeout_cb_func,
.param = (uint64_t)args,
};
add_task(task);
}
static inline
void _set(long addr, unsigned int value) {
volatile unsigned int* point = (unsigned int*)addr;
@@ -130,45 +161,47 @@ void _reboot(void)
int shell(file_node_t *initrd_root)
{
uart_puts("# ");
char buf[INPUT_BUFLEN], ch;
char *buf = kmalloc(INPUT_BUFLEN * sizeof(char)), ch;
int sz = 0;
while ((ch = uart_getc()) != '\n') {
buf[sz++] = ch;
uart_send(ch);
uart_putb((const uint8_t *)&ch, 1);
}
uart_puts(ENDL);
buf[sz] = '\0';
buf[sz] = ' ';
const char *i = buf;
vector_t *args = make_vector(0);
for (char *saveptr = 0x0, *tok = strtok_r(buf, " ", &saveptr);
tok; tok = strtok_r((char *)0x0, " ", &saveptr)) {
VEC_PUSH(args, tok);
LOG(tok);
}
char bin[INPUT_BUFLEN], *j;
for (j = bin; *i != '\0' && !isspace(*i); ++i, ++j)
*j = *i;
*j = '\0';
// DEBUG("ENDL");
CLEAN;
for (; *i != '\0' && isspace(*i); ++i);
char param[INPUT_BUFLEN];
for (j = param; *i != '\0' && !isspace(*i); ++i, ++j)
*j = *i;
*j = '\0';
if (!strcmp(bin, "help")) {
char *cmd = args->size ? VEC_AT(char, args, 0) : (char *)0x0;
if (!strcmp(cmd, "help")) {
_help();
} else if (!strcmp(bin, "hello")) {
} else if (!strcmp(cmd, "hello")) {
_hello();
} else if (!strcmp(bin, "hwinfo")) {
} else if (!strcmp(cmd, "hwinfo")) {
_hwinfo();
} else if (!strcmp(bin, "memalloc")){
_memalloc((size_t)atoi32(param));
} else if (!strcmp(bin, "ls")) {
} else if (!strcmp(cmd, "memalloc") && args->size >= 2){
char *p1 = VEC_AT(char, args, 1);
_memalloc((size_t)atoi32(p1));
} else if (!strcmp(cmd, "ls")) {
_ls(initrd_root);
} else if (!strcmp(bin, "cat")) {
_cat(initrd_root, param);
} else if (!strcmp(bin, "exec")) {
_exec(initrd_root, param);
} else if (!strcmp(bin, "reboot")) {
} else if (!strcmp(cmd, "cat") && args->size >= 2) {
char *p1 = VEC_AT(char, args, 1);
_cat(initrd_root, p1);
} else if (!strcmp(cmd, "exec") && args->size >= 2) {
char *p1 = VEC_AT(char, args, 1);
_exec(initrd_root, p1);
} else if (!strcmp(cmd, "settimeout") && args->size >= 2) {
char *p1 = VEC_AT(char, args, 1);
_settimeout(atoi32(p1), args);
} else if (!strcmp(cmd, "reboot")) {
_reboot();
}