diff --git a/Makefile b/Makefile index 1245f6f..9f3fe89 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,41 @@ -objects = entry.o kernel.o task.o handler.o interrupt.o v86.o print.o tss.o dosfs/dosfs.o gdt.o usermode.o paging.o fault.o tests.o kbd.o helper.o progs.o disk.o hexedit.o -CFLAGS = -target "i686-elf" -m32 -mgeneral-regs-only -ffreestanding -march=i686 -fno-stack-protector -Wno-int-conversion -nostdlib -c +objects = entry.o kernel.o task.o handler.o interrupt.o v86.o print.o tss.o dosfs/dosfs.o gdt.o\ + usermode.o paging.o fault.o tests.o kbd.o helper.o progs.o disk.o hexedit.o +CFLAGS = -target "i686-elf" -m32 -mgeneral-regs-only -ffreestanding\ + -march=i686 -fno-stack-protector -Wno-int-conversion -nostdlib -c +LFLAGS = -Wl,--gc-sections -Wl,--print-gc-sections -m32 -nostartfiles -nostdlib + +ifeq ($(OUTFILE),) +OUTFILE = virtdisk.bin +endif + +.PHONY: $(OUTFILE) + +all: $(OUTFILE) + +$(OUTFILE): boot.bin kernel.bin + # Copy to boot sector, don't overwrite MBR + dd bs=400 count=1 conv=notrunc if=boot.bin of=$@ + # Write kernel beyond boot sector, maximum 128K (256 sectors) + dd bs=512 count=256 seek=1 conv=notrunc if=kernel.bin of=$@ + +boot.bin: boot.nasm + nasm -o $@ $< + +kernel.bin: out.o link.ld + clang $(LFLAGS) -Wl,-M -Tlink.ld -ffreestanding -o $@ $< + +out.o: $(objects) + clang $(LFLAGS) -e entry -r -o $@ $^ %.o: %.nasm nasm -f elf32 -o $@ $< %.o: %.c - clang $(CFLAGS) -O2 -o $@ $< + clang $(CFLAGS) -ffunction-sections -fdata-sections -Os -o $@ $< -all: $(objects) - nasm boot.nasm -o boot.bin - gcc -Tlink.ld -Wl,-M -m32 -ffreestanding -nostartfiles -nostdlib -o kernel.bin\ - $(objects) - dd bs=400 count=1 conv=notrunc if=boot.bin of=virtdisk.bin - dd bs=512 seek=1 conv=notrunc if=kernel.bin of=virtdisk.bin virtdisk: dd bs=1M count=32 if=/dev/zero of=virtdisk.bin echo -n -e '\x55\xaa' | dd bs=1 seek=510 conv=notrunc of=virtdisk.bin clean: - rm $(objects) + rm -f $(objects) out.o kernel.bin boot.bin diff --git a/hexedit.c b/hexedit.c index 2a7c34d..4acab45 100644 --- a/hexedit.c +++ b/hexedit.c @@ -5,12 +5,12 @@ #define BLOCKSHIFT 16 // blockSize = 1 << blockShift #define MAXFILESIZE 0x80000000 // 2GB #define TOTALBLOCKS (MAXFILESIZE/BLOCKSIZE) -uint16_t writtenMap[TOTALBLOCKS]; -uint32_t blockLenMap[TOTALBLOCKS]; +uint16_t writtenMap[TOTALBLOCKS] __attribute__((section(".progbss")));; +uint32_t blockLenMap[TOTALBLOCKS] __attribute__((section(".progbss")));; // NOTE This is linked at the end of program BSS section, // so that it can be expanded without telling C how much // it actually needs -uint8_t writeStoreBase[BLOCKSIZE] __attribute__((section(".bss.end"))); +uint8_t writeStoreBase[BLOCKSIZE] __attribute__((section(".proglatebss"))); void HexEditor(uint8_t *path, VOLINFO *vi) { uint32_t err; uint16_t *vga_text = (uint16_t *)0xb8000; diff --git a/kernel.c b/kernel.c index d688995..5358bca 100644 --- a/kernel.c +++ b/kernel.c @@ -414,7 +414,7 @@ void FileSelect() { } } -uint32_t kernel_check= 0x12345678; +uint32_t kernel_check = 0x12345678; void start() { word *vga_text = (word *)0xb8000; char h[] = "LuciaOS"; diff --git a/link.ld b/link.ld index ae135c1..9021fe9 100644 --- a/link.ld +++ b/link.ld @@ -10,33 +10,40 @@ SECTIONS { .data : { *(.data); + *(.data*); *(.rodata); *(.rodata*); _edata = .; } .realmode 0x4000 : - AT ( ADDR(.data) + SIZEOF(.data) ) + AT ( _edata ) { _v86code = .; *(.v86); _ev86code = .; } - . = ADDR(.data) + SIZEOF(.data) + SIZEOF(.realmode); + . = _edata + SIZEOF(.realmode); .thing : { _loadusercode = .; } - .usermode 0x400000 : - AT ( ADDR(.data) + SIZEOF(.data) + SIZEOF(.realmode) ) - { _usercode = .; *(.user); _eusercode = .; } - - .bss 0x400000 : { + .usermode 0x400000 : AT(_loadusercode) { + _usercode = .; *(.user); _eusercode = .; + } + .bss 0x400000 (NOLOAD) : AT(_loadusercode + SIZEOF(.usermode)) { _bprogstart = .; - hexedit.o(.bss); + *(.progbss); + *(.progbss*); _bprogend = .; - hexedit.o(.bss.end); + *(.proglatebss); + *(.proglatebss*); } . = ADDR(.data) + SIZEOF(.data) + SIZEOF(.realmode) + SIZEOF(.usermode); .bss : ALIGN(0x1000) { - _bstart = .; *(.bss); _bend = .; + _bstart = .; *(.bss); *(.bss*) _bend = .; + } + + /DISCARD/ : { + *(.note*) + *(.comment*) } } diff --git a/progs.c b/progs.c index ca54182..3e50d47 100644 --- a/progs.c +++ b/progs.c @@ -1,6 +1,4 @@ #include "progs.h" -#include "helper.h" -#include "kbd.h" void TextViewTest(uint8_t *path, VOLINFO *vi) { uint16_t *vga_text = (uint16_t *)0xb8000;