/dev/kmem

NeXT Computer, Inc. -> Porting New Software

Title: /dev/kmem
Post by: pTeK on March 11, 2025, 12:57:17 PM
Hi.

 Does any one here have any example code that reads /dev/kmem or mainly the values from KernBootStruct after /usr/standalone/i386/boot has been executed?

 Could not find anything searching user @evolver56k Darwin 0.3 archive on github. (https://github.com/evolver56k/Darwin-0.3)

 Thanks in advance.
Title: Re: /dev/kmem
Post by: pTeK on March 15, 2025, 01:56:43 PM
Thank you to @Rhetorica who pointed me to Darwin 0.3 - /diskdev_cmds-1/fdisk.tproj/fdisk.c (https://github.com/evolver56k/Darwin-0.3/blob/745305afd074437bb660bcf02146a2754eeef5ae/diskdev_cmds-1/fdisk.tproj/fdisk.c) I was able to get some example code working. It requires kernBootStruct.h (https://github.com/evolver56k/Darwin-0.3/blob/745305afd074437bb660bcf02146a2754eeef5ae/boot-2/i386/libsa/kernBootStruct.h) (or you can get it from /machdep/i386/kernBootStruct.h (https://github.com/evolver56k/Darwin-0.3/blob/745305afd074437bb660bcf02146a2754eeef5ae/kernel-7/machdep/i386/kernBootStruct.h) which must have been on the missing NeXT sources that NeXT was selling).

Example code.
/*
 * compile with cc -o kbsread kbsread.c -DMISSING_HEADERS
 * Needs to be run as root. Thanks to Rhetorica for finding an example
 * No warranties given, use at your own risk. Can not be used to train AI
 */

#define DRIVER_PRIVATE
#include <bsd/sys/fcntl.h>
#include <libc.h>
#include <stdlib.h>
#include <stdio.h>
#if MISSING_HEADERS
#include "kernBootStruct.h"
#else
#include <machdep/i386/kernBootStruct.h>
#endif

KERNBOOTSTRUCT kernbootstruct;
void bomb(char *s1)
{
fprintf(stderr,s1);
exit(-1);
}

int main()
{
int kmfd;
if ((kmfd = open("/dev/kmem", O_RDONLY)) <0)
{
bomb("kbsread: can't get kernal boot structure or not root\n");
}
lseek(kmfd, (off_t)KERNSTRUCT_ADDR, L_SET);
read(kmfd, &kernbootstruct, sizeof(KERNBOOTSTRUCT)-CONFIG_SIZE);
if (kernbootstruct.magicCookie != KERNBOOTMAGIC)
{
bomb("kbsread: kernBootStruct invalid\n");
}
printf("kernBootStruct version %d\n",kernbootstruct.version);
printf("kbs number of boot drivers = %d\n",kernbootstruct.numBootDrivers);
printf("kbs grapics mode = %d\n", kernbootstruct.graphicsMode);
exit(0);
}

Go to top  Forum index