comparison gen_arm.c @ 684:bff307e03a94

Added ldr and str instructions to gen_arm
author Michael Pavone <pavone@retrodev.com>
date Wed, 07 Jan 2015 22:42:35 -0800
parents c8fefa140c80
children 724bbec47f86
comparison
equal deleted inserted replaced
588:963d5901f583 684:bff307e03a94
546 { 546 {
547 check_alloc_code(code); 547 check_alloc_code(code);
548 *(code->cur++) = cc | POPM | reglist; 548 *(code->cur++) = cc | POPM | reglist;
549 return CODE_OK; 549 return CODE_OK;
550 } 550 }
551
552 uint32_t load_store_immoff(code_info *code, uint32_t op, uint32_t dst, uint32_t base, int32_t offset, uint32_t cc)
553 {
554 if (offset >= 0x1000 || offset <= -0x1000) {
555 return INVALID_IMMED;
556 }
557 check_alloc_code(code);
558 uint32_t instruction = cc | op | POST_IND | OFF_IMM | SZ_W | base << 16 | dst << 12;
559 if (offset >= 0) {
560 instruction |= offset | DIR_UP;
561 } else {
562 instruction |= (-offset) | DIR_DOWN;
563 }
564 *(code->cur++) = instruction;
565 return CODE_OK;
566 }
567
568 uint32_t ldr_cc(code_info *code, uint32_t dst, uint32_t base, int32_t offset, uint32_t cc)
569 {
570 return load_store_immoff(code, OP_LDR, dst, base, offset, cc);
571 }
572
573 uint32_t ldr(code_info *code, uint32_t dst, uint32_t base, int32_t offset)
574 {
575 return ldr_cc(code, dst, base, offset, CC_AL);
576 }
577
578 uint32_t str_cc(code_info *code, uint32_t src, uint32_t base, int32_t offset, uint32_t cc)
579 {
580 return load_store_immoff(code, OP_STR, src, base, offset, cc);
581 }
582
583 uint32_t str(code_info *code, uint32_t src, uint32_t base, int32_t offset)
584 {
585 return str_cc(code, src, base, offset, CC_AL);
586 }