simple serial tty

This commit is contained in:
catfood 2023-01-01 22:40:12 +08:00
parent 91fb538b4b
commit f9ed0ed420
14 changed files with 236 additions and 522 deletions

View File

@ -14,113 +14,7 @@
/************************************************************************/
/* Macros Declaration */
/************************************************************************/
#define KB_IN_BYTES 320 /* size of keyboard input buffer */ /* FIXME */
#define MOUSE_IN_BYTES 4
#define DEBUGNEW
#ifndef DEBUGNEW
#define MAP_COLS 3 /* Number of columns in keymap */
#define NR_SCAN_CODES 0x80 /* Number of scan codes (rows in keymap) */
#define FLAG_BREAK 0x0080 /* Break Code */
#define FLAG_EXT 0x0100 /* Normal function keys */
#define FLAG_SHIFT_L 0x0200 /* Shift key */
#define FLAG_SHIFT_R 0x0400 /* Shift key */
#define FLAG_CTRL_L 0x0800 /* Control key */
#define FLAG_CTRL_R 0x1000 /* Control key */
#define FLAG_ALT_L 0x2000 /* Alternate key */
#define FLAG_ALT_R 0x4000 /* Alternate key */
#define FLAG_PAD 0x8000 /* keys in num pad */
#define MASK_RAW 0x01FF /* raw key value = code_passed_to_tty & MASK_RAW
* the value can be found either in the keymap
* column 0 or in the list below
*/
/* Special keys */
#define ESC (0x01 + FLAG_EXT) /* Esc */
#define TAB (0x02 + FLAG_EXT) /* Tab */
#define ENTER (0x03 + FLAG_EXT) /* Enter */
#define BACKSPACE (0x04 + FLAG_EXT) /* BackSpace */
#define GUI_L (0x05 + FLAG_EXT) /* L GUI */
#define GUI_R (0x06 + FLAG_EXT) /* R GUI */
#define APPS (0x07 + FLAG_EXT) /* APPS */
/* Shift, Ctrl, Alt */
#define SHIFT_L (0x08 + FLAG_EXT) /* L Shift */
#define SHIFT_R (0x09 + FLAG_EXT) /* R Shift */
#define CTRL_L (0x0A + FLAG_EXT) /* L Ctrl */
#define CTRL_R (0x0B + FLAG_EXT) /* R Ctrl */
#define ALT_L (0x0C + FLAG_EXT) /* L Alt */
#define ALT_R (0x0D + FLAG_EXT) /* R Alt */
/* Lock keys */
#define CAPS_LOCK (0x0E + FLAG_EXT) /* Caps Lock */
#define NUM_LOCK (0x0F + FLAG_EXT) /* Number Lock */
#define SCROLL_LOCK (0x10 + FLAG_EXT) /* Scroll Lock */
/* Function keys */
#define F1 (0x11 + FLAG_EXT) /* F1 */
#define F2 (0x12 + FLAG_EXT) /* F2 */
#define F3 (0x13 + FLAG_EXT) /* F3 */
#define F4 (0x14 + FLAG_EXT) /* F4 */
#define F5 (0x15 + FLAG_EXT) /* F5 */
#define F6 (0x16 + FLAG_EXT) /* F6 */
#define F7 (0x17 + FLAG_EXT) /* F7 */
#define F8 (0x18 + FLAG_EXT) /* F8 */
#define F9 (0x19 + FLAG_EXT) /* F9 */
#define F10 (0x1A + FLAG_EXT) /* F10 */
#define F11 (0x1B + FLAG_EXT) /* F11 */
#define F12 (0x1C + FLAG_EXT) /* F12 */
/* Control Pad */
#define PRINTSCREEN (0x1D + FLAG_EXT) /* Print Screen */
#define PAUSEBREAK (0x1E + FLAG_EXT) /* Pause/Break */
#define INSERT (0x1F + FLAG_EXT) /* Insert */
#define DELETE (0x20 + FLAG_EXT) /* Delete */
#define HOME (0x21 + FLAG_EXT) /* Home */
#define END (0x22 + FLAG_EXT) /* End */
#define PAGEUP (0x23 + FLAG_EXT) /* Page Up */
#define PAGEDOWN (0x24 + FLAG_EXT) /* Page Down */
#define UP (0x25 + FLAG_EXT) /* Up */
#define DOWN (0x26 + FLAG_EXT) /* Down */
#define LEFT (0x27 + FLAG_EXT) /* Left */
#define RIGHT (0x28 + FLAG_EXT) /* Right */
/* ACPI keys */
#define POWER (0x29 + FLAG_EXT) /* Power */
#define SLEEP (0x2A + FLAG_EXT) /* Sleep */
#define WAKE (0x2B + FLAG_EXT) /* Wake Up */
/* Num Pad */
#define PAD_SLASH (0x2C + FLAG_EXT) /* / */
#define PAD_STAR (0x2D + FLAG_EXT) /* * */
#define PAD_MINUS (0x2E + FLAG_EXT) /* - */
#define PAD_PLUS (0x2F + FLAG_EXT) /* + */
#define PAD_ENTER (0x30 + FLAG_EXT) /* Enter */
#define PAD_DOT (0x31 + FLAG_EXT) /* . */
#define PAD_0 (0x32 + FLAG_EXT) /* 0 */
#define PAD_1 (0x33 + FLAG_EXT) /* 1 */
#define PAD_2 (0x34 + FLAG_EXT) /* 2 */
#define PAD_3 (0x35 + FLAG_EXT) /* 3 */
#define PAD_4 (0x36 + FLAG_EXT) /* 4 */
#define PAD_5 (0x37 + FLAG_EXT) /* 5 */
#define PAD_6 (0x38 + FLAG_EXT) /* 6 */
#define PAD_7 (0x39 + FLAG_EXT) /* 7 */
#define PAD_8 (0x3A + FLAG_EXT) /* 8 */
#define PAD_9 (0x3B + FLAG_EXT) /* 9 */
#define PAD_UP PAD_8 /* Up */
#define PAD_DOWN PAD_2 /* Down */
#define PAD_LEFT PAD_4 /* Left */
#define PAD_RIGHT PAD_6 /* Right */
#define PAD_HOME PAD_7 /* Home */
#define PAD_END PAD_1 /* End */
#define PAD_PAGEUP PAD_9 /* Page Up */
#define PAD_PAGEDOWN PAD_3 /* Page Down */
#define PAD_INS PAD_0 /* Ins */
#define PAD_MID PAD_5 /* Middle key */
#define PAD_DEL PAD_DOT /* Del */
#endif
#define MOUSESCR_UP 0x1
#define MOUSESCR_DOWN 0x2
@ -136,27 +30,7 @@
#define PS2_CMD_SAMPLE_RATE (0xF3)
#define PS2_CMD_GET_DEVICE (0xF2)
#define PS2_ACK (0xfa)
/************************************************************************/
/* Stucture Definition */
/************************************************************************/
/* Keyboard structure, 1 per console. */
/**
* @todo change u8 into char
*
*/
typedef struct kb_inbuf {
u8* p_head; /**< points to the next free slot */
u8* p_tail; /**< points to the byte to be handled */
int count; /**< how many bytes to be handled in the buffer */
u8 buf[KB_IN_BYTES];
} KB_INPUT;
#define MOUSE_UPDOWN_BOUND 15
typedef struct mouse_inbuf{
int count;
u8 buf[MOUSE_IN_BYTES];
}MOUSE_INPUT;
#endif /* _ORANGES_KEYBOARD_H_ */

