(2006-08-06) rescue-bootcd

This commit is contained in:
2006-08-06 00:00:00 +02:00
parent 2f796b816a
commit decb062d20
21091 changed files with 7076462 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
sys/ansicon_write.o: sys/ansicon_write.c ../include/errno.h \
../include/string.h ../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/ansiserial_write.o: sys/ansiserial_write.c ../include/errno.h \
../include/string.h ../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,4 @@
sys/argv.o: sys/argv.c ../include/inttypes.h ../include/klibc/extern.h \
../include/stdint.h ../include/stddef.h ../include/bitsize/stddef.h \
../include/stdio.h ../include/stdarg.h \
/usr/lib/gcc/i686-pc-linux-gnu/3.4.1/include/stdarg.h

View File

@@ -0,0 +1,6 @@
sys/close.o: sys/close.c ../include/errno.h ../include/com32.h \
../include/stdint.h ../include/klibc/compiler.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h sys/file.h ../include/inttypes.h \
../include/stdlib.h ../include/sys/types.h ../include/dev.h \
../include/fcntl.h

View File

@@ -0,0 +1 @@
sys/entry.o: sys/entry.S

View File

@@ -0,0 +1,6 @@
sys/err_read.o: sys/err_read.c ../include/errno.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/err_write.o: sys/err_write.c ../include/errno.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1 @@
sys/exit.o: sys/exit.S

View File

@@ -0,0 +1,6 @@
sys/fileclose.o: sys/fileclose.c ../include/errno.h ../include/com32.h \
../include/stdint.h ../include/klibc/compiler.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h sys/file.h ../include/inttypes.h \
../include/stdlib.h ../include/sys/types.h ../include/dev.h \
../include/fcntl.h

View File

@@ -0,0 +1,5 @@
sys/fileinfo.o: sys/fileinfo.c sys/file.h ../include/inttypes.h \
../include/klibc/extern.h ../include/stdint.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/stdlib.h \
../include/klibc/compiler.h ../include/sys/types.h ../include/dev.h \
../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/fileread.o: sys/fileread.c ../include/errno.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,7 @@
sys/ftell.o: sys/ftell.c ../include/stdio.h ../include/klibc/extern.h \
../include/stdarg.h \
/usr/lib/gcc/i686-pc-linux-gnu/3.4.1/include/stdarg.h \
../include/stddef.h ../include/bitsize/stddef.h ./sys/file.h \
../include/inttypes.h ../include/stdint.h ../include/stdlib.h \
../include/klibc/compiler.h ../include/sys/types.h ../include/dev.h \
../include/fcntl.h

View File

@@ -0,0 +1,3 @@
sys/idle.o: sys/idle.c ../include/syslinux.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h

View File

@@ -0,0 +1,6 @@
sys/isatty.o: sys/isatty.c ../include/errno.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h ../include/unistd.h \
../include/sys/types.h sys/file.h ../include/inttypes.h \
../include/stdlib.h ../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,5 @@
sys/line_input.o: sys/line_input.c sys/file.h ../include/inttypes.h \
../include/klibc/extern.h ../include/stdint.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/stdlib.h \
../include/klibc/compiler.h ../include/sys/types.h ../include/dev.h \
../include/fcntl.h ../include/errno.h ../include/syslinux.h

View File

@@ -0,0 +1,6 @@
sys/null_read.o: sys/null_read.c ../include/errno.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/null_write.o: sys/null_write.c ../include/errno.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/open.o: sys/open.c ../include/errno.h ../include/com32.h \
../include/stdint.h ../include/klibc/compiler.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/unistd.h ../include/sys/types.h \
../include/fcntl.h sys/file.h ../include/inttypes.h ../include/stdlib.h \
../include/dev.h

View File

@@ -0,0 +1,5 @@
sys/openconsole.o: sys/openconsole.c ../include/unistd.h \
../include/klibc/extern.h ../include/klibc/compiler.h \
../include/stddef.h ../include/bitsize/stddef.h ../include/sys/types.h \
../include/stdint.h ../include/console.h ../include/dev.h \
../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/opendev.o: sys/opendev.c ../include/errno.h ../include/com32.h \
../include/stdint.h ../include/klibc/compiler.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h sys/file.h ../include/inttypes.h \
../include/stdlib.h ../include/sys/types.h ../include/dev.h \
../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/rawcon_read.o: sys/rawcon_read.c ../include/errno.h \
../include/string.h ../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h ../include/sys/times.h \
sys/file.h ../include/inttypes.h ../include/stdlib.h \
../include/sys/types.h ../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/rawcon_write.o: sys/rawcon_write.c ../include/errno.h \
../include/string.h ../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/read.o: sys/read.c ../include/errno.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/serial_write.o: sys/serial_write.c ../include/errno.h \
../include/string.h ../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/stdcon_read.o: sys/stdcon_read.c ../include/errno.h \
../include/string.h ../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,6 @@
sys/stdcon_write.o: sys/stdcon_write.c ../include/errno.h \
../include/string.h ../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,4 @@
sys/times.o: sys/times.c ../include/sys/times.h ../include/stdint.h \
../include/inttypes.h ../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h \
../include/klibc/compiler.h

View File

