Initial commit

This commit is contained in:
Bahadir Balban
2008-01-13 13:53:52 +00:00
commit e2b791a3d8
789 changed files with 95825 additions and 0 deletions

78
tasks/test1/SConstruct Normal file
View File

@@ -0,0 +1,78 @@
#
# User space application build script
#
# Copyright (C) 2007 Bahadir Balban
#
import os
import sys
import shutil
from os.path import join
from glob import glob
task_name = "test1"
# The root directory of the repository where this file resides:
project_root = "../.."
tools_root = join(project_root, "tools")
prev_image = join(project_root, "tasks/mm0/mm0.axf")
libs_path = join(project_root, "libs")
ld_script = "include/linker.lds"
physical_base_ld_script = "include/physical_base.lds"
# Libc situation:
# Libposix has uClibc (and therefore posix) headers.
# NICTA libc implements printf for us for now.
# Libposix implements posix calls for us, e.g. mmap.
# In conclusion nicta libc and libposix complement each other
# they should not clash. In future libposix will be part of uclibc
# and uclibc will be used.
# libc paths:
libc_variant = "userspace"
libc_libpath = join(libs_path, "c/build/%s" % libc_variant)
libc_incpath = join(libc_libpath, "include")
libc_crt0 = join(libs_path, "c/build/crt/sys-userspace/arch-arm/crt0.o")
libc_name = "c-%s" % libc_variant
# libposix paths:
libposix_libpath = "../libposix"
libposix_incpath = "../libposix/include/posix"
# libl4 paths:
libl4_path = "../libl4"
libl4_incpath = join(libl4_path, "include")
# kernel paths:
kernel_incpath = join(project_root, "include")
# If crt0 is in its library path, it becomes hard to link with it.
# For instance the linker script must use an absolute path for it.
def copy_crt0(source, target, env):
os.system("cp " + str(source[0]) + " " + str(target[0]))
def get_physical_base(source, target, env):
os.system(join(tools_root, "pyelf/readelf.py --first-free-page " + \
prev_image + " >> " + physical_base_ld_script))
# The kernel build environment:
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
# We don't use -nostdinc because sometimes we need standard headers,
# such as stdarg.h e.g. for variable args, as in printk().
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', '-Werror'],
LINKFLAGS = ['-nostdlib', '-T' + ld_script, "-L" + libc_libpath, "-L" + libl4_path, \
'-L' + libposix_libpath],
ASFLAGS = ['-D__ASSEMBLY__'],
PROGSUFFIX = '.axf', # The suffix to use for final executable
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
LIBS = [libc_name, 'gcc', libc_name, 'libl4', 'libposix'],
CPPFLAGS = "-D__USERSPACE__",
CPPPATH = ['#include', libl4_incpath, libposix_incpath, kernel_incpath])
src = [glob("src/*.c"), glob("*.c"), glob("src/arch/arm/*.c")]
objs = env.Object(src)
physical_base = env.Command(physical_base_ld_script, prev_image, get_physical_base)
crt0_copied = env.Command("crt0.o", libc_crt0, copy_crt0)
task = env.Program(task_name, objs + [crt0_copied])
env.Alias(task_name, task)
env.Depends(task, physical_base)

View File

@@ -0,0 +1,36 @@
/*
* Simple linker script for userspace or svc tasks.
*
* Copyright (C) 2007 Bahadir Balban
*/
/*
* The only catch with this linker script is that everything
* is linked starting at virtual_base, and loaded starting
* at physical_base. virtual_base is the predefined region
* of virtual memory for userland applications. physical_base
* is determined at build-time, it is one of the subsequent pages
* that come after the kernel image's load area.
*/
/* USER_AREA_START, see memlayout.h */
virtual_base = 0x10000000;
__stack = 0x20000000;
INCLUDE "include/physical_base.lds"
/* physical_base = 0x228000; */
offset = virtual_base - physical_base;
ENTRY(_start)
SECTIONS
{
. = virtual_base;
_start_text = .;
.text : AT (ADDR(.text) - offset) { crt0.o(.text) *(.text) }
/* rodata is needed else your strings will link at physical! */
.rodata : AT (ADDR(.rodata) - offset) { *(.rodata) }
.rodata1 : AT (ADDR(.rodata1) - offset) { *(.rodata1) }
.data : AT (ADDR(.data) - offset) { *(.data) }
.bss : AT (ADDR(.bss) - offset) { *(.bss) }
_end = .;
}

View File

@@ -0,0 +1,17 @@
/*
* The next free p_align'ed LMA base address
*
* p_align = 0x8000
*
* Recap from ELF spec: p_align: Loadable process segments must have
* congruent values for p_vaddr and p_offset, modulo the page size.
* This member gives the value to which the segments are aligned in
* memory and in the file. Values 0 and 1 mean that no alignment is
* required. Otherwise, p_align should be a positive, integral power
* of 2, and p_addr should equal p_offset, modulo p_align.
* This essentially means next available address must be aligned at
* p_align, rather than the page_size, which one (well, I) would
* normally expect.
*/
physical_base = 0x3000;

View File

@@ -0,0 +1,7 @@
#ifndef __TEST0_TESTS_H__
#define __TEST0_TESTS_H__
int shmtest(void);
int mmaptest(void);
#endif /* __TEST0_TESTS_H__ */

36
tasks/test1/main.c Normal file
View File

