1
0
Fork 0
mirror of https://github.com/tailix/loadwarka.git synced 2024-11-11 13:50:54 -05:00

Move common defines to header

This commit is contained in:
Alex Kotov 2022-01-27 04:03:47 +05:00
parent 8d23cec33b
commit dc5e6be490
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 29 additions and 19 deletions

16
src/x86_common.h Normal file
View file

@ -0,0 +1,16 @@
#define STACK_BASE 0x2000
#define STAGE1_BASE 0x7c00
#define STAGE2_BASE 0x7e00
#define DIST(x) (x - _start)
#define STAGE1_ADDR(x) (DIST(x) + STAGE1_BASE)
#define STAGE2_ADDR(x) (DIST(x) + STAGE2_BASE)
#define STAGE1_START \
_start: \
ljmp $0, $STAGE1_ADDR(main)
#define STAGE2_START \
_start: \
ljmp $0, $STAGE2_ADDR(main)

View file

@ -21,21 +21,16 @@
#include "config.h" #include "config.h"
#endif #endif
#define STACK_ADDR 0x2000 #include "x86_common.h"
#define STAGE1_ADDR 0x7c00
#define STAGE2_ADDR 0x7e00
#define ADDRESS(x) (x - _start + STAGE1_ADDR)
.code16 .code16
.global _start .global _start
.section .text .section .text
_start: STAGE1_START
ljmp $0, $ADDRESS(start)
disk: .byte 0 disk: .byte 0
start: main:
cli cli
xor %ax, %ax xor %ax, %ax
mov %ax, %ss mov %ax, %ss
@ -43,9 +38,9 @@ start:
mov %ax, %es mov %ax, %es
mov %ax, %fs mov %ax, %fs
mov %ax, %gs mov %ax, %gs
mov $STACK_ADDR, %sp mov $STACK_BASE, %sp
mov %dl, ADDRESS(disk) mov %dl, STAGE1_ADDR(disk)
mov $0x02, %ah mov $0x02, %ah
mov $1, %al /* Sectors count */ mov $1, %al /* Sectors count */
@ -53,10 +48,10 @@ start:
mov $0, %ch /* Cylinder */ mov $0, %ch /* Cylinder */
mov $0, %dh /* Head */ mov $0, %dh /* Head */
mov $2, %cl /* Cylinder and sector */ mov $2, %cl /* Cylinder and sector */
mov $STAGE2_ADDR, %bx /* Address */ mov $STAGE2_BASE, %bx /* Address */
int $0x13 int $0x13
ljmp $0, $STAGE2_ADDR ljmp $0, $STAGE2_BASE
hang: hang:
cli cli

View file

@ -21,22 +21,21 @@
#include "config.h" #include "config.h"
#endif #endif
#define ADDRESS(x) (x - _start + 0x7e00) #include "x86_common.h"
.code16 .code16
.global _start .global _start
.section .text .section .text
_start: STAGE2_START
ljmp $0, $ADDRESS(start)
hello: .string "Hello, World!\r\n" hello: .string "Hello, World!\r\n"
start: main:
mov $ADDRESS(hello), %si mov $STAGE2_ADDR(hello), %si
call print_str call print_str
mov $ADDRESS(hello), %si mov $STAGE2_ADDR(hello), %si
call print_str call print_str
mov $ADDRESS(hello), %si mov $STAGE2_ADDR(hello), %si
call print_str call print_str
hang: hang: