summaryrefslogtreecommitdiff
path: root/kernel/old/include
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/old/include')
-rw-r--r--kernel/old/include/.vm.h.swpbin0 -> 24576 bytes
-rw-r--r--kernel/old/include/bindings.h73
-rw-r--r--kernel/old/include/bootstrap.h101
-rw-r--r--kernel/old/include/cio.h40
-rw-r--r--kernel/old/include/clock.h12
-rw-r--r--kernel/old/include/common.h31
-rw-r--r--kernel/old/include/compat.h27
-rw-r--r--kernel/old/include/debug.h243
-rw-r--r--kernel/old/include/defs.h89
-rw-r--r--kernel/old/include/elf.h235
-rw-r--r--kernel/old/include/kdefs.h113
-rw-r--r--kernel/old/include/klib.h8
-rw-r--r--kernel/old/include/kmem.h20
-rw-r--r--kernel/old/include/lib.h314
-rw-r--r--kernel/old/include/list.h6
-rw-r--r--kernel/old/include/offsets.h83
-rw-r--r--kernel/old/include/params.h10
-rw-r--r--kernel/old/include/procs.h145
-rw-r--r--kernel/old/include/serial.h3
-rw-r--r--kernel/old/include/sio.h28
-rw-r--r--kernel/old/include/support.h27
-rw-r--r--kernel/old/include/syscalls.h38
-rw-r--r--kernel/old/include/types.h53
-rw-r--r--kernel/old/include/udefs.h113
-rw-r--r--kernel/old/include/ulib.h315
-rw-r--r--kernel/old/include/user.h25
-rw-r--r--kernel/old/include/userids.h33
-rw-r--r--kernel/old/include/vm.h356
-rw-r--r--kernel/old/include/vmtables.h2
-rw-r--r--kernel/old/include/x86/arch.h350
-rw-r--r--kernel/old/include/x86/bios.h73
-rw-r--r--kernel/old/include/x86/ops.h266
-rw-r--r--kernel/old/include/x86/pic.h125
-rw-r--r--kernel/old/include/x86/pit.h75
-rw-r--r--kernel/old/include/x86/uart.h371
35 files changed, 2380 insertions, 1423 deletions
diff --git a/kernel/old/include/.vm.h.swp b/kernel/old/include/.vm.h.swp
new file mode 100644
index 0000000..eb334b9
--- /dev/null
+++ b/kernel/old/include/.vm.h.swp
Binary files differ
diff --git a/kernel/old/include/bindings.h b/kernel/old/include/bindings.h
deleted file mode 100644
index 365abc9..0000000
--- a/kernel/old/include/bindings.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * @file bindings.h
- * @author Freya Murphy <freya@freyacat.org>
- *
- * C-style function definitions binded to their named assembly instruction.
- */
-
-#ifndef _BINDINGS_H
-#define _BINDINGS_H
-#include <types.h>
-
-static inline uint8_t inb(uint16_t port)
-{
- uint8_t ret;
- __asm__ volatile("inb %1, %0" : "=a"(ret) : "Nd"(port));
- return ret;
-}
-
-static inline void outb(uint16_t port, uint8_t val)
-{
- __asm__ volatile("outb %0, %1" : : "a"(val), "Nd"(port));
-}
-
-static inline uint16_t inw(uint16_t port)
-{
- uint16_t ret;
- __asm__ volatile("inw %1, %0" : "=a"(ret) : "Nd"(port));
- return ret;
-}
-
-static inline void outw(uint16_t port, uint16_t val)
-{
- __asm__ volatile("outw %0, %1" : : "a"(val), "Nd"(port));
-}
-
-static inline uint32_t inl(uint16_t port)
-{
- uint32_t ret;
- __asm__ volatile("inl %1, %0" : "=a"(ret) : "Nd"(port));
- return ret;
-}
-
-static inline void outl(uint16_t port, uint32_t val)
-{
- __asm__ volatile("outl %0, %1" : : "a"(val), "Nd"(port));
-}
-
-static inline void io_wait(void)
-{
- outb(0x80, 0);
-}
-
-static inline void sti(void)
-{
- __asm__ volatile("sti");
-}
-
-static inline void cli(void)
-{
- __asm__ volatile("cli");
-}
-
-static inline void int_wait(void)
-{
- __asm__ volatile("sti; hlt");
-}
-
-static inline void halt(void)
-{
- __asm__ volatile("cli; hlt");
-}
-
-#endif /* bindings.h */
diff --git a/kernel/old/include/bootstrap.h b/kernel/old/include/bootstrap.h
index 6c6dfcc..ade778a 100644
--- a/kernel/old/include/bootstrap.h
+++ b/kernel/old/include/bootstrap.h
@@ -9,89 +9,89 @@
** Addresses where various stuff goes in memory.
*/
-#ifndef BOOTSTRAP_H_
-#define BOOTSTRAP_H_
+#ifndef BOOTSTRAP_H_
+#define BOOTSTRAP_H_
/*
** The boot device
*/
-#define BDEV_FLOPPY 0x00
-#define BDEV_USB 0x80 /* hard drive */
+#define BDEV_FLOPPY 0x00
+#define BDEV_USB 0x80 /* hard drive */
-#define BDEV BDEV_USB /* default */
+#define BDEV BDEV_USB /* default */
/*
** Bootstrap definitions
*/
-#define BOOT_SEG 0x07c0 /* 07c0:0000 */
-#define BOOT_DISP 0x0000
-#define BOOT_ADDR ((BOOT_SEG << 4) + BOOT_DISP)
+#define BOOT_SEG 0x07c0 /* 07c0:0000 */
+#define BOOT_DISP 0x0000
+#define BOOT_ADDR ((BOOT_SEG << 4) + BOOT_DISP)
-#define PART2_DISP 0x0200 /* 07c0:0200 */
-#define PART2_ADDR ((BOOT_SEG << 4) + PART2_DISP)
+#define PART2_DISP 0x0200 /* 07c0:0200 */
+#define PART2_ADDR ((BOOT_SEG << 4) + PART2_DISP)
-#define SECTOR_SIZE 0x200 /* 512 bytes */
+#define SECTOR_SIZE 0x200 /* 512 bytes */
/* Note: this assumes the bootstrap is two sectors long! */
-#define BOOT_SIZE (SECTOR_SIZE + SECTOR_SIZE)
+#define BOOT_SIZE (SECTOR_SIZE + SECTOR_SIZE)
-#define OFFSET_LIMIT (0x10000 - SECTOR_SIZE)
+#define OFFSET_LIMIT (0x10000 - SECTOR_SIZE)
-#define BOOT_SP_DISP 0x4000 /* stack pointer 07c0:4000, or 0xbc00 */
-#define BOOT_SP_ADDR ((BOOT_SEG << 4) + BOOT_SP_DISP)
+#define BOOT_SP_DISP 0x4000 /* stack pointer 07c0:4000, or 0xbc00 */
+#define BOOT_SP_ADDR ((BOOT_SEG << 4) + BOOT_SP_DISP)
-#define SECTOR1_END (BOOT_ADDR + SECTOR_SIZE)
-#define SECTOR2_END (BOOT_ADDR + BOOT_SIZE)
+#define SECTOR1_END (BOOT_ADDR + SECTOR_SIZE)
+#define SECTOR2_END (BOOT_ADDR + BOOT_SIZE)
// location of the user blob data
// (three halfwords of data)
-#define USER_BLOB_DATA (SECTOR2_END - 12)
+#define USER_BLOB_DATA (SECTOR2_END - 12)
/*
** The target program itself
*/
-#define TARGET_SEG 0x00001000 /* 1000:0000 */
-#define TARGET_ADDR 0x00010000 /* and upward */
-#define TARGET_STACK 0x00010000 /* and downward */
+#define TARGET_SEG 0x00001000 /* 1000:0000 */
+#define TARGET_ADDR 0x00010000 /* and upward */
+#define TARGET_STACK 0x00010000 /* and downward */
/*
** The Global Descriptor Table (0000:0500 - 0000:2500)
*/
-#define GDT_SEG 0x00000050
-#define GDT_ADDR 0x00000500
+#define GDT_SEG 0x00000050
+#define GDT_ADDR 0x00000500
-/* segment register values */
-#define GDT_LINEAR 0x0008 /* All of memory, R/W */
-#define GDT_CODE 0x0010 /* All of memory, R/E */
-#define GDT_DATA 0x0018 /* All of memory, R/W */
-#define GDT_STACK 0x0020 /* All of memory, R/W */
+ /* segment register values */
+#define GDT_LINEAR 0x0008 /* All of memory, R/W */
+#define GDT_CODE 0x0010 /* All of memory, R/E */
+#define GDT_DATA 0x0018 /* All of memory, R/W */
+#define GDT_STACK 0x0020 /* All of memory, R/W */
/*
** The Interrupt Descriptor Table (0000:2500 - 0000:2D00)
*/
-#define IDT_SEG 0x00000250
-#define IDT_ADDR 0x00002500
+#define IDT_SEG 0x00000250
+#define IDT_ADDR 0x00002500
/*
** Additional I/O ports used by the bootstrap code
*/
// keyboard controller
-#define KBD_DATA 0x60
-#define KBD_CMD 0x64
-#define KBD_STAT 0x64
+#define KBD_DATA 0x60
+#define KBD_CMD 0x64
+#define KBD_STAT 0x64
// status register bits
-#define KBD_OBSTAT 0x01
-#define KBD_IBSTAT 0x02
-#define KBD_SYSFLAG 0x04
-#define KBD_CMDDAT 0x08
+#define KBD_OBSTAT 0x01
+#define KBD_IBSTAT 0x02
+#define KBD_SYSFLAG 0x04
+#define KBD_CMDDAT 0x08
// commands
-#define KBD_P1_DISABLE 0xad
-#define KBD_P1_ENABLE 0xae
-#define KBD_RD_OPORT 0xd0
-#define KBD_WT_OPORT 0xd1
+#define KBD_P1_DISABLE 0xad
+#define KBD_P1_ENABLE 0xae
+#define KBD_RD_OPORT 0xd0
+#define KBD_WT_OPORT 0xd1
#ifdef ASM_SRC
@@ -104,16 +104,17 @@
// .byte granularity byte
// .byte upper 8 bits of base
// we use 4K units, so we ignore the lower 12 bits of the limit
-#define SEGNULL .word 0, 0, 0, 0
+#define SEGNULL \
+ .word 0, 0, 0, 0
-#define SEGMENT(base, limit, dpl, type) \
- .word(((limit) >> 12) & 0xffff); \
- .word((base) & 0xffff); \
- .byte(((base) >> 16) & 0xff); \
- .byte(SEG_PRESENT | (dpl) | SEG_NON_SYSTEM | (type)); \
- .byte(SEG_GRAN_4KBYTE | SEG_DB_32BIT | (((limit) >> 28) & 0xf)); \
- .byte(((base) >> 24) & 0xff)
+#define SEGMENT(base,limit,dpl,type) \
+ .word (((limit) >> 12) & 0xffff); \
+ .word ((base) & 0xffff) ; \
+ .byte (((base) >> 16) & 0xff) ; \
+ .byte (SEG_PRESENT | (dpl) | SEG_NON_SYSTEM | (type)) ; \
+ .byte (SEG_GRAN_4KBYTE | SEG_DB_32BIT | (((limit) >> 28) & 0xf)) ; \
+ .byte (((base) >> 24) & 0xff)
-#endif /* ASM_SRC */
+#endif /* ASM_SRC */
#endif
diff --git a/kernel/old/include/cio.h b/kernel/old/include/cio.h
index 63bf827..1854f6e 100644
--- a/kernel/old/include/cio.h
+++ b/kernel/old/include/cio.h
@@ -11,7 +11,7 @@
** Declarations and descriptions of console I/O routines
**
** These routines provide a rudimentary capability for printing to
-** the screen and reading from the keyboard.
+** the screen and reading from the keyboard.
**
** Screen output:
** There are two families of functions. The first provides a window
@@ -50,7 +50,7 @@
** Keyboard input:
** Two functions are provided: getting a single character and getting
** a newline-terminated line. A third function returns a count of
-** the number of characters available for immediate reading.
+** the number of characters available for immediate reading.
** No conversions are provided (yet).
*/
@@ -77,7 +77,7 @@
**
** @param notify pointer to an input notification function, or NULL
*/
-void cio_init(void (*notify)(int));
+void cio_init( void (*notify)(int) );
/*****************************************************************************
**
@@ -102,8 +102,8 @@ void cio_init(void (*notify)(int));
** @param min_x,min_y upper-left corner of the region
** @param max_x,max_y lower-right corner of the region
*/
-void cio_setscroll(unsigned int min_x, unsigned int min_y, unsigned int max_x,
- unsigned int max_y);
+void cio_setscroll( unsigned int min_x, unsigned int min_y,
+ unsigned int max_x, unsigned int max_y );
/**
** cio_moveto
@@ -114,7 +114,7 @@ void cio_setscroll(unsigned int min_x, unsigned int min_y, unsigned int max_x,
**
** @param x,y desired coordinate position
*/
-void cio_moveto(unsigned int x, unsigned int y);
+void cio_moveto( unsigned int x, unsigned int y );
/**
** cio_putchar
@@ -123,7 +123,7 @@ void cio_moveto(unsigned int x, unsigned int y);
**
** @param c the character to be printed
*/
-void cio_putchar(unsigned int c);
+void cio_putchar( unsigned int c );
/**
** cio_puts
@@ -133,7 +133,7 @@ void cio_putchar(unsigned int c);
**
** @param str pointer to a NUL-terminated string to be printed
*/
-void cio_puts(const char *str);
+void cio_puts( const char *str );
/**
** cio_write
@@ -143,7 +143,7 @@ void cio_puts(const char *str);
** @param buf the buffer of characters
** @param length the number of characters to print
*/
-void cio_write(const char *buf, int length);
+void cio_write( const char *buf, int length );
/**
** cio_printf
@@ -154,7 +154,7 @@ void cio_write(const char *buf, int length);
** @param fmt a printf-style format control string
** @param ... optional additional values to be printed
*/
-void cio_printf(char *fmt, ...);
+void cio_printf( char *fmt, ... );
/**
** cio_scroll
@@ -165,7 +165,7 @@ void cio_printf(char *fmt, ...);
**
** @param lines the number of lines to scroll
*/
-void cio_scroll(unsigned int lines);
+void cio_scroll( unsigned int lines );
/**
** cio_clearscroll
@@ -173,7 +173,7 @@ void cio_scroll(unsigned int lines);
** Clears the entire scrolling region to blank spaces, and
** moves the cursor to (0,0).
*/
-void cio_clearscroll(void);
+void cio_clearscroll( void );
/*****************************************************************************
**
@@ -196,7 +196,7 @@ void cio_clearscroll(void);
** @param x,y desired coordinate position
** @param c the character to be printed
*/
-void cio_putchar_at(unsigned int x, unsigned int y, unsigned int c);
+void cio_putchar_at( unsigned int x, unsigned int y, unsigned int c );
/**
** cio_puts_at
@@ -207,7 +207,7 @@ void cio_putchar_at(unsigned int x, unsigned int y, unsigned int c);
** @param x,y desired coordinate position
** @param str pointer to a NUL-terminated string to be printed
*/
-void cio_puts_at(unsigned int x, unsigned int y, const char *str);
+void cio_puts_at( unsigned int x, unsigned int y, const char *str );
/**
** cio_printf_at
@@ -219,14 +219,14 @@ void cio_puts_at(unsigned int x, unsigned int y, const char *str);
** @param fmt a printf-style format control string
** @param ... optional additional values to be printed
*/
-void cio_printf_at(unsigned int x, unsigned int y, char *fmt, ...);
+void cio_printf_at( unsigned int x, unsigned int y, char *fmt, ... );
/**
** cio_clearscreen
**
** This function clears the entire screen, including the scrolling region.
*/
-void cio_clearscreen(void);
+void cio_clearscreen( void );
/*****************************************************************************
**
@@ -251,7 +251,7 @@ void cio_clearscreen(void);
**
** @return the next character from the keyboard input buffer
*/
-int cio_getchar(void);
+int cio_getchar( void );
/**
** cio_gets
@@ -270,7 +270,7 @@ int cio_getchar(void);
**
** @return count of the number of characters read into the buffer
*/
-int cio_gets(char *buffer, unsigned int size);
+int cio_gets( char *buffer, unsigned int size );
/**
** cio_input_queue
@@ -281,7 +281,7 @@ int cio_gets(char *buffer, unsigned int size);
**
** @return number of characters in the input queue
*/
-int cio_input_queue(void);
-#endif /* !ASM_SRC */
+int cio_input_queue( void );
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/clock.h b/kernel/old/include/clock.h
index 674d799..6eae41f 100644
--- a/kernel/old/include/clock.h
+++ b/kernel/old/include/clock.h
@@ -17,10 +17,10 @@
// conversion functions for seconds, ms, and ticks
// (SEC_TO_MS is defined in defs.h)
-#define MS_TO_TICKS(n) ((n))
-#define SEC_TO_TICKS(n) (MS_TO_TICKS(SEC_TO_MS(n)))
-#define TICKS_TO_SEC(n) ((n) / CLOCK_FREQ)
-#define TICKS_TO_SEC_ROUNDED(n) (((n) + (CLOCK_FREQ - 1)) / CLOCK_FREQ)
+#define MS_TO_TICKS(n) ((n))
+#define SEC_TO_TICKS(n) (MS_TO_TICKS(SEC_TO_MS(n)))
+#define TICKS_TO_SEC(n) ((n) / CLOCK_FREQ)
+#define TICKS_TO_SEC_ROUNDED(n) (((n)+(CLOCK_FREQ-1)) / CLOCK_FREQ)
#ifndef ASM_SRC
@@ -48,8 +48,8 @@ extern uint32_t system_time;
**
** Clock module initialization
*/
-void clk_init(void);
+void clk_init( void );
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/common.h b/kernel/old/include/common.h
new file mode 100644
index 0000000..599c492
--- /dev/null
+++ b/kernel/old/include/common.h
@@ -0,0 +1,31 @@
+/**
+** @file common.h
+**
+** @author Warren R. Carithers
+**
+** @brief Common definitions for the baseline system.
+**
+** This header file pulls in the standard header information needed
+** by all parts of the system. It is purely for our convenience.
+*/
+
+#ifndef COMMON_H_
+#define COMMON_H_
+
+// everything needs these; they also pull in
+// the kernel- or user-level defs and lib headers
+#include <types.h>
+#include <params.h>
+#include <defs.h>
+#include <lib.h>
+
+#ifdef KERNEL_SRC
+
+// only kernel code needs these headers
+#include <common.h>
+#include <cio.h>
+#include <debug.h>
+
+#endif /* KERNEL_SRC */
+
+#endif
diff --git a/kernel/old/include/compat.h b/kernel/old/include/compat.h
index f0c8c97..ee62090 100644
--- a/kernel/old/include/compat.h
+++ b/kernel/old/include/compat.h
@@ -60,10 +60,10 @@
*/
// type name for the PCB
-#define PCBTYPE pcb_t
+#define PCBTYPE pcb_t
// type name for our queue
-#define QTYPE pcb_queue_t
+#define QTYPE pcb_queue_t
/*
** Section 3: interface and behavior
@@ -77,13 +77,13 @@
*/
// string functions
-#define SLENGTH strlen
+#define SLENGTH strlen
// scheduler
-#define SCHED schedule
+#define SCHED schedule
// dispatcher
-#define DISPATCH dispatch
+#define DISPATCH dispatch
/*
** blocked queue for reading processes
@@ -93,7 +93,7 @@
** Its value should be the name of the globally-visible
** queue to be used.
*/
-#define QNAME sioread
+#define QNAME sioread
#ifdef QNAME
@@ -105,27 +105,26 @@
// invoke the queue creation function
// examples:
//
-// #define QCREATE(q) do {
-// _que_create( &(q), NULL );
+// #define QCREATE(q) do {
+// _que_create( &(q), NULL );
// } while(0)
//
// #define QCREATE(q) // do nothing
-#define QCREATE(q) // handled elsewhere for us
+#define QCREATE(q) // handled elsewhere for us
// check to see if the queue is empty
// examples:
//
// #define QEMPTY(q) queue_is_empty(q)
// #define QEMPTY(q) (quene_length(q) > 0)
-#define QEMPTY(q) pcb_queue_empty(q)
+#define QEMPTY(q) pcb_queue_empty(q)
// this macro expands into code that removes a value from
// 'q' and places it into 'd'
-#define QDEQUE(q, d) \
- do { \
- assert(pcb_queue_remove((q), (pcb_t **)&(d)) == SUCCESS); \
- } while (0)
+#define QDEQUE(q,d) do { \
+ assert(pcb_queue_remove( (q), (pcb_t **) &(d) ) == SUCCESS ); \
+ } while(0)
#endif /* QNAME */
diff --git a/kernel/old/include/debug.h b/kernel/old/include/debug.h
index 41e38cb..487a592 100644
--- a/kernel/old/include/debug.h
+++ b/kernel/old/include/debug.h
@@ -35,17 +35,11 @@
// currently, these do not use the macro parameter, but could be
// modified to do so; instead, we use the __func__ CPP pseudo-macro
// to get the function name
-#define ENTERING(n) \
- do { \
- cio_puts(" enter " __func__); \
- } while (0)
-#define EXITING(n) \
- do { \
- cio_puts(" exit " __func__); \
- } while (0)
+#define ENTERING(n) do { cio_puts( " enter " __func__ ); } while(0)
+#define EXITING(n) do { cio_puts( " exit " __func__ ); } while(0)
#else
-#define ENTERING(m) // do nothing
-#define EXITING(m) // do nothing
+#define ENTERING(m) // do nothing
+#define EXITING(m) // do nothing
#endif
/*
@@ -54,22 +48,20 @@
// Warning messages to the console
// m: message (condition, etc.)
-#define WARNING(m) \
- do { \
- cio_printf("\n** %s (%s @ %d): ", __func__, __FILE__, __LINE__); \
- cio_puts(m); \
- cio_putchar('\n'); \
- } while (0)
+#define WARNING(m) do { \
+ cio_printf( "\n** %s (%s @ %d): ", __func__, __FILE__, __LINE__ ); \
+ cio_puts( m ); \
+ cio_putchar( '\n' ); \
+ } while(0)
// Panic messages to the console
// n: severity level
// m: message (condition, etc.)
-#define PANIC(n, m) \
- do { \
- sprint(b512, "%s (%s @ %d), %d: %s\n", __func__, __FILE__, __LINE__, \
- n, #m); \
- kpanic(b512); \
- } while (0)
+#define PANIC(n,m) do { \
+ sprint( b512, "%s (%s @ %d), %d: %s\n", \
+ __func__, __FILE__, __LINE__, n, # m ); \
+ kpanic( b512 ); \
+ } while(0)
/*
** Assertions are categorized by the "sanity level" being used in this
@@ -84,48 +76,30 @@
#ifndef SANITY
// default sanity check level: check everything!
-#define SANITY 9999
+#define SANITY 9999
#endif
// Always-active assertions
-#define assert(x) \
- if (!(x)) { \
- PANIC(0, x); \
- }
+#define assert(x) if( !(x) ) { PANIC(0,x); }
// only provide these macros if the sanity check level is positive
#if SANITY > 0
-#define assert1(x) \
- if (SANITY >= 1 && !(x)) { \
- PANIC(1, x); \
- }
-#define assert2(x) \
- if (SANITY >= 2 && !(x)) { \
- PANIC(2, x); \
- }
-#define assert3(x) \
- if (SANITY >= 3 && !(x)) { \
- PANIC(3, x); \
- }
-#define assert4(x) \
- if (SANITY >= 4 && !(x)) { \
- PANIC(4, x); \
- }
+#define assert1(x) if( SANITY >= 1 && !(x) ) { PANIC(1,x); }
+#define assert2(x) if( SANITY >= 2 && !(x) ) { PANIC(2,x); }
+#define assert3(x) if( SANITY >= 3 && !(x) ) { PANIC(3,x); }
+#define assert4(x) if( SANITY >= 4 && !(x) ) { PANIC(4,x); }
// arbitrary sanity level
-#define assertN(n, x) \
- if (SANITY >= (n) && !(x)) { \
- PANIC(n, x); \
- }
+#define assertN(n,x) if( SANITY >= (n) && !(x) ) { PANIC(n,x); }
#else
-#define assert1(x) // do nothing
-#define assert2(x) // do nothing
-#define assert3(x) // do nothing
-#define assert4(x) // do nothing
-#define assertN(n, x) // do nothing
+#define assert1(x) // do nothing
+#define assert2(x) // do nothing
+#define assert3(x) // do nothing
+#define assert4(x) // do nothing
+#define assertN(n,x) // do nothing
#endif /* SANITY > 0 */
@@ -169,185 +143,182 @@
// 2^0 bit
#ifdef T_PCB
-#define TRPCB 0x00000001
+#define TRPCB 0x00000001
#else
-#define TRPCB 0
+#define TRPCB 0
#endif
#ifdef T_VM
-#define TRVM 0x00000002
+#define TRVM 0x00000002
#else
-#define TRVM 0
+#define TRVM 0
#endif
#ifdef T_QUE
-#define TRQUEUE 0x00000004
+#define TRQUEUE 0x00000004
#else
-#define TRQUEUE 0
+#define TRQUEUE 0
#endif
#ifdef T_SCH
-#define TRSCHED 0x00000008
+#define TRSCHED 0x00000008
#else
-#define TRSCHED 0
+#define TRSCHED 0
#endif
// 2^4 bit
#ifdef T_DSP
-#define TRDISP 0x00000010
+#define TRDISP 0x00000010
#else
-#define TRDISP 0
+#define TRDISP 0
#endif
#ifdef T_SCALL
-#define TRSYSCALLS 0x00000020
+#define TRSYSCALLS 0x00000020
#else
-#define TRSYSCALLS 0
+#define TRSYSCALLS 0
#endif
#ifdef T_SRET
-#define TRSYSRETS 0x00000040
+#define TRSYSRETS 0x00000040
#else
-#define TRSYSRETS 0
+#define TRSYSRETS 0
#endif
#ifdef T_EXIT
-#define TREXIT 0x00000080
+#define TREXIT 0x00000080
#else
-#define TREXIT 0
+#define TREXIT 0
#endif
// 2^8 bit
#ifdef T_INIT
-#define TRINIT 0x00000100
+#define TRINIT 0x00000100
#else
-#define TRINIT 0
+#define TRINIT 0
#endif
#ifdef T_KM
-#define TRKMEM 0x00000200
+#define TRKMEM 0x00000200
#else
-#define TRKMEM 0
+#define TRKMEM 0
#endif
#ifdef T_KMFR
-#define TRKMEM_F 0x00000400
+#define TRKMEM_F 0x00000400
#else
-#define TRKMEM_F 0
+#define TRKMEM_F 0
#endif
#ifdef T_KMIN
-#define TRKMEM_I 0x00000800
+#define TRKMEM_I 0x00000800
#else
-#define TRKMEM_I 0
+#define TRKMEM_I 0
#endif
// 2^12 bit
#ifdef T_FORK
-#define TRFORK 0x00001000
+#define TRFORK 0x00001000
#else
-#define TRFORK 0
+#define TRFORK 0
#endif
#ifdef T_EXEC
-#define TREXEC 0x00002000
+#define TREXEC 0x00002000
#else
-#define TREXEC 0
+#define TREXEC 0
#endif
#ifdef T_SIO
-#define TRSIO_STAT 0x00004000
+#define TRSIO_STAT 0x00004000
#else
-#define TRSIO_STAT 0
+#define TRSIO_STAT 0
#endif
#ifdef T_SIOR
-#define TRSIO_RD 0x00008000
+#define TRSIO_RD 0x00008000
#else
-#define TRSIO_RD 0
+#define TRSIO_RD 0
#endif
// 2^16 bit
#ifdef T_SIOW
-#define TRSIO_WR 0x00010000
+#define TRSIO_WR 0x00010000
#else
-#define TRSIO_WR 0
+#define TRSIO_WR 0
#endif
#ifdef T_USER
-#define TRUSER 0x00020000
+#define TRUSER 0x00020000
#else
-#define TRUSER 0
+#define TRUSER 0
#endif
#ifdef T_ELF
-#define TRELF 0x00040000
+#define TRELF 0x00040000
#else
-#define TRELF 0
+#define TRELF 0
#endif
// 13 bits remaining for tracing options
// next available bit: 0x00080000
-#define TRACE \
- (TRDISP | TREXIT | TRINIT | TRKMEM | TRKMEM_F | TRKMEM_I | TRPCB | \
- TRQUEUE | TRSCHED | TREXEC | TRSIO_RD | TRSIO_STAT | TRSIO_WR | TRFORK | \
- TRVM | TRSYSCALLS | TRSYSRETS | TRUSER | TRELF)
+#define TRACE (TRDISP | TREXIT | TRINIT | TRKMEM | TRKMEM_F | TRKMEM_I | TRPCB | TRQUEUE | TRSCHED | TREXEC | TRSIO_RD | TRSIO_STAT | TRSIO_WR | TRFORK | TRVM | TRSYSCALLS | TRSYSRETS | TRUSER | TRELF)
#if TRACE > 0
// compile-time expressions for testing trace options
// usage: #if TRACING_thing
-#define TRACING_PCB ((TRACE & TRPCB) != 0)
-#define TRACING_VM ((TRACE & TRVM) != 0)
-#define TRACING_QUEUE ((TRACE & TRQUEUE) != 0)
-#define TRACING_SCHED ((TRACE & TRSCHED) != 0)
-#define TRACING_DISPATCH ((TRACE & TRDISPATCH) != 0)
-#define TRACING_SYSCALLS ((TRACE & TRSYSCALLS) != 0)
-#define TRACING_SYSRETS ((TRACE & TRSYSRETS) != 0)
-#define TRACING_EXIT ((TRACE & TREXIT) != 0)
-#define TRACING_INIT ((TRACE & TRINIT) != 0)
-#define TRACING_KMEM ((TRACE & TRKMEM) != 0)
-#define TRACING_KMEM_FREELIST ((TRACE & TRKMEM_F) != 0)
-#define TRACING_KMEM_INIT ((TRACE & TRKMEM_I) != 0)
-#define TRACING_FORK ((TRACE & TRFORK) != 0)
-#define TRACING_EXEC ((TRACE & TREXEC) != 0)
-#define TRACING_SIO_STAT ((TRACE & TRSIO_STAT) != 0)
-#define TRACING_SIO_ISR ((TRACE & TRSIO_ISR) != 0)
-#define TRACING_SIO_RD ((TRACE & TRSIO_RD) != 0)
-#define TRACING_SIO_WR ((TRACE & TRSIO_WR) != 0)
-#define TRACING_USER ((TRACE & TRUSER) != 0)
-#define TRACING_ELF ((TRACE & TRELF) != 0)
+#define TRACING_PCB ((TRACE & TRPCB) != 0)
+#define TRACING_VM ((TRACE & TRVM) != 0)
+#define TRACING_QUEUE ((TRACE & TRQUEUE) != 0)
+#define TRACING_SCHED ((TRACE & TRSCHED) != 0)
+#define TRACING_DISPATCH ((TRACE & TRDISPATCH) != 0)
+#define TRACING_SYSCALLS ((TRACE & TRSYSCALLS) != 0)
+#define TRACING_SYSRETS ((TRACE & TRSYSRETS) != 0)
+#define TRACING_EXIT ((TRACE & TREXIT) != 0)
+#define TRACING_INIT ((TRACE & TRINIT) != 0)
+#define TRACING_KMEM ((TRACE & TRKMEM) != 0)
+#define TRACING_KMEM_FREELIST ((TRACE & TRKMEM_F) != 0)
+#define TRACING_KMEM_INIT ((TRACE & TRKMEM_I) != 0)
+#define TRACING_FORK ((TRACE & TRFORK) != 0)
+#define TRACING_EXEC ((TRACE & TREXEC) != 0)
+#define TRACING_SIO_STAT ((TRACE & TRSIO_STAT) != 0)
+#define TRACING_SIO_ISR ((TRACE & TRSIO_ISR) != 0)
+#define TRACING_SIO_RD ((TRACE & TRSIO_RD) != 0)
+#define TRACING_SIO_WR ((TRACE & TRSIO_WR) != 0)
+#define TRACING_USER ((TRACE & TRUSER) != 0)
+#define TRACING_ELF ((TRACE & TRELF) != 0)
// more generic tests
-#define TRACING_SOMETHING (TRACE != 0)
+#define TRACING_SOMETHING (TRACE != 0)
#else
// TRACE == 0, so just define these all as "false"
-#define TRACING_PCB 0
-#define TRACING_STACK 0
-#define TRACING_QUEUE 0
-#define TRACING_SCHED 0
-#define TRACING_DISPATCH 0
-#define TRACING_SYSCALLS 0
-#define TRACING_SYSRET 0
-#define TRACING_EXIT 0
-#define TRACING_INIT 0
-#define TRACING_KMEM 0
-#define TRACING_KMEM_FREELIST 0
-#define TRACING_KMEM_INIT 0
-#define TRACING_FORK 0
-#define TRACING_EXEC 0
-#define TRACING_SI_STAT 0
-#define TRACING_SIO_ISR 0
-#define TRACING_SIO_RD 0
-#define TRACING_SIO_WR 0
-#define TRACING_USER 0
-#define TRACING_ELF 0
+#define TRACING_PCB 0
+#define TRACING_STACK 0
+#define TRACING_QUEUE 0
+#define TRACING_SCHED 0
+#define TRACING_DISPATCH 0
+#define TRACING_SYSCALLS 0
+#define TRACING_SYSRET 0
+#define TRACING_EXIT 0
+#define TRACING_INIT 0
+#define TRACING_KMEM 0
+#define TRACING_KMEM_FREELIST 0
+#define TRACING_KMEM_INIT 0
+#define TRACING_FORK 0
+#define TRACING_EXEC 0
+#define TRACING_SI_STAT 0
+#define TRACING_SIO_ISR 0
+#define TRACING_SIO_RD 0
+#define TRACING_SIO_WR 0
+#define TRACING_USER 0
+#define TRACING_ELF 0
-#define TRACING_SOMETHING 0
+#define TRACING_SOMETHING 0
#endif /* TRACE */
diff --git a/kernel/old/include/defs.h b/kernel/old/include/defs.h
index 018b14e..0280c47 100644
--- a/kernel/old/include/defs.h
+++ b/kernel/old/include/defs.h
@@ -29,21 +29,24 @@
// we define this the traditional way so that
// it's usable from both C and assembly
-#define NULL 0
+#define NULL 0
// predefined i/o channels
-#define CHAN_CIO 0
-#define CHAN_SIO 1
+#define CHAN_CIO 0
+#define CHAN_SIO 1
+
+// maximum allowable number of command-line arguments
+#define MAX_ARGS 10
// sizes of various things
-#define NUM_1KB 0x00000400 // 2^10
-#define NUM_4KB 0x00001000 // 2^12
-#define NUM_1MB 0x00100000 // 2^20
-#define NUM_4MB 0x00400000 // 2^22
-#define NUM_1GB 0x40000000 // 2^30
-#define NUM_2GB 0x80000000 // 2^31
-#define NUM_3GB 0xc0000000 // 1GB + 2GB
+#define NUM_1KB 0x00000400 // 2^10
+#define NUM_4KB 0x00001000 // 2^12
+#define NUM_1MB 0x00100000 // 2^20
+#define NUM_4MB 0x00400000 // 2^22
+#define NUM_1GB 0x40000000 // 2^30
+#define NUM_2GB 0x80000000 // 2^31
+#define NUM_3GB 0xc0000000
#ifndef ASM_SRC
@@ -60,63 +63,59 @@
** These can be returned to both system functions
** and to user system calls.
*/
-// success!
-#define SUCCESS (0)
-#define E_SUCCESS SUCCESS
-// generic "something went wrong"
-#define E_FAILURE (-1)
-// specific failure reasons
-#define E_BAD_PARAM (-2)
-#define E_BAD_CHAN (-3)
-#define E_NO_CHILDREN (-4)
-#define E_NO_MEMORY (-5)
-#define E_NOT_FOUND (-6)
-#define E_NO_PROCS (-7)
+ // success!
+#define SUCCESS (0)
+# define E_SUCCESS SUCCESS
+ // generic "something went wrong"
+#define E_FAILURE (-1)
+ // specific failure reasons
+#define E_BAD_PARAM (-2)
+#define E_BAD_CHAN (-3)
+#define E_NO_CHILDREN (-4)
+#define E_NO_MEMORY (-5)
+#define E_NOT_FOUND (-6)
+#define E_NO_PROCS (-7)
/*
** These error codes are internal to the OS.
*/
-#define E_EMPTY_QUEUE (-100)
-#define E_NO_PCBS (-101)
-#define E_NO_PTE (-102)
-#define E_LOAD_LIMIT (-103)
+#define E_EMPTY_QUEUE (-100)
+#define E_NO_PCBS (-101)
+#define E_NO_PTE (-102)
+#define E_LOAD_LIMIT (-103)
// exit status values
-#define EXIT_SUCCESS (0)
-#define EXIT_FAILURE (-1)
-#define EXIT_KILLED (-101)
-#define EXIT_BAD_SYSCALL (-102)
+#define EXIT_SUCCESS (0)
+#define EXIT_FAILURE (-1)
+#define EXIT_KILLED (-101)
+#define EXIT_BAD_SYSCALL (-102)
/*
** Process priority values
*/
enum priority_e {
- PRIO_HIGH,
- PRIO_STD,
- PRIO_LOW,
- PRIO_DEFERRED
+ PRIO_HIGH, PRIO_STD, PRIO_LOW, PRIO_DEFERRED
// sentinel
- ,
- N_PRIOS
+ , N_PRIOS
};
// halves of various data sizes
-#define UI16_UPPER 0xff00
-#define UI16_LOWER 0x00ff
+#define UI16_UPPER 0xff00
+#define UI16_LOWER 0x00ff
-#define UI32_UPPER 0xffff0000
-#define UI32_LOWER 0x0000ffff
+#define UI32_UPPER 0xffff0000
+#define UI32_LOWER 0x0000ffff
-#define UI64_UPPER 0xffffffff00000000LL
-#define UI64_LOWER 0x00000000ffffffffLL
+#define UI64_UPPER 0xffffffff00000000LL
+#define UI64_LOWER 0x00000000ffffffffLL
// Simple conversion pseudo-functions usable by everyone
// convert seconds to ms
-#define SEC_TO_MS(n) ((n) * 1000)
+#define SEC_TO_MS(n) ((n) * 1000)
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
/*
** Level-specific definitions
@@ -125,6 +124,6 @@ enum priority_e {
#include <kdefs.h>
#else
#include <udefs.h>
-#endif /* KERNEL_SRC */
+#endif /* KERNEL_SRC */
#endif
diff --git a/kernel/old/include/elf.h b/kernel/old/include/elf.h
new file mode 100644
index 0000000..a43e5c3
--- /dev/null
+++ b/kernel/old/include/elf.h
@@ -0,0 +1,235 @@
+/**
+** @file elf.h
+**
+** @author Warren R. Carithers
+**
+** @brief ELF format declarations
+*/
+
+#ifndef ELF_H_
+#define ELF_H_
+
+#include <common.h>
+
+#ifndef ASM_SRC
+
+/*
+** Start of C-only definitions
+*/
+
+// ELF data types (TIS ELF Spec v1.2, May 1995
+typedef uint32_t e32_a; // 32-bit unsigned address
+typedef uint16_t e32_h; // 16-bit unsigned "medium" integer
+typedef uint32_t e32_o; // 32-bit unsigned offset
+typedef int32_t e32_sw; // 32-bit signed "large" integer
+typedef uint32_t e32_w; // 32-bit unsigned "large" integer
+typedef uint8_t e32_si; // 8-bit unsigned "small" integer
+
+// ELF magic number - first four bytes
+#define ELF_MAGIC 0x464C457FU // "\x7FELF" in little-endian order
+#define EI_NIDENT 16
+
+union elfident_u {
+ uint8_t bytes[EI_NIDENT]; // array of 16 bytes
+ struct {
+ uint32_t magic; // magic number
+ uint8_t class; // file class
+ uint8_t data; // data encoding
+ uint8_t version; // file version
+ uint8_t osabi; // OS ABI identification
+ uint8_t abivers; // ABI version
+ uint8_t pad[7]; // padding to 16 bytes
+ } f;
+};
+
+// indices for byte fields in the ident array
+#define EI_MAGIC 0
+# define EI_MAG0 EI_MAGIC
+# 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
+
+// ELF classes
+#define ELF_CLASS_NONE 0
+#define ELF_CLASS_32 1 // 32-bit objects
+#define ELF_CLASS_64 2 // 64-bit objects
+
+// ELF data encoding
+#define ELF_DATA_NONE 0 // invalid data encoding
+#define ELF_DATA_2LSB 1 // two's complement little-endian
+#define ELF_DATA_2MSB 2 // two's complement big-endian
+
+// ELF versions
+#define ELF_VERSION__NONE 0 // invalid version
+# define EV_NONE ELF_VERSION_NONE
+#define ELF_VERSION__CURRENT 1 // current version
+# define EV_CURRENT ELF_VERSION_CURRENT
+
+// ELF header
+//
+// field names are from the TIS ELF Spec v1.2, May 1995
+typedef struct elfhdr_s {
+ union elfident_u e_ident; // file identification
+ e32_h e_type; // file type
+ e32_h e_machine; // required architecture
+ e32_w e_version; // object file version
+ e32_a e_entry; // entry point (VA)
+ e32_o e_phoff; // offset to program header table (PHT)
+ e32_o e_shoff; // offset to section header table (SHT)
+ e32_w e_flags; // processor-specific flags
+ e32_h e_ehsize; // ELF header size (bytes)
+ e32_h e_phentsize; // size of one PHT entry (bytes)
+ e32_h e_phnum; // number of PHT entries
+ e32_h e_shentsize; // size of one SHT entry (bytes)
+ e32_h e_shnum; // number of SHT entries
+ e32_h e_shstrndx; // SHT index of the sect. name string table
+} elfhdr_t;
+
+#define SZ_ELFHDR sizeof(elfhdr_t)
+
+// field values
+// e_type
+#define ET_NONE 0 // no file type
+#define ET_REL 1 // relocatable file
+#define ET_EXEC 2 // executable file
+#define ET_DYN 3 // shared object file
+#define ET_CORE 4 // core file
+#define ET_LO_OS 0xfe00 // processor-specific
+#define ET_HI_OS 0xfeff // processor-specific
+#define ET_LO_CP 0xff00 // processor-specific
+#define ET_HI_CP 0xffff // processor-specific
+
+// e_machine
+#define EM_NONE 0x00 // no machine type
+#define EM_M32 0x01 // AT&T WE 32100
+#define EM_SPARC 0x02 // SUN SPARC
+#define EM_386 0x03 // Intel Architecture
+#define EM_68K 0x04 // Motorola 68000
+#define EM_88K 0x05 // Motorola 88000
+#define EM_IAMCU 0x06 // Intel MCU
+#define EM_860 0x07 // Intel 80860
+#define EM_MIPS 0x08 // MIPS RS3000 Big-Endian
+#define EM_S370 0x09 // IBM System/370
+#define EM_MIPS_RS3_LE 0x0a // MIPS RS3000 Big-Endian
+#define EM_SPARC32PLLUS 0x12 // Sun "v8plus"
+#define EM_PPC 0x14 // IBM PowerPC
+#define EM_PPC64 0x15 // IBM PowerPC 64-bit
+#define EM_S390 0x16 // IBM System/390
+#define EM_ARM 0x28 // ARM up to V7/AArch32
+#define EM_SPARCV9 0x2b // SPARC V9 64-bit
+#define EM_IA_64 0x32 // Intel Itanium (Merced)
+#define EM_MIPS_X 0x32 // Stanford MIPS-X
+#define EM_X86_64 0x3E // AMD x86-64 (Intel64)
+#define EM_PDP11 0x40 // DEC PDP-11
+#define EM_VAX 0x4b // DEC VAX
+#define EM_AARCH64 0xb7 // ARM AArch64
+#define EM_Z80 0xec // Zilog Z-80
+#define EM_AMDGPU 0xf0 // AMD GPU
+#define EM_RISCV 0xf3 // RISC-V
+#define EM_BPF 0xf7 // Berkeley Packet Filter
+
+// ELF section header
+//
+// field names are from the TIS ELF Spec v1.2, May 1995
+typedef struct shdr_s {
+ e32_w sh_name; // section name (index into string table)
+ e32_w sh_type; // section contents/semantics
+ e32_w sh_flags; // attribute flag bits
+ e32_a sh_addr; // 0, or load point of this section in memory
+ e32_o sh_offset; // byte offset within the file
+ e32_w sh_size; // section size in bytes
+ e32_w sh_link; // section header index table link
+ e32_w sh_info; // "extra information"
+ e32_w sh_addralign; // required alignment
+ e32_w sh_entsize; // 0, or size of each entry in the section
+} elfsecthdr_t;
+
+#define SZ_ELFSECTHDR sizeof(elfsecthdr_t)
+
+// sh_name
+#define SHN_UNDEF 0
+
+// sh_type
+#define SHT_NULL 0x00
+#define SHT_PROGBITS 0x01
+#define SHT_SYMTAB 0x02
+#define SHT_STRTAB 0x03
+#define SHT_RELA 0x04
+#define SHT_HASH 0x05
+#define SHT_DYNAMIC 0x06
+#define SHT_NOTE 0x07
+#define SHT_NOBITS 0x08
+#define SHT_REL 0x09
+#define SHT_SHLIB 0x0a
+#define SHT_DYNSYM 0x0b
+#define SHT_LO_CP 0x70000000
+#define SHT_HI_CP 0x7fffffff
+#define SHT_LO_US 0x80000000
+#define SHT_HI_US 0x8fffffff
+
+// sh_flags
+#define SHF_WRITE 0x001
+#define SHF_ALLOC 0x002
+#define SHF_EXECINSTR 0x004
+#define SHF_MERGE 0x010
+#define SHF_STRINGS 0x020
+#define SHF_INFO_LINK 0x040
+#define SHF_LINK_ORDER 0x080
+#define SHF_OS_NONCON 0x100
+#define SHF_GROUP 0x200
+#define SHF_TLS 0x400
+#define SHF_MASKOS 0x0ff00000
+#define SHF_MASKPROC 0xf0000000
+
+// ELF program header
+//
+// field names are from the TIS ELF Spec v1.2, May 1995
+typedef struct phdr_s {
+ e32_w p_type; // type of segment
+ e32_o p_offset; // byte offset in file
+ e32_a p_va; // load point in memory (virtual address)
+ e32_a p_pa; // load point in memory (physical address)
+ e32_w p_filesz; // number of bytes in this file
+ e32_w p_memsz; // number of bytes in memory
+ e32_w p_flags; // attribute flag bits
+ e32_w p_align; // required alignment
+} elfproghdr_t;
+
+#define SZ_ELFPROGHDR sizeof(elfproghdr_t)
+
+// p_type
+#define PT_NULL 0
+#define PT_LOAD 1
+#define PT_DYNAMIC 2
+#define PT_INTERP 3
+#define PT_NOTE 4
+#define PT_SHLIB 5
+#define PT_PHDR 6
+#define PT_TLS 7
+#define PT_LO_OS 0x70000000
+#define PT_HI_OS 0x7fffffff
+#define PT_LO_CP 0x70000000
+#define PT_HI_CP 0x7fffffff
+
+// p_flags
+#define PF_E 0x1
+#define PF_W 0x2
+#define PF_R 0x4
+#define PF_MASKPROC 0xf0000000
+
+/*
+** Globals
+*/
+
+/*
+** Prototypes
+*/
+
+#endif /* !ASM_SRC */
+
+#endif
diff --git a/kernel/old/include/kdefs.h b/kernel/old/include/kdefs.h
index d26fa3d..794516b 100644
--- a/kernel/old/include/kdefs.h
+++ b/kernel/old/include/kdefs.h
@@ -17,58 +17,53 @@
*/
// page sizes
-#define SZ_PAGE NUM_4KB
-#define SZ_BIGPAGE NUM_4MB
+#define SZ_PAGE NUM_4KB
+#define SZ_BIGPAGE NUM_4MB
// kernel stack size (bytes)
-#define N_KSTKPAGES 1
-#define SZ_KSTACK (N_KSTKPAGES * SZ_PAGE)
+#define N_KSTKPAGES 1
+#define SZ_KSTACK (N_KSTKPAGES * SZ_PAGE)
// user stack size
-#define N_USTKPAGES 2
-#define SZ_USTACK (N_USTKPAGES * SZ_PAGE)
+#define N_USTKPAGES 2
+#define SZ_USTACK (N_USTKPAGES * SZ_PAGE)
// declarations for modulus checking of (e.g.) sizes and addresses
-#define LOW_9_BITS 0x00000fff
-#define LOW_22_BITS 0x003fffff
-#define HIGH_20_BITS 0xfffff000
-#define HIGH_10_BITS 0xffc00000
+#define MOD4_BITS 0x00000003
+#define MOD4_MASK 0xfffffffc
+#define MOD4_INC 0x00000004
+#define MOD4_SHIFT 2
-#define MOD4_BITS 0x00000003
-#define MOD4_MASK 0xfffffffc
-#define MOD4_INC 0x00000004
-#define MOD4_SHIFT 2
+#define MOD16_BITS 0x0000000f
+#define MOD16_MASK 0xfffffff0
+#define MOD16_INC 0x00000010
+#define MOD16_SHIFT 4
-#define MOD16_BITS 0x0000000f
-#define MOD16_MASK 0xfffffff0
-#define MOD16_INC 0x00000010
-#define MOD16_SHIFT 4
+#define MOD1K_BITS 0x000003ff
+#define MOD1K_MASK 0xfffffc00
+#define MOD1K_INC 0x00000400
+#define MOD1K_SHIFT 10
-#define MOD1K_BITS 0x000003ff
-#define MOD1K_MASK 0xfffffc00
-#define MOD1K_INC 0x00000400
-#define MOD1K_SHIFT 10
+#define MOD4K_BITS 0x00000fff
+#define MOD4K_MASK 0xfffff000
+#define MOD4K_INC 0x00001000
+#define MOD4K_SHIFT 12
-#define MOD4K_BITS 0x00000fff
-#define MOD4K_MASK 0xfffff000
-#define MOD4K_INC 0x00001000
-#define MOD4K_SHIFT 12
+#define MOD1M_BITS 0x000fffff
+#define MOD1M_MASK 0xfff00000
+#define MOD1M_INC 0x00100000
+#define MOD1M_SHIFT 20
-#define MOD1M_BITS 0x000fffff
-#define MOD1M_MASK 0xfff00000
-#define MOD1M_INC 0x00100000
-#define MOD1M_SHIFT 20
+#define MOD4M_BITS 0x003fffff
+#define MOD4M_MASK 0xffc00000
+#define MOD4M_INC 0x00400000
+#define MOD4M_SHIFT 22
-#define MOD4M_BITS 0x003fffff
-#define MOD4M_MASK 0xffc00000
-#define MOD4M_INC 0x00400000
-#define MOD4M_SHIFT 22
-
-#define MOD1G_BITS 0x3fffffff
-#define MOD1G_MASK 0xc0000000
-#define MOD1G_INC 0x40000000
-#define MOD1G_SHIFT 30
+#define MOD1G_BITS 0x3fffffff
+#define MOD1G_MASK 0xc0000000
+#define MOD1G_INC 0x40000000
+#define MOD1G_SHIFT 30
#ifndef ASM_SRC
@@ -77,26 +72,26 @@
*/
// unit conversion macros
-#define B_TO_KB(x) (((uint_t)(x)) >> 10)
-#define B_TO_MB(x) (((uint_t)(x)) >> 20)
-#define B_TO_GB(x) (((uint_t)(x)) >> 30)
+#define B_TO_KB(x) (((uint_t)(x))>>10)
+#define B_TO_MB(x) (((uint_t)(x))>>20)
+#define B_TO_GB(x) (((uint_t)(x))>>30)
-#define KB_TO_B(x) (((uint_t)(x)) << 10)
-#define KB_TO_MB(x) (((uint_t)(x)) >> 10)
-#define KB_TO_GB(x) (((uint_t)(x)) >> 20)
+#define KB_TO_B(x) (((uint_t)(x))<<10)
+#define KB_TO_MB(x) (((uint_t)(x))>>10)
+#define KB_TO_GB(x) (((uint_t)(x))>>20)
-#define MB_TO_B(x) (((uint_t)(x)) << 20)
-#define MB_TO_KB(x) (((uint_t)(x)) << 10)
-#define MB_TO_GB(x) (((uint_t)(x)) >> 10)
+#define MB_TO_B(x) (((uint_t)(x))<<20)
+#define MB_TO_KB(x) (((uint_t)(x))<<10)
+#define MB_TO_GB(x) (((uint_t)(x))>>10)
-#define GB_TO_B(x) (((uint_t)(x)) << 30)
-#define GB_TO_KB(x) (((uint_t)(x)) << 20)
-#define GB_TO_MB(x) (((uint_t)(x)) << 10)
+#define GB_TO_B(x) (((uint_t)(x))<<30)
+#define GB_TO_KB(x) (((uint_t)(x))<<20)
+#define GB_TO_MB(x) (((uint_t)(x))<<10)
// potetially useful compiler attributes
#define ATTR_ALIGNED(x) __attribute__((__aligned__(x)))
-#define ATTR_PACKED __attribute__((__packed__))
-#define ATTR_UNUSED __attribute__((__unused__))
+#define ATTR_PACKED __attribute__((__packed__))
+#define ATTR_UNUSED __attribute__((__unused__))
/*
** Utility macros
@@ -107,18 +102,18 @@
//
// these are usable for clearing single-valued data items (e.g.,
// a PCB, etc.)
-#define CLEAR(v) memclr(&v, sizeof(v))
-#define CLEAR_PTR(p) memclr(p, sizeof(*p))
+#define CLEAR(v) memclr( &v, sizeof(v) )
+#define CLEAR_PTR(p) memclr( p, sizeof(*p) )
//
// macros for access registers and system call arguments
//
// REG(pcb,x) -- access a specific register in a process context
-#define REG(pcb, x) ((pcb)->context->x)
+#define REG(pcb,x) ((pcb)->context->x)
// RET(pcb) -- access return value register in a process context
-#define RET(pcb) ((pcb)->context->eax)
+#define RET(pcb) ((pcb)->context->eax)
// ARG(pcb,n) -- access argument #n from the indicated process
//
@@ -129,7 +124,7 @@
//
// ASSUMES THE STANDARD 32-BIT ABI, WITH PARAMETERS PUSHED ONTO THE
// STACK. IF THE PARAMETER PASSING MECHANISM CHANGES, SO MUST THIS!
-#define ARG(pcb, n) (((uint32_t *)(((pcb)->context) + 1))[(n)])
+#define ARG(pcb,n) ( ( (uint32_t *) (((pcb)->context) + 1) ) [(n)] )
/*
** Types
@@ -152,6 +147,6 @@ extern uint8_t kstack[SZ_KSTACK];
** Prototypes
*/
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/klib.h b/kernel/old/include/klib.h
index 60f59da..c1d270c 100644
--- a/kernel/old/include/klib.h
+++ b/kernel/old/include/klib.h
@@ -24,7 +24,7 @@
**
** @param ch The character to be printed
*/
-void put_char_or_code(int ch);
+void put_char_or_code( int ch );
/**
** Name: backtrace
@@ -35,7 +35,7 @@ void put_char_or_code(int ch);
** @param ebp Initial EBP to use
** @param args Number of function argument values to print
*/
-void backtrace(uint32_t *ebp, uint_t args);
+void backtrace( uint32_t *ebp, uint_t args );
/**
** Name: kpanic
@@ -50,8 +50,8 @@ void backtrace(uint32_t *ebp, uint_t args);
** @param msg[in] String containing a relevant message to be printed,
** or NULL
*/
-void kpanic(const char *msg);
+void kpanic( const char *msg );
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/kmem.h b/kernel/old/include/kmem.h
index 631f7ab..5a98765 100644
--- a/kernel/old/include/kmem.h
+++ b/kernel/old/include/kmem.h
@@ -28,8 +28,8 @@
// Slab and slice sizes, in bytes
-#define SZ_SLAB SZ_PAGE
-#define SZ_SLICE (SZ_SLAB >> 2)
+#define SZ_SLAB SZ_PAGE
+#define SZ_SLICE (SZ_SLAB >> 2)
// memory limits
//
@@ -37,8 +37,8 @@
// module will manage
//
// we won't map any memory below 1MB or above 1GB
-#define KM_LOW_CUTOFF NUM_1MB
-#define KM_HIGH_CUTOFF NUM_1GB
+#define KM_LOW_CUTOFF NUM_1MB
+#define KM_HIGH_CUTOFF NUM_1GB
#ifndef ASM_SRC
@@ -68,7 +68,7 @@
** Must be called before any other init routine that uses
** dynamic storage is called.
*/
-void km_init(void);
+void km_init( void );
/**
** Name: km_dump
@@ -81,7 +81,7 @@ void km_init(void);
** @param addrs Also dump page addresses
** @param both Also dump slice addresses
*/
-void km_dump(bool_t addrs, bool_t both);
+void km_dump( bool_t addrs, bool_t both );
/*
** Functions that manipulate free memory blocks.
@@ -95,7 +95,7 @@ void km_dump(bool_t addrs, bool_t both);
** @return a pointer to the beginning of the allocated page,
** or NULL if no memory is available
*/
-void *km_page_alloc(void);
+void *km_page_alloc( void );
/**
** Name: km_page_free
@@ -108,7 +108,7 @@ void *km_page_alloc(void);
**
** @param[in] block Pointer to the page to be returned to the free list
*/
-void km_page_free(void *block);
+void km_page_free( void *block );
/**
** Name: km_slice_alloc
@@ -119,7 +119,7 @@ void km_page_free(void *block);
**
** @return a pointer to the allocated slice
*/
-void *km_slice_alloc(void);
+void *km_slice_alloc( void );
/**
** Name: km_slice_free
@@ -131,7 +131,7 @@ void *km_slice_alloc(void);
**
** @param[in] block Pointer to the slice (1/4 page) to be freed
*/
-void km_slice_free(void *block);
+void km_slice_free( void *block );
#endif /* !ASM_SRC */
diff --git a/kernel/old/include/lib.h b/kernel/old/include/lib.h
new file mode 100644
index 0000000..bde0554
--- /dev/null
+++ b/kernel/old/include/lib.h
@@ -0,0 +1,314 @@
+/**
+** @file lib.h
+**
+** @author Numerous CSCI-452 classes
+**
+** @brief C declarations of common library functions
+**
+** These are callable from either kernel or user code. Care should be taken
+** that user code is linked against these separately from kernel code, to
+** ensure separation of the address spaces.
+*/
+
+#ifndef LIB_H_
+#define LIB_H_
+
+#ifndef ASM_SRC
+
+#include <common.h>
+
+/*
+**********************************************
+** MEMORY MANIPULATION FUNCTIONS
+**********************************************
+*/
+
+/**
+** blkmov(dst,src,len)
+**
+** Copy a word-aligned block from src to dst. Deals with overlapping
+** buffers.
+**
+** If the buffer addresses aren't word-aligned or the length is not a
+** multiple of four, calls memmove().
+**
+** @param dst Destination buffer
+** @param src Source buffer
+** @param len Buffer size (in bytes)
+*/
+void blkmov( void *dst, const void *src, register uint32_t len );
+
+/**
+** memset(buf,len,value)
+**
+** initialize all bytes of a block of memory to a specific value
+**
+** @param buf The buffer to initialize
+** @param len Buffer size (in bytes)
+** @param value Initialization value
+*/
+void memset( void *buf, register uint32_t len, register uint32_t value );
+
+/**
+** memclr(buf,len)
+**
+** Initialize all bytes of a block of memory to zero
+**
+** @param buf The buffer to initialize
+** @param len Buffer size (in bytes)
+*/
+void memclr( void *buf, register uint32_t len );
+
+/**
+** memcpy(dst,src,len)
+**
+** Copy a block from one place to another
+**
+** May not correctly deal with overlapping buffers
+**
+** @param dst Destination buffer
+** @param src Source buffer
+** @param len Buffer size (in bytes)
+*/
+void memcpy( void *dst, register const void *src, register uint32_t len );
+
+/**
+** memmove(dst,src,len)
+**
+** Copy a block from one place to another. Deals with overlapping
+** buffers
+**
+** @param dst Destination buffer
+** @param src Source buffer
+** @param len Buffer size (in bytes)
+*/
+void memmove( void *dst, register const void *src, register uint32_t len );
+
+/*
+**********************************************
+** STRING MANIPULATION FUNCTIONS
+**********************************************
+*/
+
+/**
+** str2int(str,base) - convert a string to a number in the specified base
+**
+** @param str The string to examine
+** @param base The radix to use in the conversion
+**
+** @return The converted integer
+*/
+int str2int( register const char *str, register int base );
+
+/**
+** strlen(str) - return length of a NUL-terminated string
+**
+** @param str The string to examine
+**
+** @return The length of the string, or 0
+*/
+uint32_t strlen( register const char *str );
+
+/**
+** strcmp(s1,s2) - compare two NUL-terminated strings
+**
+** @param s1 The first source string
+** @param s2 The second source string
+**
+** @return negative if s1 < s2, zero if equal, and positive if s1 > s2
+*/
+int strcmp( register const char *s1, register const char *s2 );
+
+/**
+** strcpy(dst,src) - copy a NUL-terminated string
+**
+** @param dst The destination buffer
+** @param src The source buffer
+**
+** @return The dst parameter
+**
+** NOTE: assumes dst is large enough to hold the copied string
+*/
+char *strcpy( register char *dst, register const char *src );
+
+/**
+** strcat(dst,src) - append one string to another
+**
+** @param dst The destination buffer
+** @param src The source buffer
+**
+** @return The dst parameter
+**
+** NOTE: assumes dst is large enough to hold the resulting string
+*/
+char *strcat( register char *dst, register const char *src );
+
+/**
+** pad(dst,extra,padchar) - generate a padding string
+**
+** @param dst Pointer to where the padding should begin
+** @param extra How many padding bytes to add
+** @param padchar What character to pad with
+**
+** @return Pointer to the first byte after the padding
+**
+** NOTE: does NOT NUL-terminate the buffer
+*/
+char *pad( char *dst, int extra, int padchar );
+
+/**
+** padstr(dst,str,len,width,leftadjust,padchar - add padding characters
+** to a string
+**
+** @param dst The destination buffer
+** @param str The string to be padded
+** @param len The string length, or -1
+** @param width The desired final length of the string
+** @param leftadjust Should the string be left-justified?
+** @param padchar What character to pad with
+**
+** @return Pointer to the first byte after the padded string
+**
+** NOTE: does NOT NUL-terminate the buffer
+*/
+char *padstr( char *dst, char *str, int len, int width,
+ int leftadjust, int padchar );
+
+/**
+** sprint(dst,fmt,...) - formatted output into a string buffer
+**
+** @param dst The string buffer
+** @param fmt Format string
+**
+** The format string parameter is followed by zero or more additional
+** parameters which are interpreted according to the format string.
+**
+** NOTE: assumes the buffer is large enough to hold the result string
+**
+** NOTE: relies heavily on the x86 parameter passing convention
+** (parameters are pushed onto the stack in reverse order as
+** 32-bit values).
+*/
+void sprint( char *dst, char *fmt, ... );
+
+/*
+**********************************************
+** CONVERSION FUNCTIONS
+**********************************************
+*/
+
+/**
+** cvtuns0(buf,value) - local support routine for cvtuns()
+**
+** Convert a 32-bit unsigned value into a NUL-terminated character string
+**
+** @param buf Result buffer
+** @param value Value to be converted
+**
+** @return Pointer to the first unused byte in the buffer
+**
+** NOTE: assumes buf is large enough to hold the resulting string
+*/
+char *cvtuns0( char *buf, uint32_t value );
+
+/**
+** cvtuns(buf,value)
+**
+** Convert a 32-bit unsigned value into a NUL-terminated character string
+**
+** @param buf Result buffer
+** @param value Value to be converted
+**
+** @return Length of the resulting buffer
+**
+** NOTE: assumes buf is large enough to hold the resulting string
+*/
+int cvtuns( char *buf, uint32_t value );
+
+/**
+** cvtdec0(buf,value) - local support routine for cvtdec()
+**
+** convert a 32-bit unsigned integer into a NUL-terminated character string
+**
+** @param buf Destination buffer
+** @param value Value to convert
+**
+** @return The number of characters placed into the buffer
+** (not including the NUL)
+**
+** NOTE: assumes buf is large enough to hold the resulting string
+*/
+char *cvtdec0( char *buf, int value );
+
+/**
+** cvtdec(buf,value)
+**
+** convert a 32-bit signed value into a NUL-terminated character string
+**
+** @param buf Destination buffer
+** @param value Value to convert
+**
+** @return The number of characters placed into the buffer
+** (not including the NUL)
+**
+** NOTE: assumes buf is large enough to hold the resulting string
+*/
+int cvtdec( char *buf, int32_t value );
+
+/**
+** cvthex(buf,value)
+**
+** convert a 32-bit unsigned value into a mininal-length (up to
+** 8-character) NUL-terminated character string
+**
+** @param buf Destination buffer
+** @param value Value to convert
+**
+** @return The number of characters placed into the buffer
+** (not including the NUL)
+**
+** NOTE: assumes buf is large enough to hold the resulting string
+*/
+int cvthex( char *buf, uint32_t value );
+
+/**
+** cvtoct(buf,value)
+**
+** convert a 32-bit unsigned value into a mininal-length (up to
+** 11-character) NUL-terminated character string
+**
+** @param buf Destination buffer
+** @param value Value to convert
+**
+** @return The number of characters placed into the buffer
+** (not including the NUL)
+**
+** NOTE: assumes buf is large enough to hold the resulting string
+*/
+int cvtoct( char *buf, uint32_t value );
+
+/**
+** bound(min,value,max)
+**
+** This function confines an argument within specified bounds.
+**
+** @param min Lower bound
+** @param value Value to be constrained
+** @param max Upper bound
+**
+** @return The constrained value
+*/
+uint32_t bound( uint32_t min, uint32_t value, uint32_t max );
+
+#endif /* !ASM_SRC */
+
+/*
+** Finally, pull in the level-specific library headers
+*/
+#ifdef KERNEL_SRC
+#include <klib.h>
+#else
+#include <ulib.h>
+#endif /* KERNEL_SRC */
+
+#endif
diff --git a/kernel/old/include/list.h b/kernel/old/include/list.h
index 0be11e9..28c2377 100644
--- a/kernel/old/include/list.h
+++ b/kernel/old/include/list.h
@@ -35,7 +35,7 @@
// The list structure
typedef struct list_s {
- struct list_s *next; // link to the successor
+ struct list_s *next; // link to the successor
} list_t;
/*
@@ -50,7 +50,7 @@ typedef struct list_s {
** @param[in,out] list The address of a list_t variable
** @param[in] data The data to prepend to the list
*/
-void list_add(list_t *list, void *data);
+void list_add( list_t *list, void *data );
/**
** Name: list_remove
@@ -61,7 +61,7 @@ void list_add(list_t *list, void *data);
**
** @return a pointer to the removed data, or NULL if the list was empty
*/
-void *list_remove(list_t *list);
+void *list_remove( list_t *list );
#endif /* !ASM_SRC */
diff --git a/kernel/old/include/offsets.h b/kernel/old/include/offsets.h
deleted file mode 100644
index bf19776..0000000
--- a/kernel/old/include/offsets.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
-** @file offsets.h
-**
-** GENERATED AUTOMATICALLY - DO NOT EDIT
-**
-** This header file contains C Preprocessor macros which expand
-** into the byte offsets needed to reach fields within structs
-** used in the baseline system. Should those struct declarations
-** change, the Offsets program should be modified (if needed),
-** recompiled, and re-run to recreate this file.
-*/
-
-#ifndef OFFSETS_H_
-#define OFFSETS_H_
-
-// Sizes of basic types
-
-#define SZ_char 1
-#define SZ_short 2
-#define SZ_int 4
-#define SZ_long 4
-#define SZ_long_long 8
-#define SZ_pointer 4
-
-// Sizes of our types
-
-#define SZ_int8_t 1
-#define SZ_uint8_t 1
-#define SZ_int16_t 2
-#define SZ_uint16_t 2
-#define SZ_int32_t 4
-#define SZ_uint32_t 4
-#define SZ_int64_t 8
-#define SZ_uint64_t 8
-#define SZ_bool_t 1
-
-// context_t structure
-
-#define SZ_CTX 72
-
-#define CTX_ss 0
-#define CTX_gs 4
-#define CTX_fs 8
-#define CTX_es 12
-#define CTX_ds 16
-#define CTX_edi 20
-#define CTX_esi 24
-#define CTX_ebp 28
-#define CTX_esp 32
-#define CTX_ebx 36
-#define CTX_edx 40
-#define CTX_ecx 44
-#define CTX_eax 48
-#define CTX_vector 52
-#define CTX_code 56
-#define CTX_eip 60
-#define CTX_cs 64
-#define CTX_eflags 68
-
-// section_t structure
-
-#define SZ_SCT 8
-
-#define SCT_length 0
-#define SCT_addr 4
-
-// pcb_t structure
-
-#define SZ_PCB 72
-
-#define PCB_context 0
-#define PCB_pdir 4
-#define PCB_sects 8
-#define PCB_next 40
-#define PCB_parent 44
-#define PCB_wakeup 48
-#define PCB_exit_status 52
-#define PCB_pid 56
-#define PCB_state 60
-#define PCB_priority 64
-#define PCB_ticks 68
-
-#endif
diff --git a/kernel/old/include/params.h b/kernel/old/include/params.h
index 7a41e02..52eb81d 100644
--- a/kernel/old/include/params.h
+++ b/kernel/old/include/params.h
@@ -20,14 +20,12 @@
// Upper bound on the number of simultaneous user-level
// processes in the system (completely arbitrary)
-#define N_PROCS 25
-// Limit on the number of entries in argv[], INCLUDING
-// the trailing NULL pointer (also completely arbitrary)
-#define N_ARGS 10
+#define N_PROCS 25
// Clock frequency (Hz)
-#define CLOCK_FREQ 1000
-#define TICKS_PER_MS 1
+
+#define CLOCK_FREQ 1000
+#define TICKS_PER_MS 1
#endif
diff --git a/kernel/old/include/procs.h b/kernel/old/include/procs.h
index bc5b705..9db4ac8 100644
--- a/kernel/old/include/procs.h
+++ b/kernel/old/include/procs.h
@@ -30,28 +30,22 @@
*/
enum state_e {
// pre-viable
- STATE_UNUSED = 0,
- STATE_NEW,
+ STATE_UNUSED = 0, STATE_NEW,
// runnable
- STATE_READY,
- STATE_RUNNING,
+ STATE_READY, STATE_RUNNING,
// runnable, but waiting for some event
- STATE_SLEEPING,
- STATE_BLOCKED,
- STATE_WAITING,
+ STATE_SLEEPING, STATE_BLOCKED, STATE_WAITING,
// no longer runnable
- STATE_KILLED,
- STATE_ZOMBIE
+ STATE_KILLED, STATE_ZOMBIE
// sentinel value
- ,
- N_STATES
+ , N_STATES
};
// these may be handy for checking general conditions of processes
// they depend on the order of the state names in the enum!
-#define FIRST_VIABLE STATE_READY
-#define FIRST_BLOCKED STATE_SLEEPING
-#define LAST_VIABLE STATE_WAITING
+#define FIRST_VIABLE STATE_READY
+#define FIRST_BLOCKED STATE_SLEEPING
+#define LAST_VIABLE STATE_WAITING
/*
** Process priorities are defined in <defs.h>
@@ -60,13 +54,17 @@ enum state_e {
/*
** Quantum lengths - values are number of clock ticks
*/
-enum quantum_e { QUANTUM_SHORT = 1, QUANTUM_STANDARD = 3, QUANTUM_LONG = 5 };
+enum quantum_e {
+ QUANTUM_SHORT = 1,
+ QUANTUM_STANDARD = 3,
+ QUANTUM_LONG = 5
+};
/*
** PID-related definitions
*/
-#define PID_INIT 1
-#define FIRST_USER_PID 2
+#define PID_INIT 1
+#define FIRST_USER_PID 2
/*
** Process context structure
@@ -80,7 +78,7 @@ enum quantum_e { QUANTUM_SHORT = 1, QUANTUM_STANDARD = 3, QUANTUM_LONG = 5 };
*/
typedef struct context_s {
- uint32_t ss; // pushed by isr_save
+ uint32_t ss; // pushed by isr_save
uint32_t gs;
uint32_t fs;
uint32_t es;
@@ -94,34 +92,34 @@ typedef struct context_s {
uint32_t ecx;
uint32_t eax;
uint32_t vector;
- uint32_t code; // pushed by isr_save or the hardware
- uint32_t eip; // pushed by the hardware
+ uint32_t code; // pushed by isr_save or the hardware
+ uint32_t eip; // pushed by the hardware
uint32_t cs;
uint32_t eflags;
} context_t;
-#define SZ_CONTEXT sizeof(context_t)
+#define SZ_CONTEXT sizeof(context_t)
/*
** program section information for user processes
*/
typedef struct section_s {
- uint_t length; // length, in some units
- uint_t addr; // location, in some units
+ uint_t length; // length, in some units
+ uint_t addr; // location, in some units
} section_t;
// note: these correspond to the PT_LOAD sections found in
// an ELF file, not necessarily to text/data/bss
-#define SECT_L1 0
-#define SECT_L2 1
-#define SECT_L3 2
-#define SECT_STACK 3
+#define SECT_L1 0
+#define SECT_L2 1
+#define SECT_L3 2
+#define SECT_STACK 3
// total number of section table entries in our PCB
-#define N_SECTS 4
+#define N_SECTS 4
// number of those that can be loaded from an ELF module
-#define N_LOADABLE 3
+#define N_LOADABLE 3
/*
** The process control block
@@ -134,31 +132,32 @@ typedef struct section_s {
*/
typedef struct pcb_s {
+
// four-byte fields
// start with these four bytes, for easy access in assembly
- context_t *context; // pointer to context save area on stack
+ context_t *context; // pointer to context save area on stack
// VM information
- pde_t *pdir; // page directory for this process
- section_t sects[N_SECTS]; // per-section memory information
+ pde_t *pdir; // page directory for this process
+ section_t sects[N_SECTS]; // per-section memory information
// queue linkage
- struct pcb_s *next; // next PCB in queue
+ struct pcb_s *next; // next PCB in queue
// process state information
- struct pcb_s *parent; // pointer to PCB of our parent process
- uint32_t wakeup; // wakeup time, for sleeping processes
- int32_t exit_status; // termination status, for parent's use
+ struct pcb_s *parent; // pointer to PCB of our parent process
+ uint32_t wakeup; // wakeup time, for sleeping processes
+ int32_t exit_status; // termination status, for parent's use
// these things may not need to be four bytes
- uint_t pid; // PID of this process
- enum state_e state; // process' current state
- enum priority_e priority; // process priority level
- uint_t ticks; // remaining ticks in this time slice
+ uint_t pid; // PID of this process
+ enum state_e state; // process' current state
+ enum priority_e priority; // process priority level
+ uint_t ticks; // remaining ticks in this time slice
} pcb_t;
-#define SZ_PCB sizeof(pcb_t)
+#define SZ_PCB sizeof(pcb_t)
/*
** PCB queue structure (opaque to the rest of the kernel)
@@ -169,16 +168,12 @@ typedef struct pcb_queue_s *pcb_queue_t;
** Queue ordering methods
*/
enum pcb_queue_order_e {
- O_FIFO,
- O_PRIO,
- O_PID,
- O_WAKEUP
+ O_FIFO, O_PRIO, O_PID, O_WAKEUP
// sentinel
- ,
- N_ORDERINGS
+ , N_ORDERINGS
};
-#define O_FIRST_STYLE O_FIFO
-#define O_LAST_STYLE O_WAKEUP
+#define O_FIRST_STYLE O_FIFO
+#define O_LAST_STYLE O_WAKEUP
/*
** Globals
@@ -205,13 +200,13 @@ extern uint_t next_pid;
extern pcb_t *init_pcb;
// table of state name strings
-extern const char state_str[N_STATES][4];
+extern const char *state_str[N_STATES];
// table of priority name strings
-extern const char prio_str[N_PRIOS][5];
+extern const char *prio_str[N_PRIOS];
// table of queue ordering name strings
-extern const char ord_str[N_ORDERINGS][5];
+extern const char *ord_str[N_ORDERINGS];
/*
** Prototypes
@@ -222,7 +217,7 @@ extern const char ord_str[N_ORDERINGS][5];
**
** Initialization for the Process module.
*/
-void pcb_init(void);
+void pcb_init( void );
/**
** Name: pcb_alloc
@@ -233,7 +228,7 @@ void pcb_init(void);
**
** @return status of the allocation attempt
*/
-int pcb_alloc(pcb_t **pcb);
+int pcb_alloc( pcb_t **pcb );
/**
** Name: pcb_free
@@ -242,7 +237,7 @@ int pcb_alloc(pcb_t **pcb);
**
** @param pcb Pointer to the PCB to be deallocated.
*/
-void pcb_free(pcb_t *pcb);
+void pcb_free( pcb_t *pcb );
/**
** Name: pcb_zombify
@@ -253,7 +248,7 @@ void pcb_free(pcb_t *pcb);
**
** @param pcb Pointer to the newly-undead PCB
*/
-void pcb_zombify(register pcb_t *victim);
+void pcb_zombify( register pcb_t *victim );
/**
** Name: pcb_cleanup
@@ -262,7 +257,7 @@ void pcb_zombify(register pcb_t *victim);
**
** @param pcb The PCB to reclaim
*/
-void pcb_cleanup(pcb_t *pcb);
+void pcb_cleanup( pcb_t *pcb );
/**
** Name: pcb_find_pid
@@ -273,7 +268,7 @@ void pcb_cleanup(pcb_t *pcb);
**
** @return Pointer to the PCB, or NULL
*/
-pcb_t *pcb_find_pid(uint_t pid);
+pcb_t *pcb_find_pid( uint_t pid );
/**
** Name: pcb_find_ppid
@@ -284,7 +279,7 @@ pcb_t *pcb_find_pid(uint_t pid);
**
** @return Pointer to the PCB, or NULL
*/
-pcb_t *pcb_find_ppid(uint_t pid);
+pcb_t *pcb_find_ppid( uint_t pid );
/**
** Name: pcb_queue_reset
@@ -296,7 +291,7 @@ pcb_t *pcb_find_ppid(uint_t pid);
**
** @return status of the init request
*/
-int pcb_queue_reset(pcb_queue_t queue, enum pcb_queue_order_e style);
+int pcb_queue_reset( pcb_queue_t queue, enum pcb_queue_order_e style );
/**
** Name: pcb_queue_empty
@@ -308,7 +303,7 @@ int pcb_queue_reset(pcb_queue_t queue, enum pcb_queue_order_e style);
**
** @return true if the queue is empty, else false
*/
-bool_t pcb_queue_empty(pcb_queue_t queue);
+bool_t pcb_queue_empty( pcb_queue_t queue );
/**
** Name: pcb_queue_length
@@ -319,7 +314,7 @@ bool_t pcb_queue_empty(pcb_queue_t queue);
**
** @return the count (0 if the queue is empty)
*/
-uint_t pcb_queue_length(const pcb_queue_t queue);
+uint_t pcb_queue_length( const pcb_queue_t queue );
/**
** Name: pcb_queue_insert
@@ -331,7 +326,7 @@ uint_t pcb_queue_length(const pcb_queue_t queue);
**
** @return status of the insertion request
*/
-int pcb_queue_insert(pcb_queue_t queue, pcb_t *pcb);
+int pcb_queue_insert( pcb_queue_t queue, pcb_t *pcb );
/**
** Name: pcb_queue_peek
@@ -343,7 +338,7 @@ int pcb_queue_insert(pcb_queue_t queue, pcb_t *pcb);
**
** @return the PCB pointer, or NULL if the queue is empty
*/
-pcb_t *pcb_queue_peek(const pcb_queue_t queue);
+pcb_t *pcb_queue_peek( const pcb_queue_t queue );
/**
** Name: pcb_queue_remove
@@ -355,7 +350,7 @@ pcb_t *pcb_queue_peek(const pcb_queue_t queue);
**
** @return status of the removal request
*/
-int pcb_queue_remove(pcb_queue_t queue, pcb_t **pcb);
+int pcb_queue_remove( pcb_queue_t queue, pcb_t **pcb );
/**
** Name: pcb_queue_remove_this
@@ -367,7 +362,7 @@ int pcb_queue_remove(pcb_queue_t queue, pcb_t **pcb);
**
** @return status of the removal request
*/
-int pcb_queue_remove_this(pcb_queue_t queue, pcb_t *pcb);
+int pcb_queue_remove_this( pcb_queue_t queue, pcb_t *pcb );
/*
** Scheduler routines
@@ -380,14 +375,14 @@ int pcb_queue_remove_this(pcb_queue_t queue, pcb_t *pcb);
**
** @param pcb Pointer to the PCB of the process to be scheduled
*/
-void schedule(pcb_t *pcb);
+void schedule( pcb_t *pcb );
/**
** dispatch()
**
** Select the next process to receive the CPU
*/
-void dispatch(void);
+void dispatch( void );
/*
** Debugging/tracing routines
@@ -401,7 +396,7 @@ void dispatch(void);
** @param msg[in] An optional message to print before the dump
** @param c[in] The context to dump out
*/
-void ctx_dump(const char *msg, register context_t *c);
+void ctx_dump( const char *msg, register context_t *c );
/**
** Name: ctx_dump_all
@@ -410,7 +405,7 @@ void ctx_dump(const char *msg, register context_t *c);
**
** @param msg[in] Optional message to print
*/
-void ctx_dump_all(const char *msg);
+void ctx_dump_all( const char *msg );
/**
** Name: pcb_dump
@@ -421,7 +416,7 @@ void ctx_dump_all(const char *msg);
** @param p[in] The PCB to dump
** @param all[in] Dump all the contents?
*/
-void pcb_dump(const char *msg, register pcb_t *p, bool_t all);
+void pcb_dump( const char *msg, register pcb_t *p, bool_t all );
/**
** Name: pcb_queue_dump
@@ -432,7 +427,7 @@ void pcb_dump(const char *msg, register pcb_t *p, bool_t all);
** @param queue[in] The queue to dump
** @param contents[in] Also dump (some) contents?
*/
-void pcb_queue_dump(const char *msg, pcb_queue_t queue, bool_t contents);
+void pcb_queue_dump( const char *msg, pcb_queue_t queue, bool_t contents );
/**
** Name: ptable_dump
@@ -442,7 +437,7 @@ void pcb_queue_dump(const char *msg, pcb_queue_t queue, bool_t contents);
** @param msg[in] Optional message to print
** @param all[in] Dump all or only part of the relevant data
*/
-void ptable_dump(const char *msg, bool_t all);
+void ptable_dump( const char *msg, bool_t all );
/**
** Name: ptable_dump_counts
@@ -450,8 +445,8 @@ void ptable_dump(const char *msg, bool_t all);
** Prints basic information about the process table (number of
** entries, number with each process state, etc.).
*/
-void ptable_dump_counts(void);
+void ptable_dump_counts( void );
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/serial.h b/kernel/old/include/serial.h
deleted file mode 100644
index 20bf192..0000000
--- a/kernel/old/include/serial.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#pragma once
-
-#include <stdint.h>
diff --git a/kernel/old/include/sio.h b/kernel/old/include/sio.h
index 629fda2..dca80ed 100644
--- a/kernel/old/include/sio.h
+++ b/kernel/old/include/sio.h
@@ -18,9 +18,9 @@
// sio interrupt settings
-#define SIO_TX 0x01
-#define SIO_RX 0x02
-#define SIO_BOTH (SIO_TX | SIO_RX)
+#define SIO_TX 0x01
+#define SIO_RX 0x02
+#define SIO_BOTH (SIO_TX | SIO_RX)
#ifndef ASM_SRC
@@ -48,7 +48,7 @@ extern QTYPE QNAME;
**
** Initialize the UART chip.
*/
-void sio_init(void);
+void sio_init( void );
/**
** sio_enable()
@@ -61,7 +61,7 @@ void sio_init(void);
**
** @return the prior IER setting
*/
-uint8_t sio_enable(uint8_t which);
+uint8_t sio_enable( uint8_t which );
/**
** sio_disable()
@@ -74,7 +74,7 @@ uint8_t sio_enable(uint8_t which);
**
** @return the prior IER setting
*/
-uint8_t sio_disable(uint8_t which);
+uint8_t sio_disable( uint8_t which );
/**
** sio_inq_length()
@@ -85,7 +85,7 @@ uint8_t sio_disable(uint8_t which);
**
** @return the count of characters still in the input queue
*/
-int sio_inq_length(void);
+int sio_inq_length( void );
/**
** sio_readc()
@@ -96,7 +96,7 @@ int sio_inq_length(void);
**
** @return the next character, or -1 if no character is available
*/
-int sio_readc(void);
+int sio_readc( void );
/**
** sio_read()
@@ -110,7 +110,7 @@ int sio_readc(void);
**
** @return the number of bytes copied, or 0 if no characters were available
*/
-int sio_read(char *buffer, int length);
+int sio_read( char *buffer, int length );
/**
** sio_writec( ch )
@@ -121,7 +121,7 @@ int sio_read(char *buffer, int length);
**
** @param ch Character to be written (in the low-order 8 bits)
*/
-void sio_writec(int ch);
+void sio_writec( int ch );
/**
** sio_write( ch )
@@ -135,7 +135,7 @@ void sio_writec(int ch);
**
** @return the number of characters copied into the SIO output buffer
*/
-int sio_write(const char *buffer, int length);
+int sio_write( const char *buffer, int length );
/**
** sio_puts( buf )
@@ -148,7 +148,7 @@ int sio_write(const char *buffer, int length);
**
** @return the count of bytes transferred
*/
-int sio_puts(const char *buffer);
+int sio_puts( const char *buffer );
/**
** sio_dump( full )
@@ -161,8 +161,8 @@ int sio_puts(const char *buffer);
** is being requested (which includes the contents
** of the queues)
*/
-void sio_dump(bool_t full);
+void sio_dump( bool_t full );
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/support.h b/kernel/old/include/support.h
index ac75a64..bdc5dc6 100644
--- a/kernel/old/include/support.h
+++ b/kernel/old/include/support.h
@@ -30,14 +30,14 @@
**
** Ultimately, just remember that THESE VALUES ARE APPROXIMATE AT BEST.
*/
-#define DELAY_1_SEC 40
-#define DELAY_1_25_SEC 50
-#define DELAY_2_SEC 80
-#define DELAY_2_5_SEC 100
-#define DELAY_3_SEC 120
-#define DELAY_5_SEC 200
-#define DELAY_7_SEC 280
-#define DELAY_10_SEC 400
+#define DELAY_1_SEC 40
+#define DELAY_1_25_SEC 50
+#define DELAY_2_SEC 80
+#define DELAY_2_5_SEC 100
+#define DELAY_3_SEC 120
+#define DELAY_5_SEC 200
+#define DELAY_7_SEC 280
+#define DELAY_10_SEC 400
#ifndef ASM_SRC
/**
@@ -49,7 +49,7 @@
**
** @param reason NUL-terminated message to be printed.
*/
-void panic(char *reason);
+void panic( char *reason );
/**
** init_interrupts
@@ -58,7 +58,7 @@ void panic(char *reason);
** IDT and the PIC. It is up to the user to enable processor interrupts
** when they're ready.
*/
-void init_interrupts(void);
+void init_interrupts( void );
/*
** install_isr
@@ -71,7 +71,8 @@ void init_interrupts(void);
**
** @return a pointer to the previously-registered ISR
*/
-void (*install_isr(int vector, void (*handler)(int, int)))(int, int);
+void (*install_isr( int vector,
+ void ( *handler )(int,int) ) )( int, int );
/*
** Name: delay
@@ -79,8 +80,8 @@ void (*install_isr(int vector, void (*handler)(int, int)))(int, int);
** See the comment above about the relative accuracy of the 'length'
** parameter.
*/
-void delay(int length);
+void delay( int length );
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/syscalls.h b/kernel/old/include/syscalls.h
index 27392a1..e66f6c0 100644
--- a/kernel/old/include/syscalls.h
+++ b/kernel/old/include/syscalls.h
@@ -23,28 +23,28 @@
** so that they can be used from assembly
*/
-#define SYS_exit 0
-#define SYS_waitpid 1
-#define SYS_fork 2
-#define SYS_exec 3
-#define SYS_read 4
-#define SYS_write 5
-#define SYS_getpid 6
-#define SYS_getppid 7
-#define SYS_gettime 8
-#define SYS_getprio 9
-#define SYS_setprio 10
-#define SYS_kill 11
-#define SYS_sleep 12
+#define SYS_exit 0
+#define SYS_waitpid 1
+#define SYS_fork 2
+#define SYS_exec 3
+#define SYS_read 4
+#define SYS_write 5
+#define SYS_getpid 6
+#define SYS_getppid 7
+#define SYS_gettime 8
+#define SYS_getprio 9
+#define SYS_setprio 10
+#define SYS_kill 11
+#define SYS_sleep 12
// UPDATE THIS DEFINITION IF MORE SYSCALLS ARE ADDED!
-#define N_SYSCALLS 13
+#define N_SYSCALLS 13
// dummy system call code for testing our ISR
-#define SYS_bogus 0xbad
+#define SYS_bogus 0xbad
// interrupt vector entry for system calls
-#define VEC_SYSCALL 0x80
+#define VEC_SYSCALL 0x80
#ifndef ASM_SRC
@@ -71,10 +71,10 @@
**
** Syscall module initialization routine
*/
-void sys_init(void);
+void sys_init( void );
-#endif /* KERNEL_SRC */
+#endif /* KERNEL_SRC */
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/types.h b/kernel/old/include/types.h
index 9435954..2f934f1 100644
--- a/kernel/old/include/types.h
+++ b/kernel/old/include/types.h
@@ -1,13 +1,58 @@
+/**
+** @file types.h
+**
+** @author Warren R. Carithers
+**
+** @brief Common type declarations.
+**
+** This header file contains type declarations used throughout
+** the kernel and user code.
+*/
+
#ifndef TYPES_H_
#define TYPES_H_
+
#ifndef ASM_SRC
+/*
+** Start of C-only definitions
+**
+** Anything that should not be visible to something other than
+** the C compiler should be put here.
+*/
+
+/*
+** Types
+*/
+
+// standard integer sized types
+typedef char int8_t;
+typedef unsigned char uint8_t;
+typedef short int16_t;
+typedef unsigned short uint16_t;
+typedef int int32_t;
+typedef unsigned int uint32_t;
+typedef long long int int64_t;
+typedef unsigned long long int uint64_t;
+
+// other integer types
+typedef unsigned char uchar_t;
+typedef unsigned int uint_t;
+typedef unsigned long int ulong_t;
+
+// Boolean values
+typedef uint8_t bool_t;
+
+#define true 1
+#define false 0
+
#ifdef KERNEL_SRC
// we define these here instead of in vm.h in order to get around a
// nasty chick/egg dependency between procs.h and vm.h
-typedef uint32_t pde_t; // page directory entry
-typedef uint32_t pte_t; // page table entry
-#endif /* KERNEL_SRC */
+typedef uint32_t pde_t; // page directory entry
+typedef uint32_t pte_t; // page table entry
+#endif /* KERNEL_SRC */
+
+#endif /* !ASM_SRC */
-#endif
#endif
diff --git a/kernel/old/include/udefs.h b/kernel/old/include/udefs.h
new file mode 100644
index 0000000..50b6952
--- /dev/null
+++ b/kernel/old/include/udefs.h
@@ -0,0 +1,113 @@
+/**
+** @file udefs.h
+**
+** @author CSCI-452 class of 20245
+**
+** @brief "Userland" configuration information
+*/
+
+#ifndef UDEFS_H_
+#define UDEFS_H_
+
+#include <common.h>
+
+/*
+** General (C and/or assembly) definitions
+**
+** This section of the header file contains definitions that can be
+** used in either C or assembly-language source code.
+*/
+
+// delay loop counts
+
+#define DELAY_LONG 100000000
+#define DELAY_MED 4500000
+#define DELAY_SHORT 2500000
+
+#define DELAY_STD DELAY_SHORT
+
+#ifndef ASM_SRC
+
+/*
+** Start of C-only definitions
+*/
+
+// convenience macros
+
+// a delay loop - kind of ugly, but it works
+
+#define DELAY(n) do { \
+ for(int _dlc = 0; _dlc < (DELAY_##n); ++_dlc) continue; \
+ } while(0)
+
+/*
+** We need the list of program IDs so that we can request
+** their execution
+*/
+
+#include <userids.h>
+
+/*
+** All user main() functions have the following prototype:
+**
+** int name( int argc, char *argv[] );
+**
+** To simplify declaring them, we define a macro that expands into
+** that header. This can be used both in the implementation (followed
+** by the function body) and in places where we just need the prototype
+** (following it with a semicolon).
+*/
+
+#define USERMAIN(f) int f( int argc, char *argv[] )
+
+/*
+** User process controls.
+**
+** To enable a specific test, define the symbol SPAWN_name here, and
+** guard the places in other code that use or refer to that test. For
+** example, test 'A' is enabled by definining SPAWN_A here, and all
+** places that refer to test 'A' are guarded with:
+**
+** #ifdef SPAWN_A
+** ... conditionally-compiled code
+** #endif
+**
+** Generally, most of these will exit with a status of 0. If a process
+** returns from its main function when it shouldn't (e.g., if it had
+** called exit() but continued to run), it will usually return a status
+** of ?.
+*/
+
+/*
+** The standard set of test programs, start by the shell (which is started
+** automatically from the initial user process)
+**
+** There is no user 'O' program, and programs 'W' through 'Z' are spawned
+** from other processes and are never spawned directly.
+*/
+
+#define SPAWN_A
+#define SPAWN_B
+#define SPAWN_C
+#define SPAWN_D
+#define SPAWN_E
+#define SPAWN_F
+#define SPAWN_G
+#define SPAWN_H
+#define SPAWN_I
+#define SPAWN_J
+#define SPAWN_K
+#define SPAWN_L
+#define SPAWN_M
+#define SPAWN_N
+#define SPAWN_P
+#define SPAWN_Q
+#define SPAWN_R
+#define SPAWN_S
+#define SPAWN_T
+#define SPAWN_U
+#define SPAWN_V
+
+#endif /* !ASM_SRC */
+
+#endif
diff --git a/kernel/old/include/ulib.h b/kernel/old/include/ulib.h
new file mode 100644
index 0000000..d254d6a
--- /dev/null
+++ b/kernel/old/include/ulib.h
@@ -0,0 +1,315 @@
+/**
+** @file ulib.h
+**
+** @author CSCI-452 class of 20245
+**
+** @brief Declarations for user-level library functions
+**
+** This module implements a simple collection of support functions
+** similar to the standard C library.
+*/
+
+#ifndef ULIB_H_
+#define ULIB_H_
+
+#include <common.h>
+
+/*
+** General (C and/or assembly) definitions
+*/
+
+#ifndef ASM_SRC
+
+/*
+** Start of C-only definitions
+*/
+
+/*
+** Types
+*/
+
+/*
+** Globals
+*/
+
+/*
+** Prototypes
+*/
+
+/*
+*************************************************
+** SYSTEM CALLS *********************************
+*************************************************
+*/
+
+/**
+** exit - terminate the calling process
+**
+** usage: exit(status);
+**
+** @param status Termination status of this process
+**
+** Does not return.
+*/
+void exit( int32_t status );
+
+/**
+** waitpid - wait for a child process to terminate
+**
+** usage: pid = waitpid(pid,&status);
+**
+** @param pid PID of the desired child, or 0 for any child
+** @param status Pointer to int32_t into which the child's status is placed,
+** or NULL
+**
+** @return The PID of the terminated child, or an error code
+**
+** If there are no children in the system, returns an error code (*status
+** is unchanged).
+**
+** If there are one or more children in the system and at least one has
+** terminated but hasn't yet been cleaned up, cleans up that process and
+** returns its information; otherwise, blocks until a child terminates.
+*/
+int waitpid( uint_t pid, int32_t *status );
+
+/**
+** fork - create a duplicate of the calling process
+**
+** usage: pid = fork();
+**
+** @return parent - the pid of the new child, or an error code
+** child - 0
+*/
+int fork( void );
+
+/**
+** exec - replace the memory image of the calling process
+**
+** usage: exec( what, args )
+**
+** @param what program table index of the program to exec
+** @param args the command-line argument vector
+**
+** Does not return if it succeeds; if it returns, something has
+** gone wrong.
+*/
+void exec( uint_t what, char **args );
+
+/**
+** read - read into a buffer from a stream
+**
+** usage: n = read(channel,buf,length)
+**
+** @param chan I/O stream to read from
+** @param buf Buffer to read into
+** @param length Maximum capacity of the buffer
+**
+** @return The count of bytes transferred, or an error code
+*/
+int read( uint_t chan, void *buffer, uint_t length );
+
+/**
+** write - write from a buffer to a stream
+**
+** usage: n = write(channel,buf,length)
+**
+** @param chan I/O stream to write to
+** @param buf Buffer to write from
+** @param length Maximum capacity of the buffer
+**
+** @return The count of bytes transferred, or an error code
+*/
+int write( uint_t chan, const void *buffer, uint_t length );
+
+/**
+** getpid - get the PID of the calling process
+**
+** usage: pid = getpid()
+**
+** @return the PID of this process
+*/
+uint_t getpid( void );
+
+/**
+** getppid - get the PID of the calling process' parent
+**
+** usage: pid = getppid()
+**
+** @return the PID of this process' parent
+*/
+uint_t getppid( void );
+
+/**
+** gettime - get the current system time
+**
+** usage: pid = gettime()
+**
+** @return the system time
+*/
+uint32_t gettime( void );
+
+/**
+** getprio - get the scheduling priority of the calling process
+**
+** usage: prio = getprio()
+**
+** @return the process' priority
+*/
+int getprio( void );
+
+/**
+** setprio - set the scheduling priority of the calling process
+**
+** usage: oldprio = setprio(newprio)
+**
+** @param new the desired new priority
+**
+** @return the old priority value
+*/
+int setprio( int new );
+
+/**
+** kill - terminate a process with extreme prejudice
+**
+** usage: n = kill( pid )
+**
+** @param pid the intended victim
+**
+** @return 0 on success, else an error code
+*/
+int32_t kill( uint_t pid );
+
+/**
+** sleep - put the current process to sleep for some length of time
+**
+** usage: sleep(n);
+**
+** @param ms Desired sleep time (in ms), or 0 to yield the CPU
+**
+** @return the time the process spent sleeping (in ms)
+*/
+int sleep( uint32_t ms );
+
+/**
+** bogus - a nonexistent system call, to test our syscall ISR
+**
+** usage: bogus()
+**
+** Does not return.
+*/
+void bogus( void );
+
+/*
+*************************************************
+** CONVENIENT "SHORTHAND" VERSIONS OF SYSCALLS **
+*************************************************
+**
+** These are library functions that perform specific common
+** variants of system calls. This helps reduce the total number
+** of system calls, keeping our baseline OS as lean and mean
+** as we can make it. :-)
+*/
+
+/**
+** wait - wait for any child to exit
+**
+** usage: pid = wait(&status)
+**
+** Calls waitpid(0,status)
+**
+** @param status Pointer to int32_t into which the child's status is placed,
+** or NULL
+**
+** @return The PID of the terminated child, or an error code
+*/
+int wait( int32_t *status );
+
+/**
+** spawn - create a new process running a different program
+**
+** usage: n = spawn(what,args)
+**
+** Creates a new process and then execs 'what'
+**
+** @param what Program table index of the program to spawn
+** @param args The command-line argument vector for the process
+**
+** @return The PID of the child, or an error code
+*/
+int spawn( uint_t what, char **args );
+
+/**
+** cwritech(ch) - write a single character to the console
+**
+** @param ch The character to write
+**
+** @return The return value from calling write()
+*/
+int cwritech( char ch );
+
+/**
+** cwrites(str) - write a NUL-terminated string to the console
+**
+** @param str The string to write
+**
+*/
+int cwrites( const char *str );
+
+/**
+** cwrite(buf,leng) - write a sized buffer to the console
+**
+** @param buf The buffer to write
+** @param leng The number of bytes to write
+**
+** @return The return value from calling write()
+*/
+int cwrite( const char *buf, uint32_t leng );
+
+/**
+** swritech(ch) - write a single character to the SIO
+**
+** @param ch The character to write
+**
+** @return The return value from calling write()
+*/
+int swritech( char ch );
+
+/**
+** swrites(str) - write a NUL-terminated string to the SIO
+**
+** @param str The string to write
+**
+** @return The return value from calling write()
+*/
+int swrites( const char *str );
+
+/**
+** swrite(buf,leng) - write a sized buffer to the SIO
+**
+** @param buf The buffer to write
+** @param leng The number of bytes to write
+**
+** @return The return value from calling write()
+*/
+int swrite( const char *buf, uint32_t leng );
+
+/*
+*************************************************
+** MISCELLANEOUS USEFUL SUPPORT FUNCTIONS *******
+*************************************************
+*/
+
+/**
+** fake_exit()
+**
+** dummy "startup" function
+**
+** calls exit(%eax) - serves as the "return to" code for
+** main() functions, in case they don't call exit() themselves
+*/
+void fake_exit( void );
+
+#endif /* !ASM_SRC */
+
+#endif
diff --git a/kernel/old/include/user.h b/kernel/old/include/user.h
index 672f916..4d9402f 100644
--- a/kernel/old/include/user.h
+++ b/kernel/old/include/user.h
@@ -15,7 +15,7 @@
#include <x86/arch.h>
// default value for EFLAGS in new processes
-#define DEFAULT_EFLAGS (EFL_MB1 | EFL_IF)
+#define DEFAULT_EFLAGS (EFL_MB1 | EFL_IF)
/*
** General (C and/or assembly) definitions
@@ -61,14 +61,14 @@ typedef struct header_s {
} header_t;
// length of the file name field
-#define NAMELEN 20
+#define NAMELEN 20
// program descriptor
typedef struct prog_s {
- char name[NAMELEN]; // truncated name (15 chars)
- uint32_t offset; // offset from the beginning of the blob
- uint32_t size; // size of this ELF module
- uint32_t flags; // miscellaneous flags
+ char name[NAMELEN]; // truncated name (15 chars)
+ uint32_t offset; // offset from the beginning of the blob
+ uint32_t size; // size of this ELF module
+ uint32_t flags; // miscellaneous flags
} prog_t;
/*
@@ -84,7 +84,7 @@ typedef struct prog_s {
**
** Initializes the user support module.
*/
-void user_init(void);
+void user_init( void );
/**
** Name: user_locate
@@ -95,7 +95,7 @@ void user_init(void);
**
** @return pointer to the program table entry in the code archive, or NULL
*/
-prog_t *user_locate(uint_t what);
+prog_t *user_locate( uint_t what );
/**
** Name: user_duplicate
@@ -107,7 +107,7 @@ prog_t *user_locate(uint_t what);
**
** @return the status of the duplicate attempt
*/
-int user_duplicate(pcb_t *new, pcb_t *old);
+int user_duplicate( pcb_t *new, pcb_t *old );
/**
** Name: user_load
@@ -118,11 +118,10 @@ int user_duplicate(pcb_t *new, pcb_t *old);
** @param prog A pointer to the program table entry to be loaded
** @param pcb The PCB for the program being loaded
** @param args The argument vector for the program
-** @param sys Is the argument vector from kernel code?
**
** @return the status of the load attempt
*/
-int user_load(prog_t *prog, pcb_t *pcb, const char **args, bool_t sys);
+int user_load( prog_t *prog, pcb_t *pcb, const char **args );
/**
** Name: user_cleanup
@@ -132,8 +131,8 @@ int user_load(prog_t *prog, pcb_t *pcb, const char **args, bool_t sys);
**
** @param pcb The PCB of the program to be cleaned up
*/
-void user_cleanup(pcb_t *pcb);
+void user_cleanup( pcb_t *pcb );
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/userids.h b/kernel/old/include/userids.h
new file mode 100644
index 0000000..284f3ee
--- /dev/null
+++ b/kernel/old/include/userids.h
@@ -0,0 +1,33 @@
+/**
+** @file userids.h
+**
+** @author Warren R. Carithers
+**
+** @brief IDs for user-level programs
+**
+** NOTE: this file is automatically generated when the user.img file
+** is created. Do not edit this manually!
+*/
+
+#ifndef USERIDS_H_
+#define USERIDS_H_
+
+#ifndef ASM_SRC
+/*
+** These IDs are used to identify the various user programs.
+** Each call to exec() will provide one of these as the first
+** argument.
+**
+** This list should be updated if/when the collection of
+** user processes changes.
+*/
+enum users_e {
+ Init, Idle, Shell, ProgABC, ProgDE, ProgFG, ProgH, ProgI,
+ ProgJ, ProgKL, ProgMN, ProgP, ProgQ, ProgR, ProgS, ProgTUV,
+ ProgW, ProgX, ProgY, ProgZ
+ // sentinel
+ , N_USERS
+};
+#endif /* !ASM_SRC */
+
+#endif
diff --git a/kernel/old/include/vm.h b/kernel/old/include/vm.h
index dc12568..6e3935e 100644
--- a/kernel/old/include/vm.h
+++ b/kernel/old/include/vm.h
@@ -64,91 +64,87 @@
*/
// user virtual addresses
-#define USER_BASE 0x00000000
-#define USER_MAX 0x003fffff
-#define USER_TEXT 0x00001000
-#define USER_STACK 0x003fe000
-#define USER_STACK_P1 USER_STACK
-#define USER_STACK_P2 0x003ff000
-#define USER_STK_END 0x00400000
+#define USER_TEXT 0x00001000
+#define USER_STACK 0x003fe000
+#define USER_STK_END 0x00400000
// how to find the addresses of the stack pages in the VM hierarchy
// user address space is the first 4MB of virtual memory
-#define USER_PDE 0
-// the stack occupies this range of pages in the user address space
-#define USER_STK_FIRST_PTE 1022
-#define USER_STK_LAST_PTE 1023
+#define USER_PDE 0
+// the stack occupies the last two pages of the address space
+#define USER_STK_PTE1 1022
+#define USER_STK_PTE2 1023
// some important memory addresses
-#define KERN_BASE 0x80000000 // start of "kernel" memory
-#define EXT_BASE 0x00100000 // start of "extended" memory (1MB)
-#define DEV_BASE 0xfe000000 // "device" memory
-#define PHYS_TOP 0x3fffffff // last usable physical address (1GB - 1)
+#define KERN_BASE 0x80000000 // start of "kernel" memory
+#define EXT_BASE 0x00100000 // start of "extended" memory (1MB)
+#define DEV_BASE 0xfe000000 // "device" memory
+#define PHYS_TOP 0x3fffffff // last usable physical address (1GB - 1)
// where the kernel actually lives
-#define KERN_PLINK 0x00010000
-#define KERN_VLINK (KERN_BASE + KERN_PLINK)
+#define KERN_PLINK 0x00010000
+#define KERN_VLINK (KERN_BASE + KERN_PLINK)
// number of entries in a page directory or page table
-#define N_PDE 1024
-#define N_PTE 1024
+#define N_PDE 1024
+#define N_PTE 1024
// index field shift counts and masks
-#define PDIX_SHIFT 22
-#define PTIX_SHIFT 12
-#define PIX2I_MASK 0x3ff
+#define PDIX_SHIFT 22
+#define PTIX_SHIFT 12
+#define PIX2I_MASK 0x3ff
// physical/virtual converters that don't use casting
// (usable from anywhere)
-#define V2PNC(a) ((a) - KERN_BASE)
-#define P2VNC(a) ((a) + KERN_BASE)
+#define V2PNC(a) ((a) - KERN_BASE)
+#define P2VNC(a) ((a) + KERN_BASE)
// page-size address rounding macros
-#define SZ_PG_M1 MOD4K_BITS
-#define SZ_PG_MASK MOD4K_MASK
-#define PGUP(a) (((a) + SZ_PG_M1) & SZ_PG_MASK)
-#define PGDOWN(a) ((a) & SZ_PG_MASK)
+#define SZ_PG_M1 MOD4K_BITS
+#define SZ_PG_MASK MOD4K_MASK
+#define PGUP(a) (((a)+SZ_PG_M1) & SZ_PG_MASK)
+#define PGDOWN(a) ((a) & SZ_PG_MASK)
// page directory entry bit fields
-#define PDE_P 0x00000001 // 1 = present
-#define PDE_RW 0x00000002 // 1 = writable
-#define PDE_US 0x00000004 // 1 = user and system usable
-#define PDE_PWT 0x00000008 // cache: 1 = write-through
-#define PDE_PCD 0x00000010 // cache: 1 = disabled
-#define PDE_A 0x00000020 // accessed
-#define PDE_D 0x00000040 // dirty (4MB pages)
-#define PDE_AVL1 0x00000040 // ignored (4KB pages)
-#define PDE_PS 0x00000080 // 1 = 4MB page size
-#define PDE_G 0x00000100 // global
-#define PDE_AVL2 0x00000e00 // ignored
-#define PDE_PAT 0x00001000 // (4MB pages) use page attribute table
-#define PDE_PTA 0xfffff000 // page table address field (4KB pages)
-#define PDE_FA 0xffc00000 // frame address field (4MB pages)
+#define PDE_P 0x00000001 // 1 = present
+#define PDE_RW 0x00000002 // 1 = writable
+#define PDE_US 0x00000004 // 1 = user and system usable
+#define PDE_PWT 0x00000008 // cache: 1 = write-through
+#define PDE_PCD 0x00000010 // cache: 1 = disabled
+#define PDE_A 0x00000020 // accessed
+#define PDE_D 0x00000040 // dirty (4MB pages)
+#define PDE_AVL1 0x00000040 // ignored (4KB pages)
+#define PDE_PS 0x00000080 // 1 = 4MB page size
+#define PDE_G 0x00000100 // global
+#define PDE_AVL2 0x00000e00 // ignored
+#define PDE_PAT 0x00001000 // (4MB pages) use page attribute table
+#define PDE_PTA 0xfffff000 // page table address field (4KB pages)
+#define PDE_FA 0xffc00000 // frame address field (4MB pages)
// page table entry bit fields
-#define PTE_P 0x00000001 // present
-#define PTE_RW 0x00000002 // 1 = writable
-#define PTE_US 0x00000004 // 1 = user and system usable
-#define PTE_PWT 0x00000008 // cache: 1 = write-through
-#define PTE_PCD 0x00000010 // cache: 1 = disabled
-#define PTE_A 0x00000020 // accessed
-#define PTE_D 0x00000040 // dirty
-#define PTE_PAT 0x00000080 // use page attribute table
-#define PTE_G 0x00000100 // global
-#define PTE_AVL2 0x00000e00 // ignored
-#define PTE_FA 0xfffff000 // frame address field
+#define PTE_P 0x00000001 // present
+#define PTE_RW 0x00000002 // 1 = writable
+#define PTE_US 0x00000004 // 1 = user and system usable
+#define PTE_PWT 0x00000008 // cache: 1 = write-through
+#define PTE_PCD 0x00000010 // cache: 1 = disabled
+#define PTE_A 0x00000020 // accessed
+#define PTE_D 0x00000040 // dirty
+#define PTE_PAT 0x00000080 // use page attribute table
+#define PTE_G 0x00000100 // global
+#define PTE_AVL2 0x00000e00 // ignored
+#define PTE_FA 0xfffff000 // frame address field
// error code bit assignments for page faults
-#define PFLT_P 0x00000001
-#define PFLT_W 0x00000002
-#define PFLT_US 0x00000004
-#define PFLT_RSVD 0x00000008
-#define PFLT_ID 0x00000010
-#define PFLT_PK 0x00000020
-#define PFLT_SS 0x00000040
-#define PFLT_HLAT 0x00000080
-#define PFLT_SGX 0x00008000
-#define PFLT_UNUSED 0xffff7f00
+#define PFLT_P 0x00000001
+#define PFLT_W 0x00000002
+#define PFLT_US 0x00000004
+#define PFLT_RSVD 0x00000008
+#define PFLT_ID 0x00000010
+#define PFLT_PK 0x00000020
+#define PFLT_SS 0x00000040
+#define PFLT_HLAT 0x00000080
+#define PFLT_SGX 0x00008000
+#define PFLT_UNUSED 0xffff7f00
#ifndef ASM_SRC
@@ -158,59 +154,54 @@
// physical/virtual converters that do use casting
// (not usable from assembly)
-#define V2P(a) (((uint32_t)(a)) - KERN_BASE)
-#define P2V(a) (((uint32_t)(a)) + KERN_BASE)
+#define V2P(a) (((uint32_t)(a)) - KERN_BASE)
+#define P2V(a) (((uint32_t)(a)) + KERN_BASE)
// create a pde/pte from an integer frame number and permission bits
-#define MKPDE(f, p) ((pde_t)(TO_FRAME((f)) | (p)))
-#define MKPTE(f, p) ((pte_t)(TO_FRAME((f)) | (p)))
+#define MKPDE(f,p) ((pde_t)( TO_FRAME((f)) | (p) ))
+#define MKPTE(f,p) ((pte_t)( TO_FRAME((f)) | (p) ))
// is a PDE/PTE present?
// (P bit is in the same place in both)
-#define IS_PRESENT(entry) (((entry) & PDE_P) != 0)
+#define IS_PRESENT(entry) (((entry) & PDE_P) != 0 )
// is a PDE a 4MB page entry?
-#define IS_LARGE(pde) (((pde) & PDE_PS) != 0)
+#define IS_LARGE(pde) (((pde) & PDE_PS) != 0 )
// is this entry "system only" or "system and user"?
-#define IS_SYSTEM(entry) (((entry) & PDE_US) == 0)
-#define IS_USER(entry) (((entry) & PDE_US) != 0)
+#define IS_SYSTEM(entry) (((entry) & PDE_US) == 0 )
+#define IS_USER(entry) (((entry) & PDE_US) != 0 )
// low-order nine bits of PDEs and PTEs hold "permission" flag bits
-#define PERMS_MASK MOD4K_BITS
+#define PERMS_MASK MOD4K_MASK
// 4KB frame numbers are 20 bits wide
-#define FRAME_4K_SHIFT 12
-#define FRAME2I_4K_MASK 0x000fffff
-#define TO_4KFRAME(n) (((n) & FRAME2I_4K_MASK) << FRAME_4K_SHIFT)
-#define GET_4KFRAME(n) (((n) >> FRAME_4K_SHIFT) & FRAME2I_4K_MASK)
-#define PDE_4K_ADDR(n) ((n) & MOD4K_MASK)
-#define PTE_4K_ADDR(n) ((n) & MOD4K_MASK)
+#define FRAME_4K_SHIFT 12
+#define FRAME2I_4K_MASK 0x000fffff
+#define TO_4KFRAME(n) (((n)&FRAME2I_4K_MASK) << FRAME_4K_SHIFT)
+#define GET_4KFRAME(n) (((n) >> FRAME_4K_SHIFT)&F2I_4K_MASK)
+#define PDE_4K_ADDR(n) ((n) & MOD4K_MASK)
+#define PTE_4K_ADDR(n) ((n) & MOD4K_MASK)
// 4MB frame numbers are 10 bits wide
-#define FRAME_4M_SHIFT 22
-#define FRAME2I_4M_MASK 0x000003ff
-#define TO_4MFRAME(n) (((n) & FRAME2I_4M_MASK) << FRAME_4M_SHIFT)
-#define GET_4MFRAME(n) (((n) >> FRAME_4M_SHIFT) & FRAME2I_4M_MASK)
-#define PDE_4M_ADDR(n) ((n) & MOD4M_MASK)
-#define PTE_4M_ADDR(n) ((n) & MOD4M_MASK)
+#define FRAME_4M_SHIFT 22
+#define FRAME2I_4M_MASK 0x000003ff
+#define TO_4MFRAME(n) (((n)&FRAME2I_4M_MASK) << FRAME_4M_SHIFT)
+#define GET_4MFRAME(n) (((n) >> FRAME_4M_SHIFT)&F2I_4M_MASK)
+#define PDE_4M_ADDR(n) ((n) & MOD4M_MASK)
+#define PTE_4M_ADDR(n) ((n) & MOD4M_MASK)
// extract the PMT address or frame address from a table entry
// PDEs could point to 4MB pages, or 4KB PMTs
-#define PDE_ADDR(p) \
- (IS_LARGE(p) ? (((uint32_t)p) & PDE_FA) : (((uint32_t)p) & PDE_PTA))
+#define PDE_ADDR(p) (IS_LARGE(p)?(((uint32_t)p)&PDE_FA):(((uint32_t)p)&PDE_PTA))
// PTEs always point to 4KB pages
-#define PTE_ADDR(p) (((uint32_t)(p)) & PTE_FA)
+#define PTE_ADDR(p) (((uint32_t)(p))&PTE_FA)
// everything has nine bits of permission flags
-#define PERMS(p) (((uint32_t)(p)) & PERMS_MASK)
+#define PERMS(p) (((uint32_t)(p))&PERMS_MASK)
-// extract the table indices from a 32-bit VA
-#define PDIX(v) ((((uint32_t)(v)) >> PDIX_SHIFT) & PIX2I_MASK)
-#define PTIX(v) ((((uint32_t)(v)) >> PTIX_SHIFT) & PIX2I_MASK)
-
-// extract the byte offset from a 32-bit VA
-#define OFFSET_4K(v) (((uint32_t)(v)) & MOD4K_BITS)
-#define OFFSET_4M(v) (((uint32_t)(v)) & MOD4M_BITS)
+// extract the table indices from a 32-bit address
+#define PDIX(v) ((((uint32_t)(v)) >> PDIX_SHIFT) & PIX2I_MASK)
+#define PTIX(v) ((((uint32_t)(v)) >> PTIX_SHIFT) & PIX2I_MASK)
/*
** Types
@@ -223,34 +214,31 @@
// PDE for 4KB pages
typedef struct pdek_s {
- uint_t p : 1; // 0: present
- uint_t rw : 1; // 1: writable
- uint_t us : 1; // 2: user/supervisor
- uint_t pwt : 1; // 3: cache write-through
- uint_t pcd : 1; // 4: cache disable
- uint_t a : 1; // 5: accessed
- uint_t avl1 : 1; // 6: ignored (available)
- uint_t ps : 1; // 7: page size (must be 0)
- uint_t avl2 : 4; // 11-8: ignored (available)
- uint_t fa : 20; // 31-12: frame address
+ uint_t p :1; // present
+ uint_t rw :1; // writable
+ uint_t us :1; // user/supervisor
+ uint_t pwt :1; // cache write-through
+ uint_t pcd :1; // cache disable
+ uint_t a :1; // accessed
+ uint_t avl1 :1; // ignored (available)
+ uint_t ps :1; // page size (must be 0)
+ uint_t avl2 :4; // ignored (available)
+ uint_t fa :20; // frame address
} pdek_f_t;
// PDE for 4MB pages
typedef struct pdem_s {
- uint_t p : 1; // 0: present
- uint_t rw : 1; // 1: writable
- uint_t us : 1; // 2: user/supervisor
- uint_t pwt : 1; // 3: cache write-through
- uint_t pcd : 1; // 4: cache disable
- uint_t a : 1; // 5: accessed
- uint_t d : 1; // 6: dirty
- uint_t ps : 1; // 7: page size (must be 1)
- uint_t g : 1; // 8: global
- uint_t avl : 3; // 11-9: ignored (available)
- uint_t pat : 1; // 12: page attribute table in use
- uint_t fa2 : 4; // 16-13: bits 35-32 of frame address (36-bit addrs)
- uint_t rsv : 5; // 21-17: reserved - must be zero
- uint_t fa : 10; // 31-22: bits 31-22 of frame address
+ uint_t p :1; // present
+ uint_t rw :1; // writable
+ uint_t us :1; // user/supervisor
+ uint_t pwt :1; // cache write-through
+ uint_t pcd :1; // cache disable
+ uint_t a :1; // accessed
+ uint_t d :1; // dirty
+ uint_t ps :1; // page size (must be 1)
+ uint_t g :1; // global
+ uint_t avl :3; // ignored (available)
+ uint_t fa :20; // frame address
} pdem_f_t;
// page table entries
@@ -260,33 +248,33 @@ typedef struct pdem_s {
// broken out into fields
typedef struct pte_s {
- uint_t p : 1; // 0: present
- uint_t rw : 1; // 1: writable
- uint_t us : 1; // 2: user/supervisor
- uint_t pwt : 1; // 3: cache write-through
- uint_t pcd : 1; // 4: cache disable
- uint_t a : 1; // 5: accessed
- uint_t d : 1; // 6: dirty
- uint_t pat : 1; // 7: page attribute table in use
- uint_t g : 1; // 8: global
- uint_t avl : 3; // 11-9: ignored (available)
- uint_t fa : 20; // 31-12: frame address
+ uint_t p :1; // present
+ uint_t rw :1; // writable
+ uint_t us :1; // user/supervisor
+ uint_t pwt :1; // cache write-through
+ uint_t pcd :1; // cache disable
+ uint_t a :1; // accessed
+ uint_t d :1; // dirty
+ uint_t pat :1; // page attribute table in use
+ uint_t g :1; // global
+ uint_t avl :3; // ignored (available)
+ uint_t fa :20; // frame address
} ptef_t;
// page fault error code bits
// comment: meaning when 1 / meaning when 0
struct pfec_s {
- uint_t p : 1; // page-level protection violation / !present
- uint_t w : 1; // write / read
- uint_t us : 1; // user-mode access / supervisor-mode access
- uint_t rsvd : 1; // reserved bit violation / not
- uint_t id : 1; // instruction fetch / data fetch
- uint_t pk : 1; // protection-key violation / !pk
- uint_t ss : 1; // shadow stack access / !ss
- uint_t hlat : 1; // HLAT paging / ordinary paging or access rights
- uint_t xtr1 : 7; // unused
- uint_t sgz : 1; // SGX-specific access control violation / !SGX
- uint_t xtr2 : 16; // more unused
+ uint_t p :1; // page-level protection violation / !present
+ uint_t w :1; // write / read
+ uint_t us :1; // user-mode access / supervisor-mode access
+ uint_t rsvd :1; // reserved bit violation / not
+ uint_t id :1; // instruction fetch / data fetch
+ uint_t pk :1; // protection-key violation / !pk
+ uint_t ss :1; // shadow stack access / !ss
+ uint_t hlat :1; // HLAT paging / ordinary paging or access rights
+ uint_t xtr1 :7; // unused
+ uint_t sgz :1; // SGX-specific access control violation / !SGX
+ uint_t xtr2 :16; // more unused
};
typedef union pfec_u {
@@ -296,23 +284,12 @@ typedef union pfec_u {
// Mapping descriptor for VA::PA mappings
typedef struct mapping_t {
- uint32_t va_start; // starting virtual address for this range
- uint32_t pa_start; // first physical address in the range
- uint32_t pa_end; // last physical address in the range
- uint32_t perm; // access control
+ uint32_t va_start; // starting virtual address for this range
+ uint32_t pa_start; // first physical address in the range
+ uint32_t pa_end; // last physical address in the range
+ uint32_t perm; // access control
} mapping_t;
-// Modes for dumping out page hierarchies
-enum vmmode_e {
- Simple = 0, // just count 'present' entries at each level
- OneLevel, // top-level only: count entries, decode 'present'
- TwoLevel, // count entries & decode at each level
- Full // ??? in case we need more?
- // sentinel
- ,
- N_VMMODES
-};
-
/*
** Globals
*/
@@ -332,20 +309,7 @@ extern pde_t *kpdir;
** Note: should not be called until after the memory free list has
** been set up.
*/
-void vm_init(void);
-
-/**
-** Name: vm_uva2kva
-**
-** Convert a user VA into a kernel address. Works for all addresses -
-** if the address is a page address, the low-order nine bits will be
-** zeroes; otherwise, they is the offset into the page, which is
-** unchanged within the address spaces.
-**
-** @param pdir Pointer to the page directory to examine
-** @param va Virtual address to check
-*/
-void *vm_uva2kva(pde_t *pdir, void *va);
+void vm_init( void );
/**
** Name: vm_pagedup
@@ -356,18 +320,7 @@ void *vm_uva2kva(pde_t *pdir, void *va);
**
** @return a pointer to the new, duplicate page, or NULL
*/
-void *vm_pagedup(void *old);
-
-/**
-** Name: vm_pdedup
-**
-** Duplicate a page directory entry
-**
-** @param entry The entry to be duplicated
-**
-** @return the new entry, or -1 on error.
-*/
-pde_t vm_pdedup(pde_t entry);
+void *vm_pagedup( void *old );
/**
** Name: vm_ptdup
@@ -379,7 +332,7 @@ pde_t vm_pdedup(pde_t entry);
**
** @return true on success, else false
*/
-bool_t vm_ptdup(pde_t *dst, pde_t *curr);
+bool_t vm_ptdup( pde_t *dst, pde_t *curr );
/**
** Name: vm_getpte
@@ -395,28 +348,28 @@ bool_t vm_ptdup(pde_t *dst, pde_t *curr);
**
** @return A pointer to the page table entry for this VA, or NULL
*/
-pte_t *vm_getpte(pde_t *pdir, const void *va, bool_t alloc);
+pte_t *vm_getpte( pde_t *pdir, const void *va, bool_t alloc );
/**
** Name: vm_mkkvm
**
** Create the kernel's page table hierarchy
*/
-pde_t *vm_mkkvm(void);
+pde_t *vm_mkkvm( void );
/**
** Name: vm_mkuvm
**
** Create the page table hierarchy for a user process
*/
-pde_t *vm_mkuvm(void);
+pde_t *vm_mkuvm( void );
/**
** Name: vm_set_kvm
**
** Switch the page table register to the kernel's page directory
*/
-void vm_set_kvm(void);
+void vm_set_kvm( void );
/**
** Name: vm_set_uvm
@@ -425,7 +378,7 @@ void vm_set_kvm(void);
**
** @param p The PCB of the user process
*/
-void vm_set_uvm(pcb_t *p);
+void vm_set_uvm( pcb_t *p );
/**
** Name: vm_add
@@ -443,8 +396,8 @@ void vm_set_uvm(pcb_t *p);
**
** @return status of the allocation attempt
*/
-int vm_add(pde_t *pdir, bool_t wr, bool_t sys, void *va, uint32_t size,
- char *data, uint32_t bytes);
+int vm_add( pde_t *pdir, bool_t wr, bool_t sys,
+ void *va, uint32_t size, char *data, uint32_t bytes );
/**
** Name: vm_free
@@ -454,7 +407,7 @@ int vm_add(pde_t *pdir, bool_t wr, bool_t sys, void *va, uint32_t size,
**
** @param pdir Pointer to the page directory
*/
-void vm_free(pde_t *pdir);
+void vm_free( pde_t *pdir );
/*
** Name: vm_map
@@ -465,11 +418,11 @@ void vm_free(pde_t *pdir);
**
** @param pdir Page directory for this address space
** @param va The starting virtual address
-** @param pa The starting physical address
** @param size Length of the range to be mapped
+** @param pa The starting physical address
** @param perm Permission bits for the PTEs
*/
-int vm_map(pde_t *pdir, void *va, uint32_t pa, uint32_t size, int perm);
+int vm_map( pde_t *pdir, void *va, uint_t size, uint_t pa, int perm );
/**
** Name: vm_uvmdup
@@ -478,24 +431,13 @@ int vm_map(pde_t *pdir, void *va, uint32_t pa, uint32_t size, int perm);
** hierarchy. We assume that the "new" page directory exists and
** the system portions of it should not be touched.
**
-** @param new New page directory
** @param old Existing page directory
+** @param new New page directory
**
** @return status of the duplication attempt
*/
-int vm_uvmdup(pde_t *new, pde_t *old);
-
-/**
-** Name: vm_print
-**
-** Print out a paging hierarchy.
-**
-** @param pt Page table to display
-** @param dir Is it a page directory (vs. a page table)?
-** @param mode How to display the entries
-*/
-void vm_print(void *pt, bool_t dir, enum vmmode_e mode);
+int vm_uvmdup( pde_t *old, pde_t *new );
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/vmtables.h b/kernel/old/include/vmtables.h
index 83c0881..17f6e0a 100644
--- a/kernel/old/include/vmtables.h
+++ b/kernel/old/include/vmtables.h
@@ -38,6 +38,6 @@ extern pte_t id_map[];
extern mapping_t kmap[];
extern const uint32_t n_kmap;
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/x86/arch.h b/kernel/old/include/x86/arch.h
index df0b2e2..113c76b 100644
--- a/kernel/old/include/x86/arch.h
+++ b/kernel/old/include/x86/arch.h
@@ -15,25 +15,25 @@
/*
** Video stuff
*/
-#define VID_BASE_ADDR 0xB8000
+#define VID_BASE_ADDR 0xB8000
/*
** Memory management
*/
-#define SEG_PRESENT 0x80
-#define SEG_PL_0 0x00
-#define SEG_PL_1 0x20
-#define SEG_PL_2 0x40
-#define SEG_PL_3 0x50
-#define SEG_SYSTEM 0x00
-#define SEG_NON_SYSTEM 0x10
-#define SEG_32BIT 0x04
-#define DESC_IGATE 0x06
+#define SEG_PRESENT 0x80
+#define SEG_PL_0 0x00
+#define SEG_PL_1 0x20
+#define SEG_PL_2 0x40
+#define SEG_PL_3 0x50
+#define SEG_SYSTEM 0x00
+#define SEG_NON_SYSTEM 0x10
+#define SEG_32BIT 0x04
+#define DESC_IGATE 0x06
/*
** Exceptions
*/
-#define N_EXCEPTIONS 256
+#define N_EXCEPTIONS 256
/*
** Bit definitions in registers
@@ -41,94 +41,95 @@
** See IA-32 Intel Architecture SW Dev. Manual, Volume 3: System
** Programming Guide, page 2-8.
*/
+
/*
** EFLAGS
*/
-#define EFL_RSVD 0xffc00000 /* reserved */
-#define EFL_MB0 0x00008020 /* must be zero */
-#define EFL_MB1 0x00000002 /* must be 1 */
+#define EFL_RSVD 0xffc00000 /* reserved */
+#define EFL_MB0 0x00008020 /* must be zero */
+#define EFL_MB1 0x00000002 /* must be 1 */
-#define EFL_ID 0x00200000
-#define EFL_VIP 0x00100000
-#define EFL_VIF 0x00080000
-#define EFL_AC 0x00040000
-#define EFL_VM 0x00020000
-#define EFL_RF 0x00010000
-#define EFL_NT 0x00004000
+#define EFL_ID 0x00200000
+#define EFL_VIP 0x00100000
+#define EFL_VIF 0x00080000
+#define EFL_AC 0x00040000
+#define EFL_VM 0x00020000
+#define EFL_RF 0x00010000
+#define EFL_NT 0x00004000
#define EFL_IOPL 0x00003000
-#define EFL_OF 0x00000800
-#define EFL_DF 0x00000400
-#define EFL_IF 0x00000200
-#define EFL_TF 0x00000100
-#define EFL_SF 0x00000080
-#define EFL_ZF 0x00000040
-#define EFL_AF 0x00000010
-#define EFL_PF 0x00000004
-#define EFL_CF 0x00000001
+#define EFL_OF 0x00000800
+#define EFL_DF 0x00000400
+#define EFL_IF 0x00000200
+#define EFL_TF 0x00000100
+#define EFL_SF 0x00000080
+#define EFL_ZF 0x00000040
+#define EFL_AF 0x00000010
+#define EFL_PF 0x00000004
+#define EFL_CF 0x00000001
/*
** CR0, CR1, CR2, CR3, CR4
**
** IA-32 V3, page 2-12.
*/
-#define CR0_RSVD 0x1ffaffc0
-#define CR0_PG 0x80000000
-#define CR0_CD 0x40000000
-#define CR0_NW 0x20000000
-#define CR0_AM 0x00040000
-#define CR0_WP 0x00010000
-#define CR0_NE 0x00000020
-#define CR0_ET 0x00000010
-#define CR0_TS 0x00000008
-#define CR0_EM 0x00000004
-#define CR0_MP 0x00000002
-#define CR0_PE 0x00000001
+#define CR0_RSVD 0x1ffaffc0
+#define CR0_PG 0x80000000
+#define CR0_CD 0x40000000
+#define CR0_NW 0x20000000
+#define CR0_AM 0x00040000
+#define CR0_WP 0x00010000
+#define CR0_NE 0x00000020
+#define CR0_ET 0x00000010
+#define CR0_TS 0x00000008
+#define CR0_EM 0x00000004
+#define CR0_MP 0x00000002
+#define CR0_PE 0x00000001
-#define CR1_RSVD 0xffffffff
+#define CR1_RSVD 0xffffffff
-#define CR2_RSVD 0x00000000
+#define CR2_RSVD 0x00000000
#define CR2_PF_LIN_ADDR 0xffffffff
-#define CR3_RSVD 0x00000fe7
-#define CR3_PD_BASE 0xfffff000
-#define CR3_PCD 0x00000010
-#define CR3_PWT 0x00000008
+#define CR3_RSVD 0x00000fe7
+#define CR3_PD_BASE 0xfffff000
+#define CR3_PCD 0x00000010
+#define CR3_PWT 0x00000008
-#define CR4_RSVD 0xfd001000
-#define CR4_UINT 0x02000000
-#define CR4_PKS 0x01000000
-#define CR4_CET 0x00800000
-#define CR4_PKE 0x00400000
-#define CR4_SMAP 0x00200000
-#define CR4_SMEP 0x00100000
-#define CR4_KL 0x00080000
-#define CR4_OSXS 0x00040000
-#define CR4_PCID 0x00020000
-#define CR4_FSGS 0x00010000
-#define CR4_SMXE 0x00004000
-#define CR4_VMXE 0x00002000
-#define CR4_LA57 0x00001000
-#define CR4_UMIP 0x00000800
-#define CR4_OSXMMEXCPT 0x00000400
-#define CR4_OSFXSR 0x00000200
-#define CR4_PCE 0x00000100
-#define CR4_PGE 0x00000080
-#define CR4_MCE 0x00000040
-#define CR4_PAE 0x00000020
-#define CR4_PSE 0x00000010
-#define CR4_DE 0x00000008
-#define CR4_TSD 0x00000004
-#define CR4_PVI 0x00000002
-#define CR4_VME 0x00000001
+#define CR4_RSVD 0xfd001000
+#define CR4_UINT 0x02000000
+#define CR4_PKS 0x01000000
+#define CR4_CET 0x00800000
+#define CR4_PKE 0x00400000
+#define CR4_SMAP 0x00200000
+#define CR4_SMEP 0x00100000
+#define CR4_KL 0x00080000
+#define CR4_OSXS 0x00040000
+#define CR4_PCID 0x00020000
+#define CR4_FSGS 0x00010000
+#define CR4_SMXE 0x00004000
+#define CR4_VMXE 0x00002000
+#define CR4_LA57 0x00001000
+#define CR4_UMIP 0x00000800
+#define CR4_OSXMMEXCPT 0x00000400
+#define CR4_OSFXSR 0x00000200
+#define CR4_PCE 0x00000100
+#define CR4_PGE 0x00000080
+#define CR4_MCE 0x00000040
+#define CR4_PAE 0x00000020
+#define CR4_PSE 0x00000010
+#define CR4_DE 0x00000008
+#define CR4_TSD 0x00000004
+#define CR4_PVI 0x00000002
+#define CR4_VME 0x00000001
/*
** PMode segment selector field masks
**
** IA-32 V3, page 3-8.
*/
-#define SEG_SEL_IX_MASK 0xfff8
-#define SEG_SEL_TI_MASK 0x0004
-#define SEG_SEL_RPL_MASK 0x0003
+#define SEG_SEL_IX_MASK 0xfff8
+#define SEG_SEL_TI_MASK 0x0004
+#define SEG_SEL_RPL_MASK 0x0003
/*
** Segment descriptor bytes
@@ -141,6 +142,7 @@
** 4: base address 23:16
** 7: base address 31:24
*/
+
/*
** Byte 5: access control bits
** 7: present
@@ -148,43 +150,43 @@
** 4: system/user
** 3-0: type
*/
-#define SEG_ACCESS_P_MASK 0x80
-#define SEG_PRESENT 0x80
-#define SEG_NOT_PRESENT 0x00
+#define SEG_ACCESS_P_MASK 0x80
+# define SEG_PRESENT 0x80
+# define SEG_NOT_PRESENT 0x00
-#define SEG_ACCESS_DPL_MASK 0x60
-#define SEG_DPL_0 0x00
-#define SEG_DPL_1 0x20
-#define SEG_DPL_2 0x40
-#define SEG_DPL_3 0x60
+#define SEG_ACCESS_DPL_MASK 0x60
+# define SEG_DPL_0 0x00
+# define SEG_DPL_1 0x20
+# define SEG_DPL_2 0x40
+# define SEG_DPL_3 0x60
-#define SEG_ACCESS_S_MASK 0x10
-#define SEG_SYSTEM 0x00
-#define SEG_NON_SYSTEM 0x10
+#define SEG_ACCESS_S_MASK 0x10
+# define SEG_SYSTEM 0x00
+# define SEG_NON_SYSTEM 0x10
-#define SEG_TYPE_MASK 0x0f
-#define SEG_DATA_A_BIT 0x1
-#define SEG_DATA_W_BIT 0x2
-#define SEG_DATA_E_BIT 0x4
-#define SEG_CODE_A_BIT 0x1
-#define SEG_CODE_R_BIT 0x2
-#define SEG_CODE_C_BIT 0x4
-#define SEG_DATA_RO 0x0
-#define SEG_DATA_ROA 0x1
-#define SEG_DATA_RW 0x2
-#define SEG_DATA_RWA 0x3
-#define SEG_DATA_RO_XD 0x4
-#define SEG_DATA_RO_XDA 0x5
-#define SEG_DATA_RW_XW 0x6
-#define SEG_DATA_RW_XWA 0x7
-#define SEG_CODE_XO 0x8
-#define SEG_CODE_XOA 0x9
-#define SEG_CODE_XR 0xa
-#define SEG_CODE_XRA 0xb
-#define SEG_CODE_XO_C 0xc
-#define SEG_CODE_XO_CA 0xd
-#define SEG_CODE_XR_C 0xe
-#define SEG_CODE_XR_CA 0xf
+#define SEG_TYPE_MASK 0x0f
+# define SEG_DATA_A_BIT 0x1
+# define SEG_DATA_W_BIT 0x2
+# define SEG_DATA_E_BIT 0x4
+# define SEG_CODE_A_BIT 0x1
+# define SEG_CODE_R_BIT 0x2
+# define SEG_CODE_C_BIT 0x4
+# define SEG_DATA_RO 0x0
+# define SEG_DATA_ROA 0x1
+# define SEG_DATA_RW 0x2
+# define SEG_DATA_RWA 0x3
+# define SEG_DATA_RO_XD 0x4
+# define SEG_DATA_RO_XDA 0x5
+# define SEG_DATA_RW_XW 0x6
+# define SEG_DATA_RW_XWA 0x7
+# define SEG_CODE_XO 0x8
+# define SEG_CODE_XOA 0x9
+# define SEG_CODE_XR 0xa
+# define SEG_CODE_XRA 0xb
+# define SEG_CODE_XO_C 0xc
+# define SEG_CODE_XO_CA 0xd
+# define SEG_CODE_XR_C 0xe
+# define SEG_CODE_XR_CA 0xf
/*
** Byte 6: sizes
@@ -195,47 +197,48 @@
** 3-0: upper 4 bits of limit
** 7: base address 31:24
*/
-#define SEG_SIZE_G_MASK 0x80
-#define SEG_GRAN_BYTE 0x00
-#define SEG_GRAN_4KBYTE 0x80
+#define SEG_SIZE_G_MASK 0x80
+# define SEG_GRAN_BYTE 0x00
+# define SEG_GRAN_4KBYTE 0x80
-#define SEG_SIZE_D_B_MASK 0x40
-#define SEG_DB_16BIT 0x00
-#define SEG_DB_32BIT 0x40
+#define SEG_SIZE_D_B_MASK 0x40
+# define SEG_DB_16BIT 0x00
+# define SEG_DB_32BIT 0x40
-#define SEG_SIZE_L_MASK 0x20
-#define SEG_L_64BIT 0x20
-#define SEG_L_32BIT 0x00
+#define SEG_SIZE_L_MASK 0x20
+# define SEG_L_64BIT 0x20
+# define SEG_L_32BIT 0x00
-#define SEG_SIZE_AVL_MASK 0x10
+#define SEG_SIZE_AVL_MASK 0x10
#define SEG_SIZE_LIM_19_16_MASK 0x0f
+
/*
** System-segment and gate-descriptor types
**
** IA-32 V3, page 3-15.
*/
-// type 0: reserved
+ // type 0: reserved
#define SEG_SYS_16BIT_TSS_AVAIL 0x1
-#define SEG_SYS_LDT 0x2
-#define SEG_SYS_16BIT_TSS_BUSY 0x3
+#define SEG_SYS_LDT 0x2
+#define SEG_SYS_16BIT_TSS_BUSY 0x3
#define SEG_SYS_16BIT_CALL_GATE 0x4
-#define SEG_SYS_TASK_GATE 0x5
-#define SEG_SYS_16BIT_INT_GATE 0x6
+#define SEG_SYS_TASK_GATE 0x5
+#define SEG_SYS_16BIT_INT_GATE 0x6
#define SEG_SYS_16BIT_TRAP_GATE 0x7
-// type 8: reserved
+ // type 8: reserved
#define SEG_SYS_32BIT_TSS_AVAIL 0x9
-// type A: reserved
-#define SEG_SYS_32BIT_TSS_BUSY 0xb
+ // type A: reserved
+#define SEG_SYS_32BIT_TSS_BUSY 0xb
#define SEG_SYS_32BIT_CALL_GATE 0xc
-// type D: reserved
-#define SEG_SYS_32BIT_INT_GATE 0xe
+ // type D: reserved
+#define SEG_SYS_32BIT_INT_GATE 0xe
#define SEG_SYS_32BIT_TRAP_GATE 0xf
/*
** IDT Descriptors
-**
+**
** IA-32 V3, page 5-13.
**
** All have a segment selector in bytes 2 and 3; Task Gate descriptors
@@ -243,57 +246,58 @@
** and 7 devoted to the 16 bits of the Offset, with the low nybble of
** byte 4 reserved.
*/
-#define IDT_PRESENT 0x8000
-#define IDT_DPL_MASK 0x6000
-#define IDT_DPL_0 0x0000
-#define IDT_DPL_1 0x2000
-#define IDT_DPL_2 0x4000
-#define IDT_DPL_3 0x6000
-#define IDT_GATE_TYPE 0x0f00
-#define IDT_TASK_GATE 0x0500
-#define IDT_INT16_GATE 0x0600
-#define IDT_INT32_GATE 0x0e00
-#define IDT_TRAP16_GATE 0x0700
-#define IDT_TRAP32_GATE 0x0f00
+#define IDT_PRESENT 0x8000
+#define IDT_DPL_MASK 0x6000
+# define IDT_DPL_0 0x0000
+# define IDT_DPL_1 0x2000
+# define IDT_DPL_2 0x4000
+# define IDT_DPL_3 0x6000
+#define IDT_GATE_TYPE 0x0f00
+# define IDT_TASK_GATE 0x0500
+# define IDT_INT16_GATE 0x0600
+# define IDT_INT32_GATE 0x0e00
+# define IDT_TRAP16_GATE 0x0700
+# define IDT_TRAP32_GATE 0x0f00
/*
** Interrupt vectors
*/
+
// predefined by the architecture
-#define VEC_DIVIDE_ERROR 0x00
-#define VEC_DEBUG_EXCEPTION 0x01
-#define VEC_NMI_INTERRUPT 0x02
-#define VEC_BREAKPOINT 0x03
-#define VEC_OVERFLOW 0x04
-#define VEC_BOUND_RANGE_EXCEEDED 0x05
-#define VEC_INVALID_OPCODE 0x06
-#define VEC_DEVICE_NOT_AVAILABLE 0x07
-#define VEC_DOUBLE_FAULT 0x08
-#define VEC_COPROCESSOR_OVERRUN 0x09
-#define VEC_INVALID_TSS 0x0a
-#define VEC_SEGMENT_NOT_PRESENT 0x0b
-#define VEC_STACK_FAULT 0x0c
-#define VEC_GENERAL_PROTECTION 0x0d
-#define VEC_PAGE_FAULT 0x0e
+#define VEC_DIVIDE_ERROR 0x00
+#define VEC_DEBUG_EXCEPTION 0x01
+#define VEC_NMI_INTERRUPT 0x02
+#define VEC_BREAKPOINT 0x03
+#define VEC_OVERFLOW 0x04
+#define VEC_BOUND_RANGE_EXCEEDED 0x05
+#define VEC_INVALID_OPCODE 0x06
+#define VEC_DEVICE_NOT_AVAILABLE 0x07
+#define VEC_DOUBLE_FAULT 0x08
+#define VEC_COPROCESSOR_OVERRUN 0x09
+#define VEC_INVALID_TSS 0x0a
+#define VEC_SEGMENT_NOT_PRESENT 0x0b
+#define VEC_STACK_FAULT 0x0c
+#define VEC_GENERAL_PROTECTION 0x0d
+#define VEC_PAGE_FAULT 0x0e
// 0x0f is reserved - unused
-#define VEC_FPU_ERROR 0x10
-#define VEC_ALIGNMENT_CHECK 0x11
-#define VEC_MACHINE_CHECK 0x12
-#define VEC_SIMD_FP_EXCEPTION 0x13
-#define VEC_VIRT_EXCEPTION 0x14
-#define VEC_CTRL_PROT_EXCEPTION 0x15
+#define VEC_FPU_ERROR 0x10
+#define VEC_ALIGNMENT_CHECK 0x11
+#define VEC_MACHINE_CHECK 0x12
+#define VEC_SIMD_FP_EXCEPTION 0x13
+#define VEC_VIRT_EXCEPTION 0x14
+#define VEC_CTRL_PROT_EXCEPTION 0x15
// 0x16 through 0x1f are reserved
// 0x20 through 0xff are user-defined, non-reserved
// IRQ0 through IRQ15 will use vectors 0x20 through 0x2f
-#define VEC_TIMER 0x20
-#define VEC_KBD 0x21
-#define VEC_COM2 0x23
-#define VEC_COM1 0x24
-#define VEC_PARALLEL 0x25
-#define VEC_FLOPPY 0x26
-#define VEC_MYSTERY 0x27
-#define VEC_MOUSE 0x2c
+#define VEC_TIMER 0x20
+#define VEC_KBD 0x21
+#define VEC_COM2 0x23
+#define VEC_COM1 0x24
+#define VEC_PARALLEL 0x25
+#define VEC_FLOPPY 0x26
+#define VEC_MYSTERY 0x27
+#define VEC_MOUSE 0x2c
#endif
diff --git a/kernel/old/include/x86/bios.h b/kernel/old/include/x86/bios.h
new file mode 100644
index 0000000..a19e570
--- /dev/null
+++ b/kernel/old/include/x86/bios.h
@@ -0,0 +1,73 @@
+/*
+** @file bios.h
+**
+** @author Warren R. Carithers
+**
+** BIOS-related declarations
+*/
+
+#ifndef BIOS_H_
+#define BIOS_H_
+
+/*
+** BIOS-related memory addresses
+*/
+
+#define BIOS_BDA 0x0400
+
+/*
+** Selected BIOS interrupt numbers
+*/
+
+#define BIOS_TIMER 0x08
+#define BIOS_KBD 0x09
+#define BIOS_VIDEO 0x10
+#define BIOS_EQUIP 0x11
+#define BIOS_MSIZ 0x12
+#define BIOS_DISK 0x13
+#define BIOS_SERIAL 0x14
+#define BIOS_MISC 0x15
+#define BIOS_KBDSVC 0x16
+#define BIOS_PRTSVC 0x17
+#define BIOS_BOOT 0x19
+#define BIOS_RTCPCI 0x1a
+
+// BIOS video commands (AH)
+#define BV_W_ADV 0x0e
+
+// BIOS disk commands (AH)
+#define BD_RESET 0x00
+#define BD_CHECK 0x01
+#define BD_RDSECT 0x02
+#define BD_WRSECT 0x03
+#define BD_PARAMS 0x08
+
+// BIOS disk commands with parameters (AX)
+#define BD_READ(n) ((BD_RDSECT << 8) | (n))
+#define BD_READ1 0x0201
+
+// CMOS ports (used for masking NMIs)
+#define CMOS_ADDR 0x70
+#define CMOS_DATA 0x71
+
+// important related commands
+#define NMI_ENABLE 0x00
+#define NMI_DISABLE 0x80
+
+/*
+** Physical Memory Map Table (0000:2D00 - 0000:7c00)
+**
+** Primarily used with the BIOS_MISC interrupt
+*/
+#define MMAP_SEG 0x02D0
+#define MMAP_DISP 0x0000
+#define MMAP_ADDR ((MMAP_SEG << 4) + MMAP_DISP)
+#define MMAP_SECTORS 0x0a
+
+#define MMAP_ENT 24 /* bytes per entry */
+#define MMAP_MAX_ENTS (BOOT_ADDR - MMAP_ADDR - 4) / 24
+
+#define MMAP_CODE 0xE820 /* int 0x15 code */
+#define MMAP_MAGIC_NUM 0x534D4150 /* for 0xE820 interrupt */
+
+#endif
diff --git a/kernel/old/include/x86/ops.h b/kernel/old/include/x86/ops.h
index 81167a1..ad795b9 100644
--- a/kernel/old/include/x86/ops.h
+++ b/kernel/old/include/x86/ops.h
@@ -10,7 +10,7 @@
** MIT's xv6, https://github.com/mit-pdos/xv6-public
**
** Note: normally, GCC doesn't inline unless the optimization level is
-** over 1. This can be forced by adding
+** over 1. This can be forced by adding
**
** __attribute__((always_inline))
**
@@ -27,10 +27,10 @@
// control "forced" inlining
#ifdef FORCE_INLINING
-#define OPSINLINED __attribute__((always_inline))
+#define OPSINLINED __attribute__((always_inline))
#else
-#define OPSINLINED /* no-op */
-#endif /* FORCE_INLINING */
+#define OPSINLINED /* no-op */
+#endif /* FORCE_INLINING */
/****************************
** Data movement
@@ -47,33 +47,36 @@
** @param src Source buffer
** @param len Byte count
*/
-static inline void movsb(void *dst, const void *src, uint32_t len) OPSINLINED
+static inline void
+movsb( void* dst, const void* src, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep movsb"
- : "+D"(dst), "+S"(src), "+c"(len)
- :
- : "memory");
+ __asm__ __volatile__( "cld; rep movsb"
+ : "+D"(dst), "+S"(src), "+c"(len)
+ : : "memory" );
}
-static inline void movsw(void *dst, const void *src, uint32_t len) OPSINLINED
+
+static inline void
+movsw( void* dst, const void* src, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep movsw"
- : "+D"(dst), "+S"(src), "+c"(len)
- :
- : "memory");
+ __asm__ __volatile__( "cld; rep movsw"
+ : "+D"(dst), "+S"(src), "+c"(len)
+ : : "memory" );
}
-static inline void movsl(void *dst, const void *src, uint32_t len) OPSINLINED
+
+static inline void
+movsl( void* dst, const void* src, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep movsl"
- : "+D"(dst), "+S"(src), "+c"(len)
- :
- : "memory");
+ __asm__ __volatile__( "cld; rep movsl"
+ : "+D"(dst), "+S"(src), "+c"(len)
+ : : "memory" );
}
-static inline void movsq(void *dst, const void *src, uint32_t len) OPSINLINED
+
+static inline void
+movsq( void* dst, const void* src, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep movsq"
- : "+D"(dst), "+S"(src), "+c"(len)
- :
- : "memory");
+ __asm__ __volatile__( "cld; rep movsq"
+ : "+D"(dst), "+S"(src), "+c"(len)
+ : : "memory" );
}
/**
@@ -87,26 +90,31 @@ static inline void movsq(void *dst, const void *src, uint32_t len) OPSINLINED
** @param val Data to copy
** @param len Byte count
*/
-static inline void stosb(void *dst, uint8_t val, uint32_t len) OPSINLINED
+static inline void
+stosb( void *dst, uint8_t val, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep stosb"
- : "=D"(dst), "=c"(len)
- : "0"(dst), "1"(len), "a"(val)
- : "memory", "cc");
+ __asm__ __volatile__( "cld; rep stosb"
+ : "=D" (dst), "=c" (len)
+ : "0" (dst), "1" (len), "a" (val)
+ : "memory", "cc" );
}
-static inline void stosw(void *dst, uint16_t val, uint32_t len) OPSINLINED
+
+static inline void
+stosw( void *dst, uint16_t val, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep stos2"
- : "=D"(dst), "=c"(len)
- : "0"(dst), "1"(len), "a"(val)
- : "memory", "cc");
+ __asm__ __volatile__( "cld; rep stos2"
+ : "=D" (dst), "=c" (len)
+ : "0" (dst), "1" (len), "a" (val)
+ : "memory", "cc" );
}
-static inline void stosl(void *dst, uint32_t val, uint32_t len) OPSINLINED
+
+static inline void
+stosl( void *dst, uint32_t val, uint32_t len ) OPSINLINED
{
- __asm__ __volatile__("cld; rep stosl"
- : "=D"(dst), "=c"(len)
- : "0"(dst), "1"(len), "a"(val)
- : "memory", "cc");
+ __asm__ __volatile__( "cld; rep stosl"
+ : "=D" (dst), "=c" (len)
+ : "0" (dst), "1" (len), "a" (val)
+ : "memory", "cc" );
}
/****************************
@@ -123,46 +131,59 @@ static inline void stosl(void *dst, uint32_t val, uint32_t len) OPSINLINED
**
** @return Contents of the register
*/
-static inline uint32_t r_cr0(void) OPSINLINED
+static inline uint32_t
+r_cr0( void ) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%cr0,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%cr0,%0" : "=r" (val) );
return val;
}
-static inline uint32_t r_cr2(void) OPSINLINED
+
+static inline uint32_t
+r_cr2( void ) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%cr2,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%cr2,%0" : "=r" (val) );
return val;
}
-static inline uint32_t r_cr3(void) OPSINLINED
+
+static inline uint32_t
+r_cr3( void ) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%cr3,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%cr3,%0" : "=r" (val) );
return val;
}
-static inline uint32_t r_cr4(void) OPSINLINED
+
+static inline uint32_t
+r_cr4( void ) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%cr4,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%cr4,%0" : "=r" (val) );
return val;
}
-static inline uint32_t r_eflags(void) OPSINLINED
+
+static inline uint32_t
+r_eflags(void) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("pushfl; popl %0" : "=r"(val));
+ __asm__ __volatile__( "pushfl; popl %0" : "=r" (val) );
return val;
}
-static inline uint32_t r_ebp(void) OPSINLINED
+
+static inline uint32_t
+r_ebp(void) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%ebp,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%ebp,%0" : "=r" (val) );
return val;
}
-static inline uint32_t r_esp(void) OPSINLINED
+
+static inline uint32_t
+r_esp(void) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl %%esp,%0" : "=r"(val));
+ __asm__ __volatile__( "movl %%esp,%0" : "=r" (val) );
return val;
}
@@ -173,25 +194,34 @@ static inline uint32_t r_esp(void) OPSINLINED
**
** Description: Writes a value into the CR indicated by its name
*/
-static inline void w_cr0(uint32_t val) OPSINLINED
+static inline void
+w_cr0( uint32_t val ) OPSINLINED
{
- __asm__ __volatile__("movl %0,%%cr0" : : "r"(val));
+ __asm__ __volatile__( "movl %0,%%cr0" : : "r" (val) );
}
-static inline void w_cr2(uint32_t val) OPSINLINED
+
+static inline void
+w_cr2( uint32_t val ) OPSINLINED
{
- __asm__ __volatile__("movl %0,%%cr2" : : "r"(val));
+ __asm__ __volatile__( "movl %0,%%cr2" : : "r" (val) );
}
-static inline void w_cr3(uint32_t val) OPSINLINED
+
+static inline void
+w_cr3( uint32_t val ) OPSINLINED
{
- __asm__ __volatile__("movl %0,%%cr3" : : "r"(val));
+ __asm__ __volatile__( "movl %0,%%cr3" : : "r" (val) );
}
-static inline void w_cr4(uint32_t val) OPSINLINED
+
+static inline void
+w_cr4( uint32_t val ) OPSINLINED
{
- __asm__ __volatile__("movl %0,%%cr4" : : "r"(val));
+ __asm__ __volatile__( "movl %0,%%cr4" : : "r" (val) );
}
-static inline void w_eflags(uint32_t eflags) OPSINLINED
+
+static inline void
+w_eflags(uint32_t eflags) OPSINLINED
{
- __asm__ __volatile__("pushl %0; popfl" : : "r"(eflags));
+ __asm__ __volatile__( "pushl %0; popfl" : : "r" (eflags) );
}
/**
@@ -203,13 +233,16 @@ static inline void w_eflags(uint32_t eflags) OPSINLINED
**
** @param addr The value to be loaded into the register
*/
-static inline void w_gdt(void *addr) OPSINLINED
+static inline void
+w_gdt( void *addr ) OPSINLINED
{
- __asm__ __volatile__("lgdt (%0)" : : "r"(addr));
+ __asm__ __volatile__( "lgdt (%0)" : : "r" (addr) );
}
-static inline void w_idt(void *addr) OPSINLINED
+
+static inline void
+w_idt( void *addr ) OPSINLINED
{
- __asm__ __volatile__("lidt (%0)" : : "r"(addr));
+ __asm__ __volatile__( "lidt (%0)" : : "r" (addr) );
}
/**
@@ -223,21 +256,19 @@ static inline void w_idt(void *addr) OPSINLINED
** @param cp Pointer to where %ecx contents should be saved, or NULL
** @param dp Pointer to where %edx contents should be saved, or NULL
*/
-static inline void cpuid(uint32_t op, uint32_t *ap, uint32_t *bp, uint32_t *cp,
- uint32_t *dp) OPSINLINED
+static inline void
+cpuid( uint32_t op, uint32_t *ap, uint32_t *bp,
+ uint32_t *cp, uint32_t *dp ) OPSINLINED
{
uint32_t eax, ebx, ecx, edx;
- __asm__ __volatile__("cpuid"
- : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
- : "a"(op));
- if (ap)
- *ap = eax;
- if (bp)
- *bp = ebx;
- if (cp)
- *cp = ecx;
- if (dp)
- *dp = edx;
+ __asm__ __volatile__( "cpuid"
+ : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
+ : "a" (op) );
+
+ if( ap ) *ap = eax;
+ if( bp ) *bp = ebx;
+ if( cp ) *cp = ecx;
+ if( dp ) *dp = edx;
}
/****************************
@@ -251,9 +282,10 @@ static inline void cpuid(uint32_t op, uint32_t *ap, uint32_t *bp, uint32_t *cp,
**
** @param addr An address within the page to be flushed
*/
-static inline void invlpg(uint32_t addr) OPSINLINED
+static inline void
+invlpg( uint32_t addr ) OPSINLINED
{
- __asm__ __volatile__("invlpg (%0)" : : "r"(addr) : "memory");
+ __asm__ __volatile__( "invlpg (%0)" : : "r" (addr) : "memory" );
}
/**
@@ -263,11 +295,12 @@ static inline void invlpg(uint32_t addr) OPSINLINED
**
** We do this by changing CR3.
*/
-static inline void flushtlb(void) OPSINLINED
+static inline void
+flushtlb( void ) OPSINLINED
{
uint32_t cr3;
- __asm__ __volatile__("movl %%cr3,%0" : "=r"(cr3));
- __asm__ __volatile__("movl %0,%%cr2" : : "r"(cr3));
+ __asm__ __volatile__( "movl %%cr3,%0" : "=r" (cr3) );
+ __asm__ __volatile__( "movl %0,%%cr2" : : "r" (cr3) );
}
/****************************
@@ -285,22 +318,27 @@ static inline void flushtlb(void) OPSINLINED
**
** @return The data read from the specified port
*/
-static inline uint8_t inb(int port) OPSINLINED
+static inline uint8_t
+inb( int port ) OPSINLINED
{
uint8_t data;
- __asm__ __volatile__("inb %w1,%0" : "=a"(data) : "d"(port));
+ __asm__ __volatile__( "inb %w1,%0" : "=a" (data) : "d" (port) );
return data;
}
-static inline uint16_t inw(int port) OPSINLINED
+
+static inline uint16_t
+inw( int port ) OPSINLINED
{
uint16_t data;
- __asm__ __volatile__("inw %w1,%0" : "=a"(data) : "d"(port));
+ __asm__ __volatile__( "inw %w1,%0" : "=a" (data) : "d" (port) );
return data;
}
-static inline uint32_t inl(int port) OPSINLINED
+
+static inline uint32_t
+inl( int port ) OPSINLINED
{
uint32_t data;
- __asm__ __volatile__("inl %w1,%0" : "=a"(data) : "d"(port));
+ __asm__ __volatile__( "inl %w1,%0" : "=a" (data) : "d" (port) );
return data;
}
@@ -316,17 +354,22 @@ static inline uint32_t inl(int port) OPSINLINED
**
** @return The data read from the specified port
*/
-static inline void outb(int port, uint8_t data) OPSINLINED
+static inline void
+outb( int port, uint8_t data ) OPSINLINED
{
- __asm__ __volatile__("outb %0,%w1" : : "a"(data), "d"(port));
+ __asm__ __volatile__( "outb %0,%w1" : : "a" (data), "d" (port) );
}
-static inline void outw(int port, uint16_t data) OPSINLINED
+
+static inline void
+outw( int port, uint16_t data ) OPSINLINED
{
- __asm__ __volatile__("outw %0,%w1" : : "a"(data), "d"(port));
+ __asm__ __volatile__( "outw %0,%w1" : : "a" (data), "d" (port) );
}
-static inline void outl(int port, uint32_t data) OPSINLINED
+
+static inline void
+outl( int port, uint32_t data ) OPSINLINED
{
- __asm__ __volatile__("outl %0,%w1" : : "a"(data), "d"(port));
+ __asm__ __volatile__( "outl %0,%w1" : : "a" (data), "d" (port) );
}
/****************************
@@ -338,9 +381,10 @@ static inline void outl(int port, uint32_t data) OPSINLINED
**
** Description: Cause a breakpoint interrupt for debugging purposes
*/
-static inline void breakpoint(void) OPSINLINED
+static inline void
+breakpoint( void ) OPSINLINED
{
- __asm__ __volatile__("int3");
+ __asm__ __volatile__( "int3" );
}
/**
@@ -351,10 +395,11 @@ static inline void breakpoint(void) OPSINLINED
**
** @return The address the calling routine will return to as a uint32_t
*/
-static inline uint32_t get_ra(void) OPSINLINED
+static inline uint32_t
+get_ra( void ) OPSINLINED
{
uint32_t val;
- __asm__ __volatile__("movl 4(%%ebp),%0" : "=r"(val));
+ __asm__ __volatile__( "movl 4(%%ebp),%0" : "=r" (val) );
return val;
}
@@ -363,11 +408,13 @@ static inline uint32_t get_ra(void) OPSINLINED
**
** Description: Pause until something happens
*/
-static inline void ev_wait(void) OPSINLINED
+static inline void
+ev_wait( void ) OPSINLINED
{
- __asm__ __volatile__("sti ; hlt");
+ __asm__ __volatile__( "sti ; hlt" );
}
+
/**
** Name: xchgl
**
@@ -378,18 +425,19 @@ static inline void ev_wait(void) OPSINLINED
**
** @return The old contents of the memory location
*/
-static inline uint32_t xchgl(volatile uint32_t *addr, uint32_t data) OPSINLINED
+static inline uint32_t
+xchgl( volatile uint32_t *addr, uint32_t data ) OPSINLINED
{
uint32_t old;
// + indicates a read-modify-write operand
- __asm__ __volatile__("lock; xchgl %0, %1"
- : "+m"(*addr), "=a"(old)
- : "1"(data)
- : "cc");
+ __asm__ __volatile__( "lock; xchgl %0, %1"
+ : "+m" (*addr), "=a" (old)
+ : "1" (data)
+ : "cc");
return old;
}
-#endif /* !ASM_SRC */
+#endif /* !ASM_SRC */
#endif
diff --git a/kernel/old/include/x86/pic.h b/kernel/old/include/x86/pic.h
index ae3fe6c..d4fa93b 100644
--- a/kernel/old/include/x86/pic.h
+++ b/kernel/old/include/x86/pic.h
@@ -16,14 +16,15 @@
** Our expected configuration is two PICs, with the secondary connected
** through the IRQ2 pin of the primary.
*/
+
/*
** Port addresses for the command port and interrupt mask register port
** for both the primary and secondary PICs.
*/
-#define PIC1_CMD 0x20 // primary command
-#define PIC1_DATA (PIC1_CMD + 1) // primary data / int mask register
-#define PIC2_CMD 0xA0 // secondary command
-#define PIC2_DATA (PIC2_CMD + 1) // secondary data / int mask register
+#define PIC1_CMD 0x20 // primary command
+#define PIC1_DATA (PIC1_CMD + 1) // primary data / int mask register
+#define PIC2_CMD 0xA0 // secondary command
+#define PIC2_DATA (PIC2_CMD + 1) // secondary data / int mask register
/*
** Initialization Command Word (ICW) definitions
@@ -41,96 +42,98 @@
** PIC2_* defines are intended for the secondary PIC
** PIC_* defines are sent to both PICs
*/
+
/*
** ICW1: initialization, send to command port
*/
-#define PIC_CW1_INIT 0x10 // start initialization sequence
-#define PIC_CW1_NEED4 0x01 // ICW4 will also be set
-#define PIC_CW1_SINGLE 0x02 // select single (vs. cascade) mode
-#define PIC_CW1_INTVAL 0x04 // set call interval to 4 (vs. 8)
-#define PIC_CW1_LEVEL 0x08 // use level-triggered mode (vs. edge)
+#define PIC_CW1_INIT 0x10 // start initialization sequence
+#define PIC_CW1_NEED4 0x01 // ICW4 will also be set
+#define PIC_CW1_SINGLE 0x02 // select single (vs. cascade) mode
+#define PIC_CW1_INTVAL 0x04 // set call interval to 4 (vs. 8)
+#define PIC_CW1_LEVEL 0x08 // use level-triggered mode (vs. edge)
/*
** ICW2: interrupt vector base offsets, send to data port
*/
-#define PIC1_CW2_VECBASE 0x20 // IRQ0 int vector number
-#define PIC2_CW2_VECBASE 0x28 // IRQ8 int vector number
+#define PIC1_CW2_VECBASE 0x20 // IRQ0 int vector number
+#define PIC2_CW2_VECBASE 0x28 // IRQ8 int vector number
/*
** ICW3: secondary::primary attachment, send to data port
*/
-#define PIC1_CW3_SEC_IRQ2 0x04 // bit mask: secondary is on pin 2
-#define PIC2_CW3_SEC_ID 0x02 // integer: secondary id
+#define PIC1_CW3_SEC_IRQ2 0x04 // bit mask: secondary is on pin 2
+#define PIC2_CW3_SEC_ID 0x02 // integer: secondary id
/*
** ICW4: operating mode, send to data port
*/
-#define PIC_CW4_PM86 0x01 // 8086 mode (vs. 8080/8085)
-#define PIC_CW4_AUTOEOI 0x02 // do auto eoi's
-#define PIC_CW4_UNBUF 0x00 // unbuffered mode
-#define PIC_CW4_SEC_BUF 0x08 // put secondary in buffered mode
-#define PIC_CW4_PRI_BUF 0x0C // put primary in buffered mode
-#define PIC_CW4_SFNMODE 0x10 // "special fully nested" mode
+#define PIC_CW4_PM86 0x01 // 8086 mode (vs. 8080/8085)
+#define PIC_CW4_AUTOEOI 0x02 // do auto eoi's
+#define PIC_CW4_UNBUF 0x00 // unbuffered mode
+#define PIC_CW4_SEC_BUF 0x08 // put secondary in buffered mode
+#define PIC_CW4_PRI_BUF 0x0C // put primary in buffered mode
+#define PIC_CW4_SFNMODE 0x10 // "special fully nested" mode
/*
** Operation Control Words (OCWs)
**
** After the init sequence, can send these
*/
+
/*
** OCW1: interrupt mask; send to data port
*/
-#define PIC_MASK_NONE 0x00 // allow all interrupts
-#define PIC_MASK_NO_IRQ0 0x01 // prevent IRQ0 interrupts
-#define PIC_MASK_NO_IRQ1 0x02 // prevent IRQ1 interrupts
-#define PIC_MASK_NO_IRQ2 0x04 // prevent IRQ2 interrupts
-#define PIC_MASK_NO_IRQ3 0x08 // prevent IRQ3 interrupts
-#define PIC_MASK_NO_IRQ4 0x10 // prevent IRQ4 interrupts
-#define PIC_MASK_NO_IRQ5 0x20 // prevent IRQ5 interrupts
-#define PIC_MASK_NO_IRQ6 0x40 // prevent IRQ6 interrupts
-#define PIC_MASK_NO_IRQ7 0x80 // prevent IRQ7 interrupts
-#define PIC_MASK_ALL 0xff // prevent all interrupts
+#define PIC_MASK_NONE 0x00 // allow all interrupts
+#define PIC_MASK_NO_IRQ0 0x01 // prevent IRQ0 interrupts
+#define PIC_MASK_NO_IRQ1 0x02 // prevent IRQ1 interrupts
+#define PIC_MASK_NO_IRQ2 0x04 // prevent IRQ2 interrupts
+#define PIC_MASK_NO_IRQ3 0x08 // prevent IRQ3 interrupts
+#define PIC_MASK_NO_IRQ4 0x10 // prevent IRQ4 interrupts
+#define PIC_MASK_NO_IRQ5 0x20 // prevent IRQ5 interrupts
+#define PIC_MASK_NO_IRQ6 0x40 // prevent IRQ6 interrupts
+#define PIC_MASK_NO_IRQ7 0x80 // prevent IRQ7 interrupts
+#define PIC_MASK_ALL 0xff // prevent all interrupts
/*
** OCW2: EOI control, interrupt level; send to command port
*/
-#define PIC_LVL_0 0x00 // act on IRQ level 0
-#define PIC_LVL_1 0x01 // act on IRQ level 1
-#define PIC_LVL_2 0x02 // act on IRQ level 2
-#define PIC_LVL_3 0x03 // act on IRQ level 3
-#define PIC_LVL_4 0x04 // act on IRQ level 4
-#define PIC_LVL_5 0x05 // act on IRQ level 5
-#define PIC_LVL_6 0x06 // act on IRQ level 6
-#define PIC_LVL_7 0x07 // act on IRQ level 7
+#define PIC_LVL_0 0x00 // act on IRQ level 0
+#define PIC_LVL_1 0x01 // act on IRQ level 1
+#define PIC_LVL_2 0x02 // act on IRQ level 2
+#define PIC_LVL_3 0x03 // act on IRQ level 3
+#define PIC_LVL_4 0x04 // act on IRQ level 4
+#define PIC_LVL_5 0x05 // act on IRQ level 5
+#define PIC_LVL_6 0x06 // act on IRQ level 6
+#define PIC_LVL_7 0x07 // act on IRQ level 7
-#define PIC_EOI_NON_SPEC 0x20 // non-specific EOI command
-#define PIC_EOI PIC_EOI_NON_SPEC
+#define PIC_EOI_NON_SPEC 0x20 // non-specific EOI command
+# define PIC_EOI PIC_EOI_NON_SPEC
-#define PIC_EOI_SPEC 0x60 // specific EOI command
-#define PIC_SEOI PIC_EOI_SPEC
-#define PIC_SEOI_LVL0 (PIC_EOI_SPEC | PIC_LVL_0)
-#define PIC_SEOI_LVL1 (PIC_EOI_SPEC | PIC_LVL_1)
-#define PIC_SEOI_LVL2 (PIC_EOI_SPEC | PIC_LVL_2)
-#define PIC_SEOI_LVL3 (PIC_EOI_SPEC | PIC_LVL_3)
-#define PIC_SEOI_LVL4 (PIC_EOI_SPEC | PIC_LVL_4)
-#define PIC_SEOI_LVL5 (PIC_EOI_SPEC | PIC_LVL_5)
-#define PIC_SEOI_LVL6 (PIC_EOI_SPEC | PIC_LVL_6)
-#define PIC_SEOI_LVL7 (PIC_EOI_SPEC | PIC_LVL_7)
+#define PIC_EOI_SPEC 0x60 // specific EOI command
+# define PIC_SEOI PIC_EOI_SPEC
+# define PIC_SEOI_LVL0 (PIC_EOI_SPEC | PIC_LVL_0)
+# define PIC_SEOI_LVL1 (PIC_EOI_SPEC | PIC_LVL_1)
+# define PIC_SEOI_LVL2 (PIC_EOI_SPEC | PIC_LVL_2)
+# define PIC_SEOI_LVL3 (PIC_EOI_SPEC | PIC_LVL_3)
+# define PIC_SEOI_LVL4 (PIC_EOI_SPEC | PIC_LVL_4)
+# define PIC_SEOI_LVL5 (PIC_EOI_SPEC | PIC_LVL_5)
+# define PIC_SEOI_LVL6 (PIC_EOI_SPEC | PIC_LVL_6)
+# define PIC_SEOI_LVL7 (PIC_EOI_SPEC | PIC_LVL_7)
-#define PIC_EOI_ROT_NONSP 0xa0 // rotate on non-spec EOI cmd
-#define PIC_EOI_SET_ROT_AUTO 0x80 // set "rotate in auto EOI mode"
-#define PIC_EOI_CLR_ROT_AUTO 0x00 // clear "rotate in auto EOI mode"
-#define PIC_EOI_ROT_SPEC 0xe0 // rotate on spec EOI cmd (+ level)
-#define PIC_EOI_SET_PRIO 0xc0 // set priority (+ level)
-#define PIC_EOI_NOP 0x40 // no operation
+#define PIC_EOI_ROT_NONSP 0xa0 // rotate on non-spec EOI cmd
+#define PIC_EOI_SET_ROT_AUTO 0x80 // set "rotate in auto EOI mode"
+#define PIC_EOI_CLR_ROT_AUTO 0x00 // clear "rotate in auto EOI mode"
+#define PIC_EOI_ROT_SPEC 0xe0 // rotate on spec EOI cmd (+ level)
+#define PIC_EOI_SET_PRIO 0xc0 // set priority (+ level)
+#define PIC_EOI_NOP 0x40 // no operation
/*
-** OCW3: read requests, special mask mode; send to command port
+** OCW3: read requests, special mask mode; send to command port
*/
-#define PIC_READIRR 0x0a // read the IR register
-#define PIC_READISR 0x0b // read the IS register
-#define PIC_POLL 0x0c // poll
-#define PIC_MASK_RESET 0x48 // reset special mask mode
-#define PIC_MASK_SET 0x68 // set special mask mode
+#define PIC_READIRR 0x0a // read the IR register
+#define PIC_READISR 0x0b // read the IS register
+#define PIC_POLL 0x0c // poll
+#define PIC_MASK_RESET 0x48 // reset special mask mode
+#define PIC_MASK_SET 0x68 // set special mask mode
#endif
diff --git a/kernel/old/include/x86/pit.h b/kernel/old/include/x86/pit.h
index 0c54539..269fcec 100644
--- a/kernel/old/include/x86/pit.h
+++ b/kernel/old/include/x86/pit.h
@@ -12,6 +12,7 @@
#ifndef X86PIT_H_
#define X86PIT_H_
+
/*
** Hardware timer (Intel 8254 Programmable Interval Timer)
**
@@ -25,57 +26,57 @@
** M - mode
** BCD - binary or BCD counter
*/
+
/* Frequency settings */
-#define PIT_DEFAULT_TICKS_PER_SECOND 18 // actually 18.2065Hz
-#define PIT_DEFAULT_MS_PER_TICK (1000 / PIT_DEFAULT_TICKS_PER_SECOND)
-#define PIT_FREQ 1193182 // clock cycles/sec
+#define PIT_DEFAULT_TICKS_PER_SECOND 18 // actually 18.2065Hz
+#define PIT_DEFAULT_MS_PER_TICK (1000/PIT_DEFAULT_TICKS_PER_SECOND)
+#define PIT_FREQ 1193182 // clock cycles/sec
/* Port assignments */
-#define PIT_BASE_PORT 0x40 // I/O port for the timer
-#define PIT_0_PORT (PIT_BASE_PORT)
-#define PIT_1_PORT (PIT_BASE_PORT + 1)
-#define PIT_2_PORT (PIT_BASE_PORT + 2)
-#define PIT_CONTROL_PORT (PIT_BASE_PORT + 3)
+#define PIT_BASE_PORT 0x40 // I/O port for the timer
+# define PIT_0_PORT (PIT_BASE_PORT)
+# define PIT_1_PORT (PIT_BASE_PORT+1)
+# define PIT_2_PORT (PIT_BASE_PORT+2)
+# define PIT_CONTROL_PORT (PIT_BASE_PORT+3)
/* BCD field */
-#define PIT_USE_DECIMAL 0x00 // 16-bit binary counter (default)
-#define PIT_USE_BCD 0x01 // BCD counter
+#define PIT_USE_DECIMAL 0x00 // 16-bit binary counter (default)
+#define PIT_USE_BCD 0x01 // BCD counter
/* Timer modes */
-#define PIT_MODE_0 0x00 // int on terminal count
-#define PIT_MODE_1 0x02 // one-shot
-#define PIT_MODE_2 0x04 // divide-by-N
-#define PIT_MODE_3 0x06 // square-wave
-#define PIT_MODE_4 0x08 // software strobe
-#define PIT_MODE_5 0x0a // hardware strobe
+#define PIT_MODE_0 0x00 // int on terminal count
+#define PIT_MODE_1 0x02 // one-shot
+#define PIT_MODE_2 0x04 // divide-by-N
+#define PIT_MODE_3 0x06 // square-wave
+#define PIT_MODE_4 0x08 // software strobe
+#define PIT_MODE_5 0x0a // hardware strobe
/* Timer 0 settings */
-#define PIT_0_SELECT 0x00 // select timer 0
-#define PIT_0_LOAD 0x30 // load LSB, then MSB
-#define PIT_0_NDIV PIT_MODE_2 // divide-by-N counter
-#define PIT_0_SQUARE PIT_MODE_3 // square-wave mode
-#define PIT_0_ENDSIGNAL 0x00 // assert OUT at end of count
+#define PIT_0_SELECT 0x00 // select timer 0
+#define PIT_0_LOAD 0x30 // load LSB, then MSB
+#define PIT_0_NDIV PIT_MODE_2 // divide-by-N counter
+#define PIT_0_SQUARE PIT_MODE_3 // square-wave mode
+#define PIT_0_ENDSIGNAL 0x00 // assert OUT at end of count
/* Timer 1 settings */
-#define PIT_1_SELECT 0x40 // select timer 1
-#define PIT_1_READ 0x30 // read/load LSB then MSB
-#define PIT_1_RATE 0x06 // square-wave, for USART
+#define PIT_1_SELECT 0x40 // select timer 1
+#define PIT_1_READ 0x30 // read/load LSB then MSB
+#define PIT_1_RATE 0x06 // square-wave, for USART
/* Timer 2 settings */
-#define PIT_2_SELECT 0x80 // select timer 1
-#define PIT_2_READ 0x30 // read/load LSB then MSB
-#define PIT_2_RATE 0x06 // square-wave, for USART
+#define PIT_2_SELECT 0x80 // select timer 1
+#define PIT_2_READ 0x30 // read/load LSB then MSB
+#define PIT_2_RATE 0x06 // square-wave, for USART
/* Timer read-back */
-
-#define PIT_READBACK 0xc0 // perform a read-back
-#define PIT_RB_NOT_COUNT 0x20 // don't latch the count
-#define PIT_RB_NOT_STATUS 0x10 // don't latch the status
-#define PIT_RB_CHAN_2 0x08 // read back channel 2
-#define PIT_RB_CHAN_1 0x04 // read back channel 1
-#define PIT_RB_CHAN_0 0x02 // read back channel 0
-#define PIT_RB_ACCESS_MASK 0x30 // access mode field
-#define PIT_RB_OP_MASK 0x0e // oper mode field
-#define PIT_RB_BCD_MASK 0x01 // BCD mode field
+#define PIT_READBACK 0xc0 // perform a read-back
+#define PIT_RB_NOT_COUNT 0x20 // don't latch the count
+#define PIT_RB_NOT_STATUS 0x10 // don't latch the status
+#define PIT_RB_CHAN_2 0x08 // read back channel 2
+#define PIT_RB_CHAN_1 0x04 // read back channel 1
+#define PIT_RB_CHAN_0 0x02 // read back channel 0
+#define PIT_RB_ACCESS_MASK 0x30 // access mode field
+#define PIT_RB_OP_MASK 0x0e // oper mode field
+#define PIT_RB_BCD_MASK 0x01 // BCD mode field
#endif
diff --git a/kernel/old/include/x86/uart.h b/kernel/old/include/x86/uart.h
index 293b7b7..0c6194b 100644
--- a/kernel/old/include/x86/uart.h
+++ b/kernel/old/include/x86/uart.h
@@ -20,7 +20,7 @@
*/
#ifndef UART_H
-#define UART_H
+#define UART_H
/*********************************************************************
***************************** I/O PORTS ******************************
@@ -29,14 +29,14 @@
/*
** Base port number assigned to the device
*/
-#define UA4_COM1_PORT 0x3f8
-#define UA4_COM2_PORT 0x2f8
-#define UA4_COM3_PORT 0x3e8
-#define UA4_COM4_PORT 0x2e8
+#define UA4_COM1_PORT 0x3f8
+#define UA4_COM2_PORT 0x2f8
+#define UA4_COM3_PORT 0x3e8
+#define UA4_COM4_PORT 0x2e8
// short name for the one we'll use
-#define UA4_PORT UA4_COM1_PORT
-#define UA5_PORT UA4_COM1_PORT
+#define UA4_PORT UA4_COM1_PORT
+#define UA5_PORT UA4_COM1_PORT
/*
** Registers
@@ -47,7 +47,7 @@
** Index Register(s)
** ===== =========================================
** 0 Receiver Data (RO), Transmitter Data (WO)
-** 1 Interrupt Enable
+** 1 Interrupt Enable
** 2 Interrupt ID (RO), FIFO Control (WO)
** 3 Line Control, Divisor Latch
** 4 Modem Control
@@ -66,156 +66,157 @@
** accessed (0 selects Line Control, 1 selects Divisor Latch), with the
** remaining bits selecting fields within the indicated register.
*/
+
/*
** Receiver Data Register (read-only)
*/
-#define UA4_RXD (UA4_PORT + 0)
-#define UA4_RX_DATA UA4_RXD
+#define UA4_RXD (UA4_PORT+0)
+# define UA4_RX_DATA UA4_RXD
/*
** Transmitter Data Register (write-only)
*/
-#define UA4_TXD (UA4_PORT + 0)
-#define UA4_TX_DATA UA4_TXD
+#define UA4_TXD (UA4_PORT+0)
+# define UA4_TX_DATA UA4_TXD
/*
** Interrupt Enable Register
*/
-#define UA4_IER (UA4_PORT + 1)
-#define UA4_INT_ENABLE_REG UA4_IER
+#define UA4_IER (UA4_PORT+1)
+# define UA4_INT_ENABLE_REG UA4_IER
// fields
-#define UA4_IER_RX_IE 0x01 // Rcvr High-Data-Level Int Enable
-#define UA4_IER_TX_IE 0x02 // Xmitter Low-data-level Int Enable
-#define UA4_IER_LS_IE 0x04 // Line Status Int Enable
-#define UA4_IER_MS_IE 0x08 // Modem Status Int Enable
+#define UA4_IER_RX_IE 0x01 // Rcvr High-Data-Level Int Enable
+#define UA4_IER_TX_IE 0x02 // Xmitter Low-data-level Int Enable
+#define UA4_IER_LS_IE 0x04 // Line Status Int Enable
+#define UA4_IER_MS_IE 0x08 // Modem Status Int Enable
// aliases
-#define UA4_IER_RX_INT_ENABLE UA4_IER_RX_IE
-#define UA4_IER_TX_INT_ENABLE UA4_IER_TX_IE
-#define UA4_IER_LINE_STATUS_INT_ENABLE UA4_IER_LS_IE
-#define UA4_IER_MODEM_STATUS_INT_ENABLE UA4_IER_MS_IE
+#define UA4_IER_RX_INT_ENABLE UA4_IER_RX_IE
+#define UA4_IER_TX_INT_ENABLE UA4_IER_TX_IE
+#define UA4_IER_LINE_STATUS_INT_ENABLE UA4_IER_LS_IE
+#define UA4_IER_MODEM_STATUS_INT_ENABLE UA4_IER_MS_IE
/*
** Interrupt Identification Register (read-only)
**
** a.k.a. Event Identification Register
*/
-#define UA4_IIR (UA4_PORT + 2)
-#define UA4_EVENT_ID UA4_IIR
+#define UA4_IIR (UA4_PORT+2)
+# define UA4_EVENT_ID UA4_IIR
// fields
-#define UA4_IIR_IPF 0x01 // Interrupt Pending flag
+#define UA4_IIR_IPF 0x01 // Interrupt Pending flag
-#define UA4_IIR_IPR_MASK 0x06 // Interrupt Priority mask
-#define UA4_IIR_IPR0_MASK 0x02 // IPR bit 0 mask
-#define UA4_IIR_IPR1_MASK 0x04 // IPR bit 1 mask
+#define UA4_IIR_IPR_MASK 0x06 // Interrupt Priority mask
+# define UA4_IIR_IPR0_MASK 0x02 // IPR bit 0 mask
+# define UA4_IIR_IPR1_MASK 0x04 // IPR bit 1 mask
-#define UA5_IIR_RXFT 0x08 // RX_FIFO Timeout
-#define UA5_IIR_FEN0 0x40 // FIFOs Enabled
-#define UA5_IIR_FEN1 0x80 // FIFOs Enabled
+#define UA5_IIR_RXFT 0x08 // RX_FIFO Timeout
+#define UA5_IIR_FEN0 0x40 // FIFOs Enabled
+#define UA5_IIR_FEN1 0x80 // FIFOs Enabled
// aliases
-#define UA4_IIR_INT_PENDING UA4_IIR_IPF
-#define UA4_IIR_INT_PRIORITY UA4_IIR_IPR
-#define UA5_IIR_RX_FIFO_TIMEOUT UA5_IIR_RXFT
-#define UA5_IIR_FIFO_ENABLED_0 UA5_IIR_FEN0
-#define UA5_IIR_FIFO_ENABLED_1 UA5_IIR_FEN1
+#define UA4_IIR_INT_PENDING UA4_IIR_IPF
+#define UA4_IIR_INT_PRIORITY UA4_IIR_IPR
+#define UA5_IIR_RX_FIFO_TIMEOUT UA5_IIR_RXFT
+#define UA5_IIR_FIFO_ENABLED_0 UA5_IIR_FEN0
+#define UA5_IIR_FIFO_ENABLED_1 UA5_IIR_FEN1
// IIR interrupt priorities (four-bit values)
-#define UA4_IIR_INT_PRI_MASK 0x0f // Mask for extracting int priority
-#define UA4_IIR_NO_INT 0x01 // no interrupt
-#define UA4_IIR_LINE_STATUS 0x06 // line status interrupt
-#define UA4_IIR_RX 0x04 // Receiver High Data Level
-#define UA5_IIR_RX_FIFO 0x0c // Receiver FIFO timeout (16550)
-#define UA4_IIR_TX 0x02 // Transmitter Low Data level
-#define UA4_IIR_MODEM_STATUS 0x00 // Modem Status
+#define UA4_IIR_INT_PRI_MASK 0x0f // Mask for extracting int priority
+# define UA4_IIR_NO_INT 0x01 // no interrupt
+# define UA4_IIR_LINE_STATUS 0x06 // line status interrupt
+# define UA4_IIR_RX 0x04 // Receiver High Data Level
+# define UA5_IIR_RX_FIFO 0x0c // Receiver FIFO timeout (16550)
+# define UA4_IIR_TX 0x02 // Transmitter Low Data level
+# define UA4_IIR_MODEM_STATUS 0x00 // Modem Status
// aliases
-#define UA4_IIR_NO_INT_PENDING UA4_IIR_NO_INT
-#define UA4_IIR_LINE_STATUS_INT_PENDING UA4_IIR_LINE_STATUS
-#define UA4_IIR_RX_INT_PENDING UA4_IIR_RX
-#define UA5_IIR_RX_FIFO_TIMEOUT_INT_PENDING UA5_IIR_RX_FIFO
-#define UA4_IIR_TX_INT_PENDING UA4_IIR_TX
-#define UA4_IIR_MODEM_STATUS_INT_PENDING UA4_IIR_MODEM_STATUS
+#define UA4_IIR_NO_INT_PENDING UA4_IIR_NO_INT
+#define UA4_IIR_LINE_STATUS_INT_PENDING UA4_IIR_LINE_STATUS
+#define UA4_IIR_RX_INT_PENDING UA4_IIR_RX
+#define UA5_IIR_RX_FIFO_TIMEOUT_INT_PENDING UA5_IIR_RX_FIFO
+#define UA4_IIR_TX_INT_PENDING UA4_IIR_TX
+#define UA4_IIR_MODEM_STATUS_INT_PENDING UA4_IIR_MODEM_STATUS
/*
** FIFO Control Register (16550 only, write-only)
*/
-#define UA5_FCR (UA5_PORT + 2)
-#define UA5_FIFO_CTL UA5_FCR
+#define UA5_FCR (UA5_PORT+2)
+# define UA5_FIFO_CTL UA5_FCR
-#define UA5_FCR_FIFO_RESET 0x00 // Reset the FIFO
-#define UA5_FCR_FIFO_EN 0x01 // FIFO Enable
-#define UA5_FCR_RXSR 0x02 // Receiver Soft Reset
-#define UA5_FCR_TXSR 0x04 // Transmitter Soft Reset
+#define UA5_FCR_FIFO_RESET 0x00 // Reset the FIFO
+#define UA5_FCR_FIFO_EN 0x01 // FIFO Enable
+#define UA5_FCR_RXSR 0x02 // Receiver Soft Reset
+#define UA5_FCR_TXSR 0x04 // Transmitter Soft Reset
-#define UA5_FCR_TXFT_MASK 0x30 // TX_FIFO threshold level mask
-#define UA5_FCR_TXFT0_MASK 0x10 // TXFT bit 0 mask
-#define UA5_FCR_TXFT1_MASK 0x20 // TXFT bit 1 mask
-#define UA5_FCR_TX_FIFO_1 0x00 // 1 char
-#define UA5_FCR_TX_FIFO_3 0x10 // 3 char
-#define UA5_FCR_TX_FIFO_9 0x20 // 9 char
-#define UA5_FCR_TX_FIFO_13 0x30 // 13 char
+#define UA5_FCR_TXFT_MASK 0x30 // TX_FIFO threshold level mask
+# define UA5_FCR_TXFT0_MASK 0x10 // TXFT bit 0 mask
+# define UA5_FCR_TXFT1_MASK 0x20 // TXFT bit 1 mask
+# define UA5_FCR_TX_FIFO_1 0x00 // 1 char
+# define UA5_FCR_TX_FIFO_3 0x10 // 3 char
+# define UA5_FCR_TX_FIFO_9 0x20 // 9 char
+# define UA5_FCR_TX_FIFO_13 0x30 // 13 char
-#define UA5_FCR_RXFT_MASK 0xc0 // RX_FIFO threshold level mask
-#define UA5_FCR_RXFT0_MASK 0x40 // RXFT bit 0 mask
-#define UA5_FCR_RXFT1_MASK 0x80 // RXFT bit 1 mask
-#define UA5_FCR_RX_FIFO_1 0x00 // 1 char
-#define UA5_FCR_RX_FIFO_4 0x40 // 4 char
-#define UA5_FCR_RX_FIFO_8 0x80 // 8 char
-#define UA5_FCR_RX_FIFO_14 0xc0 // 14 char
+#define UA5_FCR_RXFT_MASK 0xc0 // RX_FIFO threshold level mask
+# define UA5_FCR_RXFT0_MASK 0x40 // RXFT bit 0 mask
+# define UA5_FCR_RXFT1_MASK 0x80 // RXFT bit 1 mask
+# define UA5_FCR_RX_FIFO_1 0x00 // 1 char
+# define UA5_FCR_RX_FIFO_4 0x40 // 4 char
+# define UA5_FCR_RX_FIFO_8 0x80 // 8 char
+# define UA5_FCR_RX_FIFO_14 0xc0 // 14 char
// aliases
-#define UA5_FCR_FIFO_ENABLED UA5_FCR_FIFO_EN
-#define UA5_FCR_RX_SOFT_RESET UA5_FCR_RXSR
-#define UA5_FCR_TX_SOFT_RESET UA5_FCR_TXSR
-#define UA5_FCR_TX_FIFO_1_CHAR UA5_FCR_TX_FIFO_1
-#define UA5_FCR_TX_FIFO_3_CHAR UA5_FCR_TX_FIFO_3
-#define UA5_FCR_TX_FIFO_9_CHAR UA5_FCR_TX_FIFO_9
-#define UA5_FCR_TX_FIFO_13_CHAR UA5_FCR_TX_FIFO_13
-#define UA5_FCR_RX_FIFO_1_CHAR UA5_FCR_RX_FIFO_1
-#define UA5_FCR_RX_FIFO_4_CHAR UA5_FCR_RX_FIFO_4
-#define UA5_FCR_RX_FIFO_8_CHAR UA5_FCR_RX_FIFO_8
-#define UA5_FCR_RX_FIFO_14_CHAR UA5_FCR_RX_FIFO_14
+#define UA5_FCR_FIFO_ENABLED UA5_FCR_FIFO_EN
+#define UA5_FCR_RX_SOFT_RESET UA5_FCR_RXSR
+#define UA5_FCR_TX_SOFT_RESET UA5_FCR_TXSR
+#define UA5_FCR_TX_FIFO_1_CHAR UA5_FCR_TX_FIFO_1
+#define UA5_FCR_TX_FIFO_3_CHAR UA5_FCR_TX_FIFO_3
+#define UA5_FCR_TX_FIFO_9_CHAR UA5_FCR_TX_FIFO_9
+#define UA5_FCR_TX_FIFO_13_CHAR UA5_FCR_TX_FIFO_13
+#define UA5_FCR_RX_FIFO_1_CHAR UA5_FCR_RX_FIFO_1
+#define UA5_FCR_RX_FIFO_4_CHAR UA5_FCR_RX_FIFO_4
+#define UA5_FCR_RX_FIFO_8_CHAR UA5_FCR_RX_FIFO_8
+#define UA5_FCR_RX_FIFO_14_CHAR UA5_FCR_RX_FIFO_14
/*
** Line Control Register (available in all banks)
**
** Selected when bit 7 of the value written to the port is a 0.
*/
-#define UA4_LCR (UA4_PORT + 3)
-#define UA4_LINE_CTL UA4_LCR
+#define UA4_LCR (UA4_PORT+3)
+# define UA4_LINE_CTL UA4_LCR
-#define UA4_LCR_WLS_MASK 0x03 // Word Length Select mask
-#define UA4_LCR_WLS0_MASK 0x01 // WLS bit 0 mask
-#define UA4_LCR_WLS1_MASK 0x02 // WLS bit 1 mask
-#define UA4_LCR_WLS_5 0x00 // 5 bits per char
-#define UA4_LCR_WLS_6 0x01 // 6 bits per char
-#define UA4_LCR_WLS_7 0x02 // 7 bits per char
-#define UA4_LCR_WLS_8 0x03 // 8 bits per char
+#define UA4_LCR_WLS_MASK 0x03 // Word Length Select mask
+# define UA4_LCR_WLS0_MASK 0x01 // WLS bit 0 mask
+# define UA4_LCR_WLS1_MASK 0x02 // WLS bit 1 mask
+# define UA4_LCR_WLS_5 0x00 // 5 bits per char
+# define UA4_LCR_WLS_6 0x01 // 6 bits per char
+# define UA4_LCR_WLS_7 0x02 // 7 bits per char
+# define UA4_LCR_WLS_8 0x03 // 8 bits per char
-#define UA4_LCR_STB 0x04 // Stop Bits
-#define UA4_LCR_1_STOP_BIT 0x00
-#define UA4_LCR_2_STOP_BIT 0x04
+#define UA4_LCR_STB 0x04 // Stop Bits
+# define UA4_LCR_1_STOP_BIT 0x00
+# define UA4_LCR_2_STOP_BIT 0x04
-#define UA4_LCR_PEN 0x08 // Parity Enable
-#define UA4_LCR_EPS 0x10 // Even Parity Select
-#define UA4_LCR_STKP 0x20 // Sticky Parity
-#define UA4_LCR_NO_PARITY 0x00
-#define UA4_LCR_ODD_PARITY UA4_LCR_PEN
-#define UA4_LCR_EVEN_PARITY (UA4_LCR_PEN | UA4_LCR_EPS)
-#define UA4_LCR_PARITY_LOGIC_1 (UA4_LCR_PEN | UA4_LCR_STKP)
-#define UA4_LCR_PARITY_LOGIC_0 (UA4_LCR_PEN | UA4_LCR_EPS | UA4_LCR_STKP)
+#define UA4_LCR_PEN 0x08 // Parity Enable
+#define UA4_LCR_EPS 0x10 // Even Parity Select
+#define UA4_LCR_STKP 0x20 // Sticky Parity
+# define UA4_LCR_NO_PARITY 0x00
+# define UA4_LCR_ODD_PARITY UA4_LCR_PEN
+# define UA4_LCR_EVEN_PARITY (UA4_LCR_PEN|UA4_LCR_EPS)
+# define UA4_LCR_PARITY_LOGIC_1 (UA4_LCR_PEN|UA4_LCR_STKP)
+# define UA4_LCR_PARITY_LOGIC_0 (UA4_LCR_PEN|UA4_LCR_EPS|UA4_LCR_STKP)
-#define UA4_LCR_SBRK 0x40 // Set Break
-#define UA4_LCR_DLAB 0x80 // Divisor Latch select bit
+#define UA4_LCR_SBRK 0x40 // Set Break
+#define UA4_LCR_DLAB 0x80 // Divisor Latch select bit
// aliases
-#define UA4_LCR_STOP_BITS UA4_LCR_STB
-#define UA4_LCR_PARITY_ENABLE UA4_LCR_PEN
-#define UA4_LCR_SET_BREAK UA4_LCR_SBRK
-#define UA4_LCR_BANK_SELECT_ENABLE UA4_LCR_BKSE
+# define UA4_LCR_STOP_BITS UA4_LCR_STB
+# define UA4_LCR_PARITY_ENABLE UA4_LCR_PEN
+# define UA4_LCR_SET_BREAK UA4_LCR_SBRK
+# define UA4_LCR_BANK_SELECT_ENABLE UA4_LCR_BKSE
/*
** Divisor Latch Registers
@@ -232,109 +233,109 @@
** "re-lock" the Divisor Latch registers, write a command byte to
** LCR with 0 in the DLAB bit.
*/
-#define UA4_DLL (UA4_PORT + 0) // Divisor Latch (least sig.)
-#define UA4_DLM (UA4_PORT + 1) // Divisor Latch (most sig.)
+#define UA4_DLL (UA4_PORT+0) // Divisor Latch (least sig.)
+#define UA4_DLM (UA4_PORT+1) // Divisor Latch (most sig.)
// aliases
-#define UA4_DIVISOR_LATCH_LS UA4_DLL
-#define UA4_DIVISOR_LATCH_MS UA4_DLM
+#define UA4_DIVISOR_LATCH_LS UA4_DLL
+#define UA4_DIVISOR_LATCH_MS UA4_DLM
// Baud rate divisor high and low bytes
-#define BAUD_HIGH_BYTE(x) (((x) >> 8) & 0xff)
-#define BAUD_LOW_BYTE(x) ((x) & 0xff)
+#define BAUD_HIGH_BYTE(x) (((x) >> 8) & 0xff)
+#define BAUD_LOW_BYTE(x) ((x) & 0xff)
// Baud rate divisors
-#define DL_BAUD_50 2304
-#define DL_BAUD_75 1536
-#define DL_BAUD_110 1047
-#define DL_BAUD_150 768
-#define DL_BAUD_300 384
-#define DL_BAUD_600 192
-#define DL_BAUD_1200 96
-#define DL_BAUD_1800 64
-#define DL_BAUD_2000 58
-#define DL_BAUD_2400 48
-#define DL_BAUD_3600 32
-#define DL_BAUD_4800 24
-#define DL_BAUD_7200 16
-#define DL_BAUD_9600 12
-#define DL_BAUD_14400 8
-#define DL_BAUD_19200 6
-#define DL_BAUD_28800 4
-#define DL_BAUD_38400 3
-#define DL_BAUD_57600 2
-#define DL_BAUD_115200 1
+#define DL_BAUD_50 2304
+#define DL_BAUD_75 1536
+#define DL_BAUD_110 1047
+#define DL_BAUD_150 768
+#define DL_BAUD_300 384
+#define DL_BAUD_600 192
+#define DL_BAUD_1200 96
+#define DL_BAUD_1800 64
+#define DL_BAUD_2000 58
+#define DL_BAUD_2400 48
+#define DL_BAUD_3600 32
+#define DL_BAUD_4800 24
+#define DL_BAUD_7200 16
+#define DL_BAUD_9600 12
+#define DL_BAUD_14400 8
+#define DL_BAUD_19200 6
+#define DL_BAUD_28800 4
+#define DL_BAUD_38400 3
+#define DL_BAUD_57600 2
+#define DL_BAUD_115200 1
/*
** Modem Control Register
*/
-#define UA4_MCR (UA4_PORT + 4)
-#define UA4_MODEM_CTL UA4_MCR
+#define UA4_MCR (UA4_PORT+4)
+# define UA4_MODEM_CTL UA4_MCR
-#define UA4_MCR_DTR 0x01 // Data Terminal Ready
-#define UA4_MCR_RTS 0x02 // Ready to Send
-#define UA4_MCR_RILP 0x04 // Loopback Interrupt Request
-#define UA4_MCR_ISEN 0x08 // Interrupt Signal Enable
-#define UA4_MCR_DCDLP 0x08 // DCD Loopback
-#define UA4_MCR_LOOP 0x10 // Loopback Enable
+#define UA4_MCR_DTR 0x01 // Data Terminal Ready
+#define UA4_MCR_RTS 0x02 // Ready to Send
+#define UA4_MCR_RILP 0x04 // Loopback Interrupt Request
+#define UA4_MCR_ISEN 0x08 // Interrupt Signal Enable
+#define UA4_MCR_DCDLP 0x08 // DCD Loopback
+#define UA4_MCR_LOOP 0x10 // Loopback Enable
// aliases
-#define UA4_MCR_DATA_TERMINAL_READY UA4_MCR_DTR
-#define UA4_MCR_READY_TO_SEND UA4_MCR_RTS
-#define UA4_MCR_LOOPBACK_INT_REQ UA4_MCR_RILP
-#define UA4_MCR_INT_SIGNAL_ENABLE UA4_MCR_ISEN
-#define UA4_MCR_LOOPBACK_DCD UA4_MCR_DCDLP
-#define UA4_MCR_LOOPBACK_ENABLE UA4_MCR_LOOP
+#define UA4_MCR_DATA_TERMINAL_READY UA4_MCR_DTR
+#define UA4_MCR_READY_TO_SEND UA4_MCR_RTS
+#define UA4_MCR_LOOPBACK_INT_REQ UA4_MCR_RILP
+#define UA4_MCR_INT_SIGNAL_ENABLE UA4_MCR_ISEN
+#define UA4_MCR_LOOPBACK_DCD UA4_MCR_DCDLP
+#define UA4_MCR_LOOPBACK_ENABLE UA4_MCR_LOOP
/*
** Line Status Register
*/
-#define UA4_LSR (UA4_PORT + 5)
-#define UA4_LINE_STATUS UA4_LSR
+#define UA4_LSR (UA4_PORT+5)
+# define UA4_LINE_STATUS UA4_LSR
-#define UA4_LSR_RXDA 0x01 // Receiver Data Available
-#define UA4_LSR_OE 0x02 // Overrun Error
-#define UA4_LSR_PE 0x04 // Parity Error
-#define UA4_LSR_FE 0x08 // Framing Error
-#define UA4_LSR_BRK 0x10 // Break Event Detected
-#define UA4_LSR_TXRDY 0x20 // Transmitter Ready
-#define UA4_LSR_TXEMP 0x40 // Transmitter Empty
-#define UA4_LSR_ER_INF 0x80 // Error in RX_FIFO
+#define UA4_LSR_RXDA 0x01 // Receiver Data Available
+#define UA4_LSR_OE 0x02 // Overrun Error
+#define UA4_LSR_PE 0x04 // Parity Error
+#define UA4_LSR_FE 0x08 // Framing Error
+#define UA4_LSR_BRK 0x10 // Break Event Detected
+#define UA4_LSR_TXRDY 0x20 // Transmitter Ready
+#define UA4_LSR_TXEMP 0x40 // Transmitter Empty
+#define UA4_LSR_ER_INF 0x80 // Error in RX_FIFO
// aliases
-#define UA4_LSR_RX_DATA_AVAILABLE UA4_LSR_RXDA
-#define UA4_LSR_OVERRUN_ERROR UA4_LSR_OE
-#define UA4_LSR_PARITY_ERROR UA4_LSR_PE
-#define UA4_LSR_FRAMING_ERROR UA4_LSR_FE
-#define UA4_LSR_BREAK_DETECTED UA4_LSR_BRK
-#define UA4_LSR_TX_READY UA4_LSR_TXRDY
-#define UA4_LSR_TX_EMPTY UA4_LSR_TXEMP
-#define UA4_LSR_RX_FIFO_ERROR UA4_LSR_ER_INF
+#define UA4_LSR_RX_DATA_AVAILABLE UA4_LSR_RXDA
+#define UA4_LSR_OVERRUN_ERROR UA4_LSR_OE
+#define UA4_LSR_PARITY_ERROR UA4_LSR_PE
+#define UA4_LSR_FRAMING_ERROR UA4_LSR_FE
+#define UA4_LSR_BREAK_DETECTED UA4_LSR_BRK
+#define UA4_LSR_TX_READY UA4_LSR_TXRDY
+#define UA4_LSR_TX_EMPTY UA4_LSR_TXEMP
+#define UA4_LSR_RX_FIFO_ERROR UA4_LSR_ER_INF
/*
** Modem Status Register
*/
-#define UA4_MSR (UA4_PORT + 6)
-#define UA4_MODEM_STATUS UA4_MSR
+#define UA4_MSR (UA4_PORT+6)
+# define UA4_MODEM_STATUS UA4_MSR
-#define UA4_MSR_DCTS 0x01 // Delta Clear to Send
-#define UA4_MSR_DDSR 0x02 // Delta Data Set Ready
-#define UA4_MSR_TERI 0x04 // Trailing Edge Ring Indicate
-#define UA4_MSR_DDCD 0x08 // Delta Data Carrier Detect
-#define UA4_MSR_CTS 0x10 // Clear to Send
-#define UA4_MSR_DSR 0x20 // Data Set Ready
-#define UA4_MSR_RI 0x40 // Ring Indicate
-#define UA4_MSR_DCD 0x80 // Data Carrier Detect
+#define UA4_MSR_DCTS 0x01 // Delta Clear to Send
+#define UA4_MSR_DDSR 0x02 // Delta Data Set Ready
+#define UA4_MSR_TERI 0x04 // Trailing Edge Ring Indicate
+#define UA4_MSR_DDCD 0x08 // Delta Data Carrier Detect
+#define UA4_MSR_CTS 0x10 // Clear to Send
+#define UA4_MSR_DSR 0x20 // Data Set Ready
+#define UA4_MSR_RI 0x40 // Ring Indicate
+#define UA4_MSR_DCD 0x80 // Data Carrier Detect
// aliases
-#define UA4_MSR_DELTA_CLEAR_TO_SEND UA4_MSR_DCTS
-#define UA4_MSR_DELTA_DATA_SET_READY UA4_MSR_DDSR
-#define UA4_MSR_TRAILING_EDGE_RING UA4_MSR_TERI
-#define UA4_MSR_DELTA_DATA_CARRIER_DETECT UA4_MSR_DDCD
-#define UA4_MSR_CLEAR_TO_SEND UA4_MSR_CTS
-#define UA4_MSR_DATA_SET_READY UA4_MSR_DSR
-#define UA4_MSR_RING_INDICATE UA4_MSR_RI
-#define UA4_MSR_DATA_CARRIER_DETECT UA4_MSR_DCD
+#define UA4_MSR_DELTA_CLEAR_TO_SEND UA4_MSR_DCTS
+#define UA4_MSR_DELTA_DATA_SET_READY UA4_MSR_DDSR
+#define UA4_MSR_TRAILING_EDGE_RING UA4_MSR_TERI
+#define UA4_MSR_DELTA_DATA_CARRIER_DETECT UA4_MSR_DDCD
+#define UA4_MSR_CLEAR_TO_SEND UA4_MSR_CTS
+#define UA4_MSR_DATA_SET_READY UA4_MSR_DSR
+#define UA4_MSR_RING_INDICATE UA4_MSR_RI
+#define UA4_MSR_DATA_CARRIER_DETECT UA4_MSR_DCD
/*
** Scratch Register
@@ -342,7 +343,7 @@
** Not used by the UART; usable as a "scratchpad" register for
** temporary storage.
*/
-#define UA4_SCR (UA4_PORT + 7)
-#define UA4_SCRATCH UA4_UA5_SCR
+#define UA4_SCR (UA4_PORT+7)
+# define UA4_SCRATCH UA4_UA5_SCR
-#endif /* uart.h */
+#endif /* uart.h */