- cleaned up
- introduced generic UART-lowlevel I/O with interface object (less functions, which do the same) - added PS2-I/O and keycode translator (quick'n dirty) - writechar(), readchar() and _putchar() have now a port parameter - there are now 3 console interfaces available UART0, UART1 and PS2/VGA - the small function GetPort() maps between filei ID and low-level port - the small function GetPort() maps between Committed on the Free edition of March Hare Software CVSNT Server. Upgrade to CVS Suite for more features and support: http://march-hare.com/cvsnt/ git-svn-id: http://moon:8086/svn/vhdl/trunk@623 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
+427
-126
@@ -7,8 +7,102 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "libsys.h"
|
#include "libsys.h"
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
|
// Types
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
UINT32 GetPort(int file)
|
||||||
|
{
|
||||||
|
if (file == 0)
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
if (file == 1)
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
if (file == 2)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
IF_TYPE_INVALID = 0,
|
||||||
|
IF_TYPE_UART,
|
||||||
|
IF_TYPE_PS2,
|
||||||
|
IF_TYPE_VGA
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct _suart_if_t
|
||||||
|
{
|
||||||
|
volatile UINT32 *pCTRL;
|
||||||
|
volatile UINT32 *pDATA;
|
||||||
|
volatile UINT32 *pBAUD;
|
||||||
|
} uart_if_t;
|
||||||
|
|
||||||
|
typedef struct _sps2_if_t
|
||||||
|
{
|
||||||
|
volatile UINT32 *pCTRL;
|
||||||
|
volatile UINT32 *pDATA;
|
||||||
|
} ps2_if_t;
|
||||||
|
|
||||||
|
typedef struct _svga_if_t
|
||||||
|
{
|
||||||
|
volatile UINT32 *pCTRL;
|
||||||
|
volatile UINT32 *pDATA;
|
||||||
|
volatile UINT32 *pCSRX;
|
||||||
|
volatile UINT32 *pCSRY;
|
||||||
|
} vga_if_t;
|
||||||
|
|
||||||
|
typedef struct _scon_if_in_t
|
||||||
|
{
|
||||||
|
UINT32 type;
|
||||||
|
void *pIF;
|
||||||
|
} con_if_in_t;
|
||||||
|
|
||||||
|
typedef struct _scon_if_out_t
|
||||||
|
{
|
||||||
|
UINT32 type;
|
||||||
|
void *pIF;
|
||||||
|
} con_if_out_t;
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
|
// Globals
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
|
static uart_if_t uart_if[2] =
|
||||||
|
{
|
||||||
|
{(UINT32*)sys_uart0_stat, (UINT32*)sys_uart0_data, (UINT32*)sys_uart0_baud},
|
||||||
|
{(UINT32*)sys_uart1_stat, (UINT32*)sys_uart1_data, (UINT32*)sys_uart1_baud}
|
||||||
|
};
|
||||||
|
|
||||||
|
static ps2_if_t ps2_if[2] =
|
||||||
|
{
|
||||||
|
{(UINT32*)sys_ps2_0_stat, (UINT32*)sys_ps2_0_data},
|
||||||
|
{(UINT32*)sys_ps2_1_stat, (UINT32*)sys_ps2_1_data}
|
||||||
|
};
|
||||||
|
|
||||||
|
static vga_if_t vga_if =
|
||||||
|
{
|
||||||
|
(UINT32*)sys_vga_ctrl, (UINT32*)sys_vga_ascii, (UINT32*)sys_vga_posx, (UINT32*)sys_vga_posy
|
||||||
|
};
|
||||||
|
|
||||||
|
static con_if_in_t con_if_in[4] =
|
||||||
|
{
|
||||||
|
{IF_TYPE_UART, &uart_if[0]},
|
||||||
|
{IF_TYPE_UART, &uart_if[1]},
|
||||||
|
{IF_TYPE_PS2, &ps2_if[0]},
|
||||||
|
{IF_TYPE_PS2, &ps2_if[1]}
|
||||||
|
};
|
||||||
|
|
||||||
|
static con_if_out_t con_if_out[4] =
|
||||||
|
{
|
||||||
|
{IF_TYPE_UART, &uart_if[0]},
|
||||||
|
{IF_TYPE_UART, &uart_if[1]},
|
||||||
|
{IF_TYPE_VGA, &vga_if},
|
||||||
|
{IF_TYPE_INVALID, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------
|
||||||
// MIPS specific
|
// MIPS specific
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
UINT32 CP0_SR_read(void)
|
UINT32 CP0_SR_read(void)
|
||||||
{
|
{
|
||||||
UINT32 result;
|
UINT32 result;
|
||||||
@@ -149,142 +243,349 @@ void DCACHE_invalidate_at(UINT32* pPtr)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
int UART0_readchar(void)
|
// BEGIN QUICK AND DIRTY
|
||||||
|
// -------------------------------------------------------------
|
||||||
|
//keymap for the AT keyboard SG layout
|
||||||
|
typedef struct
|
||||||
{
|
{
|
||||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart0_stat;
|
char scancode;
|
||||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart0_data;
|
char unshifted;
|
||||||
|
char shifted;
|
||||||
|
} libsys_key_entry_t;
|
||||||
|
|
||||||
if (0x10 & *pUART_stat)
|
#define SHIFTED (1<<0)
|
||||||
return (*pUART_data & 0xFF);
|
#define ALTERED (1<<1)
|
||||||
|
#define CONTROLLED (1<<2)
|
||||||
|
|
||||||
return -1;
|
static const libsys_key_entry_t __keymap[] =
|
||||||
|
{
|
||||||
|
{0x1c, 'a', 'A'},
|
||||||
|
{0x32, 'b', 'B'},
|
||||||
|
{0x21, 'c', 'C'},
|
||||||
|
{0x23, 'd', 'D'},
|
||||||
|
{0x24, 'e', 'E'},
|
||||||
|
{0x2b, 'f', 'F'},
|
||||||
|
{0x34, 'g', 'G'},
|
||||||
|
{0x33, 'h', 'H'},
|
||||||
|
{0x43, 'i', 'I'},
|
||||||
|
{0x3b, 'j', 'J'},
|
||||||
|
{0x42, 'k', 'K'},
|
||||||
|
{0x4b, 'l', 'L'},
|
||||||
|
{0x3a, 'm', 'M'},
|
||||||
|
{0x31, 'n', 'N'},
|
||||||
|
{0x44, 'o', 'O'},
|
||||||
|
{0x4d, 'p', 'P'},
|
||||||
|
{0x15, 'q', 'Q'},
|
||||||
|
{0x2d, 'r', 'R'},
|
||||||
|
{0x1b, 's', 'S'},
|
||||||
|
{0x2c, 't', 'T'},
|
||||||
|
{0x3c, 'u', 'U'},
|
||||||
|
{0x2a, 'v', 'V'},
|
||||||
|
{0x1d, 'w', 'W'},
|
||||||
|
{0x22, 'x', 'X'},
|
||||||
|
{0x1a, 'y', 'Y'},
|
||||||
|
{0x35, 'z', 'Z'},
|
||||||
|
{0x16, '1', '+'},
|
||||||
|
{0x1e, '2', '"'},
|
||||||
|
{0x26, '3', '*'},
|
||||||
|
{0x25, '4', 'ç'},
|
||||||
|
{0x2e, '5', '%'},
|
||||||
|
{0x36, '6', '&'},
|
||||||
|
{0x3d, '7', '/'},
|
||||||
|
{0x3e, '8', '('},
|
||||||
|
{0x46, '9', ')'},
|
||||||
|
{0x45, '0', '='},
|
||||||
|
{0x29, ' ', ' '},
|
||||||
|
{0x41, ',', ';'},
|
||||||
|
{0x49, '.', ':'},
|
||||||
|
{0x4a, '-', '_'},
|
||||||
|
{0x76, '\x1b', '\x1b'}, //ESC
|
||||||
|
{0x5a, '\n', '\n'}, //RETURN
|
||||||
|
{0x0d, '\t', '\t'}, //TAB
|
||||||
|
{0x66, '\b', '\b'}, //BS
|
||||||
|
{0} //sentinel
|
||||||
|
};
|
||||||
|
|
||||||
|
static char __findkey(char scancode, int mode)
|
||||||
|
{
|
||||||
|
const libsys_key_entry_t *p = __keymap;
|
||||||
|
while (p->scancode)
|
||||||
|
{
|
||||||
|
if (p->scancode == scancode)
|
||||||
|
{
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case SHIFTED:
|
||||||
|
return p->shifted;
|
||||||
|
case ALTERED:
|
||||||
|
case ALTERED|SHIFTED:
|
||||||
|
default:
|
||||||
|
return p->unshifted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UART0_writechar(char c)
|
#define RELEASE 0x8000
|
||||||
|
#define SPECIALKEY 0x4000
|
||||||
|
#define EXTENDED 0x2000
|
||||||
|
#define X_CONTROLLED 0x0400
|
||||||
|
#define X_ALTERED 0x0200
|
||||||
|
#define X_SHIFTED 0x0100
|
||||||
|
#define CAPS (SPECIALKEY|0x58)
|
||||||
|
#define F1 (SPECIALKEY|0x05)
|
||||||
|
#define F2 (SPECIALKEY|0x06)
|
||||||
|
#define F3 (SPECIALKEY|0x04)
|
||||||
|
#define F4 (SPECIALKEY|0x0c)
|
||||||
|
#define F5 (SPECIALKEY|0x03)
|
||||||
|
#define F6 (SPECIALKEY|0x0b)
|
||||||
|
#define F7 (SPECIALKEY|0x83)
|
||||||
|
#define F8 (SPECIALKEY|0x0a)
|
||||||
|
#define F9 (SPECIALKEY|0x01)
|
||||||
|
#define F10 (SPECIALKEY|0x09)
|
||||||
|
#define F11 (SPECIALKEY|0x78)
|
||||||
|
#define F12 (SPECIALKEY|0x07)
|
||||||
|
#define ARROW_UP (SPECIALKEY|EXTENDED|0x75)
|
||||||
|
#define ARROW_DOWN (SPECIALKEY|EXTENDED|0x72)
|
||||||
|
#define ARROW_LEFT (SPECIALKEY|EXTENDED|0x6b)
|
||||||
|
#define ARROW_RIGHT (SPECIALKEY|EXTENDED|0x74)
|
||||||
|
|
||||||
|
UINT32 PS2_readchar(ps2_if_t *pIF)
|
||||||
{
|
{
|
||||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart0_stat;
|
if (!pIF)
|
||||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart0_data;
|
return -1;
|
||||||
|
|
||||||
while((0x01 & *pUART_stat) != 0);
|
while (!(sys_ps2_bit_rx_avail & *pIF->pCTRL));
|
||||||
|
|
||||||
|
return (*pIF->pDATA & 0xFF);
|
||||||
|
|
||||||
*pUART_data = (UINT32)c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int UART1_readchar(void)
|
int con_readchar(ps2_if_t *pIF)
|
||||||
{
|
|
||||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart1_stat;
|
|
||||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart1_data;
|
|
||||||
|
|
||||||
if (0x10 & *pUART_stat)
|
|
||||||
return (*pUART_data & 0xFF);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UART1_writechar(char c)
|
|
||||||
{
|
|
||||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart1_stat;
|
|
||||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart1_data;
|
|
||||||
|
|
||||||
while((0x01 & *pUART_stat) != 0);
|
|
||||||
|
|
||||||
*pUART_data = (UINT32)c;
|
|
||||||
}
|
|
||||||
|
|
||||||
int UART2_readchar(void)
|
|
||||||
{
|
|
||||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart2_stat;
|
|
||||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart2_data;
|
|
||||||
|
|
||||||
if (0x10 & *pUART_stat)
|
|
||||||
return (*pUART_data & 0xFF);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UART2_writechar(char c)
|
|
||||||
{
|
|
||||||
volatile UINT32 *pUART_stat = (UINT32*)sys_uart2_stat;
|
|
||||||
volatile UINT32 *pUART_data = (UINT32*)sys_uart2_data;
|
|
||||||
|
|
||||||
while((0x01 & *pUART_stat) != 0);
|
|
||||||
|
|
||||||
*pUART_data = (UINT32)c;
|
|
||||||
}
|
|
||||||
|
|
||||||
char readchar(void)
|
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
static char mode = 0;
|
||||||
|
static char nextrelease = 0;
|
||||||
|
static char extended = 0;
|
||||||
|
int flags = 0;
|
||||||
|
int char_valid = 0;
|
||||||
|
UINT8 key;
|
||||||
|
|
||||||
|
key = PS2_readchar(pIF);
|
||||||
|
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case 0xf0: //release key
|
||||||
|
nextrelease = 1;
|
||||||
|
break;
|
||||||
|
case 0x14: //control key
|
||||||
|
if (nextrelease)
|
||||||
|
{
|
||||||
|
mode &= ~CONTROLLED;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
mode |= CONTROLLED;
|
||||||
|
}
|
||||||
|
nextrelease = 0;
|
||||||
|
break;
|
||||||
|
case 0x12: //left SHIFT
|
||||||
|
case 0x59: //right SHIFT
|
||||||
|
if (nextrelease)
|
||||||
|
{
|
||||||
|
mode &= ~SHIFTED;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
mode |= SHIFTED;
|
||||||
|
}
|
||||||
|
nextrelease = 0;
|
||||||
|
break;
|
||||||
|
case 0x11: //left and right ALT (right one also with E0)
|
||||||
|
if (nextrelease)
|
||||||
|
{
|
||||||
|
mode &= ~ALTERED;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
mode |= ALTERED;
|
||||||
|
}
|
||||||
|
nextrelease = 0;
|
||||||
|
break;
|
||||||
|
case 0xe0: //extended key following
|
||||||
|
extended = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (nextrelease) flags |= RELEASE;
|
||||||
|
if (extended) flags |= EXTENDED;
|
||||||
|
flags |= mode << 8;
|
||||||
|
c = __findkey(key, mode);
|
||||||
|
char_valid = (c && ((flags & RELEASE) != RELEASE));
|
||||||
|
nextrelease = 0;
|
||||||
|
extended = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (char_valid)
|
||||||
|
{
|
||||||
|
// printf("c = %c (%d), flags = 0x%08X, mode = 0x%08X\n", c, c, flags, mode);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// -------------------------------------------------------------
|
||||||
|
// END QUICK AND DIRTY
|
||||||
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
|
// ------------------------------------
|
||||||
|
// Low-level I/O
|
||||||
|
// ------------------------------------
|
||||||
|
int UART_readchar(uart_if_t *pIF)
|
||||||
|
{
|
||||||
|
if (!pIF)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (sys_uart_bit_rx_avail & *pIF->pCTRL)
|
||||||
|
return (*pIF->pDATA & 0xFF);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UART_writechar(uart_if_t *pIF, char c)
|
||||||
|
{
|
||||||
|
if (!pIF)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while((sys_uart_bit_tx_halffull & *pIF->pCTRL) != 0);
|
||||||
|
|
||||||
|
*pIF->pDATA = (UINT32)c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cg_writechar(vga_if_t *pIF, char c)
|
||||||
|
{
|
||||||
|
if (!pIF)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (!(*pIF->pCTRL & sys_vga_bit_cgrdy));
|
||||||
|
*pIF->pDATA = (UINT32)c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cg_clr_line(vga_if_t *pIF)
|
||||||
|
{
|
||||||
|
if (!pIF)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (!(*pIF->pCTRL & sys_vga_bit_cgrdy));
|
||||||
|
*pIF->pCTRL |= sys_vga_bit_clrline;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cg_clr_screen(vga_if_t *pIF)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!pIF)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (!(*pIF->pCTRL & sys_vga_bit_cgrdy));
|
||||||
|
*pIF->pCTRL |= sys_vga_bit_clrscr;
|
||||||
|
|
||||||
|
// Cursor home
|
||||||
|
while (!(*pIF->pCTRL & sys_vga_bit_cgrdy));
|
||||||
|
*pIF->pCSRX = 0;
|
||||||
|
|
||||||
|
while (!(*pIF->pCTRL & sys_vga_bit_cgrdy));
|
||||||
|
*pIF->pCSRY = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void clr_screen(void)
|
||||||
|
{
|
||||||
|
cg_clr_screen(&vga_if);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------
|
||||||
|
char readchar(UINT32 port)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
con_if_in_t *pIF;
|
||||||
|
|
||||||
|
pIF = &con_if_in[port];
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
c = UART0_readchar();
|
switch(pIF->type)
|
||||||
|
{
|
||||||
|
case IF_TYPE_UART:
|
||||||
|
c = UART_readchar((uart_if_t*)pIF->pIF);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IF_TYPE_PS2:
|
||||||
|
c = con_readchar((ps2_if_t*)pIF->pIF);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
} while(c < 0);
|
} while(c < 0);
|
||||||
|
|
||||||
return (char)c;
|
return (char)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writechar(char c)
|
void writechar(UINT32 port, char c)
|
||||||
{
|
{
|
||||||
UART0_writechar(c);
|
con_if_out_t *pIF;
|
||||||
}
|
|
||||||
|
|
||||||
void _ser_putchar(char c)
|
pIF = &con_if_out[port];
|
||||||
{
|
|
||||||
if (c == 0x0A)
|
switch(pIF->type)
|
||||||
{
|
{
|
||||||
writechar(0x0D);
|
case IF_TYPE_UART:
|
||||||
|
UART_writechar((uart_if_t*)pIF->pIF, c);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IF_TYPE_VGA:
|
||||||
|
cg_writechar((vga_if_t*)pIF->pIF, c);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
writechar(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cg_writechar(char c)
|
void _putchar(UINT32 port, char c)
|
||||||
{
|
{
|
||||||
volatile UINT32 *pCG_ctrl = (UINT32*)sys_vga_ctrl;
|
|
||||||
volatile UINT32 *pCG_ascii = (UINT32*)sys_vga_ascii;
|
|
||||||
|
|
||||||
while (!(*pCG_ctrl & sys_vga_bit_cgrdy));
|
con_if_out_t *pIF;
|
||||||
*pCG_ascii = (UINT32)c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cg_clr_line(void)
|
pIF = &con_if_out[port];
|
||||||
{
|
|
||||||
volatile UINT32 *pCG_ctrl = (UINT32*)sys_vga_ctrl;
|
|
||||||
|
|
||||||
while (!(*pCG_ctrl & sys_vga_bit_cgrdy));
|
switch(pIF->type)
|
||||||
*pCG_ctrl |= sys_vga_bit_clrline;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cg_clr_screen(void)
|
|
||||||
{
|
|
||||||
volatile UINT32 *pCG_ctrl = (UINT32*)sys_vga_ctrl;
|
|
||||||
volatile UINT32 *pCG_x = (UINT32*)sys_vga_posx;
|
|
||||||
volatile UINT32 *pCG_y = (UINT32*)sys_vga_posy;
|
|
||||||
|
|
||||||
while (!(*pCG_ctrl & sys_vga_bit_cgrdy));
|
|
||||||
*pCG_ctrl |= sys_vga_bit_clrscr;
|
|
||||||
|
|
||||||
// Cursor home
|
|
||||||
while (!(*pCG_ctrl & sys_vga_bit_cgrdy));
|
|
||||||
*pCG_x = 0;
|
|
||||||
|
|
||||||
while (!(*pCG_ctrl & sys_vga_bit_cgrdy));
|
|
||||||
*pCG_y = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void _cg_putchar(char c)
|
|
||||||
{
|
|
||||||
if (c == 0x0A)
|
|
||||||
{
|
{
|
||||||
cg_writechar(0x0D);
|
case IF_TYPE_UART:
|
||||||
}
|
if (c == 0x0A)
|
||||||
cg_writechar(c);
|
UART_writechar((uart_if_t*)pIF->pIF, 0x0D);
|
||||||
if (c == 0x0A)
|
UART_writechar((uart_if_t*)pIF->pIF, c);
|
||||||
cg_clr_line();
|
break;
|
||||||
|
|
||||||
|
case IF_TYPE_VGA:
|
||||||
|
cg_writechar((vga_if_t*)pIF->pIF, c);
|
||||||
|
if (c == 0x0A)
|
||||||
|
{
|
||||||
|
cg_writechar((vga_if_t*)pIF->pIF, 0x0D);
|
||||||
|
cg_clr_line((vga_if_t*)pIF->pIF);
|
||||||
|
}
|
||||||
|
if (c == 0x0D)
|
||||||
|
{
|
||||||
|
cg_writechar((vga_if_t*)pIF->pIF, 0x0A);
|
||||||
|
cg_clr_line((vga_if_t*)pIF->pIF);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _exit (int exitcode)
|
void _exit (int exitcode)
|
||||||
@@ -401,7 +702,7 @@ caddr_t sbrk(int incr)
|
|||||||
|
|
||||||
int fstat(int file, struct stat *st)
|
int fstat(int file, struct stat *st)
|
||||||
{
|
{
|
||||||
// sputs("fstat\n");
|
// sputs("fstat ("); print_word(file); sputs(")\n");
|
||||||
st->st_mode = S_IFCHR;
|
st->st_mode = S_IFCHR;
|
||||||
st->st_blksize = 0;
|
st->st_blksize = 0;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -409,38 +710,41 @@ int fstat(int file, struct stat *st)
|
|||||||
|
|
||||||
int lseek(int file, int ptr, int dir)
|
int lseek(int file, int ptr, int dir)
|
||||||
{
|
{
|
||||||
// sputs("lseek\n");
|
// sputs("lseek ("); print_word(file); sputs(")\n");
|
||||||
errno = ESPIPE;
|
errno = ESPIPE;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int open(const char *name, int flags, int mode)
|
int open(const char *name, int flags, int mode)
|
||||||
{
|
{
|
||||||
// sputs("open\n");
|
// sputs("open (\""); sputs(name); sputs("\")\n");
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int close(int file)
|
int close(int file)
|
||||||
{
|
{
|
||||||
// sputs("close\n");
|
// sputs("close ("); print_word(file); sputs(")\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read(int file, char *ptr, int len)
|
int read(int file, char *ptr, int len)
|
||||||
{
|
{
|
||||||
|
UINT32 port;
|
||||||
int i;
|
int i;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
// sputs("read\n");
|
// sputs("read ("); print_word(file); sputs(")\n");
|
||||||
i = 0;
|
i = 0;
|
||||||
|
port = GetPort(file);
|
||||||
|
|
||||||
while (i < len)
|
while (i < len)
|
||||||
{
|
{
|
||||||
c = readchar();
|
c = readchar(port);
|
||||||
if ((c == 0x0D) || (c == 0x0A))
|
if ((c == 0x0D) || (c == 0x0A))
|
||||||
{
|
{
|
||||||
writechar(0x0D);
|
writechar(port, 0x0D);
|
||||||
writechar(0x0A);
|
writechar(port, 0x0A);
|
||||||
if (i==0)
|
if (i==0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -450,7 +754,7 @@ int read(int file, char *ptr, int len)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ptr[i++] = c;
|
ptr[i++] = c;
|
||||||
writechar(c);
|
writechar(port, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
@@ -458,24 +762,21 @@ int read(int file, char *ptr, int len)
|
|||||||
|
|
||||||
int write(int file, char *ptr, int len)
|
int write(int file, char *ptr, int len)
|
||||||
{
|
{
|
||||||
|
UINT32 port;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (file == 1)
|
// sputs("write ("); print_word(file); sputs(")\n");
|
||||||
{
|
|
||||||
for (i=0; i < len; i++)
|
port = GetPort(file);
|
||||||
STDOUT_FUNCTION(*ptr++);
|
for (i=0; i < len; i++)
|
||||||
}
|
_putchar(port, *ptr++);
|
||||||
if (file == 2)
|
|
||||||
{
|
|
||||||
for (i=0; i < len; i++)
|
|
||||||
STDERR_FUNCTION(*ptr++);
|
|
||||||
}
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int isatty(int file)
|
int isatty(int file)
|
||||||
{
|
{
|
||||||
// sputs("Isatty()\n");
|
// sputs("isatty ("); print_word(file); sputs(")\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,7 +786,7 @@ int sputs(char *pStr)
|
|||||||
start = pStr;
|
start = pStr;
|
||||||
|
|
||||||
while(*pStr)
|
while(*pStr)
|
||||||
_putchar(*(pStr++));
|
_putchar(0, *(pStr++));
|
||||||
|
|
||||||
return pStr - start;
|
return pStr - start;
|
||||||
}
|
}
|
||||||
@@ -505,7 +806,7 @@ void print_byte(char byte)
|
|||||||
else
|
else
|
||||||
c = nibble + 'A' - 10;
|
c = nibble + 'A' - 10;
|
||||||
|
|
||||||
_putchar(c);
|
_putchar(0, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,7 +880,7 @@ void memdump(UINT8 *pBuf, int print_offset_only, int num_bytes_per_row, int len)
|
|||||||
if((c < 0x20) || (c > 0x7F))
|
if((c < 0x20) || (c > 0x7F))
|
||||||
c = '.';
|
c = '.';
|
||||||
|
|
||||||
_putchar(c);
|
_putchar(0, c);
|
||||||
cnt_asc--;
|
cnt_asc--;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -4,98 +4,114 @@
|
|||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// Types
|
// Types
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
#define INT8 signed char
|
#define INT8 signed char
|
||||||
#define INT16 signed short
|
#define INT16 signed short
|
||||||
#define INT32 signed int
|
#define INT32 signed int
|
||||||
#define INT64 signed long long
|
#define INT64 signed long long
|
||||||
#define UINT8 unsigned char
|
#define UINT8 unsigned char
|
||||||
#define UINT16 unsigned short
|
#define UINT16 unsigned short
|
||||||
#define UINT32 unsigned int
|
#define UINT32 unsigned int
|
||||||
#define UINT64 unsigned long long
|
#define UINT64 unsigned long long
|
||||||
#define INT INT32
|
#define INT INT32
|
||||||
#define UINT UINT32
|
#define UINT UINT32
|
||||||
#define FLOAT32 float
|
#define FLOAT32 float
|
||||||
#define FLOAT64 double
|
#define FLOAT64 double
|
||||||
|
|
||||||
#define NO_ERROR LSYS_SUCCESS
|
#define NO_ERROR LSYS_SUCCESS
|
||||||
#define ERROR LSYS_ERR_BASE
|
#define ERROR LSYS_ERR_BASE
|
||||||
#define LSYS_SUCCESS 0
|
#define LSYS_SUCCESS 0
|
||||||
#define LSYS_ERR_BASE 0x80000000
|
#define LSYS_ERR_BASE 0x80000000
|
||||||
|
|
||||||
#define IS_ERROR(e) ((e & LSYS_ERR_BASE) == LSYS_ERR_BASE)
|
#define IS_ERROR(e) ((e & LSYS_ERR_BASE) == LSYS_ERR_BASE)
|
||||||
|
|
||||||
#define sys_gpio0 0xA0000000
|
// GPIO
|
||||||
#define sys_gpio1 0xA0000004
|
#define sys_gpio0 0xA0000000
|
||||||
#define sys_led_port sys_gpio0
|
#define sys_gpio1 0xA0000004
|
||||||
#define sys_usb_ctrl sys_gpio1
|
#define sys_led_port sys_gpio0
|
||||||
#define sys_timer_usec 0xA0000008
|
#define sys_usb_ctrl sys_gpio1
|
||||||
#define sys_timer_sec 0xA000000C
|
#define sys_timer_usec 0xA0000008
|
||||||
|
#define sys_timer_sec 0xA000000C
|
||||||
|
|
||||||
#define sys_itim_ctrl 0xA0000018
|
// TIMERs
|
||||||
#define sys_itim_stat 0xA000001C
|
#define sys_itim_ctrl 0xA0000018
|
||||||
#define sys_itim0_cnt 0xA0000020
|
#define sys_itim_stat 0xA000001C
|
||||||
#define sys_itim1_cnt 0xA0000024
|
#define sys_itim0_cnt 0xA0000020
|
||||||
#define sys_itim2_cnt 0xA0000028
|
#define sys_itim1_cnt 0xA0000024
|
||||||
#define sys_itim3_cnt 0xA000002C
|
#define sys_itim2_cnt 0xA0000028
|
||||||
#define sys_itim0_cmp 0xA0000030
|
#define sys_itim3_cnt 0xA000002C
|
||||||
#define sys_itim1_cmp 0xA0000034
|
#define sys_itim0_cmp 0xA0000030
|
||||||
#define sys_itim2_cmp 0xA0000038
|
#define sys_itim1_cmp 0xA0000034
|
||||||
#define sys_itim3_cmp 0xA000003C
|
#define sys_itim2_cmp 0xA0000038
|
||||||
|
#define sys_itim3_cmp 0xA000003C
|
||||||
|
|
||||||
#define sys_uart_data sys_uart0_data
|
// UARTs
|
||||||
#define sys_uart_stat sys_uart0_stat
|
#define sys_uart_bit_tx_halffull 0x00000001
|
||||||
#define sys_uart_baud sys_uart0_baud
|
#define sys_uart_bit_tx_full 0x00000002
|
||||||
#define sys_uart0_data 0xA0010000
|
#define sys_uart_bit_rx_halffull 0x00000004
|
||||||
#define sys_uart0_stat 0xA0010004
|
#define sys_uart_bit_rx_full 0x00000008
|
||||||
#define sys_uart0_baud 0xA0010008
|
#define sys_uart_bit_rx_avail 0x00000010
|
||||||
#define sys_uart1_data 0xA0010100
|
#define sys_uart_bit_tx_inten 0x00000020
|
||||||
#define sys_uart1_stat 0xA0010104
|
#define sys_uart_bit_rx_inten 0x00000040
|
||||||
#define sys_uart1_baud 0xA0010108
|
#define sys_uart_bit_tx_irq 0x00000100
|
||||||
#define sys_uart2_data 0xA0010200
|
#define sys_uart_bit_rx_irq 0x00000200
|
||||||
#define sys_uart2_stat 0xA0010204
|
#define sys_uart_data sys_uart0_data
|
||||||
#define sys_uart2_baud 0xA0010208
|
#define sys_uart_stat sys_uart0_stat
|
||||||
#define sys_usb_data 0xA0020000
|
#define sys_uart_baud sys_uart0_baud
|
||||||
#define sys_usb_mbx 0xA0020004
|
#define sys_uart0_data 0xA0010000
|
||||||
#define sys_usb_addr 0xA0020008
|
#define sys_uart0_stat 0xA0010004
|
||||||
#define sys_usb_status 0xA002000C
|
#define sys_uart0_baud 0xA0010008
|
||||||
#define sys_vga_ctrl 0xA0030000 // R/W
|
#define sys_uart1_data 0xA0010100
|
||||||
#define sys_vga_bit_cgrdy 0x00000001 // RO
|
#define sys_uart1_stat 0xA0010104
|
||||||
#define sys_vga_bit_msten 0x00000002 // R/W
|
#define sys_uart1_baud 0xA0010108
|
||||||
#define sys_vga_bit_clrscr 0x00000010 // WO
|
|
||||||
#define sys_vga_bit_clrline 0x00000020 // WO
|
|
||||||
#define sys_vga_ascii 0xA0030004 // R/W
|
|
||||||
#define sys_vga_posx 0xA0030008 // R/W
|
|
||||||
#define sys_vga_posy 0xA003000C // R/W
|
|
||||||
#define sys_vga_cgcol 0xA0030010 // R/W
|
|
||||||
#define sys_vga_moffs 0xA0030014 // R/W
|
|
||||||
#define sys_vga_resx 0xA0030018 // RO
|
|
||||||
#define sys_vga_resy 0xA003001C // RO
|
|
||||||
#define sys_vga_fps 0xA0030020 // RO
|
|
||||||
#define sys_ac97_stat 0xA0040000
|
|
||||||
#define sys_ac97_ctrl 0xA0040000
|
|
||||||
#define sys_ac97_acstat 0xA0040400
|
|
||||||
#define sys_ac97_acctrl 0xA0040600
|
|
||||||
#define sys_ac97_pcm 0xA0040800
|
|
||||||
#define sys_ac97_wavin sys_ac97_pcm
|
|
||||||
#define sys_ac97_wavout sys_ac97_pcm
|
|
||||||
#define sys_flash_io 0xA4000000
|
|
||||||
#define sys_flash_mem 0x00000000
|
|
||||||
#define sys_ssram_io 0xA8000000
|
|
||||||
|
|
||||||
//#define STDOUT_FUNCTION _cg_putchar // Video character
|
// PS2s
|
||||||
//#define STDERR_FUNCTION _putchar // Serial output
|
#define sys_ps2_bit_tx_empty 0x00000001
|
||||||
|
#define sys_ps2_bit_rx_avail 0x00000004
|
||||||
|
#define sys_ps2_bit_tx_inten 0x00000020
|
||||||
|
#define sys_ps2_bit_rx_inten 0x00000040
|
||||||
|
#define sys_ps2_bit_tx_irq 0x00000100
|
||||||
|
#define sys_ps2_bit_rx_irq 0x00000200
|
||||||
|
#define sys_ps2_0_data 0xA0010200
|
||||||
|
#define sys_ps2_0_stat 0xA0010204
|
||||||
|
#define sys_ps2_1_data 0xA0010300
|
||||||
|
#define sys_ps2_1_stat 0xA0010304
|
||||||
|
|
||||||
#ifndef _putchar
|
// USB
|
||||||
#define _putchar _ser_putchar // Serial output
|
#define sys_usb_data 0xA0020000
|
||||||
#endif
|
#define sys_usb_mbx 0xA0020004
|
||||||
|
#define sys_usb_addr 0xA0020008
|
||||||
|
#define sys_usb_status 0xA002000C
|
||||||
|
|
||||||
#ifndef STDOUT_FUNCTION
|
// VGA
|
||||||
#define STDOUT_FUNCTION _ser_putchar // Serial output
|
#define sys_vga_ctrl 0xA0030000 // R/W
|
||||||
#endif
|
#define sys_vga_bit_cgrdy 0x00000001 // RO
|
||||||
#ifndef STDERR_FUNCTION
|
#define sys_vga_bit_msten 0x00000002 // R/W
|
||||||
#define STDERR_FUNCTION _ser_putchar // Serial output
|
#define sys_vga_bit_clrscr 0x00000010 // WO
|
||||||
#endif
|
#define sys_vga_bit_clrline 0x00000020 // WO
|
||||||
|
#define sys_vga_ascii 0xA0030004 // R/W
|
||||||
|
#define sys_vga_posx 0xA0030008 // R/W
|
||||||
|
#define sys_vga_posy 0xA003000C // R/W
|
||||||
|
#define sys_vga_cgcol 0xA0030010 // R/W
|
||||||
|
#define sys_vga_moffs 0xA0030014 // R/W
|
||||||
|
#define sys_vga_resx 0xA0030018 // RO
|
||||||
|
#define sys_vga_resy 0xA003001C // RO
|
||||||
|
#define sys_vga_fps 0xA0030020 // RO
|
||||||
|
|
||||||
|
// AC'97
|
||||||
|
#define sys_ac97_stat 0xA0040000
|
||||||
|
#define sys_ac97_ctrl 0xA0040000
|
||||||
|
#define sys_ac97_acstat 0xA0040400
|
||||||
|
#define sys_ac97_acctrl 0xA0040600
|
||||||
|
#define sys_ac97_pcm 0xA0040800
|
||||||
|
#define sys_ac97_wavin sys_ac97_pcm
|
||||||
|
#define sys_ac97_wavout sys_ac97_pcm
|
||||||
|
|
||||||
|
// Flash
|
||||||
|
#define sys_flash_io 0xA4000000
|
||||||
|
#define sys_flash_mem 0x00000000
|
||||||
|
|
||||||
|
// Sync. SRAM
|
||||||
|
#define sys_ssram_io 0xA8000000
|
||||||
|
|
||||||
UINT32 CP0_SR_read(void);
|
UINT32 CP0_SR_read(void);
|
||||||
void CP0_SR_write(UINT32 val);
|
void CP0_SR_write(UINT32 val);
|
||||||
@@ -123,8 +139,8 @@ void DCACHE_invalidate_at(UINT32* pPtr);
|
|||||||
#define UART2_setbaud(b) \
|
#define UART2_setbaud(b) \
|
||||||
*((UINT32*)sys_uart2_baud) = CALC_BAUD(b);
|
*((UINT32*)sys_uart2_baud) = CALC_BAUD(b);
|
||||||
|
|
||||||
char readchar(void);
|
char readchar(UINT32 port);
|
||||||
void writechar(char c);
|
void writechar(UINT32 port, char c);
|
||||||
int write(int file, char *ptr, int len);
|
int write(int file, char *ptr, int len);
|
||||||
int sputs(char *pStr);
|
int sputs(char *pStr);
|
||||||
void print_byte(char byte);
|
void print_byte(char byte);
|
||||||
@@ -135,13 +151,7 @@ void sleep(unsigned ms);
|
|||||||
void PrintBuffer8(UINT8 *pBuf, int nbpr, int len);
|
void PrintBuffer8(UINT8 *pBuf, int nbpr, int len);
|
||||||
void memdump(UINT8 *pBuf, int print_offset_only, int num_bytes_per_row, int len);
|
void memdump(UINT8 *pBuf, int print_offset_only, int num_bytes_per_row, int len);
|
||||||
|
|
||||||
// ------------------------------------
|
void clr_screen(void);
|
||||||
// Character Generator functions
|
|
||||||
// ------------------------------------
|
|
||||||
void cg_writechar(char c);
|
|
||||||
void cg_clr_line(void);
|
|
||||||
void cg_clr_screen(void);
|
|
||||||
void _cg_putchar(char c);
|
|
||||||
|
|
||||||
#endif // LIBSYS_H
|
#endif // LIBSYS_H
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user