Advertisement
Guest User

xen-multiboot2-v2-masked-emails.patch

a guest
Aug 16th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 113.56 KB | None | 0 0
  1. diff -Naur xen-9999-bef/.gitignore xen-9999-aft/.gitignore
  2. --- xen-9999-bef/.gitignore 2015-08-16 08:29:52.832771173 +0300
  3. +++ xen-9999-aft/.gitignore 2015-08-16 08:30:57.832765013 +0300
  4. @@ -224,9 +224,10 @@
  5.  xen/arch/x86/asm-offsets.s
  6.  xen/arch/x86/boot/mkelf32
  7.  xen/arch/x86/xen.lds
  8. +xen/arch/x86/boot/cmdline.S
  9.  xen/arch/x86/boot/reloc.S
  10. -xen/arch/x86/boot/reloc.bin
  11. -xen/arch/x86/boot/reloc.lnk
  12. +xen/arch/x86/boot/*.bin
  13. +xen/arch/x86/boot/*.lnk
  14.  xen/arch/x86/efi.lds
  15.  xen/arch/x86/efi/check.efi
  16.  xen/arch/x86/efi/disabled
  17. diff -Naur xen-9999-bef/xen/arch/x86/boot/build32.mk xen-9999-aft/xen/arch/x86/boot/build32.mk
  18. --- xen-9999-bef/xen/arch/x86/boot/build32.mk   2015-08-16 08:29:52.975771160 +0300
  19. +++ xen-9999-aft/xen/arch/x86/boot/build32.mk   2015-08-16 08:32:12.234757961 +0300
  20. @@ -13,7 +13,7 @@
  21.     sed 's/ /,0x/g' | sed 's/,0x$$//' | sed 's/^[0-9]*,/ .long /') >$@
  22.  
  23.  %.bin: %.lnk
  24. -   $(OBJCOPY) -O binary $< $@
  25. +   $(OBJCOPY) -O binary -j .text $< $@
  26.  
  27.  %.lnk: %.o
  28.     $(LD) $(LDFLAGS_DIRECT) -N -Ttext 0 -o $@ $<
  29. @@ -30,6 +30,8 @@
  30.             esac; \
  31.         done
  32.  
  33. +cmdline.o: cmdline.c $(CMDLINE_DEPS)
  34. +
  35.  reloc.o: reloc.c $(RELOC_DEPS)
  36.  
  37.  .PRECIOUS: %.bin %.lnk
  38. diff -Naur xen-9999-bef/xen/arch/x86/boot/cmdline.c xen-9999-aft/xen/arch/x86/boot/cmdline.c
  39. --- xen-9999-bef/xen/arch/x86/boot/cmdline.c    1970-01-01 02:00:00.000000000 +0200
  40. +++ xen-9999-aft/xen/arch/x86/boot/cmdline.c    2015-08-16 08:30:57.833765013 +0300
  41. @@ -0,0 +1,396 @@
  42. +/*
  43. + * Copyright (c) 2015 Oracle Co.
  44. + *      Daniel Kiper <daniel.kiper@xxxxxxxxxx>
  45. + *
  46. + * This program is free software; you can redistribute it and/or modify
  47. + * it under the terms of the GNU General Public License as published by
  48. + * the Free Software Foundation; either version 2 of the License, or
  49. + * (at your option) any later version.
  50. + *
  51. + * This program is distributed in the hope that it will be useful,
  52. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  53. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  54. + * GNU General Public License for more details.
  55. + *
  56. + * You should have received a copy of the GNU General Public License along
  57. + * with this program.  If not, see <http://www.gnu.org/licenses/>.
  58. + *
  59. + * strlen(), strncmp(), strspn() and strcspn() were copied from
  60. + * Linux kernel source (linux/lib/string.c).
  61. + *
  62. + * max() was copied from xen/xen/include/xen/kernel.h.
  63. + *
  64. + */
  65. +
  66. +/*
  67. + * This entry point is entered from xen/arch/x86/boot/head.S with:
  68. + *   - 0x4(%esp) = &cmdline,
  69. + *   - 0x8(%esp) = &early_boot_opts.
  70. + */
  71. +asm (
  72. +    "    .text                         \n"
  73. +    "    .globl _start                 \n"
  74. +    "_start:                           \n"
  75. +    "    jmp  cmdline_parse_early      \n"
  76. +    );
  77. +
  78. +#include "video.h"
  79. +
  80. +#define VESA_WIDTH     0
  81. +#define VESA_HEIGHT    1
  82. +#define VESA_DEPTH     2
  83. +
  84. +#define VESA_SIZE      3
  85. +
  86. +#define NULL   ((void *)0)
  87. +
  88. +#define __cdecl                __attribute__((__cdecl__))
  89. +#define __packed       __attribute__((__packed__))
  90. +#define __text         __attribute__((__section__(".text")))
  91. +#define __used         __attribute__((__used__))
  92. +
  93. +#define max(x,y) ({ \
  94. +        const typeof(x) _x = (x);       \
  95. +        const typeof(y) _y = (y);       \
  96. +        (void) (&_x == &_y);            \
  97. +        _x > _y ? _x : _y; })
  98. +
  99. +#define tolower(c) ((c) | 0x20)
  100. +
  101. +#define strlen_static(s) (sizeof(s) - 1)
  102. +
  103. +typedef unsigned char u8;
  104. +typedef unsigned short u16;
  105. +typedef unsigned int size_t;
  106. +
  107. +#define U16_MAX        ((u16)(~0U))
  108. +
  109. +/*
  110. + * Keep in sync with trampoline.S:early_boot_opts label!
  111. + */
  112. +typedef struct __packed {
  113. +    u8 skip_realmode;
  114. +    u8 opt_edd;
  115. +    u8 opt_edid;
  116. +    u16 boot_vid_mode;
  117. +    u16 vesa_size[VESA_SIZE];
  118. +} early_boot_opts_t;
  119. +
  120. +static const char empty_chars[] __text = " \n\r\t";
  121. +
  122. +/**
  123. + * strlen - Find the length of a string
  124. + * @s: The string to be sized
  125. + */
  126. +static size_t strlen(const char *s)
  127. +{
  128. +    const char *sc;
  129. +
  130. +    for ( sc = s; *sc != '\0'; ++sc )
  131. +        /* nothing */;
  132. +    return sc - s;
  133. +}
  134. +
  135. +/**
  136. + * strncmp - Compare two length-limited strings
  137. + * @cs: One string
  138. + * @ct: Another string
  139. + * @count: The maximum number of bytes to compare
  140. + */
  141. +static int strncmp(const char *cs, const char *ct, size_t count)
  142. +{
  143. +    unsigned char c1, c2;
  144. +
  145. +    while ( count )
  146. +    {
  147. +        c1 = *cs++;
  148. +        c2 = *ct++;
  149. +        if ( c1 != c2 )
  150. +            return c1 < c2 ? -1 : 1;
  151. +        if ( !c1 )
  152. +            break;
  153. +        count--;
  154. +    }
  155. +    return 0;
  156. +}
  157. +
  158. +/**
  159. + * strspn - Calculate the length of the initial substring of @s which only contain letters in @accept
  160. + * @s: The string to be searched
  161. + * @accept: The string to search for
  162. + */
  163. +static size_t strspn(const char *s, const char *accept)
  164. +{
  165. +    const char *p;
  166. +    const char *a;
  167. +    size_t count = 0;
  168. +
  169. +    for ( p = s; *p != '\0'; ++p )
  170. +    {
  171. +        for ( a = accept; *a != '\0'; ++a )
  172. +        {
  173. +            if ( *p == *a )
  174. +                break;
  175. +        }
  176. +        if ( *a == '\0' )
  177. +            return count;
  178. +        ++count;
  179. +    }
  180. +    return count;
  181. +}
  182. +
  183. +/**
  184. + * strcspn - Calculate the length of the initial substring of @s which does not contain letters in @reject
  185. + * @s: The string to be searched
  186. + * @reject: The string to avoid
  187. + */
  188. +static size_t strcspn(const char *s, const char *reject)
  189. +{
  190. +    const char *p;
  191. +    const char *r;
  192. +    size_t count = 0;
  193. +
  194. +    for ( p = s; *p != '\0'; ++p )
  195. +    {
  196. +        for ( r = reject; *r != '\0'; ++r )
  197. +        {
  198. +            if ( *p == *r )
  199. +                return count;
  200. +        }
  201. +        ++count;
  202. +    }
  203. +    return count;
  204. +}
  205. +
  206. +static int strtoi(const char *s, const char *stop, const char **next)
  207. +{
  208. +    int base = 10, i, ores = 0, res = 0;
  209. +
  210. +    if ( *s == '0' )
  211. +      base = (tolower(*++s) == 'x') ? (++s, 16) : 8;
  212. +
  213. +    for ( ; *s != '\0'; ++s )
  214. +    {
  215. +        for ( i = 0; stop && stop[i] != '\0'; ++i )
  216. +            if ( *s == stop[i] )
  217. +                goto out;
  218. +
  219. +        if ( *s < '0' || (*s > '7' && base == 8) )
  220. +        {
  221. +            res = -1;
  222. +            goto out;
  223. +        }
  224. +
  225. +        if ( *s > '9' && (base != 16 || tolower(*s) < 'a' || tolower(*s) > 'f') )
  226. +        {
  227. +            res = -1;
  228. +            goto out;
  229. +        }
  230. +
  231. +        res *= base;
  232. +        res += (tolower(*s) >= 'a') ? (tolower(*s) - 'a' + 10) : (*s - '0');
  233. +
  234. +        if ( ores > res )
  235. +        {
  236. +            res = -1;
  237. +            goto out;
  238. +        }
  239. +
  240. +        ores = res;
  241. +    }
  242. +
  243. +out:
  244. +    if ( next )
  245. +      *next = s;
  246. +
  247. +    return res;
  248. +}
  249. +
  250. +static const char *find_opt(const char *cmdline, const char *opt, int arg)
  251. +{
  252. +    size_t lc, lo;
  253. +    static const char mm[] __text = "--";
  254. +
  255. +    lo = strlen(opt);
  256. +
  257. +    for ( ; ; )
  258. +    {
  259. +        cmdline += strspn(cmdline, empty_chars);
  260. +
  261. +        if ( *cmdline == '\0' )
  262. +            return NULL;
  263. +
  264. +        lc = strcspn(cmdline, empty_chars);
  265. +
  266. +        if ( !strncmp(cmdline, mm, max(lc, strlen_static(mm))) )
  267. +            return NULL;
  268. +
  269. +        if ( !strncmp(cmdline, opt, arg ? lo : max(lc, lo)) )
  270. +            return cmdline;
  271. +
  272. +        cmdline += lc;
  273. +    }
  274. +}
  275. +
  276. +static u8 skip_realmode(const char *cmdline)
  277. +{
  278. +    static const char nrm[] __text = "no-real-mode";
  279. +    static const char tboot[] __text = "tboot=";
  280. +
  281. +    if ( find_opt(cmdline, nrm, 0) || find_opt(cmdline, tboot, 1) )
  282. +        return 1;
  283. +
  284. +    return 0;
  285. +}
  286. +
  287. +static u8 edd_parse(const char *cmdline)
  288. +{
  289. +    const char *c;
  290. +    size_t la;
  291. +    static const char edd[] __text = "edd=";
  292. +    static const char edd_off[] __text = "off";
  293. +    static const char edd_skipmbr[] __text = "skipmbr";
  294. +
  295. +    c = find_opt(cmdline, edd, 1);
  296. +
  297. +    if ( !c )
  298. +        return 0;
  299. +
  300. +    c += strlen_static(edd);
  301. +    la = strcspn(c, empty_chars);
  302. +
  303. +    if ( !strncmp(c, edd_off, max(la, strlen_static(edd_off))) )
  304. +        return 2;
  305. +    else if ( !strncmp(c, edd_skipmbr, max(la, strlen_static(edd_skipmbr))) )
  306. +        return 1;
  307. +
  308. +    return 0;
  309. +}
  310. +
  311. +static u8 edid_parse(const char *cmdline)
  312. +{
  313. +    const char *c;
  314. +    size_t la;
  315. +    static const char edid[] __text = "edid=";
  316. +    static const char edid_force[] __text = "force";
  317. +    static const char edid_no[] __text = "no";
  318. +
  319. +    c = find_opt(cmdline, edid, 1);
  320. +
  321. +    if ( !c )
  322. +        return 0;
  323. +
  324. +    c += strlen_static(edid);
  325. +    la = strcspn(c, empty_chars);
  326. +
  327. +    if ( !strncmp(c, edid_no, max(la, strlen_static(edid_no))) )
  328. +        return 1;
  329. +    else if ( !strncmp(c, edid_force, max(la, strlen_static(edid_force))) )
  330. +        return 2;
  331. +
  332. +    return 0;
  333. +}
  334. +
  335. +static u16 rows2vmode(int rows)
  336. +{
  337. +    switch ( rows )
  338. +    {
  339. +    case 25:
  340. +        return VIDEO_80x25;
  341. +
  342. +    case 28:
  343. +        return VIDEO_80x28;
  344. +
  345. +    case 30:
  346. +        return VIDEO_80x30;
  347. +
  348. +    case 34:
  349. +        return VIDEO_80x34;
  350. +
  351. +    case 43:
  352. +        return VIDEO_80x43;
  353. +
  354. +    case 50:
  355. +        return VIDEO_80x50;
  356. +
  357. +    case 60:
  358. +        return VIDEO_80x60;
  359. +
  360. +    default:
  361. +        return ASK_VGA;
  362. +    }
  363. +}
  364. +
  365. +static void vga_parse(const char *cmdline, early_boot_opts_t *ebo)
  366. +{
  367. +    const char *c;
  368. +    int tmp;
  369. +    size_t la;
  370. +    static const char empty_chars_comma[] __text = " \n\r\t,";
  371. +    static const char x[] __text = "x";
  372. +    static const char vga[] __text = "vga=";
  373. +    static const char vga_current[] __text = "current";
  374. +    static const char vga_gfx[] __text = "gfx-";
  375. +    static const char vga_mode[] __text = "mode-";
  376. +    static const char vga_text_80x[] __text = "text-80x";
  377. +
  378. +    c = find_opt(cmdline, vga, 1);
  379. +
  380. +    if ( !c )
  381. +        return;
  382. +
  383. +    ebo->boot_vid_mode = ASK_VGA;
  384. +
  385. +    c += strlen_static(vga);
  386. +    la = strcspn(c, empty_chars_comma);
  387. +
  388. +    if ( !strncmp(c, vga_current, max(la, strlen_static(vga_current))) )
  389. +        ebo->boot_vid_mode = VIDEO_CURRENT_MODE;
  390. +    else if ( !strncmp(c, vga_text_80x, strlen_static(vga_text_80x)) )
  391. +    {
  392. +        c += strlen_static(vga_text_80x);
  393. +        ebo->boot_vid_mode = rows2vmode(strtoi(c, empty_chars_comma, NULL));
  394. +    }
  395. +    else if ( !strncmp(c, vga_gfx, strlen_static(vga_gfx)) )
  396. +    {
  397. +        tmp = strtoi(c + strlen_static(vga_gfx), x, &c);
  398. +
  399. +        if ( tmp < 0 || tmp > U16_MAX )
  400. +            return;
  401. +
  402. +        ebo->vesa_size[VESA_WIDTH] = tmp;
  403. +
  404. +        tmp = strtoi(++c, x, &c);
  405. +
  406. +        if ( tmp < 0 || tmp > U16_MAX )
  407. +            return;
  408. +
  409. +        ebo->vesa_size[VESA_HEIGHT] = tmp;
  410. +
  411. +        tmp = strtoi(++c, empty_chars_comma, NULL);
  412. +
  413. +        if ( tmp < 0 || tmp > U16_MAX )
  414. +            return;
  415. +
  416. +        ebo->vesa_size[VESA_DEPTH] = tmp;
  417. +
  418. +        ebo->boot_vid_mode = VIDEO_VESA_BY_SIZE;
  419. +    }
  420. +    else if ( !strncmp(c, vga_mode, strlen_static(vga_mode)) )
  421. +    {
  422. +        tmp = strtoi(c + strlen_static(vga_mode), empty_chars_comma, NULL);
  423. +
  424. +        if ( tmp < 0 || tmp > U16_MAX )
  425. +            return;
  426. +
  427. +        ebo->boot_vid_mode = tmp;
  428. +    }
  429. +}
  430. +
  431. +static void __cdecl __used cmdline_parse_early(const char *cmdline, early_boot_opts_t *ebo)
  432. +{
  433. +    ebo->skip_realmode = skip_realmode(cmdline);
  434. +    ebo->opt_edd = edd_parse(cmdline);
  435. +    ebo->opt_edid = edid_parse(cmdline);
  436. +    vga_parse(cmdline, ebo);
  437. +}
  438. diff -Naur xen-9999-bef/xen/arch/x86/boot/cmdline.S xen-9999-aft/xen/arch/x86/boot/cmdline.S
  439. --- xen-9999-bef/xen/arch/x86/boot/cmdline.S    2015-08-16 08:29:52.975771160 +0300
  440. +++ xen-9999-aft/xen/arch/x86/boot/cmdline.S    1970-01-01 02:00:00.000000000 +0200
  441. @@ -1,367 +0,0 @@
  442. -/******************************************************************************
  443. - * cmdline.S
  444. - *
  445. - * Early command-line parsing.
  446. - */
  447. -
  448. -        .code32
  449. -
  450. -#include "video.h"
  451. -
  452. -# NB. String pointer on stack is modified to point past parsed digits.
  453. -.Latoi:
  454. -        push    %ebx
  455. -        push    %ecx
  456. -        push    %edx
  457. -        push    %esi
  458. -        xor     %ebx,%ebx       /* %ebx = accumulator */
  459. -        mov     $10,%ecx        /* %ecx = base (default base 10) */
  460. -        mov     16+4(%esp),%esi /* %esi = pointer into ascii string. */
  461. -        lodsb
  462. -        cmpb    $'0',%al
  463. -        jne     2f
  464. -        mov     $8,%ecx         /* Prefix '0' => octal (base 8) */
  465. -        lodsb
  466. -        cmpb    $'x',%al
  467. -        jne     2f
  468. -        mov     $16,%ecx        /* Prefix '0x' => hex (base 16) */
  469. -1:      lodsb
  470. -2:      sub     $'0',%al
  471. -        jb      4f
  472. -        cmp     $9,%al
  473. -        jbe     3f
  474. -        sub     $'A'-'0'-10,%al
  475. -        jb      4f
  476. -        cmp     $15,%al
  477. -        jbe     3f
  478. -        sub     $'a'-'A',%al
  479. -        jb      4f
  480. -3:      cmp     %cl,%al
  481. -        jae     4f
  482. -        movzbl  %al,%eax
  483. -        xchg    %eax,%ebx
  484. -        mul     %ecx
  485. -        xchg    %eax,%ebx
  486. -        add     %eax,%ebx
  487. -        jmp     1b
  488. -4:      mov     %ebx,%eax
  489. -        dec     %esi
  490. -        mov     %esi,16+4(%esp)
  491. -        pop     %esi
  492. -        pop     %edx
  493. -        pop     %ecx
  494. -        pop     %ebx
  495. -        ret
  496. -
  497. -.Lstrstr:
  498. -        push    %ecx
  499. -        push    %edx
  500. -        push    %esi
  501. -        push    %edi
  502. -        xor     %eax,%eax
  503. -        xor     %ecx,%ecx
  504. -        not     %ecx
  505. -        mov     16+4(%esp),%esi
  506. -        mov     16+8(%esp),%edi
  507. -        repne   scasb
  508. -        not     %ecx
  509. -        dec     %ecx
  510. -        mov     %ecx,%edx
  511. -1:      mov     16+8(%esp),%edi
  512. -        mov     %esi,%eax
  513. -        mov     %edx,%ecx
  514. -        repe    cmpsb
  515. -        je      2f
  516. -        xchg    %eax,%esi
  517. -        inc     %esi
  518. -        cmpb    $0,-1(%eax)
  519. -        jne     1b
  520. -        xor     %eax,%eax
  521. -2:      pop     %edi
  522. -        pop     %esi
  523. -        pop     %edx
  524. -        pop     %ecx
  525. -        ret
  526. -
  527. -.Lstr_prefix:
  528. -        push    %esi
  529. -        push    %edi
  530. -        mov     8+4(%esp),%esi /* 1st arg is prefix string */
  531. -        mov     8+8(%esp),%edi /* 2nd arg is main string */
  532. -1:      lodsb
  533. -        test    %al,%al
  534. -        jz      2f
  535. -        scasb
  536. -        je      1b
  537. -        sbb     %eax,%eax
  538. -        or      $1,%al
  539. -        jmp     3f
  540. -2:      xor     %eax,%eax
  541. -3:      pop     %edi
  542. -        pop     %esi
  543. -        ret
  544. -
  545. -.Lstrlen:
  546. -        push    %ecx
  547. -        push    %esi
  548. -        push    %edi
  549. -        xor     %eax,%eax
  550. -        xor     %ecx,%ecx
  551. -        not     %ecx
  552. -        mov     12+4(%esp),%edi
  553. -        repne   scasb
  554. -        not     %ecx
  555. -        dec     %ecx
  556. -        mov     %ecx,%eax
  557. -        pop     %edi
  558. -        pop     %esi
  559. -        pop     %ecx
  560. -        ret
  561. -
  562. -.Lfind_option:
  563. -        mov     4(%esp),%eax
  564. -        dec     %eax
  565. -        push    %ebx
  566. -1:      pushl   4+8(%esp)
  567. -        inc     %eax
  568. -        push    %eax
  569. -        call    .Lstrstr
  570. -        add     $8,%esp
  571. -        test    %eax,%eax
  572. -        jz      3f
  573. -        cmp     %eax,4+4(%esp)
  574. -        je      2f
  575. -        cmpb    $' ',-1(%eax)
  576. -        jne     1b
  577. -2:      mov     %eax,%ebx
  578. -        pushl   4+8(%esp)
  579. -        call    .Lstrlen
  580. -        add     $4,%esp
  581. -        xadd    %eax,%ebx
  582. -        /* NUL check (as $'\0' == 0x30 in GAS) */
  583. -        cmpb    $0,(%ebx)
  584. -        je      3f
  585. -        cmpb    $' ',(%ebx)
  586. -        je      3f
  587. -        cmpb    $'=',(%ebx)
  588. -        jne     1b
  589. -3:      pop     %ebx
  590. -        ret
  591. -
  592. -cmdline_parse_early:
  593. -        pusha
  594. -
  595. -        /* Bail if there is no command line to parse. */
  596. -        mov     sym_phys(multiboot_ptr),%ebx
  597. -        mov     MB_flags(%ebx),%eax
  598. -        test    $4,%al
  599. -        jz      .Lcmdline_exit
  600. -        mov     MB_cmdline(%ebx),%eax
  601. -        test    %eax,%eax
  602. -        jz      .Lcmdline_exit
  603. -
  604. -        /* Check for 'no-real-mode' command-line option. */
  605. -        pushl   $sym_phys(.Lno_rm_opt)
  606. -        pushl   MB_cmdline(%ebx)
  607. -        call    .Lfind_option
  608. -        test    %eax,%eax
  609. -        setnz   %al
  610. -        or      %al,sym_phys(skip_realmode)
  611. -
  612. -        /* Check for 'tboot=' command-line option. */
  613. -        movl    $sym_phys(.Ltboot_opt),4(%esp)
  614. -        call    .Lfind_option
  615. -        test    %eax,%eax
  616. -        setnz   %al
  617. -        or      %al,sym_phys(skip_realmode) /* tboot= implies no-real-mode */
  618. -
  619. -.Lparse_edd:
  620. -        /* Check for 'edd=' command-line option. */
  621. -        movl    $sym_phys(.Ledd_opt),4(%esp)
  622. -        call    .Lfind_option
  623. -        test    %eax,%eax
  624. -        jz      .Lparse_edid
  625. -        cmpb    $'=',3(%eax)
  626. -        jne     .Lparse_edid
  627. -        add     $4,%eax
  628. -        movb    $2,sym_phys(opt_edd)  /* opt_edd=2: edd=off */
  629. -        cmpw    $0x666f,(%eax)            /* 0x666f == "of" */
  630. -        je      .Lparse_edid
  631. -        decb    sym_phys(opt_edd)     /* opt_edd=1: edd=skipmbr */
  632. -        cmpw    $0x6b73,(%eax)            /* 0x6b73 == "sk" */
  633. -        je      .Lparse_edid
  634. -        decb    sym_phys(opt_edd)     /* opt_edd=0: edd=on (default) */
  635. -
  636. -.Lparse_edid:
  637. -        /* Check for 'edid=' command-line option. */
  638. -        movl    $sym_phys(.Ledid_opt),4(%esp)
  639. -        call    .Lfind_option
  640. -        test    %eax,%eax
  641. -        jz      .Lparse_vga
  642. -        cmpb    $'=',4(%eax)
  643. -        jne     .Lparse_vga
  644. -        add     $5,%eax
  645. -        mov     %eax,%ebx
  646. -        push    %ebx
  647. -        pushl   $sym_phys(.Ledid_force)
  648. -        call    .Lstr_prefix
  649. -        add     $8,%esp
  650. -        movb    $2,sym_phys(opt_edid) /* opt_edid=2: edid=force */
  651. -        test    %eax,%eax
  652. -        jz      .Lparse_vga
  653. -        push    %ebx
  654. -        pushl   $sym_phys(.Ledid_no)
  655. -        call    .Lstr_prefix
  656. -        add     $8,%esp
  657. -        decb    sym_phys(opt_edid)    /* opt_edid=1: edid=no */
  658. -        test    %eax,%eax
  659. -        jz      .Lparse_vga
  660. -        decb    sym_phys(opt_edid)    /* opt_edid=0: default */
  661. -
  662. -.Lparse_vga:
  663. -        /* Check for 'vga=' command-line option. */
  664. -        movl    $sym_phys(.Lvga_opt),4(%esp)
  665. -        call    .Lfind_option
  666. -        add     $8,%esp
  667. -        test    %eax,%eax
  668. -        jz      .Lcmdline_exit
  669. -        cmpb    $'=',3(%eax)
  670. -        jne     .Lcmdline_exit
  671. -        add     $4,%eax
  672. -
  673. -        /* Found the 'vga=' option. Default option is to display vga menu. */
  674. -        movw    $ASK_VGA,sym_phys(boot_vid_mode)
  675. -
  676. -        /* Check for 'vga=text-80x<rows>. */
  677. -        mov     %eax,%ebx
  678. -        push    %ebx
  679. -        pushl   $sym_phys(.Lvga_text80)
  680. -        call    .Lstr_prefix
  681. -        add     $8,%esp
  682. -        test    %eax,%eax
  683. -        jnz     .Lparse_vga_gfx
  684. -
  685. -        /* We have 'vga=text-80x<rows>'. */
  686. -        add     $8,%ebx
  687. -        push    %ebx
  688. -        call    .Latoi
  689. -        add     $4,%esp
  690. -        mov     %ax,%bx
  691. -        lea     sym_phys(.Lvga_text_modes),%esi
  692. -1:      lodsw
  693. -        test    %ax,%ax
  694. -        jz      .Lcmdline_exit
  695. -        cmp     %ax,%bx
  696. -        lodsw
  697. -        jne     1b
  698. -        mov     %ax,sym_phys(boot_vid_mode)
  699. -        jmp     .Lcmdline_exit
  700. -
  701. -.Lparse_vga_gfx:
  702. -        /* Check for 'vga=gfx-<width>x<height>x<depth>'. */
  703. -        push    %ebx
  704. -        pushl   $sym_phys(.Lvga_gfx)
  705. -        call    .Lstr_prefix
  706. -        add     $8,%esp
  707. -        test    %eax,%eax
  708. -        jnz     .Lparse_vga_mode
  709. -
  710. -        /* We have 'vga=gfx-<width>x<height>x<depth>'. */
  711. -        /* skip 'gfx-' */
  712. -        add     $4,%ebx
  713. -        /* parse <width> */
  714. -        push    %ebx
  715. -        call    .Latoi
  716. -        pop     %esi
  717. -        mov     %ax,sym_phys(vesa_size)+0
  718. -        /* skip 'x' */
  719. -        lodsb
  720. -        cmpb    $'x',%al
  721. -        jne     .Lcmdline_exit
  722. -        /* parse <height> */
  723. -        push    %esi
  724. -        call    .Latoi
  725. -        pop     %esi
  726. -        mov     %ax,sym_phys(vesa_size)+2
  727. -        /* skip 'x' */
  728. -        lodsb
  729. -        cmpb    $'x',%al
  730. -        jne     .Lcmdline_exit
  731. -        /* parse <depth> */
  732. -        push    %esi
  733. -        call    .Latoi
  734. -        pop     %esi
  735. -        mov     %ax,sym_phys(vesa_size)+4
  736. -        /* commit to vesa mode */
  737. -        movw    $VIDEO_VESA_BY_SIZE,sym_phys(boot_vid_mode)
  738. -        jmp     .Lcmdline_exit
  739. -
  740. -.Lparse_vga_mode:
  741. -        /* Check for 'vga=mode-<mode>'. */
  742. -        push    %ebx
  743. -        pushl   $sym_phys(.Lvga_mode)
  744. -        call    .Lstr_prefix
  745. -        add     $8,%esp
  746. -        test    %eax,%eax
  747. -        jnz     .Lparse_vga_current
  748. -
  749. -        /* We have 'vga=mode-<mode>'. */
  750. -        add     $5,%ebx
  751. -        push    %ebx
  752. -        call    .Latoi
  753. -        add     $4,%esp
  754. -        mov     %ax,sym_phys(boot_vid_mode)
  755. -        jmp     .Lcmdline_exit
  756. -
  757. -.Lparse_vga_current:
  758. -        /* Check for 'vga=current'. */
  759. -        push    %ebx
  760. -        pushl   $sym_phys(.Lvga_current)
  761. -        call    .Lstr_prefix
  762. -        add     $8,%esp
  763. -        test    %eax,%eax
  764. -        jnz     .Lcmdline_exit
  765. -
  766. -        /* We have 'vga=current'. */
  767. -        movw    $VIDEO_CURRENT_MODE,sym_phys(boot_vid_mode)
  768. -
  769. -.Lcmdline_exit:
  770. -        popa
  771. -        ret
  772. -
  773. -        .pushsection .init.rodata, "a", @progbits
  774. -
  775. -.Lvga_text_modes: /* rows, mode_number */
  776. -        .word   25,VIDEO_80x25
  777. -        .word   50,VIDEO_80x50
  778. -        .word   43,VIDEO_80x43
  779. -        .word   28,VIDEO_80x28
  780. -        .word   30,VIDEO_80x30
  781. -        .word   34,VIDEO_80x34
  782. -        .word   60,VIDEO_80x60
  783. -        .word   0
  784. -
  785. -.Lvga_opt:
  786. -        .asciz  "vga"
  787. -.Lvga_text80:
  788. -        .asciz  "text-80x"
  789. -.Lvga_gfx:
  790. -        .asciz  "gfx-"
  791. -.Lvga_mode:
  792. -        .asciz  "mode-"
  793. -.Lvga_current:
  794. -        .asciz  "current"
  795. -.Lno_rm_opt:
  796. -        .asciz  "no-real-mode"
  797. -.Ltboot_opt:
  798. -        .asciz  "tboot"
  799. -.Ledid_opt:
  800. -        .asciz  "edid"
  801. -.Ledid_force:
  802. -        .asciz  "force"
  803. -.Ledid_no:
  804. -        .asciz  "no"
  805. -.Ledd_opt:
  806. -        .asciz  "edd"
  807. -
  808. -        .popsection
  809. diff -Naur xen-9999-bef/xen/arch/x86/boot/edd.S xen-9999-aft/xen/arch/x86/boot/edd.S
  810. --- xen-9999-bef/xen/arch/x86/boot/edd.S    2015-08-16 08:29:52.975771160 +0300
  811. +++ xen-9999-aft/xen/arch/x86/boot/edd.S    2015-08-16 08:30:57.834765013 +0300
  812. @@ -142,9 +142,6 @@
  813.  edd_done:
  814.          ret
  815.  
  816. -opt_edd:
  817. -        .byte   0                               # edd=on/off/skipmbr
  818. -
  819.  GLOBAL(boot_edd_info_nr)
  820.          .byte   0
  821.  GLOBAL(boot_mbr_signature_nr)
  822. diff -Naur xen-9999-bef/xen/arch/x86/boot/head.S xen-9999-aft/xen/arch/x86/boot/head.S
  823. --- xen-9999-bef/xen/arch/x86/boot/head.S   2015-08-16 08:29:52.975771160 +0300
  824. +++ xen-9999-aft/xen/arch/x86/boot/head.S   2015-08-16 08:30:57.835765013 +0300
  825. @@ -1,5 +1,6 @@
  826.  #include <xen/config.h>
  827.  #include <xen/multiboot.h>
  828. +#include <xen/multiboot2.h>
  829.  #include <public/xen.h>
  830.  #include <asm/asm_defns.h>
  831.  #include <asm/desc.h>
  832. @@ -11,13 +12,37 @@
  833.          .text
  834.          .code32
  835.  
  836. -#define sym_phys(sym)     ((sym) - __XEN_VIRT_START)
  837. +#define sym_phys(sym)     ((sym) - __XEN_VIRT_START + XEN_IMG_PHYS_START - XEN_IMG_OFFSET)
  838. +#define sym_offset(sym)   ((sym) - __XEN_VIRT_START)
  839.  
  840.  #define BOOT_CS32        0x0008
  841.  #define BOOT_CS64        0x0010
  842.  #define BOOT_DS          0x0018
  843.  #define BOOT_PSEUDORM_CS 0x0020
  844.  #define BOOT_PSEUDORM_DS 0x0028
  845. +#define BOOT_FS          0x0030
  846. +
  847. +#define MB2_HT(name)      (MULTIBOOT2_HEADER_TAG_##name)
  848. +#define MB2_TT(name)      (MULTIBOOT2_TAG_TYPE_##name)
  849. +
  850. +        .macro mb2ht_args arg, args:vararg
  851. +        .long \arg
  852. +        .ifnb \args
  853. +        mb2ht_args \args
  854. +        .endif
  855. +        .endm
  856. +
  857. +        .macro mb2ht_init type, req, args:vararg
  858. +        .align MULTIBOOT2_TAG_ALIGN
  859. +        0:
  860. +        .short \type
  861. +        .short \req
  862. +        .long 1f - 0b
  863. +        .ifnb \args
  864. +        mb2ht_args \args
  865. +        .endif
  866. +        1:
  867. +        .endm
  868.  
  869.  ENTRY(start)
  870.          jmp     __start
  871. @@ -34,24 +59,84 @@
  872.          .long   -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
  873.  multiboot1_header_end:
  874.  
  875. +/*** MULTIBOOT2 HEADER ****/
  876. +/* Some ideas are taken from grub-2.00/grub-core/tests/boot/kernel-i386.S file. */
  877. +        .align  MULTIBOOT2_HEADER_ALIGN
  878. +
  879. +.Lmultiboot2_header:
  880. +        /* Magic number indicating a Multiboot2 header. */
  881. +        .long   MULTIBOOT2_HEADER_MAGIC
  882. +        /* Architecture: i386. */
  883. +        .long   MULTIBOOT2_ARCHITECTURE_I386
  884. +        /* Multiboot2 header length. */
  885. +        .long   .Lmultiboot2_header_end - .Lmultiboot2_header
  886. +        /* Multiboot2 header checksum. */
  887. +        .long   -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT2_ARCHITECTURE_I386 + \
  888. +                        (.Lmultiboot2_header_end - .Lmultiboot2_header))
  889. +
  890. +        /* Multiboot2 information request tag. */
  891. +        mb2ht_init MB2_HT(INFORMATION_REQUEST), MB2_HT(REQUIRED), \
  892. +                   MB2_TT(BASIC_MEMINFO), MB2_TT(MMAP)
  893. +
  894. +        /* Align modules at page boundry. */
  895. +        mb2ht_init MB2_HT(MODULE_ALIGN), MB2_HT(REQUIRED)
  896. +
  897. +        /* Load address preference. */
  898. +        mb2ht_init MB2_HT(RELOCATABLE), MB2_HT(OPTIONAL), \
  899. +                   sym_phys(start), /* Min load address. */ \
  900. +                   0xffffffff, /* Max load address (4 GiB - 1). */ \
  901. +                   0x200000, /* Load address alignment (2 MiB). */ \
  902. +                   MULTIBOOT2_LOAD_PREFERENCE_HIGH
  903. +
  904. +        /* Console flags tag. */
  905. +        mb2ht_init MB2_HT(CONSOLE_FLAGS), MB2_HT(OPTIONAL), \
  906. +                   MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED
  907. +
  908. +        /* Framebuffer tag. */
  909. +        mb2ht_init MB2_HT(FRAMEBUFFER), MB2_HT(OPTIONAL), \
  910. +                   0, /* Number of the columns - no preference. */ \
  911. +                   0, /* Number of the lines - no preference. */ \
  912. +                   0  /* Number of bits per pixel - no preference. */
  913. +
  914. +        /* Do not disable EFI boot services. */
  915. +        mb2ht_init MB2_HT(EFI_BS), MB2_HT(OPTIONAL)
  916. +
  917. +        /* EFI64 entry point. */
  918. +        mb2ht_init MB2_HT(ENTRY_ADDRESS_EFI64), MB2_HT(OPTIONAL), \
  919. +                   sym_phys(__efi64_start)
  920. +
  921. +        /* Multiboot2 header end tag. */
  922. +        mb2ht_init MB2_HT(END), MB2_HT(REQUIRED)
  923. +.Lmultiboot2_header_end:
  924. +
  925.          .section .init.rodata, "a", @progbits
  926.          .align 4
  927.  
  928.          .word   0
  929.  gdt_boot_descr:
  930. -        .word   6*8-1
  931. -        .long   sym_phys(trampoline_gdt)
  932. +        .word   7*8-1
  933. +gdt_boot_descr_addr:
  934. +        .long   sym_offset(trampoline_gdt)
  935. +        .long   0 /* Needed for 64-bit lgdt */
  936. +
  937. +cs32_switch_addr:
  938. +        .long   sym_offset(cs32_switch)
  939. +        .word   BOOT_CS32
  940.  
  941.  .Lbad_cpu_msg: .asciz "ERR: Not a 64-bit CPU!"
  942.  .Lbad_ldr_msg: .asciz "ERR: Not a Multiboot bootloader!"
  943. +.Lbad_mb2_ldr: .asciz "ERR: Use latest Multiboot2 compatible bootloader!"
  944.  
  945.          .section .init.text, "ax", @progbits
  946.  
  947.  bad_cpu:
  948. -        mov     $(sym_phys(.Lbad_cpu_msg)),%esi # Error message
  949. +        lea     sym_offset(.Lbad_cpu_msg)(%ebp),%esi # Error message
  950.          jmp     print_err
  951.  not_multiboot:
  952. -        mov     $(sym_phys(.Lbad_ldr_msg)),%esi # Error message
  953. +        lea     sym_offset(.Lbad_ldr_msg)(%ebp),%esi # Error message
  954. +        jmp     print_err
  955. +mb2_too_old:
  956. +        lea     sym_offset(.Lbad_mb2_ldr)(%ebp),%esi # Error message
  957.  print_err:
  958.          mov     $0xB8000,%edi  # VGA framebuffer
  959.  1:      mov     (%esi),%bl
  960. @@ -71,65 +156,291 @@
  961.  .Lhalt: hlt
  962.          jmp     .Lhalt
  963.  
  964. +        .code64
  965. +
  966. +__efi64_start:
  967. +        cld
  968. +
  969. +        /* Load default Xen image base address. */
  970. +        mov     $sym_phys(__image_base__),%ebp
  971. +
  972. +        /* Check for Multiboot2 bootloader. */
  973. +        cmp     $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
  974. +        je      efi_multiboot2_proto
  975. +
  976. +        /* Jump to not_multiboot after switching CPU to x86_32 mode. */
  977. +        lea     not_multiboot(%rip),%rdi
  978. +        jmp     x86_32_switch
  979. +
  980. +efi_multiboot2_proto:
  981. +        /*
  982. +         * Multiboot2 information address is 32-bit,
  983. +         * so, zero higher half of %rbx.
  984. +         */
  985. +        mov     %ebx,%ebx
  986. +
  987. +        /* Skip Multiboot2 information fixed part. */
  988. +        lea     MB2_fixed_sizeof(%rbx),%rcx
  989. +
  990. +0:
  991. +        /* Get Xen image base address from Multiboot2 information. */
  992. +        cmpl    $MULTIBOOT2_TAG_TYPE_BASE_ADDR,MB2_tag_type(%rcx)
  993. +        jne     1f
  994. +
  995. +        mov     MB2_base_addr(%rcx),%ebp
  996. +        sub     $XEN_IMG_OFFSET,%rbp
  997. +        jmp     4f
  998. +
  999. +1:
  1000. +        /* Get EFI SystemTable address from Multiboot2 information. */
  1001. +        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%rcx)
  1002. +        jne     2f
  1003. +
  1004. +        mov     MB2_efi64_st(%rcx),%rsi
  1005. +
  1006. +        /* Do not go into real mode on EFI platform. */
  1007. +        movb    $1,skip_realmode(%rip)
  1008. +        jmp     4f
  1009. +
  1010. +2:
  1011. +        /* Get EFI ImageHandle address from Multiboot2 information. */
  1012. +        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64_IH,MB2_tag_type(%rcx)
  1013. +        jne     3f
  1014. +
  1015. +        mov     MB2_efi64_ih(%rcx),%rdi
  1016. +        jmp     4f
  1017. +
  1018. +3:
  1019. +        /* Is it the end of Multiboot2 information? */
  1020. +        cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%rcx)
  1021. +        je      run_bs
  1022. +
  1023. +4:
  1024. +        /* Go to next Multiboot2 information tag. */
  1025. +        add     MB2_tag_size(%rcx),%ecx
  1026. +        add     $(MULTIBOOT2_TAG_ALIGN-1),%rcx
  1027. +        and     $~(MULTIBOOT2_TAG_ALIGN-1),%rcx
  1028. +        jmp     0b
  1029. +
  1030. +run_bs:
  1031. +        push    %rax
  1032. +        push    %rdi
  1033. +
  1034. +        /* Initialize BSS (no nasty surprises!). */
  1035. +        lea     __bss_start(%rip),%rdi
  1036. +        lea     __bss_end(%rip),%rcx
  1037. +        sub     %rdi,%rcx
  1038. +        shr     $3,%rcx
  1039. +        xor     %eax,%eax
  1040. +        rep     stosq
  1041. +
  1042. +        pop     %rdi
  1043. +
  1044. +        /*
  1045. +         * IN: %rdi - EFI ImageHandle, %rsi - EFI SystemTable.
  1046. +         * OUT: %rax - multiboot2.mem_lower. Do not get this value from
  1047. +         * MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO tag. It could be bogus on
  1048. +         * EFI platforms.
  1049. +         */
  1050. +        call    efi_multiboot2
  1051. +
  1052. +        /* Convert multiboot2.mem_lower to bytes/16. */
  1053. +        mov     %rax,%rcx
  1054. +        shr     $4,%rcx
  1055. +
  1056. +        pop     %rax
  1057. +
  1058. +        /* Jump to trampoline_setup after switching CPU to x86_32 mode. */
  1059. +        lea     trampoline_setup(%rip),%rdi
  1060. +
  1061. +x86_32_switch:
  1062. +        cli
  1063. +
  1064. +        /* Initialise GDT. */
  1065. +        add     %ebp,gdt_boot_descr_addr(%rip)
  1066. +        lgdt    gdt_boot_descr(%rip)
  1067. +
  1068. +        /* Reload code selector. */
  1069. +        add     %ebp,cs32_switch_addr(%rip)
  1070. +        ljmpl   *cs32_switch_addr(%rip)
  1071. +
  1072. +        .code32
  1073. +
  1074. +cs32_switch:
  1075. +        /* Initialise basic data segments. */
  1076. +        mov     $BOOT_DS,%edx
  1077. +        mov     %edx,%ds
  1078. +        mov     %edx,%es
  1079. +        mov     %edx,%fs
  1080. +        mov     %edx,%gs
  1081. +        mov     %edx,%ss
  1082. +
  1083. +        /* Disable paging. */
  1084. +        mov     %cr0,%edx
  1085. +        and     $(~X86_CR0_PG),%edx
  1086. +        mov     %edx,%cr0
  1087. +
  1088. +        /* Jump to earlier loaded address. */
  1089. +        jmp     *%edi
  1090. +
  1091.  __start:
  1092.          cld
  1093.          cli
  1094.  
  1095. +        /* Load default Xen image base address. */
  1096. +        mov     $sym_phys(__image_base__),%ebp
  1097. +
  1098. +        /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value. */
  1099. +        xor     %edx,%edx
  1100. +
  1101. +        /* Check for Multiboot2 bootloader. */
  1102. +        cmp     $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
  1103. +        je      multiboot2_proto
  1104. +
  1105. +        /* Check for Multiboot bootloader. */
  1106. +        cmp     $MULTIBOOT_BOOTLOADER_MAGIC,%eax
  1107. +        jne     not_multiboot
  1108. +
  1109. +        /* Get mem_lower from Multiboot information. */
  1110. +        testb   $MBI_MEMLIMITS,MB_flags(%ebx)
  1111. +
  1112. +        /* Not available? BDA value will be fine. */
  1113. +        cmovnz  MB_mem_lower(%ebx),%edx
  1114. +        jmp     trampoline_bios_setup
  1115. +
  1116. +multiboot2_proto:
  1117. +        /* Skip Multiboot2 information fixed part. */
  1118. +        lea     MB2_fixed_sizeof(%ebx),%ecx
  1119. +
  1120. +0:
  1121. +        /* Get Xen image base address from Multiboot2 information. */
  1122. +        cmpl    $MULTIBOOT2_TAG_TYPE_BASE_ADDR,MB2_tag_type(%ecx)
  1123. +        jne     1f
  1124. +
  1125. +        mov     MB2_base_addr(%ecx),%ebp
  1126. +        sub     $XEN_IMG_OFFSET,%ebp
  1127. +        jmp     3f
  1128. +
  1129. +1:
  1130. +        /* Get mem_lower from Multiboot2 information. */
  1131. +        cmpl    $MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO,MB2_tag_type(%ecx)
  1132. +        jne     2f
  1133. +
  1134. +        mov     MB2_mem_lower(%ecx),%edx
  1135. +        jmp     3f
  1136. +
  1137. +2:
  1138. +        /* EFI mode is not supported via legacy BIOS path. */
  1139. +        cmpl    $MULTIBOOT2_TAG_TYPE_EFI32,MB2_tag_type(%ecx)
  1140. +        je      mb2_too_old
  1141. +
  1142. +        cmpl    $MULTIBOOT2_TAG_TYPE_EFI64,MB2_tag_type(%ecx)
  1143. +        je      mb2_too_old
  1144. +
  1145. +        /* Is it the end of Multiboot2 information? */
  1146. +        cmpl    $MULTIBOOT2_TAG_TYPE_END,MB2_tag_type(%ecx)
  1147. +        je      trampoline_bios_setup
  1148. +
  1149. +3:
  1150. +        /* Go to next Multiboot2 information tag. */
  1151. +        add     MB2_tag_size(%ecx),%ecx
  1152. +        add     $(MULTIBOOT2_TAG_ALIGN-1),%ecx
  1153. +        and     $~(MULTIBOOT2_TAG_ALIGN-1),%ecx
  1154. +        jmp     0b
  1155. +
  1156. +trampoline_bios_setup:
  1157. +        mov     %ebp,%esi
  1158. +
  1159.          /* Initialise GDT and basic data segments. */
  1160. -        lgdt    %cs:sym_phys(gdt_boot_descr)
  1161. +        add     %ebp,sym_offset(gdt_boot_descr_addr)(%esi)
  1162. +        lgdt    sym_offset(gdt_boot_descr)(%esi)
  1163. +
  1164.          mov     $BOOT_DS,%ecx
  1165.          mov     %ecx,%ds
  1166.          mov     %ecx,%es
  1167. +        mov     %ecx,%fs
  1168. +        mov     %ecx,%gs
  1169.          mov     %ecx,%ss
  1170.  
  1171. -        /* Check for Multiboot bootloader */
  1172. -        cmp     $MULTIBOOT_BOOTLOADER_MAGIC,%eax
  1173. -        jne     not_multiboot
  1174. -
  1175.          /* Set up trampoline segment 64k below EBDA */
  1176. -        movzwl  0x40e,%eax          /* EBDA segment */
  1177. -        cmp     $0xa000,%eax        /* sanity check (high) */
  1178. +        movzwl  0x40e,%ecx          /* EBDA segment */
  1179. +        cmp     $0xa000,%ecx        /* sanity check (high) */
  1180.          jae     0f
  1181. -        cmp     $0x4000,%eax        /* sanity check (low) */
  1182. +        cmp     $0x4000,%ecx        /* sanity check (low) */
  1183.          jae     1f
  1184.  0:
  1185. -        movzwl  0x413,%eax          /* use base memory size on failure */
  1186. -        shl     $10-4,%eax
  1187. +        movzwl  0x413,%ecx          /* use base memory size on failure */
  1188. +        shl     $10-4,%ecx
  1189.  1:
  1190.          /*
  1191.           * Compare the value in the BDA with the information from the
  1192.           * multiboot structure (if available) and use the smallest.
  1193.           */
  1194. -        testb   $MBI_MEMLIMITS,(%ebx)
  1195. -        jz      2f                  /* not available? BDA value will be fine */
  1196. -        mov     MB_mem_lower(%ebx),%edx
  1197.          cmp     $0x100,%edx         /* is the multiboot value too small? */
  1198. -        jb      2f                  /* if so, do not use it */
  1199. +        jb      trampoline_setup    /* if so, do not use it */
  1200.          shl     $10-4,%edx
  1201. -        cmp     %eax,%edx           /* compare with BDA value */
  1202. -        cmovb   %edx,%eax           /* and use the smaller */
  1203. +        cmp     %ecx,%edx           /* compare with BDA value */
  1204. +        cmovb   %edx,%ecx           /* and use the smaller */
  1205.  
  1206. -2:      /* Reserve 64kb for the trampoline */
  1207. -        sub     $0x1000,%eax
  1208. +trampoline_setup:
  1209. +        mov     %ebp,%esi
  1210. +
  1211. +        /* Initialize 0-15 bits of BOOT_FS segment descriptor base address. */
  1212. +        mov     %ebp,%edx
  1213. +        shl     $16,%edx
  1214. +        or      %edx,(sym_offset(trampoline_gdt)+BOOT_FS)(%esi)
  1215. +
  1216. +        /* Initialize 16-23 bits of BOOT_FS segment descriptor base address. */
  1217. +        mov     %ebp,%edx
  1218. +        shr     $16,%edx
  1219. +        and     $0x000000ff,%edx
  1220. +        or      %edx,(sym_offset(trampoline_gdt)+BOOT_FS+4)(%esi)
  1221. +
  1222. +        /* Initialize 24-31 bits of BOOT_FS segment descriptor base address. */
  1223. +        mov     %ebp,%edx
  1224. +        and     $0xff000000,%edx
  1225. +        or      %edx,(sym_offset(trampoline_gdt)+BOOT_FS+4)(%esi)
  1226. +
  1227. +        /* Initialize %fs and later use it to access Xen data if possible. */
  1228. +        mov     $BOOT_FS,%edx
  1229. +        mov     %edx,%fs
  1230. +
  1231. +        /* Reserve 64kb for the trampoline. */
  1232. +        sub     $0x1000,%ecx
  1233.  
  1234.          /* From arch/x86/smpboot.c: start_eip had better be page-aligned! */
  1235. -        xor     %al, %al
  1236. -        shl     $4, %eax
  1237. -        mov     %eax,sym_phys(trampoline_phys)
  1238. +        xor     %cl, %cl
  1239. +        shl     $4, %ecx
  1240. +        mov     %ecx,%fs:sym_offset(trampoline_phys)
  1241. +
  1242. +        /* Save Xen image base address for later use. */
  1243. +        mov     %ebp,%fs:sym_offset(xen_img_base_phys_addr)
  1244.  
  1245.          /* Save the Multiboot info struct (after relocation) for later use. */
  1246. -        mov     $sym_phys(cpu0_stack)+1024,%esp
  1247. -        push    %ebx
  1248. +        lea     (sym_offset(cpu0_stack)+1024)(%ebp),%esp
  1249. +        push    %eax                /* Multiboot magic. */
  1250. +        push    %ebx                /* Multiboot information address. */
  1251. +        push    %ecx                /* Boot trampoline address. */
  1252.          call    reloc
  1253. -        mov     %eax,sym_phys(multiboot_ptr)
  1254. +        add     $12,%esp            /* Remove reloc() args from stack. */
  1255. +        mov     %eax,%fs:sym_offset(multiboot_ptr)
  1256. +
  1257. +        /*
  1258. +         * Do not zero BSS on EFI platform here.
  1259. +         * It was initialized earlier.
  1260. +         */
  1261. +        cmpb    $1,%fs:sym_offset(skip_realmode)
  1262. +        je      1f
  1263.  
  1264. -        /* Initialize BSS (no nasty surprises!) */
  1265. -        mov     $sym_phys(__bss_start),%edi
  1266. -        mov     $sym_phys(__bss_end),%ecx
  1267. +        /* Initialize BSS (no nasty surprises!). */
  1268. +        lea     sym_offset(__bss_start)(%ebp),%edi
  1269. +        lea     sym_offset(__bss_end)(%ebp),%ecx
  1270.          sub     %edi,%ecx
  1271. +        shr     $2,%ecx
  1272.          xor     %eax,%eax
  1273. -        rep     stosb
  1274. +        rep     stosl
  1275.  
  1276. +1:
  1277.          /* Interrogate CPU extended features via CPUID. */
  1278.          mov     $0x80000000,%eax
  1279.          cpuid
  1280. @@ -138,8 +449,8 @@
  1281.          jbe     1f
  1282.          mov     $0x80000001,%eax
  1283.          cpuid
  1284. -1:      mov     %edx,sym_phys(cpuid_ext_features)
  1285. -        mov     %edx,sym_phys(boot_cpu_data)+CPUINFO_FEATURE_OFFSET(X86_FEATURE_LM)
  1286. +1:      mov     %edx,%fs:sym_offset(cpuid_ext_features)
  1287. +        mov     %edx,%fs:(sym_offset(boot_cpu_data)+CPUINFO_FEATURE_OFFSET(X86_FEATURE_LM))
  1288.  
  1289.          /* Check for availability of long mode. */
  1290.          bt      $X86_FEATURE_LM & 0x1f,%edx
  1291. @@ -147,63 +458,119 @@
  1292.  
  1293.          /* Stash TSC to calculate a good approximation of time-since-boot */
  1294.          rdtsc
  1295. -        mov     %eax,sym_phys(boot_tsc_stamp)
  1296. -        mov     %edx,sym_phys(boot_tsc_stamp+4)
  1297. +        mov     %eax,%fs:sym_offset(boot_tsc_stamp)
  1298. +        mov     %edx,%fs:sym_offset(boot_tsc_stamp+4)
  1299. +
  1300. +        /* Update frame addreses in page tables. */
  1301. +        lea     sym_offset(__page_tables_start)(%ebp),%edx
  1302. +        mov     $((__page_tables_end-__page_tables_start)/8),%ecx
  1303. +1:      testl   $_PAGE_PRESENT,(%edx)
  1304. +        jz      2f
  1305. +        add     %ebp,(%edx)
  1306. +2:      add     $8,%edx
  1307. +        loop    1b
  1308.  
  1309. -        /* Initialise L2 boot-map page table entries (16MB). */
  1310. -        mov     $sym_phys(l2_bootmap),%edx
  1311. -        mov     $PAGE_HYPERVISOR|_PAGE_PSE,%eax
  1312. -        mov     $8,%ecx
  1313. +        /* Initialise L2 boot-map page table entries (14MB). */
  1314. +        lea     sym_offset(l2_bootmap)(%ebp),%edx
  1315. +        lea     sym_offset(start)(%ebp),%eax
  1316. +        and     $~((1<<L2_PAGETABLE_SHIFT)-1),%eax
  1317. +        mov     %eax,%ebx
  1318. +        shr     $(L2_PAGETABLE_SHIFT-3),%ebx
  1319. +        and     $(L2_PAGETABLE_ENTRIES*4*8-1),%ebx
  1320. +        add     %ebx,%edx
  1321. +        add     $(PAGE_HYPERVISOR|_PAGE_PSE),%eax
  1322. +        mov     $7,%ecx
  1323.  1:      mov     %eax,(%edx)
  1324.          add     $8,%edx
  1325.          add     $(1<<L2_PAGETABLE_SHIFT),%eax
  1326.          loop    1b
  1327. +
  1328.          /* Initialise L3 boot-map page directory entry. */
  1329. -        mov     $sym_phys(l2_bootmap)+__PAGE_HYPERVISOR,%eax
  1330. -        mov     %eax,sym_phys(l3_bootmap) + 0*8
  1331. +        lea     (sym_offset(l2_bootmap)+__PAGE_HYPERVISOR)(%ebp),%eax
  1332. +        lea     sym_offset(l3_bootmap)(%ebp),%ebx
  1333. +        mov     $4,%ecx
  1334. +1:      mov     %eax,(%ebx)
  1335. +        add     $8,%ebx
  1336. +        add     $(L2_PAGETABLE_ENTRIES*8),%eax
  1337. +        loop    1b
  1338. +
  1339. +        /* Initialise L2 direct map page table entries (14MB). */
  1340. +        lea     sym_offset(l2_identmap)(%ebp),%edx
  1341. +        lea     sym_offset(start)(%ebp),%eax
  1342. +        and     $~((1<<L2_PAGETABLE_SHIFT)-1),%eax
  1343. +        mov     %eax,%ebx
  1344. +        shr     $(L2_PAGETABLE_SHIFT-3),%ebx
  1345. +        and     $(L2_PAGETABLE_ENTRIES*4*8-1),%ebx
  1346. +        add     %ebx,%edx
  1347. +        add     $(PAGE_HYPERVISOR|_PAGE_PSE),%eax
  1348. +        mov     $7,%ecx
  1349. +1:      mov     %eax,(%edx)
  1350. +        add     $8,%edx
  1351. +        add     $(1<<L2_PAGETABLE_SHIFT),%eax
  1352. +        loop    1b
  1353. +
  1354.          /* Hook 4kB mappings of first 2MB of memory into L2. */
  1355. -        mov     $sym_phys(l1_identmap)+__PAGE_HYPERVISOR,%edi
  1356. -        mov     %edi,sym_phys(l2_xenmap)
  1357. -        mov     %edi,sym_phys(l2_bootmap)
  1358. +        lea     (sym_offset(l1_identmap)+__PAGE_HYPERVISOR)(%ebp),%edi
  1359. +        mov     %edi,%fs:sym_offset(l2_bootmap)
  1360.  
  1361.          /* Apply relocations to bootstrap trampoline. */
  1362. -        mov     sym_phys(trampoline_phys),%edx
  1363. -        mov     $sym_phys(__trampoline_rel_start),%edi
  1364. -        mov     %edx,sym_phys(trampoline_phys)
  1365. +        mov     %fs:sym_offset(trampoline_phys),%edx
  1366. +        lea     sym_offset(__trampoline_rel_start)(%ebp),%edi
  1367. +        lea     sym_offset(__trampoline_rel_stop)(%ebp),%esi
  1368.  1:
  1369.          mov     (%edi),%eax
  1370.          add     %edx,(%edi,%eax)
  1371.          add     $4,%edi
  1372. -        cmp     $sym_phys(__trampoline_rel_stop),%edi
  1373. +        cmp     %esi,%edi
  1374.          jb      1b
  1375.  
  1376.          /* Patch in the trampoline segment. */
  1377.          shr     $4,%edx
  1378. -        mov     $sym_phys(__trampoline_seg_start),%edi
  1379. +        lea     sym_offset(__trampoline_seg_start)(%ebp),%edi
  1380. +        lea     sym_offset(__trampoline_seg_stop)(%ebp),%esi
  1381.  1:
  1382.          mov     (%edi),%eax
  1383.          mov     %dx,(%edi,%eax)
  1384.          add     $4,%edi
  1385. -        cmp     $sym_phys(__trampoline_seg_stop),%edi
  1386. +        cmp     %esi,%edi
  1387.          jb      1b
  1388.  
  1389. +        /* Do not parse command line on EFI platform here. */
  1390. +        cmpb    $1,%fs:sym_offset(skip_realmode)
  1391. +        je      1f
  1392. +
  1393. +        /* Bail if there is no command line to parse. */
  1394. +        mov     %fs:sym_offset(multiboot_ptr),%ebx
  1395. +        testl   $MBI_CMDLINE,MB_flags(%ebx)
  1396. +        jz      1f
  1397. +
  1398. +        cmpl    $0,MB_cmdline(%ebx)
  1399. +        jz      1f
  1400. +
  1401. +        lea     sym_offset(early_boot_opts)(%ebp),%eax
  1402. +        push    %eax
  1403. +        pushl   MB_cmdline(%ebx)
  1404.          call    cmdline_parse_early
  1405. +        add     $8,%esp             /* Remove cmdline_parse_early() args from stack. */
  1406. +
  1407. +1:
  1408.  
  1409.          /* Switch to low-memory stack.  */
  1410. -        mov     sym_phys(trampoline_phys),%edi
  1411. +        mov     %fs:sym_offset(trampoline_phys),%edi
  1412.          lea     0x10000(%edi),%esp
  1413.          lea     trampoline_boot_cpu_entry-trampoline_start(%edi),%eax
  1414.          pushl   $BOOT_CS32
  1415.          push    %eax
  1416.  
  1417.          /* Copy bootstrap trampoline to low memory, below 1MB. */
  1418. -        mov     $sym_phys(trampoline_start),%esi
  1419. +        lea     sym_offset(trampoline_start)(%ebp),%esi
  1420.          mov     $trampoline_end - trampoline_start,%ecx
  1421.          rep     movsb
  1422.  
  1423.          /* Jump into the relocated trampoline. */
  1424.          lret
  1425.  
  1426. +cmdline_parse_early:
  1427.  #include "cmdline.S"
  1428.  
  1429.  reloc:
  1430. diff -Naur xen-9999-bef/xen/arch/x86/boot/Makefile xen-9999-aft/xen/arch/x86/boot/Makefile
  1431. --- xen-9999-bef/xen/arch/x86/boot/Makefile 2015-08-16 08:29:52.975771160 +0300
  1432. +++ xen-9999-aft/xen/arch/x86/boot/Makefile 2015-08-16 08:30:57.835765013 +0300
  1433. @@ -1,8 +1,14 @@
  1434.  obj-bin-y += head.o
  1435.  
  1436. -RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h
  1437. +CMDLINE_DEPS = video.h
  1438.  
  1439. -head.o: reloc.S
  1440. +RELOC_DEPS = $(BASEDIR)/include/asm-x86/config.h $(BASEDIR)/include/xen/multiboot.h \
  1441. +             $(BASEDIR)/include/xen/multiboot2.h
  1442. +
  1443. +head.o: cmdline.S reloc.S
  1444. +
  1445. +cmdline.S: cmdline.c $(CMDLINE_DEPS)
  1446. +   $(MAKE) -f build32.mk $@ CMDLINE_DEPS="$(CMDLINE_DEPS)"
  1447.  
  1448.  reloc.S: reloc.c $(RELOC_DEPS)
  1449.     $(MAKE) -f build32.mk $@ RELOC_DEPS="$(RELOC_DEPS)"
  1450. diff -Naur xen-9999-bef/xen/arch/x86/boot/reloc.c xen-9999-aft/xen/arch/x86/boot/reloc.c
  1451. --- xen-9999-bef/xen/arch/x86/boot/reloc.c  2015-08-16 08:29:52.975771160 +0300
  1452. +++ xen-9999-aft/xen/arch/x86/boot/reloc.c  2015-08-16 08:30:57.836765013 +0300
  1453. @@ -5,20 +5,37 @@
  1454.   * and modules. This is most easily done early with paging disabled.
  1455.   *
  1456.   * Copyright (c) 2009, Citrix Systems, Inc.
  1457. + * Copyright (c) 2013, 2014, 2015 Oracle Co.
  1458.   *
  1459.   * Authors:
  1460.   *    Keir Fraser <keir@xxxxxxxxxxx>
  1461. + *    Daniel Kiper <daniel.kiper@xxxxxxxxx>
  1462.   */
  1463.  
  1464. -/* entered with %eax = BOOT_TRAMPOLINE */
  1465. +/*
  1466. + * This entry point is entered from xen/arch/x86/boot/head.S with:
  1467. + *   - 0x4(%esp) = BOOT_TRAMPOLINE_ADDRESS,
  1468. + *   - 0x8(%esp) = MULTIBOOT_INFORMATION_ADDRESS,
  1469. + *   - 0xc(%esp) = MULTIBOOT_MAGIC.
  1470. + */
  1471.  asm (
  1472.      "    .text                         \n"
  1473.      "    .globl _start                 \n"
  1474.      "_start:                           \n"
  1475. +    "    push %ebp                     \n"
  1476. +    "    mov  %esp,%ebp                \n"
  1477.      "    call 1f                       \n"
  1478. -    "1:  pop  %ebx                     \n"
  1479. -    "    mov  %eax,alloc-1b(%ebx)      \n"
  1480. -    "    jmp  reloc                    \n"
  1481. +    "1:  pop  %ecx                     \n"
  1482. +    "    mov  0x8(%ebp),%eax           \n"
  1483. +    "    mov  %eax,alloc-1b(%ecx)      \n"
  1484. +    "    mov  0x10(%ebp),%eax          \n"
  1485. +    "    push %eax                     \n"
  1486. +    "    mov  0xc(%ebp),%eax           \n"
  1487. +    "    push %eax                     \n"
  1488. +    "    call reloc                    \n"
  1489. +    "    add  $8,%esp                  \n"
  1490. +    "    pop  %ebp                     \n"
  1491. +    "    ret                           \n"
  1492.      );
  1493.  
  1494.  /*
  1495. @@ -31,11 +48,20 @@
  1496.      );
  1497.  
  1498.  typedef unsigned int u32;
  1499. +typedef unsigned long long u64;
  1500. +
  1501.  #include "../../../include/xen/multiboot.h"
  1502. +#include "../../../include/xen/multiboot2.h"
  1503.  
  1504. -static void *reloc_mbi_struct(void *old, unsigned int bytes)
  1505. +define ALIGN_UP(addr, align) \
  1506. +                (((addr) + (typeof(addr))(align) - 1) & ~((typeof(addr))(align) - 1))
  1507. +
  1508. +#define get_mb2_data(tag, type, member) (((type *)(tag))->member)
  1509. +
  1510. +static u32 alloc_mem(u32 bytes)
  1511.  {
  1512. -    void *new;
  1513. +    u32 s;
  1514. +
  1515.      asm(
  1516.      "    call 1f                      \n"
  1517.      "1:  pop  %%edx                   \n"
  1518. @@ -43,57 +69,199 @@
  1519.      "    sub  %1,%0                   \n"
  1520.      "    and  $~15,%0                 \n"
  1521.      "    mov  %0,alloc-1b(%%edx)      \n"
  1522. -    "    mov  %0,%%edi                \n"
  1523. -    "    rep  movsb                   \n"
  1524. -       : "=&r" (new), "+c" (bytes), "+S" (old)
  1525. -   : : "edx", "edi", "memory");
  1526. -    return new;
  1527. +       : "=&r" (s) : "r" (bytes) : "edx", "memory");
  1528. +
  1529. +    return s;
  1530. +}
  1531. +
  1532. +static void zero_mem(u32 s, u32 bytes)
  1533. +{
  1534. +    asm volatile("rep stosb" : "+D" (s), "+c" (bytes) : "a" (0) : "memory");
  1535. +}
  1536. +
  1537. +static u32 copy_mem(u32 src, u32 bytes)
  1538. +{
  1539. +    u32 dst, dst_asm;
  1540. +
  1541. +    dst = alloc_mem(bytes);
  1542. +    dst_asm = dst;
  1543. +
  1544. +    asm volatile("rep movsb" : "+S" (src), "+D" (dst_asm), "+c" (bytes) : : "memory");
  1545. +
  1546. +    return dst;
  1547.  }
  1548.  
  1549. -static char *reloc_mbi_string(char *old)
  1550. +static u32 copy_string(u32 src)
  1551.  {
  1552. -    char *p;
  1553. -    for ( p = old; *p != '\0'; p++ )
  1554. +    u32 p;
  1555. +
  1556. +    if ( src == 0 )
  1557. +        return 0;
  1558. +
  1559. +    for ( p = src; *(char *)p != '\0'; p++ )
  1560.          continue;
  1561. -    return reloc_mbi_struct(old, p - old + 1);
  1562. +
  1563. +return copy_mem(src, p - src + 1);
  1564.  }
  1565.  
  1566. -multiboot_info_t *reloc(multiboot_info_t *mbi_old)
  1567. +static multiboot_info_t *mbi_mbi(void *mbi_in)
  1568.  {
  1569. -    multiboot_info_t *mbi = reloc_mbi_struct(mbi_old, sizeof(*mbi));
  1570.      int i;
  1571. +    multiboot_info_t *mbi_out;
  1572. +
  1573. +    mbi_out = (multiboot_info_t *)copy_mem((u32)mbi_in, sizeof(*mbi_out));
  1574.  
  1575. -    if ( mbi->flags & MBI_CMDLINE )
  1576. -        mbi->cmdline = (u32)reloc_mbi_string((char *)mbi->cmdline);
  1577. +    if ( mbi_out->flags & MBI_CMDLINE )
  1578. +        mbi_out->cmdline = copy_string(mbi_out->cmdline);
  1579.  
  1580. -    if ( mbi->flags & MBI_MODULES )
  1581. +    if ( mbi_out->flags & MBI_MODULES )
  1582.      {
  1583. -        module_t *mods = reloc_mbi_struct(
  1584. -            (module_t *)mbi->mods_addr, mbi->mods_count * sizeof(module_t));
  1585. +   module_t *mods;
  1586. +
  1587. +        mbi_out->mods_addr = copy_mem(mbi_out->mods_addr,
  1588. +                                      mbi_out->mods_count * sizeof(module_t));
  1589.  
  1590. -        mbi->mods_addr = (u32)mods;
  1591. +        mods = (module_t *)mbi_out->mods_addr;
  1592.  
  1593. -        for ( i = 0; i < mbi->mods_count; i++ )
  1594. +        for ( i = 0; i < mbi_out->mods_count; i++ )
  1595.          {
  1596.              if ( mods[i].string )
  1597. -                mods[i].string = (u32)reloc_mbi_string((char *)mods[i].string);
  1598. +                mods[i].string = copy_string(mods[i].string);
  1599.          }
  1600.      }
  1601.  
  1602. -    if ( mbi->flags & MBI_MEMMAP )
  1603. -        mbi->mmap_addr = (u32)reloc_mbi_struct(
  1604. -            (memory_map_t *)mbi->mmap_addr, mbi->mmap_length);
  1605. -
  1606. -    if ( mbi->flags & MBI_LOADERNAME )
  1607. -        mbi->boot_loader_name = (u32)reloc_mbi_string(
  1608. -            (char *)mbi->boot_loader_name);
  1609. +    if ( mbi_out->flags & MBI_MEMMAP )
  1610. +        mbi_out->mmap_addr = copy_mem(mbi_out->mmap_addr, mbi_out->mmap_length);
  1611. +
  1612. +    if ( mbi_out->flags & MBI_LOADERNAME )
  1613. +        mbi_out->boot_loader_name = copy_string(mbi_out->boot_loader_name);
  1614.  
  1615.      /* Mask features we don't understand or don't relocate. */
  1616. -    mbi->flags &= (MBI_MEMLIMITS |
  1617. -                   MBI_CMDLINE |
  1618. -                   MBI_MODULES |
  1619. -                   MBI_MEMMAP |
  1620. -                   MBI_LOADERNAME);
  1621. +    mbi_out->flags &= (MBI_MEMLIMITS |
  1622. +                       MBI_CMDLINE |
  1623. +                       MBI_MODULES |
  1624. +                       MBI_MEMMAP |
  1625. +                       MBI_LOADERNAME);
  1626. +
  1627. +    return mbi_out;
  1628. +}
  1629.  
  1630. -    return mbi;
  1631. +static multiboot_info_t *mbi2_mbi(void *mbi_in)
  1632. +{
  1633. +    /* Do not complain that mbi_out_mods is not initialized. */
  1634. +    module_t *mbi_out_mods = (module_t *)0;
  1635. +    memory_map_t *mmap_dst;
  1636. +    multiboot2_memory_map_t *mmap_src;
  1637. +    multiboot2_tag_t *tag;
  1638. +    multiboot_info_t *mbi_out;
  1639. +    u32 ptr;
  1640. +    unsigned int i, mod_idx = 0;
  1641. +
  1642. +    mbi_out = (multiboot_info_t *)alloc_mem(sizeof(*mbi_out));
  1643. +    zero_mem((u32)mbi_out, sizeof(*mbi_out));
  1644. +
  1645. +    /* Skip Multiboot2 information fixed part. */
  1646. +    tag = mbi_in + sizeof(multiboot2_fixed_t);
  1647. +
  1648. +    for ( ; ; )
  1649. +    {
  1650. +        if ( tag->type == MULTIBOOT2_TAG_TYPE_MODULE )
  1651. +            ++mbi_out->mods_count;
  1652. +        else if ( tag->type == MULTIBOOT2_TAG_TYPE_END )
  1653. +        {
  1654. +            mbi_out->flags = MBI_MODULES;
  1655. +            mbi_out->mods_addr = alloc_mem(mbi_out->mods_count * sizeof(module_t));
  1656. +            mbi_out_mods = (module_t *)mbi_out->mods_addr;
  1657. +            break;
  1658. +        }
  1659. +
  1660. +        /* Go to next Multiboot2 information tag. */
  1661. +        tag = (multiboot2_tag_t *)(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN));
  1662. +
  1663. +        /* Check Multiboot2 information total size just in case. */
  1664. +       if ( (void *)tag - mbi_in >= ((multiboot2_fixed_t *)mbi_in)->total_size )
  1665. +           break;
  1666. +    }
  1667. +
  1668. +    /* Skip Multiboot2 information fixed part. */
  1669. +    tag = mbi_in + sizeof(multiboot2_fixed_t);
  1670. +
  1671. +    for ( ; ; )
  1672. +    {
  1673. +        switch ( tag->type )
  1674. +        {
  1675. +        case MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME:
  1676. +            mbi_out->flags |= MBI_LOADERNAME;
  1677. +            ptr = (u32)get_mb2_data(tag, multiboot2_tag_string_t, string);
  1678. +            mbi_out->boot_loader_name = copy_string(ptr);
  1679. +            break;
  1680. +
  1681. +        case MULTIBOOT2_TAG_TYPE_CMDLINE:
  1682. +            mbi_out->flags |= MBI_CMDLINE;
  1683. +            ptr = (u32)get_mb2_data(tag, multiboot2_tag_string_t, string);
  1684. +            mbi_out->cmdline = copy_string(ptr);
  1685. +            break;
  1686. +
  1687. +        case MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO:
  1688. +            mbi_out->flags |= MBI_MEMLIMITS;
  1689. +            mbi_out->mem_lower = get_mb2_data(tag, multiboot2_tag_basic_meminfo_t, mem_lower);
  1690. +            mbi_out->mem_upper = get_mb2_data(tag, multiboot2_tag_basic_meminfo_t, mem_upper);
  1691. +            break;
  1692. +
  1693. +        case MULTIBOOT2_TAG_TYPE_MMAP:
  1694. +            mbi_out->flags |= MBI_MEMMAP;
  1695. +            mbi_out->mmap_length = get_mb2_data(tag, multiboot2_tag_mmap_t, size);
  1696. +            mbi_out->mmap_length -= sizeof(multiboot2_tag_mmap_t);
  1697. +            mbi_out->mmap_length += sizeof(((multiboot2_tag_mmap_t){0}).entries);
  1698. +            mbi_out->mmap_length /= get_mb2_data(tag, multiboot2_tag_mmap_t, entry_size);
  1699. +            mbi_out->mmap_length *= sizeof(memory_map_t);
  1700. +
  1701. +            mbi_out->mmap_addr = alloc_mem(mbi_out->mmap_length);
  1702. +
  1703. +            mmap_src = get_mb2_data(tag, multiboot2_tag_mmap_t, entries);
  1704. +            mmap_dst = (memory_map_t *)mbi_out->mmap_addr;
  1705. +
  1706. +            for ( i = 0; i < mbi_out->mmap_length / sizeof(memory_map_t); ++i )
  1707. +            {
  1708. +                mmap_dst[i].size = sizeof(memory_map_t);
  1709. +                mmap_dst[i].size -= sizeof(((memory_map_t){0}).size);
  1710. +                mmap_dst[i].base_addr_low = (u32)mmap_src[i].addr;
  1711. +                mmap_dst[i].base_addr_high = (u32)(mmap_src[i].addr >> 32);
  1712. +                mmap_dst[i].length_low = (u32)mmap_src[i].len;
  1713. +                mmap_dst[i].length_high = (u32)(mmap_src[i].len >> 32);
  1714. +                mmap_dst[i].type = mmap_src[i].type;
  1715. +            }
  1716. +            break;
  1717. +
  1718. +        case MULTIBOOT2_TAG_TYPE_MODULE:
  1719. +            mbi_out_mods[mod_idx].mod_start = get_mb2_data(tag, multiboot2_tag_module_t, mod_start);
  1720. +            mbi_out_mods[mod_idx].mod_end = get_mb2_data(tag, multiboot2_tag_module_t, mod_end);
  1721. +            ptr = (u32)get_mb2_data(tag, multiboot2_tag_module_t, cmdline);
  1722. +            mbi_out_mods[mod_idx].string = copy_string(ptr);
  1723. +            mbi_out_mods[mod_idx].reserved = 0;
  1724. +            ++mod_idx;
  1725. +            break;
  1726. +
  1727. +        case MULTIBOOT2_TAG_TYPE_END:
  1728. +            return mbi_out;
  1729. +
  1730. +        default:
  1731. +            break;
  1732. +        }
  1733. +
  1734. +        /* Go to next Multiboot2 information tag. */
  1735. +        tag = (multiboot2_tag_t *)(ALIGN_UP((u32)tag + tag->size, MULTIBOOT2_TAG_ALIGN));
  1736. +
  1737. +        /* Check Multiboot2 information total size just in case. */
  1738. +       if ( (void *)tag - mbi_in >= ((multiboot2_fixed_t *)mbi_in)->total_size )
  1739. +            return mbi_out;
  1740. +    }
  1741. +}
  1742. +
  1743. +static multiboot_info_t __attribute__((__used__)) *reloc(void *mbi_in, u32 mb_magic)
  1744. +{
  1745. +    if ( mb_magic == MULTIBOOT2_BOOTLOADER_MAGIC )
  1746. +        return mbi2_mbi(mbi_in);
  1747. +    else
  1748. +        return mbi_mbi(mbi_in);
  1749.  }
  1750. diff -Naur xen-9999-bef/xen/arch/x86/boot/trampoline.S xen-9999-aft/xen/arch/x86/boot/trampoline.S
  1751. --- xen-9999-bef/xen/arch/x86/boot/trampoline.S 2015-08-16 08:29:52.975771160 +0300
  1752. +++ xen-9999-aft/xen/arch/x86/boot/trampoline.S 2015-08-16 08:30:57.836765013 +0300
  1753. @@ -1,3 +1,5 @@
  1754. +#include "video.h"
  1755. +
  1756.          .code16
  1757.  
  1758.  /* NB. bootsym() is only usable in real mode, or via BOOT_PSEUDORM_DS. */
  1759. @@ -50,12 +52,20 @@
  1760.          /* 0x0028: real-mode data @ BOOT_TRAMPOLINE */
  1761.          .long   0x0000ffff
  1762.          .long   0x00009200
  1763. +        /*
  1764. +         * 0x0030: ring 0 Xen data, 16 MiB size, base
  1765. +         * address is initialized during runtime.
  1766. +         */
  1767. +        .quad   0x00c0920000001000
  1768.  
  1769.          .pushsection .trampoline_rel, "a"
  1770.          .long   trampoline_gdt + BOOT_PSEUDORM_CS + 2 - .
  1771.          .long   trampoline_gdt + BOOT_PSEUDORM_DS + 2 - .
  1772.          .popsection
  1773.  
  1774. +GLOBAL(xen_img_base_phys_addr)
  1775. +        .long   0
  1776. +
  1777.  GLOBAL(cpuid_ext_features)
  1778.          .long   0
  1779.  
  1780. @@ -80,7 +90,8 @@
  1781.          mov     %ecx,%cr4
  1782.  
  1783.          /* Load pagetable base register. */
  1784. -        mov     $sym_phys(idle_pg_table),%eax
  1785. +        mov     bootsym_rel(xen_img_base_phys_addr,4,%eax)
  1786. +        lea     sym_offset(idle_pg_table)(%eax),%eax
  1787.          add     bootsym_rel(trampoline_xen_phys_start,4,%eax)
  1788.          mov     %eax,%cr3
  1789.  
  1790. @@ -201,8 +212,20 @@
  1791.          /* Jump to the common bootstrap entry point. */
  1792.          jmp     trampoline_protmode_entry
  1793.  
  1794. +/*
  1795. + * Keep in sync with cmdline.c:early_boot_opts_t type!
  1796. + */
  1797. +early_boot_opts:
  1798.  skip_realmode:
  1799.          .byte   0
  1800. +opt_edd:
  1801. +        .byte   0                               /* edd=on/off/skipmbr */
  1802. +opt_edid:
  1803. +        .byte   0                               /* EDID parsing option (force/no/default). */
  1804. +GLOBAL(boot_vid_mode)
  1805. +        .word   VIDEO_80x25                     /* If we don't run at all, assume basic video mode 3 at 80x25. */
  1806. +vesa_size:
  1807. +        .word   0,0,0                           /* width x depth x height */
  1808.  
  1809.  GLOBAL(kbd_shift_flags)
  1810.          .byte   0
  1811. diff -Naur xen-9999-bef/xen/arch/x86/boot/video.S xen-9999-aft/xen/arch/x86/boot/video.S
  1812. --- xen-9999-bef/xen/arch/x86/boot/video.S  2015-08-16 08:29:52.976771160 +0300
  1813. +++ xen-9999-aft/xen/arch/x86/boot/video.S  2015-08-16 08:30:57.837765012 +0300
  1814. @@ -945,7 +945,6 @@
  1815.  #endif
  1816.          ret
  1817.  
  1818. -opt_edid:       .byte   0       # EDID parsing option (force/no/default)
  1819.  mt_end:         .word   0       # End of video mode table if built
  1820.  edit_buf:       .space  6       # Line editor buffer
  1821.  card_name:      .word   0       # Pointer to adapter name
  1822. @@ -991,11 +990,6 @@
  1823.  
  1824.  force_size:     .word   0       # Use this size instead of the one in BIOS vars
  1825.  
  1826. -vesa_size:      .word   0,0,0   # width x depth x height
  1827. -
  1828. -/* If we don't run at all, assume basic video mode 3 at 80x25. */
  1829. -GLOBAL(boot_vid_mode)
  1830. -        .word   VIDEO_80x25
  1831.  GLOBAL(boot_vid_info)
  1832.          .byte   0, 0    /* orig_x, orig_y */
  1833.          .byte   3       /* text mode 3    */
  1834. diff -Naur xen-9999-bef/xen/arch/x86/boot/wakeup.S xen-9999-aft/xen/arch/x86/boot/wakeup.S
  1835. --- xen-9999-bef/xen/arch/x86/boot/wakeup.S 2015-08-16 08:29:52.976771160 +0300
  1836. +++ xen-9999-aft/xen/arch/x86/boot/wakeup.S 2015-08-16 08:30:57.837765012 +0300
  1837. @@ -119,8 +119,10 @@
  1838.          mov     %eax, %ss
  1839.          mov     $bootsym_rel(wakeup_stack, 4, %esp)
  1840.  
  1841. +        mov     bootsym_rel(xen_img_base_phys_addr, 4, %ebx)
  1842. +
  1843.          # check saved magic again
  1844. -        mov     $sym_phys(saved_magic), %eax
  1845. +        lea     sym_offset(saved_magic)(%ebx), %eax
  1846.          add     bootsym_rel(trampoline_xen_phys_start, 4, %eax)
  1847.          mov     (%eax), %eax
  1848.          cmp     $0x9abcdef0, %eax
  1849. @@ -133,7 +135,7 @@
  1850.          mov     %ecx, %cr4
  1851.  
  1852.          /* Load pagetable base register */
  1853. -        mov     $sym_phys(idle_pg_table),%eax
  1854. +        lea     sym_offset(idle_pg_table)(%ebx),%eax
  1855.          add     bootsym_rel(trampoline_xen_phys_start,4,%eax)
  1856.          mov     %eax,%cr3
  1857.  
  1858. diff -Naur xen-9999-bef/xen/arch/x86/boot/x86_64.S xen-9999-aft/xen/arch/x86/boot/x86_64.S
  1859. --- xen-9999-bef/xen/arch/x86/boot/x86_64.S 2015-08-16 08:29:52.976771160 +0300
  1860. +++ xen-9999-aft/xen/arch/x86/boot/x86_64.S 2015-08-16 08:30:57.838765012 +0300
  1861. @@ -81,7 +81,6 @@
  1862.          .quad 0x0000910000000000     /* per-CPU entry (limit == cpu)      */
  1863.          .align PAGE_SIZE, 0
  1864.  
  1865. -GLOBAL(__page_tables_start)
  1866.  /*
  1867.   * Mapping of first 2 megabytes of memory. This is mapped with 4kB mappings
  1868.   * to avoid type conflicts with fixed-range MTRRs covering the lowest megabyte
  1869. @@ -101,21 +100,18 @@
  1870.          .endr
  1871.          .size l1_identmap, . - l1_identmap
  1872.  
  1873. -/* Mapping of first 16 megabytes of memory. */
  1874. +GLOBAL(__page_tables_start)
  1875. +
  1876.  GLOBAL(l2_identmap)
  1877. -        .quad sym_phys(l1_identmap) + __PAGE_HYPERVISOR
  1878. -        pfn = 0
  1879. -        .rept 7
  1880. -        pfn = pfn + (1 << PAGETABLE_ORDER)
  1881. -        .quad (pfn << PAGE_SHIFT) | PAGE_HYPERVISOR | _PAGE_PSE
  1882. -        .endr
  1883. -        .fill 4 * L2_PAGETABLE_ENTRIES - 8, 8, 0
  1884. +        .quad sym_offset(l1_identmap) + __PAGE_HYPERVISOR
  1885. +        .fill 4 * L2_PAGETABLE_ENTRIES - 1, 8, 0
  1886.          .size l2_identmap, . - l2_identmap
  1887.  
  1888.  GLOBAL(l2_xenmap)
  1889. -        idx = 0
  1890. -        .rept 8
  1891. -        .quad sym_phys(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE)
  1892. +        .quad 0
  1893. +        idx = 1
  1894. +        .rept 7
  1895. +        .quad sym_offset(__image_base__) + (idx << L2_PAGETABLE_SHIFT) + (PAGE_HYPERVISOR | _PAGE_PSE)
  1896.          idx = idx + 1
  1897.          .endr
  1898.          .fill L2_PAGETABLE_ENTRIES - 8, 8, 0
  1899. @@ -125,7 +121,7 @@
  1900.          idx = 0
  1901.          .rept L2_PAGETABLE_ENTRIES
  1902.          .if idx == l2_table_offset(FIXADDR_TOP - 1)
  1903. -        .quad sym_phys(l1_fixmap) + __PAGE_HYPERVISOR
  1904. +        .quad sym_offset(l1_fixmap) + __PAGE_HYPERVISOR
  1905.          .else
  1906.          .quad 0
  1907.          .endif
  1908. @@ -136,7 +132,7 @@
  1909.  GLOBAL(l3_identmap)
  1910.          idx = 0
  1911.          .rept 4
  1912. -        .quad sym_phys(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR
  1913. +        .quad sym_offset(l2_identmap) + (idx << PAGE_SHIFT) + __PAGE_HYPERVISOR
  1914.          idx = idx + 1
  1915.          .endr
  1916.          .fill L3_PAGETABLE_ENTRIES - 4, 8, 0
  1917. @@ -146,9 +142,9 @@
  1918.          idx = 0
  1919.          .rept L3_PAGETABLE_ENTRIES
  1920.          .if idx == l3_table_offset(XEN_VIRT_START)
  1921. -        .quad sym_phys(l2_xenmap) + __PAGE_HYPERVISOR
  1922. +        .quad sym_offset(l2_xenmap) + __PAGE_HYPERVISOR
  1923.          .elseif idx == l3_table_offset(FIXADDR_TOP - 1)
  1924. -        .quad sym_phys(l2_fixmap) + __PAGE_HYPERVISOR
  1925. +        .quad sym_offset(l2_fixmap) + __PAGE_HYPERVISOR
  1926.          .else
  1927.          .quad 0
  1928.          .endif
  1929. @@ -158,13 +154,13 @@
  1930.  
  1931.  /* Top-level master (and idle-domain) page directory. */
  1932.  GLOBAL(idle_pg_table)
  1933. -        .quad sym_phys(l3_bootmap) + __PAGE_HYPERVISOR
  1934. +        .quad sym_offset(l3_bootmap) + __PAGE_HYPERVISOR
  1935.          idx = 1
  1936.          .rept L4_PAGETABLE_ENTRIES - 1
  1937.          .if idx == l4_table_offset(DIRECTMAP_VIRT_START)
  1938. -        .quad sym_phys(l3_identmap) + __PAGE_HYPERVISOR
  1939. +        .quad sym_offset(l3_identmap) + __PAGE_HYPERVISOR
  1940.          .elseif idx == l4_table_offset(XEN_VIRT_START)
  1941. -        .quad sym_phys(l3_xenmap) + __PAGE_HYPERVISOR
  1942. +        .quad sym_offset(l3_xenmap) + __PAGE_HYPERVISOR
  1943.          .else
  1944.          .quad 0
  1945.          .endif
  1946. diff -Naur xen-9999-bef/xen/arch/x86/dmi_scan.c xen-9999-aft/xen/arch/x86/dmi_scan.c
  1947. --- xen-9999-bef/xen/arch/x86/dmi_scan.c    2015-08-16 08:29:52.979771160 +0300
  1948. +++ xen-9999-aft/xen/arch/x86/dmi_scan.c    2015-08-16 08:30:57.838765012 +0300
  1949. @@ -229,7 +229,7 @@
  1950.  {
  1951.     static unsigned int __initdata instance;
  1952.  
  1953. -   if (efi_enabled) {
  1954. +       if (efi_enabled(EFI_PLATFORM)) {
  1955.         if (efi_smbios3_size && !(instance & 1)) {
  1956.             *base = efi_smbios3_address;
  1957.             *len = efi_smbios3_size;
  1958. @@ -693,7 +693,7 @@
  1959.  
  1960.  void __init dmi_scan_machine(void)
  1961.  {
  1962. -   if ((!efi_enabled ? dmi_iterate(dmi_decode) :
  1963. +        if ((!efi_enabled(EFI_PLATFORM) ? dmi_iterate(dmi_decode) :
  1964.                         dmi_efi_iterate(dmi_decode)) == 0)
  1965.         dmi_check_system(dmi_blacklist);
  1966.     else
  1967. diff -Naur xen-9999-bef/xen/arch/x86/domain_page.c xen-9999-aft/xen/arch/x86/domain_page.c
  1968. --- xen-9999-bef/xen/arch/x86/domain_page.c 2015-08-16 08:29:52.979771160 +0300
  1969. +++ xen-9999-aft/xen/arch/x86/domain_page.c 2015-08-16 08:30:57.839765012 +0300
  1970. @@ -36,7 +36,7 @@
  1971.       * domain's page tables but current may point at another domain's VCPU.
  1972.       * Return NULL as though current is not properly set up yet.
  1973.       */
  1974. -    if ( efi_enabled && efi_rs_using_pgtables() )
  1975. +     if ( efi_enabled(EFI_PLATFORM) && efi_rs_using_pgtables() )
  1976.          return NULL;
  1977.  
  1978.      /*
  1979. diff -Naur xen-9999-bef/xen/arch/x86/efi/efi-boot.h xen-9999-aft/xen/arch/x86/efi/efi-boot.h
  1980. --- xen-9999-bef/xen/arch/x86/efi/efi-boot.h    2015-08-16 08:29:52.980771159 +0300
  1981. +++ xen-9999-aft/xen/arch/x86/efi/efi-boot.h    2015-08-16 08:30:57.839765012 +0300
  1982. @@ -103,9 +103,36 @@
  1983.          *(u16 *)(*trampoline_ptr + (long)trampoline_ptr) = phys >> 4;
  1984.  }
  1985.  
  1986. +#define EBMALLOC_SIZE  MB(1)
  1987. +
  1988. +static char __initdata ebmalloc_mem[EBMALLOC_SIZE];
  1989. +static char __initdata *ebmalloc_free = NULL;
  1990. +
  1991. +/* EFI boot allocator. */
  1992. +static void __init *ebmalloc(size_t size)
  1993. +{
  1994. +    void *ptr;
  1995. +
  1996. +    /*
  1997. +     * Init ebmalloc_free on runtime. Static initialization
  1998. +     * will not work because it puts virtual address there.
  1999. +     */
  2000. +    if ( ebmalloc_free == NULL )
  2001. +        ebmalloc_free = ebmalloc_mem;
  2002. +
  2003. +    ptr = ebmalloc_free;
  2004. +
  2005. +    ebmalloc_free += size;
  2006. +
  2007. +    if ( ebmalloc_free - ebmalloc_mem > sizeof(ebmalloc_mem) )
  2008. +        blexit(L"Out of static memory\r\n");
  2009. +
  2010. +    return ptr;
  2011. +}
  2012. +
  2013.  static void __init place_string(u32 *addr, const char *s)
  2014.  {
  2015. -    static char *__initdata alloc = start;
  2016. +    char *alloc = NULL;
  2017.  
  2018.      if ( s && *s )
  2019.      {
  2020. @@ -113,7 +140,7 @@
  2021.          const char *old = (char *)(long)*addr;
  2022.          size_t len2 = *addr ? strlen(old) + 1 : 0;
  2023.  
  2024. -        alloc -= len1 + len2;
  2025. +        alloc = ebmalloc(len1 + len2);
  2026.          /*
  2027.           * Insert new string before already existing one. This is needed
  2028.           * for options passed on the command line to override options from
  2029. @@ -196,16 +223,14 @@
  2030.  
  2031.  static void *__init efi_arch_allocate_mmap_buffer(UINTN map_size)
  2032.  {
  2033. -    place_string(&mbi.mem_upper, NULL);
  2034. -    mbi.mem_upper -= map_size;
  2035. -    mbi.mem_upper &= -__alignof__(EFI_MEMORY_DESCRIPTOR);
  2036. -    if ( mbi.mem_upper < xen_phys_start )
  2037. -        return NULL;
  2038. -    return (void *)(long)mbi.mem_upper;
  2039. +    return ebmalloc(map_size);
  2040.  }
  2041.  
  2042.  static void __init efi_arch_pre_exit_boot(void)
  2043.  {
  2044. +    if ( !efi_enabled(EFI_LOADER) )
  2045. +        return;
  2046. +
  2047.      if ( !trampoline_phys )
  2048.      {
  2049.          if ( !cfg.addr )
  2050. @@ -640,6 +665,33 @@
  2051.      return 1; /* x86 always uses a config file */
  2052.  }
  2053.  
  2054. +paddr_t __init efi_multiboot2(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
  2055. +{
  2056. +    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
  2057. +    UINTN cols, gop_mode = ~0, rows;
  2058. +
  2059. +    set_bit(EFI_PLATFORM, &efi.flags);
  2060. +
  2061. +    efi_init(ImageHandle, SystemTable);
  2062. +
  2063. +    efi_console_set_mode();
  2064. +
  2065. +    if ( StdOut->QueryMode(StdOut, StdOut->Mode->Mode,
  2066. +                           &cols, &rows) == EFI_SUCCESS )
  2067. +        efi_arch_console_init(cols, rows);
  2068. +
  2069. +    gop = efi_get_gop();
  2070. +    gop_mode = efi_find_gop_mode(gop, 0, 0, 0);
  2071. +    efi_arch_edd();
  2072. +    efi_tables();
  2073. +    setup_efi_pci();
  2074. +    efi_variables();
  2075. +    efi_set_gop_mode(gop, gop_mode);
  2076. +    efi_exit_boot(ImageHandle, SystemTable);
  2077. +
  2078. +    return cfg.addr;
  2079. +}
  2080. +
  2081.  /*
  2082.   * Local variables:
  2083.   * mode: C
  2084. diff -Naur xen-9999-bef/xen/arch/x86/efi/Makefile xen-9999-aft/xen/arch/x86/efi/Makefile
  2085. --- xen-9999-bef/xen/arch/x86/efi/Makefile  2015-08-16 08:29:52.980771159 +0300
  2086. +++ xen-9999-aft/xen/arch/x86/efi/Makefile  2015-08-16 08:30:57.840765012 +0300
  2087. @@ -1,14 +1,16 @@
  2088.  CFLAGS += -fshort-wchar
  2089.  
  2090. -obj-y += stub.o
  2091. -
  2092. -create = test -e $(1) || touch -t 199901010000 $(1)
  2093. -
  2094.  efi := $(filter y,$(x86_64)$(shell rm -f disabled))
  2095.  efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
  2096.  efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y))
  2097. -efi := $(if $(efi),$(shell rm disabled)y,$(shell $(call create,boot.init.o); $(call create,runtime.o)))
  2098. +efi := $(if $(efi),$(shell rm disabled)y)
  2099.  
  2100. -extra-$(efi) += boot.init.o relocs-dummy.o runtime.o compat.o
  2101. +extra-y += relocs-dummy.o
  2102.  
  2103. -stub.o: $(extra-y)
  2104. +ifeq ($(efi),y)
  2105. +obj-y += boot.init.o
  2106. +obj-y += compat.o
  2107. +obj-y += runtime.o
  2108. +else
  2109. +obj-y += stub.o
  2110. +endif
  2111. diff -Naur xen-9999-bef/xen/arch/x86/efi/stub.c xen-9999-aft/xen/arch/x86/efi/stub.c
  2112. --- xen-9999-bef/xen/arch/x86/efi/stub.c    2015-08-16 08:29:52.980771159 +0300
  2113. +++ xen-9999-aft/xen/arch/x86/efi/stub.c    2015-08-16 08:30:57.840765012 +0300
  2114. @@ -4,9 +4,19 @@
  2115.  #include <xen/lib.h>
  2116.  #include <asm/page.h>
  2117.  
  2118. -#ifndef efi_enabled
  2119. -const bool_t efi_enabled = 0;
  2120. -#endif
  2121. +struct efi __read_mostly efi = {
  2122. +       .flags   = 0, /* Initialized later. */
  2123. +       .acpi    = EFI_INVALID_TABLE_ADDR,
  2124. +       .acpi20  = EFI_INVALID_TABLE_ADDR,
  2125. +       .mps     = EFI_INVALID_TABLE_ADDR,
  2126. +       .smbios  = EFI_INVALID_TABLE_ADDR,
  2127. +       .smbios3 = EFI_INVALID_TABLE_ADDR
  2128. +};
  2129. +
  2130. +void __init efi_multiboot2(void)
  2131. +{
  2132. +    /* TODO: Fail if entered! */
  2133. +}
  2134.  
  2135.  void __init efi_init_memory(void) { }
  2136.  
  2137. diff -Naur xen-9999-bef/xen/arch/x86/Makefile xen-9999-aft/xen/arch/x86/Makefile
  2138. --- xen-9999-bef/xen/arch/x86/Makefile  2015-08-16 08:29:52.974771160 +0300
  2139. +++ xen-9999-aft/xen/arch/x86/Makefile  2015-08-16 08:30:57.841765012 +0300
  2140. @@ -72,15 +72,16 @@
  2141.                           echo '$(TARGET).efi'; fi)
  2142.  
  2143.  $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32
  2144. -   ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \
  2145. -   `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x/'`
  2146. -
  2147. +#      THIS IS UGLY HACK! PLEASE DO NOT COMPLAIN. I WILL FIX IT IN NEXT RELEASE.
  2148. +   ./boot/mkelf32 $(TARGET)-syms $(TARGET) $(XEN_IMG_PHYS_START) 0xffff82d081000000
  2149. +#      ./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000 \
  2150. +#      `$(NM) -nr $(TARGET)-syms | head -n 1 | sed -e 's/^\([^ ]*\).*/0x/'`
  2151.  
  2152.  ALL_OBJS := $(BASEDIR)/arch/x86/boot/built_in.o $(BASEDIR)/arch/x86/efi/built_in.o $(ALL_OBJS)
  2153.  
  2154.  ifeq ($(lto),y)
  2155.  # Gather all LTO objects together
  2156. -prelink_lto.o: $(ALL_OBJS)
  2157. +prelink_lto.o: $(ALL_OBJS) efi/relocs-dummy.o
  2158.     $(LD_LTO) -r -o $@ $^
  2159.  
  2160.  prelink-efi_lto.o: $(ALL_OBJS) efi/runtime.o efi/compat.o
  2161. @@ -90,14 +91,14 @@
  2162.  prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
  2163.     $(LD) $(LDFLAGS) -r -o $@ $^
  2164.  
  2165. -prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o efi/boot.init.o
  2166. +prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink-efi_lto.o
  2167.     $(guard) $(LD) $(LDFLAGS) -r -o $@ $^
  2168.  else
  2169. -prelink.o: $(ALL_OBJS)
  2170. +prelink.o: $(ALL_OBJS) efi/relocs-dummy.o
  2171.     $(LD) $(LDFLAGS) -r -o $@ $^
  2172.  
  2173. -prelink-efi.o: $(ALL_OBJS) efi/boot.init.o efi/runtime.o efi/compat.o
  2174. -   $(guard) $(LD) $(LDFLAGS) -r -o $@ $(filter-out %/efi/built_in.o,$^)
  2175. +prelink-efi.o: $(ALL_OBJS)
  2176. +   $(guard) $(LD) $(LDFLAGS) -r -o $@ $^
  2177.  endif
  2178.  
  2179.  $(BASEDIR)/common/symbols-dummy.o:
  2180. @@ -146,9 +147,6 @@
  2181.     if $(guard) false; then rm -f $@; echo 'EFI support disabled'; fi
  2182.     rm -f $(@D)/.$(@F).[0-9]*
  2183.  
  2184. -efi/boot.init.o efi/runtime.o efi/compat.o: $(BASEDIR)/arch/x86/efi/built_in.o
  2185. -efi/boot.init.o efi/runtime.o efi/compat.o: ;
  2186. -
  2187.  asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c
  2188.     $(CC) $(filter-out -flto,$(CFLAGS)) -S -o $@ $<
  2189.  
  2190. @@ -173,4 +171,4 @@
  2191.     rm -f asm-offsets.s *.lds boot/*.o boot/*~ boot/core boot/mkelf32
  2192.     rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d
  2193.     rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.o efi/.*.d efi/*.efi efi/disabled efi/mkreloc
  2194. -   rm -f boot/reloc.S boot/reloc.lnk boot/reloc.bin
  2195. +   rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin
  2196. diff -Naur xen-9999-bef/xen/arch/x86/mm.c xen-9999-aft/xen/arch/x86/mm.c
  2197. --- xen-9999-bef/xen/arch/x86/mm.c  2015-08-16 08:29:52.985771159 +0300
  2198. +++ xen-9999-aft/xen/arch/x86/mm.c  2015-08-16 08:30:57.842765012 +0300
  2199. @@ -343,7 +343,8 @@
  2200.  
  2201.      subarch_init_memory();
  2202.  
  2203. -    efi_init_memory();
  2204. +    if ( efi_enabled(EFI_PLATFORM) )
  2205. +        efi_init_memory();
  2206.  
  2207.      mem_sharing_init();
  2208.  
  2209. diff -Naur xen-9999-bef/xen/arch/x86/mpparse.c xen-9999-aft/xen/arch/x86/mpparse.c
  2210. --- xen-9999-bef/xen/arch/x86/mpparse.c 2015-08-16 08:29:52.987771159 +0300
  2211. +++ xen-9999-aft/xen/arch/x86/mpparse.c 2015-08-16 08:30:57.843765012 +0300
  2212. @@ -557,7 +557,7 @@
  2213.  
  2214.  static __init void efi_unmap_mpf(void)
  2215.  {
  2216. -   if (efi_enabled)
  2217. +        if (efi_enabled(EFI_PLATFORM))
  2218.         clear_fixmap(FIX_EFI_MPF);
  2219.  }
  2220.  
  2221. @@ -715,7 +715,7 @@
  2222.  {
  2223.     unsigned int address;
  2224.  
  2225. -   if (efi_enabled) {
  2226. +        if (efi_enabled(EFI_PLATFORM)) {
  2227.         efi_check_config();
  2228.         return;
  2229.     }
  2230. diff -Naur xen-9999-bef/xen/arch/x86/Rules.mk xen-9999-aft/xen/arch/x86/Rules.mk
  2231. --- xen-9999-bef/xen/arch/x86/Rules.mk  2015-08-16 08:29:52.974771160 +0300
  2232. +++ xen-9999-aft/xen/arch/x86/Rules.mk  2015-08-16 08:30:57.843765012 +0300
  2233. @@ -15,6 +15,10 @@
  2234.  HAS_PDX := y
  2235.  xenoprof := y
  2236.  
  2237. +XEN_IMG_PHYS_START = 0x200000
  2238. +
  2239. +CFLAGS += -DXEN_IMG_PHYS_START=$(XEN_IMG_PHYS_START)
  2240. +
  2241.  CFLAGS += -I$(BASEDIR)/include
  2242.  CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-generic
  2243.  CFLAGS += -I$(BASEDIR)/include/asm-x86/mach-default
  2244. diff -Naur xen-9999-bef/xen/arch/x86/setup.c xen-9999-aft/xen/arch/x86/setup.c
  2245. --- xen-9999-bef/xen/arch/x86/setup.c   2015-08-16 08:29:52.988771159 +0300
  2246. +++ xen-9999-aft/xen/arch/x86/setup.c   2015-08-16 08:30:57.844765012 +0300
  2247. @@ -291,9 +291,6 @@
  2248.      if ( start >= end )
  2249.          return NULL;
  2250.  
  2251. -    if ( end <= BOOTSTRAP_MAP_BASE )
  2252. -        return (void *)(unsigned long)start;
  2253. -
  2254.      ret = (void *)(map_cur + (unsigned long)(start & mask));
  2255.      start &= ~mask;
  2256.      end = (end + mask) & ~mask;
  2257. @@ -444,8 +441,8 @@
  2258.  {
  2259.      struct boot_video_info *bvi = &bootsym(boot_vid_info);
  2260.  
  2261. -    /* The EFI loader fills vga_console_info directly. */
  2262. -    if ( efi_enabled )
  2263. +    /* vga_console_info is filled directly on EFI platform. */
  2264. +    if ( efi_enabled(EFI_PLATFORM) )
  2265.          return;
  2266.  
  2267.      if ( (bvi->orig_video_isVGA == 1) && (bvi->orig_video_mode == 3) )
  2268. @@ -641,6 +638,9 @@
  2269.  
  2270.      printk("Command line: %s\n", cmdline);
  2271.  
  2272. +    printk("Xen image base address: 0x%08lx\n",
  2273. +           xen_phys_start ? xen_phys_start : (unsigned long)xen_img_base_phys_addr);
  2274. +
  2275.      printk("Video information:\n");
  2276.  
  2277.      /* Print VGA display mode information. */
  2278. @@ -695,7 +695,7 @@
  2279.      if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
  2280.          panic("dom0 kernel not specified. Check bootloader configuration.");
  2281.  
  2282. -    if ( efi_enabled )
  2283. +    if ( efi_enabled(EFI_LOADER) )
  2284.      {
  2285.          set_pdx_range(xen_phys_start >> PAGE_SHIFT,
  2286.                        (xen_phys_start + BOOTSTRAP_MAP_BASE) >> PAGE_SHIFT);
  2287. @@ -708,7 +708,11 @@
  2288.          l3_bootmap[l3_table_offset(BOOTSTRAP_MAP_BASE)] =
  2289.              l3e_from_paddr(__pa(l2_bootmap), __PAGE_HYPERVISOR);
  2290.  
  2291. -        memmap_type = loader;
  2292. +        memmap_type = "EFI";
  2293. +    }
  2294. +    else if ( efi_enabled(EFI_PLATFORM) )
  2295. +    {
  2296. +        memmap_type = "EFI";
  2297.      }
  2298.      else if ( e820_raw_nr != 0 )
  2299.      {
  2300. @@ -806,7 +810,7 @@
  2301.       * we can relocate the dom0 kernel and other multiboot modules. Also, on
  2302.       * x86/64, we relocate Xen to higher memory.
  2303.       */
  2304. -    for ( i = 0; !efi_enabled && i < mbi->mods_count; i++ )
  2305. +    for ( i = 0; !efi_enabled(EFI_LOADER) && i < mbi->mods_count; i++ )
  2306.      {
  2307.          if ( mod[i].mod_start & (PAGE_SIZE - 1) )
  2308.              panic("Bootloader didn't honor module alignment request.");
  2309. @@ -831,10 +835,8 @@
  2310.          uint64_t s, e, mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
  2311.          uint64_t end, limit = ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT;
  2312.  
  2313. -        /* Superpage-aligned chunks from BOOTSTRAP_MAP_BASE. */
  2314.          s = (boot_e820.map[i].addr + mask) & ~mask;
  2315.          e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;
  2316. -        s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
  2317.          if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) )
  2318.              continue;
  2319.  
  2320. @@ -872,7 +874,7 @@
  2321.              /* Select relocation address. */
  2322.              e = end - reloc_size;
  2323.              xen_phys_start = e;
  2324. -            bootsym(trampoline_xen_phys_start) = e;
  2325. +            bootsym(trampoline_xen_phys_start) = e - xen_img_base_phys_addr;
  2326.  
  2327.              /*
  2328.               * Perform relocation to new physical address.
  2329. @@ -882,7 +884,7 @@
  2330.               */
  2331.              load_start = (unsigned long)_start - XEN_VIRT_START;
  2332.              barrier();
  2333. -            move_memory(e + load_start, load_start, _end - _start, 1);
  2334. +            move_memory(e + load_start, load_start + xen_img_base_phys_addr, _end - _start, 1);
  2335.  
  2336.              /* Walk initial pagetables, relocating page directory entries. */
  2337.              pl4e = __va(__pa(idle_pg_table));
  2338. @@ -891,27 +893,27 @@
  2339.                  if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) )
  2340.                      continue;
  2341.                  *pl4e = l4e_from_intpte(l4e_get_intpte(*pl4e) +
  2342. -                                        xen_phys_start);
  2343. +                                        xen_phys_start - xen_img_base_phys_addr);
  2344.                  pl3e = l4e_to_l3e(*pl4e);
  2345.                  for ( j = 0; j < L3_PAGETABLE_ENTRIES; j++, pl3e++ )
  2346.                  {
  2347.                      /* Not present, 1GB mapping, or already relocated? */
  2348.                      if ( !(l3e_get_flags(*pl3e) & _PAGE_PRESENT) ||
  2349.                           (l3e_get_flags(*pl3e) & _PAGE_PSE) ||
  2350. -                         (l3e_get_pfn(*pl3e) > 0x1000) )
  2351. +                         (l3e_get_pfn(*pl3e) > PFN_DOWN(xen_phys_start)) )
  2352.                          continue;
  2353.                      *pl3e = l3e_from_intpte(l3e_get_intpte(*pl3e) +
  2354. -                                            xen_phys_start);
  2355. +                                            xen_phys_start - xen_img_base_phys_addr);
  2356.                      pl2e = l3e_to_l2e(*pl3e);
  2357.                      for ( k = 0; k < L2_PAGETABLE_ENTRIES; k++, pl2e++ )
  2358.                      {
  2359.                          /* Not present, PSE, or already relocated? */
  2360.                          if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) ||
  2361.                               (l2e_get_flags(*pl2e) & _PAGE_PSE) ||
  2362. -                             (l2e_get_pfn(*pl2e) > 0x1000) )
  2363. +                             (l2e_get_pfn(*pl2e) > PFN_DOWN(xen_phys_start)) )
  2364.                              continue;
  2365.                          *pl2e = l2e_from_intpte(l2e_get_intpte(*pl2e) +
  2366. -                                                xen_phys_start);
  2367. +                                                xen_phys_start - xen_img_base_phys_addr);
  2368.                      }
  2369.                  }
  2370.              }
  2371. @@ -922,10 +924,10 @@
  2372.                                     PAGE_HYPERVISOR_RWX | _PAGE_PSE);
  2373.              for ( i = 1; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
  2374.              {
  2375. -                if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) )
  2376. +                if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) || (l2e_get_pfn(*pl2e) > PFN_DOWN(xen_phys_start)))
  2377.                      continue;
  2378.                  *pl2e = l2e_from_intpte(l2e_get_intpte(*pl2e) +
  2379. -                                        xen_phys_start);
  2380. +                                        xen_phys_start - xen_img_base_phys_addr);
  2381.              }
  2382.  
  2383.              /* Re-sync the stack and then switch to relocated pagetables. */
  2384. @@ -994,8 +996,10 @@
  2385.  
  2386.      if ( !xen_phys_start )
  2387.          panic("Not enough memory to relocate Xen.");
  2388. -    reserve_e820_ram(&boot_e820, efi_enabled ? mbi->mem_upper : __pa(&_start),
  2389. -                     __pa(&_end));
  2390. +
  2391. +    printk("New Xen image base address: 0x%08lx\n", xen_phys_start);
  2392. +
  2393. +    reserve_e820_ram(&boot_e820, __pa(&_start), __pa(&_end));
  2394.  
  2395.      /* Late kexec reservation (dynamic start address). */
  2396.      kexec_reserve_area(&boot_e820);
  2397. @@ -1067,14 +1071,12 @@
  2398.  
  2399.          set_pdx_range(s >> PAGE_SHIFT, e >> PAGE_SHIFT);
  2400.  
  2401. -        /* Need to create mappings above BOOTSTRAP_MAP_BASE. */
  2402. -        map_s = max_t(uint64_t, s, BOOTSTRAP_MAP_BASE);
  2403. +        map_s = s;
  2404.          map_e = min_t(uint64_t, e,
  2405.                        ARRAY_SIZE(l2_identmap) << L2_PAGETABLE_SHIFT);
  2406.  
  2407.          /* Pass mapped memory to allocator /before/ creating new mappings. */
  2408.          init_boot_pages(s, min(map_s, e));
  2409. -        s = map_s;
  2410.          if ( s < map_e )
  2411.          {
  2412.              uint64_t mask = (1UL << L2_PAGETABLE_SHIFT) - 1;
  2413. diff -Naur xen-9999-bef/xen/arch/x86/shutdown.c xen-9999-aft/xen/arch/x86/shutdown.c
  2414. --- xen-9999-bef/xen/arch/x86/shutdown.c    2015-08-16 08:29:52.988771159 +0300
  2415. +++ xen-9999-aft/xen/arch/x86/shutdown.c    2015-08-16 08:30:57.844765012 +0300
  2416. @@ -116,7 +116,7 @@
  2417.  static void default_reboot_type(void)
  2418.  {
  2419.      if ( reboot_type == BOOT_INVALID )
  2420. -        reboot_type = efi_enabled ? BOOT_EFI
  2421. +        reboot_type = efi_enabled(EFI_PLATFORM) ? BOOT_EFI
  2422.                                    : acpi_disabled ? BOOT_KBD
  2423.                                                    : BOOT_ACPI;
  2424.  }
  2425. diff -Naur xen-9999-bef/xen/arch/x86/time.c xen-9999-aft/xen/arch/x86/time.c
  2426. --- xen-9999-bef/xen/arch/x86/time.c    2015-08-16 08:29:52.989771159 +0300
  2427. +++ xen-9999-aft/xen/arch/x86/time.c    2015-08-16 08:30:57.845765012 +0300
  2428. @@ -690,7 +690,7 @@
  2429.      static bool_t __read_mostly cmos_rtc_probe;
  2430.      boolean_param("cmos-rtc-probe", cmos_rtc_probe);
  2431.  
  2432. -    if ( efi_enabled )
  2433. +    if ( efi_enabled(EFI_PLATFORM) )
  2434.      {
  2435.          res = efi_get_time();
  2436.          if ( res )
  2437. diff -Naur xen-9999-bef/xen/arch/x86/x86_64/asm-offsets.c xen-9999-aft/xen/arch/x86/x86_64/asm-offsets.c
  2438. --- xen-9999-bef/xen/arch/x86/x86_64/asm-offsets.c  2015-08-16 08:29:52.990771159 +0300
  2439. +++ xen-9999-aft/xen/arch/x86/x86_64/asm-offsets.c  2015-08-16 08:30:57.845765012 +0300
  2440. @@ -13,6 +13,7 @@
  2441.  #include <asm/fixmap.h>
  2442.  #include <asm/hardirq.h>
  2443.  #include <xen/multiboot.h>
  2444. +#include <xen/multiboot2.h>
  2445.  
  2446.  #define DEFINE(_sym, _val)                                                 \
  2447.      asm volatile ("\n.ascii\"==>#define " #_sym " %0 /* " #_val " */<==\"" \
  2448. @@ -166,4 +167,13 @@
  2449.      OFFSET(MB_flags, multiboot_info_t, flags);
  2450.      OFFSET(MB_cmdline, multiboot_info_t, cmdline);
  2451.      OFFSET(MB_mem_lower, multiboot_info_t, mem_lower);
  2452. +    BLANK();
  2453. +
  2454. +    DEFINE(MB2_fixed_sizeof, sizeof(multiboot2_fixed_t));
  2455. +    OFFSET(MB2_tag_type, multiboot2_tag_t, type);
  2456. +    OFFSET(MB2_tag_size, multiboot2_tag_t, size);
  2457. +    OFFSET(MB2_base_addr, multiboot2_tag_base_addr_t, base_addr);
  2458. +    OFFSET(MB2_mem_lower, multiboot2_tag_basic_meminfo_t, mem_lower);
  2459. +    OFFSET(MB2_efi64_st, multiboot2_tag_efi64_t, pointer);
  2460. +    OFFSET(MB2_efi64_ih, multiboot2_tag_efi64_ih_t, pointer);
  2461.  }
  2462. diff -Naur xen-9999-bef/xen/arch/x86/x86_64/mm.c xen-9999-aft/xen/arch/x86/x86_64/mm.c
  2463. --- xen-9999-bef/xen/arch/x86/x86_64/mm.c   2015-08-16 08:29:52.991771158 +0300
  2464. +++ xen-9999-aft/xen/arch/x86/x86_64/mm.c   2015-08-16 08:30:57.846765012 +0300
  2465. @@ -43,7 +43,7 @@
  2466.  
  2467.  /* Enough page directories to map into the bottom 1GB. */
  2468.  l3_pgentry_t __section(".bss.page_aligned") l3_bootmap[L3_PAGETABLE_ENTRIES];
  2469. -l2_pgentry_t __section(".bss.page_aligned") l2_bootmap[L2_PAGETABLE_ENTRIES];
  2470. +l2_pgentry_t __section(".bss.page_aligned") l2_bootmap[4 * L2_PAGETABLE_ENTRIES];
  2471.  
  2472.  l2_pgentry_t *compat_idle_pg_table_l2;
  2473.  
  2474. diff -Naur xen-9999-bef/xen/arch/x86/xen.lds.S xen-9999-aft/xen/arch/x86/xen.lds.S
  2475. --- xen-9999-bef/xen/arch/x86/xen.lds.S 2015-08-16 08:29:52.992771158 +0300
  2476. +++ xen-9999-aft/xen/arch/x86/xen.lds.S 2015-08-16 08:30:57.846765012 +0300
  2477. @@ -38,7 +38,7 @@
  2478.    . = __XEN_VIRT_START;
  2479.    __image_base__ = .;
  2480.  #endif
  2481. -  . = __XEN_VIRT_START + MB(1);
  2482. ++  . = __XEN_VIRT_START + XEN_IMG_OFFSET;
  2483.    _start = .;
  2484.    .text : {
  2485.          _stext = .;            /* Text and read-only data */
  2486. @@ -162,6 +162,7 @@
  2487.    . = ALIGN(STACK_SIZE);
  2488.    __init_end = .;
  2489.  
  2490. +  . = ALIGN(8);
  2491.    .bss : {                     /* BSS */
  2492.         __bss_start = .;
  2493.         *(.bss.stack_aligned)
  2494. @@ -175,6 +176,7 @@
  2495.         *(.bss.percpu.read_mostly)
  2496.         . = ALIGN(SMP_CACHE_BYTES);
  2497.         __per_cpu_data_end = .;
  2498. +       . = ALIGN(8);
  2499.         __bss_end = .;
  2500.    } :text
  2501.    _end = . ;
  2502. @@ -189,8 +191,6 @@
  2503.    .pad : {
  2504.      . = ALIGN(MB(16));
  2505.    } :text
  2506. -#else
  2507. -  efi = .;
  2508.  #endif
  2509.  
  2510.    /* Sections to be discarded */
  2511. diff -Naur xen-9999-bef/xen/common/efi/boot.c xen-9999-aft/xen/common/efi/boot.c
  2512. --- xen-9999-bef/xen/common/efi/boot.c  2015-08-16 08:29:52.993771158 +0300
  2513. +++ xen-9999-aft/xen/common/efi/boot.c  2015-08-16 08:30:57.847765012 +0300
  2514. @@ -79,6 +79,17 @@
  2515.  static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz);
  2516.  static bool_t match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2);
  2517.  
  2518. +static void efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
  2519. +static void efi_console_set_mode(void);
  2520. +static EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_get_gop(void);
  2521. +static UINTN efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
  2522. +                               UINTN cols, UINTN rows, UINTN depth);
  2523. +static void efi_tables(void);
  2524. +static void setup_efi_pci(void);
  2525. +static void efi_variables(void);
  2526. +static void efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop_mode);
  2527. +static void efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
  2528. +
  2529.  static const EFI_BOOT_SERVICES *__initdata efi_bs;
  2530.  static UINT32 __initdata efi_bs_revision;
  2531.  static EFI_HANDLE __initdata efi_ih;
  2532. @@ -595,6 +606,161 @@
  2533.      return NULL;
  2534.  }
  2535.  
  2536. +static void __init efi_init(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
  2537. +{
  2538. +    efi_ih = ImageHandle;
  2539. +    efi_bs = SystemTable->BootServices;
  2540. +    efi_bs_revision = efi_bs->Hdr.Revision;
  2541. +    efi_rs = SystemTable->RuntimeServices;
  2542. +    efi_ct = SystemTable->ConfigurationTable;
  2543. +    efi_num_ct = SystemTable->NumberOfTableEntries;
  2544. +    efi_version = SystemTable->Hdr.Revision;
  2545. +    efi_fw_vendor = SystemTable->FirmwareVendor;
  2546. +    efi_fw_revision = SystemTable->FirmwareRevision;
  2547. +
  2548. +    StdOut = SystemTable->ConOut;
  2549. +    StdErr = SystemTable->StdErr ?: StdOut;
  2550. +}
  2551. +
  2552. +static void __init efi_console_set_mode(void)
  2553. +{
  2554. +    UINTN cols, rows, size;
  2555. +    unsigned int best, i;
  2556. +
  2557. +    for ( i = 0, size = 0, best = StdOut->Mode->Mode;
  2558. +          i < StdOut->Mode->MaxMode; ++i )
  2559. +    {
  2560. +        if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS &&
  2561. +             cols * rows > size )
  2562. +        {
  2563. +            size = cols * rows;
  2564. +            best = i;
  2565. +        }
  2566. +    }
  2567. +    if ( best != StdOut->Mode->Mode )
  2568. +        StdOut->SetMode(StdOut, best);
  2569. +}
  2570. +
  2571. +static EFI_GRAPHICS_OUTPUT_PROTOCOL __init *efi_get_gop(void)
  2572. +{
  2573. +    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
  2574. +    EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
  2575. +    EFI_HANDLE *handles;
  2576. +    EFI_STATUS status;
  2577. +    UINTN info_size, size = 0;
  2578. +    static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
  2579. +    unsigned int i;
  2580. +
  2581. +    status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL);
  2582. +    if ( status == EFI_BUFFER_TOO_SMALL )
  2583. +        status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles);
  2584. +    if ( !EFI_ERROR(status) )
  2585. +        status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size,
  2586. +                                      handles);
  2587. +    if ( EFI_ERROR(status) )
  2588. +        size = 0;
  2589. +    for ( i = 0; i < size / sizeof(*handles); ++i )
  2590. +    {
  2591. +        status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop);
  2592. +        if ( EFI_ERROR(status) )
  2593. +            continue;
  2594. +        status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
  2595. +        if ( !EFI_ERROR(status) )
  2596. +            break;
  2597. +    }
  2598. +    if ( handles )
  2599. +        efi_bs->FreePool(handles);
  2600. +    if ( EFI_ERROR(status) )
  2601. +        gop = NULL;
  2602. +
  2603. +    return gop;
  2604. +}
  2605. +
  2606. +static UINTN __init efi_find_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop,
  2607. +                                      UINTN cols, UINTN rows, UINTN depth)
  2608. +{
  2609. +    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
  2610. +    EFI_STATUS status;
  2611. +    UINTN gop_mode = ~0, info_size, size;
  2612. +    unsigned int i;
  2613. +
  2614. +    if ( !gop )
  2615. +        return gop_mode;
  2616. +
  2617. +    for ( i = size = 0; i < gop->Mode->MaxMode; ++i )
  2618. +    {
  2619. +        unsigned int bpp = 0;
  2620. +
  2621. +        status = gop->QueryMode(gop, i, &info_size, &mode_info);
  2622. +        if ( EFI_ERROR(status) )
  2623. +            continue;
  2624. +        switch ( mode_info->PixelFormat )
  2625. +        {
  2626. +        case PixelBitMask:
  2627. +            bpp = hweight32(mode_info->PixelInformation.RedMask |
  2628. +                            mode_info->PixelInformation.GreenMask |
  2629. +                            mode_info->PixelInformation.BlueMask);
  2630. +            break;
  2631. +        case PixelRedGreenBlueReserved8BitPerColor:
  2632. +        case PixelBlueGreenRedReserved8BitPerColor:
  2633. +            bpp = 24;
  2634. +            break;
  2635. +        default:
  2636. +            continue;
  2637. +        }
  2638. +        if ( cols == mode_info->HorizontalResolution &&
  2639. +             rows == mode_info->VerticalResolution &&
  2640. +             (!depth || bpp == depth) )
  2641. +        {
  2642. +            gop_mode = i;
  2643. +            break;
  2644. +        }
  2645. +        if ( !cols && !rows &&
  2646. +             mode_info->HorizontalResolution *
  2647. +             mode_info->VerticalResolution > size )
  2648. +        {
  2649. +            size = mode_info->HorizontalResolution *
  2650. +                   mode_info->VerticalResolution;
  2651. +            gop_mode = i;
  2652. +        }
  2653. +    }
  2654. +
  2655. +    return gop_mode;
  2656. +}
  2657. +
  2658. +static void __init efi_tables(void)
  2659. +{
  2660. +    unsigned int i;
  2661. +
  2662. +    /* Obtain basic table pointers. */
  2663. +    for ( i = 0; i < efi_num_ct; ++i )
  2664. +    {
  2665. +        static EFI_GUID __initdata acpi2_guid = ACPI_20_TABLE_GUID;
  2666. +        static EFI_GUID __initdata acpi_guid = ACPI_TABLE_GUID;
  2667. +        static EFI_GUID __initdata mps_guid = MPS_TABLE_GUID;
  2668. +        static EFI_GUID __initdata smbios_guid = SMBIOS_TABLE_GUID;
  2669. +        static EFI_GUID __initdata smbios3_guid = SMBIOS3_TABLE_GUID;
  2670. +
  2671. +        if ( match_guid(&acpi2_guid, &efi_ct[i].VendorGuid) )
  2672. +              efi.acpi20 = (long)efi_ct[i].VendorTable;
  2673. +        if ( match_guid(&acpi_guid, &efi_ct[i].VendorGuid) )
  2674. +              efi.acpi = (long)efi_ct[i].VendorTable;
  2675. +        if ( match_guid(&mps_guid, &efi_ct[i].VendorGuid) )
  2676. +              efi.mps = (long)efi_ct[i].VendorTable;
  2677. +        if ( match_guid(&smbios_guid, &efi_ct[i].VendorGuid) )
  2678. +              efi.smbios = (long)efi_ct[i].VendorTable;
  2679. +        if ( match_guid(&smbios3_guid, &efi_ct[i].VendorGuid) )
  2680. +              efi.smbios3 = (long)efi_ct[i].VendorTable;
  2681. +    }
  2682. +
  2683. +#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
  2684. +    dmi_efi_get_table(efi.smbios != EFI_INVALID_TABLE_ADDR
  2685. +                      ? (void *)(long)efi.smbios : NULL,
  2686. +                      efi.smbios3 != EFI_INVALID_TABLE_ADDR
  2687. +                      ? (void *)(long)efi.smbios3 : NULL);
  2688. +#endif
  2689. +}
  2690. +
  2691.  static void __init setup_efi_pci(void)
  2692.  {
  2693.      EFI_STATUS status;
  2694. @@ -682,6 +848,95 @@
  2695.      efi_bs->FreePool(handles);
  2696.  }
  2697.  
  2698. +static void __init efi_variables(void)
  2699. +{
  2700. +    EFI_STATUS status;
  2701. +
  2702. +    status = (efi_rs->Hdr.Revision >> 16) >= 2 ?
  2703. +             efi_rs->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE |
  2704. +                                       EFI_VARIABLE_BOOTSERVICE_ACCESS |
  2705. +                                       EFI_VARIABLE_RUNTIME_ACCESS,
  2706. +                                       &efi_boot_max_var_store_size,
  2707. +                                       &efi_boot_remain_var_store_size,
  2708. +                                       &efi_boot_max_var_size) :
  2709. +             EFI_INCOMPATIBLE_VERSION;
  2710. +    if ( EFI_ERROR(status) )
  2711. +    {
  2712. +        efi_boot_max_var_store_size = 0;
  2713. +        efi_boot_remain_var_store_size = 0;
  2714. +        efi_boot_max_var_size = status;
  2715. +        PrintStr(L"Warning: Could not query variable store: ");
  2716. +        DisplayUint(status, 0);
  2717. +        PrintStr(newline);
  2718. +    }
  2719. +}
  2720. +
  2721. +static void __init efi_set_gop_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, UINTN gop_mode)
  2722. +{
  2723. +    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
  2724. +    EFI_STATUS status;
  2725. +    UINTN info_size;
  2726. +
  2727. +    if ( !gop )
  2728. +        return;
  2729. +
  2730. +    /* Set graphics mode. */
  2731. +    if ( gop_mode < gop->Mode->MaxMode && gop_mode != gop->Mode->Mode )
  2732. +        gop->SetMode(gop, gop_mode);
  2733. +
  2734. +    /* Get graphics and frame buffer info. */
  2735. +    status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
  2736. +    if ( !EFI_ERROR(status) )
  2737. +        efi_arch_video_init(gop, info_size, mode_info);
  2738. +}
  2739. +
  2740. +static void __init efi_exit_boot(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
  2741. +{
  2742. +    EFI_STATUS status;
  2743. +    UINTN info_size = 0, map_key;
  2744. +    bool_t retry;
  2745. +
  2746. +    efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
  2747. +                         &efi_mdesc_size, &mdesc_ver);
  2748. +    info_size += 8 * efi_mdesc_size;
  2749. +    efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
  2750. +    if ( !efi_memmap )
  2751. +        blexit(L"Unable to allocate memory for EFI memory map");
  2752. +
  2753. +    for ( retry = 0; ; retry = 1 )
  2754. +    {
  2755. +        efi_memmap_size = info_size;
  2756. +        status = SystemTable->BootServices->GetMemoryMap(&efi_memmap_size,
  2757. +                                                         efi_memmap, &map_key,
  2758. +                                                         &efi_mdesc_size,
  2759. +                                                         &mdesc_ver);
  2760. +        if ( EFI_ERROR(status) )
  2761. +            PrintErrMesg(L"Cannot obtain memory map", status);
  2762. +
  2763. +        efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
  2764. +                                    efi_mdesc_size, mdesc_ver);
  2765. +
  2766. +        efi_arch_pre_exit_boot();
  2767. +
  2768. +        status = SystemTable->BootServices->ExitBootServices(ImageHandle,
  2769. +                                                             map_key);
  2770. +        efi_bs = NULL;
  2771. +        if ( status != EFI_INVALID_PARAMETER || retry )
  2772. +            break;
  2773. +    }
  2774. +
  2775. +    if ( EFI_ERROR(status) )
  2776. +        PrintErrMesg(L"Cannot exit boot services", status);
  2777. +
  2778. +    /* Adjust pointers into EFI. */
  2779. +    efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
  2780. +#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
  2781. +    efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START;
  2782. +#endif
  2783. +    efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
  2784. +    efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
  2785. +}
  2786. +
  2787.  static int __init __maybe_unused set_color(u32 mask, int bpp, u8 *pos, u8 *sz)
  2788.  {
  2789.     if ( bpp < 0 )
  2790. @@ -701,34 +956,26 @@
  2791.  efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
  2792.  {
  2793.      static EFI_GUID __initdata loaded_image_guid = LOADED_IMAGE_PROTOCOL;
  2794. -    static EFI_GUID __initdata gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
  2795.      static EFI_GUID __initdata shim_lock_guid = SHIM_LOCK_PROTOCOL_GUID;
  2796.      EFI_LOADED_IMAGE *loaded_image;
  2797.      EFI_STATUS status;
  2798.      unsigned int i, argc;
  2799.      CHAR16 **argv, *file_name, *cfg_file_name = NULL, *options = NULL;
  2800. -    UINTN map_key, info_size, gop_mode = ~0;
  2801. -    EFI_HANDLE *handles = NULL;
  2802. +    UINTN gop_mode = ~0;
  2803.      EFI_SHIM_LOCK_PROTOCOL *shim_lock;
  2804.      EFI_GRAPHICS_OUTPUT_PROTOCOL *gop = NULL;
  2805. -    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *mode_info;
  2806.      union string section = { NULL }, name;
  2807. -    bool_t base_video = 0, retry;
  2808. +    bool_t base_video = 0;
  2809.      char *option_str;
  2810.      bool_t use_cfg_file;
  2811.  
  2812. -    efi_ih = ImageHandle;
  2813. -    efi_bs = SystemTable->BootServices;
  2814. -    efi_bs_revision = efi_bs->Hdr.Revision;
  2815. -    efi_rs = SystemTable->RuntimeServices;
  2816. -    efi_ct = SystemTable->ConfigurationTable;
  2817. -    efi_num_ct = SystemTable->NumberOfTableEntries;
  2818. -    efi_version = SystemTable->Hdr.Revision;
  2819. -    efi_fw_vendor = SystemTable->FirmwareVendor;
  2820. -    efi_fw_revision = SystemTable->FirmwareRevision;
  2821. +#ifndef CONFIG_ARM /* Disabled until runtime services implemented. */
  2822. +    set_bit(EFI_PLATFORM, &efi.flags);
  2823. +    set_bit(EFI_LOADER, &efi.flags);
  2824. +#endif
  2825. +
  2826. +    efi_init(ImageHandle, SystemTable);
  2827.  
  2828. -    StdOut = SystemTable->ConOut;
  2829. -    StdErr = SystemTable->StdErr ?: StdOut;
  2830.      use_cfg_file = efi_arch_use_config_file(SystemTable);
  2831.  
  2832.      status = efi_bs->HandleProtocol(ImageHandle, &loaded_image_guid,
  2833. @@ -789,23 +1036,7 @@
  2834.          }
  2835.  
  2836.          if ( !base_video )
  2837. -        {
  2838. -            unsigned int best;
  2839. -            UINTN cols, rows, size;
  2840. -
  2841. -            for ( i = 0, size = 0, best = StdOut->Mode->Mode;
  2842. -                  i < StdOut->Mode->MaxMode; ++i )
  2843. -            {
  2844. -                if ( StdOut->QueryMode(StdOut, i, &cols, &rows) == EFI_SUCCESS &&
  2845. -                     cols * rows > size )
  2846. -                {
  2847. -                    size = cols * rows;
  2848. -                    best = i;
  2849. -                }
  2850. -            }
  2851. -            if ( best != StdOut->Mode->Mode )
  2852. -                StdOut->SetMode(StdOut, best);
  2853. -        }
  2854. +            efi_console_set_mode();
  2855.      }
  2856.  
  2857.      PrintStr(L"Xen " __stringify(XEN_VERSION) "." __stringify(XEN_SUBVERSION)
  2858. @@ -824,27 +1055,7 @@
  2859.                                 &cols, &rows) == EFI_SUCCESS )
  2860.              efi_arch_console_init(cols, rows);
  2861.  
  2862. -        status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size, NULL);
  2863. -        if ( status == EFI_BUFFER_TOO_SMALL )
  2864. -            status = efi_bs->AllocatePool(EfiLoaderData, size, (void **)&handles);
  2865. -        if ( !EFI_ERROR(status) )
  2866. -            status = efi_bs->LocateHandle(ByProtocol, &gop_guid, NULL, &size,
  2867. -                                          handles);
  2868. -        if ( EFI_ERROR(status) )
  2869. -            size = 0;
  2870. -        for ( i = 0; i < size / sizeof(*handles); ++i )
  2871. -        {
  2872. -            status = efi_bs->HandleProtocol(handles[i], &gop_guid, (void **)&gop);
  2873. -            if ( EFI_ERROR(status) )
  2874. -                continue;
  2875. -            status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
  2876. -            if ( !EFI_ERROR(status) )
  2877. -                break;
  2878. -        }
  2879. -        if ( handles )
  2880. -            efi_bs->FreePool(handles);
  2881. -        if ( EFI_ERROR(status) )
  2882. -            gop = NULL;
  2883. +        gop = efi_get_gop();
  2884.  
  2885.          /* Get the file system interface. */
  2886.          dir_handle = get_parent_handle(loaded_image, &file_name);
  2887. @@ -952,46 +1163,8 @@
  2888.  
  2889.          dir_handle->Close(dir_handle);
  2890.  
  2891. -        if ( gop && !base_video )
  2892. -        {
  2893. -            for ( i = size = 0; i < gop->Mode->MaxMode; ++i )
  2894. -            {
  2895. -                unsigned int bpp = 0;
  2896. -
  2897. -                status = gop->QueryMode(gop, i, &info_size, &mode_info);
  2898. -                if ( EFI_ERROR(status) )
  2899. -                    continue;
  2900. -                switch ( mode_info->PixelFormat )
  2901. -                {
  2902. -                case PixelBitMask:
  2903. -                    bpp = hweight32(mode_info->PixelInformation.RedMask |
  2904. -                                    mode_info->PixelInformation.GreenMask |
  2905. -                                    mode_info->PixelInformation.BlueMask);
  2906. -                    break;
  2907. -                case PixelRedGreenBlueReserved8BitPerColor:
  2908. -                case PixelBlueGreenRedReserved8BitPerColor:
  2909. -                    bpp = 24;
  2910. -                    break;
  2911. -                default:
  2912. -                    continue;
  2913. -                }
  2914. -                if ( cols == mode_info->HorizontalResolution &&
  2915. -                     rows == mode_info->VerticalResolution &&
  2916. -                     (!depth || bpp == depth) )
  2917. -                {
  2918. -                    gop_mode = i;
  2919. -                    break;
  2920. -                }
  2921. -                if ( !cols && !rows &&
  2922. -                     mode_info->HorizontalResolution *
  2923. -                     mode_info->VerticalResolution > size )
  2924. -                {
  2925. -                    size = mode_info->HorizontalResolution *
  2926. -                           mode_info->VerticalResolution;
  2927. -                    gop_mode = i;
  2928. -                }
  2929. -            }
  2930. -        }
  2931. +        if ( !base_video )
  2932. +            gop_mode = efi_find_gop_mode(gop, cols, rows, depth);
  2933.      }
  2934.  
  2935.      efi_arch_edd();
  2936. @@ -999,111 +1172,19 @@
  2937.      /* XXX Collect EDID info. */
  2938.      efi_arch_cpu();
  2939.  
  2940. -    /* Obtain basic table pointers. */
  2941. -    for ( i = 0; i < efi_num_ct; ++i )
  2942. -    {
  2943. -        static EFI_GUID __initdata acpi2_guid = ACPI_20_TABLE_GUID;
  2944. -        static EFI_GUID __initdata acpi_guid = ACPI_TABLE_GUID;
  2945. -        static EFI_GUID __initdata mps_guid = MPS_TABLE_GUID;
  2946. -        static EFI_GUID __initdata smbios_guid = SMBIOS_TABLE_GUID;
  2947. -        static EFI_GUID __initdata smbios3_guid = SMBIOS3_TABLE_GUID;
  2948. -
  2949. -        if ( match_guid(&acpi2_guid, &efi_ct[i].VendorGuid) )
  2950. -          efi.acpi20 = (long)efi_ct[i].VendorTable;
  2951. -        if ( match_guid(&acpi_guid, &efi_ct[i].VendorGuid) )
  2952. -          efi.acpi = (long)efi_ct[i].VendorTable;
  2953. -        if ( match_guid(&mps_guid, &efi_ct[i].VendorGuid) )
  2954. -          efi.mps = (long)efi_ct[i].VendorTable;
  2955. -        if ( match_guid(&smbios_guid, &efi_ct[i].VendorGuid) )
  2956. -          efi.smbios = (long)efi_ct[i].VendorTable;
  2957. -        if ( match_guid(&smbios3_guid, &efi_ct[i].VendorGuid) )
  2958. -          efi.smbios3 = (long)efi_ct[i].VendorTable;
  2959. -    }
  2960. -
  2961. -#ifndef CONFIG_ARM /* TODO - disabled until implemented on ARM */
  2962. -    dmi_efi_get_table(efi.smbios != EFI_INVALID_TABLE_ADDR
  2963. -                      ? (void *)(long)efi.smbios : NULL,
  2964. -                      efi.smbios3 != EFI_INVALID_TABLE_ADDR
  2965. -                      ? (void *)(long)efi.smbios3 : NULL);
  2966. -#endif
  2967. +    efi_tables();
  2968.  
  2969.      /* Collect PCI ROM contents. */
  2970.      setup_efi_pci();
  2971.  
  2972.      /* Get snapshot of variable store parameters. */
  2973. -    status = (efi_rs->Hdr.Revision >> 16) >= 2 ?
  2974. -             efi_rs->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE |
  2975. -                                       EFI_VARIABLE_BOOTSERVICE_ACCESS |
  2976. -                                       EFI_VARIABLE_RUNTIME_ACCESS,
  2977. -                                       &efi_boot_max_var_store_size,
  2978. -                                       &efi_boot_remain_var_store_size,
  2979. -                                       &efi_boot_max_var_size) :
  2980. -             EFI_INCOMPATIBLE_VERSION;
  2981. -    if ( EFI_ERROR(status) )
  2982. -    {
  2983. -        efi_boot_max_var_store_size = 0;
  2984. -        efi_boot_remain_var_store_size = 0;
  2985. -        efi_boot_max_var_size = status;
  2986. -        PrintStr(L"Warning: Could not query variable store: ");
  2987. -        DisplayUint(status, 0);
  2988. -        PrintStr(newline);
  2989. -    }
  2990. +    efi_variables();
  2991.  
  2992.      efi_arch_memory_setup();
  2993.  
  2994. -    if ( gop )
  2995. -    {
  2996. -
  2997. -        /* Set graphics mode. */
  2998. -        if ( gop_mode < gop->Mode->MaxMode && gop_mode != gop->Mode->Mode )
  2999. -            gop->SetMode(gop, gop_mode);
  3000. +    efi_set_gop_mode(gop, gop_mode);
  3001.  
  3002. -        /* Get graphics and frame buffer info. */
  3003. -        status = gop->QueryMode(gop, gop->Mode->Mode, &info_size, &mode_info);
  3004. -        if ( !EFI_ERROR(status) )
  3005. -            efi_arch_video_init(gop, info_size, mode_info);
  3006. -    }
  3007. -
  3008. -    info_size = 0;
  3009. -    efi_bs->GetMemoryMap(&info_size, NULL, &map_key,
  3010. -                         &efi_mdesc_size, &mdesc_ver);
  3011. -    info_size += 8 * efi_mdesc_size;
  3012. -    efi_memmap = efi_arch_allocate_mmap_buffer(info_size);
  3013. -    if ( !efi_memmap )
  3014. -        blexit(L"Unable to allocate memory for EFI memory map");
  3015. -
  3016. -    for ( retry = 0; ; retry = 1 )
  3017. -    {
  3018. -        efi_memmap_size = info_size;
  3019. -        status = SystemTable->BootServices->GetMemoryMap(&efi_memmap_size,
  3020. -                                                         efi_memmap, &map_key,
  3021. -                                                         &efi_mdesc_size,
  3022. -                                                         &mdesc_ver);
  3023. -        if ( EFI_ERROR(status) )
  3024. -            PrintErrMesg(L"Cannot obtain memory map", status);
  3025. -
  3026. -        efi_arch_process_memory_map(SystemTable, efi_memmap, efi_memmap_size,
  3027. -                                    efi_mdesc_size, mdesc_ver);
  3028. -
  3029. -        efi_arch_pre_exit_boot();
  3030. -
  3031. -        status = SystemTable->BootServices->ExitBootServices(ImageHandle,
  3032. -                                                             map_key);
  3033. -        efi_bs = NULL;
  3034. -        if ( status != EFI_INVALID_PARAMETER || retry )
  3035. -            break;
  3036. -    }
  3037. -
  3038. -    if ( EFI_ERROR(status) )
  3039. -        PrintErrMesg(L"Cannot exit boot services", status);
  3040. -
  3041. -    /* Adjust pointers into EFI. */
  3042. -    efi_ct = (void *)efi_ct + DIRECTMAP_VIRT_START;
  3043. -#ifdef USE_SET_VIRTUAL_ADDRESS_MAP
  3044. -    efi_rs = (void *)efi_rs + DIRECTMAP_VIRT_START;
  3045. -#endif
  3046. -    efi_memmap = (void *)efi_memmap + DIRECTMAP_VIRT_START;
  3047. -    efi_fw_vendor = (void *)efi_fw_vendor + DIRECTMAP_VIRT_START;
  3048. +    efi_exit_boot(ImageHandle, SystemTable);
  3049.  
  3050.      efi_arch_post_exit_boot();
  3051.      for( ; ; ); /* not reached */
  3052. diff -Naur xen-9999-bef/xen/common/efi/runtime.c xen-9999-aft/xen/common/efi/runtime.c
  3053. --- xen-9999-bef/xen/common/efi/runtime.c   2015-08-16 08:29:52.994771158 +0300
  3054. +++ xen-9999-aft/xen/common/efi/runtime.c   2015-08-16 08:30:57.848765011 +0300
  3055. @@ -10,14 +10,10 @@
  3056.  
  3057.  #ifndef COMPAT
  3058.  
  3059. -#ifdef CONFIG_ARM  /* Disabled until runtime services implemented */
  3060. -const bool_t efi_enabled = 0;
  3061. -#else
  3062. +#ifndef CONFIG_ARM
  3063.  # include <asm/i387.h>
  3064.  # include <asm/xstate.h>
  3065.  # include <public/platform.h>
  3066. -
  3067. -const bool_t efi_enabled = 1;
  3068.  #endif
  3069.  
  3070.  unsigned int __read_mostly efi_num_ct;
  3071. @@ -42,11 +38,12 @@
  3072.  UINT64 __read_mostly efi_boot_max_var_size;
  3073.  
  3074.  struct efi __read_mostly efi = {
  3075. -   .acpi   = EFI_INVALID_TABLE_ADDR,
  3076. -   .acpi20 = EFI_INVALID_TABLE_ADDR,
  3077. -   .mps    = EFI_INVALID_TABLE_ADDR,
  3078. -   .smbios = EFI_INVALID_TABLE_ADDR,
  3079. -   .smbios3 = EFI_INVALID_TABLE_ADDR,
  3080. +       .flags   = 0, /* Initialized later. */
  3081. +       .acpi    = EFI_INVALID_TABLE_ADDR,
  3082. +       .acpi20  = EFI_INVALID_TABLE_ADDR,
  3083. +       .mps     = EFI_INVALID_TABLE_ADDR,
  3084. +       .smbios  = EFI_INVALID_TABLE_ADDR,
  3085. +       .smbios3 = EFI_INVALID_TABLE_ADDR
  3086.  };
  3087.  
  3088.  const struct efi_pci_rom *__read_mostly efi_pci_roms;
  3089. @@ -170,6 +167,9 @@
  3090.  {
  3091.      unsigned int i, n;
  3092.  
  3093. +    if ( !efi_enabled(EFI_PLATFORM) )
  3094. +        return -EOPNOTSUPP;
  3095. +
  3096.      switch ( idx )
  3097.      {
  3098.      case XEN_FW_EFI_VERSION:
  3099. @@ -304,6 +304,9 @@
  3100.      EFI_STATUS status = EFI_NOT_STARTED;
  3101.      int rc = 0;
  3102.  
  3103. +    if ( !efi_enabled(EFI_PLATFORM) )
  3104. +        return -EOPNOTSUPP;
  3105. +
  3106.      switch ( op->function )
  3107.      {
  3108.      case XEN_EFI_get_time:
  3109. diff -Naur xen-9999-bef/xen/drivers/acpi/osl.c xen-9999-aft/xen/drivers/acpi/osl.c
  3110. --- xen-9999-bef/xen/drivers/acpi/osl.c 2015-08-16 08:29:53.001771157 +0300
  3111. +++ xen-9999-aft/xen/drivers/acpi/osl.c 2015-08-16 08:30:57.848765011 +0300
  3112. @@ -65,7 +65,7 @@
  3113.  
  3114.  acpi_physical_address __init acpi_os_get_root_pointer(void)
  3115.  {
  3116. -   if (efi_enabled) {
  3117. +       if (efi_enabled(EFI_PLATFORM)) {
  3118.         if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
  3119.             return efi.acpi20;
  3120.         else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
  3121. diff -Naur xen-9999-bef/xen/include/asm-x86/config.h xen-9999-aft/xen/include/asm-x86/config.h
  3122. --- xen-9999-bef/xen/include/asm-x86/config.h   2015-08-16 08:29:53.017771156 +0300
  3123. +++ xen-9999-aft/xen/include/asm-x86/config.h   2015-08-16 08:30:57.849765011 +0300
  3124. @@ -114,6 +114,7 @@
  3125.                   trampoline_phys-__pa(trampoline_start)))
  3126.  extern char trampoline_start[], trampoline_end[];
  3127.  extern char trampoline_realmode_entry[];
  3128. +extern unsigned int xen_img_base_phys_addr;
  3129.  extern unsigned int trampoline_xen_phys_start;
  3130.  extern unsigned char trampoline_cpu_started;
  3131.  extern char wakeup_start[];
  3132. @@ -280,6 +281,8 @@
  3133.  #endif
  3134.  #define DIRECTMAP_VIRT_END      (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE)
  3135.  
  3136. +#define XEN_IMG_OFFSET          0x200000
  3137. +
  3138.  #ifndef __ASSEMBLY__
  3139.  
  3140.  /* This is not a fixed value, just a lower limit. */
  3141. diff -Naur xen-9999-bef/xen/include/asm-x86/page.h xen-9999-aft/xen/include/asm-x86/page.h
  3142. --- xen-9999-bef/xen/include/asm-x86/page.h 2015-08-16 08:29:53.023771155 +0300
  3143. +++ xen-9999-aft/xen/include/asm-x86/page.h 2015-08-16 08:30:57.849765011 +0300
  3144. @@ -283,7 +283,7 @@
  3145.  extern l2_pgentry_t  *compat_idle_pg_table_l2;
  3146.  extern unsigned int   m2p_compat_vstart;
  3147.  extern l2_pgentry_t l2_xenmap[L2_PAGETABLE_ENTRIES],
  3148. -    l2_bootmap[L2_PAGETABLE_ENTRIES];
  3149. +    l2_bootmap[4*L2_PAGETABLE_ENTRIES];
  3150.  extern l3_pgentry_t l3_bootmap[L3_PAGETABLE_ENTRIES];
  3151.  extern l2_pgentry_t l2_identmap[4*L2_PAGETABLE_ENTRIES];
  3152.  extern l1_pgentry_t l1_identmap[L1_PAGETABLE_ENTRIES],
  3153. diff -Naur xen-9999-bef/xen/include/xen/efi.h xen-9999-aft/xen/include/xen/efi.h
  3154. --- xen-9999-bef/xen/include/xen/efi.h  2015-08-16 08:29:53.033771154 +0300
  3155. +++ xen-9999-aft/xen/include/xen/efi.h  2015-08-16 08:30:57.850765011 +0300
  3156. @@ -2,15 +2,18 @@
  3157.  #define __XEN_EFI_H__
  3158.  
  3159.  #ifndef __ASSEMBLY__
  3160. +#include <xen/bitops.h>
  3161.  #include <xen/types.h>
  3162.  #endif
  3163.  
  3164. -extern const bool_t efi_enabled;
  3165. -
  3166.  #define EFI_INVALID_TABLE_ADDR (~0UL)
  3167.  
  3168. +#define EFI_PLATFORM   0
  3169. +#define EFI_LOADER     1
  3170. +
  3171.  /* Add fields here only if they need to be referenced from non-EFI code. */
  3172.  struct efi {
  3173. +    unsigned long flags;
  3174.      unsigned long mps;          /* MPS table */
  3175.      unsigned long acpi;         /* ACPI table (IA64 ext 0.71) */
  3176.      unsigned long acpi20;       /* ACPI table (ACPI 2.0) */
  3177. @@ -40,6 +43,16 @@
  3178.  int efi_compat_get_info(uint32_t idx, union compat_pf_efi_info *);
  3179.  int efi_compat_runtime_call(struct compat_pf_efi_runtime_call *);
  3180.  
  3181. +/*
  3182. + * Test whether the above EFI_* bits are enabled.
  3183. + *
  3184. + * Stolen from Linux Kernel.
  3185. + */
  3186. +static inline bool_t efi_enabled(int feature)
  3187. +{
  3188. +    return test_bit(feature, &efi.flags) != 0;
  3189. +}
  3190. +
  3191.  #endif /* !__ASSEMBLY__ */
  3192.  
  3193.  #endif /* __XEN_EFI_H__ */
  3194. diff -Naur xen-9999-bef/xen/include/xen/multiboot2.h xen-9999-aft/xen/include/xen/multiboot2.h
  3195. --- xen-9999-bef/xen/include/xen/multiboot2.h   1970-01-01 02:00:00.000000000 +0200
  3196. +++ xen-9999-aft/xen/include/xen/multiboot2.h   2015-08-16 08:30:57.850765011 +0300
  3197. @@ -0,0 +1,182 @@
  3198. +/*
  3199. + *  Copyright (C) 1999,2003,2007,2008,2009,2010  Free Software Foundation, Inc.
  3200. + *
  3201. + *  multiboot2.h - Multiboot 2 header file.
  3202. + *
  3203. + *  Based on grub-2.00/include/multiboot2.h file.
  3204. + *
  3205. + *  Permission is hereby granted, free of charge, to any person obtaining a copy
  3206. + *  of this software and associated documentation files (the "Software"), to
  3207. + *  deal in the Software without restriction, including without limitation the
  3208. + *  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  3209. + *  sell copies of the Software, and to permit persons to whom the Software is
  3210. + *  furnished to do so, subject to the following conditions:
  3211. + *
  3212. + *  The above copyright notice and this permission notice shall be included in
  3213. + *  all copies or substantial portions of the Software.
  3214. + *
  3215. + *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3216. + *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3217. + *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL ANY
  3218. + *  DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  3219. + *  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  3220. + *  IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  3221. + */
  3222. +
  3223. +#ifndef __MULTIBOOT2_H__
  3224. +#define __MULTIBOOT2_H__
  3225. +
  3226. +/* The magic field should contain this.  */
  3227. +#define MULTIBOOT2_HEADER_MAGIC                        0xe85250d6
  3228. +
  3229. +/* This should be in %eax on x86 architecture.  */
  3230. +#define MULTIBOOT2_BOOTLOADER_MAGIC            0x36d76289
  3231. +
  3232. +/* How many bytes from the start of the file we search for the header.  */
  3233. +#define MULTIBOOT2_SEARCH                      32768
  3234. +
  3235. +/* Multiboot 2 header alignment. */
  3236. +#define MULTIBOOT2_HEADER_ALIGN                        8
  3237. +
  3238. +/* Alignment of multiboot 2 modules.  */
  3239. +#define MULTIBOOT2_MOD_ALIGN                   0x00001000
  3240. +
  3241. +/* Alignment of the multiboot 2 info structure.  */
  3242. +#define MULTIBOOT2_INFO_ALIGN                  0x00000008
  3243. +
  3244. +/* Multiboot 2 architectures. */
  3245. +#define MULTIBOOT2_ARCHITECTURE_I386   0
  3246. +#define MULTIBOOT2_ARCHITECTURE_MIPS32 4
  3247. +
  3248. +/* Header tag types. */
  3249. +#define MULTIBOOT2_HEADER_TAG_END                      0
  3250. +#define MULTIBOOT2_HEADER_TAG_INFORMATION_REQUEST      1
  3251. +#define MULTIBOOT2_HEADER_TAG_ADDRESS                  2
  3252. +#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS            3
  3253. +#define MULTIBOOT2_HEADER_TAG_CONSOLE_FLAGS            4
  3254. +#define MULTIBOOT2_HEADER_TAG_FRAMEBUFFER              5
  3255. +#define MULTIBOOT2_HEADER_TAG_MODULE_ALIGN             6
  3256. +#define MULTIBOOT2_HEADER_TAG_EFI_BS                   7
  3257. +#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI32      8
  3258. +#define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64      9
  3259. +#define MULTIBOOT2_HEADER_TAG_RELOCATABLE              10
  3260. +
  3261. +/* Header tag flags. */
  3262. +#define MULTIBOOT2_HEADER_TAG_REQUIRED 0
  3263. +#define MULTIBOOT2_HEADER_TAG_OPTIONAL 1
  3264. +
  3265. +/* Where image should be loaded (suggestion not requirement). */
  3266. +#define MULTIBOOT2_LOAD_PREFERENCE_NONE        0
  3267. +#define MULTIBOOT2_LOAD_PREFERENCE_LOW         1
  3268. +#define MULTIBOOT2_LOAD_PREFERENCE_HIGH        2
  3269. +
  3270. +/* Header console tag console_flags. */
  3271. +#define MULTIBOOT2_CONSOLE_FLAGS_CONSOLE_REQUIRED      1
  3272. +#define MULTIBOOT2_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED    2
  3273. +
  3274. +/* Flags set in the 'flags' member of the multiboot header.  */
  3275. +#define MULTIBOOT2_TAG_TYPE_END                        0
  3276. +#define MULTIBOOT2_TAG_TYPE_CMDLINE            1
  3277. +#define MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME   2
  3278. +#define MULTIBOOT2_TAG_TYPE_MODULE             3
  3279. +#define MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO      4
  3280. +#define MULTIBOOT2_TAG_TYPE_BOOTDEV            5
  3281. +#define MULTIBOOT2_TAG_TYPE_MMAP               6
  3282. +#define MULTIBOOT2_TAG_TYPE_VBE                        7
  3283. +#define MULTIBOOT2_TAG_TYPE_FRAMEBUFFER                8
  3284. +#define MULTIBOOT2_TAG_TYPE_ELF_SECTIONS       9
  3285. +#define MULTIBOOT2_TAG_TYPE_APM                        10
  3286. +#define MULTIBOOT2_TAG_TYPE_EFI32              11
  3287. +#define MULTIBOOT2_TAG_TYPE_EFI64              12
  3288. +#define MULTIBOOT2_TAG_TYPE_SMBIOS             13
  3289. +#define MULTIBOOT2_TAG_TYPE_ACPI_OLD           14
  3290. +#define MULTIBOOT2_TAG_TYPE_ACPI_NEW           15
  3291. +#define MULTIBOOT2_TAG_TYPE_NETWORK            16
  3292. +#define MULTIBOOT2_TAG_TYPE_EFI_MMAP           17
  3293. +#define MULTIBOOT2_TAG_TYPE_EFI_BS             18
  3294. +#define MULTIBOOT2_TAG_TYPE_EFI32_IH           19
  3295. +#define MULTIBOOT2_TAG_TYPE_EFI64_IH           20
  3296. +#define MULTIBOOT2_TAG_TYPE_BASE_ADDR          21
  3297. +
  3298. +/* Multiboot 2 tag alignment. */
  3299. +#define MULTIBOOT2_TAG_ALIGN                   8
  3300. +
  3301. +/* Memory types. */
  3302. +#define MULTIBOOT2_MEMORY_AVAILABLE            1
  3303. +#define MULTIBOOT2_MEMORY_RESERVED             2
  3304. +#define MULTIBOOT2_MEMORY_ACPI_RECLAIMABLE     3
  3305. +#define MULTIBOOT2_MEMORY_NVS                  4
  3306. +#define MULTIBOOT2_MEMORY_BADRAM               5
  3307. +
  3308. +/* Framebuffer types. */
  3309. +#define MULTIBOOT2_FRAMEBUFFER_TYPE_INDEXED    0
  3310. +#define MULTIBOOT2_FRAMEBUFFER_TYPE_RGB                1
  3311. +#define MULTIBOOT2_FRAMEBUFFER_TYPE_EGA_TEXT   2
  3312. +
  3313. +#ifndef __ASSEMBLY__
  3314. +typedef struct {
  3315. +    u32 total_size;
  3316. +    u32 reserved;
  3317. +} multiboot2_fixed_t;
  3318. +
  3319. +typedef struct {
  3320. +    u32 type;
  3321. +    u32 size;
  3322. +} multiboot2_tag_t;
  3323. +
  3324. +typedef struct {
  3325. +    u32 type;
  3326. +    u32 size;
  3327. +    u32 base_addr;
  3328. +} multiboot2_tag_base_addr_t;
  3329. +
  3330. +typedef struct {
  3331. +    u32 type;
  3332. +    u32 size;
  3333. +    char string[0];
  3334. +} multiboot2_tag_string_t;
  3335. +
  3336. +typedef struct {
  3337. +    u32 type;
  3338. +    u32 size;
  3339. +    u32 mem_lower;
  3340. +    u32 mem_upper;
  3341. +} multiboot2_tag_basic_meminfo_t;
  3342. +
  3343. +typedef struct __packed {
  3344. +    u64 addr;
  3345. +    u64 len;
  3346. +    u32 type;
  3347. +    u32 zero;
  3348. +} multiboot2_memory_map_t;
  3349. +
  3350. +typedef struct {
  3351. +    u32 type;
  3352. +    u32 size;
  3353. +    u32 entry_size;
  3354. +    u32 entry_version;
  3355. +    multiboot2_memory_map_t entries[0];
  3356. +} multiboot2_tag_mmap_t;
  3357. +
  3358. +typedef struct {
  3359. +    u32 type;
  3360. +    u32 size;
  3361. +    u64 pointer;
  3362. +} multiboot2_tag_efi64_t;
  3363. +
  3364. +typedef struct {
  3365. +    u32 type;
  3366. +    u32 size;
  3367. +    u64 pointer;
  3368. +} multiboot2_tag_efi64_ih_t;
  3369. +
  3370. +typedef struct {
  3371. +    u32 type;
  3372. +    u32 size;
  3373. +    u32 mod_start;
  3374. +    u32 mod_end;
  3375. +    char cmdline[0];
  3376. +} multiboot2_tag_module_t;
  3377. +#endif /* __ASSEMBLY__ */
  3378. +
  3379. +#endif /* __MULTIBOOT2_H__ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement