title: qemu: fatal: Trying to execute code outside RAM or ROM at 0xd08ec08e
body: <p>I have a function written in C that reads a character from the keyboard, and returns the pressed character.</p>
  
  <p><strong>kmain.c</strong></p>
  
  <pre><code>#include &lt;stdint.h&gt;
  
  char getch()
  {
     uint16_t inchar;
  
     __asm__ __volatile__ ("int $0x16\n\t"
                          : "=a"(inchar)
                          : "0"(0x0));
  
     return ((char)inchar);
  }
  
  
  void println(char *str)
  {
      while (*str) 
      {
          // AH=0x0e, AL=char to print, BH=page, BL=fg color
          __asm__ __volatile__ ("int $0x10"
                                :
                                : "a" ((0x0e&lt;&lt;8) | *str++),
                                  "b" (0x0000));
  
      }
  
  }
  
  
  void kernelmain()
  {
      println("Println called from C code");
      char c;
      c = getch();
      println(c);
  }
  </code></pre>
  
  <p><strong>boot.asm</strong></p>
  
  <pre><code>extern println
  extern kernelmain
  global start
  bits 16
  
  section .text
  start:
      xor ax, ax            
      mov ds, ax
      mov es, ax
      mov ss, ax
      mov esp, 0x7C00
      jmp 0x0000:setcs     
  setcs:
      cld                   
  
      push dword msg1
      call dword println
      ; If you use call instead of jmp, it gonna throw a nice error :)
      jmp kernelmain
      cli
      hlt ; halt the processor
  
  
  section .data
      msg1 db 'Println called from NASM code', 0x0A, 0x0D, 0
  </code></pre>
  
  <p>But when I want to print that obtained key, it throw this useless error:</p>
  
  <pre><code>qemu: fatal: Trying to execute code outside RAM or ROM at 0xd08ec08e
  
  EAX=00002d78 EBX=00000000 ECX=00000000 EDX=00000000
  ESI=00000000 EDI=00000000 EBP=d88ec031 ESP=00007c08
  EIP=d08ec08e EFL=00000206 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
  ES =0000 00000000 0000ffff 00009300
  CS =0000 00000000 0000ffff 00009b00
  SS =0000 00000000 0000ffff 00009300
  DS =0000 00000000 0000ffff 00009300
  FS =0000 00000000 0000ffff 00009300
  GS =0000 00000000 0000ffff 00009300
  LDT=0000 00000000 0000ffff 00008200
  TR =0000 00000000 0000ffff 00008b00
  GDT=     000f6c00 00000037
  IDT=     00000000 000003ff
  CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
  DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
  DR6=ffff0ff0 DR7=00000400
  CCS=00000004 CCD=0000fe9c CCO=EFLAGS
  EFER=0000000000000000
  FCW=037f FSW=0000 [ST=0] FTW=00 MXCSR=00001f80
  FPR0=0000000000000000 0000 FPR1=0000000000000000 0000
  FPR2=0000000000000000 0000 FPR3=0000000000000000 0000
  FPR4=0000000000000000 0000 FPR5=0000000000000000 0000
  FPR6=0000000000000000 0000 FPR7=0000000000000000 0000
  XMM00=00000000000000000000000000000000 XMM01=00000000000000000000000000000000
  XMM02=00000000000000000000000000000000 XMM03=00000000000000000000000000000000
  XMM04=00000000000000000000000000000000 XMM05=00000000000000000000000000000000
  XMM06=00000000000000000000000000000000 XMM07=00000000000000000000000000000000
  Aborted (core dumped)
  </code></pre>
  
  <p><strong>to compile kernel.bin:</strong></p>
  
  <pre><code>gcc -fno-PIC -ffreestanding -m16 -c kmain.c -o kmain.o
  nasm -f elf32 boot.asm -o boot.o
  ld -melf_i386 -T link.ld kmain.o boot.o -o kernel.elf
  objcopy -O binary kernel.elf kernel.bin
  qemu-system-i386 -fda kernel.bin
  </code></pre>
  
  <p>I found questions with this same error, but they didn't help me. Also, I know it would be better to compile this with OpenWatcom, but it's too complicated.</p>