Improved Linker script & Makefile
This commit is contained in:
parent
cec3b93c83
commit
0953fe31ec
40
Makefile
40
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
|
objects = entry.o kernel.o task.o handler.o interrupt.o v86.o print.o tss.o dosfs/dosfs.o gdt.o\
|
||||||
CFLAGS = -target "i686-elf" -m32 -mgeneral-regs-only -ffreestanding -march=i686 -fno-stack-protector -Wno-int-conversion -nostdlib -c
|
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
|
%.o: %.nasm
|
||||||
nasm -f elf32 -o $@ $<
|
nasm -f elf32 -o $@ $<
|
||||||
|
|
||||||
%.o: %.c
|
%.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:
|
virtdisk:
|
||||||
dd bs=1M count=32 if=/dev/zero of=virtdisk.bin
|
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
|
echo -n -e '\x55\xaa' | dd bs=1 seek=510 conv=notrunc of=virtdisk.bin
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(objects)
|
rm -f $(objects) out.o kernel.bin boot.bin
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
#define BLOCKSHIFT 16 // blockSize = 1 << blockShift
|
#define BLOCKSHIFT 16 // blockSize = 1 << blockShift
|
||||||
#define MAXFILESIZE 0x80000000 // 2GB
|
#define MAXFILESIZE 0x80000000 // 2GB
|
||||||
#define TOTALBLOCKS (MAXFILESIZE/BLOCKSIZE)
|
#define TOTALBLOCKS (MAXFILESIZE/BLOCKSIZE)
|
||||||
uint16_t writtenMap[TOTALBLOCKS];
|
uint16_t writtenMap[TOTALBLOCKS] __attribute__((section(".progbss")));;
|
||||||
uint32_t blockLenMap[TOTALBLOCKS];
|
uint32_t blockLenMap[TOTALBLOCKS] __attribute__((section(".progbss")));;
|
||||||
// NOTE This is linked at the end of program BSS section,
|
// NOTE This is linked at the end of program BSS section,
|
||||||
// so that it can be expanded without telling C how much
|
// so that it can be expanded without telling C how much
|
||||||
// it actually needs
|
// 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) {
|
void HexEditor(uint8_t *path, VOLINFO *vi) {
|
||||||
uint32_t err;
|
uint32_t err;
|
||||||
uint16_t *vga_text = (uint16_t *)0xb8000;
|
uint16_t *vga_text = (uint16_t *)0xb8000;
|
||||||
|
2
kernel.c
2
kernel.c
@ -414,7 +414,7 @@ void FileSelect() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t kernel_check= 0x12345678;
|
uint32_t kernel_check = 0x12345678;
|
||||||
void start() {
|
void start() {
|
||||||
word *vga_text = (word *)0xb8000;
|
word *vga_text = (word *)0xb8000;
|
||||||
char h[] = "LuciaOS";
|
char h[] = "LuciaOS";
|
||||||
|
27
link.ld
27
link.ld
@ -10,33 +10,40 @@ SECTIONS {
|
|||||||
|
|
||||||
.data : {
|
.data : {
|
||||||
*(.data);
|
*(.data);
|
||||||
|
*(.data*);
|
||||||
*(.rodata);
|
*(.rodata);
|
||||||
*(.rodata*);
|
*(.rodata*);
|
||||||
_edata = .;
|
_edata = .;
|
||||||
}
|
}
|
||||||
|
|
||||||
.realmode 0x4000 :
|
.realmode 0x4000 :
|
||||||
AT ( ADDR(.data) + SIZEOF(.data) )
|
AT ( _edata )
|
||||||
{ _v86code = .; *(.v86); _ev86code = .; }
|
{ _v86code = .; *(.v86); _ev86code = .; }
|
||||||
|
|
||||||
. = ADDR(.data) + SIZEOF(.data) + SIZEOF(.realmode);
|
. = _edata + SIZEOF(.realmode);
|
||||||
.thing : { _loadusercode = .; }
|
.thing : { _loadusercode = .; }
|
||||||
|
|
||||||
.usermode 0x400000 :
|
.usermode 0x400000 : AT(_loadusercode) {
|
||||||
AT ( ADDR(.data) + SIZEOF(.data) + SIZEOF(.realmode) )
|
_usercode = .; *(.user); _eusercode = .;
|
||||||
{ _usercode = .; *(.user); _eusercode = .; }
|
}
|
||||||
|
.bss 0x400000 (NOLOAD) : AT(_loadusercode + SIZEOF(.usermode)) {
|
||||||
.bss 0x400000 : {
|
|
||||||
_bprogstart = .;
|
_bprogstart = .;
|
||||||
hexedit.o(.bss);
|
*(.progbss);
|
||||||
|
*(.progbss*);
|
||||||
_bprogend = .;
|
_bprogend = .;
|
||||||
hexedit.o(.bss.end);
|
*(.proglatebss);
|
||||||
|
*(.proglatebss*);
|
||||||
}
|
}
|
||||||
|
|
||||||
. = ADDR(.data) + SIZEOF(.data) + SIZEOF(.realmode) + SIZEOF(.usermode);
|
. = ADDR(.data) + SIZEOF(.data) + SIZEOF(.realmode) + SIZEOF(.usermode);
|
||||||
|
|
||||||
.bss : ALIGN(0x1000)
|
.bss : ALIGN(0x1000)
|
||||||
{
|
{
|
||||||
_bstart = .; *(.bss); _bend = .;
|
_bstart = .; *(.bss); *(.bss*) _bend = .;
|
||||||
|
}
|
||||||
|
|
||||||
|
/DISCARD/ : {
|
||||||
|
*(.note*)
|
||||||
|
*(.comment*)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user