luajitos

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

grub.h (2254B)


      1 /* GRUB Bootloader Installation for LuajitOS
      2  *
      3  * Provides functionality to install a minimal bootloader to disk.
      4  * Writes MBR boot code that chainloads from the FAT16 boot partition.
      5  */
      6 
      7 #ifndef GRUB_H
      8 #define GRUB_H
      9 
     10 #include <stdint.h>
     11 
     12 #ifdef __cplusplus
     13 extern "C" {
     14 #endif
     15 
     16 /* Error codes */
     17 #define GRUB_OK              0
     18 #define GRUB_ERR_IO         -1
     19 #define GRUB_ERR_NO_PART    -2
     20 #define GRUB_ERR_NO_FAT16   -3
     21 #define GRUB_ERR_INVALID    -4
     22 
     23 /**
     24  * Install bootloader to disk MBR
     25  *
     26  * This writes boot code to the MBR that:
     27  * 1. Loads the boot sector from the first partition (FAT16)
     28  * 2. Chainloads the FAT16 Volume Boot Record (VBR)
     29  *
     30  * The FAT16 partition should already contain:
     31  * - /boot/kernel.bin (the LuajitOS kernel)
     32  * - /boot/grub/grub.cfg (GRUB configuration)
     33  *
     34  * @param bus       ATA bus
     35  * @param drive     ATA drive
     36  * @return          GRUB_OK on success, error code on failure
     37  */
     38 int grub_install_mbr(uint8_t bus, uint8_t drive);
     39 
     40 /**
     41  * Install core loader to embedding area (sectors 1-62)
     42  *
     43  * The core loader:
     44  * - Parses FAT16 filesystem
     45  * - Finds /BOOT/KERNEL.BIN
     46  * - Loads kernel to 0x100000
     47  * - Sets up multiboot and jumps to kernel
     48  *
     49  * @param bus       ATA bus
     50  * @param drive     ATA drive
     51  * @return          GRUB_OK on success, error code on failure
     52  */
     53 int grub_install_core(uint8_t bus, uint8_t drive);
     54 
     55 /**
     56  * Full bootloader installation
     57  *
     58  * Installs both MBR and VBR boot code. The disk must already have:
     59  * - A valid MBR partition table with FAT16 boot partition
     60  * - FAT16 filesystem on the boot partition
     61  * - Kernel at /boot/kernel.bin on the FAT16 partition
     62  *
     63  * @param bus       ATA bus
     64  * @param drive     ATA drive
     65  * @return          GRUB_OK on success, error code on failure
     66  */
     67 int grub_install(uint8_t bus, uint8_t drive);
     68 
     69 /**
     70  * Get error string for error code
     71  *
     72  * @param error     Error code
     73  * @return          Human-readable error string
     74  */
     75 const char *grub_error_string(int error);
     76 
     77 /* ============================================================================
     78  * Lua Bindings
     79  * ========================================================================= */
     80 
     81 struct lua_State;
     82 int luaopen_grub(struct lua_State *L);
     83 
     84 #ifdef __cplusplus
     85 }
     86 #endif
     87 
     88 #endif /* GRUB_H */