diff --git a/Makefile b/Makefile index 856cc0a4..addd2a64 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,10 @@ bootloader/stage2.bin: force_look 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 +programs/hello/a.out: force_look + cd programs/hello; ${MAKE} a.out + +thor.flp: bootloader/stage1.bin bootloader/stage2.bin kernel/kernel.bin programs/one/a.out programs/hello/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 @@ -22,6 +25,7 @@ thor.flp: bootloader/stage1.bin bootloader/stage2.bin kernel/kernel.bin programs 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 + sudo /bin/cp programs/hello/a.out /mnt/fake_cdrom/hello sleep 0.1 sudo /bin/umount /mnt/fake_cdrom/ sudo /sbin/losetup -d /dev/loop0 diff --git a/programs/hello/Makefile b/programs/hello/Makefile new file mode 100644 index 00000000..a3d4d9a5 --- /dev/null +++ b/programs/hello/Makefile @@ -0,0 +1,15 @@ +.PHONY: default clean + +default: a.out + +include ../../cpp.mk + +%.cpp.o: src/%.cpp + $(CC) $(CPP_FLAGS_64) $(WARNING_FLAGS) -c $< -o $@ + +a.out: main.cpp.o + $(CC) $(COMMON_LINK_FLAGS) -e main $(CPP_FLAGS_64) -o a.out main.cpp.o + +clean: + rm *.cpp.o + rm -rf a.out diff --git a/programs/hello/src/main.cpp b/programs/hello/src/main.cpp new file mode 100644 index 00000000..648ce257 --- /dev/null +++ b/programs/hello/src/main.cpp @@ -0,0 +1,38 @@ +//======================================================================= +// 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__))); + +const char* source = "Hello world"; + +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); + + auto s = source; + uint64_t i = 0; + + while(*s){ + vga_buffer[10 * 80 + 20 + i * 2] = make_vga_entry(*s, make_color(15, 0)); + ++s; + ++i; + } + + return 0; +} \ No newline at end of file