@@ -0,0 +1,36 @@
/*
* Some tests for posix syscalls.
*
* Copyright (C) 2007 Bahadir Balban
*/
#include <stdio.h>
#include <string.h>
#include <l4lib/arch/message.h>
#include <l4lib/arch/syslib.h>
#include <l4lib/kip.h>
#include <l4lib/utcb.h>
#include <l4/api/ipc.h>
#include <tests.h>
#define __TASKNAME__ "test0"
void wait_pager(l4id_t partner)
{
u32 tag = L4_IPC_TAG_WAIT;
printf("%s: Syncing with pager.\n", __TASKNAME__);
l4_send(partner, tag);
printf("Pager synced with us.\n");
}
void main(void)
{
/* Sync with pager */
wait_pager(0);
/* Check mmap/munmap */
mmaptest();
/* Check shmget/shmat/shmdt */
shmtest();
}

View File

@@ -0,0 +1,60 @@
/*
* Test mmap/munmap posix calls.
*
* Copyright (C) 2007 - 2008 Bahadir Balban
*/
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <tests.h>
#define PAGE_SIZE 0x1000
int mmaptest(void)
{
int fd;
void *base;
int x = 0x1000;
if ((fd = open("./newfile.txt", O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) < 0)
perror("open:");
else
printf("open: Success.\n");
/* Extend the file */
if ((int)lseek(fd, PAGE_SIZE*16, SEEK_SET) < 0)
perror("lseek");
else
printf("lseek: Success.\n");
if (write(fd, &x, sizeof(x)) < 0)
perror("write");
else
printf("write: Success.\n");
if ((int)(base = mmap(0, PAGE_SIZE*16, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) < 0)
perror("mmap");
else
printf("mmap: Success: %p\n", base);
*(unsigned int *)(base + PAGE_SIZE*2) = 0x1000;
if (msync(base + PAGE_SIZE*2, PAGE_SIZE, MS_SYNC) < 0)
perror("msync");
else
printf("msync: Success: %p\n", base);
if (munmap(base + PAGE_SIZE*2, PAGE_SIZE) < 0)
perror("munmap");
else
printf("munmap: Success: %p\n", base);
*(unsigned int *)(base + PAGE_SIZE*3) = 0x1000;
*(unsigned int *)(base + PAGE_SIZE*1) = 0x1000;
return 0;
}

View File

@@ -0,0 +1,60 @@
/*
* Test mmap/munmap posix calls.
*
* Copyright (C) 2007 - 2008 Bahadir Balban
*/
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <tests.h>
#define PAGE_SIZE 0x1000
int mmaptest(void)
{
int fd;
void *base;
int x = 0x1000;
if ((fd = open("./newfile.txt", O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) < 0)
perror("open:");
else
printf("open: Success.\n");
/* Extend the file */
if ((int)lseek(fd, PAGE_SIZE*16, SEEK_SET) < 0)
perror("lseek");
else
printf("lseek: Success.\n");
if (write(fd, &x, sizeof(x)) < 0)
perror("write");
else
printf("write: Success.\n");
if ((int)(base = mmap(0, PAGE_SIZE*16, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) < 0)
perror("mmap");
else
printf("mmap: Success: %p\n", base);
*(unsigned int *)(base + PAGE_SIZE*2) = 0x1000;
if (msync(base + PAGE_SIZE*2, PAGE_SIZE, MS_SYNC) < 0)
perror("msync");
else
printf("msync: Success: %p\n", base);
if (munmap(base + PAGE_SIZE*2, PAGE_SIZE) < 0)
perror("munmap");
else
printf("munmap: Success: %p\n", base);
*(unsigned int *)(base + PAGE_SIZE*3) = 0x1000;
*(unsigned int *)(base + PAGE_SIZE*1) = 0x1000;
return 0;
}

51
tasks/test1/src/shmtest.c Normal file
View File

@@ -0,0 +1,51 @@
/*
* Test shmget/shmat/shmdt posix calls.
*
* Copyright (C) 2007 - 2008 Bahadir Balban
*/
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <tests.h>
int shmtest(void)
{
//key_t keys[2] = { 5, 10000 };
key_t keys[2] = { 2, 3 };
void *bases[2] = { 0 , 0 };
int shmids[2];
printf("Initiating shmget()\n");
for (int i = 0; i < 2; i++) {
if ((shmids[i] = shmget(keys[i], 27, IPC_CREAT | 0666)) < 0) {
printf("Call failed.\n");
perror("SHMGET");
} else
printf("SHMID returned: %d\n", shmids[i]);
}
printf("Now shmat()\n");
for (int i = 0; i < 2; i++) {
if ((int)(bases[i] = shmat(shmids[i], NULL, 0)) == -1)
perror("SHMAT");
else
printf("SHM base address returned: %p\n", bases[i]);
}
printf("Now shmdt()\n");
for (int i = 0; i < 2; i++) {
if (shmdt(bases[i]) < 0)
perror("SHMDT");
else
printf("SHM detached OK.\n");
}
printf("Now shmat() again\n");
for (int i = 0; i < 2; i++) {
if ((int)(bases[i] = shmat(shmids[i], NULL, 0)) == -1)
perror("SHMAT");
else
printf("SHM base address returned: %p\n", bases[i]);
}
return 0;
}

View File

@@ -0,0 +1,27 @@
#!/usr/bin/python
import os
import sys
compiler_prefix = "arm-linux-"
objdump = "objdump"
command = "-t"
image_name = "roottask.axf"
linkoutput_file_suffix = "-linkinfo.txt"
linkoutput_file = image_name + linkoutput_file_suffix
def generate_bootdesc():
command = compiler_prefix + objdump + " -t " + image_name + " > " + linkoutput_file
print command
os.system(command)
f = open(linkoutput_file, "r")
while True:
line = f.readline()
if len(line) is 0:
break
if "_start" in line or "_end" in line:
print line
f.close()
if __name__ == "__main__":
generate_bootdesc()