mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-09 04:22:04 -04:00
Prepare architecture to launch programs
This commit is contained in:
parent
e49d0077ae
commit
e368e20129
6
Makefile
6
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
|
||||
|
14
cpp.mk
Normal file
14
cpp.mk
Normal file
@ -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
|
@ -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:
|
||||
|
@ -63,6 +63,7 @@ void cat_command(const std::vector<std::string>& params);
|
||||
void mkdir_command(const std::vector<std::string>& params);
|
||||
void rm_command(const std::vector<std::string>& params);
|
||||
void touch_command(const std::vector<std::string>& params);
|
||||
void exec_command(const std::vector<std::string>& params);
|
||||
void shutdown_command(const std::vector<std::string>& params);
|
||||
|
||||
struct command_definition {
|
||||
@ -70,7 +71,7 @@ struct command_definition {
|
||||
void (*function)(const std::vector<std::string>&);
|
||||
};
|
||||
|
||||
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<std::string>& params){
|
||||
}
|
||||
}
|
||||
|
||||
void exec_command(const std::vector<std::string>& params){
|
||||
//TODO
|
||||
}
|
||||
|
||||
void shutdown_command(const std::vector<std::string>&){
|
||||
if(!acpi::init()){
|
||||
|
11
programs/one/Makefile
Normal file
11
programs/one/Makefile
Normal file
@ -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
|
BIN
programs/one/a.out
Normal file
BIN
programs/one/a.out
Normal file
Binary file not shown.
29
programs/one/src/main.cpp
Normal file
29
programs/one/src/main.cpp
Normal file
@ -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<uint16_t*>(0x0B8000);
|
||||
|
||||
vga_buffer[10 * 80 + 40] = make_vga_entry('1', make_color(15, 0));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user