Skip to content

Commit ae3c3c7

Browse files
committed
Added linker script to improve compile reliability
1 parent c36ed90 commit ae3c3c7

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

Makefile

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ app_dashboard = $(BUILD_APP)/dashboard
4444
# Parameters
4545
# 1-byte hex and 1-based indexing for BT STAGE 2 ONLY
4646
SECTOR_START_BT_STAGE2 = 03
47-
SECTOR_COUNT_BT_STAGE2 = 19
47+
SECTOR_COUNT_BT_STAGE2 = 0b
4848
SECTOR_START_SHARED_LIBRARY = 1
4949
SECTOR_COUNT_SHARED_LIBRARY = 1
50-
SECTOR_START_KERNEL = 27
51-
SECTOR_COUNT_KERNEL = 33
52-
SECTOR_START_APP_TTT = 60
53-
SECTOR_COUNT_APP_TTT = 25
54-
SECTOR_START_APP_CALC = 85
55-
SECTOR_COUNT_APP_CALC= 25
50+
SECTOR_START_KERNEL = 13
51+
SECTOR_COUNT_KERNEL = 34
52+
SECTOR_START_APP_TTT = 47
53+
SECTOR_COUNT_APP_TTT = 18
54+
SECTOR_START_APP_CALC = 65
55+
SECTOR_COUNT_APP_CALC= 18
5656

5757
MEMORY_STATIC_LIBRARY = 0x7E00
5858
MEMORY_LOCATION_KERNEL = 0xC000
@@ -64,7 +64,8 @@ SOURCE_SNAPSHOT="\"$$(git rev-parse --short HEAD)$$(git diff --quiet || echo '_u
6464
## Integer is 4 bytes
6565

6666
# Tools
67-
CC=gcc -std=c++11 -Os
67+
CC=gcc -std=c++11 -Os -nostartfiles -nostdlib -static
68+
LD=ld -nostdlib -nostartfiles -nodefaultlibs --print-map --strip-all
6869