@@ -0,0 +1,6 @@
sys/write.o: sys/write.c ../include/errno.h ../include/string.h \
../include/klibc/extern.h ../include/stddef.h \
../include/bitsize/stddef.h ../include/com32.h ../include/stdint.h \
../include/klibc/compiler.h ../include/minmax.h sys/file.h \
../include/inttypes.h ../include/stdlib.h ../include/sys/types.h \
../include/dev.h ../include/fcntl.h

View File

@@ -0,0 +1,538 @@
#ident "$Id: ansicon_write.c,v 1.9 2005/01/05 07:45:23 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* ansicon_write.c
*
* Write to the screen using ANSI control codes (about as capable as
* DOS' ANSI.SYS.)
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include <klibc/compiler.h>
#include "file.h"
struct curxy {
uint8_t x, y;
} __attribute__((packed));
#define BIOS_CURXY ((struct curxy *)0x450) /* Array for each page */
#define BIOS_ROWS (*(uint8_t *)0x484) /* Minus one; if zero use 24 (= 25 lines) */
#define BIOS_COLS (*(uint16_t *)0x44A)
#define BIOS_PAGE (*(uint8_t *)0x462)
enum ansi_state {
st_init, /* Normal (no ESC seen) */
st_esc, /* ESC seen */
st_csi, /* CSI seen */
};
#define MAX_PARMS 16
struct term_state {
int disabled;
int attr; /* Current display attribute */
int vtgraphics; /* VT graphics on/off */
int intensity;
int underline;
int blink;
int reverse;
int fg;
int bg;
int autocr;
struct curxy saved_xy;
uint16_t cursor_type;
enum ansi_state state;
int pvt; /* Private code? */
int nparms; /* Number of parameters seen */
int parms[MAX_PARMS];
};
static const struct term_state default_state =
{
.disabled = 0,
.attr = 0x07, /* Grey on black */
.vtgraphics = 0,
.intensity = 1,
.underline = 0,
.blink = 0,
.reverse = 0,
.fg = 7,
.bg = 0,
.autocr = 0,
.saved_xy = { 0, 0 },
.cursor_type = 0x0607,
.state = st_init,
.pvt = 0,
.nparms = 0,
};
static struct term_state st;
/* DEC VT graphics to codepage 437 table (characters 0x60-0x7F only) */
static const char decvt_to_cp437[] =
{ 0004, 0261, 0007, 0007, 0007, 0007, 0370, 0361, 0007, 0007, 0331, 0277, 0332, 0300, 0305, 0304,
0304, 0304, 0137, 0137, 0303, 0264, 0301, 0302, 0263, 0363, 0362, 0343, 0330, 0234, 0007, 00 };
/* Common setup */
static void __constructor ansicon_init(void)
{
static com32sys_t ireg; /* Auto-initalized to all zero */
com32sys_t oreg;
/* Initial state */
memcpy(&st, &default_state, sizeof st);
/* Are we disabled? */
ireg.eax.w[0] = 0x000b;
__intcall(0x22, &ireg, &oreg);
if ( (signed char)oreg.ebx.b[1] < 0 ) {
st.disabled = 1;
return;
}
/* Force text mode */
ireg.eax.w[0] = 0x0005;
__intcall(0x22, &ireg, NULL);
/* Get cursor shape */
ireg.eax.b[1] = 0x03;
ireg.ebx.b[1] = BIOS_PAGE;
__intcall(0x10, &ireg, &oreg);
st.cursor_type = oreg.ecx.w[0];
}
/* Erase a region of the screen */
static void ansicon_erase(int x0, int y0, int x1, int y1)
{
static com32sys_t ireg;
ireg.eax.w[0] = 0x0600; /* Clear window */
ireg.ebx.b[1] = st.attr; /* Fill with current attribute */
ireg.ecx.b[0] = x0;
ireg.ecx.b[1] = y0;
ireg.edx.b[0] = x1;
ireg.edx.b[1] = y1;
__intcall(0x10, &ireg, NULL);
}
/* Show or hide the cursor */
static void showcursor(int yes)
{
static com32sys_t ireg;
ireg.eax.b[1] = 0x01;
ireg.ecx.w[0] = yes ? st.cursor_type : 0x2020;
__intcall(0x10, &ireg, NULL);
}
static void ansicon_putchar(int ch)
{
static com32sys_t ireg;
const int rows = BIOS_ROWS ? BIOS_ROWS+1 : 25;
const int cols = BIOS_COLS;
const int page = BIOS_PAGE;
struct curxy xy = BIOS_CURXY[page];
switch ( st.state ) {
case st_init:
switch ( ch ) {
case '\b':
if ( xy.x > 0 ) xy.x--;
break;
case '\t':
{
int nsp = 8 - (xy.x & 7);
while ( nsp-- )
ansicon_putchar(' ');
}
return; /* Cursor already updated */
case '\n':
case '\v':
case '\f':
xy.y++;
if ( st.autocr )
xy.x = 0;
break;
case '\r':
xy.x = 0;
break;
case 127:
/* Ignore delete */
break;
case 14:
st.vtgraphics = 1;
break;
case 15:
st.vtgraphics = 0;
break;
case 27:
st.state = st_esc;
break;
default:
/* Print character */
if ( ch >= 32 ) {
if ( st.vtgraphics && (ch & 0xe0) == 0x60 )
ch = decvt_to_cp437[ch - 0x60];
ireg.eax.b[1] = 0x09;
ireg.eax.b[0] = ch;
ireg.ebx.b[1] = page;
ireg.ebx.b[0] = st.attr;
ireg.ecx.w[0] = 1;
__intcall(0x10, &ireg, NULL);
xy.x++;
}
break;
}
break;
case st_esc:
switch ( ch ) {
case '%':
case '(':
case ')':
case '#':
/* Ignore this plus the subsequent character, allows
compatibility with Linux sequence to set charset */
break;
case '[':
st.state = st_csi;
st.nparms = st.pvt = 0;
memset(st.parms, 0, sizeof st.parms);
break;
case 'c':
/* Reset terminal */
memcpy(&st, &default_state, sizeof st);
ansicon_erase(0, 0, cols-1, rows-1);
xy.x = xy.y = 1;
break;
default:
/* Ignore sequence */
st.state = st_init;
break;
}
break;
case st_csi:
{
int p0 = st.parms[0] ? st.parms[0] : 1;
if ( ch >= '0' && ch <= '9' ) {
st.parms[st.nparms] = st.parms[st.nparms]*10 + (ch-'0');
} else if ( ch == ';' ) {
st.nparms++;
if ( st.nparms >= MAX_PARMS )
st.nparms = MAX_PARMS-1;
break;
} else if ( ch == '?' ) {
st.pvt = 1;
} else {
switch ( ch ) {
case 'A':
{
int y = xy.y - p0;
xy.y = (y < 0) ? 0 : y;
}
break;
case 'B':
{
int y = xy.y + p0;
xy.y = (y >= rows) ? rows-1 : y;
}
break;
case 'C':
{
int x = xy.x + p0;
xy.x = (x >= cols) ? cols-1 : x;
}
break;
case 'D':
{
int x = xy.x - p0;
xy.x = (x < 0) ? 0 : x;
}
break;
case 'E':
{
int y = xy.y + p0;
xy.y = (y >= rows) ? rows-1 : y;
xy.x = 0;
}
break;
case 'F':
{
int y = xy.y - p0;
xy.y = (y < 0) ? 0 : y;
xy.x = 0;
}
break;
case 'G':
case '\'':
{
int x = st.parms[0] - 1;
xy.x = (x >= cols) ? cols-1 : (x < 0) ? 0 : x;
}
break;
case 'H':
case 'f':
{
int y = st.parms[0] - 1;
int x = st.parms[1] - 1;
xy.x = (x >= cols) ? cols-1 : (x < 0) ? 0 : x;
xy.y = (y >= rows) ? rows-1 : (y < 0) ? 0 : y;
}
break;
case 'J':
{
switch ( st.parms[0] ) {
case 0:
ansicon_erase(xy.x, xy.y, cols-1, xy.y);
if ( xy.y < rows-1 )
ansicon_erase(0, xy.y+1, cols-1, rows-1);
break;
case 1:
if ( xy.y > 0 )
ansicon_erase(0, 0, cols-1, xy.y-1);
if ( xy.y > 0 )
ansicon_erase(0, xy.y, xy.x-1, xy.y);
break;
case 2:
ansicon_erase(0, 0, cols-1, rows-1);
break;
default:
/* Ignore */
break;
}
}
break;
case 'K':
{
switch ( st.parms[0] ) {
case 0:
ansicon_erase(xy.x, xy.y, cols-1, xy.y);
break;
case 1:
if ( xy.x > 0 )
ansicon_erase(0, xy.y, xy.x-1, xy.y);
break;
case 2:
ansicon_erase(0, xy.y, cols-1, xy.y);
break;
default:
/* Ignore */
break;
}
}
break;
case 'h':
case 'l':
{
int set = (ch == 'h');
switch ( st.parms[0] ) {
case 20:
st.autocr = set;
break;
case 25:
showcursor(set);
break;
default:
/* Ignore */
break;
}
}
break;
case 'm':
{
static const int ansi2pc[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
int i;
for ( i = 0 ; i <= st.nparms ; i++ ) {
int a = st.parms[i];
switch ( a ) {
case 0:
st.fg = 7;
st.bg = 0;
st.intensity = 1;
st.underline = 0;
st.blink = 0;
st.reverse = 0;
break;
case 1:
st.intensity = 2;
break;
case 2:
st.intensity = 0;
break;
case 4:
st.underline = 1;
break;
case 5:
st.blink = 1;
break;
case 7:
st.reverse = 1;
break;
case 21:
case 22:
st.intensity = 1;
break;
case 24:
st.underline = 0;
break;
case 25:
st.blink = 0;
break;
case 27:
st.reverse = 0;
break;
case 30 ... 37:
st.fg = ansi2pc[a-30];
break;
case 38:
st.fg = 7;
st.underline = 1;
break;
case 39:
st.fg = 7;
st.underline = 0;
break;
case 40 ... 47:
st.bg = ansi2pc[a-40];
break;
case 49:
st.bg = 7;
break;
default:
/* Do nothing */
break;
}
}
/* Turn into an attribute code */
{
int bg = st.bg;
int fg;
if ( st.underline )
fg = 0x01;
else if ( st.intensity == 0 )
fg = 0x08;
else
fg = st.fg;
if ( st.reverse ) {
bg = fg & 0x07;
fg &= 0x08;
fg |= st.bg;
}
if ( st.blink )
bg ^= 0x08;
if ( st.intensity == 2 )
fg ^= 0x08;
st.attr = (bg << 4) | fg;
}
}
break;
case 's':
st.saved_xy = xy;
break;
case 'u':
xy = st.saved_xy;
break;
default: /* Includes CAN and SUB */
break; /* Drop unknown sequence */
}
st.state = st_init;
}
}
break;
}
/* If we fell off the end of the screen, adjust */
if ( xy.x >= cols ) {
xy.x = 0;
xy.y++;
}
while ( xy.y >= rows ) {
xy.y--;
ireg.eax.w[0] = 0x0601;
ireg.ebx.b[1] = st.attr;
ireg.ecx.w[0] = 0;
ireg.edx.b[1] = rows-1;
ireg.edx.b[0] = cols-1;
__intcall(0x10, &ireg, NULL); /* Scroll */
}
/* Update cursor position */
ireg.eax.b[1] = 0x02;
ireg.ebx.b[1] = page;
ireg.edx.b[1] = xy.y;
ireg.edx.b[0] = xy.x;
__intcall(0x10, &ireg, NULL);
}
ssize_t __ansicon_write(struct file_info *fp, const void *buf, size_t count)
{
const unsigned char *bufp = buf;
size_t n = 0;
(void)fp;
if ( st.disabled )
return n; /* Nothing to do */
while ( count-- ) {
ansicon_putchar(*bufp++);
n++;
}
return n;
}
const struct output_dev dev_ansicon_w = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_TTY | __DEV_OUTPUT,
.fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
.write = __ansicon_write,
.close = NULL,
};

Binary file not shown.

View File

@@ -0,0 +1,56 @@
#ident "$Id: ansiserial_write.c,v 1.1 2004/11/30 22:09:56 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* ansiserial_write.c
*
* Write to both to the ANSI console and the serial port
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include "file.h"
extern ssize_t __ansicon_write(struct file_info *, const void *, size_t);
extern ssize_t __serial_write(struct file_info *, const void *, size_t);
static ssize_t __ansiserial_write(struct file_info *fp, const void *buf, size_t count)
{
__ansicon_write(fp, buf, count);
return __serial_write(fp, buf, count);
}
const struct output_dev dev_ansiserial_w = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_TTY | __DEV_OUTPUT,
.fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
.write = __ansiserial_write,
.close = NULL,
};

