finish all,bird

master
unknown 3 years ago
parent ae697778f7
commit 041650fedd

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

@ -217,7 +217,5 @@ void init(void)
}
void print_nr(int sid)
{
if (sid > 86)
printk(" --syscall: sid=%d, pid=%d\n", sid, current->pid);
{;
}

@ -0,0 +1,12 @@
--- init/main.c 2016-08-08 09:40:13.000000000 +0800
+++ init/main.c 2021-07-06 14:16:56.000000000 +0800
@@ -208,3 +208,9 @@
}
_exit(0); /* NOTE! _exit, not exit() */
}
+
+void print_nr(int sid)
+{
+ if (sid > 86)
+ printk(" --syscall: sid=%d, pid=%d\n", sid, current->pid);
+}

@ -21,22 +21,7 @@ xor %eax,%eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
#EOI
movb $0x20,%al #8259A EOI

@ -17,22 +17,7 @@ xor %eax,%eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
#EOI
movb $0x20,%al #8259A EOI

@ -354,13 +354,14 @@ void chr_dev_init(void)
static unsigned char mouse_input_count = 0; //用来记录是鼠标输入的第几个字节的全局变量
static unsigned char mouse_left_down; //用来记录鼠标左键是否按下
static unsigned char mouse_right_down; //用来记录鼠标右键是否按下
static unsigned char mouse_center_down; // 中键按下标志1表示按下了左键
static unsigned char mouse_left_move; //用来记录鼠标是否向左移动
static unsigned char mouse_down_move;//用来记录鼠标是否向下移动
static unsigned char mouse_x_overflow; // x溢出标志位1表示x位移量溢出
static unsigned char mouse_y_overflow; // y溢出标志位1表示x位移量溢出
static unsigned int mouse_x_position; //用来记录鼠标的 x 轴位置
static unsigned int mouse_y_position;//用来记录鼠标的 y 轴位置
static int mouse_x_position; //用来记录鼠标的 x 轴位置
static int mouse_y_position;//用来记录鼠标的 y 轴位置
extern struct message *headd;
void readmouse(int mousecode)
{
//printk("1\n");
@ -378,23 +379,19 @@ switch(mouse_input_count)
case 1:
//Misplaced abandonment
mouse_left_down=(mousecode &0x01) ==0x01;
mouse_center_down = (mousecode & 0x4) == 0x4;
mouse_right_down=(mousecode &0x02)==0x02;
mouse_left_move=(mousecode & 0x10)==0x10;
mouse_down_move=(mousecode & 0x20)==0x20;
mouse_x_overflow = (mousecode & 0x40) == 0x40;
mouse_y_overflow = (mousecode & 0x80) == 0x80;
mouse_input_count++;
if(mouse_left_down==1 && mouse_left_move==0 && mouse_down_move==0)
{
#ifdef CK_DEBUG
printk("[readmouse]MSG_MOUSE_LEFT_DOWN\n");
#endif
post_message(MSG_MOUSE_LEFT_DOWN);
}
if (mouse_right_down)
if (mouse_right_down==1&& mouse_left_move==0 && mouse_down_move==0)
{
#ifdef CK_DEBUG
printk("[readmouse]MSG_MOUSE_RIGHT_DOWN\n");
#endif
post_message(MSG_MOUSE_RIGHT_DOWN);
}
@ -422,12 +419,8 @@ case 3:
case 4:
//get the z but we do not need it
++mouse_input_count;
break;
}
if(mouse_input_count==4)
{
//printk("%d\n",mouse_left_down);
//printk("%d %d\n",mouse_x_position,mouse_y_position);
}
//sys_init_graphics();
}

