merge in jyy branch

This commit is contained in:
Yanyan Jiang 2017-04-20 12:30:09 -04:00
commit ae8d4be95f
139 changed files with 2080 additions and 4123 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
.*
*~
*.a
*.o
*.d
*.pyc
tags
cscope.*
/build

View File

@ -1,49 +0,0 @@
ARCH = mips
CROSS_COMPILE = mips-linux-gnu-
AS = $(CROSS_COMPILE)as
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
CFLAGS = -MD -fno-pic -static -fno-strict-aliasing -fno-builtin -EB
CFLAGS += -fno-stack-protector -mno-check-zero-division -fno-delayed-branch
CFLAGS += -Wall -Werror -march=mips32 -mno-llsc
CFLAGS += -mno-mad -std=gnu99
CFLAGS += -I ../../include/common -I../../include/mips -O2 -Wno-unused-function
CFLAGS += -mno-abicalls -g
CFLAGS += -D DEPLOY
SCFLAGS = -MD -fno-pic -static -fno-strict-aliasing -fno-builtin
SCFLAGS += -fno-stack-protector -mno-check-zero-division -fno-delayed-branch
SCFLAGS += -Wall -Werror -march=mips32 -mno-llsc -mno-imadd -mno-mad
SCFLAGS += -I ../../include/common -I ../../include/mips -O2 -S -Wno-unused-function
ASFLAGS = -MD -mno-check-zero-division -mips32 -O0 -mno-abicalls
ASFLAGS += -fno-pic -fno-delayed-branch
LDFLAGS =
OBJ_DIR = obj
CSRC = $(shell find -L . -name "*.c")
SSRC = $(shell find -L . -name "*.S")
OBJECTS = $(SSRC:%.S=$(OBJ_DIR)/%.o) $(CSRC:%.c=$(OBJ_DIR)/%.o)
DOT_D = $(SSRC:.S=.d) $(CSRC:.c=.d)
ASMS = $(CSRC:.c=.S)
LIBS = libam-$(ARCH).a
export CROSS_COMPILE
.PHONY: asm
# ********************
# Rules of Compilation
# ********************
LIBS: $(OBJECTS)
ar crs $(LIBS) $(OBJECTS)
# Common rule
$(OBJ_DIR)/%.o: %.[cS]
@mkdir -p `dirname $@`
$(CC) $(CFLAGS) -c $< -o $@
clean:
-rm -rf *.a $(DOT_D) $(OBJECTS) obj *.txt> /dev/null

View File

@ -1,30 +0,0 @@
ARCH = x86
CC = gcc
LD = ld
CFLAGS = -m32 -march=i386 -static -MD -std=gnu89 -ggdb \
-fno-builtin -fno-stack-protector -fno-omit-frame-pointer \
-Wall -Werror -O2 -I../../include/common -I../../include/x86
ASFLAGS = -ggdb -m32 -MD
LDFLAGS = -melf_i386
OBJ_DIR = obj
CSRC = $(shell find -L . -name "*.c")
SSRC = $(shell find -L . -name "*.S")
OBJECTS = $(SSRC:%.S=$(OBJ_DIR)/%.o) $(CSRC:%.c=$(OBJ_DIR)/%.o)
ASMS = $(CSRC:.c=.S)
LIBS = libam-$(ARCH).a
# ********************
# Rules of Compilation
# ********************
LIBS: $(OBJECTS)
ar rcs $(LIBS) $(OBJECTS)
# Common rule
$(OBJ_DIR)/%.o: %.[cS]
@mkdir -p `dirname $@`
$(CC) $(CFLAGS) -c $< -o $@
clean:
-rm -rf *.a $(OBJECTS) obj *.txt> /dev/null

View File

@ -1,28 +0,0 @@
#include <draw.h>
#include <arch.h>
extern char font8x8_basic[128][8];
void draw_pixel(int x,int y,char color){
char *vmem = VMEM;
vmem[x * WIDTH + y] = color;
}
void draw_character(char ch, int x, int y, int color){
int i, j;
char *p = font8x8_basic[(int)ch];
for (i = 0; i < 8; i ++)
for (j = 0; j < 8; j ++)
if ((p[i] >> j) & 1)
draw_pixel(x + i, y + j, color);
}
void draw_string(const char *str, int x, int y, int color){
while (*str) {
draw_character(*str ++, x, y, color);
if (y + 8 >= 640) {
x += 8; y = 0;
} else {
y += 8;
}
}
}

View File

@ -1,153 +0,0 @@
/**
* 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
**/
// Constant: font8x8_basic
// Contains an 8x8 font map for unicode points U+0000 - U+007F (basic latin)
char font8x8_basic[128][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 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
};

View File

@ -1,43 +0,0 @@
#include <string.h>
extern int print(const char *str,int len);
void printf(const char *format,...){
void **args = (void **)&format + 1;
int count = 0;
int i = 0;
for(i = 0; format[i] != '\0'; i++) {
if(strcmp((char *)&format[i], 2, "%s") == 0) {
int len_temp = strlen(args[count]);
print(args[count],len_temp);
count++;
i++;
}
else if(strcmp((char *)&format[i], 2, "%d") == 0) {
char num[80];
i2str(num,(int)args[count]);
int len_temp = strlen(num);
print(num,len_temp);
count++;
i++;
}
else if(strcmp((char *)&format[i], 2, "%x") == 0) {
char num[80];
x2str(num,(int)args[count]);
int len_temp = strlen(num);
print(num,len_temp);
count++;
i++;
}
else if(strcmp((char *)&format[i], 2, "%c") == 0) {
print((void *)&args[count],1);
count++;
i++;
}
else if(format[i] == '\n') {
print("\n",1);
}
else
print((void *)&format[i],1);
}
}

View File

@ -1,30 +0,0 @@
#include <types.h>
int line,row = 0;
static inline int32_t syscall(int num, int check, uint32_t a1,uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5)
{
/*嵌入汇编代码调用int $0x80*/
int32_t ret = 0;
asm volatile("int $0x80": "=a"(ret) :"a"(num),"d"(check),"c"(a1), "b"(a2), "D"(a3), "S"(a4));
return ret;
}
int print(const char *str,int len){
if(str[0] == '\\' && str[1] == 'n' && str[2] == '\0'){
line += 1;
row = 0;
}
int length = syscall(4,1,(uint32_t)str,len,line,row,0);
row += length;
if(row >= 80) {
line += row / 80;
row = row % 80;
}
if(length < 0 || length != len){
while(1);
return -1;
}
else
return length;
}

View File

@ -1,30 +0,0 @@
ARCH = mips
all:
@cd arch/$(ARCH); make
@cd Lib/$(ARCH); make
-mkdir $(ARCH)_out
x86:
@cd src/makers/$(ARCH); make
cat build/$(ARCH)/$(ARCH)-arch src/test/umain > $(ARCH)_out/os.img
qemu-system-i386 -serial stdio $(ARCH)_out/os.img
debug:
qemu-system-i386 -serial stdio -s -S $(ARCH)_out/os.img
mips:
@cd arch/$(ARCH); make OBJ
@cd src/makers/$(ARCH); make
mips-linux-gnu-objcopy -O binary src/test/umain $(ARCH)_out/umain.bin
mips-linux-gnu-objdump -d src/test/umain > $(ARCH)_out/code.txt
python python/bin2text.py $(ARCH)_out/umain.bin $(ARCH)_out/ram.txt
python python/gen_bram_coe.py $(ARCH)_out/umain.bin app.coe
python python/instr_is_legal.py
clean:
@cd arch/$(ARCH); make clean
@cd Lib/$(ARCH); make clean
@cd src/makers/$(ARCH); make clean
-rm -rf $(ARCH)_out
-rm -rf *.coe

View File

@ -1,36 +0,0 @@
CROSS_COMPILE = mips-linux-gnu-
AS = $(CROSS_COMPILE)as
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
CFLAGS = -MD -fno-pic -static -fno-strict-aliasing -fno-builtin -EB
CFLAGS += -fno-stack-protector -mno-check-zero-division -fno-delayed-branch
CFLAGS += -Wall -Werror -march=mips32 -mno-llsc
CFLAGS += -mno-mad -std=gnu99
CFLAGS += -I include -O2 -Wno-unused-function
CFLAGS += -mno-abicalls -g
CFLAGS += -D DEPLOY
SCFLAGS = -MD -fno-pic -static -fno-strict-aliasing -fno-builtin
SCFLAGS += -fno-stack-protector -mno-check-zero-division -fno-delayed-branch
SCFLAGS += -Wall -Werror -march=mips32 -mno-llsc -mno-imadd -mno-mad
SCFLAGS += -I ../include -O2 -S -Wno-unused-function
ASFLAGS = -MD -mno-check-zero-division -mips32 -O0 -mno-abicalls
ASFLAGS += -fno-pic -fno-delayed-branch
LDFLAGS =
OBJECTS = $(shell find -L . -name "*.o")
mips-arch:
@cd boot; make;
@cd kernel; make;
@cd ../../build; rm -rf mips; mkdir mips;
OBJ:
-cp $(OBJECTS) ../../build/mips/
clean:
@cd boot; make clean;
@cd kernel; make clean;
rm -rf ../../build/mips

View File

@ -1,40 +0,0 @@
CROSS_COMPILE = mips-linux-gnu-
AS = $(CROSS_COMPILE)as
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
CFLAGS = -MD -fno-pic -static -fno-strict-aliasing -fno-builtin -EB
CFLAGS += -fno-stack-protector -mno-check-zero-division -fno-delayed-branch
CFLAGS += -Wall -Werror -march=mips32 -mno-llsc
# CFLAGS += -mno-imadd
CFLAGS += -mno-mad -std=gnu99
CFLAGS += -I inc -I include -O2 -Wno-unused-function
CFLAGS += -mno-abicalls -g
CFLAGS += -D DEPLOY
SCFLAGS = -MD -fno-pic -static -fno-strict-aliasing -fno-builtin
SCFLAGS += -fno-stack-protector -mno-check-zero-division -fno-delayed-branch
SCFLAGS += -Wall -Werror -march=mips32 -mno-llsc -mno-imadd -mno-mad
SCFLAGS += -I../include -O2 -S -Wno-unused-function
ASFLAGS = -MD -mno-check-zero-division -mips32 -O0 -mno-abicalls
ASFLAGS += -fno-pic -fno-delayed-branch
LDFLAGS =
CSRC = $(shell find -L . -name "*.c")
SSRC = $(shell find -L . -name "*.S")
OBJECTS = $(shell find -L . -name "*.o")
export CROSS_COMPILE
.PHONY: asm
# ********************
# Rules of Compilation
# ********************
OBJECTS: $(CSRC) $(SSRC)
$(CC) $(CFLAGS) -c $(CSRC) $(SSRC)
clean:
-rm -f *.o *.d > /dev/null

View File

@ -1,6 +0,0 @@
extern int main();
void bootmain(){
asm volatile("jal kentry");
while(1);
}

Binary file not shown.

View File

@ -1,25 +0,0 @@
.globl _start
.type _start, @function
.globl _qemu
.type _qemu, @function
.globl _bad
.type _bad, @function
_start:
li $sp, 0x0001fffc
jal bootmain
$L_GOOD:
b $L_GOOD
_qemu:
nop # Make address the same offset
jal bootmain
$L_LOOP:
b $L_LOOP
_bad:
$L_BAD:
b $L_BAD

View File

