comparison gen_arm.c @ 803:236a184bf6f0

Merge
author Michael Pavone <pavone@retrodev.com>
date Sun, 26 Jul 2015 16:51:03 -0700
parents 724bbec47f86
children
comparison
equal deleted inserted replaced
802:6811f601008f 803:236a184bf6f0
74 { 74 {
75 if (code->cur == code->last) { 75 if (code->cur == code->last) {
76 size_t size = CODE_ALLOC_SIZE; 76 size_t size = CODE_ALLOC_SIZE;
77 uint32_t *next_code = alloc_code(&size); 77 uint32_t *next_code = alloc_code(&size);
78 if (!next_code) { 78 if (!next_code) {
79 fputs("Failed to allocate memory for generated code\n", stderr); 79 fatal_error("Failed to allocate memory for generated code\n");
80 exit(1);
81 } 80 }
82 if (next_code = code->last + RESERVE_WORDS) { 81 if (next_code = code->last + RESERVE_WORDS) {
83 //new chunk is contiguous with the current one 82 //new chunk is contiguous with the current one
84 code->last = next_code + size/sizeof(code_word) - RESERVE_WORDS; 83 code->last = next_code + size/sizeof(code_word) - RESERVE_WORDS;
85 } else { 84 } else {
546 { 545 {
547 check_alloc_code(code); 546 check_alloc_code(code);
548 *(code->cur++) = cc | POPM | reglist; 547 *(code->cur++) = cc | POPM | reglist;
549 return CODE_OK; 548 return CODE_OK;
550 } 549 }
550
551 uint32_t load_store_immoff(code_info *code, uint32_t op, uint32_t dst, uint32_t base, int32_t offset, uint32_t cc)
552 {
553 if (offset >= 0x1000 || offset <= -0x1000) {
554 return INVALID_IMMED;
555 }
556 check_alloc_code(code);
557 uint32_t instruction = cc | op | POST_IND | OFF_IMM | SZ_W | base << 16 | dst << 12;
558 if (offset >= 0) {
559 instruction |= offset | DIR_UP;
560 } else {
561 instruction |= (-offset) | DIR_DOWN;
562 }
563 *(code->cur++) = instruction;
564 return CODE_OK;
565 }
566
567 uint32_t ldr_cc(code_info *code, uint32_t dst, uint32_t base, int32_t offset, uint32_t cc)
568 {
569 return load_store_immoff(code, OP_LDR, dst, base, offset, cc);
570 }
571
572 uint32_t ldr(code_info *code, uint32_t dst, uint32_t base, int32_t offset)
573 {
574 return ldr_cc(code, dst, base, offset, CC_AL);
575 }
576
577 uint32_t str_cc(code_info *code, uint32_t src, uint32_t base, int32_t offset, uint32_t cc)
578 {
579 return load_store_immoff(code, OP_STR, src, base, offset, cc);
580 }
581
582 uint32_t str(code_info *code, uint32_t src, uint32_t base, int32_t offset)
583 {
584 return str_cc(code, src, base, offset, CC_AL);
585 }