Skip to content

Commit

Permalink
Fix some warnings in the decompressor and do not use special symbol m…
Browse files Browse the repository at this point in the history
…ain() for entry points
  • Loading branch information
mintsuki committed Sep 18, 2020
1 parent 8410abb commit 6591a9c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 38 deletions.
8 changes: 6 additions & 2 deletions decompressor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ OBJCOPY = i386-elf-objcopy
CFLAGS = -flto -Os -pipe -Wall -Wextra

INTERNAL_CFLAGS = \
-std=gnu99 \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-pic \
Expand All @@ -32,7 +32,8 @@ INTERNAL_LDFLAGS = \
.PHONY: all clean

C_FILES := $(shell find ./ -type f -name '*.c' | sort)
OBJ := $(C_FILES:.c=.o)
ASM_FILES := $(shell find ./ -type f -name '*.asm' | sort)
OBJ := $(ASM_FILES:.asm=.o) $(C_FILES:.c=.o)

all: decompressor.bin

Expand All @@ -43,5 +44,8 @@ decompressor.bin: $(OBJ)
%.o: %.c
$(CC) $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@

%.o: %.asm
nasm $< -f elf32 -o $@

clean:
rm -f decompressor.bin decompressor.elf $(OBJ)
18 changes: 18 additions & 0 deletions decompressor/entry.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extern bss_begin
extern bss_end
extern entry

section .entry

global _start
_start:
cld

; Zero out .bss
xor al, al
mov edi, bss_begin
mov ecx, bss_end
sub ecx, bss_begin
rep stosb

jmp entry
2 changes: 1 addition & 1 deletion decompressor/linker.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
OUTPUT_FORMAT(elf32-i386)
ENTRY(main)
ENTRY(_start)

SECTIONS
{
Expand Down
20 changes: 2 additions & 18 deletions decompressor/main.c
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
asm (
".section .entry\n\t"

"cld\n\t"

// Zero out .bss
"xor al, al\n\t"
"mov edi, OFFSET bss_begin\n\t"
"mov ecx, OFFSET bss_end\n\t"
"sub ecx, OFFSET bss_begin\n\t"
"rep stosb\n\t"

"mov ebx, OFFSET main\n\t"
"jmp ebx\n\t"
);

#include <stdint.h>
#include <stddef.h>
#include <gzip/tinf.h>

__attribute__((noreturn))
void main(uint8_t *compressed_stage2, size_t stage2_size, uint8_t boot_drive) {
void entry(uint8_t *compressed_stage2, size_t stage2_size, uint8_t boot_drive) {
// The decompressor should decompress compressed_stage2 to address 0x4000.
volatile uint8_t *dest = (volatile uint8_t *)0x4000;
uint8_t *dest = (uint8_t *)0x4000;

tinf_gzip_uncompress(dest, compressed_stage2, stage2_size);

Expand Down
Binary file modified limine.bin
Binary file not shown.
18 changes: 18 additions & 0 deletions stage2/entry.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extern bss_begin
extern bss_end
extern entry

section .entry

global _start
_start:
cld

; Zero out .bss
xor al, al
mov edi, bss_begin
mov ecx, bss_end
sub ecx, bss_begin
rep stosb

jmp entry
2 changes: 1 addition & 1 deletion stage2/linker.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
OUTPUT_FORMAT(elf32-i386)
ENTRY(main)
ENTRY(_start)

SECTIONS
{
Expand Down
17 changes: 1 addition & 16 deletions stage2/main.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
asm (
".section .entry\n\t"

"cld\n\t"

// Zero out .bss
"xor al, al\n\t"
"mov edi, OFFSET bss_begin\n\t"
"mov ecx, OFFSET bss_end\n\t"
"sub ecx, OFFSET bss_begin\n\t"
"rep stosb\n\t"

"jmp main\n\t"
);

#include <limine.h>
#include <lib/term.h>
#include <lib/real.h>
Expand All @@ -31,7 +16,7 @@ asm (
#include <protos/chainload.h>
#include <menu.h>

void main(int boot_drive) {
void entry(int boot_drive) {
term_textmode();

print("Limine " LIMINE_VERSION "\n\n");
Expand Down

0 comments on commit 6591a9c

Please sign in to comment.