diff options
Diffstat (limited to '01_exercise')
-rw-r--r-- | 01_exercise/Makefile | 28 | ||||
-rw-r--r-- | 01_exercise/bootloader.c | 23 | ||||
-rw-r--r-- | 01_exercise/linker.ld | 34 |
3 files changed, 85 insertions, 0 deletions
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); + } +} |