@ -1,45 +0,0 @@
CROSS_COMPILE = mips-linux-gnu-
AS = $(CROSS_COMPILE)as
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
CFLAGS = -MD -fno-pic -static -fno-strict-aliasing -fno-builtin -EB
CFLAGS += -fno-stack-protector -mno-check-zero-division -fno-delayed-branch
CFLAGS += -Wall -Werror -march=mips32 -mno-llsc
CFLAGS += -mno-mad -std=gnu99
CFLAGS += -I inc -I include -O2 -Wno-unused-function
CFLAGS += -mno-abicalls -g
CFLAGS += -D DEPLOY
SCFLAGS = -MD -fno-pic -static -fno-strict-aliasing -fno-builtin
SCFLAGS += -fno-stack-protector -mno-check-zero-division -fno-delayed-branch
SCFLAGS += -Wall -Werror -march=mips32 -mno-llsc -mno-imadd -mno-mad
SCFLAGS += -I../include -O2 -S -Wno-unused-function
ASFLAGS = -MD -mno-check-zero-division -mips32 -O0 -mno-abicalls
ASFLAGS += -fno-pic -fno-delayed-branch
LDFLAGS =
OBJ_DIR = obj
CSRC = $(shell find -L . -name "*.c")
SSRC = $(shell find -L . -name "*.S")
OBJECTS = $(SSRC:%.S=$(OBJ_DIR)/%.o) $(CSRC:%.c=$(OBJ_DIR)/%.o)
DOT_D = $(SSRC:.S=.d) $(CSRC:.c=.d)
ASMS = $(CSRC:.c=.S)
export CROSS_COMPILE
.PHONY: asm
# ********************
# Rules of Compilation
# *******************
all:$(OBJECTS)
# Common rule
$(OBJ_DIR)/%.o: %.[cS]
@mkdir -p `dirname $@`
$(CC) $(CFLAGS) -c $< -o $@
clean:
-rm -rf $(OBJ_DIR) $(DOT_D) $(OBJECTS) > /dev/null

View File

@ -1,3 +0,0 @@
unsigned int load_umain(){
return 0;
}

View File

@ -1,9 +0,0 @@
#ifndef __COMMON_H__
#define __COMMON_H__
#include "common/assert.h"
#include "common/debug.h"
#include "common/trap.h"
#include "common/printk.h"
#endif

View File

@ -1,13 +0,0 @@
#ifndef NPC_ASSERT_H
#define NPC_ASSERT_H
extern void _bad(void);
#define _S(x) #x
#define S(x) _S(x)
#define assert(x) \
do { \
if (!(x)) { puts(__FILE__ "@" S(__LINE__) ":" "Assertion failed: " S(x)); _bad(); } \
} while (0)
#endif

View File

@ -1,27 +0,0 @@
#ifndef __NPC_DEBUG_H__
#define __NPC_DEBUG_H__
union debug_que_entry {
unsigned int part[4];
struct {
unsigned int data_to_mig_low_word;
unsigned int data_from_mig_low_word;
unsigned int addr_to_mig;
unsigned int cache_status : 3;
unsigned int cache_counter : 3;
unsigned int mid_rdy : 1;
unsigned int mig_wdf_dry : 1;
unsigned int mig_ddr_inited : 1;
unsigned int mig_data_end : 1;
unsigned int mig_data_valid : 1;
unsigned int ddr_ctrl_reading : 1;
unsigned int ddr_ctrl_writing : 1;
unsigned int miss_count : 7;
unsigned int pad : 12;
};
};
#endif //__NPC_DEBUG_H__

View File

@ -1,5 +0,0 @@
#ifndef __PRINTK_H__
#define __PRINTK_H__
int printk(const char *format,...);
#endif

View File

@ -1,26 +0,0 @@
#ifndef TRAP_H
#define TRAP_H
static __attribute__((noinline)) int good() {
char* vga = (char*)0xc0000000 + 100*210 + 80;
*vga++ = 'G';
*vga++ = 'O';
*vga++ = 'O';
*vga++ = 'D';
while (1);
return 0;
}
static __attribute__((noinline)) int bad() {
char* vga = (char*)0xc0000000 + 100*210 + 80;
*vga++ = 'B';
*vga++ = 'A';
*vga++ = 'D';
while (1);
return -1;
}
#define ASSERT(x) do { if (!(x)) bad(); } while (0)
#define set_sp asm volatile("li $sp, 16000");
#endif // TRAP_H

View File

@ -1,6 +0,0 @@
#ifndef __DEVICE_H__
#define __DEVICE_H__
#include "device/serial.h"
#endif

View File

@ -1,15 +0,0 @@
#ifndef __SERIAL_H__
#define __SERIAL_H__
#define Rx 0x0
#define Tx 0x04
#define STAT 0x08
#define CTRL 0x0c
#define SERIAL_PORT ((char *)0xe0000000)
void init_serial();
void out_byte(char ch);
char in_byte();
void putchar(char ch);
#endif

View File

@ -1,7 +0,0 @@
#ifndef __MIPS_H__
#define __MIPS_H__
#include "mips/arch.h"
#include "mips/irq.h"
#include "mips/memory.h"
#endif

View File

@ -1,28 +0,0 @@
#ifndef __ARCH_H__
#define __ARCH_H__
#define KERNEL_MODE 0
#define USER_MODE 3
#define NULL ((void*)0)
typedef struct CP0 {
unsigned int index,entrylo0,entrylo1,
context,pagemask,badvaddr,
count,entryhi,compare,status,
cause,epc,prid,watchlo,watchhi,
taglo,taghi;
} CP0;
typedef struct _RegSet {
unsigned int zero,
at,
v0,v1,
a0,a1,a2,a3,
t0,t1,t2,t3,t4,t5,t6,t7,
s0,s1,s2,s3,s4,s5,s6,s7,
k0,k1,
t8,t9,
gp,sp,fp,ra;
} _RegSet;
#endif

View File

@ -1,8 +0,0 @@
#ifndef __IRQ_H__
#define __IRQ_H__
/* 中断处理相关函数 */
void init_idt(void);
void init_intr(void);
#endif

View File

@ -1,6 +0,0 @@
#ifndef __MIPS_MEMORY_H__
#define __MIPS_MEMORY_H__
unsigned int load_umain();
void init_seg();
#endif

View File

@ -1,2 +0,0 @@
void init_idt(){
}

View File

@ -1,2 +0,0 @@
void init_intr(){
}

View File

@ -1,30 +0,0 @@
#include "common.h"
#include "mips.h"
#include "device.h"
void enter_user_space(unsigned int);
extern int main();
void
kentry(void) {
printk("Hello, welcome to kernel!\n");
init_serial();
printk("serial initialization complete!\n");
init_idt();
printk("idt initialization complete!\n");
init_intr();
printk("interrupt initialization complete!\n");
init_seg();
printk("segment initialization complete!\n");
printk("loading files...\n");
unsigned int entry = load_umain();
printk("leaving kernel, entering user space!\n");
enter_user_space(entry);
printk("should not reach here!\n");
}
void
enter_user_space(unsigned int entry) {
asm volatile("jal main\n\t");
while(1);
}

View File

@ -1,171 +0,0 @@
#include "mips.h"
#include "device.h"
#include <stdarg.h>
static void printchar(char **str, int c)
{
if (str) {
**str = c;
++(*str);
}
else putchar(c);
}
#define PAD_RIGHT 1
#define PAD_ZERO 2
static int prints(char **out, const char *string, int width, int pad)
{
register int pc = 0, padchar = ' ';
if (width > 0) {
register int len = 0;
register const char *ptr;
for (ptr = string; *ptr; ++ptr) ++len;
if (len >= width) width = 0;
else width -= len;
if (pad & PAD_ZERO) padchar = '0';
}
if (!(pad & PAD_RIGHT)) {
for ( ; width > 0; --width) {
printchar (out, padchar);
++pc;
}
}
for ( ; *string ; ++string) {
printchar (out, *string);
++pc;
}
for ( ; width > 0; --width) {
printchar (out, padchar);
++pc;
}
return pc;
}
/* the following should be enough for 32 bit int */
#define PRINT_BUF_LEN 12
static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase)
{
char print_buf[PRINT_BUF_LEN];
register char *s;
register int t, neg = 0, pc = 0;
register unsigned int u = i;
if (i == 0) {
print_buf[0] = '0';
print_buf[1] = '\0';
return prints (out, print_buf, width, pad);
}
if (sg && b == 10 && i < 0) {
neg = 1;
u = -i;
}
s = print_buf + PRINT_BUF_LEN-1;
*s = '\0';
while (u) {
t = u % b;
if( t >= 10 )
t += letbase - '0' - 10;
*--s = t + '0';
u /= b;
}
if (neg) {
if( width && (pad & PAD_ZERO) ) {
printchar (out, '-');
++pc;
--width;
}
else {
*--s = '-';
}
}
return pc + prints (out, s, width, pad);
}
static int print(char **out, const char *format, va_list args )
{
register int width, pad;
register int pc = 0;
char scr[2];
for (; *format != 0; ++format) {
if (*format == '%') {
++format;
width = pad = 0;
if (*format == '\0') break;
if (*format == '%') goto out;
if (*format == '-') {
++format;
pad = PAD_RIGHT;
}
while (*format == '0') {
++format;
pad |= PAD_ZERO;
}
for ( ; *format >= '0' && *format <= '9'; ++format) {
width *= 10;
width += *format - '0';
}
if( *format == 's' ) {
register char *s = (char *)va_arg( args, int );
pc += prints (out, s?s:"(null)", width, pad);
continue;
}
if( *format == 'd' ) {
pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
continue;
}
if( *format == 'x' ) {
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
continue;
}
if( *format == 'X' ) {
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
continue;
}
if( *format == 'u' ) {
pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
continue;
}
if( *format == 'c' ) {
/* char are converted to int then pushed on the stack */
scr[0] = (char)va_arg( args, int );
scr[1] = '\0';
pc += prints (out, scr, width, pad);
continue;
}
}
else {
out:
printchar (out, *format);
++pc;
}
}
if (out) **out = '\0';
va_end( args );
return pc;
}
int printk(const char *format, ...)
{
va_list args;
va_start( args, format );
return print( 0, format, args );
}
int sprintk(char *out, const char *format, ...)
{
va_list args;
va_start( args, format );
return print( &out, format, args );
}

View File

@ -1,25 +0,0 @@
#include "mips.h"
#include "device.h"
void init_serial(){
}
char *csend = SERIAL_PORT + Tx;
char *crecv = SERIAL_PORT + Rx;
char *stat = SERIAL_PORT + STAT;
char *ctrl = SERIAL_PORT + CTRL;
void out_byte(char ch){
while(((*stat >> 3) & 0x1));
*csend = ch;
}
char in_byte(){
while(!(*stat & 0x1));
return *crecv;
}
void
putchar(char ch) {
out_byte(ch);
}

View File

@ -1,2 +0,0 @@
void init_seg(){
}

View File

@ -1,19 +0,0 @@
CC = gcc
LD = ld
CFLAGS = -m32 -march=i386 -static -MD -std=gnu89 -ggdb \
-fno-builtin -fno-stack-protector -fno-omit-frame-pointer \
-Wall -Werror -O2
ASFLAGS = -ggdb -m32 -MD
LDFLAGS = -melf_i386
QEMU = qemu-system-i386
x86-arch:
@cd boot; make
@cd kernel; make
@cd ../../build; rm -rf x86; mkdir x86
cat boot/mbr kernel/kmain > ../../build/x86/x86-arch
clean:
@cd boot; make clean
@cd kernel; make clean
rm -rf ../../build/x86

View File

@ -1,7 +0,0 @@
mbr: start.S boot.c asm.h boot.h
gcc -nostdlib -Os -g start.S boot.c -m32 -Ttext 0x7C00 -o bootblock.o
@objcopy -S -O binary -j .text bootblock.o mbr
@perl genboot.pl mbr
clean:
rm -rf bootblock *.o mbr

View File

@ -1,58 +0,0 @@
#include "boot.h"
#define SECTSIZE 512
void readdisk(unsigned char *elf, int count, int offset);
void bootmain(void)
{
struct ELFHeader *elf;
/* 这里是加载磁盘程序的代码 */
struct ProgramHeader *ph, *eph;
unsigned char * pa, *i;
elf = (struct ELFHeader *)0x8000;
readdisk((void *)elf, 4096, 0);
ph = (struct ProgramHeader *)((char *)elf + elf->phoff);
eph = ph + elf->phnum;
for(;ph < eph; ph++)
{
pa = (unsigned char *)ph->paddr;
readdisk(pa, ph->filesz, ph->off);
for(i = pa + ph->filesz; i < pa + ph->memsz; *i ++ = 0);
}
((void(*)(void))elf->entry)(); //goto kernel main
}
void
waitdisk(void) {
while((in_byte(0x1F7) & 0xC0) != 0x40); /* 等待磁盘完毕 */
}
/* 读磁盘的一个扇区 */
void
readsect(void *dst, int offset) {
int i;
waitdisk();
out_byte(0x1F2, 1);
out_byte(0x1F3, offset);
out_byte(0x1F4, offset >> 8);
out_byte(0x1F5, offset >> 16);
out_byte(0x1F6, (offset >> 24) | 0xE0);
out_byte(0x1F7, 0x20);
waitdisk();
for (i = 0; i < SECTSIZE / 4; i ++) {
((int *)dst)[i] = in_long(0x1F0);
}
}
void readdisk(unsigned char *elf, int count, int offset) {
unsigned char * eelf;
eelf = elf + count;
elf -= offset % SECTSIZE;
offset = offset / SECTSIZE + 1;
for(; elf < eelf; elf += SECTSIZE, offset++)
readsect(elf,offset);
}

