1d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org/* 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LC-3b Architecture header file 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Copyright (C) 2003-2007 Peter Johnson 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Redistribution and use in source and binary forms, with or without 745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * modification, are permitted provided that the following conditions 845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * are met: 945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1. Redistributions of source code must retain the above copyright 1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer. 1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 2. Redistributions in binary form must reproduce the above copyright 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer in the 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * documentation and/or other materials provided with the distribution. 1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * POSSIBILITY OF SUCH DAMAGE. 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_LC3BARCH_H 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LC3BARCH_H 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Types of immediate. All immediates are stored in the LSBs of the insn. */ 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum lc3b_imm_type { 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LC3B_IMM_NONE = 0, /* no immediate */ 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LC3B_IMM_4, /* 4-bit */ 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LC3B_IMM_5, /* 5-bit */ 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LC3B_IMM_6_WORD, /* 6-bit, word-multiple (byte>>1) */ 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LC3B_IMM_6_BYTE, /* 6-bit, byte-multiple */ 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LC3B_IMM_8, /* 8-bit, word-multiple (byte>>1) */ 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LC3B_IMM_9, /* 9-bit, signed, word-multiple (byte>>1) */ 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org LC3B_IMM_9_PC /* 9-bit, signed, word-multiple, PC relative */ 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} lc3b_imm_type; 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Bytecode types */ 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct lc3b_insn { 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_value imm; /* immediate or relative value */ 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org lc3b_imm_type imm_type; /* size of the immediate */ 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned int opcode; /* opcode */ 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} lc3b_insn; 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_lc3b__bc_transform_insn(yasm_bytecode *bc, lc3b_insn *insn); 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_arch_insnprefix yasm_lc3b__parse_check_insnprefix 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (yasm_arch *arch, const char *id, size_t id_len, unsigned long line, 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@out@*/ /*@only@*/ yasm_bytecode **bc, /*@out@*/ uintptr_t *prefix); 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_arch_regtmod yasm_lc3b__parse_check_regtmod 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (yasm_arch *arch, const char *id, size_t id_len, 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@out@*/ uintptr_t *data); 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_lc3b__intnum_tobytes 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (yasm_arch *arch, const yasm_intnum *intn, unsigned char *buf, 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t destsize, size_t valsize, int shift, const yasm_bytecode *bc, 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int warn); 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_bytecode *yasm_lc3b__create_empty_insn(yasm_arch *arch, 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned long line); 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_lc3b__ea_destroy(/*@only@*/ yasm_effaddr *ea); 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 71