summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/arch/aarch64/aarch64/machdep.c7
-rw-r--r--sys/arch/amd64/amd64/machdep.c15
-rw-r--r--sys/arch/amd64/amd64/trap.c18
-rw-r--r--sys/dev/cons/cons_buf.c40
-rw-r--r--sys/include/arch/aarch64/cpu.h2
-rw-r--r--sys/include/arch/amd64/cpu.h1
-rw-r--r--sys/include/arch/amd64/frameasm.h8
-rw-r--r--sys/include/dev/cons/consvar.h2
-rw-r--r--sys/kern/kern_panic.c8
-rw-r--r--sys/kern/kern_spawn.c6
10 files changed, 77 insertions, 30 deletions
diff --git a/sys/arch/aarch64/aarch64/machdep.c b/sys/arch/aarch64/aarch64/machdep.c
index a29ad7e..7c21e62 100644
--- a/sys/arch/aarch64/aarch64/machdep.c
+++ b/sys/arch/aarch64/aarch64/machdep.c
@@ -42,6 +42,13 @@ cpu_startup(struct cpu_info *ci)
}
void
+cpu_halt_others(void)
+{
+ /* TODO: STUB */
+ return;
+}
+
+void
serial_init(void)
{
/* TODO: STUB */
diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c
index 07d6cdd..4a885fa 100644
--- a/sys/arch/amd64/amd64/machdep.c
+++ b/sys/arch/amd64/amd64/machdep.c
@@ -174,6 +174,21 @@ cpu_halt_all(void)
for (;;);
}
+/*
+ * Same as cpu_halt_all() but for all other
+ * cores but ourselves.
+ */
+void
+cpu_halt_others(void)
+{
+ if (rdmsr(IA32_GS_BASE) == 0) {
+ __ASMV("cli; hlt");
+ }
+
+ /* Send IPI to all cores */
+ lapic_send_ipi(0, IPI_SHORTHAND_OTHERS, halt_vector);
+}
+
void
serial_init(void)
{
diff --git a/sys/arch/amd64/amd64/trap.c b/sys/arch/amd64/amd64/trap.c
index 9a3a7ba..6492a29 100644
--- a/sys/arch/amd64/amd64/trap.c
+++ b/sys/arch/amd64/amd64/trap.c
@@ -120,20 +120,6 @@ trap_user(struct trapframe *tf)
dispatch_signals(td);
}
-static void
-trap_quirks(struct cpu_info *ci)
-{
- static uint8_t count;
-
- if (ISSET(ci->irq_mask, CPU_IRQ(1)) && count < 1) {
- ++count;
- pr_error("detected buggy i8042\n");
- pr_error("applying I8042_HOSTILE quirk\n");
- i8042_quirk(I8042_HOSTILE);
- return;
- }
-}
-
void
trap_syscall(struct trapframe *tf)
{
@@ -155,8 +141,6 @@ trap_syscall(struct trapframe *tf)
void
trap_handler(struct trapframe *tf)
{
- struct cpu_info *ci;
-
splraise(IPL_HIGH);
if (tf->trapno >= NELEM(trap_type)) {
@@ -164,8 +148,6 @@ trap_handler(struct trapframe *tf)
}
pr_error("got %s\n", trap_type[tf->trapno]);
- ci = this_cpu();
- trap_quirks(ci);
/* Handle traps from userland */
if (ISSET(tf->cs, 3)) {
diff --git a/sys/dev/cons/cons_buf.c b/sys/dev/cons/cons_buf.c
index 3bc45a1..84a38ce 100644
--- a/sys/dev/cons/cons_buf.c
+++ b/sys/dev/cons/cons_buf.c
@@ -81,20 +81,26 @@ int
cons_obuf_push(struct cons_buf *bp, struct cons_char c)
{
uint8_t next;
+ int retval = 0;
if (bp == NULL) {
return -EINVAL;
}
+ spinlock_acquire(&bp->lock);
__assert(bp->type == CONS_BUF_OUTPUT);
next = bp->head + 1;
if (next > bp->len) {
- return -ENOSPC;
+ retval = -ENOSPC;
+ goto done;
}
bp->obuf[bp->head] = c;
bp->head = next;
- return 0;
+
+done:
+ spinlock_release(&bp->lock);
+ return retval;
}
/*
@@ -108,18 +114,21 @@ int
cons_obuf_pop(struct cons_buf *bp, struct cons_char *res)
{
uint8_t next;
+ int retval = 0;
if (bp == NULL || res == NULL) {
return -EINVAL;
}
__assert(bp->type == CONS_BUF_OUTPUT);
+ spinlock_acquire(&bp->lock);
/* Do we have any data left? */
if (bp->head == bp->tail) {
bp->head = 0;
bp->tail = 0;
- return -EAGAIN;
+ retval = -EAGAIN;
+ goto done;
}
next = bp->tail + 1;
@@ -129,7 +138,10 @@ cons_obuf_pop(struct cons_buf *bp, struct cons_char *res)
*res = bp->obuf[bp->tail];
bp->tail = next;
- return 0;
+
+done:
+ spinlock_release(&bp->lock);
+ return retval;
}
int
@@ -137,22 +149,28 @@ cons_ibuf_push(struct cons_screen *scr, struct cons_input in)
{
struct cons_buf *bp;
uint8_t head_next;
+ int retval = 0;
if (scr == NULL) {
return -EINVAL;
}
bp = scr->ib;
+ spinlock_acquire(&bp->lock);
__assert(bp->type == CONS_BUF_INPUT);
head_next = bp->head + 1;
if (head_next > bp->len) {
- return -ENOSPC;
+ retval = -ENOSPC;
+ goto done;
}
bp->ibuf[bp->head] = in;
bp->head = head_next;
- return 0;
+
+done:
+ spinlock_release(&bp->lock);
+ return retval;
}
int
@@ -160,6 +178,7 @@ cons_ibuf_pop(struct cons_screen *scr, struct cons_input *res)
{
uint8_t tail_next;
struct cons_buf *bp;
+ int retval = 0;
if (scr == NULL || res == NULL) {
return -EINVAL;
@@ -167,12 +186,14 @@ cons_ibuf_pop(struct cons_screen *scr, struct cons_input *res)
bp = scr->ib;
__assert(bp->type == CONS_BUF_INPUT);
+ spinlock_acquire(&bp->lock);
/* Do we have any data left? */
if (bp->head == bp->tail) {
bp->head = 0;
bp->tail = 0;
- return -EAGAIN;
+ retval = -EAGAIN;
+ goto done;
}
tail_next = bp->tail + 1;
@@ -182,5 +203,8 @@ cons_ibuf_pop(struct cons_screen *scr, struct cons_input *res)
*res = bp->ibuf[bp->tail];
bp->tail = tail_next;
- return 0;
+
+done:
+ spinlock_release(&bp->lock);
+ return retval;
}
diff --git a/sys/include/arch/aarch64/cpu.h b/sys/include/arch/aarch64/cpu.h
index a6ccdec..2f62d95 100644
--- a/sys/include/arch/aarch64/cpu.h
+++ b/sys/include/arch/aarch64/cpu.h
@@ -40,6 +40,8 @@ struct cpu_info {
};
void cpu_startup(struct cpu_info *ci);
+void cpu_halt_others(void);
+
void mp_bootstrap_aps(struct cpu_info *ci);
struct cpu_info *this_cpu(void);
diff --git a/sys/include/arch/amd64/cpu.h b/sys/include/arch/amd64/cpu.h
index ce42416..dd753b7 100644
--- a/sys/include/arch/amd64/cpu.h
+++ b/sys/include/arch/amd64/cpu.h
@@ -49,6 +49,7 @@ struct cpu_info {
};
__dead void cpu_halt_all(void);
+void cpu_halt_others(void);
void cpu_startup(struct cpu_info *ci);
struct cpu_info *this_cpu(void);
diff --git a/sys/include/arch/amd64/frameasm.h b/sys/include/arch/amd64/frameasm.h
index 22217eb..c6316a5 100644
--- a/sys/include/arch/amd64/frameasm.h
+++ b/sys/include/arch/amd64/frameasm.h
@@ -121,6 +121,7 @@
*/
#define TRAPENTRY_EC(ENTLABEL, TRAPNO) \
ENTLABEL: ; \
+ cli ; \
testq $0x3, 16(%rsp) ; \
jz 1f ; \
lfence ; \
@@ -133,7 +134,8 @@
jz 2f ; \
lfence ; \
swapgs ; \
- 2: iretq
+ 2: sti ; \
+ iretq
/*
* Trap entry where no error code is on
@@ -141,6 +143,7 @@
*/
#define TRAPENTRY(ENTLABEL, TRAPNO) \
ENTLABEL: ; \
+ cli ; \
testq $0x3, 8(%rsp) ; \
jz 1f ; \
lfence ; \
@@ -153,6 +156,7 @@
jz 2f ; \
lfence ; \
swapgs ; \
- 2: iretq
+ 2: sti ; \
+ iretq
#endif /* !_MACHINE_FRAMEASM_H_ */
diff --git a/sys/include/dev/cons/consvar.h b/sys/include/dev/cons/consvar.h
index 483d5f1..253176b 100644
--- a/sys/include/dev/cons/consvar.h
+++ b/sys/include/dev/cons/consvar.h
@@ -32,6 +32,7 @@
#include <sys/types.h>
#include <sys/param.h>
+#include <sys/spinlock.h>
/* Buffer types */
#define CONS_BUF_INPUT 0
@@ -62,6 +63,7 @@ struct cons_input {
* keyboard input or console output.
*/
struct cons_buf {
+ struct spinlock lock;
union {
struct cons_input *ibuf;
struct cons_char *obuf;
diff --git a/sys/kern/kern_panic.c b/sys/kern/kern_panic.c
index 950ea8f..7660fff 100644
--- a/sys/kern/kern_panic.c
+++ b/sys/kern/kern_panic.c
@@ -31,6 +31,8 @@
#include <sys/spinlock.h>
#include <sys/syslog.h>
#include <sys/reboot.h>
+#include <machine/cdefs.h>
+#include <machine/cpu.h>
/*
* Burn and sizzle - the core logic that really ends
@@ -69,8 +71,12 @@ panic(const char *fmt, ...)
{
va_list ap;
+ /* Shut everything else up */
+ md_intoff();
+ cpu_halt_others();
+
va_start(ap, fmt);
- kprintf(OMIT_TIMESTAMP "panic: ");
+ kprintf(OMIT_TIMESTAMP "\npanic: ");
vkprintf(fmt, &ap);
bas(true, REBOOT_HALT);
diff --git a/sys/kern/kern_spawn.c b/sys/kern/kern_spawn.c
index 2cddd84..cb898dc 100644
--- a/sys/kern/kern_spawn.c
+++ b/sys/kern/kern_spawn.c
@@ -81,7 +81,11 @@ spawn_thunk(void)
path = NULL;
dynfree(args);
- execve(cur, &execve_args);
+
+ if (execve(cur, &execve_args) != 0) {
+ pr_error("execve failed, aborting\n");
+ exit1(this_td());
+ }
__builtin_unreachable();
}