Compare commits

...

97 Commits

Author SHA1 Message Date
f39779e810 i386: remove dependency on <sys/mman.h>
This defines memory-protection flags specifically for the GDT.
2025-03-20 19:03:46 +01:00
96eafeac45 Merge branch 'khorben/tss' 2025-03-20 18:52:54 +01:00
abf21dedde tests: append a TSS to the GDT tests 2025-03-20 18:52:46 +01:00
a10b4f2b25 Update the copyright notice 2025-03-20 18:52:46 +01:00
5fa83bd311 i386: allow appending system segments to the GDT 2025-03-20 18:52:46 +01:00
f94ea311d2 tests: register the "gdt" target 2025-03-20 18:52:39 +01:00
cb9b7d11fc Update the copyright notice 2025-03-20 16:26:17 +01:00
869a68af63 x86: code cleanup 2025-03-20 16:25:46 +01:00
084bdd18a2 Merge branch 'khorben/gdt' 2025-03-20 14:55:04 +01:00
fb07c0b7ce tests: import a test tool for the GDT 2025-03-20 14:54:26 +01:00
ec0bef8573 loader: register a dependency 2025-03-20 14:54:26 +01:00
424bcec667 Update the copyright notice 2025-03-20 14:54:26 +01:00
8bf47da51c i386: re-implement the GDT setup 2025-03-20 14:54:26 +01:00
6aec0c1962 Update the copyright notice 2025-03-17 20:12:46 +01:00
8d3b5cc6b9 i386: enable interrupts before calling main()
This is for the kernel itself.
2025-03-17 20:12:46 +01:00
04b87759ef Update the copyright notice 2025-03-16 11:34:14 +01:00
799964ac2f i386: code cleanup 2025-03-16 11:34:00 +01:00
3d811ed787 Update the copyright notice 2025-03-16 11:32:45 +01:00
49ca697b74 i386: enable interrupts before calling main() 2025-03-16 11:31:49 +01:00
9aa1251c70 Update the copyright notice 2025-03-15 10:39:20 +01:00
ed7adc26f4 lib: remove unused variable 2025-03-15 10:39:03 +01:00
ea795c5c4c crt?.S: fix the build with macOS 2025-03-14 20:21:29 +01:00
a8970f8e6b Import the latest version 2025-02-28 00:43:02 +01:00
d711cd6900 doc: spell e.g., in full 2025-02-05 00:11:18 +01:00
351050db96 Import the latest version 2025-02-05 00:10:39 +01:00
788cf3a214 Import the latest version 2024-11-24 23:23:39 +01:00
c907d271ac deforaos-c-ci_ubuntu-latest: use checkout v4 2024-05-26 00:04:59 +02:00
679b5d3974 deforaos-c-ci_ubuntu-latest.yml: force gcc's 32-bit backend
This should really bootstrap a cross-compiler instead.
2022-05-31 07:38:00 +02:00
b9c6fe8889 deforaos-c-ci_ubuntu-latest.yml: actually build for i386 2022-05-31 07:32:30 +02:00
4c80d5acfd deforaos-c-ci_ubuntu-latest.yml: checkout sub-modules 2022-05-31 07:18:21 +02:00
7dec975c14 Import the latest scripts from DeforaOS configure 2022-05-31 07:07:45 +02:00
b441af0b44 Create deforaos-c-ci_ubuntu-latest.yml 2022-05-31 07:07:45 +02:00
17878ca36b Fix the amd64 build 2021-09-29 04:26:11 +02:00
2625b4b51f Update the copyright notice 2021-09-29 04:14:36 +02:00
bdfe05c628 Fix building the amd64 loader 2021-09-29 04:14:24 +02:00
1f07b0b9b4 Update the scripts from DeforaOS configure 2021-09-29 04:06:58 +02:00
ef9c1d0a9e Update the copyright notice 2021-09-29 04:05:21 +02:00
1a3de2c259 Use _brk() from DeforaOS libc 2021-09-29 04:04:54 +02:00
af052c2002 Update the copyright notice 2021-09-29 03:39:35 +02:00
10d0b11b6d Add a stub for __start_dlfcn 2021-09-29 03:38:47 +02:00
c68673e0c1 Build faster on known targets 2021-01-09 20:31:00 +01:00
c65d2682c7 Only build DeforaOS.iso for known project modes 2021-01-09 20:30:33 +01:00
1ffd766137 Register project modes globally 2021-01-09 20:30:13 +01:00
ac9bb36b42 Import the latest version 2020-12-27 04:06:03 +01:00
75b452ee86 Update the copyright notice 2020-12-27 04:03:11 +01:00
987ee27bbc No longer build dlopen() in the userland kernel 2020-12-27 04:02:30 +01:00
6f292d88b2 Update the copyright notice 2020-12-27 04:01:31 +01:00
6849331bbc Avoid using .type with clang
This is probably a more accurate fix than just for macOS.
2020-12-27 04:01:02 +01:00
35ae28b95d Use the correct fallback value for $CC 2020-12-27 03:59:51 +01:00
cf1f9f11cd Fix building the kernel 2020-12-27 03:37:26 +01:00
bf8c5c32e5 Update the copyright notice 2020-12-27 03:37:08 +01:00
30641adb21 Fix building the kernel loader 2020-12-27 03:36:56 +01:00
36d3ccf6f1 Update the copyright notice 2020-12-27 02:07:27 +01:00
2fbeb0608a Detect and report errors when cross-building gcc 2020-12-27 02:07:04 +01:00
ec6724b544 Update the copyright notice 2020-12-27 01:45:59 +01:00
c82d2f45cb Avoid using .type on macOS
This should be replaced by generic macros for assembly files.
2020-12-27 01:45:11 +01:00
2a4c1c3e6d Import the latest version 2020-12-27 01:35:10 +01:00
8771f6083e Fix building from source archives 2020-12-19 02:22:48 +01:00
3196f29e6b Import the latest version 2020-12-19 02:22:48 +01:00
32856fce8d Also ship platform.conf 2020-12-19 02:22:48 +01:00
465efafc3d Register the "clint" and "distcheck" tests 2020-12-19 02:22:48 +01:00
49cc75b7ab Import the "distcheck" test from DeforaOS configure 2020-12-19 02:22:48 +01:00
f443007e9e Import the latest version 2020-12-13 21:36:42 +01:00
d7a6a20006 Disable running the tests by default 2020-12-13 21:31:15 +01:00
4b019f5954 Bring platform.sh a bit closer to DeforaOS configure 2020-12-13 21:27:25 +01:00
12263ca7fb Restore the original platform.sh 2020-12-13 21:24:50 +01:00
e29dbdfbae Import the newer scripts from DeforaOS configure 2020-11-19 03:14:16 +01:00
0ec0061bd0 Import the newer scripts from DeforaOS configure 2020-11-19 02:57:18 +01:00
d30a9a986d Import newer scripts upstream 2020-11-03 23:31:35 +01:00
a094eaf0e8 Import the latest version 2020-10-20 01:35:20 +02:00
dd5dc86c50 Import the latest version 2020-04-11 02:33:56 +02:00
1e21eaf1dc Build the kernel in the perspective of DeforaOS 2019-10-10 02:47:58 +02:00
cfa3c70d71 Import the latest version 2019-10-10 02:37:25 +02:00
e157c1dab4 Build the drivers in the perspective of DeforaOS 2019-10-10 02:23:47 +02:00
979cc4b326 Import the latest version 2019-10-10 01:44:45 +02:00
e3da0b55c6 Do not forget to ship multiboot.S 2019-10-03 23:50:54 +02:00
8f2a9640f2 Re-use more code from DeforaOS libc 2019-10-03 23:47:36 +02:00
1ef072043a Explicitly list Github as a mirror 2019-10-03 23:25:19 +02:00
e747d7ebe2 Document the Git submodule 2019-10-03 23:25:08 +02:00
41b5a82017 Insist on the trailing slash for OBJDIR 2019-10-03 23:22:08 +02:00
3cb499b8f5 Import the latest version 2019-10-02 16:18:18 +02:00
2bb88f8533 Unify the handling of assembly flags 2019-10-02 16:14:25 +02:00
f61f489ec5 Include <stddef.h> for NULL 2019-10-02 16:06:23 +02:00
2d3566fc61 Let more headers be visible 2019-10-01 12:39:08 +02:00
2a9846de88 Import the latest version 2019-10-01 12:37:50 +02:00
e8f394268e Ship more missing files from DeforaOS libc 2019-09-29 16:05:12 +02:00
fcaf1ef1d3 Ship every include from DeforaOS libc
This should help fix "make dist" but will also install the includes.
2019-09-29 13:57:42 +02:00
193a46d367 Import the latest version 2019-09-29 13:57:42 +02:00
52d156d961 Let the userland uKernel build again 2019-09-05 23:08:20 +02:00
4fbaf259f0 Update the copyright notice 2019-09-05 23:03:44 +02:00
2dc44905d9 Initialize the platform directly 2019-09-05 23:03:27 +02:00
b6157e0035 Register missing calls in the userland uKernel 2019-09-05 22:58:24 +02:00
147157f774 Import the latest version upstream 2019-09-05 22:49:50 +02:00
47001ea896 Import the latest version upstream 2019-07-16 02:52:14 +02:00
f8c4d902a8 Merge the latest version upstream 2019-07-02 19:34:07 +02:00
c524928fa1 Import the latest version upstream 2019-06-13 02:50:42 +02:00
902d71edd4 Import the latest version upstream 2019-06-13 02:47:25 +02:00
58 changed files with 1163 additions and 481 deletions

