From fd104c0a6ce881990b9a26d6441386eef9cc4209 Mon Sep 17 00:00:00 2001 From: "E. C. Masloch" Date: Wed, 22 Apr 2026 21:00:15 +0200 Subject: [PATCH] add Intel syntax alternatives to all gcc inline assembly --- hdr/portab.h | 4 ++-- kernel/chario.c | 2 +- kernel/inthndlr.c | 2 +- kernel/main.c | 2 +- kernel/prf.c | 4 ++-- sys/sys.c | 21 ++++++++++++++++++--- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/hdr/portab.h b/hdr/portab.h index bc79aed5..6f2ed46d 100644 --- a/hdr/portab.h +++ b/hdr/portab.h @@ -162,7 +162,7 @@ static inline void enable(void) static inline unsigned short getCS(void) { unsigned short ret; - asm volatile("mov %%cs, %0" : "=r"(ret)); + asm volatile("{ mov %%cs, %0 | mov %0, cs }" : "=r"(ret)); return ret; } @@ -170,7 +170,7 @@ static inline unsigned short getCS(void) static inline unsigned short getSS(void) { unsigned short ret; - asm volatile("mov %%ss, %0" : "=r"(ret)); + asm volatile("{ mov %%ss, %0 | mov %0, ss }" : "=r"(ret)); return ret; } extern char DosDataSeg[]; diff --git a/kernel/chario.c b/kernel/chario.c index 4041f962..1a3e212b 100644 --- a/kernel/chario.c +++ b/kernel/chario.c @@ -152,7 +152,7 @@ STATIC void fast_put_char(unsigned char chr) _AL = chr; __int__(0x29); #elif defined(__GNUC__) - asm volatile("int $0x29":: "a"(chr):"bx"); + asm volatile("{ int $0x29 | int 0x29 }":: "a"(chr):"bx"); #elif defined(I86) asm { diff --git a/kernel/inthndlr.c b/kernel/inthndlr.c index 46422c82..36d908b3 100644 --- a/kernel/inthndlr.c +++ b/kernel/inthndlr.c @@ -178,7 +178,7 @@ VOID ASMCFUNC int21_syscall(iregs FAR * irp) #if !defined __GNUC__ || defined __IA16_FEATURE_ATTRIBUTE_NO_ASSUME_SS_DATA irp->DX = FP_SEG(os_release); #else /* TODO: remove this hacky SS != DGROUP workaround --tkchia 20191207 */ - asm volatile("movw %%ds, %0" : "=g" (irp->DX)); + asm volatile("{ movw %%ds, %0 | mov %0, ds }" : "=g" (irp->DX)); #endif irp->AX = FP_OFF(os_release); } diff --git a/kernel/main.c b/kernel/main.c index 33e78419..123d3e23 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -840,7 +840,7 @@ STATIC void CheckContinueBootFromHarddisk(void) { #if __GNUC__ - asm volatile("jmp $0,$0x7c00"); + asm volatile("{ jmp $0,$0x7c00 | jmp 0,0x7c00 }"::); #else void (far *reboot)(void) = (void (far*)(void)) MK_FP(0x0,0x7c00); diff --git a/kernel/prf.c b/kernel/prf.c index baa01f0e..24703680 100644 --- a/kernel/prf.c +++ b/kernel/prf.c @@ -75,7 +75,7 @@ void put_console(int c) __int__(0xe6); #elif defined(__GNUC__) asm volatile( - "int $0xe6\n" + "{ int $0xe6 | int 0xe6 }" : /* outputs */ : /* inputs */ "a"(0x13), "e"(FP_SEG(buff)), "d"(FP_OFF(buff)) ); @@ -126,7 +126,7 @@ void put_console(int c) fastComPrint(c); #endif #elif defined(__GNUC__) - asm volatile("int $0x29" : : "a"(c) : "bx"); + asm volatile("{ int $0x29 | int 0x29 }" : : "a"(c) : "bx"); #elif defined(I86) __asm { diff --git a/sys/sys.c b/sys/sys.c index 6e79b2da..943b9a53 100644 --- a/sys/sys.c +++ b/sys/sys.c @@ -108,14 +108,25 @@ struct _diskfree_t { int int86x(int ivec, union REGS *in, union REGS *out, struct SREGS *s) { /* must save sp for int25/26 */ - asm("mov %7, %%cs:(1f+1); jmp 0f; 0:" + asm("{" + "mov %7, %%cs:(1f+1); jmp 0f; 0:" "mov %%di, %%dx; mov %%sp, %%di;" "push %%di; push %%di;" /* push twice to work both for int 25h/26h and int 21h */ "1:int $0x00; pop %%di; pop %%di;" /* second pop always reads the correct SP value. the first pop may read the FL left on stack. */ - "mov %%di, %%sp; sbb %0, %0" : + "mov %%di, %%sp; sbb %0, %0;" + " | " + "mov byte ptr cs:[1f+1], %7; jmp 0f; 0:" + "mov dx, di; mov di, sp;" + "push di; push di;" + /* push twice to work both for int 25h/26h and int 21h */ + "1:int 0x00; pop di; pop di;" + /* second pop always reads the correct SP value. + the first pop may read the FL left on stack. */ + "mov sp, di; sbb %0, %0;" + "}" : "=r"(out->x.cflag), "=a"(out->x.ax), "=b"(out->x.bx), "=c"(out->x.cx), "=d"(out->x.dx), "=e"(s->es), "=Rds"(s->ds) : @@ -140,7 +151,11 @@ int intdos(union REGS *in, union REGS *out) int intdosx(union REGS *in, union REGS *out, struct SREGS *s) { - asm("push %%ds; mov %%bx, %%ds; int $0x21; pop %%ds; sbb %0, %0": + asm("{" + "push %%ds; mov %%bx, %%ds; int $0x21; pop %%ds; sbb %0, %0\n" + " | " + "push ds; mov ds, bx; int 0x21; pop ds; sbb %0, %0\n" + "}" : "=r"(out->x.cflag), "=a"(out->x.ax) : "a"(in->x.ax), "c"(in->x.cx), "d"(in->x.dx), "D"(in->x.di), "S"(in->x.si), "b"(s->ds), "e"(s->es) :