Binary file not shown.

View File

@@ -0,0 +1,98 @@
#ident "$Id: argv.c,v 1.3 2004/12/21 02:47:08 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* argv.c
*
* Parse a single C string into argc and argv (argc is return value.)
* memptr points to available memory.
*/
#include <inttypes.h>
#include <stddef.h>
#include <stdio.h>
#define ALIGN_UP(p,t) ((t *)(((uintptr_t)(p) + (sizeof(t)-1)) & ~(sizeof(t)-1)))
extern char _end[]; /* Symbol created by linker */
void *__mem_end = &_end; /* Global variable for use by malloc() */
int __parse_argv(char ***argv, const char *str)
{
char argv0[] = "";
char *mem = __mem_end;
const char *p = str;
char *q = mem;
char *r;
char **arg;
int wasspace = 1;
int argc = 1;
/* First copy the string, turning whitespace runs into nulls */
for ( p = str ; ; p++ ) {
if ( *p <= ' ' ) {
if ( !wasspace ) {
wasspace = 1;
*q++ = '\0';
}
} else {
if ( wasspace ) {
argc++;
wasspace = 0;
}
*q++ = *p;
}
/* This test is AFTER we have processed the null byte;
we treat it as a whitespace character so it terminates
the last argument */
if ( ! *p )
break;
}
/* Now create argv */
arg = ALIGN_UP(q,char *);
*argv = arg;
*arg++ = argv0; /* argv[0] */
q--; /* Point q to final null */
if ( mem < q )
*arg++ = mem; /* argv[1] */
for ( r = mem ; r < q ; r++ ) {
if ( *r == '\0' ) {
*arg++ = r+1;
}
}
*arg++ = NULL; /* Null pointer at the end */
__mem_end = arg; /* End of memory we used */
return argc;
}

