[sys] More system calls, more stability, kill bad processes

This commit is contained in:
Kevin Lange 2011-04-17 13:26:31 -05:00
parent 9e3d03da4f
commit 254ceb51ab
11 changed files with 70 additions and 14 deletions

View File

@ -14,7 +14,7 @@ ECHO = `which echo` -e
MODULES = $(patsubst %.c,%.o,$(wildcard kernel/core/*.c))
FILESYSTEMS = $(patsubst %.c,%.o,$(wildcard kernel/core/fs/*.c))
VIDEODRIVERS = $(patsubst %.c,%.o,$(wildcard kernel/core/video/*.c))
BINARIES = initrd/bin/hello initrd/bin/echo initrd/bin/yes initrd/bin/cat
BINARIES = initrd/bin/hello initrd/bin/echo initrd/bin/yes initrd/bin/cat initrd/bin/sh
UTILITIES = util/bin/readelf util/bin/typewriter
EMU = qemu
GENEXT = genext2fs

View File

@ -68,6 +68,23 @@ get_time(
*seconds = from_bcd(values[0]);
}
int
gettimeofday(struct timeval * t, void *z) {
uint16_t values[128];
cmos_dump(values);
/* Math Time */
uint32_t time = (from_bcd(values[9]) - 70) * 31556926 +
from_bcd(values[8]) * 2629743 +
from_bcd(values[7]) * 87400 +
from_bcd(values[4]) * 3600 +
from_bcd(values[2]) * 60 +
from_bcd(values[0]);
t->tv_sec = time;
t->tv_usec = 0;
return 0;
}
/*
* vim:tabstop=4
* vim:noexpandtab

View File

@ -12,7 +12,8 @@ void kernel_halt() {
void halt_and_catch_fire(char * error_message, const char * file, int line, struct regs * regs) {
__asm__ __volatile__("cli");
settextcolor(14,4);
settextcolor(0,11);
kprintf("Process %d did a dumb.\n", getpid());
kprintf("PANIC! %s\n", error_message);
kprintf("File: %s\n", file);
kprintf("Line: %d\n", line);
@ -26,7 +27,9 @@ void halt_and_catch_fire(char * error_message, const char * file, int line, stru
kprintf("User ESP: 0x%x\n", regs->useresp);
kprintf("eip=0x%x\n", regs->eip);
}
kernel_halt();
kprintf("Killing process...\n");
resettextcolor();
kexit(0);
}
void assert_failed(const char *file, uint32_t line, const char *desc) {

View File

@ -67,6 +67,20 @@ static int close(int fd) {
return 0;
}
static int execve(const char * filename, char *const argv[], char *const envp[]) {
int i = 0;
while (argv[i]) {
++i;
}
/* Discard envp */
exec((char *)filename, i, (char **)argv);
return -1;
}
static int sys_fork() {
return fork();
}
/*
* System Call Internals
*/
@ -78,9 +92,12 @@ static uintptr_t syscalls[] = {
(uintptr_t)&open,
(uintptr_t)&read,
(uintptr_t)&write,
(uintptr_t)&close
(uintptr_t)&close,
(uintptr_t)&gettimeofday,
(uintptr_t)&execve,
(uintptr_t)&sys_fork,
};
uint32_t num_syscalls = 6;
uint32_t num_syscalls = 9;
void
syscalls_install() {

View File

@ -157,7 +157,7 @@ switch_task() {
__asm__ __volatile__ ("mov %%ebp, %0" : "=r" (ebp));
eip = read_eip();
if (eip == 0x10000) {
__asm__ __volatile__ ("sti");
return;
}
current_task->eip = eip;
@ -190,7 +190,6 @@ void
enter_user_mode() {
set_kernel_stack(current_task->stack + KERNEL_STACK_SIZE);
__asm__ __volatile__(
"cli\n"
"mov $0x23, %ax\n"
"mov %ax, %ds\n"
"mov %ax, %es\n"
@ -214,7 +213,6 @@ void
enter_user_jmp(uintptr_t location, int argc, char ** argv) {
set_kernel_stack(current_task->stack + KERNEL_STACK_SIZE);
__asm__ __volatile__(
"cli\n"
"mov $0x23, %%ax\n"
"mov %%ax, %%ds\n"
"mov %%ax, %%es\n"

View File

@ -315,7 +315,6 @@ void draw_cursor() {
}
void bochs_write(char c) {
__asm__ __volatile__ ("cli");
cell_redraw(csr_x, csr_y);
if (c == '\n') {
for (uint16_t i = csr_x; i < TERM_WIDTH; ++i) {
@ -346,7 +345,6 @@ void bochs_write(char c) {
csr_y = TERM_HEIGHT - 1;
}
draw_cursor();
__asm__ __volatile__ ("sti");
}

View File

@ -62,7 +62,7 @@ DECL_SYSCALL2(stat, const char *, void *);
/* Process Control */
DECL_SYSCALL0(getpid);
DECL_SYSCALL3(exec, char *, char **, char **);
DECL_SYSCALL3(execve, char *, char **, char **);
DECL_SYSCALL0(fork);
DECL_SYSCALL2(kill, int, int);
DECL_SYSCALL1(wait, int *);
@ -70,6 +70,8 @@ DECL_SYSCALL1(wait, int *);
/* Memory management */
DECL_SYSCALL1(sbrk, int);
DECL_SYSCALL2(gettimeofday, void *, void *);
#endif
/*

View File

@ -247,6 +247,14 @@ extern void parse_args(char * argv);
extern void get_time(uint16_t * hours, uint16_t * minutes, uint16_t * seconds);
extern void get_date(uint16_t * month, uint16_t * day);
struct timeval {
uint32_t tv_sec;
uint32_t tv_usec;
};
extern int gettimeofday(struct timeval * t, void * z);
/* CPU Detect by Brynet */
extern int detect_cpu();

View File

@ -157,9 +157,7 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
start_shell();
fork();
if (getpid() == 0) {
if (fork()) {
char * args[] = {
"/bin/yes",
"\033[1;32mA\033[0m"

12
loader/sh.c Normal file
View File

@ -0,0 +1,12 @@
#include <syscall.h>
int main(int argc, char ** argv) {
/* A Simple Shell */
int i = syscall_fork();
if (i == 0) {
syscall_print("Herpy derpy!\n");
} else {
syscall_print("Hello World!\n");
}
return 0;
}

View File

@ -6,3 +6,6 @@ DEFN_SYSCALL3(open, 2, const char *, int, int)
DEFN_SYSCALL3(read, 3, int, char *, int)
DEFN_SYSCALL3(write, 4, int, char *, int)
DEFN_SYSCALL1(close, 5, int)
DEFN_SYSCALL2(gettimeofday, 6, void *, void *)
DEFN_SYSCALL3(execve, 7, char *, char **, char **)
DEFN_SYSCALL0(fork, 8)