diff mbox

[02/12,v9] linux-user: tilegx: Add target features support within qemu

Message ID BLU436-SMTP19368AB992B451B18893E28B9090@phx.gbl
State New
Headers show

Commit Message

Chen Gang March 27, 2015, 10:49 a.m. UTC
They are for target features within qemu which independent from outside.

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
 linux-user/tilegx/target_cpu.h     | 35 +++++++++++++++++++++++++++
 linux-user/tilegx/target_signal.h  | 28 ++++++++++++++++++++++
 linux-user/tilegx/target_structs.h | 48 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)
 create mode 100644 linux-user/tilegx/target_cpu.h
 create mode 100644 linux-user/tilegx/target_signal.h
 create mode 100644 linux-user/tilegx/target_structs.h

Comments

Peter Maydell April 9, 2015, 9:31 p.m. UTC | #1
On 27 March 2015 at 10:49, Chen Gang <xili_gchen_5257@hotmail.com> wrote:
> They are for target features within qemu which independent from outside.
>
> Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
> ---
>  linux-user/tilegx/target_cpu.h     | 35 +++++++++++++++++++++++++++
>  linux-user/tilegx/target_signal.h  | 28 ++++++++++++++++++++++
>  linux-user/tilegx/target_structs.h | 48 ++++++++++++++++++++++++++++++++++++++
>  3 files changed, 111 insertions(+)
>  create mode 100644 linux-user/tilegx/target_cpu.h
>  create mode 100644 linux-user/tilegx/target_signal.h
>  create mode 100644 linux-user/tilegx/target_structs.h
>
> diff --git a/linux-user/tilegx/target_cpu.h b/linux-user/tilegx/target_cpu.h
> new file mode 100644
> index 0000000..c96e81d
> --- /dev/null
> +++ b/linux-user/tilegx/target_cpu.h
> @@ -0,0 +1,35 @@
> +/*
> + * TILE-Gx specific CPU ABI and functions for linux-user
> + *
> + * Copyright (c) 2015 Chen Gang
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, see <http://www.gnu.org/licenses/>.
> + */
> +#ifndef TARGET_CPU_H
> +#define TARGET_CPU_H
> +
> +static inline void cpu_clone_regs(CPUTLGState *env, target_ulong newsp)
> +{
> +    if (newsp) {
> +        env->regs[TILEGX_R_SP] = newsp;
> +    }
> +    env->regs[TILEGX_R_RE] = 0;

This is slightly confusing, because the kernel code we're matching here
doesn't call this register RE, it just uses 0:
        childregs->regs[0] = 0;         /* return value is zero */

> +}
> +
> +static inline void cpu_set_tls(CPUTLGState *env, target_ulong newtls)
> +{
> +    env->regs[TILEGX_R_TP] = newtls;
> +}
> +
> +#endif
> diff --git a/linux-user/tilegx/target_signal.h b/linux-user/tilegx/target_signal.h
> new file mode 100644
> index 0000000..fbab216
> --- /dev/null
> +++ b/linux-user/tilegx/target_signal.h
> @@ -0,0 +1,28 @@
> +#ifndef TARGET_SIGNAL_H
> +#define TARGET_SIGNAL_H
> +
> +#include "cpu.h"
> +
> +/* this struct defines a stack used during syscall handling */
> +
> +typedef struct target_sigaltstack {
> +    abi_ulong ss_sp;
> +    abi_ulong ss_size;
> +    abi_long ss_flags;
> +} target_stack_t;

Where does this come from? It doesn't match the kernel's
generic-headers struct layout.

