From 3ab5f07bac34bc9de5b9038407353c707f3f4c2f Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 21 Jul 2025 09:17:30 -0400 Subject: oasm: Parse and encode the "HLT" instruction Signed-off-by: Ian Moffett --- usr.bin/oasm/emit.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'usr.bin/oasm/emit.c') diff --git a/usr.bin/oasm/emit.c b/usr.bin/oasm/emit.c index ee13582..cef90d7 100644 --- a/usr.bin/oasm/emit.c +++ b/usr.bin/oasm/emit.c @@ -220,6 +220,26 @@ emit_encode_add(struct emit_state *state, struct oasm_token *tok) return TAILQ_NEXT(tok, link); } +/* + * Encode a HLT instruction + * + * 'hlt' - no operands + * + * Returns the next token on success, + * otherwise NULL. + */ +static struct oasm_token * +emit_encode_hlt(struct emit_state *state, struct oasm_token *tok) +{ + inst_t curinst; + + curinst.opcode = OSMX64_HLT; + curinst.rd = 0; + curinst.unused = 0; + emit_bytes(state, &curinst, sizeof(curinst)); + return TAILQ_NEXT(tok, link); +} + int emit_osxm64(struct emit_state *state, struct oasm_token *tp) { @@ -301,6 +321,9 @@ emit_process(struct oasm_state *oasm, struct emit_state *emit) case TT_ADD: curtok = emit_encode_add(emit, curtok); break; + case TT_HLT: + curtok = emit_encode_hlt(emit, curtok); + break; default: curtok = TAILQ_NEXT(curtok, link); break; -- cgit v1.2.3