Package org.jnode.build

Examples of org.jnode.build.BuildException


        Elf elf;
        try {
            elf = Elf.newFromFile(name);
            loadElfObject(elf);
        } catch (IOException ex) {
            throw new BuildException(ex);
        }
    }
View Full Code Here


     * Load an ELF object file with a given name and link it into the native
     * stream.
     */
    public void loadElfObject(Elf elf) throws BuildException {
        if (!elf.isRel()) {
            throw new BuildException("Elf object is not relocatable");
        }

        final Section text = elf.getSectionByName(".text");
        if (text == null) {
            throw new BuildException(".text section not found");
        }

        // Write the code
        start = os.getLength();
        final byte[] tdata = text.getBody();
        os.write(tdata, 0, tdata.length);

        // Add all resolved symbols
        final int symCnt = elf.getNoSymbols();
        for (int i = 1; i < symCnt; i++) {
            final Symbol sym = elf.getSymbol(i);
            final Section sec = sym.getSection();
            if (sec == text) {
                // System.out.println(sym);
                X86BinaryAssembler.X86ObjectRef ref = (X86BinaryAssembler.X86ObjectRef) os
                    .getObjectRef(new Label(sym.getName()));
                ref.setPublic();
                if (!sym.isUndef()) {
                    // System.out.println("Defined symbol at " + sym.getValue()
                    // + " [" + sym.getName() + "]");
                    ref.setOffset((int) sym.getValue() + start);
                } else {
                    System.out.println("Undefined symbol: " + sym.getName());
                }
            } else if ((sec != null) && !sym.isUndef()) {
                System.out
                    .println("Symbol '" + sym.getName()
                        + "' refers to unknown section '"
                        + sec.getName() + "'");
            }
        }

        // Add all relocation items
        Section rels = elf.getSectionByName(".rel.text");
        if (rels == null) {
            rels = elf.getSectionByName(".rela.text");
        }
        if (rels != null) {
            final int relocCnt = rels.getNoRelocs();
            for (int i = 0; i < relocCnt; i++) {
                try {
                    final Reloc r = rels.getReloc(i);
                    final String symName = r.getSymbol().getName();
                    final boolean hasSymName = (symName.length() > 0);
                    final boolean hasAddEnd = r.hasAddEnd();
                    final long addr = r.getAddress() + start;
                    final long addend = r.getAddEnd();

                    final Reloc.Type relocType = r.getRelocType();
                    if ((relocType == Reloc.R_386_32) && !hasAddEnd) {
                        resolve_R386_32(addr, symName, hasSymName);
                    } else if ((relocType == Reloc.R_386_PC32) && !hasAddEnd) {
                        resolve_R386_PC32(addr, symName, hasSymName);
                    } else if ((relocType == Reloc.R_X86_64_32) && hasAddEnd) {
                        resolve_R_X86_64_32(addr, addend, symName, hasSymName);
                    } else if ((relocType == Reloc.R_X86_64_64) && hasAddEnd) {
                        resolve_R_X86_64_64(addr, addend, symName, hasSymName);
                    } else {
                        throw new BuildException("Unknown relocation type "
                            + relocType);
                    }
                } catch (UnresolvedObjectRefException ex) {
                    throw new BuildException(ex);
                }
            }
        }
    }
View Full Code Here

                if (!file.exists() || overwriteScripts) {
                    build(applicationDir, cmd, file);
                }
            }
        } catch (Throwable t) {
            throw new BuildException("failed to build scripts", t);
        }
    }
View Full Code Here

                    processor = new VmX86Processor64(0,
                        (VmX86Architecture64) getArchitecture(), statics, isolatedStatics, scheduler,
                        getCPUID());
                    break;
                default:
                    throw new BuildException("Unknown bits " + bits);
            }
        }
        return processor;
    }
