changeset 1:da98dc08f575

loadagent: beginning to lay the foundation
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 29 Apr 2013 03:21:00 +0000
parents 9beb566ded04
children ddda170fa6f4
files .hgignore loadagent/halt.h loadagent/libnosys/Makefile loadagent/libnosys/close.c loadagent/libnosys/fstat.c loadagent/libnosys/getpid.c loadagent/libnosys/glue.h loadagent/libnosys/isatty.c loadagent/libnosys/kill.c loadagent/libnosys/lseek.c loadagent/libnosys/open.c loadagent/libnosys/read.c loadagent/libnosys/sbrk.c loadagent/libnosys/stat.c loadagent/libnosys/unlink.c loadagent/libnosys/write.c loadagent/main.c loadagent/ns16550.h loadagent/romvars.h loadagent/serio.S loadagent/serwait.c loadagent/types.h
diffstat 22 files changed, 643 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sun Apr 28 17:36:07 2013 +0000
+++ b/.hgignore	Mon Apr 29 03:21:00 2013 +0000
@@ -1,6 +1,10 @@
-re:^toolchain/binutils-2.21.1/
-re:^toolchain/binutils-build/
-re:^toolchain/gcc-4.5.4/
-re:^toolchain/gcc-build/
-re:^toolchain/newlib-2.0.0/
-re:^toolchain/newlib-build/
+syntax: regexp
+
+\.[oa]$
+
+^toolchain/binutils-2.21.1/
+^toolchain/binutils-build/
+^toolchain/gcc-4.5.4/
+^toolchain/gcc-build/
+^toolchain/newlib-2.0.0/
+^toolchain/newlib-build/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/halt.h	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,10 @@
+/*
+ * In some error cases in our loadagent code we have no better course
+ * of action available than to halt in a tight loop.  We define _exit()
+ * to do the latter.  We have defined some codes for the argument value
+ * that goes into R0; if you manage to hook up JTAG and get it to work,
+ * you might be able to see what went wrong.
+ */
+
+#define	HALTCODE_MAINEXITED	0x40
+#define	HALTCODE_INVALIDUART	0x41
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/Makefile	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,16 @@
+CC=	arm-elf-gcc
+CFLAGS=	-Os -mcpu=arm7tdmi -marm -mno-thumb-interwork
+AR=	arm-elf-ar
+RANLIB=	arm-elf-ranlib
+
+OBJS=	close.o fstat.o getpid.o isatty.o kill.o lseek.o open.o read.o sbrk.o \
+	stat.o unlink.o write.o
+
+all:	libnosys.a
+
+libnosys.a:	${OBJS}
+	${AR} cru $@ ${OBJS}
+	${RANLIB} $@
+
+clean:
+	rm -f *.[oa] *errs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/close.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,25 @@
+/* close.c -- close a file descriptor.
+ *
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include "glue.h"
+
+/*
+ * close -- We don't need to do anything, but pretend we did.
+ */
+int
+_DEFUN (_close ,(fd),
+       int fd)
+{
+  return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/fstat.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,30 @@
+/* fstat.c -- get status of a file.
+ *
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include <sys/stat.h>
+#include "glue.h"
+
+/*
+ * fstat -- Since we have no file system, we just return an error.
+ */
+int
+_DEFUN (_fstat, (fd, buf),
+       int fd _AND
+       struct stat *buf)
+{
+  buf->st_mode = S_IFCHR;	/* Always pretend to be a tty */
+  buf->st_blksize = 0;
+
+  return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/getpid.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,25 @@
+/* getpid.c -- get the current process id.
+ *
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include "glue.h"
+
+/*
+ * getpid -- only one process, so just return 1.
+ */
+int
+_DEFUN (_getpid, (),
+        )
+{
+  return __MYPID;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/glue.h	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,31 @@
+/* glue.h -- common definitions for "glue" fucntions.
+ *
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include <_ansi.h>
+
+#ifndef NULL
+#  define NULL 0
+#endif
+
+#ifdef __NO_UNDERSCORE__
+#  define _end    end
+#  define _exit	  exit
+#endif
+
+extern char _end[];                /* _end is set in the linker command file */
+
+/* only one prcess support, as this is OS dependant */
+#define __MYPID 1
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/isatty.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,27 @@
+/* isatty.c -- chek the terminal device.
+ * 
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include "glue.h"
+
+/*
+ * isatty -- returns 1 if connected to a terminal device,
+ *           returns 0 if not. Since we're hooked up to a
+ *           serial port, we'll say yes _AND return a 1.
+ */
+int
+_DEFUN (_isatty, (fd),
+       int fd)
+{
+  return (1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/kill.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,28 @@
+/* kill.c -- remove a process.
+ *
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include "glue.h"
+
+/*
+ * kill -- go out via exit...
+ */
+int
+_DEFUN (_kill, (pid, sig),
+        int pid _AND 
+        int sig)
+{
+  if(pid == __MYPID)
+    _exit(sig);
+  return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/lseek.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,31 @@
+/* lseek.c -- move read/write pointer.
+ *
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include <sys/types.h>
+#include <errno.h>
+#include "glue.h"
+
+/*
+ * lseek --  Since a serial port is non-seekable, we return an error.
+ */
+off_t
+_DEFUN (_lseek, (fd,  offset, whence),
+       int fd _AND
+       off_t offset _AND
+       int whence)
+{
+  errno = ESPIPE;
+  return ((off_t)-1);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/open.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,31 @@
+/* open.c -- open a file.
+ * 
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include <errno.h>
+#include "glue.h"
+
+/*
+ * open -- open a file descriptor. We don't have a filesystem, so
+ *         we return an error.
+ */
+int
+_DEFUN (_open, (buf, flags, mode),
+       const char *buf _AND
+       int flags _AND
+       int mode)
+{
+  errno = EIO;
+  return (-1);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/read.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,30 @@
+/* read.c -- read bytes from a input device.
+ * 
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include "glue.h"
+
+/*
+ * read  -- read bytes from the serial port. Ignore fd, since
+ *          we only have stdin.
+ *
+ * In the present version changed to always return EOF indication.
+ */
+int
+_DEFUN (_read, (fd, buf, nbytes),
+       int fd _AND
+       char *buf _AND
+       int nbytes)
+{
+  return (0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/sbrk.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,55 @@
+/* sbrk.c -- allocate memory dynamically.
+ * 
+ * Copyright (c) 1995,1996 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include <errno.h>
+#include "glue.h"
+
+/* just in case, most boards have at least some memory */
+#ifndef RAMSIZE
+#  define RAMSIZE             (caddr_t)0x100000
+#endif
+
+char *heap_ptr;
+
+/*
+ * sbrk -- changes heap size size. Get nbytes more
+ *         RAM. We just increment a pointer in what's
+ *         left of memory on the board.
+ */
+char *
+_sbrk (nbytes)
+     int nbytes;
+{
+  char        *base;
+
+  if (!heap_ptr)
+    heap_ptr = (char *)&_end;
+  base = heap_ptr;
+  heap_ptr += nbytes;
+
+  return base;
+/* FIXME: We really want to make sure we don't run out of RAM, but this
+ *       isn't very portable.
+ */
+#if 0
+  if ((RAMSIZE - heap_ptr - nbytes) >= 0) {
+    base = heap_ptr;
+    heap_ptr += nbytes;
+    return (base);
+  } else {
+    errno = ENOMEM;
+    return ((char *)-1);
+  }
+#endif
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/stat.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,30 @@
+/* stat.c -- Get the status of a file.
+ *
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include <sys/stat.h>
+#include <errno.h>
+#include "glue.h"
+
+/*
+ * stat -- Since we have no file system, we just return an error.
+ */
+int
+_DEFUN (_stat, (path, buf),
+       const char *path _AND
+       struct stat *buf)
+{
+  errno = EIO;
+  return (-1);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/unlink.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,28 @@
+/* unlink.c -- remove a file.
+ * 
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include <errno.h>
+#include "glue.h"
+
+/*
+ * unlink -- since we have no file system, 
+ *           we just return an error.
+ */
+int
+_DEFUN (_unlink, (path),
+        char * path)
+{
+  errno = EIO;
+  return (-1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/libnosys/write.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,39 @@
+/* write.c -- write bytes to an output device.
+ *
+ * Copyright (c) 1995 Cygnus Support
+ *
+ * The authors hereby grant permission to use, copy, modify, distribute,
+ * and license this software and its documentation for any purpose, provided
+ * that existing copyright notices are retained in all copies and that this
+ * notice is included verbatim in any distributions. No written agreement,
+ * license, or royalty fee is required for any of the authorized uses.
+ * Modifications to this software may be copyrighted by their authors
+ * and need not follow the licensing terms described here, provided that
+ * the new terms are clearly indicated on the first page of each file where
+ * they apply.
+ */
+#include "glue.h"
+
+extern int  _EXFUN (serial_out, (char x));
+
+/*
+ * write -- write bytes to the serial port. Ignore fd, since
+ *          stdout and stderr are the same. Since we have no filesystem,
+ *          open will only return an error.
+ */
+int
+_DEFUN (_write, (fd, buf, nbytes),
+       int fd _AND
+       char *buf _AND
+       int nbytes)
+{
+  int i;
+
+  for (i = 0; i < nbytes; i++) {
+    if (*(buf + i) == '\n') {
+      serial_out ('\r');
+    }
+    serial_out (*(buf + i));
+  }
+  return (nbytes);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/main.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,31 @@
+/*
+ * FreeCalypso loadagent main() function lives here
+ */
+
+#include "types.h"
+#include "romvars.h"
+#include "ns16550.h"
+#include "halt.h"
+
+#include <stdio.h>
+
+extern struct boot_rom_vars rom_vars;
+
+struct ns16550_regs *uart_base;
+char *uart_name;
+
+uart_select_init()
+{
+	switch (rom_vars.uart_id) {
+	case 0:
+		uart_base = (struct ns16550_regs *) 0xFFFF5800;
+		uart_name = "MODEM";
+		break;
+	case 1:
+		uart_base = (struct ns16550_regs *) 0xFFFF5000;
+		uart_name = "IrDA";
+		break;
+	default:
+		_exit(HALTCODE_INVALIDUART);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/ns16550.h	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,101 @@
+#ifndef __NS16550_H
+#define	__NS16550_H
+
+/* NS16550 registers */
+#define	NS16550_RBR	0
+#define	NS16550_THR	0
+#define	NS16550_IER	1
+#define	NS16550_IIR	2
+#define	NS16550_FCR	2
+#define	NS16550_LCR	3
+#define	NS16550_MCR	4
+#define	NS16550_LSR	5
+#define	NS16550_MSR	6
+#define	NS16550_SCR	7
+#define	NS16550_DLL	0
+#define	NS16550_DLM	1
+
+#ifndef __ASSEMBLER__
+#include "types.h"
+
+struct ns16550_regs {
+	u8	datareg;
+	u8	ier;
+	u8	iir_fcr;
+	u8	lcr;
+	u8	mcr;
+	u8	lsr;
+	u8	msr;
+	u8	scr;
+};
+#endif
+
+/* IER bits */
+#define	NS16550_IER_EDSSI	0x08
+#define	NS16550_IER_ELSI	0x04
+#define	NS16550_IER_ETBEI	0x02
+#define	NS16550_IER_ERBFI	0x01
+
+/* IIR bits */
+#define	NS16550_IIR_FIFOEN	0xC0
+#define	NS16550_IIR_INTID	0x0E
+#define	NS16550_IIR_INT_RLS	0x06
+#define	NS16550_IIR_INT_RDA	0x04
+#define	NS16550_IIR_INT_CTO	0x0C
+#define	NS16550_IIR_INT_THRE	0x02
+#define	NS16550_IIR_INT_MODEM	0x00
+#define	NS16550_IIR_INTPEND	0x01
+
+/* FCR bits */
+
+#define	NS16550_FCR_RXTR	0xC0
+#define	NS16550_FCR_RXTR_1	0x00
+#define	NS16550_FCR_RXTR_4	0x40
+#define	NS16550_FCR_RXTR_8	0x80
+#define	NS16550_FCR_RXTR_14	0xC0
+#define	NS16550_FCR_DMAMODE	0x08
+#define	NS16550_FCR_TXRST	0x04
+#define	NS16550_FCR_RXRST	0x02
+#define	NS16550_FCR_FIFOEN	0x01
+
+/* LCR bits */
+#define	NS16550_LCR_DLAB	0x80
+#define	NS16550_LCR_BREAK	0x40
+#define	NS16550_LCR_STICK	0x20
+#define	NS16550_LCR_EPS		0x10
+#define	NS16550_LCR_PEN		0x08
+#define	NS16550_LCR_STB		0x04
+#define	NS16550_LCR_WLS		0x03
+#define	NS16550_LCR_WLS_5	0x00
+#define	NS16550_LCR_WLS_6	0x01
+#define	NS16550_LCR_WLS_7	0x02
+#define	NS16550_LCR_WLS_8	0x03
+
+/* MCR bits */
+#define	NS16550_MCR_LOOP	0x10
+#define	NS16550_MCR_OUT2	0x08
+#define	NS16550_MCR_OUT1	0x04
+#define	NS16550_MCR_RTS		0x02
+#define	NS16550_MCR_DTR		0x01
+
+/* LSR bits */
+#define	NS16550_LSR_ERR		0x80
+#define	NS16550_LSR_TEMP	0x40
+#define	NS16550_LSR_THRE	0x20
+#define	NS16550_LSR_BI		0x10
+#define	NS16550_LSR_FE		0x08
+#define	NS16550_LSR_PE		0x04
+#define	NS16550_LSR_OE		0x02
+#define	NS16550_LSR_DR		0x01
+
+/* MSR bits */
+#define	NS16550_MSR_DCD		0x80
+#define	NS16550_MSR_RI		0x40
+#define	NS16550_MSR_DSR		0x20
+#define	NS16550_MSR_CTS		0x10
+#define	NS16550_MSR_DDCD	0x08
+#define	NS16550_MSR_TERI	0x04
+#define	NS16550_MSR_DDSR	0x02
+#define	NS16550_MSR_DCTS	0x01
+
+#endif	/* __NS16550_H */
--- a/loadagent/romvars.h	Sun Apr 28 17:36:07 2013 +0000
+++ b/loadagent/romvars.h	Mon Apr 29 03:21:00 2013 +0000
@@ -13,6 +13,11 @@
  * based on the disassembly of the boot ROM.
  */
 
+#ifndef __ROMVARS_H
+#define	__ROMVARS_H
+
+#include "types.h"
+
 struct boot_rom_vars {
 	u8	baud_rate_code;
 	u8	pad1[3];
@@ -27,3 +32,5 @@
 	u16	pad2;
 	u32	branch_addr;
 };
+
+#endif	/* include guard */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/serio.S	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,26 @@
+#include "ns16550.h"
+
+@ this module implements the elementary serial I/O operations
+
+	.text
+	.code	32
+	.global	serial_out
+serial_out:
+	ldr	r1, =uart_base
+	ldr	r2, [r1]
+1:	ldrb	r3, [r2, #NS16550_LSR]
+	tst	r3, #NS16550_LSR_THRE
+	beq	1b
+	strb	r0, [r2, #NS16550_THR]
+	bx	lr
+
+	.global	serial_in_poll
+serial_in_poll:
+	ldr	r1, =uart_base
+	ldr	r2, [r1]
+	ldrb	r3, [r2, #NS16550_LSR]
+	tst	r3, #NS16550_LSR_DR
+	mvneq	r0, #1
+	bxeq	lr
+	ldrb	r0, [r2, #NS16550_RBR]
+	bx	lr
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/serwait.c	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,14 @@
+/* this C module is a wrapper around serio.S */
+/* we implement serial_in_wait() as a C wrapper around serial_in_poll() */
+
+extern int serial_in_poll();
+
+int serial_in_wait()
+{
+	register int c;
+
+	do
+		c = serial_in_poll();
+	while (c < 0);
+	return c;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadagent/types.h	Mon Apr 29 03:21:00 2013 +0000
@@ -0,0 +1,18 @@
+/*
+ * I personally like the u8/u16/u32 types, but I don't see them
+ * being defined in any of the headers provided by newlib.
+ * So we'll define them ourselves.
+ */
+
+#ifndef	__OUR_OWN_TYPES_H
+#define	__OUR_OWN_TYPES_H
+
+typedef unsigned char u8;
+typedef unsigned short u16;
+typedef unsigned int u32;
+
+typedef signed char s8;
+typedef signed short s16;
+typedef signed int s32;
+
+#endif	/* include guard */