> +
> +/*
> + * sigaltstack controls
> + */
> +#define TARGET_SS_ONSTACK     1
> +#define TARGET_SS_DISABLE     2
> +
> +#define TARGET_MINSIGSTKSZ    2048
> +#define TARGET_SIGSTKSZ       8192
> +
> +static inline abi_ulong get_sp_from_cpustate(CPUTLGState *state)
> +{
> +    return state->regs[TILEGX_R_SP];
> +}
> +
> +#endif /* TARGET_SIGNAL_H */
> diff --git a/linux-user/tilegx/target_structs.h b/linux-user/tilegx/target_structs.h
> new file mode 100644
> index 0000000..13a1505
> --- /dev/null
> +++ b/linux-user/tilegx/target_structs.h
> @@ -0,0 +1,48 @@
> +/*
> + * TILE-Gx specific structures for linux-user
> + *
> + * Copyright (c) 2015 Chen Gang
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, see <http://www.gnu.org/licenses/>.
> + */
> +#ifndef TARGET_STRUCTS_H
> +#define TARGET_STRUCTS_H
> +
> +struct target_ipc_perm {
> +    abi_int __key;                      /* Key.  */
> +    abi_uint uid;                       /* Owner's user ID.  */
> +    abi_uint gid;                       /* Owner's group ID.  */
> +    abi_uint cuid;                      /* Creator's user ID.  */
> +    abi_uint cgid;                      /* Creator's group ID.  */
> +    abi_uint mode;                    /* Read/write permission.  */
> +    abi_ushort __seq;                   /* Sequence number.  */
> +    abi_ushort __pad2;
> +    abi_ulong __unused1;
> +    abi_ulong __unused2;
> +};

Again, doesn't seem to match kernel?

> +
> +struct target_shmid_ds {
> +    struct target_ipc_perm shm_perm;    /* operation permission struct */
> +    abi_long shm_segsz;                 /* size of segment in bytes */
> +    abi_ulong shm_atime;                /* time of last shmat() */
> +    abi_ulong shm_dtime;                /* time of last shmdt() */
> +    abi_ulong shm_ctime;                /* time of last change by shmctl() */
> +    abi_int shm_cpid;                   /* pid of creator */
> +    abi_int shm_lpid;                   /* pid of last shmop */
> +    abi_ulong shm_nattch;               /* number of current attaches */
> +    abi_ulong __unused4;
> +    abi_ulong __unused5;
> +};
> +
> +#endif

