A related constraint is that the stack pointer should always start at an address that is 8-byte aligned (evenly divisible by 8). This is because the largest data types that require alignment (and which might be pushed onto a stack) are 8 bytes long, e.g., a double-precision floating point value.
int main(int argc, char **argv) { int file; if (argc < 3) { errx(1, "Usage: tailargv is a character pointer pointer - it points to an array of character pointers, each of which points to one of the arguments. For example, if the tail program is invoked from the kernel command line like this:"); } file = open(argv[1], O_RDONLY); if (file < 0) { err(1, "%s", argv[1]); } tail(file, atoi(argv[2]), argv[1]); close(file); return 0; }
OS/161 kernel [? for menu]: p testbin/sort foo 100Then the argv and argc variables should be set up as illustrated in the following illustration:
result = vfs_open("string", mode, &2vn);is incorrect and should bring a warning from the compiler. The problem is that vfs_open may modify its first argument, but "string" is an unmodifiable literal.
Since vfs_open may modify its first argument, it is generally a good idea to make a copy of that argument and then pass the copy to vfs_open. For example, if fname points to a string representing the name of the file to be opened, you can use code similar to this:
char *fname_temp; fname_temp = kstrdup(fname); result = vfs_open(fname_temp,mode,&vn); kfree(fname_temp);
(gdb) print argsarraystart $5 = 2147483616However, you can simply ask gdb to format it as hex:
(gdb) print /x argsarraystart $6 = 0x7fffffe0
(gdb) print *(char *)0x7fffffe8 $17 = 117 'u'The (char *) in this command tells gdb to treat the address 0x7fffffe8 as a character pointer. The leading * tells gdb to dereference that address and print the value stored there. This is an easy way to see whether things are as you expect them to be in memory. For example, once you have copied arguments into a new address space, you can inspect the address space to see if things are laid out as you expect.
You build all of the OS/161 application programs when you run bmake in the directory cs350-os161/os161-1.99. When you do this, the application program executable files are copied into subdirectories under cs350-os161/root/.
Once your OS/161 kernel has booted, you can launch an application program using the p command from the kernel menu. For example, to run the palin program, which is located in testbin, use the following command
OS/161 kernel [? for menu]: p testbin/palinAs usual, you can pass commands to the kernel on sys161 command line, e.g.,
sys161 kernel "p testbin/palin"
# Old/default value # 31 busctl ramsize=524288 # Changed to 2 MB. 31 busctl ramsize=2097152