From cc61fbecb9ee053341be62f08cf7846a8f5dcd71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Quei=C3=9Fner?= Date: Sat, 7 May 2016 16:59:40 +0200 Subject: [PATCH] Adds a simple program which starts at 1 GB. --- prototypes/program0/Makefile | 61 +++++++++++++++++++++++++++++++ prototypes/program0/linker.ld | 30 +++++++++++++++ prototypes/program0/program.c | 11 ++++++ prototypes/program0/program0.bin | Bin 0 -> 4144 bytes 4 files changed, 102 insertions(+) create mode 100644 prototypes/program0/Makefile create mode 100644 prototypes/program0/linker.ld create mode 100644 prototypes/program0/program.c create mode 100644 prototypes/program0/program0.bin diff --git a/prototypes/program0/Makefile b/prototypes/program0/Makefile new file mode 100644 index 0000000..8165fd4 --- /dev/null +++ b/prototypes/program0/Makefile @@ -0,0 +1,61 @@ + +AS=gcc +CC=gcc +CXX=g++ +LD=ld + +FLAGS = -mno-sse -DIDT_DISPATCH=$(IDT_DISPATCH) -ffreestanding -m32 -Werror -Wall -iquote include -iquote lists -O3 -g +ASFLAGS = $(FLAGS) +CFLAGS = $(FLAGS) +CXXFLAGS = $(FLAGS) -std=c++14 -fno-rtti -fno-exceptions -fno-leading-underscore -fno-use-cxa-atexit -nostdlib -fno-builtin + +ARTIFACT = program0.bin + +SRCS = $(shell find -regextype egrep -regex '.*/.*\.(cpp|S|c)') +OBJS = $(addsuffix .o, $(notdir $(basename $(SRCS)))) + +LIBGCC = $(shell gcc -m32 -print-libgcc-file-name) + +all: $(ARTIFACT) + +$(ARTIFACT): $(OBJS) + $(LD) -melf_i386 -Tlinker.ld -o $(ARTIFACT) $(addprefix obj/, $^) $(LIBGCC) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o obj/$@ $< + +%.o: %.c + $(CC) $(ASFLAGS) -c -o obj/$@ $< + +%.o: %.S + $(AS) $(CFLAGS) -c -o obj/$@ $< + +%.o: src/%.cpp + $(CXX) $(CXXFLAGS) -c -o obj/$@ $< + +%.o: src/%.c + $(CC) $(ASFLAGS) -c -o obj/$@ $< + +%.o: src/%.S + $(AS) $(CFLAGS) -c -o obj/$@ $< + +# Linux/Multiboot boot specific: +# -kernel bzImage use 'bzImage' as kernel image +# -append cmdline use 'cmdline' as kernel command line +# -initrd file use 'file' as initial ram disk +# -dtb file use 'file' as device tree image + + +run: + qemu-system-i386 \ + -kernel kernel-base.ker \ + -m 64 \ + -d cpu_reset,int \ + -no-reboot \ + -no-shutdown \ + -serial stdio + +bnr: kernel-base.ker run + +deploy: kernel-base.ker + cp $(ARTIFACT) /srv/tftp/$(ARTIFACT) \ No newline at end of file diff --git a/prototypes/program0/linker.ld b/prototypes/program0/linker.ld new file mode 100644 index 0000000..14ccb06 --- /dev/null +++ b/prototypes/program0/linker.ld @@ -0,0 +1,30 @@ +ENTRY(_start) +OUTPUT_FORMAT(binary) +OUTPUT_ARCH(i386:i386) + +SECTIONS +{ + . = 0x40000000; + .text : { + *(.text) + } + .data ALIGN(4096) : { + start_ctors = .; + KEEP(*( .init_array )); + KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* ))); + end_ctors = .; + + start_dtors = .; + KEEP(*( .fini_array )); + end_dtors = .; + + *(.data) + } + .rodata ALIGN(4096) : { + *(.rodata) + } + .bss ALIGN(4096) : { + *(.bss) + } + . = ALIGN(4096); +} diff --git a/prototypes/program0/program.c b/prototypes/program0/program.c new file mode 100644 index 0000000..ce530bd --- /dev/null +++ b/prototypes/program0/program.c @@ -0,0 +1,11 @@ +#include + +uint16_t *video = (uint16_t*)0xB8000; + +void _start() +{ + for(int i = 0; i < 256; i++) { + video[i] = 0xF000 | i; + } + while(1); +} \ No newline at end of file diff --git a/prototypes/program0/program0.bin b/prototypes/program0/program0.bin new file mode 100644 index 0000000000000000000000000000000000000000..55034e9a15ec3231ea93faff4250e14464ac1114 GIT binary patch literal 4144 zcmeC?We{L+Fg!4!cZ(VW5Of|&Ydpp9A+1xyvH1X_EdwJ1L+R_+|3FfsU^E0qLtr!n zMnhmU1V%$(Gz3ONU^E0qLtr!nMnhmU1V%$(sD?lTH-iY&?Tl4H42(4#jM6+TEFHj( SzW`8N28i#x|Nmbdss;eVlN6Ew literal 0 HcmV?d00001