Proper userspace program
This commit is contained in:
parent
522d74b65d
commit
ef5994e389
@ -6,6 +6,8 @@
|
||||
#define SYS_yield 1
|
||||
#define SYS_sleep 2
|
||||
#define SYS_write 3
|
||||
#define SYS_paint 4
|
||||
#define SYS_rand 5
|
||||
|
||||
namespace Syscall
|
||||
{
|
||||
@ -15,4 +17,6 @@ namespace Syscall
|
||||
void sys_exit(Context* context);
|
||||
void sys_yield(Context* context);
|
||||
void sys_sleep(Context* context, uint64_t ms);
|
||||
void sys_write(Context* context, const char* addr, size_t size);
|
||||
void sys_write(Context* context, const char* addr, size_t size);
|
||||
void sys_paint(Context* context, uint64_t x, uint64_t y, uint64_t w, uint64_t h, uint64_t col);
|
||||
void sys_rand(Context* context);
|
@ -9,20 +9,36 @@ global _userspace
|
||||
_userspace:
|
||||
mov rdi, 4000 ; 4000 ms / 4 seconds
|
||||
mov rax, 2 ; sys_sleep
|
||||
int 42h ; syscall
|
||||
mov rcx, 10
|
||||
.loop:
|
||||
dec rcx
|
||||
int 42h
|
||||
cmp rax, 0
|
||||
jne .fail ; syscall failed
|
||||
mov rdi, .message
|
||||
mov rsi, 22
|
||||
mov rsi, 33
|
||||
mov rax, 3 ; sys_write
|
||||
int 42h ; syscall
|
||||
mov rdi, 200 ; 200 ms / 0.2 seconds
|
||||
mov rax, 2
|
||||
int 42h ; syscall
|
||||
cmp rcx, 0
|
||||
jne .loop
|
||||
mov rax, 0
|
||||
int 42h ; Exit current task
|
||||
int 42h
|
||||
cmp rax, 33
|
||||
jne .fail ; syscall did not write enough bytes
|
||||
.draw:
|
||||
mov rax, 5 ; sys_rand
|
||||
int 42h
|
||||
mov r9, rax ; color
|
||||
mov rdi, 20 ; x
|
||||
mov rsi, 20 ; y
|
||||
mov r10, 40 ; width
|
||||
mov r8, 30 ; height
|
||||
mov rax, 4 ; sys_paint
|
||||
int 42h
|
||||
cmp rax, 0
|
||||
jne .fail
|
||||
mov rdi, 100
|
||||
mov rax, 2 ; sys_sleep
|
||||
int 42h
|
||||
cmp rax, 0
|
||||
jne .fail
|
||||
jmp .draw
|
||||
.fail:
|
||||
mov rax, 0 ; sys_exit
|
||||
int 42h
|
||||
jmp $ ; sys_exit failed, nothing more we can do
|
||||
.message:
|
||||
db "hello from userspace!", 0xA, 0
|
||||
db "userspace preparing for painting", 0xA
|
@ -19,6 +19,8 @@ void Syscall::entry(Context* context)
|
||||
case SYS_write: // sys_write
|
||||
sys_write(context, (const char*)context->rdi, context->rsi);
|
||||
break;
|
||||
case SYS_paint: sys_paint(context, context->rdi, context->rsi, context->r10, context->r8, context->r9); break;
|
||||
case SYS_rand: sys_rand(context); break;
|
||||
default: context->rax = -1; break;
|
||||
}
|
||||
}
|
27
kernel/src/sys/gfx.cpp
Normal file
27
kernel/src/sys/gfx.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "bootboot.h"
|
||||
#include "interrupts/Context.h"
|
||||
#include "render/Framebuffer.h"
|
||||
#include <stdint.h>
|
||||
|
||||
extern BOOTBOOT bootboot;
|
||||
|
||||
void sys_paint(Context* context, uint64_t x, uint64_t y, uint64_t w, uint64_t h, uint64_t c)
|
||||
{
|
||||
if ((x + w) > bootboot.fb_width)
|
||||
{
|
||||
context->rax = -1;
|
||||
return;
|
||||
}
|
||||
if ((y + h) > bootboot.fb_height)
|
||||
{
|
||||
context->rax = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t color = (uint32_t)c;
|
||||
uint32_t* colptr = &color;
|
||||
|
||||
framebuffer0.paint_rect(x, y, w, h, *(Color*)colptr);
|
||||
|
||||
context->rax = 0;
|
||||
}
|
7
kernel/src/sys/rand.cpp
Normal file
7
kernel/src/sys/rand.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include "interrupts/Context.h"
|
||||
#include "rand/Mersenne.h"
|
||||
|
||||
void sys_rand(Context* context)
|
||||
{
|
||||
context->rax = Mersenne::get();
|
||||
}
|
Loading…
Reference in New Issue
Block a user