View File

@ -1,230 +0,0 @@
#ifndef _ORANGES_KEYMAP_H_
#define _ORANGES_KEYMAP_H_
/* Keymap for US MF-2 keyboard. */
static u32 keymap[NR_SCAN_CODES * MAP_COLS] = {
/* scan-code !Shift Shift E0 XX */
/* ==================================================================== */
/* 0x00 - none */ 0, 0, 0,
/* 0x01 - ESC */ ESC, ESC, 0,
/* 0x02 - '1' */ '1', '!', 0,
/* 0x03 - '2' */ '2', '@', 0,
/* 0x04 - '3' */ '3', '#', 0,
/* 0x05 - '4' */ '4', '$', 0,
/* 0x06 - '5' */ '5', '%', 0,
/* 0x07 - '6' */ '6', '^', 0,
/* 0x08 - '7' */ '7', '&', 0,
/* 0x09 - '8' */ '8', '*', 0,
/* 0x0A - '9' */ '9', '(', 0,
/* 0x0B - '0' */ '0', ')', 0,
/* 0x0C - '-' */ '-', '_', 0,
/* 0x0D - '=' */ '=', '+', 0,
/* 0x0E - BS */ BACKSPACE, BACKSPACE, 0,
/* 0x0F - TAB */ TAB, TAB, 0,
/* 0x10 - 'q' */ 'q', 'Q', 0,
/* 0x11 - 'w' */ 'w', 'W', 0,
/* 0x12 - 'e' */ 'e', 'E', 0,
/* 0x13 - 'r' */ 'r', 'R', 0,
/* 0x14 - 't' */ 't', 'T', 0,
/* 0x15 - 'y' */ 'y', 'Y', 0,
/* 0x16 - 'u' */ 'u', 'U', 0,
/* 0x17 - 'i' */ 'i', 'I', 0,
/* 0x18 - 'o' */ 'o', 'O', 0,
/* 0x19 - 'p' */ 'p', 'P', 0,
/* 0x1A - '[' */ '[', '{', 0,
/* 0x1B - ']' */ ']', '}', 0,
/* 0x1C - CR/LF */ ENTER, ENTER, PAD_ENTER,
/* 0x1D - l. Ctrl */ CTRL_L, CTRL_L, CTRL_R,
/* 0x1E - 'a' */ 'a', 'A', 0,
/* 0x1F - 's' */ 's', 'S', 0,
/* 0x20 - 'd' */ 'd', 'D', 0,
/* 0x21 - 'f' */ 'f', 'F', 0,
/* 0x22 - 'g' */ 'g', 'G', 0,
/* 0x23 - 'h' */ 'h', 'H', 0,
/* 0x24 - 'j' */ 'j', 'J', 0,
/* 0x25 - 'k' */ 'k', 'K', 0,
/* 0x26 - 'l' */ 'l', 'L', 0,
/* 0x27 - ';' */ ';', ':', 0,
/* 0x28 - '\'' */ '\'', '"', 0,
/* 0x29 - '`' */ '`', '~', 0,
/* 0x2A - l. SHIFT */ SHIFT_L, SHIFT_L, 0,
/* 0x2B - '\' */ '\\', '|', 0,
/* 0x2C - 'z' */ 'z', 'Z', 0,
/* 0x2D - 'x' */ 'x', 'X', 0,
/* 0x2E - 'c' */ 'c', 'C', 0,
/* 0x2F - 'v' */ 'v', 'V', 0,
/* 0x30 - 'b' */ 'b', 'B', 0,
/* 0x31 - 'n' */ 'n', 'N', 0,
/* 0x32 - 'm' */ 'm', 'M', 0,
/* 0x33 - ',' */ ',', '<', 0,
/* 0x34 - '.' */ '.', '>', 0,
/* 0x35 - '/' */ '/', '?', PAD_SLASH,
/* 0x36 - r. SHIFT */ SHIFT_R, SHIFT_R, 0,
/* 0x37 - '*' */ '*', '*', 0,
/* 0x38 - ALT */ ALT_L, ALT_L, ALT_R,
/* 0x39 - ' ' */ ' ', ' ', 0,
/* 0x3A - CapsLock */ CAPS_LOCK, CAPS_LOCK, 0,
/* 0x3B - F1 */ F1, F1, 0,
/* 0x3C - F2 */ F2, F2, 0,
/* 0x3D - F3 */ F3, F3, 0,
/* 0x3E - F4 */ F4, F4, 0,
/* 0x3F - F5 */ F5, F5, 0,
/* 0x40 - F6 */ F6, F6, 0,
/* 0x41 - F7 */ F7, F7, 0,
/* 0x42 - F8 */ F8, F8, 0,
/* 0x43 - F9 */ F9, F9, 0,
/* 0x44 - F10 */ F10, F10, 0,
/* 0x45 - NumLock */ NUM_LOCK, NUM_LOCK, 0,
/* 0x46 - ScrLock */ SCROLL_LOCK, SCROLL_LOCK, 0,
/* 0x47 - Home */ PAD_HOME, '7', HOME,
/* 0x48 - CurUp */ PAD_UP, '8', UP,
/* 0x49 - PgUp */ PAD_PAGEUP, '9', PAGEUP,
/* 0x4A - '-' */ PAD_MINUS, '-', 0,
/* 0x4B - Left */ PAD_LEFT, '4', LEFT,
/* 0x4C - MID */ PAD_MID, '5', 0,
/* 0x4D - Right */ PAD_RIGHT, '6', RIGHT,
/* 0x4E - '+' */ PAD_PLUS, '+', 0,
/* 0x4F - End */ PAD_END, '1', END,
/* 0x50 - Down */ PAD_DOWN, '2', DOWN,
/* 0x51 - PgDown */ PAD_PAGEDOWN, '3', PAGEDOWN,
/* 0x52 - Insert */ PAD_INS, '0', INSERT,
/* 0x53 - Delete */ PAD_DOT, '.', DELETE,
/* 0x54 - Enter */ 0, 0, 0,
/* 0x55 - ??? */ 0, 0, 0,
/* 0x56 - ??? */ 0, 0, 0,
/* 0x57 - F11 */ F11, F11, 0,
/* 0x58 - F12 */ F12, F12, 0,
/* 0x59 - ??? */ 0, 0, 0,
/* 0x5A - ??? */ 0, 0, 0,
/* 0x5B - ??? */ 0, 0, GUI_L,
/* 0x5C - ??? */ 0, 0, GUI_R,
/* 0x5D - ??? */ 0, 0, APPS,
/* 0x5E - ??? */ 0, 0, 0,
/* 0x5F - ??? */ 0, 0, 0,
/* 0x60 - ??? */ 0, 0, 0,
/* 0x61 - ??? */ 0, 0, 0,
/* 0x62 - ??? */ 0, 0, 0,
/* 0x63 - ??? */ 0, 0, 0,
/* 0x64 - ??? */ 0, 0, 0,
/* 0x65 - ??? */ 0, 0, 0,
/* 0x66 - ??? */ 0, 0, 0,
/* 0x67 - ??? */ 0, 0, 0,
/* 0x68 - ??? */ 0, 0, 0,
/* 0x69 - ??? */ 0, 0, 0,
/* 0x6A - ??? */ 0, 0, 0,
/* 0x6B - ??? */ 0, 0, 0,
/* 0x6C - ??? */ 0, 0, 0,
/* 0x6D - ??? */ 0, 0, 0,
/* 0x6E - ??? */ 0, 0, 0,
/* 0x6F - ??? */ 0, 0, 0,
/* 0x70 - ??? */ 0, 0, 0,
/* 0x71 - ??? */ 0, 0, 0,
/* 0x72 - ??? */ 0, 0, 0,
/* 0x73 - ??? */ 0, 0, 0,
/* 0x74 - ??? */ 0, 0, 0,
/* 0x75 - ??? */ 0, 0, 0,
/* 0x76 - ??? */ 0, 0, 0,
/* 0x77 - ??? */ 0, 0, 0,
/* 0x78 - ??? */ 0, 0, 0,
/* 0x78 - ??? */ 0, 0, 0,
/* 0x7A - ??? */ 0, 0, 0,
/* 0x7B - ??? */ 0, 0, 0,
/* 0x7C - ??? */ 0, 0, 0,
/* 0x7D - ??? */ 0, 0, 0,
/* 0x7E - ??? */ 0, 0, 0,
/* 0x7F - ??? */ 0, 0, 0
};
/*
:
:
*/
/*====================================================================
Appendix: Scan code set 1
*====================================================================
KEY MAKE BREAK| KEY MAKE BREAK | KEY MAKE BREAK
---------------------|------------------------|-----------------------
A 1E 9E | 9 0A 8A | [ 1A 9A
B 30 B0 | ` 29 89 | INSERT E0,52 E0,D2
C 2E AE | - 0C 8C | HOME E0,47 E0,C7
D 20 A0 | = 0D 8D | PG UP E0,49 E0,C9
E 12 92 | \ 2B AB | DELETE E0,53 E0,D3
F 21 A1 | BKSP 0E 8E | END E0,4F E0,CF
G 22 A2 | SPACE 39 B9 | PG DN E0,51 E0,D1
H 23 A3 | TAB 0F 8F | U ARROW E0,48 E0,C8
I 17 97 | CAPS 3A BA | L ARROW E0,4B E0,CB
J 24 A4 | L SHFT 2A AA | D ARROW E0,50 E0,D0
K 25 A5 | L CTRL 1D 9D | R ARROW E0,4D E0,CD
L 26 A6 | L GUI E0,5B E0,DB | NUM 45 C5
M 32 B2 | L ALT 38 B8 | KP / E0,35 E0,B5
N 31 B1 | R SHFT 36 B6 | KP * 37 B7
O 18 98 | R CTRL E0,1D E0,9D | KP - 4A CA
P 19 99 | R GUI E0,5C E0,DC | KP + 4E CE
Q 10 19 | R ALT E0,38 E0,B8 | KP EN E0,1C E0,9C
R 13 93 | APPS E0,5D E0,DD | KP . 53 D3
S 1F 9F | ENTER 1C 9C | KP 0 52 D2
T 14 94 | ESC 01 81 | KP 1 4F CF
U 16 96 | F1 3B BB | KP 2 50 D0
V 2F AF | F2 3C BC | KP 3 51 D1
W 11 91 | F3 3D BD | KP 4 4B CB
X 2D AD | F4 3E BE | KP 5 4C CC
Y 15 95 | F5 3F BF | KP 6 4D CD
Z 2C AC | F6 40 C0 | KP 7 47 C7
0 0B 8B | F7 41 C1 | KP 8 48 C8
1 02 82 | F8 42 C2 | KP 9 49 C9
2 03 83 | F9 43 C3 | ] 1B 9B
3 04 84 | F10 44 C4 | ; 27 A7
4 05 85 | F11 57 D7 | ' 28 A8
5 06 86 | F12 58 D8 | , 33 B3
| |
6 07 87 | PRTSCRN E0,2A E0,B7 | . 34 B4
| E0,37 E0,AA |
| |
7 08 88 | SCROLL 46 C6 | / 35 B5
| |
8 09 89 | PAUSE E1,1D |
| 45,E1, -NONE-|
| 9D,C5 |
----------------------------------------------------------------------
-----------------
ACPI Scan Codes:
-------------------------------------------
Key Make Code Break Code
-------------------------------------------
Power E0, 5E E0, DE
Sleep E0, 5F E0, DF
Wake E0, 63 E0, E3
-------------------------------
Windows Multimedia Scan Codes:
-------------------------------------------
Key Make Code Break Code
-------------------------------------------
Next Track E0, 19 E0, 99
Previous Track E0, 10 E0, 90
Stop E0, 24 E0, A4
Play/Pause E0, 22 E0, A2
Mute E0, 20 E0, A0
Volume Up E0, 30 E0, B0
Volume Down E0, 2E E0, AE
Media Select E0, 6D E0, ED
E-Mail E0, 6C E0, EC
Calculator E0, 21 E0, A1
My Computer E0, 6B E0, EB
WWW Search E0, 65 E0, E5
WWW Home E0, 32 E0, B2
WWW Back E0, 6A E0, EA
WWW Forward E0, 69 E0, E9
WWW Stop E0, 68 E0, E8
WWW Refresh E0, 67 E0, E7
WWW Favorites E0, 66 E0, E6
*=====================================================================================*/
#endif /* _ORANGES_KEYMAP_H_ */

