Skip to content

Commit 7cafe35

Browse files
committed
Kernel to receive argv via syscall spawn
1 parent 4585798 commit 7cafe35

File tree

9 files changed

+29
-24
lines changed

9 files changed

+29
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ binaries: $(bt_stage1) $(bt_stage2) $(kernel_core) $(rm_static)
102102
SECTOR_COUNT_BT_STAGE1 = 1
103103
SECTOR_COUNT_SHARED_LIBRARY = 1
104104
SECTOR_COUNT_BT_STAGE2 = 11
105-
SECTOR_COUNT_KERNEL = 45
105+
SECTOR_COUNT_KERNEL = 47
106106

107107
SECTOR_START_BT_STAGE1 = 0
108108
SECTOR_START_SHARED_LIBRARY = $(shell expr $(SECTOR_START_BT_STAGE1) + $(SECTOR_COUNT_BT_STAGE1) )

include/fuzzy/kernel/process/process.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int get_idt_ds_entry(int process_id);
3636
int get_idt_reverse_pid_lookup(int cs);
3737

3838
// process create or kill
39-
int process_create();
39+
int process_create(char *argv[]);
4040
void process_kill(int user_ds, int status);
4141

4242
// scheduler

memory_layout.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| 0x7E00 | 0x7EFF | 256B | SHARED STATIC CODE for real_mode library |
88
| 0x7F00 | 0x7FFF | 256B | SHARED STATIC MEMORY for real_mode library |
99
| 0x8000 | 0xBFFF | - | BOOT LOADER STAGE 2 + own stack |
10-
| 0xC000 | 0x10200 | - | KERNEL |
10+
| 0xC000 | 0x1FFFF | - | KERNEL |
1111
| 0x20000 | 0x2FFFF | - | Application 0 |
1212
| 0x30000 | 0x3FFFF | - | Application 1 |
1313
...