View File

@ -0,0 +1,32 @@
name: DeforaOS C CI (ubuntu-latest)
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: initialize sub-modules
run: git submodule init
- name: update sub-modules
run: git submodule update
- name: bootstrap libSystem
run: git clone https://github.com/DeforaOS/libSystem.git libSystem && for dir in include data src; do (cd libSystem/$dir && make PREFIX="$HOME/opt/DeforaOS" install); done
- name: bootstrap configure
run: git clone https://github.com/DeforaOS/configure.git configure && (cd configure/src && PKG_CONFIG_PATH="$HOME/opt/DeforaOS/lib/pkgconfig" make PREFIX="$HOME/opt/DeforaOS" install)
- name: configure
run: $HOME/opt/DeforaOS/bin/configure -p "$HOME/opt/DeforaOS" -M i386-debug
- name: make (i386)
#XXX bootstrap a cross-compiler first
run: PKG_CONFIG_PATH="$HOME/opt/DeforaOS/lib/pkgconfig" make ARCH="i386" CC="gcc -m32" CCSHARED="gcc -m32 -shared"
- name: make tests (i386)
run: PKG_CONFIG_PATH="$HOME/opt/DeforaOS/lib/pkgconfig" make ARCH="i386" CC="gcc -m32" CCSHARED="gcc -m32 -shared" tests
- name: make distcheck (i386)
run: PKG_CONFIG_PATH="$HOME/opt/DeforaOS/lib/pkgconfig" make ARCH="i386" CC="gcc -m32" CCSHARED="gcc -m32 -shared" distcheck

View File

@ -13,9 +13,15 @@ in progress (amd64).
Compiling uKernel
-----------------
First, the Makefiles must be generated for the current platform. This can be
First, when compiling from the source code repository, make sure that the Git
submodules have been initialized and checked out as required:
$ git submodule init
$ git submodule update
Then, the Makefiles must be generated for the current platform. This can be
performed with `configure(1)` from the DeforaOS configure project, found at
<https://www.defora.org/os/project/16/configure> (or
<https://www.defora.org/os/project/16/configure> (or on the Github mirror at
<https://github.com/DeforaOS/configure>). The procedure is then as follows:
$ configure
@ -41,7 +47,9 @@ amd64 platforms, it produces a multiboot-compliant kernel file.
Note that it is also possible to build uKernel outside of the source tree, by
using the "OBJDIR" variable as follows:
$ make ARCH="i386" OBJDIR="$PWD/obj-i386"
$ make ARCH="i386" OBJDIR="$PWD/obj-i386/"
(note that the trailing slash is required)
Testing uKernel
---------------

View File

@ -15,15 +15,15 @@ Dependencies
Binutils and GCC require the following software components to be available in
the system prior to their installation:
| Component | Notes |
| --------- | ----------------------- |
| Make | eg GNU Make or BSD Make |
| Bison | |
| Flex | |
| GMP | |
| MPC | |
| MPFR | |
| Texinfo | |
| Component | Notes |
| --------- | -------------------------- |
| Make | e.g., GNU Make or BSD Make |
| Bison | |
| Flex | |
| GMP | |
| MPC | |
| MPFR | |
| Texinfo | |
Please refer to the manual of your local system for information on how to find
and install these components as required.

View File

