summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/kstat/kstat.c7
-rw-r--r--usr.bin/oasm/emit.c25
-rw-r--r--usr.bin/oasm/include/oasm/lex.h4
-rw-r--r--usr.bin/oasm/label.c1
-rw-r--r--usr.bin/oasm/lex.c8
-rw-r--r--usr.bin/oasm/parse.c12
-rw-r--r--usr.bin/oemu/cpu.c11
-rw-r--r--usr.bin/osh/osh.c40
8 files changed, 100 insertions, 8 deletions
diff --git a/usr.bin/kstat/kstat.c b/usr.bin/kstat/kstat.c
index 853bc8b..e3b7e6a 100644
--- a/usr.bin/kstat/kstat.c
+++ b/usr.bin/kstat/kstat.c
@@ -37,6 +37,8 @@ get_sched_stat(void)
{
struct sched_stat stat;
struct sched_cpu *cpu;
+ double nonline, noffline;
+ uint16_t online_percent;
int fd;
fd = open("/ctl/sched/stat", O_RDONLY);
@@ -50,10 +52,15 @@ get_sched_stat(void)
}
close(fd);
+ noffline = stat.nhlt;
+ nonline = (stat.ncpu - noffline);
+ online_percent = (uint16_t)(((double)nonline / (nonline + noffline)) * 100);
+
printf("-------------------------------\n");
printf("Number of tasks: %d\n", stat.nproc);
printf("Number of cores online: %d\n", stat.ncpu);
printf("Scheduler quantum: %d usec\n", stat.quantum_usec);
+ printf("CPU is %d%% online\n", online_percent);
printf("-------------------------------\n");
/*
diff --git a/usr.bin/oasm/emit.c b/usr.bin/oasm/emit.c
index 3261522..6b17eab 100644
--- a/usr.bin/oasm/emit.c
+++ b/usr.bin/oasm/emit.c
@@ -357,6 +357,26 @@ emit_encode_mro(struct emit_state *state, struct oasm_token *tok)
return TAILQ_NEXT(tok, link);
}
+/*
+ * Encode a NOP instruction
+ *
+ * 'nop' - no operands
+ *
+ * Returns the next token on success,
+ * otherwise NULL.
+ */
+static struct oasm_token *
+emit_encode_nop(struct emit_state *state, struct oasm_token *tok)
+{
+ inst_t curinst;
+
+ curinst.opcode = OSMX64_NOP;
+ curinst.rd = 0;
+ curinst.unused = 0;
+ emit_bytes(state, &curinst, sizeof(curinst));
+ return TAILQ_NEXT(tok, link);
+}
+
int
emit_osmx64(struct emit_state *state, struct oasm_token *tp)
{
@@ -428,6 +448,9 @@ emit_process(struct oasm_state *oasm, struct emit_state *emit)
curtok = TAILQ_FIRST(&emit->ir);
while (curtok != NULL) {
switch (curtok->type) {
+ case TT_NOP:
+ curtok = emit_encode_nop(emit, curtok);
+ break;
case TT_MOV:
curtok = emit_encode_mov(emit, curtok);
break;
@@ -448,7 +471,7 @@ emit_process(struct oasm_state *oasm, struct emit_state *emit)
curtok = emit_encode_hlt(emit, curtok);
break;
default:
- if (lex_is_mro(curtok->type)) {
+ if (tok_is_mro(curtok->type)) {
curtok = emit_encode_mro(emit, curtok);
break;
}
diff --git a/usr.bin/oasm/include/oasm/lex.h b/usr.bin/oasm/include/oasm/lex.h
index fa82398..873f6b9 100644
--- a/usr.bin/oasm/include/oasm/lex.h
+++ b/usr.bin/oasm/include/oasm/lex.h
@@ -33,6 +33,7 @@
#include <sys/queue.h>
#include <sys/cdefs.h>
#include <stdint.h>
+#include <stdbool.h>
struct oasm_state;
@@ -89,6 +90,7 @@ struct oasm_state;
*/
typedef enum {
TT_UNKNOWN, /* Unknown token */
+ TT_NOP, /* No operation */
/* Arithmetic instructions */
TT_ADD, /* 'add' */
@@ -165,7 +167,7 @@ tok_is_xreg(tt_t tok)
* instruction. Returns true on match.
*/
__always_inline static inline bool
-lex_is_mro(tt_t tok)
+tok_is_mro(tt_t tok)
{
switch (tok) {
case TT_MROB:
diff --git a/usr.bin/oasm/label.c b/usr.bin/oasm/label.c
index c54209a..2647bb9 100644
--- a/usr.bin/oasm/label.c
+++ b/usr.bin/oasm/label.c
@@ -35,6 +35,7 @@
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
+#include <stdbool.h>
static struct oasm_label *labels[MAX_LABELS];
static size_t label_count = 0;
diff --git a/usr.bin/oasm/lex.c b/usr.bin/oasm/lex.c
index dcd7c1f..fea9dc3 100644
--- a/usr.bin/oasm/lex.c
+++ b/usr.bin/oasm/lex.c
@@ -40,6 +40,7 @@
static char putback = '\0';
/* Instruction mnemonic strings */
+#define S_IMN_NOP "nop"
#define S_IMN_MOV "mov"
#define S_IMN_ADD "add"
#define S_IMN_SUB "sub"
@@ -372,6 +373,13 @@ lex_tok(struct oasm_state *state, struct oasm_token *ttp)
return 0;
}
+ /* No operation? */
+ if (strcmp(p, S_IMN_NOP) == 0) {
+ ttp->type = TT_NOP;
+ ttp->raw = p;
+ return 0;
+ }
+
/* Arithmetic operation? */
if ((tok = token_arith(p)) != TT_UNKNOWN) {
ttp->type = tok;
diff --git a/usr.bin/oasm/parse.c b/usr.bin/oasm/parse.c
index 229455b..c81b498 100644
--- a/usr.bin/oasm/parse.c
+++ b/usr.bin/oasm/parse.c
@@ -39,6 +39,7 @@
static struct emit_state emit_state;
static const char *tokstr[] = {
[ TT_UNKNOWN] = "bad",
+ [ TT_NOP ] = "nop",
[ TT_ADD ] = "add",
[ TT_SUB ] = "sub",
[ TT_MUL ] = "mul",
@@ -126,13 +127,12 @@ parse_reg(struct oasm_state *state, struct oasm_token *tok)
state->last = tok->type;
break;
default:
- if (lex_is_mro(state->last)) {
- state->last = tok->type;
+ if (tok_is_mro(state->last)) {
break;
}
p = tokstr[state->last];
- oasm_err("bad instruction '%s' for regop\n", p);
+ oasm_err("bad token '%s' for regop\n", p);
return -1;
}
@@ -154,6 +154,10 @@ parse_tok(struct oasm_state *state, struct oasm_token *tok)
int error;
switch (tok->type) {
+ case TT_NOP:
+ state->last = tok->type;
+ emit_osmx64(&emit_state, tok);
+ break;
case TT_BR:
state->last = tok->type;
emit_osmx64(&emit_state, tok);
@@ -200,7 +204,7 @@ parse_tok(struct oasm_state *state, struct oasm_token *tok)
emit_osmx64(&emit_state, tok);
break;
default:
- if (lex_is_mro(tok->type)) {
+ if (tok_is_mro(tok->type)) {
state->last = tok->type;
emit_osmx64(&emit_state, tok);
return 0;
diff --git a/usr.bin/oemu/cpu.c b/usr.bin/oemu/cpu.c
index 5a2c761..49d4671 100644
--- a/usr.bin/oemu/cpu.c
+++ b/usr.bin/oemu/cpu.c
@@ -377,6 +377,10 @@ cpu_kick(struct oemu_cpu *cpu, struct sysmem *mem)
inst = (inst_t *)&memp[regs->ip];
switch (inst->opcode) {
+ case INST_NOP:
+ /* NOP */
+ regs->ip += sizeof(*inst);
+ continue;
case INST_MOV_IMM:
cpu_mov_imm(cpu, inst);
break;
@@ -408,6 +412,13 @@ cpu_kick(struct oemu_cpu *cpu, struct sysmem *mem)
break;
}
+ /*
+ * X0 is readonly and should always be zero, undo
+ * any writes or side effects from any operations
+ * upon this register.
+ */
+ regs->xreg[0] = 0;
+
/* Is this a halt instruction? */
if (inst->opcode == INST_HLT) {
printf("HALTED\n");
diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c
index af7f4ab..545f95a 100644
--- a/usr.bin/osh/osh.c
+++ b/usr.bin/osh/osh.c
@@ -43,6 +43,9 @@
#define is_printable(C) ((C) >= 32 && (C) <= 126)
#define is_ascii(C) ((C) >= 0 && (C) <= 128)
+#define INPUT_SIZE 64
+
+#define REPEAT "!!"
#define COMMENT '@'
#define WELCOME \
":::::::::::::::::::::::::::::::::::::::\n" \
@@ -66,7 +69,8 @@
#define PROMPT "[%s::osmora]~ "
-static char buf[64];
+static char last_command[INPUT_SIZE];
+static char buf[INPUT_SIZE];
static int running;
static int bell_fd;
static bool bs_bell = true; /* Beep on backspace */
@@ -365,6 +369,18 @@ parse_line(char *input)
struct parse_state state = {0};
pid_t child;
+ /*
+ * If we are using the REPEAT shorthand,
+ * repeat the last command. We return -EAGAIN
+ * to indicate we did not parse a normal command
+ * so the repeat command isn't pushed into the last
+ * command buffer and we enter a recursive hell.
+ */
+ if (strcmp(input, REPEAT) == 0) {
+ parse_line(last_command);
+ return -EAGAIN;
+ }
+
/* Ensure the aux vector is zeored */
memset(argv, 0, sizeof(argv));
@@ -426,6 +442,25 @@ open_script(const char *pathname)
return 0;
}
+static void
+dump_file(const char *pathname)
+{
+ FILE *file;
+ char buf[64];
+ int fd;
+
+ file = fopen(pathname, "r");
+ if (file == NULL) {
+ return;
+ }
+
+ while (fgets(buf, sizeof(buf), file) != NULL) {
+ printf("%s", buf);
+ }
+
+ fclose(file);
+}
+
int
main(int argc, char **argv)
{
@@ -442,7 +477,7 @@ main(int argc, char **argv)
running = 1;
bell_fd = open("/dev/beep", O_WRONLY);
- puts(WELCOME);
+ dump_file("/etc/motd");
while (running) {
printf(PROMPT, getlogin());
@@ -457,6 +492,7 @@ main(int argc, char **argv)
continue;
}
+ memcpy(last_command, buf, buf_i + 1);
buf[0] = '\0';
}
return 0;