Re-use more code from DeforaOS libc
This commit is contained in:
parent
1ef072043a
commit
8f2a9640f2
|
@ -1,5 +1,5 @@
|
|||
targets=platform.c
|
||||
dist=Makefile,platform.conf,start.S
|
||||
dist=Makefile,platform.conf
|
||||
|
||||
#targets
|
||||
[platform.c]
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS uKernel */
|
||||
|
||||
|
||||
.section .text
|
||||
_syscall:
|
||||
mov %rcx, %r10
|
||||
syscall
|
||||
jnc _syscall_return
|
||||
.errno:
|
||||
#ifdef __PIC__
|
||||
mov errno@GOTPCREL(%rip), %rcx
|
||||
mov %rax, (%rcx)
|
||||
#else
|
||||
mov %rax, errno
|
||||
#endif
|
||||
mov $-1, %rax
|
||||
_syscall_return:
|
||||
ret
|
||||
|
||||
|
||||
/* start */
|
||||
.global _start
|
||||
.type _start, @function
|
||||
_start:
|
||||
/* reset the stack */
|
||||
xor %rbp, %rbp
|
||||
|
||||
/* setup the environment */
|
||||
mov (%rsp), %rdi /* argc */
|
||||
mov %rsp, %rsi /* argv */
|
||||
add $0x8, %rsi
|
||||
mov %rdi, %rdx /* envp */
|
||||
shl $3, %rdx
|
||||
add %rsi, %rdx
|
||||
add $0x8, %rdx
|
||||
#ifdef __PIC__ /* environ */
|
||||
mov environ@GOTPCREL(%rip), %rcx
|
||||
mov %rdx, (%rcx)
|
||||
#else
|
||||
mov %rdx, environ
|
||||
#endif
|
||||
push %rdi
|
||||
push %rsi
|
||||
push %rdx
|
||||
#ifdef __ELF__
|
||||
mov %rdx, %rcx /* auxv */
|
||||
auxv:
|
||||
cmpq $0x0, (%rcx)
|
||||
jz auxv_done
|
||||
add $0x8, %rcx
|
||||
jmp auxv
|
||||
auxv_done:
|
||||
add $0x8, %rcx
|
||||
push %rcx
|
||||
#endif
|
||||
|
||||
#if defined(__SSP__)
|
||||
/* initialize SSP */
|
||||
# ifdef __PIC__
|
||||
call __stack_chk_setup@PLT
|
||||
# else
|
||||
call __stack_chk_setup
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* initialize the platform */
|
||||
#ifdef __PIC__
|
||||
call platform_init
|
||||
#else
|
||||
call platform_init
|
||||
#endif
|
||||
|
||||
/* run the userland kernel */
|
||||
#ifdef __ELF__
|
||||
pop %rcx
|
||||
#else
|
||||
xor %rcx, %rcx
|
||||
#endif
|
||||
pop %rdx
|
||||
pop %rsi
|
||||
pop %rdi
|
||||
#ifdef __PIC__
|
||||
call main@PLT
|
||||
#else
|
||||
call main
|
||||
#endif
|
||||
|
||||
/* exit the userland kernel */
|
||||
mov %rax, %rdi
|
||||
#ifdef __PIC__
|
||||
call exit@PLT
|
||||
#else
|
||||
call exit
|
||||
#endif
|
||||
|
||||
hlt
|
|
@ -1,5 +1,5 @@
|
|||
targets=platform.c
|
||||
dist=Makefile,start.S
|
||||
dist=Makefile
|
||||
|
||||
#targets
|
||||
[platform.c]
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS uKernel */
|
||||
|
||||
|
||||
.section .text
|
||||
_syscall:
|
||||
#ifdef __linux__
|
||||
push %ebx
|
||||
push %esi
|
||||
push %edi
|
||||
mov 0x10(%esp), %ebx
|
||||
mov 0x14(%esp), %ecx
|
||||
mov 0x18(%esp), %edx
|
||||
mov 0x1c(%esp), %esi
|
||||
mov 0x20(%esp), %edi
|
||||
int $0x80
|
||||
pop %edi
|
||||
pop %esi
|
||||
pop %ebx
|
||||
cmp $0, %eax
|
||||
jge .errnoret
|
||||
neg %eax
|
||||
#else
|
||||
int $0x80
|
||||
jnc .errnoret
|
||||
#endif
|
||||
.errno:
|
||||
mov %eax, errno
|
||||
mov $-1, %eax
|
||||
.errnoret:
|
||||
ret
|
||||
|
||||
|
||||
/* start */
|
||||
.global _start
|
||||
.type _start, @function
|
||||
_start:
|
||||
/* initialize the stack */
|
||||
xor %ebp, %ebp
|
||||
|
||||
/* setup the environment */
|
||||
mov (%esp), %eax /* argc */
|
||||
mov %esp, %ebx /* argv */
|
||||
add $0x4, %ebx
|
||||
mov %eax, %ecx /* envp */
|
||||
inc %ecx
|
||||
shl $2, %ecx
|
||||
add %ebx, %ecx
|
||||
mov %ecx, environ /* environ */
|
||||
#if defined(__ELF__)
|
||||
mov %ecx, %edx /* auxv */
|
||||
1:
|
||||
cmpl $0x0, (%edx)
|
||||
jz 2f
|
||||
add $0x4, %edx
|
||||
jmp 1b
|
||||
2:
|
||||
add $0x4, %edx
|
||||
push %edx
|
||||
#endif
|
||||
push %ecx
|
||||
push %ebx
|
||||
push %eax
|
||||
|
||||
#if defined(__SSP__)
|
||||
/* initialize SSP */
|
||||
call __stack_chk_setup
|
||||
#endif
|
||||
|
||||
/* call the global constructors */
|
||||
call _init
|
||||
|
||||
/* initialize the platform */
|
||||
call platform_init
|
||||
|
||||
/* run the userland kernel */
|
||||
call main
|
||||
#if defined(__ELF__)
|
||||
add $0x10, %esp
|
||||
#else
|
||||
add $0xc, %esp
|
||||
#endif
|
||||
push %eax
|
||||
|
||||
/* call the global destructors */
|
||||
call _fini
|
||||
|
||||
/* exit the userland kernel */
|
||||
call exit
|
||||
add $0x4, %esp
|
||||
|
||||
hlt
|
|
@ -1,2 +1,2 @@
|
|||
subdirs=amd64,i386
|
||||
dist=Makefile,start.S
|
||||
dist=Makefile
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS uKernel */
|
||||
|
||||
|
||||
|
||||
#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
|
||||
#elif defined(__OpenBSD__)
|
||||
/* OpenBSD emulation */
|
||||
|
||||
.section ".note.openbsd.ident", "a"
|
||||
.p2align 2
|
||||
.long 8
|
||||
.long 4
|
||||
.long 1
|
||||
.ascii "OpenBSD\0"
|
||||
.long 0
|
||||
.previous
|
||||
#endif
|
|
@ -18,6 +18,7 @@
|
|||
#include <ssp.h>
|
||||
|
||||
#include "lib/libc/src/ctype.c"
|
||||
#include "lib/libc/src/dlfcn.c"
|
||||
#include "lib/libc/src/dirent.c"
|
||||
#include "lib/libc/src/errno.c"
|
||||
#include "lib/libc/src/fcntl.c"
|
||||
|
@ -36,6 +37,3 @@
|
|||
#include "lib/libc/src/termios.c"
|
||||
#include "lib/libc/src/time.c"
|
||||
#include "lib/libc/src/unistd.c"
|
||||
#include "lib/sys/mman.c"
|
||||
#include "lib/sys/time.c"
|
||||
#include "lib/unistd.c"
|
||||
|
|
|
@ -61,6 +61,3 @@ depends=../src/kernel/main.c
|
|||
[platform.c]
|
||||
cppflags=-include $(OBJDIR)arch/$(ARCH)/platform.c
|
||||
depends=$(OBJDIR)arch/$(ARCH)/platform.c
|
||||
|
||||
[start.S]
|
||||
depends=arch/start.S,arch/amd64/start.S,arch/i386/start.S
|
||||
|
|
|
@ -4,16 +4,4 @@
|
|||
|
||||
|
||||
|
||||
.section .text
|
||||
|
||||
|
||||
/* check for supported architectures */
|
||||
#if defined(__amd64__)
|
||||
# include "arch/amd64/start.S"
|
||||
# include "arch/start.S"
|
||||
#elif defined(__i386__)
|
||||
# include "arch/i386/start.S"
|
||||
# include "arch/start.S"
|
||||
#else
|
||||
# warning Unsupported architecture
|
||||
#endif
|
||||
#include "lib/libc/src/start.S"
|
||||
|
|
Loading…
Reference in New Issue
Block a user