2020-10-17 04:13:18 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
2020-05-08 06:44:32 +02:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
2020-05-10 06:21:49 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2020-10-12 05:02:02 +02:00
|
|
|
#include <sys/mman.h>
|
2020-05-10 06:21:49 +02:00
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/stat.h>
|
2020-05-08 06:44:32 +02:00
|
|
|
#include <sys/time.h>
|
2020-05-10 06:21:49 +02:00
|
|
|
#include <sys/types.h>
|
2020-05-08 06:44:32 +02:00
|
|
|
#include "umka.h"
|
2020-05-10 06:21:49 +02:00
|
|
|
#include "shell.h"
|
2020-10-17 04:13:18 +02:00
|
|
|
#include "trace.h"
|
2020-05-08 06:44:32 +02:00
|
|
|
|
2020-10-17 04:13:18 +02:00
|
|
|
#define THREAD_STACK_SIZE 0x100000
|
2020-05-08 06:44:32 +02:00
|
|
|
|
2020-10-17 04:13:18 +02:00
|
|
|
static void
|
|
|
|
monitor(void) {
|
2020-10-14 19:56:28 +02:00
|
|
|
umka_sti();
|
2020-05-10 06:21:49 +02:00
|
|
|
fprintf(stderr, "Start monitor thread\n");
|
|
|
|
FILE *fin = fopen("/tmp/umka.fifo.2u", "r");
|
|
|
|
FILE *fout = fopen("/tmp/umka.fifo.4u", "w");
|
|
|
|
if (!fin || !fout) {
|
|
|
|
fprintf(stderr, "Can't open monitor files!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
run_test(fin, fout, 0);
|
2020-05-09 06:34:28 +02:00
|
|
|
}
|
|
|
|
|
2020-10-14 05:30:01 +02:00
|
|
|
void umka_thread_ping(void);
|
|
|
|
void umka_thread_net_drv(void);
|
|
|
|
|
|
|
|
struct itimerval timeout = {.it_value = {.tv_sec = 0, .tv_usec = 10000},
|
|
|
|
.it_interval = {.tv_sec = 0, .tv_usec = 10000}};
|
|
|
|
|
2020-10-17 04:13:18 +02:00
|
|
|
static void
|
|
|
|
thread_start(int is_kernel, void (*entry)(void), size_t stack_size) {
|
|
|
|
uint8_t *stack = malloc(stack_size);
|
|
|
|
umka_new_sys_threads(is_kernel, entry, stack + stack_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
can't get pty working
|
|
|
|
may be because of my custom threads and blocking, don't know
|
|
|
|
void new_monitor(void) {
|
2020-10-14 19:56:28 +02:00
|
|
|
umka_sti();
|
2020-10-17 04:13:18 +02:00
|
|
|
fprintf(stderr, "Start monitor thread\n");
|
|
|
|
|
|
|
|
int mpty = posix_openpt(O_RDWR | O_NOCTTY);
|
|
|
|
if (mpty == -1) {
|
|
|
|
perror("open master pty");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (grantpt(mpty) == -1) {
|
|
|
|
perror("grantpt");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (unlockpt(mpty) == -1) {
|
|
|
|
perror("unlockpt");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char *spty_name = ptsname(mpty);
|
|
|
|
if (spty_name == NULL) {
|
|
|
|
perror("open slave pty");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "[os] pty=%s\n", spty_name);
|
|
|
|
FILE *fmpty = fdopen(mpty, "r+");
|
|
|
|
if (fmpty == NULL) {
|
|
|
|
perror("fdopen mpty");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
run_test(fmpty, fmpty, 0);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
main() {
|
|
|
|
if (coverage)
|
|
|
|
trace_begin();
|
|
|
|
|
2020-05-11 05:38:44 +02:00
|
|
|
umka_tool = UMKA_OS;
|
2020-10-17 04:13:18 +02:00
|
|
|
umka_sti();
|
2020-05-08 06:44:32 +02:00
|
|
|
|
2020-10-10 01:30:52 +02:00
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_sigaction = irq0;
|
2020-05-08 06:44:32 +02:00
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = SA_SIGINFO;
|
|
|
|
|
|
|
|
if (sigaction(SIGPROF, &sa, NULL) == -1) {
|
|
|
|
printf("Can't install signal handler!\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-10-12 05:02:02 +02:00
|
|
|
/*
|
2020-10-21 16:57:54 +02:00
|
|
|
void *app_base = mmap((void*)0x000000, 16*0x100000, PROT_READ | PROT_WRITE |
|
|
|
|
PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS,
|
|
|
|
-1, 0);
|
2020-10-12 05:02:02 +02:00
|
|
|
if (app_base == MAP_FAILED) {
|
|
|
|
perror("mmap failed");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
printf("pid=%d, kos_lfb_base=%p\n", getpid(), (void*)kos_lfb_base);
|
2020-05-09 06:34:28 +02:00
|
|
|
|
2020-10-14 19:56:28 +02:00
|
|
|
umka_init();
|
|
|
|
umka_stack_init();
|
2020-10-14 05:30:01 +02:00
|
|
|
|
2020-10-17 04:13:18 +02:00
|
|
|
thread_start(0, monitor, THREAD_STACK_SIZE);
|
|
|
|
thread_start(0, umka_thread_net_drv, THREAD_STACK_SIZE);
|
|
|
|
// thread_start(0, umka_thread_ping, THREAD_STACK_SIZE);
|
2020-10-10 01:30:52 +02:00
|
|
|
|
2020-10-14 05:30:01 +02:00
|
|
|
setitimer(ITIMER_PROF, &timeout, NULL);
|
2020-10-10 01:30:52 +02:00
|
|
|
|
2020-10-14 19:56:28 +02:00
|
|
|
kos_osloop(); // doesn't return
|
2020-05-08 06:44:32 +02:00
|
|
|
|
2020-10-17 04:13:18 +02:00
|
|
|
if (coverage)
|
|
|
|
trace_end();
|
|
|
|
|
2020-05-08 06:44:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|