OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [scripts/] [loader/] [generate_loader_asm.py] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#! /usr/bin/env python2.6
2
# -*- mode: python; coding: utf-8; -*-
3
#
4
#  Codezero -- a microkernel for embedded systems.
5
#
6
#  Copyright © 2009  B Labs Ltd
7
#
8
import os, sys, shelve, subprocess
9
from os.path import join
10
from configure import *
11
 
12
PROJRELROOT = '../../'
13
 
14
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), PROJRELROOT)))
15
 
16
from config.projpaths import *
17
from config.configuration import *
18
from config.lib import *
19
 
20
config = configuration_retrieve()
21
 
22
# Convert address from python literal to numeric value
23
def address_remove_literal(address):
24
    value = hex(int(address, 16) - 0xf0000000)
25
    if value[-1] in ['l', 'L']:
26
        value = value[:-1]
27
    return value
28
 
29
ksym_header = \
30
'''
31
/*
32
 * %s autogenerated from %s.
33
 * by %s
34
 *
35
 * This file is included by the loader sources so that any
36
 * kernel symbol address can be known in advance and stopped
37
 * at by debuggers before virtual memory is enabled.
38
 */
39
'''
40
 
41
assembler_symbol_definition = \
42
'''
43
.section .text
44
.align 4
45
.global %s
46
.type %s, function
47
.equ %s, %s
48
'''
49
 
50
def generate_ksym_to_loader(target_path, source_path):
51
    symbols = ['break_virtual']
52
    with open(target_path, 'w') as asm_file:
53
        asm_file.write(ksym_header % (target_path, source_path, sys.argv[0]))
54
        for symbol in symbols:
55
            process = \
56
                subprocess.Popen(config.toolchain_kernel + 'objdump -d ' + \
57
                                 source_path + ' | grep "<' + \
58
                                        symbol + '>"', shell=True, \
59
                                        stdout=subprocess.PIPE)
60
            assert process.wait() == 0
61
            address, name = process.stdout.read().split()
62
            assert '<' + symbol + '>:' == name
63
            asm_file.write(assembler_symbol_definition % \
64
                           (symbol, symbol, symbol, \
65
                            address_remove_literal(address)))
66
 
67
decl_sect_asm = \
68
'''
69
.align 4
70
.section %s
71
.incbin "%s"
72
'''
73
 
74
 
75
def generate_image_S(target_path, images):
76
    kern_fname = 'kernel.elf'
77
    conts_fname = 'containers.elf'
78
    fbody = ''
79
    with open(target_path, 'w+') as images_S:
80
        for img in images:
81
            if os.path.basename(img.path) == kern_fname:
82
                fbody += decl_sect_asm % ('.kernel', img)
83
            if os.path.basename(img.path) == conts_fname:
84
                fbody += decl_sect_asm % ('.containers', img)
85
        images_S.write(fbody)
86
 
87
if __name__ == "__main__":
88
    if len(sys.argv) == 1:
89
        generate_ksym_to_loader(join(PROJROOT, 'loader/ksyms.S'), \
90
                                join(BUILDDIR, 'kernel.elf'))
91
    elif len(sys.argv) == 3:
92
        generate_ksym_to_loader(sys.argv[1], sys.argv[1])
93
    else:
94
        print "Usage: %s <asm filename> <kernel image filename>" % sys.argv[0]
95
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.