/*
|
/*
|
* main.c -- the main program
|
* main.c -- the main program
|
*/
|
*/
|
|
|
|
|
#include "common.h"
|
#include "common.h"
|
#include "lib.h"
|
#include "lib.h"
|
#include "start.h"
|
#include "start.h"
|
|
|
|
|
int charAvail = 0;
|
int charAvail = 0;
|
char charRead;
|
char charRead;
|
|
|
|
|
/**************************************************************/
|
/**************************************************************/
|
|
|
|
|
/*
|
/*
|
* Interrupt and exception messages which will be shown if
|
* Interrupt and exception messages which will be shown if
|
* the corresponding interrupt or exception is not handled.
|
* the corresponding interrupt or exception is not handled.
|
*/
|
*/
|
char *exceptionCause[32] = {
|
char *exceptionCause[32] = {
|
/* 00 */ "terminal 0 transmitter interrupt",
|
/* 00 */ "terminal 0 transmitter interrupt",
|
/* 01 */ "terminal 0 receiver interrupt",
|
/* 01 */ "terminal 0 receiver interrupt",
|
/* 02 */ "terminal 1 transmitter interrupt",
|
/* 02 */ "terminal 1 transmitter interrupt",
|
/* 03 */ "terminal 1 receiver interrupt",
|
/* 03 */ "terminal 1 receiver interrupt",
|
/* 04 */ "keyboard interrupt",
|
/* 04 */ "keyboard interrupt",
|
/* 05 */ "unknown interrupt 5",
|
/* 05 */ "unknown interrupt 5",
|
/* 06 */ "unknown interrupt 6",
|
/* 06 */ "unknown interrupt 6",
|
/* 07 */ "unknown interrupt 7",
|
/* 07 */ "unknown interrupt 7",
|
/* 08 */ "disk interrupt",
|
/* 08 */ "disk interrupt",
|
/* 09 */ "unknown interrupt 9",
|
/* 09 */ "unknown interrupt 9",
|
/* 10 */ "unknown interrupt 10",
|
/* 10 */ "unknown interrupt 10",
|
/* 11 */ "unknown interrupt 11",
|
/* 11 */ "unknown interrupt 11",
|
/* 12 */ "unknown interrupt 12",
|
/* 12 */ "unknown interrupt 12",
|
/* 13 */ "unknown interrupt 13",
|
/* 13 */ "unknown interrupt 13",
|
/* 14 */ "timer interrupt",
|
/* 14 */ "timer 0 interrupt",
|
/* 15 */ "unknown interrupt 15",
|
/* 15 */ "timer 1 interrupt",
|
/* 16 */ "bus timeout exception",
|
/* 16 */ "bus timeout exception",
|
/* 17 */ "illegal instruction exception",
|
/* 17 */ "illegal instruction exception",
|
/* 18 */ "privileged instruction exception",
|
/* 18 */ "privileged instruction exception",
|
/* 19 */ "divide instruction exception",
|
/* 19 */ "divide instruction exception",
|
/* 20 */ "trap instruction exception",
|
/* 20 */ "trap instruction exception",
|
/* 21 */ "TLB miss exception",
|
/* 21 */ "TLB miss exception",
|
/* 22 */ "TLB write exception",
|
/* 22 */ "TLB write exception",
|
/* 23 */ "TLB invalid exception",
|
/* 23 */ "TLB invalid exception",
|
/* 24 */ "illegal address exception",
|
/* 24 */ "illegal address exception",
|
/* 25 */ "privileged address exception",
|
/* 25 */ "privileged address exception",
|
/* 26 */ "unknown exception 26",
|
/* 26 */ "unknown exception 26",
|
/* 27 */ "unknown exception 27",
|
/* 27 */ "unknown exception 27",
|
/* 28 */ "unknown exception 28",
|
/* 28 */ "unknown exception 28",
|
/* 29 */ "unknown exception 29",
|
/* 29 */ "unknown exception 29",
|
/* 30 */ "unknown exception 30",
|
/* 30 */ "unknown exception 30",
|
/* 31 */ "unknown exception 31"
|
/* 31 */ "unknown exception 31"
|
};
|
};
|
|
|
|
|
/*
|
/*
|
* This is the default interrupt service routine.
|
* This is the default interrupt service routine.
|
* It simply panics with a message that tells the cause.
|
* It simply panics with a message that tells the cause.
|
*/
|
*/
|
void defaultISR(int irq, InterruptContext *icp) {
|
void defaultISR(int irq, InterruptContext *icp) {
|
printf("**** %s ****\n", exceptionCause[irq]);
|
printf("**** %s ****\n", exceptionCause[irq]);
|
while (1) ;
|
while (1) ;
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Initialize all interrupts and exceptions to the default ISR.
|
* Initialize all interrupts and exceptions to the default ISR.
|
* Enable interrupts.
|
* Enable interrupts.
|
*/
|
*/
|
void initInterrupts(void) {
|
void initInterrupts(void) {
|
int i;
|
int i;
|
|
|
for (i = 0; i < 32; i++) {
|
for (i = 0; i < 32; i++) {
|
setISR(i, defaultISR);
|
setISR(i, defaultISR);
|
}
|
}
|
enable();
|
enable();
|
}
|
}
|
|
|
|
|
/**************************************************************/
|
/**************************************************************/
|
|
|
|
|
void kbdISR(int irq, InterruptContext *icp) {
|
void kbdISR(int irq, InterruptContext *icp) {
|
unsigned int *p;
|
unsigned int *p;
|
|
|
p = (unsigned int *) 0xF0200000;
|
p = (unsigned int *) 0xF0200000;
|
charRead = *(p + 1);
|
charRead = *(p + 1);
|
charAvail = 1;
|
charAvail = 1;
|
}
|
}
|
|
|
|
|
void kbdEnable(void) {
|
void kbdEnable(void) {
|
unsigned int *p;
|
unsigned int *p;
|
|
|
p = (unsigned int *) 0xF0200000;
|
p = (unsigned int *) 0xF0200000;
|
*p = 2;
|
*p = 2;
|
}
|
}
|
|
|
|
|
int main(void) {
|
int main(void) {
|
unsigned char c;
|
unsigned char c;
|
int n;
|
int n;
|
|
|
printf("Keyboard Test:\n");
|
printf("Keyboard Test:\n");
|
printf("initializing interrupts...\n");
|
printf("initializing interrupts...\n");
|
initInterrupts();
|
initInterrupts();
|
printf("setting kbd ISR...\n");
|
printf("setting kbd ISR...\n");
|
setISR(4, kbdISR);
|
setISR(4, kbdISR);
|
printf("enabling kbd interrupt mask bit...\n");
|
printf("enabling kbd interrupt mask bit...\n");
|
setMask(getMask() | (1 << 4));
|
setMask(getMask() | (1 << 4));
|
printf("enabling interrupts in kbd controller...\n");
|
printf("enabling interrupts in kbd controller...\n");
|
kbdEnable();
|
kbdEnable();
|
n = 0;
|
n = 0;
|
while (1) {
|
while (1) {
|
while (charAvail == 0) ;
|
while (charAvail == 0) ;
|
disable();
|
disable();
|
c = charRead;
|
c = charRead;
|
charAvail = 0;
|
charAvail = 0;
|
enable();
|
enable();
|
printf("%02X ", c);
|
printf("%02X ", c);
|
if (++n == 24) {
|
if (++n == 24) {
|
n = 0;
|
n = 0;
|
printf("\n");
|
printf("\n");
|
}
|
}
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|