@ -1,6 +1,6 @@
#!/bin/sh -e
#!/bin/sh
#$Id$
#Copyright (c) 2019 Pierre Pronchery <khorben@defora.org>
#Copyright (c) 2019-2020 Pierre Pronchery <khorben@defora.org>
#This file is part of DeforaOS uKernel
#
#Redistribution and use in source and binary forms, with or without
@ -34,6 +34,7 @@ GCC_TARGETS="all-gcc all-target-libgcc install-gcc install-target-libgcc"
GCC_VERSION="8.3.0"
GZEXT="gz"
MIRROR="https://ftpmirror.gnu.org"
PROGNAME="cross-gcc.sh"
TARGET="i686-elf"
#executables
MAKE="make"
@ -43,6 +44,14 @@ WGET="wget"
#functions
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#main
#Modify the environment to reflect the port chosen
@ -50,32 +59,57 @@ PREFIX="$HOME/opt/cross-gcc-$TARGET"
PATH="$PREFIX/bin:$PATH"
#Download binutils
[ -f "binutils-$BINUTILS_VERSION.tar.$GZEXT" ] ||
if [ ! -f "binutils-$BINUTILS_VERSION.tar.$GZEXT" ]; then
$WGET "$MIRROR/binutils/binutils-$BINUTILS_VERSION.tar.$GZEXT"
if [ $? -ne 0 ]; then
_error "Could not download binutils"
exit $?
fi
fi
#Extract, configure, and build binutils in a dedicated tree
[ -d "binutils-$BINUTILS_VERSION" ] ||
if [ ! -d "binutils-$BINUTILS_VERSION" ]; then
$TAR xzvf "binutils-$BINUTILS_VERSION.tar.$GZEXT"
if [ $? -ne 0 ]; then
_error "Could not extract binutils"
exit $?
fi
fi
case "$TARGET" in
aarch64-elf|amd64-elf|sparc64-elf)
BINUTILS_FLAGS="$BINUTILS_FLAGS --enable-multilib"
;;
esac
$MKDIR "binutils-$TARGET"
(cd "binutils-$TARGET" && "../binutils-$BINUTILS_VERSION/configure" \
($MKDIR "binutils-$TARGET" &&
cd "binutils-$TARGET" &&
"../binutils-$BINUTILS_VERSION/configure" \
--target="$TARGET" --prefix="$PREFIX" --with-sysroot --disable-nls \
--disable-werror $BINUTILS_FLAGS)
if [ $? -ne 0 ]; then
_error "Could not configure binutils"
exit $?
fi
for target in $BINUTILS_TARGETS; do
(cd "binutils-$TARGET" && $MAKE "$target")
done
#Download GCC
[ -f "gcc-$GCC_VERSION.tar.$GZEXT" ] ||
if [ ! -f "gcc-$GCC_VERSION.tar.$GZEXT" ]; then
$WGET "$MIRROR/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.$GZEXT"
if [ $? -ne 0 ]; then
_error "Could not download gcc"
exit $?
fi
fi
#Extract, configure, and build GCC in a dedicated tree
[ -d "gcc-$GCC_VERSION" ] ||
if [ ! -d "gcc-$GCC_VERSION" ]; then
$TAR xzvf "gcc-$GCC_VERSION.tar.$GZEXT"
if [ $? -ne 0 ]; then
_error "Could not extract gcc"
exit $?
fi
fi
case "$TARGET" in
aarch64-elf)
GCC_FLAGS="$GCC_FLAGS --with-multilib-list=lp64,ilp32"
@ -84,10 +118,19 @@ case "$TARGET" in
GCC_FLAGS="$GCC_FLAGS --with-multilib-list=m64,m32"
;;
esac
$MKDIR "gcc-$TARGET"
(cd "gcc-$TARGET" && "../gcc-$GCC_VERSION/configure" --target="$TARGET" \
($MKDIR "gcc-$TARGET" &&
cd "gcc-$TARGET" &&
"../gcc-$GCC_VERSION/configure" --target="$TARGET" \
--prefix="$PREFIX" --disable-nls --enable-languages=c,c++ \
--without-headers $GCC_FLAGS)
if [ $? -ne 0 ]; then
_error "Could not configure gcc"
exit $?
fi
for target in $GCC_TARGETS; do
(cd "gcc-$TARGET" && $MAKE "$target")
if [ $? -ne 0 ]; then
_error "$target: Could not build gcc target"
exit $?
fi
done

View File

@ -7,6 +7,7 @@
# define UKERNEL_DRIVERS_BUS_H
# include <stdarg.h>
# include <stddef.h>
# include <stdint.h>

View File

@ -2,4 +2,27 @@ package=uKernel
version=0.0.0
subdirs=doc,include,src,tools,tests
targets=tests
dist=COPYING,Makefile,README.md
mode=i386-debug
#modes
[mode::amd64-debug]
title=amd64-debug
[mode::amd64-release]
title=amd64-release
[mode::i386-debug]
title=i386-debug
[mode::i386-release]
title=i386-release
#targets
[tests]
type=command
command=cd tests && (if [ -n "$(OBJDIR)" ]; then $(MAKE) OBJDIR="$(OBJDIR)tests/" "$(OBJDIR)tests/clint.log" "$(OBJDIR)tests/distcheck.log" "$(OBJDIR)tests/fixme.log" "$(OBJDIR)tests/grub.log"; else $(MAKE) clint.log distcheck.log fixme.log grub.log; fi)
depends=all
enabled=0
phony=1

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2020 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* Originally from https://wiki.osdev.org/Bare_Bones */
@ -7,18 +7,42 @@
/* sections */
/* init */
#ifdef __APPLE__
.section __TEXT,__text
#else
.section .init
#endif
.global _init
#ifndef __clang__
.type _init, @function
#endif
_init:
push %rbp
mov %rsp, %rbp
#ifdef __APPLE__
.section __DATA,__mod_init_func,mod_init_funcs
.p2align 3
.quad _init
#endif
/* fini */
#ifdef __APPLE__
.section __TEXT,__text
#else
.section .fini
#endif
.global _fini
#ifndef __clang__
.type _fini, @function
#endif
_fini:
push %rbp
mov %rsp, %rbp
#ifdef __APPLE__
.section __DATA,__mod_term_func,mod_term_funcs
.p2align 3
.quad _fini
#endif

View File

@ -7,12 +7,36 @@
/* sections */
/* init */
#ifdef __APPLE__
.section __TEXT,__text
.global _crtn_init
_crtn_init:
#else
.section .init
#endif
pop %rbp
ret
#ifdef __APPLE__
.section __DATA,__mod_init_func,mod_init_funcs
.p2align 3
.quad _crtn_init
#endif
/* fini */
#ifdef __APPLE__
.section __TEXT,__text
.global _crtn_fini
_crtn_fini:
#else
.section .fini
#endif
pop %rbp
ret
#ifdef __APPLE__
.section __DATA,__mod_term_func,mod_term_funcs
.p2align 3
.quad _crtn_fini
#endif

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* Originally from https://wiki.osdev.org/Bare_Bones */
@ -9,20 +9,36 @@
.section .text
/* arch_setgdt */
.global __arch_setgdt
#ifndef __clang__
.type __arch_setgdt, @function
__arch_setgdt:
#if 0
lea gdt_descriptor, %rcx
#else
mov (gdt_descriptor), %rcx
#endif
__arch_setgdt:
lea gdt_descriptor, %rcx
/* set the offset of the GDT */
mov %rsi, 0x2(%rcx)
/* set the size of the GDT */
shl $0x3, %rdi
dec %rdi
mov %di, (%rcx)
/* load the GDT */
lgdt (%rcx)
/* apply the GDT */
push $0x8
lea gdt_flush, %rax
push %rax
retf
gdt_flush:
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss
ret
@ -31,4 +47,4 @@ __arch_setgdt:
.align 16
gdt_descriptor:
.skip 2 /* size */
.skip 4 /* offset */
.skip 8 /* offset */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
@ -9,9 +9,4 @@
# include "../i386/gdt.h"
/* public */
/* prototypes */
int _arch_setgdt64(GDT const * gdt, size_t count);
#endif /* !UKERNEL_ARCH_I386_GDT_H */
#endif /* !UKERNEL_ARCH_AMD64_GDT_H */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2021 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* Originally from https://wiki.osdev.org/Bare_Bones */
@ -38,14 +38,6 @@ stack_top:
/* text */
.section .text
/* brk */
.global _brk
.type _brk, @function
_brk:
xor %rax, %rax
ret
/* start */
.global _start
.type _start, @function

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2020 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* Originally from https://wiki.osdev.org/Bare_Bones */
@ -9,7 +9,9 @@
/* init */
.section .init
.global _init
#ifndef __clang__
.type _init, @function
#endif
_init:
push %ebp
mov %esp, %ebp
@ -18,7 +20,9 @@ _init:
/* fini */
.section .fini
.global _fini
#ifndef __clang__
.type _fini, @function
#endif
_fini:
push %ebp
mov %esp, %ebp

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2020 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* Originally from https://wiki.osdev.org/Bare_Bones */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* Originally from https://wiki.osdev.org/Bare_Bones */
@ -9,22 +9,35 @@
.section .text
/* arch_setgdt */
.global __arch_setgdt
#ifndef __clang__
.type __arch_setgdt, @function
__arch_setgdt:
#if 1
lea gdt_descriptor, %ecx
#else
mov (gdt_descriptor), %ecx
#endif
__arch_setgdt:
lea gdt_descriptor, %ecx
/* set the offset of the GDT */
mov 0x4(%esp), %eax
mov %eax, 0x2(%ecx)
/* set the size of the GDT */
mov 0x8(%esp), %eax
shl $0x3, %eax
dec %eax
mov %ax, (%ecx)
/* load the GDT */
lgdt (%ecx)
lgdt (gdt_descriptor)
/* apply the GDT */
mov $0x10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss
ljmp $0x8, $gdt_flush
gdt_flush:
ret

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
@ -13,15 +13,79 @@
/* public */
/* types */
typedef struct _GDT
typedef struct _GDT GDT;
typedef struct _GDTTable
{
vaddr_t base;
vaddr_t limit;
uint8_t type;
} GDT;
size_t size;
unsigned int prot;
} GDTTable;
#pragma pack(1)
typedef struct _TSS
{
uint16_t link;
uint16_t __padding0;
uint32_t esp0;
uint16_t ss0;
uint16_t __padding1;
uint32_t esp1;
uint16_t ss1;
uint16_t __padding2;
uint32_t esp2;
uint16_t ss2;
uint16_t __padding3;
uint32_t cr3;
uint32_t eip;
uint32_t eflags;
uint32_t eax;
uint32_t ecx;
uint32_t edx;
uint32_t ebx;
uint32_t esp;
uint32_t ebp;
uint32_t esi;
uint32_t edi;
uint16_t es;
uint16_t __padding4;
uint16_t cs;
uint16_t __padding5;
uint16_t ss;
uint16_t __padding6;
uint16_t ds;
uint16_t __padding7;
uint16_t fs;
uint16_t __padding8;
uint16_t gs;
uint16_t __padding9;
uint16_t ldtr;
uint16_t __padding10;
uint16_t __padding11;
uint16_t iopb;
uint32_t ssp;
} TSS;
#pragma pack()
/* constants */
# define GDT_PROT_READ 0x1
# define GDT_PROT_WRITE 0x2
# define GDT_PROT_EXEC 0x4
# define GDT_SYSTEM_TYPE_LDT 0x2
# define GDT_SYSTEM_TYPE_TSS 0x9
/* prototypes */
int _arch_setgdt(GDT const * gdt, size_t count);
GDT * gdt_init(void);
int gdt_init_table(GDTTable const * table, size_t table_cnt, size_t tss_cnt);
/* useful */
int gdt_append(GDT * gdt, vaddr_t base, size_t size, unsigned int prot);
int gdt_append_system(GDT * gdt, void * base, size_t size, unsigned int type);
void gdt_apply(GDT * gdt);
#endif /* !UKERNEL_ARCH_I386_GDT_H */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2020 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* Originally from https://wiki.osdev.org/Bare_Bones */
@ -9,7 +9,9 @@
.section .text
/* arch_setidt */
.global __arch_setidt
#ifndef __clang__
.type __arch_setidt, @function
#endif
__arch_setidt:
lea idt, %ecx
/* set the offset of the IDT */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2020 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
@ -8,7 +8,9 @@
/* text */
.section .text
.global intr_disable
#ifndef __clang__
.type intr_disable, @function
#endif
intr_disable:
cli
ret
@ -16,7 +18,9 @@ intr_disable:
/* intr_enable */
.global intr_enable
#ifndef __clang__
.type intr_enable, @function
#endif
intr_enable:
sti
ret

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2020 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
@ -8,7 +8,9 @@
.section .text
/* inb */
.global inb
#ifndef __clang__
.type inb, @function
#endif
inb:
mov 0x4(%esp), %dx /* address */
movl 0x8(%esp), %ecx /* return address */
@ -22,7 +24,9 @@ inb:
/* iowait */
.global iowait
#ifndef __clang__
.type iowait, @function
#endif
iowait:
xor %eax, %eax
outb %al, $0x80
@ -33,7 +37,9 @@ iowait:
/* outb */
.global outb
#ifndef __clang__
.type outb, @function
#endif
outb:
mov 0x4(%esp), %dx /* address */
mov 0x8(%esp), %al /* value */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* Originally from https://wiki.osdev.org/Bare_Bones */
@ -33,7 +33,9 @@ stack_top:
.section .text
/* start */
.global _start
#ifndef __clang__
.type _start, @function
#endif
_start:
/* disable interrupts */
cli
@ -127,6 +129,9 @@ _start:
push $0x0
2:
/* enable interrupts */
sti
/* start the kernel */
call main
mov %ebp, %esp

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
/* Originally from https://wiki.osdev.org/Bare_Bones */
@ -33,7 +33,9 @@ stack_top:
.section .text
/* start */
.global _start
#ifndef __clang__
.type _start, @function
#endif
_start:
/* disable interrupts */
cli
@ -123,6 +125,9 @@ _start:
push $0x0
2:
/* enable interrupts */
sti
/* start the loader */
call main
mov %ebp, %esp

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2020 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
@ -25,7 +25,9 @@
.section .text
/* multiboot_boot_kernel32 */
.global multiboot_boot_kernel32
#ifndef __clang__
.type multiboot_boot_kernel32, @function
#endif
multiboot_boot_kernel32:
/* jump into the 32-bit kernel */
mov 0x4(%esp), %ebx
@ -41,7 +43,9 @@ multiboot_boot_kernel32:
.global multiboot_boot_kernel64
#ifndef __clang__
.type multiboot_boot_kernel64, @function
#endif
multiboot_boot_kernel64:
/* check for 64-bit capability */
pushf

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2020 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
@ -50,7 +50,9 @@ multiboot_header:
.section .text
/* multiboot_start */
.global _multiboot_start
# ifndef __clang__
.type _multiboot_start, @function
# endif
_multiboot_start:
jmp _start
#endif

