changeset 159:89be7c9881b5

merge
author Jonathan Pevarnek <pevarnj@gmail.com>
date Fri, 25 Nov 2011 23:16:22 -0500
parents a6482018de66 (current diff) 180108494f08 (diff)
children 3d891b634acb
files Makefile ipl/loader.c
diffstat 17 files changed, 542 insertions(+), 630 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Thu Nov 24 19:48:24 2011 -0500
+++ b/.hgignore	Fri Nov 25 23:16:22 2011 -0500
@@ -1,19 +1,19 @@
 \.o$
 \.a$
 \.rto$
+^ipl/ipl_ccws$
 ^ipl/ipl_ccws\.S$
-^shell$
-^hello$
-^ls$
-^echo$
-^rpn$
-^dynamic$
-^testFS$
-^broken$
-^loader\.bin$
+^ipl/loader$
+^ipl/loader\.bin$
 ^cscope\.out$
 \.swp$
 
+CMakeFiles
+CMakeCache.txt
+cmake_install.cmake
+^build$
+Makefile
+
 ^hercules/curDisk\.img$
 
 ^changes
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CMakeLists.txt	Fri Nov 25 23:16:22 2011 -0500
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 2.8)
+include(CMakeForceCompiler)
+
+set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build)
+
+set(CMAKE_SYSTEM_NAME Linux)
+
+set(CMAKE_OBJCOPY "s390x-linux-objcopy")
+set(CMAKE_LINKER "s390x-linux-ld")
+CMAKE_FORCE_C_COMPILER(s390x-linux-gcc GNU)
+
+set(CMAKE_ASM_COMPILER "s390x-linux-gcc")
+enable_language(ASM)
+
+set(CMAKE_ASM_FLAGS "-g -fno-strict-aliasing -fno-builtin -nostdinc -nostdlib -Wall -m64 -I${PROJECT_SOURCE_DIR}/include/ -O2")
+set(CMAKE_C_FLAGS "${CMAKE_ASM_FLAGS} -include ${PROJECT_SOURCE_DIR}/include/system.h")
+
+add_subdirectory(arch)
+add_subdirectory(src)
+add_subdirectory(ipl)
+
+add_custom_command(
+	OUTPUT ${PROJECT_BINARY_DIR}/hercules/curDisk.img
+	COMMAND ${PROJECT_SOURCE_DIR}/utility/fsGen.py ${EXECUTABLE_OUTPUT_PATH}/* > ${PROJECT_BINARY_DIR}/hercules/curDisk.img
+)
+add_custom_target(fsgen DEPENDS ${PROJECT_BINARY_DIR}/hercules/curDisk.img)
--- a/Makefile	Thu Nov 24 19:48:24 2011 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,188 +0,0 @@
-CROSS_COMPILE=s390x-linux-
-AS=$(CROSS_COMPILE)as
-CC=$(CROSS_COMPILE)gcc
-CXX=$(CROSS_COMPILE)g++
-LD=$(CROSS_COMPILE)ld
-AR=$(CROSS_COMPILE)ar
-OBJCOPY=$(CROSS_COMPILE)objcopy
-
-MAKEFLAGS += -rR --no-print-directory
-CFLAGS=-g -fno-strict-aliasing -fno-builtin -nostdinc -nostdlib -Wall -m64 -I include/ -O2
-CXXFLAGS=$(CFLAGS)
-LDFLAGS=-m elf64_s390
-
-OSBINS=shell
-PROGBINS=hello ls echo dynamic rpn broken
-
-shell_OBJS=src/os/shell.o src/os/std.o src/os/fs.o src/os/string.o \
-					 src/os/stdio.o src/os/scall.o src/os/heap.o src/os/memStack.o \
-					 src/os/except.o src/os/storageKeys.o arch/arch.a
-hello_OBJS=src/prog/hello.o src/prog/std.o src/prog/string.o
-ls_OBJS=src/prog/ls.o
-echo_OBJS=src/prog/echo.o src/prog/std.o src/prog/string.o
-dynamic_OBJS=src/prog/dynamic.o src/prog/std.o src/prog/string.o src/prog/stack.o
-rpn_OBJS=src/prog/rpn.o src/prog/std.o src/prog/string.o src/prog/stack.o src/prog/operations.o src/prog/math.o
-broken_OBJS=src/prog/broken.o arch/arch.a
-
-testFS_OBJS=src/testFS.o src/std.o src/string.o src/os/fs.o arch/arch.a
-
-ARCH_OBJS=arch/io.o arch/cons.o arch/ebcdic.o arch/fba.o arch/ioint.o \
-	  arch/svc.o arch/svcint.o arch/progint.o
-
-.PHONY: all build clean tags
-
-all: $(OSBINS) $(PROGBINS) loader.bin
-	utility/fsGen.py $(PROGBINS) > hercules/curDisk.img
-	@echo "Loader is `stat -c %s loader.bin` bytes"
-
-clean:
-	rm -f $(shell_OBJS)
-	rm -f $(hello_OBJS)
-	rm -f $(ls_OBJS)
-	rm -f $(echo_OBJS)
-	rm -f $(rpn_OBJS)
-	rm -f $(dynamic_OBJS)
-	rm -f $(testFS_OBJS)
-	rm -f $(broken_OBJS)
-	rm -f $(ARCH_OBJS)
-	rm -f $(OSBINS)
-	rm -f $(PROGBINS)
-	rm -f loader.bin ipl/*.o ipl/*.rto ipl/ipl_ccws.S cscope.out
-
-tags:
-	cscope -R -b
-	ctags -R
-
-shell: $(shell_OBJS)
-	$(LD) $(LDFLAGS) -T scripts/linker.script -o $@ $^
-hello: $(hello_OBJS)
-	$(LD) $(LDFLAGS) -T scripts/linkerProg.script -o $@ $^
-ls: $(ls_OBJS)
-	$(LD) $(LDFLAGS) -T scripts/linkerProg.script -o $@ $^
-echo: $(echo_OBJS)
-	$(LD) $(LDFLAGS) -T scripts/linkerProg.script -o $@ $^
-broken: $(broken_OBJS)
-	$(LD) $(LDFLAGS) -T scripts/linkerProg.script -o $@ $^
-dynamic: $(dynamic_OBJS)
-	$(LD) $(LDFLAGS) -T scripts/linkerProg.script -o $@ $^
-rpn: $(rpn_OBJS)
-	$(LD) $(LDFLAGS) -T scripts/linkerProg.script -o $@ $^
-
-testFS: $(testFS_OBJS)
-	$(LD) $(LDFLAGS) -T scripts/linker.script -o $@ $^
-
-arch/arch.a: $(ARCH_OBJS)
-	$(AR) rc $@ $^
-
-%.o: %.S
-	$(CC) $(CFLAGS) -c -o $@ $<
-
-src/prog/%.o: src/prog/%.c
-	$(CC) $(CFLAGS) -include include/system.h -c -o $@ $<
-src/os/%.o: src/os/%.c
-	$(CC) $(CFLAGS) -include include/system.h -c -o $@ $< -DOSLEVEL
-%.o: %.c
-	$(CC) $(CFLAGS) -include include/system.h -c -o $@ $<
-
-
-%.o: %.cpp
-	$(CXX) $(CXXFLAGS) -include include/system.h -c -o $@ $<
-
-#
-# IPL specific bits
-#
-
-.PRECIOUS: ipl/loader.o ipl/loader_c.o ipl/loader_asm.o ipl/setmode.o \
-	ipl/ipl_ccws.o ipl/ipl.o
-
-loader.bin: ipl/ipl.rto ipl/ipl_ccws.rto ipl/setmode.rto ipl/loader.rto
-	cat $^ > $@
-	( len=`stat -c %s "$@"`; dif=`expr $$len % 80`; if [ $$dif -ne 0 ]; then dif=`expr 80 - $$dif`; dd if=/dev/zero bs=1 count=$$dif 2> /dev/null >> "$@"; fi)
-
-ipl/loader_asm.o: ipl/loader_asm.S
-	$(AS) -m64 -o $@ $<
-
-ipl/loader_c.o: ipl/loader.c
-	$(CC) $(CFLAGS) -DBLOCK_SIZE=80 -c -o $@ $<
-
-ipl/ipl_ccws.S: ipl/setmode.rto ipl/loader.rto
-	bash scripts/gen_ccws.sh $@
-
-ipl/loader.rto: ipl/loader.o
-	$(OBJCOPY) -O binary -j .text -j .data -j .rodata $< $@
-
-ipl/loader.o: ipl/loader_c.o ipl/loader_asm.o
-	$(LD) -melf64_s390 -T ipl/linker.script -o $@ $^
-
-ipl/%.rto: ipl/%.o
-	$(OBJCOPY) -O binary -j .text $< $@
-
-ipl/%.o: ipl/%.S
-	$(AS) -m64 -o $@ $<
-
-depend:
-	makedepend -I include src/*.c src/os/*.c src/prog/*.c
-
-# DO NOT DELETE
-
-src/testFS.o: include/std.h include/die.h include/memHead.h include/os/fs.h
-src/testFS.o: include/error.h include/os/fsStructs.h
-src/os/except.o: include/os/psw.h include/os/progint.h include/std.h
-src/os/except.o: include/die.h include/memHead.h include/string.h
-src/os/except.o: include/stdio.h include/os/scall.h include/os/pcb.h
-src/os/except.o: include/os/svc.h
-src/os/fs.o: include/os/fs.h include/std.h include/die.h include/memHead.h
-src/os/fs.o: include/error.h include/os/fsStructs.h include/string.h
-src/os/fs.o: include/tod.h
-src/os/heap.o: include/os/heap.h include/memHead.h include/os/storageKeys.h
-src/os/heap.o: include/os/memLayout.h
-src/os/memStack.o: include/memStack.h include/error.h include/std.h
-src/os/memStack.o: include/die.h include/memHead.h
-src/os/scall.o: include/os/scall.h include/os/psw.h include/os/pcb.h
-src/os/scall.o: include/os/svc.h include/os/svcNums.h include/os/fs.h
-src/os/scall.o: include/std.h include/die.h include/memHead.h include/error.h
-src/os/scall.o: include/os/fsStructs.h include/os/heap.h
-src/os/scall.o: include/os/storageKeys.h include/memStack.h
-src/os/shell.o: include/std.h include/die.h include/memHead.h
-src/os/shell.o: include/string.h include/stdio.h include/error.h
-src/os/shell.o: include/os/fs.h include/os/fsStructs.h include/os/elf.h
-src/os/shell.o: include/os/psw.h include/os/svc.h include/os/scall.h
-src/os/shell.o: include/os/pcb.h include/os/storageKeys.h
-src/os/shell.o: include/os/memLayout.h
-src/os/std.o: include/std.h include/die.h include/memHead.h include/string.h
-src/os/std.o: include/prog/svcCalls.h include/prog/svc_prog.h
-src/os/std.o: include/os/svcNums.h include/error.h
-src/os/stdio.o: include/stdio.h include/std.h include/die.h include/memHead.h
-src/os/stdio.o: include/string.h include/stdarg.h
-src/os/storageKeys.o: include/os/storageKeys.h include/os/memLayout.h
-src/os/storageKeys.o: include/string.h
-src/os/string.o: include/string.h
-src/prog/dynamic.o: include/prog/svcCalls.h include/prog/svc_prog.h
-src/prog/dynamic.o: include/os/svcNums.h include/error.h include/std.h
-src/prog/dynamic.o: include/die.h include/memHead.h include/string.h
-src/prog/dynamic.o: include/stack.h
-src/prog/echo.o: include/prog/svcCalls.h include/prog/svc_prog.h
-src/prog/echo.o: include/os/svcNums.h include/error.h include/std.h
-src/prog/echo.o: include/die.h include/memHead.h include/string.h
-src/prog/hello.o: include/prog/svcCalls.h include/prog/svc_prog.h
-src/prog/hello.o: include/os/svcNums.h include/error.h include/std.h
-src/prog/hello.o: include/die.h include/memHead.h
-src/prog/ls.o: include/os/fsStructs.h include/prog/svcCalls.h
-src/prog/ls.o: include/prog/svc_prog.h include/os/svcNums.h include/error.h
-src/prog/operations.o: include/prog/svcCalls.h include/prog/svc_prog.h
-src/prog/operations.o: include/os/svcNums.h include/error.h
-src/prog/operations.o: include/prog/operations.h include/std.h include/die.h
-src/prog/operations.o: include/memHead.h include/stack.h include/string.h
-src/prog/operations.o: include/math.h
-src/prog/rpn.o: include/prog/svcCalls.h include/prog/svc_prog.h
-src/prog/rpn.o: include/os/svcNums.h include/error.h include/std.h
-src/prog/rpn.o: include/die.h include/memHead.h include/string.h
-src/prog/rpn.o: include/prog/operations.h include/stack.h
-src/prog/stack.o: include/stack.h include/std.h include/die.h
-src/prog/stack.o: include/memHead.h
-src/prog/std.o: include/std.h include/die.h include/memHead.h
-src/prog/std.o: include/string.h include/prog/svcCalls.h
-src/prog/std.o: include/prog/svc_prog.h include/os/svcNums.h include/error.h
-src/prog/stdio.o: include/stdio.h include/std.h include/die.h
-src/prog/stdio.o: include/memHead.h include/string.h include/stdarg.h
-src/prog/string.o: include/string.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arch/CMakeLists.txt	Fri Nov 25 23:16:22 2011 -0500
@@ -0,0 +1,2 @@
+add_library(arch io.c cons.c ebcdic.c fba.c ioint.S svc.c svcint.S
+	progint.S)
--- a/hercules/shell.cnf	Thu Nov 24 19:48:24 2011 -0500
+++ b/hercules/shell.cnf	Fri Nov 25 23:16:22 2011 -0500
@@ -15,6 +15,6 @@
 # V     V       V
 #---    ----    --------------------
 0009	3215	
-000C    3505	../loader.bin ../shell ebcdic multifile eof
+000C    3505	../ipl/loader.bin ../build/shell ebcdic multifile eof
 
 0100	9336	curDisk.img
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ipl/CMakeLists.txt	Fri Nov 25 23:16:22 2011 -0500
@@ -0,0 +1,33 @@
+set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/ipl)
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -DBLOCK_SIZE=80")
+
+add_executable(loader setmode.S loader_c.c loader_asm.S)
+set_target_properties(loader PROPERTIES LINK_FLAGS "-T linker.script")
+add_custom_command(
+	OUTPUT loader.rto
+	COMMAND ${CMAKE_OBJCOPY} -O binary -j .text -j .data -j .rodata loader loader.rto
+	DEPENDS loader
+)
+
+add_custom_command(
+	OUTPUT ipl_ccws.S
+	COMMAND ${PROJECT_SOURCE_DIR}/scripts/gen_ccws.sh ipl_ccws.S ipl.S loader.rto
+	DEPENDS loader.rto
+)
+
+add_executable(ipl_ccws ipl_ccws.S)
+set_target_properties(ipl_ccws PROPERTIES LINK_FLAGS "-T linker-ccws.script")
+add_custom_command(
+	OUTPUT ipl_ccws.rto
+	COMMAND ${CMAKE_OBJCOPY} -O binary -j .text -j .data -j .rodata ipl_ccws ipl_ccws.rto
+	DEPENDS ipl_ccws
+)
+
+add_custom_command(
+	OUTPUT loader.bin
+	COMMAND ${PROJECT_SOURCE_DIR}/scripts/gen_loaderbin.sh
+	DEPENDS ipl_ccws.rto loader.rto
+)
+
+add_custom_target(ldr ALL DEPENDS loader.bin)
--- a/ipl/ipl.S	Thu Nov 24 19:48:24 2011 -0500
+++ b/ipl/ipl.S	Fri Nov 25 23:16:22 2011 -0500
@@ -3,6 +3,11 @@
 # NOTE: zArch IPLs in ESA/390 mode.
 #
 
+.text
+	.align	4
+.globl START
+	.type	START, @function
+START:
 #
 # Bytes 0-7 contain PSW to be loaded after IO operation completes
 #
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ipl/linker-ccws.script	Fri Nov 25 23:16:22 2011 -0500
@@ -0,0 +1,9 @@
+SECTIONS
+{
+  ENTRY(START)
+  . = 0x0;
+  .text : { *(.text) }
+  .data : { *(.data) }
+  .rodata : { *(.rodata) }
+  .bss : { *(.bss) }
+}
--- a/ipl/linker.script	Thu Nov 24 19:48:24 2011 -0500
+++ b/ipl/linker.script	Fri Nov 25 23:16:22 2011 -0500
@@ -1,7 +1,7 @@
 SECTIONS
 {
-  ENTRY(load_system)
-  . = 0x800020;
+  ENTRY(START)
+  . = 0x800000;
   .text : { *(.text) }
   .data : { *(.data) }
   .rodata : { *(.rodata) }
--- a/ipl/loader.c	Thu Nov 24 19:48:24 2011 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,421 +0,0 @@
-#ifndef BLOCK_SIZE
-#error missing BLOCK_SIZE
-#endif
-
-#define TEMP_BASE	((unsigned char*) 0x400000) /* 4MB */
-
-typedef unsigned long u64;
-typedef signed long s64;
-
-typedef unsigned int u32;
-typedef signed int s32;
-
-typedef unsigned short u16;
-typedef signed short s16;
-
-typedef unsigned char u8;
-typedef signed char s8;
-
-#define EI_MAG0		0
-#define EI_MAG1		1
-#define EI_MAG2		2
-#define EI_MAG3		3
-#define EI_CLASS	4
-#define EI_DATA		5
-#define EI_VERSION	6
-#define EI_OSABI	7
-#define EI_ABIVERSION	8
-#define EI_PAD		9
-#define EI_NIDENT	16
-
-#define ELFCLASS32	1
-#define ELFCLASS64	2
-
-#define ELFDATA2LSB	1
-#define ELFDATA2MSB	2
-
-#define EV_CURRENT	1
-
-#define ET_NONE		0
-#define ET_REL		1
-#define ET_EXEC		2
-#define ET_DYN		3
-#define ET_CORE		4
-#define ET_LOOS		0xfe00
-#define ET_HIOS		0xfeff
-#define ET_LOPROC	0xff00
-#define ET_HIPROC	0xffff
-
-#define SHT_NULL	0
-#define SHT_PROGBITS	1
-#define SHT_SYMTAB	2
-#define SHT_STRTAB	3
-#define SHT_RELA	4
-#define SHT_HASH	5
-#define SHT_DYNAMIC	6
-#define SHT_NOTE	7
-#define SHT_NOBITS	8
-#define SHT_REL		9
-#define SHT_SHLIB	10
-#define SHT_DYNSYM	11
-#define SHT_LOOS	0x60000000
-#define SHT_HIOS	0x6fffffff
-#define SHT_LOPROC	0x70000000
-#define SHT_HIPROC	0x7fffffff
-
-typedef u64 Elf64_Addr;
-typedef u64 Elf64_Off;
-typedef u16 Elf64_Half;
-typedef u32 Elf64_Word;
-typedef s32 Elf64_Sword;
-typedef u64 Elf64_Xword;
-typedef s64 Elf64_Sxword;
-
-/*
- * ELF file header
- */
-typedef struct {
-	unsigned char   e_ident[EI_NIDENT];	/* ELF identification */
-	Elf64_Half      e_type;			/* Object file type */
-	Elf64_Half      e_machine;		/* Machine type */
-	Elf64_Word      e_version;		/* Object file version */
-	Elf64_Addr      e_entry;		/* Entry point address */
-	Elf64_Off       e_phoff;		/* Program header offset */
-	Elf64_Off       e_shoff;		/* Section header offset */
-	Elf64_Word      e_flags;		/* Processor-specific flags */
-	Elf64_Half      e_ehsize;		/* ELF header size */
-	Elf64_Half      e_phentsize;		/* Size of program header entry */
-	Elf64_Half      e_phnum;		/* Number of program header entries */
-	Elf64_Half      e_shentsize;		/* Size of section header entries */
-	Elf64_Half      e_shnum;		/* Number of section header entries */
-	Elf64_Half      e_shstrndx;		/* Section name string table index */
-} Elf64_Ehdr;
-
-/*
- * ELF section header
- */
-typedef struct {
-	Elf64_Word	sh_name;		/* Section name */
-	Elf64_Word	sh_type;		/* Section type */
-	Elf64_Xword	sh_flags;		/* Section attributes */
-	Elf64_Addr	sh_addr;		/* Virtual address in memory */
-	Elf64_Off	sh_offset;		/* Offset in file */
-	Elf64_Xword	sh_size;		/* Size of section */
-	Elf64_Word	sh_link;		/* Link to other section */
-	Elf64_Word	sh_info;		/* Misc information */
-	Elf64_Xword	sh_addralign;		/* Address alignment boundary */
-	Elf64_Xword	sh_entsize;		/* Size of entries, if section has table */
-} Elf64_Shdr;
-
-static unsigned char read_ccw[8] __attribute__ ((aligned (8))) = {
-	/*
-	 * CCW2; read the entire system ELF
-	 */
-
-	0x02,
-	/*   bits  value   name                        desc             */
-	/*    0-7      2   Cmd Code                    read, no modifiers*/
-
-	0xff, 0xff, 0xff,
-	/*   bits  value   name                        desc             */
-	/*   8-31   addr   Data Address                dest of the read */
-
-	0x20,
-	/*   bits  value   name                        desc             */
-	/*     32      0   Chain-Data (CD)             don't chain      */
-	/*     33      0   Chain-Command (CC)          don't chain      */
-	/*     34      1   Sup.-Len.-Inditcation (SLI) suppress         */
-	/*     35      0   Skip (SKP)                  issue read       */
-	/*     36      0   Prog.-Contr.-Inter. (PCI)   don't interrupt  */
-	/*     37      0   Indir.-Data-Addr. (IDA)     real addr        */
-	/*     38      0   Suspend (S)                 don't suspend    */
-	/*     39      0   Modified I.D.A. (MIDA)      real addr        */
-
-	0x00,
-	/*   bits  value   name                        desc             */
-	/*  40-47      0   <ignored>                                    */
-
-	0xff, 0xff,
-	/*   bits  value   name                        desc             */
-	/*  48-63    len   number of bytes to read                      */
-};
-
-unsigned char ORB[32] __attribute__ ((aligned (16))) = {
-	/* Word 0 */
-	0x12,0x34,0x56,0x78,
-	/*   bits  value   name                        desc             */
-	/*   0-31  magic   Interrupt Parameter                          */
-
-	/* Word 1 */
-	0x00,
-	/*   bits  value   name                        desc             */
-	/*    0-3      0   Subchannel Key                               */
-	/*      4      0   Suspend Control                              */
-	/*      5      0   Streaming-Mode Control                       */
-	/*      6      0   Modification Control                         */
-	/*      7      0   Synchronization Control                      */
-
-	0x00,
-	/*   bits  value   name                        desc             */
-	/*      8      0   Format Control              format-0 CCWs    */
-	/*      9      0   Prefetch Control                             */
-	/*     10      0   Initial-Status-Interruption Control          */
-	/*     11      0   Address-Limit-Checking Control               */
-	/*     12      0   Suppress-Suspended-Interruption Control      */
-	/*     13      0   <zero>                                       */
-	/*     14      0   Format-2-IDAW Control                        */
-	/*     15      0   2K-IDAW Control                              */
-
-	0xff,
-	/*   bits  value   name                        desc             */
-	/*  16-23   0xff   Logical-Path Mask           All paths        */
-
-	0x00,
-	/*   bits  value   name                        desc             */
-	/*     24      0   Incorrect-Length-Suppression Mode            */
-	/*     25      0   Modified-CCW-Indirect-Data-Addressing Control*/
-	/*  26-30      0   <zero>                                       */
-	/*     31      0   ORB-Extension Control                        */
-
-	/* Word 2 */
-	0xff,0xff,0xff,0xff,
-	/*   bits  value   name                        desc             */
-	/*   0-31   addr   Channel-Program Address                      */
-
-	/* Word 3 */
-	0x00,
-	/*   bits  value   name                        desc             */
-	/*    0-7      0   Channel-Subsystem Priority                   */
-
-	0x00,
-	/*   bits  value   name                        desc             */
-	/*   8-15      0   <zero/reserved>                              */
-
-	0x00,
-	/*   bits  value   name                        desc             */
-	/*  15-23      0   Control-Unit Priority                        */
-
-	0x00,
-	/*   bits  value   name                        desc             */
-	/*  24-31      0   <zero/reserved>                              */
-
-	/* Word 4 */
-	0x00,0x00,0x00,0x00,
-	/*   bits  value   name                        desc             */
-	/*   0-31      0   <zero/reserved>                              */
-
-	/* Word 5 */
-	0x00,0x00,0x00,0x00,
-	/*   bits  value   name                        desc             */
-	/*   0-31      0   <zero/reserved>                              */
-
-	/* Word 6 */
-	0x00,0x00,0x00,0x00,
-	/*   bits  value   name                        desc             */
-	/*   0-31      0   <zero/reserved>                              */
-
-	/* Word 7 */
-	0x00,0x00,0x00,0x00,
-	/*   bits  value   name                        desc             */
-	/*   0-31      0   <zero/reserved>                              */
-};
-
-#define memcpy(d,s,l)	__builtin_memcpy((d), (s), (l))
-#define memset(s,c,n)	__builtin_memset((s),(c),(n))
-
-/*
- * halt the cpu
- *
- * NOTE: we don't care about not clobbering registers as when this
- * code executes, the CPU will be stopped.
- */
-static inline void die()
-{
-	asm volatile(
-		"SR	%r1, %r1	# not used, but should be zero\n"
-		"SR	%r3, %r3 	# CPU Address\n"
-		"SIGP	%r1, %r3, 0x05	# Signal, order 0x05\n"
-	);
-
-	/*
-	 * Just in case SIGP fails
-	 */
-	for(;;);
-}
-
-/*
- * It is easier to write this thing in assembly...
- */
-extern int __do_io();
-extern void PGMHANDLER();
-
-static u64 pgm_new_psw[2] = {
-	0x0000000180000000ULL, (u64) &PGMHANDLER,
-};
-
-static u64 pgm_new_psw_real[2] = {
-	0x0002000180000000ULL, 0xfa11,
-};
-
-/*
- * determine amount of storage
- */
-static u64 sense_memsize()
-{
-	u64 size;
-	int cc;
-
-#define SKIP_SIZE	(1024*1024ULL)
-
-	/* set new PGM psw */
-	memcpy((void*)0x1d0, pgm_new_psw, 16);
-
-	for(size = 0; size < ((u64)~SKIP_SIZE)-1; size += SKIP_SIZE) {
-		asm volatile(
-			"lg	%%r1,%1\n"
-			"tprot	0(%%r1),0\n"
-			"ipm	%0\n"
-			"srl    %0,28\n"
-		: /* output */
-		  "=d" (cc)
-		: /* input */
-		  "m" (size)
-		: /* clobber */
-		  "cc", "r1"
-		);
-
-		/*
-		 * we cheat here a little...if we try to tprot a location
-		 * that isn't part of the configuration, a program exception
-		 * fires off, but our handler sets the CC to 3, and resumes
-		 * execution
-		 */
-		if (cc == 3)
-			break;
-	}
-
-	/* invalidate new PGM psw */
-	memcpy((void*)0x1d0, pgm_new_psw_real, 16);
-
-	return size;
-}
-
-/*
- * read the entire system into into TEMP_BASE
- */
-static inline void readsystem()
-{
-	register unsigned long base;
-
-	/*
-	 * Read in BLOCK_SIZE chunks of system
-	 */
-
-	/* set the CCW address in the ORB */
-	*((u32 *) &ORB[8]) = (u32) (u64) read_ccw;
-
-	read_ccw[6] = ((unsigned char) (BLOCK_SIZE >> 8) & 0xff);
-	read_ccw[7] = ((unsigned char) (BLOCK_SIZE & 0xff));
-
-	base = (unsigned long) TEMP_BASE;
-	for(;; base += BLOCK_SIZE) {
-		read_ccw[1] = ((unsigned char) (base >> 16));
-		read_ccw[2] = ((unsigned char) (base >> 8) & 0xff);
-		read_ccw[3] = ((unsigned char) (base & 0xff));
-		if (__do_io())
-			break;
-	}
-}
-
-static inline void enable_bfp()
-{
-	u64 cr0;
-
-	asm volatile(
-		"stctg	0,0,%0\n"
-		"oi	%1,0x04\n"
-		"lctlg	0,0,%0\n"
-	: /* output */
-	: /* input */
-	  "m" (cr0),
-	  "m" (*(u64*) (((u8*)&cr0) + 5))
-	);
-}
-
-void load_system(void)
-{
-	/*
-	 * These are all stored in registers
-	 */
-	register int i;
-	register Elf64_Ehdr *system_elf;
-	register Elf64_Shdr *section;
-	register void (*start_sym)(u64);
-
-	/*
-	 * Read entire ELF to temporary location
-	 */
-	readsystem();
-
-	system_elf = (Elf64_Ehdr*) TEMP_BASE;
-
-	/*
-	 * Check that this looks like a valid ELF
-	 */
-	if (system_elf->e_ident[0] != '\x7f' ||
-	    system_elf->e_ident[1] != 'E' ||
-	    system_elf->e_ident[2] != 'L' ||
-	    system_elf->e_ident[3] != 'F' ||
-	    system_elf->e_ident[EI_CLASS] != ELFCLASS64 ||
-	    system_elf->e_ident[EI_DATA] != ELFDATA2MSB ||
-	    system_elf->e_ident[EI_VERSION] != EV_CURRENT ||
-	    system_elf->e_type != ET_EXEC ||
-	    system_elf->e_machine != 0x16 || // FIXME: find the name for the #define
-	    system_elf->e_version != EV_CURRENT)
-		die();
-
-	/*
-	 * Iterate through each section, and copy it to the final
-	 * destination as necessary
-	 */
-	for (i=0; i<system_elf->e_shnum; i++) {
-		section = (Elf64_Shdr*) (TEMP_BASE +
-					 system_elf->e_shoff +
-					 system_elf->e_shentsize * i);
-
-		switch (section->sh_type) {
-			case SHT_PROGBITS:
-				if (!section->sh_addr)
-					break;
-
-				/*
-				 * just copy the data from TEMP_BASE to
-				 * where it wants to be
-				 */
-				memcpy((void*) section->sh_addr,
-					TEMP_BASE + section->sh_offset,
-					section->sh_size);
-				break;
-			case SHT_NOBITS:
-				/*
-				 * No action needed as there's no data to
-				 * copy, and we assume that the ELF sections
-				 * don't overlap
-				 */
-				memset((void*) section->sh_addr,
-				       0, section->sh_size);
-				break;
-			default:
-				/* Ignoring */
-				break;
-		}
-	}
-
-	enable_bfp();
-
-	/*
-	 * Now, jump to the system entry point
-	 */
-	start_sym = (void*) system_elf->e_entry;
-	start_sym(sense_memsize());
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ipl/loader_c.c	Fri Nov 25 23:16:22 2011 -0500
@@ -0,0 +1,418 @@
+#ifndef BLOCK_SIZE
+#error missing BLOCK_SIZE
+#endif
+
+#define TEMP_BASE	((unsigned char*) 0x400000) /* 4MB */
+
+typedef unsigned int u32;
+typedef signed int s32;
+
+typedef unsigned short u16;
+typedef signed short s16;
+
+typedef unsigned char u8;
+typedef signed char s8;
+
+#define EI_MAG0		0
+#define EI_MAG1		1
+#define EI_MAG2		2
+#define EI_MAG3		3
+#define EI_CLASS	4
+#define EI_DATA		5
+#define EI_VERSION	6
+#define EI_OSABI	7
+#define EI_ABIVERSION	8
+#define EI_PAD		9
+#define EI_NIDENT	16
+
+#define ELFCLASS32	1
+#define ELFCLASS64	2
+
+#define ELFDATA2LSB	1
+#define ELFDATA2MSB	2
+
+#define EV_CURRENT	1
+
+#define ET_NONE		0
+#define ET_REL		1
+#define ET_EXEC		2
+#define ET_DYN		3
+#define ET_CORE		4
+#define ET_LOOS		0xfe00
+#define ET_HIOS		0xfeff
+#define ET_LOPROC	0xff00
+#define ET_HIPROC	0xffff
+
+#define SHT_NULL	0
+#define SHT_PROGBITS	1
+#define SHT_SYMTAB	2
+#define SHT_STRTAB	3
+#define SHT_RELA	4
+#define SHT_HASH	5
+#define SHT_DYNAMIC	6
+#define SHT_NOTE	7
+#define SHT_NOBITS	8
+#define SHT_REL		9
+#define SHT_SHLIB	10
+#define SHT_DYNSYM	11
+#define SHT_LOOS	0x60000000
+#define SHT_HIOS	0x6fffffff
+#define SHT_LOPROC	0x70000000
+#define SHT_HIPROC	0x7fffffff
+
+typedef u64 Elf64_Addr;
+typedef u64 Elf64_Off;
+typedef u16 Elf64_Half;
+typedef u32 Elf64_Word;
+typedef s32 Elf64_Sword;
+typedef u64 Elf64_Xword;
+typedef s64 Elf64_Sxword;
+
+/*
+ * ELF file header
+ */
+typedef struct {
+	unsigned char   e_ident[EI_NIDENT];	/* ELF identification */
+	Elf64_Half      e_type;			/* Object file type */
+	Elf64_Half      e_machine;		/* Machine type */
+	Elf64_Word      e_version;		/* Object file version */
+	Elf64_Addr      e_entry;		/* Entry point address */
+	Elf64_Off       e_phoff;		/* Program header offset */
+	Elf64_Off       e_shoff;		/* Section header offset */
+	Elf64_Word      e_flags;		/* Processor-specific flags */
+	Elf64_Half      e_ehsize;		/* ELF header size */
+	Elf64_Half      e_phentsize;		/* Size of program header entry */
+	Elf64_Half      e_phnum;		/* Number of program header entries */
+	Elf64_Half      e_shentsize;		/* Size of section header entries */
+	Elf64_Half      e_shnum;		/* Number of section header entries */
+	Elf64_Half      e_shstrndx;		/* Section name string table index */
+} Elf64_Ehdr;
+
+/*
+ * ELF section header
+ */
+typedef struct {
+	Elf64_Word	sh_name;		/* Section name */
+	Elf64_Word	sh_type;		/* Section type */
+	Elf64_Xword	sh_flags;		/* Section attributes */
+	Elf64_Addr	sh_addr;		/* Virtual address in memory */
+	Elf64_Off	sh_offset;		/* Offset in file */
+	Elf64_Xword	sh_size;		/* Size of section */
+	Elf64_Word	sh_link;		/* Link to other section */
+	Elf64_Word	sh_info;		/* Misc information */
+	Elf64_Xword	sh_addralign;		/* Address alignment boundary */
+	Elf64_Xword	sh_entsize;		/* Size of entries, if section has table */
+} Elf64_Shdr;
+
+static unsigned char read_ccw[8] __attribute__ ((aligned (8))) = {
+	/*
+	 * CCW2; read the entire system ELF
+	 */
+
+	0x02,
+	/*   bits  value   name                        desc             */
+	/*    0-7      2   Cmd Code                    read, no modifiers*/
+
+	0xff, 0xff, 0xff,
+	/*   bits  value   name                        desc             */
+	/*   8-31   addr   Data Address                dest of the read */
+
+	0x20,
+	/*   bits  value   name                        desc             */
+	/*     32      0   Chain-Data (CD)             don't chain      */
+	/*     33      0   Chain-Command (CC)          don't chain      */
+	/*     34      1   Sup.-Len.-Inditcation (SLI) suppress         */
+	/*     35      0   Skip (SKP)                  issue read       */
+	/*     36      0   Prog.-Contr.-Inter. (PCI)   don't interrupt  */
+	/*     37      0   Indir.-Data-Addr. (IDA)     real addr        */
+	/*     38      0   Suspend (S)                 don't suspend    */
+	/*     39      0   Modified I.D.A. (MIDA)      real addr        */
+
+	0x00,
+	/*   bits  value   name                        desc             */
+	/*  40-47      0   <ignored>                                    */
+
+	0xff, 0xff,
+	/*   bits  value   name                        desc             */
+	/*  48-63    len   number of bytes to read                      */
+};
+
+unsigned char ORB[32] __attribute__ ((aligned (16))) = {
+	/* Word 0 */
+	0x12,0x34,0x56,0x78,
+	/*   bits  value   name                        desc             */
+	/*   0-31  magic   Interrupt Parameter                          */
+
+	/* Word 1 */
+	0x00,
+	/*   bits  value   name                        desc             */
+	/*    0-3      0   Subchannel Key                               */
+	/*      4      0   Suspend Control                              */
+	/*      5      0   Streaming-Mode Control                       */
+	/*      6      0   Modification Control                         */
+	/*      7      0   Synchronization Control                      */
+
+	0x00,
+	/*   bits  value   name                        desc             */
+	/*      8      0   Format Control              format-0 CCWs    */
+	/*      9      0   Prefetch Control                             */
+	/*     10      0   Initial-Status-Interruption Control          */
+	/*     11      0   Address-Limit-Checking Control               */
+	/*     12      0   Suppress-Suspended-Interruption Control      */
+	/*     13      0   <zero>                                       */
+	/*     14      0   Format-2-IDAW Control                        */
+	/*     15      0   2K-IDAW Control                              */
+
+	0xff,
+	/*   bits  value   name                        desc             */
+	/*  16-23   0xff   Logical-Path Mask           All paths        */
+
+	0x00,
+	/*   bits  value   name                        desc             */
+	/*     24      0   Incorrect-Length-Suppression Mode            */
+	/*     25      0   Modified-CCW-Indirect-Data-Addressing Control*/
+	/*  26-30      0   <zero>                                       */
+	/*     31      0   ORB-Extension Control                        */
+
+	/* Word 2 */
+	0xff,0xff,0xff,0xff,
+	/*   bits  value   name                        desc             */
+	/*   0-31   addr   Channel-Program Address                      */
+
+	/* Word 3 */
+	0x00,
+	/*   bits  value   name                        desc             */
+	/*    0-7      0   Channel-Subsystem Priority                   */
+
+	0x00,
+	/*   bits  value   name                        desc             */
+	/*   8-15      0   <zero/reserved>                              */
+
+	0x00,
+	/*   bits  value   name                        desc             */
+	/*  15-23      0   Control-Unit Priority                        */
+
+	0x00,
+	/*   bits  value   name                        desc             */
+	/*  24-31      0   <zero/reserved>                              */
+
+	/* Word 4 */
+	0x00,0x00,0x00,0x00,
+	/*   bits  value   name                        desc             */
+	/*   0-31      0   <zero/reserved>                              */
+
+	/* Word 5 */
+	0x00,0x00,0x00,0x00,
+	/*   bits  value   name                        desc             */
+	/*   0-31      0   <zero/reserved>                              */
+
+	/* Word 6 */
+	0x00,0x00,0x00,0x00,
+	/*   bits  value   name                        desc             */
+	/*   0-31      0   <zero/reserved>                              */
+
+	/* Word 7 */
+	0x00,0x00,0x00,0x00,
+	/*   bits  value   name                        desc             */
+	/*   0-31      0   <zero/reserved>                              */
+};
+
+#define memcpy(d,s,l)	__builtin_memcpy((d), (s), (l))
+#define memset(s,c,n)	__builtin_memset((s),(c),(n))
+
+/*
+ * halt the cpu
+ *
+ * NOTE: we don't care about not clobbering registers as when this
+ * code executes, the CPU will be stopped.
+ */
+static inline void die()
+{
+	asm volatile(
+		"SR	%r1, %r1	# not used, but should be zero\n"
+		"SR	%r3, %r3 	# CPU Address\n"
+		"SIGP	%r1, %r3, 0x05	# Signal, order 0x05\n"
+	);
+
+	/*
+	 * Just in case SIGP fails
+	 */
+	for(;;);
+}
+
+/*
+ * It is easier to write this thing in assembly...
+ */
+extern int __do_io();
+extern void PGMHANDLER();
+
+static u64 pgm_new_psw[2] = {
+	0x0000000180000000ULL, (u64) &PGMHANDLER,
+};
+
+static u64 pgm_new_psw_real[2] = {
+	0x0002000180000000ULL, 0xfa11,
+};
+
+/*
+ * determine amount of storage
+ */
+static u64 sense_memsize()
+{
+	u64 size;
+	int cc;
+
+#define SKIP_SIZE	(1024*1024ULL)
+
+	/* set new PGM psw */
+	memcpy((void*)0x1d0, pgm_new_psw, 16);
+
+	for(size = 0; size < ((u64)~SKIP_SIZE)-1; size += SKIP_SIZE) {
+		asm volatile(
+			"lg	%%r1,%1\n"
+			"tprot	0(%%r1),0\n"
+			"ipm	%0\n"
+			"srl    %0,28\n"
+		: /* output */
+		  "=d" (cc)
+		: /* input */
+		  "m" (size)
+		: /* clobber */
+		  "cc", "r1"
+		);
+
+		/*
+		 * we cheat here a little...if we try to tprot a location
+		 * that isn't part of the configuration, a program exception
+		 * fires off, but our handler sets the CC to 3, and resumes
+		 * execution
+		 */
+		if (cc == 3)
+			break;
+	}
+
+	/* invalidate new PGM psw */
+	memcpy((void*)0x1d0, pgm_new_psw_real, 16);
+
+	return size;
+}
+
+/*
+ * read the entire system into into TEMP_BASE
+ */
+static inline void readsystem()
+{
+	register unsigned long base;
+
+	/*
+	 * Read in BLOCK_SIZE chunks of system
+	 */
+
+	/* set the CCW address in the ORB */
+	*((u32 *) &ORB[8]) = (u32) (u64) read_ccw;
+
+	read_ccw[6] = ((unsigned char) (BLOCK_SIZE >> 8) & 0xff);
+	read_ccw[7] = ((unsigned char) (BLOCK_SIZE & 0xff));
+
+	base = (unsigned long) TEMP_BASE;
+	for(;; base += BLOCK_SIZE) {
+		read_ccw[1] = ((unsigned char) (base >> 16));
+		read_ccw[2] = ((unsigned char) (base >> 8) & 0xff);
+		read_ccw[3] = ((unsigned char) (base & 0xff));
+		if (__do_io())
+			break;
+	}
+}
+
+static inline void enable_bfp()
+{
+	u64 cr0;
+
+	asm volatile(
+		"stctg	0,0,%0\n"
+		"oi	%1,0x04\n"
+		"lctlg	0,0,%0\n"
+	: /* output */
+	: /* input */
+	  "m" (cr0),
+	  "m" (*(u64*) (((u8*)&cr0) + 5))
+	);
+}
+
+void load_system(void)
+{
+	/*
+	 * These are all stored in registers
+	 */
+	register int i;
+	register Elf64_Ehdr *system_elf;
+	register Elf64_Shdr *section;
+	register void (*start_sym)(u64);
+
+	/*
+	 * Read entire ELF to temporary location
+	 */
+	readsystem();
+
+	system_elf = (Elf64_Ehdr*) TEMP_BASE;
+
+	/*
+	 * Check that this looks like a valid ELF
+	 */
+	if (system_elf->e_ident[0] != '\x7f' ||
+	    system_elf->e_ident[1] != 'E' ||
+	    system_elf->e_ident[2] != 'L' ||
+	    system_elf->e_ident[3] != 'F' ||
+	    system_elf->e_ident[EI_CLASS] != ELFCLASS64 ||
+	    system_elf->e_ident[EI_DATA] != ELFDATA2MSB ||
+	    system_elf->e_ident[EI_VERSION] != EV_CURRENT ||
+	    system_elf->e_type != ET_EXEC ||
+	    system_elf->e_machine != 0x16 || // FIXME: find the name for the #define
+	    system_elf->e_version != EV_CURRENT)
+		die();
+
+	/*
+	 * Iterate through each section, and copy it to the final
+	 * destination as necessary
+	 */
+	for (i=0; i<system_elf->e_shnum; i++) {
+		section = (Elf64_Shdr*) (TEMP_BASE +
+					 system_elf->e_shoff +
+					 system_elf->e_shentsize * i);
+
+		switch (section->sh_type) {
+			case SHT_PROGBITS:
+				if (!section->sh_addr)
+					break;
+
+				/*
+				 * just copy the data from TEMP_BASE to
+				 * where it wants to be
+				 */
+				memcpy((void*) section->sh_addr,
+					TEMP_BASE + section->sh_offset,
+					section->sh_size);
+				break;
+			case SHT_NOBITS:
+				/*
+				 * No action needed as there's no data to
+				 * copy, and we assume that the ELF sections
+				 * don't overlap
+				 */
+				memset((void*) section->sh_addr,
+				       0, section->sh_size);
+				break;
+			default:
+				/* Ignoring */
+				break;
+		}
+	}
+
+	enable_bfp();
+
+	/*
+	 * Now, jump to the system entry point
+	 */
+	start_sym = (void*) system_elf->e_entry;
+	start_sym(sense_memsize());
+}
--- a/ipl/setmode.S	Thu Nov 24 19:48:24 2011 -0500
+++ b/ipl/setmode.S	Fri Nov 25 23:16:22 2011 -0500
@@ -2,7 +2,11 @@
 # At this point, the machine is running in ESA390 mode. Let's load a new
 # PSW, making it switch to 64-bit mode
 #
-
+.text
+	.align	4
+.globl START
+	.type	START, @function
+START:
 	# switch to 64-bit mode
 	#
 	# Signal Processor
@@ -39,8 +43,4 @@
 	SLL	%r15, 20
 	AHI	%r15, -160
 
-#
-# Padding to make the entire file 0x20 bytes
-#
-	BCR	0, %r7
-	BCR	0, %r7
+	BRASL	%r14,load_system
--- a/scripts/gen_ccws.sh	Thu Nov 24 19:48:24 2011 -0500
+++ b/scripts/gen_ccws.sh	Fri Nov 25 23:16:22 2011 -0500
@@ -1,7 +1,6 @@
 #!/bin/bash
 
-len=`stat -c %s ipl/setmode.rto`
-len=`expr $len + $(stat -c %s ipl/loader.rto)`
+len=`stat -c %s $3`
 dif=`expr $len % 80`
 
 if [ $dif -ne 0 ]; then
@@ -17,7 +16,7 @@
 	exit 1
 fi
 
-echo -n "" > "$1"
+cat "$2" > "$1"
 
 addr=8388608 # == 0x800000
 flags="0x60"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/gen_loaderbin.sh	Fri Nov 25 23:16:22 2011 -0500
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+cat ipl_ccws.rto loader.rto > loader.bin
+
+len=`stat -c %s "loader.bin"`
+dif=`expr $len % 80`
+if [ $dif -ne 0 ]; then
+	dif=`expr 80 - $dif`
+	dd if=/dev/zero bs=1 count=$dif 2> /dev/null >> "loader.bin"
+fi
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/CMakeLists.txt	Fri Nov 25 23:16:22 2011 -0500
@@ -0,0 +1,2 @@
+add_subdirectory(os)
+add_subdirectory(prog)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/os/CMakeLists.txt	Fri Nov 25 23:16:22 2011 -0500
@@ -0,0 +1,7 @@
+set(CMAKE_EXE_LINKER_FLAGS "-T ${PROJECT_SOURCE_DIR}/scripts/linker.script")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DOSLEVEL")
+
+add_executable(shell shell.c std.c fs.c string.c stdio.c scall.c heap.c
+	memStack.c except.c storageKeys.c)
+
+target_link_libraries(shell arch)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/prog/CMakeLists.txt	Fri Nov 25 23:16:22 2011 -0500
@@ -0,0 +1,10 @@
+set(CMAKE_EXE_LINKER_FLAGS "-T ${PROJECT_SOURCE_DIR}/scripts/linkerProg.script")
+
+add_executable(hello hello.c std.c string.c)
+add_executable(ls ls.c)
+add_executable(echo echo.c std.c string.c)
+add_executable(dynamic dynamic.c std.c string.c stack.c)
+add_executable(rpn rpn.c std.c string.c stack.c operations.c math.c)
+add_executable(broken broken.c)
+
+target_link_libraries(broken arch)