From e368e20129dc79c36649a7e771fce889059f9747 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sun, 5 Jan 2014 16:14:10 +0100 Subject: [PATCH] Prepare architecture to launch programs --- Makefile | 6 +++++- cpp.mk | 14 ++++++++++++++ kernel/Makefile | 17 +++-------------- kernel/src/shell.cpp | 7 ++++++- programs/one/Makefile | 11 +++++++++++ programs/one/a.out | Bin 0 -> 1392 bytes programs/one/src/main.cpp | 29 +++++++++++++++++++++++++++++ 7 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 cpp.mk create mode 100644 programs/one/Makefile create mode 100644 programs/one/a.out create mode 100644 programs/one/src/main.cpp diff --git a/Makefile b/Makefile index 2288e7cc..963d050d 100644 --- a/Makefile +++ b/Makefile @@ -11,13 +11,17 @@ bootloader/stage1.bin: force_look bootloader/stage2.bin: force_look cd bootloader; $(MAKE) stage2.bin -thor.flp: bootloader/stage1.bin bootloader/stage2.bin kernel/kernel.bin +programs/one/a.out: force_look + cd programs/one; ${MAKE} a.out + +thor.flp: bootloader/stage1.bin bootloader/stage2.bin kernel/kernel.bin programs/one/a.out dd if=bootloader/stage1.bin of=hdd.img conv=notrunc dd if=bootloader/stage2.bin of=hdd.img seek=1 conv=notrunc sudo /sbin/losetup -o1048576 /dev/loop0 hdd.img sudo /usr/sbin/mkdosfs -F32 /dev/loop0 sudo /bin/mount -t vfat /dev/loop0 /mnt/fake_cdrom/ sudo /bin/cp kernel/kernel.bin /mnt/fake_cdrom/ + sudo /bin/cp programs/one/a.out /mnt/fake_cdrom/one sleep 0.1 sudo /bin/umount /mnt/fake_cdrom/ sudo /sbin/losetup -d /dev/loop0 diff --git a/cpp.mk b/cpp.mk new file mode 100644 index 00000000..17bedc11 --- /dev/null +++ b/cpp.mk @@ -0,0 +1,14 @@ +CC=x86_64-elf-g++ +AS=x86_64-elf-as +OC=x86_64-elf-objcopy + +WARNING_FLAGS=-Wall -Wextra -pedantic -Wold-style-cast -Wshadow +COMMON_CPP_FLAGS=-masm=intel -Iinclude/ -nostdlib -Os -std=c++11 -fno-stack-protector -fno-exceptions -funsigned-char -fno-rtti -ffreestanding -fomit-frame-pointer -mno-red-zone -mno-3dnow -mno-mmx + +CPP_FLAGS_LOW=-march=i386 -m32 -fno-strict-aliasing -fno-pic -fno-toplevel-reorder -mno-sse -mno-sse2 -mno-sse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 + +CPP_FLAGS_16=$(COMMON_CPP_FLAGS) $(CPP_FLAGS_LOW) -mregparm=3 -mpreferred-stack-boundary=2 +CPP_FLAGS_32=$(COMMON_CPP_FLAGS) $(CPP_FLAGS_LOW) -mpreferred-stack-boundary=4 +CPP_FLAGS_64=$(COMMON_CPP_FLAGS) -mno-sse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 + +COMMON_LINK_FLAGS=-lgcc diff --git a/kernel/Makefile b/kernel/Makefile index e19288c5..e74b334d 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -1,21 +1,10 @@ default: kernel.bin -CC=x86_64-elf-g++ -AS=x86_64-elf-as -OC=x86_64-elf-objcopy +include ../cpp.mk THOR_FLAGS=-DCONFIG_HISTORY=y -WARNING_FLAGS=-Wall -Wextra -pedantic -Wold-style-cast -Wshadow -COMMON_CPP_FLAGS=-masm=intel -Iinclude/ -nostdlib -Os -std=c++11 -fno-stack-protector -fno-exceptions -funsigned-char -fno-rtti -ffreestanding -fomit-frame-pointer -mno-red-zone -mno-3dnow -mno-mmx - -CPP_FLAGS_LOW=-march=i386 -m32 -fno-strict-aliasing -fno-pic -fno-toplevel-reorder -mno-sse -mno-sse2 -mno-sse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 - -CPP_FLAGS_16=$(COMMON_CPP_FLAGS) $(CPP_FLAGS_LOW) -mregparm=3 -mpreferred-stack-boundary=2 -CPP_FLAGS_32=$(COMMON_CPP_FLAGS) $(CPP_FLAGS_LOW) -mpreferred-stack-boundary=4 -CPP_FLAGS_64=$(COMMON_CPP_FLAGS) -mno-sse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 - -LINK_FLAGS=-lgcc -T linker.ld +KERNEL_LINK_FLAGS=$(COMMON_LINK_FLAGS) -T linker.ld KERNEL_CPP_FILES=$(wildcard src/*.cpp) KERNEL_CPP_STL_FILES=$(wildcard src/stl/*.cpp) @@ -62,7 +51,7 @@ src/stl/%.cpp.o: -include $(KERNEL_D_STL_FILES) kernel.bin: $(LINK_O_FILES) - $(CC) $(LINK_FLAGS) $(CPP_FLAGS_64) -o kernel.bin.o $(LINK_O_FILES) + $(CC) $(KERNEL_LINK_FLAGS) $(CPP_FLAGS_64) -o kernel.bin.o $(LINK_O_FILES) $(OC) -R .note -R .comment -S -O binary kernel.bin.o kernel.bin debug: diff --git a/kernel/src/shell.cpp b/kernel/src/shell.cpp index f66860e6..64e8a96e 100644 --- a/kernel/src/shell.cpp +++ b/kernel/src/shell.cpp @@ -63,6 +63,7 @@ void cat_command(const std::vector& params); void mkdir_command(const std::vector& params); void rm_command(const std::vector& params); void touch_command(const std::vector& params); +void exec_command(const std::vector& params); void shutdown_command(const std::vector& params); struct command_definition { @@ -70,7 +71,7 @@ struct command_definition { void (*function)(const std::vector&); }; -command_definition commands[24] = { +command_definition commands[25] = { {"reboot", reboot_command}, {"help", help_command}, {"uptime", uptime_command}, @@ -94,6 +95,7 @@ command_definition commands[24] = { {"mkdir", mkdir_command}, {"touch", touch_command}, {"rm", rm_command}, + {"exec", exec_command}, {"shutdown", shutdown_command}, }; @@ -634,6 +636,9 @@ void rm_command(const std::vector& params){ } } +void exec_command(const std::vector& params){ + //TODO +} void shutdown_command(const std::vector&){ if(!acpi::init()){ diff --git a/programs/one/Makefile b/programs/one/Makefile new file mode 100644 index 00000000..5a9bb981 --- /dev/null +++ b/programs/one/Makefile @@ -0,0 +1,11 @@ +.PHONY: default clean + +default: a.out + +include ../../cpp.mk + +a.out: src/main.cpp + $(CC) $(CPP_FLAGS_64) $(WARNING_FLAGS) -c $< -o $@ + +clean: + rm -rf a.out diff --git a/programs/one/a.out b/programs/one/a.out new file mode 100644 index 0000000000000000000000000000000000000000..78d7e000fa261e548e0a03ed85bd75e006cc1cf7 GIT binary patch literal 1392 zcmbtU&r2Io5S}$@U4Im9upsCmJ(Q+U9;QSP53-P|J%|UPPJb3j_@aQq#yxI9SZ<5!?p4x$ZGxN>Nn|U*D-^u#c#+c`kkVk7Y(gY={SYVLB z0Zoxl!CC+MzBuu8bKVbTE}yUOeU{n2cUydSaXLlSnd;RIZPx3n<;v#v*AL~IT2Y^f z=FHaK@eX;tS#M!_+`r%)vy3kq+l1l3mW(`YIO0DW`IX@rQ{AID)w`s+X)@rENNLzh zN&V2NCbiq`k^;bfI!O;Yq?+wG4)@t330qo)QDZOBacJ-TAMygnqJ=M=Jp!Y@aqyy} zzhxcq1qc7;=%Tvu@7dt<_pk9EIX16;$^X|3j4!hxt+Ir8nWGq_za;?-hc8I@7bA~l z=xFH~QR)y2&T3Pg6}Km_S6&Rfus;ZQ4l|PYd4No>`Ez>*{0e_avwtFk-+38T@dvz(+zr#ke-D)RM1fZ4y khd*_LAA;nl84=u3Mi~neW@yi`mZ2kD>X7>cU;8wF01)<5-~a#s literal 0 HcmV?d00001 diff --git a/programs/one/src/main.cpp b/programs/one/src/main.cpp new file mode 100644 index 00000000..048ac1df --- /dev/null +++ b/programs/one/src/main.cpp @@ -0,0 +1,29 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +typedef unsigned int uint8_t __attribute__((__mode__(__QI__))); +typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__))); +typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__))); +typedef unsigned int uint64_t __attribute__ ((__mode__ (__DI__))); + +uint8_t make_color(uint8_t fg, uint8_t bg){ + return fg | bg << 4; +} + +uint16_t make_vga_entry(char c, uint8_t color){ + uint16_t c16 = c; + uint16_t color16 = color; + return c16 | color16 << 8; +} + +int main(){ + uint16_t* vga_buffer = reinterpret_cast(0x0B8000); + + vga_buffer[10 * 80 + 40] = make_vga_entry('1', make_color(15, 0)); + + return 0; +} \ No newline at end of file