mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-08-03 17:26:08 -04:00
Create a program generating more complex ELF file
This commit is contained in:
parent
868445e2e9
commit
dbbe1dfcd5
6
Makefile
6
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
|
||||
|
15
programs/hello/Makefile
Normal file
15
programs/hello/Makefile
Normal file
@ -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
|
38
programs/hello/src/main.cpp
Normal file
38
programs/hello/src/main.cpp
Normal file
@ -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<uint16_t*>(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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user