6970
# Targets
7071
rebuild: clean all_artifacts
@@ -170,7 +171,7 @@ $(bt_stage2): $(SRC_BOOTLOADER)/stage2.asm $(SRC_BOOTLOADER)/stage2.c $(SRC_MEMM
170171
-D MEMORY_LOCATION_KERNEL=$(MEMORY_LOCATION_KERNEL) \
171172
-D MEMORY_LOCATION_APP=$(MEMORY_LOCATION_APP) \
172173
-o $(BUILD_BOOTLOADER)/stage2_c.o $(SRC_BOOTLOADER)/stage2.c
173-
ld --oformat binary -m elf_i386 -Ttext 0x8000 --strip-all -o $@ $(BUILD_BOOTLOADER)/stage2_asm.o $(BUILD_BOOTLOADER)/stage2_c.o $(BUILD_LIB_UTILS)/libutils_16 $(BUILD_DRIVERS)/display/libtm_bios $(BUILD_DRIVERS)/disk/libdisk_16
174+
$(LD) --oformat binary -m elf_i386 -Ttext 0x8000 -T linker.ld -o $@ $(BUILD_BOOTLOADER)/stage2_asm.o $(BUILD_BOOTLOADER)/stage2_c.o $(BUILD_LIB_UTILS)/libutils_16 $(BUILD_DRIVERS)/display/libtm_bios $(BUILD_DRIVERS)/disk/libdisk_16
174175
truncate --size=%512 $@
175176

176177
$(BUILD_REALMODE)/static_library: $(SRC_REALMODE)/static_library.asm $(SRC_REALMODE)/stub.asm
@@ -191,7 +192,7 @@ $(kernel_core): $(SRC_KERNEL)/core.asm $(SRC_KERNEL)/core.c $(SRC_KERNEL)/essent
191192
-D SECTOR_START_APP_CALC=$(SECTOR_START_APP_CALC) \
192193
-D SECTOR_COUNT_APP_CALC=$(SECTOR_COUNT_APP_CALC) \
193194
-o $(BUILD_KERNEL)/core_c.o $(SRC_KERNEL)/core.c
194-
ld --oformat binary -m elf_i386 --trace -Ttext 0x0000 --strip-all -o $(kernel_core) $(BUILD_KERNEL)/core_asm.o $(BUILD_KERNEL)/process_asm.o $(BUILD_KERNEL)/core_c.o $(BUILD_KERNEL)/interrupts_asm.o $(BUILD_DRIVERS)/keyboard/libkeyboard $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga $(BUILD_LIB_DS)/libds $(BUILD_DRIVERS)/disk/libdisk $(BUILD_LIB_SYSCALL)/libsyscall
195+
$(LD) --oformat binary -m elf_i386 -Ttext 0x0000 -T linker.ld -o $(kernel_core) $(BUILD_KERNEL)/core_asm.o $(BUILD_KERNEL)/process_asm.o $(BUILD_KERNEL)/core_c.o $(BUILD_KERNEL)/interrupts_asm.o $(BUILD_DRIVERS)/keyboard/libkeyboard $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga $(BUILD_LIB_DS)/libds $(BUILD_DRIVERS)/disk/libdisk $(BUILD_LIB_SYSCALL)/libsyscall
195196
truncate --size=%512 $(kernel_core)
196197

197198
# Libraries
@@ -274,11 +275,11 @@ $(BUILD_LIB_SYSCALL)/libsyscall: $(SRC_LIB_SYSCALL)/syscall.h $(SRC_LIB_SYSCALL)
274275
$(app_calc): $(app_entry) $(SRC_APP)/calc.c $(SRC_LIB_UTILS)/output.h $(SRC_LIB_UTILS)/time.h $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga $(BUILD_LIB_SYSCALL)/libsyscall # And dependecies :/
275276
mkdir -p $$(dirname $(app_calc))
276277
$(CC) -m32 -fno-pie -c -Isrc -o $(BUILD_APP)/calc.o $(SRC_APP)/calc.c
277-
ld --oformat binary -m elf_i386 -Ttext 0x0 --strip-all -o $@ $(app_entry) $(BUILD_APP)/calc.o $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga $(BUILD_LIB_SYSCALL)/libsyscall
278+
$(LD) --oformat binary -m elf_i386 -Ttext 0x0 -T linker.ld -o $@ $(app_entry) $(BUILD_APP)/calc.o $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga $(BUILD_LIB_SYSCALL)/libsyscall
278279
truncate --size=%512 $@
279280

280281
$(app_tic_tac_toe): $(app_entry) $(SRC_APP)/tic_tac_toe.c $(SRC_LIB_UTILS)/output.h $(SRC_LIB_UTILS)/input.h $(SRC_LIB_UTILS)/time.h $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga $(BUILD_LIB_SYSCALL)/libsyscall # And dependecies :/
281282
mkdir -p $$(dirname $(app_tic_tac_toe))
282283
$(CC) -m32 -fno-pie -c -Isrc -o $(BUILD_APP)/tic_tac_toe.o $(SRC_APP)/tic_tac_toe.c
283-
ld --oformat binary -m elf_i386 -Ttext 0x0 --strip-all -o $@ $(app_entry) $(BUILD_APP)/tic_tac_toe.o $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga $(BUILD_LIB_SYSCALL)/libsyscall
284+
$(LD) --oformat binary -m elf_i386 -Ttext 0x0 -T linker.ld -o $@ $(app_entry) $(BUILD_APP)/tic_tac_toe.o $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga $(BUILD_LIB_SYSCALL)/libsyscall
284285
truncate --size=%512 $@

linker.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SECTIONS
2+
{
3+
.text ALIGN(8) : { *(.text) }
4+
.data ALIGN(8) : { *(.data) *(.bss) }
5+
}

src/drivers/display/text_mode_vga.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ global _low_flush
5757
mov eax, 0x20
5858
mov es, eax ; Absolute memory address
5959

60-
mov esi,[ebp + 0x8] ; (buffer)
61-
mov cx, [ebp + 0xc] ; (count)
60+
mov esi, [ebp + 0x8] ; (buffer)
61+
mov ecx, [ebp + 0xc] ; (count)
6262
mov edi, 0xb8000
6363

6464
cld

src/kernel/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ void kernel_core_entry() {
2626
print_rectangle(0, 0, TEXT_WINDOW_WIDTH-1, TEXT_WINDOW_HEIGHT-1);
2727
print_log("Initializing Kernel");
2828

29+
2930
populate_and_load_idt_table();
3031

3132
kernel_core_entry_asm();
3233

3334
print_log("Kernel enabling interrupts");
35+
PANIC(501, "Early exiting kernel, development stage.");
36+
3437
kernel_enable_interrupts();
3538
keyboard_init();
3639

tests/kernel_core_entry_test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ test_screen_content $LINENO "Initializing Kernel"
1313
test_screen_content $LINENO "Registering syscalls"
1414
test_screen_content $LINENO "Loading IDT Table"
1515

16-
1716
wait ${QEMU_PID:?}
1817
echo "$0 passed!!!"

0 commit comments

Comments
 (0)