Binary file not shown.

View File

@@ -0,0 +1,62 @@
#ident "$Id: close.c,v 1.4 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* close.c
*/
#include <errno.h>
#include <com32.h>
#include <string.h>
#include "file.h"
int close(int fd)
{
struct file_info *fp = &__file_info[fd];
int rv = 0;
if ( fd >= NFILES || !fp->iop || !fp->oop ) {
errno = EBADF;
return -1;
}
if ( fp->iop->close ) {
rv = fp->iop->close(fp);
if ( rv )
return rv;
}
if ( fp->oop->close ) {
rv = fp->oop->close(fp);
if ( rv )
return rv;
}
memset(fp, 0, sizeof *fp); /* File structure unused */
return 0;
}

Binary file not shown.

View File

@@ -0,0 +1,90 @@
#ident "$Id: entry.S,v 1.3 2004/12/21 02:47:08 hpa Exp $"
# -----------------------------------------------------------------------
#
# Copyright 2003-2004 H. Peter Anvin - All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom
# the Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall
# be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# -----------------------------------------------------------------------
# COM32 start up code - must be linked first in the binary
.section ".init","ax"
.globl _start
.type _start, @function
_start:
# This first instruction acts as COM32 magic number
movl $0x21cd4cff,%eax
# Upwards string operations
cld
# Zero the .bss segment
xorl %eax,%eax
movl $__bss_start,%edi # Symbol provided by linker
movl $_end+3,%ecx # Symbol provided by linker
subl %edi,%ecx
shrl $2,%ecx
rep ; stosl
# Copy COM32 invocation parameters
leal 4(%esp),%esi # Argument list
movl $__com32,%edi
movl $6,%ecx
movl %esp,-4(%edi) # Save the initial stack ptr
cmpl (%esi),%ecx
jbe 1f
movl (%esi),%ecx
1: rep ; movsl
# Parse the command line (assumes REGPARM)
movl __com32+4,%edx # Command line
pushl %edx # Make space for argv
movl %esp,%eax
call __parse_argv
pushl %eax # Save argc
# Look for library initialization functions
movl $__ctors_start, %esi
2:
cmpl $__ctors_end, %esi
jae 3f
call *(%esi)
addl $4,%esi
jmp 2b
#
# Actually run main. This assumes REGPARM is used!!!!
#
3:
popl %eax # argc
popl %edx # argv
call main
call *(__exit_handler)
hlt
.size _start, .-_start
.bss
.globl __entry_esp
__entry_esp: .space 4
.globl __com32
__com32: .space 4*6

