aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNic Gaffney <gaffney_nic@protonmail.com>2023-11-06 02:00:07 -0600
committerNic Gaffney <gaffney_nic@protonmail.com>2023-11-06 02:00:07 -0600
commite14a65df735ce1b00533c73533ce91f8e591ea68 (patch)
tree6105dc57bbbdd88b6c6b1cec5da87e930cdd9dc8
parent036398ab051f2df5b70303e03f4f6506d36cb6eb (diff)
downloadgftos-e14a65df735ce1b00533c73533ce91f8e591ea68.tar.gz
global constructors
-rw-r--r--Makefile25
-rw-r--r--src/header/crti.s12
-rw-r--r--src/header/crtn.s7
-rw-r--r--src/kernel/kernel.c2
-rw-r--r--src/kernel/print.c8
5 files changed, 40 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index a64980d..258638f 100644
--- a/Makefile
+++ b/Makefile
@@ -22,11 +22,19 @@ LINK_FILE = linker.ld
LDFLAGS = -O2 -nostdlib -lgcc -ffreestanding
OBJS =
-C_OBJS := $(C:$(SRC)/%.c=$(BUILD)/C/%.o)
-ASM_OBJS := $(ASM:$(SRC)/%.s=$(BUILD)/ASM/%.o)
+C_OBJS := $(C:$(SRC)/%.c=$(BUILD)/%.o)
+ASM_OBJS := $(ASM:$(SRC)/%.s=$(BUILD)/%.o)
-OBJS += $(C_OBJS)
-OBJS += $(ASM_OBJS)
+CRTBEGIN_OBJ := $(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o)
+CRTEND_OBJ := $(shell $(CC) $(CFLAGS) -print-file-name=crtend.o)
+CRTI_OBJ = $(BUILD)/header/crti.o
+CRTN_OBJ = $(BUILD)/header/crtn.o
+
+OBJS += $(CRTI_OBJ) $(CRTBEGIN_OBJ)
+OBJS += $(C_OBJS) $(ASM_OBJS)
+OBJS += $(CRTEND_OBJ) $(CRTN_OBJ)
+
+INTERNAL_OBJS = $(CRTI_OBJ) $(ASM_OBJS) $(C_OBJS) $(CRTN_OBJ)
DEPS := $(OBJS:.o=.d)
.PHONY: all
@@ -42,19 +50,18 @@ $(OUT_DIR)/$(ISO).iso : $(OUT_DIR)/isodir/boot/$(ISO).bin
$(OUT_DIR)/isodir/boot/$(ISO).bin : $(OBJS)
$(CC) -T $(SRC)/$(LINK_FILE) -o $@ $(LDFLAGS) $^
-$(BUILD)/ASM/%.o: $(SRC)/%.s
+$(BUILD)/%.o: $(SRC)/%.s
mkdir -p $(BUILD)
- mkdir -p $(BUILD)/ASM
mkdir -p $(@D)
$(ASSEMBLER) $^ -o $@
-$(BUILD)/C/%.o: $(SRC)/%.c
+$(BUILD)/%.o: $(SRC)/%.c
mkdir -p $(BUILD)
- mkdir -p $(BUILD)/C
mkdir -p $(@D)
$(CC) $(CFLAGS) -c $^ -o $@
+
clean:
- rm -rf $(BUILD)
+ rm -rf $(INTERNAL_OBJS)
rm -rf $(OUT_DIR)/$(ISO).iso
rm -rf $(OUT_DIR)/isodir/boot/$(ISO).bin
diff --git a/src/header/crti.s b/src/header/crti.s
new file mode 100644
index 0000000..91e86fa
--- /dev/null
+++ b/src/header/crti.s
@@ -0,0 +1,12 @@
+.section .init
+.global _init
+.type _init @function
+_init:
+ push %ebp
+ movl %esp, %ebp
+
+.section .fini
+.global _fini
+_fini:
+ push %ebp
+ movl %esp, %ebp
diff --git a/src/header/crtn.s b/src/header/crtn.s
new file mode 100644
index 0000000..4874122
--- /dev/null
+++ b/src/header/crtn.s
@@ -0,0 +1,7 @@
+.section .init
+ popl %ebp
+ ret
+
+.section .fini
+ popl %ebp
+ ret
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index 50da3c6..a47a0a7 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -17,5 +17,5 @@ void kernel_main(void) {
print_set_color(PRINT_COLOR_YELLOW, PRINT_COLOR_BLACK);
printf("printf\n\tint: %d\n\tstring: %s\n\tchar: %c\n\tpercent: "
"%%\n\tnothing: %n",
- 1287, "World! ", 't');
+ 99, "World! ", 't');
}
diff --git a/src/kernel/print.c b/src/kernel/print.c
index 35533cd..89f6722 100644
--- a/src/kernel/print.c
+++ b/src/kernel/print.c
@@ -24,8 +24,8 @@ uint8_t color = PRINT_COLOR_WHITE | PRINT_COLOR_BLACK << 4;
void clear_row(size_t row) {
// Define empty character
struct Char empty = (struct Char){
- character : ' ',
- color : color,
+ ' ',
+ color,
};
// For every col in row, set vmem to empty
@@ -82,8 +82,8 @@ void print_char(char character) {
// set video memeory to requested character
buffer[col + NUM_COLS * row] = (struct Char){
- character : (uint8_t)character,
- color : color,
+ (uint8_t)character,
+ color,
};
// iterate col