Programs: loading, 1 fake syscall.. (bad) #12
@@ -25,6 +25,8 @@ extern void irq13();
|
||||
extern void irq14();
|
||||
extern void irq15();
|
||||
|
||||
extern void syscall_common_stub();
|
||||
|
||||
void *irq_routines[16] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@@ -76,6 +78,8 @@ void irq_install()
|
||||
idt_set_gate(46, (unsigned)irq14, 0x08, 0x8E);
|
||||
idt_set_gate(47, (unsigned)irq15, 0x08, 0x8E);
|
||||
printf("[kernel] installed irq 0-15\n");
|
||||
|
||||
idt_set_gate(0x80, (unsigned long)syscall_common_stub, 0x08, 0x8E);
|
||||
}
|
||||
|
||||
void irq_handler(struct regs *r)
|
||||
|
||||
@@ -210,6 +210,37 @@ irq_common_stub:
|
||||
add esp, 8
|
||||
iret
|
||||
|
||||
; we'll be placing the syscall_common_stub here.
|
||||
; push everything, then call syscall_handler (be sure to define it extern)
|
||||
; then pop back everything and iret
|
||||
extern syscall_handler
|
||||
|
||||
global syscall_common_stub
|
||||
syscall_common_stub:
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
push fs
|
||||
push gs
|
||||
|
||||
mov eax, ds
|
||||
push eax ; save ds
|
||||
mov ax, 0x10 ; kernel segment
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
|
||||
call syscall_handler
|
||||
|
||||
pop eax
|
||||
mov ds, eax ; restore ds
|
||||
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
iret
|
||||
|
||||
section .bss
|
||||
align 4
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#include <stdarg.h>
|
||||
#include "../libc/stdio.h"
|
||||
#include "syscall.h"
|
||||
|
||||
syscall_t syscalls[] = {
|
||||
(syscall_t)printf,
|
||||
};
|
||||
|
||||
int syscall_handler(int syscall_num, ...)
|
||||
{
|
||||
if ((unsigned)syscall_num < sizeof(syscalls)/sizeof(syscall_t))
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, syscall_num);
|
||||
syscalls[syscall_num](va_arg(args, const char*));
|
||||
va_end(args);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef SYSCALL_H
|
||||
#define SYSCALL_H
|
||||
|
||||
#define SYSCALL_PRINTF 0
|
||||
|
||||
typedef void (*syscall_t)();
|
||||
|
||||
#endif
|
||||
33
src/kernel/syscalls.c
Normal file
33
src/kernel/syscalls.c
Normal file
@@ -0,0 +1,33 @@
|
||||
// System calls
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https://github.com/xamidev/blankos
|
||||
|
||||
#include "../libc/stdio.h"
|
||||
|
||||
void handle_syscall(int syscall_number, void* arg)
|
||||
{
|
||||
switch(syscall_number)
|
||||
{
|
||||
case 1:
|
||||
puts("Here's the syscall 1\n");
|
||||
break;
|
||||
default:
|
||||
printf("[error] Invalid syscall number '%d'!\n", syscall_number);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void syscall_handler()
|
||||
{
|
||||
int syscall_number;
|
||||
void* arg;
|
||||
// mov eax, syscall_number
|
||||
// mov ebx, arg
|
||||
asm volatile("mov %%eax, %0" : "=r"(syscall_number));
|
||||
asm volatile("mov %%ebx, %0" : "=r"(arg));
|
||||
|
||||
printf("[syscall] syscall_number=%d, arg=%p\n", syscall_number, arg);
|
||||
|
||||
handle_syscall(syscall_number, arg);
|
||||
}
|
||||
@@ -39,5 +39,7 @@ extern volatile unsigned long global_ticks;
|
||||
|
||||
extern unsigned int g_multiboot_info_address;
|
||||
|
||||
void syscall_handler();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
void user_printf(const char* format) {
|
||||
asm volatile ("int $0x80" : : "a"(1), "b"(format));
|
||||
void user_syscall(int syscall_no) {
|
||||
asm volatile ("mov %0, %%eax" : : "r"(syscall_no));
|
||||
asm volatile ("int $0x80");
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
user_printf("Hello, world, from a PROGRAM!\n");
|
||||
user_syscall(1);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user