MOV AX, 0x0000 doesn't work.
Re: MOV AX, 0x0000 doesn't work.
Could you post the entire floppy image?
- RGOS
- Member
- Posts: 38
- Joined: Sat Feb 13, 2010 10:52 am
- Location: Buurmalsen, The Netherlands
- Contact:
Re: MOV AX, 0x0000 doesn't work.
Hello,
Here's the floppy image, i'm trying to check with putting something on the screen now.
It's a .rar file, the .img was too big .
I'll post if I find anything.
Thanks.
Here's the floppy image, i'm trying to check with putting something on the screen now.
It's a .rar file, the .img was too big .
I'll post if I find anything.
Thanks.
- Attachments
-
- floppyimg.rar
- The complete floppy image with my OS so far.
- (905 Bytes) Downloaded 94 times
Program development: Think, think more and think again, then find the solution and code it.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
Re: MOV AX, 0x0000 doesn't work.
The file you posted doesn't have any code in it. It's just a FAT header and a bunch of 0's.
- RGOS
- Member
- Posts: 38
- Joined: Sat Feb 13, 2010 10:52 am
- Location: Buurmalsen, The Netherlands
- Contact:
Re: MOV AX, 0x0000 doesn't work.
Hello,
Sorry, something has to be gone wrong at rar-time , I did it again and now it has to be okay.
I also found out that the code (FindFile) runs about 103 times before the error that Bochs gave me.
I'm going to try and fix things, I'll post if I find anything.
Thanks.
Sorry, something has to be gone wrong at rar-time , I did it again and now it has to be okay.
I also found out that the code (FindFile) runs about 103 times before the error that Bochs gave me.
I'm going to try and fix things, I'll post if I find anything.
Thanks.
- Attachments
-
- floppyimg.rar
- The complete floppy-image.
- (19.5 KiB) Downloaded 93 times
Program development: Think, think more and think again, then find the solution and code it.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
Re: MOV AX, 0x0000 doesn't work.
I found the problem. The loading offset wraps to 0 and the code is overwritten. To fix this, add 32 to ES after loading a sector instead of adding 512 to BX.
- RGOS
- Member
- Posts: 38
- Joined: Sat Feb 13, 2010 10:52 am
- Location: Buurmalsen, The Netherlands
- Contact:
Re: MOV AX, 0x0000 doesn't work.
Hello,
Thanks for analyzing, but did you mean this?
I don't know if this is the place where you ment, but I'm a bit sleepy and I'll see tomorow morning if I understand more, I'm going to think about it tonight .
Thanks.
Thanks for analyzing, but did you mean this?
I don't know if this is the place where you ment, but I'm a bit sleepy and I'll see tomorow morning if I understand more, I'm going to think about it tonight .
Code: Select all
;add bx, cx
mov ax, es
add ax, 32
mov es, ax
Program development: Think, think more and think again, then find the solution and code it.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
Re: MOV AX, 0x0000 doesn't work.
Well, I was actually talking about this one inside ReadSectors:
pop cx
pop bx
pop ax
add bx, ds:word_811 <= this
inc ax
loop ReadSectors
Change to:
mov ax,es
add ax,32
mov es,ax
pop cx
pop bx
pop ax
inc ax
loop ReadSectors
But it will crash in MEMEM since it pushes a lot of things and then returns.
pop cx
pop bx
pop ax
add bx, ds:word_811 <= this
inc ax
loop ReadSectors
Change to:
mov ax,es
add ax,32
mov es,ax
pop cx
pop bx
pop ax
inc ax
loop ReadSectors
But it will crash in MEMEM since it pushes a lot of things and then returns.
- RGOS
- Member
- Posts: 38
- Joined: Sat Feb 13, 2010 10:52 am
- Location: Buurmalsen, The Netherlands
- Contact:
Re: MOV AX, 0x0000 doesn't work.
Hello,
Thanks, and that's more obvious, I now commented call LoadFile, and the 'OS' reported that the image was corrupted, because it didn't load the image. But this is after I had moved call MEMEM to the end, because some calls can only be made in protected mode, but probably it isn't going to work because of no interrupts in PMode, but that's a problem of the future. But when I make the change you suggested, I still get the error, and now MEMEM is at the end, and the error is thus in FindFile. I'm going to play a little with it and check if I can spot something.
Thanks.
Thanks, and that's more obvious, I now commented call LoadFile, and the 'OS' reported that the image was corrupted, because it didn't load the image. But this is after I had moved call MEMEM to the end, because some calls can only be made in protected mode, but probably it isn't going to work because of no interrupts in PMode, but that's a problem of the future. But when I make the change you suggested, I still get the error, and now MEMEM is at the end, and the error is thus in FindFile. I'm going to play a little with it and check if I can spot something.
Thanks.
Program development: Think, think more and think again, then find the solution and code it.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
- RGOS
- Member
- Posts: 38
- Joined: Sat Feb 13, 2010 10:52 am
- Location: Buurmalsen, The Netherlands
- Contact:
Re: MOV AX, 0x0000 doesn't work.
Hello,
I've played with it, and now it does the job, I've not changed to your solution, but I've added it. Now the next problem:
(The entire code is in the attachment).
The code excecutes untill a certain instruction (see comment), but then Bochs just resets, I've really no idea what the problem is, especially because when I comment a random instruction before the reset, the code excecutes one instruction further, and if I comment two instructions, then it excecutes two instructions further, so it looks like there are too many instruction. Do you know what the problem is? I'm going to check if I can see more.
The (I think) interresting part of the Bochs log:
Then I'm worried about:
and
Does anybody know what it means, and/or what I can do about it? Ican't seem to find out.
Thanks.
I've played with it, and now it does the job, I've not changed to your solution, but I've added it. Now the next problem:
Code: Select all
MEMEM:
pop ebx
mov [retip], ebx
mov eax, 'SOGR'
push eax
xor eax, eax
mov ax, 0x0
push ax
mov es, ax
mov ax, 0x1000
push ax
cli
hlt
mov di, ax
cli
hlt
xor ax, ax ;<=this instruction is executed normally
call BiosGetMemoryMap
jc err
push bp
jmp nerr
err:
mov bp, 0x0000
push bp
nerr:
call BiosGetMemorySize64MB_32Bit
push ax
push bx
call BiosGetMemorySize64MB
push ax
push bx
call BiosGetMemorySize
push ax
call BiosGetExtendedMemorySize
push ax
mov eax, 'RGOS'
push eax
xor eax, eax
mov ebx, [retip]
push ebx
ret
The code excecutes untill a certain instruction (see comment), but then Bochs just resets, I've really no idea what the problem is, especially because when I comment a random instruction before the reset, the code excecutes one instruction further, and if I comment two instructions, then it excecutes two instructions further, so it looks like there are too many instruction. Do you know what the problem is? I'm going to check if I can see more.
The (I think) interresting part of the Bochs log:
Code: Select all
00024458004i[PCI ] setting SMRAM control register to 0x4a
00024622098i[CPU0 ] Enter to System Management Mode
00024622108i[CPU0 ] RSM: Resuming from System Management Mode
00024786128i[PCI ] setting SMRAM control register to 0x0a
00024795297i[BIOS ] MP table addr=0x000fbb60 MPC table addr=0x000fba90 size=0xd0
00024797239i[BIOS ] SMBIOS table addr=0x000fbb70
00024799623i[BIOS ] ACPI tables: RSDP addr=0x000fbc80 ACPI DATA addr=0x01ff0000 size=0x988
00024802862i[BIOS ] Firmware waking vector 0x1ff00cc
00024813975i[PCI ] 440FX PMC write to PAM register 59 (TLB Flush)
00024814819i[BIOS ] bios_table_cur_addr: 0x000fbca4
00037008075i[BIOS ] Booting from 0000:7c00
00045932607e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0e)
00045932607e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
00045932607i[CPU0 ] CPU is in protected mode (active)
00045932607i[CPU0 ] CS.d_b = 32 bit
00045932607i[CPU0 ] SS.d_b = 32 bit
00045932607i[CPU0 ] EFER = 0x00000000
00045932607i[CPU0 ] | RAX=000000008e500000 RBX=0000000000100ae1
00045932607i[CPU0 ] | RCX=0000000000000007 RDX=0000000000000000
00045932607i[CPU0 ] | RSP=000000000008fff8 RBP=00000000004112fd
00045932607i[CPU0 ] | RSI=00000000001000e2 RDI=0000000000000abd
00045932607i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
00045932607i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
00045932607i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00045932607i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
00045932607i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf ZF af PF cf
00045932607i[CPU0 ] | SEG selector base limit G D
00045932607i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00045932607i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
00045932607i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00045932607i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00045932607i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00045932607i[CPU0 ] | FS:07c0( 0005| 0| 0) 00007c00 0000ffff 0 0
00045932607i[CPU0 ] | GS:07c0( 0005| 0| 0) 00007c00 0000ffff 0 0
00045932607i[CPU0 ] | MSR_FS_BASE:0000000000007c00
00045932607i[CPU0 ] | MSR_GS_BASE:0000000000007c00
00045932607i[CPU0 ] | RIP=000000000000068d (000000000000068d)
00045932607i[CPU0 ] | CR0=0xe0000011 CR2=0x0000000017a01000
00045932607i[CPU0 ] | CR3=0x0009c000 CR4=0x00000000
00045932607i[CPU0 ] 0x000000000000068d>> sar byte ptr ds:[eax+0x89501000], 0xc7 : C0B800105089C7
00045932607e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00045932607i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
00045932607i[CPU0 ] cpu hardware reset
00045932607i[APIC0] allocate APIC id=0 (MMIO enabled) to 0xfee00000
00045932607i[ ] reset of 'unmapped' plugin device by virtual method
00045932607i[ ] reset of 'biosdev' plugin device by virtual method
00045932607i[ ] reset of 'speaker' plugin device by virtual method
00045932607i[ ] reset of 'extfpuirq' plugin device by virtual method
00045932607i[ ] reset of 'gameport' plugin device by virtual method
00045932607i[ ] reset of 'pci_ide' plugin device by virtual method
00045932607i[ ] reset of 'acpi' plugin device by virtual method
00045932607i[ ] reset of 'ioapic' plugin device by virtual method
00045932607i[ ] reset of 'keyboard' plugin device by virtual method
00045932607i[ ] reset of 'harddrv' plugin device by virtual method
00045932607i[ ] reset of 'serial' plugin device by virtual method
00045932607i[ ] reset of 'parallel' plugin device by virtual method
Code: Select all
00037008075i[BIOS ] Booting from 0000:7c00
00045932607e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0e) <=this
00045932607e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08) <=and this
00045932607i[CPU0 ] CPU is in protected mode (active)
Code: Select all
00045932607i[CPU0 ] 0x000000000000068d>> sar byte ptr ds:[eax+0x89501000], 0xc7 : C0B800105089C7
00045932607e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting <=and ofcourse this
00045932607i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
Thanks.
- Attachments
-
- BochsLog.txt
- The complete Bochs log.
- (18.72 KiB) Downloaded 88 times
-
- code.rar
- The complete code except for the kernel self (so it's only the bootloader, and kernelloader).
- (5.07 KiB) Downloaded 120 times
-
- floppyimg.rar
- The current floppy image.
- (19.52 KiB) Downloaded 108 times
Program development: Think, think more and think again, then find the solution and code it.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: MOV AX, 0x0000 doesn't work.
You are, once again, executing garbage. Actually, it looks like you're halfway some other (16-bits?) instructions, since that opcode contains mov ax, 0x1000; push ax; mov di, ax; - try if you can find that sequence somewheresar byte ptr ds:[eax+0x89501000], 0xc7
- RGOS
- Member
- Posts: 38
- Joined: Sat Feb 13, 2010 10:52 am
- Location: Buurmalsen, The Netherlands
- Contact:
Re: MOV AX, 0x0000 doesn't work.
Hello,
Thanks for your reply, so probably I'm jumping to the wrong location:
So probably ebp doesn't contain the right address (of the kernel entry point), but I'm making the kernel in Visual C 2010, and the Brokenthorn series are using the 2005 version, is this maybe my problem? Checking the image is okay, because when I change the signature the 'OS' says that the image is corrupt. The problem must be here then. The kernel is a windows .exe file, so no flat binary, and I haven't really understood everything of the header so I don't know if there's the problem or if it's just a typo or something. I'm going to test again.
EDIT: VMWare gives me the error: *** Virtual machine kernel stack fault (hardware reset) ***
I don't know what if has to do with it, because probably I'm jumping to the wrong location but I think I'd post it maybe anyone can link it to each other.
Thanks.
Thanks for your reply, so probably I'm jumping to the wrong location:
Code: Select all
EXECUTE:
add ebx, 24
mov eax, [ebx]
add ebx, 20-4
mov ebp, dword [ebx]
add ebx, 12
mov eax, dword [ebx]
add ebp, eax
cli
call ebp
cli
hlt
EDIT: VMWare gives me the error: *** Virtual machine kernel stack fault (hardware reset) ***
I don't know what if has to do with it, because probably I'm jumping to the wrong location but I think I'd post it maybe anyone can link it to each other.
Thanks.
Program development: Think, think more and think again, then find the solution and code it.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
Re: MOV AX, 0x0000 doesn't work.
Not related to the bug, but you're unnecessarily repeating the loading of segment registers in the beginning. There's also a superfluous mov ax, 0x0000 instruction in both spots where ax is already 0. And there's this:
Which can be replaced with:
However, that doesn't quite work unless you link with /ALIGN:0x200 (or any power of 2 between the largest section alignment and 0x800) and /DRIVER. To load a non-flat image correctly, you must go through all the sections and copy each of them to the correct location. For example:
The code at TestImage, I would replace with:
You can't call MEMEM in this part because MEMEM is a 16 bit procedure which also invokes the BIOS, which must be done in real mode. It must be called before you enter the protected mode part. So instead of pushing things in MEMEM on the stack, they must be stored to fixed memory locations.
And when you link the kernel image, you must specify /FIXED /BASE:0xc0000000 on the command line.
Another thing that will guarrantee it to fail is that the kernel is linked with the VS RTL. You must specify the /NODEDFAULTLIB option to avoid this and the /ENTRY: option to define the entry point of your program. Other things to disable are run-time checks and Edit and Continue. C++ exceptions can't be used in the program.
Code: Select all
mov eax, dword [ImageSize]
movzx ebx, word [bpbBytesPerSector]
mul ebx
mov ebx, 4
div ebx
cld
mov esi, IMAGE_RMODE_BASE
mov edi, IMAGE_PMODE_BASE
mov ecx, eax
rep movsd
Code: Select all
mov ecx, [ImageSize]
movzx ebx, word [bpbBytesPerSector]
imul ecx,ebx
shr ecx,2
cld
mov esi, IMAGE_RMODE_BASE
mov edi, IMAGE_PMODE_BASE
rep movsd
Code: Select all
mov esi,IMAGE_RMODE_BASE
mov ebx,[esi+60]
cmp word [esi+ebx],'PE'
je ContinueLoad
mov ebx, BadImage
call Puts32
cli
hlt
ContinueLoad:
movzx edx,word [esi+ebx+6]
add ebx,256
sectionloop:
mov ebp,[esi+ebx]
mov edi,[esi+ebx+4]
add edi,IMAGE_PMODE_BASE
mov ecx,[esi+ebx+8]
sub ebp,ecx
push esi
add esi,[esi+ebx+12]
rep movsb
pop esi
mov ecx,ebp
mov al,0
rep stosb
add ebx,40
dec edx
jnz sectionloop
Code: Select all
mov esi,IMAGE_RMODE_BASE
mov ebx,[esi+60]
mov eax,[esi+ebx+40]
add eax,[esi+ebx+52]
call eax
cli
hlt
And when you link the kernel image, you must specify /FIXED /BASE:0xc0000000 on the command line.
Another thing that will guarrantee it to fail is that the kernel is linked with the VS RTL. You must specify the /NODEDFAULTLIB option to avoid this and the /ENTRY: option to define the entry point of your program. Other things to disable are run-time checks and Edit and Continue. C++ exceptions can't be used in the program.
Last edited by quok on Mon Feb 22, 2010 1:11 pm, edited 1 time in total.
Reason: Added [code][/code] tags. Please follow forum rules next time!
Reason: Added [code][/code] tags. Please follow forum rules next time!
- RGOS
- Member
- Posts: 38
- Joined: Sat Feb 13, 2010 10:52 am
- Location: Buurmalsen, The Netherlands
- Contact:
Re: MOV AX, 0x0000 doesn't work.
Hello,
I'm trying to understand you, but I don't build using the commandline, but directley from the IDE of visual studio, does this work or is there my problem, and if that can't work, how do you compile using the commandline (since I've never used Visual C from the commandline?).
And if I understand, then the piece of code you posted first would be replaced with the third item, and not with the second?
Thanks.
I'm trying to understand you, but I don't build using the commandline, but directley from the IDE of visual studio, does this work or is there my problem, and if that can't work, how do you compile using the commandline (since I've never used Visual C from the commandline?).
And if I understand, then the piece of code you posted first would be replaced with the third item, and not with the second?
Thanks.
Program development: Think, think more and think again, then find the solution and code it.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
OS development: Don't think, think less and don't think again, then the solution will come, else you're screwed.
Most of the time at OSDev you're screwed.
Re: MOV AX, 0x0000 doesn't work.
In the IDE, open Project Properties, and go to Configuration Properties => Linker => Input. There you can check "Ignore all default libraries". Then go to Advanced, and type the name of your entry point function in the Entry Point field. In the Base Address field, write 0xC0000000. At Fixed Base Address, select "Image must be loaded at a fixed address (/FIXED)". You should also set "Turn off Assembly Generation" to Yes, as this relates to the .NET framework. At the Manifest File section, set "Generate Manifest" to No.
At C++ => General, set Debug Information Format to anything except "Program Database for Edit and Continue". At Code Generation, set Enable Minimal Rebuild to No, Enable C++ Exceptions to No, Smaller Type Check to No, Basic Runtime Checks to Default and Buffer Security Check to No. That's how it is in VS 2008, but it's probably similar in VS 2010.
At C++ => General, set Debug Information Format to anything except "Program Database for Edit and Continue". At Code Generation, set Enable Minimal Rebuild to No, Enable C++ Exceptions to No, Smaller Type Check to No, Basic Runtime Checks to Default and Buffer Security Check to No. That's how it is in VS 2008, but it's probably similar in VS 2010.
Re: MOV AX, 0x0000 doesn't work.
Hello,
In addition to Gigasoft's post, insure Linker->Command Line->Additional options has /ALIGN:512. Not doing so will cause execution issues. It is slightly different between VS 2010 and VS 2008 but its basically the same and works without issues in both of them.
The vector number is the processor exception number. (More specifically, 0xe=page fault which is from later tutorials. I sure hope you are not copying and pasting...)
In addition to Gigasoft's post, insure Linker->Command Line->Additional options has /ALIGN:512. Not doing so will cause execution issues. It is slightly different between VS 2010 and VS 2008 but its basically the same and works without issues in both of them.
When Bochs gives this:Does anybody know what it means, and/or what I can do about it? Ican't seem to find out.
Code: Select all
00045932607e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0e)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}