insl(REG_DATA(0), buf, 512>>2);
u16_t *s = (u16_t *) (buf+510);
- printk("insw %04x\n", *s);
+ printk("hard disk data %04x\n", *s);
}
void ide_init()
{
- ide_read_identify();
+ //ide_read_identify();
init_pci_controller(PCI_VENDORID_INTEL, 0x2829);
init_pci_controller(PCI_VENDORID_INTEL, 0x7010);
}
const char *devname,
void *dev_id);
-static inline int enable_irq(unsigned int irq)
-{
- return irq_desc[irq].chip->enable(irq);
-}
-static inline int disable_irq(unsigned int irq)
-{
- return irq_desc[irq].chip->disable(irq);
-}
+int open_irq(unsigned int irq);
+int close_irq(unsigned int irq);
+
+#define enable_irq() asm("sti")
+#define disable_irq() asm("cli")
+
+#define irq_save(x) __asm__ __volatile__("pushfl; popl %0; cli":"=g"(x)::"memory")
+
+#define irq_restore(x) do { \
+ typecheck(unsigned long, x); \
+ __asm__ __volatile__("pushl %0; popfl"::"g"(x):"memory", "cc"); \
+} while(0)
+
+
+
#endif //_IRQ_H
#define PT_REGS_ESP 60
#define PT_REGS_SS 64
-#ifndef ASM
+#ifndef ASM
#include "types.h"
#include "printk.h"
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
+#define typecheck(type, x) \
+({ type __dummy; \
+ typeof(x) __dummy2; \
+ (void)(&__dummy == &__dummy2); \
+ 1; \
+})
+
void *kmalloc(size_t size, gfp_t gfpflags);
void kfree(void *addr);
unsigned long esp;
unsigned long eip;
+ unsigned long weight;
+
pid_t pid;
pid_t ppid;
unsigned int state;
#define current get_current()
-#define ROOT_TSK_PID (0)
+#define ROOT_TSK_PID (7)
+
+#define TASK_INIT_WEIGHT 10
extern ListHead tsk_list;
printk("tsk %08x child_regs esp %08x esp0 %08x\n", tsk, tsk->esp, tsk->esp0);
tsk->state = TASK_RUNNING;
-
+ tsk->weight= TASK_INIT_WEIGHT;
INIT_LIST_HEAD(&tsk->list);
// TODO Lock
char __initdata kernel_init_stack[KRNL_INIT_STACK_SIZE] __attribute__ ((__aligned__(PAGE_SIZE)));
+static unsigned int eid = 0;
void init_task_entry()
{
printk("hahahha %s\n", __func__);
+ unsigned int id = eid++;
while(1)
{
- printk("i");
+ printk("%d", id);
asm("sti;hlt;");
}
}
asm("sti;hlt;");
}
#endif
- pt_regs_t regs;
- memset((void*)®s, 0, sizeof(regs));
- regs.edx = (unsigned long) init_task_entry;
- int pid = do_fork(®s, FORK_KRNL);
+ {
+ pt_regs_t regs;
+ memset((void*)®s, 0, sizeof(regs));
+ regs.edx = (unsigned long) init_task_entry;
+ int pid = do_fork(®s, FORK_KRNL);
+ printk("a pid is %d\n", pid);
+ }
+
+
+ {
+ pt_regs_t regs;
+ memset((void*)®s, 0, sizeof(regs));
+ regs.edx = (unsigned long) init_task_entry;
+ int pid = do_fork(®s, FORK_KRNL);
+ printk("b pid is %d\n", pid);
+ }
+
- printk("pid is %d\n", pid);
while(1)
{
printk("r");
//printk("irq: %d action:%x\n", irq, p);
return 0;
}
+
+
+
+int open_irq(unsigned int irq)
+{
+ return irq_desc[irq].chip->enable(irq);
+}
+
+int close_irq(unsigned int irq)
+{
+ return irq_desc[irq].chip->disable(irq);
+}
pid_t get_next_pid()
{
- static pid_t g_pid = ROOT_TSK_PID;
+ static pid_t g_pid = ROOT_TSK_PID;
- pid_t pid = g_pid;
+ pid_t pid = g_pid++;
return pid;
}
root_task.pid = get_next_pid();
root_task.ppid = 0;
root_task.state = TASK_RUNNING;
+ root_task.weight = TASK_INIT_WEIGHT;
INIT_LIST_HEAD(&root_task.list);
for(i=0; i<NR_OPENS; i++)
unsigned long schedule()
{
- static task_union *last_sel = &root_task;
task_union *sel = &root_task;
task_union *p = 0;
list_head_t *pos = 0;
- list_for_each(pos, &(last_sel->list))
+ unsigned int max_weight = 0;
+
+ list_for_each(pos, &root_task.list)
{
p = list_entry(pos, task_union, list);
- if(p->state == TASK_RUNNING)
+ if(p->state != TASK_RUNNING)
+ continue;
+
+ if(p->weight > max_weight)
{
+ max_weight = p->weight;
sel = p;
- last_sel = sel;
- break;
+ }
+ else if(p->weight == 0)
+ {
+ p->weight = TASK_INIT_WEIGHT;
}
}
+ sel->weight--;
+
task_union *prev = current;
task_union *next = sel;
void debug_sched()
{
- task_union *p = list_entry(root_task.list.next, task_union, list);
+ task_union *p = list_entry(current->list.next, task_union, list);
p->state = (p->state == TASK_RUNNING) ? TASK_INTERRUPTIBLE : TASK_RUNNING;
}
* ------------------------------------------------------------------------
*/
#include <mm.h>
+#include <irq.h>
#include <sysctl.h>
struct buddy_system
// gfp_mask
// ...
+ unsigned long flags;
+ irq_save(flags);
page_t *page = __alloc_pages(order);
+ irq_restore(flags);
return (unsigned long) page2va(page);
}
page_t *page = va2page(addr);
+ unsigned long flags;
+ irq_save(flags);
__free_pages(page, page->order);
+ irq_restore(flags);
}
void dump_buddy_system()
#include <mm.h>
#include <system.h>
+#include <irq.h>
list_head_t slub_caches = LIST_HEAD_INIT(slub_caches);
if(cache == 0)
return 0;
+ unsigned long flags;
+ irq_save(flags);
+
if(cache->page == 0 || cache->page->freelist == 0)
{
cache->page = 0;
cache->page->inuse++;
}
+ irq_restore(flags);
+
return object;
}
static void slub_free(kmem_cache_t *cache, page_t *page, void *addr)
{
+ unsigned long flags;
+ irq_save(flags);
+
void **object = addr;
page->inuse--;
{
__slub_free(cache, page, addr);
}
+
+ irq_restore(flags);
}
void *kmem_cache_alloc(kmem_cache_t *cache, gfp_t gfpflags)
unsigned int i;
kmem_cache_t *cache = 0;
+ unsigned long flags;
+ irq_save(flags);
+
for(i=0; i<SLUB_INIT_CACHE_SIZE; ++i)
{
kmem_cache_t *p = kmalloc_caches + i;
}
}
- return kmem_cache_alloc(cache, gfpflags);
+ void *addr = kmem_cache_alloc(cache, gfpflags);
+
+ irq_restore(flags);
+
+ return addr;
}
void kfree(void *addr)
{
+ unsigned long flags;
+ irq_save(flags);
+
page_t *page = get_head_page(va2page((unsigned long)addr));
kmem_cache_t *cache = page->cache;
slub_free(cache, page, addr);
+
+ irq_restore(flags);
}
kmem_cache_t *kmem_cache_create(const char *name, size_t size, size_t align)
{
+
kmem_cache_t *cache = kmalloc(sizeof(kmem_cache_t), 0);
if(cache == 0)
return 0;
+ unsigned long flags;
+ irq_save(flags);
+
kmem_cache_init(cache, name, size, align);
list_add(&(cache->list), &slub_caches);
+ irq_restore(flags);
+
return cache;
}
extern void reboot();
-#define HZ 100
+#define HZ 10
#define CLOCK_TICK_RATE 1193180
#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ)
}
for(i=0; i<16; i++)
- enable_irq(i);
- asm("sti");
+ open_irq(i);
+
+ enable_irq();
}
void set_tss()