Alperen Erkan <[email protected]> writes:

> Hello,
>
> Thanks for working on the LoongArch64 port.
>
> Could we defer mach_loongarch64.srv until the first machine-specific
> RPC is added? It includes <mach/machine/mach_loongarch64.defs>, which
> this patch does not provide. The new Makefrag.am only lists the .srv
> file in EXTRA_DIST, so the host and header changes can stand on their
> own.
Hello Alperen,
Yes, thats right.
>
> One small correction to the commit message: the top-level Makefrag.am
> and configure.ac are existing files. Their entries could read:
>
> * Makefrag.am: Include loongarch64/Makefrag.am.
> * configure.ac: Accept loongarch64 hosts and include
>   loongarch64/configfrag.ac.
>
OK i've edited that. :)
> I've only reviewed the diff. Did you try configuring for loongarch64
> and installing the Mach headers into a staging directory?
>
> Best regards,
> Alperen
>
Yes I've tested the 'configure --host=loongarch64-gnu' and 'make
install-data'

>From f87db72b482670884d91595ee6c0354582244829 Mon Sep 17 00:00:00 2001
From: Donjuanplatinum <[email protected]>
Date: Tue, 1 Dec 2026 14:22:51 +0800
Subject: [PATCH] loongarch64: Add basic files

Add "loongarch64" host support to the build system.

With this, it should be possible to run 'configure --host=loongarch64-gnu'
and 'make install-data' successfully.

* Makefrag.am: Include loongarch64/Makefrag.am.
* configure.ac: Accpet loongarch64 hosts and include
loongarch64/configfrag.ac.
* loongarch64/Makefrag.am: New file.
* loongarch64/configfrag.ac: New file.
* loongarch64/include/mach/loongarch64/boolean.h: New file.
* loongarch64/include/mach/loongarch64/kern_return.h: New file.
* loongarch64/include/mach/loongarch64/machine_types.defs: New file.
* loongarch64/include/mach/loongarch64/vm_types.h: New file.
---
 Makefrag.am                                   |  3 +
 configure.ac                                  |  4 +
 loongarch64/Makefrag.am                       | 39 ++++++++
 loongarch64/configfrag.ac                     | 34 +++++++
 .../include/mach/loongarch64/boolean.h        | 23 +++++
 .../include/mach/loongarch64/kern_return.h    | 24 +++++
 .../mach/loongarch64/machine_types.defs       | 62 ++++++++++++
 .../include/mach/loongarch64/vm_types.h       | 96 +++++++++++++++++++
 8 files changed, 285 insertions(+)
 create mode 100644 loongarch64/Makefrag.am
 create mode 100644 loongarch64/configfrag.ac
 create mode 100644 loongarch64/include/mach/loongarch64/boolean.h
 create mode 100644 loongarch64/include/mach/loongarch64/kern_return.h
 create mode 100644 loongarch64/include/mach/loongarch64/machine_types.defs
 create mode 100644 loongarch64/include/mach/loongarch64/vm_types.h

diff --git a/Makefrag.am b/Makefrag.am
index 8427655b..dd07eaff 100644
--- a/Makefrag.am
+++ b/Makefrag.am
@@ -613,3 +613,6 @@ include x86_64/Makefrag.am
 
 # aarch64.
 include aarch64/Makefrag.am
+
+# loongarch
+include loongarch64/Makefrag.am
diff --git a/configure.ac b/configure.ac
index c3d5ffaa..a5708825 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,8 @@ case $host_platform:$host_cpu in
     :;;
   *:aarch64)
     ;;
