AlgorithMan-de / wyoos

Source codes for the "Write your own Operating System" video-series on YouTube
http://wyoos.org
GNU General Public License v3.0
719 stars 222 forks source link

Invalid 'asm': invalid expression as operand #31

Closed wiltaylor closed 2 years ago

wiltaylor commented 2 years ago

I am getting the following error when trying to compile the code at the end of video 3.

g++ -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -o gdt.o -c gdt.cpp
gdt.cpp: In constructor ‘GlobalDescriptorTable::GlobalDescriptorTable()’:
gdt.cpp:13:5: error: invalid 'asm': invalid expression as operand
   13 |     asm volatile("lgdt (%0)": : "p" (((uint8_t *) i)+2));
      |     ^~~
make: *** [Makefile:8: gdt.o] Error 1

I have tried a number of things. Tried different versions of GCC (5 and 6 as well as 10.3.0). I have also tried both 32bit and 64bit versions of gcc.

M1sterPl0w commented 2 years ago

I am using the following version: "gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0" And it works well. My guess would be that you haven't installed GCC correctly.

What happens when use __asm__ instead asm these happens to be different. stackoverflow

__asm__ volatile("lgdt (%0)" : : "p"(((uint8_t *) i)+2));

wiltaylor commented 2 years ago

Thanks for the reply. It was indeed a bunch of missing packages. I added a few more to my development environment and was able to get it working.

Here is the nix flake with the working development environment.

{
  description = "Development Environment For OS tutorial";
  inputs = {
    nixpkgs.url = "nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs }:
  let
    pkgs = nixpkgs.legacyPackages.x86_64-linux;

  in {
    devShell.x86_64-linux = pkgs.pkgsi686Linux.mkShell {
      buildInputs = with pkgs; [
        gcc
        nasm
        gnumake
        valgrind
        inetutils
        grub2
        binutils
        xorriso
      ];

      shellHook = ''
        ${pkgs.figlet}/bin/figlet "OS Development Tutorial"     
      '';
    };
  };
}