@ -1,3 +1,4 @@
/*
* linux/kernel/system_call.s
*

@ -0,0 +1,14 @@
--- kernel/system_call.s 2015-09-03 20:21:09.000000000 +0800
+++ kernel/system_call.s 2021-07-06 14:18:56.000000000 +0800
@@ -91,6 +91,11 @@
mov %dx,%es
movl $0x17,%edx # fs points to local data space
mov %dx,%fs
+
+ pushl %eax #by wyj
+ call print_nr
+ popl %eax
+
call sys_call_table(,%eax,4)
pushl %eax
movl current,%eax

Binary file not shown.

@ -0,0 +1,434 @@
/*
* linux/mm/memory.c
*
* (C) 1991 Linus Torvalds
*/
/*
* demand-loading started 01.12.91 - seems it is high on the list of
* things wanted, and it should be easy to implement. - Linus
*/
/*
* Ok, demand-loading was easy, shared pages a little bit tricker. Shared
* pages started 02.12.91, seems to work. - Linus.
*
* Tested sharing by executing about 30 /bin/sh: under the old kernel it
* would have taken more than the 6M I have free, but it worked well as
* far as I could see.
*
* Also corrected some "invalidate()"s - I wasn't doing enough of them.
*/
#include <signal.h>
#include <asm/system.h>
#include <linux/sched.h>
#include <linux/head.h>
#include <linux/kernel.h>
volatile void do_exit(long code);
static inline volatile void oom(void)
{
printk("out of memory\n\r");
do_exit(SIGSEGV);
}
#define invalidate() \
__asm__("movl %%eax,%%cr3"::"a" (0))
/* these are not to be changed without changing head.s etc */
#define LOW_MEM 0x100000
#define PAGING_MEMORY (15*1024*1024)
#define PAGING_PAGES (PAGING_MEMORY>>12)
#define MAP_NR(addr) (((addr)-LOW_MEM)>>12)
#define USED 100
#define CODE_SPACE(addr) ((((addr)+4095)&~4095) < \
current->start_code + current->end_code)
static long HIGH_MEMORY = 0;
#define copy_page(from,to) \
__asm__("cld ; rep ; movsl"::"S" (from),"D" (to),"c" (1024))
static unsigned char mem_map [ PAGING_PAGES ] = {0,};
/*
* Get physical address of first (actually last :-) free page, and mark it
* used. If no free pages left, return 0.
*/
unsigned long get_free_page(void)
{
register unsigned long __res asm("ax");
__asm__("std ; repne ; scasb\n\t"
"jne 1f\n\t"
"movb $1,1(%%edi)\n\t"
"sall $12,%%ecx\n\t"
"addl %2,%%ecx\n\t"
"movl %%ecx,%%edx\n\t"
"movl $1024,%%ecx\n\t"
"leal 4092(%%edx),%%edi\n\t"
"rep ; stosl\n\t"
"movl %%edx,%%eax\n\t"
"1:"
"cld\n\t" /* by wyj */
:"=a" (__res)
:"0" (0),"i" (LOW_MEM),"c" (PAGING_PAGES),
"D" (mem_map+PAGING_PAGES-1)
);
return __res;
}
/*
* Free a page of memory at physical address 'addr'. Used by
* 'free_page_tables()'
*/
void free_page(unsigned long addr)
{
if (addr < LOW_MEM) return;
if (addr >= HIGH_MEMORY)
panic("trying to free nonexistent page");
addr -= LOW_MEM;
addr >>= 12;
if (mem_map[addr]--) return;
mem_map[addr]=0;
panic("trying to free free page");
}
/*
* This function frees a continuos block of page tables, as needed
* by 'exit()'. As does copy_page_tables(), this handles only 4Mb blocks.
*/
int free_page_tables(unsigned long from,unsigned long size)
{
unsigned long *pg_table;
unsigned long * dir, nr;
if (from & 0x3fffff)
panic("free_page_tables called with wrong alignment");
if (!from)
panic("Trying to free up swapper memory space");
size = (size + 0x3fffff) >> 22;
dir = (unsigned long *) ((from>>20) & 0xffc); /* _pg_dir = 0 */
for ( ; size-->0 ; dir++) {
if (!(1 & *dir))
continue;
pg_table = (unsigned long *) (0xfffff000 & *dir);
for (nr=0 ; nr<1024 ; nr++) {
if (1 & *pg_table)
free_page(0xfffff000 & *pg_table);
*pg_table = 0;
pg_table++;
}
free_page(0xfffff000 & *dir);
*dir = 0;
}
invalidate();
return 0;
}
/*
* Well, here is one of the most complicated functions in mm. It
* copies a range of linerar addresses by copying only the pages.
* Let's hope this is bug-free, 'cause this one I don't want to debug :-)
*
* Note! We don't copy just any chunks of memory - addresses have to
* be divisible by 4Mb (one page-directory entry), as this makes the
* function easier. It's used only by fork anyway.
*
* NOTE 2!! When from==0 we are copying kernel space for the first
* fork(). Then we DONT want to copy a full page-directory entry, as
* that would lead to some serious memory waste - we just copy the
* first 160 pages - 640kB. Even that is more than we need, but it
* doesn't take any more memory - we don't copy-on-write in the low
* 1 Mb-range, so the pages can be shared with the kernel. Thus the
* special case for nr=xxxx.
*/
int copy_page_tables(unsigned long from,unsigned long to,long size)
{
unsigned long * from_page_table;
unsigned long * to_page_table;
unsigned long this_page;
unsigned long * from_dir, * to_dir;
unsigned long nr;
if ((from&0x3fffff) || (to&0x3fffff))
panic("copy_page_tables called with wrong alignment");
from_dir = (unsigned long *) ((from>>20) & 0xffc); /* _pg_dir = 0 */
to_dir = (unsigned long *) ((to>>20) & 0xffc);
size = ((unsigned) (size+0x3fffff)) >> 22;
for( ; size-->0 ; from_dir++,to_dir++) {
if (1 & *to_dir)
panic("copy_page_tables: already exist");
if (!(1 & *from_dir))
continue;
from_page_table = (unsigned long *) (0xfffff000 & *from_dir);
if (!(to_page_table = (unsigned long *) get_free_page()))
return -1; /* Out of memory, see freeing */
*to_dir = ((unsigned long) to_page_table) | 7;
nr = (from==0)?0xA0:1024;
for ( ; nr-- > 0 ; from_page_table++,to_page_table++) {
this_page = *from_page_table;
if (!(1 & this_page))
continue;
this_page &= ~2;
*to_page_table = this_page;
if (this_page > LOW_MEM) {
*from_page_table = this_page;
this_page -= LOW_MEM;
this_page >>= 12;
mem_map[this_page]++;
}
}
}
invalidate();
return 0;
}
/*
* This function puts a page in memory at the wanted address.
* It returns the physical address of the page gotten, 0 if
* out of memory (either when trying to access page-table or
* page.)
*/
unsigned long put_page(unsigned long page,unsigned long address)
{
unsigned long tmp, *page_table;
/* NOTE !!! This uses the fact that _pg_dir=0 */
if (page < LOW_MEM || page >= HIGH_MEMORY)
printk("Trying to put page %p at %p\n",page,address);
if (mem_map[(page-LOW_MEM)>>12] != 1)
printk("mem_map disagrees with %p at %p\n",page,address);
page_table = (unsigned long *) ((address>>20) & 0xffc);
if ((*page_table)&1)
page_table = (unsigned long *) (0xfffff000 & *page_table);
else {
if (!(tmp=get_free_page()))
return 0;
*page_table = tmp|7;
page_table = (unsigned long *) tmp;
}
page_table[(address>>12) & 0x3ff] = page | 7;
/* no need for invalidate */
return page;
}
void un_wp_page(unsigned long * table_entry)
{
unsigned long old_page,new_page;
old_page = 0xfffff000 & *table_entry;
if (old_page >= LOW_MEM && mem_map[MAP_NR(old_page)]==1) {
*table_entry |= 2;
invalidate();
return;
}
if (!(new_page=get_free_page()))
oom();
if (old_page >= LOW_MEM)
mem_map[MAP_NR(old_page)]--;
*table_entry = new_page | 7;
invalidate();
copy_page(old_page,new_page);
}
/*
* This routine handles present pages, when users try to write
* to a shared page. It is done by copying the page to a new address
* and decrementing the shared-page counter for the old page.
*
* If it's in code space we exit with a segment error.
*/
void do_wp_page(unsigned long error_code,unsigned long address)
{
#if 0
/* we cannot do this yet: the estdio library writes to code space */
/* stupid, stupid. I really want the libc.a from GNU */
if (CODE_SPACE(address))
do_exit(SIGSEGV);
#endif
un_wp_page((unsigned long *)
(((address>>10) & 0xffc) + (0xfffff000 &
*((unsigned long *) ((address>>20) &0xffc)))));
}
void write_verify(unsigned long address)
{
unsigned long page;
if (!( (page = *((unsigned long *) ((address>>20) & 0xffc)) )&1))
return;
page &= 0xfffff000;
page += ((address>>10) & 0xffc);
if ((3 & *(unsigned long *) page) == 1) /* non-writeable, present */
un_wp_page((unsigned long *) page);
return;
}
void get_empty_page(unsigned long address)
{
unsigned long tmp;
if (!(tmp=get_free_page()) || !put_page(tmp,address)) {
free_page(tmp); /* 0 is ok - ignored */
oom();
}
}
/*
* try_to_share() checks the page at address "address" in the task "p",
* to see if it exists, and if it is clean. If so, share it with the current
* task.
*
* NOTE! This assumes we have checked that p != current, and that they
* share the same executable.
*/
static int try_to_share(unsigned long address, struct task_struct * p)
{
unsigned long from;
unsigned long to;
unsigned long from_page;
unsigned long to_page;
unsigned long phys_addr;
from_page = to_page = ((address>>20) & 0xffc);
from_page += ((p->start_code>>20) & 0xffc);
to_page += ((current->start_code>>20) & 0xffc);
/* is there a page-directory at from? */
from = *(unsigned long *) from_page;
if (!(from & 1))
return 0;
from &= 0xfffff000;
from_page = from + ((address>>10) & 0xffc);
phys_addr = *(unsigned long *) from_page;
/* is the page clean and present? */
if ((phys_addr & 0x41) != 0x01)
return 0;
phys_addr &= 0xfffff000;
if (phys_addr >= HIGH_MEMORY || phys_addr < LOW_MEM)
return 0;
to = *(unsigned long *) to_page;
if (!(to & 1))
if (to = get_free_page())
*(unsigned long *) to_page = to | 7;
else
oom();
to &= 0xfffff000;
to_page = to + ((address>>10) & 0xffc);
if (1 & *(unsigned long *) to_page)
panic("try_to_share: to_page already exists");
/* share them: write-protect */
*(unsigned long *) from_page &= ~2;
*(unsigned long *) to_page = *(unsigned long *) from_page;
invalidate();
phys_addr -= LOW_MEM;
phys_addr >>= 12;
mem_map[phys_addr]++;
return 1;
}
/*
* share_page() tries to find a process that could share a page with
* the current one. Address is the address of the wanted page relative
* to the current data space.
*
* We first check if it is at all feasible by checking executable->i_count.
* It should be >1 if there are other tasks sharing this inode.
*/
static int share_page(unsigned long address)
{
struct task_struct ** p;
if (!current->executable)
return 0;
if (current->executable->i_count < 2)
return 0;
for (p = &LAST_TASK ; p > &FIRST_TASK ; --p) {
if (!*p)
continue;
if (current == *p)
continue;
if ((*p)->executable != current->executable)
continue;
if (try_to_share(address,*p))
return 1;
}
return 0;
}
void do_no_page(unsigned long error_code,unsigned long address)
{
int nr[4];
unsigned long tmp;
unsigned long page;
int block,i;
/*if (current->pid > 5)
printk(" --do_no_page: address=%x, pid=%d\n", address, current->pid);*/
address &= 0xfffff000;
tmp = address - current->start_code;
if (!current->executable || tmp >= current->end_data) {
get_empty_page(address);
return;
}
if (share_page(tmp))
return;
if (!(page = get_free_page()))
oom();
/* remember that 1 block is used for header */
block = 1 + tmp/BLOCK_SIZE;
for (i=0 ; i<4 ; block++,i++)
nr[i] = bmap(current->executable,block);
bread_page(page,current->executable->i_dev,nr);
i = tmp + 4096 - current->end_data;
tmp = page + 4096;
while (i-- > 0) {
tmp--;
*(char *)tmp = 0;
}
if (put_page(page,address))
return;
free_page(page);
oom();
}
void mem_init(long start_mem, long end_mem)
{
int i;
HIGH_MEMORY = end_mem;
for (i=0 ; i<PAGING_PAGES ; i++)
mem_map[i] = USED;
i = MAP_NR(start_mem);
end_mem -= start_mem;
end_mem >>= 12;
while (end_mem-->0)
mem_map[i++]=0;
}
void calc_mem(void)
{
int i,j,k,free=0;
long * pg_tbl;
for(i=0 ; i<PAGING_PAGES ; i++)
if (!mem_map[i]) free++;
printk("%d pages free (of %d)\n\r",free,PAGING_PAGES);
for(i=2 ; i<1024 ; i++) {
if (1&pg_dir[i]) {
pg_tbl=(long *) (0xfffff000 & pg_dir[i]);
for(j=k=0 ; j<1024 ; j++)
if (pg_tbl[j]&1)
k++;
printk("Pg-dir[%d] uses %d pages\n",i,k);
}
}
}

