Skip to content

Commit 7dec891

Browse files
module loader aliases
1 parent 502aae1 commit 7dec891

File tree

5 files changed

+149
-2
lines changed

5 files changed

+149
-2
lines changed

include/module.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,6 @@ bool load_module(const char *name);
366366
*/
367367
bool unload_module(const char *name);
368368

369-
bool module_addr_to_symbol(uintptr_t addr, const char **modname_out, const char **symname_out, uint64_t *offset_out);
369+
bool module_addr_to_symbol(uintptr_t addr, const char **modname_out, const char **symname_out, uint64_t *offset_out);
370+
371+
bool module_parse_alias(const char* alias);

os/programs/init.rrbasic

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GLOBAL LIB$ = "/programs/libraries" ' Default library path
22

33
PROCmessage("Loading", "drivers")
4-
MODLOAD "e1000"
4+
MODLOAD "net"
55

66
PROCmessage("Mounting", "filesystems")
77
MOUNT "/devices", "", "devfs"

os/system/config/loadorder.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# vendor device type modules
2+
3+
# Network drivers
4+
[net]
5+
1AF4 1041 * virtio_net
6+
8086 100E * e1000
7+
8086 107C * e1000
8+
8086 153A * e1000
9+
8086 10EA * e1000
10+
10EC 8139 * rtl8139
11+
12+
# Sound drivers
13+
[sound]
14+
* * 0403 hda
15+
* * 0401 ac97
16+
17+
[codecs]
18+
* * * flac,mod,mp3,ogg,xm

src/kernel.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ void kmain() {
2222
}
2323
}
2424

25+
module_parse_alias("net");
26+
wait_forever();
27+
2528
init_process();
2629
}

src/module_loader.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,127 @@ bool unload_module(const char* name) {
627627
hashmap_delete(modules, mod);
628628
return true;
629629
}
630+
631+
enum loadorder_parse_state_t {
632+
SEARCH_ALIAS,
633+
READ_ALIAS,
634+
READ_VENDOR,
635+
READ_DEVICE,
636+
READ_TYPE,
637+
READ_MODLIST
638+
};
639+
640+
bool module_parse_alias(const char* alias) {
641+
int handle = _open("/system/config/loadorder.conf", _O_RDONLY);
642+
if (handle < 0) {
643+
return false;
644+
}
645+
char found_alias[MAX_STRINGLEN], vendor[MAX_STRINGLEN], device[MAX_STRINGLEN], type[MAX_STRINGLEN], modlist[MAX_STRINGLEN];
646+
char* alias_ptr = found_alias, *vendor_ptr = vendor, *device_ptr = device, *type_ptr = type, *modlist_ptr = modlist;
647+
bool alias_located = false;
648+
enum loadorder_parse_state_t state = SEARCH_ALIAS;
649+
while (!_eof(handle)) {
650+
char c;
651+
_read(handle, &c, 1);
652+
switch (c) {
653+
case '[':
654+
/* Start of alias */
655+
if (state == SEARCH_ALIAS || state == READ_VENDOR) {
656+
state = READ_ALIAS;
657+
alias_ptr = found_alias;
658+
memset(found_alias, 0, sizeof(found_alias));
659+
alias_located = false;
660+
} else {
661+
/* Invalid: [ outside of ALIAS */
662+
dprintf("Parse error: [ in wrong state\n");
663+
_close(handle);
664+
return false;
665+
}
666+
break;
667+
case ']':
668+
/* End of alias */
669+
if (state == READ_ALIAS) {
670+
state = READ_VENDOR;
671+
if (!strcasecmp(alias, found_alias)) {
672+
alias_located = true;
673+
}
674+
memset(vendor, 0, sizeof(vendor));
675+
memset(device, 0, sizeof(device));
676+
memset(type, 0, sizeof(type));
677+
memset(modlist, 0, sizeof(modlist));
678+
vendor_ptr = vendor;
679+
device_ptr = device;
680+
type_ptr = type;
681+
modlist_ptr = modlist;
682+
} else {
683+
/* Invalid: ] outside of ALIAS */
684+
dprintf("Parse error: ] in wrong state\n");
685+
_close(handle);
686+
return false;
687+
}
688+
break;
689+
case '\n':
690+
/* Newline */
691+
if (state == READ_MODLIST) {
692+
if (alias_located) {
693+
dprintf("Read line in alias '%s': vendor: '%s' device: '%s' type: '%s' modlist: '%s'\n", found_alias, vendor, device, type, modlist);
694+
}
695+
state = READ_VENDOR;
696+
memset(vendor, 0, sizeof(vendor));
697+
memset(device, 0, sizeof(device));
698+
memset(type, 0, sizeof(type));
699+
memset(modlist, 0, sizeof(modlist));
700+
vendor_ptr = vendor;
701+
device_ptr = device;
702+
type_ptr = type;
703+
modlist_ptr = modlist;
704+
}
705+
break;
706+
case '#':
707+
/* Comment */
708+
while (!_eof(handle) && c != '\n') {
709+
_read(handle, &c, 1);
710+
}
711+
break;
712+
default:
713+
switch (state) {
714+
case READ_ALIAS:
715+
*alias_ptr++ = c;
716+
break;
717+
case READ_VENDOR:
718+
if (c == '\t' || c == ' ') {
719+
state = READ_DEVICE;
720+
} else {
721+
*vendor_ptr++ = c;
722+
}
723+
break;
724+
case READ_DEVICE:
725+
if (c == '\t' || c == ' ') {
726+
state = READ_TYPE;
727+
} else {
728+
*device_ptr++ = c;
729+
}
730+
break;
731+
case READ_TYPE:
732+
if (c == '\t' || c == ' ') {
733+
state = READ_MODLIST;
734+
} else {
735+
*type_ptr++ = c;
736+
}
737+
break;
738+
case READ_MODLIST:
739+
if (c == '\n') {
740+
state = READ_DEVICE;
741+
} else {
742+
*modlist_ptr++ = c;
743+
}
744+
break;
745+
case SEARCH_ALIAS:
746+
break;
747+
}
748+
break;
749+
}
750+
}
751+
_close(handle);
752+
return false;
753+
}

0 commit comments

Comments
 (0)