View File

@ -5,7 +5,7 @@
#define MEMMAN_ADDR 0x01ff0000 //存memman31M960K
#define FMIBuff 0x007ff000 //loader中getFreeMemInfo返回值存放起始地址(7M1020K)
#define KWALL 0x00600000
#define WALL 0x00800000
#define WALL 0x00A00000
#define UWALL 0x01000000
#define MEMSTART 0x00400000
#define MEMEND 0x02000000

18
include/serialport.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef _SERIALPORT_H_
#define _SERIALPORT_H_
#include "tty.h"
#define PORT 0x3f8 // COM1
#define SERIAL_BUF_SIZE 256
int init_serial();
char read_serial();
void write_serial(char a);
void serial_tty_init_i(NTTY* tty);
void serial_tty_init_o(NTTY* tty);
int serial_tty_read(NTTY* tty, char* buf, int nr);
void serial_tty_write(NTTY* tty, char ch);
void serial_tty_rcevbuf(NTTY* tty, char ch);
#endif

View File

@ -13,6 +13,7 @@
#ifndef _ORANGES_TTY_H_
#define _ORANGES_TTY_H_
#include "type.h"
#define TTY_IN_BYTES 256 /* tty input queue size */
#define TTY_OUT_BUF_LEN 2 /* tty output buffer size */
@ -88,6 +89,14 @@ typedef struct keyboard_buf {
int readable;
} keyboard_buf;
typedef struct serial_buf {
void *buf;
int tail;
int head;
int len;
int readable;
} serial_buf;
#include "console.h"
void select_console(int nr_console);
@ -95,9 +104,7 @@ void init_screen(TTY *tty);
void out_char(CONSOLE *con, char ch);
int is_current_console(CONSOLE *con);
int init_serial();
char read_serial();
void write_serial(char a);
NTTY* get_tty(const int nr_tty);
void vga_tty_init(NTTY* tty);
void vga_tty_write(NTTY* tty, char ch);
@ -113,7 +120,7 @@ int ps2_tty_read(NTTY* tty, char* buf, int nr);
#define CYCLE_SUB(head, tail, _max) ((head) <= (tail) ? (tail)-(head) : (tail) + (_max) - (head))
#define NEXT(x, _max) (((x) + 1) % (_max))
#define LAST(x, _max) (((x) - 1) >= 0 ? ((x) - 1) % (_max) : (_max) - 1)
#define DEBUGNEW
#define FOREGROUND(color) ((u16)(color & 0xf) << 8)
#define BACKGROUND(color) ((u16)(color & 0xf) << 12)

