From 0cf88f665b00962e9fa93f0d52977c1437d034c9 Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Tue, 28 Apr 2020 11:50:23 +0200 Subject: adapted dir structure to exercise modualities --- .gitignore | 1 + 01_exercise/Makefile | 28 +++++++++++++++++++++++++ 01_exercise/bootloader.c | 23 ++++++++++++++++++++ 01_exercise/linker.ld | 34 ++++++++++++++++++++++++++++++ Makefile | 53 ----------------------------------------------- folien/praktikum1.pdf | Bin 0 -> 143089 bytes folien/praktikum2.pdf | Bin 0 -> 124527 bytes main.c | 21 ------------------- praktikum/praktikum1.pdf | Bin 143089 -> 0 bytes 9 files changed, 86 insertions(+), 74 deletions(-) create mode 100644 01_exercise/Makefile create mode 100644 01_exercise/bootloader.c create mode 100644 01_exercise/linker.ld delete mode 100644 Makefile create mode 100644 folien/praktikum1.pdf create mode 100644 folien/praktikum2.pdf delete mode 100644 main.c delete mode 100644 praktikum/praktikum1.pdf diff --git a/.gitignore b/.gitignore index 7623090..2c56edf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea *.o *_exe +cmake-build-debug/ diff --git a/01_exercise/Makefile b/01_exercise/Makefile new file mode 100644 index 0000000..4bf8198 --- /dev/null +++ b/01_exercise/Makefile @@ -0,0 +1,28 @@ +#!/usr/bin/make +.SUFFIXES: +SRC = bootloader.c +TAR = bootloader.bin +PCK = lab-1.zip + +CFLAGS = -m32 -c -Os -march=i686 -ffreestanding -Wall -Werror +LFLAGS = -m elf_i386 -static -Tlinker.ld -nostdlib --nmagic + +%.o: %.c + $(CC) $(CFLAGS) $^ -o $@ + +%.elf: %.o + $(LD) $(LFLAGS) -o $@ $^ + +%.bin: %.elf + objcopy -O binary $^ $@ + +all: $(TAR) + +run: $(TAR) + qemu-system-x86_64 -drive format=raw,file=$^ + +pack: + zip $(PCK) Makefile *.c *.h *.s + +clean: + $(RM) $(RMFILES) $(TAR) $(PCK) diff --git a/01_exercise/bootloader.c b/01_exercise/bootloader.c new file mode 100644 index 0000000..a5806e4 --- /dev/null +++ b/01_exercise/bootloader.c @@ -0,0 +1,23 @@ +/* needs to stay the first line */ +asm(".code16gcc\njmp $0, $main"); + +/* space for additional code */ + +void main(void) +{ + asm( + "mov $0x007, %%ebx;" + "mov $0xE4E, %%eax; int $0x10;" + "mov $0xE69, %%eax; int $0x10;" + "mov $0xE63, %%eax; int $0x10;" + "mov $0xE65, %%eax; int $0x10;" + "mov $0xE20, %%eax; int $0x10;" + "mov $0xE42, %%eax; int $0x10;" + "mov $0xE6F, %%eax; int $0x10;" + "mov $0xE6F, %%eax; int $0x10;" + "mov $0xE74, %%eax; int $0x10;" + "mov $0xE73, %%eax; int $0x10;" + "jmp .;" + ::: "eax", "ebx" + ); +} diff --git a/01_exercise/linker.ld b/01_exercise/linker.ld new file mode 100644 index 0000000..b02f05e --- /dev/null +++ b/01_exercise/linker.ld @@ -0,0 +1,34 @@ +ENTRY(main); +SECTIONS +{ + . = 0x7C00; + .text : AT(0x7C00) + { + _text = .; + *(.text); + _text_end = .; + } + .data : + { + _data = .; + *(.bss); + *(.bss*); + *(.data); + *(.rodata*); + *(COMMON) + _data_end = .; + } + .sig : AT(0x7DFE) + { + SHORT(0xaa55); + } + /DISCARD/ : + { + *(.note*); + *(.iplt*); + *(.igot*); + *(.rel*); + *(.comment); + *(.eh_frame); + } +} diff --git a/Makefile b/Makefile deleted file mode 100644 index 647ebcd..0000000 --- a/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# if $CC is not set, use gcc as a sensible default -CC ?= gcc -RM ?= rm -fv - -# if $CFLAGS is not set, be very pedantic and compile -# as C11, that should catch some common errors, also -# fortify the source, which is a must for security. -CFLAGS ?= -Wall \ - -D_FORTIFY_SOURCE=2 \ - -Wextra -Wcast-align -Wcast-qual -Wpointer-arith \ - -Waggregate-return -Wunreachable-code -Wfloat-equal \ - -Wformat=2 -Wredundant-decls -Wundef \ - -Wdisabled-optimization -Wshadow -Wmissing-braces \ - -Wstrict-aliasing=2 -Wstrict-overflow=5 -Wconversion \ - -Wno-unused-parameter \ - -pedantic -std=c11 - -CFLAGS_DEBUG := -g3 \ - -O \ - -DDEBUG - -CFLAGS_RELEASE := -O2 \ - -DNDEBUG \ - -march=native \ - -mtune=native \ - -ftree-vectorize - -# the default target is debug -all: debug - -# clean target, removing all .o and the executable -clean: - $(RM) *o bs_exe - -# when the target is debug, -# add CFLAGS_DEBUG to CFLAGS -debug: CFLAGS += $(CFLAGS_DEBUG) -debug: clean bs_exe - -# when the target is release, -# add CFLAGS_RELEASE to CFLAGS -release: CFLAGS += $(CFLAGS_RELEASE) -release: clean bs_exe - -bs_exe: main.o - $(CC) $^ -o $@ $(CFLAGS) - -# when looking for something that ends in .o, look -# for the same thing ending in .c and run gcc on it -%.o: %.c - $(CC) -c $< $(CFLAGS) - -.PHONY: debug release clean \ No newline at end of file diff --git a/folien/praktikum1.pdf b/folien/praktikum1.pdf new file mode 100644 index 0000000..09a176c Binary files /dev/null and b/folien/praktikum1.pdf differ diff --git a/folien/praktikum2.pdf b/folien/praktikum2.pdf new file mode 100644 index 0000000..132d4a5 Binary files /dev/null and b/folien/praktikum2.pdf differ diff --git a/main.c b/main.c deleted file mode 100644 index db72bf9..0000000 --- a/main.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -#if !defined(NDEBUG) - #define TRACE(MSG) \ - fprintf(stderr, "%s\n", #MSG) -#else - #define TRACE(MSG) -#endif - -int main(int argc, char *argv[]) { - TRACE(pre assembly); - __asm__("imul %%eax, %%eax" - : - : - : - ); - TRACE(post assembly); - return 0; -} - -/* https://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html */ \ No newline at end of file diff --git a/praktikum/praktikum1.pdf b/praktikum/praktikum1.pdf deleted file mode 100644 index 09a176c..0000000 Binary files a/praktikum/praktikum1.pdf and /dev/null differ -- cgit v1.2.3-54-g00ecf