From 64a74b4e096eb4c7f2095c8df12407efbf6977d2 Mon Sep 17 00:00:00 2001 From: Tee-Kiah Chia Date: Fri, 19 Mar 2021 13:36:24 +0000 Subject: [PATCH] Add .seek asm pseudo-op, advances location counter to fixed offset The new .seek assembler pseudo-op advances the location counter to a fixed offset within a section --- or to a fixed address, if the section is a .base'd section. It works somewhat like the GNU assembler's .org pseudo-op, though with a hopefully less confusing name. This pseudo-op lets us avoid having to manually compute the needed boot sector padding in the pc86 start-up code plat/pc86/boot.s . --- mach/proto/as/comm0.h | 1 + mach/proto/as/comm2.y | 11 +++++++++++ mach/proto/as/comm3.c | 1 + mach/proto/as/comm6.c | 2 ++ plat/pc86/boot.s | 15 +-------------- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/mach/proto/as/comm0.h b/mach/proto/as/comm0.h index 5ef226be6..e2f42a311 100644 --- a/mach/proto/as/comm0.h +++ b/mach/proto/as/comm0.h @@ -226,6 +226,7 @@ typedef struct sect_t sect_t; /* s_flag bits: */ #define BASED 1 /* at fixed position */ +#define SOUGHT 2 /* did a .seek in the section */ /* sflag bits: */ #define SYM_EXT 001 /* external symbols */ diff --git a/mach/proto/as/comm2.y b/mach/proto/as/comm2.y index 83d74f5fc..b6e809b9f 100644 --- a/mach/proto/as/comm2.y +++ b/mach/proto/as/comm2.y @@ -59,6 +59,7 @@ static item_t *last_it, *o_it; %token ALIGN %token ASSERT %token SPACE +%token SEEK %token LINE %token FILe %token LIST @@ -252,6 +253,16 @@ operation DOTVAL += $2; DOTSCT->s_zero += $2; } + | SEEK absexp + { if (DOTSCT == NULL) + nosect(); + if ($2 < DOTVAL) + serror("cannot move location counter backwards"); + if (pass == PASS_1) + DOTSCT->s_flag |= SOUGHT; + DOTSCT->s_zero += $2 - DOTVAL; + DOTVAL = $2; + } | DATA datalist | DATA8 data8list | DATAF dataflist diff --git a/mach/proto/as/comm3.c b/mach/proto/as/comm3.c index f45aa723c..d53ac224e 100644 --- a/mach/proto/as/comm3.c +++ b/mach/proto/as/comm3.c @@ -37,6 +37,7 @@ item_t keytab[] = { {0, ALIGN, 0, ".align"}, {0, ASSERT, 0, ".assert"}, {0, SPACE, 0, ".space"}, + {0, SEEK, 0, ".seek"}, {0, COMMON, 0, ".comm"}, {0, SECTION, 0, ".sect"}, {0, BASE, 0, ".base"}, diff --git a/mach/proto/as/comm6.c b/mach/proto/as/comm6.c index 404e08742..1d917fdb8 100644 --- a/mach/proto/as/comm6.c +++ b/mach/proto/as/comm6.c @@ -142,6 +142,8 @@ newbase(valu_t base) nosect(); if (sp->s_flag & BASED) serror("already based"); + if (sp->s_flag & SOUGHT) + serror("cannot rebase section after a seek"); sp->s_base = base; sp->s_flag |= BASED; DOTVAL += base; diff --git a/plat/pc86/boot.s b/plat/pc86/boot.s index 51b288e75..6c0962a08 100644 --- a/plat/pc86/boot.s +++ b/plat/pc86/boot.s @@ -12,19 +12,6 @@ .sect .text -! ****** WARNING! ****** -! -! The PC boot sector requires a magic number at the end to signify that the -! disk is bootable. Unfortunately, the ACK assembler is a bit simple and we -! can't tell it to put the 0xAA55 at a particular address without writing our -! own custom binary generator. As a result, we need to manually insert just -! the right amount of padding in order to make this work. -! -! If you ever need to change the boot code, this needs adjusting. I recommend -! a hex editor. - -PADDING = 0xB3 - ! Some definitions. BOOT_SEGMENT = 0x07C0 ! Where we've been loaded @@ -317,7 +304,7 @@ exename: .asciz 'pc86.img' ! ...and we need this to fool the PC into booting our boot sector. - .space PADDING + .seek 0x1FE .data2 0xAA55 ! Define symbols at the beginning of our various segments, so that we can find