int pause(unsigned long tick);
int main()
{
+
+ while(1)
+ {
+ printf("shell#");
+ char buf[256];
+ read(0, buf, 256);
+
+ int pid = fork();
+ if(pid > 0)
+ {
+ wait(pid);
+ }
+ else
+ {
+ execv(buf, 0);
+ }
+ }
+
+
+
int pid = fork();
printf("pid %u\n", pid);
if(pid > 0)
{
+ printf("parent. child pid %u\n", pid);
while(1) {
- printf("parent. child pid %u\n", pid);
systest();
sysdebug(0x44444444);
}
}
else
{
+ printf("child\n");
while(1) {
- printf("child\n");
systest();
sysdebug(0xAABBCCDD);
}
int cnsl_kbd_write(char ch)
{
+ if(ch == 0)
+ return 0;
+
if(ch == '\b')
{
if(!empty(&cnsl.wr_q))
- vga_putc(0, '\b', 0x2);
+ vga_putc(0, '\b', 0xF);
erase(&cnsl.wr_q);
erase(&cnsl.sc_q);
}
{
put(&cnsl.wr_q, ch);
put(&cnsl.sc_q, ch);
- vga_putc(0, ch, 0x2);
+ vga_putc(0, ch, 0xF);
}
put(&cnsl.rd_q, ch);
wake_up(&rdwq);
}
-
-#if 0
- printl(23, "rd: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
- cnsl.rd_q.data[0],
- cnsl.rd_q.data[1],
- cnsl.rd_q.data[2],
- cnsl.rd_q.data[3],
- cnsl.rd_q.data[4],
- cnsl.rd_q.data[5],
- cnsl.rd_q.data[6],
- cnsl.rd_q.data[7],
- cnsl.rd_q.data[8],
- cnsl.rd_q.data[9]);
-#endif
}
if(r)
{
- buf[cnt++] = ch;
+ if(ch != '\n')
+ buf[cnt++] = ch;
task->state = TASK_RUNNING;
del_wait_queue(&rdwq, &wait);
#include<wait.h>
-#define CNSL_QUEUE_SIZE 10
+#define CNSL_QUEUE_SIZE 1024
typedef struct cnsl_queue
{
void *blk = ext2_alloc_block();
assert(blk != 0);
- printk("read_inode %u\n", ino);
+ printd("read_inode %u\n", ino);
unsigned int in; // inode number
unsigned int gn; // group number
memcpy(inode, blk+inoff, sizeof(ext2_inode_t));
- printk(" inode size %u \n", inode->i_size);
+ printd(" inode size %u \n", inode->i_size);
ext2_free_block(blk);
}
assert(inode->i_size > 0 && inode->i_size<=MAX_SUPT_FILE_SIZE);
assert(offset+size <= inode->i_size);
assert(offset % EXT2_BLOCK_SIZE == 0); // for easy
- printk("offset %x size %x %x\n", offset, size, offset+size);
+ printd("offset %x size %x %x\n", offset, size, offset+size);
assert((offset+size) % EXT2_BLOCK_SIZE == 0);
unsigned int blkid = offset / EXT2_BLOCK_SIZE;
unsigned int blkcnt = size / EXT2_BLOCK_SIZE;
- printk("id %u cnt %u\n", blkid, blkcnt);
+ printd("id %u cnt %u\n", blkid, blkcnt);
BLKRW(inode->i_block[blkid], blkcnt, buf);
}
while((len=get_filename_from_path(path, file)) != 0)
{
ino = ext2_search_indir(file, inode);
- assert(ino != 0);
+ //assert(ino != 0);
path += len;
}
ext2_read_inode(2, &ext2_root_inode);
-#if 1
+#if 0
printk("root inode.i_size %u \n", ext2_root_inode.i_size);
printk("root blocks %u \n", ext2_root_inode.i_blocks);
#include <sched.h>
#include <system.h>
+#include <wait.h>
int sysc_exit(int status)
{
- // simple implement.
+ unsigned long flags;
+ irq_save(flags);
current->state = TASK_EXITING;
task_union *t = current;
-
- schedule();
+
+ irq_restore(flags);
return 0;
}
printk("----pde[%u] pte_src[%u] %08x\n", i, j, pte_src[j]);
page_t *page = pa2page(pte_src[j]);
page->count ++;
- //assert(page->count <= 1);
- if(page->count > 1)
- {
- printk("page %08x count %d\n", page, page->count);
- panic("----");
- }
}
}
unsigned long schedule()
{
static turn = 0;
- task_union *sel = &root_task;
+ task_union *sel = 0;
task_union *p = 0;
list_head_t *pos = 0, *t=0;
{
p = list_entry(pos, task_union, list);
+ printl(MPL_ROOT+p->pid, "task:%d [%08x] state %02x TURN %d turn %d cnt %u", p->pid, p, p->state, turn, p->weight, p->cnt);
+
if(p->state != TASK_RUNNING)
{
continue;
printd("%08x weight %d\n", p, p->weight);
- if(p->weight != turn)
+
+ if(sel == 0 && p->weight != turn)
{
p->weight = turn;
sel = p;
- break;
}
}
irq_restore(iflags);
- if(sel == &root_task)
+
+ if(sel == 0)
{
+ sel = &root_task;
turn ++;
}
- printl(MPL_ROOT+sel->pid, "task:%d [%08x] turn %d cnt %u", sel->pid, sel, sel->weight, sel->cnt);
task_union *prev = current;
task_union *next = sel;
"Kernel "
VERSION
" Build on "__DATE__ " " __TIME__
- " by "
- BUIDER;
+ " @ "
+ BUIDER
+ "\n";
void setup_kernel()
{
setup_fs();
- printk("%s\n", version);
- //vga_dbg_toggle();
+ vga_puts(0, version, 0x2F);
+
+ switch_printk_screen();
}
if(p == 0)
return 0;
+ if(p->state == TASK_EXITING)
+ return 0;
+
task_union * task = current;
DECLARE_WAIT_QUEUE(wait, task);
add_wait_queue(&p->wait, &wait);
while(true)
{
- task->state = TASK_WAIT;
+ //task->state = TASK_WAIT;
- if(p->state == TASK_EXITING) // no need irq_save
+ unsigned long flags;
+ irq_save(flags);
+ unsigned int state = p->state;
+ irq_restore(flags);
+
+ if(state == TASK_EXITING) // no need irq_save
break;
schedule();