Skip to content

Commit e9450da

Browse files
committed
Working on a port to x86_64, switching from GRUB to Limine
1 parent 8ce4074 commit e9450da

File tree

107 files changed

+3948
-3577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+3948
-3577
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ documentation/out/*
3939
target/iso/boot/kernel
4040
target/iso/boot/loader
4141
target/iso/boot/ramdisk
42+
target/iso/boot/limine/limine-*.sys
43+
target/iso/boot/limine/limine-*.bin
44+
target/limine-*/*
45+
target/limine-*.tar.gz
46+
47+
node_modules
4248

4349
sysroot/system/include
4450
sysroot/system/lib/*

applications/gsh/src/gosh.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <string.h>
2929
#include <string>
3030

31+
#include <ghost/tasks/types.h>
32+
3133
char* cwdbuf = 0;
3234

3335
std::vector<std::string> gshAutocomplete(std::string toComplete)
@@ -306,6 +308,12 @@ bool gshHandleBuiltin(program_call_t* call)
306308
return true;
307309
}
308310

311+
if(call->program == "bg")
312+
{
313+
g_spawn(call->arguments.at(0).c_str(), "", "", G_SECURITY_LEVEL_APPLICATION);
314+
return true;
315+
}
316+
309317
if(call->program == "clear" || call->program == "cls")
310318
{
311319
g_terminal::clear();

build.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ APPS_ALL=0
2525

2626
EVERYTHING=1
2727

28+
# Targets
29+
requireTool mtools
30+
2831
# Define some helpers
2932
pushd() {
3033
command pushd "$@" >/dev/null
@@ -85,7 +88,27 @@ backspace_len() {
8588
printf "%0.s\b" $(seq 1 $@)
8689
}
8790

88-
# Targets
91+
# Build limine if required
92+
verify_limine() {
93+
pushd target
94+
print_name "bootloader-limine"
95+
printf "\n"
96+
97+
# TODO: Maybe move this all to toolchain setup
98+
if [ ! -d "limine-$LIMINE_VERSION" ]; then
99+
curl "$LIMINE_SOURCE" -k -o "limine-$LIMINE_VERSION.tar.gz"
100+
tar -xf "limine-$LIMINE_VERSION.tar.gz"
101+
pushd "limine-$LIMINE_VERSION"
102+
./configure --enable-bios-cd --enable-uefi-cd
103+
make
104+
popd
105+
fi
106+
107+
cp "limine-$LIMINE_VERSION/limine.h" "$SYSROOT/system/include/limine.h"
108+
109+
popd
110+
}
111+
89112
build_ports() {
90113
pushd patches/ports
91114

@@ -281,6 +304,9 @@ if [ ! -f "$SYSROOT/system/lib/libgcc_s.so.1" ]; then
281304
FIRST_RUN=1
282305
fi
283306

307+
# Always check limine
308+
verify_limine
309+
284310
# Parse arguments
285311
NEXT_ARGS_APPS=0
286312
for var in "$@"; do

docker-build-toolchain-image.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ echo "Building toolchain within Docker container..."
88
docker run --name ghost-toolchain-setup -v "$(pwd):/ghost/source" ubuntu:latest /ghost/source/docker-prepare.sh >>ghost-build.log 2>&1
99

1010
echo "Committing image..."
11-
docker commit --change='WORKDIR /ghost/source' --change='CMD ["/bin/bash"]' ghost-toolchain-setup ghost-toolchain
11+
docker commit --change='WORKDIR /ghost/source' --change='CMD ["/bin/bash"]' ghost-toolchain-setup ghost-toolchain-64
1212

1313
echo "Removing temporary container..."
1414
docker rm ghost-toolchain-setup
1515

1616
echo "Starting toolchain container now!"
1717
echo "To build the operating system, run within container: ./build.sh"
18-
echo "After exiting, you can join it again with: docker exec -it ghost-toolchain bash"
19-
docker run -it --name ghost-toolchain -v "$(pwd):/ghost/source" ghost-toolchain
18+
echo "After exiting, you can join it again with: docker exec -it ghost-toolchain-64 bash"
19+
docker run -it --name ghost-toolchain-64 -v "$(pwd):/ghost/source" ghost-toolchain-64

docker-prepare.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ apt-get install -y \
1717
autoconf2.69 pkg-config xorriso grub-pc-bin \
1818
make texinfo flex bison gcc g++ nasm \
1919
asciidoc asciidoctor \
20+
mtools \
2021
patch curl
2122

2223
# Clean up

ghost.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,16 @@ popd () {
145145

146146

147147
# Global variables
148-
with TARGET "i686-ghost"
148+
with TARGET "x86_64-ghost"
149149
with CROSS_CC $TARGET"-gcc"
150150
with CROSS_CXX $TARGET"-g++"
151151
with CROSS_LD $TARGET"-ld"
152152
with CROSS_GAS $TARGET"-as"
153153
with CROSS_AR $TARGET"-ar"
154154

155+
# Limine
156+
with LIMINE_VERSION "9.2.0"
157+
with LIMINE_SOURCE "https://ghostkernel.org/repository/limine/limine-$LIMINE_VERSION.tar.gz"
155158

156159
# Target architecture
157160
__TARGET_ARCH_PART=${TARGET%-*}

kernel/build.sh

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,26 @@ with TARGET "all"
1515
INC=inc
1616
BIN=bin
1717
SRC=src
18-
SRC_LOADER=$SRC/loader
1918
SRC_KERNEL=$SRC/kernel
2019
SRC_SHARED=$SRC/shared
2120

2221
#
2322
# Compiler flags
2423
#
2524
LDFLAGS="-nostdlib -nostartfiles"
26-
CFLAGS="-std=c++11 -D_GHOST_KERNEL_=1 -Wall -Wno-unused-but-set-variable -ffreestanding -fno-exceptions -fno-rtti"
25+
CFLAGS="-mcmodel=large -std=c++11 -D_GHOST_KERNEL_=1 -Wall -Wno-unused-but-set-variable -ffreestanding -fno-exceptions -fno-rtti"
2726

2827
#
2928
# Object output folders
3029
#
3130
OBJ_SHARED=$BIN/obj-shared
32-
OBJ_LOADER=$BIN/obj-loader
3331
OBJ_KERNEL=$BIN/obj-kernel
3432

3533

3634
#
3735
# Generated artifacts & linker scripts
3836
#
39-
ARTIFACT_LOADER=loader
4037
ARTIFACT_KERNEL=kernel
41-
LINKSCRIPT_LOADER=extra/link-loader.ld
4238
LINKSCRIPT_KERNEL=extra/link-kernel.ld
4339

4440

@@ -59,11 +55,9 @@ target_headline $TARGET
5955
target_clean() {
6056

6157
headline "cleaning"
62-
remove $ARTIFACT_LOADER
6358
remove $ARTIFACT_KERNEL
6459
cleanDirectory $BIN
6560
cleanDirectory $OBJ_SHARED
66-
cleanDirectory $OBJ_LOADER
6761
cleanDirectory $OBJ_KERNEL
6862
changes --clear
6963
}
@@ -122,7 +116,7 @@ target_compile() {
122116
if ( [ $headers_have_changed -eq 1 ] || [ $changed -eq 1 ] ); then
123117
out=`sourceToObject $file`
124118
list $out
125-
$NASM -f elf -s $file -o "$objdir/$out"
119+
$NASM -f elf64 -s $file -o "$objdir/$out"
126120
failOnError
127121
changes -s $file
128122
fi
@@ -138,7 +132,8 @@ target_link() {
138132
script=$2
139133
objects=$3
140134
headline "linking $artifact"
141-
135+
136+
echo $CROSS_LD $LD_FLAGS -o $artifact -T $script $objects
142137
$CROSS_LD $LD_FLAGS -o $artifact -T $script $objects
143138
failOnError
144139
}
@@ -149,9 +144,7 @@ target_link() {
149144
target_all() {
150145
target_compile_ap_startup
151146
target_compile $SRC_SHARED $OBJ_SHARED "-I$INC -I$SRC"
152-
target_compile $SRC_LOADER $OBJ_LOADER "-I$INC -I$SRC"
153147
target_compile $SRC_KERNEL $OBJ_KERNEL "-I$INC -I$SRC"
154-
target_link $ARTIFACT_LOADER $LINKSCRIPT_LOADER "$OBJ_LOADER/* $OBJ_SHARED/*"
155148
target_link $ARTIFACT_KERNEL $LINKSCRIPT_KERNEL "$OBJ_KERNEL/* $OBJ_SHARED/*"
156149
}
157150

kernel/extra/link-kernel.ld

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
1-
ENTRY (kernelMain)
1+
OUTPUT_FORMAT(elf64-x86-64)
2+
3+
ENTRY(kernelMain)
4+
5+
PHDRS
6+
{
7+
limine_requests PT_LOAD;
8+
text PT_LOAD;
9+
rodata PT_LOAD;
10+
data PT_LOAD;
11+
}
212

313
SECTIONS
414
{
5-
/* Start at this address*/
6-
. = 0xC0000000;
7-
8-
/* Text section */
9-
textSectionStart = .;
10-
.text BLOCK(4K) : ALIGN(4K)
11-
{
12-
*(.text)
13-
}
14-
textSectionEnd = .;
15-
16-
/* Read-only section */
17-
rodataSectionStart = .;
18-
.rodata BLOCK(4K) : ALIGN(4K)
19-
{
20-
startConstructors = .;
21-
*(SORT(.ctors*))
22-
endConstructors = .;
23-
24-
*(.rodata)
25-
}
26-
rodataSectionEnd = .;
27-
28-
/* Data section */
29-
dataSectionStart = .;
30-
.data BLOCK(4K) : ALIGN(4K)
31-
{
32-
*(.data)
33-
}
34-
dataSectionEnd = .;
35-
36-
/* BSS section */
37-
bssSectionStart = .;
38-
.bss BLOCK(4K) : ALIGN(4K)
39-
{
40-
*(COMMON)
41-
*(.bss)
42-
}
43-
bssSectionEnd = .;
44-
45-
/* Align the end of the kernel to 0x1000 */
46-
endKernel = ALIGN(4K);
15+
. = 0xffffffff80000000;
16+
17+
.limine_requests : {
18+
KEEP(*(.limine_requests_start))
19+
KEEP(*(.limine_requests))
20+
KEEP(*(.limine_requests_end))
21+
} :limine_requests
22+
23+
. = ALIGN(CONSTANT(MAXPAGESIZE));
24+
25+
.text : {
26+
*(.text .text.*)
27+
} :text
28+
29+
. = ALIGN(CONSTANT(MAXPAGESIZE));
30+
31+
.rodata : {
32+
*(.rodata .rodata.*)
33+
} :rodata
34+
35+
. = ALIGN(CONSTANT(MAXPAGESIZE));
36+
37+
.data : {
38+
*(.data .data.*)
39+
} :data
40+
41+
.bss : {
42+
*(.bss .bss.*)
43+
*(COMMON)
44+
} :data
45+
46+
/DISCARD/ : {
47+
*(.eh_frame*)
48+
*(.note .note.*)
49+
}
4750
}

kernel/extra/link-loader.ld

Lines changed: 0 additions & 53 deletions
This file was deleted.

kernel/inc/build_config.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
#endif
3333

3434
// pretty boot
35-
#define G_PRETTY_BOOT true
36-
#define G_VIDEO_LOG_BOOT false
35+
#define G_PRETTY_BOOT false
36+
#define G_VIDEO_LOG_BOOT true
3737

3838
// logging settings
3939
#define G_LOG_LEVEL G_LOG_LEVEL_INFO

0 commit comments

Comments
 (0)