Autogenerating the break_virtual symbol

This commit is contained in:
Bahadir Balban
2009-09-16 18:04:09 +03:00
parent ee44a2007a
commit 1925cd5704
4 changed files with 78 additions and 14 deletions

View File

@@ -10,7 +10,6 @@ from os.path import join
Import('env')
src = Glob('*.[cS]')
objs = env.Object(src)
Return('objs')

View File

@@ -1,7 +1,7 @@
/*
* Linker script that packs all containers in loader image.
* Loader linker script that contains kernel and container images
*
* Copyright (C) 2007-2009 B Labs Ltd.
* Copyright (C) 2008-2009 B Labs Ltd.
*/
ENTRY(_start)
@@ -13,17 +13,15 @@ SECTIONS
.rodata1 : { *(.rodata1) }
.data :
{
*(.data)
*(.data)
_start_kernel = .;
*(.kernel)
_end_kernel = .;
_start_containers = .;
*(.containers)
_end_containers = .;
}
_start_containers = .;
.cont.0 : { *(.cont.0) }
.cont.1 : { *(.cont.1) }
_end_containers = .;
.got : { *(.got) *(.got.plt) }
.bss : { *(.bss) }
}

View File

@@ -6,19 +6,22 @@
/* These symbols are defined by the linker script. */
extern char _start_kernel[];
extern char _end_kernel[];
extern char _start_containers[];
extern char _end_containers[];
/* This is a kernel symbol exported to loader's linker script from kernel build */
extern char bkpt_phys_to_virt[];
/*
void load_container_images(unsigned long start, unsigned long end)
{
struct elf_image *elf_img = (struct elf_image *)start;
int nsect_headers;
// Find all section headers
}
}
*/
int main(void)
{
void *kernel_entry = 0;
@@ -28,10 +31,10 @@ int main(void)
printf("ELF Loader: Started.\n");
printf("Loading the kernel...\n");
load_elf_image(&kernel_entry, _start_kernel, _end_kernel);
// load_elf_image(&kernel_entry, _start_kernel, _end_kernel);
printf("Loading containers...\n");
load_container_images(_start_containers, _end_containers)
// load_container_images(_start_containers, _end_containers)
printf("elf-loader:\tkernel entry point is %p\n", kernel_entry);
// arch_start_kernel(kernel_entry);

View File

@@ -0,0 +1,64 @@
#! /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'))