Changeset 32
- Timestamp:
- Jun 21, 2017, 11:34:09 AM (7 years ago)
- Location:
- trunk/hal/x86_64
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hal/x86_64/hal_boot.S
r29 r32 24 24 #define x86_ASM 25 25 #include <hal_boot.h> 26 #include <hal_multiboot.h> 26 27 #include <hal_register.h> 27 28 #include <hal_segmentation.h> … … 181 182 /* Warm boot */ 182 183 movw $0x1234,0x472 184 cld 183 185 184 186 /* Make sure it is a multiboot-compliant bootloader. */ 185 // cmpl $MULTIBOOT_INFO_MAGIC,%eax 186 // jne boot_panic 187 cmpl $MULTIBOOT_INFO_MAGIC,%eax 188 je 1f 189 ret /* what to do? */ 190 1: 187 191 188 192 movl $RELOC(tmpstk),%esp … … 192 196 popfl 193 197 198 /* 199 * Copy the various multiboot structures 200 */ 201 movl %ebx,%esi /* src */ 202 movl $RELOC(mb_info),%edi /* dst */ 203 movl $MULTIBOOT_INFO_SIZE,%ecx /* len */ 204 rep 205 movsb /* copy esi -> edi */ 206 207 testl $MULTIBOOT_INFO_HAS_LOADER_NAME,MB_MI_FLAGS(%ebx) 208 jz 1f 209 movl MB_MI_LOADER_NAME(%ebx),%esi /* src */ 210 movl $RELOC(mb_loader_name),%edi /* dst */ 211 copy_loop: 212 cmpb $0,(%esi) 213 je copy_end 214 movsb /* copy esi -> edi */ 215 jmp copy_loop 216 copy_end: 217 movsb /* copy esi -> edi */ 218 1: 219 220 testl $MULTIBOOT_INFO_HAS_MMAP,MB_MI_FLAGS(%ebx) 221 jz 1f 222 movl MB_MI_MMAP_ADDR(%ebx),%esi /* src */ 223 movl $RELOC(mb_mmap),%edi /* dst */ 224 movl MB_MI_MMAP_LENGTH(%ebx),%ecx /* len */ 225 226 rep 227 movsb /* copy esi -> edi */ 228 1: 229 194 230 /* 195 231 * There are four levels of pages in amd64: PML4 -> PDP -> PD -> PT. They will … … 197 233 * 198 234 * Virtual address space of the kernel: 199 * +---------------+------------+-----------------------------------+--- 200 * | TEXT + RODATA | DATA + BSS | L4 -> PROC0 STK -> L3 -> L2 -> L1 | 201 * +---------------+------------+-----------------------------------+--- 202 * (1) 203 * 204 * ---+-------------+ 205 * | ISA I/O MEM | 206 * ---+-------------+ 207 * (2) 235 * +---------------+------+-----------------------------------+-------------+ 236 * | TEXT + RODATA | DATA | L4 -> PROC0 STK -> L3 -> L2 -> L1 | ISA I/O MEM | 237 * +---------------+------+-----------------------------------+-------------+ 238 * (1) (2) 208 239 * 209 240 * PROC0 STK is obviously not linked as a page level. It just happens to be … … 215 246 * 216 247 * Important note: the kernel segments are properly 4k-aligned 217 * (see kern .ldscript), so there's no need to enforce alignment.248 * (see kernel_x86.ld), so there's no need to enforce alignment. 218 249 */ 219 250 … … 430 461 killkpt 431 462 432 /* Relocate atdevbase. */463 /* Save the virtual address of ISA I/O MEM. */ 433 464 movq $(TABLESIZE+KERNBASE),%rdx 434 465 addq %rsi,%rdx -
trunk/hal/x86_64/hal_init.c
r31 r32 22 22 #include <hal_types.h> 23 23 #include <hal_boot.h> 24 #include <hal_multiboot.h> 24 25 #include <hal_segmentation.h> 25 26 … … 39 40 void cpu_attach(); 40 41 41 /* -------------------------------------------------------------------------- */ 42 43 struct multiboot_info mb_info __in_kdata; 44 char mb_loader_name[PAGE_SIZE] __in_kdata; 45 uint8_t mb_mmap[PAGE_SIZE] __in_kdata; 46 47 #define offsetof(type, member) __builtin_offsetof(type, member) 48 49 50 /* -------------------------------------------------------------------------- */ 51 52 static void 53 dump_memmap() 54 { 55 size_t mmap_length = mb_info.mi_mmap_length; 56 uint8_t *mmap_addr = (uint8_t *)&mb_mmap; 57 size_t i; 58 59 if (!(mb_info.mi_flags & MULTIBOOT_INFO_HAS_MMAP)) 60 x86_printf("SHIT!!\n"); 61 62 i = 0; 63 while (i < mmap_length) { 64 struct multiboot_mmap *mm; 65 66 mm = (struct multiboot_mmap *)(mmap_addr + i); 67 68 x86_printf("-> [%Z, %Z] %s\n", mm->mm_base_addr, 69 mm->mm_base_addr + mm->mm_length, 70 (mm->mm_type == 1) ? "ram" : "rsv" ); 71 72 i += mm->mm_size + 4; 73 } 74 } 42 75 43 76 void init_x86_64(paddr_t firstpa) … … 46 79 47 80 extern uint64_t __kernel_end; 48 x86_printf("__kernel_end: % p\n", (void *)&__kernel_end);81 x86_printf("__kernel_end: %Z\n", (uint64_t)&__kernel_end); 49 82 50 83 /* Create the global structures */ … … 58 91 cpu_attach(); 59 92 x86_printf("[+] cpu_attach called\n"); 93 94 x86_printf("[+] bootloader: %s\n", mb_loader_name); 95 96 dump_memmap(); 97 98 x86_printf("[+] dump finished\n"); 60 99 61 100 char *buf = NULL; -
trunk/hal/x86_64/hal_types.h
r29 r32 35 35 #define __in_kdata __attribute__((section(".kdata"))) 36 36 37 38 37 /************************************************************************** 39 38 * Exact-width integer types. 40 39 **************************************************************************/ 41 40 42 typedef signed char int8_t;43 typedef unsigned char uint8_t;41 typedef signed char int8_t; 42 typedef unsigned char uint8_t; 44 43 45 44 typedef signed short int16_t; 46 45 typedef unsigned short uint16_t; 47 46 48 typedef signed long intint32_t;49 typedef unsigned long intuint32_t;47 typedef int int32_t; 48 typedef unsigned int uint32_t; 50 49 51 50 typedef signed long long int int64_t; … … 53 52 54 53 typedef uint64_t size_t; 54 55 typedef uint64_t vaddr_t; // XXX 55 56 56 57 /*************************************************************************** -
trunk/hal/x86_64/x86_printf.c
r31 r32 75 75 } 76 76 77 static void x86_ztoa(char *buf, uint64_t n, uint64_t base) 78 { 79 uint64_t tmp; 80 int i, j; 81 82 tmp = n; 83 i = 0; 84 85 do { 86 tmp = n % base; 87 buf[i++] = (tmp < 10) ? (tmp + '0') : (tmp + 'a' - 10); 88 } while (n /= base); 89 buf[i--] = 0; 90 91 for (j = 0; j < i; j++, i--) { 92 tmp = buf[j]; 93 buf[j] = buf[i]; 94 buf[i] = tmp; 95 } 96 } 97 77 98 void x86_printf(char *s, ...) 78 99 { … … 85 106 int ival; 86 107 unsigned int uival; 108 uint64_t zval; 87 109 88 110 va_start(ap, s); … … 101 123 } 102 124 103 if (c == 'd') { 125 if (c == 'z') { 126 zval = va_arg(ap, uint64_t); 127 x86_ztoa(buf, zval, 10); 128 129 buflen = strlen(buf); 130 if (buflen < size) 131 for (i = size, j = buflen; i >= 0; i--, j--) 132 buf[i] = (j >= 0) ? buf[j] : '0'; 133 134 x86_printf(buf); 135 } else if (c == 'Z') { 136 zval = va_arg(ap, uint64_t); 137 x86_ztoa(buf, zval, 16); 138 139 buflen = strlen(buf); 140 if (buflen < size) 141 for (i = size, j = buflen; i >= 0; i--, j--) 142 buf[i] = (j >= 0) ? buf[j] : '0'; 143 144 x86_printf("0x%s", buf); 145 } else if (c == 'd') { 104 146 ival = va_arg(ap, int); 105 147 if (ival < 0) {
Note: See TracChangeset
for help on using the changeset viewer.