I have finally gotten my code to compile. Now Im trying to run it in bochs. I have created a image of my kernel.
When I run it in bochs, it loads but nothings outputted to the screen. If I look at the bochsout.txt file, it shows that it halts at the point where I want it to in my code. So I know the code works, its just that theres nothing on the screen.
What could be the problem? Before I moved to cygwin, it was working fine.
Code issue with bochs
Re:Code issue with bochs
this wont really help, but i found objcopy doing strange things when i was using it.
in the end, i let it just output my kernel as a PE, and embed a grub header in it that skips the PE header.
this is my link flags
and this being my startup
and by making my startup.asm the first file in the link order, the grub header fits within the 8k requirement offset, and grub loads it perfectly! no flat binary image needed.
in the end, i let it just output my kernel as a PE, and embed a grub header in it that skips the PE header.
this is my link flags
Code: Select all
LDFLAGS = --oformat pei-i386 -Ttext 0x100000 --file-alignment 0x1000 --section-alignment 0x1000 -Tstage1.ld -Map map.txt
Code: Select all
%define d dword
%define w word
%define b byte
[bits 32]
[section .text]
global start
global _main
extern code
extern edata
extern eend
extern _hi_mem_start
extern _stage1_main
start:
lgdt [start_gdt]
jmp dword 8:lgdt_fixup
alignb 4, db 0x0
lgdt_fixup:
mov edx, 0x10
mov ds,dx
mov es,dx
mov fs,dx
mov gs,dx
mov ss,dx
mov [0x600],eax
mov [0x604],ebx
mov esp,0x10000-4
mov ebp,esp
push dword 0
popfl
xor eax,eax
mov edi,edata
mov ecx,eend
sub ecx,edi
push ecx
shr ecx,2
rep stosd
pop ecx
and ecx,0x3
rep stosb
add edi,0xFFF
and edi,0xFFFFF000
; end of memory, now take 8kb for init stack
add edi,8192
mov [_hi_mem_start],edi
; setup new esp
lea esp,[edi-4]
jmp _stage1_main
alignb 4, db 0x0
start_gdt:
dw 23
dd start_gdt
dw 0
dd 0x0000ffff
dd 0x00CF9A00
dd 0x0000ffff
dd 0x00CF9200
;//
;// put our GRUB bootloader header code here
;//
align 16, db 0x0
db "GRUB Multiboot",0
align 16, db 0x0
multiboot_header:
dd 0x1BADB002 ;## magic
dd 0x00010003 ;## flags[16]
dd 0-(0x1BADB002 + 0x00010003) ;## zero crc of fields 1+2
;; kludge offsets for binary or non-elf load points
dd multiboot_header
dd code
dd edata
dd eend
dd start
-- Stu --
Re:Code issue with bochs
The thing is Im using my own two-stage bootloader for loading my operating system. The first file loads into protected mode and loads my kernel to 1MB and is compiled to binary. For the time being, I have to compile it seperate from my makefile. The second file is the stub code that loads my C kernel. It is linked to win32 format and is combined with my c files.
My linker script is outputting "pei-i386 because of cygwin and is compiled and linked. The kernel_image is comiled to a .exe. I then use objcopy to convert it to a binary file. I then make a image out of the two files using makeboot. "makeboot ibox.img bootpm.bin kernel.bin"
When I run it in bochs, it loads but nothings outputted to the screen. I wonder if my stub that gets loaded at the begining is somehow being overwritten. How would I check this?
Any help would be appreciated,
My linker script is outputting "pei-i386 because of cygwin and is compiled and linked. The kernel_image is comiled to a .exe. I then use objcopy to convert it to a binary file. I then make a image out of the two files using makeboot. "makeboot ibox.img bootpm.bin kernel.bin"
When I run it in bochs, it loads but nothings outputted to the screen. I wonder if my stub that gets loaded at the begining is somehow being overwritten. How would I check this?
Any help would be appreciated,
Re:Code issue with bochs
maybe some variable is not being cleared in memory on start or something? id do a disassemble of your object after the objcopy to flat binary and see if your getting the correct offsets.
i dont really trust objcopy very much at all.
i dont really trust objcopy very much at all.
-- Stu --
Re:Code issue with bochs
My version of objdump doesnt support binary, but I was able to make a object with coverting to elf.
After looking at the disassembled code, I have noticed that __main is getting called and not _main. My linker was complaining about a undefined reference error with __main.
So I added this line of code to my kernel and it compiled and converted to elf fine.
I have attached the dissabled output of the __main and _main sections from my kernel. Hope this helps. How do I fix this?
[attachment deleted by admin]
After looking at the disassembled code, I have noticed that __main is getting called and not _main. My linker was complaining about a undefined reference error with __main.
So I added this line of code to my kernel and it compiled and converted to elf fine.
Code: Select all
int __main(void) { return 0; }
[attachment deleted by admin]
Re:Code issue with bochs
well, run ndisasmw over your binary kernel. or set your start in the linker -e startfunc...
-- Stu --
Re:Code issue with bochs
Adding a multiboot header to my code and loading it with grub worked just like you said it would DF. I wonder what could be wrong. Maybe after a few tests, I'll have the answer