View File

@ -1,6 +1,6 @@
subdirs=multiboot
targets=platform.c
dist=Makefile,arch.h,crti.S,crtn.S,gdt.h,gdt.S,idt.h,idt.S,intr.S,kernel.S,ioport.S,loader.S,platform.conf,uKernel.ld
dist=Makefile,arch.h,crti.S,crtn.S,gdt.h,gdt.S,idt.h,idt.S,intr.S,kernel.S,ioport.S,loader.S,multiboot.S,platform.conf,uKernel.ld
#targets
[platform.c]

View File

@ -1,2 +1,16 @@
subdirs=amd64,i386
dist=Makefile,arch.h
mode=i386-debug
#modes
[mode::amd64-debug]
subdirs=amd64
[mode::amd64-release]
subdirs=amd64
[mode::i386-debug]
subdirs=i386
[mode::i386-release]
subdirs=i386

View File

@ -11,8 +11,6 @@
# include <stdio.h>
# include <string.h>
# include <elf.h>
# include "arch/amd64/gdt.h"
# include "arch/i386/gdt.h"
# include "drivers/boot/multiboot.h"
# ifndef MAX

View File

@ -1,7 +1,7 @@
targets=multiboot.o
as=$(CC)
cc=$(CROSS)gcc
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -isystem ../../../src/lib/libc/include/dl -I../..
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -isystem ../../../src/lib/libc/include/dl -I../.. -D__DeforaOS__
asflags_force=$(CFLAGSF) $(CFLAGS) -c
cflags_force=`../../../tools/platform.sh -V UKERNEL_CFLAGS -C "$$ARCH"`
cflags=-W -Wall -g -O2

View File

@ -1,7 +1,7 @@
targets=cmos.o,ioport.o,tty.o,vga.o
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -I../..
as=$(CC)
cc=$(CROSS)gcc
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -I../.. -D__DeforaOS__
asflags_force=$(CFLAGSF) $(CFLAGS) -c
cflags_force=`../../../tools/platform.sh -V UKERNEL_CFLAGS -C "$$ARCH"`
cflags=-W -Wall -g -O2

View File

@ -1,6 +1,6 @@
targets=cmos.o,sys.o
cc=$(CROSS)gcc
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -I../..
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -I../.. -D__DeforaOS__
cflags_force=`../../../tools/platform.sh -V UKERNEL_CFLAGS -C "$$ARCH"`
cflags=-W -Wall -g -O2
ldflags_force=`../../../tools/platform.sh -V UKERNEL_LDFLAGS -C "$$ARCH"`

View File

@ -1,6 +1,6 @@
targets=stdio.o,uart.o
cc=$(CROSS)gcc
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -I../..
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -I../.. -D__DeforaOS__
cflags_force=`../../../tools/platform.sh -V UKERNEL_CFLAGS -C "$$ARCH"`
cflags=-W -Wall -g -O2
ldflags_force=`../../../tools/platform.sh -V UKERNEL_LDFLAGS -C "$$ARCH"`

View File

@ -1,6 +1,6 @@
targets=vesa.o,vga.o
cc=$(CROSS)gcc
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -I../..
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -I../.. -D__DeforaOS__
cflags_force=`../../../tools/platform.sh -V UKERNEL_CFLAGS -C "$$ARCH"`
cflags=-W -Wall -g -O2
ldflags_force=`../../../tools/platform.sh -V UKERNEL_LDFLAGS -C "$$ARCH"`

View File

@ -1,6 +1,6 @@
targets=i8259a.o
cc=$(CROSS)gcc
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -I../..
cppflags_force=-nostdinc -isystem ../../../include -isystem ../../../src/lib/libc/include -I../.. -D__DeforaOS__
cflags_force=`../../../tools/platform.sh -V UKERNEL_CFLAGS -C "$$ARCH"`
cflags=-W -Wall -g -O2
ldflags_force=`../../../tools/platform.sh -V UKERNEL_LDFLAGS -C "$$ARCH"`

View File

