Added preliminary hppa64 support to dietlibc (patch attached)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello from Bulgaria!

Please find attached my patch for adding preliminary 64-bit PA-RISC support to dietlibc_0.34~cvs20160606-18, along with your patch which I applied first. It took me almost a month to do it. While it’s still in pre-alpha stage (and there’s no guarantee that it won’t stay so), it allowed me to build and test the hppa64 port of my assembly language examples, whose I/O is written entirely in C. It works with kernel version up to 4.19. Unfortunately, the later kernels no longer support 64-bit system calls. Even 4.19.66 from the Gentoo installation disc doesn’t. And even the kernels that do support 64-bit system calls don’t support them all. For example, malloc() doesn’t work probably because mmap() doesn’t. As a consequence, buffered ‘stdio' support doesn’t work. Fortunately, unbuffered does. Besides, argc and argv aren’t passed in r25 and r24 to _start() as in the 32-bit kernels. And so on, and so forth. Despite that, the port allows some small C programs to be built. The compiler generates .PROC/.PROCEND directives which cause the linker to build dynamic executables, although static ones are small enough with dietlibc. But there is a blessing in disguise: the small .dynamic section added by the linker can now be used as a preliminary stack in start.S, since beside loading the executable in memory and passing control to it, the kernel doesn’t anything else. No further memory is allocated for it. Even the initial stack pointer value is invalid. So the startup code must take care of all that its 32-bit counterpart doesn’t have to. But it’s not overly complex to compensate this ‘Spartan' kernel behaviour in start.S, which I’ve done, tested, and it works.

Here are some explanations of the patch, file by file and hunk by hunk:

1. dietfieatures.h: Conditionally commented out some features the kernel doesn’t support like TLS and everything else that is not mandatory to minimise startup code size.
2. dirent.h: Fixed a bug where 'make hppa DEBUG=1' stops with an error.
3. endian.h: Defined WORDSIZE for all architectures where __LP64__ is defined, including hppa64.
4. threads.h: Disabled the __thread keyword which the hppa64 compiler doesn’t support.
5. unistd.h: __const__ overrides __pure__ so removed the latter.
6. qsort.c: Added -O2 optimisation pragma because qsort() must be as fast as possible (-O3 increases code size way too much).
7. reallocarray.c: __uint128 was used which isn’t supported by old versions of libgcc before GCC 11, so replaced the whole file with the original OpenBSD implementation.
8. syscall.S: Added 3 more arguments in registers as per PA-RISC 2.0W spec; added a NOP after the CMPB instruction which turned out to be necessary for 64 bits.
9. Makefile: Replaced the non-working ‘u' argument of ‘ar' with ‘D'; disabled the dynamic linker for the really static 64-bit executables and set the entry point; let the preprocessor undefine WANT_TLS.
10. argv_env.c: Added a function that builds the argv and envp arrays which the 64-bit kernel doesn’t do, at least when executing 64-bit executables from 32-bit ones.
11. __longjmp.S: Added a 64-bit implementation of the register saving code (it compiles OK but isn't tested!).
12. Makefile.add: Added the new argv_env.o file.
13. setjmp.S: Added a 64-bit implementation of the register restoring code (compiles OK but isn't tested!).
14. start.S: Added 64-bit support (see the comments in the code itself).
15. strcasecmp.S, strcmp.S, strlen.S, strncasecmp.S, strncmp.S, strncpy.S, strpbrk.S, strstr.S, __testandset.S, unified.S: Added PA-RISC 2.0 .level directive for the 64-bit code.
19. strrchr.S and many others: All BV return instructions replaced with BVE for 64 bits because that’s what the 64-bit compiler generates; I don’t know whether this is really necessary.

I don’t use the diet.c utility so it may not work.
I hope the patch proves useful for others, too.

Best regards from Varna!
Лъчезар
-- 
https://lucho.ddns.net

Attachment: patches.tar.xz
Description: Binary data


[Index of Archives]     [Linux SoC]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux