Use C preprocessor

This commit is contained in:
Alex Kotov 2022-01-27 02:46:30 +05:00
parent d103eb0c6c
commit aff8076b22
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 13 additions and 6 deletions

View File

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

View File

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