grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC] New object format for grub2


From: Bean
Subject: [RFC] New object format for grub2
Date: Wed, 8 Jul 2009 19:31:46 +0800

Hi,

Why another format ? Here are some reason:

The current object format is ELF. Most unix based os use ELF as native
object format, but there are minor difference, and gcc may add extra
segment which is of no use for grub. Mingw/cygwin uses PE, and we need
to convert it to ELF. Platform like OSX also requires special
treatment. All these make the build system complicated, so we might
just use an unified format specific to grub.

The ELF format is designed to be compatible with many system, it's
neither compact nor easy to parse. If we invent a new format, we
should make it simple.

There are extra data useful to grub, such as module dependence list.
It's possible to piggyback it using special segment of ELF, but it's
not very clean. We could specify the information explicitly in our own
format.

Here are my proposed format:

struct grub_obj_header
{
  grub_uint32_t magic;
  grub_uint32_t version;
  grub_uint32_t mod_attr;
  grub_uint32_t mod_deps;
  grub_uint32_t string_table;
  grub_uint32_t symbol_table;
  grub_uint32_t init_func;
  grub_uint32_t fini_func;
  struct grub_obj_segment segments[0];
} __attribute__((packed));

magic: magic number "GOBJ"
version: version number
mod_attr: offset to the module attributes
mod_deps: offset to the module dependent list
string_table: offset to the string table
symbol_table: offset to the symbol table
init_func: init function offset, init function must be in segment 0
fini_func: fini function offset, fini function must be in segment 0
segments: segment list, ends when segment type is 0

segment structure, the fields should be self explaining

struct grub_obj_segment
{
  grub_uint16_t type;
  grub_uint16_t align;
  grub_uint32_t offset;
  grub_uint32_t raw_size;
  grub_uint32_t mem_size;
} __attribute__((packed));

symbol table defines import, export and unnamed symbols, it's the
catenation of structure grub_obj_symbol, and ends when segment field
is 0xff:

#define GRUB_OBJ_SYM_EXPORT     0
#define GRUB_OBJ_SYM_PC32               1
#define GRUB_OBJ_SYM_ABS32      2
#define GRUB_OBJ_SYM_PC64               3
#define GRUB_OBJ_SYM_ABS64      4

struct grub_obj_symbol
{
  grub_uint8_t segment;
  grub_uint8_t type;
  grub_uint16_t name;
  grub_uint32_t offset;
} __attribute__((packed));

name is the offset to the string table, if name == 0, it's an unnamed symbol.

mod_attr is a series of null-terminated string, ended with an extra 0,
it can be used to store information, such as:

fs:fat
command:ls
handler.script:sh

we could use it to generate the *.lst files, which is more reliable
than sed the source files.

mod_deps is a series of null-terminated string, ended with an extra 0.
To make it easier to modify, mod_deps should be at the end of the
module file.

-- 
Bean




reply via email to

[Prev in Thread] Current Thread [Next in Thread]