View File

@ -30,7 +30,7 @@ void scroll_screen(CONSOLE *con, int dir);
*****************************************************************************/
void init_screen(TTY *tty)
{
int nr_tty = tty - tty_table;
int nr_tty = 0;
tty->console = console_table + nr_tty;

View File

@ -15,10 +15,6 @@
#include "minix_keymap.h"
#include "memman.h"
static KB_INPUT kb_in;
static MOUSE_INPUT mouse_in;
static int mouse_init;
static int code_with_E0;
static int shift_l; /* l shift state */
static int shift_r; /* r shift state */
@ -30,6 +26,9 @@ static int caps_lock; /* Caps Lock */
static int num_lock; /* Num Lock */
static int scroll_lock; /* Scroll Lock */
static int mouse_count;
static u8 mouse_data[MOUSE_IN_BYTES];
static void set_leds();
static void set_mouse_leds();
static void kb_wait();
@ -93,12 +92,19 @@ static u8 mouse_get_id()
return device_type;
}
void kb_handler(int irq)
static void set_mouse_leds()
{
u8 scan_code = inb(PS2_PORT_DATA);
kbd_process(scan_code);
// kprintf("kb");
};
kb_wait();
outb(KB_CMD, KBCMD_EN_MOUSE_INTFACE);
kb_wait();
outb(KB_CMD, KEYCMD_SENDTO_MOUSE);
kb_wait();
outb(KB_DATA, MOUSECMD_ENABLE);
kb_wait();
outb(KB_CMD, KEYCMD_WRITE_MODE);
kb_wait();
outb(KB_DATA, KBC_MODE);
}
void mouse_handler(int irq)
{
@ -106,17 +112,17 @@ void mouse_handler(int irq)
static int aux_state = 0;
int i;
u32 pack;
if (mouse_in.count == 0 && !(scan_code & 0x08))
if (mouse_count == 0 && !(scan_code & 0x08))
return; // resync
mouse_in.buf[mouse_in.count++] = scan_code;
if (mouse_in.count < 4)
mouse_data[mouse_count++] = scan_code;
if (mouse_count < 4)
return;
mouse_in.count = 0;
mouse_count = 0;
for (i = 0; i < 3; i++)
{
pack = ISMOUSE | MOUSEBTN;
if ((aux_state ^ mouse_in.buf[0]) & (1 << i))
if ((aux_state ^ mouse_data[0]) & (1 << i))
{
aux_state ^= (1 << i);
pack |= !!(aux_state & (1 << i)) ? MOUSEBTN_CLICK : MOUSEBTN_RELEASE;
@ -125,13 +131,13 @@ void mouse_handler(int irq)
}
}
pack = ISMOUSE | MOUSESCR;
if ((signed char)mouse_in.buf[3] > 0)
if ((signed char)mouse_data[3] > 0)
{
// actually it is 0x1
pack |= MOUSESCR_DOWN;
ps2_push(cur_ntty, pack);
}
else if ((signed char)mouse_in.buf[3] < 0)
else if ((signed char)mouse_data[3] < 0)
{
// actually it is 0xff
pack |= MOUSESCR_UP;
@ -139,23 +145,23 @@ void mouse_handler(int irq)
}
for (i = 0; i < 2; i++)
{
pack = mouse_in.buf[1 + i];
pack = mouse_data[1 + i];
if (pack != 0)
{
pack |= ISMOUSE | MOUSEPOS;
if (mouse_in.buf[0] & (0x10 << i))
if (mouse_data[0] & (0x10 << i))
pack |= MOUSEPOS_NEG;
if (i == 1)
pack |= MOUSEPOS_XY;
ps2_push(cur_ntty, pack);
}
}
// kprintf("0x%02x 0x%02x 0x%02x 0x%02x\n", mouse_in.buf[0], mouse_in.buf[1], mouse_in.buf[2], mouse_in.buf[3]);
// kprintf("0x%02x 0x%02x 0x%02x 0x%02x\n", mouse_data[0], mouse_data[1], mouse_data[2], mouse_data[3]);
}
void init_mouse()
{
mouse_in.count = 0;
mouse_count = 0;
put_irq_handler(MOUSE_IRQ, mouse_handler);
enable_irq(MOUSE_IRQ);
@ -181,13 +187,44 @@ void init_mouse()
assert(mouse_get_id() == 0x03); // z-axis enabled, id should be 3 (Mouse with scroll wheel)
mouse_write(PS2_CMD_DATA_REPORT_ENB);
assert(mouse_read() == PS2_ACK);
set_mouse_leds();
}
/**
* Wait until the input buffer of 8042 is empty.
*/
static void kb_wait() /* 等待 8042 的输入缓冲区空 */
{
u8 kb_stat;
do
{
kb_stat = inb(KB_CMD);
} while (kb_stat & 0x02);
}
/**
* Set the leds according to: caps_lock, num_lock & scroll_lock.
*/
static void set_leds()
{
kb_wait();
outb(KB_CMD, KEYCMD_WRITE_MODE);
kb_wait();
outb(KB_DATA, KBC_MODE);
}
void kb_handler(int irq)
{
u8 scan_code = inb(PS2_PORT_DATA);
kbd_process(scan_code);
// kprintf("kb");
};
void init_kb()
{
kb_in.count = 0;
kb_in.p_head = kb_in.p_tail = kb_in.buf;
shift_l = shift_r = 0;
alt_l = alt_r = 0;
ctrl_l = ctrl_r = 0;
@ -200,7 +237,6 @@ void init_kb()
enable_irq(KEYBOARD_IRQ);
init_mouse();
set_mouse_leds();
}
static u16 map_key(int code)
@ -326,53 +362,6 @@ static void kbd_process(unsigned char scode)
}
/*****************************************************************************
* kb_wait
*****************************************************************************/
/**
* Wait until the input buffer of 8042 is empty.
*
*****************************************************************************/
static void kb_wait() /* 等待 8042 的输入缓冲区空 */
{
u8 kb_stat;
do
{
kb_stat = inb(KB_CMD);
} while (kb_stat & 0x02);
}
/*****************************************************************************
* set_leds
*****************************************************************************/
/**
* Set the leds according to: caps_lock, num_lock & scroll_lock.
*
*****************************************************************************/
static void set_leds()
{
kb_wait();
outb(KB_CMD, KEYCMD_WRITE_MODE);
kb_wait();
outb(KB_DATA, KBC_MODE);
}
static void set_mouse_leds()
{
kb_wait();
outb(KB_CMD, KBCMD_EN_MOUSE_INTFACE);
kb_wait();
outb(KB_CMD, KEYCMD_SENDTO_MOUSE);
kb_wait();
outb(KB_DATA, MOUSECMD_ENABLE);
kb_wait();
outb(KB_CMD, KEYCMD_WRITE_MODE);
kb_wait();
outb(KB_DATA, KBC_MODE);
}
#define LASTKEY(x) LAST(x, TTY_IN_BYTES)
#define NEXTKEY(x) NEXT(x, TTY_IN_BYTES)
@ -390,13 +379,6 @@ void ps2_tty_init(NTTY *tty)
kbd->len = 0;
}
static inline void printallbuf(u8* ibuf) {
for (int i = 0; i < TTY_IN_BYTES; ++ i) {
kprintf("%c", ibuf[i]);
}
kprintf("\n");
}
int ps2_tty_read(NTTY *tty, char *buf, int nr)
{
assert(tty->input_buf);
@ -475,7 +457,8 @@ static void ps2_push(NTTY *tty, u32 key)
if (conno < NR_CONSOLES)
{
// kprintf("select console %d\n", conno);
vga_tty_select(get_tty(conno));
if (get_tty(conno)->driver_type == 1)
vga_tty_select(get_tty(conno));
}
break;
}

