Magic‐1 Bootloader Format - retrotruestory/M1DEV GitHub Wiki

Based on the provided Magic-1 source files, here's the key information about the bootloader binary format and initialization procedure:

Magic-1 Bootloader Format

Binary File Structure

1. Executable Header (struct m1_exec):
   - a_magic: Magic number (OMAGIC)
   - a_text: Text segment size  
   - a_data: Data segment size
   - a_bss: BSS segment size
   - a_syms: Symbol table size
   - a_entry: Entry point address
   - a_trsize: Text relocation size
   - a_drsize: Data relocation size

Disk Layout

Sector 0-1: Reserved
Sector 2: Image Table Directory
Sectors 3+: Boot Images (256 sectors per image)

Image Table Entry:
- PID (Process ID)
- Name (16 bytes)
- Flags (free, loaded, default_image, split)

Key Memory Regions

0x0000-0x3FFF: ROM (16KB)
0x4000-0x7FFF: Device SRAM (16KB) 
0x8000-0xF7FF: Main Memory
0xF800-0xFFFF: Device Page

Initialization Sequence

  1. Hardware Reset:
// Initial CPU State
- Interrupts disabled
- System mode active  
- Paging disabled
- MSW = 0x0000
  1. Basic Setup:
// From bcrt0.s
_start:
    // Ensure system state
    ld.16   a,0x0000
    copy    msw,a          // Interrupts off, system mode
    
    // Setup kernel stack 
    ld.16   a,0x8000      // stack_start
    copy    sp,a
    
    // Initialize data pointer
    ld.16   a,0x0000      // dp_start  
    copy    dp,a
  1. Device Initialization:
// Initialize devices in sequence
init_rs232(CONSOLE, UART0_BASE);
init_rs232(AUX, UART1_BASE); 
init_uart(CONSOLE, console_baud);
init_uart(AUX, aux_baud);
init_rtc();
init_ide_info();
  1. Memory Management:
// Setup paging
setup_address_space();
- Copy ROM to SRAM
- Setup page tables
- Enable paging
  1. Boot Image Loading:
// Read boot image
read_image_table();
stage_boot_image();
do_boot0();

The bootloader uses Intel HEX format for loading images and supports both split (separate code/data) and joined memory models.