View File

@ -1,43 +0,0 @@
#include "asm.h"
.code16
.globl _start
_start:
cli
xorw %ax, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw $0x2401, %ax
int $0x15
lgdt gdtdesc
movl %cr0, %eax
orl $0x1, %eax
movl %eax, %cr0
ljmp $GDT_ENTRY(1), $start32
.code32
start32:
movw $GDT_ENTRY(2), %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movl $0x8000, %esp
call bootmain
# GDT
.p2align 2 #
gdt:
SEG_NULLASM
SEG_ASM(0xA, 0x0, 0xffffffff, 0x0)
SEG_ASM(0x2, 0x0, 0xffffffff, 0x0)
gdtdesc: # GDT
.word (gdtdesc - gdt - 1) # GDT
.long gdt # GDT

View File

@ -1,23 +0,0 @@
CC = gcc
LD = ld
CFLAGS = -m32 -march=i386 -static -MD -std=gnu89 -ggdb -g\
-fno-builtin -fno-stack-protector -fno-omit-frame-pointer \
-Wall -Werror -O2 -Iinclude
ASFLAGS = -ggdb -m32 -MD
LDFLAGS = -melf_i386
QEMU = qemu-system-i386
# 编译目标src目录下的所有.c和.S文件
KCFILES = $(shell find ./ -name "*.c")
KSFILES = $(shell find ./ -name "*.S")
KOBJS = $(KCFILES:.c=.o) $(KSFILES:.S=.o)
kmain: $(KOBJS)
$(LD) $(LDFLAGS) -e kentry -Ttext 0x00100000 -o kmain $(KOBJS)
./genkernel.pl kmain
objdump -d kmain > kmain.s
-include $(patsubst %.o, %.d, $(KOBJS))
clean:
rm -rf $(KOBJS) $(KOBJS:.o=.d) kmain

View File

@ -1,67 +0,0 @@
#include "x86.h"
#include "device.h"
#define SECTSIZE 512
#define ELF_OFFSET_DISK 200 * SECTSIZE
void readdisk(unsigned char *elf, int count, int offset);
struct ELFHeader *elf;
uint8_t buf[4096];
uint32_t
load_umain(void) {
/*
* Load your app here
*
*/
struct ProgramHeader *ph, *eph;
unsigned char * pa, *i;
elf = (void *)buf;
readdisk((void *)elf, 4096, ELF_OFFSET_DISK);
ph = (struct ProgramHeader *)((char *)elf + elf->phoff);
eph = ph + elf->phnum;
for(;ph < eph; ph++)
{
if(ph->type == 1)
{
pa = (unsigned char *)ph->paddr + USER_CS_BASE;
readdisk(pa, ph->filesz, ph->off + ELF_OFFSET_DISK);
for(i = pa + ph->filesz; i < pa + ph->memsz; *i++ = 0);
}
}
return elf->entry;
}
void
waitdisk(void) {
while((in_byte(0x1F7) & 0xC0) != 0x40);
}
void
readsect(void *dst, int offset) {
int i;
waitdisk();
out_byte2(0x1F2, 1);
out_byte2(0x1F3, offset);
out_byte2(0x1F4, offset >> 8);
out_byte2(0x1F5, offset >> 16);
out_byte2(0x1F6, (offset >> 24) | 0xE0);
out_byte2(0x1F7, 0x20);
waitdisk();
for (i = 0; i < SECTSIZE / 4; i ++) {
((int *)dst)[i] = in_long(0x1F0);
}
}
void readdisk(unsigned char *elf, int count, int offset) {
unsigned char * eelf;
eelf = elf + count;
elf -= offset % SECTSIZE;
offset = offset / SECTSIZE + 1;
for(; elf < eelf; elf += SECTSIZE, offset++)
readsect(elf,offset);
}

View File

@ -1,27 +0,0 @@
#include "x86.h"
#include "device.h"
union character {
uint16_t val;
struct {
uint8_t ch;
uint8_t color;
};
};
int write(int fd, char *buf, int len, int line, int row) {
if(fd == 1 || fd == 2){
uint16_t *gs = (void *)0xb8000;
gs = gs + line * 80 + row;
union character c;
int i;
for(i = 0; i < len; i++){
c.ch = (buf + 0x200000)[i];
c.color = 0x0b;
gs[i] = c.val;
}
return len;
}
else
return -1;
}

View File

@ -1,13 +0,0 @@
#!/usr/bin/perl
open(SIG, $ARGV[0]) || die "open $ARGV[0]: $!";
$n = sysread(SIG, $buf, 100000);
print STDERR "OK: Kernel is $n bytes - Extended to 200 sectors\n";
$buf .= "\0" x (102400-$n);
open(SIG, ">$ARGV[0]") || die "open >$ARGV[0]: $!";
print SIG $buf;
close SIG;

View File

@ -1,9 +0,0 @@
#ifndef __COMMON_H__
#define __COMMON_H__
#include "common/types.h"
#include "common/const.h"
#include "common/assert.h"
#include "common/printk.h"
#endif

View File

@ -1,10 +0,0 @@
#ifndef __ASSERT_H__
#define __ASSERT_H__
int abort(const char *, int);
/* assert: 断言条件为真,若为假则蓝屏退出 */
#define assert(cond) \
((cond) ? (0) : (abort(__FILE__, __LINE__)))
#endif

View File

@ -1,9 +0,0 @@
#ifndef __CONST_H__
#define __CONST_H__
#define TRUE 1
#define FALSE 0
#define NULL ((void*)0)
#endif

View File

@ -1,5 +0,0 @@
#ifndef __PRINTK_H__
#define __PRINTK_H__
int printk(const char *format,...);
#endif

View File

@ -1,12 +0,0 @@
#ifndef __TYPES_H__
#define __TYPES_H__
/* 定义数据类型 */
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned short uint16_t;
typedef short int16_t;
typedef unsigned char uint8_t;
typedef char int8_t;
typedef unsigned int size_t;
#endif

View File

@ -1,7 +0,0 @@
#ifndef __DEVICE_H__
#define __DEVICE_H__
#include "device/serial.h"
#include "device/vga.h"
#endif

View File

@ -1,8 +0,0 @@
#ifndef __SERIAL_H__
#define __SERIAL_H__
void init_serial(void);
void putchar(char);
#define SERIAL_PORT 0x3F8
#endif

View File

@ -1,11 +0,0 @@
#ifndef __VGA_H__
#define __VGA_H__
#define VMEM (void *)0xa0000
#define VMEM_SIZE (0xbffff - 0xa0000)
#define WIDTH 320
#define HEIGHT 200
void init_vga();
void draw_pixel(int x,int y,int color);
#endif

View File

@ -1,12 +0,0 @@
#ifndef __X86_H__
#define __X86_H__
#include "x86/cpu.h"
#include "x86/memory.h"
#include "x86/io.h"
#include "x86/irq.h"
void init_seg(void);
uint32_t load_umain(void);
#endif

View File

@ -1,36 +0,0 @@
#ifndef __X86_CPU_H__
#define __X86_CPU_H__
#include "common.h"
/* 将CPU置入休眠状态直到下次中断到来 */
static inline void
wait_for_interrupt() {
asm volatile("hlt");
}
/* 修改IDTR */
static inline void
save_idt(void *addr, uint32_t size) {
static volatile uint16_t data[3];
data[0] = size - 1;
data[1] = (uint32_t)addr;
data[2] = ((uint32_t)addr) >> 16;
asm volatile("lidt (%0)" : : "r"(data));
}
/* 打开外部中断 */
static inline void
enable_interrupt(void) {
asm volatile("sti");
}
/* 关闭外部中断 */
static inline void
disable_interrupt(void) {
asm volatile("cli");
}
#define NR_IRQ 256
#endif

View File

@ -1,60 +0,0 @@
#ifndef __X86_IO_H__
#define __X86_IO_H__
/* ELF32二进制文件头 */
struct ELFHeader {
unsigned int magic;
unsigned char elf[12];
unsigned short type;
unsigned short machine;
unsigned int version;
unsigned int entry;
unsigned int phoff;
unsigned int shoff;
unsigned int flags;
unsigned short ehsize;
unsigned short phentsize;
unsigned short phnum;
unsigned short shentsize;
unsigned short shnum;
unsigned short shstrndx;
};
/* ELF32 Program header */
struct ProgramHeader {
unsigned int type;
unsigned int off;
unsigned int vaddr;
unsigned int paddr;
unsigned int filesz;
unsigned int memsz;
unsigned int flags;
unsigned int align;
};
static inline int
in_long(short port) {
int data;
asm volatile("in %1, %0" : "=a" (data) : "d" (port));
return data;
}
/* 读I/O端口 */
static inline uint8_t
in_byte(uint16_t port) {
uint8_t data;
asm volatile("in %1, %0" : "=a"(data) : "d"(port));
return data;
}
/* 写I/O端口 */
static inline void
out_byte(uint16_t port, int8_t data) {
asm volatile("out %%al, %%dx" : : "a"(data), "d"(port));
}
static inline void
out_byte2(short port, char data) {
asm volatile("out %0,%1" : : "a" (data), "d" (port));
}
#endif

View File

@ -1,8 +0,0 @@
#ifndef __IRQ_H__
#define __IRQ_H__
/* 中断处理相关函数 */
void init_idt(void);
void init_intr(void);
#endif

View File

@ -1,114 +0,0 @@
#ifndef __X86_MEMORY_H__
#define __X86_MEMORY_H__
#define DPL_KERN 0
#define DPL_USER 3
#define STACK 0x800000
#define USER_CS_BASE 0x200000
#define USER_SS_BASE 0x200000
// Application segment type bits
#define STA_X 0x8 // Executable segment
#define STA_W 0x2 // Writeable (non-executable segments)
#define STA_R 0x2 // Readable (executable segments)
// System segment type bits
#define STS_T32A 0x9 // Available 32-bit TSS
#define STS_IG32 0xE // 32-bit Interrupt Gate
#define STS_TG32 0xF // 32-bit Trap Gate
// GDT entries
#define NR_SEGMENTS 7 // GDT size
#define SEG_KCODE 1 // Kernel code
#define SEG_KDATA 2 // Kernel data/stack
#define SEG_UCODE 3 // User code
#define SEG_UDATA 4 // User data/stack
#define SEG_TSS 5 // Global unique task state segement
// Selectors
#define KSEL(desc) (((desc) << 3) | DPL_KERN)
#define USEL(desc) (((desc) << 3) | DPL_USER)
struct GateDescriptor {
uint32_t offset_15_0 : 16;
uint32_t segment : 16;
uint32_t pad0 : 8;
uint32_t type : 4;
uint32_t system : 1;
uint32_t privilege_level : 2;
uint32_t present : 1;
uint32_t offset_31_16 : 16;
};
struct TrapFrame {
uint32_t edi, esi, ebp, xxx, ebx, edx, ecx, eax;
int32_t irq;
};
struct SegDesc {
uint32_t lim_15_0 : 16; // Low bits of segment limit
uint32_t base_15_0 : 16; // Low bits of segment base address
uint32_t base_23_16 : 8; // Middle bits of segment base address
uint32_t type : 4; // Segment type (see STS_ constants)
uint32_t s : 1; // 0 = system, 1 = application
uint32_t dpl : 2; // Descriptor Privilege Level
uint32_t p : 1; // Present
uint32_t lim_19_16 : 4; // High bits of segment limit
uint32_t avl : 1; // Unused (available for software use)
uint32_t rsv1 : 1; // Reserved
uint32_t db : 1; // 0 = 16-bit segment, 1 = 32-bit segment
uint32_t g : 1; // Granularity: limit scaled by 4K when set
uint32_t base_31_24 : 8; // High bits of segment base address
};
typedef struct SegDesc SegDesc;
#define SEG(type, base, lim, dpl) (SegDesc) \
{ ((lim) >> 12) & 0xffff, (uint32_t)(base) & 0xffff, \
((uint32_t)(base) >> 16) & 0xff, type, 1, dpl, 1, \
(uint32_t)(lim) >> 28, 0, 0, 1, 1, (uint32_t)(base) >> 24 }
#define SEG16(type, base, lim, dpl) (SegDesc) \
{ (lim) & 0xffff, (uint32_t)(base) & 0xffff, \
((uint32_t)(base) >> 16) & 0xff, type, 0, dpl, 1, \
(uint32_t)(lim) >> 16, 0, 0, 1, 0, (uint32_t)(base) >> 24 }
// Task state segment format
struct TSS {
uint32_t link; // old ts selector
uint32_t esp0; // Ring 0 Stack pointer and segment selector
uint32_t ss0; // after an increase in privilege level
union{
struct{
char dontcare[88];
};
struct{
uint32_t esp1,ss1,esp2,ss2;
uint32_t cr3, eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
uint32_t es, cs, ss, ds, fs, gs, ldt;
};
};
};
typedef struct TSS TSS;
static inline void
set_gdt(SegDesc *gdt, uint32_t size) {
volatile static uint16_t data[3];
data[0] = size - 1;
data[1] = (uint32_t)gdt;
data[2] = (uint32_t)gdt >> 16;
asm volatile("lgdt (%0)" : : "r"(data));
}
static inline void
lldt(uint16_t sel)
{
asm volatile("lldt %0" :: "r"(sel));
}
static inline void
ltr(uint16_t sel)
{
asm volatile("ltrw %0" :: "r"(sel));
}
#endif