View Full Code Here

                    break;
                case 64:
                    arch = new VmX86Architecture64(getJnodeCompiler());
                    break;
                default:
                    throw new BuildException("Unknown bits " + bits);
            }
        }
        return arch;
    }
View Full Code Here

        try {
            Elf elf = Elf.newFromFile(getKernelFile().getCanonicalPath());
            // elf.print();
            new ElfLinker((X86BinaryAssembler) os).loadElfObject(elf);
        } catch (IOException ex) {
            throw new BuildException(ex);
        }

        // Link the jump table entries
        for (int i = 0; i < X86JumpTable.TABLE_LENGTH; i++) {
            final Label lbl = new Label(X86JumpTable.TABLE_ENTRY_LABELS[i]);
View Full Code Here

            VmType<?> vmCodeClass = loadClass(VmMethodCode.class);
            final X86BinaryAssembler.ObjectInfo initObject = os
                .startObject(vmCodeClass);
            final int offset = os.getLength() - startLength;
            if (offset != JUMP_MAIN_OFFSET()) {
                throw new BuildException("JUMP_MAIN_OFFSET is incorrect ["
                    + offset + " instead of " + JUMP_MAIN_OFFSET()
                    + "] (set to Object headersize)");
            }

            final X86BinaryAssembler os86 = (X86BinaryAssembler) os;
            final Label introCode = new Label("$$introCode");

            os86.setObjectRef(new Label("$$jmp-introCode"));
            os86.writeJMP(introCode);
            initObject.markEnd();

            // The loading of class can emit object in between, so first load
            // all required classes here.
            loadClass(Main.class);
            loadClass(MonitorManager.class);
            loadClass(SoftByteCodes.class);
            loadClass(Vm.class);
            loadClass(VmMethod.class);
            loadClass(VmProcessor.class);
            loadClass(VmThread.class);
            loadClass(VmType.class);
            loadClass(VmSystem.class);
            loadClass(VmSystemObject.class);

            final X86BinaryAssembler.ObjectInfo initCodeObject = os
                .startObject(vmCodeClass);
            os86.setObjectRef(introCode);
            initMain(os86, pluginRegistry);
            initVm(os86, vm);
            // initHeapManager(os86, vm);
            initVmThread(os86);

            os.setObjectRef(new Label("$$Initial call to clInitCaller"));
            os86.writeCALL(clInitCaller);

            initCallMain(os86);

            initCodeObject.markEnd();

        } catch (ClassNotFoundException ex) {
            throw new BuildException(ex);
        }
    }
View Full Code Here

                * System.currentTimeMillis(); log.info("... took " + (end-start) +
                * "ms"); elf.store(getDestFile().getAbsolutePath() + ".elf");
                */

        } catch (IOException ex) {
            throw new BuildException(ex);
        }
    }
View Full Code Here

                mb_hdr = i;
                break;
            }
        }
        if (mb_hdr < 0) {
            throw new BuildException("Cannot find Multiboot header");
        }

        int loadAddr = os.get32(mb_hdr + MB_LOAD_ADDR);
        if (loadAddr != os.getBaseAddr()) {
            throw new BuildException("Non-matching load address, found 0x"
                + Integer.toHexString(loadAddr) + ", expected 0x"
                + Long.toHexString(os.getBaseAddr()));
        }

        os.set32(mb_hdr + MB_LOAD_END_ADDR, (int) os.getBaseAddr()
View Full Code Here

    protected void initializeStatics(VmSharedStatics statics) throws BuildException {
        for (int i = 0; i < X86JumpTable.TABLE_LENGTH; i++) {
            final int idx = statics.allocAddressField();
            if (getArchitecture().getReferenceSize() == 4) {
                if (i != idx) {
                    throw new BuildException("JumpTable entry " + i + " must be at index " + i + " not " + idx);
                }
            } else {
                if ((i * 2) != idx) {
                    throw new BuildException("JumpTable entry " + i + " must be at index " + (i * 2) + " not " + idx);
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.jnode.build.BuildException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.