+  *:loongarch64)
+    ;;
   *)]
     AC_MSG_ERROR([unsupported combination of cpu type `$host_cpu' and platform
       `$host_platform'.])[;;
@@ -180,6 +182,8 @@ m4_include([x86_64/configfrag.ac])
 # aarch64
 m4_include([aarch64/configfrag.ac])
 
+# loongarch
+m4_include([loongarch64/configfrag.ac])
 # General options.
 m4_include([configfrag.ac])
 
diff --git a/loongarch64/Makefrag.am b/loongarch64/Makefrag.am
new file mode 100644
index 00000000..a7018480
--- /dev/null
+++ b/loongarch64/Makefrag.am
@@ -0,0 +1,39 @@
+# Makefile fragment for loongarch64.
+
+# Copyright (C) 2026 Free Software Foundation, Inc.
+
+# Author: DonjuanPlatinum <[email protected]>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program 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 General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Building a distribution.
+EXTRA_DIST += \
+	loongarch64/loongarch64/mach_loongarch64.srv \
+	loongarch64/include/mach/loongarch64
+
+if HOST_loongarch64
+
+# Installation.
+
+include_mach_loongarch64dir = $(includedir)/mach/loongarch64
+include_mach_loongarch64_HEADERS = \
+	loongarch64/include/mach/loongarch64/asm.h \
+	loongarch64/include/mach/loongarch64/boolean.h \
+	loongarch64/include/mach/loongarch64/kern_return.h \
+	loongarch64/include/mach/loongarch64/machine_types.defs \
+	loongarch64/include/mach/loongarch64/syscall_sw.h \
+	loongarch64/include/mach/loongarch64/vm_types.h
+
+endif # HOST_loongarch64
diff --git a/loongarch64/configfrag.ac b/loongarch64/configfrag.ac
new file mode 100644
index 00000000..dd9fb88c
--- /dev/null
+++ b/loongarch64/configfrag.ac
@@ -0,0 +1,34 @@
+dnl Configure fragment for loongarch64.
+
+dnl Copyright (C) 2026 Free Software Foundation, Inc.
+
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+dnl GNU General Public License for more details.
+
+dnl You should have received a copy of the GNU General Public License along
+dnl with this program; if not, write to the Free Software Foundation, Inc.,
+dnl 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+[case $host_cpu in
+  loongarch64)]
+    AM_CONDITIONAL([HOST_loongarch64], [true])
+
+    [
+    # Does the architecture provide machine-specific interfaces?
+    # mach_machine_routines=1
+    ;;
+  *)]
+    AM_CONDITIONAL([HOST_loongarch64], [false])
+    [;;
+esac]
+
+dnl Local Variables:
+dnl mode: autoconf
+dnl End:
diff --git a/loongarch64/include/mach/loongarch64/boolean.h b/loongarch64/include/mach/loongarch64/boolean.h
new file mode 100644
index 00000000..becd2cf4
--- /dev/null
+++ b/loongarch64/include/mach/loongarch64/boolean.h
@@ -0,0 +1,23 @@
+/* Boolean data type for loongarch64.
+
+Copyright (C) 2026 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program 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 General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.  */
+
+#ifndef _MACH_LOONGARCH64_BOOLEAN_H_
+#define _MACH_LOONGARCH64_BOOLEAN_H_
+typedef int boolean_t;
+#endif /* _MACH_LOONGARCH64_BOOLEAN_H_ */
+
diff --git a/loongarch64/include/mach/loongarch64/kern_return.h b/loongarch64/include/mach/loongarch64/kern_return.h
new file mode 100644
index 00000000..5f5a18a4
--- /dev/null
+++ b/loongarch64/include/mach/loongarch64/kern_return.h
@@ -0,0 +1,24 @@
+/* Kernel return codes for loongarch64.
+
+Copyright (C) 2026 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program 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 General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.  */
+
+#ifndef _MACH_LOONGARCH64_KERN_RETURN_H_
+#define _MACH_LOONGARCH64_KERN_RETURN_H_ 1
+# ifndef __ASSEMBLER__
+typedef int kern_return_t;
+# endif  /* __ASSEMBLER__ */
+#endif  /* _MACH_LOONGARCH64_KERN_RETURN_H_ */
diff --git a/loongarch64/include/mach/loongarch64/machine_types.defs b/loongarch64/include/mach/loongarch64/machine_types.defs
new file mode 100644
index 00000000..2f2debad
--- /dev/null
+++ b/loongarch64/include/mach/loongarch64/machine_types.defs
@@ -0,0 +1,62 @@
+/* Copyright (C) 2026 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program 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 General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.  */
+
+#ifndef _MACHINE_MACHINE_TYPES_DEFS_
+#define _MACHINE_MACHINE_TYPES_DEFS_ 1
+
+/* A natural_t is the type for the native unsigned integer type,
+   usually 32 bits. It is suitable for most counters with a small
+   chance of overflow.  While historically natural_t was meant to be
+   the same as a pointer, that is not the case here.  */
+type natural_t = uint32_t;
+
+/* An integer_t is the signed counterpart of the natural_t type. Both
+   types are only supposed to be used to define other types in a
+   machine-independent way.  */
+type integer_t = int32_t;
+
+type rpc_long_natural_t = uint64_t;
+type rpc_long_integer_t = int64_t;
+
+/* A long_natural_t is a possibly larger unsigned integer type than natural_t.
+   Should be used instead of natural_t when we want the data to be less subject
+   to overflows.  */
+type long_natural_t = rpc_long_natural_t
+
+# if defined(KERNEL_SERVER)
+    intran: long_natural_t convert_long_natural_from_user(rpc_long_natural_t)
+    outtran: rpc_long_natural_t convert_long_natural_to_user(long_natural_t)
+# elif defined(KERNEL_USER)
+    ctype: rpc_long_natural_t
+# endif
+    ;
+
+/* Larger version of integer_t. Only used when we want to hold
+   possibly larger values than what is possible with integer_t.  */
+type long_integer_t = rpc_long_integer_t
+# if defined(KERNEL_SERVER)
+    intran: long_integer_t convert_long_integer_from_user(rpc_long_integer_t)
+    outtran: rpc_long_integer_t convert_long_integer_to_user(long_integer_t)
+# elif defined(KERNEL_USER)
+    ctype: rpc_long_integer_t
+# endif
+    ;
+
+/* Physical address size.  */
+type rpc_phys_addr_t = uint64_t;
+type rpc_phys_addr_array_t = array[] of rpc_phys_addr_t;
+
+#endif	/* _MACHINE_MACHINE_TYPES_DEFS_ */
diff --git a/loongarch64/include/mach/loongarch64/vm_types.h b/loongarch64/include/mach/loongarch64/vm_types.h
new file mode 100644
index 00000000..85011388
--- /dev/null
+++ b/loongarch64/include/mach/loongarch64/vm_types.h
@@ -0,0 +1,96 @@
+/* Header file for VM data types in loongarch64.
+
+Copyright (C) 2026 Free Software Foundation, Inc.
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program 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 General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.  */
+
+#ifndef _MACHINE_VM_TYPES_H_
+#define _MACHINE_VM_TYPES_H_ 1
+
+# ifdef __ASSEMBLER__
+# else /* __ASSEMBLER__ */
+
+#include <stdint.h>
+
+# ifdef MACH_KERNEL
+#include <kern/assert.h>
+# endif /* MACH_KERNEL */
+
+/* A natural_t is the type for the native unsigned integer type,
+   usually 32 bits. It is suitable for most counters with a small
+   chance of overflow.  While historically natural_t was meant to be
+   the same as a pointer, that is not the case here.  */
+typedef unsigned int natural_t;
+
+/* An integer_t is the signed counterpart of the natural_t type. Both
+   types are only supposed to be used to define other types in a
+   machine-independent way.  */
+typedef int integer_t;
+
+/* A long_natural_t is a possibly larger unsigned integer type than
+   natural_t.  Should be used instead of natural_t when we want the
+   data to be less subject to overflows.  */
+typedef unsigned long long_natural_t;
+
+/* Larger version of integer_t. Only used when we want to hold possibly larger
+   values than what is possible with integer_t.  */
+typedef long long_integer_t;
+
+/* A vm_offset_t is a type-neutral pointer,
+   e.g. an offset into a virtual memory space.  */
+typedef uintptr_t vm_offset_t;
+typedef vm_offset_t* vm_offset_array_t;
+
+/* A type for physical addresses.  */
+typedef unsigned long phys_addr_t;
+typedef unsigned long rpc_phys_addr_t;
+typedef rpc_phys_addr_t* rpc_phys_addr_array_t;
+
+/* A vm_size_t is the proper type for e.g.
+   expressing the difference between two
+   vm_offset_t entities.  */
+typedef uintptr_t vm_size_t;
+typedef vm_size_t* vm_size_array_t;
+
+/* rpc_types are for user/kernel interfaces. On kernel side they may
+   differ from the native types, while on user space they shall be the
+   same.  These three types are always of the same size, so we can reuse
+   the conversion functions.  */
+typedef uintptr_t rpc_uintptr_t;
+typedef vm_offset_t rpc_vm_address_t;
+typedef vm_offset_t rpc_vm_offset_t;
+typedef vm_size_t rpc_vm_size_t;
+
+#define convert_vm_to_user null_conversion
+#define convert_vm_from_user null_conversion
+
+typedef long_natural_t rpc_long_natural_t;
+typedef long_integer_t rpc_long_integer_t;
+
+#define convert_long_integer_to_user null_conversion
+#define convert_long_integer_from_user null_conversion
+
+#define convert_long_natural_to_user convert_vm_to_user
+#define convert_long_natural_from_user convert_vm_from_user
+
+typedef rpc_vm_size_t* rpc_vm_size_array_t;
+typedef rpc_vm_offset_t* rpc_vm_offset_array_t;
+
+# endif /* __ASSEMBLER__ */
+
+/* If composing messages by hand (please dont).  */
+#define MACH_MSG_TYPE_INTEGER_T MACH_MSG_TYPE_INTEGER_32
+
+#endif /* __MACHINE_VM_TYPES_H */
-- 
2.56.0

-- 
Donjuanplatinum, Yifei Yao <[email protected]>
GPG: 1C9E EEE5 4C8E D5A8 3039  1C87 A9F6 8632 D259 40E6
满堂兮美人 忽独与余兮目成

Reply via email to