├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .gitmodules ├── LICENSE.md ├── Makefile ├── README.md ├── apple-include ├── Availability.h ├── AvailabilityInternal.h ├── AvailabilityMacros.h ├── AvailabilityVersions.h ├── architecture │ └── byte_order.h ├── arm │ ├── _types.h │ └── arch.h ├── i386 │ ├── _types.h │ └── eflags.h ├── libkern │ ├── OSByteOrder.h │ ├── _OSByteOrder.h │ ├── arm │ │ └── OSByteOrder.h │ └── machine │ │ └── OSByteOrder.h ├── mach-o │ ├── loader.h │ ├── nlist.h │ └── reloc.h ├── mach │ ├── arm │ │ ├── _structs.h │ │ ├── boolean.h │ │ ├── kern_return.h │ │ ├── thread_state.h │ │ ├── thread_status.h │ │ └── vm_types.h │ ├── boolean.h │ ├── i386 │ │ ├── _structs.h │ │ ├── boolean.h │ │ ├── fp_reg.h │ │ ├── kern_return.h │ │ ├── thread_state.h │ │ ├── thread_status.h │ │ └── vm_types.h │ ├── kern_return.h │ ├── machine.h │ ├── machine │ │ ├── _structs.h │ │ ├── boolean.h │ │ ├── kern_return.h │ │ ├── thread_state.h │ │ ├── thread_status.h │ │ └── vm_types.h │ ├── message.h │ ├── port.h │ ├── vm_prot.h │ └── vm_types.h ├── machine │ └── _types.h └── sys │ ├── _pthread │ └── _pthread_types.h │ ├── _types.h │ ├── _types │ ├── _mach_port_t.h │ └── _os_inline.h │ └── appleapiopts.h ├── checkra1n ├── kpf-test │ ├── .gitignore │ ├── Makefile │ ├── ent.plist │ └── main.c └── kpf │ ├── main.c │ ├── not_strip.txt │ └── shellcode.S ├── example ├── include │ └── pongo.h └── testmodule │ ├── Makefile │ └── main.c ├── include ├── archive.h ├── archive_entry.h ├── font8x8_basic.h ├── iokit.h ├── kerninfo.h ├── key.h ├── loader_xpc_service.h ├── lzma │ ├── lzmadec.h │ └── types.h ├── mac.h └── xpc.h ├── scripts ├── .gitignore ├── Makefile ├── arm64-apple-ios12.0.0-clang ├── boot-checkra1n.py ├── fetch_stdout.py ├── issue_cmd.py ├── load_linux.py ├── module_load.py ├── module_load_boot.py ├── pongoterm.c └── upload_data.py ├── src ├── boot │ ├── clearhook.S │ ├── demote_patch.S │ ├── entry.S │ ├── jump_to_image.S │ ├── libc_workarounds.h │ ├── mac.h │ ├── main.c │ ├── patches.S │ └── stage3.c ├── drivers │ ├── aes │ │ ├── aes.c │ │ ├── aes.h │ │ ├── aes_a7.c │ │ ├── aes_a9.c │ │ └── aes_private.h │ ├── framebuffer │ │ ├── fb.c │ │ └── fb.h │ ├── gpio │ │ ├── gpio.c │ │ └── gpio.h │ ├── hal │ │ ├── hal.c │ │ └── hal.h │ ├── mipi │ │ ├── mipi.c │ │ └── mipi.h │ ├── plat │ │ ├── s5l8960.c │ │ ├── s8000.c │ │ ├── s8001.c │ │ ├── s8003.c │ │ ├── t7000.c │ │ ├── t7001.c │ │ ├── t8010.c │ │ ├── t8011.c │ │ ├── t8012.c │ │ └── t8015.c │ ├── recfg │ │ ├── recfg.c │ │ ├── recfg.h │ │ ├── recfg_soc.c │ │ ├── recfg_soc.h │ │ └── recfg_soc_private.h │ ├── sep │ │ ├── sep.c │ │ ├── sep.h │ │ └── sep_racer.S │ ├── timer │ │ ├── timer.c │ │ └── timer.h │ ├── tz │ │ ├── tz.c │ │ └── tz.h │ ├── uart │ │ ├── uart.c │ │ └── uart.h │ ├── usb │ │ ├── synopsys_otg.c │ │ ├── synopsys_otg_regs.h │ │ └── usb.h │ └── xnu │ │ ├── xnu.S │ │ ├── xnu.c │ │ └── xnu.h ├── dynamic │ ├── modload.c │ └── modload_macho.c ├── kernel │ ├── dtree.c │ ├── dtree_getprop.c │ ├── entry.c │ ├── int.S │ ├── legacy.c │ ├── locks.c │ ├── lowlevel.c │ ├── main_task.c │ ├── mm.c │ ├── panic.c │ ├── pongo.h │ ├── support │ │ ├── exit.c │ │ ├── io.c │ │ ├── malloc.c │ │ ├── process.c │ │ └── sbrk.c │ ├── syscall.c │ ├── task.c │ ├── task.h │ ├── vfs.c │ └── vfs.h ├── lib │ ├── img4 │ │ ├── img4.c │ │ └── img4.h │ ├── libDER │ │ ├── DER_Decode.c │ │ ├── DER_Decode.h │ │ ├── DER_Encode.c │ │ ├── DER_Encode.h │ │ ├── asn1Types.h │ │ ├── libDER.h │ │ ├── libDER_config.h │ │ ├── oids.c │ │ └── oids.h │ └── lzma │ │ └── lzmadec.c ├── modules │ └── linux │ │ ├── libfdt │ │ ├── Makefile.libfdt │ │ ├── README.license │ │ ├── TODO │ │ ├── fdt.c │ │ ├── fdt.h │ │ ├── fdt_addresses.c │ │ ├── fdt_empty_tree.c │ │ ├── fdt_overlay.c │ │ ├── fdt_ro.c │ │ ├── fdt_rw.c │ │ ├── fdt_strerror.c │ │ ├── fdt_sw.c │ │ ├── fdt_wip.c │ │ ├── libfdt.h │ │ ├── libfdt_env.h │ │ ├── libfdt_internal.h │ │ └── version.lds │ │ └── linux.c ├── shell │ ├── autoboot.c │ ├── command.c │ ├── hex.c │ ├── linux.c │ ├── main.c │ └── usbloader.c └── sym_order.txt └── tools └── vmacho.c /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | # Trigger on all pushes and pull requests 5 | push: 6 | pull_request: 7 | 8 | # Allows you to run this workflow manually from the Actions tab 9 | workflow_dispatch: 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-20.04 14 | steps: 15 | - name: Install toolchain 16 | run: | 17 | echo 'deb https://assets.checkra.in/debian /' | sudo tee /etc/apt/sources.list.d/checkra1n.list 18 | sudo apt-key adv --fetch-keys https://assets.checkra.in/debian/archive.key 19 | sudo apt-get update 20 | sudo apt-get install -y ld64 cctools-strip 21 | - name: Voodoo magic 22 | id: voodoo 23 | uses: actions/cache@v2 24 | with: 25 | key: ${{ github.event_name }}-${{ github.ref }}-${{ github.run_id }} 26 | restore-keys: | 27 | push-${{ github.ref }}- 28 | push- 29 | path: | 30 | ** 31 | - name: Checkout repository 32 | if: steps.voodoo.outputs.cache-hit != 'true' 33 | uses: actions/checkout@v2 34 | with: 35 | submodules: true 36 | - name: Update repository 37 | if: steps.voodoo.outputs.cache-hit == 'true' 38 | run: | 39 | git fetch --all 40 | git reset --hard origin/$(git branch --show-current) 41 | git submodule update --recursive --remote 42 | - name: Compile 43 | run: EMBEDDED_CC='clang-10' EMBEDDED_AR='llvm-ar-10' EMBEDDED_RANLIB='llvm-ranlib-10' make all 44 | - name: Archive 45 | uses: actions/upload-artifact@v2 46 | with: 47 | name: PongoOS 48 | path: | 49 | build/checkra1n-kpf-pongo 50 | build/Pongo 51 | build/Pongo.bin 52 | build/PongoConsolidated.bin 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build/ 3 | *.patch 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "newlib"] 2 | path = newlib 3 | url = https://github.com/checkra1n/newlib.git 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pongoOS 2 | 3 | A pre-boot execution environment for Apple boards built on top of checkra1n. 4 | 5 | ## Building on macOS 6 | 7 | - Install Xcode + command-line utilities 8 | - Run `make all` 9 | 10 | ## Building on Linux 11 | 12 | - Install clang (if in doubt, from [apt.llvm.org](https://apt.llvm.org)) 13 | - Install `ld64` and cctools' `strip`. 14 | - On Debian/Ubuntu these can be installed from the checkra1n repo: 15 | ``` 16 | echo 'deb https://assets.checkra.in/debian /' | sudo tee /etc/apt/sources.list.d/checkra1n.list 17 | sudo apt-key adv --fetch-keys https://assets.checkra.in/debian/archive.key 18 | sudo apt-get update 19 | sudo apt-get install -y ld64 cctools-strip 20 | ``` 21 | - On other Linux flavours you'll likely have to build them yourself. Maybe [this repo](https://github.com/Siguza/ld64) will help you. 22 | - Run `make all` 23 | 24 | If `clang`, `ld64` or `cctools-strip` don't have their default names/paths, you'll want to change their invocation. For reference, the default variables are equivalent to: 25 | 26 | EMBEDDED_CC=clang EMBEDDED_LDFLAGS=-fuse-ld=/usr/bin/ld64 STRIP=cctools-strip make all 27 | 28 | ## Build artifacts 29 | 30 | The Makefile will create four binaries in `build/`: 31 | 32 | - `Pongo` - A Mach-O of the main PongoOS 33 | - `Pongo.bin` - Same as the above, but as a bare metal binary that can be jumped to 34 | - `checkra1n-kpf-pongo` - The checkra1n kernel patchfinder, as a Pongo module (Mach-O/kext) 35 | - `PongoConsolidated.bin` - PongoOS and the KPF merged into a single binary 36 | 37 | ## Usage 38 | 39 | checkra1n -k Pongo.bin # Boots to Pongo shell, KPF not available 40 | checkra1n -k PongoConsolidated.bin # Auto-runs KPF and boots to XNU 41 | checkra1n -k PongoConsolidated.bin -p # Loads KPF, but boots to Pongo shell 42 | 43 | ## Contributions 44 | 45 | By submitting a pull request, you agree to license your contributions under the [MIT License](https://github.com/checkra1n/pongoOS/blob/master/LICENSE.md) and you certify that you have the right to do so. 46 | If you want to import third-party code that cannot be licensed as such, that shall be noted prominently for us to evaluate accordingly. 47 | 48 | ## Structure 49 | 50 | - The core PongoOS and drivers are in `src/`. 51 | - Build-time helper tools are in `tools/`. 52 | - The stdlib used by PongoOS (Newlib) is in `aarch64-none-darwin`. 53 | - This includes a custom patch for Newlib to work with the Darwin ABI. 54 | - An example module exists in `example/`. 55 | - Scripts to communicate with the PongoOS shell are in `scripts/`. 56 | - This includes `pongoterm`, an interactive shell client for macOS. 57 | - The checkra1n kernel patchfinder (KPF) is in `checkra1n/kpf`. 58 | - This currently includes the SEP exploit, though that is to be moved into mainline PongoOS in the future. 59 | - A userland version of the KPF can be built from `checkra1n/kpf-test` (can only be run on arm64). 60 | -------------------------------------------------------------------------------- /apple-include/arm/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | */ 4 | #ifndef _BSD_ARM__TYPES_H_ 5 | #define _BSD_ARM__TYPES_H_ 6 | 7 | /* 8 | * This header file contains integer types. It's intended to also contain 9 | * flotaing point and other arithmetic types, as needed, later. 10 | */ 11 | 12 | #ifdef __GNUC__ 13 | typedef __signed char __int8_t; 14 | #else /* !__GNUC__ */ 15 | typedef char __int8_t; 16 | #endif /* !__GNUC__ */ 17 | typedef unsigned char __uint8_t; 18 | typedef short __int16_t; 19 | typedef unsigned short __uint16_t; 20 | typedef int __int32_t; 21 | typedef unsigned int __uint32_t; 22 | typedef long long __int64_t; 23 | typedef unsigned long long __uint64_t; 24 | 25 | typedef long __darwin_intptr_t; 26 | typedef unsigned int __darwin_natural_t; 27 | 28 | /* 29 | * The rune type below is declared to be an ``int'' instead of the more natural 30 | * ``unsigned long'' or ``long''. Two things are happening here. It is not 31 | * unsigned so that EOF (-1) can be naturally assigned to it and used. Also, 32 | * it looks like 10646 will be a 31 bit standard. This means that if your 33 | * ints cannot hold 32 bits, you will be in trouble. The reason an int was 34 | * chosen over a long is that the is*() and to*() routines take ints (says 35 | * ANSI C), but they use __darwin_ct_rune_t instead of int. By changing it 36 | * here, you lose a bit of ANSI conformance, but your programs will still 37 | * work. 38 | * 39 | * NOTE: rune_t is not covered by ANSI nor other standards, and should not 40 | * be instantiated outside of lib/libc/locale. Use wchar_t. wchar_t and 41 | * rune_t must be the same type. Also wint_t must be no narrower than 42 | * wchar_t, and should also be able to hold all members of the largest 43 | * character set plus one extra value (WEOF). wint_t must be at least 16 bits. 44 | */ 45 | 46 | typedef int __darwin_ct_rune_t; /* ct_rune_t */ 47 | 48 | /* 49 | * mbstate_t is an opaque object to keep conversion state, during multibyte 50 | * stream conversions. The content must not be referenced by user programs. 51 | */ 52 | typedef union { 53 | char __mbstate8[128]; 54 | long long _mbstateL; /* for alignment */ 55 | } __mbstate_t; 56 | 57 | typedef __mbstate_t __darwin_mbstate_t; /* mbstate_t */ 58 | 59 | #if defined(__PTRDIFF_TYPE__) 60 | typedef __PTRDIFF_TYPE__ __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 61 | #elif defined(__LP64__) 62 | typedef long __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 63 | #else 64 | typedef int __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 65 | #endif /* __GNUC__ */ 66 | 67 | #if defined(__SIZE_TYPE__) 68 | typedef __SIZE_TYPE__ __darwin_size_t; /* sizeof() */ 69 | #else 70 | typedef unsigned long __darwin_size_t; /* sizeof() */ 71 | #endif 72 | 73 | #if (__GNUC__ > 2) 74 | typedef __builtin_va_list __darwin_va_list; /* va_list */ 75 | #else 76 | typedef void * __darwin_va_list; /* va_list */ 77 | #endif 78 | 79 | #if defined(__WCHAR_TYPE__) 80 | typedef __WCHAR_TYPE__ __darwin_wchar_t; /* wchar_t */ 81 | #else 82 | typedef __darwin_ct_rune_t __darwin_wchar_t; /* wchar_t */ 83 | #endif 84 | 85 | typedef __darwin_wchar_t __darwin_rune_t; /* rune_t */ 86 | 87 | #if defined(__WINT_TYPE__) 88 | typedef __WINT_TYPE__ __darwin_wint_t; /* wint_t */ 89 | #else 90 | typedef __darwin_ct_rune_t __darwin_wint_t; /* wint_t */ 91 | #endif 92 | 93 | typedef unsigned long __darwin_clock_t; /* clock() */ 94 | typedef __uint32_t __darwin_socklen_t; /* socklen_t (duh) */ 95 | typedef long __darwin_ssize_t; /* byte count or error */ 96 | typedef long __darwin_time_t; /* time() */ 97 | 98 | #endif /* _BSD_ARM__TYPES_H_ */ 99 | -------------------------------------------------------------------------------- /apple-include/arm/arch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _ARM_ARCH_H 29 | #define _ARM_ARCH_H 30 | 31 | /* Collect the __ARM_ARCH_*__ compiler flags into something easier to use. */ 32 | #if defined (__ARM_ARCH_7A__) || defined (__ARM_ARCH_7S__) || defined (__ARM_ARCH_7F__) || defined (__ARM_ARCH_7K__) 33 | #define _ARM_ARCH_7 34 | #endif 35 | 36 | #if defined (_ARM_ARCH_7) || defined (__ARM_ARCH_6K__) || defined (__ARM_ARCH_6ZK__) 37 | #define _ARM_ARCH_6K 38 | #endif 39 | 40 | #if defined (_ARM_ARCH_7) || defined (__ARM_ARCH_6Z__) || defined (__ARM_ARCH_6ZK__) 41 | #define _ARM_ARCH_6Z 42 | #endif 43 | 44 | #if defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6J__) || \ 45 | defined (_ARM_ARCH_6Z) || defined (_ARM_ARCH_6K) 46 | #define _ARM_ARCH_6 47 | #endif 48 | 49 | #if defined (_ARM_ARCH_6) || defined (__ARM_ARCH_5E__) || \ 50 | defined (__ARM_ARCH_5TE__) || defined (__ARM_ARCH_5TEJ__) 51 | #define _ARM_ARCH_5E 52 | #endif 53 | 54 | #if defined (_ARM_ARCH_5E) || defined (__ARM_ARCH_5__) || \ 55 | defined (__ARM_ARCH_5T__) 56 | #define _ARM_ARCH_5 57 | #endif 58 | 59 | #if defined (_ARM_ARCH_5) || defined (__ARM_ARCH_4T__) 60 | #define _ARM_ARCH_4T 61 | #endif 62 | 63 | #if defined (_ARM_ARCH_4T) || defined (__ARM_ARCH_4__) 64 | #define _ARM_ARCH_4 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /apple-include/mach/arm/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: boolean.h 61 | * 62 | * Boolean type, for ARM. 63 | */ 64 | 65 | #ifndef _MACH_ARM_BOOLEAN_H_ 66 | #define _MACH_ARM_BOOLEAN_H_ 67 | 68 | typedef int boolean_t; 69 | 70 | #endif /* _MACH_ARM_BOOLEAN_H_ */ 71 | -------------------------------------------------------------------------------- /apple-include/mach/arm/kern_return.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: kern_return.h 61 | * Author: Avadis Tevanian, Jr., Michael Wayne Young 62 | * Date: 1985 63 | * 64 | * Machine-dependent kernel return definitions. 65 | */ 66 | 67 | #ifndef _MACH_ARM_KERN_RETURN_H_ 68 | #define _MACH_ARM_KERN_RETURN_H_ 69 | 70 | #ifndef ASSEMBLER 71 | typedef int kern_return_t; 72 | #endif /* ASSEMBLER */ 73 | 74 | #endif /* _MACH_ARM_KERN_RETURN_H_ */ 75 | -------------------------------------------------------------------------------- /apple-include/mach/arm/thread_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | 32 | #ifndef _MACH_ARM_THREAD_STATE_H_ 33 | #define _MACH_ARM_THREAD_STATE_H_ 34 | 35 | /* Size of maximum exported thread state in words */ 36 | #define ARM_THREAD_STATE_MAX (1296) /* Size of biggest state possible */ 37 | 38 | #if defined (__arm__) || defined(__arm64__) 39 | #define THREAD_STATE_MAX ARM_THREAD_STATE_MAX 40 | #else 41 | #error Unsupported arch 42 | #endif 43 | 44 | #endif /* _MACH_ARM_THREAD_STATE_H_ */ 45 | -------------------------------------------------------------------------------- /apple-include/mach/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | /* 59 | * File: mach/boolean.h 60 | * 61 | * Boolean data type. 62 | * 63 | */ 64 | 65 | #ifndef _MACH_BOOLEAN_H_ 66 | #define _MACH_BOOLEAN_H_ 67 | 68 | /* 69 | * Pick up "boolean_t" type definition 70 | */ 71 | 72 | #ifndef ASSEMBLER 73 | #include 74 | #endif /* ASSEMBLER */ 75 | 76 | /* 77 | * Define TRUE and FALSE if not defined. 78 | */ 79 | 80 | #ifndef TRUE 81 | #define TRUE 1 82 | #endif /* TRUE */ 83 | 84 | #ifndef FALSE 85 | #define FALSE 0 86 | #endif /* FALSE */ 87 | 88 | #endif /* _MACH_BOOLEAN_H_ */ 89 | -------------------------------------------------------------------------------- /apple-include/mach/i386/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: boolean.h 61 | * 62 | * Boolean type, for I386. 63 | */ 64 | 65 | #ifndef _MACH_I386_BOOLEAN_H_ 66 | #define _MACH_I386_BOOLEAN_H_ 67 | 68 | #if defined(__x86_64__) && !defined(KERNEL) 69 | typedef unsigned int boolean_t; 70 | #else 71 | typedef int boolean_t; 72 | #endif 73 | 74 | #endif /* _MACH_I386_BOOLEAN_H_ */ 75 | -------------------------------------------------------------------------------- /apple-include/mach/i386/kern_return.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: kern_return.h 61 | * Author: Avadis Tevanian, Jr., Michael Wayne Young 62 | * Date: 1985 63 | * 64 | * Machine-dependent kernel return definitions. 65 | */ 66 | 67 | #ifndef _MACH_I386_KERN_RETURN_H_ 68 | #define _MACH_I386_KERN_RETURN_H_ 69 | 70 | #ifndef ASSEMBLER 71 | typedef int kern_return_t; 72 | #endif /* ASSEMBLER */ 73 | 74 | #endif /* _MACH_I386_KERN_RETURN_H_ */ 75 | -------------------------------------------------------------------------------- /apple-include/mach/i386/thread_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | 32 | #ifndef _MACH_I386_THREAD_STATE_H_ 33 | #define _MACH_I386_THREAD_STATE_H_ 34 | 35 | /* Size of maximum exported thread state in 32-bit words */ 36 | #define I386_THREAD_STATE_MAX (614) /* Size of biggest state possible */ 37 | 38 | #if defined (__i386__) || defined(__x86_64__) 39 | #define THREAD_STATE_MAX I386_THREAD_STATE_MAX 40 | #endif 41 | 42 | #endif /* _MACH_I386_THREAD_STATE_H_ */ 43 | -------------------------------------------------------------------------------- /apple-include/mach/machine/_structs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE__STRUCTS_H_ 30 | #define _MACH_MACHINE__STRUCTS_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/_structs.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/_structs.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE__STRUCTS_H_ */ 41 | -------------------------------------------------------------------------------- /apple-include/mach/machine/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_BOOLEAN_H_ 30 | #define _MACH_MACHINE_BOOLEAN_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/boolean.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/boolean.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_BOOLEAN_H_ */ 41 | -------------------------------------------------------------------------------- /apple-include/mach/machine/kern_return.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_KERN_RETURN_H_ 30 | #define _MACH_MACHINE_KERN_RETURN_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/kern_return.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/kern_return.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_KERN_RETURN_H_ */ 41 | -------------------------------------------------------------------------------- /apple-include/mach/machine/thread_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_THREAD_STATE_H_ 30 | #define _MACH_MACHINE_THREAD_STATE_H_ 31 | 32 | #if defined (__arm__) || defined (__arm64__) 33 | #include "mach/arm/thread_state.h" 34 | #else 35 | #error architecture not supported 36 | #endif 37 | 38 | #endif /* _MACH_MACHINE_THREAD_STATE_H_ */ 39 | -------------------------------------------------------------------------------- /apple-include/mach/machine/thread_status.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_THREAD_STATUS_H_ 30 | #define _MACH_MACHINE_THREAD_STATUS_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/thread_status.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/thread_status.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_THREAD_STATUS_H_ */ 41 | -------------------------------------------------------------------------------- /apple-include/mach/machine/vm_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_VM_TYPES_H_ 30 | #define _MACH_MACHINE_VM_TYPES_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/vm_types.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/vm_types.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_VM_TYPES_H_ */ 41 | -------------------------------------------------------------------------------- /apple-include/mach/vm_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2018 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | * 31 | */ 32 | #ifndef _MACH_VM_TYPES_H_ 33 | #define _MACH_VM_TYPES_H_ 34 | 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | typedef vm_offset_t pointer_t; 41 | typedef vm_offset_t vm_address_t; 42 | 43 | /* 44 | * We use addr64_t for 64-bit addresses that are used on both 45 | * 32 and 64-bit machines. On PPC, they are passed and returned as 46 | * two adjacent 32-bit GPRs. We use addr64_t in places where 47 | * common code must be useable both on 32 and 64-bit machines. 48 | */ 49 | typedef uint64_t addr64_t; /* Basic effective address */ 50 | 51 | /* 52 | * We use reg64_t for addresses that are 32 bits on a 32-bit 53 | * machine, and 64 bits on a 64-bit machine, but are always 54 | * passed and returned in a single GPR on PPC. This type 55 | * cannot be used in generic 32-bit c, since on a 64-bit 56 | * machine the upper half of the register will be ignored 57 | * by the c compiler in 32-bit mode. In c, we can only use the 58 | * type in prototypes of functions that are written in and called 59 | * from assembly language. This type is basically a comment. 60 | */ 61 | typedef uint32_t reg64_t; 62 | 63 | /* 64 | * To minimize the use of 64-bit fields, we keep some physical 65 | * addresses (that are page aligned) as 32-bit page numbers. 66 | * This limits the physical address space to 16TB of RAM. 67 | */ 68 | typedef uint32_t ppnum_t; /* Physical page number */ 69 | #define PPNUM_MAX UINT32_MAX 70 | 71 | 72 | 73 | typedef mach_port_t vm_map_t, vm_map_read_t, vm_map_inspect_t; 74 | 75 | 76 | #define VM_MAP_NULL ((vm_map_t) 0) 77 | #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) 0) 78 | #define VM_MAP_READ_NULL ((vm_map_read_t) 0) 79 | 80 | /* 81 | * Evolving definitions, likely to change. 82 | */ 83 | 84 | typedef uint64_t vm_object_offset_t; 85 | typedef uint64_t vm_object_size_t; 86 | 87 | 88 | 89 | 90 | typedef mach_port_t upl_t; 91 | typedef mach_port_t vm_named_entry_t; 92 | 93 | 94 | #define UPL_NULL ((upl_t) 0) 95 | #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) 0) 96 | 97 | #endif /* _MACH_VM_TYPES_H_ */ 98 | -------------------------------------------------------------------------------- /apple-include/machine/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _BSD_MACHINE__TYPES_H_ 29 | #define _BSD_MACHINE__TYPES_H_ 30 | 31 | #if defined (__i386__) || defined(__x86_64__) 32 | #include "i386/_types.h" 33 | #elif defined (__arm__) || defined (__arm64__) 34 | #include "arm/_types.h" 35 | #else 36 | #error architecture not supported 37 | #endif 38 | 39 | #endif /* _BSD_MACHINE__TYPES_H_ */ 40 | -------------------------------------------------------------------------------- /apple-include/sys/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _SYS__TYPES_H_ 30 | #define _SYS__TYPES_H_ 31 | 32 | #include 33 | #include 34 | 35 | /* 36 | * Type definitions; takes common type definitions that must be used 37 | * in multiple header files due to [XSI], removes them from the system 38 | * space, and puts them in the implementation space. 39 | */ 40 | 41 | #ifdef __cplusplus 42 | #ifdef __GNUG__ 43 | #define __DARWIN_NULL __null 44 | #else /* ! __GNUG__ */ 45 | #ifdef __LP64__ 46 | #define __DARWIN_NULL (0L) 47 | #else /* !__LP64__ */ 48 | #define __DARWIN_NULL 0 49 | #endif /* __LP64__ */ 50 | #endif /* __GNUG__ */ 51 | #else /* ! __cplusplus */ 52 | #define __DARWIN_NULL ((void *)0) 53 | #endif /* __cplusplus */ 54 | 55 | typedef __int64_t __darwin_blkcnt_t; /* total blocks */ 56 | typedef __int32_t __darwin_blksize_t; /* preferred block size */ 57 | typedef __int32_t __darwin_dev_t; /* dev_t */ 58 | typedef unsigned int __darwin_fsblkcnt_t; /* Used by statvfs and fstatvfs */ 59 | typedef unsigned int __darwin_fsfilcnt_t; /* Used by statvfs and fstatvfs */ 60 | typedef __uint32_t __darwin_gid_t; /* [???] process and group IDs */ 61 | typedef __uint32_t __darwin_id_t; /* [XSI] pid_t, uid_t, or gid_t*/ 62 | typedef __uint64_t __darwin_ino64_t; /* [???] Used for 64 bit inodes */ 63 | #if __DARWIN_64_BIT_INO_T 64 | typedef __darwin_ino64_t __darwin_ino_t; /* [???] Used for inodes */ 65 | #else /* !__DARWIN_64_BIT_INO_T */ 66 | typedef __uint32_t __darwin_ino_t; /* [???] Used for inodes */ 67 | #endif /* __DARWIN_64_BIT_INO_T */ 68 | typedef __darwin_natural_t __darwin_mach_port_name_t; /* Used by mach */ 69 | typedef __darwin_mach_port_name_t __darwin_mach_port_t; /* Used by mach */ 70 | typedef __uint16_t __darwin_mode_t; /* [???] Some file attributes */ 71 | typedef __int64_t __darwin_off_t; /* [???] Used for file sizes */ 72 | typedef __int32_t __darwin_pid_t; /* [???] process and group IDs */ 73 | typedef __uint32_t __darwin_sigset_t; /* [???] signal set */ 74 | typedef __int32_t __darwin_suseconds_t; /* [???] microseconds */ 75 | typedef __uint32_t __darwin_uid_t; /* [???] user IDs */ 76 | typedef __uint32_t __darwin_useconds_t; /* [???] microseconds */ 77 | typedef unsigned char __darwin_uuid_t[16]; 78 | typedef char __darwin_uuid_string_t[37]; 79 | 80 | #include 81 | 82 | #endif /* _SYS__TYPES_H_ */ 83 | -------------------------------------------------------------------------------- /apple-include/sys/_types/_mach_port_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | /* 30 | * mach_port_t - a named port right 31 | * 32 | * In user-space, "rights" are represented by the name of the 33 | * right in the Mach port namespace. Even so, this type is 34 | * presented as a unique one to more clearly denote the presence 35 | * of a right coming along with the name. 36 | * 37 | * Often, various rights for a port held in a single name space 38 | * will coalesce and are, therefore, be identified by a single name 39 | * [this is the case for send and receive rights]. But not 40 | * always [send-once rights currently get a unique name for 41 | * each right]. 42 | * 43 | * This definition of mach_port_t is only for user-space. 44 | * 45 | */ 46 | 47 | #ifndef _MACH_PORT_T 48 | #define _MACH_PORT_T 49 | #include "../_types.h" /* __darwin_mach_port_t */ 50 | typedef __darwin_mach_port_t mach_port_t; 51 | #endif /* _MACH_PORT_T */ 52 | -------------------------------------------------------------------------------- /apple-include/sys/_types/_os_inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #if !defined(OS_INLINE) 29 | # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 30 | # define OS_INLINE static inline 31 | # else 32 | # define OS_INLINE static __inline__ 33 | # endif 34 | #endif /* OS_INLINE */ 35 | -------------------------------------------------------------------------------- /apple-include/sys/appleapiopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef __SYS_APPLEAPIOPTS_H__ 30 | #define __SYS_APPLEAPIOPTS_H__ 31 | 32 | 33 | #ifndef __APPLE_API_STANDARD 34 | #define __APPLE_API_STANDARD 35 | #endif /* __APPLE_API_STANDARD */ 36 | 37 | #ifndef __APPLE_API_STABLE 38 | #define __APPLE_API_STABLE 39 | #endif /* __APPLE_API_STABLE */ 40 | 41 | #ifndef __APPLE_API_STRICT_CONFORMANCE 42 | 43 | #ifndef __APPLE_API_EVOLVING 44 | #define __APPLE_API_EVOLVING 45 | #endif /* __APPLE_API_EVOLVING */ 46 | 47 | #ifndef __APPLE_API_UNSTABLE 48 | #define __APPLE_API_UNSTABLE 49 | #endif /* __APPLE_API_UNSTABLE */ 50 | 51 | #ifndef __APPLE_API_PRIVATE 52 | #define __APPLE_API_PRIVATE 53 | #endif /* __APPLE_API_PRIVATE */ 54 | 55 | #ifndef __APPLE_API_OBSOLETE 56 | #define __APPLE_API_OBSOLETE 57 | #endif /* __APPLE_API_OBSOLETE */ 58 | 59 | #endif /* __APPLE_API_STRICT_CONFORMANCE */ 60 | 61 | #endif /* __SYS_APPLEAPIOPTS_H__ */ 62 | -------------------------------------------------------------------------------- /checkra1n/kpf-test/.gitignore: -------------------------------------------------------------------------------- 1 | /kpf-test.ios 2 | /kpf-test.macos 3 | -------------------------------------------------------------------------------- /checkra1n/kpf-test/Makefile: -------------------------------------------------------------------------------- 1 | ifndef $(HOST_OS) 2 | ifeq ($(OS),Windows_NT) 3 | HOST_OS = Windows 4 | else 5 | HOST_OS := $(shell uname -s) 6 | endif 7 | endif 8 | 9 | PONGO_VERSION := x.y.z-$(shell git log -1 --pretty=format:"%H" | cut -c1-8) 10 | ROOT := ../.. 11 | SRC := $(ROOT)/src 12 | INC := $(ROOT)/include 13 | RA1N := $(ROOT)/checkra1n/kpf 14 | 15 | CHECKRA1N_C := main.c $(RA1N)/main.c $(RA1N)/shellcode.S $(SRC)/drivers/xnu/xnu.c $(SRC)/drivers/xnu/xnu.S 16 | CHECKRA1N_LDFLAGS := -Wl,-fatal_warnings -Wl,-dead_strip 17 | CHECKRA1N_FLAGS := -std=gnu17 -Wall -Wunused-label -Werror -O3 -flto -I$(INC) -I$(SRC)/kernel -I$(SRC)/drivers -DCHECKRAIN_VERSION='' -Diprintf=printf -Dpanic=realpanic -DOVERRIDE_CACHEABLE_VIEW=0x800000000ULL -DDEV_BUILD=1 $(CHECKRA1N_LDFLAGS) $(KPF_CFLAGS) $(CFLAGS) 18 | 19 | ifeq ($(HOST_OS),Darwin) 20 | IOS_CC ?= xcrun -sdk iphoneos clang -arch arm64 21 | MACOS_CC ?= clang -arch arm64 22 | IOS_FLAGS ?= -miphoneos-version-min=7.0 23 | MACOS_FLAGS ?= -mmacosx-version-min=11.0 '-Djit_set_exec(m)=void pthread_jit_write_protect_np(int); pthread_jit_write_protect_np(m)' 24 | SIGN ?= codesign -s - --entitlements ent.plist 25 | else 26 | ifeq ($(HOST_OS),Linux) 27 | # TODO: macOS target 28 | IOS_CC ?= arm64-apple-ios12.0.0-clang -arch arm64 29 | SIGN ?= ldid -Sent.plist 30 | endif 31 | endif 32 | 33 | 34 | .PHONY: all clean 35 | 36 | all: kpf-test.ios kpf-test.macos 37 | 38 | kpf-test.ios: $(CHECKRA1N_C) 39 | $(IOS_CC) -o $@ $(CHECKRA1N_C) $(CHECKRA1N_FLAGS) $(IOS_FLAGS) 40 | $(SIGN) $@ 41 | 42 | kpf-test.macos: $(CHECKRA1N_C) 43 | $(MACOS_CC) -o $@ $(CHECKRA1N_C) $(CHECKRA1N_FLAGS) $(MACOS_FLAGS) 44 | 45 | clean: 46 | rm -f kpf-test.ios kpf-test.macos 47 | -------------------------------------------------------------------------------- /checkra1n/kpf-test/ent.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.private.security.no-container 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /checkra1n/kpf/not_strip.txt: -------------------------------------------------------------------------------- 1 | _module_entry 2 | _module_name 3 | _exported_symbols 4 | -------------------------------------------------------------------------------- /example/testmodule/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2019-2021 checkra1n team 3 | # This file is part of pongoOS. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | # 23 | ifndef $(HOST_OS) 24 | ifeq ($(OS),Windows_NT) 25 | HOST_OS = Windows 26 | else 27 | HOST_OS := $(shell uname -s) 28 | endif 29 | endif 30 | 31 | ifeq ($(HOST_OS),Darwin) 32 | EMBEDDED_CC ?= xcrun -sdk iphoneos clang 33 | STRIP ?= strip 34 | STAT ?= stat -L -f %z 35 | else 36 | ifeq ($(HOST_OS),Linux) 37 | EMBEDDED_CC ?= clang 38 | EMBEDDED_LDFLAGS ?= -fuse-ld=/usr/bin/ld64 39 | STRIP ?= cctools-strip 40 | STAT ?= stat -L -c %s 41 | endif 42 | endif 43 | 44 | DEP := ../../newlib 45 | LIB := $(DEP)/aarch64-none-darwin 46 | BUILD := build 47 | 48 | # General options 49 | EMBEDDED_LD_FLAGS ?= -nostdlib -static -Wl,-fatal_warnings -Wl,-dead_strip -Wl,-Z $(EMBEDDED_LDFLAGS) 50 | EMBEDDED_CC_FLAGS ?= --target=arm64-apple-ios12.0 -Wall -Wunused-label -Werror -O3 -flto -ffreestanding -U__nonnull -nostdlibinc -DTARGET_OS_OSX=0 -DTARGET_OS_MACCATALYST=0 -I$(LIB)/include $(EMBEDDED_LD_FLAGS) $(EMBEDDED_CFLAGS) 51 | 52 | # Module options 53 | MODULE_LDFLAGS ?= -Wl,-kext 54 | MODULE_CC_FLAGS ?= -I../../apple-include/ -I../include/ $(MODULE_LDFLAGS) 55 | 56 | MODULE_C := main.c 57 | 58 | .PHONY: all clean 59 | 60 | all: $(BUILD)/testmodule 61 | 62 | $(BUILD)/testmodule: Makefile $(MODULE_C) 63 | $(EMBEDDED_CC) -o $@ $(EMBEDDED_CC_FLAGS) $(MODULE_CC_FLAGS) $(MODULE_C) 64 | 65 | clean: 66 | rm -rf $(BUILD) -------------------------------------------------------------------------------- /example/testmodule/main.c: -------------------------------------------------------------------------------- 1 | // Permission is hereby granted, free of charge, to any person obtaining a copy 2 | // of this software and associated documentation files (the "Software"), to deal 3 | // in the Software without restriction, including without limitation the rights 4 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | // copies of the Software, and to permit persons to whom the Software is 6 | // furnished to do so, subject to the following conditions: 7 | // 8 | // The above copyright notice and this permission notice shall be included in all 9 | // copies or substantial portions of the Software. 10 | // 11 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 | // SOFTWARE. 18 | // 19 | // 20 | // Copyright (C) 2019-2021 checkra1n team 21 | // This file is part of pongoOS. 22 | // 23 | #include 24 | 25 | void (*existing_preboot_hook)(); 26 | 27 | void m_preboot_hook() 28 | { 29 | puts("Called pre-boot hook"); 30 | /* Do patches here */ 31 | if (existing_preboot_hook != NULL) 32 | existing_preboot_hook(); 33 | return; 34 | } 35 | 36 | void hello() { 37 | puts("Hello world! And now continuing to XNU."); 38 | queue_rx_string("bootx\n"); // Adding boot XNU command to buffer 39 | } 40 | 41 | void module_entry() { 42 | existing_preboot_hook = preboot_hook; 43 | preboot_hook = m_preboot_hook; 44 | command_register("hello", "Hello world!", hello); 45 | } 46 | 47 | char* module_name = "test_module"; 48 | 49 | struct pongo_exports exported_symbols[] = { 50 | {.name = 0, .value = 0} 51 | }; 52 | -------------------------------------------------------------------------------- /include/kerninfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #ifndef _KERNINFO_H 28 | #define _KERNINFO_H 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #define MAX_BOOTARGS_LEN 256 35 | #define DEFAULT_BOOTARGS "rootdev=md0" 36 | 37 | typedef enum { 38 | checkrain_option_none = 0, 39 | checkrain_option_all = -1, 40 | checkrain_option_failure = -2, 41 | 42 | checkrain_option_safemode = 1 << 0, 43 | checkrain_option_verbose_boot = 1 << 1, 44 | checkrain_option_verbose_logging = 1 << 2, 45 | checkrain_option_demote = 1 << 3, 46 | checkrain_option_pongo_shell = 1 << 4, 47 | checkrain_option_early_exit = 1 << 5, 48 | } checkrain_option_t, *checkrain_option_p; 49 | 50 | struct kerninfo { 51 | uint64_t size; 52 | uint64_t base; 53 | uint64_t slide; 54 | checkrain_option_t flags; 55 | uint16_t cpid; 56 | char bootargs[MAX_BOOTARGS_LEN]; 57 | }; 58 | 59 | #define checkrain_set_option(options, option, enabled) do { \ 60 | if (enabled) \ 61 | options = (checkrain_option_t)(options | option); \ 62 | else \ 63 | options = (checkrain_option_t)(options & ~option); \ 64 | } while (0); 65 | 66 | static inline bool checkrain_option_enabled(checkrain_option_t flags, checkrain_option_t opt) 67 | { 68 | if(flags == checkrain_option_failure) 69 | { 70 | switch(opt) 71 | { 72 | case checkrain_option_safemode: 73 | return true; 74 | default: 75 | return false; 76 | } 77 | } 78 | return (flags & opt) != 0; 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /include/key.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #define PUBKEY_BITS (const unsigned char[]) { \ 28 | 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xaf, 0xb0, 0xe8, 0xed, 0x4d, 0xc5, 0x18, \ 29 | 0x72, 0xcd, 0x0d, 0xbe, 0x8f, 0xd7, 0x00, 0x1a, 0xcf, 0xdb, 0x42, 0x39, 0x6c, 0x77, 0x4f, 0x80, \ 30 | 0x77, 0x9c, 0x01, 0x12, 0x0e, 0x01, 0xbb, 0x0e, 0x95, 0xdb, 0x39, 0xcd, 0xee, 0x75, 0xa1, 0x82, \ 31 | 0x82, 0x0d, 0xfa, 0x48, 0xb6, 0xa5, 0x66, 0xce, 0xe2, 0x0f, 0x0e, 0x10, 0xe6, 0xa8, 0xf6, 0x60, \ 32 | 0xe2, 0xb8, 0xa1, 0xf9, 0xf9, 0x98, 0x1d, 0x29, 0xb0, 0x0c, 0xbf, 0x6b, 0xf1, 0x10, 0x8b, 0xbe, \ 33 | 0x4a, 0x4b, 0x60, 0x35, 0x4f, 0x6e, 0x1c, 0x0a, 0x6a, 0xc8, 0xb4, 0xfa, 0x81, 0x6e, 0xbd, 0x74, \ 34 | 0x74, 0xba, 0x92, 0x57, 0xab, 0x58, 0xaa, 0x27, 0x44, 0x70, 0xc5, 0xa4, 0x2c, 0xf9, 0x16, 0xfd, \ 35 | 0xef, 0x4b, 0x39, 0xfb, 0xfa, 0x60, 0x40, 0x16, 0x30, 0xda, 0x5f, 0xb7, 0xdc, 0x85, 0x80, 0xd1, \ 36 | 0x16, 0xe5, 0x6a, 0x7d, 0x18, 0xb1, 0xa6, 0xc1, 0xae, 0x7d, 0x48, 0x86, 0x2c, 0x29, 0x98, 0x8a, \ 37 | 0xe2, 0x33, 0xb1, 0x7f, 0xa4, 0x3d, 0x4a, 0xda, 0x14, 0xec, 0xb5, 0x69, 0x03, 0x3c, 0x35, 0xf2, \ 38 | 0xd9, 0xe1, 0x04, 0x1f, 0xfc, 0x24, 0xa5, 0x87, 0x35, 0x86, 0x46, 0x07, 0xa7, 0x3d, 0x93, 0x29, \ 39 | 0x80, 0xd3, 0x0c, 0xdb, 0xff, 0x09, 0xaa, 0x4a, 0xe8, 0x59, 0x71, 0x32, 0x39, 0x9a, 0xb2, 0x8d, \ 40 | 0xeb, 0xbc, 0x51, 0xee, 0x7d, 0x52, 0x3b, 0x42, 0xc8, 0x0c, 0xee, 0x0e, 0xcf, 0x22, 0x1e, 0x50, \ 41 | 0x6f, 0x3b, 0xd8, 0x67, 0xbf, 0x93, 0x8d, 0xa9, 0xe4, 0x35, 0x0c, 0xa3, 0xfd, 0x6d, 0x02, 0x28, \ 42 | 0x29, 0x49, 0xb2, 0x9a, 0x49, 0x24, 0xfc, 0xc5, 0xe6, 0x61, 0x59, 0xde, 0x1f, 0xb7, 0x0d, 0x43, \ 43 | 0x0a, 0xa1, 0x14, 0x69, 0xc3, 0x54, 0x7e, 0x31, 0x81, 0x97, 0x84, 0x19, 0xaf, 0xa9, 0xa3, 0x0f, \ 44 | 0x9b, 0x28, 0xa7, 0x44, 0x6d, 0x5f, 0x32, 0x47, 0x47, 0x02, 0x03, 0x01, 0x00, 0x01 } 45 | -------------------------------------------------------------------------------- /include/loader_xpc_service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | #define LOADERD_SUCCESS 0 30 | #define LOADERD_ERROR_INVALID_ACTION -1 31 | #define LOADERD_ERROR_GENERAL 1 32 | #define LOADERD_ERROR_ALREADY_BOOTSTRAPPED 2 33 | #define LOADERD_ERROR_MOUNT 3 34 | #define LOADERD_ERROR_MISSING_BOOTSTRAP 4 35 | #define LOADERD_ERROR_TAR 5 36 | #define LOADERD_ERROR_INVALID_DPKG_ENTRY 6 37 | #define LOADERD_ERROR_STATUS_FILE 7 38 | #define LOADERD_ERROR_ROOTFS_RESTORE 8 39 | #define LOADERD_ERROR_SIGNATURE_INVALID 9 40 | #define LOADERD_ERROR_SNAPSHOT 10 41 | #define LOADERD_ERROR_OTA 11 42 | #define LOADERD_NO_CONNECTION 12 43 | 44 | #define LOADERD_ACTION_CHECK_SNAPSHOT "verify" 45 | #define LOADERD_ACTION_BOOTSTRAP "bootstrap" 46 | #define LOADERD_ACTION_RESTORE_ROOTFS "restore_rootfs" 47 | 48 | static const char* loaderd_errors[] = { 49 | "invalid_action", // LOADERD_ERROR_INVALID_ACTION -1 50 | "success", // LOADERD_SUCCESS 0 51 | "general_error", // LOADERD_ERROR_GENERAL 1 52 | "device_already_bootstrapped", // LOADERD_ERROR_ALREADY_BOOTSTRAPPED 2 53 | "mount_error", // LOADERD_ERROR_MOUNT 3 54 | "missing_bootstrap", // LOADERD_ERROR_MISSING_BOOTSTRAP 4 55 | "bootstrap_extraction_error", // LOADERD_ERROR_TAR 5 56 | "invalid_dpkg_entry", // LOADERD_ERROR_INVALID_DPKG_ENTRY 6 57 | "error_in_status_file", // LOADERD_ERROR_STATUS_FILE 7 58 | "rootfs_restore_failed", // LOADERD_ERROR_ROOTFS_RESTORE 8 59 | "bootstrap_signature_invalid", // LOADERD_ERROR_SIGNATURE_INVALID 9 60 | "error_renaming_snapshot", // LOADERD_ERROR_SNAPSHOT 10 61 | "error_ota", // LOADERD_ERROR_OTA 11 62 | "error_connection", // LOADERD_NO_CONNECTION 12 63 | NULL 64 | }; 65 | 66 | 67 | static inline const char *loaderd_strerror(int error) { 68 | error += 1; 69 | if (error < 0 || error > (sizeof(loaderd_errors)/sizeof(const char*)) - 2) { 70 | return "invalid_error"; 71 | } 72 | return loaderd_errors[error]; 73 | } 74 | -------------------------------------------------------------------------------- /scripts/.gitignore: -------------------------------------------------------------------------------- 1 | /pongoterm 2 | -------------------------------------------------------------------------------- /scripts/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2019-2021 checkra1n team 3 | # This file is part of pongoOS. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | # 23 | ifndef $(HOST_OS) 24 | ifeq ($(OS),Windows_NT) 25 | HOST_OS = Windows 26 | else 27 | HOST_OS := $(shell uname -s) 28 | endif 29 | endif 30 | 31 | ifeq ($(HOST_OS),Darwin) 32 | C_FLAGS ?= -Wall -O3 -x objective-c $(CFLAGS) 33 | LD_FLAGS ?= -framework Foundation -framework CoreFoundation -framework IOKit $(LDFLAGS) 34 | else 35 | ifeq ($(HOST_OS),Linux) 36 | C_FLAGS ?= -Wall -O3 -DUSE_LIBUSB=1 $(CFLAGS) 37 | LD_FLAGS ?= -lpthread -lusb-1.0 $(LDFLAGS) 38 | endif 39 | endif 40 | 41 | .PHONY: all clean 42 | 43 | all: pongoterm 44 | 45 | pongoterm: pongoterm.c 46 | $(CC) $(C_FLAGS) -o $@ $^ $(LD_FLAGS) 47 | 48 | clean: 49 | rm -f pongoterm 50 | -------------------------------------------------------------------------------- /scripts/arm64-apple-ios12.0.0-clang: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | # 3 | # Copyright (C) 2019-2021 checkra1n team 4 | # This file is part of pongoOS. 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | 25 | TOOLCHAIN=/opt/ios-arm64e-clang-toolchain 26 | REALNAME="$(realpath "$0")" 27 | DIR="$(dirname "${REALNAME}")" 28 | BASENAME="$(basename "${REALNAME}")" 29 | TARGET="${BASENAME%-*}" 30 | EXE="${BASENAME##*-}" 31 | ARCH="${TARGET%%-*}" 32 | export SDKROOT="$TOOLCHAIN/sdks/MacOSX.sdk" 33 | export PATH="${TOOLCHAIN}/bin:$PATH" 34 | TOOL="clang" 35 | case $EXE in 36 | clang++|g++|c++) 37 | TOOL="clang++" # -isystem $TOOLCHAIN/libc++/include/c++/v1" 38 | ;; 39 | as) 40 | # TOOL="as" 41 | esac 42 | case $ARCH in 43 | x86_64|x86_64h) 44 | export SDKROOT="$TOOLCHAIN/sdks/MacOSX.sdk" 45 | #LINKER="-Xlinker $TOOLCHAIN/clangrt/lib/darwin/libclang_rt.osx.a" 46 | ;; 47 | i386) 48 | #LINKER="-Xlinker $TOOLCHAIN/clangrt/lib/darwin/libclang_rt.osx.a 49 | export SDKROOT="$TOOLCHAIN/sdks/MacOSX.sdk" 50 | ;; 51 | arm64) 52 | #LINKER="-Xlinker $TOOLCHAIN/clangrt/lib/darwin/libclang_rt.ios.a 53 | export SDKROOT="$TOOLCHAIN/sdks/iPhoneOS.sdk" 54 | ;; 55 | esac 56 | "${TOOLCHAIN}/bin/${EXE}" -Wno-unused-command-line-argument -fuse-ld="${TOOLCHAIN}/bin/ld" -isysroot "${SDKROOT}" -target $TARGET $LINKER "$@" 57 | -------------------------------------------------------------------------------- /scripts/boot-checkra1n.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2019-2021 checkra1n team 4 | # This file is part of pongoOS. 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | import sys 25 | import time 26 | import usb.core 27 | data = open(sys.argv[1], "rb").read() 28 | rdsk = open(sys.argv[2], "rb").read() 29 | dev = usb.core.find(idVendor=0x05ac, idProduct=0x4141) 30 | if dev is None: 31 | raise ValueError('Device not found') 32 | dev.set_configuration() 33 | 34 | dev.ctrl_transfer(0x21, 4, 0, 0, 0) 35 | dev.ctrl_transfer(0x21, 3, 0, 0, "xargs serial=3 rootdev=md0\n") 36 | dev.ctrl_transfer(0x21, 2, 0, 0, 0) 37 | dev.ctrl_transfer(0x21, 1, 0, 0, 0) 38 | dev.write(2,data) 39 | #dev.write(2,"") 40 | dev.ctrl_transfer(0x21, 4, 0, 0, 0) 41 | dev.ctrl_transfer(0x21, 3, 0, 0, "modload\n") 42 | dev.ctrl_transfer(0x21, 2, 0, 0, 0) 43 | dev.ctrl_transfer(0x21, 1, 0, 0, 0) 44 | dev.write(2,rdsk,100000) 45 | dev.write(2,"") 46 | dev.ctrl_transfer(0x21, 4, 0, 0, 0) 47 | dev.ctrl_transfer(0x21, 3, 0, 0, "ramdisk\n") 48 | dev.ctrl_transfer(0x21, 4, 0, 0, 0) 49 | dev.ctrl_transfer(0x21, 3, 0, 0, "kpf_flags 1\n") 50 | dev.ctrl_transfer(0x21, 4, 0, 0, 0) 51 | dev.ctrl_transfer(0x21, 3, 0, 0, "bootx\n") 52 | -------------------------------------------------------------------------------- /scripts/fetch_stdout.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2019-2021 checkra1n team 4 | # This file is part of pongoOS. 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | 25 | import sys 26 | import usb.core 27 | dev = usb.core.find(idVendor=0x05ac, idProduct=0x4141) 28 | if dev is None: 29 | raise ValueError('Device not found') 30 | dev.set_configuration() 31 | 32 | #dev.ctrl_transfer(0x21, 4, 0, 0, 0) 33 | print("".join(chr (x) for x in dev.ctrl_transfer(0xa1, 1, 0, 0, 512))) 34 | -------------------------------------------------------------------------------- /scripts/issue_cmd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2019-2021 checkra1n team 4 | # This file is part of pongoOS. 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | import sys 25 | import usb.core 26 | dev = usb.core.find(idVendor=0x05ac, idProduct=0x4141) 27 | if dev is None: 28 | raise ValueError('Device not found') 29 | dev.set_configuration() 30 | 31 | #dev.ctrl_transfer(0x21, 4, 0, 0, 0) 32 | dev.ctrl_transfer(0x21, 3, 0, 0, sys.argv[1] + "\n") 33 | -------------------------------------------------------------------------------- /scripts/load_linux.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import usb.core 3 | import struct 4 | import sys 5 | import argparse 6 | import time 7 | 8 | parser = argparse.ArgumentParser(description='A little Linux kernel/initrd uploader for pongoOS.') 9 | 10 | parser.add_argument('-k', '--kernel', dest='kernel', help='path to kernel image') 11 | parser.add_argument('-d', '--dtbpack', dest='dtbpack', help='path to dtbpack') 12 | parser.add_argument('-r', '--initrd', dest='initrd', help='path to initial ramdisk') 13 | parser.add_argument('-c', '--cmdline', dest='cmdline', help='custom kernel command line') 14 | 15 | args = parser.parse_args() 16 | 17 | if args.kernel is None: 18 | print(f"error: No kernel specified! Run `{sys.argv[0]} --help` for usage.") 19 | exit(1) 20 | 21 | if args.dtbpack is None: 22 | print(f"error: No dtbpack specified! Run `{sys.argv[0]} --help` for usage.") 23 | exit(1) 24 | 25 | dev = usb.core.find(idVendor=0x05ac, idProduct=0x4141) 26 | if dev is None: 27 | print("Waiting for device...") 28 | 29 | while dev is None: 30 | dev = usb.core.find(idVendor=0x05ac, idProduct=0x4141) 31 | if dev is not None: 32 | dev.set_configuration() 33 | break 34 | time.sleep(2) 35 | else: 36 | dev.set_configuration() 37 | 38 | kernel = open(args.kernel, "rb").read() 39 | fdt = open(args.dtbpack, "rb").read() 40 | 41 | if args.cmdline is not None: 42 | dev.ctrl_transfer(0x21, 4, 0, 0, 0) 43 | dev.ctrl_transfer(0x21, 3, 0, 0, f"linux_cmdline {args.cmdline}\n") 44 | 45 | if args.initrd is not None: 46 | print("Loading initial ramdisk...") 47 | initrd = open(args.initrd, "rb").read() 48 | initrd_size = len(initrd) 49 | dev.ctrl_transfer(0x21, 2, 0, 0, 0) 50 | dev.ctrl_transfer(0x21, 1, 0, 0, struct.pack('I', initrd_size)) 51 | 52 | dev.write(2, initrd, 1000000) 53 | dev.ctrl_transfer(0x21, 4, 0, 0, 0) 54 | dev.ctrl_transfer(0x21, 3, 0, 0, "ramdisk\n") 55 | print("Initial ramdisk loaded successfully.") 56 | 57 | print("Loading device tree...") 58 | dev.ctrl_transfer(0x21, 2, 0, 0, 0) 59 | dev.ctrl_transfer(0x21, 1, 0, 0, 0) 60 | dev.write(2, fdt) 61 | 62 | dev.ctrl_transfer(0x21, 4, 0, 0, 0) 63 | dev.ctrl_transfer(0x21, 3, 0, 0, "fdt\n") 64 | print("Device tree loaded successfully.") 65 | 66 | print("Loading kernel...") 67 | kernel_size = len(kernel) 68 | dev.ctrl_transfer(0x21, 2, 0, 0, 0) 69 | dev.ctrl_transfer(0x21, 1, 0, 0, struct.pack('I', kernel_size)) 70 | 71 | dev.write(2, kernel, 1000000) 72 | print("Kernel loaded successfully.") 73 | 74 | dev.ctrl_transfer(0x21, 4, 0, 0, 0) 75 | 76 | print("Booting...") 77 | try: 78 | dev.ctrl_transfer(0x21, 3, 0, 0, "bootl\n") 79 | except: 80 | # if the device disconnects without acknowledging it usually means it succeeded 81 | print("Success.") 82 | -------------------------------------------------------------------------------- /scripts/module_load.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2019-2021 checkra1n team 4 | # This file is part of pongoOS. 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | import struct 25 | import sys 26 | data = open(sys.argv[1], "rb").read() 27 | import usb.core 28 | dev = usb.core.find(idVendor=0x05ac, idProduct=0x4141) 29 | if dev is None: 30 | raise ValueError('Device not found') 31 | dev.set_configuration() 32 | 33 | dev.ctrl_transfer(0x21, 2, 0, 0, 0) 34 | dev.ctrl_transfer(0x21, 1, 0, 0, struct.pack('I', len(data))) 35 | dev.write(2,data,100000) 36 | if len(data) % 512 == 0: 37 | dev.write(2,"") 38 | dev.ctrl_transfer(0x21, 3, 0, 0, "modload\n") 39 | -------------------------------------------------------------------------------- /scripts/module_load_boot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2019-2021 checkra1n team 4 | # This file is part of pongoOS. 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | import sys 25 | data = open(sys.argv[1], "rb").read() 26 | import usb.core 27 | dev = usb.core.find(idVendor=0x05ac, idProduct=0x4141) 28 | if dev is None: 29 | raise ValueError('Device not found') 30 | dev.set_configuration() 31 | 32 | dev.ctrl_transfer(0x21, 2, 0, 0, 0) 33 | dev.ctrl_transfer(0x21, 1, 0, 0, 0) 34 | dev.write(2,data,100000) 35 | if len(data) % 512 == 0: 36 | dev.write(2,"") 37 | dev.ctrl_transfer(0x21, 3, 0, 0, "modload\n") 38 | dev.ctrl_transfer(0x21, 3, 0, 0, "bootx\n") 39 | -------------------------------------------------------------------------------- /scripts/upload_data.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2019-2021 checkra1n team 4 | # This file is part of pongoOS. 5 | # 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy 7 | # of this software and associated documentation files (the "Software"), to deal 8 | # in the Software without restriction, including without limitation the rights 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | # copies of the Software, and to permit persons to whom the Software is 11 | # furnished to do so, subject to the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be included in all 14 | # copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | # SOFTWARE. 23 | # 24 | import struct 25 | import sys 26 | data = open(sys.argv[1], "rb").read() 27 | import usb.core 28 | dev = usb.core.find(idVendor=0x05ac, idProduct=0x4141) 29 | if dev is None: 30 | raise ValueError('Device not found') 31 | dev.set_configuration() 32 | 33 | dev.ctrl_transfer(0x21, 2, 0, 0, 0) 34 | dev.ctrl_transfer(0x21, 1, 0, 0, struct.pack('I', len(data))) 35 | dev.write(2,data,1000000) 36 | -------------------------------------------------------------------------------- /src/boot/clearhook.S: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | .globl _clear_hook 28 | .globl _clear_hook_end 29 | .globl _clear_hook_orig_backing 30 | 31 | 32 | .align 4 33 | _clear_hook: 34 | mov x16, x30 35 | mov x30, x5 36 | mov x3, #0x800000000 37 | movk x3, #0x1800, lsl#16 38 | cmp x0, x3 39 | b.hi _clear_hook_orig_backing 40 | add x2, x1, x0 41 | cmp x2, x3 42 | b.lo _clear_hook_orig_backing 43 | mov x3, #0x800000000 44 | movk x3, #0x18e0, lsl#16 45 | cmp x0, x3 46 | b.hi _clear_hook_orig_backing 47 | add x2, x1, x0 48 | cmp x2, x3 49 | b.lo _clear_hook_orig_backing 50 | mov x1, #0 51 | _clear_hook_orig_backing: 52 | nop 53 | nop 54 | br x16 55 | _clear_hook_end: 56 | -------------------------------------------------------------------------------- /src/boot/jump_to_image.S: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | .align 2 28 | .global _jump_to_image 29 | _jump_to_image: 30 | mov x30, x0 31 | mov x0, x1 32 | isb 33 | dsb sy 34 | ic iallu 35 | dsb sy 36 | isb 37 | mov x1, xzr 38 | mov x2, xzr 39 | mov x3, xzr 40 | ret 41 | 42 | .global _jump_to_image_extended 43 | _jump_to_image_extended: 44 | mov x30, x0 45 | mov x0, x1 46 | mov x8, x2 47 | isb 48 | dsb sy 49 | ic iallu 50 | dsb sy 51 | isb 52 | mov x1, xzr 53 | mov x2, xzr 54 | mov x3, xzr 55 | ret 56 | 57 | .global _tramp_hook 58 | _tramp_hook: 59 | mov x8, x27 60 | mov x9, x29 61 | mov x27, #0x800000000 62 | movk x27, #0x1800, lsl#16 63 | add x29, x27, #0x4 64 | -------------------------------------------------------------------------------- /src/boot/libc_workarounds.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #define strcpy strcpy_ 28 | #define memcpy memcpy_ 29 | #define strcmp strcmp_ 30 | #define strlen strlen_ 31 | 32 | char* strcpy_(char* to, const char* from) 33 | { 34 | char cur = 0; 35 | while ((cur = (*from++))) 36 | *to++ = cur; 37 | *to++ = 0; 38 | return to; // i know this is not up to spec but who uses the return value of strcpy anyway lmao 39 | } 40 | 41 | void* memcpy_(void* dst, const void* src, unsigned long n) 42 | { 43 | while (n) { 44 | *(char*)dst++ = *(char*)src++; 45 | n--; 46 | } 47 | return dst; // i know this is not up to spec but who uses the return value of memcpy anyway lmao 48 | } 49 | 50 | int strcmp_(const char* s1, const char* s2) 51 | { 52 | while (*s1 && (*s1 == *s2)) 53 | s1++, s2++; 54 | return *(const unsigned char*)s1 - *(const unsigned char*)s2; 55 | } 56 | 57 | unsigned long strlen_(const char* str) 58 | { 59 | unsigned long rv = 0; 60 | while (*str++) 61 | rv++; 62 | return rv; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/boot/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | extern void stage3_exit_to_el1_image(void* boot_args, void* boot_entry_point); 29 | extern void* gboot_args; 30 | extern void* gboot_entry_point; 31 | void main (void) { 32 | // hypv or kernel 33 | if (*(uint8_t*)(gboot_args + 8 + 7)) { 34 | // kernel 35 | pongo_entry((uint64_t*)gboot_args, gboot_entry_point, stage3_exit_to_el1_image); 36 | } else { 37 | // hypv 38 | pongo_entry(*(uint64_t**)(gboot_args + 0x20), (void*)*(uint64_t*)(gboot_args + 0x28), stage3_exit_to_el1_image); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/drivers/aes/aes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #ifndef AES_H 28 | #define AES_H 29 | 30 | #include 31 | #include 32 | 33 | #define AES_ALL_MASK (AES_MODE_MASK | AES_CIPHER_MASK | AES_BITS_MASK | AES_KEY_MASK) 34 | 35 | #define AES_ENCRYPT 0x00000000 36 | #define AES_DECRYPT 0x80000000 37 | #define AES_MODE_MASK 0x80000000 38 | 39 | #define AES_CBC 0x00000000 40 | #define AES_ECB 0x40000000 41 | #define AES_CIPHER_MASK 0x40000000 42 | 43 | #define AES_128 0x10000000 44 | #define AES_192 0x20000000 45 | #define AES_256 0x30000000 46 | #define AES_BITS_MASK 0x30000000 47 | 48 | #define AES_USER_KEY 0x00000000 49 | #define AES_UID 0x00000001 50 | #define AES_GID0 0x00000002 51 | #define AES_GID1 0x00000003 52 | #define AES_KEY_MASK 0x00000003 53 | 54 | // Return value of 0 = success. 55 | // Any other return value is an error from . 56 | int aes(uint32_t op, const void *src, void *dst, size_t len, const void *iv, const void *key); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/drivers/aes/aes_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #ifndef AES_PRIVATE_H 28 | #define AES_PRIVATE_H 29 | 30 | #ifdef PONGO_PRIVATE 31 | 32 | #include 33 | #include 34 | 35 | void aes_init(void); 36 | void aes_a7_init(void); 37 | void aes_a9_init(void); 38 | int aes_a7(uint32_t op, const void *src, void *dst, size_t len, const void *iv, const void *key); 39 | int aes_a9(uint32_t op, const void *src, void *dst, size_t len, const void *iv, const void *key); 40 | 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/drivers/framebuffer/fb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | #define SCALE_FACTOR scale_factor 30 | #define LEFT_MARGIN 4 * scale_factor 31 | 32 | extern char overflow_mode; 33 | extern uint32_t* gFramebuffer; 34 | extern uint32_t gWidth; 35 | extern uint32_t gHeight; 36 | extern uint32_t gRowPixels; 37 | extern uint32_t y_cursor; 38 | extern uint32_t x_cursor; 39 | extern uint8_t scale_factor; 40 | 41 | void screen_init(); 42 | void screen_puts(const char* str); 43 | void screen_write(const char* str); 44 | void screen_putc(uint8_t c); 45 | void screen_clear_row(); 46 | void screen_mark_banner(); 47 | void screen_fill_basecolor(); 48 | void screen_fill(uint32_t color); 49 | -------------------------------------------------------------------------------- /src/drivers/gpio/gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | void gpio_main() { 30 | while(1) { 31 | iprintf("gpio irq %x\n", task_current()->irq_type); 32 | task_exit_irq(); 33 | } 34 | } 35 | struct task gpio_task = {.name = "gpio"}; 36 | 37 | uint64_t gGpioBase; 38 | void gpio_early_init() { 39 | gGpioBase = dt_get_u32_prop("gpio", "reg"); 40 | gGpioBase += gIOBase; 41 | } 42 | 43 | void gpio_init() { 44 | /* 45 | uint32_t len = 0; 46 | dt_node_t* buttons = dt_find(gDeviceTree, "buttons"); 47 | if (!buttons) panic("invalid devicetree: no buttons!"); 48 | uint32_t* interrupts = dt_prop(buttons, "interrupts", &len); 49 | if (!interrupts) panic("invalid devicetree: no interrupts!"); 50 | 51 | for (int i=0; i 28 | 29 | static bool s5l8960_probe(struct hal_platform_driver* device_driver, struct hal_platform* device) { 30 | if (device->cpid == 0x8960) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | static struct usb_regs s5l8960_usb_regs = { 37 | .reg1 = 0x0e020158, 38 | .reg2 = 0x0e020160, 39 | .reg3 = 0x0e020188, 40 | .otg_irq = 162 41 | }; 42 | 43 | static bool s5l8960_get_platform_value(const char* name, void* value, size_t* size) { 44 | if (strcmp(name, "usb_regs") == 0 && *size == sizeof(struct usb_regs)) { 45 | memcpy(value, &s5l8960_usb_regs, sizeof(struct usb_regs)); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | static struct hal_platform_driver s5l8960_plat = { 52 | .name = "Apple A7 (S5L8960)", 53 | .context = NULL, 54 | .probe = s5l8960_probe, 55 | .get_platform_value = s5l8960_get_platform_value 56 | }; 57 | 58 | static void s5l8960_init(struct driver* driver) { 59 | hal_register_platform_driver(&s5l8960_plat); 60 | } 61 | 62 | REGISTER_DRIVER(s5l8960, s5l8960_init, NULL, DRIVER_FLAGS_PLATFORM); 63 | -------------------------------------------------------------------------------- /src/drivers/plat/s8000.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #import 28 | 29 | static bool s8000_probe(struct hal_platform_driver* device_driver, struct hal_platform* device) { 30 | if (device->cpid == 0x8000) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | static struct usb_regs s8000_usb_regs = { 37 | .reg1 = 0x0e080250, 38 | .reg2 = 0x0e080258, 39 | .reg3 = 0x0e080290, 40 | .otg_irq = 214 41 | }; 42 | 43 | static bool s8000_get_platform_value(const char* name, void* value, size_t* size) { 44 | if (strcmp(name, "usb_regs") == 0 && *size == sizeof(struct usb_regs)) { 45 | memcpy(value, &s8000_usb_regs, sizeof(struct usb_regs)); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | static struct hal_platform_driver s8000_plat = { 52 | .name = "Apple A9 (S8000, Samsung)", 53 | .context = NULL, 54 | .probe = s8000_probe, 55 | .get_platform_value = s8000_get_platform_value 56 | }; 57 | 58 | static void s8000_init(struct driver* driver) { 59 | hal_register_platform_driver(&s8000_plat); 60 | } 61 | 62 | REGISTER_DRIVER(s8000, s8000_init, NULL, DRIVER_FLAGS_PLATFORM); 63 | -------------------------------------------------------------------------------- /src/drivers/plat/s8001.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #import 28 | 29 | static bool s8001_probe(struct hal_platform_driver* device_driver, struct hal_platform* device) { 30 | if (device->cpid == 0x8001) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | static struct usb_regs s8001_usb_regs = { 37 | .reg1 = 0x0e080278, 38 | .reg2 = 0x0e080280, 39 | .reg3 = 0x0e0802B8, 40 | .otg_irq = 241 41 | }; 42 | 43 | static bool s8001_get_platform_value(const char* name, void* value, size_t* size) { 44 | if (strcmp(name, "usb_regs") == 0 && *size == sizeof(struct usb_regs)) { 45 | memcpy(value, &s8001_usb_regs, sizeof(struct usb_regs)); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | static struct hal_platform_driver s8001_plat = { 52 | .name = "Apple A9X (S8001)", 53 | .context = NULL, 54 | .probe = s8001_probe, 55 | .get_platform_value = s8001_get_platform_value 56 | }; 57 | 58 | static void s8001_init(struct driver* driver) { 59 | hal_register_platform_driver(&s8001_plat); 60 | } 61 | 62 | REGISTER_DRIVER(s8001, s8001_init, NULL, DRIVER_FLAGS_PLATFORM); 63 | -------------------------------------------------------------------------------- /src/drivers/plat/s8003.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #import 28 | 29 | static bool s8003_probe(struct hal_platform_driver* device_driver, struct hal_platform* device) { 30 | if (device->cpid == 0x8003) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | static struct usb_regs s8003_usb_regs = { 37 | .reg1 = 0x0e080250, 38 | .reg2 = 0x0e080258, 39 | .reg3 = 0x0e080290, 40 | .otg_irq = 214 41 | }; 42 | 43 | static bool s8003_get_platform_value(const char* name, void* value, size_t* size) { 44 | if (strcmp(name, "usb_regs") == 0 && *size == sizeof(struct usb_regs)) { 45 | memcpy(value, &s8003_usb_regs, sizeof(struct usb_regs)); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | static struct hal_platform_driver s8003_plat = { 52 | .name = "Apple A9 (S8003, TSMC)", 53 | .context = NULL, 54 | .probe = s8003_probe, 55 | .get_platform_value = s8003_get_platform_value 56 | }; 57 | 58 | static void s8003_init(struct driver* driver) { 59 | hal_register_platform_driver(&s8003_plat); 60 | } 61 | 62 | REGISTER_DRIVER(s8003, s8003_init, NULL, DRIVER_FLAGS_PLATFORM); 63 | -------------------------------------------------------------------------------- /src/drivers/plat/t7000.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #import 28 | 29 | static bool t7000_probe(struct hal_platform_driver* device_driver, struct hal_platform* device) { 30 | if (device->cpid == 0x7000) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | static struct usb_regs t7000_usb_regs = { 37 | .reg1 = 0x0e020248, 38 | .reg2 = 0x0e020250, 39 | .reg3 = 0x0e020288, 40 | .otg_irq = 182 41 | }; 42 | 43 | static bool t7000_get_platform_value(const char* name, void* value, size_t* size) { 44 | if (strcmp(name, "usb_regs") == 0 && *size == sizeof(struct usb_regs)) { 45 | memcpy(value, &t7000_usb_regs, sizeof(struct usb_regs)); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | static struct hal_platform_driver t7000_plat = { 52 | .name = "Apple A8 (T7000)", 53 | .context = NULL, 54 | .probe = t7000_probe, 55 | .get_platform_value = t7000_get_platform_value 56 | }; 57 | 58 | static void t7000_init(struct driver* driver) { 59 | hal_register_platform_driver(&t7000_plat); 60 | } 61 | 62 | REGISTER_DRIVER(t7000, t7000_init, NULL, DRIVER_FLAGS_PLATFORM); 63 | -------------------------------------------------------------------------------- /src/drivers/plat/t7001.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #import 28 | 29 | static bool t7001_probe(struct hal_platform_driver* device_driver, struct hal_platform* device) { 30 | if (device->cpid == 0x7001) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | static struct usb_regs t7001_usb_regs = { 37 | .reg1 = 0x0e020248, 38 | .reg2 = 0x0e020250, 39 | .reg3 = 0x0e020288, 40 | .otg_irq = 182 41 | }; 42 | 43 | static bool t7001_get_platform_value(const char* name, void* value, size_t* size) { 44 | if (strcmp(name, "usb_regs") == 0 && *size == sizeof(struct usb_regs)) { 45 | memcpy(value, &t7001_usb_regs, sizeof(struct usb_regs)); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | static struct hal_platform_driver t7001_plat = { 52 | .name = "Apple A8X (T7001)", 53 | .context = NULL, 54 | .probe = t7001_probe, 55 | .get_platform_value = t7001_get_platform_value 56 | }; 57 | 58 | static void t7001_init(struct driver* driver) { 59 | hal_register_platform_driver(&t7001_plat); 60 | } 61 | 62 | REGISTER_DRIVER(t7001, t7001_init, NULL, DRIVER_FLAGS_PLATFORM); 63 | -------------------------------------------------------------------------------- /src/drivers/plat/t8010.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #import 28 | 29 | static bool t8010_probe(struct hal_platform_driver* device_driver, struct hal_platform* device) { 30 | if (device->cpid == 0x8010) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | static struct usb_regs t8010_usb_regs = { 37 | .reg1 = 0x0e080268, 38 | .reg2 = 0x0e080270, 39 | .reg3 = 0x0e080290, 40 | .otg_irq = 241 41 | }; 42 | 43 | static bool t8010_get_platform_value(const char* name, void* value, size_t* size) { 44 | if (strcmp(name, "usb_regs") == 0 && *size == sizeof(struct usb_regs)) { 45 | memcpy(value, &t8010_usb_regs, sizeof(struct usb_regs)); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | static struct hal_platform_driver t8010_plat = { 52 | .name = "Apple A10 (T8010)", 53 | .context = NULL, 54 | .probe = t8010_probe, 55 | .get_platform_value = t8010_get_platform_value 56 | }; 57 | 58 | static void t8010_init(struct driver* driver) { 59 | hal_register_platform_driver(&t8010_plat); 60 | } 61 | 62 | REGISTER_DRIVER(t8010, t8010_init, NULL, DRIVER_FLAGS_PLATFORM); 63 | -------------------------------------------------------------------------------- /src/drivers/plat/t8011.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #import 28 | 29 | static bool t8011_probe(struct hal_platform_driver* device_driver, struct hal_platform* device) { 30 | if (device->cpid == 0x8011) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | static struct usb_regs t8011_usb_regs = { 37 | .reg1 = 0x0e080288, 38 | .reg2 = 0x0e080290, 39 | .reg3 = 0x0e0802a0, 40 | .otg_irq = 243 41 | }; 42 | 43 | static bool t8011_get_platform_value(const char* name, void* value, size_t* size) { 44 | if (strcmp(name, "usb_regs") == 0 && *size == sizeof(struct usb_regs)) { 45 | memcpy(value, &t8011_usb_regs, sizeof(struct usb_regs)); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | static struct hal_platform_driver t8011_plat = { 52 | .name = "Apple A10X (T8011)", 53 | .context = NULL, 54 | .probe = t8011_probe, 55 | .get_platform_value = t8011_get_platform_value 56 | }; 57 | 58 | static void t8011_init(struct driver* driver) { 59 | hal_register_platform_driver(&t8011_plat); 60 | } 61 | 62 | REGISTER_DRIVER(t8011, t8011_init, NULL, DRIVER_FLAGS_PLATFORM); 63 | -------------------------------------------------------------------------------- /src/drivers/plat/t8012.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #import 28 | 29 | static bool t8012_probe(struct hal_platform_driver* device_driver, struct hal_platform* device) { 30 | if (device->cpid == 0x8012) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | static struct usb_regs t8012_usb_regs = { 37 | .reg1 = 0x0e080268, 38 | .reg2 = 0x0e080270, 39 | .reg3 = 0x0e080290, 40 | .otg_irq = 304 41 | }; 42 | 43 | static bool t8012_get_platform_value(const char* name, void* value, size_t* size) { 44 | if (strcmp(name, "usb_regs") == 0 && *size == sizeof(struct usb_regs)) { 45 | memcpy(value, &t8012_usb_regs, sizeof(struct usb_regs)); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | static struct hal_platform_driver t8012_plat = { 52 | .name = "Apple T2 (T8012)", 53 | .context = NULL, 54 | .probe = t8012_probe, 55 | .get_platform_value = t8012_get_platform_value 56 | }; 57 | 58 | static void t8012_init(struct driver* driver) { 59 | hal_register_platform_driver(&t8012_plat); 60 | } 61 | 62 | REGISTER_DRIVER(t8012, t8012_init, NULL, DRIVER_FLAGS_PLATFORM); 63 | -------------------------------------------------------------------------------- /src/drivers/plat/t8015.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #import 28 | 29 | static bool t8015_probe(struct hal_platform_driver* device_driver, struct hal_platform* device) { 30 | if (device->cpid == 0x8015) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | static struct usb_regs t8015_usb_regs = { 37 | .reg1 = 0x32080270, 38 | .reg2 = 0x32080278, 39 | .reg3 = 0x32080270, 40 | .otg_irq = 324 41 | }; 42 | 43 | static bool t8015_get_platform_value(const char* name, void* value, size_t* size) { 44 | if (strcmp(name, "usb_regs") == 0 && *size == sizeof(struct usb_regs)) { 45 | memcpy(value, &t8015_usb_regs, sizeof(struct usb_regs)); 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | static struct hal_platform_driver t8015_plat = { 52 | .name = "Apple A11 (T8015)", 53 | .context = NULL, 54 | .probe = t8015_probe, 55 | .get_platform_value = t8015_get_platform_value 56 | }; 57 | 58 | static void t8015_init(struct driver* driver) { 59 | hal_register_platform_driver(&t8015_plat); 60 | } 61 | 62 | REGISTER_DRIVER(t8015, t8015_init, NULL, DRIVER_FLAGS_PLATFORM); 63 | -------------------------------------------------------------------------------- /src/drivers/recfg/recfg_soc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | 28 | #ifndef RECFG_SOC 29 | #define RECFG_SOC 30 | 31 | void recfg_soc_sync(void); 32 | void recfg_soc_lock(void); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/drivers/recfg/recfg_soc_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | 28 | #ifndef RECFG_SOC 29 | #define RECFG_SOC 30 | 31 | #ifdef PONGO_PRIVATE 32 | 33 | void recfg_soc_setup(void); 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/drivers/sep/sep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | void sep_setup(); 28 | void sep_teardown(void); 29 | extern void (*sepfw_kpf_hook)(void* sepfw_bytes, size_t sepfw_size); 30 | -------------------------------------------------------------------------------- /src/drivers/timer/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | extern void set_timer_reg(uint64_t v); 29 | extern void set_timer_ctr(uint64_t v); 30 | 31 | void timer_enable() { 32 | set_timer_reg(1); // turn on timer 33 | 34 | } 35 | void timer_disable() { 36 | set_timer_reg(2); // turn off timer 37 | } 38 | 39 | #define LLKTRW_QUANTA 24000 // 1ms quanta 40 | char timer_inited = 0; 41 | 42 | void timer_rearm() { 43 | set_timer_ctr(LLKTRW_QUANTA); 44 | } 45 | 46 | void timer_init() { 47 | set_timer_reg(2); // turn off timer 48 | set_timer_ctr(0xfffffff); 49 | set_timer_reg(1); // turn on timer 50 | timer_inited = 1; 51 | } 52 | -------------------------------------------------------------------------------- /src/drivers/timer/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | void timer_init(); 28 | void timer_rearm(); 29 | void timer_disable(); 30 | void timer_enable(); 31 | -------------------------------------------------------------------------------- /src/drivers/tz/tz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | void tz_setup(void); 32 | void tz_lockdown(void); 33 | bool tz_blackbird(void); 34 | void *tz0_calculate_encrypted_block_addr(uint64_t offset); 35 | bool tz0_is_locked(void); 36 | uint64_t tz0_base(void); 37 | uint64_t tz0_size(void); 38 | -------------------------------------------------------------------------------- /src/drivers/uart/uart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | void serial_init(); 28 | void serial_early_init(); 29 | void serial_pinmux_init(); 30 | void serial_putc(char c); 31 | void serial_disable_rx(); 32 | void serial_enable_rx(); 33 | void uart_flush(); 34 | void serial_teardown(void); 35 | 36 | #ifdef UART_INTERNAL 37 | #define rULCON0 (*(volatile uint32_t*)(gUartBase + 0x00)) //UART 0 Line control 38 | #define rUCON0 (*(volatile uint32_t*)(gUartBase + 0x04)) //UART 0 Control 39 | #define rUFCON0 (*(volatile uint32_t*)(gUartBase + 0x08)) //UART 0 FIFO control 40 | #define rUMCON0 (*(volatile uint32_t*)(gUartBase + 0x0c)) //UART 0 Modem control 41 | #define rUTRSTAT0 (*(volatile uint32_t*)(gUartBase + 0x10)) //UART 0 Tx/Rx status 42 | #define rUERSTAT0 (*(volatile uint32_t*)(gUartBase + 0x14)) //UART 0 Rx error status 43 | #define rUFSTAT0 (*(volatile uint32_t*)(gUartBase + 0x18)) //UART 0 FIFO status 44 | #define rUMSTAT0 (*(volatile uint32_t*)(gUartBase + 0x1c)) //UART 0 Modem status 45 | #define rUTXH0 (*(volatile uint32_t*)(gUartBase + 0x20)) //UART 0 Transmission Hold 46 | #define rURXH0 (*(volatile uint32_t*)(gUartBase + 0x24)) //UART 0 Receive buffer 47 | #define rUBRDIV0 (*(volatile uint32_t*)(gUartBase + 0x28)) //UART 0 Baud rate divisor 48 | #define rUDIVSLOT0 (*(volatile uint32_t*)(gUartBase + 0x2C)) //UART 0 Baud rate divisor 49 | #define rUINTM0 (*(volatile uint32_t*)(gUartBase + 0x38)) //UART 0 Baud rate divisor 50 | 51 | #define rT8011RX (*(volatile uint32_t*)(gGpioBase + 0x2A0)) 52 | #define rT8011TX (*(volatile uint32_t*)(gGpioBase + 0x2A4)) 53 | #define UART_TX_MUX 0x8723A0 54 | #define UART_RX_MUX 0x0763A0 55 | 56 | extern uint64_t gUartBase; 57 | #endif 58 | -------------------------------------------------------------------------------- /src/drivers/usb/synopsys_otg_regs.h: -------------------------------------------------------------------------------- 1 | // 2 | // Project: KTRW 3 | // Author: Brandon Azad 4 | // 5 | // Copyright 2019 Google LLC 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | 20 | #ifndef SYNOPSYS_OTG_REGS__H_ 21 | #define SYNOPSYS_OTG_REGS__H_ 22 | 23 | #ifndef SYNOPSYS_OTG_REGISTER 24 | #define SYNOPSYS_OTG_REGISTER(_x) (_x) 25 | #endif 26 | 27 | #define rGOTGCTL (SYNOPSYS_OTG_REGISTER(0x000)) 28 | #define rGOTGINT (SYNOPSYS_OTG_REGISTER(0x004)) 29 | #define rGAHBCFG (SYNOPSYS_OTG_REGISTER(0x008)) 30 | #define rGUSBCFG (SYNOPSYS_OTG_REGISTER(0x00c)) 31 | #define rGRSTCTL (SYNOPSYS_OTG_REGISTER(0x010)) 32 | #define rGINTSTS (SYNOPSYS_OTG_REGISTER(0x014)) 33 | #define rGINTMSK (SYNOPSYS_OTG_REGISTER(0x018)) 34 | #define rGRXSTSR (SYNOPSYS_OTG_REGISTER(0x01c)) 35 | #define rGRXSTSP (SYNOPSYS_OTG_REGISTER(0x020)) 36 | #define rGRXFSIZ (SYNOPSYS_OTG_REGISTER(0x024)) 37 | #define rGNPTXFSIZ (SYNOPSYS_OTG_REGISTER(0x028)) 38 | #define rGNPTXSTS (SYNOPSYS_OTG_REGISTER(0x02c)) 39 | #define rGI2CCTL (SYNOPSYS_OTG_REGISTER(0x030)) 40 | #define rGPVNDCTL (SYNOPSYS_OTG_REGISTER(0x034)) 41 | #define rGGPIO (SYNOPSYS_OTG_REGISTER(0x038)) 42 | #define rGUID (SYNOPSYS_OTG_REGISTER(0x03c)) 43 | #define rGSNPSID (SYNOPSYS_OTG_REGISTER(0x040)) 44 | #define rGHWCFG1 (SYNOPSYS_OTG_REGISTER(0x044)) 45 | #define rGHWCFG2 (SYNOPSYS_OTG_REGISTER(0x048)) 46 | #define rGHWCFG3 (SYNOPSYS_OTG_REGISTER(0x04c)) 47 | #define rGHWCFG4 (SYNOPSYS_OTG_REGISTER(0x050)) 48 | #define rGLPMCFG (SYNOPSYS_OTG_REGISTER(0x054)) 49 | #define rGPWRDN (SYNOPSYS_OTG_REGISTER(0x058)) 50 | #define rGDFIFOCFG (SYNOPSYS_OTG_REGISTER(0x05c)) 51 | #define rADPCTL (SYNOPSYS_OTG_REGISTER(0x060)) 52 | 53 | #define rHPTXFSIZ (SYNOPSYS_OTG_REGISTER(0x100)) 54 | #define rDTXFSIZ(n) (SYNOPSYS_OTG_REGISTER(0x104 + 0x4 * (n - 1))) 55 | 56 | #define rHPTXSIZ (SYNOPSYS_OTG_REGISTER(0x400)) 57 | 58 | #define rHPRT0 (SYNOPSYS_OTG_REGISTER(0x440)) 59 | 60 | #define rDCFG (SYNOPSYS_OTG_REGISTER(0x800)) 61 | #define rDCTL (SYNOPSYS_OTG_REGISTER(0x804)) 62 | #define rDSTS (SYNOPSYS_OTG_REGISTER(0x808)) 63 | #define rDIEPMSK (SYNOPSYS_OTG_REGISTER(0x810)) 64 | #define rDOEPMSK (SYNOPSYS_OTG_REGISTER(0x814)) 65 | #define rDAINT (SYNOPSYS_OTG_REGISTER(0x818)) 66 | #define rDAINTMSK (SYNOPSYS_OTG_REGISTER(0x81c)) 67 | 68 | #define rDIEPCTL(ep) (SYNOPSYS_OTG_REGISTER(0x900 + 0x20 * ep)) 69 | #define rDIEPINT(ep) (SYNOPSYS_OTG_REGISTER(0x908 + 0x20 * ep)) 70 | #define rDIEPTSIZ(ep) (SYNOPSYS_OTG_REGISTER(0x910 + 0x20 * ep)) 71 | #define rDIEPDMA(ep) (SYNOPSYS_OTG_REGISTER(0x914 + 0x20 * ep)) 72 | #define rDTXFSTS(ep) (SYNOPSYS_OTG_REGISTER(0x918 + 0x20 * ep)) 73 | #define rDIEPDMAB(ep) (SYNOPSYS_OTG_REGISTER(0x91c + 0x20 * ep)) 74 | 75 | #define rDOEPCTL(ep) (SYNOPSYS_OTG_REGISTER(0xb00 + 0x20 * ep)) 76 | #define rDOEPINT(ep) (SYNOPSYS_OTG_REGISTER(0xb08 + 0x20 * ep)) 77 | #define rDOEPTSIZ(ep) (SYNOPSYS_OTG_REGISTER(0xb10 + 0x20 * ep)) 78 | #define rDOEPDMA(ep) (SYNOPSYS_OTG_REGISTER(0xb14 + 0x20 * ep)) 79 | #define rDOEPDMAB(ep) (SYNOPSYS_OTG_REGISTER(0xb1c + 0x20 * ep)) 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/drivers/xnu/xnu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | extern void xnu_boot(void); 28 | extern void xnu_init(void); 29 | extern void xnu_loadrd(void); 30 | extern void xnu_hook(void); 31 | -------------------------------------------------------------------------------- /src/kernel/dtree_getprop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | uint32_t dt_get_u32_prop(const char* device, const char* prop) { 30 | uint32_t rval = 0; 31 | uint32_t len = 0; 32 | dt_node_t* dev = dt_find(gDeviceTree, device); 33 | if (!dev) panic("invalid devicetree: no device!"); 34 | uint32_t* val = dt_prop(dev, prop, &len); 35 | if (!val) panic("invalid devicetree: no prop!"); 36 | memcpy(&rval, &val[0], 4); 37 | return rval; 38 | } 39 | uint64_t dt_get_u64_prop(const char* device, const char* prop) { 40 | uint64_t rval = 0; 41 | uint32_t len = 0; 42 | dt_node_t* dev = dt_find(gDeviceTree, device); 43 | if (!dev) panic("invalid devicetree: no device!"); 44 | uint64_t* val = dt_prop(dev, prop, &len); 45 | if (!val) panic("invalid devicetree: no prop!"); 46 | memcpy(&rval, &val[0], 8); 47 | return rval; 48 | } 49 | uint64_t dt_get_u64_prop_i(const char* device, const char* prop, uint32_t idx) { 50 | uint64_t rval = 0; 51 | uint32_t len = 0; 52 | dt_node_t* dev = dt_find(gDeviceTree, device); 53 | if (!dev) panic("invalid devicetree: no device!"); 54 | uint64_t* val = dt_prop(dev, prop, &len); 55 | if (!val) panic("invalid devicetree: no prop!"); 56 | memcpy(&rval, &val[idx], 8); 57 | return rval; 58 | } 59 | void* dt_get_prop(const char* device, const char* prop, uint32_t* size) { 60 | uint32_t len = 0; 61 | dt_node_t* dev = dt_find(gDeviceTree, device); 62 | if (!dev) panic("invalid devicetree: no device!"); 63 | void* val = dt_prop(dev, prop, &len); 64 | if (!val) panic("invalid devicetree: no prop!"); 65 | if (size) *size = len; 66 | return val; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/kernel/legacy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | #include 29 | // Legacy support - this was exported to modules 30 | 31 | void print_register(uint64_t value) 32 | { 33 | iprintf("0x%016llx\n", value); 34 | } 35 | 36 | void command_puts(const char* c) 37 | { 38 | puts(c); 39 | } 40 | 41 | void command_putc(char c) 42 | { 43 | putc(c, stdout); 44 | } 45 | 46 | void* memstr(const void* big, unsigned long blength, const char* little) 47 | { 48 | return memmem(big, blength, (void*)little, strlen(little) + 1); 49 | } 50 | void* memstr_partial(const void* big, unsigned long blength, const char* little) 51 | { 52 | return memmem(big, blength, (void*)little, strlen(little)); 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/kernel/main_task.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | #include 29 | #include 30 | 31 | void shell_main(); 32 | 33 | /* 34 | 35 | Name: pongo_main_task 36 | Description: main task handler 37 | 38 | */ 39 | 40 | uint64_t gBootTimeTicks; 41 | void pongo_main_task() { 42 | gBootTimeTicks = get_ticks(); 43 | 44 | // Setup GPIO Base 45 | gpio_early_init(); 46 | 47 | // Setup serial pinmux 48 | serial_pinmux_init(); 49 | 50 | // Enable serial TX 51 | serial_early_init(); 52 | 53 | // Setup HAL 54 | hal_init(); 55 | 56 | // Turn on IRQ controller 57 | interrupt_init(); 58 | 59 | // Enable IRQ serial RX 60 | serial_init(); 61 | 62 | // Initialize pmgr 63 | pmgr_init(); 64 | 65 | /* 66 | Initialize display 67 | */ 68 | mipi_init(); 69 | 70 | /* 71 | Initialize TrustZone drivers 72 | */ 73 | tz_setup(); 74 | 75 | // Relieve WDT of its duty 76 | wdt_disable(); 77 | 78 | // Recfg stuff 79 | recfg_soc_setup(); 80 | 81 | // Set up AES 82 | aes_init(); 83 | 84 | // Set up Secure Enclave 85 | sep_setup(); 86 | 87 | puts(""); 88 | puts("#=================="); 89 | puts("#"); 90 | puts("# pongoOS " PONGO_VERSION); 91 | puts("#"); 92 | puts("# https://checkra.in"); 93 | puts("#"); 94 | puts("#=================="); 95 | screen_mark_banner(); 96 | 97 | iprintf("Booted by: %s\n", (const char*)dt_get_prop("chosen", "firmware-version", NULL)); 98 | strcpy(dt_get_prop("chosen", "firmware-version", NULL), "pongoOS-"); 99 | strcat(dt_get_prop("chosen", "firmware-version", NULL), PONGO_VERSION); 100 | #ifdef __clang__ 101 | iprintf("Built with: Clang %s\n", __clang_version__); 102 | #else 103 | iprintf("Built with: GCC %s\n", __VERSION__); 104 | #endif 105 | iprintf("Running on: %s\n", hal_platform_name()); 106 | 107 | shell_main(); 108 | } 109 | -------------------------------------------------------------------------------- /src/kernel/panic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | #include 29 | #include 30 | char preemption_over; 31 | 32 | char panic_did_enter = 0; 33 | void panic(const char* str, ...) { 34 | disable_interrupts(); 35 | 36 | if (panic_did_enter) { 37 | iprintf("\ndouble panic: %s\n", str); 38 | while(1) {} 39 | } 40 | panic_did_enter = 1; 41 | preemption_over = 1; 42 | 43 | va_list va; 44 | va_start(va, str); 45 | iprintf("\npanic: "); 46 | viprintf(str, va); 47 | va_end(va); 48 | 49 | struct task *t = task_current(); 50 | 51 | iprintf("\ncrashed task: "); 52 | if (t && t->name[0]) 53 | puts(t->name); 54 | else puts("unknown"); 55 | iprintf("\ncrashed process: "); 56 | if (t && t->proc && t->proc->name[0]) 57 | puts(t->proc->name); 58 | else puts("unknown"); 59 | int depth = 0; 60 | 61 | iprintf("\nCall stack:\n"); 62 | uint64_t fpcopy[2]; 63 | for(uint64_t *fp = __builtin_frame_address(0); fp; fp = (uint64_t*)fpcopy[0]) 64 | { 65 | if (memcpy_trap(fpcopy, fp, 0x10) == 0x10) { 66 | iprintf("0x%016llx: fp 0x%016llx, lr 0x%016llx\n", ((uint64_t)fp), fpcopy[0], fpcopy[1]); 67 | } else { 68 | iprintf("couldn't access frame at %016llx, stopping here..,\n", (uint64_t)fp); 69 | break; 70 | } 71 | depth++; 72 | if (depth > 64) { 73 | iprintf("stack depth too large, stopping here...\n"); 74 | } 75 | } 76 | 77 | sleep(5); 78 | wdt_reset(); 79 | } 80 | -------------------------------------------------------------------------------- /src/kernel/support/exit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | int _exit() { 30 | task_exit(); 31 | return -1; // should never be reached, ever. 32 | } 33 | -------------------------------------------------------------------------------- /src/kernel/support/malloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | void __malloc_lock(struct _reent * unused) { 30 | disable_interrupts(); 31 | } 32 | 33 | void __malloc_unlock(struct _reent * unused) { 34 | enable_interrupts(); 35 | } 36 | -------------------------------------------------------------------------------- /src/kernel/support/process.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | #include 29 | 30 | pid_t _getpid(void) 31 | { 32 | return task_current()->pid; 33 | } 34 | 35 | int _kill(pid_t pid, int sig) 36 | { 37 | return ENOTSUP; 38 | } 39 | -------------------------------------------------------------------------------- /src/kernel/support/sbrk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | uint64_t heap_base = 0xe00000000; 30 | uint64_t heap_cursor = 0xe00000000; 31 | uint64_t heap_end = 0xe00000000; 32 | extern struct vm_space kernel_vm_space; 33 | caddr_t _sbrk(int size) { 34 | disable_interrupts(); 35 | uint64_t cursor_copy = heap_cursor; 36 | heap_cursor += size; 37 | while (heap_cursor > heap_end) { 38 | vm_space_map_page_physical_prot(&kernel_vm_space, heap_end, ppage_alloc(), PROT_READ|PROT_WRITE|PROT_KERN_ONLY); 39 | heap_end += 0x4000; 40 | } 41 | enable_interrupts(); 42 | return (caddr_t)cursor_copy; 43 | } 44 | -------------------------------------------------------------------------------- /src/kernel/syscall.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | #define SYSCALL(name, handlerf) {.handler = handlerf, .sysc_name = name} 30 | struct uap { 31 | uint64_t u64_arguments[7]; 32 | uint64_t* state; 33 | }; 34 | struct syscall_table { 35 | int (*handler)(struct task* task, struct uap* uap); 36 | char* sysc_name; 37 | }; 38 | 39 | int sys_exit(struct task* task, struct uap* uap) { 40 | task_exit(); 41 | return 0; 42 | } 43 | 44 | int sys_crash(struct task* task, struct uap* uap) { 45 | uap->state[0x100/8] = 0x41414141; 46 | return 0; 47 | } 48 | 49 | int sys_return(struct task* task, struct uap* uap) { 50 | return 0; 51 | } 52 | 53 | int sys_kmcrash(struct task* task, struct uap* uap) { 54 | *(uint32_t*)(0xbbadbeef) = 0x41424344; 55 | return 0; 56 | } 57 | 58 | struct syscall_table sysc_table[] = { 59 | SYSCALL("exit", sys_exit), 60 | SYSCALL("crash", sys_crash), 61 | SYSCALL("return", sys_return), 62 | SYSCALL("kmcrash", sys_kmcrash), 63 | }; 64 | 65 | 66 | void pongo_syscall_entry(struct task* task, uint32_t sysnr, uint64_t* state) { 67 | enable_interrupts(); 68 | bool is_valid_svc = false; 69 | if (sysnr == 0x42) { 70 | // pongo syscall 71 | uint32_t syscall_nr = state[15] & 0xffffffff; 72 | 73 | iprintf("-> got SVC 0x%x from task %s (%p)! syscall_nr = %d\n", sysnr, task->name, task, syscall_nr); 74 | struct uap uap; 75 | memcpy(uap.u64_arguments, state, 7 * 8); 76 | uap.state = state; 77 | 78 | if (syscall_nr == 0) { 79 | syscall_nr = state[0] & 0xffffffff; 80 | memcpy(uap.u64_arguments, &state[1], 7 * 8); 81 | } 82 | syscall_nr--; 83 | 84 | state[0] = -1; 85 | 86 | if (syscall_nr < (sizeof(sysc_table) / sizeof(struct syscall_table))) { 87 | if (sysc_table[syscall_nr].handler) { 88 | state[0] = sysc_table[syscall_nr].handler(task, &uap); 89 | is_valid_svc = true; 90 | } 91 | } 92 | } 93 | if (!is_valid_svc) 94 | { 95 | task_crash("bad syscall from task |%s|\n", task->name); 96 | } 97 | disable_interrupts(); 98 | } 99 | -------------------------------------------------------------------------------- /src/kernel/vfs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include "vfs.h" 28 | void filetable_reference(struct filetable* filetable) { 29 | if (!filetable) return; 30 | __atomic_fetch_add(&filetable->refcount, 1, __ATOMIC_SEQ_CST); 31 | } 32 | void filetable_release(struct filetable* filetable) { 33 | if (!filetable) return; 34 | uint32_t refcount = __atomic_fetch_sub(&filetable->refcount, 1, __ATOMIC_SEQ_CST); 35 | if (refcount == 1) { 36 | #if DEBUG_REFCOUNT 37 | fiprintf(stderr, "freeing filetable: %p\n", filetable); 38 | #endif 39 | for (uint32_t i=0; i < filetable->file_count; i++) { 40 | filedesc_release(filetable->file_table[i]); 41 | } 42 | free(filetable->file_table); 43 | free(filetable); 44 | } 45 | } 46 | void filedesc_reference(struct filedesc* fd) { 47 | if (!fd) return; 48 | __atomic_fetch_add(&fd->refcount, 1, __ATOMIC_SEQ_CST); 49 | } 50 | void filedesc_release(struct filedesc* fd) { 51 | if (!fd) return; 52 | uint32_t refcount = __atomic_fetch_sub(&fd->refcount, 1, __ATOMIC_SEQ_CST); 53 | if (refcount == 1) { 54 | file_release(fd->file); 55 | free(fd); 56 | } 57 | } 58 | void file_reference(struct file* file) { 59 | if (!file) return; 60 | __atomic_fetch_add(&file->refcount, 1, __ATOMIC_SEQ_CST); 61 | } 62 | void file_release(struct file* file) { 63 | if (!file) return; 64 | uint32_t refcount = __atomic_fetch_sub(&file->refcount, 1, __ATOMIC_SEQ_CST); 65 | if (refcount == 1) { 66 | free(file); 67 | } 68 | } 69 | struct file* file_create() { 70 | struct file* file = malloc(sizeof(struct file)); 71 | bzero(file, sizeof(struct file)); 72 | file->refcount = 1; 73 | return file; 74 | } 75 | struct filedesc* filedesc_create(struct file* file) { 76 | struct filedesc* filedesc = malloc(sizeof(struct filedesc)); 77 | bzero(filedesc, sizeof(struct filedesc)); 78 | file_reference(file); 79 | filedesc->file = file; 80 | filedesc->refcount = 1; 81 | return filedesc; 82 | } 83 | struct filetable* filetable_create(uint32_t size) { 84 | struct filetable* filetable = malloc(sizeof(struct filetable)); 85 | bzero(filetable, sizeof(struct filetable)); 86 | if (size > FILETABLE_MAX_SIZE) panic("filetable_create called with huge size"); 87 | filetable->file_table = calloc(sizeof(struct filedesc*), size); 88 | filetable->refcount = 1; 89 | return filetable; 90 | } 91 | -------------------------------------------------------------------------------- /src/kernel/vfs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #ifndef vfs_h 28 | #define vfs_h 29 | 30 | #include 31 | 32 | #define FILETABLE_MAX_SIZE 512 33 | 34 | struct file; 35 | 36 | struct fileops { 37 | void (*initialize)(struct file* file); 38 | void (*destroy)(struct file* file); 39 | }; 40 | 41 | struct vnode { 42 | 43 | }; 44 | 45 | struct file { 46 | lock lock; 47 | uint32_t refcount; 48 | struct fileops* fileops; 49 | void* fileinfo; 50 | }; 51 | 52 | struct filedesc { 53 | struct file* file; 54 | uint32_t refcount; 55 | }; 56 | 57 | struct filetable { 58 | struct filedesc** file_table; 59 | uint32_t file_count; 60 | uint32_t refcount; 61 | }; 62 | 63 | void filetable_reference(struct filetable* filetable); 64 | void filetable_release(struct filetable* filetable); 65 | 66 | void filedesc_reference(struct filedesc* filetable); 67 | void filedesc_release(struct filedesc* filetable); 68 | 69 | void file_reference(struct file* filetable); 70 | void file_release(struct file* filetable); 71 | 72 | struct file* file_create(); 73 | struct filedesc* filedesc_create(struct file* file); 74 | struct filetable* filetable_create(uint32_t size); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /src/lib/libDER/asn1Types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2007,2011,2014 Apple Inc. All Rights Reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | 25 | /* 26 | * asn1Types.h - ASN.1/DER #defines - strictly hard coded per the real world 27 | * 28 | */ 29 | 30 | #ifndef _ASN1_TYPES_H_ 31 | #define _ASN1_TYPES_H_ 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* copied from libsecurity_asn1 project */ 38 | 39 | #define ASN1_BOOLEAN 0x01 40 | #define ASN1_INTEGER 0x02 41 | #define ASN1_BIT_STRING 0x03 42 | #define ASN1_OCTET_STRING 0x04 43 | #define ASN1_NULL 0x05 44 | #define ASN1_OBJECT_ID 0x06 45 | #define ASN1_OBJECT_DESCRIPTOR 0x07 46 | /* External type and instance-of type 0x08 */ 47 | #define ASN1_REAL 0x09 48 | #define ASN1_ENUMERATED 0x0a 49 | #define ASN1_EMBEDDED_PDV 0x0b 50 | #define ASN1_UTF8_STRING 0x0c 51 | /* 0x0d */ 52 | /* 0x0e */ 53 | /* 0x0f */ 54 | #define ASN1_SEQUENCE 0x10 55 | #define ASN1_SET 0x11 56 | #define ASN1_NUMERIC_STRING 0x12 57 | #define ASN1_PRINTABLE_STRING 0x13 58 | #define ASN1_T61_STRING 0x14 59 | #define ASN1_VIDEOTEX_STRING 0x15 60 | #define ASN1_IA5_STRING 0x16 61 | #define ASN1_UTC_TIME 0x17 62 | #define ASN1_GENERALIZED_TIME 0x18 63 | #define ASN1_GRAPHIC_STRING 0x19 64 | #define ASN1_VISIBLE_STRING 0x1a 65 | #define ASN1_GENERAL_STRING 0x1b 66 | #define ASN1_UNIVERSAL_STRING 0x1c 67 | /* 0x1d */ 68 | #define ASN1_BMP_STRING 0x1e 69 | #define ASN1_HIGH_TAG_NUMBER 0x1f 70 | #define ASN1_TELETEX_STRING ASN1_T61_STRING 71 | 72 | #ifdef DER_MULTIBYTE_TAGS 73 | 74 | #define ASN1_TAG_MASK ((DERTag)~0) 75 | #define ASN1_TAGNUM_MASK ((DERTag)~((DERTag)7 << (sizeof(DERTag) * 8 - 3))) 76 | 77 | #define ASN1_METHOD_MASK ((DERTag)1 << (sizeof(DERTag) * 8 - 3)) 78 | #define ASN1_PRIMITIVE ((DERTag)0 << (sizeof(DERTag) * 8 - 3)) 79 | #define ASN1_CONSTRUCTED ((DERTag)1 << (sizeof(DERTag) * 8 - 3)) 80 | 81 | #define ASN1_CLASS_MASK ((DERTag)3 << (sizeof(DERTag) * 8 - 2)) 82 | #define ASN1_UNIVERSAL ((DERTag)0 << (sizeof(DERTag) * 8 - 2)) 83 | #define ASN1_APPLICATION ((DERTag)1 << (sizeof(DERTag) * 8 - 2)) 84 | #define ASN1_CONTEXT_SPECIFIC ((DERTag)2 << (sizeof(DERTag) * 8 - 2)) 85 | #define ASN1_PRIVATE ((DERTag)3 << (sizeof(DERTag) * 8 - 2)) 86 | 87 | #else /* DER_MULTIBYTE_TAGS */ 88 | 89 | #define ASN1_TAG_MASK 0xff 90 | #define ASN1_TAGNUM_MASK 0x1f 91 | #define ASN1_METHOD_MASK 0x20 92 | #define ASN1_PRIMITIVE 0x00 93 | #define ASN1_CONSTRUCTED 0x20 94 | 95 | #define ASN1_CLASS_MASK 0xc0 96 | #define ASN1_UNIVERSAL 0x00 97 | #define ASN1_APPLICATION 0x40 98 | #define ASN1_CONTEXT_SPECIFIC 0x80 99 | #define ASN1_PRIVATE 0xc0 100 | 101 | #endif /* !DER_MULTIBYTE_TAGS */ 102 | 103 | /* sequence and set appear as the following */ 104 | #define ASN1_CONSTR_SEQUENCE (ASN1_CONSTRUCTED | ASN1_SEQUENCE) 105 | #define ASN1_CONSTR_SET (ASN1_CONSTRUCTED | ASN1_SET) 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #endif /* _ASN1_TYPES_H_ */ 112 | 113 | -------------------------------------------------------------------------------- /src/lib/libDER/libDER.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2007,2011,2014 Apple Inc. All Rights Reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | 25 | /* 26 | * libDER.h - main header for libDER, a ROM-capable DER decoding library. 27 | * 28 | */ 29 | 30 | #ifndef _LIB_DER_H_ 31 | #define _LIB_DER_H_ 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | #include 38 | /* 39 | * Error returns generated by this library. 40 | */ 41 | typedef enum { 42 | DR_Success, 43 | DR_EndOfSequence, /* end of sequence or set */ 44 | DR_UnexpectedTag, /* unexpected tag found while decoding */ 45 | DR_DecodeError, /* misc. decoding error (badly formatted DER) */ 46 | DR_Unimplemented, /* function not implemented in this configuration */ 47 | DR_IncompleteSeq, /* incomplete sequence */ 48 | DR_ParamErr, /* incoming parameter error */ 49 | DR_BufOverflow /* buffer overflow */ 50 | /* etc. */ 51 | } DERReturn; 52 | 53 | /* 54 | * Primary representation of a block of memory. 55 | */ 56 | typedef struct { 57 | DERByte *data; 58 | DERSize length; 59 | } DERItem; 60 | 61 | /* 62 | * The structure of a sequence during decode or encode is expressed as 63 | * an array of DERItemSpecs. While decoding or encoding a sequence, 64 | * each item in the sequence corresponds to one DERItemSpec. 65 | */ 66 | typedef struct { 67 | DERSize offset; /* offset of destination DERItem */ 68 | DERTag tag; /* DER tag */ 69 | DERShort options; /* DER_DEC_xxx or DER_ENC_xxx */ 70 | } DERItemSpec; 71 | 72 | /* 73 | * Macro to obtain offset of a DERDecodedInfo within a struct. 74 | * FIXME this is going to need reworking to avoid compiler warnings 75 | * on 64-bit compiles. It'll work OK as long as an offset can't be larger 76 | * than a DERSize, but the cast from a pointer to a DERSize may 77 | * provoke compiler warnings. 78 | */ 79 | #define DER_OFFSET(type, field) ((DERSize)(&((type *)0)->field)) 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /* _LIB_DER_H_ */ 86 | 87 | -------------------------------------------------------------------------------- /src/lib/libDER/libDER_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2007,2011-2012,2014 Apple Inc. All Rights Reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | 25 | /* 26 | * libDER_config.h - platform dependent #defines and typedefs for libDER 27 | * 28 | */ 29 | 30 | #ifndef _LIB_DER_CONFIG_H_ 31 | #define _LIB_DER_CONFIG_H_ 32 | 33 | #include 34 | #include 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /* 41 | * Basic data types: unsigned 8-bit integer, unsigned 32-bit integer 42 | */ 43 | typedef uint8_t DERByte; 44 | typedef uint16_t DERShort; 45 | typedef uint32_t DERSize; 46 | 47 | /* 48 | * Use these #defines of you have memset, memmove, and memcmp; else 49 | * write your own equivalents. 50 | */ 51 | 52 | #define DERMemset(ptr, c, len) memset(ptr, c, len) 53 | #define DERMemmove(dst, src, len) memmove(dst, src, len) 54 | #define DERMemcmp(b1, b2, len) memcmp(b1, b2, len) 55 | 56 | 57 | /*** 58 | *** Compile time options to trim size of the library. 59 | ***/ 60 | 61 | /* enable general DER encode */ 62 | #define DER_ENCODE_ENABLE 1 63 | 64 | /* enable general DER decode */ 65 | #define DER_DECODE_ENABLE 1 66 | 67 | #ifndef DER_MULTIBYTE_TAGS 68 | /* enable multibyte tag support. */ 69 | #define DER_MULTIBYTE_TAGS 1 70 | #endif 71 | 72 | #ifndef DER_TAG_SIZE 73 | /* Iff DER_MULTIBYTE_TAGS is 1 this is the sizeof(DERTag) in bytes. Note that 74 | tags are still encoded and decoded from a minimally encoded DER 75 | represantation. This value determines how big each DERItemSpecs is, we 76 | choose 2 since that makes DERItemSpecs 8 bytes wide. */ 77 | #define DER_TAG_SIZE 2 78 | #endif 79 | 80 | 81 | /* ---------------------- Do not edit below this line ---------------------- */ 82 | 83 | /* 84 | * Logical representation of a tag (the encoded representation is always in 85 | * the minimal number of bytes). The top 3 bits encode class and method 86 | * The remaining bits encode the tag value. To obtain smaller DERItemSpecs 87 | * sizes, choose the smallest type that fits your needs. Most standard ASN.1 88 | * usage only needs single byte tags, but ocasionally custom applications 89 | * require a larger tag namespace. 90 | */ 91 | #if DER_MULTIBYTE_TAGS 92 | 93 | #if DER_TAG_SIZE == 1 94 | typedef uint8_t DERTag; 95 | #elif DER_TAG_SIZE == 2 96 | typedef uint16_t DERTag; 97 | #elif DER_TAG_SIZE == 4 98 | typedef uint32_t DERTag; 99 | #elif DER_TAG_SIZE == 8 100 | typedef uint64_t DERTag; 101 | #else 102 | #error DER_TAG_SIZE invalid 103 | #endif 104 | 105 | #else /* DER_MULTIBYTE_TAGS */ 106 | typedef DERByte DERTag; 107 | #endif /* !DER_MULTIBYTE_TAGS */ 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /* _LIB_DER_CONFIG_H_ */ 114 | -------------------------------------------------------------------------------- /src/modules/linux/libfdt/Makefile.libfdt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) 2 | # Makefile.libfdt 3 | # 4 | # This is not a complete Makefile of itself. Instead, it is designed to 5 | # be easily embeddable into other systems of Makefiles. 6 | # 7 | LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1 8 | LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h 9 | LIBFDT_VERSION = version.lds 10 | LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \ 11 | fdt_addresses.c fdt_overlay.c 12 | LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) 13 | LIBFDT_LIB = libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT) 14 | 15 | libfdt_clean: 16 | @$(VECHO) CLEAN "(libfdt)" 17 | rm -f $(STD_CLEANFILES:%=$(LIBFDT_dir)/%) 18 | rm -f $(LIBFDT_dir)/$(LIBFDT_soname) 19 | -------------------------------------------------------------------------------- /src/modules/linux/libfdt/README.license: -------------------------------------------------------------------------------- 1 | Licensing and contribution policy of dtc and libfdt 2 | =================================================== 3 | 4 | This dtc package contains two pieces of software: dtc itself, and 5 | libfdt which comprises the files in the libfdt/ subdirectory. These 6 | two pieces of software, although closely related, are quite distinct. 7 | dtc does not incorporate or rely on libfdt for its operation, nor vice 8 | versa. It is important that these two pieces of software have 9 | different license conditions. 10 | 11 | As SPDX license tags in each source file attest, dtc is licensed 12 | under the GNU GPL. The full text of the GPL can be found in the file 13 | entitled 'GPL' which should be included in this package. dtc code, 14 | therefore, may not be incorporated into works which do not have a GPL 15 | compatible license. 16 | 17 | libfdt, however, is GPL/BSD dual-licensed. That is, it may be used 18 | either under the terms of the GPL, or under the terms of the 2-clause 19 | BSD license (aka the ISC license). The full terms of that license can 20 | be found are in the file entitled 'BSD-2-Clause'. This is, in 21 | practice, equivalent to being BSD licensed, since the terms of the BSD 22 | license are strictly more permissive than the GPL. 23 | 24 | I made the decision to license libfdt in this way because I want to 25 | encourage widespread and correct usage of flattened device trees, 26 | including by proprietary or otherwise GPL-incompatible firmware or 27 | tools. Allowing libfdt to be used under the terms of the BSD license 28 | makes that it easier for vendors or authors of such software to do so. 29 | 30 | This does mean that libfdt code could be "stolen" - say, included in a 31 | proprietary fimware and extended without contributing those extensions 32 | back to the libfdt mainline. While I hope that doesn't happen, I 33 | believe the goal of allowing libfdt to be widely used is more 34 | important than avoiding that. libfdt is quite small, and hardly 35 | rocket science; so the incentive for such impolite behaviour is small, 36 | and the inconvenience caused thereby is not dire. 37 | 38 | Licenses such as the LGPL which would allow code to be used in non-GPL 39 | software, but also require contributions to be returned were 40 | considered. However, libfdt is designed to be used in firmwares and 41 | other environments with unusual technical constraints. It's difficult 42 | to anticipate all possible changes which might be needed to meld 43 | libfdt into such environments and so difficult to suitably word a 44 | license that puts the boundary between what is and isn't permitted in 45 | the intended place. Again, I judged encouraging widespread use of 46 | libfdt by keeping the license terms simple and familiar to be the more 47 | important goal. 48 | 49 | **IMPORTANT** It's intended that all of libfdt as released remain 50 | permissively licensed this way. Therefore only contributions which 51 | are released under these terms can be merged into the libfdt mainline. 52 | 53 | 54 | David Gibson 55 | (principal original author of dtc and libfdt) 56 | 2 November 2007 57 | -------------------------------------------------------------------------------- /src/modules/linux/libfdt/TODO: -------------------------------------------------------------------------------- 1 | - Tree traversal functions 2 | - Graft function 3 | - Complete libfdt.h documenting comments 4 | -------------------------------------------------------------------------------- /src/modules/linux/libfdt/fdt.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ 2 | #ifndef FDT_H 3 | #define FDT_H 4 | /* 5 | * libfdt - Flat Device Tree manipulation 6 | * Copyright (C) 2006 David Gibson, IBM Corporation. 7 | * Copyright 2012 Kim Phillips, Freescale Semiconductor. 8 | */ 9 | 10 | #ifndef __ASSEMBLY__ 11 | 12 | struct fdt_header { 13 | fdt32_t magic; /* magic word FDT_MAGIC */ 14 | fdt32_t totalsize; /* total size of DT block */ 15 | fdt32_t off_dt_struct; /* offset to structure */ 16 | fdt32_t off_dt_strings; /* offset to strings */ 17 | fdt32_t off_mem_rsvmap; /* offset to memory reserve map */ 18 | fdt32_t version; /* format version */ 19 | fdt32_t last_comp_version; /* last compatible version */ 20 | 21 | /* version 2 fields below */ 22 | fdt32_t boot_cpuid_phys; /* Which physical CPU id we're 23 | booting on */ 24 | /* version 3 fields below */ 25 | fdt32_t size_dt_strings; /* size of the strings block */ 26 | 27 | /* version 17 fields below */ 28 | fdt32_t size_dt_struct; /* size of the structure block */ 29 | }; 30 | 31 | struct fdt_reserve_entry { 32 | fdt64_t address; 33 | fdt64_t size; 34 | }; 35 | 36 | struct fdt_node_header { 37 | fdt32_t tag; 38 | char name[0]; 39 | }; 40 | 41 | struct fdt_property { 42 | fdt32_t tag; 43 | fdt32_t len; 44 | fdt32_t nameoff; 45 | char data[0]; 46 | }; 47 | 48 | #endif /* !__ASSEMBLY */ 49 | 50 | #define FDT_MAGIC 0xd00dfeed /* 4: version, 4: total size */ 51 | #define FDT_TAGSIZE sizeof(fdt32_t) 52 | 53 | #define FDT_BEGIN_NODE 0x1 /* Start node: full name */ 54 | #define FDT_END_NODE 0x2 /* End node */ 55 | #define FDT_PROP 0x3 /* Property: name off, 56 | size, content */ 57 | #define FDT_NOP 0x4 /* nop */ 58 | #define FDT_END 0x9 59 | 60 | #define FDT_V1_SIZE (7*sizeof(fdt32_t)) 61 | #define FDT_V2_SIZE (FDT_V1_SIZE + sizeof(fdt32_t)) 62 | #define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t)) 63 | #define FDT_V16_SIZE FDT_V3_SIZE 64 | #define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t)) 65 | 66 | #endif /* FDT_H */ 67 | -------------------------------------------------------------------------------- /src/modules/linux/libfdt/fdt_addresses.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) 2 | /* 3 | * libfdt - Flat Device Tree manipulation 4 | * Copyright (C) 2014 David Gibson 5 | * Copyright (C) 2018 embedded brains GmbH 6 | */ 7 | #include "libfdt_env.h" 8 | 9 | #include 10 | #include 11 | 12 | #include "libfdt_internal.h" 13 | 14 | static int fdt_cells(const void *fdt, int nodeoffset, const char *name) 15 | { 16 | const fdt32_t *c; 17 | uint32_t val; 18 | int len; 19 | 20 | c = fdt_getprop(fdt, nodeoffset, name, &len); 21 | if (!c) 22 | return len; 23 | 24 | if (len != sizeof(*c)) 25 | return -FDT_ERR_BADNCELLS; 26 | 27 | val = fdt32_to_cpu(*c); 28 | if (val > FDT_MAX_NCELLS) 29 | return -FDT_ERR_BADNCELLS; 30 | 31 | return (int)val; 32 | } 33 | 34 | int fdt_address_cells(const void *fdt, int nodeoffset) 35 | { 36 | int val; 37 | 38 | val = fdt_cells(fdt, nodeoffset, "#address-cells"); 39 | if (val == 0) 40 | return -FDT_ERR_BADNCELLS; 41 | if (val == -FDT_ERR_NOTFOUND) 42 | return 2; 43 | return val; 44 | } 45 | 46 | int fdt_size_cells(const void *fdt, int nodeoffset) 47 | { 48 | int val; 49 | 50 | val = fdt_cells(fdt, nodeoffset, "#size-cells"); 51 | if (val == -FDT_ERR_NOTFOUND) 52 | return 1; 53 | return val; 54 | } 55 | 56 | /* This function assumes that [address|size]_cells is 1 or 2 */ 57 | int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset, 58 | const char *name, uint64_t addr, uint64_t size) 59 | { 60 | int addr_cells, size_cells, ret; 61 | uint8_t data[sizeof(fdt64_t) * 2], *prop; 62 | 63 | ret = fdt_address_cells(fdt, parent); 64 | if (ret < 0) 65 | return ret; 66 | addr_cells = ret; 67 | 68 | ret = fdt_size_cells(fdt, parent); 69 | if (ret < 0) 70 | return ret; 71 | size_cells = ret; 72 | 73 | /* check validity of address */ 74 | prop = data; 75 | if (addr_cells == 1) { 76 | if ((addr > UINT32_MAX) || ((UINT32_MAX + 1 - addr) < size)) 77 | return -FDT_ERR_BADVALUE; 78 | 79 | fdt32_st(prop, (uint32_t)addr); 80 | } else if (addr_cells == 2) { 81 | fdt64_st(prop, addr); 82 | } else { 83 | return -FDT_ERR_BADNCELLS; 84 | } 85 | 86 | /* check validity of size */ 87 | prop += addr_cells * sizeof(fdt32_t); 88 | if (size_cells == 1) { 89 | if (size > UINT32_MAX) 90 | return -FDT_ERR_BADVALUE; 91 | 92 | fdt32_st(prop, (uint32_t)size); 93 | } else if (size_cells == 2) { 94 | fdt64_st(prop, size); 95 | } else { 96 | return -FDT_ERR_BADNCELLS; 97 | } 98 | 99 | return fdt_appendprop(fdt, nodeoffset, name, data, 100 | (addr_cells + size_cells) * sizeof(fdt32_t)); 101 | } 102 | -------------------------------------------------------------------------------- /src/modules/linux/libfdt/fdt_empty_tree.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) 2 | /* 3 | * libfdt - Flat Device Tree manipulation 4 | * Copyright (C) 2012 David Gibson, IBM Corporation. 5 | */ 6 | #include "libfdt_env.h" 7 | 8 | #include 9 | #include 10 | 11 | #include "libfdt_internal.h" 12 | 13 | int fdt_create_empty_tree(void *buf, int bufsize) 14 | { 15 | int err; 16 | 17 | err = fdt_create(buf, bufsize); 18 | if (err) 19 | return err; 20 | 21 | err = fdt_finish_reservemap(buf); 22 | if (err) 23 | return err; 24 | 25 | err = fdt_begin_node(buf, ""); 26 | if (err) 27 | return err; 28 | 29 | err = fdt_end_node(buf); 30 | if (err) 31 | return err; 32 | 33 | err = fdt_finish(buf); 34 | if (err) 35 | return err; 36 | 37 | return fdt_open_into(buf, buf, bufsize); 38 | } 39 | -------------------------------------------------------------------------------- /src/modules/linux/libfdt/fdt_strerror.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) 2 | /* 3 | * libfdt - Flat Device Tree manipulation 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 6 | */ 7 | #include "libfdt_env.h" 8 | 9 | #include 10 | #include 11 | 12 | #include "libfdt_internal.h" 13 | 14 | struct fdt_errtabent { 15 | const char *str; 16 | }; 17 | 18 | #define FDT_ERRTABENT(val) \ 19 | [(val)] = { .str = #val, } 20 | 21 | static struct fdt_errtabent fdt_errtable[] = { 22 | FDT_ERRTABENT(FDT_ERR_NOTFOUND), 23 | FDT_ERRTABENT(FDT_ERR_EXISTS), 24 | FDT_ERRTABENT(FDT_ERR_NOSPACE), 25 | 26 | FDT_ERRTABENT(FDT_ERR_BADOFFSET), 27 | FDT_ERRTABENT(FDT_ERR_BADPATH), 28 | FDT_ERRTABENT(FDT_ERR_BADPHANDLE), 29 | FDT_ERRTABENT(FDT_ERR_BADSTATE), 30 | 31 | FDT_ERRTABENT(FDT_ERR_TRUNCATED), 32 | FDT_ERRTABENT(FDT_ERR_BADMAGIC), 33 | FDT_ERRTABENT(FDT_ERR_BADVERSION), 34 | FDT_ERRTABENT(FDT_ERR_BADSTRUCTURE), 35 | FDT_ERRTABENT(FDT_ERR_BADLAYOUT), 36 | FDT_ERRTABENT(FDT_ERR_INTERNAL), 37 | FDT_ERRTABENT(FDT_ERR_BADNCELLS), 38 | FDT_ERRTABENT(FDT_ERR_BADVALUE), 39 | FDT_ERRTABENT(FDT_ERR_BADOVERLAY), 40 | FDT_ERRTABENT(FDT_ERR_NOPHANDLES), 41 | FDT_ERRTABENT(FDT_ERR_BADFLAGS), 42 | }; 43 | #define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0])) 44 | 45 | const char *fdt_strerror(int errval) 46 | { 47 | if (errval > 0) 48 | return ""; 49 | else if (errval == 0) 50 | return ""; 51 | else if (errval > -FDT_ERRTABSIZE) { 52 | const char *s = fdt_errtable[-errval].str; 53 | 54 | if (s) 55 | return s; 56 | } 57 | 58 | return ""; 59 | } 60 | -------------------------------------------------------------------------------- /src/modules/linux/libfdt/fdt_wip.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) 2 | /* 3 | * libfdt - Flat Device Tree manipulation 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. 5 | */ 6 | #include "libfdt_env.h" 7 | 8 | #include 9 | #include 10 | 11 | #include "libfdt_internal.h" 12 | 13 | int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, 14 | const char *name, int namelen, 15 | uint32_t idx, const void *val, 16 | int len) 17 | { 18 | void *propval; 19 | int proplen; 20 | 21 | propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen, 22 | &proplen); 23 | if (!propval) 24 | return proplen; 25 | 26 | if (proplen < (len + idx)) 27 | return -FDT_ERR_NOSPACE; 28 | 29 | memcpy((char *)propval + idx, val, len); 30 | return 0; 31 | } 32 | 33 | int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, 34 | const void *val, int len) 35 | { 36 | const void *propval; 37 | int proplen; 38 | 39 | propval = fdt_getprop(fdt, nodeoffset, name, &proplen); 40 | if (!propval) 41 | return proplen; 42 | 43 | if (proplen != len) 44 | return -FDT_ERR_NOSPACE; 45 | 46 | return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name, 47 | strlen(name), 0, 48 | val, len); 49 | } 50 | 51 | static void fdt_nop_region_(void *start, int len) 52 | { 53 | fdt32_t *p; 54 | 55 | for (p = start; (char *)p < ((char *)start + len); p++) 56 | *p = cpu_to_fdt32(FDT_NOP); 57 | } 58 | 59 | int fdt_nop_property(void *fdt, int nodeoffset, const char *name) 60 | { 61 | struct fdt_property *prop; 62 | int len; 63 | 64 | prop = fdt_get_property_w(fdt, nodeoffset, name, &len); 65 | if (!prop) 66 | return len; 67 | 68 | fdt_nop_region_(prop, len + sizeof(*prop)); 69 | 70 | return 0; 71 | } 72 | 73 | int fdt_node_end_offset_(void *fdt, int offset) 74 | { 75 | int depth = 0; 76 | 77 | while ((offset >= 0) && (depth >= 0)) 78 | offset = fdt_next_node(fdt, offset, &depth); 79 | 80 | return offset; 81 | } 82 | 83 | int fdt_nop_node(void *fdt, int nodeoffset) 84 | { 85 | int endoffset; 86 | 87 | endoffset = fdt_node_end_offset_(fdt, nodeoffset); 88 | if (endoffset < 0) 89 | return endoffset; 90 | 91 | fdt_nop_region_(fdt_offset_ptr_w(fdt, nodeoffset, 0), 92 | endoffset - nodeoffset); 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /src/modules/linux/libfdt/libfdt_env.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ 2 | #ifndef LIBFDT_ENV_H 3 | #define LIBFDT_ENV_H 4 | /* 5 | * libfdt - Flat Device Tree manipulation 6 | * Copyright (C) 2006 David Gibson, IBM Corporation. 7 | * Copyright 2012 Kim Phillips, Freescale Semiconductor. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #ifdef __CHECKER__ 18 | #define FDT_FORCE __attribute__((force)) 19 | #define FDT_BITWISE __attribute__((bitwise)) 20 | #else 21 | #define FDT_FORCE 22 | #define FDT_BITWISE 23 | #endif 24 | 25 | typedef uint16_t FDT_BITWISE fdt16_t; 26 | typedef uint32_t FDT_BITWISE fdt32_t; 27 | typedef uint64_t FDT_BITWISE fdt64_t; 28 | 29 | #define EXTRACT_BYTE(x, n) ((unsigned long long)((uint8_t *)&x)[n]) 30 | #define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1)) 31 | #define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \ 32 | (EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3)) 33 | #define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \ 34 | (EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \ 35 | (EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \ 36 | (EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7)) 37 | 38 | static inline uint16_t fdt16_to_cpu(fdt16_t x) 39 | { 40 | return (FDT_FORCE uint16_t)CPU_TO_FDT16(x); 41 | } 42 | static inline fdt16_t cpu_to_fdt16(uint16_t x) 43 | { 44 | return (FDT_FORCE fdt16_t)CPU_TO_FDT16(x); 45 | } 46 | 47 | static inline uint32_t fdt32_to_cpu(fdt32_t x) 48 | { 49 | return (FDT_FORCE uint32_t)CPU_TO_FDT32(x); 50 | } 51 | static inline fdt32_t cpu_to_fdt32(uint32_t x) 52 | { 53 | return (FDT_FORCE fdt32_t)CPU_TO_FDT32(x); 54 | } 55 | 56 | static inline uint64_t fdt64_to_cpu(fdt64_t x) 57 | { 58 | return (FDT_FORCE uint64_t)CPU_TO_FDT64(x); 59 | } 60 | static inline fdt64_t cpu_to_fdt64(uint64_t x) 61 | { 62 | return (FDT_FORCE fdt64_t)CPU_TO_FDT64(x); 63 | } 64 | #undef CPU_TO_FDT64 65 | #undef CPU_TO_FDT32 66 | #undef CPU_TO_FDT16 67 | #undef EXTRACT_BYTE 68 | 69 | #ifdef __APPLE__ 70 | #include 71 | 72 | /* strnlen() is not available on Mac OS < 10.7 */ 73 | # if !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < \ 74 | MAC_OS_X_VERSION_10_7) 75 | 76 | #define strnlen fdt_strnlen 77 | 78 | /* 79 | * fdt_strnlen: returns the length of a string or max_count - which ever is 80 | * smallest. 81 | * Input 1 string: the string whose size is to be determined 82 | * Input 2 max_count: the maximum value returned by this function 83 | * Output: length of the string or max_count (the smallest of the two) 84 | */ 85 | static inline size_t fdt_strnlen(const char *string, size_t max_count) 86 | { 87 | const char *p = memchr(string, 0, max_count); 88 | return p ? p - string : max_count; 89 | } 90 | 91 | #endif /* !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < 92 | MAC_OS_X_VERSION_10_7) */ 93 | 94 | #endif /* __APPLE__ */ 95 | 96 | #endif /* LIBFDT_ENV_H */ 97 | -------------------------------------------------------------------------------- /src/modules/linux/libfdt/libfdt_internal.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ 2 | #ifndef LIBFDT_INTERNAL_H 3 | #define LIBFDT_INTERNAL_H 4 | /* 5 | * libfdt - Flat Device Tree manipulation 6 | * Copyright (C) 2006 David Gibson, IBM Corporation. 7 | */ 8 | #include 9 | 10 | #define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) 11 | #define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) 12 | 13 | int32_t fdt_ro_probe_(const void *fdt); 14 | #define FDT_RO_PROBE(fdt) \ 15 | { \ 16 | int32_t totalsize_; \ 17 | if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \ 18 | return totalsize_; \ 19 | } 20 | 21 | int fdt_check_node_offset_(const void *fdt, int offset); 22 | int fdt_check_prop_offset_(const void *fdt, int offset); 23 | const char *fdt_find_string_(const char *strtab, int tabsize, const char *s); 24 | int fdt_node_end_offset_(void *fdt, int nodeoffset); 25 | 26 | static inline const void *fdt_offset_ptr_(const void *fdt, int offset) 27 | { 28 | return (const char *)fdt + fdt_off_dt_struct(fdt) + offset; 29 | } 30 | 31 | static inline void *fdt_offset_ptr_w_(void *fdt, int offset) 32 | { 33 | return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset); 34 | } 35 | 36 | static inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n) 37 | { 38 | const struct fdt_reserve_entry *rsv_table = 39 | (const struct fdt_reserve_entry *) 40 | ((const char *)fdt + fdt_off_mem_rsvmap(fdt)); 41 | 42 | return rsv_table + n; 43 | } 44 | static inline struct fdt_reserve_entry *fdt_mem_rsv_w_(void *fdt, int n) 45 | { 46 | return (void *)(uintptr_t)fdt_mem_rsv_(fdt, n); 47 | } 48 | 49 | #define FDT_SW_MAGIC (~FDT_MAGIC) 50 | 51 | #endif /* LIBFDT_INTERNAL_H */ 52 | -------------------------------------------------------------------------------- /src/modules/linux/libfdt/version.lds: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */ 2 | LIBFDT_1.2 { 3 | global: 4 | fdt_next_node; 5 | fdt_check_header; 6 | fdt_move; 7 | fdt_string; 8 | fdt_num_mem_rsv; 9 | fdt_get_mem_rsv; 10 | fdt_subnode_offset_namelen; 11 | fdt_subnode_offset; 12 | fdt_path_offset_namelen; 13 | fdt_path_offset; 14 | fdt_get_name; 15 | fdt_get_property_namelen; 16 | fdt_get_property; 17 | fdt_getprop_namelen; 18 | fdt_getprop; 19 | fdt_get_phandle; 20 | fdt_get_alias_namelen; 21 | fdt_get_alias; 22 | fdt_get_path; 23 | fdt_supernode_atdepth_offset; 24 | fdt_node_depth; 25 | fdt_parent_offset; 26 | fdt_node_offset_by_prop_value; 27 | fdt_node_offset_by_phandle; 28 | fdt_node_check_compatible; 29 | fdt_node_offset_by_compatible; 30 | fdt_setprop_inplace; 31 | fdt_nop_property; 32 | fdt_nop_node; 33 | fdt_create; 34 | fdt_add_reservemap_entry; 35 | fdt_finish_reservemap; 36 | fdt_begin_node; 37 | fdt_property; 38 | fdt_end_node; 39 | fdt_finish; 40 | fdt_open_into; 41 | fdt_pack; 42 | fdt_add_mem_rsv; 43 | fdt_del_mem_rsv; 44 | fdt_set_name; 45 | fdt_setprop; 46 | fdt_delprop; 47 | fdt_add_subnode_namelen; 48 | fdt_add_subnode; 49 | fdt_del_node; 50 | fdt_strerror; 51 | fdt_offset_ptr; 52 | fdt_next_tag; 53 | fdt_appendprop; 54 | fdt_create_empty_tree; 55 | fdt_first_property_offset; 56 | fdt_get_property_by_offset; 57 | fdt_getprop_by_offset; 58 | fdt_next_property_offset; 59 | fdt_first_subnode; 60 | fdt_next_subnode; 61 | fdt_address_cells; 62 | fdt_size_cells; 63 | fdt_stringlist_contains; 64 | fdt_stringlist_count; 65 | fdt_stringlist_search; 66 | fdt_stringlist_get; 67 | fdt_resize; 68 | fdt_overlay_apply; 69 | fdt_get_string; 70 | fdt_find_max_phandle; 71 | fdt_generate_phandle; 72 | fdt_check_full; 73 | fdt_setprop_placeholder; 74 | fdt_property_placeholder; 75 | fdt_header_size_; 76 | fdt_appendprop_addrrange; 77 | fdt_setprop_inplace_namelen_partial; 78 | fdt_create_with_flags; 79 | local: 80 | *; 81 | }; 82 | -------------------------------------------------------------------------------- /src/shell/autoboot.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #ifdef AUTOBOOT 28 | #include 29 | uint64_t* autoboot_block; 30 | void pongo_autoboot() 31 | { 32 | if (autoboot_block) { 33 | resize_loader_xfer_data((uint32_t)autoboot_block[1]); 34 | memcpy(loader_xfer_recv_data, &autoboot_block[2], (uint32_t)autoboot_block[1]); 35 | loader_xfer_recv_count = (uint32_t)autoboot_block[1]; 36 | autoboot_count = loader_xfer_recv_count; 37 | phys_force_free(vatophys((uint64_t)autoboot_block), (autoboot_block[1] + 0x20 + 0x3fff) & ~0x3fff); 38 | 39 | queue_rx_string("modload\nautoboot\n"); 40 | } 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/shell/hex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | int hexparse(uint8_t *buf, char *s, size_t len) 33 | { 34 | for(size_t i = 0; i < len; ++i) 35 | { 36 | char c = s[2*i], 37 | d = s[2*i+1]; 38 | if(!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) || 39 | !((d >= '0' && d <= '9') || (d >= 'a' && d <= 'f') || (d >= 'A' && d <= 'F'))) 40 | { 41 | return -1; 42 | } 43 | buf[i] = ((uint8_t)(c >= '0' && c <= '9' ? c - '0' : (c >= 'a' && c <= 'f' ? c - 'a' : c - 'A') + 10) << 4) | 44 | (uint8_t)(d >= '0' && d <= '9' ? d - '0' : (d >= 'a' && d <= 'f' ? d - 'a' : d - 'A') + 10); 45 | } 46 | return 0; 47 | } 48 | 49 | void hexprint(uint8_t *data, size_t sz) 50 | { 51 | char buf[0x61]; 52 | for(size_t i = 0; i < sz; i += 0x30) 53 | { 54 | size_t max = sz - i > 0x30 ? 0x30 : sz - i; 55 | for(size_t j = 0; j < max; ++j) 56 | { 57 | uint8_t u = data[i+j], 58 | hi = (u >> 4) & 0xf, 59 | lo = u & 0xf; 60 | buf[2*j] = hi < 10 ? '0' + hi : 'a' + (hi - 10); 61 | buf[2*j+1] = lo < 10 ? '0' + lo : 'a' + (lo - 10); 62 | } 63 | buf[2*max] = '\0'; 64 | iprintf("%s", buf); 65 | } 66 | iprintf("\n"); 67 | } 68 | -------------------------------------------------------------------------------- /src/shell/linux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | extern volatile char gBootFlag; 30 | 31 | /* 32 | 33 | Name: fdt_cmd 34 | Description: command handler for fdt 35 | 36 | */ 37 | extern void * fdt; 38 | extern bool fdt_initialized; 39 | extern char gLinuxCmdLine[LINUX_CMDLINE_SIZE]; 40 | 41 | void fdt_cmd() { 42 | if (!loader_xfer_recv_count) { 43 | iprintf("please upload a fdt before issuing this command\n"); 44 | return; 45 | } 46 | if (fdt_initialized) free(fdt); 47 | fdt = malloc(LINUX_DTREE_SIZE); 48 | if (!fdt) panic("couldn't reserve heap for fdt"); 49 | memcpy(fdt, loader_xfer_recv_data, loader_xfer_recv_count); 50 | fdt_initialized = 1; 51 | loader_xfer_recv_count = 0; 52 | } 53 | 54 | void linux_cmdline_cmd(const char* cmd, char* args) { 55 | if (!*args) { 56 | iprintf("linux_cmdline usage: linux_cmdline [cmdline]\n"); 57 | return; 58 | } 59 | 60 | size_t len = strlen(args); 61 | if (len > LINUX_CMDLINE_SIZE) { 62 | iprintf("Provided command line length is greater than LINUX_CMDLINE_SIZE (%lu > %lu)\n", len, (size_t) LINUX_CMDLINE_SIZE); 63 | return; 64 | } 65 | 66 | memcpy(gLinuxCmdLine, args, len); 67 | } 68 | 69 | /* 70 | 71 | Name: pongo_boot_linux 72 | Description: command handler for bootl 73 | 74 | */ 75 | 76 | void pongo_boot_linux() { 77 | if (!linux_can_boot()) { 78 | printf("linux boot not prepared\n"); 79 | return; 80 | } 81 | gBootFlag = BOOT_FLAG_LINUX; 82 | task_yield(); 83 | } 84 | 85 | void linux_commands_register() { 86 | command_register("bootl", "boots linux", pongo_boot_linux); 87 | command_register("linux_cmdline", "update linux kernel command line", linux_cmdline_cmd); 88 | command_register("fdt", "load linux fdt from usb", fdt_cmd); 89 | } 90 | -------------------------------------------------------------------------------- /src/sym_order.txt: -------------------------------------------------------------------------------- 1 | start 2 | --------------------------------------------------------------------------------