View File

@ -1,49 +0,0 @@
#define DPL_KERN 0
#define DPL_USER 3
#define KSEL(desc) (((desc) << 3) | DPL_KERN)
#define USEL(desc) (((desc) << 3) | DPL_USER)
#define SEG_KDATA 2
#define SEG_UDATA 4
.globl vec0; vec0: pushl $0; jmp asm_do_irq
.globl vec1; vec1: pushl $1; jmp asm_do_irq
.globl vec2; vec2: pushl $2; jmp asm_do_irq
.globl vec3; vec3: pushl $3; jmp asm_do_irq
.globl vec4; vec4: pushl $4; jmp asm_do_irq
.globl vec5; vec5: pushl $5; jmp asm_do_irq
.globl vec6; vec6: pushl $6; jmp asm_do_irq
.globl vec7; vec7: pushl $7; jmp asm_do_irq
.globl vec8; vec8: pushl $8; jmp asm_do_irq
.globl vec9; vec9: pushl $9; jmp asm_do_irq
.globl vec10; vec10: pushl $10; jmp asm_do_irq
.globl vec11; vec11: pushl $11; jmp asm_do_irq
.globl vec12; vec12: pushl $12; jmp asm_do_irq
.globl vec13; vec13: pushl $13; jmp asm_do_irq
.globl vec14; vec14: pushl $14; jmp asm_do_irq
.globl vecsys; vecsys: pushl $0x80; jmp asm_do_irq
.globl irq0; irq0: pushl $1000; jmp asm_do_irq
.globl irq1; irq1: pushl $1001; jmp asm_do_irq
.globl irq14; irq14: pushl $1014; jmp asm_do_irq
.globl irq_empty; irq_empty: pushl $-1; jmp asm_do_irq
# C(irq/irq_handle.c)
.globl asm_do_irq
.extern irq_handle
# ring3 ,
asm_do_irq:
pushal
pushl %esp
movw $KSEL(SEG_KDATA),%ax
movw %ax,%es
movw %ax,%ds
call irq_handle
movw $USEL(SEG_UDATA),%ax
movw %ax,%es
movw %ax,%ds
addl $4, %esp
popal
addl $4, %esp
iret

View File

@ -1,26 +0,0 @@
#include "x86.h"
#define PORT_PIC_MASTER 0x20
#define PORT_PIC_SLAVE 0xA0
#define IRQ_SLAVE 2
/* 初始化8259中断控制器
* IRQ从32号开始EOI */
void
init_intr(void) {
out_byte(PORT_PIC_MASTER + 1, 0xFF);
out_byte(PORT_PIC_SLAVE + 1 , 0xFF);
out_byte(PORT_PIC_MASTER, 0x11);
out_byte(PORT_PIC_MASTER + 1, 32);
out_byte(PORT_PIC_MASTER + 1, 1 << 2);
out_byte(PORT_PIC_MASTER + 1, 0x3);
out_byte(PORT_PIC_SLAVE, 0x11);
out_byte(PORT_PIC_SLAVE + 1, 32 + 8);
out_byte(PORT_PIC_SLAVE + 1, 2);
out_byte(PORT_PIC_SLAVE + 1, 0x3);
out_byte(PORT_PIC_MASTER, 0x68);
out_byte(PORT_PIC_MASTER, 0x0A);
out_byte(PORT_PIC_SLAVE, 0x68);
out_byte(PORT_PIC_SLAVE, 0x0A);
}

View File

@ -1,93 +0,0 @@
#include "x86.h"
#include "device.h"
#define INTERRUPT_GATE_32 0xE
#define TRAP_GATE_32 0xF
/* IDT表的内容 */
struct GateDescriptor idt[NR_IRQ];
/* 初始化一个中断门(interrupt gate) */
static void
set_intr(struct GateDescriptor *ptr, uint32_t selector, uint32_t offset, uint32_t dpl) {
ptr->offset_15_0 = offset & 0xFFFF;
ptr->segment = selector << 3;
ptr->pad0 = 0;
ptr->type = INTERRUPT_GATE_32;
ptr->system = FALSE;
ptr->privilege_level = dpl;
ptr->present = TRUE;
ptr->offset_31_16 = (offset >> 16) & 0xFFFF;
}
/* 初始化一个陷阱门(trap gate) */
static void
set_trap(struct GateDescriptor *ptr, uint32_t selector, uint32_t offset, uint32_t dpl) {
ptr->offset_15_0 = offset & 0xFFFF;
ptr->segment = selector << 3;
ptr->pad0 = 0;
ptr->type = TRAP_GATE_32;
ptr->system = FALSE;
ptr->privilege_level = dpl;
ptr->present = TRUE;
ptr->offset_31_16 = (offset >> 16) & 0xFFFF;
}
/* 声明函数,这些函数在汇编代码里定义 */
void vec0();
void vec1();
void vec2();
void vec3();
void vec4();
void vec5();
void vec6();
void vec7();
void vec8();
void vec9();
void vec10();
void vec11();
void vec12();
void vec13();
void vec14();
void vecsys();
void irq0();
void irq1();
void irq14();
void irq_empty();
void init_idt() {
int i;
/* 为了防止系统异常终止所有irq都有处理函数(irq_empty)。 */
for (i = 0; i < NR_IRQ; i ++) {
set_trap(idt + i, SEG_KCODE, (uint32_t)irq_empty, DPL_KERN);
}
/*
* init your idt here
* IDT ,
*/
set_trap(idt + 0, SEG_KCODE, (uint32_t)vec0, DPL_KERN);
set_trap(idt + 1, SEG_KCODE, (uint32_t)vec1, DPL_KERN);
set_trap(idt + 2, SEG_KCODE, (uint32_t)vec2, DPL_KERN);
set_trap(idt + 3, SEG_KCODE, (uint32_t)vec3, DPL_KERN);
set_trap(idt + 4, SEG_KCODE, (uint32_t)vec4, DPL_KERN);
set_trap(idt + 5, SEG_KCODE, (uint32_t)vec5, DPL_KERN);
set_trap(idt + 6, SEG_KCODE, (uint32_t)vec6, DPL_KERN);
set_trap(idt + 7, SEG_KCODE, (uint32_t)vec7, DPL_KERN);
set_trap(idt + 8, SEG_KCODE, (uint32_t)vec8, DPL_KERN);
set_trap(idt + 9, SEG_KCODE, (uint32_t)vec9, DPL_KERN);
set_trap(idt + 10, SEG_KCODE, (uint32_t)vec10, DPL_KERN);
set_trap(idt + 11, SEG_KCODE, (uint32_t)vec11, DPL_KERN);
set_trap(idt + 12, SEG_KCODE, (uint32_t)vec12, DPL_KERN);
set_trap(idt + 13, SEG_KCODE, (uint32_t)vec13, DPL_KERN);
set_trap(idt + 14, SEG_KCODE, (uint32_t)vec14, DPL_KERN);
set_trap(idt + 0x80, SEG_KCODE, (uint32_t)vecsys, DPL_USER);
set_intr(idt + 32, SEG_KCODE, (uint32_t)irq0, DPL_KERN);
set_intr(idt + 32 + 1, SEG_KCODE, (uint32_t)irq1, DPL_KERN);
set_intr(idt + 32 + 14, SEG_KCODE, (uint32_t)irq14, DPL_KERN);
/* 写入IDT */
save_idt(idt, sizeof(idt));
}

View File

