From patchwork Tue Jun 7 22:26:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 579445 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp5597040max; Tue, 7 Jun 2022 16:13:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVnIqxUX7wwbVY2u1+pZP6Dk1izl2OoWonoIqlUedYSHHo+uXPUPruqdcOl2FXfulz495V X-Received: by 2002:ad4:596f:0:b0:467:d3ad:b582 with SMTP id eq15-20020ad4596f000000b00467d3adb582mr21257862qvb.113.1654643591434; Tue, 07 Jun 2022 16:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654643591; cv=none; d=google.com; s=arc-20160816; b=nQ4HGdQ3TRkavUdcG95jXMRYc2xAzdkkQslgzV7EclvoiOpeVwwnrWlm1g9KR724NC tqsVkj0vH9kFz01LK0S2Dlk9bCi7G15GhzbalmVOwE34joCGqULJDHMmcKcpAPa4M4Mv bg5V1KwWhxIXtr6sNjQo9Zyke+1Qxk3H3mEkV707r1TH3g/KEWKr/zFCGgVgBu/fQpWl 7J4DvvzDkAx9pPX2I6+6cDwlZC4vwozblK6GKiKUi28YdEPZPmssbpAq2K+r9ZRg+PZc jEpEgwM63EfV67VGjOA72N1l7gmV4vDpJg3ZfY/6hsH1ZaBoFwYoEmz9FpW6g9P+cVba 7Gag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0rn+Nwlq/SZ84k46btrnEBM9Y+gGCUfAzGjjM5Ob5VY=; b=rTySkBMrWQg72enzzqJelB/frW1qVzgTwTo3mju1D+CepOaoGbLCVcD24s5c0fhluh dG8pombsf1lo2VB/PFrd6shUEQEu2EaLOif8xDgeM/EbNbNkuzwovwDtqB0WDEBuhzRg 5Jd7tIhldFA6xyi+GEwjQMVaYMzfwyfbB3Sw2miRTDS0ZiwvAnQHLZA9O7U6uHJ0cPhI CbuAlGQmU8I9SBzNggkLeI+DLvffSJqa8whZB8QroyqeI4x8Ck7Y0lFNnvmIxlJ6dT6z 6H0irw6g/jcHlklOPE3p38Q9nZrPK3uGZM/F0ToFj9T7qvnoboQ/qaAP0Hm8LpLQukpp h1xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LcmhXeIM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q12-20020a05620a0d8c00b006a67b49fe7bsi10037287qkl.631.2022.06.07.16.13.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Jun 2022 16:13:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LcmhXeIM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyiNq-0000Vx-MO for patch@linaro.org; Tue, 07 Jun 2022 19:13:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyhec-0005a2-Lb for qemu-devel@nongnu.org; Tue, 07 Jun 2022 18:26:26 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:38862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyheW-0007vK-Bo for qemu-devel@nongnu.org; Tue, 07 Jun 2022 18:26:26 -0400 Received: by mail-pl1-x631.google.com with SMTP id n18so16018133plg.5 for ; Tue, 07 Jun 2022 15:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0rn+Nwlq/SZ84k46btrnEBM9Y+gGCUfAzGjjM5Ob5VY=; b=LcmhXeIME/8vZ2Phkl3G7YcHStZ7PLnKkT2iriviH9nUQV09KCHKtH4eZDETDGPRSn /c4h08+FnXVshhINPRRL5Ih6n0mkLLn0jrDpXqFHq6EQ72irmHFXonQJPRW9iwiG4aCp pt9t4eo7FTnvDLjYDcjuBi8mldNcAQKWWtqXfbwx52r+nQcCQZLLkvZ941dPJR3v5SO5 JfrOEs3Leiabvd80gRmiWDmG7DR9f6jlMs2MDOT2fwfUoURtCzPuPwa4D0DHQohAd3bK 9rjjZInjYF8BvInGsIIOnA9Q4jKDqLxlwUYQdIkzrJl8MFDxgTTZV30DC2Ch/e0GOOKG d6IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0rn+Nwlq/SZ84k46btrnEBM9Y+gGCUfAzGjjM5Ob5VY=; b=kGgOnvk5F3XWqfF/6JdA5AzG/eYdIboP/NT2nxRKm8rep7oh1Uw9qctIHXdDVzNTeN gBljIDHgir4oGOOgZyWxAkiD3dpeCN6EX2fBOxVGPoew+rrqRlnRw0JadaopA758Moij qlmf6Wmy5z5RkbMscw0CbsgJ+19yoCyzq+BwRG4CWwVa8IUPD3V08J/ZnNOQ3S1c0umh OMx24uVwluZF0hd9NMr2T0BdlrYKyCzx7vO7VHLG/g6vWR/XeW+x90OMndlIMHqLitc/ WZWhK53seoCo7HYdhf1GcwTH/DGKLth+jSi8qMiEHibi4wqmk/u8GoHiuXq50yrWOaqv Wmuw== X-Gm-Message-State: AOAM531kwBJHSGcemeI4J4QWJiZ0hLk38hK6hkaXJKyyekw4WyRO+84w xk+Uw93lgX5DTr4Wqbud940xQYRU3iVjwQ== X-Received: by 2002:a17:90a:cc0d:b0:1e3:1256:faa3 with SMTP id b13-20020a17090acc0d00b001e31256faa3mr50111677pju.107.1654640779043; Tue, 07 Jun 2022 15:26:19 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3cf2:c634:5b19:25f6]) by smtp.gmail.com with ESMTPSA id e19-20020a17090ae4d300b001e2fade86c1sm15112133pju.2.2022.06.07.15.26.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 15:26:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu Subject: [PATCH v4 1/3] target/m68k: Eliminate m68k_semi_is_fseek Date: Tue, 7 Jun 2022 15:26:14 -0700 Message-Id: <20220607222616.717435-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220607222616.717435-1-richard.henderson@linaro.org> References: <20220607222616.717435-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reorg m68k_semi_return_* to gdb_syscall_complete_cb. Use the 32-bit version normally, and the 64-bit version for HOSTED_LSEEK. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- target/m68k/m68k-semi.c | 55 +++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 8c186c0e9f..37b409b0b9 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -95,8 +95,11 @@ static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) unlock_user(p, addr, sizeof(struct gdb_stat)); } -static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err) +static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { + M68kCPU *cpu = M68K_CPU(cs); + CPUM68KState *env = &cpu->env; + target_ulong args = env->dregs[1]; if (put_user_u32(ret, args) || put_user_u32(err, args + 4)) { @@ -110,8 +113,11 @@ static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err) } } -static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err) +static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err) { + M68kCPU *cpu = M68K_CPU(cs); + CPUM68KState *env = &cpu->env; + target_ulong args = env->dregs[1]; if (put_user_u32(ret >> 32, args) || put_user_u32(ret, args + 4) || @@ -122,21 +128,6 @@ static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err) } } -static int m68k_semi_is_fseek; - -static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err) -{ - M68kCPU *cpu = M68K_CPU(cs); - CPUM68KState *env = &cpu->env; - - if (m68k_semi_is_fseek) { - m68k_semi_return_u64(env, ret, err); - m68k_semi_is_fseek = 0; - } else { - m68k_semi_return_u32(env, ret, err); - } -} - /* * Read the input value from the argument block; fail the semihosting * call if the memory read fails. @@ -151,6 +142,7 @@ static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err) void do_m68k_semihosting(CPUM68KState *env, int nr) { + CPUState *cs = env_cpu(env); uint32_t args; target_ulong arg0, arg1, arg2, arg3; void *p; @@ -169,7 +161,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "open,%s,%x,%x", arg0, (int)arg1, + gdb_do_syscall(m68k_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, arg2, arg3); return; } else { @@ -190,7 +182,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) int fd = arg0; if (fd > 2) { if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "close,%x", arg0); + gdb_do_syscall(m68k_semi_u32_cb, "close,%x", arg0); return; } else { result = close(fd); @@ -206,7 +198,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); len = arg2; if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "read,%x,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "read,%x,%x,%x", arg0, arg1, len); return; } else { @@ -226,7 +218,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); len = arg2; if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "write,%x,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "write,%x,%x,%x", arg0, arg1, len); return; } else { @@ -249,12 +241,11 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(3); off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); if (use_gdb_syscalls()) { - m68k_semi_is_fseek = 1; - gdb_do_syscall(m68k_semi_cb, "fseek,%x,%lx,%x", + gdb_do_syscall(m68k_semi_u64_cb, "fseek,%x,%lx,%x", arg0, off, arg3); } else { off = lseek(arg0, off, arg3); - m68k_semi_return_u64(env, off, errno); + m68k_semi_u64_cb(cs, off, errno); } return; } @@ -264,7 +255,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "rename,%s,%s", + gdb_do_syscall(m68k_semi_u32_cb, "rename,%s,%s", arg0, (int)arg1, arg2, (int)arg3); return; } else { @@ -284,7 +275,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "unlink,%s", + gdb_do_syscall(m68k_semi_u32_cb, "unlink,%s", arg0, (int)arg1); return; } else { @@ -303,7 +294,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(1); GET_ARG(2); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "stat,%s,%x", + gdb_do_syscall(m68k_semi_u32_cb, "stat,%s,%x", arg0, (int)arg1, arg2); return; } else { @@ -325,7 +316,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "fstat,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "fstat,%x,%x", arg0, arg1); return; } else { @@ -340,7 +331,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "gettimeofday,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "gettimeofday,%x,%x", arg0, arg1); return; } else { @@ -361,7 +352,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) case HOSTED_ISATTY: GET_ARG(0); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "isatty,%x", arg0); + gdb_do_syscall(m68k_semi_u32_cb, "isatty,%x", arg0); return; } else { result = isatty(arg0); @@ -371,7 +362,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "system,%s", + gdb_do_syscall(m68k_semi_u32_cb, "system,%s", arg0, (int)arg1); return; } else { @@ -429,5 +420,5 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) result = 0; } failed: - m68k_semi_return_u32(env, result, errno); + m68k_semi_u32_cb(cs, result, errno); } From patchwork Tue Jun 7 22:26:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 579447 Delivered-To: patch@linaro.org Received: by 2002:a5d:6706:0:0:0:0:0 with SMTP id o6csp3759308wru; Tue, 7 Jun 2022 16:27:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBa1/4RJ+sHhHZW61E+lrA8Ii4rJtsqetW2MPW8Miny8PiesX/3Yb9Hr34uznGfINudlvk X-Received: by 2002:a05:622a:58e:b0:304:da27:b691 with SMTP id c14-20020a05622a058e00b00304da27b691mr22688823qtb.601.1654644452599; Tue, 07 Jun 2022 16:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654644452; cv=none; d=google.com; s=arc-20160816; b=jzrWxSGmuw+Mz3pV8vYeqNpagyx7RuUL32Fj71wSLzgsjKs+K6eMYdXOYivET4FKDr rsv5LAcKIDgqnEDARckvSBXNQFzJfM3jKKLYGQCusr4MqeOJTmo/rBBNMUB03Td4imKA mQJ5qFkFflcnb+VdrdccDlLF7tTFz9qRMCZlbZzzzsY1WMd6jAGU593xcGv8kOW4ltd0 dltZ5bU2hEDdGCMxHzZnCpKYj8lizxud7um07XHu8LovKMye4CB9C//k51jDk/nTy6k7 BL4oiu3kHol5tSwMmhgPy0C+qXpX5NC4ba0h4jvnknRZFJdaySpnQd81bqFy51cOgutk sJAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bOpw6kxmi87dpdkEkilkb5+DQd7aJjfziEI5ji+nxm4=; b=QfJ6N8juwiRcDEGqWZzd/b7iEvTN1MCyFMgvi8xxB6DnRm+XfFqXSswj4WxLNojTwq m2F7PJeSVKX79a1tT1YGL+WKnfj6rpD7O38G3UabQnjjys2ZzO4g4XSduuH6tsuBDABs 5/Uch26P8qOuPaMuzht70cwj7vOTuDpLZMJxiKa/MClHghAdWDvE6ZsxIqwMyvwQdK1d ZR+EIr8MoSRquIK+sz9MyaIfinBGNfDhql6mSzoTXxHx5gLdAiuiMNVBRfd5XaVnpb9g CyyjHIRwMNKV73lGxlPT59Qd3F0/QkfTkMskNwMEIBaZQu8PxPiUO9vCCbRD5Eapqucx UomQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hyzrz15T; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o17-20020a05622a139100b00304eacb2c87si4811556qtk.769.2022.06.07.16.27.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Jun 2022 16:27:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hyzrz15T; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyibk-0004i9-2R for patch@linaro.org; Tue, 07 Jun 2022 19:27:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyhef-0005in-Nr for qemu-devel@nongnu.org; Tue, 07 Jun 2022 18:26:29 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]:43696) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyheX-0007vO-Ax for qemu-devel@nongnu.org; Tue, 07 Jun 2022 18:26:29 -0400 Received: by mail-pl1-x62a.google.com with SMTP id b5so15995724plx.10 for ; Tue, 07 Jun 2022 15:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bOpw6kxmi87dpdkEkilkb5+DQd7aJjfziEI5ji+nxm4=; b=hyzrz15TYzUF17CeVLOonEZS2zzErQPIL2uYxRGmTETIlRNsAHKxpdgD9chnNAzjQr 9LktInSlaClMX1CmWSeGtk0cooyYVd6m4GoU6p9EQ2x5m/xk2SehCe3zGiWo0yOI6txj zz4VAEExk+GvtQCbbR/UmzLgEoDBF/jhV4tHXrbscLDjaZPc9axPvws4Unp0J9QE4585 NwPjSU9C0OIWHKhpzfXKOgr2DztlHEZvKcMV3rFmmREcIUtHLtQIpG7FehvEw8nTvhr3 ktkMTudLg9CvMtEh35LxOfuFUYCnqX+7GO3XlxfzTH+VQdkBN0w++n1MXUW+cyVCP08r t0Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bOpw6kxmi87dpdkEkilkb5+DQd7aJjfziEI5ji+nxm4=; b=kFSZjcDx9w3DtbS8g9PO5JH2Z2FqqSVeA8rDiFLEUduoTmwe9BRfGA3NfwxctQHRru b7k5bfnd2qp5nghl1zoxyJA2Wi4VVvM7jwJmJ5tj+IV4Au0CkeQQ7YHFKjsGpTti5QxH SkCzeo6mpJVOT2itoiFEqgmRbtrKNfrjYGBJjInNgCzhg495znvRY+q0ibY/IC+PAa/M qPPianFtxwpOjlokhBDJ8YM5svs97MUsTeTNrKgymt4YgMyhvXc2ePri6pYl9Xs/irg0 Gv0ZWcDgM5sTJ8Q+2J1cAaJZp8Bj1lSRqMMAwX7Q1gxkf+K523ReyiBhd5FwIuYDzeN3 7qFw== X-Gm-Message-State: AOAM530vwckwH2NHQYEc4Vfe1WbZn1m7FKEo0mrwOHQkOu+4JzaCNvnB m+j1w+gSaX7qWpR9mCjGAlRqhd7lBJ0cqQ== X-Received: by 2002:a17:902:f64c:b0:156:7ceb:b579 with SMTP id m12-20020a170902f64c00b001567cebb579mr30456157plg.73.1654640779883; Tue, 07 Jun 2022 15:26:19 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3cf2:c634:5b19:25f6]) by smtp.gmail.com with ESMTPSA id e19-20020a17090ae4d300b001e2fade86c1sm15112133pju.2.2022.06.07.15.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 15:26:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu Subject: [PATCH v4 2/3] target/m68k: Make semihosting system only Date: Tue, 7 Jun 2022 15:26:15 -0700 Message-Id: <20220607222616.717435-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220607222616.717435-1-richard.henderson@linaro.org> References: <20220607222616.717435-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" While we had a call to do_m68k_semihosting in linux-user, it wasn't actually reachable. We don't include DISAS_INSN(halt) as an instruction unless system mode. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- linux-user/m68k/cpu_loop.c | 5 ----- target/m68k/m68k-semi.c | 36 ------------------------------------ target/m68k/meson.build | 6 ++++-- 3 files changed, 4 insertions(+), 43 deletions(-) diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c index 3d3033155f..caead1cb74 100644 --- a/linux-user/m68k/cpu_loop.c +++ b/linux-user/m68k/cpu_loop.c @@ -36,11 +36,6 @@ void cpu_loop(CPUM68KState *env) process_queued_cpu_work(cs); switch(trapnr) { - case EXCP_HALT_INSN: - /* Semihosing syscall. */ - env->pc += 4; - do_m68k_semihosting(env, env->dregs[0]); - break; case EXCP_ILLEGAL: case EXCP_LINEA: case EXCP_LINEF: diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 37b409b0b9..d0697ddbd1 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -21,13 +21,8 @@ #include "cpu.h" #include "exec/gdbstub.h" -#if defined(CONFIG_USER_ONLY) -#include "qemu.h" -#define SEMIHOSTING_HEAP_SIZE (128 * 1024 * 1024) -#else #include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" -#endif #include "qemu/log.h" #define HOSTED_EXIT 0 @@ -377,43 +372,12 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) } break; case HOSTED_INIT_SIM: -#if defined(CONFIG_USER_ONLY) - { - CPUState *cs = env_cpu(env); - TaskState *ts = cs->opaque; - /* Allocate the heap using sbrk. */ - if (!ts->heap_limit) { - abi_ulong ret; - uint32_t size; - uint32_t base; - - base = do_brk(0); - size = SEMIHOSTING_HEAP_SIZE; - /* Try a big heap, and reduce the size if that fails. */ - for (;;) { - ret = do_brk(base + size); - if (ret >= (base + size)) { - break; - } - size >>= 1; - } - ts->heap_limit = base + size; - } - /* - * This call may happen before we have writable memory, so return - * values directly in registers. - */ - env->dregs[1] = ts->heap_limit; - env->aregs[7] = ts->stack_base; - } -#else /* * FIXME: This is wrong for boards where RAM does not start at * address zero. */ env->dregs[1] = current_machine->ram_size; env->aregs[7] = current_machine->ram_size; -#endif return; default: cpu_abort(env_cpu(env), "Unsupported semihosting syscall %d\n", nr); diff --git a/target/m68k/meson.build b/target/m68k/meson.build index 05cd9fbd1e..27d2d7ba87 100644 --- a/target/m68k/meson.build +++ b/target/m68k/meson.build @@ -4,14 +4,16 @@ m68k_ss.add(files( 'fpu_helper.c', 'gdbstub.c', 'helper.c', - 'm68k-semi.c', 'op_helper.c', 'softfloat.c', 'translate.c', )) m68k_softmmu_ss = ss.source_set() -m68k_softmmu_ss.add(files('monitor.c')) +m68k_softmmu_ss.add(files( + 'm68k-semi.c', + 'monitor.c' +)) target_arch += {'m68k': m68k_ss} target_softmmu_arch += {'m68k': m68k_softmmu_ss} From patchwork Tue Jun 7 22:26:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 579446 Delivered-To: patch@linaro.org Received: by 2002:a5d:6706:0:0:0:0:0 with SMTP id o6csp3755974wru; Tue, 7 Jun 2022 16:17:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUgxNUDNJIP2bAZ4qJSCyliLAu6COGHnyezN07aBSxcDDADMMH70bZ/bWPaNcqN14529ou X-Received: by 2002:a05:622a:164a:b0:2fb:870e:f931 with SMTP id y10-20020a05622a164a00b002fb870ef931mr25302051qtj.17.1654643879685; Tue, 07 Jun 2022 16:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654643879; cv=none; d=google.com; s=arc-20160816; b=gar/JMcYPOlRbbEIkXn/I3v/nh+CCb0cD7AOoA3COfTgLAI/QTPlLwxVcgszv4n4eO PtPp7Y8EqR41JP68xJcOWrk+78qyhMNV500K0R/AatM5LtbwuK0O9Qb31I55KwF8x4ZR l62Lapk4zLAhh87Bbcwu7U2Zni662ktMwpM6oWbtid5p7Z61a6vUJukZbxPFZZt7/c0x GeJJLRbJckdBxEWs/KgR94O7sUu7DkJB9W9NKv7hvjj+Z5X7HPHiDM4mC04le6+0Dv+Q w8puXXtMngHfNsQKbB0mPbz9sJvpsCbUuy7nTUdXaKSF/CPhmAAC9z9h1IL41qsss/7h 26eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lbUVCZIzmf7Ku+4VUqNMsbqIl/D3k7AtZw52ek+GaWg=; b=Xs/trXOlbEvVMbv/70T8EqM3wfltnGDGZ4NUKDWmZoy6E01dR44tQQQ0i8N6L/yGxp uDD9CFFaX32gbeplFhXzx/qdC2OsZWhg6v5n32aFaHmg3HGazKykA+Ijs+FaQv0jR8wN EKgzDKxDY/7j9+7SnFkj8YUGBvMhqLrIB7AgHEmO/IUuFDiGgTuZOoHiwpFoImLBBega BZyg5vRx2199sthMYVhefgqz2OdvmwhNXpDg4OEwbfaYY5HnKoeaqPrZp4a4cfbx2UMi W9swQnwwcQa76yYLA3EluT9RPKqXYuOp/GqeIPnuGTuP7xtbMD11ovayHT1x/tF0cEFK Ibuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wZCmSXnV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u33-20020a05622a19a100b00304ee8659f8si3607141qtc.111.2022.06.07.16.17.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Jun 2022 16:17:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wZCmSXnV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyiSU-0006Yu-QG for patch@linaro.org; Tue, 07 Jun 2022 19:17:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58542) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyhef-0005jW-VE for qemu-devel@nongnu.org; Tue, 07 Jun 2022 18:26:29 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:33614) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyheY-0007vw-CT for qemu-devel@nongnu.org; Tue, 07 Jun 2022 18:26:29 -0400 Received: by mail-pj1-x1034.google.com with SMTP id hv24-20020a17090ae41800b001e33eebdb5dso14757240pjb.0 for ; Tue, 07 Jun 2022 15:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lbUVCZIzmf7Ku+4VUqNMsbqIl/D3k7AtZw52ek+GaWg=; b=wZCmSXnVq4u0FWkaGhVpAJId0UX8bqcEPUCPpx18VSa2b5qGjsWc7i5cRtDmko/wYH 8wUOMpseXTSvP+GlUsf5sMExuLecf21GcNwbBfF17KTdDMPLBc7FkoUfsdy3njJdxL2B LcinDGYtS9tULTp7e66Iqxk2ceCAm6c8jnb1G99fUUOfiEmDSE4Rvn7/eqssBZy1rSzD tHNf3w3RJz/NQhu9hgI5I3IsqL2QTcXoqcWMJHOdwuvq8ce46mpy8HB0vsjfTaIbjB3N 0qehOz7KHuCf1YvSyd2PHTVJjgkHYD3cVh0TIyjHTvlWMikorKKN1RU0GBVNuYezE3M5 30GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lbUVCZIzmf7Ku+4VUqNMsbqIl/D3k7AtZw52ek+GaWg=; b=OB08Xa5j+C3Zz7NfnuINtDMtaITkyEjG8a6UdVeChH8ZfaIbgpDSHLcIWaAz2f0Sj6 RtqhQSDLFLzPMFhyBk0LMKazuBR8Ezh8ALDy3N59nu9qBVNaPfp2cFZd7o6dpcF0SaPL hTq5IEETjlovr3doBD3HMFhJbAb0jhg4y2Fi7zUN5rGlJywk4HEHEQS+vVyEP2oTPHVy rKmpmZqJXK68rAwgCxD/1penznp+JUsYmLmr0tv3BHZjgV5BfeyaV/E+O94R+OcZxKTd t8d7e5rBvrRpdCgQDn9sPMHl9QXQOlX/R1GWTlvmiReSRn634tL/ztStRwGxoFfQ2SoO cAng== X-Gm-Message-State: AOAM531EnfYtc1EfoiZoK2XMqOrV7hY8k0Lb5sbHtKjSgi5UQ0nJ0z2x 1O+xHpnttZpujDxRpIohP/aw5fU7l4yxZg== X-Received: by 2002:a17:90a:a614:b0:1df:8aec:cc71 with SMTP id c20-20020a17090aa61400b001df8aeccc71mr34027645pjq.82.1654640780991; Tue, 07 Jun 2022 15:26:20 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3cf2:c634:5b19:25f6]) by smtp.gmail.com with ESMTPSA id e19-20020a17090ae4d300b001e2fade86c1sm15112133pju.2.2022.06.07.15.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 15:26:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu Subject: [PATCH v4 3/3] target/m68k: Use semihosting/syscalls.h Date: Tue, 7 Jun 2022 15:26:16 -0700 Message-Id: <20220607222616.717435-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220607222616.717435-1-richard.henderson@linaro.org> References: <20220607222616.717435-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Signed-off-by: Richard Henderson Reviewed-by: Laurent Vivier --- target/m68k/m68k-semi.c | 306 ++++++++++------------------------------ 1 file changed, 76 insertions(+), 230 deletions(-) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index d0697ddbd1..87b1314925 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -21,6 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" +#include "semihosting/syscalls.h" #include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" #include "qemu/log.h" @@ -40,54 +41,33 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -static int translate_openflags(int flags) +static int host_to_gdb_errno(int err) { - int hf; - - if (flags & GDB_O_WRONLY) - hf = O_WRONLY; - else if (flags & GDB_O_RDWR) - hf = O_RDWR; - else - hf = O_RDONLY; - - if (flags & GDB_O_APPEND) hf |= O_APPEND; - if (flags & GDB_O_CREAT) hf |= O_CREAT; - if (flags & GDB_O_TRUNC) hf |= O_TRUNC; - if (flags & GDB_O_EXCL) hf |= O_EXCL; - - return hf; -} - -static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) -{ - struct gdb_stat *p; - - p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); - if (!p) { - /* FIXME - should this return an error code? */ - return; +#define E(X) case E##X: return GDB_E##X + switch (err) { + E(PERM); + E(NOENT); + E(INTR); + E(BADF); + E(ACCES); + E(FAULT); + E(BUSY); + E(EXIST); + E(NODEV); + E(NOTDIR); + E(ISDIR); + E(INVAL); + E(NFILE); + E(MFILE); + E(FBIG); + E(NOSPC); + E(SPIPE); + E(ROFS); + E(NAMETOOLONG); + default: + return GDB_EUNKNOWN; } - p->gdb_st_dev = cpu_to_be32(s->st_dev); - p->gdb_st_ino = cpu_to_be32(s->st_ino); - p->gdb_st_mode = cpu_to_be32(s->st_mode); - p->gdb_st_nlink = cpu_to_be32(s->st_nlink); - p->gdb_st_uid = cpu_to_be32(s->st_uid); - p->gdb_st_gid = cpu_to_be32(s->st_gid); - p->gdb_st_rdev = cpu_to_be32(s->st_rdev); - p->gdb_st_size = cpu_to_be64(s->st_size); -#ifdef _WIN32 - /* Windows stat is missing some fields. */ - p->gdb_st_blksize = 0; - p->gdb_st_blocks = 0; -#else - p->gdb_st_blksize = cpu_to_be64(s->st_blksize); - p->gdb_st_blocks = cpu_to_be64(s->st_blocks); -#endif - p->gdb_st_atime = cpu_to_be32(s->st_atime); - p->gdb_st_mtime = cpu_to_be32(s->st_mtime); - p->gdb_st_ctime = cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct gdb_stat)); +#undef E } static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err) @@ -97,7 +77,7 @@ static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err) target_ulong args = env->dregs[1]; if (put_user_u32(ret, args) || - put_user_u32(err, args + 4)) { + put_user_u32(host_to_gdb_errno(err), args + 4)) { /* * The m68k semihosting ABI does not provide any way to report this * error to the guest, so the best we can do is log it in qemu. @@ -116,7 +96,7 @@ static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err) target_ulong args = env->dregs[1]; if (put_user_u32(ret >> 32, args) || put_user_u32(ret, args + 4) || - put_user_u32(err, args + 8)) { + put_user_u32(host_to_gdb_errno(err), args + 8)) { /* No way to report this via m68k semihosting ABI; just log it */ qemu_log_mask(LOG_GUEST_ERROR, "m68k-semihosting: return value " "discarded because argument block not writable\n"); @@ -129,248 +109,109 @@ static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err) */ #define GET_ARG(n) do { \ if (get_user_ual(arg ## n, args + (n) * 4)) { \ - result = -1; \ - errno = EFAULT; \ goto failed; \ } \ } while (0) +#define GET_ARG64(n) do { \ + if (get_user_ual(arg ## n, args + (n) * 4)) { \ + goto failed64; \ + } \ +} while (0) + + void do_m68k_semihosting(CPUM68KState *env, int nr) { CPUState *cs = env_cpu(env); uint32_t args; target_ulong arg0, arg1, arg2, arg3; - void *p; - void *q; - uint32_t len; - uint32_t result; args = env->dregs[1]; switch (nr) { case HOSTED_EXIT: gdb_exit(env->dregs[0]); exit(env->dregs[0]); + case HOSTED_OPEN: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, - arg2, arg3); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = open(p, translate_openflags(arg2), arg3); - unlock_user(p, arg0, 0); - } - } + semihost_sys_open(cs, m68k_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_CLOSE: - { - /* Ignore attempts to close stdin/out/err. */ - GET_ARG(0); - int fd = arg0; - if (fd > 2) { - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "close,%x", arg0); - return; - } else { - result = close(fd); - } - } else { - result = 0; - } - break; - } + GET_ARG(0); + semihost_sys_close(cs, m68k_semi_u32_cb, arg0); + break; + case HOSTED_READ: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "read,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_WRITE, arg1, len, 0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = read(arg0, p, len); - unlock_user(p, arg1, len); - } - } + semihost_sys_read(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_WRITE: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "write,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_READ, arg1, len, 1); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = write(arg0, p, len); - unlock_user(p, arg0, 0); - } - } + semihost_sys_write(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_LSEEK: - { - uint64_t off; - GET_ARG(0); - GET_ARG(1); - GET_ARG(2); - GET_ARG(3); - off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u64_cb, "fseek,%x,%lx,%x", - arg0, off, arg3); - } else { - off = lseek(arg0, off, arg3); - m68k_semi_u64_cb(cs, off, errno); - } - return; - } + GET_ARG64(0); + GET_ARG64(1); + GET_ARG64(2); + GET_ARG64(3); + semihost_sys_lseek(cs, m68k_semi_u64_cb, arg0, + deposit64(arg2, arg1, 32, 32), arg3); + break; + case HOSTED_RENAME: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "rename,%s,%s", - arg0, (int)arg1, arg2, (int)arg3); - return; - } else { - p = lock_user_string(arg0); - q = lock_user_string(arg2); - if (!p || !q) { - /* FIXME - check error code? */ - result = -1; - } else { - result = rename(p, q); - } - unlock_user(p, arg0, 0); - unlock_user(q, arg2, 0); - } + semihost_sys_rename(cs, m68k_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_UNLINK: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "unlink,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = unlink(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_remove(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_STAT: GET_ARG(0); GET_ARG(1); GET_ARG(2); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "stat,%s,%x", - arg0, (int)arg1, arg2); - return; - } else { - struct stat s; - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = stat(p, &s); - unlock_user(p, arg0, 0); - } - if (result == 0) { - translate_stat(env, arg2, &s); - } - } + semihost_sys_stat(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_FSTAT: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "fstat,%x,%x", - arg0, arg1); - return; - } else { - struct stat s; - result = fstat(arg0, &s); - if (result == 0) { - translate_stat(env, arg1, &s); - } - } + semihost_sys_fstat(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_GETTIMEOFDAY: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "gettimeofday,%x,%x", - arg0, arg1); - return; - } else { - struct gdb_timeval *p; - int64_t rt = g_get_real_time(); - p = lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval), 0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = 0; - p->tv_sec = cpu_to_be32(rt / G_USEC_PER_SEC); - p->tv_usec = cpu_to_be64(rt % G_USEC_PER_SEC); - unlock_user(p, arg0, sizeof(struct gdb_timeval)); - } - } + semihost_sys_gettimeofday(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_ISATTY: GET_ARG(0); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "isatty,%x", arg0); - return; - } else { - result = isatty(arg0); - } + semihost_sys_isatty(cs, m68k_semi_u32_cb, arg0); break; + case HOSTED_SYSTEM: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "system,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = system(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_system(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_INIT_SIM: /* * FIXME: This is wrong for boards where RAM does not start at @@ -379,10 +220,15 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) env->dregs[1] = current_machine->ram_size; env->aregs[7] = current_machine->ram_size; return; + default: cpu_abort(env_cpu(env), "Unsupported semihosting syscall %d\n", nr); - result = 0; + + failed: + m68k_semi_u32_cb(cs, -1, EFAULT); + break; + failed64: + m68k_semi_u64_cb(cs, -1, EFAULT); + break; } -failed: - m68k_semi_u32_cb(cs, result, errno); }