src/kernel/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void kernel_core_entry() {
3333
set_color_bg(C_BLUE);
3434
set_color_fg(C_WHITE);
3535
print_rectangle(0, 0, TEXT_WINDOW_WIDTH-1, TEXT_WINDOW_HEIGHT-1);
36+
move_xy(0, 0);
3637
print_log("Initializing Kernel");
3738

3839

@@ -50,7 +51,7 @@ void kernel_core_entry() {
5051
clrscr();
5152

5253
int init_pid = spawnl(INIT_APPNAME, INIT_APPNAME, NULL);
53-
print_log("init process created: %d", init_pid);
54+
print_log("init process got created: %d", init_pid);
5455

5556
// interrupt_pit_enable();
5657
while (1);

src/kernel/process/allocation.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* pid 2 : user app 2 and so on...
1010
*
1111
* Process Cycle
12-
* - process_create()
12+
* - process_create(...)
1313
* - process_load_from_disk()
1414
* - OR process_load_from_ram()
1515
*/
@@ -88,7 +88,7 @@ void process_scheduler_init() {
8888
load_gdt_table(&gdtr);
8989
}
9090

91-
int process_create() {
91+
int process_create(char *argv[]) {
9292
// returnd pid >= 0 if success
9393
int pid = -1;
9494
for (int i = 0; i < MAX_PROCESS; ++i) {
@@ -130,6 +130,7 @@ int process_create() {
130130
// initially ds == ss
131131
process->ss = get_gdt_number_from_entry_id(idt_ds_entry);
132132
process->sp = create_infant_process_irq0_stack(process->ss);
133+
// TODO: Push argv in process stack
133134
return pid;
134135
}
135136

src/kernel/process/process.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
#include <lib/utils/logging.h>
88
#include <lib/utils/output.h>
99

10-
extern int call_main(int cs, int ds, int argc, char *argv[]);
11-
12-
int process_spawn(int lba_index, int sector_count) {
10+
int process_spawn(int lba_index, int sector_count, char *argv[]) {
1311
print_info("[process_spawn] create");
14-
int pid = process_create();
12+
int pid = process_create(argv);
1513
if(pid<0) {
1614
print_log("Failed to reserved a new pid");
1715
return -1;
@@ -39,7 +37,8 @@ int syscall_1_process_exit(int user_ds, int status) {
3937
}
4038

4139
int syscall_1_process_spawn_lba_sc(int lba_start, int sector_count) {
42-
return process_spawn(lba_start, sector_count);
40+
char *fake_argv[]={"fake_spawn", NULL};
41+
return process_spawn(lba_start, sector_count, fake_argv);
4342
}
4443

4544
int syscall_1_process_exec_lba_sc(int lba_start, int sector_count) {
@@ -48,19 +47,23 @@ int syscall_1_process_exec_lba_sc(int lba_start, int sector_count) {
4847

4948
int syscall_1_process_spawn_fname(int user_ds, char *_us_filename, char *_us_argv[]) {
5049
char filename[FS_FFS_FILENAME_LIMIT];
51-
char argv_with_uspointer[PROCESS_MAX_ARGC];
52-
char *argv_with_kspointer[PROCESS_MAX_ARGC];
53-
char argv[PROCESS_MAX_ARGC][PROCESS_MAX_ARG_LEN]; // data store
50+
char argv_data[PROCESS_MAX_ARGC][PROCESS_MAX_ARG_LEN];
51+
char *argv_with_uspointer[PROCESS_MAX_ARGC];
52+
char *argv[PROCESS_MAX_ARGC]; // kernel mode
5453
syscall_strncpy_user_to_kernel(user_ds, _us_filename, filename, sizeof(filename));
5554
syscall_strncpy_user_to_kernel(user_ds, _us_argv, argv_with_uspointer, sizeof(argv_with_uspointer));
56-
// if src string is NULL, then dst should be null.
55+
// if src string is NULL, then dst string also should be null.
5756
for (int i = 0; i < PROCESS_MAX_ARGC; i++) {
5857
if(argv_with_uspointer[i]==NULL) {
59-
argv_with_kspointer[i]=NULL;
58+
argv[i]=NULL;
6059
break;
6160
}
62-
syscall_strncpy_user_to_kernel(user_ds, argv[i], argv_with_uspointer[i], sizeof(argv[i]));
63-
argv_with_kspointer[i] = argv[i];
61+
syscall_strncpy_user_to_kernel(user_ds, argv_with_uspointer[i], argv_data[i], sizeof(argv_data[i]));
62+
argv[i] = argv_data[i];
63+
}
64+
65+
for (int i = 0; argv[i]; i++) {
66+
printf("[kernel] arg%d: %s\n", i, argv[i]);
6467
}
6568

6669
union FFSFileEntry entry;
@@ -71,8 +74,7 @@ int syscall_1_process_spawn_fname(int user_ds, char *_us_filename, char *_us_arg
7174
int lba_start = resolve_abs_lba(FFS_UNIQUE_PARITION_ID, entry.content.start_block_id);
7275
int sector_count = (entry.content.filesize + FS_BLOCK_SIZE -1)/FS_BLOCK_SIZE;
7376

74-
// TODO: process created should have argv pushed on top of stack.
75-
return syscall_1_process_spawn_lba_sc(lba_start, sector_count);
77+
return process_spawn(lba_start, sector_count, argv);
7678
}
7779

7880
int syscall_1_process(int operation, int a0, int a1, int a2, int a3, int user_ds) {

src/usr/include/process.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#define SYSCALL_PROCESS_SUB_EXEC_LBA_SC 2
66
#define SYSCALL_PROCESS_SUB_SPAWN_FNAME 3
77

8-
#define PROCESS_MAX_ARGC 32
9-
#define PROCESS_MAX_ARG_LEN 64
8+
#define PROCESS_MAX_ARGC 6
9+
#define PROCESS_MAX_ARG_LEN 32
1010

1111
// if non-negative value is returned
1212
// then it's the pid of the new process

src/usr/lib/process.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ int spawnl(char *file_path, char *arg0, ...) {
1010

1111
// prepare argv
1212
{
13-
int i = 0;
13+
argv[0] = arg0;
14+
int i = 1;
1415
while(i<PROCESS_MAX_ARGC-1) {
1516
char *arg = va_arg(args, char *);
1617
if(arg==NULL) break;

src/usr/local/src/sh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int cmd_run(char *fname) {
2828
printf("usage: run <filename>\n");
2929
return -2;
3030
}
31-
return spawnl(fname, fname, NULL);
31+
return spawnl(fname, fname, "testing", "yoyo", NULL);
3232
}
3333

3434
int cmd_echo(char *text) {

0 commit comments

Comments
 (0)