thanks
-- PMM
Chen Gang April 10, 2015, 8:41 p.m. UTC | #2
On 4/10/15 05:31, Peter Maydell wrote:
> On 27 March 2015 at 10:49, Chen Gang <xili_gchen_5257@hotmail.com> wrote:
[...]
>> +static inline void cpu_clone_regs(CPUTLGState *env, target_ulong newsp)
>> +{
>> +    if (newsp) {
>> +        env->regs[TILEGX_R_SP] = newsp;
>> +    }
>> +    env->regs[TILEGX_R_RE] = 0;
> 
> This is slightly confusing, because the kernel code we're matching here
> doesn't call this register RE, it just uses 0:
>         childregs->regs[0] = 0;         /* return value is zero */
> 

TILEGX_R_RE is just 0, I define a macro instead the hardcode number in
cpu.h with the comment for it.

[...]
>> +
>> +/* this struct defines a stack used during syscall handling */
>> +
>> +typedef struct target_sigaltstack {
>> +    abi_ulong ss_sp;
>> +    abi_ulong ss_size;
>> +    abi_long ss_flags;
>> +} target_stack_t;
> 
> Where does this come from? It doesn't match the kernel's
> generic-headers struct layout.
> 

Oh, sorry, originally, I guess, I only copied it from microblaze, did
not check kernel.

I shall use generic-headers which tilegx will use (the result will like
alpha has done):

typedef struct target_sigaltstack {
    abi_ulong ss_sp;
    int32_t ss_flags;
    int32_t dummy;
    abi_ulong ss_size;
} target_stack_t;


[...]
>> +
>> +struct target_ipc_perm {
>> +    abi_int __key;                      /* Key.  */
>> +    abi_uint uid;                       /* Owner's user ID.  */
>> +    abi_uint gid;                       /* Owner's group ID.  */
>> +    abi_uint cuid;                      /* Creator's user ID.  */
>> +    abi_uint cgid;                      /* Creator's group ID.  */
>> +    abi_uint mode;                    /* Read/write permission.  */
>> +    abi_ushort __seq;                   /* Sequence number.  */
>> +    abi_ushort __pad2;
>> +    abi_ulong __unused1;
>> +    abi_ulong __unused2;
>> +};
> 
> Again, doesn't seem to match kernel?
> 

For me, it matches kernel. mode is abi_uint (__kernel_mode_t is 32-bit).


Thanks.
Peter Maydell April 10, 2015, 9:51 p.m. UTC | #3
On 10 April 2015 at 21:41, Chen Gang <xili_gchen_5257@hotmail.com> wrote:
> On 4/10/15 05:31, Peter Maydell wrote:
>> On 27 March 2015 at 10:49, Chen Gang <xili_gchen_5257@hotmail.com> wrote:
>>> +typedef struct target_sigaltstack {
>>> +    abi_ulong ss_sp;
>>> +    abi_ulong ss_size;
>>> +    abi_long ss_flags;
>>> +} target_stack_t;
>>
>> Where does this come from? It doesn't match the kernel's
>> generic-headers struct layout.
>>
>
> Oh, sorry, originally, I guess, I only copied it from microblaze, did
> not check kernel.

These structures are all user-guest-facing ABI, so they must
match the kernel's structures for your target architecture.

> I shall use generic-headers which tilegx will use (the result will like
> alpha has done):
>
> typedef struct target_sigaltstack {
>     abi_ulong ss_sp;
>     int32_t ss_flags;
>     int32_t dummy;
>     abi_ulong ss_size;
> } target_stack_t;

This doesn't match the kernel either.

http://lxr.free-electrons.com/source/include/uapi/asm-generic/signal.h#L111

You have a pointer, an int and a size_t, so you want
    abi_ulong ss_sp;
    abi_int ss_flags;
    abi_ulong ss_size;

like aarch64.

>
> [...]
>>> +
>>> +struct target_ipc_perm {
>>> +    abi_int __key;                      /* Key.  */
>>> +    abi_uint uid;                       /* Owner's user ID.  */
>>> +    abi_uint gid;                       /* Owner's group ID.  */
>>> +    abi_uint cuid;                      /* Creator's user ID.  */
>>> +    abi_uint cgid;                      /* Creator's group ID.  */
>>> +    abi_uint mode;                    /* Read/write permission.  */
>>> +    abi_ushort __seq;                   /* Sequence number.  */
>>> +    abi_ushort __pad2;
>>> +    abi_ulong __unused1;
>>> +    abi_ulong __unused2;
>>> +};
>>
>> Again, doesn't seem to match kernel?
>>
>
> For me, it matches kernel. mode is abi_uint (__kernel_mode_t is 32-bit).

I'm looking at
http://lxr.free-electrons.com/source/include/uapi/linux/ipc.h#L9
which doesn't have that padding and unused fields at the end.
However the ipc structs are pretty confusing so maybe that's
the wrong one -- which one are you looking at?

-- PMM
Andreas Färber April 10, 2015, 9:59 p.m. UTC | #4
Am 10.04.2015 um 23:51 schrieb Peter Maydell:
> On 10 April 2015 at 21:41, Chen Gang <xili_gchen_5257@hotmail.com> wrote:
>> On 4/10/15 05:31, Peter Maydell wrote:
>>> On 27 March 2015 at 10:49, Chen Gang <xili_gchen_5257@hotmail.com> wrote:
>>>> +typedef struct target_sigaltstack {
>>>> +    abi_ulong ss_sp;
>>>> +    abi_ulong ss_size;
>>>> +    abi_long ss_flags;
>>>> +} target_stack_t;
>>>
>>> Where does this come from? It doesn't match the kernel's
>>> generic-headers struct layout.
>>>
>>
>> Oh, sorry, originally, I guess, I only copied it from microblaze, did
>> not check kernel.
> 
> These structures are all user-guest-facing ABI, so they must
> match the kernel's structures for your target architecture.
> 
>> I shall use generic-headers which tilegx will use (the result will like
>> alpha has done):
>>
>> typedef struct target_sigaltstack {
>>     abi_ulong ss_sp;
>>     int32_t ss_flags;
>>     int32_t dummy;
>>     abi_ulong ss_size;
>> } target_stack_t;
> 
> This doesn't match the kernel either.
> 
> http://lxr.free-electrons.com/source/include/uapi/asm-generic/signal.h#L111
> 
> You have a pointer, an int and a size_t, so you want
>     abi_ulong ss_sp;
>     abi_int ss_flags;
>     abi_ulong ss_size;
> 
> like aarch64.

I know linux-user is a mess. But that does not sound appealing. If this
is from a generic header, can't we put that in a shared header too and
#include it from aarch64 and tilegx without duplicating it?

Regards,
Andreas
Peter Maydell April 10, 2015, 10:21 p.m. UTC | #5
On 10 April 2015 at 22:59, Andreas Färber <afaerber@suse.de> wrote:
> I know linux-user is a mess. But that does not sound appealing. If this
> is from a generic header, can't we put that in a shared header too and
> #include it from aarch64 and tilegx without duplicating it?

I certainly wouldn't object if somebody wanted to try to
factor out some of our mess of ifdefs to produce something
more like "structs defined in linux-user/$arch/$foo.h, which
might just include linux-user/generic/$foo.h". I'm just not
insisting on it as a blocker for a new target (would be
a bit hypocritical given we didn't do it for aarch64).

This is just one of the many cleanups I'd do in linux-user
if I had 3 to 6 months to spend on refactoring and fixing
it :-)

-- PMM
Chen Gang April 11, 2015, 3:37 a.m. UTC | #6
On 4/11/15 05:51, Peter Maydell wrote:
> On 10 April 2015 at 21:41, Chen Gang <xili_gchen_5257@hotmail.com> wrote:
>> On 4/10/15 05:31, Peter Maydell wrote:
>>> On 27 March 2015 at 10:49, Chen Gang <xili_gchen_5257@hotmail.com> wrote:
>>>> +typedef struct target_sigaltstack {
>>>> +    abi_ulong ss_sp;
>>>> +    abi_ulong ss_size;
>>>> +    abi_long ss_flags;
>>>> +} target_stack_t;
>>>
>>> Where does this come from? It doesn't match the kernel's
>>> generic-headers struct layout.
>>>
>>
>> Oh, sorry, originally, I guess, I only copied it from microblaze, did
>> not check kernel.
> 
> These structures are all user-guest-facing ABI, so they must
> match the kernel's structures for your target architecture.
> 
>> I shall use generic-headers which tilegx will use (the result will like
>> alpha has done):
>>
>> typedef struct target_sigaltstack {
>>     abi_ulong ss_sp;
>>     int32_t ss_flags;
>>     int32_t dummy;
>>     abi_ulong ss_size;
>> } target_stack_t;
> 
> This doesn't match the kernel either.
> 
> http://lxr.free-electrons.com/source/include/uapi/asm-generic/signal.h#L111
> 
> You have a pointer, an int and a size_t, so you want
>     abi_ulong ss_sp;
>     abi_int ss_flags;
>     abi_ulong ss_size;
> 
> like aarch64.
>

For me, for tilegx which is always 64-bit, add 'dummy' is more clearer
(but need to use abi_int instead of original int32_t).

And does it pragma packed ()? As far as I know, it doesn't.
 
>>
>> [...]
>>>> +
>>>> +struct target_ipc_perm {
>>>> +    abi_int __key;                      /* Key.  */
>>>> +    abi_uint uid;                       /* Owner's user ID.  */
>>>> +    abi_uint gid;                       /* Owner's group ID.  */
>>>> +    abi_uint cuid;                      /* Creator's user ID.  */
>>>> +    abi_uint cgid;                      /* Creator's group ID.  */
>>>> +    abi_uint mode;                    /* Read/write permission.  */
>>>> +    abi_ushort __seq;                   /* Sequence number.  */
>>>> +    abi_ushort __pad2;
>>>> +    abi_ulong __unused1;
>>>> +    abi_ulong __unused2;
>>>> +};
>>>
>>> Again, doesn't seem to match kernel?
>>>
>>
>> For me, it matches kernel. mode is abi_uint (__kernel_mode_t is 32-bit).
> 
> I'm looking at
> http://lxr.free-electrons.com/source/include/uapi/linux/ipc.h#L9
> which doesn't have that padding and unused fields at the end.
> However the ipc structs are pretty confusing so maybe that's
> the wrong one -- which one are you looking at?
> 

I check the linux-next tree next-20150401 in include/uapi/linux/ipc.h,
the __kernel_mode_t is unsigned int for tile (and also most of 64-bit
targets in qemu, mode is 32-bit), please check again.

it really has no "__pad2" and "__unused?", but after check all the other
targets within qemu, they all have "__pad2" and "__unused?".  May qemu
itself need them? I am not quite sure, but for me, appending them is OK.


Thanks.
diff mbox

Patch

diff --git a/linux-user/tilegx/target_cpu.h b/linux-user/tilegx/target_cpu.h
new file mode 100644
index 0000000..c96e81d
--- /dev/null
+++ b/linux-user/tilegx/target_cpu.h
@@ -0,0 +1,35 @@ 
+/*
+ * TILE-Gx specific CPU ABI and functions for linux-user
+ *
+ * Copyright (c) 2015 Chen Gang
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef TARGET_CPU_H
+#define TARGET_CPU_H
+
+static inline void cpu_clone_regs(CPUTLGState *env, target_ulong newsp)
+{
+    if (newsp) {
+        env->regs[TILEGX_R_SP] = newsp;
+    }
+    env->regs[TILEGX_R_RE] = 0;
+}
+
+static inline void cpu_set_tls(CPUTLGState *env, target_ulong newtls)
+{
+    env->regs[TILEGX_R_TP] = newtls;
+}
+
+#endif
diff --git a/linux-user/tilegx/target_signal.h b/linux-user/tilegx/target_signal.h
new file mode 100644
index 0000000..fbab216
--- /dev/null
+++ b/linux-user/tilegx/target_signal.h
@@ -0,0 +1,28 @@ 
+#ifndef TARGET_SIGNAL_H
+#define TARGET_SIGNAL_H
+
+#include "cpu.h"
+
+/* this struct defines a stack used during syscall handling */
+
+typedef struct target_sigaltstack {
+    abi_ulong ss_sp;
+    abi_ulong ss_size;
+    abi_long ss_flags;
+} target_stack_t;
+
+/*
+ * sigaltstack controls
+ */
+#define TARGET_SS_ONSTACK     1
+#define TARGET_SS_DISABLE     2
+
+#define TARGET_MINSIGSTKSZ    2048
+#define TARGET_SIGSTKSZ       8192
+
+static inline abi_ulong get_sp_from_cpustate(CPUTLGState *state)
+{
+    return state->regs[TILEGX_R_SP];
+}
+
+#endif /* TARGET_SIGNAL_H */
diff --git a/linux-user/tilegx/target_structs.h b/linux-user/tilegx/target_structs.h
new file mode 100644
index 0000000..13a1505
--- /dev/null
+++ b/linux-user/tilegx/target_structs.h
@@ -0,0 +1,48 @@ 
+/*
+ * TILE-Gx specific structures for linux-user
+ *
+ * Copyright (c) 2015 Chen Gang
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef TARGET_STRUCTS_H
+#define TARGET_STRUCTS_H
+
+struct target_ipc_perm {
+    abi_int __key;                      /* Key.  */
+    abi_uint uid;                       /* Owner's user ID.  */
+    abi_uint gid;                       /* Owner's group ID.  */
+    abi_uint cuid;                      /* Creator's user ID.  */
+    abi_uint cgid;                      /* Creator's group ID.  */
+    abi_uint mode;                    /* Read/write permission.  */
+    abi_ushort __seq;                   /* Sequence number.  */
+    abi_ushort __pad2;
+    abi_ulong __unused1;
+    abi_ulong __unused2;
+};
+
+struct target_shmid_ds {
+    struct target_ipc_perm shm_perm;    /* operation permission struct */
+    abi_long shm_segsz;                 /* size of segment in bytes */
+    abi_ulong shm_atime;                /* time of last shmat() */
+    abi_ulong shm_dtime;                /* time of last shmdt() */
+    abi_ulong shm_ctime;                /* time of last change by shmctl() */
+    abi_int shm_cpid;                   /* pid of creator */
+    abi_int shm_lpid;                   /* pid of last shmop */
+    abi_ulong shm_nattch;               /* number of current attaches */
+    abi_ulong __unused4;
+    abi_ulong __unused5;
+};
+
+#endif