**********************************************************************/
#define SECTSIZE 512
-#define ELFHDR ((struct Elf *) 0x10000) // scratch space
+#define ELFHDR ((struct elfhdr *) 0x10000) // scratch space
void readsect(void*, uint32_t);
void readseg(uint32_t, uint32_t, uint32_t);
void
cmain(void)
{
- struct Proghdr *ph, *eph;
+ struct proghdr *ph, *eph;
// read 1st page off disk
readseg((uint32_t) ELFHDR, SECTSIZE*8, 0);
goto bad;
// load each program segment (ignores ph flags)
- ph = (struct Proghdr *) ((uint8_t *) ELFHDR + ELFHDR->phoff);
+ ph = (struct proghdr *) ((uint8_t *) ELFHDR + ELFHDR->phoff);
eph = ph + ELFHDR->phnum;
for (; ph < eph; ph++)
readseg(ph->va, ph->memsz, ph->offset);
#define ELF_MAGIC 0x464C457FU /* "\x7FELF" in little endian */
-struct Elf {
+struct elfhdr {
uint32_t magic; // must equal ELF_MAGIC
uint8_t elf[12];
uint16_t type;
uint16_t shstrndx;
};
-struct Proghdr {
+struct proghdr {
uint32_t type;
uint32_t offset;
uint32_t va;
p->mem = kalloc(p->sz);
memset(p->mem, 0, p->sz);
p->kstack = kalloc(KSTACKSIZE);
- p->tf = (struct Trapframe *) (p->kstack + KSTACKSIZE - sizeof(struct Trapframe));
- memset(p->tf, 0, sizeof(struct Trapframe));
+ p->tf = (struct trapframe *) (p->kstack + KSTACKSIZE - sizeof(struct trapframe));
+ memset(p->tf, 0, sizeof(struct trapframe));
p->tf->es = p->tf->ds = p->tf->ss = (SEG_UDATA << 3) | 3;
p->tf->cs = (SEG_UCODE << 3) | 3;
p->tf->eflags = FL_IF;
load_icode(struct proc *p, uint8_t *binary, uint size)
{
int i;
- struct Elf *elf;
- struct Proghdr *ph;
+ struct elfhdr *elf;
+ struct proghdr *ph;
// Check magic number on binary
- elf = (struct Elf*) binary;
+ elf = (struct elfhdr*) binary;
cprintf("elf %x magic %x\n", elf, elf->magic);
if (elf->magic != ELF_MAGIC)
panic("load_icode: not an ELF binary");
p->tf->esp = p->sz;
// Map and load segments as directed.
- ph = (struct Proghdr*) (binary + elf->phoff);
+ ph = (struct proghdr*) (binary + elf->phoff);
for (i = 0; i < elf->phnum; i++, ph++) {
if (ph->type != ELF_PROG_LOAD)
continue;
#else // not __ASSEMBLER__
// Segment Descriptors
-struct Segdesc {
+struct segdesc {
uint lim_15_0 : 16; // Low bits of segment limit
uint base_15_0 : 16; // Low bits of segment base address
uint base_23_16 : 8; // Middle bits of segment base address
uint base_31_24 : 8; // High bits of segment base address
};
// Null segment
-#define SEG_NULL (struct Segdesc){ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+#define SEG_NULL (struct segdesc){ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
// Segment that is loadable but faults when used
-#define SEG_FAULT (struct Segdesc){ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0 }
+#define SEG_FAULT (struct segdesc){ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0 }
// Normal segment
-#define SEG(type, base, lim, dpl) (struct Segdesc) \
+#define SEG(type, base, lim, dpl) (struct segdesc) \
{ ((lim) >> 12) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \
type, 1, dpl, 1, (uint) (lim) >> 28, 0, 0, 1, 1, \
(uint) (base) >> 24 }
-#define SEG16(type, base, lim, dpl) (struct Segdesc) \
+#define SEG16(type, base, lim, dpl) (struct segdesc) \
{ (lim) & 0xffff, (base) & 0xffff, ((base) >> 16) & 0xff, \
type, 1, dpl, 1, (uint) (lim) >> 16, 0, 0, 1, 0, \
(uint) (base) >> 24 }
#ifndef __ASSEMBLER__
// Task state segment format (as described by the Pentium architecture book)
-struct Taskstate {
+struct taskstate {
uint32_t link; // Old ts selector
uintptr_t esp0; // Stack pointers and segment selectors
uint16_t ss0; // after an increase in privilege level
};
// Gate descriptors for interrupts and traps
-struct Gatedesc {
+struct gatedesc {
uint off_15_0 : 16; // low 16 bits of offset in segment
uint ss : 16; // segment selector
uint args : 5; // # args, 0 for interrupt/trap gates
#define APBOOTCODE 0x7000 // XXX hack
-static struct MP* mp; // The MP floating point structure
+static struct mp* mp; // The MP floating point structure
struct cpu cpus[NCPU];
int ncpu;
static struct cpu *bcpu;
-static struct MP*
+static struct mp*
mp_scan(uint8_t *addr, int len)
{
uint8_t *e, *p, sum;
cprintf("scanning: 0x%x\n", (uint32_t)addr);
e = addr+len;
- for(p = addr; p < e; p += sizeof(struct MP)){
+ for(p = addr; p < e; p += sizeof(struct mp)){
if(memcmp(p, "_MP_", 4))
continue;
sum = 0;
- for(i = 0; i < sizeof(struct MP); i++)
+ for(i = 0; i < sizeof(struct mp); i++)
sum += p[i];
if(sum == 0)
- return (struct MP *)p;
+ return (struct mp *)p;
}
return 0;
}
-static struct MP*
+static struct mp*
mp_search(void)
{
uint8_t *bda;
uint32_t p;
- struct MP *mp;
+ struct mp *mp;
/*
* Search for the MP Floating Pointer Structure, which according to the
static int
mp_detect(void)
{
- struct MPCTB *pcmp;
+ struct mpctb *pcmp;
uint8_t *p, sum;
uint32_t length;
if((mp = mp_search()) == 0 || mp->physaddr == 0)
return 1;
- pcmp = (struct MPCTB *) mp->physaddr;
+ pcmp = (struct mpctb *) mp->physaddr;
if(memcmp(pcmp, "PCMP", 4))
return 2;
{
int r;
uint8_t *p, *e;
- struct MPCTB *mpctb;
- struct MPPE *proc;
- struct MPBE *bus;
+ struct mpctb *mpctb;
+ struct mppe *proc;
+ struct mpbe *bus;
int i;
ncpu = 0;
* application processors and initialising any I/O APICs. The table
* is guaranteed to be in order such that only one pass is necessary.
*/
- mpctb = (struct MPCTB *) mp->physaddr;
+ mpctb = (struct mpctb *) mp->physaddr;
lapicaddr = (uint32_t *) mpctb->lapicaddr;
cprintf("apicaddr: %x\n", lapicaddr);
- p = ((uint8_t*)mpctb)+sizeof(struct MPCTB);
+ p = ((uint8_t*)mpctb)+sizeof(struct mpctb);
e = ((uint8_t*)mpctb)+mpctb->length;
while(p < e) {
switch(*p){
case MPPROCESSOR:
- proc = (struct MPPE *) p;
+ proc = (struct mppe *) p;
cpus[ncpu].apicid = proc->apicid;
cprintf("a processor %x\n", cpus[ncpu].apicid);
if (proc->flags & MPBP) {
bcpu = &cpus[ncpu];
}
ncpu++;
- p += sizeof(struct MPPE);
+ p += sizeof(struct mppe);
continue;
case MPBUS:
- bus = (struct MPBE *) p;
+ bus = (struct mpbe *) p;
for(i = 0; buses[i]; i++){
if(strncmp(buses[i], bus->string, sizeof(bus->string)) == 0)
break;
}
cprintf("a bus %d\n", i);
- p += sizeof(struct MPBE);
+ p += sizeof(struct mpbe);
continue;
case MPIOAPIC:
cprintf("an I/O APIC\n");
- p += sizeof(struct MPIOAPIC);
+ p += sizeof(struct mpioapic);
continue;
case MPIOINTR:
cprintf("an I/O intr\n");
- p += sizeof(struct MPIE);
+ p += sizeof(struct mpie);
continue;
default:
cprintf("mpinit: unknown PCMP type 0x%x (e-p 0x%x)\n", *p, e-p);
* Credit: Plan 9 sources
*/
-struct MP { /* floating pointer */
+struct mp { /* floating pointer */
uint8_t signature[4]; /* "_MP_" */
physaddr_t physaddr; /* physical address of MP configuration table */
uint8_t length; /* 1 */
uint8_t reserved[3];
};
-struct MPCTB { /* configuration table header */
+struct mpctb { /* configuration table header */
uint8_t signature[4]; /* "PCMP" */
uint16_t length; /* total table length */
uint8_t version; /* [14] */
uint8_t reserved;
};
-struct MPPE { /* processor table entry */
+struct mppe { /* processor table entry */
uint8_t type; /* entry type (0) */
uint8_t apicid; /* local APIC id */
uint8_t version; /* local APIC verison */
uint8_t reserved[8];
};
-struct MPBE { /* bus table entry */
+struct mpbe { /* bus table entry */
uint8_t type; /* entry type (1) */
uint8_t busno; /* bus id */
char string[6]; /* bus type string */
};
-struct MPIOAPIC { /* I/O APIC table entry */
+struct mpioapic { /* I/O APIC table entry */
uint8_t type; /* entry type (2) */
uint8_t apicno; /* I/O APIC id */
uint8_t version; /* I/O APIC version */
uintptr_t addr; /* I/O APIC address */
};
-struct MPIE { /* interrupt table entry */
+struct mpie { /* interrupt table entry */
uint8_t type; /* entry type ([34]) */
uint8_t intr; /* interrupt type */
uint16_t flags; /* interrupt flag */
struct proc *curproc[NCPU];
int next_pid = 1;
extern void forkret(void);
-extern void forkret1(struct Trapframe*);
+extern void forkret1(struct trapframe*);
/*
* set up a process's task state and segment descriptors
void
setupsegs(struct proc *p)
{
- memset(&p->ts, 0, sizeof(struct Taskstate));
+ memset(&p->ts, 0, sizeof(struct taskstate));
p->ts.ss0 = SEG_KDATA << 3;
p->ts.esp0 = (uint)(p->kstack + KSTACKSIZE);
setupsegs(np);
// Copy trapframe registers from parent.
- np->tf = (struct Trapframe*)(np->kstack + KSTACKSIZE) - 1;
+ np->tf = (struct trapframe*)(np->kstack + KSTACKSIZE) - 1;
*np->tf = *p->tf;
// Clear %eax so that fork system call returns 0 in child.
int killed;
struct fd *fds[NOFILE];
- struct Taskstate ts; // only to give cpu address of kernel stack
- struct Segdesc gdt[NSEGS];
+ struct taskstate ts; // only to give cpu address of kernel stack
+ struct segdesc gdt[NSEGS];
uint esp; // kernel stack pointer
uint ebp; // kernel frame pointer
struct jmpbuf jmpbuf;
- struct Trapframe *tf; // points into kstack, used to find user regs
+ struct trapframe *tf; // points into kstack, used to find user regs
};
extern struct proc proc[];
#include "traps.h"
#include "syscall.h"
-struct Gatedesc idt[256];
+struct gatedesc idt[256];
extern uint vectors[]; /* vectors.S, array of 256 entry point addresses */
extern void trapenter(void);
}
void
-trap(struct Trapframe *tf)
+trap(struct trapframe *tf)
{
int v = tf->trapno;
static __inline void outsl(int port, const void *addr, int cnt) __attribute__((always_inline));
static __inline void outl(int port, uint32_t data) __attribute__((always_inline));
static __inline void invlpg(void *addr) __attribute__((always_inline));
-struct Segdesc;
-static __inline void lgdt(struct Segdesc *p, int) __attribute__((always_inline));
-struct Gatedesc;
-static __inline void lidt(struct Gatedesc *p, int) __attribute__((always_inline));
+struct segdesc;
+static __inline void lgdt(struct segdesc *p, int) __attribute__((always_inline));
+struct gatedesc;
+static __inline void lidt(struct gatedesc *p, int) __attribute__((always_inline));
static __inline void lldt(uint16_t sel) __attribute__((always_inline));
static __inline void ltr(uint16_t sel) __attribute__((always_inline));
static __inline void lcr0(uint32_t val) __attribute__((always_inline));
}
static __inline void
-lgdt(struct Segdesc *p, int size)
+lgdt(struct segdesc *p, int size)
{
volatile uint16_t pd[3];
}
static __inline void
-lidt(struct Gatedesc *p, int size)
+lidt(struct gatedesc *p, int size)
{
volatile uint16_t pd[3];
__asm__ volatile("sti");
}
-struct Trapframe {
+struct trapframe {
/* registers as pushed by pusha */
uint32_t edi;
uint32_t esi;