version 1.1.1.1, 2008/06/03 10:38:46 |
version 1.1.1.1.2.1, 2008/08/13 17:12:32 |
|
|
#include <task.h> |
#include <task.h> |
#include <irq.h> |
#include <irq.h> |
#include <page.h> |
#include <page.h> |
#include <kmem.h> |
|
#include <vm.h> |
|
#include <device.h> |
#include <device.h> |
#include <system.h> |
#include <system.h> |
|
#include <version.h> |
|
|
/* |
/* |
* kernel information. |
* kernel information. |
*/ |
*/ |
static const struct info_kernel kern_info = KERNEL_INFO(kern_info); |
static const struct info_kernel kern_info = { |
|
"Prex", VERSION, __DATE__, MACHINE, "preky" |
|
}; |
|
|
/* |
/* |
* Logging system call. |
* Logging system call. |
* |
* |
* Write a message to the logging device. |
* Write a message to the logging device. The log function is |
* The log function is available only when kernel is built with |
* available only when kernel is built with debug option. |
* debug option. |
|
*/ |
*/ |
int |
int |
sys_log(const char *str) |
sys_log(const char *str) |
{ |
{ |
#ifdef DEBUG |
#ifdef DEBUG |
char buf[MSGBUFSZ]; |
char buf[DBGMSG_SIZE]; |
size_t len; |
size_t len; |
|
|
if (umem_strnlen(str, MSGBUFSZ, &len)) |
if (umem_strnlen(str, DBGMSG_SIZE, &len)) |
return EFAULT; |
return EFAULT; |
if (len >= MSGBUFSZ) |
if (len >= DBGMSG_SIZE) |
return EINVAL; |
return EINVAL; |
if (umem_copyin((void *)str, buf, len + 1)) |
if (umem_copyin(str, buf, len + 1)) |
return EFAULT; |
return EFAULT; |
printk(buf); |
printf(buf); |
return 0; |
return 0; |
#else |
#else |
return ENOSYS; |
return ENOSYS; |
|
|
/* |
/* |
* Panic system call. |
* Panic system call. |
* |
* |
* Kernel behavior for sys_panic() is different for its debug option. |
* If kernel is built with debug option, sys_panic() displays |
* - Debug build |
* a panic message and stops the enture system. Otherwise, it |
* Show a panic message and stop the entire system. |
* terminates the task which called sys_panic(). |
* - Release build |
|
* Terminate the task which called sys_panic(). |
|
*/ |
*/ |
int |
int |
sys_panic(const char *str) |
sys_panic(const char *str) |
{ |
{ |
#ifdef DEBUG |
#ifdef DEBUG |
|
task_t self = cur_task(); |
|
|
irq_lock(); |
irq_lock(); |
printk("\nUser mode panic: task:%s thread:%x\n", |
printf("\nUser mode panic: task:%s thread:%x\n", |
cur_task()->name ? cur_task()->name : "no name", cur_thread); |
self->name != NULL ? self->name : "no name", cur_thread); |
|
|
sys_log(str); |
sys_log(str); |
printk("\n"); |
printf("\n"); |
|
|
sched_lock(); |
sched_lock(); |
irq_unlock(); |
irq_unlock(); |
|
|
|
|
switch (type) { |
switch (type) { |
case INFO_KERNEL: |
case INFO_KERNEL: |
err = umem_copyout((void *)&kern_info, buf, |
err = umem_copyout(&kern_info, buf, sizeof(kern_info)); |
sizeof(kern_info)); |
|
break; |
break; |
|
|
case INFO_MEMORY: |
case INFO_MEMORY: |
page_info(&imem.total, &imem.free); |
page_info(&imem.total, &imem.free); |
kmem_info(&imem.kernel); |
|
err = umem_copyout(&imem, buf, sizeof(imem)); |
err = umem_copyout(&imem, buf, sizeof(imem)); |
break; |
break; |
|
|
|
|
|
|
default: |
default: |
err = EINVAL; |
err = EINVAL; |
|
break; |
} |
} |
return err; |
return err; |
} |
} |
|
|
/* |
/* |
* Get system time - return ticks from OS boot. |
* Get system time - return ticks since OS boot. |
*/ |
*/ |
int |
int |
sys_time(u_long *ticks) |
sys_time(u_long *ticks) |
|
|
u_long t; |
u_long t; |
|
|
t = timer_count(); |
t = timer_count(); |
return umem_copyout(&t, ticks, sizeof(u_long)); |
return umem_copyout(&t, ticks, sizeof(t)); |
} |
} |
|
|
/* |
/* |
* Kernel debug service. |
* Kernel debug service. |
*/ |
*/ |
int |
int |
sys_debug(int cmd, u_long param) |
sys_debug(int cmd, void *data) |
{ |
{ |
#ifdef DEBUG |
#ifdef DEBUG |
int err = EINVAL; |
int err = EINVAL; |
size_t size; |
size_t size; |
char *buf; |
int item; |
|
|
/* |
|
* Check capability for some commands. |
|
*/ |
|
switch (cmd) { |
switch (cmd) { |
case DCMD_DUMP: |
case DCMD_DUMP: |
if (!task_capable(CAP_DEBUG)) |
if (umem_copyin(data, &item, sizeof(item))) |
return EPERM; |
err = EFAULT; |
} |
else |
|
err = debug_dump(item); |
switch (cmd) { |
|
case DCMD_DUMP: |
|
err = debug_dump(param); |
|
break; |
break; |
case DCMD_LOGSIZE: |
case DCMD_LOGSIZE: |
if ((err = log_get(&buf, &size)) == 0) |
size = LOGBUF_SIZE; |
err = umem_copyout(&size, (void *)param, sizeof(size)); |
err = umem_copyout(&size, data, sizeof(size)); |
break; |
break; |
case DCMD_GETLOG: |
case DCMD_GETLOG: |
if ((err = log_get(&buf, &size)) == 0) |
err = debug_getlog(data); |
err = umem_copyout(buf, (void *)param, size); |
|
break; |
break; |
default: |
default: |
|
/* DO NOTHING */ |
break; |
break; |
} |
} |
return err; |
return err; |