- refactored libsys
- added critical section - added interrupt global enable/disable - added console::getInstanveByName git-svn-id: http://moon:8086/svn/mips@76 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
+2
-2
@@ -16,7 +16,7 @@ char * volatile pPtr_w;
|
|||||||
volatile int timeout_cnt;
|
volatile int timeout_cnt;
|
||||||
volatile int file_len;
|
volatile int file_len;
|
||||||
|
|
||||||
void handler3(void)
|
void handler3(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
volatile uint32_t *pUART_stat = (uint32_t*)SYS_UART0_STAT;
|
volatile uint32_t *pUART_stat = (uint32_t*)SYS_UART0_STAT;
|
||||||
volatile uint32_t *pUART_data = (uint32_t*)SYS_UART0_DATA;
|
volatile uint32_t *pUART_data = (uint32_t*)SYS_UART0_DATA;
|
||||||
@@ -54,7 +54,7 @@ int main(int argc, char **argv)
|
|||||||
z_stream zs;
|
z_stream zs;
|
||||||
time_t start_time, work_time;
|
time_t start_time, work_time;
|
||||||
|
|
||||||
UART0_setbaud(460800);
|
UART_setbaud(con_getInstanceByName("UART-0"), 460800);
|
||||||
|
|
||||||
fprintf(stdout, "Reading gzipped stream..\n");
|
fprintf(stdout, "Reading gzipped stream..\n");
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ static usb_t _g_usb[USB_MAX_NUM_PORTS];
|
|||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// HPI ISR
|
// HPI ISR
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
void cy67k3_isr(void)
|
void cy67k3_isr(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
int32_t i;
|
int32_t i;
|
||||||
uint16_t sie_msg, hpi_status;
|
uint16_t sie_msg, hpi_status;
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ typedef struct _susb_irp_t
|
|||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
// HPI low-level routines
|
// HPI low-level routines
|
||||||
void cy67k3_isr(void);
|
void cy67k3_isr(struct xcptcontext *xcp);
|
||||||
void cy67k3_reset(void);
|
void cy67k3_reset(void);
|
||||||
uint16_t cy67k3_read_HPI_DATA(void);
|
uint16_t cy67k3_read_HPI_DATA(void);
|
||||||
uint16_t cy67k3_read_HPI_MAILBOX(void);
|
uint16_t cy67k3_read_HPI_MAILBOX(void);
|
||||||
|
|||||||
+2
-2
@@ -31,8 +31,8 @@ OBJDUMP=mipsel-elf-objdump
|
|||||||
OBJCOPY=mipsel-elf-objcopy
|
OBJCOPY=mipsel-elf-objcopy
|
||||||
FLASHGEN=flashgen
|
FLASHGEN=flashgen
|
||||||
|
|
||||||
OBJS-ml402=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o irq.o mips_dbg.o mips_dis.o mips_ps2.o mips_gfx.o console.o screen.o uart.o board.o gpio.o)
|
OBJS-ml402=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o cop0.o irq.o mips_dbg.o mips_dis.o mips_ps2.o mips_gfx.o console.o screen.o uart.o board.o gpio.o)
|
||||||
OBJS-denano=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o irq.o mips_dbg.o mips_dis.o console.o uart.o board.o)
|
OBJS-denano=$(addprefix $(BUILD_DIR)/, libsys.o xcpt.o syscalls.o cop0.o irq.o mips_dbg.o mips_dis.o console.o uart.o board.o)
|
||||||
|
|
||||||
all: $(BUILD_DIR) $(BUILD_DIR)/libsys.a
|
all: $(BUILD_DIR) $(BUILD_DIR)/libsys.a
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,6 @@
|
|||||||
|
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
#include "../../irq.h"
|
|
||||||
#include "../../uart.h"
|
|
||||||
#include "../../console.h"
|
|
||||||
|
|
||||||
extern uart_if_t uart_if[];
|
extern uart_if_t uart_if[];
|
||||||
|
|
||||||
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
|
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
|
||||||
@@ -21,7 +17,8 @@ const con_if_entry_t con_if_entry[] =
|
|||||||
{0, "stdin", &uart_if[0], NULL, NULL, UART_readchar, NULL},
|
{0, "stdin", &uart_if[0], NULL, NULL, UART_readchar, NULL},
|
||||||
{1, "stdout", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
{1, "stdout", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
||||||
{2, "stderr", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
{2, "stderr", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
||||||
{3, "UART1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar}
|
{3, "UART-0", &uart_if[0], NULL, NULL, UART_readchar, UART_writechar},
|
||||||
|
{4, "UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar}
|
||||||
};
|
};
|
||||||
|
|
||||||
con_if_t con_if =
|
con_if_t con_if =
|
||||||
@@ -50,10 +47,10 @@ void board_init(void)
|
|||||||
|
|
||||||
void dbg_putchar(char c)
|
void dbg_putchar(char c)
|
||||||
{
|
{
|
||||||
writechar(3, c);
|
writechar(4, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
char dbg_getchar()
|
char dbg_getchar()
|
||||||
{
|
{
|
||||||
return (char)readchar(3);
|
return (char)readchar(4);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,10 @@
|
|||||||
#ifndef BOARD_H
|
#ifndef BOARD_H
|
||||||
#define BOARD_H
|
#define BOARD_H
|
||||||
|
|
||||||
|
#include "../../irq.h"
|
||||||
|
#include "../../uart.h"
|
||||||
|
#include "../../console.h"
|
||||||
|
|
||||||
#define CPU_FREQ_HZ 50000000
|
#define CPU_FREQ_HZ 50000000
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|||||||
@@ -7,11 +7,6 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "../../irq.h"
|
|
||||||
#include "../../mips_ps2.h"
|
|
||||||
#include "../../screen.h"
|
|
||||||
#include "../../uart.h"
|
|
||||||
#include "../../console.h"
|
|
||||||
|
|
||||||
extern void dbg_init();
|
extern void dbg_init();
|
||||||
extern void dbg_handler(struct xcptcontext * xcp);
|
extern void dbg_handler(struct xcptcontext * xcp);
|
||||||
@@ -27,10 +22,11 @@ static const con_if_entry_t con_if_entry[] =
|
|||||||
{0, "stdin", &uart_if[0], NULL, NULL, UART_readchar, NULL},
|
{0, "stdin", &uart_if[0], NULL, NULL, UART_readchar, NULL},
|
||||||
{1, "stdout", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
{1, "stdout", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
||||||
{2, "stderr", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
{2, "stderr", &uart_if[0], NULL, NULL, NULL, UART_writechar},
|
||||||
{3, "UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar},
|
{10, "UART-0", &uart_if[0], NULL, NULL, UART_readchar, UART_writechar},
|
||||||
{4, "PS2-0", &ps2_if[0], PS2_open, PS2_close, PS2_readchar, NULL},
|
{11, "UART-1", &uart_if[1], NULL, NULL, UART_readchar, UART_writechar},
|
||||||
{5, "PS2-1", &ps2_if[1], PS2_open, PS2_close, PS2_readchar, NULL},
|
{20, "PS2-0", &ps2_if[0], PS2_open, PS2_close, PS2_readchar, NULL},
|
||||||
{6, "VGA-0", &vga_if, cg_open, cg_close, NULL, cg_writechar}
|
{21, "PS2-1", &ps2_if[1], PS2_open, PS2_close, PS2_readchar, NULL},
|
||||||
|
{30, "VGA-0", &vga_if, cg_open, cg_close, NULL, cg_writechar}
|
||||||
};
|
};
|
||||||
|
|
||||||
con_if_t con_if =
|
con_if_t con_if =
|
||||||
|
|||||||
@@ -14,6 +14,13 @@
|
|||||||
#ifndef BOARD_H
|
#ifndef BOARD_H
|
||||||
#define BOARD_H
|
#define BOARD_H
|
||||||
|
|
||||||
|
#include "../../irq.h"
|
||||||
|
#include "../../mips_ps2.h"
|
||||||
|
#include "../../mips_gfx.h"
|
||||||
|
#include "../../screen.h"
|
||||||
|
#include "../../uart.h"
|
||||||
|
#include "../../console.h"
|
||||||
|
|
||||||
#define CPU_FREQ_HZ 100000000
|
#define CPU_FREQ_HZ 100000000
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|||||||
+20
-5
@@ -11,7 +11,7 @@
|
|||||||
extern con_if_t con_if;
|
extern con_if_t con_if;
|
||||||
|
|
||||||
// Funcs
|
// Funcs
|
||||||
con_if_entry_t const* con_getPort(int file)
|
con_if_entry_t const* con_getInterface(int file)
|
||||||
{
|
{
|
||||||
con_if_entry_t const *result = NULL;
|
con_if_entry_t const *result = NULL;
|
||||||
int i;
|
int i;
|
||||||
@@ -26,6 +26,21 @@ con_if_entry_t const* con_getPort(int file)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void const* con_getInstanceByName(char const *pName)
|
||||||
|
{
|
||||||
|
void const *result = NULL;
|
||||||
|
int i;
|
||||||
|
for (i=0; i < con_if.length; i++)
|
||||||
|
{
|
||||||
|
if (!strcmp(pName, con_if.con_if_entry[i].pName))
|
||||||
|
{
|
||||||
|
result = con_if.con_if_entry[i].pInst;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int con_open(char const *pName)
|
int con_open(char const *pName)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -53,7 +68,7 @@ int con_close(int fd)
|
|||||||
void con_flush(int fd)
|
void con_flush(int fd)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
con_if_entry_t const *pIF = con_getPort(fd);
|
con_if_entry_t const *pIF = con_getInterface(fd);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -66,7 +81,7 @@ void con_flush(int fd)
|
|||||||
int readchar(int fd)
|
int readchar(int fd)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
con_if_entry_t const *pIF = con_getPort(fd);
|
con_if_entry_t const *pIF = con_getInterface(fd);
|
||||||
|
|
||||||
assert(pIF);
|
assert(pIF);
|
||||||
|
|
||||||
@@ -82,7 +97,7 @@ int readchar(int fd)
|
|||||||
|
|
||||||
void writechar(int fd, char c)
|
void writechar(int fd, char c)
|
||||||
{
|
{
|
||||||
con_if_entry_t const *pIF = con_getPort(fd);
|
con_if_entry_t const *pIF = con_getInterface(fd);
|
||||||
|
|
||||||
assert(pIF);
|
assert(pIF);
|
||||||
|
|
||||||
@@ -92,7 +107,7 @@ void writechar(int fd, char c)
|
|||||||
|
|
||||||
void _putchar(int fd, char c)
|
void _putchar(int fd, char c)
|
||||||
{
|
{
|
||||||
con_if_entry_t const *pIF = con_getPort(fd);
|
con_if_entry_t const *pIF = con_getInterface(fd);
|
||||||
|
|
||||||
assert(pIF);
|
assert(pIF);
|
||||||
if (c == 0x0A)
|
if (c == 0x0A)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#ifndef CONSOLE_H
|
#ifndef CONSOLE_H
|
||||||
#define CONSOLE_H
|
#define CONSOLE_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef int (*read_func_t)(void const *pInst);
|
typedef int (*read_func_t)(void const *pInst);
|
||||||
@@ -48,7 +49,8 @@ extern "C" {
|
|||||||
int con_open(char const *pName);
|
int con_open(char const *pName);
|
||||||
int con_close(int fd);
|
int con_close(int fd);
|
||||||
void con_flush(int file);
|
void con_flush(int file);
|
||||||
con_if_entry_t const* con_getPort(int file);
|
con_if_entry_t const* con_getInterface(int file);
|
||||||
|
void const* con_getInstanceByName(char const *pName);
|
||||||
|
|
||||||
int readchar(int file);
|
int readchar(int file);
|
||||||
void writechar(int file, char c);
|
void writechar(int file, char c);
|
||||||
|
|||||||
+14
-6
@@ -1,9 +1,5 @@
|
|||||||
#include <sys/times.h>
|
#include <stddef.h>
|
||||||
#include <sys/time.h>
|
#include <stdint.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "libsys.h"
|
|
||||||
#include "regdef.h"
|
#include "regdef.h"
|
||||||
#include "xcpt.h"
|
#include "xcpt.h"
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
@@ -63,6 +59,18 @@ void interrupt_disable(int irq_num)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void interrupt_enable_all()
|
||||||
|
{
|
||||||
|
uint32_t reg = CP0_SR_read() | SR_MASK_IEC;
|
||||||
|
CP0_SR_write(reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void interrupt_disable_all()
|
||||||
|
{
|
||||||
|
uint32_t reg = CP0_SR_read() & ~SR_MASK_IEC;
|
||||||
|
CP0_SR_write(reg);
|
||||||
|
}
|
||||||
|
|
||||||
void interrupt_set(int irq_num)
|
void interrupt_set(int irq_num)
|
||||||
{
|
{
|
||||||
reg_t reg, ip;
|
reg_t reg, ip;
|
||||||
|
|||||||
@@ -12,5 +12,7 @@ int _irq_dispatch(struct xcptcontext * xcp);
|
|||||||
void interrupt_register(int irq_num, fp_irq_t fp);
|
void interrupt_register(int irq_num, fp_irq_t fp);
|
||||||
void interrupt_enable(int irq_num);
|
void interrupt_enable(int irq_num);
|
||||||
void interrupt_disable(int irq_num);
|
void interrupt_disable(int irq_num);
|
||||||
|
void interrupt_enable_all();
|
||||||
|
void interrupt_disable_all();
|
||||||
|
|
||||||
#endif // IRQ_H
|
#endif // IRQ_H
|
||||||
|
|||||||
+17
-151
@@ -5,164 +5,30 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "console.h"
|
|
||||||
#include "libsys.h"
|
#include "libsys.h"
|
||||||
|
#include "regdef.h"
|
||||||
|
|
||||||
|
static uint32_t critical_nesting_counter = 0;
|
||||||
|
|
||||||
#define CALC_BAUD(b) \
|
void enter_critical()
|
||||||
((uint32_t)((float)CPU_FREQ_HZ/(16*b) + 0.5f) - 1);
|
|
||||||
|
|
||||||
void UART0_setbaud(uint32_t baudrate)
|
|
||||||
{
|
{
|
||||||
*((uint32_t*)SYS_UART0_BAUD) = CALC_BAUD(baudrate);
|
if (critical_nesting_counter == 0)
|
||||||
|
{
|
||||||
|
interrupt_disable_all();
|
||||||
|
}
|
||||||
|
critical_nesting_counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UART1_setbaud(uint32_t baudrate)
|
void exit_critical()
|
||||||
{
|
{
|
||||||
*((uint32_t*)SYS_UART1_BAUD) = CALC_BAUD(baudrate);
|
if (critical_nesting_counter > 0)
|
||||||
}
|
{
|
||||||
|
critical_nesting_counter--;
|
||||||
// ---------------------------------------------------------------------------------
|
if (critical_nesting_counter == 0)
|
||||||
// MIPS specific
|
{
|
||||||
// ---------------------------------------------------------------------------------
|
interrupt_enable_all();
|
||||||
uint32_t CP0_SR_read(void)
|
}
|
||||||
{
|
}
|
||||||
uint32_t result;
|
|
||||||
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"mfc0 %[val], $12\n"
|
|
||||||
: [val] "=r" (result)
|
|
||||||
);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CP0_SR_write(uint32_t val)
|
|
||||||
{
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"mtc0 %[val], $12\n"
|
|
||||||
: /* no output */
|
|
||||||
: [val] "r" (val)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CP0_CR_read(void)
|
|
||||||
{
|
|
||||||
uint32_t result;
|
|
||||||
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"mfc0 %[val], $13\n"
|
|
||||||
: [val] "=r" (result)
|
|
||||||
);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CP0_CR_write(uint32_t val)
|
|
||||||
{
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"mtc0 %[val], $13\n"
|
|
||||||
:
|
|
||||||
: [val] "r" (val)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CP0_TR_read(void)
|
|
||||||
{
|
|
||||||
uint32_t result;
|
|
||||||
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"mfc0 %[val], $31\n"
|
|
||||||
: [val] "=r" (result)
|
|
||||||
);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CP0_TR_write(uint32_t val)
|
|
||||||
{
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"mtc0 %[val], $31\n"
|
|
||||||
:
|
|
||||||
: [val] "r" (val)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t CP0_PRID_read(void)
|
|
||||||
{
|
|
||||||
uint32_t result;
|
|
||||||
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"mfc0 %[val], $15\n"
|
|
||||||
: [val] "=r" (result)
|
|
||||||
);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CP0_TR_write_ptr(uint32_t* pPtr)
|
|
||||||
{
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"swc0 $31, 0(%[pPtr])\n"
|
|
||||||
:
|
|
||||||
: [pPtr] "r" (pPtr)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CP0_TR_read_ptr(uint32_t* pPtr)
|
|
||||||
{
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"lwc0 $31, 0(%[pPtr])\n"
|
|
||||||
:
|
|
||||||
: [pPtr] "r" (pPtr)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ICACHE_invalidate_all(void)
|
|
||||||
{
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"cop0 32\n"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ICACHE_invalidate_at(uint32_t* pPtr)
|
|
||||||
{
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"mtc0 %[pPtr], $31\n"
|
|
||||||
"cop0 33\n"
|
|
||||||
:
|
|
||||||
: [pPtr] "r" (pPtr)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DCACHE_invalidate_all(void)
|
|
||||||
{
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"cop0 34\n"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DCACHE_invalidate_at(uint32_t* pPtr)
|
|
||||||
{
|
|
||||||
__asm__
|
|
||||||
(
|
|
||||||
"mtc0 %[pPtr], $31\n"
|
|
||||||
"cop0 35\n"
|
|
||||||
:
|
|
||||||
: [pPtr] "r" (pPtr)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _exit (int exitcode)
|
void _exit (int exitcode)
|
||||||
|
|||||||
+2
-70
@@ -15,76 +15,8 @@
|
|||||||
|
|
||||||
#define IS_ERROR(e) ((e & LSYS_ERR_BASE) == LSYS_ERR_BASE)
|
#define IS_ERROR(e) ((e & LSYS_ERR_BASE) == LSYS_ERR_BASE)
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
void enter_critical();
|
||||||
// Chip registers
|
void exit_critical();
|
||||||
// ---------------------------------------------------------
|
|
||||||
// COP0 registers
|
|
||||||
#define COP0_REG_INVAT_POINTER 31
|
|
||||||
|
|
||||||
// COP0 instructions
|
|
||||||
#define COP0_INSTR_INVALL_ICACHE 32
|
|
||||||
#define COP0_INSTR_INVAT_ICACHE 33
|
|
||||||
#define COP0_INSTR_INVALL_DCACHE 34
|
|
||||||
#define COP0_INSTR_INVAT_DCACHE 35
|
|
||||||
|
|
||||||
#define CP0_read(idx) \
|
|
||||||
({ \
|
|
||||||
uint32_t result; \
|
|
||||||
__asm__ __volatile__ \
|
|
||||||
( \
|
|
||||||
"mfc0\t%0,$"#idx"\n" \
|
|
||||||
: "=r" (result) \
|
|
||||||
); \
|
|
||||||
result; \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define CP0_write(idx, val) \
|
|
||||||
({ \
|
|
||||||
__asm__ __volatile__ \
|
|
||||||
( \
|
|
||||||
"mtc0\t%0,$"#idx"\n" \
|
|
||||||
"nop\n" \
|
|
||||||
: /* no output */ \
|
|
||||||
: "r" (val) \
|
|
||||||
); \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define CP0_TLBR \
|
|
||||||
({ \
|
|
||||||
__asm__ __volatile__ \
|
|
||||||
( \
|
|
||||||
"tlbr\n" \
|
|
||||||
: /* no output */ \
|
|
||||||
: /* no input */ \
|
|
||||||
); \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define CP0_TLBWI \
|
|
||||||
({ \
|
|
||||||
__asm__ __volatile__ \
|
|
||||||
( \
|
|
||||||
"tlbwi\n" \
|
|
||||||
: /* no output */ \
|
|
||||||
: /* no input */ \
|
|
||||||
); \
|
|
||||||
})
|
|
||||||
|
|
||||||
uint32_t CP0_SR_read(void);
|
|
||||||
void CP0_SR_write(uint32_t val);
|
|
||||||
uint32_t CP0_CR_read(void);
|
|
||||||
void CP0_CR_write(uint32_t val);
|
|
||||||
uint32_t CP0_PRID_read(void);
|
|
||||||
uint32_t CP0_TR_read(void);
|
|
||||||
void CP0_TR_write(uint32_t val);
|
|
||||||
void CP0_TR_write_ptr(uint32_t* pPtr);
|
|
||||||
void CP0_TR_read_ptr(uint32_t* pPtr);
|
|
||||||
void ICACHE_invalidate_all(void);
|
|
||||||
void ICACHE_invalidate_at(uint32_t* pPtr);
|
|
||||||
void DCACHE_invalidate_all(void);
|
|
||||||
void DCACHE_invalidate_at(uint32_t* pPtr);
|
|
||||||
|
|
||||||
void UART0_setbaud(uint32_t baudrate);
|
|
||||||
void UART1_setbaud(uint32_t baudrate);
|
|
||||||
|
|
||||||
int write(int file, char *ptr, int len);
|
int write(int file, char *ptr, int len);
|
||||||
int sputs(char const *pStr);
|
int sputs(char const *pStr);
|
||||||
|
|||||||
+2
-12
@@ -396,17 +396,6 @@ static char __findkey(char scancode, int mode)
|
|||||||
#define ARROW_LEFT (SPECIALKEY|EXTENDED|0x6b)
|
#define ARROW_LEFT (SPECIALKEY|EXTENDED|0x6b)
|
||||||
#define ARROW_RIGHT (SPECIALKEY|EXTENDED|0x74)
|
#define ARROW_RIGHT (SPECIALKEY|EXTENDED|0x74)
|
||||||
|
|
||||||
static uint32_t readchar(ps2_if_t *pIF)
|
|
||||||
{
|
|
||||||
if (!pIF)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
while (!(SYS_PS2_BIT_RX_AVAIL & *pIF->pCTRL));
|
|
||||||
|
|
||||||
return (*pIF->pDATA & 0xFF);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t con_readchar(ps2_if_t *pIF)
|
uint32_t con_readchar(ps2_if_t *pIF)
|
||||||
{
|
{
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
@@ -417,7 +406,8 @@ uint32_t con_readchar(ps2_if_t *pIF)
|
|||||||
int char_valid = 0;
|
int char_valid = 0;
|
||||||
uint8_t key;
|
uint8_t key;
|
||||||
|
|
||||||
key = readchar(pIF);
|
while (!(SYS_PS2_BIT_RX_AVAIL & *pIF->pCTRL));
|
||||||
|
key = *pIF->pDATA & 0xFF;
|
||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,18 @@ uart_if_t uart_if[2] =
|
|||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
// Low-level I/O
|
// Low-level I/O
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
|
#define CALC_BAUD(b) \
|
||||||
|
((uint32_t)((float)CPU_FREQ_HZ/(16*b) + 0.5f) - 1);
|
||||||
|
|
||||||
|
void UART_setbaud(void const *pInst, uint32_t baudrate)
|
||||||
|
{
|
||||||
|
assert(pInst);
|
||||||
|
|
||||||
|
uart_if_t *pReg = (uart_if_t*)pInst;
|
||||||
|
|
||||||
|
*pReg->pBAUD = CALC_BAUD(baudrate);
|
||||||
|
}
|
||||||
|
|
||||||
int UART_readchar(void const *pInst)
|
int UART_readchar(void const *pInst)
|
||||||
{
|
{
|
||||||
assert(pInst);
|
assert(pInst);
|
||||||
|
|||||||
@@ -171,13 +171,13 @@ void _exc_dbe(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler0(void)
|
void handler0(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
printf("Interrupt 0\n");
|
printf("Interrupt 0\n");
|
||||||
interrupt_clr(0);
|
interrupt_clr(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler1(void)
|
void handler1(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
printf("Interrupt 1\n");
|
printf("Interrupt 1\n");
|
||||||
interrupt_clr(1);
|
interrupt_clr(1);
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ uint16_t makeBuffer16(uint16_t *pDst, uint8_t *pSrc, uint32_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void uart_handler(void)
|
void uart_handler(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
volatile uint32_t *pUART_stat = (uint32_t*)SYS_UART_STAT;
|
volatile uint32_t *pUART_stat = (uint32_t*)SYS_UART_STAT;
|
||||||
volatile uint32_t *pUART_data = (uint32_t*)SYS_UART_DATA;
|
volatile uint32_t *pUART_data = (uint32_t*)SYS_UART_DATA;
|
||||||
|
|||||||
+15
-20
@@ -5,12 +5,7 @@
|
|||||||
#include <sys/times.h>
|
#include <sys/times.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <console.h>
|
|
||||||
#include "libsys.h"
|
#include "libsys.h"
|
||||||
#include "irq.h"
|
|
||||||
#include "mips_gfx.h"
|
|
||||||
#include "mips_ps2.h"
|
|
||||||
#include "libsys/console.h"
|
|
||||||
|
|
||||||
#define PS2_NUM_IF 2
|
#define PS2_NUM_IF 2
|
||||||
char buffer[16384];
|
char buffer[16384];
|
||||||
@@ -23,27 +18,27 @@ static gfx_t gfx;
|
|||||||
static volatile int _g_posx, _g_posy;
|
static volatile int _g_posx, _g_posy;
|
||||||
static volatile g_btn_l, g_btn_r;
|
static volatile g_btn_l, g_btn_r;
|
||||||
static volatile uint32_t g_color;
|
static volatile uint32_t g_color;
|
||||||
static int ps2_fd[PS2_NUM_IF];
|
static char *ps2_name[PS2_NUM_IF] = {"PS2-0", "PS2-1"};
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
void handler0(void)
|
void handler0(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
printf("Interrupt 0\n");
|
printf("Interrupt 0\n");
|
||||||
interrupt_clr(0);
|
interrupt_clr(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler1(void)
|
void handler1(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
printf("Interrupt 1\n");
|
printf("Interrupt 1\n");
|
||||||
interrupt_clr(1);
|
interrupt_clr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler2(void)
|
void handler2(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
printf("Interrupt 2\n");
|
printf("Interrupt 2\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler3(void)
|
void handler3(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
volatile uint32_t *pUART0_stat = (uint32_t*)SYS_UART0_STAT;
|
volatile uint32_t *pUART0_stat = (uint32_t*)SYS_UART0_STAT;
|
||||||
volatile uint32_t *pUART0_data = (uint32_t*)SYS_UART0_DATA;
|
volatile uint32_t *pUART0_data = (uint32_t*)SYS_UART0_DATA;
|
||||||
@@ -68,12 +63,12 @@ void handler3(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler4(void)
|
void handler4(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
printf("Interrupt 4\n");
|
printf("Interrupt 4\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler5(void)
|
void handler5(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
uint32_t volatile *pVGA_ctrl = (uint32_t*)SYS_VGA_CTRL;
|
uint32_t volatile *pVGA_ctrl = (uint32_t*)SYS_VGA_CTRL;
|
||||||
|
|
||||||
@@ -82,10 +77,10 @@ void handler5(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler6(void)
|
void handler6(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
int p, i;
|
int p, i;
|
||||||
ps2_if_t const *pIF;
|
ps2_if_t *pIF;
|
||||||
uint8_t mouse_rsp[3];
|
uint8_t mouse_rsp[3];
|
||||||
uint32_t timeout_count, key;
|
uint32_t timeout_count, key;
|
||||||
|
|
||||||
@@ -93,7 +88,7 @@ void handler6(void)
|
|||||||
|
|
||||||
for (p=0; p < PS2_NUM_IF; p++)
|
for (p=0; p < PS2_NUM_IF; p++)
|
||||||
{
|
{
|
||||||
pIF = (ps2_if_t const *)con_getPort(ps2_fd[p])->pInst;
|
pIF = (ps2_if_t*)con_getInstanceByName(ps2_name[p]);
|
||||||
if (SYS_PS2_BIT_RX_ERR_FLAG & *pIF->pCTRL)
|
if (SYS_PS2_BIT_RX_ERR_FLAG & *pIF->pCTRL)
|
||||||
fprintf(stderr, "PS2[%d]: Status = 0x%08X\n", p, *pIF->pCTRL);
|
fprintf(stderr, "PS2[%d]: Status = 0x%08X\n", p, *pIF->pCTRL);
|
||||||
|
|
||||||
@@ -209,7 +204,7 @@ int main(void)
|
|||||||
interrupt_register(7, (void*)handler7);
|
interrupt_register(7, (void*)handler7);
|
||||||
|
|
||||||
srand(clock());
|
srand(clock());
|
||||||
UART1_setbaud(460800);
|
UART_setbaud(con_getInstanceByName("UART-1"), 460800);
|
||||||
printf("Hello\n");
|
printf("Hello\n");
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
|
||||||
@@ -238,8 +233,8 @@ int main(void)
|
|||||||
printf("UART0 Status = 0x%8.8X\n", *pUART0_stat);
|
printf("UART0 Status = 0x%8.8X\n", *pUART0_stat);
|
||||||
printf("UART1 Status = 0x%8.8X\n", *pUART1_stat);
|
printf("UART1 Status = 0x%8.8X\n", *pUART1_stat);
|
||||||
|
|
||||||
ps2_fd[0] = open("PS2-0", 0, 0);
|
PS2_init((ps2_if_t*)con_getInstanceByName(ps2_name[0]));
|
||||||
ps2_fd[1] = open("PS2-1", 0, 0);
|
PS2_init((ps2_if_t*)con_getInstanceByName(ps2_name[1]));
|
||||||
|
|
||||||
sputs("r: "); print_word((int)pPtr_r); sputs("\n");
|
sputs("r: "); print_word((int)pPtr_r); sputs("\n");
|
||||||
sputs("w: "); print_word((int)pPtr_w); sputs("\n");
|
sputs("w: "); print_word((int)pPtr_w); sputs("\n");
|
||||||
@@ -256,8 +251,8 @@ int main(void)
|
|||||||
printf("Du schriebst: %s\n", string);
|
printf("Du schriebst: %s\n", string);
|
||||||
|
|
||||||
// Flush buffer
|
// Flush buffer
|
||||||
PS2_flush((ps2_if_t*)(con_getPort(ps2_fd[0])->pInst));
|
PS2_flush((ps2_if_t*)con_getInstanceByName(ps2_name[0]));
|
||||||
PS2_flush((ps2_if_t*)(con_getPort(ps2_fd[1])->pInst));
|
PS2_flush((ps2_if_t*)con_getInstanceByName(ps2_name[1]));
|
||||||
|
|
||||||
printf("Start:\n");
|
printf("Start:\n");
|
||||||
|
|
||||||
|
|||||||
+11
-15
@@ -5,11 +5,7 @@
|
|||||||
#include <sys/times.h>
|
#include <sys/times.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <console.h>
|
|
||||||
#include "libsys.h"
|
#include "libsys.h"
|
||||||
#include "irq.h"
|
|
||||||
#include "mips_gfx.h"
|
|
||||||
#include "mips_ps2.h"
|
|
||||||
|
|
||||||
#define PS2_NUM_IF 2
|
#define PS2_NUM_IF 2
|
||||||
static volatile int32_t mouse_x;
|
static volatile int32_t mouse_x;
|
||||||
@@ -19,10 +15,10 @@ static gfx_t gfx;
|
|||||||
static volatile int _g_posx, _g_posy;
|
static volatile int _g_posx, _g_posy;
|
||||||
static volatile g_btn_l, g_btn_r;
|
static volatile g_btn_l, g_btn_r;
|
||||||
static volatile uint32_t g_color;
|
static volatile uint32_t g_color;
|
||||||
static int ps2_fd[PS2_NUM_IF];
|
static char *ps2_name[PS2_NUM_IF] = {"PS2-0", "PS2-1"};
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
void handler5(void)
|
void handler5(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
uint32_t volatile *pVGA_ctrl = (uint32_t*)SYS_VGA_CTRL;
|
uint32_t volatile *pVGA_ctrl = (uint32_t*)SYS_VGA_CTRL;
|
||||||
|
|
||||||
@@ -31,10 +27,10 @@ void handler5(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler6(void)
|
void handler6(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
int p, i;
|
int p, i;
|
||||||
ps2_if_t const *pIF;
|
ps2_if_t *pIF;
|
||||||
uint8_t mouse_rsp[3];
|
uint8_t mouse_rsp[3];
|
||||||
uint32_t timeout_count, key;
|
uint32_t timeout_count, key;
|
||||||
|
|
||||||
@@ -42,7 +38,7 @@ void handler6(void)
|
|||||||
|
|
||||||
for (p=0; p < PS2_NUM_IF; p++)
|
for (p=0; p < PS2_NUM_IF; p++)
|
||||||
{
|
{
|
||||||
pIF = (ps2_if_t const *)con_getPort(ps2_fd[p])->pInst;
|
pIF = (ps2_if_t*)con_getInstanceByName(ps2_name[p]);
|
||||||
if (SYS_PS2_BIT_RX_ERR_FLAG & *pIF->pCTRL)
|
if (SYS_PS2_BIT_RX_ERR_FLAG & *pIF->pCTRL)
|
||||||
fprintf(stderr, "PS2[%d]: Status = 0x%08X\n", p, *pIF->pCTRL);
|
fprintf(stderr, "PS2[%d]: Status = 0x%08X\n", p, *pIF->pCTRL);
|
||||||
|
|
||||||
@@ -140,8 +136,8 @@ int main(void)
|
|||||||
interrupt_register(6, (void*)handler6);
|
interrupt_register(6, (void*)handler6);
|
||||||
|
|
||||||
srand(clock());
|
srand(clock());
|
||||||
UART1_setbaud(460800);
|
UART_setbaud(con_getInstanceByName("UART-1"), 460800);
|
||||||
|
|
||||||
*pVGA_cgcol = 0x00FFFFFF;
|
*pVGA_cgcol = 0x00FFFFFF;
|
||||||
_g_posx = _g_posy = 0;
|
_g_posx = _g_posy = 0;
|
||||||
rmb_posx = rmb_posy = 0;
|
rmb_posx = rmb_posy = 0;
|
||||||
@@ -157,12 +153,12 @@ int main(void)
|
|||||||
GFX_show(&gfx);
|
GFX_show(&gfx);
|
||||||
printf("VGA status = %08X\n", *pVGA_ctrl);
|
printf("VGA status = %08X\n", *pVGA_ctrl);
|
||||||
|
|
||||||
ps2_fd[0] = open("PS2-0", 0, 0);
|
PS2_init((ps2_if_t*)con_getInstanceByName(ps2_name[0]));
|
||||||
ps2_fd[1] = open("PS2-1", 0, 0);
|
PS2_init((ps2_if_t*)con_getInstanceByName(ps2_name[1]));
|
||||||
|
|
||||||
// Flush buffer
|
// Flush buffer
|
||||||
PS2_flush((ps2_if_t*)(con_getPort(ps2_fd[0])->pInst));
|
PS2_flush((ps2_if_t*)con_getInstanceByName(ps2_name[0]));
|
||||||
PS2_flush((ps2_if_t*)(con_getPort(ps2_fd[1])->pInst));
|
PS2_flush((ps2_if_t*)con_getInstanceByName(ps2_name[1]));
|
||||||
|
|
||||||
// interrupt_enable(5);
|
// interrupt_enable(5);
|
||||||
interrupt_enable(6);
|
interrupt_enable(6);
|
||||||
|
|||||||
+2
-2
@@ -100,7 +100,7 @@ int IsEndianBig(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handler3(void)
|
void handler3(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
volatile uint32_t *pUART_stat = (uint32_t*)SYS_UART_STAT;
|
volatile uint32_t *pUART_stat = (uint32_t*)SYS_UART_STAT;
|
||||||
volatile uint32_t *pUART_data = (uint32_t*)SYS_UART_DATA;
|
volatile uint32_t *pUART_data = (uint32_t*)SYS_UART_DATA;
|
||||||
@@ -117,7 +117,7 @@ box_t box;
|
|||||||
gfx_t gfx;
|
gfx_t gfx;
|
||||||
int posx, posy;
|
int posx, posy;
|
||||||
|
|
||||||
void handler7(void)
|
void handler7(struct xcptcontext *xcp)
|
||||||
{
|
{
|
||||||
uint32_t volatile *pTim_stat = (uint32_t*)SYS_ITIM_STAT;
|
uint32_t volatile *pTim_stat = (uint32_t*)SYS_ITIM_STAT;
|
||||||
uint32_t volatile *pTim_ctrl = (uint32_t*)SYS_ITIM_CTRL;
|
uint32_t volatile *pTim_ctrl = (uint32_t*)SYS_ITIM_CTRL;
|
||||||
|
|||||||
Reference in New Issue
Block a user