i have the following piece of code, which does not work (anymore). I remember that it already worked a few months ago. Maybe this is an compiler issue?
Im working on a little operating system. Just for understanding how it works in detail. And i wanted to start using C, as it is more readable than assembler.
My C code in question is:
#ifndef _CODE16GCC_H_
#define _CODE16GCC_H_
asm(".code16gcc\n");
#endif
#define VIDEO_MEM 0xB8000
#define WIDTH 80
#define HEIGHT 25
asm("call main\n");
asm("xor %eax, %eax\n");
asm("xor %ebx, %ebx\n");
asm("int $0x21\n");
void main(void)
{
unsigned char* mem = (unsigned char*)VIDEO_MEM;
for(int x = 0; x < 80; x++)
{
for(int y = 0; y < 25; y++)
{
*mem = 'A';
mem++;
*mem = 0x07;
mem++;
}
}
asm("xor %ax, %ax;int $0x16;");
}
I compile it with:
gcc -m32 -Os -march=i686 -ffreestanding -fno-stack-protector -Wall -Werror print.c -o print.o
and link using:
ld -m elf_i386 -static -Tlinker.ld -nostdlib --nmagic print.o -o print.elf
and create a binary by using:
objcopy -O binary print.elf -o print.bin
(Thats basically from a makefile we used in the university to write a little bootloader)
My problem now is, that the produced assembly code seems to be wrong:
objdump -d -M intel print.o
yields:
print.o: file format elf32-i386
Disassembly of section .text:
00000000 <.text>:
0: 66 e8 fc ff callw 0 <.text>
4: ff (bad)
5: ff 66 31 jmp DWORD PTR [esi+0x31]
8: c0 66 31 db shl BYTE PTR [esi+0x31],0xdb
c: cd 21 int 0x21
Disassembly of section .text.startup:
00000000 <main>:
0: 66 ba 00 80 mov dx,0x8000
4: 0b 00 or eax,DWORD PTR [eax]
6: 66 31 c0 xor ax,ax
9: 67 c6 04 42 mov BYTE PTR [si],0x42
d: 41 inc ecx
e: 67 c6 44 42 01 mov BYTE PTR [si+0x42],0x1
13: 07 pop es
14: 66 40 inc ax
16: 66 83 f8 19 cmp ax,0x19
1a: 75 ed jne 9 <main+0x9>
1c: 66 83 c2 32 add dx,0x32
20: 66 81 fa a0 8f cmp dx,0x8fa0
25: 0b 00 or eax,DWORD PTR [eax]
27: 75 dd jne 6 <main+0x6>
29: 31 c0 xor eax,eax
2b: cd 16 int 0x16
2d: 66 c3 retw
The main function itself looks good to me. But what is going on in the very first section? The part i wrote using inline assembly. Its just random instructions and even a (bad) bit.
I know for sure, that this used to work. But what am i missing now? Is this an issue of GCC 8.2.1? Or is my code just incorrect?
I appreciate any help!