Build a userland version of the kernel for tests

This commit is contained in:
Pierre Pronchery 2018-03-23 14:02:31 +01:00
parent 5e6d68106b
commit dcf2dc2e67
7 changed files with 181 additions and 1 deletions

View File

@ -11,6 +11,13 @@
# include <stdint.h> # include <stdint.h>
/* constants */
/* file streams */
# define STDIN_FILENO 0
# define STDOUT_FILENO 1
# define STDERR_FILENO 2
/* prototypes */ /* prototypes */
void _exit(int status); void _exit(int status);

View File

@ -1,5 +1,5 @@
package=uKernel package=uKernel
version=0.0.0 version=0.0.0
subdirs=include,src,tests subdirs=include,src,tools,tests
dist=COPYING,Makefile,README.md dist=COPYING,Makefile,README.md

87
tools/arch/i386/start.S Normal file
View File

@ -0,0 +1,87 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
.section .text
/* exit */
.global _exit
.type _exit, @function
_exit:
mov $0x1, %eax
int $0x80
ret
/* start */
_start:
/* reset the stack */
xor %ebp, %ebp
/* setup the environment */
mov (%esp), %eax /* argc */
mov %esp, %ebx /* argv */
add $0x4, %ebx
mov %eax, %ecx /* envp */
shl $2, %ecx
add %ebx, %ecx
#if defined(__ELF__)
mov %ecx, %edx /* auxv */
auxv:
cmpl $0x0, (%edx)
jz auxv_done
add $0x4, %edx
jmp auxv
auxv_done:
add $0x4, %edx
#endif
push %ebp
push %esp
mov %esp, %ebp
push %ecx
push %ebx
push %eax
#if defined(__ELF__)
push %edx
#endif
#if defined(__SSP__)
/* initialize SSP */
call __stack_chk_setup
#endif
/* run the userland kernel */
call main
/* exit the userland kernel */
mov %ebp, %esp
push %eax
call exit
hlt
/* write */
.global _write
.type _write, @function
_write:
mov $0x4, %eax
int $0x80
ret
#if defined(__NetBSD__)
/* NetBSD emulation */
# define __NetBSD_Version__ 600000000
.section ".note.netbsd.ident", "a"
.p2align 2
.long 7
.long 4
.long 1
.ascii "NetBSD\0\0"
.long __NetBSD_Version__
.previous
.p2align 2
#endif

47
tools/console.c Normal file
View File

@ -0,0 +1,47 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
#include <unistd.h>
#include <stdint.h>
#include "drivers/console.h"
/* types */
struct _Console
{
int fd;
};
/* prototypes */
int _write(int fd, char const * buf, size_t len);
/* variables */
static Console _console;
/* functions */
/* console_init */
Console * console_init(void)
{
_console.fd = STDOUT_FILENO;
return &_console;
}
/* useful */
/* console_clear */
void console_clear(Console * console)
{
}
/* console_print */
void console_print(Console * console, char const * text, size_t len)
{
_write(console->fd, text, len);
}

1
tools/main.c Normal file
View File

@ -0,0 +1 @@
#include "../src/main.c"

18
tools/project.conf Normal file
View File

@ -0,0 +1,18 @@
targets=start.o,uKernel
cppflags_force=-nostdinc -isystem ../include -I ../src
cflags_force=-ffreestanding -m32
cflags=-W -Wall -g -O2 -fstack-protector
as=$(CC)
asflags_force=$(CFLAGSF) $(CFLAGS) -c
ldflags_force=-nostdlib -static -m32
dist=Makefile
[start.o]
type=object
sources=start.S
[uKernel]
type=binary
sources=console.c,main.c
ldflags=$(OBJDIR)start.o $(OBJDIR)../src/lib/libuKernel.a `$(CC) -m32 -print-libgcc-file-name`
depends=$(OBJDIR)start.o,$(OBJDIR)../src/lib/libuKernel.a

20
tools/start.S Normal file
View File

@ -0,0 +1,20 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
.text
/* _start */
.global _start
.type _start, @function
/* check for supported architectures */
#if defined(__amd64__) || defined(__i386__)
# include "arch/i386/start.S"
#else
# warning Unsupported architecture
#endif