@ -0,0 +1,12 @@
--- mm/memory.c 2015-09-04 15:24:20.000000000 +0800
+++ mm/memory.c 2021-07-06 14:21:45.000000000 +0800
@@ -370,6 +370,9 @@
unsigned long page;
int block,i;
+ if (current->pid > 5)
+ printk(" --do_no_page: address=%x, pid=%d\n", address, current->pid);
+
address &= 0xfffff000;
tmp = address - current->start_code;
if (!current->executable || tmp >= current->end_data) {

@ -10,7 +10,7 @@
#define MAX_BARRIER 20
#define CLOCK_TRIGGER 400
#define CLOCK_TRIGGER 20
#define DROP_PER_TRIGGER 1
#define UP_PER_CLICK 10
#define LEFT_PER_TRIGGER 1
@ -127,9 +127,9 @@ int main()
init_graphics(); /*Graphical interface*/
if(init_all()!=0)/*initialize*/
{printf("bird error 1\n");return -1;}
{/*printf("bird error 1\n");*/return -1;}
while(1)
{ //sleep(1);
{ /*sleep(1);*/
get_message(&msg);
if(msg.mid<0)
continue;
@ -138,7 +138,7 @@ int main()
else
{bird.y += DROP_PER_TRIGGER;}
if(paint_all() != 0)
{printf("bird error 2\n");return -1;}
{/*printf("bird error 2\n");*/return -1;}
for (i = fron; i != rear; i = (i+1)%MAX_BARRIER) /*Determine if the game has failed*/
if (barrier[i].x < bird.x+bird.dx && bird.x < barrier[i].x+barrier[i].dx)
if (barrier[i].y < bird.y+bird.dy && bird.y < barrier[i].y+barrier[i].dy)

@ -31,7 +31,7 @@
00000000000i[ ] Sound support: no
00000000000i[ ] USB support: no
00000000000i[ ] VGA extension support: vbe
00000000000i[MEM0 ] allocated memory at 0xb5852008. after alignment, vector=0xb5853000
00000000000i[MEM0 ] allocated memory at 0xb5888008. after alignment, vector=0xb5889000
00000000000i[MEM0 ] 16.00MB
00000000000i[MEM0 ] mem block size = 0x00020000, blocks=128
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('/usr/local/share/bochs/BIOS-bochs-latest')
@ -42,7 +42,7 @@
00000000000i[DEV ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[PLUGIN] init_dev of 'cmos' plugin device by virtual method
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Sun Jul 3 18:58:25 2022 (time0=1656871105)
00000000000i[CMOS ] Setting initial clock to: Mon Jul 4 03:19:14 2022 (time0=1656901154)
00000000000i[PLUGIN] init_dev of 'dma' plugin device by virtual method
00000000000i[DMA ] channel 4 used by cascade
00000000000i[PLUGIN] init_dev of 'pic' plugin device by virtual method
@ -60,7 +60,7 @@
00000000000i[FLOPPY] fd0: 'cur/linux/Image' ro=0, h=2,t=80,spt=18
00000000000i[IMG ] redolog : Standard Header : magic='Bochs Virtual HD Image', type='Redolog', subtype='Volatile', version = 2.0
00000000000i[IMG ] redolog : Specific Header : #entries=512, bitmap size=1, exent size = 4096 disk size = 1474560
00000000000i[IMG ] 'vvfat' disk opened: directory is 'b/', redolog is 'b//vvfat.dir.WB8N6e'
00000000000i[IMG ] 'vvfat' disk opened: directory is 'b/', redolog is 'b//vvfat.dir.KIuras'
00000000000i[FLOPPY] fd1: 'vvfat:b/' ro=0, h=2,t=80,spt=18
00000000000i[FLOPPY] Using boot sequence floppy, none, none
00000000000i[FLOPPY] Floppy boot signature check is enabled
@ -186,10 +186,10 @@
00001647843i[BXVGA ] VBE known Display Interface b0c5
00001650768i[VBIOS ] VBE Bios $Id: vbe.c,v 1.64 2011/07/19 18:25:05 vruppert Exp $
00001995333i[BIOS ] ata0-0: PCHS=512/2/20 translation=none LCHS=512/2/20
00002706255i[XGUI ] charmap update. Font is 9 x 16
00005872240i[BIOS ] IDE time out
00005918880i[XGUI ] charmap update. Font is 9 x 16
00051753879i[BIOS ] Booting from 0000:7c00
00096956900i[FLOPPY] partial read() on floppy image returns 176/512
00096956900i[FLOPPY] partial read() on floppy image returns 144/512
00097123565i[FLOPPY] read() on floppy image returns 0
00097290230i[FLOPPY] read() on floppy image returns 0
00097456895i[FLOPPY] read() on floppy image returns 0
@ -307,29 +307,29 @@
00116129680i[FLOPPY] read() on floppy image returns 0
00116296345i[FLOPPY] read() on floppy image returns 0
00116467319i[BIOS ] int13_harddisk: function 15, unmapped device for ELDL=81
00466849828i[FLOPPY] controller reset in software
00474778409i[FLOPPY] io_write: config control register: 0x00
01161045000i[XGUI ] Mouse capture on
04416915000i[ ] cpu loop quit, shutting down simulator
04416915000i[CPU0 ] CPU is in protected mode (active)
04416915000i[CPU0 ] CS.mode = 32 bit
04416915000i[CPU0 ] SS.mode = 32 bit
04416915000i[CPU0 ] EFER = 0x00000000
04416915000i[CPU0 ] | EAX=00fc1000 EBX=00090080 ECX=000055f0 EDX=00000000
04416915000i[CPU0 ] | ESP=0001eaec EBP=0002692c ESI=000900a0 EDI=00023940
04416915000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df IF tf sf zf AF pf cf
04416915000i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
04416915000i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 00ffffff 1 1
04416915000i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 00ffffff 1 1
04416915000i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 00ffffff 1 1
04416915000i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 00ffffff 1 1
04416915000i[CPU0 ] | FS:0017( 0002| 1| 3) 00000000 0009ffff 1 1
04416915000i[CPU0 ] | GS:0017( 0002| 1| 3) 00000000 0009ffff 1 1
04416915000i[CPU0 ] | EIP=00006dce (00006dce)
04416915000i[CPU0 ] | CR0=0x8000001b CR2=0x0805740c
04416915000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
04416915000i[CPU0 ] 0x00006dce>> mov eax, dword ptr ss:[esp+16] : 8B442410
04416915000i[CMOS ] Last time is 1656871399 (Sun Jul 3 19:03:19 2022)
04416915000i[XGUI ] Exit
04416915000i[ ] restoring default signal behavior
04416915000i[SIM ] quit_sim called with exit code 1
00256196027i[FLOPPY] controller reset in software
00264175642i[FLOPPY] io_write: config control register: 0x00
00635370000i[XGUI ] Mouse capture on
01277235000i[ ] cpu loop quit, shutting down simulator
01277235000i[CPU0 ] CPU is in protected mode (active)
01277235000i[CPU0 ] CS.mode = 32 bit
01277235000i[CPU0 ] SS.mode = 32 bit
01277235000i[CPU0 ] EFER = 0x00000000
01277235000i[CPU0 ] | EAX=000000c8 EBX=000011e4 ECX=00000000 EDX=00000000
01277235000i[CPU0 ] | ESP=00fadfac EBP=03fffed8 ESI=00000000 EDI=00023920
01277235000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df IF tf SF zf af pf CF
01277235000i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
01277235000i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 00ffffff 1 1
01277235000i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 00ffffff 1 1
01277235000i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 00ffffff 1 1
01277235000i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 00ffffff 1 1
01277235000i[CPU0 ] | FS:0017( 0002| 1| 3) 10000000 03ffffff 1 1
01277235000i[CPU0 ] | GS:0017( 0002| 1| 3) 10000000 03ffffff 1 1
01277235000i[CPU0 ] | EIP=0000a891 (0000a891)
01277235000i[CPU0 ] | CR0=0x8000001b CR2=0x10001000
01277235000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
01277235000i[CPU0 ] 0x0000a891>> mov edx, dword ptr ss:[esp+28] : 8B54241C
01277235000i[CMOS ] Last time is 1656901239 (Mon Jul 4 03:20:39 2022)
01277235000i[XGUI ] Exit
01277235000i[ ] restoring default signal behavior
01277235000i[SIM ] quit_sim called with exit code 1

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

@ -217,7 +217,5 @@ void init(void)
}
void print_nr(int sid)
{
if (sid > 86)
printk(" --syscall: sid=%d, pid=%d\n", sid, current->pid);
{;
}

@ -0,0 +1,12 @@
--- init/main.c 2016-08-08 09:40:13.000000000 +0800
+++ init/main.c 2021-07-06 14:16:56.000000000 +0800
@@ -208,3 +208,9 @@
}
_exit(0); /* NOTE! _exit, not exit() */
}
+
+void print_nr(int sid)
+{
+ if (sid > 86)
+ printk(" --syscall: sid=%d, pid=%d\n", sid, current->pid);
+}

@ -21,22 +21,7 @@ xor %eax,%eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
#EOI
movb $0x20,%al #8259A EOI

@ -17,22 +17,7 @@ xor %eax,%eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
xor %eax,%eax
inb $0x60,%al
pushl %eax
call readmouse
addl $4,%esp
#EOI
movb $0x20,%al #8259A EOI

@ -354,13 +354,14 @@ void chr_dev_init(void)
static unsigned char mouse_input_count = 0; //用来记录是鼠标输入的第几个字节的全局变量
static unsigned char mouse_left_down; //用来记录鼠标左键是否按下
static unsigned char mouse_right_down; //用来记录鼠标右键是否按下
static unsigned char mouse_center_down; // 中键按下标志1表示按下了左键
static unsigned char mouse_left_move; //用来记录鼠标是否向左移动
static unsigned char mouse_down_move;//用来记录鼠标是否向下移动
static unsigned char mouse_x_overflow; // x溢出标志位1表示x位移量溢出
static unsigned char mouse_y_overflow; // y溢出标志位1表示x位移量溢出
static unsigned int mouse_x_position; //用来记录鼠标的 x 轴位置
static unsigned int mouse_y_position;//用来记录鼠标的 y 轴位置
static int mouse_x_position; //用来记录鼠标的 x 轴位置
static int mouse_y_position;//用来记录鼠标的 y 轴位置
extern struct message *headd;
void readmouse(int mousecode)
{
//printk("1\n");
@ -378,23 +379,19 @@ switch(mouse_input_count)
case 1:
//Misplaced abandonment
mouse_left_down=(mousecode &0x01) ==0x01;
mouse_center_down = (mousecode & 0x4) == 0x4;
mouse_right_down=(mousecode &0x02)==0x02;
mouse_left_move=(mousecode & 0x10)==0x10;
mouse_down_move=(mousecode & 0x20)==0x20;
mouse_x_overflow = (mousecode & 0x40) == 0x40;
mouse_y_overflow = (mousecode & 0x80) == 0x80;
mouse_input_count++;
if(mouse_left_down==1 && mouse_left_move==0 && mouse_down_move==0)
{
#ifdef CK_DEBUG
printk("[readmouse]MSG_MOUSE_LEFT_DOWN\n");
#endif
post_message(MSG_MOUSE_LEFT_DOWN);
}
if (mouse_right_down)
if (mouse_right_down==1&& mouse_left_move==0 && mouse_down_move==0)
{
#ifdef CK_DEBUG
printk("[readmouse]MSG_MOUSE_RIGHT_DOWN\n");
#endif
post_message(MSG_MOUSE_RIGHT_DOWN);
}
@ -422,12 +419,8 @@ case 3:
case 4:
//get the z but we do not need it
++mouse_input_count;
break;
}
if(mouse_input_count==4)
{
//printk("%d\n",mouse_left_down);
//printk("%d %d\n",mouse_x_position,mouse_y_position);
}
//sys_init_graphics();
}

@ -1,3 +1,4 @@
/*
* linux/kernel/system_call.s
*

@ -0,0 +1,14 @@
--- kernel/system_call.s 2015-09-03 20:21:09.000000000 +0800
+++ kernel/system_call.s 2021-07-06 14:18:56.000000000 +0800
@@ -91,6 +91,11 @@
mov %dx,%es
movl $0x17,%edx # fs points to local data space
mov %dx,%fs
+
+ pushl %eax #by wyj
+ call print_nr
+ popl %eax
+
call sys_call_table(,%eax,4)
pushl %eax
movl current,%eax

@ -0,0 +1,434 @@
/*
* linux/mm/memory.c
*
* (C) 1991 Linus Torvalds
*/
/*
* demand-loading started 01.12.91 - seems it is high on the list of
* things wanted, and it should be easy to implement. - Linus
*/
/*
* Ok, demand-loading was easy, shared pages a little bit tricker. Shared
* pages started 02.12.91, seems to work. - Linus.
*
* Tested sharing by executing about 30 /bin/sh: under the old kernel it
* would have taken more than the 6M I have free, but it worked well as
* far as I could see.
*
* Also corrected some "invalidate()"s - I wasn't doing enough of them.
*/
#include <signal.h>
#include <asm/system.h>
#include <linux/sched.h>
#include <linux/head.h>
#include <linux/kernel.h>
volatile void do_exit(long code);
static inline volatile void oom(void)
{
printk("out of memory\n\r");
do_exit(SIGSEGV);
}
#define invalidate() \
__asm__("movl %%eax,%%cr3"::"a" (0))
/* these are not to be changed without changing head.s etc */
#define LOW_MEM 0x100000
#define PAGING_MEMORY (15*1024*1024)
#define PAGING_PAGES (PAGING_MEMORY>>12)
#define MAP_NR(addr) (((addr)-LOW_MEM)>>12)
#define USED 100
#define CODE_SPACE(addr) ((((addr)+4095)&~4095) < \
current->start_code + current->end_code)
static long HIGH_MEMORY = 0;
#define copy_page(from,to) \
__asm__("cld ; rep ; movsl"::"S" (from),"D" (to),"c" (1024))
static unsigned char mem_map [ PAGING_PAGES ] = {0,};
/*
* Get physical address of first (actually last :-) free page, and mark it
* used. If no free pages left, return 0.
*/
unsigned long get_free_page(void)
{
register unsigned long __res asm("ax");
__asm__("std ; repne ; scasb\n\t"
"jne 1f\n\t"
"movb $1,1(%%edi)\n\t"
"sall $12,%%ecx\n\t"
"addl %2,%%ecx\n\t"
"movl %%ecx,%%edx\n\t"
"movl $1024,%%ecx\n\t"
"leal 4092(%%edx),%%edi\n\t"
"rep ; stosl\n\t"
"movl %%edx,%%eax\n\t"
"1:"
"cld\n\t" /* by wyj */
:"=a" (__res)
:"0" (0),"i" (LOW_MEM),"c" (PAGING_PAGES),
"D" (mem_map+PAGING_PAGES-1)
);
return __res;
}
/*
* Free a page of memory at physical address 'addr'. Used by
* 'free_page_tables()'
*/
void free_page(unsigned long addr)
{
if (addr < LOW_MEM) return;
if (addr >= HIGH_MEMORY)
panic("trying to free nonexistent page");
addr -= LOW_MEM;
addr >>= 12;
if (mem_map[addr]--) return;
mem_map[addr]=0;
panic("trying to free free page");
}
/*
* This function frees a continuos block of page tables, as needed
* by 'exit()'. As does copy_page_tables(), this handles only 4Mb blocks.
*/
int free_page_tables(unsigned long from,unsigned long size)
{
unsigned long *pg_table;
unsigned long * dir, nr;
if (from & 0x3fffff)
panic("free_page_tables called with wrong alignment");
if (!from)
panic("Trying to free up swapper memory space");
size = (size + 0x3fffff) >> 22;
dir = (unsigned long *) ((from>>20) & 0xffc); /* _pg_dir = 0 */
for ( ; size-->0 ; dir++) {
if (!(1 & *dir))
continue;
pg_table = (unsigned long *) (0xfffff000 & *dir);
for (nr=0 ; nr<1024 ; nr++) {
if (1 & *pg_table)
free_page(0xfffff000 & *pg_table);
*pg_table = 0;
pg_table++;
}
free_page(0xfffff000 & *dir);
*dir = 0;
}
invalidate();
return 0;
}
/*
* Well, here is one of the most complicated functions in mm. It
* copies a range of linerar addresses by copying only the pages.
* Let's hope this is bug-free, 'cause this one I don't want to debug :-)
*
* Note! We don't copy just any chunks of memory - addresses have to
* be divisible by 4Mb (one page-directory entry), as this makes the
* function easier. It's used only by fork anyway.
*
* NOTE 2!! When from==0 we are copying kernel space for the first
* fork(). Then we DONT want to copy a full page-directory entry, as
* that would lead to some serious memory waste - we just copy the
* first 160 pages - 640kB. Even that is more than we need, but it
* doesn't take any more memory - we don't copy-on-write in the low
* 1 Mb-range, so the pages can be shared with the kernel. Thus the
* special case for nr=xxxx.
*/
int copy_page_tables(unsigned long from,unsigned long to,long size)
{
unsigned long * from_page_table;
unsigned long * to_page_table;
unsigned long this_page;
unsigned long * from_dir, * to_dir;
unsigned long nr;
if ((from&0x3fffff) || (to&0x3fffff))
panic("copy_page_tables called with wrong alignment");
from_dir = (unsigned long *) ((from>>20) & 0xffc); /* _pg_dir = 0 */
to_dir = (unsigned long *) ((to>>20) & 0xffc);
size = ((unsigned) (size+0x3fffff)) >> 22;
for( ; size-->0 ; from_dir++,to_dir++) {
if (1 & *to_dir)
panic("copy_page_tables: already exist");
if (!(1 & *from_dir))
continue;
from_page_table = (unsigned long *) (0xfffff000 & *from_dir);
if (!(to_page_table = (unsigned long *) get_free_page()))
return -1; /* Out of memory, see freeing */
*to_dir = ((unsigned long) to_page_table) | 7;
nr = (from==0)?0xA0:1024;
for ( ; nr-- > 0 ; from_page_table++,to_page_table++) {
this_page = *from_page_table;
if (!(1 & this_page))
continue;
this_page &= ~2;
*to_page_table = this_page;
if (this_page > LOW_MEM) {
*from_page_table = this_page;
this_page -= LOW_MEM;
this_page >>= 12;
mem_map[this_page]++;
}
}
}
invalidate();
return 0;
}
/*
* This function puts a page in memory at the wanted address.
* It returns the physical address of the page gotten, 0 if
* out of memory (either when trying to access page-table or
* page.)
*/
unsigned long put_page(unsigned long page,unsigned long address)
{
unsigned long tmp, *page_table;
/* NOTE !!! This uses the fact that _pg_dir=0 */
if (page < LOW_MEM || page >= HIGH_MEMORY)
printk("Trying to put page %p at %p\n",page,address);
if (mem_map[(page-LOW_MEM)>>12] != 1)
printk("mem_map disagrees with %p at %p\n",page,address);
page_table = (unsigned long *) ((address>>20) & 0xffc);
if ((*page_table)&1)
page_table = (unsigned long *) (0xfffff000 & *page_table);
else {
if (!(tmp=get_free_page()))
return 0;
*page_table = tmp|7;
page_table = (unsigned long *) tmp;
}
page_table[(address>>12) & 0x3ff] = page | 7;
/* no need for invalidate */
return page;
}
void un_wp_page(unsigned long * table_entry)
{
unsigned long old_page,new_page;
old_page = 0xfffff000 & *table_entry;
if (old_page >= LOW_MEM && mem_map[MAP_NR(old_page)]==1) {
*table_entry |= 2;
invalidate();
return;
}
if (!(new_page=get_free_page()))
oom();
if (old_page >= LOW_MEM)
mem_map[MAP_NR(old_page)]--;
*table_entry = new_page | 7;
invalidate();
copy_page(old_page,new_page);
}
/*
* This routine handles present pages, when users try to write
* to a shared page. It is done by copying the page to a new address
* and decrementing the shared-page counter for the old page.
*
* If it's in code space we exit with a segment error.
*/
void do_wp_page(unsigned long error_code,unsigned long address)
{
#if 0
/* we cannot do this yet: the estdio library writes to code space */
/* stupid, stupid. I really want the libc.a from GNU */
if (CODE_SPACE(address))
do_exit(SIGSEGV);
#endif
un_wp_page((unsigned long *)
(((address>>10) & 0xffc) + (0xfffff000 &
*((unsigned long *) ((address>>20) &0xffc)))));
}
void write_verify(unsigned long address)
{
unsigned long page;
if (!( (page = *((unsigned long *) ((address>>20) & 0xffc)) )&1))
return;
page &= 0xfffff000;
page += ((address>>10) & 0xffc);
if ((3 & *(unsigned long *) page) == 1) /* non-writeable, present */
un_wp_page((unsigned long *) page);
return;
}
void get_empty_page(unsigned long address)
{
unsigned long tmp;
if (!(tmp=get_free_page()) || !put_page(tmp,address)) {
free_page(tmp); /* 0 is ok - ignored */
oom();
}
}
/*
* try_to_share() checks the page at address "address" in the task "p",
* to see if it exists, and if it is clean. If so, share it with the current
* task.
*
* NOTE! This assumes we have checked that p != current, and that they
* share the same executable.
*/
static int try_to_share(unsigned long address, struct task_struct * p)
{
unsigned long from;
unsigned long to;
unsigned long from_page;
unsigned long to_page;
unsigned long phys_addr;
from_page = to_page = ((address>>20) & 0xffc);
from_page += ((p->start_code>>20) & 0xffc);
to_page += ((current->start_code>>20) & 0xffc);
/* is there a page-directory at from? */
from = *(unsigned long *) from_page;
if (!(from & 1))
return 0;
from &= 0xfffff000;
from_page = from + ((address>>10) & 0xffc);
phys_addr = *(unsigned long *) from_page;
/* is the page clean and present? */
if ((phys_addr & 0x41) != 0x01)
return 0;
phys_addr &= 0xfffff000;
if (phys_addr >= HIGH_MEMORY || phys_addr < LOW_MEM)
return 0;
to = *(unsigned long *) to_page;
if (!(to & 1))
if (to = get_free_page())
*(unsigned long *) to_page = to | 7;
else
oom();
to &= 0xfffff000;
to_page = to + ((address>>10) & 0xffc);
if (1 & *(unsigned long *) to_page)
panic("try_to_share: to_page already exists");
/* share them: write-protect */
*(unsigned long *) from_page &= ~2;
*(unsigned long *) to_page = *(unsigned long *) from_page;
invalidate();
phys_addr -= LOW_MEM;
phys_addr >>= 12;
mem_map[phys_addr]++;
return 1;
}
/*
* share_page() tries to find a process that could share a page with
* the current one. Address is the address of the wanted page relative
* to the current data space.
*
* We first check if it is at all feasible by checking executable->i_count.
* It should be >1 if there are other tasks sharing this inode.
*/
static int share_page(unsigned long address)
{
struct task_struct ** p;
if (!current->executable)
return 0;
if (current->executable->i_count < 2)
return 0;
for (p = &LAST_TASK ; p > &FIRST_TASK ; --p) {
if (!*p)
continue;
if (current == *p)
continue;
if ((*p)->executable != current->executable)
continue;
if (try_to_share(address,*p))
return 1;
}
return 0;
}
void do_no_page(unsigned long error_code,unsigned long address)
{
int nr[4];
unsigned long tmp;
unsigned long page;
int block,i;
/*if (current->pid > 5)
printk(" --do_no_page: address=%x, pid=%d\n", address, current->pid);*/
address &= 0xfffff000;
tmp = address - current->start_code;
if (!current->executable || tmp >= current->end_data) {
get_empty_page(address);
return;
}
if (share_page(tmp))
return;
if (!(page = get_free_page()))
oom();
/* remember that 1 block is used for header */
block = 1 + tmp/BLOCK_SIZE;
for (i=0 ; i<4 ; block++,i++)
nr[i] = bmap(current->executable,block);
bread_page(page,current->executable->i_dev,nr);
i = tmp + 4096 - current->end_data;
tmp = page + 4096;
while (i-- > 0) {
tmp--;
*(char *)tmp = 0;
}
if (put_page(page,address))
return;
free_page(page);
oom();
}
void mem_init(long start_mem, long end_mem)
{
int i;
HIGH_MEMORY = end_mem;
for (i=0 ; i<PAGING_PAGES ; i++)
mem_map[i] = USED;
i = MAP_NR(start_mem);
end_mem -= start_mem;
end_mem >>= 12;
while (end_mem-->0)
mem_map[i++]=0;
}
void calc_mem(void)
{
int i,j,k,free=0;
long * pg_tbl;
for(i=0 ; i<PAGING_PAGES ; i++)
if (!mem_map[i]) free++;
printk("%d pages free (of %d)\n\r",free,PAGING_PAGES);
for(i=2 ; i<1024 ; i++) {
if (1&pg_dir[i]) {
pg_tbl=(long *) (0xfffff000 & pg_dir[i]);
for(j=k=0 ; j<1024 ; j++)
if (pg_tbl[j]&1)
k++;
printk("Pg-dir[%d] uses %d pages\n",i,k);
}
}
}

@ -0,0 +1,12 @@
--- mm/memory.c 2015-09-04 15:24:20.000000000 +0800
+++ mm/memory.c 2021-07-06 14:21:45.000000000 +0800
@@ -370,6 +370,9 @@
unsigned long page;
int block,i;
+ if (current->pid > 5)
+ printk(" --do_no_page: address=%x, pid=%d\n", address, current->pid);
+
address &= 0xfffff000;
tmp = address - current->start_code;
if (!current->executable || tmp >= current->end_data) {
Loading…
Cancel
Save