mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
Got the first part of the packing phase in place.
Generate kernel.S rather than have it as a manually maintained file.
This commit is contained in:
77
loader/SConscript
Normal file
77
loader/SConscript
Normal file
@@ -0,0 +1,77 @@
|
||||
# -*- mode: python; coding: utf-8; -*-
|
||||
|
||||
# Codezero -- a microkernel for embedded systems.
|
||||
#
|
||||
# Copyright © 2009 B Labs Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
# License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with this program. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author: Russel Winder
|
||||
|
||||
import os.path
|
||||
import subprocess
|
||||
|
||||
Import('environment', 'images')
|
||||
|
||||
def ksymToLds(target, source, env):
|
||||
symbols = ['break_virtual']
|
||||
with open(target[0].path, 'w') as asmFile:
|
||||
asmFile.write('''
|
||||
/*
|
||||
* %s autogenerated from %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.
|
||||
*/
|
||||
''' % (target[0].name, source[0].name))
|
||||
for symbol in symbols:
|
||||
process = subprocess.Popen('arm-none-eabi-objdump -d ' + source[0].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, (hex(int(address, 16) - 0xf0000000))))
|
||||
|
||||
def createKernelSFile(target, source, env):
|
||||
with open(target[0].path, 'w') as asmFile:
|
||||
asmFile.write('''
|
||||
/* This file defines kernel symbols extracted from the kernel image in their physical address */
|
||||
.include "start.axf.S"
|
||||
|
||||
.section .kernel
|
||||
|
||||
.incbin "%s"
|
||||
|
||||
''' % (source[0].path))
|
||||
for image in source[1:]:
|
||||
asmFile.write('''
|
||||
.align 4
|
||||
.section .%s
|
||||
.incbin "%s"
|
||||
''' % (os.path.splitext(image.name)[0], image.path))
|
||||
|
||||
startAxfS = Command('start.axf.S', images[0], ksymToLds)
|
||||
|
||||
kernelS = Command('kernel.S', images + [startAxfS], createKernelSFile)
|
||||
|
||||
objects = environment.Object(Glob('*.c') + [kernelS])
|
||||
Depends(objects, environment['configFiles'])
|
||||
Depends(objects, images)
|
||||
program = environment.Program('final', objects)
|
||||
|
||||
Return('program')
|
||||
Reference in New Issue
Block a user