a proto type
This commit is contained in:
parent
5f3333b6ce
commit
b070592c0b
@ -13,7 +13,7 @@
|
||||
|
||||
#ifndef _ORANGES_CONSOLE_H_
|
||||
#define _ORANGES_CONSOLE_H_
|
||||
|
||||
#include "tty.h"
|
||||
/* CONSOLE */
|
||||
typedef struct s_console
|
||||
{
|
||||
@ -28,10 +28,19 @@ typedef struct fb_console {
|
||||
|
||||
} fb_console;
|
||||
|
||||
typedef struct ringbuf {
|
||||
unsigned int head;
|
||||
unsigned int tail;
|
||||
unsigned int maxsize;
|
||||
unsigned int size;
|
||||
void* buf;
|
||||
} ringbuf_t;
|
||||
|
||||
void simpleconsole_init();
|
||||
void simpleconsole_write(char* buf, int nr);
|
||||
void simpleconsole_transfer(void (*write)(char ch));
|
||||
void simpleconsole_setcur(int row, int col);
|
||||
void fbcon_tty_write(NTTY* tty, char ch) ;
|
||||
|
||||
#define CON_MAX_LOGBUF 1024
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#define MEMMAN_FREES 4090 //32KB
|
||||
#define MEMMAN_ADDR 0x01ff0000 //存memman,31M960K
|
||||
#define FMIBuff 0x007ff000 //loader中getFreeMemInfo返回值存放起始地址(7M1020K)
|
||||
#define KWALL 0x00600000
|
||||
#define KWALL 0x00500000
|
||||
#define WALL 0x00A00000
|
||||
#define UWALL 0x01000000
|
||||
#define MEMSTART 0x00400000
|
||||
|
||||
@ -209,7 +209,7 @@ xchg(volatile u32 *addr, u32 newval)
|
||||
u32 result;
|
||||
|
||||
// The + in "+m" denotes a read-modify-write operand.
|
||||
asm volatile("lock\n\t xchgl %0, %1"
|
||||
asm volatile("lock; xchgl %0, %1"
|
||||
: "+m" (*addr), "=a" (result)
|
||||
: "1" (newval)
|
||||
: "cc");
|
||||
|
||||
13
include/yieldlock.h
Normal file
13
include/yieldlock.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "x86.h"
|
||||
#include "proto.h"
|
||||
static inline void acquire_y(volatile u32* lock) {
|
||||
while (xchg(lock, 1) == 1){
|
||||
sys_yield();
|
||||
}
|
||||
}
|
||||
|
||||
static inline void release_y(volatile u32* lock) {
|
||||
xchg(lock, 0);
|
||||
}
|
||||
@ -34,6 +34,7 @@ KERN_SRCFILES :=kernel/kernel.asm \
|
||||
kernel/vga.c \
|
||||
kernel/pci.c \
|
||||
kernel/bga.c \
|
||||
kernel/fbcon.c \
|
||||
lib/klib.c \
|
||||
|
||||
|
||||
|
||||
272
kernel/fbcon.c
272
kernel/fbcon.c
@ -1,101 +1,229 @@
|
||||
#include "type.h"
|
||||
#include "const.h"
|
||||
#include "protect.h"
|
||||
#include "string.h"
|
||||
#include "proc.h"
|
||||
#include "tty.h"
|
||||
#include "console.h"
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
#include "keyboard.h"
|
||||
#include "x86.h"
|
||||
#include "memman.h"
|
||||
#include "stdio.h"
|
||||
#include "serialport.h"
|
||||
#include "bga.h"
|
||||
#include "console.h"
|
||||
#include "const.h"
|
||||
#include "global.h"
|
||||
#include "keyboard.h"
|
||||
#include "memman.h"
|
||||
#include "proc.h"
|
||||
#include "protect.h"
|
||||
#include "proto.h"
|
||||
#include "serialport.h"
|
||||
#include "spinlock.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "tty.h"
|
||||
#include "type.h"
|
||||
#include "x86.h"
|
||||
#include "yieldlock.h"
|
||||
|
||||
|
||||
static int _cursor_x = 0;
|
||||
static int _cursor_y = 0;
|
||||
static int cur_col = 0;
|
||||
static int cur_row = 0;
|
||||
static int _fnt_char_width = 0;
|
||||
static int _fnt_char_height = 0;
|
||||
static int _scr_max_rows = 0;
|
||||
static int _scr_max_cols = 0;
|
||||
static int _fbbufsize = 0;
|
||||
static int _fbwidth = 0;
|
||||
static int _fbheight = 0;
|
||||
static int _fbpixels_per_row = 0;
|
||||
static int _fbscale = 1;
|
||||
static int cursor_blink = 0;
|
||||
static uint32_t _basecolor = 0x0;
|
||||
static uintptr_t _fb_paddr = 0;
|
||||
volatile uint32_t* _fb = NULL;
|
||||
static uint32_t* _fb = NULL;
|
||||
static uint32_t* cur_fb = NULL;
|
||||
static volatile int framecnt = 0;
|
||||
static char* textbuf;
|
||||
#define UNIT_CHAR_H (_fnt_char_height * _fbscale)
|
||||
#define UNIT_CHAR_W (_fnt_char_width * _fbscale)
|
||||
|
||||
#include "font8x8.h"
|
||||
static void update_cursor_position(char c)
|
||||
{
|
||||
_cursor_x += 8 * _fbscale;
|
||||
static void fast_copy(void* dst, void* src, int len);
|
||||
|
||||
if (c == '\n' || (_cursor_x + 8 * _fbscale) > _fbwidth) {
|
||||
_cursor_y += 8 * _fbscale;
|
||||
_cursor_x = 0;
|
||||
|
||||
if ((_cursor_y + 8 * _fbscale + 2) > _fbheight) {
|
||||
_cursor_y = 0;
|
||||
static void fbcon_draw_raw(int row, int col, char ch) {
|
||||
for (int x = 0; x < UNIT_CHAR_H; x++) {
|
||||
for (int y = 0; y < UNIT_CHAR_W; y++) {
|
||||
uint32_t ind = (col * UNIT_CHAR_W + x) + ((row * UNIT_CHAR_H + y) * _fbpixels_per_row);
|
||||
uint32_t clr = _basecolor;
|
||||
if (font8x8_basic[ch & 0x7f][y / _fbscale] &
|
||||
(1 << (x / _fbscale))) {
|
||||
clr ^= 0xffffffff;
|
||||
}
|
||||
cur_fb[ind] = clr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_cursor() {
|
||||
for (int x = 0; x < (8 * _fbscale); x++) {
|
||||
for (int y = 0; y < (8 * _fbscale); y++) {
|
||||
uint32_t ind = (_cursor_x + x) + ((_cursor_y + y) * _fbpixels_per_row);
|
||||
uint32_t clr = _basecolor;
|
||||
if (font8x8_basic[0][y / _fbscale] & (1 << (x / _fbscale))) {
|
||||
clr ^= 0xffffffff;
|
||||
}
|
||||
_fb[ind] = clr;
|
||||
}
|
||||
}
|
||||
fbcon_draw_raw(cur_row, cur_col, 0);
|
||||
}
|
||||
static void draw_char_on_screen(char c)
|
||||
{
|
||||
for (int x = 0; x < (8 * _fbscale); x++) {
|
||||
for (int y = 0; y < (8 * _fbscale); y++) {
|
||||
uint32_t ind = (_cursor_x + x) + ((_cursor_y + y) * _fbpixels_per_row);
|
||||
uint32_t clr = _basecolor;
|
||||
if (font8x8_basic[c & 0x7f][y / _fbscale] & (1 << (x / _fbscale))) {
|
||||
clr ^= 0xffffffff;
|
||||
}
|
||||
_fb[ind] = clr;
|
||||
}
|
||||
}
|
||||
update_cursor_position(c);
|
||||
|
||||
static void draw_cursor_clear() {
|
||||
fbcon_draw_raw(cur_row, cur_col, 1);
|
||||
}
|
||||
int screen_setup()
|
||||
{
|
||||
_cursor_x = 0;
|
||||
_cursor_y = 0;
|
||||
|
||||
static void fbcon_scroll() {
|
||||
int lineoffset = _fbwidth * _fnt_char_height * _fbscale;
|
||||
fast_copy( (void*)cur_fb,
|
||||
(void*)cur_fb + lineoffset,
|
||||
_fbbufsize - lineoffset);
|
||||
memset((void*)cur_fb + _fbbufsize - lineoffset, 0, lineoffset);
|
||||
}
|
||||
|
||||
static void fbcon_putchar(char ch) {
|
||||
switch (ch)
|
||||
{
|
||||
case '\n':
|
||||
cur_row ++;
|
||||
cur_col = 0;
|
||||
if (cur_row >= _scr_max_rows) {
|
||||
fbcon_scroll();
|
||||
cur_row --;
|
||||
}
|
||||
break;
|
||||
case '\r':
|
||||
cur_col = 0;
|
||||
break;
|
||||
case '\b':
|
||||
if (cur_col == 0) {
|
||||
if (cur_row) cur_row --;
|
||||
cur_col = _scr_max_cols - 1;
|
||||
}
|
||||
else {
|
||||
cur_col --;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fbcon_draw_raw(cur_row, cur_col, ch);
|
||||
cur_col ++;
|
||||
if (cur_col >= _scr_max_cols) {
|
||||
cur_col = 0;
|
||||
cur_row ++;
|
||||
}
|
||||
|
||||
if (cur_row >= _scr_max_rows) {
|
||||
fbcon_scroll();
|
||||
cur_row --;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
volatile u32 buflock;
|
||||
static char _buf1[TTY_IN_BYTES];
|
||||
ringbuf_t writebuf;
|
||||
|
||||
int screen_setup() {
|
||||
cur_col = 0;
|
||||
cur_row = 0;
|
||||
_fnt_char_width = 8;
|
||||
_fnt_char_height = 8;
|
||||
_fb = (uint32_t*)bga_ioctl(BGA_GET_BUFFER, 0);
|
||||
_fb_paddr = bga_ioctl(BGA_GET_BUFFER, 0);
|
||||
_fbwidth = bga_ioctl(BGA_GET_WIDTH, 0);
|
||||
_fbheight = bga_ioctl(BGA_GET_HEIGHT, 0);
|
||||
_fbpixels_per_row = _fbwidth;
|
||||
_fbbufsize = _fbwidth * _fbheight * 4;
|
||||
kprintf("bufsz = %p\n", _fbbufsize);
|
||||
_fbscale = 2;
|
||||
cur_fb = _fb;
|
||||
_scr_max_cols = _fbwidth / _fnt_char_width / _fbscale;
|
||||
_scr_max_rows = _fbheight / _fnt_char_height / _fbscale;
|
||||
|
||||
_basecolor = 0;
|
||||
cursor_blink = 1;
|
||||
writebuf.buf = &_buf1;
|
||||
writebuf.head = writebuf.tail = writebuf.size = 0;
|
||||
writebuf.maxsize = TTY_IN_BYTES;
|
||||
framecnt = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void task_tty()
|
||||
{
|
||||
// main rountine for drawing framebuffered console
|
||||
static inline void bufpush(ringbuf_t* buf, char data) {
|
||||
((char*)buf->buf)[buf->tail] = data;
|
||||
buf->tail = NEXT(buf->tail, buf->maxsize);
|
||||
if (buf->head == buf->tail)
|
||||
buf->head = NEXT(buf->head, buf->maxsize);
|
||||
else
|
||||
buf->size++;
|
||||
}
|
||||
|
||||
char text1[] = "hello world\n shit\b idiot\n retard fuckyou\n";
|
||||
char text2[] = "shabi ni\n ni zhe ge zhi zhangg\b ma de la ji wan yi er\n";
|
||||
|
||||
screen_setup();
|
||||
static inline char bufpop(ringbuf_t* buf) {
|
||||
if (buf->size == 0) return -1;
|
||||
char retval = ((char*)buf->buf)[buf->head];
|
||||
buf->head = NEXT(buf->head, buf->maxsize);
|
||||
buf->size--;
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void do_fbcon_write(char* buf, int nr) {
|
||||
while (xchg(&buflock, 1) == 1)
|
||||
sys_yield();
|
||||
while (nr--) {
|
||||
bufpush(&writebuf, *buf++);
|
||||
}
|
||||
xchg(&buflock, 0);
|
||||
}
|
||||
|
||||
void fbcon_tty_write(NTTY* tty, char ch) {
|
||||
do_fbcon_write(&ch, 1);
|
||||
}
|
||||
|
||||
static void blink_ctrl() {
|
||||
if (framecnt < 10) {
|
||||
framecnt ++;
|
||||
// kprintf("frame %d\n", framecnt);
|
||||
}
|
||||
else {
|
||||
framecnt = 0;
|
||||
cursor_blink = ! cursor_blink;
|
||||
// kprintf("should change\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void fast_copy(void* dst, void* src, int len) {
|
||||
// assume all address align, 32 bytes a time
|
||||
uint32_t* _src = src;
|
||||
uint32_t* _dst = dst;
|
||||
int i;
|
||||
for (i = 0; i < len / 4; i += 8) {
|
||||
_dst[i + 0] = _src[i + 0];
|
||||
_dst[i + 1] = _src[i + 1];
|
||||
_dst[i + 2] = _src[i + 2];
|
||||
_dst[i + 3] = _src[i + 3];
|
||||
_dst[i + 4] = _src[i + 4];
|
||||
_dst[i + 5] = _src[i + 5];
|
||||
_dst[i + 6] = _src[i + 6];
|
||||
_dst[i + 7] = _src[i + 7];
|
||||
}
|
||||
}
|
||||
|
||||
void task_tty() {
|
||||
// main rountine for drawing framebuffered console
|
||||
screen_setup();
|
||||
mmap((u32)_fb, _fb_paddr, _fbwidth * _fbheight * 4 * 2);
|
||||
for (char* p = text1; *p; ++ p){
|
||||
draw_char_on_screen(*p);
|
||||
}
|
||||
for (char* p = text2; *p; ++ p){
|
||||
draw_char_on_screen(*p);
|
||||
}
|
||||
draw_cursor();
|
||||
while (1)
|
||||
{
|
||||
|
||||
}
|
||||
buflock = 0;
|
||||
// fbcon_write(text1, strlen(text1));
|
||||
int cur_buf = 0, last_buf = 1;
|
||||
while (1) {
|
||||
fast_copy((void*)_fb + cur_buf * _fbbufsize, (void*)_fb + last_buf * _fbbufsize, _fbbufsize);
|
||||
draw_cursor_clear();
|
||||
while (xchg(&buflock, 1) == 1)
|
||||
yield();
|
||||
while (writebuf.size) {
|
||||
char ch = bufpop(&writebuf);
|
||||
fbcon_putchar(ch);
|
||||
}
|
||||
xchg(&buflock, 0);
|
||||
blink_ctrl();
|
||||
if (cursor_blink)
|
||||
draw_cursor();
|
||||
bga_ioctl(BGA_SWAP_BUFFERS, cur_buf);
|
||||
last_buf = cur_buf;
|
||||
cur_buf = !cur_buf;
|
||||
cur_fb = (void*)_fb + cur_buf * _fbbufsize;
|
||||
|
||||
sleep(5); // to no need to refresh that fast
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,7 @@
|
||||
#include "minix_keymap.h"
|
||||
#include "serialport.h"
|
||||
#include "memman.h"
|
||||
#include "yieldlock.h"
|
||||
|
||||
static int code_with_E0;
|
||||
static int shift_l; /* l shift state */
|
||||
@ -370,6 +371,7 @@ static void kbd_process(unsigned char scode)
|
||||
kbd_state = 0;
|
||||
}
|
||||
|
||||
static u32 kbdlock;
|
||||
|
||||
#define LASTKEY(x) LAST(x, TTY_IN_BYTES)
|
||||
#define NEXTKEY(x) NEXT(x, TTY_IN_BYTES)
|
||||
@ -386,6 +388,7 @@ void ps2_tty_init(NTTY *tty)
|
||||
// kprintf("kbd buf: %p\n", kbd->buf);
|
||||
kbd->head = kbd->tail = kbd->readable = 0;
|
||||
kbd->len = 0;
|
||||
kbdlock = 0;
|
||||
}
|
||||
|
||||
int ps2_tty_read(NTTY *tty, char *buf, int nr)
|
||||
@ -395,11 +398,15 @@ int ps2_tty_read(NTTY *tty, char *buf, int nr)
|
||||
int i = 0;
|
||||
while (1)
|
||||
{
|
||||
while (xchg(&kbdlock, 1) == 1)
|
||||
sys_yield();
|
||||
|
||||
if (kbd->readable)
|
||||
{
|
||||
disable_int();
|
||||
break;
|
||||
}
|
||||
release_y(&kbdlock);
|
||||
sys_yield();
|
||||
}
|
||||
assert(kbd->buf);
|
||||
u8 *ibuf = kbd->buf;
|
||||
@ -411,7 +418,7 @@ int ps2_tty_read(NTTY *tty, char *buf, int nr)
|
||||
}
|
||||
kbd->readable -= i;
|
||||
kbd->len -= i;
|
||||
enable_int();
|
||||
release_y(&kbdlock);
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -427,7 +434,7 @@ void ps2_tty_flush(NTTY *tty)
|
||||
void ps2_tty_recvbuf(NTTY *tty, u32 key)
|
||||
{
|
||||
// kprintf("%x\n", key);
|
||||
disable_int();
|
||||
// disable_int();
|
||||
assert(tty->input_buf);
|
||||
keyboard_buf *kbd = (keyboard_buf *)tty->input_buf;
|
||||
u8* buf = kbd->buf;
|
||||
@ -481,14 +488,19 @@ void ps2_tty_recvbuf(NTTY *tty, u32 key)
|
||||
{
|
||||
case '\r':
|
||||
case '\n': // escape ENTER
|
||||
while (xchg(&kbdlock, 1) == 1)
|
||||
sys_yield();
|
||||
tty->write(tty, '\n');
|
||||
buf[kbd->tail] = '\n';
|
||||
kbd->len++;
|
||||
kbd->tail = NEXTKEY(kbd->tail);
|
||||
kbd->readable = CYCLE_SUB(kbd->head, kbd->tail, TTY_IN_BYTES);
|
||||
release_y(&kbdlock);
|
||||
// kprintf("len=%d, h=%d, t=%d, rd=%d\n", kbd->len, kbd->head, kbd->tail, kbd->readable);
|
||||
break;
|
||||
case '\b':
|
||||
while (xchg(&kbdlock, 1) == 1)
|
||||
sys_yield();
|
||||
if (kbd->len > kbd->readable)
|
||||
{
|
||||
// vga_tty_backspace(tty);
|
||||
@ -498,22 +510,25 @@ void ps2_tty_recvbuf(NTTY *tty, u32 key)
|
||||
kbd->len--;
|
||||
kbd->tail = LASTKEY(kbd->tail);
|
||||
}
|
||||
release_y(&kbdlock);
|
||||
break;
|
||||
|
||||
default:
|
||||
while (xchg(&kbdlock, 1) == 1);
|
||||
if ((key & 0xff) == 0)
|
||||
return;
|
||||
if (kbd->len == TTY_IN_BYTES - 1)
|
||||
return; // leave one space for ctrl ascii
|
||||
tty->write(tty, key);
|
||||
buf[kbd->tail] = (u8)(key & 0xff);
|
||||
// kprintf("%d %d %d", key & 0xff, kbd->tail, buf[kbd->tail]);
|
||||
kbd->len++;
|
||||
kbd->tail = NEXTKEY(kbd->tail);
|
||||
release_y(&kbdlock);
|
||||
tty->write(tty, key);
|
||||
// kprintf("len=%d, h=%d, t=%d, rd=%d\n", kbd->len, kbd->head, kbd->tail, kbd->readable);
|
||||
break;
|
||||
}
|
||||
tty->ioctl(tty, IOCTL_CMD_TTY_FLUSH, 0);
|
||||
}
|
||||
enable_int();
|
||||
// enable_int();
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ void initial()
|
||||
do_vclose(stdout);
|
||||
do_vclose(stderr);
|
||||
|
||||
exec("orange/shell_1.bin");
|
||||
exec("orange/shell_0.bin");
|
||||
|
||||
while (1)
|
||||
;
|
||||
|
||||
@ -174,18 +174,18 @@ static int initialize_processes()
|
||||
/**************LDT*********************************/
|
||||
p_proc->task.ldt_sel = selector_ldt;
|
||||
memcpy(&p_proc->task.ldts[0], &gdt[SELECTOR_KERNEL_CS >> 3], sizeof(DESCRIPTOR));
|
||||
p_proc->task.ldts[0].attr1 = DA_C | PRIVILEGE_TASK << 5;
|
||||
p_proc->task.ldts[0].attr1 = DA_C | PRIVILEGE_KRNL << 5;
|
||||
memcpy(&p_proc->task.ldts[1], &gdt[SELECTOR_KERNEL_DS >> 3], sizeof(DESCRIPTOR));
|
||||
p_proc->task.ldts[1].attr1 = DA_DRW | PRIVILEGE_TASK << 5;
|
||||
p_proc->task.ldts[1].attr1 = DA_DRW | PRIVILEGE_KRNL << 5;
|
||||
|
||||
/**************寄存器初值**********************************/
|
||||
p_proc->task.regs.cs = ((8 * 0) & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
|
||||
p_proc->task.regs.ds = ((8 * 1) & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
|
||||
p_proc->task.regs.es = ((8 * 1) & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
|
||||
p_proc->task.regs.fs = ((8 * 1) & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
|
||||
p_proc->task.regs.ss = ((8 * 1) & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_TASK;
|
||||
p_proc->task.regs.gs = (SELECTOR_KERNEL_GS & SA_RPL_MASK) | RPL_TASK;
|
||||
p_proc->task.regs.eflags = 0x1202; /* IF=1, IOPL=1 */
|
||||
p_proc->task.regs.cs = ((8 * 0) & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_KRNL;
|
||||
p_proc->task.regs.ds = ((8 * 1) & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_KRNL;
|
||||
p_proc->task.regs.es = ((8 * 1) & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_KRNL;
|
||||
p_proc->task.regs.fs = ((8 * 1) & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_KRNL;
|
||||
p_proc->task.regs.ss = ((8 * 1) & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | RPL_KRNL;
|
||||
p_proc->task.regs.gs = (SELECTOR_KERNEL_GS & SA_RPL_MASK) | RPL_KRNL;
|
||||
p_proc->task.regs.eflags = 0x0202; /* IF=1, IOPL=1 */
|
||||
// p_proc->task.cr3 在页表初始化中处理
|
||||
|
||||
/**************线性地址布局初始化**********************************/ // add by visual 2016.5.4
|
||||
|
||||
@ -416,7 +416,7 @@ int sys_mmap(void *uesp)
|
||||
size_t mapsize = get_arg(uesp, 3);
|
||||
if (mapsize % num_4K) return -1;
|
||||
int pid = p_proc_current->task.pid;
|
||||
|
||||
kprintf("[\x1b[32mmmap\x1b[0m] 0x%08X -> 0x%08X, length %X\n", linaddr, phyaddr, mapsize);
|
||||
for (size_t off = 0; off <= mapsize; off += num_4K) {
|
||||
lin_mapping_phy(linaddr + off, phyaddr + off, pid, PG_P | PG_USU | PG_RWW, PG_P | PG_USU | PG_RWW);
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "proc.h"
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
#include "stdio.h"
|
||||
|
||||
/*======================================================================*
|
||||
schedule
|
||||
@ -19,35 +20,43 @@
|
||||
void schedule()
|
||||
{
|
||||
PROCESS* p;
|
||||
int greatest_ticks = 0;
|
||||
|
||||
//Added by xw, 18/4/21
|
||||
if (p_proc_current->task.stat == READY && p_proc_current->task.ticks > 0) {
|
||||
p_proc_next = p_proc_current; //added by xw, 18/4/26
|
||||
return;
|
||||
}
|
||||
|
||||
while (!greatest_ticks)
|
||||
{
|
||||
for (p = proc_table; p < proc_table+NR_PCBS; p++) //edit by visual 2016.4.5
|
||||
{
|
||||
if (p->task.stat == READY && p->task.ticks > greatest_ticks) //edit by visual 2016.4.5
|
||||
{
|
||||
greatest_ticks = p->task.ticks;
|
||||
// p_proc_current = p;
|
||||
p_proc_next = p; //modified by xw, 18/4/26
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!greatest_ticks)
|
||||
{
|
||||
for (p = proc_table; p < proc_table+NR_PCBS; p++) //edit by visual 2016.4.5
|
||||
{
|
||||
p->task.ticks = p->task.priority;
|
||||
}
|
||||
for (int i = NEXT(p_proc_current->task.pid, NR_PCBS); i != p_proc_current->task.pid; i = NEXT(i, NR_PCBS)) {
|
||||
if (proc_table[i].task.stat == READY) {
|
||||
p_proc_next = &proc_table[i];
|
||||
return;
|
||||
}
|
||||
}
|
||||
p_proc_next = p_proc_current;
|
||||
kprintf("shit\n");
|
||||
|
||||
// int greatest_ticks = 0;
|
||||
// //Added by xw, 18/4/21
|
||||
// if (p_proc_current->task.stat == READY && p_proc_current->task.ticks > 0) {
|
||||
// p_proc_next = p_proc_current; //added by xw, 18/4/26
|
||||
// return;
|
||||
// }
|
||||
|
||||
// while (!greatest_ticks)
|
||||
// {
|
||||
// for (p = proc_table; p < proc_table+NR_PCBS; p++) //edit by visual 2016.4.5
|
||||
// {
|
||||
// if (p->task.stat == READY && p->task.ticks > greatest_ticks) //edit by visual 2016.4.5
|
||||
// {
|
||||
// greatest_ticks = p->task.ticks;
|
||||
// // p_proc_current = p;
|
||||
// p_proc_next = p; //modified by xw, 18/4/26
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// if (!greatest_ticks)
|
||||
// {
|
||||
// for (p = proc_table; p < proc_table+NR_PCBS; p++) //edit by visual 2016.4.5
|
||||
// {
|
||||
// p->task.ticks = p->task.priority;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/*======================================================================*
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
|
||||
/* 本文件内函数声明 */
|
||||
static void init_idt_desc(unsigned char vector, u8 desc_type, int_handler handler, unsigned char privilege);
|
||||
@ -264,32 +265,25 @@ void exception_handler(int vec_no, int err_code, int eip, int cs, int eflags)
|
||||
"#MC Machine Check",
|
||||
"#XF SIMD Floating-Point Exception"};
|
||||
|
||||
/* 通过打印空格的方式清空屏幕的前五行,并把 disp_pos 清零 */
|
||||
disp_pos = 0;
|
||||
for (i = 0; i < 80 * 5; i++)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
disp_pos = 0;
|
||||
|
||||
printf("\x1b[31;47mException! --> ");
|
||||
printf(err_description[vec_no]);
|
||||
printf("\n\n");
|
||||
printf("EFLAGS:\x1b[m");
|
||||
printf("%d", eflags);
|
||||
printf("\x1b[31;47mCS:\x1b[m");
|
||||
printf("%d", cs);
|
||||
printf("\x1b[31;47mEIP:\x1b[m");
|
||||
printf("%d", eip);
|
||||
kprintf("\x1b[31;47mException! --> ");
|
||||
kprintf(err_description[vec_no]);
|
||||
kprintf("\n\n");
|
||||
kprintf("EFLAGS:\x1b[m");
|
||||
kprintf("%x", eflags);
|
||||
kprintf("\x1b[31;47mCS:\x1b[m");
|
||||
kprintf("%x", cs);
|
||||
kprintf("\x1b[31;47mEIP:\x1b[m");
|
||||
kprintf("%p", eip);
|
||||
|
||||
if (err_code != 0xFFFFFFFF)
|
||||
{
|
||||
printf("\x1b[31;47mError code:\x1b[m");
|
||||
printf("%d", err_code);
|
||||
kprintf("\x1b[31;47mError code:\x1b[m");
|
||||
kprintf("%x", err_code);
|
||||
}
|
||||
|
||||
// added by xw, 18/12/19
|
||||
printf("\n");
|
||||
kprintf("\n");
|
||||
|
||||
// added by xw, 18/12/19
|
||||
p_proc_current->task.stat = KILLED;
|
||||
@ -316,7 +310,7 @@ void divide_error_handler()
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("Loop in divide error handler...\n");
|
||||
kprintf("Loop in divide error handler...\n");
|
||||
|
||||
i = 100;
|
||||
while (--i)
|
||||
|
||||
19
kernel/tty.c
19
kernel/tty.c
@ -57,7 +57,24 @@ static int dummy_ioctl(NTTY* tty, u32 cmd, long arg) {return 0;}
|
||||
void init_tty_main()
|
||||
{
|
||||
NTTY *tty;
|
||||
for (int i = 0; i < 2; ++i)
|
||||
for (int i = 0; i < 1; ++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 = (keyboard_buf*)K_PHY2LIN(do_kmalloc(sizeof(keyboard_buf)));
|
||||
tty->output_buf = NULL;
|
||||
// vga_tty_init(tty);
|
||||
ps2_tty_init(tty);
|
||||
tty->write = fbcon_tty_write;
|
||||
tty->read = ps2_tty_read;
|
||||
tty->recvbuf = ps2_tty_recvbuf;
|
||||
tty->ioctl = dummy_ioctl;
|
||||
ntty_table[i] = tty;
|
||||
}
|
||||
for (int i = 1; i < 2; ++i)
|
||||
{
|
||||
// tty = &ntty_table[i];
|
||||
tty = (NTTY*)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
||||
|
||||
@ -9,8 +9,8 @@
|
||||
static void kprintfputch(int ch, int *cnt)
|
||||
{
|
||||
write_serial(ch);
|
||||
char _ch = ch;
|
||||
tty_write(cur_ntty, &_ch, 1);
|
||||
// char _ch = ch;
|
||||
// tty_write(cur_ntty, &_ch, 1);
|
||||
(*cnt)++;
|
||||
}
|
||||
|
||||
|
||||
@ -9,9 +9,9 @@
|
||||
|
||||
int main(int arg, char *argv[])
|
||||
{
|
||||
int stdin = open("dev_tty2", O_RDWR);
|
||||
int stdout = open("dev_tty2", O_RDWR);
|
||||
int stderr = open("dev_tty2", O_RDWR);
|
||||
int stdin = open("dev_tty0", O_RDWR);
|
||||
int stdout = open("dev_tty0", O_RDWR);
|
||||
int stderr = open("dev_tty0", O_RDWR);
|
||||
|
||||
char buf[1024];
|
||||
int pid;
|
||||
|
||||
@ -16,10 +16,11 @@ int main(int arg, char *argv[])
|
||||
char buf[1024];
|
||||
int pid;
|
||||
int times = 0;
|
||||
// for (int i = 0; i < 20; ++i)
|
||||
// {
|
||||
// printf("test %d\n", i);
|
||||
// }
|
||||
for (int i = 0; i < 50; ++i)
|
||||
{
|
||||
printf("test %d\n", i);
|
||||
for (int j = 0; j < 2000000; ++ j);
|
||||
}
|
||||
// for (int i = 0; i < 2; ++i)
|
||||
// {
|
||||
// printf("\x1b[42;31m1111111111");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user