Subversion Repositories HelenOS

Compare Revisions

No changes between revisions

Ignore whitespace Rev 3102 → Rev 3107

/branches/dynload/kernel/generic/include/lib/rd.h
66,16 → 66,18
#define RE_UNSUPPORTED 2 /* Non-supported image (e.g. wrong version) */
 
/** RAM disk header */
typedef struct {
struct rd_header {
uint8_t magic[RD_MAGIC_SIZE];
uint8_t version;
uint8_t data_type;
uint32_t header_size;
uint64_t data_size;
} rd_header;
} __attribute__ ((packed));
 
extern int init_rd(rd_header * addr, size_t size);
typedef struct rd_header rd_header_t;
 
extern int init_rd(rd_header_t *addr, size_t size);
 
#endif
 
/** @}
/branches/dynload/kernel/generic/include/ipc/ipc.h
205,6 → 205,8
 
#define IPC_MAX_PHONES 16
 
#include <synch/spinlock.h>
#include <synch/mutex.h>
#include <synch/waitq.h>
 
struct answerbox;
225,7 → 227,7
 
/** Structure identifying phone (in TASK structure) */
typedef struct {
SPINLOCK_DECLARE(lock);
mutex_t lock;
link_t link;
struct answerbox *callee;
ipc_phone_state_t state;
/branches/dynload/kernel/generic/src/main/kinit.c
189,7 → 189,7
/* It was the program loader and was registered */
} else {
/* RAM disk image */
int rd = init_rd((rd_header *) init.tasks[i].addr,
int rd = init_rd((rd_header_t *) init.tasks[i].addr,
init.tasks[i].size);
if (rd != RE_OK)
/branches/dynload/kernel/generic/src/lib/rd.c
42,7 → 42,6
#include <mm/frame.h>
#include <sysinfo/sysinfo.h>
#include <ddi/ddi.h>
#include <print.h>
#include <align.h>
 
static parea_t rd_parea; /**< Physical memory area for rd. */
52,7 → 51,7
* and information about the share is provided as sysinfo values to the userspace
* tasks.
*/
int init_rd(rd_header * header, size_t size)
int init_rd(rd_header_t *header, size_t size)
{
/* Identify RAM disk */
if ((header->magic[0] != RD_MAG0) || (header->magic[1] != RD_MAG1) ||
80,10 → 79,7
if ((hsize % FRAME_SIZE) || (dsize % FRAME_SIZE))
return RE_UNSUPPORTED;
if (dsize % FRAME_SIZE)
return RE_UNSUPPORTED;
 
if (hsize > size)
return RE_INVALID;
/branches/dynload/kernel/generic/src/lib/elf.c
166,9 → 166,11
case PT_DYNAMIC:
case PT_INTERP:
interp = (char *)elf + entry->p_offset;
if (memcmp(interp, ELF_INTERP_ZSTR, ELF_INTERP_ZLEN) != 0) {
/* DO NOT COMMIT ME */
/*if (memcmp((uintptr_t)interp, (uintptr_t)ELF_INTERP_ZSTR,
ELF_INTERP_ZLEN) != 0) {
return EE_UNSUPPORTED;
}
}*/
if ((flags & ELD_F_LOADER) == 0) {
return EE_LOADER;
}
/branches/dynload/kernel/generic/src/ipc/sysipc.c
168,7 → 168,7
/* In case of forward, hangup the forwared phone,
* not the originator
*/
spinlock_lock(&answer->data.phone->lock);
mutex_lock(&answer->data.phone->lock);
spinlock_lock(&TASK->answerbox.lock);
if (answer->data.phone->state == IPC_PHONE_CONNECTED) {
list_remove(&answer->data.phone->link);
175,7 → 175,7
answer->data.phone->state = IPC_PHONE_SLAMMED;
}
spinlock_unlock(&TASK->answerbox.lock);
spinlock_unlock(&answer->data.phone->lock);
mutex_unlock(&answer->data.phone->lock);
}
 
if (!olddata)
/branches/dynload/kernel/generic/src/ipc/ipc.c
37,7 → 37,9
* First the answerbox, then the phone.
*/
 
#include <synch/synch.h>
#include <synch/spinlock.h>
#include <synch/mutex.h>
#include <synch/waitq.h>
#include <synch/synch.h>
#include <ipc/ipc.h>
140,7 → 142,7
*/
void ipc_phone_connect(phone_t *phone, answerbox_t *box)
{
spinlock_lock(&phone->lock);
mutex_lock(&phone->lock);
 
phone->state = IPC_PHONE_CONNECTED;
phone->callee = box;
149,7 → 151,7
list_append(&phone->link, &box->connected_phones);
spinlock_unlock(&box->lock);
 
spinlock_unlock(&phone->lock);
mutex_unlock(&phone->lock);
}
 
/** Initialize a phone structure.
158,7 → 160,7
*/
void ipc_phone_init(phone_t *phone)
{
spinlock_initialize(&phone->lock, "phone_lock");
mutex_initialize(&phone->lock);
phone->callee = NULL;
phone->state = IPC_PHONE_FREE;
atomic_set(&phone->active_calls, 0);
261,9 → 263,9
{
answerbox_t *box;
 
spinlock_lock(&phone->lock);
mutex_lock(&phone->lock);
if (phone->state != IPC_PHONE_CONNECTED) {
spinlock_unlock(&phone->lock);
mutex_unlock(&phone->lock);
if (call->flags & IPC_CALL_FORWARDED) {
IPC_SET_RETVAL(call->data, EFORWARD);
_ipc_answer_free_call(call);
278,7 → 280,7
box = phone->callee;
_ipc_call(phone, box, call);
spinlock_unlock(&phone->lock);
mutex_unlock(&phone->lock);
return 0;
}
 
297,11 → 299,11
answerbox_t *box;
call_t *call;
spinlock_lock(&phone->lock);
mutex_lock(&phone->lock);
if (phone->state == IPC_PHONE_FREE ||
phone->state == IPC_PHONE_HUNGUP ||
phone->state == IPC_PHONE_CONNECTING) {
spinlock_unlock(&phone->lock);
mutex_unlock(&phone->lock);
return -1;
}
box = phone->callee;
320,7 → 322,7
}
 
phone->state = IPC_PHONE_HUNGUP;
spinlock_unlock(&phone->lock);
mutex_unlock(&phone->lock);
 
return 0;
}
449,7 → 451,7
while (!list_empty(&TASK->answerbox.connected_phones)) {
phone = list_get_instance(TASK->answerbox.connected_phones.next,
phone_t, link);
if (!spinlock_trylock(&phone->lock)) {
if (SYNCH_FAILED(mutex_trylock(&phone->lock))) {
spinlock_unlock(&TASK->answerbox.lock);
DEADLOCK_PROBE(p_phonelck, DEADLOCK_THRESHOLD);
goto restart_phones;
460,7 → 462,7
phone->state = IPC_PHONE_SLAMMED;
list_remove(&phone->link);
 
spinlock_unlock(&phone->lock);
mutex_unlock(&phone->lock);
}
 
/* Answer all messages in 'calls' and 'dispatched_calls' queues */
535,7 → 537,10
/* Print opened phones & details */
printf("PHONE:\n");
for (i = 0; i < IPC_MAX_PHONES; i++) {
spinlock_lock(&task->phones[i].lock);
if (SYNCH_FAILED(mutex_trylock(&task->phones[i].lock))) {
printf("%d: mutex busy\n", i);
continue;
}
if (task->phones[i].state != IPC_PHONE_FREE) {
printf("%d: ", i);
switch (task->phones[i].state) {
560,7 → 565,7
printf("active: %d\n",
atomic_get(&task->phones[i].active_calls));
}
spinlock_unlock(&task->phones[i].lock);
mutex_unlock(&task->phones[i].lock);
}
 
 
579,7 → 584,7
}
/* Print answerbox - calls */
printf("ABOX - DISPATCHED CALLS:\n");
for (tmp=task->answerbox.dispatched_calls.next;
for (tmp = task->answerbox.dispatched_calls.next;
tmp != &task->answerbox.dispatched_calls;
tmp = tmp->next) {
call = list_get_instance(tmp, call_t, link);
/branches/dynload/kernel/arch/amd64/include/memstr.h
35,110 → 35,13
#ifndef KERN_amd64_MEMSTR_H_
#define KERN_amd64_MEMSTR_H_
 
/** Copy memory
*
* Copy a given number of bytes (3rd argument)
* from the memory location defined by 2nd argument
* to the memory location defined by 1st argument.
* The memory areas cannot overlap.
*
* @param dst Destination
* @param src Source
* @param cnt Number of bytes
* @return Destination
*/
static inline void * memcpy(void * dst, const void * src, size_t cnt)
{
unative_t d0, d1, d2;
#define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt))
 
asm volatile(
"rep movsq\n\t"
"movq %4, %%rcx\n\t"
"andq $7, %%rcx\n\t"
"jz 1f\n\t"
"rep movsb\n\t"
"1:\n"
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
: "0" ((unative_t)(cnt / 8)), "g" ((unative_t)cnt), "1" ((unative_t) dst), "2" ((unative_t) src)
: "memory");
extern void memsetw(uintptr_t dst, size_t cnt, uint16_t x);
extern void memsetb(uintptr_t dst, size_t cnt, uint8_t x);
 
return dst;
}
extern int memcmp(uintptr_t src, uintptr_t dst, int cnt);
 
 
/** Compare memory regions for equality
*
* Compare a given number of bytes (3rd argument)
* at memory locations defined by 1st and 2nd argument
* for equality. If bytes are equal function returns 0.
*
* @param src Region 1
* @param dst Region 2
* @param cnt Number of bytes
* @return Zero if bytes are equal, non-zero otherwise
*/
static inline int memcmp(const void * src, const void * dst, size_t cnt)
{
unative_t d0, d1, d2;
unative_t ret;
asm (
"repe cmpsb\n\t"
"je 1f\n\t"
"movq %3, %0\n\t"
"addq $1, %0\n\t"
"1:\n"
: "=a" (ret), "=%S" (d0), "=&D" (d1), "=&c" (d2)
: "0" (0), "1" (src), "2" (dst), "3" ((unative_t)cnt)
);
return ret;
}
 
/** Fill memory with words
* Fill a given number of words (2nd argument)
* at memory defined by 1st argument with the
* word value defined by 3rd argument.
*
* @param dst Destination
* @param cnt Number of words
* @param x Value to fill
*/
static inline void memsetw(uintptr_t dst, size_t cnt, uint16_t x)
{
unative_t d0, d1;
asm volatile (
"rep stosw\n\t"
: "=&D" (d0), "=&c" (d1), "=a" (x)
: "0" (dst), "1" ((unative_t)cnt), "2" (x)
: "memory"
);
 
}
 
/** Fill memory with bytes
* Fill a given number of bytes (2nd argument)
* at memory defined by 1st argument with the
* word value defined by 3rd argument.
*
* @param dst Destination
* @param cnt Number of bytes
* @param x Value to fill
*/
static inline void memsetb(uintptr_t dst, size_t cnt, uint8_t x)
{
unative_t d0, d1;
asm volatile (
"rep stosb\n\t"
: "=&D" (d0), "=&c" (d1), "=a" (x)
: "0" (dst), "1" ((unative_t)cnt), "2" (x)
: "memory"
);
 
}
 
#endif
 
/** @}
/branches/dynload/kernel/arch/amd64/src/asm_utils.S
65,6 → 65,8
.global get_cycle
.global read_efer_flag
.global set_efer_flag
.global memsetb
.global memsetw
.global memcpy
.global memcpy_from_uspace
.global memcpy_to_uspace
71,6 → 73,14
.global memcpy_from_uspace_failover_address
.global memcpy_to_uspace_failover_address
 
# Wrapper for generic memsetb
memsetb:
jmp _memsetb
 
# Wrapper for generic memsetw
memsetw:
jmp _memsetw
 
#define MEMCPY_DST %rdi
#define MEMCPY_SRC %rsi
#define MEMCPY_SIZE %rdx
/branches/dynload/kernel/arch/mips32/include/atomic.h
63,7 → 63,7
" sc %0, %1\n"
" beq %0, %4, 1b\n" /* if the atomic operation failed, try again */
" nop\n"
: "=r" (tmp), "=m" (val->count), "=r" (v)
: "=&r" (tmp), "=m" (val->count), "=&r" (v)
: "i" (i), "i" (0)
);
 
/branches/dynload/kernel/arch/ia32/include/memstr.h
35,116 → 35,13
#ifndef KERN_ia32_MEMSTR_H_
#define KERN_ia32_MEMSTR_H_
 
/** Copy memory
*
* Copy a given number of bytes (3rd argument)
* from the memory location defined by 2nd argument
* to the memory location defined by 1st argument.
* The memory areas cannot overlap.
*
* @param dst Destination
* @param src Source
* @param cnt Number of bytes
* @return Destination
*/
static inline void * memcpy(void * dst, const void * src, size_t cnt)
{
unative_t d0, d1, d2;
#define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt))
 
asm volatile(
/* copy all full dwords */
"rep movsl\n\t"
/* load count again */
"movl %4, %%ecx\n\t"
/* ecx = ecx mod 4 */
"andl $3, %%ecx\n\t"
/* are there last <=3 bytes? */
"jz 1f\n\t"
/* copy last <=3 bytes */
"rep movsb\n\t"
/* exit from asm block */
"1:\n"
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
: "0" ((unative_t) (cnt / 4)), "g" ((unative_t) cnt), "1" ((unative_t) dst), "2" ((unative_t) src)
: "memory");
extern void memsetw(uintptr_t dst, size_t cnt, uint16_t x);
extern void memsetb(uintptr_t dst, size_t cnt, uint8_t x);
 
return dst;
}
extern int memcmp(uintptr_t src, uintptr_t dst, int cnt);
 
 
/** Compare memory regions for equality
*
* Compare a given number of bytes (3rd argument)
* at memory locations defined by 1st and 2nd argument
* for equality. If bytes are equal function returns 0.
*
* @param src Region 1
* @param dst Region 2
* @param cnt Number of bytes
* @return Zero if bytes are equal, non-zero otherwise
*/
static inline int memcmp(const void * src, const void * dst, size_t cnt)
{
uint32_t d0, d1, d2;
int ret;
asm (
"repe cmpsb\n\t"
"je 1f\n\t"
"movl %3, %0\n\t"
"addl $1, %0\n\t"
"1:\n"
: "=a" (ret), "=%S" (d0), "=&D" (d1), "=&c" (d2)
: "0" (0), "1" ((unative_t) src), "2" ((unative_t) dst), "3" ((unative_t) cnt)
);
return ret;
}
 
/** Fill memory with words
* Fill a given number of words (2nd argument)
* at memory defined by 1st argument with the
* word value defined by 3rd argument.
*
* @param dst Destination
* @param cnt Number of words
* @param x Value to fill
*/
static inline void memsetw(uintptr_t dst, size_t cnt, uint16_t x)
{
uint32_t d0, d1;
asm volatile (
"rep stosw\n\t"
: "=&D" (d0), "=&c" (d1), "=a" (x)
: "0" (dst), "1" (cnt), "2" (x)
: "memory"
);
 
}
 
/** Fill memory with bytes
* Fill a given number of bytes (2nd argument)
* at memory defined by 1st argument with the
* word value defined by 3rd argument.
*
* @param dst Destination
* @param cnt Number of bytes
* @param x Value to fill
*/
static inline void memsetb(uintptr_t dst, size_t cnt, uint8_t x)
{
uint32_t d0, d1;
asm volatile (
"rep stosb\n\t"
: "=&D" (d0), "=&c" (d1), "=a" (x)
: "0" (dst), "1" (cnt), "2" (x)
: "memory"
);
 
}
 
#endif
 
/** @}
/branches/dynload/kernel/arch/ia32/src/asm.S
37,6 → 37,8
.global paging_on
.global enable_l_apic_in_msr
.global interrupt_handlers
.global memsetb
.global memsetw
.global memcpy
.global memcpy_from_uspace
.global memcpy_from_uspace_failover_address
44,6 → 46,15
.global memcpy_to_uspace_failover_address
 
 
# Wrapper for generic memsetb
memsetb:
jmp _memsetb
 
# Wrapper for generic memsetw
memsetw:
jmp _memsetw
 
 
#define MEMCPY_DST 4
#define MEMCPY_SRC 8
#define MEMCPY_SIZE 12
/branches/dynload/tools/cygwin_symlink_patch.sh
File deleted
/branches/dynload/tools/fix_symlinks.sh
0,0 → 1,24
#!/bin/bash
 
# by Alf
# This script solves malfunction of symlinks in cygwin
#
# Download sources from repository and than run this script to correct symlinks
# to be able compile project
 
 
if uname | grep 'CYGWIN' > /dev/null; then
echo "Good ... you have cygwin"
else
echo "Wrong. This script is only for cygwin"
exit
fi
for linkName in `find . ! -iwholename '.*svn*' ! -type d -print`; do
if head -n 1 $linkName | grep '^link' > /dev/null; then
linkTarget=`head -n 1 $linkName | sed 's/^link //'`
echo $linkName " -> " $linkTarget
rm $linkName
ln -s "$linkTarget" "$linkName"
fi
done
/branches/dynload/tools/mktmpfs.py
0,0 → 1,101
#!/usr/bin/env python
#
# Copyright (c) 2008 Martin Decky
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# - The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""
TMPFS creator
"""
 
import sys
import os
import struct
 
def align_up(size, alignment):
"Align upwards to a given alignment"
return (((size) + ((alignment) - 1)) & ~((alignment) - 1))
 
def usage(prname):
"Print usage syntax"
print prname + " <ALIGNMENT> <PATH> <IMAGE>"
 
def main():
if (len(sys.argv) < 4):
usage(sys.argv[0])
return
if (not sys.argv[1].isdigit()):
print "<ALIGNMENT> must be a number"
return
align = int(sys.argv[1], 0)
path = os.path.abspath(sys.argv[2])
if (not os.path.isdir(path)):
print "<PATH> must be a directory"
return
header_size = align_up(18, align)
payload_size = 0
outf = file(sys.argv[3], "w")
outf.write(struct.pack("<" + ("%d" % header_size) + "x"))
for root, dirs, files in os.walk(path):
relpath = root[len(path):len(root)]
for name in files:
canon = os.path.join(relpath, name)
outf.write(struct.pack("<BL" + ("%d" % len(canon)) + "s", 1, len(canon), canon))
payload_size += 5 + len(canon)
fn = os.path.join(root, name)
size = os.path.getsize(fn)
rd = 0;
outf.write(struct.pack("<L", size))
payload_size += 4
inf = file(fn, "r")
while (rd < size):
data = inf.read(4096);
outf.write(data)
payload_size += len(data)
rd += len(data)
inf.close()
for name in dirs:
canon = os.path.join(relpath, name)
outf.write(struct.pack("<BL" + ("%d" % len(canon)) + "s", 2, len(canon), canon))
payload_size += 5 + len(canon)
aligned_size = align_up(payload_size, align)
if (aligned_size - payload_size > 0):
outf.write(struct.pack("<" + ("%d" % (aligned_size - payload_size)) + "x"))
outf.seek(0)
outf.write(struct.pack("<4sBBLQ", "HORD", 1, 1, header_size, aligned_size))
outf.close()
 
if __name__ == '__main__':
main()
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/branches/dynload/tools/config.py
1,6 → 1,6
#!/usr/bin/env python
#
# Copyright (c) 2006 Ondrej Palkovsky
# Copyright (c) 2006 Ondrej Palkovsky
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
/branches/dynload/uspace/lib/libc/arch/mips32/include/atomic.h
64,7 → 64,7
" sc %0, %1\n"
" beq %0, %4, 1b\n" /* if the atomic operation failed, try again */
/* nop */ /* nop is inserted automatically by compiler */
: "=r" (tmp), "=m" (val->count), "=r" (v)
: "=&r" (tmp), "=m" (val->count), "=&r" (v)
: "i" (i), "i" (0)
);
 
/branches/dynload/uspace/srv/pci/update-ids
2,15 → 2,14
 
wget http://pciids.sourceforge.net/v2.2/pci.ids
 
cat >pci_ids.h <<EOF
cat > pci_ids.h <<EOF
/* DO NOT EDIT, THIS FILE IS AUTOMATICALLY GENERATED */
char *pci_ids[] = {
EOF
 
cat pci.ids | grep -v '^#.*' | grep -v '^$' | tr \" \' | sed -n 's/\(.*\)/"\1",/p' >>pci_ids.h
cat pci.ids | grep -v '^#.*' | grep -v '^$' | tr \" \' | sed -n 's/\(.*\)/"\1",/p' >> pci_ids.h
 
cat >>pci_ids.h <<EOF
cat >> pci_ids.h <<EOF
""
};
EOF
 
/branches/dynload/HelenOS.config
44,7 → 44,7
@ "msim" MSIM
@ "simics" Simics
@ "bgxemul" GXEmul big endian
@ "lgxemul" GXEmul little endia
@ "lgxemul" GXEmul little endian
@ "indy" Sgi Indy
! [PLATFORM=mips32] MACHINE (choice)
 
/branches/dynload/boot/tools/pack.py
0,0 → 1,132
#!/usr/bin/env python
#
# Copyright (c) 2008 Martin Decky
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# - The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""
Binary package creator
"""
 
import sys
import os
import subprocess
 
def usage(prname):
"Print usage syntax"
print prname + " <OBJCOPY> <FORMAT> <ARCH> <ALIGNMENT> <UINTPTR>"
 
def main():
if (len(sys.argv) < 6):
usage(sys.argv[0])
return
if (not sys.argv[4].isdigit()):
print "<ALIGNMENT> must be a number"
return
objcopy = sys.argv[1]
format = sys.argv[2]
arch = sys.argv[3]
align = int(sys.argv[4], 0)
uintptr = sys.argv[5]
workdir = os.getcwd()
header = file("_components.h", "w")
data = file("_components.c", "w")
header.write("#ifndef ___COMPONENTS_H__\n")
header.write("#define ___COMPONENTS_H__\n\n")
data.write("#include \"_components.h\"\n\n")
data.write("void init_components(component_t *components)\n")
data.write("{\n")
cnt = 0
link = ""
for task in sys.argv[6:]:
basename = os.path.basename(task)
plainname = os.path.splitext(basename)[0]
path = os.path.dirname(task)
object = plainname + ".o"
symbol = "_binary_" + basename.replace(".", "_")
macro = plainname.upper()
print task + " -> " + object
if (align > 1):
link += "\t\t. = ALIGN(" + ("%d" % align) + ");\n"
link += "\t\t*(." + plainname + "_image);\n"
header.write("extern int " + symbol + "_start;\n")
header.write("extern int " + symbol + "_end;\n\n")
header.write("#define " + macro + "_START ((void *) &" + symbol + "_start)\n")
header.write("#define " + macro + "_END ((void *) &" + symbol + "_end)\n")
header.write("#define " + macro + "_SIZE ((" + uintptr + ") " + macro + "_END - (" + uintptr + ") " + macro + "_START)\n\n")
data.write("\tcomponents[" + ("%d" % cnt) + "].name = \"" + plainname + "\";\n")
data.write("\tcomponents[" + ("%d" % cnt) + "].start = " + macro + "_START;\n")
data.write("\tcomponents[" + ("%d" % cnt) + "].end = " + macro + "_END;\n")
data.write("\tcomponents[" + ("%d" % cnt) + "].size = " + macro + "_SIZE;\n\n")
os.chdir(path)
subprocess.call([objcopy,
"-I", "binary",
"-O", format,
"-B", arch,
"--rename-section", ".data=." + plainname + "_image",
basename, os.path.join(workdir, object)])
os.chdir(workdir)
cnt += 1
header.write("#define COMPONENTS " + ("%d" % cnt) + "\n\n")
header.write("typedef struct {\n")
header.write("\tchar *name;\n\n")
header.write("\tvoid *start;\n")
header.write("\tvoid *end;\n")
header.write("\t" + uintptr + " size;\n")
header.write("} component_t;\n\n")
header.write("extern void init_components(component_t *components);\n\n")
header.write("#endif\n")
data.write("}\n")
header.close()
data.close()
linkname = "_link.ld"
link_in = file(linkname + ".in", "r")
template = link_in.read(os.path.getsize(linkname + ".in"))
link_in.close()
link_out = file(linkname, "w")
link_out.write(template.replace("[[COMPONENTS]]", link))
link_out.close()
 
if __name__ == '__main__':
main()
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/branches/dynload/boot/arch/sparc64/loader/pack
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/branches/dynload/boot/arch/sparc64/loader/_link.ld.in
0,0 → 1,23
OUTPUT_FORMAT("elf64-sparc")
ENTRY(start)
 
SECTIONS {
.boot 0x4000: AT (0x4000) {
*(BOOTSTRAP);
*(.text);
*(.rodata);
*(.rodata.*);
*(.data); /* initialized data */
*(.sdata);
*(.sdata2);
*(.sbss);
*(.bss); /* uninitialized static variables */
*(COMMON);
[[COMPONENTS]]
}
/DISCARD/ : {
*(.comment);
*(.note*);
}
}
/branches/dynload/boot/arch/sparc64/loader/Makefile
32,6 → 32,8
## Toolchain configuration
#
 
BFD_NAME = elf64-sparc
BFD_ARCH = sparc
TARGET = sparc64-linux-gnu
TOOLCHAIN_DIR = /usr/local/sparc64/bin
 
43,14 → 45,6
OBJDUMP = objdump
endif
 
ifeq ($(COMPILER),icc_native)
CC = icc
AS = as
LD = ld
OBJCOPY = objcopy
OBJDUMP = objdump
endif
 
ifeq ($(COMPILER),gcc_cross)
CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc
AS = $(TOOLCHAIN_DIR)/$(TARGET)-as
71,6 → 65,7
 
SOURCES = \
main.c \
_components.c \
../../../generic/printf.c \
../../../generic/string.c \
../../../genarch/balloc.c \
111,10 → 106,10
-makedepend $(DEFS) $(CFLAGS) -f - $(SOURCES) > Makefile.depend 2> /dev/null
 
clean:
-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot boot.disasm Makefile.depend
-rm -f _components.h _components.c _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot image.map image.disasm Makefile.depend
 
_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
./pack $(IMAGE) $(OBJCOPY) $(COMPONENTS)
_components.h _components.c _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS) _link.ld.in
../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD_ARCH) 1 "unsigned long" $(COMPONENTS)
 
%.o: %.S
$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
123,4 → 118,4
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@
 
disasm: image.boot
$(OBJDUMP) -d image.boot > boot.disasm
$(OBJDUMP) -d image.boot > image.disasm
/branches/dynload/boot/arch/ia64/loader/pack
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/branches/dynload/boot/arch/ia64/loader/_link.ld.in
0,0 → 1,26
OUTPUT_FORMAT("elf64-ia64-little")
ENTRY(start)
 
SECTIONS {
.boot 0x4400000: AT (0x4400000) {
*(BOOTSTRAP);
[[COMPONENTS]]
. = ALIGN (16384);
*(.text);
*(.rodata);
*(.rodata.*);
*(.data); /* initialized data */
_got = . ;
*(.got .got.*);
*(.sdata);
*(.sdata2);
*(.sbss);
*(.bss); /* uninitialized static variables */
*(COMMON);
}
/DISCARD/ : {
*(.comment);
*(.note*);
}
}
/branches/dynload/boot/arch/ia64/loader/Makefile
32,6 → 32,8
## Toolchain configuration
#
 
BFD_NAME = elf64-ia64-little
BFD_ARCH = ia64
TARGET = ia64-pc-linux-gnu
TOOLCHAIN_DIR = /usr/local/ia64/bin
 
77,6 → 79,7
../../../generic/printf.c \
../../../generic/string.c \
../../../genarch/balloc.c \
_components.c \
asm.S \
boot.S
 
95,7 → 98,6
$(USPACEDIR)/app/tester/tester \
$(USPACEDIR)/app/klog/klog
 
 
OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
COMPONENT_OBJECTS := $(addsuffix .o,$(basename $(notdir $(COMPONENTS))))
 
105,7 → 107,6
 
-include Makefile.depend
 
 
hello.efi: image.boot
make -C gefi/HelenOS PREFIX=$(GEFI_PREFIX)
cp gefi/HelenOS/hello.efi ../../../../
113,17 → 114,17
cp gefi/HelenOS/image.bin ../../../../
 
image.boot: depend _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS)
$(LD) -Map boot.map -no-check-sections -N -T _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) -o $@
$(LD) -Map image.map -no-check-sections -N -T _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) -o $@
 
depend:
-makedepend $(DEFS) $(CFLAGS) -f - $(SOURCES) > Makefile.depend 2> /dev/null
 
clean:
-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot boot.disasm Makefile.depend
-rm -f _components.h _components.c _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot image.map image.disasm Makefile.depend
make -C gefi/HelenOS clean
 
_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
./pack $(IMAGE) $(OBJCOPY) $(COMPONENTS)
_components.h _components.c _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS) _link.ld.in
../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD_ARCH) 16384 "unsigned long" $(COMPONENTS)
 
%.o: %.S
$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
132,4 → 133,4
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@
 
disasm: image.boot
$(OBJDUMP) -d image.boot > boot.disasm
$(OBJDUMP) -d image.boot > image.disasm
/branches/dynload/boot/arch/arm32/loader/pack
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/branches/dynload/boot/arch/arm32/loader/_link.ld.in
0,0 → 1,24
OUTPUT_FORMAT("elf32-littlearm")
ENTRY(start)
 
SECTIONS {
.boot 0x0: AT (0) {
*(BOOTSTRAP);
*(.text);
*(.rodata);
*(.rodata.*);
*(.data); /* initialized data */
*(.sdata);
*(.sdata2);
*(.sbss);
*(.scommon);
*(.bss); /* uninitialized static variables */
*(COMMON); /* global variables */
*(.reginfo);
 
. = 0x4000;
*(PT); /* page table placed at 0x4000 */
[[COMPONENTS]]
}
}
/branches/dynload/boot/arch/arm32/loader/main.c
76,9 → 76,10
version_print();
 
component_t components[COMPONENTS];
bootinfo_t bootinfo;
init_components(components);
bootinfo_t bootinfo;
printf("\nMemory statistics\n");
printf(" kernel entry point at %L\n", KERNEL_VIRTUAL_ADDRESS);
printf(" %L: boot info structure\n", &bootinfo);
/branches/dynload/boot/arch/arm32/loader/Makefile
27,21 → 27,25
#
 
include ../../../../version
include ../../../../Makefile.config
include ../../../Makefile.config
 
## Toolchain configuration
#
 
BFD_NAME = elf32-littlearm
BFD_ARCH = arm
TARGET = arm-linux-gnu
TOOLCHAIN_DIR = /usr/local/arm/bin
 
ifeq ($(COMPILER),native)
ifeq ($(COMPILER),gcc_native)
CC = gcc
AS = as
LD = ld
OBJCOPY = objcopy
OBJDUMP = objdump
else
endif
 
ifeq ($(COMPILER),gcc_cross)
CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc
AS = $(TOOLCHAIN_DIR)/$(TARGET)-as
LD = $(TOOLCHAIN_DIR)/$(TARGET)-ld
68,24 → 72,23
boot.S \
asm.S \
mm.c \
print/gxemul.c \
_components.c \
../../../generic/printf.c \
../../../genarch/division.c
 
ifeq ($(MACHINE), gxemul_testarm)
SOURCES += print/gxemul.c
endif
 
 
COMPONENTS = \
$(KERNELDIR)/kernel.bin \
$(USPACEDIR)/srv/ns/ns \
$(USPACEDIR)/srv/fb/fb \
$(USPACEDIR)/srv/kbd/kbd \
$(USPACEDIR)/srv/console/console \
$(USPACEDIR)/srv/fb/fb \
$(USPACEDIR)/srv/vfs/vfs \
$(USPACEDIR)/srv/fs/tmpfs/tmpfs \
$(USPACEDIR)/srv/devmap/devmap \
$(USPACEDIR)/app/init/init \
$(USPACEDIR)/app/tetris/tetris \
$(USPACEDIR)/app/tester/tester \
$(USPACEDIR)/app/klog/klog \
$(USPACEDIR)/app/iramfs/iramfs \
$(USPACEDIR)/app/iloader/iloader \
100,17 → 103,17
 
-include Makefile.depend
 
image.boot: depend _components.h _link.ld $(OBJECTS) $(COMPONENT_OBJECTS)
$(LD) -no-check-sections -N -T _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) -o $@
image.boot: depend _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS)
$(LD) -no-check-sections -N -T _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) -o $@
 
depend:
-makedepend $(DEFS) $(CFLAGS) -f - $(SOURCES) > Makefile.depend 2> /dev/null
 
clean:
-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
-rm -f _components.h _components.c _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
 
_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
./pack $(IMAGE) $(OBJCOPY) $(COMPONENTS)
_components.h _components.c _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS) _link.ld.in
../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD_ARCH) 4096 "unsigned int" $(COMPONENTS)
 
%.o: %.S
$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
/branches/dynload/boot/arch/ppc32/loader/pack
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/branches/dynload/boot/arch/ppc32/loader/_link.ld.in
0,0 → 1,21
OUTPUT_FORMAT("elf32-powerpc")
OUTPUT_ARCH(powerpc:common)
ENTRY(start)
SECTIONS {
.boot 0x10000000: AT (0) {
*(BOOTSTRAP);
*(REALMODE);
*(.text);
*(.rodata);
*(.rodata.*);
*(.data); /* initialized data */
*(.sdata);
*(.sdata2);
*(.sbss);
*(.bss); /* uninitialized static variables */
*(COMMON); /* global variables */
[[COMPONENTS]]
}
}
/branches/dynload/boot/arch/ppc32/loader/main.c
96,10 → 96,10
{
version_print();
init_components();
component_t components[COMPONENTS];
init_components(components);
unsigned int i;
for (i = 0; i < COMPONENTS; i++)
check_align(components[i].start, components[i].name);
/branches/dynload/boot/arch/ppc32/loader/Makefile
32,6 → 32,8
## Toolchain configuration
#
 
BFD_NAME = elf32-powerpc
BFD_ARCH = powerpc:common
TARGET = ppc-linux-gnu
TOOLCHAIN_DIR = /usr/local/ppc/bin
 
43,14 → 45,6
OBJDUMP = objdump
endif
 
ifeq ($(COMPILER),icc_native)
CC = icc
AS = as
LD = ld
OBJCOPY = objcopy
OBJDUMP = objdump
endif
 
ifeq ($(COMPILER),gcc_cross)
CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc
AS = $(TOOLCHAIN_DIR)/$(TARGET)-as
72,6 → 66,7
SOURCES = \
main.c \
ofwarch.c \
_components.c \
../../../genarch/ofw.c \
../../../generic/printf.c \
asm.S \
108,10 → 103,10
-makedepend $(DEFS) $(CFLAGS) -f - $(SOURCES) > Makefile.depend 2> /dev/null
 
clean:
-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
-rm -f _components.h _components.c _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
 
_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
./pack $(OBJCOPY) $(COMPONENTS)
_components.h _components.c _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS) _link.ld.in
../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD_ARCH) 4096 "unsigned int" $(COMPONENTS)
 
%.o: %.S
$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
/branches/dynload/boot/arch/ppc64/loader/pack
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/branches/dynload/boot/arch/ppc64/loader/_link.ld.in
0,0 → 1,27
OUTPUT_FORMAT("elf64-powerpc")
OUTPUT_ARCH(powerpc:common64)
ENTRY(start)
SECTIONS {
.boot 0x0000000010000000: AT (0) {
*(BOOTSTRAP);
*(REALMODE);
*(.text);
*(.toc);
*(.opd);
*(.rodata);
*(.rodata.*);
*(.data); /* initialized data */
*(.sdata);
*(.sdata2);
*(.sbss);
*(.bss); /* uninitialized static variables */
*(COMMON); /* global variables */
[[COMPONENTS]]
}
/DISCARD/ : {
*(*);
}
}
/branches/dynload/boot/arch/ppc64/loader/main.c
96,8 → 96,9
{
version_print();
init_components();
component_t components[COMPONENTS];
init_components(components);
unsigned int i;
for (i = 0; i < COMPONENTS; i++)
/branches/dynload/boot/arch/ppc64/loader/Makefile
32,6 → 32,8
## Toolchain configuration
#
 
BFD_NAME = elf64-powerpc
BFD_ARCH = powerpc:common64
TARGET = ppc64-linux-gnu
TOOLCHAIN_DIR = /usr/local/ppc64/bin
 
43,14 → 45,6
OBJDUMP = objdump
endif
 
ifeq ($(COMPILER),icc_native)
CC = icc
AS = as
LD = ld
OBJCOPY = objcopy
OBJDUMP = objdump
endif
 
ifeq ($(COMPILER),gcc_cross)
CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc
AS = $(TOOLCHAIN_DIR)/$(TARGET)-as
72,6 → 66,7
SOURCES = \
main.c \
ofwarch.c \
_components.c \
../../../genarch/ofw.c \
../../../generic/printf.c \
asm.S \
108,10 → 103,10
-makedepend $(DEFS) $(CFLAGS) -f - $(SOURCES) > Makefile.depend 2> /dev/null
 
clean:
-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
-rm -f _components.h _components.c _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
 
_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
./pack $(OBJCOPY) $(COMPONENTS)
_components.h _components.c _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS) _link.ld.in
../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD_ARCH) 4096 "unsigned long" $(COMPONENTS)
 
%.o: %.S
$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
/branches/dynload/boot/arch/mips32/loader/pack
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/branches/dynload/boot/arch/mips32/loader/_link.ld.in.ecoff
0,0 → 1,21
OUTPUT_FORMAT("ecoff-littlemips")
ENTRY(start)
SECTIONS {
.boot 0xbfc00000: AT (0) {
*(BOOTSTRAP);
*(.text);
*(.rodata);
*(.rodata.*);
*(.data); /* initialized data */
*(.sdata);
*(.sdata2);
*(.sbss);
*(.scommon);
*(.bss); /* uninitialized static variables */
*(COMMON); /* global variables */
*(.reginfo);
[[COMPONENTS]]
}
}
/branches/dynload/boot/arch/mips32/loader/_link.ld.in.binary
0,0 → 1,21
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS {
.boot 0xbfc00000: AT (0) {
*(BOOTSTRAP);
*(.text);
*(.rodata);
*(.rodata.*);
*(.data); /* initialized data */
*(.sdata);
*(.sdata2);
*(.sbss);
*(.scommon);
*(.bss); /* uninitialized static variables */
*(COMMON); /* global variables */
*(.reginfo);
[[COMPONENTS]]
}
}
/branches/dynload/boot/arch/mips32/loader/main.c
59,9 → 59,10
version_print();
component_t components[COMPONENTS];
bootinfo_t bootinfo;
init_components(components);
bootinfo_t bootinfo;
printf("\nMemory statistics\n");
printf(" kernel entry point at %L\n", KERNEL_VIRTUAL_ADDRESS);
printf(" %L: boot info structure\n", &bootinfo);
/branches/dynload/boot/arch/mips32/loader/Makefile
32,6 → 32,14
## Toolchain configuration
#
 
ifeq ($(IMAGE),binary)
LD_IN = binary
endif
ifeq ($(IMAGE),ecoff)
LD_IN = ecoff
endif
BFD_NAME = elf32-tradlittlemips
BFD_ARCH = mips
TARGET = mipsel-linux-gnu
TOOLCHAIN_DIR = /usr/local/mipsel/bin
 
43,14 → 51,6
OBJDUMP = objdump
endif
 
ifeq ($(COMPILER),icc_native)
CC = icc
AS = as
LD = ld
OBJCOPY = objcopy
OBJDUMP = objdump
endif
 
ifeq ($(COMPILER),gcc_cross)
CC = $(TOOLCHAIN_DIR)/$(TARGET)-gcc
AS = $(TOOLCHAIN_DIR)/$(TARGET)-as
72,6 → 72,7
SOURCES = \
main.c \
msim.c \
_components.c \
../../../generic/printf.c \
asm.S \
boot.S
107,11 → 108,14
-makedepend $(DEFS) $(CFLAGS) -f - $(SOURCES) > Makefile.depend 2> /dev/null
 
clean:
-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
-rm -f _components.h _components.c _link.ld _link.ld.in $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
 
_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
./pack $(IMAGE) $(OBJCOPY) $(COMPONENTS)
_components.h _components.c _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS) _link.ld.in
../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD_ARCH) 4096 "unsigned int" $(COMPONENTS)
 
_link.ld.in: _link.ld.in.$(LD_IN)
cp $< $@
 
%.o: %.S
$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@