1
.set MAGIC, 0x1badb002
.set FLAGS, (1<<0 | 1<<1)
.set CHECKSUM, -(MAGIC + FLAGS)

.multiboot
    .long MAGIC
    .long FLAGS
    .long CHECKSUM 

.text
.extern _kernelMain
.global loader

loader:
    mov $kernel_stack, %esp
    push %eax
    push %ebx
    call kernelMain

_stop:
    cli
    hlt
    jmp _stop

.bss
.space 2*1024*1024
kernel_stack: 

This is my code and it raises an error when ever I compile it says I have to add .section but when I do it raises a different error telling me to remove .section. How can I solve this?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Omer Ozhan
  • 63
  • 1
  • 5
  • 1
    what is the relation of this question to C++ programming language?!. – Adam Jun 15 '20 at 11:57
  • When you use `.section .multiboot` exactly what error message do you get? Is it an assembly error or a linker error. Knowing the exact error message would help to understand the problem – Michael Petch Jun 16 '20 at 16:07
  • It raises the linker error when I compile it with .section it raises linker error. When I do it without it it raises linker error. – Omer Ozhan Jun 17 '20 at 07:02
  • What is the exact error. Please copy and paste it into your question or a comment. – Michael Petch Jun 17 '20 at 13:30
  • loader.s:5:1: error: unknown directive .multiboot – Omer Ozhan Jun 18 '20 at 09:16
  • and error: unexpected token in '.section' directive .section .multiboot – Omer Ozhan Jun 18 '20 at 09:16
  • The problem is that you are using Apple's native toolchain and the GNU assembler (linker) and Compiler operate differently than yo are expecting. Apple's assembler requires at least a segment name and section name with the `.section` directive. So you could do something like `.section .multiboot, .multiboot` . But this is least of your concerns. The linker on MacOS doesn't support linker scripts and you can't even use `-T` to change the origin point. Because of that I highly recommend you install something like Homebrew or Macports and build an i686 or x86_64 cross compiler. – Michael Petch Jun 19 '20 at 13:30
  • Some info building cross compilers (including MacOS) can be found here: https://wiki.osdev.org/GCC_Cross-Compiler#macOS_Users . Although I haven't tried the instructions on a recent version of MacOS. – Michael Petch Jun 19 '20 at 13:31

0 Answers0