diff gen_arm.c @ 803:236a184bf6f0

Merge
author Michael Pavone <pavone@retrodev.com>
date Sun, 26 Jul 2015 16:51:03 -0700
parents 724bbec47f86
children
line wrap: on
line diff
--- a/gen_arm.c	Sun Jul 26 16:48:25 2015 -0700
+++ b/gen_arm.c	Sun Jul 26 16:51:03 2015 -0700
@@ -76,8 +76,7 @@
 		size_t size = CODE_ALLOC_SIZE;
 		uint32_t *next_code = alloc_code(&size);
 		if (!next_code) {
-			fputs("Failed to allocate memory for generated code\n", stderr);
-			exit(1);
+			fatal_error("Failed to allocate memory for generated code\n");
 		}
 		if (next_code = code->last + RESERVE_WORDS) {
 			//new chunk is contiguous with the current one
@@ -548,3 +547,39 @@
 	*(code->cur++) = cc | POPM | reglist;
 	return CODE_OK;
 }
+
+uint32_t load_store_immoff(code_info *code, uint32_t op, uint32_t dst, uint32_t base, int32_t offset, uint32_t cc)
+{
+	if (offset >= 0x1000 || offset <= -0x1000) {
+		return INVALID_IMMED;
+	}
+	check_alloc_code(code);
+	uint32_t instruction = cc | op | POST_IND | OFF_IMM | SZ_W | base << 16 | dst << 12;
+	if (offset >= 0) {
+		instruction |= offset | DIR_UP;
+	} else {
+		instruction |= (-offset) | DIR_DOWN;
+	}
+	*(code->cur++) = instruction;
+	return CODE_OK;
+}
+
+uint32_t ldr_cc(code_info *code, uint32_t dst, uint32_t base, int32_t offset, uint32_t cc)
+{
+	return load_store_immoff(code, OP_LDR, dst, base, offset, cc);
+}
+
+uint32_t ldr(code_info *code, uint32_t dst, uint32_t base, int32_t offset)
+{
+	return ldr_cc(code, dst, base, offset, CC_AL);
+}
+
+uint32_t str_cc(code_info *code, uint32_t src, uint32_t base, int32_t offset, uint32_t cc)
+{
+	return load_store_immoff(code, OP_STR, src, base, offset, cc);
+}
+
+uint32_t str(code_info *code, uint32_t src, uint32_t base, int32_t offset)
+{
+	return str_cc(code, src, base, offset, CC_AL);
+}