Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I'm very new to OS development. I've written a simple bootloader that does everything to get into protected mode (enable a20, set up gdt, etc.)(I haven't set up an IDT yet, though). I can get it to load and use the kernel entry point (which I can do whatever with), but including any C code at all kills it. Even just having something like
If you are calling main from assembler make sure that you are blocking after the call for when main returns (your kernel main() normally shouldn't return anyway)
ld: warning: i386 architecture of input file `start.o' is incompatible with i386:x86-64 output
I'm guessing the linker's the source of the problem here....
EDIT: The linker's almost definitely to blame. My start.asm file crashes when there's any C file linked to it, but runs perfectly fine if unlinked. No references between the programs are made at all.
Are you sure it links properly?
since start.asm should be linked first(assuming your using binary) you can have something at the first of your asm file like "db "I'm start.asm"
and then look in your hex editor to see if it is the first part of the file..
hckr83 wrote:Are you sure it links properly?
since start.asm should be linked first(assuming your using binary) you can have something at the first of your asm file like "db "I'm start.asm"
and then look in your hex editor to see if it is the first part of the file..
You're right. For whatever reason, the string shows up at the very end of the file.
To Solar: I do have a stack set up in the bootloader. Just in case, I tried setting it up again in start.asm, but it didn't do anything.
No, undefined reference to _main. GCC doesn't put underscores before function names, right? And the square brackets around "global start" didn't affect anything.
That's what I use to build the kernel. For now, I just want my kernel to be x86. Building everything on my x86 laptop eliminated the warning but not the problem.
gdt:
gdt_null:
dd 0
dd 0
gdt_cs:
dw 0xffff
dw 0
db 0
db 0x9a
db 0xcf
db 0
gdt_ds:
dw 0xffff
dw 0
db 0
db 0x92
db 0xcf
db 0
gdte:
descriptor:
dw gdte-gdt-1
dd gdt
There's the GDT, and here's the code that calls start:
That's what I use to build the kernel. For now, I just want my kernel to be x86. Building everything on my x86 laptop eliminated the warning but not the problem.
You're using your system compiler. Do you happen to have a 64-bit system setup?
If so, try our cross-compiler setup logic we have here to avoid loads of bogus "errors" that only occur because of setups that weren't meant to do OS dev. For an example, see the _main suggestion above. Cygwin GCC does prepend them by default, crosscompilers really should not (it was for compatibility with a language over 30 years ago).