I always hate writing up these basic little questions, they seem so insignificant. Anyway, I started remodeling the structure from the bootloader up and ran into a doozy. I started with my own bootloader loading into a very very simple kernel.
All the sudden, k_printf doesn't work. What the hell, I think. So I try and boot the same very very simple kernel using John Fine's fat12 bootf02, confident that it will correct the problem (e.g. I had screwed up my own bootloader).
The problem doesn't go away. Damn. So I know the problem's within the kernel. I make sure that my kprint_f is functional by loading a string into a variable and then calling kprintf with the variable rather than the immediate value "hello". It prints fine.
This tells me that there's a stack problem, because when the function doesn't have to push "hello" to the stack (it can function straight from that variable) it works just fine.
Anyway, I thought it was because I misunderstood bootf02 and it wasn't setting up a 32 bit stack correctly, so I added:
mov ax, DATASEL ;<-from the GDT
mov ss, ax
mov esp, 0xFFFF
to the ASM tab at the beginning of my kernel to no effect. Now I'm completely at a loss... please take a look at the code, see if any of our code masters can see the problem...
NOTE: the attached .txt includes all the code, including John Fine's bootf02
[attachment deleted by admin]
something stack
Re:something stack
Might just be me, but isn't 0xffff a bad place to start a 32-bit stack, in that it's not divisable by 4.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:something stack
witw ? pushing "hello" on the stack, hey ? you know you never push or pop "strings" from the stack, but only their address, regardless of whether you call print("hello") or print(HelloStr);wangpeng wrote:
This tells me that there's a stack problem, because when the function doesn't have to push "hello" to the stack (it can function straight from that variable) it works just fine.
the only difference that exists between
Code: Select all
print("Hello");
Code: Select all
char *HelloStr="Hello";
print(HelloStr);
If i were you, i would rather check that your whole kernel is properly loaded in memory before continuing investigations.
Re:something stack
All right all right, sorry. Geez.
I figured it out, just for further reference. It was a combination of several elements of my own fault. First was the realization that I accidentally put down 0x10000 instead of 0x100000 in my linker script, making it align things very oddly. The second realization was that I kept forgetting to unmount the floppy I was copying the kernel to before I used bochs, evidently Linux didn't want to share.
I would have to argue with you though that something is different between k_printf("Hello",3) and k_printf(data,3). Maybe something along the lines of absolute versus relative addressing. Whatever, but there's gotta be something different just for the simple reason that one worked and one didn't in the broken state of my kernel.
Also, about pushing the string to the stack, I sorta thought that was weird, but I was going off a friend (no offense, Ubu) whom I assumed was smarter than myself (as usually is the case).
I figured it out, just for further reference. It was a combination of several elements of my own fault. First was the realization that I accidentally put down 0x10000 instead of 0x100000 in my linker script, making it align things very oddly. The second realization was that I kept forgetting to unmount the floppy I was copying the kernel to before I used bochs, evidently Linux didn't want to share.
I would have to argue with you though that something is different between k_printf("Hello",3) and k_printf(data,3). Maybe something along the lines of absolute versus relative addressing. Whatever, but there's gotta be something different just for the simple reason that one worked and one didn't in the broken state of my kernel.
Also, about pushing the string to the stack, I sorta thought that was weird, but I was going off a friend (no offense, Ubu) whom I assumed was smarter than myself (as usually is the case).