Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add m1n1 boot support and wash away the sandcastle #193

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,20 +435,6 @@ FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
Please see the License for the specific language governing rights and
limitations under the License."

**libfdt license**:

libfdt is dual-licensed under the GPLv2 license or BSD 2-clause (ISC license). Read README.license at src/modules/linux/libfdt for more information.

The text of the 2-clause BSD license:

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

**LZMA decompressor**:
src/lib/lzma/lzmadec.c

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ endif

# Pongo options
PONGO_LD_FLAGS ?= -static -L$(LIB)/fixup -lc -Wl,-preload -Wl,-no_uuid -Wl,-e,start -Wl,-order_file,$(SRC)/sym_order.txt -Wl,-image_base,0x100000000 -Wl,-sectalign,__DATA,__common,0x8 -Wl,-segalign,0x4000 $(PONGO_LDFLAGS)
PONGO_CC_FLAGS ?= -Os -moutline -DPONGO_VERSION='"$(PONGO_VERSION)"' -DPONGO_BUILD='"$(PONGO_BUILD)"' -DPONGO_PRIVATE=1 -I$(SRC)/lib -I$(INC) -Iapple-include -I$(INC)/modules/linux/ -I$(SRC)/kernel -I$(SRC)/drivers -I$(SRC)/modules/linux/libfdt $(PONGO_LD_FLAGS) $(PONGO_CFLAGS)
PONGO_CC_FLAGS ?= -Os -moutline -DPONGO_VERSION='"$(PONGO_VERSION)"' -DPONGO_BUILD='"$(PONGO_BUILD)"' -DPONGO_PRIVATE=1 -I$(SRC)/lib -I$(INC) -Iapple-include -I$(SRC)/kernel -I$(SRC)/drivers $(PONGO_LD_FLAGS) $(PONGO_CFLAGS)

# KPF options
KPF_LD_FLAGS ?= -Wl,-kext $(KPF_LDFLAGS)
Expand Down
81 changes: 0 additions & 81 deletions scripts/load_linux.py

This file was deleted.

38 changes: 18 additions & 20 deletions src/kernel/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,7 @@ __attribute__((noinline)) void pongo_entry_cached()
{
default: // >4
case BOOT_FLAG_RAW: // 4
break;

case BOOT_FLAG_LINUX: // 3
linux_prep_boot();
boot_msg = "Booting Linux...";
case BOOT_FLAG_M1N1: // 3
break;

case BOOT_FLAG_HOOK: // 2
Expand Down Expand Up @@ -296,7 +292,7 @@ __attribute__((noinline)) void pongo_entry_cached()
*/
extern void set_exception_stack_core0();
extern void lowlevel_set_identity(void);
extern _Noreturn void jump_to_image_extended(uint64_t image, uint64_t args, uint64_t tramp, uint64_t original_image);
extern _Noreturn void jump_to_image_extended(void *image, void *args, void *tramp, void *original_image);
extern uint64_t gPongoSlide;

_Noreturn void pongo_entry(uint64_t *kernel_args, void *entryp, void (*exit_to_el1_image)(void *boot_args, void *boot_entry_point, void *trampoline))
Expand All @@ -313,30 +309,32 @@ _Noreturn void pongo_entry(uint64_t *kernel_args, void *entryp, void (*exit_to_e
set_exception_stack_core0();
gFramebuffer = (uint32_t*)gBootArgs->Video.v_baseAddr;
lowlevel_cleanup();
if(gBootFlag == BOOT_FLAG_RAW)

// Unused space above kernel static area
void *boot_tramp = (void*)((gTopOfKernelData + 0x3fffULL) & ~0x3fffULL);
if(gBootFlag == BOOT_FLAG_RAW || gBootFlag == BOOT_FLAG_M1N1)
{
// We're in EL1 here, but we might need to go back to EL3
uint64_t pfr0;
__asm__ volatile("mrs %0, id_aa64pfr0_el1" : "=r"(pfr0));
if((pfr0 & 0xf000) != 0)
if((__builtin_arm_rsr64("id_aa64pfr0_el1") & 0xf000) != 0)
{
__asm__ volatile("smc 0"); // elevate to EL3
}
uint64_t entryOff = 0x800;
if(gBootFlag == BOOT_FLAG_RAW)
{
boot_tramp = NULL;
entryOff = 0;
}
// XXX: We should really replace loader_xfer_recv_data with something dedicated here.
jump_to_image_extended(((uint64_t)loader_xfer_recv_data) - kCacheableView + 0x800000000, (uint64_t)gBootArgs, 0, (uint64_t)gEntryPoint);
void *image = (void*)((uint64_t)loader_xfer_recv_data - kCacheableView + 0x800000000 + entryOff);
jump_to_image_extended(image, gBootArgs, boot_tramp, gEntryPoint);
}
else
{
if(gBootFlag == BOOT_FLAG_LINUX)
{
linux_boot();
}
else
{
xnu_boot();
}
exit_to_el1_image(gBootArgs, gEntryPoint, (void*)((gTopOfKernelData + 0x3fffULL) & ~0x3fffULL));
xnu_boot();
exit_to_el1_image(gBootArgs, gEntryPoint, boot_tramp);
}

screen_puts("didn't boot?!");
while(1)
{}
Expand Down
2 changes: 2 additions & 0 deletions src/kernel/main_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void shell_main();
*/

uint64_t gBootTimeTicks;
char gFWVersion[256];
void pongo_main_task() {
gBootTimeTicks = get_ticks();

Expand Down Expand Up @@ -87,6 +88,7 @@ void pongo_main_task() {

char *fwversion = dt_get_prop("/chosen", "firmware-version", NULL);
iprintf("Booted by: %s\n", fwversion);
strlcpy(gFWVersion, fwversion, 256);
strcpy(fwversion, "pongoOS-" PONGO_VERSION);
#ifdef __clang__
iprintf("Built with: Clang %s\n", __clang_version__);
Expand Down
8 changes: 1 addition & 7 deletions src/kernel/pongo.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,9 @@ extern volatile char gBootFlag;
#define BOOT_FLAG_DEFAULT 0
#define BOOT_FLAG_HARD 1
#define BOOT_FLAG_HOOK 2
#define BOOT_FLAG_LINUX 3
#define BOOT_FLAG_M1N1 3
#define BOOT_FLAG_RAW 4

#define LINUX_DTREE_SIZE 262144
#define LINUX_CMDLINE_SIZE 4096

typedef uint64_t lock;
extern void lock_take(lock* lock); // takes a lock spinning initially but after being pre-empted once it will start yielding until it acquires it
extern void lock_take_spin(lock* lock); // takes a lock spinning until it acquires it
Expand Down Expand Up @@ -409,9 +406,6 @@ extern void mask_interrupt(uint32_t reg);
extern _Noreturn void wdt_reset();
extern void wdt_enable();
extern void wdt_disable();
extern bool linux_can_boot();
extern void linux_prep_boot();
extern void linux_boot();
extern void command_register(const char* name, const char* desc, void (*cb)(const char* cmd, char* args));
extern char* command_tokenize(char* str, uint32_t strbufsz);
extern uint8_t get_el(void);
Expand Down
18 changes: 0 additions & 18 deletions src/modules/linux/libfdt/Makefile.libfdt

This file was deleted.

56 changes: 0 additions & 56 deletions src/modules/linux/libfdt/README.license

This file was deleted.

3 changes: 0 additions & 3 deletions src/modules/linux/libfdt/TODO

This file was deleted.

Loading
Loading