View File

@ -132,7 +132,7 @@ void initial()
do_vclose(stdout);
do_vclose(stderr);
exec("orange/test.bin");
exec("orange/shell_1.bin");
while (1)
;

View File

@ -22,6 +22,7 @@
#include "assert.h"
#include "stdio.h"
#include "tty.h"
#include "serialport.h"
static int initialize_processes(); // added by xw, 18/5/26
static int initialize_cpus(); // added by xw, 18/6/2
@ -44,7 +45,7 @@ int kernel_main()
// }
disp_pos = 0;
kprintf("-----Kernel Initialization Begins-----\n");
// kprintf("-----Kernel Initialization Begins-----\n");
kernel_initial = 1; // kernel is in initial state. added by xw, 18/5/31
init(); // 内存管理模块的初始化 add by liang

View File

@ -1,8 +1,112 @@
#include "serialport.h"
#include "x86.h"
#include "tty.h"
#include "const.h"
#include "type.h"
#include "assert.h"
#include "stdio.h"
#include "memman.h"
void put_irq_handler(int irq, irq_handler handler);
void enable_irq(int irq);
static void serial_buf_push(NTTY* tty, u32 key);
void serial_handler(int irq) {
volatile char ch = read_serial();
// kprintf("[%d]", ch);
serial_buf_push(get_tty(2), ch);
}
void serial_tty_init_i(NTTY* tty) {
serial_buf* sp = (serial_buf*)tty->input_buf;
sp->buf = (void*)K_PHY2LIN(do_kmalloc(SERIAL_BUF_SIZE));
kprintf("%p", sp->buf);
sp->head = sp->tail = sp->readable = sp->len = 0;
outb(PORT + 1, 0x01);
put_irq_handler(RS232_IRQ, serial_handler);
enable_irq(RS232_IRQ);
}
void serial_tty_init_o(NTTY* tty) {
// do nothing
}
#define NEXTKEY(x) NEXT(x, SERIAL_BUF_SIZE)
#define LASTKEY(x) LAST(x, SERIAL_BUF_SIZE)
static void serial_buf_push(NTTY* tty, u32 key) {
serial_buf* sp = (serial_buf*)tty->input_buf;
u8* buf = sp->buf;
switch (key)
{
case '\r':
case '\n': // escape ENTER
key = '\n';
buf[sp->tail] = '\n';
sp->len++;
sp->tail = NEXTKEY(sp->tail);
sp->readable = CYCLE_SUB(sp->head, sp->tail, SERIAL_BUF_SIZE);
serial_tty_rcevbuf(tty, '\n');
break;
case '\b': case 127:
key = '\b';
if (sp->len > sp->readable)
{
sp->len--;
sp->tail = LASTKEY(sp->tail);
serial_tty_rcevbuf(tty, '\b');
serial_tty_rcevbuf(tty, ' ');
serial_tty_rcevbuf(tty, '\b');
}
break;
default:
if ((key & 0xff) == 0)
return;
if (sp->len == SERIAL_BUF_SIZE - 1)
return;
buf[sp->tail] = (u8)(key & 0xff);
sp->len++;
sp->tail = NEXTKEY(sp->tail);
serial_tty_rcevbuf(tty, key & 0xff);
break;
}
}
int serial_tty_read(NTTY* tty, char* buf, int nr) {
assert(tty->input_buf);
serial_buf *sp = (serial_buf *)tty->input_buf;
int i = 0;
while (1)
{
if (sp->readable)
{
disable_int();
break;
}
}
assert(sp->buf);
u8 *ibuf = sp->buf;
for (; i < nr && i < sp->readable; ++i)
{
*buf ++ = ibuf[sp->head];
sp->head = NEXTKEY(sp->head);
}
sp->readable -= i;
sp->len -= i;
enable_int();
return i;
}
void serial_tty_write(NTTY* tty, char ch) {
write_serial(ch);
}
void serial_tty_rcevbuf(NTTY* tty, char ch) {
serial_tty_write(tty, ch);
}
#define PORT 0x3f8 // COM1
int init_serial() {
outb(PORT + 1, 0x00); // Disable all interrupts
outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
@ -16,12 +120,13 @@ int init_serial() {
// Check if serial is faulty (i.e: not same byte as sent)
if(inb(PORT + 0) != 0xAE) {
assert(0);
return 1;
}
// If serial is not faulty set it in normal operation mode
// (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
outb(PORT + 4, 0x0F);
outb(PORT + 4, 0x0f);
return 0;
}
static inline int is_transmit_empty() {

View File

@ -11,9 +11,11 @@
#include "x86.h"
#include "memman.h"
#include "stdio.h"
#include "serialport.h"
int current_console; // 当前显示在屏幕上的console
int tty_ok = 0;
void tty_write(NTTY *tty, char *buf, int len);
int tty_read(NTTY *tty, char *buf, int len);
@ -22,13 +24,9 @@ static void tty_dev_read(TTY *tty);
static void tty_dev_write(TTY *tty);
static void put_key(TTY *tty, u32 key);
#ifdef DEBUGNEW
NTTY* cur_ntty;
NTTY* ntty_table[NR_CONSOLES];
// int cur_ntty = 0;
static keyboard_buf keyboardbuf[NR_CONSOLES];
static vga_buf vgabuf[NR_CONSOLES];
inline NTTY* get_tty(const int nr_tty) {
return ntty_table[nr_tty];
@ -37,89 +35,32 @@ inline NTTY* get_tty(const int nr_tty) {
void init_tty_main()
{
NTTY *tty;
for (int i = 0; i < 3; ++i)
for (int i = 0; i < 2; ++i)
{
// tty = &ntty_table[i];
tty = (NTTY*)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
tty->driver_type = 1; // vga
// tty->input_buf = (void*)do_kmalloc(sizeof(keyboard_buf));
// tty->output_buf = (void*)do_kmalloc(sizeof(vga_buf));
tty->input_buf = &keyboardbuf[i];
tty->output_buf = &vgabuf[i];
tty->input_buf = (keyboard_buf*)K_PHY2LIN(do_kmalloc(sizeof(keyboard_buf)));
tty->output_buf = (vga_buf*)K_PHY2LIN(do_kmalloc(sizeof(vga_buf)));
vga_tty_init(tty);
ps2_tty_init(tty);
ntty_table[i] = tty;
// kprintf("tty: %p, outbuf: %p\n", tty, tty->output_buf);
}
tty = (NTTY*)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
tty->driver_type = 2;
tty->input_buf = (serial_buf*)K_PHY2LIN(do_kmalloc(sizeof(serial_buf)));
kprintf("tty: %p, outbuf: %p\n", tty, tty->input_buf);
tty->output_buf = NULL;
serial_tty_init_i(tty);
serial_tty_init_o(tty);
ntty_table[2] = tty;
cur_ntty = ntty_table[0];
tty_ok = 1;
}
#endif
#ifndef DEBUGNEW
void in_process(TTY *p_tty, u32 key)
{
int real_line = p_tty->console->orig / SCR_WIDTH;
if (!(key & FLAG_EXT))
{
put_key(p_tty, key);
}
else
{
int raw_code = key & MASK_RAW;
switch (raw_code)
{
case ENTER:
put_key(p_tty, '\n');
p_tty->status = p_tty->status & 3; //&3'b011
break;
case BACKSPACE:
put_key(p_tty, '\b');
break;
case UP:
if (p_tty->console->current_line < 43)
{
disable_int();
p_tty->console->current_line++;
outb(CRTC_ADDR_REG, START_ADDR_H);
outb(CRTC_DATA_REG, ((80 * (p_tty->console->current_line + real_line)) >> 8) & 0xFF);
outb(CRTC_ADDR_REG, START_ADDR_L);
outb(CRTC_DATA_REG, (80 * (p_tty->console->current_line + real_line)) & 0xFF);
enable_int();
}
break;
case DOWN:
if (p_tty->console->current_line > 0)
{
disable_int();
p_tty->console->current_line--;
outb(CRTC_ADDR_REG, START_ADDR_H);
outb(CRTC_DATA_REG, ((80 * (p_tty->console->current_line + real_line)) >> 8) & 0xFF);
outb(CRTC_ADDR_REG, START_ADDR_L);
outb(CRTC_DATA_REG, (80 * (p_tty->console->current_line + real_line)) & 0xFF);
enable_int();
}
break;
case F1:
case F2:
case F3:
case F4:
case F5:
case F6:
case F7:
case F8:
case F9:
case F10:
case F11:
case F12:
select_console(raw_code - F1);
break;
}
}
}
#endif
void task_tty()
{
@ -127,10 +68,14 @@ void task_tty()
// for (p_tty = ntty_table; p_tty < ntty_table + 3; ++ p_tty) {
// init_ntty(p_tty);
// }
volatile char serial_input;
while (1)
{
// sys_yield();
// vga_tty_flush(cur_ntty);
// serial_input = read_serial();
// vga_tty_write(get_tty(2), serial_input);
// kprintf("%c", serial_input);
}
}
@ -144,6 +89,13 @@ void task_tty()
*****************************************************************************/
void tty_write(NTTY *tty, char *buf, int len)
{
if (!tty_ok) {
while (--len >= 0)
{
write_serial(*buf++);
}
return;
}
while (--len >= 0)
{
vga_tty_write(tty, *buf++);

View File

@ -127,8 +127,8 @@ void vga_tty_init(NTTY *tty)
assert(tty->driver_type == 1);
assert(tty->output_buf);
vga_buf *vga = tty->output_buf;
// vga->buf = (void*)do_kmalloc(sizeof(u16) * SCR_BUFSIZE);
vga->buf = (void *)pagebuf[_cnt++];
vga->buf = (void*)K_PHY2LIN(do_kmalloc(sizeof(u16) * SCR_BUFSIZE));
// vga->buf = (void *)pagebuf[_cnt++];
// kprintf("malloced %p %p %p\n", vga->buf, &vga->buf, &vga->scr_top_line);
vga->cur_col = vga->cur_row = 0;
// buf->max_line = SCR_BUFSIZE / SCR_WIDTH;
@ -139,7 +139,7 @@ void vga_tty_init(NTTY *tty)
{
ptr_buf[i] = (BLANK << 16) | BLANK; // bg-black, fg-white, ascii-space
}
kprintf("%p 0x%x %d\n", vga->buf, ((u32 *)vga->buf)[20], vga->scr_cur_line);
// kprintf("%p 0x%x %d\n", vga->buf, ((u32 *)vga->buf)[20], vga->scr_cur_line);
}
#define INDEX(row, col) ((row)*SCR_WIDTH + (col))

View File

@ -4,9 +4,12 @@
#include "global.h"
#include "proto.h"
#include "tty.h"
#include "serialport.h"
static void serialputch(int ch, void * cnt) {
write_serial(ch);
// char _ch = ch;
// tty_write(cur_ntty, &_ch, 1);
}
static void

View File

@ -43,6 +43,7 @@ int main(int arg, char *argv[])
printf("\nminiOS:/ $ ");
if (gets(buf) && strlen(buf) != 0)
{
printf("received\n");
if (exec(buf) != 0)
{
printf("exec failed: file not found!\n");