Binary file not shown.

View File

@@ -0,0 +1,54 @@
#ident "$Id: err_read.c,v 1.1 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* err_read.c
*
* Reading from a device which doesn't support reading
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include "file.h"
static ssize_t __err_read(struct file_info *fp, void *buf, size_t count)
{
(void)fp; (void)buf; (void)count;
errno = -EINVAL;
return -1;
}
const struct input_dev dev_error_r = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_INPUT | __DEV_ERROR,
.fileflags = O_RDONLY,
.read = __err_read,
.close = NULL,
};

Binary file not shown.

View File

@@ -0,0 +1,54 @@
#ident "$Id: err_write.c,v 1.1 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* err_write.c
*
* Writing to a device which doesn't support writing
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include "file.h"
static ssize_t __err_write(struct file_info *fp, const void *buf, size_t count)
{
(void)fp; (void)buf; (void)count;
errno = -EINVAL;
return -1;
}
const struct output_dev dev_error_w = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_OUTPUT | __DEV_ERROR,
.fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
.write = __err_write,
.close = NULL,
};

Binary file not shown.

View File

@@ -0,0 +1,35 @@
# $Id: exit.S,v 1.2 2004/12/17 19:40:41 hpa Exp $
#
# Implementation of _exit() for com32 based on c32entry.S
#
.text
.globl _exit
.type _exit, @function
_exit:
#ifdef REGPARM
pushl %eax
#endif
# Run any destructors
movl $__dtors_start, %esi
2:
cmpl $__dtors_end, %esi
jae 1f
call *(%esi)
addl $4,%esi
jmp 2b
1:
#ifdef REGPARM
popl %eax
#else
movl 4(%esp),%eax # Exit code in %eax = return value
#endif
movl (__entry_esp),%esp # Return stack pointer to entry value
ret # Return to termination address
.size _exit, .-_exit
.data
__exit_handler:
.globl __exit_handler
.long _exit

Binary file not shown.

View File

@@ -0,0 +1,99 @@
#ident "$Id: file.h,v 1.4 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2003-2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* file.h
*
* Internal implementation of file I/O for COM32
*/
#ifndef _COM32_SYS_FILE_H
#define _COM32_SYS_FILE_H
#include <inttypes.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dev.h>
#include <fcntl.h>
/* Device structure; contains the relevant operations */
struct file_info;
#define __DEV_MAGIC 0xf4e7
#define __DEV_TTY 0x0001 /* TTY - must be bit 0 */
#define __DEV_FILE 0x0002 /* Ordinary file */
#define __DEV_OUTPUT 0x0004 /* This is an output device */
#define __DEV_INPUT 0 /* Dummy */
#define __DEV_ERROR 0x0008 /* This is the error device */
#define __DEV_NULL 0x0010 /* This is the null device */
struct input_dev {
uint16_t dev_magic; /* Magic number */
uint16_t flags; /* Flags */
int fileflags; /* Permitted file flags */
ssize_t (*read)(struct file_info *, void *, size_t);
int (*close)(struct file_info *);
};
struct output_dev {
uint16_t dev_magic; /* Magic number */
uint16_t flags; /* Flags */
int fileflags;
ssize_t (*write)(struct file_info *, const void *, size_t);
int (*close)(struct file_info *);
};
/* File structure */
#define NFILES 32 /* Number of files to support */
#define MAXBLOCK 16384 /* Defined by ABI */
struct file_info {
const struct input_dev *iop; /* Input operations */
const struct output_dev *oop; /* Output operations */
/* Structure used for input blocking */
struct {
int blocklg2; /* Blocksize log 2 */
size_t offset; /* Current file offset */
size_t length; /* Total file length */
uint16_t filedes; /* File descriptor */
uint16_t _filler; /* Unused */
size_t nbytes; /* Number of bytes available in buffer */
char *datap; /* Current data pointer */
char buf[MAXBLOCK];
} i;
};
extern struct file_info __file_info[NFILES];
/* Line input discipline */
ssize_t __line_input(struct file_info *fp, char *buf, size_t bufsize,
ssize_t (*get_char)(struct file_info *, void *, size_t));
#endif /* _COM32_SYS_FILE_H */

View File

