Merge pull request #227 from tkchia/tkchia/sepid

Add .seek asm pseudo-op, advances location counter to fixed offset
This commit is contained in:
David Given 2021-03-20 19:05:14 +01:00 committed by GitHub
commit 3dcd16e0a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 17 deletions

View file

@ -226,6 +226,7 @@ typedef struct sect_t sect_t;
/* s_flag bits: */ /* s_flag bits: */
#define BASED 1 /* at fixed position */ #define BASED 1 /* at fixed position */
#define SOUGHT 2 /* did a .seek in the section */
/* sflag bits: */ /* sflag bits: */
#define SYM_EXT 001 /* external symbols */ #define SYM_EXT 001 /* external symbols */

View file

@ -59,6 +59,7 @@ static item_t *last_it, *o_it;
%token ALIGN %token ALIGN
%token ASSERT %token ASSERT
%token SPACE %token SPACE
%token SEEK
%token <y_word> LINE %token <y_word> LINE
%token FILe %token FILe
%token <y_word> LIST %token <y_word> LIST
@ -252,6 +253,16 @@ operation
DOTVAL += $2; DOTVAL += $2;
DOTSCT->s_zero += $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 | DATA datalist
| DATA8 data8list | DATA8 data8list
| DATAF dataflist | DATAF dataflist

View file

@ -37,6 +37,7 @@ item_t keytab[] = {
{0, ALIGN, 0, ".align"}, {0, ALIGN, 0, ".align"},
{0, ASSERT, 0, ".assert"}, {0, ASSERT, 0, ".assert"},
{0, SPACE, 0, ".space"}, {0, SPACE, 0, ".space"},
{0, SEEK, 0, ".seek"},
{0, COMMON, 0, ".comm"}, {0, COMMON, 0, ".comm"},
{0, SECTION, 0, ".sect"}, {0, SECTION, 0, ".sect"},
{0, BASE, 0, ".base"}, {0, BASE, 0, ".base"},

View file

@ -142,6 +142,8 @@ newbase(valu_t base)
nosect(); nosect();
if (sp->s_flag & BASED) if (sp->s_flag & BASED)
serror("already based"); serror("already based");
if (sp->s_flag & SOUGHT)
serror("cannot rebase section after a seek");
sp->s_base = base; sp->s_base = base;
sp->s_flag |= BASED; sp->s_flag |= BASED;
DOTVAL += base; DOTVAL += base;

View file

@ -234,6 +234,9 @@ The default is the word-size of the target machine.
.Pu ".space \fIexpression\fP" .Pu ".space \fIexpression\fP"
Allocate the indicated amount of bytes. Allocate the indicated amount of bytes.
The expression must be absolute. The expression must be absolute.
.Pu ".seek \fIexpression\fP"
Advance the current position to the value of the expression.
The expression must be absolute.
.Pu ".comm \fIname\fP,\fIexpression\fP" .Pu ".comm \fIname\fP,\fIexpression\fP"
Allocate the indicated amount of bytes and assign the location of the first Allocate the indicated amount of bytes and assign the location of the first
byte allocated to byte allocated to
@ -248,9 +251,8 @@ is extern, then assemblers leave definition of
to the linkeditor \fIled\fP(1). to the linkeditor \fIled\fP(1).
.Pu .sect \fIname\fP .Pu .sect \fIname\fP
section name definition. section name definition.
.Pu ".base \fIexpresssion\fP" .Pu ".base \fIexpression\fP"
Set the starting address of the first of the consecutive segments Set the starting address of the current section to the value of the expression.
(text) to the value of the expression.
The expression must be absolute. The expression must be absolute.
.Pu .assert \fIexpression\fP .Pu .assert \fIexpression\fP
assembly-time assertion checking. Stop with a fatal error message when assembly-time assertion checking. Stop with a fatal error message when

View file

@ -12,19 +12,6 @@
.sect .text .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. ! Some definitions.
BOOT_SEGMENT = 0x07C0 ! Where we've been loaded 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. ! ...and we need this to fool the PC into booting our boot sector.
.space PADDING .seek 0x1FE
.data2 0xAA55 .data2 0xAA55
! Define symbols at the beginning of our various segments, so that we can find ! Define symbols at the beginning of our various segments, so that we can find