mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Implement syscall for arm32
This commit is contained in:
+68
-43
@@ -189,7 +189,7 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body)
|
|||||||
GB_ASSERT(entity->kind == Entity_Procedure);
|
GB_ASSERT(entity->kind == Entity_Procedure);
|
||||||
String link_name = entity->Procedure.link_name;
|
String link_name = entity->Procedure.link_name;
|
||||||
if (entity->flags & EntityFlag_CustomLinkName &&
|
if (entity->flags & EntityFlag_CustomLinkName &&
|
||||||
link_name != "") {
|
link_name != "") {
|
||||||
if (string_starts_with(link_name, str_lit("__"))) {
|
if (string_starts_with(link_name, str_lit("__"))) {
|
||||||
LLVMSetLinkage(p->value, LLVMExternalLinkage);
|
LLVMSetLinkage(p->value, LLVMExternalLinkage);
|
||||||
} else {
|
} else {
|
||||||
@@ -1315,9 +1315,9 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
|
|||||||
|
|
||||||
case BuiltinProc_clamp:
|
case BuiltinProc_clamp:
|
||||||
return lb_emit_clamp(p, type_of_expr(expr),
|
return lb_emit_clamp(p, type_of_expr(expr),
|
||||||
lb_build_expr(p, ce->args[0]),
|
lb_build_expr(p, ce->args[0]),
|
||||||
lb_build_expr(p, ce->args[1]),
|
lb_build_expr(p, ce->args[1]),
|
||||||
lb_build_expr(p, ce->args[2]));
|
lb_build_expr(p, ce->args[2]));
|
||||||
|
|
||||||
|
|
||||||
case BuiltinProc_soa_zip:
|
case BuiltinProc_soa_zip:
|
||||||
@@ -1370,7 +1370,7 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
|
|||||||
|
|
||||||
case BuiltinProc_cpu_relax:
|
case BuiltinProc_cpu_relax:
|
||||||
if (build_context.metrics.arch == TargetArch_i386 ||
|
if (build_context.metrics.arch == TargetArch_i386 ||
|
||||||
build_context.metrics.arch == TargetArch_amd64) {
|
build_context.metrics.arch == TargetArch_amd64) {
|
||||||
LLVMTypeRef func_type = LLVMFunctionType(LLVMVoidTypeInContext(p->module->ctx), nullptr, 0, false);
|
LLVMTypeRef func_type = LLVMFunctionType(LLVMVoidTypeInContext(p->module->ctx), nullptr, 0, false);
|
||||||
LLVMValueRef the_asm = llvm_get_inline_asm(func_type, str_lit("pause"), {}, true);
|
LLVMValueRef the_asm = llvm_get_inline_asm(func_type, str_lit("pause"), {}, true);
|
||||||
GB_ASSERT(the_asm != nullptr);
|
GB_ASSERT(the_asm != nullptr);
|
||||||
@@ -1993,47 +1993,72 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
|
|||||||
break;
|
break;
|
||||||
case TargetArch_arm64:
|
case TargetArch_arm64:
|
||||||
{
|
{
|
||||||
GB_ASSERT(arg_count <= 7);
|
GB_ASSERT(arg_count <= 7);
|
||||||
|
|
||||||
if(build_context.metrics.os == TargetOs_darwin) {
|
if(build_context.metrics.os == TargetOs_darwin) {
|
||||||
char asm_string[] = "svc #0x80";
|
char asm_string[] = "svc #0x80";
|
||||||
gbString constraints = gb_string_make(heap_allocator(), "={x0}");
|
gbString constraints = gb_string_make(heap_allocator(), "={x0}");
|
||||||
for (unsigned i = 0; i < arg_count; i++) {
|
for (unsigned i = 0; i < arg_count; i++) {
|
||||||
constraints = gb_string_appendc(constraints, ",{");
|
constraints = gb_string_appendc(constraints, ",{");
|
||||||
static char const *regs[] = {
|
static char const *regs[] = {
|
||||||
"x16",
|
"x16",
|
||||||
"x0",
|
"x0",
|
||||||
"x1",
|
"x1",
|
||||||
"x2",
|
"x2",
|
||||||
"x3",
|
"x3",
|
||||||
"x4",
|
"x4",
|
||||||
"x5",
|
"x5",
|
||||||
};
|
};
|
||||||
constraints = gb_string_appendc(constraints, regs[i]);
|
constraints = gb_string_appendc(constraints, regs[i]);
|
||||||
constraints = gb_string_appendc(constraints, "}");
|
constraints = gb_string_appendc(constraints, "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline_asm = llvm_get_inline_asm(func_type, make_string_c(asm_string), make_string_c(constraints));
|
inline_asm = llvm_get_inline_asm(func_type, make_string_c(asm_string), make_string_c(constraints));
|
||||||
} else {
|
} else {
|
||||||
char asm_string[] = "svc #0";
|
char asm_string[] = "svc #0";
|
||||||
gbString constraints = gb_string_make(heap_allocator(), "={x0}");
|
gbString constraints = gb_string_make(heap_allocator(), "={x0}");
|
||||||
for (unsigned i = 0; i < arg_count; i++) {
|
for (unsigned i = 0; i < arg_count; i++) {
|
||||||
constraints = gb_string_appendc(constraints, ",{");
|
constraints = gb_string_appendc(constraints, ",{");
|
||||||
static char const *regs[] = {
|
static char const *regs[] = {
|
||||||
"x8",
|
"x8",
|
||||||
"x0",
|
"x0",
|
||||||
"x1",
|
"x1",
|
||||||
"x2",
|
"x2",
|
||||||
"x3",
|
"x3",
|
||||||
"x4",
|
"x4",
|
||||||
"x5",
|
"x5",
|
||||||
};
|
};
|
||||||
constraints = gb_string_appendc(constraints, regs[i]);
|
constraints = gb_string_appendc(constraints, regs[i]);
|
||||||
constraints = gb_string_appendc(constraints, "}");
|
constraints = gb_string_appendc(constraints, "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline_asm = llvm_get_inline_asm(func_type, make_string_c(asm_string), make_string_c(constraints));
|
inline_asm = llvm_get_inline_asm(func_type, make_string_c(asm_string), make_string_c(constraints));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TargetArch_arm32:
|
||||||
|
{
|
||||||
|
// TODO(bill): Check this is correct
|
||||||
|
GB_ASSERT(arg_count <= 7);
|
||||||
|
|
||||||
|
char asm_string[] = "svc #0";
|
||||||
|
gbString constraints = gb_string_make(heap_allocator(), "={r0}");
|
||||||
|
for (unsigned i = 0; i < arg_count; i++) {
|
||||||
|
constraints = gb_string_appendc(constraints, ",{");
|
||||||
|
static char const *regs[] = {
|
||||||
|
"r8",
|
||||||
|
"r0",
|
||||||
|
"r1",
|
||||||
|
"r2",
|
||||||
|
"r3",
|
||||||
|
"r4",
|
||||||
|
"r5",
|
||||||
|
};
|
||||||
|
constraints = gb_string_appendc(constraints, regs[i]);
|
||||||
|
constraints = gb_string_appendc(constraints, "}");
|
||||||
|
}
|
||||||
|
|
||||||
|
inline_asm = llvm_get_inline_asm(func_type, make_string_c(asm_string), make_string_c(constraints));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user