Compare commits
97 Commits
khorben/to
...
master
Author | SHA1 | Date | |
---|---|---|---|
f39779e810 | |||
96eafeac45 | |||
abf21dedde | |||
a10b4f2b25 | |||
5fa83bd311 | |||
f94ea311d2 | |||
cb9b7d11fc | |||
869a68af63 | |||
084bdd18a2 | |||
fb07c0b7ce | |||
ec0bef8573 | |||
424bcec667 | |||
8bf47da51c | |||
6aec0c1962 | |||
8d3b5cc6b9 | |||
04b87759ef | |||
799964ac2f | |||
3d811ed787 | |||
49ca697b74 | |||
9aa1251c70 | |||
ed7adc26f4 | |||
ea795c5c4c | |||
a8970f8e6b | |||
d711cd6900 | |||
351050db96 | |||
788cf3a214 | |||
c907d271ac | |||
679b5d3974 | |||
b9c6fe8889 | |||
4c80d5acfd | |||
7dec975c14 | |||
b441af0b44 | |||
17878ca36b | |||
2625b4b51f | |||
bdfe05c628 | |||
1f07b0b9b4 | |||
ef9c1d0a9e | |||
1a3de2c259 | |||
af052c2002 | |||
10d0b11b6d | |||
c68673e0c1 | |||
c65d2682c7 | |||
1ffd766137 | |||
ac9bb36b42 | |||
75b452ee86 | |||
987ee27bbc | |||
6f292d88b2 | |||
6849331bbc | |||
35ae28b95d | |||
cf1f9f11cd | |||
bf8c5c32e5 | |||
30641adb21 | |||
36d3ccf6f1 | |||
2fbeb0608a | |||
ec6724b544 | |||
c82d2f45cb | |||
2a4c1c3e6d | |||
8771f6083e | |||
3196f29e6b | |||
32856fce8d | |||
465efafc3d | |||
49cc75b7ab | |||
f443007e9e | |||
d7a6a20006 | |||
4b019f5954 | |||
12263ca7fb | |||
e29dbdfbae | |||
0ec0061bd0 | |||
d30a9a986d | |||
a094eaf0e8 | |||
dd5dc86c50 | |||
1e21eaf1dc | |||
cfa3c70d71 | |||
e157c1dab4 | |||
979cc4b326 | |||
e3da0b55c6 | |||
8f2a9640f2 | |||
1ef072043a | |||
e747d7ebe2 | |||
41b5a82017 | |||
3cb499b8f5 | |||
2bb88f8533 | |||
f61f489ec5 | |||
2d3566fc61 | |||
2a9846de88 | |||
e8f394268e | |||
fcaf1ef1d3 | |||
193a46d367 | |||
52d156d961 | |||
4fbaf259f0 | |||
2dc44905d9 | |||
b6157e0035 | |||
147157f774 | |||
47001ea896 | |||
f8c4d902a8 | |||
c524928fa1 | |||
902d71edd4 |
32
.github/workflows/deforaos-c-ci_ubuntu-latest.yml
vendored
Normal file
32
.github/workflows/deforaos-c-ci_ubuntu-latest.yml
vendored
Normal 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
|
14
README.md
14
README.md
|
@ -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
|
||||
---------------
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
# define UKERNEL_DRIVERS_BUS_H
|
||||
|
||||
# include <stdarg.h>
|
||||
# include <stddef.h>
|
||||
# include <stdint.h>
|
||||
|
||||
|
||||
|
|
23
project.conf
23
project.conf
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
|
@ -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]
|
||||
|
|
|
@ -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)
|
||||
|
|
281
src/loader/gdt.c
281
src/loader/gdt.c
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
3
tests/.gitignore
vendored
|
@ -1,2 +1,5 @@
|
|||
/clint.log
|
||||
/distcheck.log
|
||||
/fixme.log
|
||||
/gdt
|
||||
/grub.log
|
||||
|
|
192
tests/clint.sh
Executable file
192
tests/clint.sh
Executable 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
102
tests/distcheck.sh
Executable 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
|
132
tests/fixme.sh
132
tests/fixme.sh
|
@ -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
76
tests/gdt.c
Normal 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;
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
targets=platform.c
|
||||
dist=Makefile,platform.conf,start.S
|
||||
dist=Makefile,platform.conf
|
||||
|
||||
#targets
|
||||
[platform.c]
|
||||
|
|
|
@ -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
|
|
@ -1,5 +1,5 @@
|
|||
targets=platform.c
|
||||
dist=Makefile,start.S
|
||||
dist=Makefile,platform.conf
|
||||
|
||||
#targets
|
||||
[platform.c]
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
15
tools/init.c
15
tools/init.c
|
@ -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;
|
||||
}
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue
Block a user