CE process watching WIP
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
|
||||
set -x
|
||||
|
||||
qemu-system-x86_64 -M pc -m 4G -serial stdio -enable-kvm -cdrom mop3.iso -smp 4 -boot d $@
|
||||
qemu-system-x86_64 -M pc -m 4G -serial stdio -enable-kvm -cdrom mop3.iso -smp 1 -boot d $@
|
||||
|
||||
@@ -9,7 +9,7 @@ $(eval $(call add_lib,libterminal))
|
||||
$(eval $(call add_lib,libfat))
|
||||
$(eval $(call add_lib,libmalloc))
|
||||
$(eval $(call add_lib,libdebugconsole))
|
||||
$(eval $(call add_include,libkb))
|
||||
$(eval $(call add_lib,libkb))
|
||||
|
||||
cflags += -DPRINTF_INCLUDE_CONFIG_H=1
|
||||
|
||||
|
||||
6
ce/ce.c
6
ce/ce.c
@@ -76,9 +76,11 @@ void app_main (void) {
|
||||
|
||||
mprintf (PROMPT);
|
||||
|
||||
uint8_t ch = 0;
|
||||
for (;;) {
|
||||
mail_receive (&ch, 1);
|
||||
int ch = kb_read_key ();
|
||||
|
||||
if (ch == 0)
|
||||
continue;
|
||||
|
||||
if (ch == '\n')
|
||||
break;
|
||||
|
||||
32
ce/interp.c
32
ce/interp.c
@@ -342,10 +342,16 @@ static void help (struct context* context) {
|
||||
static void cmd_cancel_proc (void* arg) {
|
||||
int pid = (int)(uintptr_t)arg;
|
||||
|
||||
char ch = 0;
|
||||
do {
|
||||
mail_receive_nonblock (&ch, 1);
|
||||
} while (ch != KB_CTRL ('C'));
|
||||
int ch = 0;
|
||||
|
||||
for (;;) {
|
||||
ch = kb_read_key_nonblock ();
|
||||
|
||||
if (ch == KB_CTRL ('C'))
|
||||
break;
|
||||
else
|
||||
sched ();
|
||||
}
|
||||
|
||||
kill (pid);
|
||||
}
|
||||
@@ -353,12 +359,15 @@ static void cmd_cancel_proc (void* arg) {
|
||||
static void cmd_collect_proc (void* arg) {
|
||||
#define RECV_MAX (1024 * 16)
|
||||
|
||||
(void)arg;
|
||||
|
||||
char recv[RECV_MAX];
|
||||
for (;;) {
|
||||
char recv[RECV_MAX];
|
||||
memset (recv, 0, sizeof (recv));
|
||||
if (mail_receive_nonblock (&recv, sizeof (recv) - 1) == ST_OK) {
|
||||
if (mail_receive_nonblock (&recv, sizeof (recv) - 1) == ST_OK)
|
||||
mail_send (process_get_exec_pgid (), recv, strlen (recv));
|
||||
}
|
||||
else
|
||||
sched ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,17 +442,16 @@ static void execute_cmd (struct ast_cmd* cmd, struct context* context) {
|
||||
}
|
||||
}
|
||||
|
||||
exec_partial_fini (pid);
|
||||
|
||||
struct process_data* cancel_pdata = process_spawn (&cmd_cancel_proc, (void*)pid);
|
||||
struct process_data* collect_pdata = process_spawn (&cmd_collect_proc, NULL);
|
||||
struct process_data* cancel_pdata = process_spawn (&cmd_cancel_proc, (void*)pid);
|
||||
|
||||
exec_partial_fini (pid);
|
||||
wait_for_pid (pid);
|
||||
|
||||
kill (cancel_pdata->pid);
|
||||
process_data_free (cancel_pdata);
|
||||
kill (collect_pdata->pid);
|
||||
process_data_free (collect_pdata);
|
||||
kill (cancel_pdata->pid);
|
||||
process_data_free (cancel_pdata);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
#define TERMINAL_DIMENSIONS 1
|
||||
|
||||
/* keyboard device */
|
||||
#define KB_READ_KEY 0
|
||||
#define KB_READ_KEY 0
|
||||
#define KB_READ_KEY_NONBLOCK 1
|
||||
|
||||
/* drive devices */
|
||||
#define XDRV_TYPE_RAMDRV 0
|
||||
|
||||
@@ -3,7 +3,6 @@ include ../make/ufuncs.mk
|
||||
$(eval $(call add_lib,libterminal))
|
||||
$(eval $(call add_lib,libprocess))
|
||||
$(eval $(call add_lib,libstring))
|
||||
$(eval $(call add_lib,libkb))
|
||||
$(eval $(call add_lib,libdebugconsole))
|
||||
$(eval $(call add_lib,libaux))
|
||||
$(eval $(call add_lib,libmalloc))
|
||||
|
||||
12
init/init.c
12
init/init.c
@@ -1,5 +1,4 @@
|
||||
#include <debugconsole.h>
|
||||
#include <kb.h>
|
||||
#include <limits.h>
|
||||
#include <malloc.h>
|
||||
#include <process.h>
|
||||
@@ -30,14 +29,9 @@ void app_main (void) {
|
||||
int ce_pid = exec ("sys", "/ce");
|
||||
ce_pgid = get_procgroup (ce_pid);
|
||||
|
||||
process_spawn (&receiver, NULL);
|
||||
struct process_data* pdata = process_spawn (&receiver, NULL);
|
||||
|
||||
for (;;) {
|
||||
int ch = kb_read_key ();
|
||||
wait_for_pid (pdata->pid);
|
||||
|
||||
if (ch == 0)
|
||||
continue;
|
||||
|
||||
mail_send (ce_pgid, (uint8_t*)&ch, 1);
|
||||
}
|
||||
process_data_free (pdata);
|
||||
}
|
||||
|
||||
@@ -27,9 +27,11 @@ uintptr_t syscall_dispatch (void* stack_ptr) {
|
||||
|
||||
spin_lock (&thiscpu->lock, &fc);
|
||||
struct proc* caller = thiscpu->proc_current;
|
||||
int caller_pid = caller->pid;
|
||||
|
||||
spin_lock (&caller->lock, &fp);
|
||||
|
||||
int caller_pid = caller->pid;
|
||||
|
||||
memcpy (&caller->pdata.regs, regs, sizeof (struct saved_regs));
|
||||
|
||||
fx_save (caller->pdata.fx_env);
|
||||
|
||||
@@ -188,6 +188,7 @@ static void ps2kb_device_init (void) {
|
||||
|
||||
device_op_func_t ops[] = {
|
||||
[KB_READ_KEY] = &ps2kb_read_key,
|
||||
[KB_READ_KEY_NONBLOCK] = &ps2kb_read_key_nonblock,
|
||||
};
|
||||
device_create ("kb", ops, lengthof (ops), &ps2kb_init, &ps2kb_fini, NULL, thiscpu->kproc, &rctx);
|
||||
}
|
||||
|
||||
@@ -213,6 +213,33 @@ DEFINE_DEVICE_OP (ps2kb_read_key) {
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
DEFINE_DEVICE_OP (ps2kb_read_key_nonblock) {
|
||||
uint64_t frb, fsq;
|
||||
|
||||
uint8_t* chbuf = (uint8_t*)a1;
|
||||
|
||||
if (chbuf == NULL)
|
||||
return -ST_BAD_ADDRESS_SPACE;
|
||||
|
||||
spin_lock (&ps2kb_ringbuffer_lock, &frb);
|
||||
|
||||
size_t prev_count = ps2kb_ringbuffer.count;
|
||||
|
||||
ringbuffer_pop (uint8_t, &ps2kb_ringbuffer, chbuf);
|
||||
|
||||
size_t new_count = ps2kb_ringbuffer.count;
|
||||
|
||||
/* didn't pop anything */
|
||||
if (prev_count == new_count) {
|
||||
spin_unlock (&ps2kb_ringbuffer_lock, frb);
|
||||
return -ST_TRY_AGAIN;
|
||||
}
|
||||
|
||||
spin_unlock (&ps2kb_ringbuffer_lock, frb);
|
||||
|
||||
return ST_OK;
|
||||
}
|
||||
|
||||
static void ps2kb_set_typematic (uint8_t delay, uint8_t rate) {
|
||||
while (inb (KB_CTL_STATUS) & 0x02)
|
||||
;
|
||||
|
||||
@@ -11,6 +11,8 @@ struct device;
|
||||
|
||||
DEFINE_DEVICE_OP (ps2kb_read_key);
|
||||
|
||||
DEFINE_DEVICE_OP (ps2kb_read_key_nonblock);
|
||||
|
||||
DEFINE_DEVICE_INIT (ps2kb_init);
|
||||
|
||||
DEFINE_DEVICE_FINI (ps2kb_fini);
|
||||
|
||||
10
libkb/kb.c
10
libkb/kb.c
@@ -13,3 +13,13 @@ int kb_read_key (void) {
|
||||
else
|
||||
return r;
|
||||
}
|
||||
|
||||
int kb_read_key_nonblock (void) {
|
||||
char ch = 0;
|
||||
int r = device_do ("kb", KB_READ_KEY_NONBLOCK, &ch, NULL, NULL, NULL);
|
||||
|
||||
if (r == ST_OK)
|
||||
return (int)ch;
|
||||
else
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
#include <kb_defs.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* \brief Read key from keyboard
|
||||
* \return < 0 status on failure; ascii key on success
|
||||
*/
|
||||
int kb_read_key (void);
|
||||
|
||||
int kb_read_key_nonblock (void);
|
||||
|
||||
#endif // _LIBKB_KB_H
|
||||
|
||||
@@ -91,12 +91,12 @@ int create_volume (const char* key, int fs_type, const char* device_key) {
|
||||
return (int)do_syscall (SYS_CREATE_VOLUME, key, fs_type, device_key);
|
||||
}
|
||||
|
||||
int env_set (int pid, const char* key, void* buffer, size_t len) {
|
||||
return (int)do_syscall (SYS_ENV_SET, pid, key, buffer, len);
|
||||
int env_set (int pgid, const char* key, void* buffer, size_t len) {
|
||||
return (int)do_syscall (SYS_ENV_SET, pgid, key, buffer, len);
|
||||
}
|
||||
|
||||
int env_get (int pid, const char* key, void* buffer, size_t len) {
|
||||
return (int)do_syscall (SYS_ENV_GET, pid, key, buffer, len);
|
||||
int env_get (int pgid, const char* key, void* buffer, size_t len) {
|
||||
return (int)do_syscall (SYS_ENV_GET, pgid, key, buffer, len);
|
||||
}
|
||||
|
||||
int exec_partial (const char* volume, const char* path) {
|
||||
|
||||
@@ -97,10 +97,10 @@ int remove (const char* path);
|
||||
int create_volume (const char* key, int fs_type, const char* device_key);
|
||||
|
||||
/* Set environment variable */
|
||||
int env_set (int pid, const char* key, void* buffer, size_t len);
|
||||
int env_set (int pgid, const char* key, void* buffer, size_t len);
|
||||
|
||||
/* Get environment variable */
|
||||
int env_get (int pid, const char* key, void* buffer, size_t len);
|
||||
int env_get (int pgid, const char* key, void* buffer, size_t len);
|
||||
|
||||
/* Prepare process for execution */
|
||||
int exec_partial (const char* volume, const char* path);
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
include ../make/ufuncs.mk
|
||||
|
||||
$(eval $(call add_lib,libstring))
|
||||
$(eval $(call add_lib,libprocess))
|
||||
$(eval $(call add_lib,libaux))
|
||||
$(eval $(call add_lib,libmalloc))
|
||||
|
||||
cflags += -DPRINTF_INCLUDE_CONFIG_H=1
|
||||
|
||||
include ../make/user.mk
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
#include <mprintf.h>
|
||||
#include <process_self.h>
|
||||
#include <status.h>
|
||||
#include <system.h>
|
||||
|
||||
void app_main (void) {}
|
||||
#define COMMAND_MAX 32
|
||||
|
||||
void app_main (void) {
|
||||
libprocess_self_init ();
|
||||
|
||||
char commandbuf[COMMAND_MAX];
|
||||
commandbuf[0] = '\0';
|
||||
|
||||
mprintf ("HELLO!\n");
|
||||
|
||||
/* if (env_get (process_get_pgid (), "C", (void*)commandbuf, sizeof (commandbuf)) == ST_OK) { */
|
||||
/* } */
|
||||
|
||||
/* mprintf ("C=%s\n", commandbuf); */
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <system.h>
|
||||
|
||||
void app_main (void) {
|
||||
for (;;)
|
||||
;
|
||||
sched ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user