@ -1,30 +0,0 @@
#include "x86.h"
#include "device.h"
#include "common.h"
#define SYS_write 4
void do_syscall(struct TrapFrame *tf);
extern int write(int fd, char *buf, int len, int line, int row);
void
irq_handle(struct TrapFrame *tf) {
switch(tf->irq) {
case 0x80:do_syscall(tf);break;
case 3:printk("hit breakpoint exception(3)\n");while(1);break;
case 13:printk("hit protect exception(13)\n");while(1);break;
case 1000:assert(0);break;
case 1001:assert(0);break;
case 1014:assert(0);break;
default:printk("irq = %d\n",tf->irq);assert(0);
}
}
void
do_syscall(struct TrapFrame *tf) {
switch(tf->eax)
{
case SYS_write:tf->eax = write(tf->edx,(void *)tf->ecx,tf->ebx,tf->edi,tf->esi);break;
default: assert(0);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,46 +0,0 @@
#include "common.h"
#include "x86.h"
#include "device.h"
static char *
itoa(int a) {
static char buf[30];
char *p = buf + sizeof(buf) - 1;
do {
*--p = '0' + a % 10;
} while (a /= 10);
return p;
}
static void
append(char **p, const char *str) {
while (*str) {
*((*p) ++) = *str ++;
}
}
/* 将文件名和assert fail的行号显示在屏幕上 */
#define BLUE_SCREEN_TEXT "Assertion failed: "
static void
display_message(const char *file, int line) {
static char buf[256] = BLUE_SCREEN_TEXT;
char *p = buf + sizeof(BLUE_SCREEN_TEXT) - 1;
append(&p, file);
append(&p, ":");
append(&p, itoa(line));
append(&p, "\n");
for (p = buf; *p; p ++) {
putchar(*p);
}
}
int
abort(const char *fname, int line) {
disable_interrupt();
display_message(fname, line);
while (TRUE) {
wait_for_interrupt();
}
}

View File

@ -1,171 +0,0 @@
#include "x86.h"
#include "device.h"
#include <stdarg.h>
static void printchar(char **str, int c)
{
if (str) {
**str = c;
++(*str);
}
else putchar(c);
}
#define PAD_RIGHT 1
#define PAD_ZERO 2
static int prints(char **out, const char *string, int width, int pad)
{
register int pc = 0, padchar = ' ';
if (width > 0) {
register int len = 0;
register const char *ptr;
for (ptr = string; *ptr; ++ptr) ++len;
if (len >= width) width = 0;
else width -= len;
if (pad & PAD_ZERO) padchar = '0';
}
if (!(pad & PAD_RIGHT)) {
for ( ; width > 0; --width) {
printchar (out, padchar);
++pc;
}
}
for ( ; *string ; ++string) {
printchar (out, *string);
++pc;
}
for ( ; width > 0; --width) {
printchar (out, padchar);
++pc;
}
return pc;
}
/* the following should be enough for 32 bit int */
#define PRINT_BUF_LEN 12
static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase)
{
char print_buf[PRINT_BUF_LEN];
register char *s;
register int t, neg = 0, pc = 0;
register unsigned int u = i;
if (i == 0) {
print_buf[0] = '0';
print_buf[1] = '\0';
return prints (out, print_buf, width, pad);
}
if (sg && b == 10 && i < 0) {
neg = 1;
u = -i;
}
s = print_buf + PRINT_BUF_LEN-1;
*s = '\0';
while (u) {
t = u % b;
if( t >= 10 )
t += letbase - '0' - 10;
*--s = t + '0';
u /= b;
}
if (neg) {
if( width && (pad & PAD_ZERO) ) {
printchar (out, '-');
++pc;
--width;
}
else {
*--s = '-';
}
}
return pc + prints (out, s, width, pad);
}
static int print(char **out, const char *format, va_list args )
{
register int width, pad;
register int pc = 0;
char scr[2];
for (; *format != 0; ++format) {
if (*format == '%') {
++format;
width = pad = 0;
if (*format == '\0') break;
if (*format == '%') goto out;
if (*format == '-') {
++format;
pad = PAD_RIGHT;
}
while (*format == '0') {
++format;
pad |= PAD_ZERO;
}
for ( ; *format >= '0' && *format <= '9'; ++format) {
width *= 10;
width += *format - '0';
}
if( *format == 's' ) {
register char *s = (char *)va_arg( args, int );
pc += prints (out, s?s:"(null)", width, pad);
continue;
}
if( *format == 'd' ) {
pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
continue;
}
if( *format == 'x' ) {
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
continue;
}
if( *format == 'X' ) {
pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
continue;
}
if( *format == 'u' ) {
pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
continue;
}
if( *format == 'c' ) {
/* char are converted to int then pushed on the stack */
scr[0] = (char)va_arg( args, int );
scr[1] = '\0';
pc += prints (out, scr, width, pad);
continue;
}
}
else {
out:
printchar (out, *format);
++pc;
}
}
if (out) **out = '\0';
va_end( args );
return pc;
}
int printk(const char *format, ...)
{
va_list args;
va_start( args, format );
return print( 0, format, args );
}
int sprintk(char *out, const char *format, ...)
{
va_list args;
va_start( args, format );
return print( &out, format, args );
}

View File

@ -1,25 +0,0 @@
#include "x86.h"
#include "device.h"
void
init_serial(void) {
out_byte(SERIAL_PORT + 1, 0x00);
out_byte(SERIAL_PORT + 3, 0x80);
out_byte(SERIAL_PORT + 0, 0x01);
out_byte(SERIAL_PORT + 1, 0x00);
out_byte(SERIAL_PORT + 3, 0x03);
out_byte(SERIAL_PORT + 2, 0xC7);
out_byte(SERIAL_PORT + 4, 0x0B);
}
static inline int
serial_idle(void) {
return (in_byte(SERIAL_PORT + 5) & 0x20) != 0;
}
void
putchar(char ch) {
while (serial_idle() != TRUE);
out_byte(SERIAL_PORT, ch);
}

View File

@ -1,10 +0,0 @@
#include "x86.h"
#include "device.h"
uint16_t *vmem = (void *)0xa0000;
void init_vga(){
}
void draw_pixel(int x,int y,int color){
vmem[x * WIDTH + y] = 0x0;
}

View File

@ -1,49 +0,0 @@
#include "common.h"
#include "x86.h"
#include "device.h"
void enter_user_space(uint32_t);
void
kentry(void) {
printk("Hello, welcome to kernel!\n");
init_serial();
printk("serial initialization complete!\n");
init_idt();
printk("idt initialization complete!\n");
init_intr();
printk("interrupt initialization complete!\n");
init_seg();
printk("segment initialization complete!\n");
init_vga();
printk("vga initialization complete!\n");
printk("loading files...\n");
uint32_t entry = load_umain();
printk("leaving kernel, entering user space!\n");
enter_user_space(entry);
printk("should not reach here!\n");
assert(0);
}
void
enter_user_space(uint32_t entry) {
/*
* Before enter user space
* you should set the right segment registers here
* and use 'iret' to jump to ring3
*
*/
asm volatile("movw %%ax,%%es":: "a" (USEL(SEG_UDATA)));
asm volatile("movw %%ax,%%ds":: "a" (USEL(SEG_UDATA)));
asm volatile("pushl %0 \n\t"
"pushl %1 \n\t"
"pushl $0x2 \n\t"
"pushl %2 \n\t"
"pushl %3 \n\t"
"iret \n\t"
::"i"(USEL(SEG_UDATA)),
"i"(STACK),
"i"(USEL(SEG_UCODE)),
"g"(entry));
}

View File

@ -1,27 +0,0 @@
#include "x86.h"
#include "device.h"
SegDesc gdt[NR_SEGMENTS]; // the new GDT
TSS tss;
void
init_seg() {
// setup kernel segements
gdt[SEG_KCODE] = SEG(STA_X | STA_R, 0, 0xffffffff, DPL_KERN);
gdt[SEG_KDATA] = SEG(STA_W, 0, 0xffffffff, DPL_KERN);
gdt[SEG_UCODE] = SEG(STA_X | STA_R, USER_CS_BASE, 0xffffffff, DPL_USER);
gdt[SEG_UDATA] = SEG(STA_W, USER_SS_BASE, 0xffffffff, DPL_USER);
gdt[SEG_TSS] = SEG16(STS_T32A, &tss, sizeof(TSS)-1, DPL_KERN);
gdt[SEG_TSS].s = 0;
set_gdt(gdt, sizeof(gdt));
tss.esp0 = STACK;
tss.ss0 = KSEL(SEG_KDATA);
ltr(KSEL(SEG_TSS));
/*设置正确的段寄存器*/
asm volatile("movw %%ax,%%es":: "a" (KSEL(SEG_KDATA)));
asm volatile("movw %%ax,%%ds":: "a" (KSEL(SEG_KDATA)));
asm volatile("movw %%ax,%%ss":: "a" (KSEL(SEG_KDATA)));
lldt(0);
}

View File

@ -1,8 +0,0 @@
#ifndef __DRAW_H__
#define __DRAW_H__
void draw_pixel(int x,int y,char color);
void prepare_buffer();
void draw_character(char ch, int x, int y, int color);
void draw_string(const char *str, int x, int y, int color);
#endif

View File

@ -1,5 +0,0 @@
#ifndef __STDIO_H__
#define __STDIO_H__
void printf(const char *format,...);
#endif

View File

@ -1,104 +0,0 @@
#ifndef __STRING_H__
#define __STRING_H__
#include "types.h"
uint32_t strlen(const char *str);
int strcmp(char *str1, int len, char *str2);
void i2str(char *str,int num);
void x2str(char *str, int num);
uint32_t strlen(const char *str) {
/*return lenth of str*/
uint32_t count = 0;
for(;str[count] != '\0';count++);
return count;
}
int strcmp(char *str1, int len, char *str2) {
/*return 0 when str1 == str2
else return -1*/
int i;
for(i = 0; i < len; i++)
if(str1[i] != str2[i])
return -1;
return 0;
}
void i2str(char *str,int num) {
int count = 0;
int pre_num = num;
if(num == 0) {
str[0] = '0';
str[1] = '\0';
}
else {
char sign = (uint32_t)num >> 31;
if(sign == 1) {
if(num == 0x80000000) {
num = ~num;
pre_num = num;
count++;
str[0] = '-';
for(count = 0; num != 0; count++)
num = num / 10;
num = pre_num;
int tail = count;
str[count] = '\0';
for(;num != 0; count--) {
str[count] = (char)(num % 10 + '0');
num = num / 10;
}
str[tail]++;
return;
}
else {
num = ~num + 1;
pre_num = num;
for(count = 0; num != 0; count++)
num = num / 10;
count++;
str[0] = '-';
}
}
if(sign == 0)
for(count = 0; num != 0; count++)
num = num / 10;
num = pre_num;
str[count] = '\0';
for(;num != 0; count--) {
str[count - 1] = (char)(num % 10 + '0');
num = num / 10;
}
}
}
void x2str(char *str, int num) {
int count = 0;
int pre_num = num;
if(num == 0) {
str[0] = '0';
str[1] = '\0';
return;
}
for(; num != 0; count++) {
num = (uint32_t)num >> 4;
}
num = pre_num;
str[count] = '\0';
for(;num != 0; count--) {
switch((uint32_t)num % 16) {
case 10:str[count - 1] = 'a';break;
case 11:str[count - 1] = 'b';break;
case 12:str[count - 1] = 'c';break;
case 13:str[count - 1] = 'd';break;
case 14:str[count - 1] = 'e';break;
case 15:str[count - 1] = 'f';break;
default :str[count - 1] = (char)((uint32_t)num % 16 + '0');
}
num = (uint32_t)num >> 4;
}
}
#endif

View File

@ -1,17 +0,0 @@
#ifndef __TYPES_H__
#define __TYPES_H__
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned short uint16_t;
typedef short int16_t;
typedef unsigned char uint8_t;
typedef char int8_t;
typedef unsigned char boolean;
typedef uint32_t size_t;
typedef int32_t pid_t;
#endif

View File

@ -1,6 +0,0 @@
#ifndef __TIME_H__
#define __TIME_H__
int getCount();
void setCompare(int count);
#endif

View File

@ -1,8 +0,0 @@
#ifndef __ARCH_LIB__
#define __ARCH_LIB__
#define VMEM (void*)0xa0000
#define VMEM_SIZE (0xbffff - 0xa0000)
#define WIDTH 640
#define HEIGHT 480
#endif

View File

@ -1,78 +0,0 @@
ADD
ADDU
ADDI
ADDIU
SUB
SUBU
AND
ANDI
OR
ORI
XOR
XORI
NOR
SLT
SLTU
SLTI
SLTIU
SLL
SLLV
SRL
SRLV
SRA
SRAV
CLO
SEH
SEB
CLZ
BEQ
BEQL
BGEZ
BGTZ
BLEZ
BLTZ
BNE
TEQ
TEQI
TGE
TGEI
TGEU
TGEIU
TLT
TLTI
TLTU
TLTIU
TNE
TNEI
J
JAL
JR
MOVN
MOVZ
LUI
MUL
MULT
MULTU
DIV
DIVU
MFHI
MTHI
MFLO
MTLO
LB
LBU
LH
LHU
LW
SB
SH
SW
LWL
LWR
SWL
SWR
MFC0
MTC0
SYSCALL
ERET
NOP

View File

@ -1,13 +0,0 @@
with open('mips_out/code.txt') as code_file, open ('python/instr.txt') as instr_file:
instr_list = []
for line in instr_file:
instr_list.append(line[:len(line)-1].lower())
#print instruction set
print instr_list
for line in code_file:
content = line.split('\t\n')
if len(content) >= 3:
if content[2] not in instr_list:
print content[2] + ' is an illegal instruction !'

View File

@ -1,41 +0,0 @@
ARCH = mips
CROSS_COMPILE = mips-linux-gnu-
AS = $(CROSS_COMPILE)as
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
CFLAGS = -MD -fno-pic -static -fno-strict-aliasing -fno-builtin -EB
CFLAGS += -fno-stack-protector -mno-check-zero-division -fno-delayed-branch
CFLAGS += -Wall -Werror -march=mips32 -mno-llsc
CFLAGS += -mno-mad -std=gnu99
CFLAGS += -I../../../include/common -I../../../include/$(ARCH) -O2 -Wno-unused-function
CFLAGS += -mno-abicalls -g
CFLAGS += -D DEPLOY
SCFLAGS = -MD -fno-pic -static -fno-strict-aliasing -fno-builtin
SCFLAGS += -fno-stack-protector -mno-check-zero-division -fno-delayed-branch
SCFLAGS += -Wall -Werror -march=mips32 -mno-llsc -mno-imadd -mno-mad
SCFLAGS += -I../../../include/common -I../../../include/$(ARCH) -O2 -S -Wno-unused-function
ASFLAGS = -MD -mno-check-zero-division -mips32 -O0 -mno-abicalls
ASFLAGS += -fno-pic -fno-delayed-branch
LDFLAGS =
OBJ_DIR = obj
CSRC = $(shell find ../../test/ -name "*.c")
SSRC = $(shell find ../../test/ -name "*.S")
LIBS = ../../../Lib/$(ARCH)/libam-$(ARCH).a
OBJECTS = $(SSRC:%.S=$(OBJ_DIR)/%.o) $(CSRC:%.c=$(OBJ_DIR)/%.o)
DOT_D = $(SSRC:.S=.d) $(CSRC:.c=.d)
ASMS = $(CSRC:.c=.S)
umain: ../../../build/$(ARCH)/*.o $(OBJECTS)
$(LD) $(LDFLAGS) -T loader.ld -o ../../test/umain ../../../build/$(ARCH)/*.o $(OBJECTS) $(LIBS)
clean:
rm -rf $(OBJECTS) $(OBJECTS:.o=.d) ../../test/umain obj ../test
# Common rule
$(OBJ_DIR)/%.o: %.[cS]
@mkdir -p `dirname $@`
$(CC) $(CFLAGS) -c $< -o $@

View File

@ -1,8 +0,0 @@
SECTIONS
{
. = 0x00000000;
.text : AT(0x00100000) { *(.text) }
.data : { *(.data) }
.bss : { *(.bss) }
stack_top = .;
}

View File

@ -1,28 +0,0 @@
ARCH = x86
CC = gcc
LD = ld
CFLAGS = -m32 -march=i386 -static -MD -std=gnu89 -ggdb -g\
-fno-builtin -fno-stack-protector -fno-omit-frame-pointer \
-Wall -Werror -O2 -I../../../include/common -I../../../include/$(ARCH)
ASFLAGS = -ggdb -m32 -MD
LDFLAGS = -melf_i386
OBJ_DIR = obj
CSRC = $(shell find ../../test/ -name "*.c")
SSRC = $(shell find ../../test/ -name "*.S")
LIBS = ../../../Lib/$(ARCH)/libam-$(ARCH).a
OBJECTS = $(SSRC:%.S=$(OBJ_DIR)/%.o) $(CSRC:%.c=$(OBJ_DIR)/%.o)
DOT_D = $(SSRC:.S=.d) $(CSRC:.c=.d)
ASMS = $(CSRC:.c=.S)
umain: $(OBJECTS)
$(LD) $(LDFLAGS) -e main -Ttext 0x200000 -o ../../test/umain $(OBJECTS) $(LIBS)
objdump -d ../../test/umain > ../../test/umain.s
clean:
rm -rf $(OBJECTS) $(OBJECTS:.o=.d) ../../test/umain obj ../test
# Common rule
$(OBJ_DIR)/%.o: %.[cS]
@mkdir -p `dirname $@`
$(CC) $(CFLAGS) -c $< -o $@

View File

@ -1,13 +0,0 @@
#include <stdio.h>
#include <draw.h>
int main(){
//printf("Hello,world\n");
printf("Hello,world");
int i = 0;
short *vmem = (void *)0xb8000;
for(i = 0; i < 100; i++)
vmem[i] = 'h' + 0x0d00;
while(1);
return 0;
}

View File

@ -1,448 +0,0 @@
../../test/umain: file format elf32-i386
Disassembly of section .text:
00200000 <main>:
200000: 8d 4c 24 04 lea 0x4(%esp),%ecx
200004: 83 e4 f0 and $0xfffffff0,%esp
200007: ff 71 fc pushl -0x4(%ecx)
20000a: 55 push %ebp
20000b: 89 e5 mov %esp,%ebp
20000d: 51 push %ecx
20000e: 83 ec 10 sub $0x10,%esp
200011: 68 24 04 20 00 push $0x200424
200016: e8 21 02 00 00 call 20023c <printf>
20001b: 83 c4 10 add $0x10,%esp
20001e: b8 00 80 0b 00 mov $0xb8000,%eax
200023: 90 nop
200024: 66 c7 00 68 0d movw $0xd68,(%eax)
200029: 83 c0 02 add $0x2,%eax
20002c: 3d c8 80 0b 00 cmp $0xb80c8,%eax
200031: 75 f1 jne 200024 <main+0x24>
200033: eb fe jmp 200033 <main+0x33>
200035: 66 90 xchg %ax,%ax
200037: 90 nop
00200038 <x2str.part.1>:
200038: 85 d2 test %edx,%edx
20003a: 74 68 je 2000a4 <x2str.part.1+0x6c>
20003c: 55 push %ebp
20003d: 89 e5 mov %esp,%ebp
20003f: 53 push %ebx
200040: 89 d3 mov %edx,%ebx
200042: 31 c9 xor %ecx,%ecx
200044: 41 inc %ecx
200045: c1 eb 04 shr $0x4,%ebx
200048: 75 fa jne 200044 <x2str.part.1+0xc>
20004a: 01 c8 add %ecx,%eax
20004c: c6 00 00 movb $0x0,(%eax)
20004f: 90 nop
200050: 89 d3 mov %edx,%ebx
200052: 83 e3 0f and $0xf,%ebx
200055: 8d 4b f6 lea -0xa(%ebx),%ecx
200058: 83 f9 05 cmp $0x5,%ecx
20005b: 77 3f ja 20009c <x2str.part.1+0x64>
20005d: ff 24 8d 30 04 20 00 jmp *0x200430(,%ecx,4)
200064: c6 40 ff 65 movb $0x65,-0x1(%eax)
200068: 48 dec %eax
200069: c1 ea 04 shr $0x4,%edx
20006c: 75 e2 jne 200050 <x2str.part.1+0x18>
20006e: 5b pop %ebx
20006f: 5d pop %ebp
200070: c3 ret
200071: 8d 76 00 lea 0x0(%esi),%esi
200074: c6 40 ff 64 movb $0x64,-0x1(%eax)
200078: eb ee jmp 200068 <x2str.part.1+0x30>
20007a: 66 90 xchg %ax,%ax
20007c: c6 40 ff 63 movb $0x63,-0x1(%eax)
200080: eb e6 jmp 200068 <x2str.part.1+0x30>
200082: 66 90 xchg %ax,%ax
200084: c6 40 ff 62 movb $0x62,-0x1(%eax)
200088: eb de jmp 200068 <x2str.part.1+0x30>
20008a: 66 90 xchg %ax,%ax
20008c: c6 40 ff 61 movb $0x61,-0x1(%eax)
200090: eb d6 jmp 200068 <x2str.part.1+0x30>
200092: 66 90 xchg %ax,%ax
200094: c6 40 ff 66 movb $0x66,-0x1(%eax)
200098: eb ce jmp 200068 <x2str.part.1+0x30>
20009a: 66 90 xchg %ax,%ax
20009c: 83 c3 30 add $0x30,%ebx
20009f: 88 58 ff mov %bl,-0x1(%eax)
2000a2: eb c4 jmp 200068 <x2str.part.1+0x30>
2000a4: c6 00 00 movb $0x0,(%eax)
2000a7: c3 ret
002000a8 <strlen>:
2000a8: 55 push %ebp
2000a9: 89 e5 mov %esp,%ebp
2000ab: 8b 55 08 mov 0x8(%ebp),%edx
2000ae: 31 c0 xor %eax,%eax
2000b0: 80 3a 00 cmpb $0x0,(%edx)
2000b3: 74 0a je 2000bf <strlen+0x17>
2000b5: 8d 76 00 lea 0x0(%esi),%esi
2000b8: 40 inc %eax
2000b9: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1)
2000bd: 75 f9 jne 2000b8 <strlen+0x10>
2000bf: 5d pop %ebp
2000c0: c3 ret
2000c1: 8d 76 00 lea 0x0(%esi),%esi
002000c4 <strcmp>:
2000c4: 55 push %ebp
2000c5: 89 e5 mov %esp,%ebp
2000c7: 56 push %esi
2000c8: 53 push %ebx
2000c9: 8b 4d 08 mov 0x8(%ebp),%ecx
2000cc: 8b 75 0c mov 0xc(%ebp),%esi
2000cf: 8b 5d 10 mov 0x10(%ebp),%ebx
2000d2: 85 f6 test %esi,%esi
2000d4: 7e 17 jle 2000ed <strcmp+0x29>
2000d6: 8a 03 mov (%ebx),%al
2000d8: 38 01 cmp %al,(%ecx)
2000da: 75 18 jne 2000f4 <strcmp+0x30>
2000dc: 31 c0 xor %eax,%eax
2000de: eb 08 jmp 2000e8 <strcmp+0x24>
2000e0: 8a 14 03 mov (%ebx,%eax,1),%dl
2000e3: 38 14 01 cmp %dl,(%ecx,%eax,1)
2000e6: 75 0c jne 2000f4 <strcmp+0x30>
2000e8: 40 inc %eax
2000e9: 39 c6 cmp %eax,%esi
2000eb: 75 f3 jne 2000e0 <strcmp+0x1c>
2000ed: 31 c0 xor %eax,%eax
2000ef: 5b pop %ebx
2000f0: 5e pop %esi
2000f1: 5d pop %ebp
2000f2: c3 ret
2000f3: 90 nop
2000f4: b8 ff ff ff ff mov $0xffffffff,%eax
2000f9: 5b pop %ebx
2000fa: 5e pop %esi
2000fb: 5d pop %ebp
2000fc: c3 ret
2000fd: 8d 76 00 lea 0x0(%esi),%esi
00200100 <i2str>:
200100: 55 push %ebp
200101: 89 e5 mov %esp,%ebp
200103: 57 push %edi
200104: 56 push %esi
200105: 53 push %ebx
200106: 8b 4d 0c mov 0xc(%ebp),%ecx
200109: 85 c9 test %ecx,%ecx
20010b: 74 5f je 20016c <i2str+0x6c>
20010d: 85 c9 test %ecx,%ecx
20010f: 78 6b js 20017c <i2str+0x7c>
200111: 89 ce mov %ecx,%esi
200113: 31 db xor %ebx,%ebx
200115: bf 67 66 66 66 mov $0x66666667,%edi
20011a: 66 90 xchg %ax,%ax
20011c: 89 f0 mov %esi,%eax
20011e: f7 ef imul %edi
200120: 89 d0 mov %edx,%eax
200122: c1 f8 02 sar $0x2,%eax
200125: c1 fe 1f sar $0x1f,%esi
200128: 43 inc %ebx
200129: 29 f0 sub %esi,%eax
20012b: 89 c6 mov %eax,%esi
20012d: 75 ed jne 20011c <i2str+0x1c>
20012f: 8b 45 08 mov 0x8(%ebp),%eax
200132: c6 04 18 00 movb $0x0,(%eax,%ebx,1)
200136: 03 5d 08 add 0x8(%ebp),%ebx
200139: be 67 66 66 66 mov $0x66666667,%esi
20013e: 66 90 xchg %ax,%ax
200140: 89 c8 mov %ecx,%eax
200142: f7 ee imul %esi
200144: 89 d0 mov %edx,%eax
200146: c1 f8 02 sar $0x2,%eax
200149: 89 ca mov %ecx,%edx
20014b: c1 fa 1f sar $0x1f,%edx
20014e: 29 d0 sub %edx,%eax
200150: 8d 14 80 lea (%eax,%eax,4),%edx
200153: 01 d2 add %edx,%edx
200155: 29 d1 sub %edx,%ecx
200157: 83 c1 30 add $0x30,%ecx
20015a: 88 4b ff mov %cl,-0x1(%ebx)
20015d: 89 c1 mov %eax,%ecx
20015f: 4b dec %ebx
200160: 85 c0 test %eax,%eax
200162: 75 dc jne 200140 <i2str+0x40>
200164: 5b pop %ebx
200165: 5e pop %esi
200166: 5f pop %edi
200167: 5d pop %ebp
200168: c3 ret
200169: 8d 76 00 lea 0x0(%esi),%esi
20016c: 8b 45 08 mov 0x8(%ebp),%eax
20016f: c6 00 30 movb $0x30,(%eax)
200172: c6 40 01 00 movb $0x0,0x1(%eax)
200176: 5b pop %ebx
200177: 5e pop %esi
200178: 5f pop %edi
200179: 5d pop %ebp
20017a: c3 ret
20017b: 90 nop
20017c: 81 f9 00 00 00 80 cmp $0x80000000,%ecx
200182: 74 44 je 2001c8 <i2str+0xc8>
200184: f7 d9 neg %ecx
200186: 0f 84 83 00 00 00 je 20020f <i2str+0x10f>
20018c: 89 cb mov %ecx,%ebx
20018e: 31 f6 xor %esi,%esi
200190: bf 67 66 66 66 mov $0x66666667,%edi
200195: eb 03 jmp 20019a <i2str+0x9a>
200197: 90 nop
200198: 89 d6 mov %edx,%esi
20019a: 89 d8 mov %ebx,%eax
20019c: f7 ef imul %edi
20019e: 89 d0 mov %edx,%eax
2001a0: c1 f8 02 sar $0x2,%eax
2001a3: c1 fb 1f sar $0x1f,%ebx
2001a6: 8d 56 01 lea 0x1(%esi),%edx
2001a9: 29 d8 sub %ebx,%eax
2001ab: 89 c3 mov %eax,%ebx
2001ad: 75 e9 jne 200198 <i2str+0x98>
2001af: 83 c6 02 add $0x2,%esi
2001b2: 89 f3 mov %esi,%ebx
2001b4: 8b 45 08 mov 0x8(%ebp),%eax
2001b7: c6 00 2d movb $0x2d,(%eax)
2001ba: c6 04 30 00 movb $0x0,(%eax,%esi,1)
2001be: 85 c9 test %ecx,%ecx
2001c0: 0f 85 70 ff ff ff jne 200136 <i2str+0x36>
2001c6: eb 9c jmp 200164 <i2str+0x64>
2001c8: 8b 45 08 mov 0x8(%ebp),%eax
2001cb: c6 00 2d movb $0x2d,(%eax)
2001ce: c6 40 0a 00 movb $0x0,0xa(%eax)
2001d2: 8d 58 0a lea 0xa(%eax),%ebx
2001d5: b9 ff ff ff 7f mov $0x7fffffff,%ecx
2001da: be 0a 00 00 00 mov $0xa,%esi
2001df: bf 67 66 66 66 mov $0x66666667,%edi
2001e4: 89 c8 mov %ecx,%eax
2001e6: 99 cltd
2001e7: f7 fe idiv %esi
2001e9: 83 c2 30 add $0x30,%edx
2001ec: 88 13 mov %dl,(%ebx)
2001ee: 89 c8 mov %ecx,%eax
2001f0: f7 ef imul %edi
2001f2: 89 d0 mov %edx,%eax
2001f4: c1 f8 02 sar $0x2,%eax
2001f7: c1 f9 1f sar $0x1f,%ecx
2001fa: 29 c8 sub %ecx,%eax
2001fc: 89 c1 mov %eax,%ecx
2001fe: 4b dec %ebx
2001ff: 39 5d 08 cmp %ebx,0x8(%ebp)
200202: 75 e0 jne 2001e4 <i2str+0xe4>
200204: 8b 45 08 mov 0x8(%ebp),%eax
200207: fe 40 0a incb 0xa(%eax)
20020a: e9 55 ff ff ff jmp 200164 <i2str+0x64>
20020f: be 01 00 00 00 mov $0x1,%esi
200214: bb 01 00 00 00 mov $0x1,%ebx
200219: eb 99 jmp 2001b4 <i2str+0xb4>
20021b: 90 nop
0020021c <x2str>:
20021c: 55 push %ebp
20021d: 89 e5 mov %esp,%ebp
20021f: 8b 45 08 mov 0x8(%ebp),%eax
200222: 8b 55 0c mov 0xc(%ebp),%edx
200225: 85 d2 test %edx,%edx
200227: 74 07 je 200230 <x2str+0x14>
200229: 5d pop %ebp
20022a: e9 09 fe ff ff jmp 200038 <x2str.part.1>
20022f: 90 nop
200230: c6 00 30 movb $0x30,(%eax)
200233: c6 40 01 00 movb $0x0,0x1(%eax)
200237: 5d pop %ebp
200238: c3 ret
200239: 8d 76 00 lea 0x0(%esi),%esi
0020023c <printf>:
20023c: 55 push %ebp
20023d: 89 e5 mov %esp,%ebp
20023f: 57 push %edi
200240: 56 push %esi
200241: 53 push %ebx
200242: 83 ec 6c sub $0x6c,%esp
200245: 8b 55 08 mov 0x8(%ebp),%edx
200248: 8a 02 mov (%edx),%al
20024a: 84 c0 test %al,%al
20024c: 74 58 je 2002a6 <printf+0x6a>
20024e: 89 d1 mov %edx,%ecx
200250: c7 45 94 00 00 00 00 movl $0x0,-0x6c(%ebp)
200257: 31 db xor %ebx,%ebx
200259: 31 ff xor %edi,%edi
20025b: 8d 75 98 lea -0x68(%ebp),%esi
20025e: 66 90 xchg %ax,%ax
200260: 3c 25 cmp $0x25,%al
200262: 0f 85 c5 00 00 00 jne 20032d <printf+0xf1>
200268: 8b 45 94 mov -0x6c(%ebp),%eax
20026b: 8a 44 02 01 mov 0x1(%edx,%eax,1),%al
20026f: 3c 73 cmp $0x73,%al
200271: 75 3b jne 2002ae <printf+0x72>
200273: 8b 54 bd 0c mov 0xc(%ebp,%edi,4),%edx
200277: 31 c0 xor %eax,%eax
200279: 80 3a 00 cmpb $0x0,(%edx)
20027c: 74 09 je 200287 <printf+0x4b>
20027e: 66 90 xchg %ax,%ax
200280: 40 inc %eax
200281: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1)
200285: 75 f9 jne 200280 <printf+0x44>
200287: 83 ec 08 sub $0x8,%esp
20028a: 50 push %eax
20028b: 52 push %edx
20028c: e8 ef 00 00 00 call 200380 <print>
200291: 47 inc %edi
200292: 43 inc %ebx
200293: 83 c4 10 add $0x10,%esp
200296: 43 inc %ebx
200297: 8b 55 08 mov 0x8(%ebp),%edx
20029a: 89 5d 94 mov %ebx,-0x6c(%ebp)
20029d: 8d 0c 1a lea (%edx,%ebx,1),%ecx
2002a0: 8a 01 mov (%ecx),%al
2002a2: 84 c0 test %al,%al
2002a4: 75 ba jne 200260 <printf+0x24>
2002a6: 8d 65 f4 lea -0xc(%ebp),%esp
2002a9: 5b pop %ebx
2002aa: 5e pop %esi
2002ab: 5f pop %edi
2002ac: 5d pop %ebp
2002ad: c3 ret
2002ae: 3c 64 cmp $0x64,%al
2002b0: 75 30 jne 2002e2 <printf+0xa6>
2002b2: 83 ec 08 sub $0x8,%esp
2002b5: ff 74 bd 0c pushl 0xc(%ebp,%edi,4)
2002b9: 56 push %esi
2002ba: e8 41 fe ff ff call 200100 <i2str>
2002bf: 83 c4 10 add $0x10,%esp
2002c2: 31 c0 xor %eax,%eax
2002c4: 80 7d 98 00 cmpb $0x0,-0x68(%ebp)
2002c8: 74 07 je 2002d1 <printf+0x95>
2002ca: 40 inc %eax
2002cb: 80 3c 06 00 cmpb $0x0,(%esi,%eax,1)
2002cf: 75 f9 jne 2002ca <printf+0x8e>
2002d1: 83 ec 08 sub $0x8,%esp
2002d4: 50 push %eax
2002d5: 56 push %esi
2002d6: e8 a5 00 00 00 call 200380 <print>
2002db: 47 inc %edi
2002dc: 43 inc %ebx
2002dd: 83 c4 10 add $0x10,%esp
2002e0: eb b4 jmp 200296 <printf+0x5a>
2002e2: 3c 78 cmp $0x78,%al
2002e4: 75 2a jne 200310 <printf+0xd4>
2002e6: 8b 54 bd 0c mov 0xc(%ebp,%edi,4),%edx
2002ea: 85 d2 test %edx,%edx
2002ec: 75 56 jne 200344 <printf+0x108>
2002ee: c6 45 98 30 movb $0x30,-0x68(%ebp)
2002f2: c6 45 99 00 movb $0x0,-0x67(%ebp)
2002f6: 31 c0 xor %eax,%eax
2002f8: 40 inc %eax
2002f9: 80 3c 06 00 cmpb $0x0,(%esi,%eax,1)
2002fd: 75 f9 jne 2002f8 <printf+0xbc>
2002ff: 83 ec 08 sub $0x8,%esp
200302: 50 push %eax
200303: 56 push %esi
200304: e8 77 00 00 00 call 200380 <print>
200309: 47 inc %edi
20030a: 43 inc %ebx
20030b: 83 c4 10 add $0x10,%esp
20030e: eb 86 jmp 200296 <printf+0x5a>
200310: 3c 63 cmp $0x63,%al
200312: 75 1d jne 200331 <printf+0xf5>
200314: 83 ec 08 sub $0x8,%esp
200317: 6a 01 push $0x1
200319: 8d 44 bd 0c lea 0xc(%ebp,%edi,4),%eax
20031d: 50 push %eax
20031e: e8 5d 00 00 00 call 200380 <print>
200323: 47 inc %edi
200324: 43 inc %ebx
200325: 83 c4 10 add $0x10,%esp
200328: e9 69 ff ff ff jmp 200296 <printf+0x5a>
20032d: 3c 0a cmp $0xa,%al
20032f: 74 36 je 200367 <printf+0x12b>
200331: 83 ec 08 sub $0x8,%esp
200334: 6a 01 push $0x1
200336: 51 push %ecx
200337: e8 44 00 00 00 call 200380 <print>
20033c: 83 c4 10 add $0x10,%esp
20033f: e9 52 ff ff ff jmp 200296 <printf+0x5a>
200344: 89 f0 mov %esi,%eax
200346: e8 ed fc ff ff call 200038 <x2str.part.1>
20034b: 80 7d 98 00 cmpb $0x0,-0x68(%ebp)
20034f: 75 a5 jne 2002f6 <printf+0xba>
200351: 31 c0 xor %eax,%eax
200353: 83 ec 08 sub $0x8,%esp
200356: 50 push %eax
200357: 56 push %esi
200358: e8 23 00 00 00 call 200380 <print>
20035d: 47 inc %edi
20035e: 43 inc %ebx
20035f: 83 c4 10 add $0x10,%esp
200362: e9 2f ff ff ff jmp 200296 <printf+0x5a>
200367: 83 ec 08 sub $0x8,%esp
20036a: 6a 01 push $0x1
20036c: 68 48 04 20 00 push $0x200448
200371: e8 0a 00 00 00 call 200380 <print>
200376: 83 c4 10 add $0x10,%esp
200379: e9 18 ff ff ff jmp 200296 <printf+0x5a>
20037e: 66 90 xchg %ax,%ax
00200380 <print>:
200380: 55 push %ebp
200381: 89 e5 mov %esp,%ebp
200383: 57 push %edi
200384: 56 push %esi
200385: 53 push %ebx
200386: 51 push %ecx
200387: 8b 4d 08 mov 0x8(%ebp),%ecx
20038a: 80 39 5c cmpb $0x5c,(%ecx)
20038d: 74 65 je 2003f4 <print+0x74>
20038f: a1 cc 15 20 00 mov 0x2015cc,%eax
200394: 89 45 f0 mov %eax,-0x10(%ebp)
200397: 89 c6 mov %eax,%esi
200399: 8b 3d d0 15 20 00 mov 0x2015d0,%edi
20039f: ba 01 00 00 00 mov $0x1,%edx
2003a4: b8 04 00 00 00 mov $0x4,%eax
2003a9: 8b 5d 0c mov 0xc(%ebp),%ebx
2003ac: cd 80 int $0x80
2003ae: 89 c3 mov %eax,%ebx
2003b0: 8b 4d f0 mov -0x10(%ebp),%ecx
2003b3: 01 c1 add %eax,%ecx
2003b5: 89 0d cc 15 20 00 mov %ecx,0x2015cc
2003bb: 83 f9 4f cmp $0x4f,%ecx
2003be: 7e 29 jle 2003e9 <print+0x69>
2003c0: b8 67 66 66 66 mov $0x66666667,%eax
2003c5: f7 e9 imul %ecx
2003c7: 89 d0 mov %edx,%eax
2003c9: c1 f8 05 sar $0x5,%eax
2003cc: 89 ca mov %ecx,%edx
2003ce: c1 fa 1f sar $0x1f,%edx
2003d1: 29 d0 sub %edx,%eax
2003d3: 01 c7 add %eax,%edi
2003d5: 89 3d d0 15 20 00 mov %edi,0x2015d0
2003db: 8d 04 80 lea (%eax,%eax,4),%eax
2003de: c1 e0 04 shl $0x4,%eax
2003e1: 29 c1 sub %eax,%ecx
2003e3: 89 0d cc 15 20 00 mov %ecx,0x2015cc
2003e9: 85 db test %ebx,%ebx
2003eb: 78 05 js 2003f2 <print+0x72>
2003ed: 39 5d 0c cmp %ebx,0xc(%ebp)
2003f0: 74 27 je 200419 <print+0x99>
2003f2: eb fe jmp 2003f2 <print+0x72>
2003f4: 80 79 01 6e cmpb $0x6e,0x1(%ecx)
2003f8: 75 95 jne 20038f <print+0xf>
2003fa: 80 79 02 00 cmpb $0x0,0x2(%ecx)
2003fe: 75 8f jne 20038f <print+0xf>
200400: a1 d0 15 20 00 mov 0x2015d0,%eax
200405: 8d 78 01 lea 0x1(%eax),%edi
200408: 89 3d d0 15 20 00 mov %edi,0x2015d0
20040e: 31 f6 xor %esi,%esi
200410: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
200417: eb 86 jmp 20039f <print+0x1f>
200419: 8b 45 0c mov 0xc(%ebp),%eax
20041c: 5a pop %edx
20041d: 5b pop %ebx
20041e: 5e pop %esi
20041f: 5f pop %edi
200420: 5d pop %ebp
200421: c3 ret

72
Makefile Normal file
View File

@ -0,0 +1,72 @@
# ARCH in [mips32-npc, x86-linux, x86-qemu]
ARCH = mips32-npc
# APP in [hello, video]
APP = hello
ifeq ($(ARCH), mips32-npc)
CROSS_COMPILE = mips-linux-gnu-
endif
AS = $(CROSS_COMPILE)as
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
LD = $(CROSS_COMPILE)ld
$(shell mkdir -p build/)
# AM library archive
AM_PATH = ./am/arch/$(ARCH)
AM_LIB = ./build/libam-$(ARCH).a
AM_SRC = $(shell find -L $(AM_PATH)/src -name "*.c" -o -name "*.cpp" -o -name "*.S")
AM_OBJ = $(addsuffix .o, $(basename $(AM_SRC)))
# Application archive
APP_PATH = ./apps/$(APP)
APP_LIB = ./build/$(APP)-$(ARCH).a
APP_SRC = $(shell find -L $(APP_PATH)/src -name "*.c" -o -name "*.cpp" -o -name "*.S")
APP_OBJ = $(addsuffix .o, $(basename $(APP_SRC)))
# Basic compilation flags
CFLAGS += -std=gnu99 -I ./am/ -I./$(AM_PATH)/include -I./$(APP_PATH)/include -O2 -MD -Wall -Werror -ggdb
CXXFLAGS += -std=c++11 -I ./am/ -I./$(AM_PATH)/include -I./$(APP_PATH)/include -O2 -MD -Wall -Werror -ggdb
ASFLAGS += -I ./am/ -I./$(AM_PATH)/include -I./$(APP_PATH)/include
# Arch-dependent compilation flags
ifeq ($(ARCH), mips32-npc)
CXX = $(CROSS_COMPILE)g++-5
CFLAGS += -fno-pic -static -fno-strict-aliasing -fno-builtin -fno-stack-protector -fno-delayed-branch -mno-abicalls -march=mips32
CXXFLAGS += -fno-pic -static -fno-strict-aliasing -fno-builtin -fno-stack-protector -fno-delayed-branch -mno-abicalls -march=mips32 -ffreestanding -fno-rtti -fno-exceptions
ASFLAGS += -march=mips32
endif
ifeq ($(ARCH), x86-qemu)
CFLAGS += -m32 -fno-builtin -fno-stack-protector -fno-omit-frame-pointer
CXXFLAGS += -m32 -fno-builtin -fno-stack-protector -fno-omit-frame-pointer -ffreestanding -fno-rtti -fno-exceptions
ASFLAGS += -m32
endif
# The final binary (a.out)
build/a.out: $(AM_LIB) $(APP_LIB)
$(AM_PATH)/img/build build/a.out $(shell readlink -f $(APP_LIB)) $(shell readlink -f $(AM_LIB))
# AM library
$(AM_LIB): $(AM_OBJ)
ar rcs $(AM_LIB) $(AM_OBJ)
# Application
$(APP_LIB): $(APP_OBJ)
ar rcs $(APP_LIB) $(APP_OBJ)
.PHONY: play clean
play: $(AM_LIB) build/a.out
ifeq ($(ARCH), mips32-npc)
@echo "Burn it to FPGA."
endif
ifeq ($(ARCH), x86-linux)
@./build/a.out
endif
ifeq ($(ARCH), x86-qemu)
@qemu-system-i386 -serial stdio build/a.out
endif
clean:
rm -rf build/ $(shell find . -name "*.o" -o -name "*.d")

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# The Abstract Machine
"Abstract" machine for building a complete computer system from scratch.

108
am/am.h Executable file
View File

@ -0,0 +1,108 @@
/*
* The minmal architectural-independent library for
* implementing a system software
*
* Please refer to the AM specification
*/
#ifndef __AM_H__
#define __AM_H__
#include <arch.h>
typedef unsigned long ulong;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef unsigned char uchar;
#define MAX_CPU 8
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _Area {
void *start, *end;
} _Area;
// TODO: add more keys
enum {
_KEY_NONE = 0,
_KEY_UP, _KEY_DOWN, _KEY_LEFT, _KEY_RIGHT,
_KEY_Z, _KEY_X,
};
typedef struct _Screen {
int width, height;
} _Screen;
typedef struct _Protect {
_Area area;
void *ptr;
} _Protect;
// =======================================================================
// [0] Turing Machine: code execution & a heap memory
// =======================================================================
void _start();
void _trm_init();
void _putc(char ch);
void _halt(int code);
extern _Area _heap;
// =======================================================================
// [1] IO Extension
// =======================================================================
void _ioe_init();
ulong _uptime();
ulong _cycles();
int _peek_key();
typedef u32 _Pixel;
void _draw_p(int x, int y, _Pixel p);
void _draw_f(_Pixel *p);
void _draw_sync();
extern _Screen _screen;
// TODO: bus interfaces
// =======================================================================
// [2] Asynchronous Extension
// =======================================================================
void _asye_init();
void _listen(_RegSet* (*l)(int ex, _RegSet *regs));
_RegSet *_make(_Area kstack, void *entry);
void _trap();
void _idle();
void _ienable();
void _idisable();
int _istatus();
// =======================================================================
// [3] Protection Extension
// =======================================================================
void _pte_init(void*(*palloc)(), void (*pfree)(void*));
void _protect(_Protect *p);
void _release(_Protect *p);
void _map(_Protect *p, void *va, void *pa);
void _ummap(_Protect *p, void *va);
void _switch(_Protect *p);
_RegSet *_umake(_Area ustack, _Area kstack, void *entry, int argc, char **argv);
// =======================================================================
// [4] Multi-Processor Extension
// =======================================================================
void _mpe_init(void (*entry)());
int _cpu();
ulong _atomic_xchg(volatile ulong *addr, ulong newval);
void _barrier();
extern int _NR_CPU;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,7 @@
# MIPS32-NPC
AbstractMachine implementation for NJU-Personal-Computer (NPC).
## Memory Mappings
XXX - XXX: XXX

View File

@ -0,0 +1,2 @@
start.o: start.S
mips-linux-gnu-as -march=mips32 start.S -o start.o

View File

@ -0,0 +1,9 @@
.globl _start
_start:
li $sp, 0x0001fffc
jal main
.globl _qemu
_qemu:
nop
jal main

20
am/arch/mips32-npc/img/build Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
DIR=./am/arch/mips32-npc/img
DEST=$1
shift
bash -c "cd $DIR/boot && make"
mips-linux-gnu-ld -T $DIR/loader.ld -e _start -o ./build/kernel.o $DIR/boot/start.o --start-group $@ --end-group
KERN=$(readlink -f ./build/kernel.o)
# generate COE
mips-linux-gnu-objcopy -O binary $KERN ./build/kernel.bin
python $DIR/scripts/bin2text.py ./build/kernel.bin ./build/ram.txt
python $DIR/scripts/gen_bram_coe.py ./build/kernel.bin ./build/app.coe
# check instructions
mips-linux-gnu-objdump -d $KERN | python $DIR/scripts/instr_check.py

View File

@ -0,0 +1,7 @@
SECTIONS
{
. = 0x00100000;
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss) }
}