@@ -0,0 +1,53 @@
#ident "$Id: fileclose.c,v 1.2 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* fileclose.c
*
* Close an ordinary file
*/
#include <errno.h>
#include <com32.h>
#include <string.h>
#include "file.h"
int __file_close(struct file_info *fp)
{
com32sys_t regs;
if ( fp->i.filedes ) {
memset(&regs, 0, sizeof regs);
regs.eax.w[0] = 0x0008; /* Close file */
regs.esi.w[0] = fp->i.filedes;
__com32.cs_intcall(0x22, &regs, NULL);
}
return 0;
}

Binary file not shown.

View File

@@ -0,0 +1,3 @@
#include "file.h"
struct file_info __file_info[NFILES];

Binary file not shown.

View File

@@ -0,0 +1,86 @@
#ident "$Id: fileread.c,v 1.2 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* read.c
*
* Reading from a file
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include "file.h"
ssize_t __file_read(struct file_info *fp, void *buf, size_t count)
{
com32sys_t ireg, oreg;
char *bufp = buf;
size_t n = 0;
size_t ncopy;
memset(&ireg, 0, sizeof ireg);
ireg.eax.w[0] = 0x0007; /* Read file */
ireg.esi.w[0] = OFFS(__com32.cs_bounce);
ireg.es = SEG(__com32.cs_bounce);
while ( count ) {
if ( fp->i.nbytes == 0 ) {
if ( fp->i.offset >= fp->i.length || !fp->i.filedes )
return n; /* As good as it gets... */
ireg.esi.w[0] = fp->i.filedes;
ireg.ecx.w[0] = MAXBLOCK >> fp->i.blocklg2;
__intcall(0x22, &ireg, &oreg);
if ( oreg.eflags.l & EFLAGS_CF ) {
errno = EIO;
return -1;
}
fp->i.filedes = ireg.esi.w[0];
fp->i.nbytes = min(fp->i.length-fp->i.offset, (unsigned)MAXBLOCK);
fp->i.datap = fp->i.buf;
memcpy(fp->i.buf, __com32.cs_bounce, fp->i.nbytes);
}
ncopy = min(count, fp->i.nbytes);
memcpy(bufp, fp->i.datap, ncopy);
n += ncopy;
bufp += ncopy;
count -= ncopy;
fp->i.datap += ncopy;
fp->i.offset += ncopy;
fp->i.nbytes -= ncopy;
}
return n;
}

Binary file not shown.

View File

@@ -0,0 +1,18 @@
/*
* sys/ftell.c
*
* We can't seek, but we can at least tell...
*/
#include <stdio.h>
#include "sys/file.h"
long ftell(FILE *stream)
{
int fd = fileno(stream);
struct file_info *fp = &__file_info[fd];
return fp->i.offset;
}

Binary file not shown.

View File

@@ -0,0 +1,49 @@
#ident "$Id: idle.c,v 1.1 2005/01/20 18:41:12 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2005 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* idle.c
*
* What to do in a busy loop...
*/
#include <syslinux.h>
#include <stddef.h>
#include <com32.h>
void syslinux_idle(void)
{
static com32sys_t sys_idle = {
.eax.l = 0x0013,
};
/* This call isn't supported on SYSLINUX < 3.08, but all it does
is return an error, so we don't care. */
__intcall(0x22, &sys_idle, NULL);
}

Binary file not shown.

View File

@@ -0,0 +1,53 @@
#ident "$Id: isatty.c,v 1.2 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* isatty.c
*
* Return if this is a tty or not
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include <unistd.h>
#include <klibc/compiler.h>
#include "file.h"
int isatty(int fd)
{
struct file_info *fp = &__file_info[fd];
if ( fd >= NFILES || !fp->iop ) {
errno = EBADF;
return -1;
}
return (fp->iop->flags & __DEV_TTY);
}

Binary file not shown.

View File

