History

added 16-bit x86 assembly support

Frederic Feret committed 17 years ago

Commit 0d768b91 parent 2349efa8 files · +245 −37Browse files

Unified · Split

8 files
  1. elf.h +4 −0
  2. i386-asm.c +188 −31
  3. i386-asm.h +15 −6
  4. libtcc.c +3 −0
  5. tcc.h +4 −0
  6. tccasm.c +14 −0
  7. tccelf.c +12 −0
  8. tcctok.h +5 −0
elf.h+4−0
@@ -949,6 +949,10 @@ typedef struct · 948 unmodified lines
949/* Keep this the last entry. */949/* Keep this the last entry. */
950#define R_386_NUM 11950#define R_386_NUM 11
951 951
952/* TCC-specific 16-bit relocs. */
953#define R_386_16 12 /* Direct 16 bit */
954#define R_386_PC16 13 /* PC relative 16 bit */
955
952/* SUN SPARC specific definitions. */956/* SUN SPARC specific definitions. */
953 957
954/* Values for Elf64_Ehdr.e_flags. */958/* Values for Elf64_Ehdr.e_flags. */
i386-asm.c+188−31
@@ -116,8 +116,6 @@ static const uint8_t reg_to_size[5] = { · 115 unmodified lines
116*/116*/
117 0, 0, 1, 0, 2117 0, 0, 1, 0, 2
118};118};
119
120#define WORD_PREFIX_OPCODE 0x66
121 119
122#define NB_TEST_OPCODES 30120#define NB_TEST_OPCODES 30
123 121
@@ -190,6 +188,10 @@ static inline int get_reg_shift(TCCState *s1) · 66 unmodified lines
190{188{
191 int shift, v;189 int shift, v;
192 190
191 if (s1->seg_size == 16) {
192 error("invalid effective address");
193 }
194
193 v = asm_int_expr(s1);195 v = asm_int_expr(s1);
194 switch(v) {196 switch(v) {
195 case 1:197 case 1:
@@ -222,9 +224,13 @@ static int asm_parse_reg(void) · 26 unmodified lines
222 reg = tok - TOK_ASM_eax;224 reg = tok - TOK_ASM_eax;
223 next();225 next();
224 return reg;226 return reg;
227 } else if (tok >= TOK_ASM_ax && tok <= TOK_ASM_di) {
228 reg = tok - TOK_ASM_ax;
229 next();
230 return reg;
225 } else {231 } else {
226 error_32:232 error_32:
227 expect("32 bit register");233 expect("register");
228 return 0;234 return 0;
229 }235 }
230}236}
@@ -336,6 +342,12 @@ static void parse_operand(TCCState *s1, Operand *op) · 105 unmodified lines
336 op->type |= indir;342 op->type |= indir;
337}343}
338 344
345static void gen_le16(int v)
346{
347 g(v);
348 g(v >> 8);
349}
350
339/* XXX: unify with C code output ? */351/* XXX: unify with C code output ? */
340static void gen_expr32(ExprValue *pe)352static void gen_expr32(ExprValue *pe)
341{353{
@@ -344,6 +356,13 @@ static void gen_expr32(ExprValue *pe) · 2 unmodified lines
344 gen_le32(pe->v);356 gen_le32(pe->v);
345}357}
346 358
359static void gen_expr16(ExprValue *pe)
360{
361 if (pe->sym)
362 greloc(cur_text_section, pe->sym, ind, R_386_16);
363 gen_le16(pe->v);
364}
365
347/* XXX: unify with C code output ? */366/* XXX: unify with C code output ? */
348static void gen_disp32(ExprValue *pe)367static void gen_disp32(ExprValue *pe)
349{368{
@@ -368,11 +387,27 @@ static void gen_disp32(ExprValue *pe) · 18 unmodified lines
368 }387 }
369}388}
370 389
371 390static void gen_disp16(ExprValue *pe)
372static void gen_le16(int v)
373{391{
374 g(v);392 Sym *sym;
375 g(v >> 8);393 sym = pe->sym;
394 if (sym) {
395 if (sym->r == cur_text_section->sh_num) {
396 /* same section: we can output an absolute value. Note
397 that the TCC compiler behaves differently here because
398 it always outputs a relocation to ease (future) code
399 elimination in the linker */
400 gen_le16(pe->v + (long)sym->next - ind - 2);
401 } else {
402 greloc(cur_text_section, sym, ind, R_386_PC16);
403 gen_le16(pe->v - 2);
404 }
405 } else {
406 /* put an empty PC32 relocation */
407 put_elf_reloc(symtab_section, cur_text_section,
408 ind, R_386_PC16, 0);
409 gen_le16(pe->v - 2);
410 }
376}411}
377 412
378/* generate the modrm operand */413/* generate the modrm operand */
@@ -384,8 +419,13 @@ static inline void asm_modrm(int reg, Operand *op) · 5 unmodified lines
384 g(0xc0 + (reg << 3) + op->reg);419 g(0xc0 + (reg << 3) + op->reg);
385 } else if (op->reg == -1 && op->reg2 == -1) {420 } else if (op->reg == -1 && op->reg2 == -1) {
386 /* displacement only */421 /* displacement only */
387 g(0x05 + (reg << 3));422 if (tcc_state->seg_size == 16) {
388 gen_expr32(&op->e);423 g(0x06 + (reg << 3));
424 gen_expr16(&op->e);
425 } else if (tcc_state->seg_size == 32) {
426 g(0x05 + (reg << 3));
427 gen_expr32(&op->e);
428 }
389 } else {429 } else {
390 sib_reg1 = op->reg;430 sib_reg1 = op->reg;
391 /* fist compute displacement encoding */431 /* fist compute displacement encoding */
@@ -403,20 +443,59 @@ static inline void asm_modrm(int reg, Operand *op) · 11 unmodified lines
403 reg1 = op->reg;443 reg1 = op->reg;
404 if (op->reg2 != -1)444 if (op->reg2 != -1)
405 reg1 = 4;445 reg1 = 4;
406 g(mod + (reg << 3) + reg1);446 if (tcc_state->seg_size == 32) {
407 if (reg1 == 4) {447 g(mod + (reg << 3) + reg1);
408 /* add sib byte */448 if (reg1 == 4) {
409 reg2 = op->reg2;449 /* add sib byte */
410 if (reg2 == -1)450 reg2 = op->reg2;
411 reg2 = 4; /* indicate no index */451 if (reg2 == -1)
412 g((op->shift << 6) + (reg2 << 3) + sib_reg1);452 reg2 = 4; /* indicate no index */
453 g((op->shift << 6) + (reg2 << 3) + sib_reg1);
454 }
455 } else if (tcc_state->seg_size == 16) {
456 /* edi = 7, esi = 6 --> di = 5, si = 4 */
457 if ((reg1 == 6) || (reg1 == 7)) {
458 reg1 -= 2;
459 /* ebx = 3 --> bx = 7 */
460 } else if (reg1 == 3) {
461 reg1 = 7;
462 /* o32 = 5 --> o16 = 6 */
463 } else if (reg1 == 5) {
464 reg1 = 6;
465 /* sib not valid in 16-bit mode */
466 } else if (reg1 == 4) {
467 reg2 = op->reg2;
468 /* bp + si + offset */
469 if ((sib_reg1 == 5) && (reg2 == 6)) {
470 reg1 = 2;
471 /* bp + di + offset */
472 } else if ((sib_reg1 == 5) && (reg2 == 7)) {
473 reg1 = 3;
474 /* bx + si + offset */
475 } else if ((sib_reg1 == 3) && (reg2 == 6)) {
476 reg1 = 0;
477 /* bx + di + offset */
478 } else if ((sib_reg1 == 3) && (reg2 == 7)) {
479 reg1 = 1;
480 } else {
481 error("invalid effective address");
482 }
483 if (op->e.v == 0)
484 mod = 0;
485 } else {
486 error("invalid register");
487 }
488 g(mod + (reg << 3) + reg1);
413 }489 }
414 490
415 /* add offset */491 /* add offset */
416 if (mod == 0x40) {492 if (mod == 0x40) {
417 g(op->e.v);493 g(op->e.v);
418 } else if (mod == 0x80 || op->reg == -1) {494 } else if (mod == 0x80 || op->reg == -1) {
419 gen_expr32(&op->e);495 if (tcc_state->seg_size == 16)
496 gen_expr16(&op->e);
497 else if (tcc_state->seg_size == 32)
498 gen_expr32(&op->e);
420 }499 }
421 }500 }
422}501}
@@ -428,6 +507,7 @@ static void asm_opcode(TCCState *s1, int opcode) · 5 unmodified lines
428 int nb_ops, s, ss;507 int nb_ops, s, ss;
429 Operand ops[MAX_OPERANDS], *pop;508 Operand ops[MAX_OPERANDS], *pop;
430 int op_type[3]; /* decoded op type */509 int op_type[3]; /* decoded op type */
510 static int a32 = 0, o32 = 0, addr32 = 0, data32 = 0;
431 511
432 /* get operands */512 /* get operands */
433 pop = ops;513 pop = ops;
@@ -442,14 +522,17 @@ static void asm_opcode(TCCState *s1, int opcode) · 8 unmodified lines
442 parse_operand(s1, pop);522 parse_operand(s1, pop);
443 if (tok == ':') {523 if (tok == ':') {
444 if (pop->type != OP_SEG || seg_prefix) {524 if (pop->type != OP_SEG || seg_prefix) {
525 bad_prefix:
445 error("incorrect prefix");526 error("incorrect prefix");
446 }527 }
447 seg_prefix = segment_prefixes[pop->reg];528 seg_prefix = segment_prefixes[pop->reg];
448 next();529 next();
449 parse_operand(s1, pop);530 parse_operand(s1, pop);
531#if 0
450 if (!(pop->type & OP_EA)) {532 if (!(pop->type & OP_EA)) {
451 error("segment prefix must be followed by memory reference");533 error("segment prefix must be followed by memory reference");
452 }534 }
535#endif
453 }536 }
454 pop++;537 pop++;
455 nb_ops++;538 nb_ops++;
@@ -531,6 +614,17 @@ static void asm_opcode(TCCState *s1, int opcode) · 75 unmodified lines
531 if (opcode >= TOK_ASM_pusha && opcode <= TOK_ASM_emms) {614 if (opcode >= TOK_ASM_pusha && opcode <= TOK_ASM_emms) {
532 int b;615 int b;
533 b = op0_codes[opcode - TOK_ASM_pusha];616 b = op0_codes[opcode - TOK_ASM_pusha];
617 if (opcode == TOK_ASM_o32) {
618 if (s1->seg_size == 32)
619 goto bad_prefix;
620 else
621 o32 = data32 = 1;
622 } else if (opcode == TOK_ASM_a32) {
623 if (s1->seg_size == 32)
624 goto bad_prefix;
625 else
626 a32 = addr32 = 1;
627 }
534 if (b & 0xff00) 628 if (b & 0xff00)
535 g(b >> 8);629 g(b >> 8);
536 g(b);630 g(b);
@@ -555,12 +649,37 @@ static void asm_opcode(TCCState *s1, int opcode) · 18 unmodified lines
555 }649 }
556 }650 }
557 651
558 /* generate data16 prefix if needed */652 for(i = 0; i < nb_ops; i++) {
653 if (ops[i].type & OP_REG32) {
654 if (s1->seg_size == 16)
655 o32 = 1;
656 } else if (!ops[i].type & OP_REG32) {
657 if (s1->seg_size == 32)
658 o32 = 1;
659 }
660 }
661
559 ss = s;662 ss = s;
560 if (s == 1 || (pa->instr_type & OPC_D16))663 if (s == 1 || (pa->instr_type & OPC_D16)) {
561 g(WORD_PREFIX_OPCODE);664 if (s1->seg_size == 32)
562 else if (s == 2)665 o32 = 1;
666 } else if (s == 2) {
667 if (s1->seg_size == 16) {
668 if (!(pa->instr_type & OPC_D16))
669 o32 = 1;
670 }
563 s = 1;671 s = 1;
672 }
673
674 /* generate a16/a32 prefix if needed */
675 if ((a32 == 1) && (addr32 == 0))
676 g(0x67);
677 /* generate o16/o32 prefix if needed */
678 if ((o32 == 1) && (data32 == 0))
679 g(0x66);
680
681 addr32 = data32 = 0;
682
564 /* now generates the operation */683 /* now generates the operation */
565 if (pa->instr_type & OPC_FWAIT)684 if (pa->instr_type & OPC_FWAIT)
566 g(0x9b);685 g(0x9b);
@@ -685,9 +804,17 @@ static void asm_opcode(TCCState *s1, int opcode) · 118 unmodified lines
685 /* emit constants */804 /* emit constants */
686 if (pa->opcode == 0x9a || pa->opcode == 0xea) {805 if (pa->opcode == 0x9a || pa->opcode == 0xea) {
687 /* ljmp or lcall kludge */806 /* ljmp or lcall kludge */
688 gen_expr32(&ops[1].e);807 if (s1->seg_size == 16) {
689 if (ops[0].e.sym)808 if (o32 == 0)
809 gen_expr16(&ops[1].e);
810 else if (o32 == 1)
811 gen_expr32(&ops[1].e);
812 } else
813 gen_expr32(&ops[1].e);
814 if (ops[0].e.sym) {
815 error_relocate:
690 error("cannot relocate");816 error("cannot relocate");
817 }
691 gen_le16(ops[0].e.v);818 gen_le16(ops[0].e.v);
692 } else {819 } else {
693 for(i = 0;i < nb_ops; i++) {820 for(i = 0;i < nb_ops; i++) {
@@ -709,24 +836,48 @@ static void asm_opcode(TCCState *s1, int opcode) · 15 unmodified lines
709 goto error_relocate;836 goto error_relocate;
710 g(ops[i].e.v);837 g(ops[i].e.v);
711 } else if (v & OP_IM16) {838 } else if (v & OP_IM16) {
712 if (ops[i].e.sym) {839 if (s1->seg_size == 16)
713 error_relocate:840 gen_expr16(&ops[i].e);
714 error("cannot relocate");841 else {
842 if (ops[i].e.sym)
843 goto error_relocate;
715 }844 }
716 gen_le16(ops[i].e.v);845 gen_le16(ops[i].e.v);
846 }
717 } else {847 } else {
718 if (pa->instr_type & (OPC_JMP | OPC_SHORTJMP)) {848 if (pa->instr_type & (OPC_JMP | OPC_SHORTJMP)) {
719 if (is_short_jmp)849 if (is_short_jmp)
720 g(ops[i].e.v);850 g(ops[i].e.v);
721 else851 else {
722 gen_disp32(&ops[i].e);852 if (s1->seg_size == 16)
853 gen_disp16(&ops[i].e);
854 else
855 gen_disp32(&ops[i].e);
856 }
723 } else {857 } else {
724 gen_expr32(&ops[i].e);858 if (s1->seg_size == 16) {
859 if ((o32 == 1) && (v & OP_IM32))
860 gen_expr32(&ops[i].e);
861 else
862 gen_expr16(&ops[i].e);
863 } else if (s1->seg_size == 32) {
864 if (o32 == 1)
865 gen_expr16(&ops[i].e);
866 else
867 gen_expr32(&ops[i].e);
868 }
725 }869 }
726 }870 }
871 } else if (v & (OP_REG16 | OP_REG32)) {
872 if (pa->instr_type & (OPC_JMP | OPC_SHORTJMP)) {
873 /* jmp $r */
874 g(0xE0 + ops[i].reg);
875 }
727 }876 }
728 }877 }
729 }878 }
879
880 a32 = o32 = 0;
730}881}
731 882
732#define NB_SAVED_REGS 3883#define NB_SAVED_REGS 3
@@ -1127,8 +1278,11 @@ static void asm_gen_code(ASMOperand *operands, int nb_operands, · 394 unmodified lines
1127 /* generate reg save code */1278 /* generate reg save code */
1128 for(i = 0; i < NB_SAVED_REGS; i++) {1279 for(i = 0; i < NB_SAVED_REGS; i++) {
1129 reg = reg_saved[i];1280 reg = reg_saved[i];
1130 if (regs_allocated[reg]) 1281 if (regs_allocated[reg]) {
1282 if (tcc_state->seg_size == 16)
1283 g(0x66);
1131 g(0x50 + reg);1284 g(0x50 + reg);
1285 }
1132 }1286 }
1133 1287
1134 /* generate load code */1288 /* generate load code */
@@ -1184,8 +1338,11 @@ static void asm_gen_code(ASMOperand *operands, int nb_operands, · 49 unmodified lines
1184 /* generate reg restore code */1338 /* generate reg restore code */
1185 for(i = NB_SAVED_REGS - 1; i >= 0; i--) {1339 for(i = NB_SAVED_REGS - 1; i >= 0; i--) {
1186 reg = reg_saved[i];1340 reg = reg_saved[i];
1187 if (regs_allocated[reg]) 1341 if (regs_allocated[reg]) {
1342 if (tcc_state->seg_size == 16)
1343 g(0x66);
1188 g(0x58 + reg);1344 g(0x58 + reg);
1345 }
1189 }1346 }
1190 }1347 }
1191}1348}
i386-asm.h+15−6
@@ -74,10 +74,8 @@ ALT(DEF_ASM_OP2(btcw, 0x0fbb, 0, OPC_MODRM | OPC_WL, OPT_REGW, OPT_REGW | OPT_EA · 73 unmodified lines
74ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))74ALT(DEF_ASM_OP2(btcw, 0x0fba, 7, OPC_MODRM | OPC_WL, OPT_IM8, OPT_REGW | OPT_EA))
75 75
76 /* prefixes */76 /* prefixes */
77 DEF_ASM_OP0(aword, 0x67)77 DEF_ASM_OP0(addr32, 0x67)
78 DEF_ASM_OP0(addr16, 0x67)78 DEF_ASM_OP0(data32, 0x66)
79 DEF_ASM_OP0(word, 0x66)
80 DEF_ASM_OP0(data16, 0x66)
81 DEF_ASM_OP0(lock, 0xf0)79 DEF_ASM_OP0(lock, 0xf0)
82 DEF_ASM_OP0(rep, 0xf3)80 DEF_ASM_OP0(rep, 0xf3)
83 DEF_ASM_OP0(repe, 0xf3)81 DEF_ASM_OP0(repe, 0xf3)
@@ -120,9 +118,9 @@ ALT(DEF_ASM_OP2(movzwl, 0x0fb7, 0, OPC_MODRM, OPT_REG16 | OPT_EA, OPT_REG32)) · 36 unmodified lines
120 118
121ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WL, OPT_REGW))119ALT(DEF_ASM_OP1(pushw, 0x50, 0, OPC_REG | OPC_WL, OPT_REGW))
122ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))120ALT(DEF_ASM_OP1(pushw, 0xff, 6, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
123ALT(DEF_ASM_OP1(pushw, 0x6a, 0, OPC_WL, OPT_IM8S))
124ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WL, OPT_IM32))121ALT(DEF_ASM_OP1(pushw, 0x68, 0, OPC_WL, OPT_IM32))
125ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WL, OPT_SEG))122ALT(DEF_ASM_OP1(pushw, 0x06, 0, OPC_WL, OPT_SEG))
123 DEF_ASM_OP1(pushb, 0x6a, 0, OPC_B, OPT_IM8S)
126 124
127ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WL, OPT_REGW))125ALT(DEF_ASM_OP1(popw, 0x58, 0, OPC_REG | OPC_WL, OPT_REGW))
128ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))126ALT(DEF_ASM_OP1(popw, 0x8f, 0, OPC_MODRM | OPC_WL, OPT_REGW | OPT_EA))
@@ -201,6 +199,7 @@ ALT(DEF_ASM_OP1(call, 0xff, 2, OPC_MODRM, OPT_INDIR)) · 72 unmodified lines
201ALT(DEF_ASM_OP1(call, 0xe8, 0, OPC_JMP, OPT_ADDR))199ALT(DEF_ASM_OP1(call, 0xe8, 0, OPC_JMP, OPT_ADDR))
202ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR))200ALT(DEF_ASM_OP1(jmp, 0xff, 4, OPC_MODRM, OPT_INDIR))
203ALT(DEF_ASM_OP1(jmp, 0xeb, 0, OPC_SHORTJMP | OPC_JMP, OPT_ADDR))201ALT(DEF_ASM_OP1(jmp, 0xeb, 0, OPC_SHORTJMP | OPC_JMP, OPT_ADDR))
202ALT(DEF_ASM_OP1(jmp, 0xff, 0, OPC_JMP | OPC_WL, OPT_REGW))
204 203
205ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32))204ALT(DEF_ASM_OP2(lcall, 0x9a, 0, 0, OPT_IM16, OPT_IM32))
206ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))205ALT(DEF_ASM_OP1(lcall, 0xff, 3, 0, OPT_EA))
@@ -350,6 +349,9 @@ ALT(DEF_ASM_OP2(lslw, 0x0f03, 0, OPC_MODRM | OPC_WL, OPT_EA | OPT_REG, OPT_REG)) · 143 unmodified lines
350 DEF_ASM_OP1(verr, 0x0f00, 4, OPC_MODRM, OPT_REG | OPT_EA)349 DEF_ASM_OP1(verr, 0x0f00, 4, OPC_MODRM, OPT_REG | OPT_EA)
351 DEF_ASM_OP1(verw, 0x0f00, 5, OPC_MODRM, OPT_REG | OPT_EA)350 DEF_ASM_OP1(verw, 0x0f00, 5, OPC_MODRM, OPT_REG | OPT_EA)
352 351
352 /* 386 */
353 DEF_ASM_OP0(loadall386, 0x0f07)
354
353 /* 486 */355 /* 486 */
354 DEF_ASM_OP1(bswap, 0x0fc8, 0, OPC_REG, OPT_REG32 )356 DEF_ASM_OP1(bswap, 0x0fc8, 0, OPC_REG, OPT_REG32 )
355ALT(DEF_ASM_OP2(xaddb, 0x0fc0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))357ALT(DEF_ASM_OP2(xaddb, 0x0fc0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT_EA ))
@@ -363,7 +365,14 @@ ALT(DEF_ASM_OP2(cmpxchgb, 0x0fb0, 0, OPC_MODRM | OPC_BWL, OPT_REG, OPT_REG | OPT · 7 unmodified lines
363 DEF_ASM_OP1(cmpxchg8b, 0x0fc7, 1, OPC_MODRM, OPT_EA )365 DEF_ASM_OP1(cmpxchg8b, 0x0fc7, 1, OPC_MODRM, OPT_EA )
364 366
365 /* pentium pro */367 /* pentium pro */
366 ALT(DEF_ASM_OP2(cmovo, 0x0f40, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))368ALT(DEF_ASM_OP2(cmovo, 0x0f40, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
369ALT(DEF_ASM_OP2(cmovno, 0x0f41, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
370ALT(DEF_ASM_OP2(cmovc, 0x0f42, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
371ALT(DEF_ASM_OP2(cmovnc, 0x0f43, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
372ALT(DEF_ASM_OP2(cmovz, 0x0f44, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
373ALT(DEF_ASM_OP2(cmovnz, 0x0f45, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
374ALT(DEF_ASM_OP2(cmovna, 0x0f46, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
375ALT(DEF_ASM_OP2(cmova, 0x0f47, 0, OPC_MODRM | OPC_TEST, OPT_REG32 | OPT_EA, OPT_REG32))
367 376
368 DEF_ASM_OP2(fcmovb, 0xdac0, 0, OPC_REG, OPT_ST, OPT_ST0 )377 DEF_ASM_OP2(fcmovb, 0xdac0, 0, OPC_REG, OPT_ST, OPT_ST0 )
369 DEF_ASM_OP2(fcmove, 0xdac8, 0, OPC_REG, OPT_ST, OPT_ST0 )378 DEF_ASM_OP2(fcmove, 0xdac8, 0, OPC_REG, OPT_ST, OPT_ST0 )
libtcc.c+3−0
@@ -1937,6 +1937,9 @@ TCCState *tcc_new(void) · 1936 unmodified lines
1937#if defined(TCC_TARGET_PE) && 01937#if defined(TCC_TARGET_PE) && 0
1938 /* XXX: currently the PE linker is not ready to support that */1938 /* XXX: currently the PE linker is not ready to support that */
1939 s->leading_underscore = 1;1939 s->leading_underscore = 1;
1940#endif
1941#ifdef TCC_TARGET_I386
1942 s->seg_size = 32;
1940#endif1943#endif
1941 return s;1944 return s;
1942}1945}
tcc.h+4−0
@@ -512,6 +512,10 @@ struct TCCState { · 511 unmodified lines
512 struct InlineFunc **inline_fns;512 struct InlineFunc **inline_fns;
513 int nb_inline_fns;513 int nb_inline_fns;
514 514
515#ifdef TCC_TARGET_I386
516 int seg_size;
517#endif
518
515#ifndef TCC_TARGET_PE519#ifndef TCC_TARGET_PE
516#ifdef TCC_TARGET_X86_64520#ifdef TCC_TARGET_X86_64
517 /* write PLT and GOT here */521 /* write PLT and GOT here */
tccasm.c+14−0
@@ -571,6 +571,20 @@ static void asm_parse_directive(TCCState *s1) · 570 unmodified lines
571 last_text_section = sec;571 last_text_section = sec;
572 }572 }
573 break;573 break;
574#ifdef TCC_TARGET_I386
575 case TOK_ASM_code16:
576 {
577 next();
578 s1->seg_size = 16;
579 }
580 break;
581 case TOK_ASM_code32:
582 {
583 next();
584 s1->seg_size = 32;
585 }
586 break;
587#endif
574 default:588 default:
575 error("unknown assembler directive '.%s'", get_tok_str(tok, NULL));589 error("unknown assembler directive '.%s'", get_tok_str(tok, NULL));
576 break;590 break;
tccelf.c+12−0
@@ -591,6 +591,18 @@ static void relocate_section(TCCState *s1, Section *s) · 590 unmodified lines
591 /* we load the got offset */591 /* we load the got offset */
592 *(int *)ptr += s1->got_offsets[sym_index];592 *(int *)ptr += s1->got_offsets[sym_index];
593 break;593 break;
594 case R_386_16:
595 if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) {
596 output_file:
597 error("can only produce 16-bit binary files");
598 }
599 *(short *)ptr += val;
600 break;
601 case R_386_PC16:
602 if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY)
603 goto output_file;
604 *(short *)ptr += val - addr;
605 break;
594#elif defined(TCC_TARGET_ARM)606#elif defined(TCC_TARGET_ARM)
595 case R_ARM_PC24:607 case R_ARM_PC24:
596 case R_ARM_CALL:608 case R_ARM_CALL:
tcctok.h+5−0
@@ -235,6 +235,7 @@ · 234 unmodified lines
235/* Tiny Assembler */235/* Tiny Assembler */
236 236
237 DEF_ASM(byte)237 DEF_ASM(byte)
238 DEF_ASM(word)
238 DEF_ASM(align)239 DEF_ASM(align)
239 DEF_ASM(skip)240 DEF_ASM(skip)
240 DEF_ASM(space)241 DEF_ASM(space)
@@ -250,6 +251,10 @@ · 9 unmodified lines
250 DEF_ASM(fill)251 DEF_ASM(fill)
251 DEF_ASM(org)252 DEF_ASM(org)
252 DEF_ASM(quad)253 DEF_ASM(quad)
254#if defined(TCC_TARGET_I386)
255 DEF_ASM(code16)
256 DEF_ASM(code32)
257#endif
253 258
254#ifdef TCC_TARGET_I386259#ifdef TCC_TARGET_I386
255 260

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t