ref: 06e6115044b91e559b22287c76207c3bc787800c
parent: 0e03a5f9fd033eb1f3defe58d799ec7e1dba564a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Dec 17 04:23:21 EST 2014
pc, pc64: remove old B.COM command line parsing and just pass tokenized BOOTLINE to /boot/boot as argv[] this change allows command line passing to /boot/boot from qemu like: qemu -kernel 9pcf -append "-u glenda tcp"
--- a/sys/src/9/pc/initcode.s
+++ /dev/null
@@ -1,23 +1,0 @@
-#include "/sys/src/libc/9syscall/sys.h"
-
-TEXT main(SB),$0
-
- /*
- * exec("/boot", bootv)
- */
- LEAL 4(SP),AX
- PUSHL AX
- LEAL boot(SB),AX
- PUSHL AX
- PUSHL $0
- MOVL $EXEC,AX
- INT $64
-
- /*
- * should never get here
- */
-here:
- JMP here
-
-GLOBL boot+0(SB),$6
-DATA boot+0(SB)/5,$"/boot"
--- a/sys/src/9/pc/main.c
+++ b/sys/src/9/pc/main.c
@@ -29,7 +29,7 @@
char *confname[MAXCONF];
char *confval[MAXCONF];
int nconf;
-uchar *sp; /* user stack of init proc */
+char *sp; /* user stack of init proc */
int delaylink;
int idle_spin;
@@ -321,53 +321,39 @@
ready(p);
}
-uchar *
-pusharg(char *p)
-{
- int n;
-
- n = strlen(p)+1;
- sp -= n;
- memmove(sp, p, n);
- return sp;
-}
-
void
bootargs(void *base)
{
- int i, ac;
- uchar *av[32];
- uchar **lsp;
- char *cp = BOOTLINE;
- char buf[64];
+ char *argv[8];
+ int i, argc;
- sp = (uchar*)base + BY2PG - sizeof(Tos);
+#define UA(ka) ((char*)(ka) + ((uintptr)(USTKTOP - BY2PG) - (uintptr)base))
+ sp = (char*)base + BY2PG - sizeof(Tos);
- ac = 0;
- av[ac++] = pusharg("boot");
+ /* push boot command line onto the stack */
+ sp -= BOOTLINELEN;
+ sp[BOOTLINELEN-1] = '\0';
+ memmove(sp, BOOTLINE, BOOTLINELEN-1);
- /* when boot is changed to only use rc, this code can go away */
- cp[BOOTLINELEN-1] = 0;
- buf[0] = 0;
- if(strncmp(cp, "fd", 2) == 0){
- sprint(buf, "local!#f/fd%lddisk", strtol(cp+2, 0, 0));
- av[ac++] = pusharg(buf);
- } else if(strncmp(cp, "sd", 2) == 0){
- sprint(buf, "local!#S/sd%c%c/fs", *(cp+2), *(cp+3));
- av[ac++] = pusharg(buf);
- } else if(strncmp(cp, "ether", 5) == 0)
- av[ac++] = pusharg("-n");
+ /* parse boot command line */
+ argc = tokenize(sp, argv, nelem(argv));
+ if(argc < 1){
+ strcpy(sp, "boot");
+ argc = 0;
+ argv[argc++] = sp;
+ }
/* 4 byte word align stack */
- sp = (uchar*)((ulong)sp & ~3);
+ sp = (char*)((uintptr)sp & ~3);
- /* build argc, argv on stack */
- sp -= (ac+1)*sizeof(sp);
- lsp = (uchar**)sp;
- for(i = 0; i < ac; i++)
- lsp[i] = av[i] + ((USTKTOP - BY2PG) - (ulong)base);
- lsp[i] = 0;
- sp += (USTKTOP - BY2PG) - (ulong)base;
+ /* build argv on stack */
+ sp -= (argc+1)*BY2WD;
+ for(i=0; i<argc; i++)
+ ((char**)sp)[i] = UA(argv[i]);
+ ((char**)sp)[i] = nil;
+
+ sp = UA(sp);
+#undef UA
sp -= BY2WD;
}
--- a/sys/src/9/pc64/main.c
+++ b/sys/src/9/pc64/main.c
@@ -29,7 +29,7 @@
int delaylink;
int idle_spin;
-uchar *sp; /* user stack of init proc */
+char *sp; /* user stack of init proc */
extern void (*i8237alloc)(void);
extern void bootscreeninit(void);
@@ -330,54 +330,39 @@
active.exiting = 0;
}
-
-uchar *
-pusharg(char *p)
-{
- int n;
-
- n = strlen(p)+1;
- sp -= n;
- memmove(sp, p, n);
- return sp;
-}
-
void
bootargs(void *base)
{
- int i, ac;
- uchar *av[32];
- uchar **lsp;
- char *cp = BOOTLINE;
- char buf[64];
+ char *argv[8];
+ int i, argc;
- sp = (uchar*)base + BY2PG - sizeof(Tos);
+#define UA(ka) ((char*)(ka) + ((uintptr)(USTKTOP - BY2PG) - (uintptr)base))
+ sp = (char*)base + BY2PG - sizeof(Tos);
- ac = 0;
- av[ac++] = pusharg("boot");
+ /* push boot command line onto the stack */
+ sp -= BOOTLINELEN;
+ sp[BOOTLINELEN-1] = '\0';
+ memmove(sp, BOOTLINE, BOOTLINELEN-1);
- /* when boot is changed to only use rc, this code can go away */
- cp[BOOTLINELEN-1] = 0;
- buf[0] = 0;
- if(strncmp(cp, "fd", 2) == 0){
- sprint(buf, "local!#f/fd%lddisk", strtol(cp+2, 0, 0));
- av[ac++] = pusharg(buf);
- } else if(strncmp(cp, "sd", 2) == 0){
- sprint(buf, "local!#S/sd%c%c/fs", *(cp+2), *(cp+3));
- av[ac++] = pusharg(buf);
- } else if(strncmp(cp, "ether", 5) == 0)
- av[ac++] = pusharg("-n");
+ /* parse boot command line */
+ argc = tokenize(sp, argv, nelem(argv));
+ if(argc < 1){
+ strcpy(sp, "boot");
+ argc = 0;
+ argv[argc++] = sp;
+ }
/* 8 byte word align stack */
- sp = (uchar*)((uintptr)sp & ~7);
+ sp = (char*)((uintptr)sp & ~7);
- /* build argc, argv on stack */
- sp -= (ac+1)*sizeof(sp);
- lsp = (uchar**)sp;
- for(i = 0; i < ac; i++)
- lsp[i] = av[i] + ((uintptr)(USTKTOP - BY2PG) - (uintptr)base);
- lsp[i] = 0;
- sp += (uintptr)(USTKTOP - BY2PG) - (uintptr)base;
+ /* build argv on stack */
+ sp -= (argc+1)*BY2WD;
+ for(i=0; i<argc; i++)
+ ((char**)sp)[i] = UA(argv[i]);
+ ((char**)sp)[i] = nil;
+
+ sp = UA(sp);
+#undef UA
sp -= BY2WD;
}