From aff8076b22d2b87498ffd878fe71b8bb2bae3c94 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 27 Jan 2022 02:46:30 +0500 Subject: [PATCH] Use C preprocessor --- build.sh | 4 ++-- src/x86_stage1.S | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index d2a18da..e0d506f 100755 --- a/build.sh +++ b/build.sh @@ -5,8 +5,8 @@ set -e BIN='../cross/root/bin' CROSS="$BIN/i386-elf-" -${CROSS}as -c src/x86_stage1.S -o src/x86_stage1.o -${CROSS}as -c src/x86_stage2.S -o src/x86_stage2.o +${CROSS}gcc -c src/x86_stage1.S -o src/x86_stage1.o +${CROSS}gcc -c src/x86_stage2.S -o src/x86_stage2.o ${CROSS}ld -Ttext 200000 --oformat binary -o src/x86_stage1.bin src/x86_stage1.o ${CROSS}ld -Ttext 200000 --oformat binary -o src/x86_stage2.bin src/x86_stage2.o ./testyboot mbr mbr.bin src/x86_stage1.bin diff --git a/src/x86_stage1.S b/src/x86_stage1.S index cbcfb3f..0d090f5 100644 --- a/src/x86_stage1.S +++ b/src/x86_stage1.S @@ -1,11 +1,18 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif + +#define STACK_ADDR 0x2000 +#define STAGE1_ADDR 0x7c00 +#define STAGE2_ADDR 0x7e00 + +#define ADDRESS(x) (x - _start + STAGE1_ADDR) + .code16 .global _start .section .text _start: - ljmp $0, $(start - _start + 0x7c00) + ljmp $0, $ADDRESS(start) disk: .byte 0 @@ -18,9 +25,9 @@ start: mov %ax, %es mov %ax, %fs mov %ax, %gs - mov $0x2000, %sp + mov $STACK_ADDR, %sp - mov %dl, (disk - _start + 0x7c00) + mov %dl, ADDRESS(disk) mov $0x02, %ah mov $1, %al /* Sectors count */ @@ -75,7 +82,7 @@ start: mov $'\n', %al int $0x10 - ljmp $0, $0x7e00 + ljmp $0, $STAGE2_ADDR hang: cli