Bug #647 » vkhalt.patch
| include/globaldata.h 20 May 2007 17:50:44 -0000 | ||
|---|---|---|
|
int gd_sdelayed; /* delayed software ints */
|
||
|
int gd_currentldt;
|
||
|
int gd_mailbox; /* signal delivery mailbox */
|
||
|
int gd_powerbutton; /* shutdown signal mailbox */
|
||
|
u_int unused001;
|
||
|
u_int gd_other_cpus;
|
||
|
u_int gd_ss_eflags;
|
||
| include/md_var.h 20 May 2007 20:34:04 -0000 | ||
|---|---|---|
|
#endif
|
||
|
#define VKNETIF_MAX 16
|
||
|
#define VKD_MAX 16
|
||
|
struct vknetif_info {
|
||
|
int tap_fd;
|
||
| ... | ... | |
|
in_addr_t netif_mask;
|
||
|
};
|
||
|
struct vkd_info {
|
||
|
int fd;
|
||
|
int unit;
|
||
|
char fname[MAXPATHLEN];
|
||
|
};
|
||
|
extern char sigcode[];
|
||
|
extern int szsigcode;
|
||
|
extern vpte_t *KernelPTA; /* NOTE: Offset for direct VA translation */
|
||
| ... | ... | |
|
extern char cpu_vendor[]; /* XXX belongs in i386 */
|
||
|
extern u_int cpu_id; /* XXX belongs in i386 */
|
||
|
extern int RootImageFd;
|
||
|
extern struct vkd_info VkdInfo[VKD_MAX];
|
||
|
extern int VkdNum;
|
||
|
extern int MemImageFd;
|
||
|
extern int KQueueFd;
|
||
|
extern struct vknetif_info NetifInfo[VKNETIF_MAX];
|
||
| ... | ... | |
|
void cpu_setregs (void);
|
||
|
void cpu_idle (void);
|
||
|
void go_user (struct intrframe *frame);
|
||
|
void vk_poweroff (void);
|
||
|
void init_exceptions(void);
|
||
|
void init_kqueue(void);
|
||
| platform/init.c 20 May 2007 20:32:08 -0000 | ||
|---|---|---|
|
#include <sys/proc.h>
|
||
|
#include <sys/msgbuf.h>
|
||
|
#include <sys/vmspace.h>
|
||
|
#include <sys/signalvar.h>
|
||
|
#include <sys/socket.h>
|
||
|
#include <sys/sockio.h>
|
||
|
#include <vm/vm_page.h>
|
||
| ... | ... | |
|
vm_paddr_t Maxmem;
|
||
|
vm_paddr_t Maxmem_bytes;
|
||
|
int MemImageFd = -1;
|
||
|
int RootImageFd = -1;
|
||
|
struct vkd_info VkdInfo[VKD_MAX];
|
||
|
int VkdNum = 0;
|
||
|
struct vknetif_info NetifInfo[VKNETIF_MAX];
|
||
|
int NetifNum;
|
||
|
int NetifNum = 0;
|
||
|
vm_offset_t KvaStart;
|
||
|
vm_offset_t KvaEnd;
|
||
|
vm_offset_t KvaSize;
|
||
| ... | ... | |
|
static void init_kern_memory(void);
|
||
|
static void init_globaldata(void);
|
||
|
static void init_vkernel(void);
|
||
|
static void init_rootdevice(char *imageFile);
|
||
|
static void init_netif(char *netifFile[], int netifFileNum);
|
||
|
static void init_vkd(char *vkdFile[], int vkdExpNum);
|
||
|
static void init_netif(char *netifExp[], int netifExpNum);
|
||
|
static void usage(const char *ctl);
|
||
|
/*
|
||
| ... | ... | |
|
main(int ac, char **av)
|
||
|
{
|
||
|
char *memImageFile = NULL;
|
||
|
char *rootImageFile = NULL;
|
||
|
char *netifFile[VKNETIF_MAX];
|
||
|
char *vkdFile[VKD_MAX];
|
||
|
char *suffix;
|
||
|
int netifFileNum = 0;
|
||
|
int vkdFileNum = 0;
|
||
|
int c;
|
||
|
int i;
|
||
|
int n;
|
||
| ... | ... | |
|
netifFile[netifFileNum++] = optarg;
|
||
|
break;
|
||
|
case 'r':
|
||
|
rootImageFile = optarg;
|
||
|
if ( vkdFileNum < VKD_MAX )
|
||
|
vkdFile[vkdFileNum++] = optarg;
|
||
|
break;
|
||
|
case 'm':
|
||
|
Maxmem_bytes = strtoull(optarg, &suffix, 0);
|
||
| ... | ... | |
|
init_globaldata();
|
||
|
init_vkernel();
|
||
|
init_kqueue();
|
||
|
init_rootdevice(rootImageFile);
|
||
|
init_vkd(vkdFile, vkdFileNum);
|
||
|
init_netif(netifFile, netifFileNum);
|
||
|
init_exceptions();
|
||
|
mi_startup();
|
||
| ... | ... | |
|
}
|
||
|
/*
|
||
|
* The root filesystem path for the virtual kernel is optional. If specified
|
||
|
* it points to a filesystem image.
|
||
|
* Filesystem image paths for the virtual kernel are optional.
|
||
|
* If specified they each should point to a disk image,
|
||
|
* the first of which will become the VKERNEL root disk.
|
||
|
*
|
||
|
* The virtual kernel caches data from our 'disk' just like a normal kernel,
|
||
|
* so we do not really want the real kernel to cache the data too. Use
|
||
| ... | ... | |
|
*/
|
||
|
static
|
||
|
void
|
||
|
init_rootdevice(char *imageFile)
|
||
|
init_vkd ( char *vkdExp[], int vkdExpNum )
|
||
|
{
|
||
|
int i;
|
||
|
if (vkdExpNum == 0)
|
||
|
return;
|
||
|
for(i=0; i < vkdExpNum; i++){
|
||
|
char *fname;
|
||
|
fname = vkdExp[i];
|
||
|
if (fname == NULL) {
|
||
|
warnx("Invalid argument to '-r'");
|
||
|
continue;
|
||
|
}
|
||
|
if (VkdNum < VKD_MAX ) {
|
||
|
struct stat st;
|
||
|
struct vkd_info* info = NULL;
|
||
|
int fd;
|
||
|
size_t l = 0;
|
||
|
if (imageFile) {
|
||
|
RootImageFd = open(imageFile, O_RDWR|O_DIRECT, 0644);
|
||
|
if (RootImageFd < 0 || fstat(RootImageFd, &st) < 0) {
|
||
|
err(1, "Unable to open/create %s", imageFile);
|
||
|
fd = open(fname, O_RDWR|O_DIRECT, 0644);
|
||
|
if (fd < 0 || fstat(fd, &st) < 0) {
|
||
|
err(1, "Unable to open/create %s: %s",
|
||
|
fname, strerror(errno));
|
||
|
/* NOT REACHED */
|
||
|
}
|
||
|
info = &VkdInfo[VkdNum];
|
||
|
l = strlen(fname);
|
||
|
info->unit = i;
|
||
|
info->fd = fd;
|
||
|
memcpy(info->fname, fname, l);
|
||
|
if(i == 0)
|
||
|
rootdevnames[0] = "ufs:vkd0a";
|
||
|
VkdNum++;
|
||
|
}
|
||
|
else {
|
||
|
warnx("vkd%d (%s) > VKD_MAX",
|
||
|
VkdNum, fname);
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
| ... | ... | |
|
netif = strtok(netifExp[i], ":");
|
||
|
if (netif == NULL) {
|
||
|
warnx("Invalide argument to '-I'");
|
||
|
warnx("Invalid argument to '-I'");
|
||
|
continue;
|
||
|
}
|
||
| ... | ... | |
|
for (;;)
|
||
|
__asm__ __volatile("hlt");
|
||
|
}
|
||
|
void
|
||
|
vk_poweroff(void)
|
||
|
{
|
||
|
if(initproc != NULL) {
|
||
|
ksignal(initproc, SIGUSR2);
|
||
|
} else {
|
||
|
reboot(RB_POWEROFF);
|
||
|
}
|
||
|
}
|
||
| platform/kqueue.c 20 May 2007 20:29:51 -0000 | ||
|---|---|---|
|
sa.sa_flags = SA_MAILBOX | SA_NODEFER;
|
||
|
sigemptyset(&sa.sa_mask);
|
||
|
sigaction(SIGIO, &sa, NULL);
|
||
|
sa.sa_mailbox = &mdcpu->gd_powerbutton;
|
||
|
sigaction(SIGTERM, &sa, NULL);
|
||
|
KQueueFd = kqueue();
|
||
|
if (fcntl(KQueueFd, F_SETOWN, getpid()) < 0)
|
||
|
panic("Cannot configure kqueue for SIGIO, update your kernel");
|
||
| ... | ... | |
|
int n;
|
||
|
int i;
|
||
|
if (gd->gd_mailbox == 0)
|
||
|
return;
|
||
|
/* note:
|
||
|
* should this be a separate mailbox handler call in
|
||
|
* platform/vkernel/i386/trap.c?
|
||
|
*/
|
||
|
if (gd->gd_powerbutton != 0) {
|
||
|
kprintf("Caught SIGTERM from host. Shutting down...\n");
|
||
|
gd->gd_powerbutton=0;
|
||
|
vk_poweroff();
|
||
|
}
|
||
|
if (gd->gd_mailbox != 0) {
|
||
|
gd->gd_mailbox = 0;
|
||
|
ts.tv_sec = 0;
|
||
|
ts.tv_nsec = 0;
|
||
| ... | ... | |
|
crit_exit();
|
||
|
}
|
||
|
}
|
||
|
/*
|
||
|
* Generic I/O event support
|
||
|
*/
|
||