I've already implemented multitasking and a simple form of IPC in my kernel. I'm trying to set up a simple system under it with a shell and console driver. The way it works is that the shell sends a signal (sort of like *nix signals, but more like a small message) to the console driver. The console driver then asks the kernel to map a page of memory from the shell's address space (where the buffer to be printed is) to a location into the driver's own address space. The proper memory location is then read directly from this remapping and printed to the screen.
So far, this has been working fine, as long as the buffer is a global variable (i.e. in the data section). However, if I allocate the buffer on the stack as a local variable, the driver prints out either nothing or garbage. I have compensated for the buffer not being page aligned, and that is not the problem. I also tried enabling write-through caching and disabling caching, both on the pages in the stack and on the system as a whole (by setting flags on CR3). I checked the addresses being passed to the driver, and they are also correct. There are no compiler optimizations - optimizing breaks both cases. Any idea what the problem could be?
Cannot output from stack
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
- alethiophile
- Member
- Posts: 90
- Joined: Sat May 30, 2009 10:28 am
Re: Cannot output from stack
It sounds like rather a brittle method of doing things, anyway. Isn't your kernel mapped into all process address spaces?
If I had an OS, there would be a link here.
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Cannot output from stack
It is, but I'm trying to do a microkernel, so drivers need to send large amount of information. However, I see your point - I think I'm going to have a system call for the kernel to do the copying of data instead.
-
- Member
- Posts: 65
- Joined: Sat Jul 04, 2009 9:39 pm
Re: Cannot output from stack
Wild guess: buffer overrun?NickJohnson wrote:Any idea what the problem could be?
Try surrounding the buffer with "guards".
Code: Select all
int x = 0xDEADBEEF;
char buffer[100];
int y = 0xDEADBEEF;
-
- Member
- Posts: 199
- Joined: Sat Jun 28, 2008 6:44 pm
Re: Cannot output from stack
This is a bad idea. Most compilers won't guarantee that the values are pushed in order.manonthemoon wrote:Wild guess: buffer overrun?NickJohnson wrote:Any idea what the problem could be?
Try surrounding the buffer with "guards".
Then make sure the guard variables around the buffer don't get changed. If they do, the kernel wrote too much and corrupted the stack.Code: Select all
int x = 0xDEADBEEF; char buffer[100]; int y = 0xDEADBEEF;
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Cannot output from stack
Except that the kernel isn't really doing anything, and the driver is reading the buffer, not writing. Either way, I've changed the design so that there can't be a problem anymore - copying through the kernel is much more robust anyway.manonthemoon wrote:Wild guess: buffer overrun?NickJohnson wrote:Any idea what the problem could be?
Try surrounding the buffer with "guards".
Then make sure the guard variables around the buffer don't get changed. If they do, the kernel wrote too much and corrupted the stack.Code: Select all
int x = 0xDEADBEEF; char buffer[100]; int y = 0xDEADBEEF;