@@ -0,0 +1,90 @@
#ident "$Id: line_input.c,v 1.6 2005/01/20 18:41:12 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* line_input.c
*
* Line-oriented input discupline
*/
#include "file.h"
#include <errno.h>
#include <syslinux.h>
ssize_t __line_input(struct file_info *fp, char *buf, size_t bufsize,
ssize_t (*get_char)(struct file_info *, void *, size_t))
{
size_t n = 0;
char ch;
int rv;
ssize_t (* const Write)(struct file_info *, const void *, size_t) =
fp->oop->write;
for(;;) {
rv = get_char(fp, &ch, 1);
if ( rv != 1 ) {
syslinux_idle();
continue;
}
switch ( ch ) {
case '\n': /* Ignore incoming linefeed */
break;
case '\r':
*buf = '\n';
Write(fp, "\n", 1);
return n+1;
case '\b':
if ( n > 0 ) {
n--; buf--;
Write(fp, "\b \b", 3);
}
break;
case '\x15': /* Ctrl-U */
while ( n ) {
n--; buf--;
Write(fp, "\b \b", 3);
}
break;
default:
if ( n < bufsize-1 ) {
*buf = ch;
Write(fp, buf, 1);
n++;
buf++;
}
break;
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,53 @@
#ident "$Id: null_read.c,v 1.1 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* null_read.c
*
* Reading null device
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include "file.h"
static ssize_t __null_read(struct file_info *fp, void *buf, size_t count)
{
(void)fp; (void)buf; (void)count;
return 0;
}
const struct input_dev dev_null_r = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_INPUT | __DEV_NULL,
.fileflags = O_RDONLY,
.read = __null_read,
.close = NULL,
};

Binary file not shown.

View File

@@ -0,0 +1,53 @@
#ident "$Id: null_write.c,v 1.1 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* null_write.c
*
* Null writing device
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include "file.h"
static ssize_t __null_write(struct file_info *fp, const void *buf, size_t count)
{
(void)fp; (void)buf; (void)count;
return count;
}
const struct output_dev dev_null_w = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_OUTPUT | __DEV_NULL,
.fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
.write = __null_write,
.close = NULL,
};

Binary file not shown.

View File

@@ -0,0 +1,90 @@
#ident "$Id: open.c,v 1.4 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2003-2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
#include <errno.h>
#include <com32.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "file.h"
/*
* open.c
*
* Open an ordinary file
*/
extern ssize_t __file_read(struct file_info *, void *, size_t);
extern int __file_close(struct file_info *);
static const struct input_dev file_dev = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_FILE | __DEV_INPUT,
.fileflags = O_RDONLY,
.read = __file_read,
.close = __file_close,
};
int open(const char *pathname, int flags, ...)
{
com32sys_t regs;
int fd;
struct file_info *fp;
fd = opendev(&file_dev, NULL, flags);
if ( fd < 0 )
return -1;
fp = &__file_info[fd];
strlcpy(__com32.cs_bounce, pathname, __com32.cs_bounce_size);
regs.eax.w[0] = 0x0006;
regs.esi.w[0] = OFFS(__com32.cs_bounce);
regs.es = SEG(__com32.cs_bounce);
__com32.cs_intcall(0x22, &regs, &regs);
if ( (regs.eflags.l & EFLAGS_CF) || regs.esi.w[0] == 0 ) {
errno = ENOENT;
return -1;
}
{
uint16_t blklg2;
asm("bsrw %1,%0" : "=r" (blklg2) : "rm" (regs.ecx.w[0]));
fp->i.blocklg2 = blklg2;
}
fp->i.length = regs.eax.l;
fp->i.filedes = regs.esi.w[0];
fp->i.offset = 0;
fp->i.nbytes = 0;
return fd;
}

Binary file not shown.

View File

@@ -0,0 +1,52 @@
#ident "$Id: openconsole.c,v 1.2 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* openconsole.c
*
* Open the chosen console device
*/
#include <unistd.h>
#include <console.h>
#include <fcntl.h>
int openconsole(const struct input_dev *idev, const struct output_dev *odev)
{
close(0);
if ( opendev(idev, odev, O_RDONLY) != 0 )
return -1;
close(1);
if ( opendev(idev, odev, O_WRONLY) != 1 )
return -1;
close(2);
if ( opendev(idev, odev, O_WRONLY) != 2 )
return -1;
return 0;
}

Binary file not shown.

View File

@@ -0,0 +1,69 @@
#ident "$Id: opendev.c,v 1.3 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2003-2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
#include <errno.h>
#include <com32.h>
#include <string.h>
#include "file.h"
/*
* opendev.c
*
* Open a special device
*/
int opendev(const struct input_dev *idev, const struct output_dev *odev, int flags)
{
int fd;
struct file_info *fp;
int okflags;
okflags = (idev ? idev->fileflags : 0) | (odev ? odev->fileflags : 0);
if ( !(flags & 3) || (flags & ~okflags) ) {
errno = EINVAL;
return -1;
}
for ( fd = 0, fp = __file_info ; fd < NFILES ; fd++, fp++ )
if ( !fp->iop && !fp->oop )
break;
if ( fd >= NFILES ) {
errno = EMFILE;
return -1;
}
fp->iop = idev ? idev : &dev_error_r;
fp->oop = odev ? odev : &dev_error_w;
fp->i.offset = 0;
fp->i.nbytes = 0;
fp->i.datap = fp->i.buf;
return fd;
}

Binary file not shown.

View File

@@ -0,0 +1,80 @@
#ident "$Id: rawcon_read.c,v 1.5 2005/01/20 18:41:12 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* rawcon_read.c
*
* Character-oriented reading from the console without echo;
* this is a NONBLOCKING device.
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include <sys/times.h>
#include "file.h"
/* Global, since it's used by stdcon_read */
ssize_t __rawcon_read(struct file_info *fp, void *buf, size_t count)
{
com32sys_t ireg, oreg;
char *bufp = buf;
size_t n = 0;
clock_t start;
(void)fp;
memset(&ireg, 0, sizeof ireg);
start = times(NULL);
while ( n < count ) {
/* Poll */
ireg.eax.b[1] = 0x0B;
__intcall(0x21, &ireg, &oreg);
if ( !oreg.eax.b[0] )
break;
/* We have data, go get it */
ireg.eax.b[1] = 0x08;
__intcall(0x21, &ireg, &oreg);
*bufp++ = oreg.eax.b[0];
n++;
}
return n;
}
const struct input_dev dev_rawcon_r = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_TTY | __DEV_INPUT,
.fileflags = O_RDONLY,
.read = __rawcon_read,
.close = NULL,
};

Binary file not shown.

View File

