Fixed syscalls
This commit is contained in:
parent
ddb45b819b
commit
645626551b
2
Makefile
2
Makefile
|
@ -22,6 +22,7 @@ KERNEL_OBJS=\
|
|||
kernel/kernel.o \
|
||||
kernel/debugging.o \
|
||||
kernel/elf.o \
|
||||
kernel/syscall.o \
|
||||
kernel/keyboard.o \
|
||||
|
||||
LIB_OBJS=\
|
||||
|
@ -30,6 +31,7 @@ $(ARCHDIR)/tty.o \
|
|||
$(ARCHDIR)/strlib.o \
|
||||
$(ARCHDIR)/interrupts/idt.o \
|
||||
$(ARCHDIR)/interrupts/interrupt.o \
|
||||
$(ARCHDIR)/interrupts/syscall.o \
|
||||
$(ARCHDIR)/gdt.o \
|
||||
$(ARCHDIR)/userland.o \
|
||||
$(ARCHDIR)/interrupts/pic.o \
|
||||
|
|
|
@ -139,23 +139,14 @@ void idt_init()
|
|||
entry = generate_entry(true, keyboard_interrupt, 0xE, 0, 0x8);
|
||||
add_entry(entry, IRQ1);
|
||||
|
||||
struct InterruptDescriptor print_entry;
|
||||
print_entry.present = true;
|
||||
print_entry.offset = (uint32_t)print;
|
||||
print_entry.gate_type = 0xE;
|
||||
print_entry.ring = 3;
|
||||
print_entry.selector = 0x8;
|
||||
struct InterruptDescriptor syscall_entry;
|
||||
syscall_entry.present = true;
|
||||
syscall_entry.offset = (uint32_t)syscall;
|
||||
syscall_entry.gate_type = 0xE;
|
||||
syscall_entry.ring = 3;
|
||||
syscall_entry.selector = 0x8;
|
||||
|
||||
add_entry(print_entry, 0x80);
|
||||
|
||||
struct InterruptDescriptor input_entry;
|
||||
input_entry.present = true;
|
||||
input_entry.offset = (uint32_t)input;
|
||||
input_entry.gate_type = 0xE;
|
||||
input_entry.ring = 3;
|
||||
input_entry.selector = 0x8;
|
||||
|
||||
add_entry(input_entry, 0x81);
|
||||
add_entry(syscall_entry, 0x80);
|
||||
|
||||
load_idt();
|
||||
}
|
||||
|
|
|
@ -25,65 +25,39 @@ static void stack_trace()
|
|||
}
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void divide_by_zero(struct interrupt_frame* frame)
|
||||
__attribute__((interrupt)) void divide_by_zero(void*)
|
||||
{
|
||||
terminal_writestring("Yo dude u cant divide by zero yao\n");
|
||||
while (1) { }
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void general_protection_fault(struct interrupt_frame* frame)
|
||||
__attribute__((interrupt)) void general_protection_fault(void*)
|
||||
{
|
||||
terminal_writestring("GPF handler called\n");
|
||||
while (1) { }
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void double_fault(struct interrupt_frame* frame)
|
||||
__attribute__((interrupt)) void double_fault(void*)
|
||||
{
|
||||
stack_trace();
|
||||
terminal_writestring("2 Errors in a row, u better behave naughty naughty\n");
|
||||
while (1) { }
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void exception(struct interrupt_frame* frame)
|
||||
__attribute__((interrupt)) void exception(void*)
|
||||
{
|
||||
terminal_writestring("Some weird error code stuff\n");
|
||||
while (1) { }
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void print(struct interrupt_frame* frame)
|
||||
{
|
||||
char* start;
|
||||
asm("mov %%edx, %0" : "=r" (start));
|
||||
terminal_writestring(start);
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void input(struct interrupt_frame* frame)
|
||||
{
|
||||
char* buffer;
|
||||
asm("mov %%edx, %0" : "=r" (buffer));
|
||||
|
||||
/* size_t index = 0;
|
||||
|
||||
char current_character = get_last_key_pressed();
|
||||
while (current_character != '\n') {
|
||||
char tmp = get_last_key_pressed();
|
||||
if (current_character != -1 && tmp != current_character) {
|
||||
buffer[index] = current_character;
|
||||
terminal_putchar(current_character);
|
||||
index++;
|
||||
}
|
||||
current_character = tmp;
|
||||
}
|
||||
buffer[index] = '\0'; */
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void keyboard_interrupt(struct interrupt_frame* frame)
|
||||
__attribute__((interrupt)) void keyboard_interrupt(void*)
|
||||
{
|
||||
uint8_t scancode = inb(0x60);
|
||||
handle_keyboard(scancode);
|
||||
outb(0x20, 0x20);
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void irq(struct interrupt_frame* frame)
|
||||
__attribute__((interrupt)) void irq(void*)
|
||||
{
|
||||
outb(0x20, 0x20);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ __attribute__((interrupt)) void double_fault(struct interrupt_frame* frame);
|
|||
|
||||
__attribute__((interrupt)) void exception(struct interrupt_frame* frame);
|
||||
|
||||
__attribute__((interrupt)) void print(struct interrupt_frame* frame);
|
||||
__attribute__((interrupt)) void input(struct interrupt_frame* frame);
|
||||
__attribute__((interrupt)) void syscall(void*);
|
||||
|
||||
__attribute__((interrupt)) void keyboard_interrupt(struct interrupt_frame* frame);
|
||||
__attribute__((interrupt)) void irq(struct interrupt_frame* frame);
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
|
||||
|
||||
void init_pic() {
|
||||
uint8_t a1, a2;
|
||||
uint8_t a1;
|
||||
|
||||
a1 = inb(PIC1_DATA); // save masks
|
||||
a2 = inb(PIC2_DATA);
|
||||
inb(PIC2_DATA);
|
||||
|
||||
outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4); // starts the initialization sequence (in cascade mode)
|
||||
io_wait();
|
||||
|
|
18
arch/i686/interrupts/syscall.s
Normal file
18
arch/i686/interrupts/syscall.s
Normal file
|
@ -0,0 +1,18 @@
|
|||
.extern _syscall
|
||||
.global syscall
|
||||
syscall:
|
||||
sti
|
||||
|
||||
push %edx
|
||||
push %ecx
|
||||
push %ebx
|
||||
push %eax
|
||||
|
||||
call _syscall
|
||||
|
||||
pop %eax
|
||||
pop %ebx
|
||||
pop %ecx
|
||||
pop %edx
|
||||
iret
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
extern char keyboard_buffer[100];
|
||||
extern size_t keyboard_buffer_top;
|
||||
void handle_keyboard(uint8_t scancode);
|
||||
|
|
|
@ -10,34 +10,12 @@
|
|||
#endif
|
||||
|
||||
uint8_t program[] = {
|
||||
0xba, 0x09, 0x00, 0x80, 0x00, // mov $string, %edx
|
||||
0xba, 0x01, 0x00, 0x00, 0x00, // mov 1, %edx
|
||||
0xb8, 0xff, 0x00, 0x80, 0x00, // mov $buffer, %eax
|
||||
0xcd, 0x80, // int 0x80
|
||||
0xba, 0x00, 0x00, 0x00, 0x00, // mov 0, %edx
|
||||
0xcd, 0x80, // int 0x80
|
||||
0xeb, 0xfe, // jmp .
|
||||
'H',
|
||||
'e',
|
||||
'l',
|
||||
'l',
|
||||
'o',
|
||||
' ',
|
||||
'W',
|
||||
'o',
|
||||
'r',
|
||||
'l',
|
||||
'd',
|
||||
' ',
|
||||
'f',
|
||||
'r',
|
||||
'o',
|
||||
'm',
|
||||
' ',
|
||||
'r',
|
||||
'i',
|
||||
'n',
|
||||
'g',
|
||||
' ',
|
||||
'3',
|
||||
'!',
|
||||
0x00,
|
||||
};
|
||||
|
||||
void kernel_main(void)
|
||||
|
@ -47,8 +25,5 @@ void kernel_main(void)
|
|||
|
||||
init_pic();
|
||||
idt_init();
|
||||
// run_program(program, sizeof(program));
|
||||
while (true) {
|
||||
|
||||
}
|
||||
run_program(program, sizeof(program));
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
static bool is_in_shift;
|
||||
|
||||
char buffer[100];
|
||||
static size_t i;
|
||||
char keyboard_buffer[100];
|
||||
size_t keyboard_buffer_top;
|
||||
|
||||
static unsigned char keyboard_char(unsigned char scancode)
|
||||
{
|
||||
|
@ -125,8 +125,8 @@ void handle_keyboard(uint8_t scancode) {
|
|||
return;
|
||||
}
|
||||
|
||||
buffer[i] = character;
|
||||
i++;
|
||||
keyboard_buffer[keyboard_buffer_top] = character;
|
||||
keyboard_buffer_top++;
|
||||
|
||||
terminal_putchar(character);
|
||||
}
|
||||
|
|
42
kernel/syscall.c
Normal file
42
kernel/syscall.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <kernel/tty.h>
|
||||
#include <kernel/keyboard.h>
|
||||
#include <debugging.h>
|
||||
|
||||
static void print(char* buffer)
|
||||
{
|
||||
terminal_writestring(buffer);
|
||||
}
|
||||
|
||||
static void* memcpy(void* restrict dstptr, const void* restrict srcptr, size_t size) {
|
||||
unsigned char* dst = (unsigned char*) dstptr;
|
||||
const unsigned char* src = (const unsigned char*) srcptr;
|
||||
for (size_t i = 0; i < size; i++)
|
||||
dst[i] = src[i];
|
||||
return dstptr;
|
||||
}
|
||||
|
||||
static void input(char* buffer)
|
||||
{
|
||||
while (true) {
|
||||
for (int i = 0; i < keyboard_buffer_top; i++) {
|
||||
buffer[i] = keyboard_buffer[i];
|
||||
if (keyboard_buffer[i] == '\n') {
|
||||
buffer[keyboard_buffer_top] = 0;
|
||||
keyboard_buffer_top = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _syscall(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
|
||||
{
|
||||
switch (d) {
|
||||
case 0x00:
|
||||
print((char*) a);
|
||||
break;
|
||||
case 0x01:
|
||||
input((char*) a);
|
||||
break;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue