ISR(32)
ISR(33)
+ISR(34)
ISR(201)
ISR(202)
// LunaixOS related
#define LUNAIX_SYS_PANIC 32
#define LUNAIX_SYS_CALL 33
+#define LUNAIX_SCHED 34
#define EX_INTERRUPT_BEGIN 200
: "r"(interm));
}
+static inline void
+cpu_int(int vect)
+{
+ asm("int %0" ::"i"(vect));
+}
+
void
cpu_rdmsr(uint32_t msr_idx, uint32_t* reg_high, uint32_t* reg_low);
schedule();
void
-sched_yield();
+sched_yieldk();
#endif /* __LUNAIX_SCHEDULER_H */
// We make this a non-trap entry, and enable interrupt
// only when needed!
_set_idt_intr_entry(LUNAIX_SYS_CALL, 0x08, _asm_isr33, 3);
+
+ _set_idt_intr_entry(LUNAIX_SCHED, 0x08, _asm_isr34, 0);
}
\ No newline at end of file
isr_template LUNAIX_SYS_PANIC
isr_template LUNAIX_SYS_CALL
+ isr_template LUNAIX_SCHED
isr_template APIC_ERROR_IV
isr_template APIC_LINT0_IV
#include <arch/x86/interrupts.h>
#include <lunaix/lxconsole.h>
#include <lunaix/process.h>
+#include <lunaix/sched.h>
#include <lunaix/spike.h>
#include <lunaix/syslog.h>
#include <lunaix/tty/tty.h>
spin();
}
+void
+intr_routine_sched(const isr_param* param)
+{
+ schedule();
+}
+
void
intr_routine_init()
{
intr_subscribe(FAULT_GENERAL_PROTECTION, intr_routine_general_protection);
intr_subscribe(FAULT_PAGE_FAULT, intr_routine_page_fault);
intr_subscribe(FAULT_STACK_SEG_FAULT, intr_routine_page_fault);
+
intr_subscribe(LUNAIX_SYS_PANIC, intr_routine_sys_panic);
+ intr_subscribe(LUNAIX_SCHED, intr_routine_sched);
+
intr_subscribe(APIC_SPIV_IV, intr_routine_apic_spi);
intr_subscribe(APIC_ERROR_IV, intr_routine_apic_error);
goto done;
}
- cpu_enable_interrupt();
- errno = file->ops.read(file, buf, count, file->f_pos);
- cpu_disable_interrupt();
+ __SYSCALL_INTERRUPTIBLE(
+ { errno = file->ops.read(file, buf, count, file->f_pos); })
if (errno > 0) {
file->f_pos += errno;
goto done;
}
- cpu_enable_interrupt();
- errno = file->ops.write(file, buf, count, file->f_pos);
- cpu_disable_interrupt();
+ __SYSCALL_INTERRUPTIBLE(
+ { errno = file->ops.write(file, buf, count, file->f_pos); })
if (errno > 0) {
file->f_pos += errno;
goto done;
}
+ size_t len = 0;
+
if (!__current->cwd) {
*buf = PATH_DELIM;
- goto done;
- }
-
- size_t len = vfs_get_path(__current->cwd, buf, size, 0);
- if (len == size) {
- errno = ERANGE;
- goto done;
+ len = 1;
+ } else {
+ len = vfs_get_path(__current->cwd, buf, size, 0);
+ if (len == size) {
+ errno = ERANGE;
+ goto done;
+ }
}
buf[len + 1] = '\0';
// When a key is arrived, one of the processes will win the race and
// swallow it (advancing the key buffer pointer)
if (!kbd_recv_key(&keyevent)) {
- sched_yield();
+ sched_yieldk();
continue;
}
if (!(keyevent.state & KBD_KEY_FPRESSED)) {
run(next);
}
+void
+sched_yieldk()
+{
+ cpu_int(LUNAIX_SCHED);
+}
+
__DEFINE_LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
{
if (!seconds) {
}
wpid = wpid ? wpid : -__current->pgid;
- cpu_enable_interrupt();
repeat:
llist_for_each(proc, n, &__current->children, siblings)
{
return 0;
}
// 放弃当前的运行机会
- sched_yield();
+ sched_yieldk();
goto repeat;
done:
- cpu_disable_interrupt();
status_flags |= PEXITSIG * (proc->sig_inprogress != 0);
if (status) {
*status = proc->exit_code | status_flags;
struct mm_region *pos, *n;
llist_for_each(pos, n, &proc->mm.regions.head, head)
{
- lxfree(pos);
+ vfree(pos);
}
vmm_mount_pd(PD_MOUNT_1, proc->page_table);
{
__current->flags |= PROC_FINPAUSE;
- __SYSCALL_INTERRUPTIBLE({
- while ((__current->flags & PROC_FINPAUSE)) {
- sched_yield();
- }
- })
+ while ((__current->flags & PROC_FINPAUSE)) {
+ sched_yieldk();
+ }
+
__current->k_status = EINTR;
}
}
}
-void
-sched_yield()
-{
- sched_ticks_counter = sched_ticks;
-}
-
static void
temp_intr_routine_rtc_tick(const isr_param* param)
{