Fix some warnings in the decompressor and do not use special symbol main() for entry points

This commit is contained in:
mintsuki 2020-09-18 22:15:27 +02:00
parent 8410abb3d9
commit 6591a9c32f
8 changed files with 47 additions and 38 deletions

View File

@ -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 \
@ -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
@ -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
decompressor/entry.asm Normal file
View File

@ -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

View File

@ -1,5 +1,5 @@
OUTPUT_FORMAT(elf32-i386)
ENTRY(main)
ENTRY(_start)
SECTIONS
{

View File

@ -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);

Binary file not shown.

18
stage2/entry.asm Normal file
View File

@ -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

View File

@ -1,5 +1,5 @@
OUTPUT_FORMAT(elf32-i386)
ENTRY(main)
ENTRY(_start)
SECTIONS
{

View File

@ -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>
@ -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");