*
*--------------------------------------------------------------------------
*/
-#define ASM_FILE
#define ASM
#include "boot.h"
#include "system.h"
.short MULTIBOOT_HEADER_TAG_END
.short 0
.long 8
-multiboot2_header_end:
\ No newline at end of file
+multiboot2_header_end:
#define MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED 1
#define MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED 2
-#ifndef ASM_FILE
+#ifndef ASM
typedef unsigned char multiboot_uint8_t;
typedef unsigned short multiboot_uint16_t;
multiboot_uint32_t load_base_addr;
};
-#endif /* ! ASM_FILE */
+#endif /* ! ASM */
-#endif /* ! MULTIBOOT_HEADER */
\ No newline at end of file
+#endif /* ! MULTIBOOT_HEADER */
if (ch == '\n') {
clear(&cnsl.wr_q);
+ return 0; // TODO FIX
while (get(&cnsl.sc_q, &ch)) put(&cnsl.rd_q, ch);
wake_up(&rdwq);
}
#define KRNL_INIT_STACK_SIZE 4096
+#ifndef ASM
+// 内核进程
+void root_task_entry();
+void init_task_entry();
+void disk_task_entry();
+void user_task_entry();
+
+extern uint32_t preempt_count;
+#endif
+
#endif //_SYSTEM_H
#define TASK_SIZE 4096
-#define TI_preempt_cnt 0
-
#ifndef ASM
#include <fs.h>
#include <list.h>
typedef union task_union {
struct {
- unsigned long preempt_cnt;
-
unsigned long esp0; /* kernel stack */
/* for context switch */
printl(MPL_CLOCK, "clock irq: %d", jiffies);
}
- unsigned long iflags;
- irq_save(iflags);
+ // unsigned long iflags;
+ // irq_save(iflags);
task_union *p = 0;
task_union *t = 0;
}
}
- irq_restore(iflags);
+ // irq_restore(iflags);
}
}
}
+void ack_i8259_irq(unsigned int irq) {
+ unsigned char mask = 0;
+
+ if (irq & 8) // Slave
+ {
+#if PIC_AEOI
+ // ...
+#else
+ // Specific EOI to slave
+ outb(0x60 + (irq & 0x07), PIC_SLAVE_CMD);
+ // Specific EOI to master
+ outb(0x60 + (PIC_CASCADE_IR & 0x07), PIC_MASTER_CMD);
+#endif
+ } else // Master
+ {
+#if PIC_AEOI
+ // ...
+#else
+ // Specific EOI to master
+ outb(0x60 + irq, PIC_MASTER_CMD);
+#endif
+ }
+}
+
irq_chip_t i8259_chip = {
.name = "XT-PIC",
.enable = enable_i8259_irq,
.disable = disable_i8259_irq,
- .ack = mask_ack_i8259_irq,
+ .ack = ack_i8259_irq,
};
void do_i8259_IRQ(pt_regs_t *regs, unsigned int irq) {}
.global _irq_handler
.extern irq_handler
.extern schedule
+.extern preempt_count
_irq_handler:
SAVE_REGS
movl %esp, %eax
call irq_handler
- cmpl $0, TI_preempt_cnt(%ebp)
+ cmpl $0, (preempt_count)
jnz restore_regs
call schedule
#include <atomic.h>
#include <errno.h>
#include <irq.h>
+#include <system.h>
#include <task.h>
irq_desc_t irq_desc[NR_IRQS];
irq_action_t *action = p->action;
- atomic_inc(&(current->preempt_cnt));
+ atomic_inc(&preempt_count);
unsigned long esp;
asm("movl %%esp, %%eax" : "=a"(esp));
- printl(MPL_PREEMPT, "current %08x cr3 %08x preempt %d esp %08x", current, current->cr3, current->preempt_cnt, esp);
+ printl(MPL_PREEMPT, "current %08x cr3 %08x preempt %d esp %08x", current, current->cr3, preempt_count, esp);
p->chip->ack(irq);
- sti();
while (action && action->handler) {
action->handler(irq, regs, action->dev_id);
action = action->next;
}
- cli();
- p->chip->enable(irq);
+ // sti();
+ // ....
+ // cli();
- atomic_dec(&(current->preempt_cnt));
+ atomic_dec(&preempt_count);
}
-int request_irq(unsigned int irq, void (*handler)(unsigned int, pt_regs_t *, void *), const char *devname, void *dev_id) {
+int request_irq(unsigned int irq, void (*handler)(unsigned int, pt_regs_t *, void *), const char *devname,
+ void *dev_id) {
irq_action_t *p;
if (irq >= NR_IRQS) return -EINVAL;
void init_root_task() {
int i;
- root_task.preempt_cnt = 0;
root_task.pid = get_next_pid();
root_task.ppid = 0;
root_task.state = TASK_RUNNING;
Desc idt[NIDT] __attribute__((__aligned__(8)));
Desc gdt[NGDT] __attribute__((__aligned__(8)));
char gdtr[6] __attribute__((__aligned__(4)));
-char idtr[6] __attribute__((__aligned__(4)));
\ No newline at end of file
+char idtr[6] __attribute__((__aligned__(4)));
+
+uint32_t preempt_count = 0x00;
\ No newline at end of file
void disk_task_entry() {
while (1) {
- schedule();
+ // TODO
+ asm("hlt;");
+ //schedule();
}
-}
\ No newline at end of file
+}
#include <system.h>
#include <types.h>
-void disk_task_entry();
-void init_task_entry();
-void user_task_entry();
int do_fork(pt_regs_t *regs, unsigned long flags);
void kernel_task(char *name, void *entry) {