View File

@ -28,4 +28,4 @@ with open(outPath, 'w') as f:
f.write("@{0:x} {1:s} \n".format(i, contents))
# for i in range(len(bins)/4,fileSize):
# f.write("@{0:x} {1:d} \n".format(i, 0))
print "Process complete!"
print "{0} -> {1} complete!".format(inPath, outPath)

View File

@ -36,4 +36,4 @@ with open(outPath, 'w') as f:
f.write(';')
f.write('\n')
print "Process complete!"
print "{0} -> {1} complete!".format(inPath, outPath)

View File

@ -0,0 +1,89 @@
import sys
INST = """ADD
ADDU
ADDI
ADDIU
SUB
SUBU
AND
ANDI
OR
ORI
XOR
XORI
NOR
SLT
SLTU
SLTI
SLTIU
SLL
SLLV
SRL
SRLV
SRA
SRAV
CLO
SEH
SEB
CLZ
BEQ
BEQL
BGEZ
BGTZ
BLEZ
BLTZ
BNE
TEQ
TEQI
TGE
TGEI
TGEU
TGEIU
TLT
TLTI
TLTU
TLTIU
TNE
TNEI
J
JAL
JR
MOVN
MOVZ
LUI
MUL
MULT
MULTU
DIV
DIVU
MFHI
MTHI
MFLO
MTLO
LB
LBU
LH
LHU
LW
SB
SH
SW
LWL
LWR
SWL
SWR
MFC0
MTC0
SYSCALL
ERET
NOP"""
INST = [i.strip() for i in INST.strip().split('\n')]
for line in sys.stdin:
content = line.strip().split('\t')
if len(content) >= 3:
inst = content[2].upper()
if inst not in INST:
print "[INSTcheck] '{0}' is invalid.".format(inst)

