One definition of several macros and constants

This commit is contained in:
Frans Kaashoek 2011-08-08 13:30:08 -04:00
parent 11b7438b10
commit a56c8d609b
7 changed files with 25 additions and 33 deletions

View file

@ -1,15 +1,12 @@
#include "asm.h" #include "asm.h"
#include "memlayout.h"
#include "mmu.h"
# Start the first CPU: switch to 32-bit protected mode, jump into C. # Start the first CPU: switch to 32-bit protected mode, jump into C.
# The BIOS loads this code from the first sector of the hard disk into # The BIOS loads this code from the first sector of the hard disk into
# memory at physical address 0x7c00 and starts executing in real mode # memory at physical address 0x7c00 and starts executing in real mode
# with %cs=0 %ip=7c00. # with %cs=0 %ip=7c00.
#define SEG_KCODE 1 // kernel code
#define SEG_KDATA 2 // kernel data+stack
#define CR0_PE 1 // protected mode enable bit
.code16 # Assemble for 16-bit mode .code16 # Assemble for 16-bit mode
.globl start .globl start
start: start:
@ -88,3 +85,4 @@ gdt:
gdtdesc: gdtdesc:
.word (gdtdesc - gdt - 1) # sizeof(gdt) - 1 .word (gdtdesc - gdt - 1) # sizeof(gdt) - 1
.long gdt # address gdt .long gdt # address gdt

View file

@ -1,5 +1,6 @@
#include "asm.h" #include "asm.h"
#include "memlayout.h" #include "memlayout.h"
#include "mmu.h"
# Each non-boot CPU ("AP") is started up in response to a STARTUP # Each non-boot CPU ("AP") is started up in response to a STARTUP
# IPI from the boot CPU. Section B.4.2 of the Multi-Processor # IPI from the boot CPU. Section B.4.2 of the Multi-Processor
@ -20,13 +21,6 @@
# - it uses the address at start-4 for the %esp # - it uses the address at start-4 for the %esp
# - it jumps to the address at start-8 instead of calling bootmain # - it jumps to the address at start-8 instead of calling bootmain
#define SEG_KCODE 1
#define SEG_KDATA 2
#define CR0_PE 1
#define RELOC1(x) ((x) + KERNBASE) // same as V2P, but without casts
.code16 .code16
.globl start .globl start
start: start:
@ -56,10 +50,10 @@ start32:
movw %ax, %gs movw %ax, %gs
# switch to the stack allocated by bootothers() # switch to the stack allocated by bootothers()
movl RELOC1(start-4), %esp movl P2V_WO(start-4), %esp
# call mpmain() # call mpmain()
call *(RELOC1(start)-8) call *(P2V_WO(start)-8)
movw $0x8a00, %ax movw $0x8a00, %ax
movw %ax, %dx movw %ax, %dx

View file

@ -9,7 +9,7 @@
#define IOSPACEE 0x100000 // end IO space #define IOSPACEE 0x100000 // end IO space
#define PHYSTOP 0xE000000 // use phys mem up to here as free pool #define PHYSTOP 0xE000000 // use phys mem up to here as free pool
// Key addresses for address space layout (see kmap in vm.c for the actual layout) // Key addresses for address space layout (see kmap in vm.c for the layout)
#define KERNBASE 0xF0000000 // First kernel virtual address #define KERNBASE 0xF0000000 // First kernel virtual address
#define USERTOP (KERNBASE-PGSIZE) // Highest user virtual address #define USERTOP (KERNBASE-PGSIZE) // Highest user virtual address
#define KERNLINK 0xF0100000 // Address where kernel is linked #define KERNLINK 0xF0100000 // Address where kernel is linked
@ -24,3 +24,5 @@ static inline void *p2v(uint a) { return (void *) a + KERNBASE; }
#define V2P(a) ((uint) a - KERNBASE) #define V2P(a) ((uint) a - KERNBASE)
#define P2V(a) ((void *) a + KERNBASE) #define P2V(a) ((void *) a + KERNBASE)
#define V2P_WO(x) ((x) - KERNBASE) // same as V2P, but without casts
#define P2V_WO(x) ((x) + KERNBASE) // same as V2P, but without casts

11
mmu.h
View file