@ -2,7 +2,7 @@ subdirs=boot,bus,clock,console,display,pic
targets=bus.o,clock.o,console.o,display.o,pic.o
as=$(CC)
cc=$(CROSS)gcc
cppflags_force=-nostdinc -isystem ../../include -isystem ../../src/lib/libc/include -I..
cppflags_force=-nostdinc -isystem ../../include -isystem ../../src/lib/libc/include -I.. -D__DeforaOS__
asflags_force=$(CFLAGSF) $(CFLAGS) -c
cflags_force=`../../tools/platform.sh -V UKERNEL_CFLAGS -C "$$ARCH"`
cflags=-W -Wall -g -O2

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
@ -27,12 +27,10 @@
/* private */
/* constants */
/* GDT: 4GB flat memory setup */
static const GDT _gdt_4gb[4] =
static const GDTTable _gdt_4gb[2] =
{
{ 0x00000000, 0x00000000, 0x00 },
{ 0x00000000, 0xffffffff, 0x9a },
{ 0x00000000, 0xffffffff, 0x92 },
{ 0x00000000, 0x00000000, 0x89 }
{ 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_EXEC },
{ 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_WRITE }
};
static const IDT _idt[] =
@ -93,7 +91,8 @@ int multiboot(const ukMultibootInfo * mi)
#if defined(__amd64__)
if(_arch_setgdt64(_gdt_4gb, sizeof(_gdt_4gb) / sizeof(*_gdt_4gb)) != 0)
#else
if(_arch_setgdt(_gdt_4gb, sizeof(_gdt_4gb) / sizeof(*_gdt_4gb)) != 0)
if(gdt_init_table((const GDTTable *)&_gdt_4gb,
sizeof(_gdt_4gb) / sizeof(*_gdt_4gb), 1) != 0)
#endif
{
puts("Could not setup the GDT");

View File

@ -1,8 +1,9 @@
targets=crtbegin.o,crtend.o,crti.o,crtn.o,uKernel.bin
as=$(CC)
cc=$(CROSS)gcc
cppflags_force=-nostdinc -isystem ../../include -isystem ../../src/lib/libc/include -isystem ../../src/lib/libc/include/dl -I..
asflags_force=$(CFLAGSF) $(CFLAGS) -c
cppflags_force=-nostdinc -isystem ../../include -isystem ../../src/lib/libc/include -isystem ../../src/lib/libc/include/dl -I.. -D__DeforaOS__
asflags_force=$(CFLAGSF) -c
asflags=$(CFLAGS)
cflags_force=`../../tools/platform.sh -V UKERNEL_CFLAGS -C "$$ARCH"`
cflags=-W -Wall -g -O2
ldflags_force=`../../tools/platform.sh -V UKERNEL_LDFLAGS -C "$$ARCH"`

@ -1 +1 @@
Subproject commit 22fca9ce13c4dc1fafa8f02311a0d1e0710395e2
Subproject commit 1ff21ed155f9fc8773b415fb828a82cccdea0a98

View File

@ -1,13 +1,14 @@
subdirs=libc/include,libc/src/kernel
targets=libk
as=$(CC)
cc=$(CROSS)gcc
cppflags_force=-nostdinc -isystem ../../include -isystem libc/include -I.. -D__DeforaOS__
asflags_force=$(CFLAGSF)
asflags=$(CFLAGS) -c
asflags_force=$(CFLAGSF) -c
asflags=$(CFLAGS)
cflags_force=`../../tools/platform.sh -V LIBK_CFLAGS -C "$$ARCH"`
cflags=-W -Wall -g -O2
ldflags_force=`../../tools/platform.sh -V LIBK_LDFLAGS -C "$$ARCH"`
dist=Makefile
dist=Makefile,libc/src/chacha/chacha.c,libc/src/chacha/ecrypt-config.h,libc/src/chacha/ecrypt-machine.h,libc/src/chacha/ecrypt-portable.h,libc/src/chacha/ecrypt-sync.h,libc/src/dlfcn.c,libc/src/dlfcn.h,libc/src/endian.h,libc/src/kernel/deforaos/amd64/syscalls.S,libc/src/kernel/deforaos/i386/syscalls.S,libc/src/kernel/deforaos/common.h,libc/src/start.h,libc/src/start.S,libc/src/syscalls.h
#targets
[libk]

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2019 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2019-2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
@ -13,7 +13,6 @@
/* gettimeofday */
int gettimeofday(struct timeval * tv, void * null)
{
ukClock * clock;
time_t t;
if(clock_get_time(NULL, &t) != 0)

View File

@ -1,10 +1,11 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
#if defined(__amd64__) || defined(__i386__)
# include <limits.h>
# include <stdint.h>
# include <string.h>
# include <errno.h>
@ -12,101 +13,239 @@
# include "arch/i386/gdt.h"
/* constants */
# define GDT_ENTRIES_MAX 8192
# define GDT_LIMIT_MAX 0x000fffff
/* access */
# define GDT_ACCESS_SET 0x01
# define GDT_ACCESS_PROT_RW 0x02
# define GDT_ACCESS_PROT_X 0x08
# define GDT_ACCESS_SEGMENT 0x10
# define GDT_ACCESS_RING(level) ((level) << 5)
# define GDT_ACCESS_PRESENT 0x80
/* flags */
# define GDT_FLAG_LONG_MODE 0x2 /* 64-bit code segment */
# define GDT_FLAG_PROTECTED_MODE 0x4 /* 32-bit protected mode
code segment */
# define GDT_FLAG_PAGE_GRANULARITY 0x8 /* 4 KB page size */
/* types */
#pragma pack(1)
typedef struct _GDTEntry
{
uint8_t limit0;
uint8_t limit1;
uint8_t base0;
uint8_t base1;
uint8_t base2;
uint8_t access;
unsigned int limit2:4;
unsigned int flags:4;
uint8_t base3;
} GDTEntry;
#pragma pack()
#pragma pack(1)
typedef struct _LDT
{
uint8_t limit0;
uint8_t limit1;
uint8_t base0;
uint8_t base1;
uint8_t base2;
uint8_t access;
unsigned int limit2:4;
unsigned int flags:4;
uint8_t base3;
} LDT;
#pragma pack()
struct _GDT
{
GDTEntry entries[GDT_ENTRIES_MAX];
size_t entries_cnt;
};
/* prototypes */
extern void __arch_setgdt(uint8_t * buf, size_t count);
extern void __arch_setgdt(GDTEntry const * entries, size_t count);
static int _gdt_append_entry(GDT * gdt, vaddr_t base, uint32_t limit,
uint8_t access, uint8_t flags);
/* variables */
static uint8_t _buf[65536];
static GDT _gdt;
static TSS _tss;
/* functions */
/* arch_setgdt */
int _arch_setgdt(GDT const * gdt, size_t count)
/* gdt_init */
GDT * gdt_init(void)
{
uint8_t * buf = _buf;
size_t i;
GDT g;
memset(&_gdt.entries[0], 0, sizeof(_gdt.entries[0]));
_gdt.entries_cnt = 1;
return &_gdt;
}
memset(&_buf, 0, sizeof(_buf));
/* check for errors */
if(count == 0 || count > sizeof(_buf) / sizeof(*gdt))
/* gdt_init_table */
int gdt_init_table(GDTTable const * table, size_t table_cnt, size_t tss_cnt)
{
int ret = 0;
GDT * gdt;
size_t i;
gdt = gdt_init();
for(i = 0; i < table_cnt; i++)
if((ret = gdt_append(gdt, table[i].base, table[i].size,
table[i].prot)) != 0)
return ret;
/* set the TSS */
if(tss_cnt > 1)
{
errno = ERANGE;
errno = ENOSYS;
return -1;
}
for(i = 0; i < count; i++)
{
g = gdt[i];
buf = &_buf[sizeof(g) * i];
if(g.limit > 65536)
{
/* make sure the limit can be encoded */
if((g.limit & 0xfff) != 0xfff)
return -1;
g.limit = g.limit >> 12;
buf[6] = 0xc0;
}
else
buf[6] = 0x40;
//encode the limit
buf[0] = g.limit & 0xff;
buf[1] = (g.limit >> 8) & 0xff;
buf[6] |= (g.limit >> 16) & 0xf;
//encode the base
buf[2] = g.base & 0xff;
buf[3] = (g.base >> 8) & 0xff;
buf[4] = (g.base >> 16) & 0xff;
buf[7] = (g.base >> 24) & 0xff;
//encode the type
buf[5] = g.type;
}
__arch_setgdt(_buf, count);
else if(tss_cnt == 1 && (ret = gdt_append_system(gdt, &_tss,
sizeof(_tss), GDT_SYSTEM_TYPE_TSS))
!= 0)
return ret;
gdt_apply(gdt);
return 0;
}
/* arch_setgdt64 */
int _arch_setgdt64(GDT const * gdt, size_t count)
/* useful */
/* gdt_append */
int gdt_append(GDT * gdt, vaddr_t base, size_t size, unsigned int prot)
{
uint8_t * buf;
size_t i;
GDT g;
uint32_t limit;
uint8_t access = GDT_ACCESS_SEGMENT | GDT_ACCESS_PRESENT
| GDT_ACCESS_RING(0);
uint8_t flags = GDT_FLAG_PROTECTED_MODE;
memset(&_buf, 0, sizeof(_buf));
/* check for errors */
if(count == 0 || count > sizeof(_buf) / sizeof(*gdt))
if(size == 0)
{
errno = ERANGE;
return -1;
}
for(i = 0; i < count; i++)
if(size > ULONG_MAX || ULONG_MAX - size < base)
{
g = gdt[i];
buf = &_buf[sizeof(g) * i];
if(g.limit > 65536)
{
/* make sure the limit can be encoded */
if((g.limit & 0xfff) != 0xfff)
return -1;
g.limit = g.limit >> 12;
buf[6] = 0xa0;
}
else
buf[6] = 0x20;
//encode the limit
buf[0] = g.limit & 0xff;
buf[1] = (g.limit >> 8) & 0xff;
buf[6] |= (g.limit >> 16) & 0xf;
//encode the base
buf[2] = g.base & 0xff;
buf[3] = (g.base >> 8) & 0xff;
buf[4] = (g.base >> 16) & 0xff;
buf[7] = (g.base >> 24) & 0xff;
//encode the type
buf[5] = g.type;
errno = ENOMEM;
return -1;
}
__arch_setgdt(_buf, count);
if(prot != GDT_PROT_READ
&& prot != (GDT_PROT_READ | GDT_PROT_WRITE)
&& prot != (GDT_PROT_READ | GDT_PROT_EXEC))
{
errno = EPERM;
return -1;
}
/* limit */
if(size - 1 > GDT_LIMIT_MAX)
{
limit = (size & 0xfff) == 0
? (size >> 12) - 1
: (((size | 0xfff) + 1) >> 12) - 1;
flags |= GDT_FLAG_PAGE_GRANULARITY;
}
else
limit = size - 1;
/* access */
if(prot == (GDT_PROT_READ | GDT_PROT_EXEC))
/* code segment */
access |= GDT_ACCESS_PROT_RW | GDT_ACCESS_PROT_X;
else if(prot == (GDT_PROT_READ | GDT_PROT_WRITE))
/* data segment (read/write) */
access |= GDT_ACCESS_PROT_RW;
else if(prot == GDT_PROT_READ)
/* data segment (read-only) */
access |= GDT_ACCESS_SET;
return _gdt_append_entry(gdt, base, limit, access, flags);
}
/* gdt_append_system */
static int _append_system_ldt(GDT * gdt, void * base, size_t size);
static int _append_system_tss(GDT * gdt, void * base, size_t size);
int gdt_append_system(GDT * gdt, void * base, size_t size, unsigned int type)
{
switch(type)
{
case GDT_SYSTEM_TYPE_LDT:
return _append_system_ldt(gdt, base, size);
case GDT_SYSTEM_TYPE_TSS:
return _append_system_tss(gdt, base, size);
default:
errno = ENOSYS;
return -1;
}
}
static int _append_system_ldt(GDT * gdt, void * base, size_t size)
{
uint32_t access = GDT_ACCESS_PRESENT | GDT_SYSTEM_TYPE_LDT;
uint8_t flags = GDT_FLAG_PROTECTED_MODE;
if(size != sizeof(LDT))
{
errno = ERANGE;
return -1;
}
return _gdt_append_entry(gdt, (vaddr_t)base, size - 1, access, flags);
}
static int _append_system_tss(GDT * gdt, void * base, size_t size)
{
uint32_t access = GDT_ACCESS_PRESENT | GDT_SYSTEM_TYPE_TSS;
uint8_t flags = GDT_FLAG_PROTECTED_MODE;
if(size != sizeof(TSS))
{
errno = ERANGE;
return -1;
}
return _gdt_append_entry(gdt, (vaddr_t)base, size - 1, access, flags);
}
/* gdt_apply */
void gdt_apply(GDT * gdt)
{
__arch_setgdt(gdt->entries, gdt->entries_cnt);
}
/* private */
/* gdt_append_entry */
static int _gdt_append_entry(GDT * gdt, vaddr_t base, uint32_t limit,
uint8_t access, uint8_t flags)
{
GDTEntry * entry;
/* check for errors */
if(gdt->entries_cnt >= sizeof(gdt->entries) / sizeof(*gdt->entries))
{
errno = ENOMEM;
return -1;
}
entry = &gdt->entries[gdt->entries_cnt];
entry->base0 = base & 0xff;
entry->base1 = (base & 0xff00) >> 8;
entry->base2 = (base & 0xff0000) >> 16;
entry->base3 = (base & 0xff000000) >> 24;
entry->limit0 = limit & 0xff;
entry->limit1 = (limit & 0xff00) >> 8;
entry->limit2 = (limit & 0xf0000) >> 16;
entry->access = access;
entry->flags = flags;
gdt->entries_cnt++;
return 0;
}
#endif

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2018-2019 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
@ -9,6 +9,7 @@
# include <string.h>
# include <kernel/drivers/bus.h>
# include <kernel/drivers/console.h>
# include <kernel/drivers/clock.h>
# include <kernel/drivers/display.h>
# include "arch/amd64/gdt.h"
# include "arch/i386/gdt.h"
@ -28,12 +29,10 @@
/* private */
/* constants */
/* GDT: 4GB flat memory setup */
static const GDT _gdt_4gb[4] =
static const GDTTable _gdt_4gb[2] =
{
{ 0x00000000, 0x00000000, 0x00 },
{ 0x00000000, 0xffffffff, 0x9a },
{ 0x00000000, 0xffffffff, 0x92 },
{ 0x00000000, 0x00000000, 0x89 }
{ 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_EXEC },
{ 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_WRITE }
};
@ -87,7 +86,8 @@ int multiboot(const ukMultibootInfo * mi)
printf("Booted from %#x\n", mi->boot_device_drive);
/* setup the GDT */
if(_arch_setgdt(_gdt_4gb, sizeof(_gdt_4gb) / sizeof(*_gdt_4gb)) != 0)
if(gdt_init_table((const GDTTable *)&_gdt_4gb,
sizeof(_gdt_4gb) / sizeof(*_gdt_4gb), 1) != 0)
{
puts("Could not setup the GDT");
return 4;

View File

@ -2,7 +2,8 @@ targets=crtbegin.o,crtend.o,crti.o,crtn.o,libuLoader,uLoader.bin
as=$(CC)
cc=$(CROSS)gcc
cppflags_force=-nostdinc -isystem ../../include -isystem ../../src/lib/libc/include -isystem ../../src/lib/libc/include/dl -I.. -D__DeforaOS__
asflags_force=$(CFLAGSF) $(CFLAGS) -c
asflags_force=$(CFLAGSF) -c
asflags=$(CFLAGS)
cflags=-W -Wall -g -O2
dist=Makefile
@ -28,6 +29,7 @@ asflags=`../../tools/platform.sh -V ULOADER_CFLAGS -C "$$ARCH"`
[libuLoader]
type=library
sources=boot/multiboot.c,bus.c,bus/cmos.c,bus/ioport.c,bus/vga.c,clock.c,clock/cmos.c,console.c,console/uart.c,display.c,display/vesa.c,display/vga.c,libk.c,syscalls.S
asflags=`../../tools/platform.sh -V LIBULOADER_ASFLAGS -C "$$ARCH"`
cflags=`../../tools/platform.sh -V LIBULOADER_CFLAGS -C "$$ARCH"`
ldflags=`../../tools/platform.sh -V LIBULOADER_LDFLAGS -C "$$ARCH"`
@ -83,7 +85,7 @@ depends=$(OBJDIR)../lib/libk.a
depends=../drivers/boot/multiboot.h,../../include/kernel/drivers/bus.h,../../include/kernel/drivers/console.h
[start.S]
depends=../arch/i386/intr.S,../arch/i386/loader.S,../arch/i386/multiboot.S
depends=../arch/i386/gdt.S,../arch/i386/intr.S,../arch/i386/loader.S,../arch/i386/multiboot.S
[syscalls.S]
depends=$(OBJDIR)../lib/libc/src/syscalls.o

View File

@ -1,6 +1,19 @@
subdirs=arch,common,lib,drivers,kernel,loader
targets=DeforaOS.iso
dist=Makefile
mode=i386-debug
#modes
[mode::amd64-debug]
targets=DeforaOS.iso
[mode::amd64-release]
targets=DeforaOS.iso
[mode::i386-debug]
targets=DeforaOS.iso
[mode::i386-release]
targets=DeforaOS.iso
#targets
[DeforaOS.iso]

3
tests/.gitignore vendored
View File

@ -1,2 +1,5 @@
/clint.log
/distcheck.log
/fixme.log
/gdt
/grub.log

192
tests/clint.sh Executable file
View File

@ -0,0 +1,192 @@
#!/bin/sh
#$Id$
#Copyright (c) 2016-2021 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#variables
CONFIGSH="${0%/clint.sh}/../config.sh"
CFLAGS=
CPPFLAGS=
PROGNAME="clint.sh"
PROJECTCONF="../project.conf"
#executables
DATE="date"
DEBUG="_debug"
ECHO="/bin/echo"
FIND="find"
GREP="grep"
LINT="lint -g"
MKDIR="mkdir -p"
SORT="sort -n"
TR="tr"
[ -f "$CONFIGSH" ] && . "$CONFIGSH"
#functions
#clint
_clint()
{
res=0
subdirs=
$DATE
while read line; do
case "$line" in
"["*)
break
;;
"subdirs="*)
subdirs=${line#subdirs=}
subdirs=$(echo "$subdirs" | $TR ',' ' ')
;;
esac
done < "$PROJECTCONF"
if [ ! -n "$subdirs" ]; then
_error "Could not locate directories to analyze"
return $?
fi
for subdir in $subdirs; do
[ -d "../$subdir" ] || continue
while read filename; do
[ -n "$filename" ] || continue
r=0
case "$filename" in
*.c)
echo
_clint_lint "$filename" || r=$?
_clint_rtrim "$filename"|| r=$?
;;
*.h)
echo
echo "$filename:"
_clint_rtrim "$filename"|| r=$?
;;
*)
continue
;;
esac
if [ $r -eq 0 ]; then
echo " OK"
echo "$PROGNAME: $filename: OK" 1>&2
else
echo "FAIL"
echo "$PROGNAME: $filename: FAIL" 1>&2
res=2
fi
done << EOF
$($FIND "../$subdir" -type f | $SORT)
EOF
done
return $res
}
_clint_lint()
{(
filename="$1"
$ECHO -n "${filename%/*}/"
$DEBUG $LINT $CPPFLAGS $CFLAGS "$filename" 2>&1
ret=$?
if [ $ret -eq 127 ]; then
#XXX ignore errors when $LINT is not available
ret=0
fi
return $ret
)}
_clint_rtrim()
{
filename="$1"
regex="[ ]\\+\$"
$DEBUG $GREP -vq "$regex" "$filename" 2>&1
}
#debug
_debug()
{
echo "$@" 1>&3
"$@"
}
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
#usage
_usage()
{
echo "Usage: $PROGNAME [-c] target..." 1>&2
return 1
}
#main
clean=0
while getopts "cO:P:" name; do
case "$name" in
c)
clean=1
;;
O)
export "${OPTARG%%=*}"="${OPTARG#*=}"
;;
P)
CPPFLAGS="$CPPFLAGS -I$OPTARG/include"
;;
?)
_usage
exit $?
;;
esac
done
shift $((OPTIND - 1))
if [ $# -lt 1 ]; then
_usage
exit $?
fi
#clean
[ $clean -ne 0 ] && exit 0
exec 3>&1
ret=0
while [ $# -gt 0 ]; do
target="$1"
dirname="${target%/*}"
shift
if [ -n "$dirname" -a "$dirname" != "$target" ]; then
$MKDIR -- "$dirname" || ret=$?
fi
_clint > "$target" || ret=$?
done
exit $ret

102
tests/distcheck.sh Executable file
View File

@ -0,0 +1,102 @@
#!/bin/sh
#$Id$
#Copyright (c) 2020 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#variables
CONFIGSH="${0%/distcheck.sh}/../config.sh"
CFLAGS=
LDFLAGS=
PROGNAME="distcheck.sh"
TARGET="tests.log"
#executables
DATE="date"
[ -n "$MAKE" ] || MAKE="make"
MKDIR="mkdir -p"
MKTEMP="mktemp"
RM="rm -f"
[ -f "$CONFIGSH" ] && . "$CONFIGSH"
#distcheck
_distcheck()
{
(cd .. && $MAKE distcheck)
}
#date
_date()
{
if [ -n "$SOURCE_DATE_EPOCH" ]; then
TZ=UTC $DATE -d "@$SOURCE_DATE_EPOCH" '+%a %b %d %T %Z %Y'
else
$DATE
fi
}
#usage
_usage()
{
echo "Usage: $PROGNAME [-c] target..." 1>&2
return 1
}
#main
clean=0
while getopts "cO:P:" name; do
case "$name" in
c)
clean=1
;;
O)
export "${OPTARG%%=*}"="${OPTARG#*=}"
;;
P)
#XXX ignored
;;
?)
_usage
exit $?
;;
esac
done
shift $((OPTIND - 1))
if [ $# -eq 0 ]; then
_usage
exit $?
fi
while [ $# -ne 0 ]; do
target="$1"
shift
[ "$clean" -eq 0 ] || break
(_date; echo; _distcheck) > "$target" || exit 2
done
exit 0

View File

@ -1,6 +1,6 @@
#!/bin/sh
#$Id$
#Copyright (c) 2017-2019 Pierre Pronchery <khorben@defora.org>
#Copyright (c) 2017-2022 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
@ -25,23 +25,30 @@
#variables
CONFIGSH="${0%/fixme.sh}/../config.sh"
PROGNAME="fixme.sh"
PROJECTCONF="../project.conf"
REGEXP_ERROR="FIXME"
REGEXP_WARNING="\\(TODO\|XXX\\)"
#executables
DATE="date"
DEBUG="_debug"
FIND="find"
GREP="grep"
HEAD="head"
MKDIR="mkdir -p"
SORT="sort -n"
TR="tr"
[ -f "$CONFIGSH" ] && . "$CONFIGSH"
#functions
#fixme
_fixme()
{
res=0
subdirs=
$DATE
echo
@ -56,27 +63,14 @@ _fixme()
;;
esac
done < "$PROJECTCONF"
if [ ! -n "$subdirs" ]; then
_error "Could not locate directories to analyze"
return $?
fi
for subdir in $subdirs; do
[ -d "../$subdir" ] || continue
for filename in $($FIND "../$subdir" -type f | $SORT); do
callback=
ext=${filename##*/}
ext=${ext%.in}
ext=${ext##*.}
case "$ext" in
asm|S)
callback="_fixme_asm"
;;
c|cc|cpp|cxx|h|js)
callback="_fixme_c"
;;
conf|sh)
callback="_fixme_sh"
;;
htm|html|xml)
callback="_fixme_xml"
;;
esac
callback=$(_fixme_callback "$filename")
[ -n "$callback" ] || continue
($callback "$filename") 2>&1
if [ $? -ne 0 ]; then
@ -88,54 +82,114 @@ _fixme()
return $res
}
_fixme_asm()
_fixme_callback()
{
filename="$1"
ext=${filename##*/}
ext=${ext%.in}
ext=${ext##*.}
callback=
case "$ext" in
asm|S)
echo "_fixme_callback_asm"
return 0
;;
c|cc|cpp|cxx|go|h|js|v)
echo "_fixme_callback_c"
return 0
;;
conf|sh)
echo "_fixme_callback_sh"
return 0
;;
py)
echo "_fixme_callback_python"
return 0
;;
htm|html|xml|xsl)
echo "_fixme_callback_xml"
return 0
;;
esac
case $($HEAD -n 1 "$filename") in
"#!/bin/sh"*|"#! /bin/sh"*|\
"#!/usr/bin/env bash"*|"#! /usr/bin/env bash"*)
echo "_fixme_callback_sh"
return 0
;;
"#!/usr/bin/env python"*|"#! /usr/bin/env python"*)
echo "_fixme_callback_python"
return 0
;;
"<!DOCTYPE"*|"<!doctype"*|"<HTML"*|"<html"*|"<?xml"*)
echo "_fixme_callback_xml"
return 0
;;
esac
return 2
}
_fixme_callback_asm()
{
res=0
filename="$1"
#warnings
$GREP -nH '/\*.*\(TODO\|XXX\)' "$filename"
$GREP -nH "/\\*.*$REGEXP_WARNING" "$filename"
#failures
$GREP -nH '/\*.*FIXME' "$filename" && res=2
$GREP -nH "/\\*.*$REGEXP_ERROR" "$filename" && res=2
return $res
}
_fixme_c()
_fixme_callback_c()
{
res=0
filename="$1"
#warnings
$GREP -nH '/\(/\|\*\).*\(TODO\|XXX\)' "$filename"
$GREP -nH "/\\(/\\|\\*\\).*$REGEXP_WARNING" "$filename"
#failures
$GREP -nH '/\(/\|\*\).*FIXME' "$filename" && res=2
$GREP -nH "/\\(/\\|\\*\\).*$REGEXP_ERROR" "$filename" && res=2
return $res
}
_fixme_sh()
_fixme_callback_python()
{
res=0
filename="$1"
#XXX avoid matching the regexp
comment="#"
#warnings
$GREP -nH "$comment.*\\(TODO\\|XXX\\)" "$filename"
$GREP -nH "$comment.*$REGEXP_WARNING" "$filename"
#failures
$GREP -nH "$comment.*FIXME" "$filename" && res=2
$GREP -nH "$comment.*$REGEXP_ERROR" "$filename" && res=2
return $res
}
_fixme_xml()
_fixme_callback_sh()
{
res=0
filename="$1"
comment="#"
#warnings
$GREP -nH "$comment.*$REGEXP_WARNING" "$filename"
#failures
$GREP -nH "$comment.*$REGEXP_ERROR" "$filename" && res=2
return $res
}
_fixme_callback_xml()
{
res=0
filename="$1"
#XXX limited to a single line
#warnings
$GREP -nH '<!--.*\(TODO\|XXX\)' "$filename"
$GREP -nH "<!--.*$REGEXP_WARNING" "$filename"
#failures
$GREP -nH '<!--.*FIXME' "$filename" && res=2
$GREP -nH "<!--.*$REGEXP_ERROR" "$filename" && res=2
return $res
}
@ -145,10 +199,14 @@ _debug()
{
echo "$@" 1>&3
"$@"
res=$?
#ignore errors when the command is not available
[ $res -eq 127 ] && return 0
return $res
}
#error
_error()
{
echo "$PROGNAME: $@" 1>&2
return 2
}
@ -200,6 +258,4 @@ while [ $# -gt 0 ]; do
fi
_fixme > "$target" || ret=$?
done
#XXX ignore errors
ret=0
exit $ret

76
tests/gdt.c Normal file
View File

@ -0,0 +1,76 @@
/* $Id$ */
/* Copyright (c) 2025 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
#include <stdio.h>
#ifndef vaddr_t
# define vaddr_t unsigned long
#endif
#include "../src/loader/gdt.c"
#if defined(__amd64__) || defined(__i386__)
/* variables */
static TSS tss;
/* functions */
/* __arch_setgdt */
void __arch_setgdt(GDTEntry const * entries, size_t count)
{
size_t i;
GDTEntry const * entry;
printf("sizeof(*entries) => %zu\n", sizeof(*entries));
for(i = 0; i < count; i++)
{
entry = &entries[i];
printf("base=0x%02x%02x%02x%02x ",
entry->base3, entry->base2,
entry->base1, entry->base0);
printf("limit=0x%x%02x%02x ",
entry->limit2, entry->limit1, entry->limit0);
printf("access=0x%02x ", entry->access);
printf("flags=0x%0x\n", entry->flags);
}
printf("count=0x%zx => size=0x%zx\n", count, (count << 3) - 1);
}
#endif
/* main */
int main(int argc, char * argv[])
{
#if defined(__amd64__) || defined(__i386__)
GDT * gdt;
(void) argc;
(void) argv;
printf("sizeof(GDTEntry) = %zu (expected: %u)\n\n",
sizeof(GDTEntry), 8);
/* flat 4 GB */
printf("Flat 4 GB:\n");
gdt = gdt_init();
gdt_append(gdt, 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_EXEC);
gdt_append(gdt, 0x00000000, 0xffffffff, GDT_PROT_READ | GDT_PROT_WRITE);
gdt_append_system(gdt, &tss, sizeof(tss), GDT_SYSTEM_TYPE_TSS);
gdt_apply(gdt);
/* 4 MB code + 4 MB data (read-write) + 4 MB data (read-only) */
printf("\n4 MB (rx) + 4 MB (rw) + 4 MB (ro):\n");
gdt = gdt_init();
gdt_append(gdt, 0x00400000, 0x00400000, GDT_PROT_READ | GDT_PROT_EXEC);
gdt_append(gdt, 0x00800000, 0x00400000, GDT_PROT_READ | GDT_PROT_WRITE);
gdt_append(gdt, 0x00c00000, 0x00400000, GDT_PROT_READ);
gdt_append_system(gdt, &tss, sizeof(tss), GDT_SYSTEM_TYPE_TSS);
gdt_apply(gdt);
#endif
(void) argc;
(void) argv;
return 0;
}

View File

@ -1,12 +1,37 @@
targets=fixme.log,grub.log
dist=Makefile,fixme.sh,grub.sh
targets=clint.log,distcheck.log,fixme.log,gdt,grub.log
cppflags_force=-I../src
cflags_force=-W -Wall -g -O2
dist=Makefile,clint.sh,distcheck.sh,fixme.sh,grub.sh
[grub.log]
#targets
[clint.log]
type=script
script=./grub.sh
depends=$(OBJDIR)../src/kernel/uKernel.bin,grub.sh
script=./clint.sh
depends=clint.sh
enabled=0
[distcheck.log]
type=script
script=./distcheck.sh
depends=distcheck.sh
enabled=0
[fixme.log]
type=script
script=./fixme.sh
depends=fixme.sh
enabled=0
[gdt]
type=binary
sources=gdt.c
[grub.log]
type=script
script=./grub.sh
depends=$(OBJDIR)../src/kernel/uKernel.bin,grub.sh
enabled=0
#sources
[gdt.c]
depends=../src/loader/gdt.c,../src/arch/amd64/gdt.h,../src/arch/i386/gdt.h

View File

@ -1,5 +1,5 @@
targets=platform.c
dist=Makefile,platform.conf,start.S
dist=Makefile,platform.conf
#targets
[platform.c]

View File

@ -1,91 +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
/* 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

View File

@ -1,5 +1,5 @@
targets=platform.c
dist=Makefile,start.S
dist=Makefile,platform.conf
#targets
[platform.c]

View File

@ -1,93 +0,0 @@
/* $Id$ */
/* Copyright (c) 2018 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 userland */
call 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

View File

@ -1,2 +1,15 @@
subdirs=amd64,i386
dist=Makefile,start.S
dist=Makefile
#modes
[mode::amd64-debug]
subdirs=amd64
[mode::amd64-release]
subdirs=amd64
[mode::i386-debug]
subdirs=i386
[mode::i386-release]
subdirs=i386

View File

@ -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

View File

@ -1,15 +0,0 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
#include <kernel/platform.h>
/* init */
int init(void)
{
platform_init();
return 0;
}

View File

@ -1,10 +1,13 @@
/* $Id$ */
/* Copyright (c) 2019 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2019-2020 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
@ -17,6 +20,7 @@
#include "lib/libc/src/ctype.c"
#include "lib/libc/src/dirent.c"
#include "lib/libc/src/errno.c"
#include "lib/libc/src/fcntl.c"
#include "lib/libc/src/pwd.c"
#include "lib/libc/src/signal.c"
#include "lib/libc/src/ssp/ssp.c"
@ -26,6 +30,7 @@
#include "lib/libc/src/string.c"
#include "lib/libc/src/sys/ioctl.c"
#include "lib/libc/src/sys/mman.c"
#include "lib/libc/src/sys/stat.c"
#include "lib/libc/src/sys/time.c"
#include "lib/libc/src/sys/wait.c"
#include "lib/libc/src/termios.c"

View File

@ -1,6 +1,6 @@
#!/bin/sh
#$Id$
#Copyright (c) 2015-2019 Pierre Pronchery <khorben@defora.org>
#Copyright (c) 2015-2021 Pierre Pronchery <khorben@defora.org>
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions are met:
@ -30,9 +30,10 @@ DESTDIR=
LDSOCONF="/etc/ld.so.conf"
PREFIX="/usr/local"
PROGNAME="platform.sh"
SOEXT=".so"
SOEXT=
#executables
UNAME="uname"
[ -f "$CONFIGSH" ] && . "$CONFIGSH"
@ -72,10 +73,17 @@ _library_ldsoconf()
line="${line%#*}"
#recurse into the file included
#XXX does not support globbing
filename="${ldsoconf%/*}/${line#include }"
[ -f "$filename" ] &&
_library_ldsoconf "$filename"
line="${line#include }"
if [ "${line#/}" = "$line" ]; then
files="${ldsoconf%/*}/$line"
else
files="$DESTDIR${line#include }"
fi
#XXX breaks on whitespace
for filename in $files; do
[ -f "$filename" ] &&
_library_ldsoconf "$filename"
done
;;
*)
#remove trailing comments
@ -148,6 +156,9 @@ _platform_variable()
SBINDIR)
echo "$PREFIX/sbin"
;;
SOEXT)
echo ".so"
;;
SYSCONFDIR)
if [ "$PREFIX" = "/usr" ]; then
echo "/etc"
@ -176,14 +187,14 @@ _platform_variable_amd64()
LIBK_LDFLAGS|NATIVE_LDFLAGS)
echo "-nostdlib"
;;
LIBULOADER_CFLAGS)
echo "-m32 -ffreestanding -fPIC -mno-red-zone$extra"
LIBULOADER_ASFLAGS|LIBULOADER_CFLAGS)
echo "-m32 -ffreestanding -fPIC$extra"
;;
LIBULOADER_LDFLAGS)
echo "-m32 -nostdlib"
;;
NATIVE_CFLAGS)
echo "-ffreestanding -fPIE$extra"
echo "-ffreestanding -fPIC$extra"
;;
UKERNEL_CFLAGS)
echo "-ffreestanding -fPIE -mno-red-zone$extra"
@ -195,7 +206,7 @@ _platform_variable_amd64()
echo "-m32 -ffreestanding$extra"
;;
ULOADER_LDFLAGS)
[ -n "$CC" ] || CC="cc"
[ -n "$CC" ] || CC="${CROSS}gcc"
echo "-m32 -nostdlib -static -T ${prepend}src/arch/i386/uKernel.ld $($CC -m32 -print-libgcc-file-name)"
;;
esac
@ -229,7 +240,7 @@ _platform_variable_i386()
echo "-ffreestanding$extra"
;;
ULOADER_LDFLAGS)
[ -n "$CC" ] || CC="cc"
[ -n "$CC" ] || CC="${CROSS}gcc"
echo "-nostdlib -static -T ${prepend}src/arch/i386/uKernel.ld $($CC -m32 -print-libgcc-file-name)"
;;
esac
@ -278,6 +289,8 @@ if [ $# -ne 0 ]; then
exit $?
fi
[ -n "$SOEXT" ] || SOEXT=$(_platform_variable SOEXT)
case "$type" in
library)
"_platform_$type" "$library"

View File

@ -1,7 +1,7 @@
subdirs=arch
targets=crtbegin.o,crtend.o,crti.o,crtn.o,libk,start.o,uKernel
as=$(CC)
cppflags_force=-nostdinc -isystem ../include -isystem ../src/lib/libc/include -I../src
cppflags_force=-nostdinc -isystem ../include -isystem ../src/lib/libc/include -isystem ../src/lib/libc/include/dl -isystem ../src/lib/libc/include/math -isystem ../src/lib/libc/include/pthread -isystem ../src/lib/libc/include/rt -isystem ../src/lib/libc/include/socket -I../src
asflags_force=$(CFLAGSF) $(CFLAGS) -c
cflags_force=`../tools/platform.sh -V NATIVE_CFLAGS -C "$$ARCH"`
cflags=-W -Wall -g -O2
@ -35,7 +35,7 @@ sources=start.S
[uKernel]
type=binary
sources=bus.c,clock.c,console.c,init.c,platform.c,main.c
sources=bus.c,clock.c,console.c,platform.c,main.c
ldflags=$(OBJDIR)crti.o $(OBJDIR)crtbegin.o $(OBJDIR)start.o $(OBJDIR)libk.a $(OBJDIR)crtend.o $(OBJDIR)crtn.o `$(CC) -print-libgcc-file-name`
depends=$(OBJDIR)crtbegin.o,$(OBJDIR)crtend.o,$(OBJDIR)start.o,$(OBJDIR)libk.a
@ -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

View File

@ -1,19 +1,17 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2018-2021 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
.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
#if defined(__ELF__)
.global __start_dlfcn
# ifndef __clang__
.type __start_dlfcn, @function
# endif
__start_dlfcn:
ret
#endif
#include "lib/libc/src/start.S"