View File

@ -0,0 +1,14 @@
#ifndef __ARCH_H__
#define __ARCH_H__
typedef unsigned int u32;
typedef int i32;
typedef unsigned short u16;
typedef short int i16;
typedef unsigned char u8;
typedef char i8;
typedef struct _RegSet {
} _RegSet;
#endif

View File

@ -1,5 +1,5 @@
#ifndef __ARCH_LIB__
#define __ARCH_LIB__
#ifndef __NPC_H__
#define __NPC_H__
#define VMEM ((char *)0xc0000000)
#define KEY_CODE_ADDR ((volatile unsigned int *)0xf0000000)

View File

@ -0,0 +1,33 @@
#include <am.h>
#include <npc.h>
// TODO: implement these functions.
void _trm_init() {
while (1);
}
void _ioe_init() {
}
void _halt(int code) {
}
void _putc(char ch) {
}
void _draw_f(_Pixel *p) {
}
void _draw_p(int x, int y, _Pixel p) {
}
void _draw_sync() {
}
ulong _uptime() {
return 0;
}
_Area _heap;
_Screen _screen;

View File

@ -25,7 +25,6 @@
*/
#include <stdarg.h>
#include <stdio.h>
#define putchar(c) npc_putc(c)

View File

@ -1,5 +1,5 @@
#include <arch.h>
#include <draw.h>
#include <npc.h>
int curr_line = 0;
int curr_col = 0;
@ -11,7 +11,7 @@ void npc_putc(char ch)
curr_line += 8;
}
else{
draw_character(ch,curr_line,curr_col,0x3c);
// draw_character(ch,curr_line,curr_col,0x3c);
}
if (curr_col + 8 >= SCR_WIDTH) {
curr_line += 8; curr_col = 0;
@ -19,7 +19,7 @@ void npc_putc(char ch)
curr_col += 8;
}
if(curr_line >= SCR_HEIGHT){
prepare_buffer();
// prepare_buffer();
curr_line = 0;
}
}

View File

@ -1,5 +1,5 @@
#include <arch.h>
#include <draw.h>
#include <npc.h>
char *pos = (char *)VMEM;
extern char font8x8_basic[128][8];

View File

@ -0,0 +1 @@
# MIPS32-qemu

Some files were not shown because too many files have changed in this diff Show More