Cosmos: a small open source operating system written in C
Copyright (C) 2002 - Christopher Giese <geezer@execpc.com>
http://www.execpc.com/~geezer/os/index.htm#cosmos

This kernel builds with DOS using these free software tools:
- NASM                      http://www.web-sites.co.uk/nasm
- DJGPP (GCC for DOS)       http://www.delorie.com/djgpp
  including MAKE and SED

To build the OS, type:
	make
	nasm -f bin -o load.com

To run the OS, exit Win95 to "MS-DOS" mode (real DOS) and type:
        krnl

================================================================
FEATURES
================================================================
NEW in release 10:
- New app: ANSI Space Invaders :)
- Bootloader deleted until it can be fixed, must boot from DOS :(
- Got rid of all far pointers in kernel and C library
- Added malloc(), calloc(), realloc(), and free() to C library
  (xxx - not yet tested)
- Kernel threads
- Task/thread priority levels
- Bottom-half interrupt handler for keyboard
- Added kmalloc(), krealloc(), and kfree() to kernel
- Virtual consoles backed with kernel memory, instead of video
  memory (can have 12 text consoles, 90x60 each, 127K memory!)
- Code in KSTART.ASM that builds initial page tables is more flexible
  and correct
- Fewer compiler warnings

Old features:
- 32-bit protected mode OS
- Movable kernel; can be loaded into contiguous RAM on any
  page (4K) boundary
- Unified IRQ/exception/fault/interrupt handler
- Initial RAM disk contains user tasks to be run
- Separate kernel- and user-privilege stacks for each task
- Preemptive multitasking, driven by timer interrupt.
  Round-robin scheduling (within same priority level).
- Tasks run at user privilege (ring 3). If a task performs an
  illegal operation, it is killed (the kernel keeps running).
- Paging. Tasks run in their own paged address spaces.
- Demand-loading. Still no block devices or filesystems;
  the "load" is actually a memcpy()
- Kernel memory (code and data) that is used only during kernel
  initialization is freed after use.
- Text-mode VGA virtual consoles, with software scrolling
  and a subset of ANSI escapes
- Realtime clock driver. time() syscall; uses unique JDN algorithm
- Tinylib, a small C library (libc)
- Make process creates kernel disassembly and symbol table files
- Ctrl+Alt+Del reboots

================================================================
BUGS/NOTES/GOTCHAS
================================================================
The resolution of the virtual consoles is that of the PC screen
before the OS starts. If you want to see lots of text on the
screen at once, compile 90X60.C in the UTIL directory, and run
that before typing 'krnl' (DOS only).

Support is in place for Cosmos to build with GCC for Linux or
GCC for Win32 (CygWin or MinGW32). However, GCC for Linux
doesn't work because of a bug in NASM, and CygWin/MinGW32 don't
work because of a compiler bug. Both bugs are known and fixed in
CVS. Because of these bugs, the Linux and MinGW32 makefiles have
been removed for now. The stand-alone bootloader introduced in
release 9 has also been removed for debug and rework. This
version of Cosmos can be started only from the DOS prompt.

================================================================
TO DO SOON
================================================================
Fix the damn bootloader.

Make USTART.ASM call sys_exit() with value returned by main().
Maybe add support for atexit() termination functions

Space Invaders freezes up after the first game. FIX.

kbrk() needs work: back out of failed allocations, and support
kfree() (reducing size of kernel heap instead of increasing it)

Change both kbrk() and sbrk() so they signal success/failure
and return the break value (old or new).

If given more memory than wanted, both malloc() and kmalloc()
should split off excess to form a new, free block.

Change _page_use_count[4096] in PAGING.C so it's a variable-
sized structure

Test user-level malloc(), free(), realloc()

A kernel thread that fails will call sys_exit() which will
destroy not only the thread but the parent address space. This
is bad. sys_exit() should check what is exiting: a kernel thread
or a user task.

Maybe clean up code that creates kernel threads

ECHO.C no longer works very well: causes page faults and won't
let you press Enter when buffer is full. Re-think the keyboard
input queues in do_console()

Interrupt stubs with installable vectors. Need 256 INTR and
INTR_EC macros, and INSTALL_HANDLER function or macro. Later,
need SAVE_VECTOR, RESTORE_VECTOR, and the ability for INSTALL_
HANDLER to set privilege level (must change IDT to do this)

LOADER.C should probably do more validation of executable files

Loadable kernel modules in relocatable (.o file) format.

Add device architecture, starting with console character device.

Add a read-only RAM disk (the first block device), read-only VFS
layer, read-only FAT12 filesystem, and read-only shell.

i18n: mixed text- and graphics-mode virtual consoles, installable
text and graphics fonts and keyboard tables, Unicode

================================================================
TO DO LATER
================================================================
Yielding by using INT 20h to simulate a timer interrupt:
is this a crock?

Port Tinylib string functions to asm for speed

Add V86 mode monitor

IPC: shared memory, signals, message queues, anonymous pipes

Advanced paging: figure out when to do invalidates, add shared
memory, add memory-mapped files, add swapping

Advanced block devices: read-write ATA, ATAPI, and PC floppy
drivers, disk cache, request queues

More filesystems: FAT16/32, VFAT, ext2, ISO-9660

================================================================
LICENSE
================================================================
Copyright 2002 by Christopher E. Giese <geezer@execpc.com>

Non-exclusive rights for redistribution and use of this material,
in source or binary form, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions, and the following disclaimer.
2. 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.

THIS MATERIAL IS PROVIDED BY THE AUTHOR(S) ``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(S) 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 MATERIAL, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.



Have fun!
