/*
 * src/userspace/bridge/loadable.c - Universal FPF Binary Wrapper
 * Compile your app logic alongside this file to output a valid .fpf package.
 */

#include <stdint.h>
#include <stddef.h>
#include "../../include/fpf.h"

// Forward declaration of the user's actual main function
extern int florid_main(void);

// Force the compiler to place this header at the very beginning of the binary
__attribute__((section(".fpf_header"), used))
const fpf_header_t __app_header = {
    .magic = {'F', 'L', 'O', 'R'},
    .version = 1,
    .type = FPF_TYPE_DE,             // Setting to DE so it can draw the Bloom menu
    .flags = 0x08,                   // FPF_FLAG_FRAMEBUFFER_OWN
    .entry_point = 0,                // Offset from start of code section
    .stack_size = 1024 * 1024,       // 1MB stack request
    .heap_size = 1024 * 1024 * 16,   // 16MB heap request
    .signature = {0}                 // Unsigned demo
};

// The raw entry point called by the kernel loader
void _start(void) {
    // Jump to the application logic
    florid_main();
    
    // If the app exits, trap the CPU so it doesn't execute garbage memory
    while(1) { __asm__ volatile("hlt"); }
}