@ -37,7 +37,15 @@
#define CR0_CD 0x40000000 // Cache Disable #define CR0_CD 0x40000000 // Cache Disable
#define CR0_PG 0x80000000 // Paging #define CR0_PG 0x80000000 // Paging
#define SEG_KCODE 1 // kernel code
#define SEG_KDATA 2 // kernel data+stack
#define SEG_KCPU 3 // kernel per-cpu data
#define SEG_UCODE 4 // user code
#define SEG_UDATA 5 // user data+stack
#define SEG_TSS 6 // this process's task state
//PAGEBREAK! //PAGEBREAK!
#ifndef __ASSEMBLER__
// Segment Descriptor // Segment Descriptor
struct segdesc { struct segdesc {
uint lim_15_0 : 16; // Low bits of segment limit uint lim_15_0 : 16; // Low bits of segment limit
@ -64,6 +72,7 @@ struct segdesc {
{ (lim) & 0xffff, (uint)(base) & 0xffff, \ { (lim) & 0xffff, (uint)(base) & 0xffff, \
((uint)(base) >> 16) & 0xff, type, 1, dpl, 1, \ ((uint)(base) >> 16) & 0xff, type, 1, dpl, 1, \
(uint)(lim) >> 16, 0, 0, 1, 0, (uint)(base) >> 24 } (uint)(lim) >> 16, 0, 0, 1, 0, (uint)(base) >> 24 }
#endif
#define DPL_USER 0x3 // User DPL #define DPL_USER 0x3 // User DPL
@ -130,6 +139,7 @@ struct segdesc {
// Address in page table or page directory entry // Address in page table or page directory entry
#define PTE_ADDR(pte) ((uint)(pte) & ~0xFFF) #define PTE_ADDR(pte) ((uint)(pte) & ~0xFFF)
#ifndef __ASSEMBLER__
typedef uint pte_t; typedef uint pte_t;
// Task state segment format // Task state segment format
@ -208,3 +218,4 @@ struct gatedesc {
(gate).off_31_16 = (uint)(off) >> 16; \ (gate).off_31_16 = (uint)(off) >> 16; \
} }
#endif

View file

@ -16,14 +16,10 @@
#include "asm.h" #include "asm.h"
#include "memlayout.h" #include "memlayout.h"
#include "mmu.h"
#define RELOC(x) ((x) - KERNBASE) // same as V2P, but without casts
#define STACK 4096 #define STACK 4096
#define SEG_KCODE 1 // kernel code
#define SEG_KDATA 2 // kernel data+stack
# Multiboot header. Data to direct multiboot loader. # Multiboot header. Data to direct multiboot loader.
.p2align 2 .p2align 2
.text .text
@ -45,7 +41,7 @@ multiboot_header:
# boot loader - bootasm.S - sets up. # boot loader - bootasm.S - sets up.
.globl multiboot_entry .globl multiboot_entry
multiboot_entry: multiboot_entry:
lgdt RELOC(gdtdesc) lgdt V2P_WO(gdtdesc)
ljmp $(SEG_KCODE<<3), $mbstart32 ljmp $(SEG_KCODE<<3), $mbstart32
mbstart32: mbstart32:
@ -73,6 +69,6 @@ gdt:
gdtdesc: gdtdesc:
.word (gdtdesc - gdt - 1) # sizeof(gdt) - 1 .word (gdtdesc - gdt - 1) # sizeof(gdt) - 1
.long RELOC(gdt) # address gdt .long V2P_WO(gdt) # address gdt
.comm stack, STACK .comm stack, STACK

7
proc.h
View file

@ -1,11 +1,4 @@
// Segments in proc->gdt. // Segments in proc->gdt.
// Also known to bootasm.S and trapasm.S
#define SEG_KCODE 1 // kernel code
#define SEG_KDATA 2 // kernel data+stack
#define SEG_KCPU 3 // kernel per-cpu data
#define SEG_UCODE 4 // user code
#define SEG_UDATA 5 // user data+stack
#define SEG_TSS 6 // this process's task state
#define NSEGS 7 #define NSEGS 7
// Per-CPU state // Per-CPU state

View file

@ -1,6 +1,4 @@
#define SEG_KCODE 1 // kernel code #include "mmu.h"
#define SEG_KDATA 2 // kernel data+stack
#define SEG_KCPU 3 // kernel per-cpu data
# vectors.S sends all traps here. # vectors.S sends all traps here.
.globl alltraps .globl alltraps