Been looking into the syntax of asm now that gospel is over and got as far as this:
Code:
#include <inttypes.h>
#include <string.h>
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef intmax_t asm_registers_t[0x10];
volatile void bios(
asm_registers_t *dst,
uchar interrupt,
uchar ah,
uchar al
);
...
#include "bios.h"
#include <stdio.h>
int main() {
#if 0
printf( "%s\n", PRIxMAX );
#else
unsigned int i = 0;
asm_registers_t reg = {0};
bios(®,1u,0u,0u);
for ( i = 0; i < 0x10; ++i ) {
(void)printf(
"reg[%u] = %" PRIxMAX "\n",
i, reg[i]
);
}
#endif
}
int hex2CHAR( int val )
{
val &= 0xF;
if ( val < 10 )
return '0' + val;
return 'A' + val;
}
int hex2char( int val )
{
val &= 0xF;
if ( val < 10 )
return '0' + val;
return 'a' + val;
}
volatile void bios(
asm_registers_t *dst,
uchar interrupt,
uchar ah,
uchar al
)
{
volatile ushort *word = (ushort*)(&word);
(void)memset( dst, 0, sizeof(asm_registers_t) );
fprintf( stderr, "word = %p, %hx", word, *word );
for ( ; *word != 0xCD00; ++word );
++word; *word = 0xCD00 | (uchar)interrupt;
asm( "mov ah,%0" : "=r" (ah) );
asm( "mov al,%0" : "=r" (al) );
asm( "int 0x00" );
#if 0
asm( "mov %0,%r0" : "=m" ((*dst)[0]) );
asm( "mov %0,%r1" : "=m" ((*dst)[1]) );
asm( "mov %0,%r2" : "=m" ((*dst)[2]) );
asm( "mov %0,%r3" : "=m" ((*dst)[3]) );
asm( "mov %0,%r4" : "=m" ((*dst)[4]) );
asm( "mov %0,%r5" : "=m" ((*dst)[5]) );
asm( "mov %0,%r6" : "=m" ((*dst)[6]) );
asm( "mov %0,%r7" : "=m" ((*dst)[7]) );
asm( "mov %0,%r8" : "=m" ((*dst)[8]) );
asm( "mov %0,%r9" : "=m" ((*dst)[9]) );
asm( "mov %0,%r10" : "=m" ((*dst)[10]) );
asm( "mov %0,%r11" : "=m" ((*dst)[11]) );
asm( "mov %0,%r12" : "=m" ((*dst)[12]) );
asm( "mov %0,%r13" : "=m" ((*dst)[13]) );
asm( "mov %0,%r14" : "=m" ((*dst)[14]) );
asm( "mov %0,%r15" : "=m" ((*dst)[15]) );
#endif
*word = 0xCD00;
}
But still no luck in getting it to compile
Edit: Forgot to mention the compiler error message:
Code:
bios.c:50: Error: operand size mismatch for `int'
Also forgot to add some details to those mov functions that copy all the registers, added but they still give me errors:
Code:
gcc -Wall -o bios bios.c -lpthread && ./bios
bios.c: In function ‘bios’:
bios.c:52:2: error: invalid 'asm': operand is not a specific integer, invalid operand code 'r'
52 | asm( "mov %0,%r0" : "=m" ((*dst)[0]) );
| ^~~
bios.c:53:2: error: invalid 'asm': operand number out of range
53 | asm( "mov %0,%r1" : "=m" ((*dst)[1]) );
| ^~~
bios.c:54:2: error: invalid 'asm': operand number out of range
54 | asm( "mov %0,%r2" : "=m" ((*dst)[2]) );
| ^~~
bios.c:55:2: error: invalid 'asm': operand number out of range
55 | asm( "mov %0,%r3" : "=m" ((*dst)[3]) );
| ^~~
bios.c:56:2: error: invalid 'asm': operand number out of range
56 | asm( "mov %0,%r4" : "=m" ((*dst)[4]) );
| ^~~
bios.c:57:2: error: invalid 'asm': operand number out of range
57 | asm( "mov %0,%r5" : "=m" ((*dst)[5]) );
| ^~~
bios.c:58:2: error: invalid 'asm': operand number out of range
58 | asm( "mov %0,%r6" : "=m" ((*dst)[6]) );
| ^~~
bios.c:59:2: error: invalid 'asm': operand number out of range
59 | asm( "mov %0,%r7" : "=m" ((*dst)[7]) );
| ^~~
bios.c:60:2: error: invalid 'asm': operand number out of range
60 | asm( "mov %0,%r8" : "=m" ((*dst)[8]) );
| ^~~
bios.c:61:2: error: invalid 'asm': operand number out of range
61 | asm( "mov %0,%r9" : "=m" ((*dst)[9]) );
| ^~~
bios.c:62:2: error: invalid 'asm': operand number out of range
62 | asm( "mov %0,%r10" : "=m" ((*dst)[10]) );
| ^~~
bios.c:63:2: error: invalid 'asm': operand number out of range
63 | asm( "mov %0,%r11" : "=m" ((*dst)[11]) );
| ^~~
bios.c:64:2: error: invalid 'asm': operand number out of range
64 | asm( "mov %0,%r12" : "=m" ((*dst)[12]) );
| ^~~
bios.c:65:2: error: invalid 'asm': operand number out of range
65 | asm( "mov %0,%r13" : "=m" ((*dst)[13]) );
| ^~~
bios.c:66:2: error: invalid 'asm': operand number out of range
66 | asm( "mov %0,%r14" : "=m" ((*dst)[14]) );
| ^~~
bios.c:67:2: error: invalid 'asm': operand number out of range
67 | asm( "mov %0,%r15" : "=m" ((*dst)[15]) );
| ^~~
Compilation failed.