Ugly Stool Rotating Header Image

Syslinux

This is a post of me meandering through the Syslinux source code, there isn’t a real point.

Syslinux is most closely associated with Linux, but it actually supports the booting of other OS’s.  It can boot over the network (PXE), CD-ROM, and various file systems.

I am working on a project that utilizes Syslinux; the project must read and write Syslinux boot configuration files.  I need to understand the available options, and what they mean.  The best place to start is with the Syslinux documentation, and the relevant code.  (The real impetus for this project is to learn Scala.)

I was reading the parsing source code that I found in com32/menu/readconfig.c, but I could not find the code that configured the serial console.  The documentation has this to say about serial port configuration.

For the SERIAL directive to be guaranteed to work properly, it
should be the first directive in the configuration file.

Despite this statement, I could not find any code to parse the serial directive, so I started to ack.  I found the method __syslinux_get_serial_console_info(void), which seemed like a good start.  The prototype had an attribute that did not make sense to me – __constructor__.

void __constructor __syslinux_get_serial_console_info(void)
{
    static com32sys_t reg;
    memset(&reg, 0, sizeof reg);
    reg.eax.w[0] = 0x000b;
    __intcall(0x22, &reg, &reg);
    __syslinux_serial_console_info.iobase = reg.edx.w[0];
    __syslinux_serial_console_info.divisor = reg.ecx.w[0];
    __syslinux_serial_console_info.flowctl = reg.ebx.w[0];
}

I asked the oracle, and found out that this is a GCC-ism, that guarantees the function is invoked before main().  But, wait, there is even more coolness going on.  What about com32sys_ and intcall!

I went back to the oracle, and asked about interrupt 0x22.  I found out that it is typically reserved for DOS methods, so I assumed that Syslinux was hooking the interrupt to provide system calls.

After some more acking I found out the intcall function’s methods are the following. 

  1. interrupt handler to invoke
  2. register values to pass to the invoked system call; call executed is determined by the value in EAX.
  3. register results of the invoked system call

The actual system calls are setup in comboot.inc.  The assembly code calls into C code to do the heavy lifting.  Comboot is an API to extend Syslinux, and there are several projects that take advantage of it.

Back to the code…

Comments are closed.

Page optimized by WP Minify WordPress Plugin