userland HELLO WORLD
This commit is contained in:
+41
-5
@@ -4,21 +4,57 @@
|
|||||||
* @license GPL-3.0-only
|
* @license GPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "sched/scheduler.h"
|
||||||
#include <arch/x86.h>
|
#include <arch/x86.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <io/term/term.h>
|
||||||
|
|
||||||
|
void sys_write(unsigned int fd, const char* buf, size_t count)
|
||||||
|
{
|
||||||
|
switch (fd) {
|
||||||
|
case 1: //stdout
|
||||||
|
for (size_t i=0; i<count; i++) {
|
||||||
|
internal_putc(buf[i], NULL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2: //stderr
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* syscall_handler - System call dispatcher
|
||||||
|
* @regs: CPU state
|
||||||
|
*
|
||||||
|
* This function is called from the interrupt dispatcher,
|
||||||
|
* when an interrupt 0x80 is emitted from userland.
|
||||||
|
*
|
||||||
|
* It switches control to the syscall number provided
|
||||||
|
* in %rax.
|
||||||
|
*
|
||||||
|
* We try to follow the System V convention here:
|
||||||
|
* - syscall number in %rax
|
||||||
|
* - args in %rdi, %rsi, %rdx, %r10, %r8, %r9
|
||||||
|
* - return value (if any) in %rax
|
||||||
|
*
|
||||||
|
* Return:
|
||||||
|
* <regs> - CPU state after system call
|
||||||
|
*/
|
||||||
struct cpu_status* syscall_handler(struct cpu_status* regs)
|
struct cpu_status* syscall_handler(struct cpu_status* regs)
|
||||||
{
|
{
|
||||||
DEBUG("Syscall %lx with argument %lx", regs->rdi, regs->rsi);
|
DEBUG("Syscall %lx with (arg0=%lx arg1=%lx)", regs->rax, regs->rdi, regs->rsi);
|
||||||
|
|
||||||
switch (regs->rdi)
|
switch (regs->rax)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0: //sys_read
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1: //sys_write
|
||||||
|
sys_write(regs->rdi, (char*)regs->rsi, regs->rdx);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
regs->rsi = 0xdeadbeef;
|
regs->rax = 0xbad515ca11;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -1,4 +1,16 @@
|
|||||||
bits 64
|
bits 64
|
||||||
|
|
||||||
|
section .data
|
||||||
|
hi db "hi from userland :) we did it man", 0
|
||||||
|
|
||||||
|
section .text
|
||||||
|
|
||||||
hello:
|
hello:
|
||||||
mov rax, 0xcafebabe
|
mov rax, 0x1 ;sys_write
|
||||||
|
mov rdi, 0x1 ;stdout
|
||||||
|
lea rsi, [rel hi] ;char* buf
|
||||||
|
mov rdx, 33 ;count
|
||||||
|
int 0x80
|
||||||
|
|
||||||
|
.loop:
|
||||||
|
jmp .loop
|
||||||
Reference in New Issue
Block a user