Doom port #21
@@ -50,9 +50,17 @@ void internal_putc(int c, void *_)
|
|||||||
if (init.terminal) {
|
if (init.terminal) {
|
||||||
if (panic_count == 0) {
|
if (panic_count == 0) {
|
||||||
spinlock_acquire(&term_lock);
|
spinlock_acquire(&term_lock);
|
||||||
|
if (ch == '\n') {
|
||||||
|
char cr = '\r';
|
||||||
|
flanterm_write(ft_ctx, &cr, 1);
|
||||||
|
}
|
||||||
flanterm_write(ft_ctx, &ch, 1);
|
flanterm_write(ft_ctx, &ch, 1);
|
||||||
spinlock_release(&term_lock);
|
spinlock_release(&term_lock);
|
||||||
} else {
|
} else {
|
||||||
|
if (ch == '\n') {
|
||||||
|
char cr = '\r';
|
||||||
|
flanterm_write(ft_ctx, &cr, 1);
|
||||||
|
}
|
||||||
flanterm_write(ft_ctx, &ch, 1);
|
flanterm_write(ft_ctx, &ch, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,9 +90,17 @@ void debug_putc(int c, void *_)
|
|||||||
if (init.terminal && (!init.all || panic_count > 0)) {
|
if (init.terminal && (!init.all || panic_count > 0)) {
|
||||||
if (panic_count == 0) {
|
if (panic_count == 0) {
|
||||||
spinlock_acquire(&term_lock);
|
spinlock_acquire(&term_lock);
|
||||||
|
if (ch == '\n') {
|
||||||
|
char cr = '\r';
|
||||||
|
flanterm_write(ft_ctx, &cr, 1);
|
||||||
|
}
|
||||||
flanterm_write(ft_ctx, &ch, 1);
|
flanterm_write(ft_ctx, &ch, 1);
|
||||||
spinlock_release(&term_lock);
|
spinlock_release(&term_lock);
|
||||||
} else {
|
} else {
|
||||||
|
if (ch == '\n') {
|
||||||
|
char cr = '\r';
|
||||||
|
flanterm_write(ft_ctx, &cr, 1);
|
||||||
|
}
|
||||||
flanterm_write(ft_ctx, &ch, 1);
|
flanterm_write(ft_ctx, &ch, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+68
-9
@@ -13,6 +13,7 @@
|
|||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <time/date.h>
|
#include <time/date.h>
|
||||||
#include <mem/kheap.h>
|
#include <mem/kheap.h>
|
||||||
|
#include <sched/process.h>
|
||||||
|
|
||||||
__attribute__((noinline))
|
__attribute__((noinline))
|
||||||
void smash_it()
|
void smash_it()
|
||||||
@@ -23,6 +24,52 @@ void smash_it()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern struct process* processes_list;
|
||||||
|
|
||||||
|
void ps()
|
||||||
|
{
|
||||||
|
printf("pid\tname\tstatus\n");
|
||||||
|
struct process* curr = processes_list;
|
||||||
|
while (curr != NULL) {
|
||||||
|
char* status;
|
||||||
|
switch (curr->status) {
|
||||||
|
case READY: status = "READY"; break;
|
||||||
|
case RUNNING: status = "RUNNING"; break;
|
||||||
|
case DEAD: status = "DEAD"; break;
|
||||||
|
default: status = "N/A"; break;
|
||||||
|
}
|
||||||
|
printf("%u\t%s\t%s\n", curr->pid, curr->name, status);
|
||||||
|
if (curr->next != NULL) {
|
||||||
|
curr = curr->next;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void kill()
|
||||||
|
{
|
||||||
|
char input_buf[11] = {0};
|
||||||
|
printf("pid> ");
|
||||||
|
keyboard_getline(input_buf, 10);
|
||||||
|
int pid = atoi(input_buf);
|
||||||
|
|
||||||
|
struct process* curr = processes_list;
|
||||||
|
while (curr != NULL) {
|
||||||
|
if (curr->pid == (size_t)pid) {
|
||||||
|
curr->status = DEAD; // equivalent of SIGKILL (no clean termination like SIGTERM)
|
||||||
|
printf("killed %d\n", pid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (curr->next != NULL) {
|
||||||
|
curr = curr->next;
|
||||||
|
} else {
|
||||||
|
printf("couldn't find process with PID %d\n", pid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* pedicel_main - Kernel shell main function
|
* pedicel_main - Kernel shell main function
|
||||||
* @arg: argument (optional)
|
* @arg: argument (optional)
|
||||||
@@ -44,15 +91,17 @@ void pedicel_main(void* arg)
|
|||||||
|
|
||||||
if (strncmp(input_buf, "help", 4) == 0) {
|
if (strncmp(input_buf, "help", 4) == 0) {
|
||||||
printf("++ shell builtins ++\r\n\r\n"
|
printf("++ shell builtins ++\r\n\r\n"
|
||||||
"\tclear - clear the screen\r\n"
|
"\tclear - clear the screen\n"
|
||||||
"\tpanic - trigger a test panic\r\n"
|
"\tpanic - trigger a test panic\n"
|
||||||
"\tsyscall - trigger int 0x80\r\n"
|
"\tsyscall - trigger int 0x80\n"
|
||||||
"\tpf - trigger a page fault\r\n"
|
"\tpf - trigger a page fault\n"
|
||||||
"\tnow - get current date\r\n"
|
"\tnow - get current date\n"
|
||||||
"\tsmash - smash the stack\r\n"
|
"\tsmash - smash the stack\n"
|
||||||
"\tmem - get used heap info\r\n"
|
"\tmem - get used heap info\n"
|
||||||
"\tload - load an user executable\r\n"
|
"\tload - load an user executable\n"
|
||||||
"\tlist - list initfs.tar contents\r\n");
|
"\tlist - list initfs.tar contents\n"
|
||||||
|
"\tps - list running processes\n"
|
||||||
|
"\tkill - kill a running process by PID\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +156,16 @@ void pedicel_main(void* arg)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strncmp(input_buf, "ps", 2) == 0) {
|
||||||
|
ps();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncmp(input_buf, "kill", 4) == 0) {
|
||||||
|
kill();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
printf("%s: command not found\r\n", input_buf);
|
printf("%s: command not found\r\n", input_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user