f'd myself over of course, scheduler can now run user programs....
This commit is contained in:
23
build_and_run.sh
Executable file
23
build_and_run.sh
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# cd rocklibc
|
||||||
|
# make clean
|
||||||
|
# make
|
||||||
|
# cd ..
|
||||||
|
|
||||||
|
cd programs
|
||||||
|
make clean
|
||||||
|
make
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
make clean
|
||||||
|
make
|
||||||
|
|
||||||
|
cd initrd
|
||||||
|
./make_img.sh
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
make -B
|
||||||
|
|
||||||
|
make run
|
||||||
|
|
||||||
@@ -2,20 +2,16 @@
|
|||||||
|
|
||||||
cd rocklibc
|
cd rocklibc
|
||||||
make clean
|
make clean
|
||||||
make
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
cd programs
|
cd programs
|
||||||
make clean
|
make clean
|
||||||
make
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
make clean
|
make clean
|
||||||
make
|
|
||||||
|
|
||||||
cd initrd
|
cd initrd
|
||||||
./make_img.sh
|
rm -rf output
|
||||||
|
rm *.elf
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
make -B
|
|
||||||
|
|
||||||
@@ -18,10 +18,22 @@ isr\num:
|
|||||||
isr_common_stub:
|
isr_common_stub:
|
||||||
pushal
|
pushal
|
||||||
|
|
||||||
|
xor %eax, %eax
|
||||||
|
mov %ds, %ax
|
||||||
|
pushl %eax
|
||||||
|
|
||||||
|
mov $0x10, %ax
|
||||||
|
mov %ax, %ds
|
||||||
|
mov %ax, %es
|
||||||
|
|
||||||
pushl %esp
|
pushl %esp
|
||||||
call common_interrupt_handler
|
call common_interrupt_handler
|
||||||
addl $4, %esp
|
addl $4, %esp
|
||||||
|
|
||||||
|
popl %eax
|
||||||
|
mov %ax, %ds
|
||||||
|
mov %ax, %es
|
||||||
|
|
||||||
popal
|
popal
|
||||||
addl $8, %esp
|
addl $8, %esp
|
||||||
iret
|
iret
|
||||||
@@ -44,17 +56,28 @@ ISR_ERRCODE 14 # Page Fault (Has Error Code!)
|
|||||||
.extern send_eoi_master # drivers/pic/pic.S
|
.extern send_eoi_master # drivers/pic/pic.S
|
||||||
isr32:
|
isr32:
|
||||||
cli
|
cli
|
||||||
pushal
|
pushal
|
||||||
|
call send_eoi_master
|
||||||
|
|
||||||
|
xor %eax, %eax
|
||||||
|
mov %ds, %ax
|
||||||
|
pushl %eax
|
||||||
|
|
||||||
|
mov $0x10, %ax
|
||||||
|
mov %ax, %ds
|
||||||
|
mov %ax, %es
|
||||||
|
|
||||||
pushl %esp
|
pushl %esp
|
||||||
call switch_context
|
call switch_context
|
||||||
movl %eax, %esp
|
movl %eax, %esp
|
||||||
|
|
||||||
call send_eoi_master
|
popl %eax
|
||||||
|
mov %ax, %ds
|
||||||
|
mov %ax, %es
|
||||||
|
|
||||||
popal
|
popal
|
||||||
sti
|
sti
|
||||||
iret
|
iret
|
||||||
|
|
||||||
ISR_NOERRCODE 33 # IRQ1 - Keyboard
|
ISR_NOERRCODE 33 # IRQ1 - Keyboard
|
||||||
|
|
||||||
|
|||||||
@@ -29,15 +29,6 @@ typedef struct __attribute__((packed)) {
|
|||||||
uint32_t base;
|
uint32_t base;
|
||||||
} idt_ptr;
|
} idt_ptr;
|
||||||
|
|
||||||
typedef struct __attribute__((packed)) {
|
|
||||||
uint32_t edi, esi, ebp, dummy, ebx, edx, ecx, eax;
|
|
||||||
|
|
||||||
uint32_t int_no;
|
|
||||||
uint32_t error_code;
|
|
||||||
|
|
||||||
uint32_t eip, cs, eflags, u_esp, u_ss;
|
|
||||||
} intr_regs_t;
|
|
||||||
|
|
||||||
// (interrupts.S)
|
// (interrupts.S)
|
||||||
extern void load_idt(void);
|
extern void load_idt(void);
|
||||||
extern void isr0();
|
extern void isr0();
|
||||||
@@ -89,7 +80,7 @@ void init_idt() {
|
|||||||
if (isr_stub_table[i] != 0) {
|
if (isr_stub_table[i] != 0) {
|
||||||
set_idtr(i, isr_stub_table[i], SEGMENT_KERN, ATTR_KERN_32);
|
set_idtr(i, isr_stub_table[i], SEGMENT_KERN, ATTR_KERN_32);
|
||||||
} else {
|
} else {
|
||||||
set_idtr(i, 0, SEGMENT_KERN, 0);
|
set_idtr(i, 0, SEGMENT_KERN, ATTR_KERN_32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +89,15 @@ void init_idt() {
|
|||||||
load_idt();
|
load_idt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct __attribute__((packed)) {
|
||||||
|
uint32_t ds;
|
||||||
|
uint32_t edi, esi, ebp, dummy, ebx, edx, ecx, eax;
|
||||||
|
|
||||||
|
uint32_t int_no;
|
||||||
|
uint32_t error_code;
|
||||||
|
|
||||||
|
uint32_t eip, cs, eflags, u_esp, u_ss;
|
||||||
|
} intr_regs_t;
|
||||||
void common_interrupt_handler(intr_regs_t *args) {
|
void common_interrupt_handler(intr_regs_t *args) {
|
||||||
switch (args->int_no) {
|
switch (args->int_no) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -116,7 +116,6 @@ void common_interrupt_handler(intr_regs_t *args) {
|
|||||||
case 13:
|
case 13:
|
||||||
case 15:
|
case 15:
|
||||||
case 16:
|
case 16:
|
||||||
asm volatile("cli");
|
|
||||||
kprintf("\n--- CPU Exception ---\n");
|
kprintf("\n--- CPU Exception ---\n");
|
||||||
kprintf("Error: [%d] %s\n", args->int_no, err_messages[args->int_no]);
|
kprintf("Error: [%d] %s\n", args->int_no, err_messages[args->int_no]);
|
||||||
kprintf("Error Code: 0x%x\n", args->error_code);
|
kprintf("Error Code: 0x%x\n", args->error_code);
|
||||||
@@ -125,10 +124,10 @@ void common_interrupt_handler(intr_regs_t *args) {
|
|||||||
kprintf("EAX: 0x%x\n", args->eax);
|
kprintf("EAX: 0x%x\n", args->eax);
|
||||||
kprintf("EFLAGS: 0x%x\n", args->eflags);
|
kprintf("EFLAGS: 0x%x\n", args->eflags);
|
||||||
kprintf("Code Segment: 0x%x\n", args->cs);
|
kprintf("Code Segment: 0x%x\n", args->cs);
|
||||||
|
kprintf("Calling Data Segment: 0x%x\n", args->ds);
|
||||||
kprintf("Current cr3: 0x%x\n", fetch_cr3());
|
kprintf("Current cr3: 0x%x\n", fetch_cr3());
|
||||||
kprintf("tss.esp0: 0x%x\n", tss.esp0);
|
kprintf("tss.esp0: 0x%x\n", tss.esp0);
|
||||||
process_t* task = current_task();
|
kprintf("instruction: 0x%x\n", *(uint32_t*)args->eip);
|
||||||
kprintf("Task kstack_top: 0x%x\n", task->kstack_top);
|
|
||||||
asm volatile("hlt");
|
asm volatile("hlt");
|
||||||
break;
|
break;
|
||||||
case 14:{
|
case 14:{
|
||||||
@@ -154,6 +153,10 @@ void common_interrupt_handler(intr_regs_t *args) {
|
|||||||
asm volatile("hlt");
|
asm volatile("hlt");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 32: {
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 33: {
|
case 33: {
|
||||||
kprintf("ps2 keyboard interrupt\n");
|
kprintf("ps2 keyboard interrupt\n");
|
||||||
uint8_t data = ps2_read_data();
|
uint8_t data = ps2_read_data();
|
||||||
|
|||||||
@@ -69,17 +69,13 @@ uint32_t switch_context(uint32_t current_esp) {
|
|||||||
|
|
||||||
uint32_t current_cr3 = fetch_cr3();
|
uint32_t current_cr3 = fetch_cr3();
|
||||||
if (current_cr3 != process_table[current_process].cr3) {
|
if (current_cr3 != process_table[current_process].cr3) {
|
||||||
kprintf("switching cr3 | old: 0x%x | new: 0x%x\n", current_cr3, process_table[current_process].cr3);
|
|
||||||
load_pd((void*)process_table[current_process].cr3);
|
load_pd((void*)process_table[current_process].cr3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process_table[current_process].flags & PROCESS_FLAG_USER) {
|
if (process_table[current_process].flags & PROCESS_FLAG_USER) {
|
||||||
tss.esp0 = process_table[current_process].kstack_top;
|
tss.esp0 = process_table[current_process].kstack_top;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_ready) {
|
|
||||||
kprintf("found ready task %d | cr3: 0x%x\n", current_process, process_table[current_process].cr3);
|
|
||||||
}
|
|
||||||
return process_table[current_process].esp;
|
return process_table[current_process].esp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,12 +119,12 @@ int create_task(uint32_t entry_point, uint32_t cr3, int user, uint32_t u_esp) {
|
|||||||
if (user) {
|
if (user) {
|
||||||
*(--esp) = 0x23; // User Data Segment (SS) with RPL 3 (0x20 | 3)
|
*(--esp) = 0x23; // User Data Segment (SS) with RPL 3 (0x20 | 3)
|
||||||
*(--esp) = u_esp; // User Stack Pointer (ESP) - location mapped in user space
|
*(--esp) = u_esp; // User Stack Pointer (ESP) - location mapped in user space
|
||||||
*(--esp) = 0x0202; // EFLAGS (Interrupts enabled)
|
*(--esp) = 0x202; // EFLAGS (Interrupts enabled)
|
||||||
*(--esp) = 0x1B; // User Code Segment (CS) with RPL 3 (0x18 | 3)
|
*(--esp) = 0x1B; // User Code Segment (CS) with RPL 3 (0x18 | 3)
|
||||||
*(--esp) = entry_point; // EIP
|
*(--esp) = entry_point; // EIP
|
||||||
} else {
|
} else {
|
||||||
// IRET values for Ring 0
|
// IRET values for Ring 0
|
||||||
*(--esp) = 0x0202; // EFLAGS
|
*(--esp) = 0x202; // EFLAGS
|
||||||
*(--esp) = 0x08; // Kernel Code Segment (CS)
|
*(--esp) = 0x08; // Kernel Code Segment (CS)
|
||||||
*(--esp) = entry_point; // EIP
|
*(--esp) = entry_point; // EIP
|
||||||
}
|
}
|
||||||
@@ -142,6 +138,12 @@ int create_task(uint32_t entry_point, uint32_t cr3, int user, uint32_t u_esp) {
|
|||||||
*(--esp) = 0; // ESI
|
*(--esp) = 0; // ESI
|
||||||
*(--esp) = 0; // EDI
|
*(--esp) = 0; // EDI
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
*(--esp) = 0x23; // User Data Segment Selector (RPL 3)
|
||||||
|
} else {
|
||||||
|
*(--esp) = 0x10; // Kernel Data Segment Selector (RPL 0)
|
||||||
|
}
|
||||||
|
|
||||||
process->esp = (uint32_t)esp;
|
process->esp = (uint32_t)esp;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,33 +4,33 @@
|
|||||||
syscall_handler:
|
syscall_handler:
|
||||||
cli
|
cli
|
||||||
|
|
||||||
pushfl
|
push $0
|
||||||
pushl %cs
|
push $0x80
|
||||||
|
|
||||||
movl 8(%esp), %eax
|
pusha
|
||||||
pushl %eax
|
|
||||||
movl 4(%esp), %ebx # Get CS
|
|
||||||
movl %ebx, 8(%esp) # Move CS over Old EIP
|
|
||||||
movl 0(%esp), %ebx # Get Return EIP
|
|
||||||
movl %ebx, 4(%esp) # Move Return EIP over CS
|
|
||||||
addl $4, %esp # Adjust stack pointer
|
|
||||||
|
|
||||||
movw %ds, %ax
|
push %ds
|
||||||
pushl %eax
|
push %es
|
||||||
|
push %fs
|
||||||
|
push %gs
|
||||||
|
|
||||||
pushal
|
mov $0x10, %ax
|
||||||
|
mov %ax, %ds
|
||||||
pushl %esp
|
mov %ax, %es
|
||||||
call switch_context
|
mov %ax, %fs
|
||||||
movl %eax, %esp
|
mov %ax, %gs
|
||||||
|
|
||||||
popal
|
|
||||||
|
|
||||||
popl %eax
|
push %esp
|
||||||
movw %ax, %ds
|
call syscall
|
||||||
movw %ax, %es
|
add $4, %esp
|
||||||
movw %ax, %fs
|
|
||||||
movw %ax, %gs
|
mov 28(%esp), %eax
|
||||||
|
|
||||||
sti
|
pop %gs
|
||||||
|
pop %fs
|
||||||
|
pop %es
|
||||||
|
pop %ds
|
||||||
|
|
||||||
|
popa
|
||||||
|
add $8, %esp
|
||||||
iret
|
iret
|
||||||
@@ -18,6 +18,7 @@ typedef struct registers {
|
|||||||
|
|
||||||
|
|
||||||
static int32_t sys_exit(int status) {
|
static int32_t sys_exit(int status) {
|
||||||
|
asm volatile("cli");
|
||||||
asm volatile("hlt");
|
asm volatile("hlt");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
.global _start
|
.global _start
|
||||||
|
|
||||||
.section .text
|
.section .text
|
||||||
_start:
|
_start:
|
||||||
xor %ebp, %ebp
|
xor %ebp, %ebp
|
||||||
push %ebp
|
push %ebp
|
||||||
mov %esp, %ebp
|
mov %esp, %ebp
|
||||||
@@ -13,9 +13,10 @@ _start:
|
|||||||
push %ecx
|
push %ecx
|
||||||
push %ebx
|
push %ebx
|
||||||
push %eax
|
push %eax
|
||||||
1: jmp 1b
|
|
||||||
call main
|
call main
|
||||||
|
|
||||||
push %eax
|
push %eax
|
||||||
|
1: jmp 1b
|
||||||
call exit
|
call exit
|
||||||
1: jmp 1b
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char *argv[]) {
|
||||||
printf("RockOS booting...\n");
|
printf("RockOS booting...\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -21,4 +21,4 @@ $(TARGET): crt0.o main.o ../rocklibc/rlibc.a
|
|||||||
clean:
|
clean:
|
||||||
rm -f *.o $(TARGET)
|
rm -f *.o $(TARGET)
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean test
|
||||||
@@ -96,7 +96,7 @@ void * sbrk(intptr_t increment) {
|
|||||||
|
|
||||||
if (increment == 0) {
|
if (increment == 0) {
|
||||||
return (void *)current_break;
|
return (void *)current_break;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t new_break = (uint32_t)((intptr_t)current_break + increment);
|
uint32_t new_break = (uint32_t)((intptr_t)current_break + increment);
|
||||||
|
|
||||||
@@ -109,6 +109,6 @@ void * sbrk(intptr_t increment) {
|
|||||||
return (void *)-1;
|
return (void *)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void exit(int status) {
|
void _exit(int status) {
|
||||||
_PDCLIB_exit(status);
|
_PDCLIB_exit(status);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user