#! /usr/bin/env python2.6 # -*- mode: python; coding: utf-8; -*- # # Codezero -- a microkernel for embedded systems. # # Copyright © 2009 B Labs Ltd # import os, sys, shelve, subprocess from os.path import join PROJRELROOT = '../../' SCRIPTROOT = os.path.abspath(os.path.dirname(".")) sys.path.append(os.path.abspath(PROJRELROOT)) from config.projpaths import * from config.configuration import * # Convert address from python literal to numeric value def address_remove_literal(address): value = hex(int(address, 16) - 0xf0000000) if value[-1] in ['l', 'L']: value = value[:-1] return value ksym_header = \ ''' /* * %s autogenerated from %s. * by %s * This file is included by the loader sources so that any * kernel symbol address can be known in advance and stopped * at by debuggers before virtual memory is enabled. */ ''' assembler_symbol_definition = \ ''' .section .text .align 4 .global %s .type %s, function .equ %s, %s ''' def generate_ksym_to_loader(target_path, source_path): symbols = ['break_virtual'] with open(target_path, 'w') as asmFile: asmFile.write(ksym_header % (target_path, source_path, __name__)) for symbol in symbols: process = subprocess.Popen('arm-none-eabi-objdump -d ' + source_path + ' | grep "<' + symbol + '>"', shell=True, stdout=subprocess.PIPE) assert process.wait() == 0 address, name = process.stdout.read().split() assert '<' + symbol + '>:' == name asmFile.write( ''' .section .text .align 4 .global %s .type %s, function .equ %s, %s ''' % (symbol, symbol, symbol, address_remove_literal(address))) if __name__ == "__main__": generate_ksym_to_loader(join(PROJROOT, 'loader/ksyms.S'), join(BUILDDIR, 'kernel.elf'))