Page 5 of 6
Re: MOV AX, 0x0000 doesn't work.
Posted: Wed Feb 24, 2010 12:17 pm
by RGOS
jal wrote:Didn't think it would, given that it's the linker that gives the error, but still it's better to have a working memset.
I was afraid already...
jal wrote:Could you give the exact linker error output (sorry, too lazy to check the previous pages to see whether you already did).
Don't mind, the exact error:
Code: Select all
Error 16 error LNK2019: unresolved external symbol __aullshr referenced in function "int __cdecl install_ir(unsigned int,unsigned short,unsigned short,void (__cdecl*)(void))" (?install_ir@@YAHIGGP6AXXZ@Z) IDT.obj main
Error 17 error LNK2019: unresolved external symbol _memset referenced in function "int __cdecl idt_initialize(unsigned short)" (?idt_initialize@@YAHG@Z) IDT.obj main
Error 18 error LNK2001: unresolved external symbol _memset MemManagePhys.obj main
Error 19 error LNK2001: unresolved external symbol _memset MemManageVirt.obj main
Error 20 error LNK1120: 2 unresolved externals
The 15 items before this are warnings, but those aren't important (I think, if you do want to see them, say it).
jal wrote:A simple Google reveals
this. But why would you want to shift 64-bit variables in 32-bit code?
I don't use aullshr myself, but I do use 'uiBase
>> 16', and apparently that's replaced by the linker or compiler or whatever, that's why I'm afraid the solution Gigasoft posted isn't going to work, but more on that later.
jal wrote:And why does the linker complain about memset, if you don't use memset yourself? Are you sure you aren't linking some standard libraries?
I'm using memset myself, it's even a function inside my own code (is that maybe just the problem?).
@Gigasoft: Is this (the attachment) right then? And do I need to make a function in my C++
code to implement aullshr (with inline assembley) or don't I get you?
Thanks.
Re: MOV AX, 0x0000 doesn't work.
Posted: Wed Feb 24, 2010 12:48 pm
by Gigasoft
You don't need the code from CopyImage up to and including the rep movsd since the header is accessed at IMAGE_RMODE_BASE and the sections are copied by the code below.
The __aullshr can be placed in a separate ASM file which you assemble (using the -f win32 option in the NASM command line), and then you can add the result OBJ file to the project. Be sure to have a bits 32 at the start of the ASM file. Then it should work. _memset and _strlen are also simple, the most basic versions look like this:
Code: Select all
global _memset
_memset:
push edi
mov edi,[esp+8]
mov al,[esp+12]
mov ecx,[esp+16]
rep stosb
pop edi
ret
global _strlen
_strlen:
push edi
mov edi,[esp+8]
or ecx,-1
mov edx,edi
mov al,0
repnz scasb
sub edi,edx
dec edi
xchg edi,eax
pop edi
ret
They could probably also be written in the C file (then you wouldn't use the global statement or the labels) if you add the __declspec(naked) to the declaration of the functions. Then __aullshr would be named _aullshr and _memset would be named memset.
Re: MOV AX, 0x0000 doesn't work.
Posted: Wed Feb 24, 2010 2:36 pm
by RGOS
Hello,
I've tried what you said, pasting the code of aullshr and memset in a .asm file and compile it with -f win32, all and well, I've added them to the VS2010 project, but do I need to add a reference or something (I don't know)? Because I get the linker errors still...
Thanks.
Re: MOV AX, 0x0000 doesn't work.
Posted: Wed Feb 24, 2010 4:14 pm
by Gigasoft
Well if adding the OBJ to the project doesn't work, try putting the name of the OBJ in Linker => Input => Additional Dependencies instead.
Re: MOV AX, 0x0000 doesn't work.
Posted: Wed Feb 24, 2010 4:35 pm
by RGOS
Hello,
I've tried adding the .obj file to the Additional Dependencies, but now I get these errors:
Code: Select all
Error 16 error LNK2001: unresolved external symbol _memset memsetaullshr.obj main
Error 17 error LNK2001: unresolved external symbol _memset IDT.obj main
Error 18 error LNK2001: unresolved external symbol _memset MemManagePhys.obj main
Error 19 error LNK2001: unresolved external symbol _memset MemManageVirt.obj main
Error 20 error LNK2001: unresolved external symbol __aullshr memsetaullshr.obj main
Error 21 error LNK2001: unresolved external symbol __aullshr IDT.obj main
Error 22 error LNK2001: unresolved external symbol aus_1 memsetaullshr.obj main
Error 23 error LNK2001: unresolved external symbol aus_2 memsetaullshr.obj main
Error 24 error LNK1120: 4 unresolved externals C:\Users\Robke.WALHALLA\Desktop\RGOS\DevelopmentOfRGOS\FILES\NewTry\kernel\Debug\main.exe main
I've to go get some sleep now, I go on tomorrow.
But do you know how this happens?
Thanks.
Re: MOV AX, 0x0000 doesn't work.
Posted: Wed Feb 24, 2010 5:04 pm
by Combuster
This thread is more and more looking like errors between the keyboard and chair. The asm as posted generates an object file with the desired symbols as exports, not imports, which basically means that I can not reproduce your error without deviating from the instructions.
And in general, you should not need to ask about how to fix undefined references, given that you are apparently
good enough to write an OS?</sarcasm>
Re: MOV AX, 0x0000 doesn't work.
Posted: Wed Feb 24, 2010 5:31 pm
by Gigasoft
There's a slight mistake in the __aullshr I posted (the aus_2: should be aus_0: ), but it shouldn't cause those error messages.
Try adding section .text at the top of the ASM file and reassemble it. If it still doesn't work, maybe you should post the generated OBJ file because it sounds like something's very wrong with it.
Re: MOV AX, 0x0000 doesn't work.
Posted: Thu Feb 25, 2010 5:48 am
by RGOS
Hello,
@Combuster: I'm trying to develop an OS just because I want to learn how it works, and the best way is if you run into trouble to ask. And I do have the bare minimum knowledge, but I want to expand that knowledge, but I'm sorry if I sound stupid.
@Gigasoft: I've corrected the error, but also you wrote public instead of global, and nasm doesn't understand it, I've changed it to global and assembled it to an .obj. I'll also post the .asm, and .obj files I've got from it. But now I also get errors from VS that aus_1 and aus_0 are unresolved external symbols...
I'm goint to test .text at the top. EDIT: If I put .text at the top of the .asm then I get an error from NASM: attempt to define a local label before any non-local labels.
Thanks.
Re: MOV AX, 0x0000 doesn't work.
Posted: Thu Feb 25, 2010 9:47 am
by Gigasoft
Ok, I just tested it and it's strange that NASM doesn't report an error but makes this output file instead. Anyway, add section .text - not just .text and it should work.
Re: MOV AX, 0x0000 doesn't work.
Posted: Thu Feb 25, 2010 10:28 am
by RGOS
Hello,
Great I don't get any errors from VS, but when I test it I still get a stack fault, but it can't be my MEMEM function, because everything I pushed in that function, I pop afer it and store it all in memory, and if I, before calling the kernel, move bytes 0xEB and 0xFE (jmp $) to where the kernel is (supposed to be), the code stops excecuting, to accomplish that move I've got this code:
Code: Select all
TestImage:
mov esi,IMAGE_RMODE_BASE
mov ebx,[esi+60]
mov eax,[esi+ebx+40]
add eax,[esi+ebx+52]
mov byte[eax], 0xEB
inc eax
mov byte[eax], 0xFE
dec eax
call eax
cli
hlt
But when I comment it out, then I get the stack fault, the only thing where I can come up with is that eax doesn't contain the right address. And that seems to be the problem, because when I use this code:
Code: Select all
push eax
mov eax, IMAGE_PMODE_BASE
mov byte[eax], 0xEB
inc eax
mov byte[eax], 0xFE
dec eax
pop eax
I also get a stack fault, so probably eax doesn't contain the kernel's entry point. When I just call IMAGE_PMODE_BASE (without the code's from above), then the CPU is disabled, and when I just call IMAGE_RMODE_BASE, I get the stack fault, so I don't know what the problem is
. Do any of you know?
Thanks.
Re: MOV AX, 0x0000 doesn't work.
Posted: Thu Feb 25, 2010 11:48 am
by Combuster
RGOS wrote:@Combuster: I'm trying to develop an OS just because I want to learn how it works, and the best way is if you run into trouble to ask.
The best way to learn is to do something yourself, not having it done for you...
And I do have the bare minimum knowledge
I have never seen you debug, and I see you make all sorts of beginner mistakes that indicate otherwise, and especially the last one where I couldn't write it off as something else.
Speaking of which, that's what Bochs' debugger is for - it allows you to debug your OS as if it were an userspace application. Basically, what you really need to do is to start verifying your assumptions. At the very least stop using a virtualizer - they have only one message for system crashes (which might or might not be the real cause).
Re: MOV AX, 0x0000 doesn't work.
Posted: Thu Feb 25, 2010 1:14 pm
by RGOS
Hello,
Yes, I do use Bochs debugger, but also when I try to use a floppy with the OS in a real system, it doesn't even boot (I've to fix that to, but a later time).
I've found out that eax contains 0xC0000430 before calling, and I think that can be right, because in VS I've stated that base-address must be 0xC0000000, but maybe I must change that to 0x100000 (IMAGE_PMODE_BASE), I'm going to try that now.
Thanks.
Re: MOV AX, 0x0000 doesn't work.
Posted: Thu Feb 25, 2010 1:18 pm
by neon
Hello,
The address that you call to execute the kernel must always be a virtual address do to paging being enabled. (However it must also be mapped memory as well.) You can have VS output a linker map file to obtain the RVA address of the entry point. Compare that address to see if its the entry point.
*edit: You mentioned that you are getting stack faults. Use the bochs debugger and check the stack is still intact right before the stack fault occurs.. Last time I personally ran into that issue was do to stack corruption.
Re: MOV AX, 0x0000 doesn't work.
Posted: Thu Feb 25, 2010 2:46 pm
by RGOS
Hello,
I've debugged it, with base-address set to 0x100000 and I've found out that KERNEL.EXE is finaly called and excecuting, but there the OS crashes. But I think I'm going to check if I myself can find out whats going wrong, and if I can't find out, Ill post.
EDIT:@neon: I get a stack fault from VMWare, and as you stated it can be that that's not the problem, and I found out the KERNEL.EXE is already called so I'm chekking where the error occurs... I'll post if I know more. But how would you advice to check for a corrupted stack? It probably isn't the MEMEM function, because what I already mensioned is that changed to moving the info to memory.
Thanks.
Re: MOV AX, 0x0000 doesn't work.
Posted: Thu Feb 25, 2010 4:14 pm
by neon
Hello,
Bochs debugger comes with an option to display the contents of the stack. Verify its contents before and after the stack fault occurs. You know whats on the stack so only you can tell if the contents of the stack are fine.
*edit: Also, Check to insure that the base address of your kernel (Check your project properties) is indeed 1MB. If its not, it will not work with you calling it as if its base was 1MB.