merge for submit
This commit is contained in:
parent
0eb609914b
commit
fdaff54b21
16
include/bga.h
Normal file
16
include/bga.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "pci.h"
|
||||
#include "type.h"
|
||||
|
||||
#define BGA_SWAP_BUFFERS 0x0101
|
||||
#define BGA_GET_HEIGHT 0x0102
|
||||
#define BGA_GET_WIDTH 0x0103
|
||||
#define BGA_GET_SCALE 0x0104
|
||||
#define BGA_DISABLE 0x0105
|
||||
#define BGA_SET_WIDTH 0x0106
|
||||
#define BGA_SET_HEIGHT 0x0107
|
||||
#define BGA_SET_UPDATE 0x0108
|
||||
#define BGA_GET_BUFFER 0x0109
|
||||
|
||||
int init_bga(pci_dev_t* dev);
|
||||
int bga_ioctl(uintptr_t cmd, uintptr_t arg);
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
#ifndef _ORANGES_CONSOLE_H_
|
||||
#define _ORANGES_CONSOLE_H_
|
||||
|
||||
#include "tty.h"
|
||||
/* CONSOLE */
|
||||
typedef struct s_console
|
||||
{
|
||||
@ -22,12 +22,22 @@ typedef struct s_console
|
||||
unsigned int buf_head; // for futher restore after true tty initialized
|
||||
unsigned int buf_tail;
|
||||
char *buf;
|
||||
} CONSOLE;
|
||||
} s_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) ;
|
||||
void fbcon_screen_setup();
|
||||
|
||||
#define CON_MAX_LOGBUF 1024
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@
|
||||
|
||||
/* system call */
|
||||
// #define NR_SYS_CALL 23 //last modified by xw, 18/6/19
|
||||
#define NR_SYS_CALL 26 // modified by mingxuan 2019-5-17
|
||||
#define NR_SYS_CALL 30 // modified by mingxuan 2019-5-17
|
||||
|
||||
/* TTY */
|
||||
// added by mingxuan 2019-5-19
|
||||
|
||||
152
include/font8x8.h
Normal file
152
include/font8x8.h
Normal file
@ -0,0 +1,152 @@
|
||||
/**
|
||||
* 8x8 monochrome bitmap fonts for rendering
|
||||
* Author: Daniel Hepper <daniel@hepper.net>
|
||||
*
|
||||
* License: Public Domain
|
||||
*
|
||||
* Based on:
|
||||
* // Summary: font8x8.h
|
||||
* // 8x8 monochrome bitmap fonts for rendering
|
||||
* //
|
||||
* // Author:
|
||||
* // Marcel Sondaar
|
||||
* // International Business Machines (public domain VGA fonts)
|
||||
* //
|
||||
* // License:
|
||||
* // Public Domain
|
||||
*
|
||||
* Fetched from: http://dimensionalrift.homelinux.net/combuster/mos3/?p=viewsource&file=/modules/gfx/font8_8.asm
|
||||
**/
|
||||
#pragma once
|
||||
// Constant: font8x8_basic
|
||||
// Contains an 8x8 font map for unicode points U+0000 - U+007F (basic latin)
|
||||
static char font8x8_basic[128][8] = {
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x3E }, // U+0000 (nul)
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0001
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0002
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0003
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0004
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0005
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0006
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0007
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0008
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0009
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000A
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000B
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000C
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000D
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000E
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000F
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0010
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0011
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0012
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0013
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0014
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0015
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0016
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0017
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0018
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0019
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001A
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001B
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001C
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001D
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001E
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001F
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0020 (space)
|
||||
{ 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00 }, // U+0021 (!)
|
||||
{ 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0022 (")
|
||||
{ 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00 }, // U+0023 (#)
|
||||
{ 0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00 }, // U+0024 ($)
|
||||
{ 0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00 }, // U+0025 (%)
|
||||
{ 0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00 }, // U+0026 (&)
|
||||
{ 0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0027 (')
|
||||
{ 0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00 }, // U+0028 (()
|
||||
{ 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00 }, // U+0029 ())
|
||||
{ 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00 }, // U+002A (*)
|
||||
{ 0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00 }, // U+002B (+)
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06 }, // U+002C (,)
|
||||
{ 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00 }, // U+002D (-)
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00 }, // U+002E (.)
|
||||
{ 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00 }, // U+002F (/)
|
||||
{ 0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00 }, // U+0030 (0)
|
||||
{ 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00 }, // U+0031 (1)
|
||||
{ 0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00 }, // U+0032 (2)
|
||||
{ 0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00 }, // U+0033 (3)
|
||||
{ 0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00 }, // U+0034 (4)
|
||||
{ 0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00 }, // U+0035 (5)
|
||||
{ 0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00 }, // U+0036 (6)
|
||||
{ 0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00 }, // U+0037 (7)
|
||||
{ 0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00 }, // U+0038 (8)
|
||||
{ 0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00 }, // U+0039 (9)
|
||||
{ 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00 }, // U+003A (:)
|
||||
{ 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06 }, // U+003B (;)
|
||||
{ 0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00 }, // U+003C (<)
|
||||
{ 0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00 }, // U+003D (=)
|
||||
{ 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00 }, // U+003E (>)
|
||||
{ 0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00 }, // U+003F (?)
|
||||
{ 0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00 }, // U+0040 (@)
|
||||
{ 0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00 }, // U+0041 (A)
|
||||
{ 0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00 }, // U+0042 (B)
|
||||
{ 0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00 }, // U+0043 (C)
|
||||
{ 0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00 }, // U+0044 (D)
|
||||
{ 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00 }, // U+0045 (E)
|
||||
{ 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00 }, // U+0046 (F)
|
||||
{ 0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00 }, // U+0047 (G)
|
||||
{ 0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00 }, // U+0048 (H)
|
||||
{ 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0049 (I)
|
||||
{ 0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00 }, // U+004A (J)
|
||||
{ 0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00 }, // U+004B (K)
|
||||
{ 0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00 }, // U+004C (L)
|
||||
{ 0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00 }, // U+004D (M)
|
||||
{ 0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00 }, // U+004E (N)
|
||||
{ 0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00 }, // U+004F (O)
|
||||
{ 0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00 }, // U+0050 (P)
|
||||
{ 0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00 }, // U+0051 (Q)
|
||||
{ 0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00 }, // U+0052 (R)
|
||||
{ 0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00 }, // U+0053 (S)
|
||||
{ 0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0054 (T)
|
||||
{ 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00 }, // U+0055 (U)
|
||||
{ 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00 }, // U+0056 (V)
|
||||
{ 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00 }, // U+0057 (W)
|
||||
{ 0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00 }, // U+0058 (X)
|
||||
{ 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0059 (Y)
|
||||
{ 0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00 }, // U+005A (Z)
|
||||
{ 0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00 }, // U+005B ([)
|
||||
{ 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00 }, // U+005C (\)
|
||||
{ 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00 }, // U+005D (])
|
||||
{ 0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00 }, // U+005E (^)
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF }, // U+005F (_)
|
||||
{ 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0060 (`)
|
||||
{ 0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00 }, // U+0061 (a)
|
||||
{ 0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00 }, // U+0062 (b)
|
||||
{ 0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00 }, // U+0063 (c)
|
||||
{ 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00 }, // U+0064 (d)
|
||||
{ 0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00 }, // U+0065 (e)
|
||||
{ 0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00 }, // U+0066 (f)
|
||||
{ 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F }, // U+0067 (g)
|
||||
{ 0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00 }, // U+0068 (h)
|
||||
{ 0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0069 (i)
|
||||
{ 0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E }, // U+006A (j)
|
||||
{ 0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00 }, // U+006B (k)
|
||||
{ 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+006C (l)
|
||||
{ 0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00 }, // U+006D (m)
|
||||
{ 0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00 }, // U+006E (n)
|
||||
{ 0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00 }, // U+006F (o)
|
||||
{ 0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F }, // U+0070 (p)
|
||||
{ 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78 }, // U+0071 (q)
|
||||
{ 0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00 }, // U+0072 (r)
|
||||
{ 0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00 }, // U+0073 (s)
|
||||
{ 0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00 }, // U+0074 (t)
|
||||
{ 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00 }, // U+0075 (u)
|
||||
{ 0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00 }, // U+0076 (v)
|
||||
{ 0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00 }, // U+0077 (w)
|
||||
{ 0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00 }, // U+0078 (x)
|
||||
{ 0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F }, // U+0079 (y)
|
||||
{ 0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00 }, // U+007A (z)
|
||||
{ 0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00 }, // U+007B ({)
|
||||
{ 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00 }, // U+007C (|)
|
||||
{ 0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00 }, // U+007D (})
|
||||
{ 0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+007E (~)
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } // U+007F
|
||||
};
|
||||
@ -8,6 +8,11 @@
|
||||
/* equal to 1 if kernel is initializing, equal to 0 if done.
|
||||
* added by xw, 18/5/31
|
||||
*/
|
||||
#pragma once
|
||||
#include "protect.h"
|
||||
#include "proc.h"
|
||||
#include "const.h"
|
||||
//#define USE_FBCON
|
||||
extern int kernel_initial;
|
||||
|
||||
extern int ticks;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#ifndef _ORANGES_MEMMAN_H_
|
||||
#define _ORANGES_MEMMAN_H_
|
||||
|
||||
#include "type.h"
|
||||
#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
|
||||
|
||||
53
include/pci.h
Normal file
53
include/pci.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
** Copyright 2002-2003, Michael Noisternig. All rights reserved.
|
||||
** Distributed under the terms of the NewOS License.
|
||||
*/
|
||||
#ifndef _PCI_H_
|
||||
#define _PCI_H_
|
||||
#include "type.h"
|
||||
typedef struct {
|
||||
char prefetchable;
|
||||
uint32_t address;
|
||||
uint8_t type;
|
||||
} bar_t;
|
||||
#define INPUT_OUTPUT 0
|
||||
#define MEMORY_MAPPED 1
|
||||
|
||||
struct device_desc_pci {
|
||||
uint8_t bus;
|
||||
uint8_t device;
|
||||
uint8_t function;
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
uint8_t class_id;
|
||||
uint8_t subclass_id;
|
||||
uint8_t interface_id;
|
||||
uint8_t revision_id;
|
||||
uint32_t interrupt;
|
||||
uint32_t port_base;
|
||||
uint32_t type;
|
||||
};
|
||||
typedef struct device_desc_pci pci_dev_t;
|
||||
|
||||
enum DEVICES_TYPE {
|
||||
DEVICE_STORAGE = (1 << 0),
|
||||
DEVICE_SOUND = (1 << 1),
|
||||
DEVICE_INPUT_SYSTEMS = (1 << 2),
|
||||
DEVICE_NETWORK = (1 << 3),
|
||||
DEVICE_DISPLAY = (1 << 4),
|
||||
DEVICE_BUS_CONTROLLER = (1 << 5),
|
||||
DEVICE_BRIDGE = (1 << 6),
|
||||
DEVICE_CHAR = (1 << 7),
|
||||
DEVICE_RTC = (1 << 8),
|
||||
DEVICE_UNKNOWN = (1 << 9),
|
||||
};
|
||||
|
||||
uint32_t pci_read(uint16_t bus, uint16_t device, uint16_t function, uint32_t offset);
|
||||
void pci_write(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint32_t data);
|
||||
pci_dev_t pci_get_device_desriptor(uint8_t bus, uint8_t device, uint8_t function);
|
||||
pci_dev_t* get_pci_bga();
|
||||
uint32_t pci_read_bar(pci_dev_t* pci_dev, int bar_id);
|
||||
|
||||
#define NR_PCI_DEV 8
|
||||
|
||||
#endif
|
||||
@ -15,6 +15,8 @@
|
||||
* below instead.
|
||||
* added by xw, 17/12/11
|
||||
*/
|
||||
#pragma once
|
||||
#include "protect.h"
|
||||
#define INIT_STACK_SIZE 1024 * 8 //new kernel stack is 8kB
|
||||
#define P_STACKBASE 0
|
||||
#define GSREG 0
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
#ifndef _ORANGES_PROTECT_H_
|
||||
#define _ORANGES_PROTECT_H_
|
||||
|
||||
#include "type.h"
|
||||
|
||||
/* 存储段描述符/系统段描述符 */
|
||||
typedef struct s_descriptor /* 共 8 个字节 */
|
||||
|
||||
@ -4,6 +4,11 @@
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Forrest Yu, 2005
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
#ifndef _PROTO_H_
|
||||
#define _PROTO_H_
|
||||
|
||||
#include "type.h"
|
||||
#include "tty.h"
|
||||
|
||||
// added by zcr
|
||||
void disable_irq(int irq);
|
||||
@ -86,7 +91,7 @@ int sys_get_ticks(); /* sys_call */
|
||||
int sys_get_pid(); // add by visual 2016.4.6
|
||||
void *sys_kmalloc(int size); // edit by visual 2016.5.9
|
||||
void *sys_kmalloc_4k(); // edit by visual 2016.5.9
|
||||
void *sys_malloc(int size); // edit by visual 2016.5.9
|
||||
void *sys_malloc(void* uesp); // edit by visual 2016.5.9
|
||||
void *sys_malloc_4k(); // edit by visual 2016.5.9
|
||||
int sys_free(void *arg); // edit by visual 2016.5.9
|
||||
int sys_free_4k(void *AdddrLin); // edit by visual 2016.5.9
|
||||
@ -128,4 +133,11 @@ void write_page_pde(u32 PageDirPhyAddr, u32 AddrLin, u32 TblPhyAddr, u32 Attribu
|
||||
void write_page_pte(u32 TblPhyAddr, u32 AddrLin, u32 PhyAddr, u32 Attribute);
|
||||
u32 vmalloc(u32 size);
|
||||
int lin_mapping_phy(u32 AddrLin, u32 phy_addr, u32 pid, u32 pde_Attribute, u32 pte_Attribute); // edit by visual 2016.5.19
|
||||
int klin_mapping_phy(u32 AddrLin, u32 phy_addr, u32 pde_Attribute, u32 pte_Attribute); // edit by visual 2016.5.19
|
||||
void clear_kernel_pagepte_low(); // add by visual 2016.5.12
|
||||
int sys_mmap(void *uesp);
|
||||
int mmap(u32 linaddr, u32 phyaddr, u32 size);
|
||||
/* add by catfood */
|
||||
|
||||
void init_pci();
|
||||
#endif
|
||||
@ -24,6 +24,24 @@ typedef unsigned short u16;
|
||||
typedef char i8;
|
||||
typedef unsigned char u8;
|
||||
|
||||
typedef long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
typedef int int32;
|
||||
typedef unsigned int uint32;
|
||||
typedef short int16;
|
||||
typedef unsigned short uint16;
|
||||
typedef char int8;
|
||||
typedef unsigned char uint8;
|
||||
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
|
||||
typedef i32 intptr_t;
|
||||
typedef u32 uintptr_t;
|
||||
|
||||
|
||||
@ -187,6 +187,14 @@ read_esp(void)
|
||||
return esp;
|
||||
}
|
||||
|
||||
static inline u32
|
||||
read_cr3(void)
|
||||
{
|
||||
u32 cr3;
|
||||
asm volatile("movl %%cr3,%0" : "=r" (cr3));
|
||||
return cr3;
|
||||
}
|
||||
|
||||
static inline u64
|
||||
read_tsc(void)
|
||||
{
|
||||
@ -201,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");
|
||||
|
||||
@ -33,6 +33,9 @@ KERN_SRCFILES :=kernel/kernel.asm \
|
||||
kernel/serialport.c \
|
||||
kernel/vga.c \
|
||||
kernel/csi.c \
|
||||
kernel/pci.c \
|
||||
kernel/bga.c \
|
||||
kernel/fbcon.c \
|
||||
lib/klib.c \
|
||||
|
||||
|
||||
|
||||
136
kernel/bga.c
Normal file
136
kernel/bga.c
Normal file
@ -0,0 +1,136 @@
|
||||
#include "bga.h"
|
||||
|
||||
#include "assert.h"
|
||||
#include "console.h"
|
||||
#include "const.h"
|
||||
#include "global.h"
|
||||
#include "keyboard.h"
|
||||
#include "memman.h"
|
||||
#include "pci.h"
|
||||
#include "proc.h"
|
||||
#include "protect.h"
|
||||
#include "proto.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "tty.h"
|
||||
#include "type.h"
|
||||
#include "x86.h"
|
||||
|
||||
#define VBE_DISPI_IOPORT_INDEX 0x01CE
|
||||
#define VBE_DISPI_IOPORT_DATA 0x01CF
|
||||
|
||||
#define VBE_DISPI_INDEX_ID 0x0
|
||||
#define VBE_DISPI_INDEX_XRES 0x1
|
||||
#define VBE_DISPI_INDEX_YRES 0x2
|
||||
#define VBE_DISPI_INDEX_BPP 0x3
|
||||
#define VBE_DISPI_INDEX_ENABLE 0x4
|
||||
#define VBE_DISPI_INDEX_BANK 0x5
|
||||
#define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
|
||||
#define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
|
||||
#define VBE_DISPI_INDEX_X_OFFSET 0x8
|
||||
#define VBE_DISPI_INDEX_Y_OFFSET 0x9
|
||||
|
||||
#define VBE_DISPI_DISABLED 0x00
|
||||
#define VBE_DISPI_ENABLED 0x01
|
||||
#define VBE_DISPI_LFB_ENABLED 0x40
|
||||
|
||||
static uint16_t bga_screen_width, bga_screen_height;
|
||||
static uint32_t bga_screen_line_size, bga_screen_buffer_size;
|
||||
static uint32_t bga_buf_paddr;
|
||||
|
||||
static inline void _bga_write_reg(uint16_t cmd, uint16_t data) {
|
||||
outw(VBE_DISPI_IOPORT_INDEX, cmd);
|
||||
outw(VBE_DISPI_IOPORT_DATA, data);
|
||||
}
|
||||
|
||||
static inline uint16_t _bga_read_reg(uint16_t cmd) {
|
||||
outw(VBE_DISPI_IOPORT_INDEX, cmd);
|
||||
return inw(VBE_DISPI_IOPORT_DATA);
|
||||
}
|
||||
|
||||
static void _bga_set_resolution(uint16_t width, uint16_t height) {
|
||||
_bga_write_reg(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_DISABLED);
|
||||
_bga_write_reg(VBE_DISPI_INDEX_XRES, width);
|
||||
_bga_write_reg(VBE_DISPI_INDEX_YRES, height);
|
||||
_bga_write_reg(VBE_DISPI_INDEX_VIRT_WIDTH, width);
|
||||
_bga_write_reg(VBE_DISPI_INDEX_VIRT_HEIGHT, (uint16_t)height * 2);
|
||||
_bga_write_reg(VBE_DISPI_INDEX_BPP, 32);
|
||||
_bga_write_reg(VBE_DISPI_INDEX_X_OFFSET, 0);
|
||||
_bga_write_reg(VBE_DISPI_INDEX_Y_OFFSET, 0);
|
||||
_bga_write_reg(VBE_DISPI_INDEX_ENABLE,
|
||||
VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED);
|
||||
_bga_write_reg(VBE_DISPI_INDEX_BANK, 0);
|
||||
|
||||
bga_screen_line_size = (uint32_t)width * 4;
|
||||
}
|
||||
|
||||
static void bga_set_resolution(uint32_t width, uint32_t height) {
|
||||
_bga_set_resolution(width, height);
|
||||
bga_screen_width = width;
|
||||
bga_screen_height = height;
|
||||
bga_screen_buffer_size = bga_screen_line_size * height * 2;
|
||||
}
|
||||
|
||||
int bga_ioctl(uintptr_t cmd, uintptr_t arg) {
|
||||
uint32_t y_offset = 0;
|
||||
switch (cmd) {
|
||||
case BGA_GET_HEIGHT:
|
||||
return bga_screen_height;
|
||||
case BGA_GET_WIDTH:
|
||||
return bga_screen_width;
|
||||
case BGA_GET_SCALE:
|
||||
return 1;
|
||||
case BGA_GET_BUFFER:
|
||||
if (arg == 0)
|
||||
return bga_buf_paddr;
|
||||
else
|
||||
return bga_buf_paddr + bga_screen_buffer_size / 2;
|
||||
case BGA_SWAP_BUFFERS:
|
||||
y_offset = bga_screen_height * (arg & 1);
|
||||
_bga_write_reg(VBE_DISPI_INDEX_Y_OFFSET, (uint16_t)y_offset);
|
||||
return 0;
|
||||
case BGA_DISABLE:
|
||||
_bga_write_reg(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_DISABLED);
|
||||
return 0;
|
||||
case BGA_SET_WIDTH:
|
||||
bga_screen_width = arg;
|
||||
return 0;
|
||||
case BGA_SET_HEIGHT:
|
||||
bga_screen_height = arg;
|
||||
return 0;
|
||||
case BGA_SET_UPDATE:
|
||||
bga_set_resolution(bga_screen_width, bga_screen_height);
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int init_bga(pci_dev_t *dev) {
|
||||
if (dev->type != DEVICE_DISPLAY) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bga_buf_paddr = pci_read_bar(dev, 0) & 0xfffffff0;
|
||||
bga_set_resolution(1024, 768);
|
||||
kprintf("bga buf paddr=%p; buf size= %d KB\n", bga_buf_paddr,
|
||||
bga_screen_buffer_size / 1024);
|
||||
kprintf("bga mapped in kernel cr3=%p\n", read_cr3());
|
||||
// for (int k = 0; k < bga_screen_buffer_size; k += 4096) {
|
||||
// klin_mapping_phy(bga_buf_paddr + k, bga_buf_paddr + k,
|
||||
// PG_P | PG_USU | PG_RWW, PG_P | PG_USU | PG_RWW);
|
||||
// }
|
||||
// uint32_t *test = (uint32_t *)bga_buf_paddr;
|
||||
// uint32_t *test2 = (uint32_t *)(bga_buf_paddr + bga_screen_buffer_size / 2);
|
||||
// for (int i = 0; i <= 1024 * 20; ++i) test[i] = 0x00ff12;
|
||||
// for (int i = 1024 * 20; i <= 1024 * 40; ++i) test2[i] = 0x0000ff;
|
||||
// while (1) {
|
||||
// bga_ioctl(BGA_SWAP_BUFFERS, 1);
|
||||
// for (volatile int i = 0; i < 0x03ffffff; ++i)
|
||||
// ;
|
||||
// bga_ioctl(BGA_SWAP_BUFFERS, 0);
|
||||
// for (volatile int i = 0; i < 0x03ffffff; ++i)
|
||||
// ;
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
@ -16,7 +16,7 @@
|
||||
#define INDEX(row, col) ((row)*SCR_WIDTH + (col))
|
||||
|
||||
static char logbuf[CON_MAX_LOGBUF];
|
||||
static CONSOLE con = {
|
||||
static s_console con = {
|
||||
.row = 0,
|
||||
.col = 0,
|
||||
.buf = logbuf,
|
||||
|
||||
@ -141,6 +141,7 @@ static u32 exec_elfcpy(u32 fd, Elf32_Phdr Echo_Phdr, u32 attribute) // 这部分
|
||||
// 已初始化数据段拷贝完毕,剩下的是未初始化的数据段,在内存中填0
|
||||
*((u8 *)lin_addr) = 0; // memset((void*)lin_addr,0,1);
|
||||
}
|
||||
// if (!(lin_addr & 0x3f)) kprintf(".");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -158,6 +159,7 @@ static u32 exec_load(u32 fd, const Elf32_Ehdr *Echo_Ehdr, const Elf32_Phdr Echo_
|
||||
kprintf("\x1b[31;47mexec_load: elf ERROR!\x1b[m", 0x74);
|
||||
return -1;
|
||||
}
|
||||
// kprintf("loading elf from file");
|
||||
|
||||
// 我们还不能确定elf中一共能有几个program,但就目前我们查看过的elf文件中,只出现过两中program,一种.text(R-E)和一种.data(RW-)
|
||||
for (ph_num = 0; ph_num < Echo_Ehdr->e_phnum; ph_num++)
|
||||
@ -186,6 +188,7 @@ static u32 exec_load(u32 fd, const Elf32_Ehdr *Echo_Ehdr, const Elf32_Phdr Echo_
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
// kprintf("[\x1b[32mok\x1b[0m]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
279
kernel/fbcon.c
Normal file
279
kernel/fbcon.c
Normal file
@ -0,0 +1,279 @@
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
|
||||
#ifdef USE_FBCON
|
||||
|
||||
#include "bga.h"
|
||||
#include "console.h"
|
||||
#include "const.h"
|
||||
#include "keyboard.h"
|
||||
#include "memman.h"
|
||||
#include "proc.h"
|
||||
#include "protect.h"
|
||||
#include "serialport.h"
|
||||
#include "spinlock.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "tty.h"
|
||||
#include "type.h"
|
||||
#include "x86.h"
|
||||
#include "fs.h" //added by mingxuan 2019-5-19
|
||||
#include "vfs.h"
|
||||
|
||||
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;
|
||||
static uint32_t* _fb = NULL;
|
||||
static uint32_t* cur_fb = NULL;
|
||||
static volatile int framecnt = 0;
|
||||
static u16* textbuf;
|
||||
char* hzk16h_buf;
|
||||
volatile u32 buflock;
|
||||
static int halfchar;
|
||||
|
||||
#define UNIT_CHAR_H (_fnt_char_height * _fbscale)
|
||||
#define UNIT_CHAR_W (_fnt_char_width * _fbscale)
|
||||
#define INDEX(row, col, mx) ((row) * (mx) + (col))
|
||||
#define HZK16_SIZE (261696)
|
||||
#include "font8x8.h"
|
||||
static void fast_copy(void* dst, void* src, int len);
|
||||
|
||||
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 fbcon_draw_hzk(int row, int col, u16 ch) {
|
||||
u8 code0 = ((ch >> 8) & 0xff);
|
||||
u8 code1 = (ch & 0xff);
|
||||
if (code0 == 0) {fbcon_draw_raw(row, col, code1); return; }
|
||||
else { code0 -= 0xa0; code1 -= 0xa0; }
|
||||
u32 offset = (94 * (code0 - 1) + (code1 - 1)) * 32;
|
||||
u16* hzk16h = (u16*)&hzk16h_buf[offset];
|
||||
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 + (UNIT_CHAR_W - x)) + ((row * UNIT_CHAR_H + y) * _fbpixels_per_row);
|
||||
uint32_t clr = _basecolor;
|
||||
u16 bigend = (hzk16h[y] >> 8) | ((hzk16h[y] & 0xff) << 8);
|
||||
if (bigend & (1 << (x))) {
|
||||
clr ^= 0xffffffff;
|
||||
}
|
||||
cur_fb[ind] = clr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_cursor() {
|
||||
fbcon_draw_raw(cur_row, cur_col, 0);
|
||||
}
|
||||
|
||||
static void draw_cursor_clear() {
|
||||
fbcon_draw_raw(cur_row, cur_col, 1);
|
||||
}
|
||||
|
||||
static void fbcon_scroll() {
|
||||
int lineoffset = _fbwidth * _fnt_char_height * _fbscale * sizeof(*textbuf);
|
||||
fast_copy( (void*)cur_fb,
|
||||
(void*)cur_fb + lineoffset,
|
||||
_fbbufsize - lineoffset);
|
||||
memset((void*)cur_fb + _fbbufsize - lineoffset, 0, lineoffset);
|
||||
}
|
||||
|
||||
static void textbuf_scroll() {
|
||||
memcpy((void*) textbuf, (void*)textbuf + _scr_max_cols *2, (_scr_max_rows-1)*_scr_max_cols * 2);
|
||||
memset((void*)textbuf + (_scr_max_rows-1)*_scr_max_cols*2, ' ', _scr_max_cols*2);
|
||||
}
|
||||
|
||||
static void fbcon_putchar(u8 ch) {
|
||||
if (ch >= 0xa0) {
|
||||
if (halfchar == 0) {
|
||||
textbuf[INDEX(cur_row, cur_col, _scr_max_cols)] = ch << 8;
|
||||
halfchar = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
switch (ch)
|
||||
{
|
||||
case '\n':
|
||||
cur_row ++;
|
||||
cur_col = 0;
|
||||
if (cur_row >= _scr_max_rows) {
|
||||
textbuf_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:
|
||||
if (halfchar) {
|
||||
halfchar = 0;
|
||||
textbuf[INDEX(cur_row, cur_col, _scr_max_cols)] |= ch;
|
||||
}
|
||||
else {
|
||||
textbuf[INDEX(cur_row, cur_col, _scr_max_cols)] = ch;
|
||||
}
|
||||
cur_col ++;
|
||||
if (cur_col >= _scr_max_cols) {
|
||||
cur_col = 0;
|
||||
cur_row ++;
|
||||
}
|
||||
|
||||
if (cur_row >= _scr_max_rows) {
|
||||
textbuf_scroll();
|
||||
cur_row --;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void fbcon_clear_screen() {
|
||||
for (int i = 0; i < _scr_max_cols * _scr_max_rows; ++ i) {
|
||||
textbuf[i] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
void fbcon_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;
|
||||
_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;
|
||||
framecnt = 0;
|
||||
kprintf("allocating screen res for %dx%d...\n", _scr_max_rows, _scr_max_cols);
|
||||
textbuf = (u16*)K_PHY2LIN(sys_kmalloc(_scr_max_cols * _scr_max_rows * sizeof(*textbuf))); // alloc double for later use
|
||||
fbcon_clear_screen();
|
||||
// memset(textbuf, ' ', _scr_max_cols * _scr_max_rows);
|
||||
hzk16h_buf = (char*)K_PHY2LIN(sys_kmalloc(HZK16_SIZE));
|
||||
halfchar = 0;
|
||||
kprintf("bufsz = %p, maxsize(%d, %d) textbuf=%p, fontbuf=%p\n", _fbbufsize, _scr_max_rows, _scr_max_cols, textbuf, hzk16h_buf);
|
||||
}
|
||||
|
||||
|
||||
static void do_fbcon_write(char* buf, int nr) {
|
||||
disable_int();
|
||||
while (nr--) {
|
||||
fbcon_putchar(*buf++);
|
||||
}
|
||||
enable_int();
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
static void textbuf_render() {
|
||||
for (int row = 0; row < _scr_max_rows; ++ row) {
|
||||
for (int col = 0; col < _scr_max_cols; ++ col) {
|
||||
fbcon_draw_hzk(row, col, textbuf[INDEX(row, col, _scr_max_cols)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void fbcon_switchfont() {
|
||||
while (xchg(&buflock, 1) == 1)
|
||||
yield();
|
||||
_fbscale = 1;
|
||||
xchg(&buflock, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
void task_tty() {
|
||||
#ifdef USE_FBCON
|
||||
// main rountine for drawing framebuffered console
|
||||
mmap((u32)_fb, _fb_paddr, _fbwidth * _fbheight * 4 * 2);
|
||||
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();
|
||||
textbuf_render();
|
||||
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
|
||||
}
|
||||
#else
|
||||
while(1) yield();
|
||||
#endif
|
||||
}
|
||||
@ -13,6 +13,7 @@
|
||||
#include "fs_misc.h"
|
||||
#include "stdio.h"
|
||||
#include "assert.h"
|
||||
#include "x86.h"
|
||||
|
||||
// added by xw, 18/8/28
|
||||
/* data */
|
||||
@ -385,13 +386,13 @@ int real_open(const char *pathname, int flags) // modified by mingxuan 2019-5-17
|
||||
{
|
||||
// added by xw, 18/8/27
|
||||
MESSAGE fs_msg;
|
||||
|
||||
disable_int();
|
||||
fs_msg.type = OPEN;
|
||||
fs_msg.PATHNAME = (void *)pathname;
|
||||
fs_msg.FLAGS = flags;
|
||||
fs_msg.NAME_LEN = strlen(pathname);
|
||||
fs_msg.source = proc2pid(p_proc_current);
|
||||
|
||||
enable_int();
|
||||
int fd = do_open(&fs_msg);
|
||||
|
||||
return fd;
|
||||
@ -417,7 +418,7 @@ static int do_open(MESSAGE *fs_msg)
|
||||
int flags = fs_msg->FLAGS; /* access mode */
|
||||
int name_len = fs_msg->NAME_LEN; /* length of filename */
|
||||
int src = fs_msg->source; /* caller proc nr. */
|
||||
|
||||
disable_int();
|
||||
memcpy((void *)va2la(src, pathname), (void *)va2la(src, fs_msg->PATHNAME), name_len);
|
||||
pathname[name_len] = 0;
|
||||
|
||||
@ -441,7 +442,7 @@ static int do_open(MESSAGE *fs_msg)
|
||||
break;
|
||||
|
||||
assert(i < NR_FILE_DESC);
|
||||
|
||||
enable_int();
|
||||
int inode_nr = search_file(pathname);
|
||||
struct inode *pin = 0;
|
||||
if (flags & O_CREAT)
|
||||
|
||||
@ -76,5 +76,7 @@ system_call sys_call_table[NR_SYS_CALL] = {
|
||||
sys_delete, // added by mingxuan 2019-5-17
|
||||
sys_opendir, // added by mingxuan 2019-5-17
|
||||
sys_createdir, // added by mingxuan 2019-5-17
|
||||
sys_deletedir // added by mingxuan 2019-5-17
|
||||
sys_deletedir, // added by mingxuan 2019-5-17
|
||||
sys_mmap,
|
||||
};
|
||||
|
||||
|
||||
@ -370,6 +370,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 +387,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 +397,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;
|
||||
}
|
||||
xchg(&kbdlock, 0);
|
||||
sys_yield();
|
||||
}
|
||||
assert(kbd->buf);
|
||||
u8 *ibuf = kbd->buf;
|
||||
@ -411,7 +417,7 @@ int ps2_tty_read(NTTY *tty, char *buf, int nr)
|
||||
}
|
||||
kbd->readable -= i;
|
||||
kbd->len -= i;
|
||||
enable_int();
|
||||
xchg(&kbdlock, 0);
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -427,7 +433,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 +487,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);
|
||||
xchg(&kbdlock, 0);
|
||||
// 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 +509,25 @@ void ps2_tty_recvbuf(NTTY *tty, u32 key)
|
||||
kbd->len--;
|
||||
kbd->tail = LASTKEY(kbd->tail);
|
||||
}
|
||||
xchg(&kbdlock, 0);
|
||||
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);
|
||||
xchg(&kbdlock, 0);
|
||||
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();
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include "fs.h"
|
||||
#include "vfs.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
|
||||
/**
|
||||
* @struct posix_tar_header
|
||||
@ -112,6 +113,8 @@ static void untar(const char *filename)
|
||||
|
||||
printf(" done, %d files extracted]\n", i);
|
||||
}
|
||||
extern char* hzk16h_buf;
|
||||
#define HZK16_SIZE (261696)
|
||||
|
||||
void initial()
|
||||
{
|
||||
@ -127,13 +130,31 @@ void initial()
|
||||
printf("untar:%s\n", full_name);
|
||||
strcat(full_name, INSTALL_FILENAME);
|
||||
untar(full_name);
|
||||
#ifdef USE_FBCON
|
||||
|
||||
kprintf("loading font(%dKB) to %p...", HZK16_SIZE / num_1K, hzk16h_buf);
|
||||
printf("Loading Font HZK16H...\n");
|
||||
int fd = do_vopen("orange/hzk16h", O_RDWR);
|
||||
do_vlseek(fd, 0, SEEK_SET);
|
||||
for (int i = 0; i < HZK16_SIZE/64; ++ i)
|
||||
{
|
||||
do_vread(fd, hzk16h_buf + i * 64, 64);
|
||||
if (i % 50 == 0) kprintf(".");
|
||||
}
|
||||
if (hzk16h_buf[0x54] != 0x30) kprintf("Font Loading Failed\n");
|
||||
do_vclose(fd);
|
||||
kprintf("[\x1b[32mOK\x1b[0m]\n");
|
||||
printf("Font loaded.\n");
|
||||
printf("Loaing Simple Shell...\n");
|
||||
#endif
|
||||
do_vclose(stdin);
|
||||
do_vclose(stdout);
|
||||
do_vclose(stderr);
|
||||
|
||||
#ifdef USE_FBCON
|
||||
exec("orange/shell_chn.bin");
|
||||
#else
|
||||
exec("orange/shell_1.bin");
|
||||
|
||||
#endif
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
@ -23,6 +23,8 @@
|
||||
#include "stdio.h"
|
||||
#include "tty.h"
|
||||
#include "serialport.h"
|
||||
#include "bga.h"
|
||||
#include "pci.h"
|
||||
|
||||
static int initialize_processes(); // added by xw, 18/5/26
|
||||
static int initialize_cpus(); // added by xw, 18/6/2
|
||||
@ -33,7 +35,6 @@ static int initialize_cpus(); // added by xw, 18/6/2
|
||||
int kernel_main()
|
||||
{
|
||||
clear_kernel_pagepte_low();
|
||||
|
||||
init_serial();
|
||||
int error;
|
||||
|
||||
@ -44,6 +45,7 @@ int kernel_main()
|
||||
|
||||
init(); // 内存管理模块的初始化 add by liang
|
||||
init_tty_main();
|
||||
|
||||
// initialize PCBs, added by xw, 18/5/26
|
||||
error = initialize_processes();
|
||||
if (error != 0)
|
||||
@ -96,7 +98,12 @@ int kernel_main()
|
||||
init_fs();
|
||||
init_fs_fat(); // added by mingxuan 2019-5-17
|
||||
// init_vfs(); //added by mingxuan 2019-5-17 //deleted by mingxuan 2020-10-30
|
||||
|
||||
#ifdef USE_FBCON
|
||||
init_pci();
|
||||
pci_dev_t* dev_bga = get_pci_bga();
|
||||
init_bga(dev_bga);
|
||||
fbcon_screen_setup();
|
||||
#endif
|
||||
/*************************************************************************
|
||||
*第一个进程开始启动执行
|
||||
**************************************************************************/
|
||||
@ -169,18 +176,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
|
||||
|
||||
@ -341,3 +341,85 @@ void clear_kernel_pagepte_low()
|
||||
memset((void *)(K_PHY2LIN(KernelPageTblAddr + 0x1000)), 0, 4096 * page_num); // 从内核页表中清除线性地址的低端映射关系
|
||||
refresh_page_cache();
|
||||
}
|
||||
|
||||
int klin_mapping_phy(u32 AddrLin, // 线性地址
|
||||
u32 phy_addr, // 物理地址,若为MAX_UNSIGNED_INT(0xFFFFFFFF),则表示需要由该函数判断是否分配物理地址,否则将phy_addr直接和AddrLin建立映射
|
||||
u32 pde_Attribute, // 页目录中的属性位
|
||||
u32 pte_Attribute) // 页表中的属性位
|
||||
{
|
||||
u32 pte_addr_phy;
|
||||
u32 pde_addr_phy = read_cr3(); // add by visual 2016.5.19
|
||||
|
||||
if (0 == pte_exist(pde_addr_phy, AddrLin))
|
||||
{ // 页表不存在,创建一个,并填进页目录中
|
||||
pte_addr_phy = (u32)do_kmalloc_4k(); // 为页表申请一页
|
||||
memset((void *)K_PHY2LIN(pte_addr_phy), 0, num_4K); // add by visual 2016.5.26
|
||||
|
||||
if (pte_addr_phy < 0 || (pte_addr_phy & 0x3FF) != 0) // add by visual 2016.5.9
|
||||
{
|
||||
kprintf("\x1b[31;47mlin_mapping_phy Error:pte_addr_phy\x1b[m");
|
||||
return -1;
|
||||
}
|
||||
|
||||
write_page_pde(pde_addr_phy, // 页目录物理地址
|
||||
AddrLin, // 线性地址
|
||||
pte_addr_phy, // 页表物理地址
|
||||
pde_Attribute); // 属性
|
||||
}
|
||||
else
|
||||
{ // 页表存在,获取该页表物理地址
|
||||
pte_addr_phy = (*((u32 *)K_PHY2LIN(read_cr3()) + get_pde_index(AddrLin))) & 0xFFFFF000;
|
||||
}
|
||||
|
||||
if (MAX_UNSIGNED_INT == phy_addr) // add by visual 2016.5.19
|
||||
{ // 由函数申请内存
|
||||
if (0 == phy_exist(pte_addr_phy, AddrLin))
|
||||
{ // 无物理页,申请物理页并修改phy_addr
|
||||
if (AddrLin >= K_PHY2LIN(0))
|
||||
phy_addr = do_kmalloc_4k(); // 从内核物理地址申请一页
|
||||
else
|
||||
{
|
||||
phy_addr = do_malloc_4k(); // 从用户物理地址空间申请一页
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 有物理页,什么也不做,直接返回,必须返回
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // 指定填写phy_addr
|
||||
// 不用修改phy_addr
|
||||
}
|
||||
|
||||
if (phy_addr < 0 || (phy_addr & 0x3FF) != 0)
|
||||
{
|
||||
kprintf("\x1b[31;47mlin_mapping_phy:phy_addr ERROR\x1b[m");
|
||||
return -1;
|
||||
}
|
||||
|
||||
write_page_pte(pte_addr_phy, // 页表物理地址
|
||||
AddrLin, // 线性地址
|
||||
phy_addr, // 物理页物理地址
|
||||
pte_Attribute); // 属性
|
||||
refresh_page_cache();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_mmap(void *uesp)
|
||||
{
|
||||
disable_int();
|
||||
uintptr_t linaddr = get_arg(uesp, 1);
|
||||
uintptr_t phyaddr = get_arg(uesp, 2);
|
||||
size_t mapsize = get_arg(uesp, 3);
|
||||
mapsize = mapsize % num_4K == 0 ? mapsize : (mapsize / num_4K + 1) * num_4K;
|
||||
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);
|
||||
}
|
||||
enable_int();
|
||||
return 0;
|
||||
}
|
||||
174
kernel/pci.c
Normal file
174
kernel/pci.c
Normal file
@ -0,0 +1,174 @@
|
||||
#include "type.h"
|
||||
#include "assert.h"
|
||||
#include "console.h"
|
||||
#include "const.h"
|
||||
#include "keyboard.h"
|
||||
#include "memman.h"
|
||||
#include "proc.h"
|
||||
#include "protect.h"
|
||||
#include "proto.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "x86.h"
|
||||
#include "global.h"
|
||||
#include "tty.h"
|
||||
#include "pci.h"
|
||||
|
||||
/*
|
||||
* Copyright (C) 2020-2022 The opuntiaOS Project Authors.
|
||||
* + Contributed by Nikita Melekhin <nimelehin@gmail.com>
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#define DEBUG_PCI
|
||||
|
||||
pci_dev_t pci_devs[NR_PCI_DEV];
|
||||
|
||||
static uint32_t _pci_do_read_bar(uint8_t bus, uint8_t device, uint8_t function,
|
||||
uint8_t bar_id) {
|
||||
uint32_t header_type = pci_read(bus, device, function, 0x0e) & 0x7f;
|
||||
uint8_t max_bars = 6 - (header_type * 4);
|
||||
if (bar_id >= max_bars) return 0;
|
||||
uint32_t bar_val = pci_read(bus, device, function, 0x10 + 4 * bar_id);
|
||||
return bar_val;
|
||||
}
|
||||
|
||||
static bar_t _pci_get_bar(uint8_t bus, uint8_t device, uint8_t function,
|
||||
uint8_t bar_id) {
|
||||
bar_t result;
|
||||
|
||||
uint32_t bar_val = _pci_do_read_bar(bus, device, function, bar_id);
|
||||
result.type = (bar_val & 0x1) ? INPUT_OUTPUT : MEMORY_MAPPED;
|
||||
|
||||
if (result.type == MEMORY_MAPPED) {
|
||||
} else {
|
||||
result.address = (uint32_t)((bar_val >> 2) << 2);
|
||||
result.prefetchable = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t pci_read(uint16_t bus, uint16_t device, uint16_t function,
|
||||
uint32_t offset) {
|
||||
uint32_t id = (0x1 << 31) | ((bus & 0xFF) << 16) | ((device & 0x1F) << 11) |
|
||||
((function & 0x07) << 8) | (offset & 0xFC);
|
||||
outl(0xCF8, id);
|
||||
uint32_t tmp = (uint32_t)(inl(0xCFC) >> (8 * (offset % 4)));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void pci_write(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset,
|
||||
uint32_t data) {
|
||||
uint32_t bus32 = bus;
|
||||
uint32_t device32 = device;
|
||||
uint16_t function16 = function;
|
||||
uint32_t address = (1 << 31) | (bus32 << 16) | (device32 << 11) |
|
||||
(function16 << 8) | (offset & 0xFC);
|
||||
outl(0xCF8, address);
|
||||
outl(0xCFC, data);
|
||||
}
|
||||
|
||||
static int dev_type_by_class(pci_dev_t* dd) {
|
||||
switch (dd->class_id) {
|
||||
case 0x1:
|
||||
switch (dd->subclass_id) {
|
||||
case 0x1:
|
||||
case 0x3:
|
||||
case 0x4:
|
||||
return DEVICE_BUS_CONTROLLER;
|
||||
default:
|
||||
return DEVICE_STORAGE;
|
||||
}
|
||||
case 0x2:
|
||||
return DEVICE_NETWORK;
|
||||
case 0x3:
|
||||
return DEVICE_DISPLAY;
|
||||
case 0x6:
|
||||
return DEVICE_BRIDGE;
|
||||
default:
|
||||
#ifdef DEBUG_PCI
|
||||
kprintf("PCI: DEVICE_UNKNOWN: Class %d subclass %d", dd->class_id,
|
||||
dd->subclass_id);
|
||||
#endif
|
||||
return DEVICE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
static char pci_has_device_functions(uint8_t bus, uint8_t device) {
|
||||
return pci_read(bus, device, 0, 0x0e) & (1 << 7);
|
||||
}
|
||||
|
||||
int pci_find_devices() {
|
||||
#ifdef DEBUG_PCI
|
||||
kprintf("PCI: scanning\n");
|
||||
#endif
|
||||
uint8_t bus, device, function;
|
||||
int count = 0;
|
||||
for (bus = 0; bus < 8; bus++) {
|
||||
for (device = 0; device < 32; device++) {
|
||||
uint8_t functions_count =
|
||||
pci_has_device_functions(bus, device) == 0 ? 8 : 1;
|
||||
for (function = 0; function < functions_count; function++) {
|
||||
pci_dev_t dev =
|
||||
pci_get_device_desriptor(bus, device, function);
|
||||
if (dev.vendor_id == 0x0000 || dev.vendor_id == 0xffff) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (uint8_t bar_id = 0; bar_id < 6; bar_id++) {
|
||||
bar_t bar = _pci_get_bar(bus, device, function, bar_id);
|
||||
if (bar.address && (bar.type == INPUT_OUTPUT)) {
|
||||
dev.port_base = (uint32_t)bar.address;
|
||||
}
|
||||
}
|
||||
dev.type = dev_type_by_class(&dev);
|
||||
pci_devs[count ++] = dev;
|
||||
#ifdef DEBUG_PCI
|
||||
kprintf("PCI: Vendor %x, devID %x, cl %x scl %x\n",
|
||||
dev.vendor_id, dev.device_id, dev.class_id,
|
||||
dev.subclass_id);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pci_dev_t pci_get_device_desriptor(uint8_t bus, uint8_t device,
|
||||
uint8_t function) {
|
||||
pci_dev_t new_device = {0};
|
||||
|
||||
new_device.bus = bus;
|
||||
new_device.device = device;
|
||||
new_device.function = function;
|
||||
|
||||
new_device.vendor_id = pci_read(bus, device, function, 0x00);
|
||||
new_device.device_id = pci_read(bus, device, function, 0x02);
|
||||
|
||||
new_device.class_id = pci_read(bus, device, function, 0x0b);
|
||||
new_device.subclass_id = pci_read(bus, device, function, 0x0a);
|
||||
new_device.interface_id = pci_read(bus, device, function, 0x09);
|
||||
new_device.revision_id = pci_read(bus, device, function, 0x08);
|
||||
|
||||
new_device.interrupt = pci_read(bus, device, function, 0x3c);
|
||||
|
||||
return new_device;
|
||||
}
|
||||
|
||||
uint32_t pci_read_bar(pci_dev_t* pci_dev, int bar_id) {
|
||||
return _pci_do_read_bar(pci_dev->bus, pci_dev->device, pci_dev->function,
|
||||
bar_id);
|
||||
}
|
||||
|
||||
void init_pci() { pci_find_devices(); }
|
||||
|
||||
pci_dev_t* get_pci_bga()
|
||||
{
|
||||
for (int i = 0; i < NR_PCI_DEV; ++ i) {
|
||||
if (pci_devs[i].type == DEVICE_DISPLAY) return &pci_devs[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -12,6 +12,7 @@
|
||||
#include "proc.h"
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
#include "stdio.h"
|
||||
|
||||
/*======================================================================*
|
||||
schedule
|
||||
@ -19,8 +20,17 @@
|
||||
void schedule()
|
||||
{
|
||||
PROCESS* p;
|
||||
int greatest_ticks = 0;
|
||||
#ifdef USE_FBCON
|
||||
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;
|
||||
#else
|
||||
|
||||
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
|
||||
@ -48,6 +58,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*======================================================================*
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -35,6 +35,7 @@ _NR_delete equ 22 ; //added by mingxuan 2019-5-17
|
||||
_NR_opendir equ 23 ; //added by mingxuan 2019-5-17
|
||||
_NR_createdir equ 24 ; //added by mingxuan 2019-5-17
|
||||
_NR_deletedir equ 25 ; //added by mingxuan 2019-5-17
|
||||
_NR_mmap equ 26 ;
|
||||
|
||||
INT_VECTOR_SYS_CALL equ 0x90
|
||||
|
||||
@ -67,6 +68,7 @@ global delete ; //added by mingxuan 2019-5-17
|
||||
global opendir ; //added by mingxuan 2019-5-17
|
||||
global createdir ; //added by mingxuan 2019-5-17
|
||||
global deletedir ; //added by mingxuan 2019-5-17
|
||||
global mmap
|
||||
|
||||
bits 32
|
||||
[section .text]
|
||||
@ -111,13 +113,13 @@ get_pid:
|
||||
; ; ====================================================================
|
||||
; ; malloc //add by visual 2016.4.7
|
||||
; ; ====================================================================
|
||||
; malloc:
|
||||
; push ebx
|
||||
; mov ebx,[esp+4] ; 将C函数调用时传来的参数放到ebx里!!111
|
||||
; mov eax, _NR_malloc
|
||||
; int INT_VECTOR_SYS_CALL
|
||||
; pop ebx
|
||||
; ret
|
||||
malloc:
|
||||
push ebx
|
||||
mov ebx, esp ; 将C函数调用时传来的参数放到ebx里!!111
|
||||
mov eax, _NR_malloc
|
||||
int INT_VECTOR_SYS_CALL
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
; ; ====================================================================
|
||||
; ; malloc_4k //add by visual 2016.4.7
|
||||
@ -334,3 +336,11 @@ deletedir:
|
||||
int INT_VECTOR_SYS_CALL
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
mmap:
|
||||
push ebx
|
||||
mov ebx, esp
|
||||
mov eax, _NR_mmap
|
||||
int INT_VECTOR_SYS_CALL
|
||||
pop ebx
|
||||
ret
|
||||
@ -51,19 +51,19 @@ void *sys_kmalloc_4k()
|
||||
/*======================================================================*
|
||||
sys_malloc edit by visual 2016.5.4
|
||||
*======================================================================*/
|
||||
void *sys_malloc(int size)
|
||||
void *sys_malloc(void* uesp)
|
||||
{
|
||||
int vir_addr, AddrLin;
|
||||
vir_addr = vmalloc(size);
|
||||
// int vir_addr, AddrLin;
|
||||
void* vir_addr = K_PHY2LIN(sys_kmalloc(get_arg(uesp, 1)));
|
||||
|
||||
for (AddrLin = vir_addr; AddrLin < vir_addr + size; AddrLin += num_4B) // 一个字节一个字节处理
|
||||
{
|
||||
lin_mapping_phy(AddrLin, // 线性地址 //add by visual 2016.5.9
|
||||
MAX_UNSIGNED_INT, // 物理地址 //edit by visual 2016.5.19
|
||||
p_proc_current->task.pid, // 进程pid //edit by visual 2016.5.19
|
||||
PG_P | PG_USU | PG_RWW, // 页目录的属性位
|
||||
PG_P | PG_USU | PG_RWW); // 页表的属性位
|
||||
}
|
||||
// for (AddrLin = vir_addr; AddrLin < vir_addr + size; AddrLin += num_4B) // 一个字节一个字节处理
|
||||
// {
|
||||
// lin_mapping_phy(AddrLin, // 线性地址 //add by visual 2016.5.9
|
||||
// MAX_UNSIGNED_INT, // 物理地址 //edit by visual 2016.5.19
|
||||
// p_proc_current->task.pid, // 进程pid //edit by visual 2016.5.19
|
||||
// PG_P | PG_USU | PG_RWW, // 页目录的属性位
|
||||
// PG_P | PG_USU | PG_RWW); // 页表的属性位
|
||||
// }
|
||||
return (void *)vir_addr;
|
||||
}
|
||||
|
||||
|
||||
46
kernel/tty.c
46
kernel/tty.c
@ -12,6 +12,7 @@
|
||||
#include "memman.h"
|
||||
#include "stdio.h"
|
||||
#include "serialport.h"
|
||||
#include "bga.h"
|
||||
|
||||
int tty_ok = 0;
|
||||
void tty_write(NTTY *tty, char *buf, int len);
|
||||
@ -61,7 +62,34 @@ 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*)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
||||
tty->driver_type = 1;
|
||||
#ifdef USE_FBCON
|
||||
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;
|
||||
#else
|
||||
tty = (NTTY*)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
||||
tty->driver_type = 1;
|
||||
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);
|
||||
tty->write = vga_tty_write;
|
||||
tty->read = ps2_tty_read;
|
||||
tty->recvbuf = ps2_tty_recvbuf;
|
||||
tty->ioctl = ps2_vga_ioctl;
|
||||
#endif
|
||||
ntty_table[i] = tty;
|
||||
}
|
||||
for (int i = 1; i < 2; ++i)
|
||||
{
|
||||
// tty = &ntty_table[i];
|
||||
tty = (NTTY *)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
||||
@ -98,22 +126,6 @@ void init_tty_main()
|
||||
kprintf("TTY initialized\n");
|
||||
}
|
||||
|
||||
void task_tty()
|
||||
{
|
||||
// NTTY* p_tty;
|
||||
// for (p_tty = ntty_table; p_tty < ntty_table + 3; ++ p_tty) {
|
||||
// init_ntty(p_tty);
|
||||
// }
|
||||
volatile char serial_input;
|
||||
while (1)
|
||||
{
|
||||
yield();
|
||||
// vga_tty_flush(cur_ntty);
|
||||
// serial_input = read_serial();
|
||||
// vga_tty_write(get_tty(2), serial_input);
|
||||
// kprintf("%c", serial_input);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* tty_write
|
||||
|
||||
11
kernel/vfs.c
11
kernel/vfs.c
@ -16,6 +16,7 @@
|
||||
#include "vfs.h"
|
||||
#include "fat32.h"
|
||||
#include "stdio.h"
|
||||
#include "x86.h"
|
||||
|
||||
// static struct device device_table[NR_DEV]; //deleted by mingxuan 2020-10-18
|
||||
static struct vfs vfs_table[NR_FS]; // modified by mingxuan 2020-10-18
|
||||
@ -35,10 +36,10 @@ void init_super_block_table(); // added by mingxuan 2020-10-30
|
||||
void init_sb_op_table();
|
||||
|
||||
static int get_index(char path[]);
|
||||
|
||||
static volatile u32 openlock;
|
||||
void init_vfs()
|
||||
{
|
||||
|
||||
openlock = 0;
|
||||
init_file_desc_table();
|
||||
init_fileop_table();
|
||||
|
||||
@ -283,7 +284,8 @@ int sys_deletedir(void *uesp)
|
||||
|
||||
int do_vopen(const char *path, int flags)
|
||||
{
|
||||
|
||||
while(xchg(&openlock, 1) == 1)
|
||||
;
|
||||
int pathlen = strlen(path);
|
||||
char pathname[MAX_PATH];
|
||||
|
||||
@ -296,6 +298,7 @@ int do_vopen(const char *path, int flags)
|
||||
if (index == -1)
|
||||
{
|
||||
kprintf("pathname error! path: %s\n", path);
|
||||
xchg(&openlock, 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -308,7 +311,7 @@ int do_vopen(const char *path, int flags)
|
||||
{
|
||||
kprintf("open %s error!\n", path);
|
||||
}
|
||||
|
||||
xchg(&openlock, 0);
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
@ -9,8 +9,10 @@
|
||||
static void kprintfputch(int ch, int *cnt)
|
||||
{
|
||||
// write_serial(ch);
|
||||
#ifndef USE_FBCON
|
||||
char _ch = ch;
|
||||
tty_write(cur_ntty, &_ch, 1);
|
||||
#endif
|
||||
(*cnt)++;
|
||||
}
|
||||
|
||||
|
||||
@ -11,7 +11,14 @@ USER_SRCS := user/shell_1.c \
|
||||
user/test.c \
|
||||
user/test2.c \
|
||||
user/sgr_test.c \
|
||||
user/cur_test.c
|
||||
user/cur_test.c \
|
||||
user/shell_2con.c \
|
||||
user/shell_chn.c \
|
||||
user/shell_mix.c \
|
||||
user/shell_uart.c \
|
||||
user/test2con.c \
|
||||
user/testchn.c \
|
||||
user/testscr.c \
|
||||
|
||||
USER_BINS := $(patsubst %.c, $(OBJDIR)/%.bin, $(USER_SRCS))
|
||||
USER_BASENAMES := $(patsubst $(OBJDIR)/user/%, %, $(USER_BINS))
|
||||
@ -34,4 +41,5 @@ $(OBJDIR)/user/%.bin: $(OBJDIR)/user/%.o $(USERLIB_OBJS) $(LIB_A) $(OBJDIR)/.var
|
||||
|
||||
$(OBJDIR)/user/$(USER_TAR): $(USER_BINS)
|
||||
@echo + tar $@
|
||||
@tar -vcf $@ -C $(OBJDIR)/user $(USER_BASENAMES)
|
||||
@cp -f user/hzk16h $(OBJDIR)/user/
|
||||
@tar -vcf $@ -C $(OBJDIR)/user $(USER_BASENAMES) hzk16h
|
||||
BIN
user/hzk16h
Normal file
BIN
user/hzk16h
Normal file
Binary file not shown.
@ -1,41 +0,0 @@
|
||||
#include "stdio.h"
|
||||
|
||||
int global=0;
|
||||
|
||||
char *str2,*str3;
|
||||
|
||||
|
||||
void pthread_test1()
|
||||
{
|
||||
int i;
|
||||
//pthread(pthread_test2);
|
||||
while(1)
|
||||
{
|
||||
printf("pth1");
|
||||
printf("%d",++global);
|
||||
printf(" ");
|
||||
i=10000000;
|
||||
while(--i){}
|
||||
}
|
||||
}
|
||||
|
||||
/*======================================================================*
|
||||
Syscall Pthread Test
|
||||
added by xw, 18/4/27
|
||||
*======================================================================*/
|
||||
|
||||
int main(int arg,char *argv[])
|
||||
{
|
||||
int i=0;
|
||||
|
||||
pthread(pthread_test1);
|
||||
while(1)
|
||||
{
|
||||
printf("init");
|
||||
printf("%d",++global);
|
||||
printf(" ");
|
||||
i=10000000;
|
||||
while(--i){}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
54
user/shell_2con.c
Normal file
54
user/shell_2con.c
Normal file
@ -0,0 +1,54 @@
|
||||
#include "type.h"
|
||||
#include "const.h"
|
||||
#include "protect.h"
|
||||
#include "string.h"
|
||||
#include "proc.h"
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
#include "stdio.h"
|
||||
|
||||
int main(int arg, char *argv[])
|
||||
{
|
||||
if (0 == fork()) {
|
||||
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;
|
||||
int times = 0;
|
||||
while (1)
|
||||
{
|
||||
printf("\nminiOS:/ $ ");
|
||||
if (gets(buf) && strlen(buf) != 0)
|
||||
{
|
||||
if (exec(buf) != 0)
|
||||
{
|
||||
printf("exec failed: file not found!\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
int stdin = open("dev_tty1", O_RDWR);
|
||||
int stdout = open("dev_tty1", O_RDWR);
|
||||
int stderr = open("dev_tty1", O_RDWR);
|
||||
|
||||
char buf[1024];
|
||||
int pid;
|
||||
int times = 0;
|
||||
while (1)
|
||||
{
|
||||
printf("\nminiOS:/ $ ");
|
||||
if (gets(buf) && strlen(buf) != 0)
|
||||
{
|
||||
if (exec(buf) != 0)
|
||||
{
|
||||
printf("exec failed: file not found!\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
user/shell_chn.c
Normal file
33
user/shell_chn.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include "type.h"
|
||||
#include "const.h"
|
||||
#include "protect.h"
|
||||
#include "string.h"
|
||||
#include "proc.h"
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
#include "stdio.h"
|
||||
|
||||
int main(int arg, char *argv[])
|
||||
{
|
||||
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;
|
||||
int times = 0;
|
||||
printf("操作系统加载完成\n欢迎使用\n");
|
||||
printf("\n");
|
||||
while (1)
|
||||
{
|
||||
printf("试点班OS:/ $ ");
|
||||
if (gets(buf) && strlen(buf) != 0)
|
||||
{
|
||||
if (exec(buf) != 0)
|
||||
{
|
||||
printf("exec failed: file not found!\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
user/shell_mix.c
Normal file
31
user/shell_mix.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include "type.h"
|
||||
#include "const.h"
|
||||
#include "protect.h"
|
||||
#include "string.h"
|
||||
#include "proc.h"
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
#include "stdio.h"
|
||||
|
||||
int main(int arg, char *argv[])
|
||||
{
|
||||
int stdin = open("dev_tty2", O_RDWR);
|
||||
int stdout = open("dev_tty0", O_RDWR);
|
||||
int stderr = open("dev_tty0", O_RDWR);
|
||||
|
||||
char buf[1024];
|
||||
int pid;
|
||||
int times = 0;
|
||||
while (1)
|
||||
{
|
||||
printf("miniOS:/ $ ");
|
||||
if (gets(buf) && strlen(buf) != 0)
|
||||
{
|
||||
if (exec(buf) != 0)
|
||||
{
|
||||
printf("exec failed: file not found!\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
user/shell_uart.c
Normal file
31
user/shell_uart.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include "type.h"
|
||||
#include "const.h"
|
||||
#include "protect.h"
|
||||
#include "string.h"
|
||||
#include "proc.h"
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
#include "stdio.h"
|
||||
|
||||
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);
|
||||
|
||||
char buf[1024];
|
||||
int pid;
|
||||
int times = 0;
|
||||
while (1)
|
||||
{
|
||||
printf("\nminiOS:/ $ ");
|
||||
if (gets(buf) && strlen(buf) != 0)
|
||||
{
|
||||
if (exec(buf) != 0)
|
||||
{
|
||||
printf("exec failed: file not found!\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
40
user/test2con.c
Normal file
40
user/test2con.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include "type.h"
|
||||
#include "const.h"
|
||||
#include "protect.h"
|
||||
#include "string.h"
|
||||
#include "proc.h"
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
#include "stdio.h"
|
||||
|
||||
int main(int arg, char *argv[])
|
||||
{
|
||||
int pid = fork();
|
||||
volatile int i;
|
||||
if (pid == 0) {
|
||||
int stdin = open("dev_tty0", O_RDWR);
|
||||
int stdout = open("dev_tty0", O_RDWR);
|
||||
int stderr = open("dev_tty0", O_RDWR);
|
||||
|
||||
while(1) {
|
||||
printf("\x1b[32;40mAAA ");
|
||||
i=100000000;
|
||||
while(--i);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int stdin = open("dev_tty1", O_RDWR);
|
||||
int stdout = open("dev_tty1", O_RDWR);
|
||||
int stderr = open("dev_tty1", O_RDWR);
|
||||
|
||||
while(1) {
|
||||
char* s = "\x1b[33;40mBBB ";
|
||||
for (char* p = s; *p != 0; p++ ){
|
||||
write(stdout, p, 1);
|
||||
}
|
||||
i=100000000;
|
||||
while(--i);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
30
user/testchn.c
Normal file
30
user/testchn.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include "type.h"
|
||||
#include "const.h"
|
||||
#include "protect.h"
|
||||
#include "string.h"
|
||||
#include "proc.h"
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
#include "stdio.h"
|
||||
|
||||
|
||||
int main(int arg, char *argv[])
|
||||
{
|
||||
int stdin = open("dev_tty0", O_RDWR);
|
||||
int stdout = open("dev_tty0", O_RDWR);
|
||||
int stderr = open("dev_tty0", O_RDWR);
|
||||
|
||||
char testtext[] = "\n 你们有一个好,全世界跑到什么地方,你们比其他的西方记者啊跑得还快。但是呢问来问去的问题啊,都 too simple,啊,sometimes naive!懂了没啊?\n";
|
||||
char testtext2[] = "\n 我今天是作为一个长者跟你们讲这个。我不是新闻工作者,但是我见得太多了,我有这个必要告诉你们一点,人生的经验。\n\n I'm angry!我跟你们讲,你们这样子啊是不行的!\n";
|
||||
char testtext3[] = "\n 那么人呐就都不知道,自己就不可以预料。你一个人的命运啊,当然要靠自我奋斗,但是也要考虑到历史的行程,我绝对不知道,我作为一个上海市委书记怎么把我选到北京去了,所以邓小平同志跟我讲话,说“中央都决定啦,你来当总书记”,我说另请高明吧。我实在我也不是谦虚,我一个上海市委书记怎么到北京来了呢?但是呢,小平同志讲“大家已经研究决定了”,所以后来我就念了两首诗,叫“苟利国家生死以,岂因祸福避趋之”。\n";
|
||||
char testtext4[] = "\n 苟利国家生死以,\n 岂因祸福避趋之。\n";
|
||||
printf(testtext);
|
||||
printf(testtext2);
|
||||
printf(testtext3);
|
||||
for (int i = 0; i < 5; ++ i) {
|
||||
printf(testtext4);
|
||||
}
|
||||
while (1)
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
29
user/testscr.c
Normal file
29
user/testscr.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include "type.h"
|
||||
#include "const.h"
|
||||
#include "protect.h"
|
||||
#include "string.h"
|
||||
#include "proc.h"
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
#include "stdio.h"
|
||||
|
||||
int main(int arg, char *argv[])
|
||||
{
|
||||
int stdin = open("dev_tty0", O_RDWR);
|
||||
int stdout = open("dev_tty0", O_RDWR);
|
||||
int stderr = open("dev_tty0", O_RDWR);
|
||||
|
||||
for (int i = 0; i < 40; i++)
|
||||
{
|
||||
printf("%02d ", i);
|
||||
}
|
||||
for (int i = 0; i < 50; ++i)
|
||||
{
|
||||
printf("test %d\n", i);
|
||||
for (int j = 0; j < 2000000; ++ j);
|
||||
}
|
||||
|
||||
while (1)
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user