@@ -0,0 +1,67 @@
#ident "$Id: rawcon_write.c,v 1.2 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* rawcon_write.c
*
* Raw writing to the console; no \n -> \r\n translation
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include "file.h"
static ssize_t __rawcon_write(struct file_info *fp, const void *buf, size_t count)
{
com32sys_t ireg;
const char *bufp = buf;
size_t n = 0;
(void)fp;
memset(&ireg, 0, sizeof ireg);
ireg.eax.b[1] = 0x02;
while ( count-- ) {
ireg.edx.b[0] = *bufp++;
__intcall(0x21, &ireg, NULL);
n++;
}
return n;
}
const struct output_dev dev_rawcon_w = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_TTY | __DEV_OUTPUT,
.fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
.write = __rawcon_write,
.close = NULL,
};

Binary file not shown.

View File

@@ -0,0 +1,52 @@
#ident "$Id: read.c,v 1.3 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* read.c
*
* Reading from a file descriptor
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include <klibc/compiler.h>
#include "file.h"
ssize_t read(int fd, void *buf, size_t count)
{
struct file_info *fp = &__file_info[fd];
if ( fd >= NFILES || !fp->iop ) {
errno = EBADF;
return -1;
}
return fp->iop->read(fp, buf, count);
}

Binary file not shown.

View File

@@ -0,0 +1,67 @@
#ident "$Id: serial_write.c,v 1.2 2004/11/30 22:09:56 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* serial_write.c
*
* Raw writing to the serial port; no \n -> \r\n translation
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include "file.h"
ssize_t __serial_write(struct file_info *fp, const void *buf, size_t count)
{
com32sys_t ireg;
const char *bufp = buf;
size_t n = 0;
(void)fp;
memset(&ireg, 0, sizeof ireg);
ireg.eax.b[1] = 0x04;
while ( count-- ) {
ireg.edx.b[0] = *bufp++;
__intcall(0x21, &ireg, NULL);
n++;
}
return n;
}
const struct output_dev dev_serial_w = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_TTY | __DEV_OUTPUT,
.fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
.write = __serial_write,
.close = NULL,
};

Binary file not shown.

View File

@@ -0,0 +1,77 @@
#ident "$Id: stdcon_read.c,v 1.3 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* stdcon_read.c
*
* Line-oriented reading from the standard console
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include "file.h"
extern ssize_t __rawcon_read(struct file_info *fp, void *buf, size_t count);
static ssize_t __stdcon_read(struct file_info *fp, void *buf, size_t count)
{
char *bufp = buf;
size_t n = 0;
char ch;
(void)fp;
while ( n < count ) {
if ( fp->i.nbytes ) {
ch = *bufp++ = *fp->i.datap++;
fp->i.nbytes--;
n++;
if ( ch == '\n' )
return n;
} else {
fp->i.nbytes = __line_input(fp, fp->i.buf, MAXBLOCK,
__rawcon_read);
fp->i.datap = fp->i.buf;
if ( fp->i.nbytes == 0 )
return n;
}
}
return n;
}
const struct input_dev dev_stdcon_r = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_TTY | __DEV_INPUT,
.fileflags = O_RDONLY,
.read = __stdcon_read,
.close = NULL,
};

Binary file not shown.

View File

@@ -0,0 +1,71 @@
#ident "$Id: stdcon_write.c,v 1.3 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* stdcon_write.c
*
* Writing to the console
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include "file.h"
static ssize_t __stdcon_write(struct file_info *fp, const void *buf, size_t count)
{
com32sys_t ireg;
const char *bufp = buf;
size_t n = 0;
(void)fp;
memset(&ireg, 0, sizeof ireg);
ireg.eax.b[1] = 0x02;
while ( count-- ) {
if ( *bufp == '\n' ) {
ireg.edx.b[0] = '\r';
__intcall(0x21, &ireg, NULL);
}
ireg.edx.b[0] = *bufp++;
__intcall(0x21, &ireg, NULL);
n++;
}
return n;
}
const struct output_dev dev_stdcon_w = {
.dev_magic = __DEV_MAGIC,
.flags = __DEV_TTY | __DEV_OUTPUT,
.fileflags = O_WRONLY | O_CREAT | O_TRUNC | O_APPEND,
.write = __stdcon_write,
.close = NULL,
};

Binary file not shown.

View File

@@ -0,0 +1,45 @@
#ident "$Id: times.c,v 1.1 2004/12/20 22:28:30 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* sys/times.c
*
* Returns something like a clock.
*/
#include <sys/times.h>
#include <inttypes.h>
#include <com32.h>
clock_t times(struct tms *buf)
{
(void)buf; /* Ignored */
/* Should we get this via INT 1Ah? */
return *(uint16_t *)0x46c;
}

Binary file not shown.

View File

@@ -0,0 +1,52 @@
#ident "$Id: write.c,v 1.3 2004/11/23 23:43:02 hpa Exp $"
/* ----------------------------------------------------------------------- *
*
* Copyright 2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall
* be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* ----------------------------------------------------------------------- */
/*
* write.c
*
* Write to a file descriptor
*/
#include <errno.h>
#include <string.h>
#include <com32.h>
#include <minmax.h>
#include <klibc/compiler.h>
#include "file.h"
ssize_t write(int fd, void *buf, size_t count)
{
struct file_info *fp = &__file_info[fd];
if ( fd >= NFILES || !fp->oop ) {
errno = EBADF;
return -1;
}
return fp->oop->write(fp, buf, count);
}

Binary file not shown.